Added VMA.
This commit is contained in:
parent
35347d28e0
commit
e7d74e6b0f
|
|
@ -154,6 +154,7 @@
|
|||
<ClCompile Include="GlobalMemory.cpp" />
|
||||
<ClCompile Include="MiscData.cpp" />
|
||||
<ClCompile Include="RenderDevice.cpp" />
|
||||
<ClCompile Include="VmaImpl.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include=".gitignore" />
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@
|
|||
<ClCompile Include="GlobalMemory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="VmaImpl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="vcpkg.json">
|
||||
|
|
|
|||
|
|
@ -278,7 +278,6 @@ void MiscData::init(RenderDevice const& renderDevice)
|
|||
.imageMemoryBarrierCount = 1,
|
||||
.pImageMemoryBarriers = &renderToPresentBarrier,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
void MiscData::cleanup(RenderDevice const& renderDevice)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <SDL3/SDL_log.h>
|
||||
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
|
||||
#include "Frame.h"
|
||||
|
|
@ -60,7 +61,8 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
|||
|
||||
VkPhysicalDevice physicalDeviceInUse = nullptr;
|
||||
VkDevice device = nullptr;
|
||||
uint32_t directQueueFamilyIndex = -1;
|
||||
VmaAllocator gpuAllocator = nullptr;
|
||||
std::optional<uint32_t> directQueueFamilyIndex;
|
||||
VkQueue directQueue = nullptr;
|
||||
// Create Device and Queue
|
||||
{
|
||||
|
|
@ -152,13 +154,14 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
|||
}
|
||||
|
||||
ASSERT(physicalDeviceInUse);
|
||||
ASSERT(directQueueFamilyIndex.has_value());
|
||||
|
||||
float priority = 1.0f;
|
||||
VkDeviceQueueCreateInfo queueCreateInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = 0,
|
||||
.queueFamilyIndex = directQueueFamilyIndex,
|
||||
.queueFamilyIndex = directQueueFamilyIndex.value(),
|
||||
.queueCount = 1,
|
||||
.pQueuePriorities = &priority,
|
||||
};
|
||||
|
|
@ -193,7 +196,29 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
|||
};
|
||||
|
||||
VK_CHECK(vkCreateDevice(physicalDeviceInUse, &deviceCreateInfo, nullptr, &device));
|
||||
vkGetDeviceQueue(device, directQueueFamilyIndex, 0, &directQueue);
|
||||
volkLoadDevice(device);
|
||||
|
||||
VmaAllocatorCreateInfo allocatorCreateInfo = {
|
||||
.flags = 0,
|
||||
.physicalDevice = physicalDeviceInUse,
|
||||
.device = device,
|
||||
.preferredLargeHeapBlockSize = 0,
|
||||
.pAllocationCallbacks = nullptr,
|
||||
.pDeviceMemoryCallbacks = nullptr,
|
||||
.pHeapSizeLimit = nullptr,
|
||||
.pVulkanFunctions = nullptr,
|
||||
.instance = instance,
|
||||
.vulkanApiVersion = VK_API_VERSION_1_3,
|
||||
.pTypeExternalMemoryHandleTypes = nullptr,
|
||||
};
|
||||
|
||||
VmaVulkanFunctions vkFunctions;
|
||||
VK_CHECK(vmaImportVulkanFunctionsFromVolk(&allocatorCreateInfo, &vkFunctions));
|
||||
allocatorCreateInfo.pVulkanFunctions = &vkFunctions;
|
||||
|
||||
VK_CHECK(vmaCreateAllocator(&allocatorCreateInfo, &gpuAllocator));
|
||||
|
||||
vkGetDeviceQueue(device, directQueueFamilyIndex.value(), 0, &directQueue);
|
||||
|
||||
mem->restoreState(tempAllocStart);
|
||||
}
|
||||
|
|
@ -340,13 +365,13 @@ RenderDevice* CreateRenderDevice(GlobalMemory* mem, RenderDevice::CreateInfo con
|
|||
Frame* frames = reinterpret_cast<Frame*>(mem->allocate(sizeof(Frame) * swapchainImageCount));
|
||||
for (uint32_t i = 0; i != swapchainImageCount; ++i)
|
||||
{
|
||||
new (frames + i) Frame(device, directQueueFamilyIndex);
|
||||
new (frames + i) Frame(device, directQueueFamilyIndex.value());
|
||||
}
|
||||
|
||||
Byte* allocation = mem->allocate(sizeof(RenderDevice), alignof(RenderDevice));
|
||||
return new (allocation) RenderDevice{
|
||||
instance, surface, physicalDeviceInUse,
|
||||
device, directQueue, directQueueFamilyIndex,
|
||||
device, gpuAllocator, directQueue, directQueueFamilyIndex.value(),
|
||||
swapchainFormat, swapchainExtent, swapchain, swapchainImages, swapchainViews, frames, swapchainImageCount,
|
||||
};
|
||||
}
|
||||
|
|
@ -393,13 +418,14 @@ uint32_t RenderDevice::getNumFrames() const
|
|||
}
|
||||
|
||||
RenderDevice::RenderDevice(VkInstance const instance, VkSurfaceKHR const surface, VkPhysicalDevice const physicalDeviceInUse,
|
||||
VkDevice const device, VkQueue const directQueue, uint32_t const directQueueFamilyIndex, VkFormat const swapchainFormat,
|
||||
VkExtent2D const swapchainExtent, VkSwapchainKHR const swapchain, VkImage* swapchainImages, VkImageView* swapchainViews,
|
||||
Frame* frames, uint32_t const swapchainImageCount)
|
||||
VkDevice const device, VmaAllocator gpuAllocator, VkQueue const directQueue, uint32_t const directQueueFamilyIndex,
|
||||
VkFormat const swapchainFormat, VkExtent2D const swapchainExtent, VkSwapchainKHR const swapchain, VkImage* swapchainImages,
|
||||
VkImageView* swapchainViews, Frame* frames, uint32_t const swapchainImageCount)
|
||||
: instance{ instance }
|
||||
, surface{ surface }
|
||||
, physicalDeviceInUse{ physicalDeviceInUse }
|
||||
, device{ device }
|
||||
, gpuAllocator{ gpuAllocator }
|
||||
, directQueue{ directQueue }
|
||||
, directQueueFamilyIndex{ directQueueFamilyIndex }
|
||||
, swapchainFormat{ swapchainFormat }
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
#include <volk.h>
|
||||
|
||||
#define VMA_STATIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
|
||||
#include <vma/vk_mem_alloc.h>
|
||||
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <SDL3/SDL_vulkan.h>
|
||||
|
||||
|
|
@ -24,10 +28,11 @@ struct RenderDevice
|
|||
VkInstance instance;
|
||||
VkSurfaceKHR surface;
|
||||
VkPhysicalDevice physicalDeviceInUse;
|
||||
|
||||
VkDevice device;
|
||||
VmaAllocator gpuAllocator;
|
||||
VkQueue directQueue;
|
||||
uint32_t directQueueFamilyIndex;
|
||||
// TODO: Pack?
|
||||
|
||||
VkFormat swapchainFormat;
|
||||
VkExtent2D swapchainExtent;
|
||||
|
|
@ -48,6 +53,7 @@ struct RenderDevice
|
|||
VkSurfaceKHR surface,
|
||||
VkPhysicalDevice physicalDeviceInUse,
|
||||
VkDevice device,
|
||||
VmaAllocator gpuAllocator,
|
||||
VkQueue directQueue,
|
||||
uint32_t directQueueFamilyIndex,
|
||||
// TODO: Pack?
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
#include <volk.h>
|
||||
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning(disable : 5045)
|
||||
#define VMA_IMPLEMENTATION
|
||||
#include <vma/vk_mem_alloc.h>
|
||||
#pragma warning(pop)
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
"dependencies": [
|
||||
"volk",
|
||||
"shader-slang",
|
||||
"vulkan-memory-allocator",
|
||||
{
|
||||
"name": "sdl3",
|
||||
"features": [ "vulkan" ]
|
||||
|
|
|
|||
Loading…
Reference in New Issue