Start integrating VMA

This commit is contained in:
Henrik Rydgård 2021-11-21 23:08:47 +01:00
parent eceb691f92
commit 8f9ce03a8d
6 changed files with 48 additions and 9 deletions

View File

@ -376,6 +376,7 @@
<ClInclude Include="..\ext\libpng17\pnglibconf.h" />
<ClInclude Include="..\ext\libpng17\pngpriv.h" />
<ClInclude Include="..\ext\libpng17\pngstruct.h" />
<ClInclude Include="..\ext\vma\vk_mem_alloc.h" />
<ClInclude Include="ABI.h" />
<ClInclude Include="Arm64Emitter.h" />
<ClInclude Include="ArmCommon.h" />
@ -794,6 +795,7 @@
<ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
</ForcedIncludeFiles>
</ClCompile>
<ClCompile Include="..\ext\vma\vk_mem_alloc.cpp" />
<ClCompile Include="ABI.cpp" />
<ClCompile Include="Arm64Emitter.cpp" />
<ClCompile Include="ArmCPUDetect.cpp">

View File

@ -406,6 +406,9 @@
<ClInclude Include="Thread\Event.h">
<Filter>Thread</Filter>
</ClInclude>
<ClInclude Include="..\ext\vma\vk_mem_alloc.h">
<Filter>ext\vma</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ABI.cpp" />
@ -777,6 +780,9 @@
<Filter>Thread</Filter>
</ClCompile>
<ClCompile Include="RiscVCPUDetect.cpp" />
<ClCompile Include="..\ext\vma\vk_mem_alloc.cpp">
<Filter>ext\vma</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Crypto">
@ -878,6 +884,9 @@
<Filter Include="Render\Text">
<UniqueIdentifier>{9da96cce-c74a-4669-b755-c95defbe1e93}</UniqueIdentifier>
</Filter>
<Filter Include="ext\vma">
<UniqueIdentifier>{7b17065c-729c-47c3-a02d-66dc383529dd}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="..\ext\libpng17\CMakeLists.txt">

View File

@ -13,14 +13,17 @@
#include "Common/StringUtils.h"
#include "Core/Config.h"
// Change this to 1, 2, and 3 to fake failures in a few places, so that
// we can test our fallback-to-GL code.
#define SIMULATE_VULKAN_FAILURE 0
#ifdef USE_CRT_DBG
#undef new
#endif
#include "ext/vma/vk_mem_alloc.h"
// Change this to 1, 2, and 3 to fake failures in a few places, so that
// we can test our fallback-to-GL code.
#define SIMULATE_VULKAN_FAILURE 0
#include "ext/glslang/SPIRV/GlslangToSpv.h"
#ifdef USE_CRT_DBG
@ -656,6 +659,15 @@ VkResult VulkanContext::CreateDevice() {
}
INFO_LOG(G3D, "Device created.\n");
VulkanSetAvailable(true);
VmaAllocatorCreateInfo allocatorInfo = {};
allocatorInfo.vulkanApiVersion = VK_API_VERSION_1_0;
allocatorInfo.physicalDevice = physical_devices_[physical_device_];
allocatorInfo.device = device_;
allocatorInfo.instance = instance_;
VmaAllocator allocator;
vmaCreateAllocator(&allocatorInfo, &allocator);
return res;
}
@ -1103,6 +1115,9 @@ void VulkanContext::DestroyDevice() {
INFO_LOG(G3D, "VulkanContext::DestroyDevice (performing deletes)");
PerformPendingDeletes();
vmaDestroyAllocator(allocator_);
allocator_ = VK_NULL_HANDLE;
vkDestroyDevice(device_, nullptr);
device_ = nullptr;
}

View File

@ -26,6 +26,8 @@ enum {
VULKAN_VENDOR_IMGTEC = 0x00001010, // PowerVR
};
VK_DEFINE_HANDLE(VmaAllocator);
std::string VulkanVendorString(uint32_t vendorId);
// Not all will be usable on all platforms, of course...
@ -359,6 +361,8 @@ private:
VkSurfaceCapabilitiesKHR surfCapabilities_{};
std::vector<VkCommandBuffer> cmdQueue_;
VmaAllocator allocator_ = VK_NULL_HANDLE;
};
// Detailed control.

View File

@ -38,6 +38,7 @@ PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatPrope
PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties;
PFN_vkGetPhysicalDeviceQueueFamilyProperties vkGetPhysicalDeviceQueueFamilyProperties;
PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
PFN_vkGetPhysicalDeviceMemoryProperties2 vkGetPhysicalDeviceMemoryProperties2;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
PFN_vkCreateDevice vkCreateDevice;
@ -58,11 +59,13 @@ PFN_vkFlushMappedMemoryRanges vkFlushMappedMemoryRanges;
PFN_vkInvalidateMappedMemoryRanges vkInvalidateMappedMemoryRanges;
PFN_vkGetDeviceMemoryCommitment vkGetDeviceMemoryCommitment;
PFN_vkBindBufferMemory vkBindBufferMemory;
PFN_vkBindBufferMemory2 vkBindBufferMemory2;
PFN_vkBindImageMemory vkBindImageMemory;
PFN_vkBindImageMemory2 vkBindImageMemory2;
PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements;
PFN_vkGetBufferMemoryRequirements2 vkGetBufferMemoryRequirements2;
PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
PFN_vkGetImageSparseMemoryRequirements vkGetImageSparseMemoryRequirements;
PFN_vkQueueBindSparse vkQueueBindSparse;
PFN_vkGetImageMemoryRequirements2 vkGetImageMemoryRequirements2;
PFN_vkCreateFence vkCreateFence;
PFN_vkDestroyFence vkDestroyFence;
PFN_vkGetFenceStatus vkGetFenceStatus;
@ -581,11 +584,13 @@ void VulkanLoadDeviceFunctions(VkDevice device, const VulkanExtensions &enabledE
LOAD_DEVICE_FUNC(device, vkInvalidateMappedMemoryRanges);
LOAD_DEVICE_FUNC(device, vkGetDeviceMemoryCommitment);
LOAD_DEVICE_FUNC(device, vkBindBufferMemory);
LOAD_DEVICE_FUNC(device, vkBindBufferMemory2);
LOAD_DEVICE_FUNC(device, vkBindImageMemory);
LOAD_DEVICE_FUNC(device, vkBindImageMemory2);
LOAD_DEVICE_FUNC(device, vkGetBufferMemoryRequirements);
LOAD_DEVICE_FUNC(device, vkGetBufferMemoryRequirements2);
LOAD_DEVICE_FUNC(device, vkGetImageMemoryRequirements);
LOAD_DEVICE_FUNC(device, vkGetImageSparseMemoryRequirements);
LOAD_DEVICE_FUNC(device, vkQueueBindSparse);
LOAD_DEVICE_FUNC(device, vkGetImageMemoryRequirements2);
LOAD_DEVICE_FUNC(device, vkCreateFence);
LOAD_DEVICE_FUNC(device, vkDestroyFence);
LOAD_DEVICE_FUNC(device, vkResetFences);

View File

@ -44,6 +44,7 @@ extern PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageForm
extern PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties;
extern PFN_vkGetPhysicalDeviceQueueFamilyProperties vkGetPhysicalDeviceQueueFamilyProperties;
extern PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
extern PFN_vkGetPhysicalDeviceMemoryProperties2 vkGetPhysicalDeviceMemoryProperties2;
extern PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
extern PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
extern PFN_vkCreateDevice vkCreateDevice;
@ -64,10 +65,13 @@ extern PFN_vkFlushMappedMemoryRanges vkFlushMappedMemoryRanges;
extern PFN_vkInvalidateMappedMemoryRanges vkInvalidateMappedMemoryRanges;
extern PFN_vkGetDeviceMemoryCommitment vkGetDeviceMemoryCommitment;
extern PFN_vkBindBufferMemory vkBindBufferMemory;
extern PFN_vkBindBufferMemory2 vkBindBufferMemory2;
extern PFN_vkBindImageMemory vkBindImageMemory;
extern PFN_vkBindImageMemory2 vkBindImageMemory2;
extern PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements;
extern PFN_vkGetBufferMemoryRequirements2 vkGetBufferMemoryRequirements2;
extern PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
extern PFN_vkGetImageSparseMemoryRequirements vkGetImageSparseMemoryRequirements;
extern PFN_vkGetImageMemoryRequirements2 vkGetImageMemoryRequirements2;
extern PFN_vkQueueBindSparse vkQueueBindSparse;
extern PFN_vkCreateFence vkCreateFence;
extern PFN_vkDestroyFence vkDestroyFence;