Added #if VMA_DEDICATED_ALLOCATION around every usage of VK_KHR_get_memory_requirements2 or VK_KHR_dedicated_allocation extension - for compatibility with Android. #23 Thanks @achienbsi !

This commit is contained in:
Adam Sawicki 2018-04-03 13:45:39 +02:00
parent 5a51732c47
commit 4f91939dea
2 changed files with 32 additions and 1 deletions

View File

@ -20,6 +20,8 @@ include all public interface declarations. Example:
//#define VMA_HEAVY_ASSERT(expr)
//#define VMA_DEDICATED_ALLOCATION 0
#pragma warning(push, 4)
#pragma warning(disable: 4127) // conditional expression is constant
#pragma warning(disable: 4100) // unreferenced formal parameter

View File

@ -1077,6 +1077,14 @@ Features deliberately excluded from the scope of this library:
#include <vulkan/vulkan.h>
#if !defined(VMA_DEDICATED_ALLOCATION)
#if VK_KHR_get_memory_requirements2 && VK_KHR_dedicated_allocation
#define VMA_DEDICATED_ALLOCATION 1
#else
#define VMA_DEDICATED_ALLOCATION 0
#endif
#endif
/** \struct VmaAllocator
\brief Represents main object of this library initialized.
@ -1168,8 +1176,10 @@ typedef struct VmaVulkanFunctions {
PFN_vkDestroyBuffer vkDestroyBuffer;
PFN_vkCreateImage vkCreateImage;
PFN_vkDestroyImage vkDestroyImage;
#if VMA_DEDICATED_ALLOCATION
PFN_vkGetBufferMemoryRequirements2KHR vkGetBufferMemoryRequirements2KHR;
PFN_vkGetImageMemoryRequirements2KHR vkGetImageMemoryRequirements2KHR;
#endif
} VmaVulkanFunctions;
/// Description of a Allocator to be created.
@ -7386,7 +7396,14 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
m_CurrentFrameIndex(0),
m_Pools(VmaStlAllocator<VmaPool>(GetAllocationCallbacks()))
{
VMA_ASSERT(pCreateInfo->physicalDevice && pCreateInfo->device);
VMA_ASSERT(pCreateInfo->physicalDevice && pCreateInfo->device);
#if !(VMA_DEDICATED_ALLOCATION)
if((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0)
{
VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT set but required extensions are disabled by preprocessor macros.");
}
#endif
memset(&m_DeviceMemoryCallbacks, 0 ,sizeof(m_DeviceMemoryCallbacks));
memset(&m_MemProps, 0, sizeof(m_MemProps));
@ -7477,6 +7494,7 @@ void VmaAllocator_T::ImportVulkanFunctions(const VmaVulkanFunctions* pVulkanFunc
m_VulkanFunctions.vkDestroyBuffer = &vkDestroyBuffer;
m_VulkanFunctions.vkCreateImage = &vkCreateImage;
m_VulkanFunctions.vkDestroyImage = &vkDestroyImage;
#if VMA_DEDICATED_ALLOCATION
if(m_UseKhrDedicatedAllocation)
{
m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR =
@ -7484,6 +7502,7 @@ void VmaAllocator_T::ImportVulkanFunctions(const VmaVulkanFunctions* pVulkanFunc
m_VulkanFunctions.vkGetImageMemoryRequirements2KHR =
(PFN_vkGetImageMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetImageMemoryRequirements2KHR");
}
#endif // #if VMA_DEDICATED_ALLOCATION
#endif // #if VMA_STATIC_VULKAN_FUNCTIONS == 1
#define VMA_COPY_IF_NOT_NULL(funcName) \
@ -7505,8 +7524,10 @@ void VmaAllocator_T::ImportVulkanFunctions(const VmaVulkanFunctions* pVulkanFunc
VMA_COPY_IF_NOT_NULL(vkDestroyBuffer);
VMA_COPY_IF_NOT_NULL(vkCreateImage);
VMA_COPY_IF_NOT_NULL(vkDestroyImage);
#if VMA_DEDICATED_ALLOCATION
VMA_COPY_IF_NOT_NULL(vkGetBufferMemoryRequirements2KHR);
VMA_COPY_IF_NOT_NULL(vkGetImageMemoryRequirements2KHR);
#endif
}
#undef VMA_COPY_IF_NOT_NULL
@ -7527,11 +7548,13 @@ void VmaAllocator_T::ImportVulkanFunctions(const VmaVulkanFunctions* pVulkanFunc
VMA_ASSERT(m_VulkanFunctions.vkDestroyBuffer != VMA_NULL);
VMA_ASSERT(m_VulkanFunctions.vkCreateImage != VMA_NULL);
VMA_ASSERT(m_VulkanFunctions.vkDestroyImage != VMA_NULL);
#if VMA_DEDICATED_ALLOCATION
if(m_UseKhrDedicatedAllocation)
{
VMA_ASSERT(m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR != VMA_NULL);
VMA_ASSERT(m_VulkanFunctions.vkGetImageMemoryRequirements2KHR != VMA_NULL);
}
#endif
}
VkDeviceSize VmaAllocator_T::CalcPreferredBlockSize(uint32_t memTypeIndex)
@ -7665,6 +7688,7 @@ VkResult VmaAllocator_T::AllocateDedicatedMemory(
allocInfo.memoryTypeIndex = memTypeIndex;
allocInfo.allocationSize = size;
#if VMA_DEDICATED_ALLOCATION
VkMemoryDedicatedAllocateInfoKHR dedicatedAllocInfo = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR };
if(m_UseKhrDedicatedAllocation)
{
@ -7680,6 +7704,7 @@ VkResult VmaAllocator_T::AllocateDedicatedMemory(
allocInfo.pNext = &dedicatedAllocInfo;
}
}
#endif // #if VMA_DEDICATED_ALLOCATION
// Allocate VkDeviceMemory.
VkDeviceMemory hMemory = VK_NULL_HANDLE;
@ -7731,6 +7756,7 @@ void VmaAllocator_T::GetBufferMemoryRequirements(
bool& requiresDedicatedAllocation,
bool& prefersDedicatedAllocation) const
{
#if VMA_DEDICATED_ALLOCATION
if(m_UseKhrDedicatedAllocation)
{
VkBufferMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR };
@ -7748,6 +7774,7 @@ void VmaAllocator_T::GetBufferMemoryRequirements(
prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
}
else
#endif // #if VMA_DEDICATED_ALLOCATION
{
(*m_VulkanFunctions.vkGetBufferMemoryRequirements)(m_hDevice, hBuffer, &memReq);
requiresDedicatedAllocation = false;
@ -7761,6 +7788,7 @@ void VmaAllocator_T::GetImageMemoryRequirements(
bool& requiresDedicatedAllocation,
bool& prefersDedicatedAllocation) const
{
#if VMA_DEDICATED_ALLOCATION
if(m_UseKhrDedicatedAllocation)
{
VkImageMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR };
@ -7778,6 +7806,7 @@ void VmaAllocator_T::GetImageMemoryRequirements(
prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
}
else
#endif // #if VMA_DEDICATED_ALLOCATION
{
(*m_VulkanFunctions.vkGetImageMemoryRequirements)(m_hDevice, hImage, &memReq);
requiresDedicatedAllocation = false;