@@ -3552,6 +3552,7 @@ constexpr uint32_t VMA_VENDOR_ID_AMD = 4098;
35523552// Vulkan 1.0, but doesn't actually define it in Vulkan SDK earlier than 1.2.131.
35533553// See pull request #207.
35543554#define VK_ERROR_UNKNOWN_COPY ((VkResult)-13)
3555+ } // namespace
35553556
35563557
35573558#if VMA_STATS_STRING_ENABLED
@@ -3602,12 +3603,12 @@ enum class VmaAllocationRequestType
36023603
36033604#endif // _VMA_ENUM_DECLARATIONS
36043605
3605- } // namespace
3606-
36073606#ifndef _VMA_FORWARD_DECLARATIONS
36083607// Opaque handle used by allocation algorithms to identify single allocation in any conforming way.
36093608VK_DEFINE_NON_DISPATCHABLE_HANDLE(VmaAllocHandle);
36103609
3610+ struct VmaBufferImageUsage;
3611+
36113612struct VmaMutexLock;
36123613struct VmaMutexLockRead;
36133614struct VmaMutexLockWrite;
@@ -3672,6 +3673,85 @@ class VmaAllocationObjectAllocator;
36723673
36733674#endif // _VMA_FORWARD_DECLARATIONS
36743675
3676+ #ifndef _VMA_BUFFER_IMAGE_USAGE
3677+
3678+ // Finds structure with s->sType == sType in mainStruct->pNext chain.
3679+ // Returns pointer to it. If not found, returns null.
3680+ template<typename FindT, typename MainT>
3681+ inline const FindT* VmaPnextChainFind(const MainT* mainStruct, VkStructureType sType)
3682+ {
3683+ for(const VkBaseInStructure* s = (const VkBaseInStructure*)mainStruct->pNext;
3684+ s != VMA_NULL; s = s->pNext)
3685+ {
3686+ if(s->sType == sType)
3687+ {
3688+ return (const FindT*)s;
3689+ }
3690+ }
3691+ return VMA_NULL;
3692+ }
3693+
3694+ // An abstraction over buffer or image `usage` flags, depending on available extensions.
3695+ struct VmaBufferImageUsage
3696+ {
3697+ #if VMA_KHR_MAINTENANCE5
3698+ typedef uint64_t BaseType; // VkFlags64
3699+ #else
3700+ typedef uint32_t BaseType; // VkFlags32
3701+ #endif
3702+
3703+ static const VmaBufferImageUsage UNKNOWN;
3704+
3705+ BaseType Value;
3706+
3707+ VmaBufferImageUsage() { *this = UNKNOWN; }
3708+ explicit VmaBufferImageUsage(BaseType usage) : Value(usage) { }
3709+ VmaBufferImageUsage(const VkBufferCreateInfo &createInfo, bool useKhrMaintenance5);
3710+ explicit VmaBufferImageUsage(const VkImageCreateInfo &createInfo);
3711+
3712+ bool operator==(const VmaBufferImageUsage& rhs) const { return Value == rhs.Value; }
3713+ bool operator!=(const VmaBufferImageUsage& rhs) const { return Value != rhs.Value; }
3714+
3715+ bool Contains(BaseType flag) const { return (Value & flag) != 0; }
3716+ bool ContainsDeviceAccess() const
3717+ {
3718+ // This relies on values of VK_IMAGE_USAGE_TRANSFER* being the same as VK_BUFFER_IMAGE_TRANSFER*.
3719+ return (Value & ~BaseType(VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT)) != 0;
3720+ }
3721+ };
3722+
3723+ const VmaBufferImageUsage VmaBufferImageUsage::UNKNOWN = VmaBufferImageUsage(0);
3724+
3725+ VmaBufferImageUsage::VmaBufferImageUsage(const VkBufferCreateInfo &createInfo,
3726+ bool useKhrMaintenance5)
3727+ {
3728+ #if VMA_KHR_MAINTENANCE5
3729+ if(useKhrMaintenance5)
3730+ {
3731+ // If VkBufferCreateInfo::pNext chain contains VkBufferUsageFlags2CreateInfoKHR,
3732+ // take usage from it and ignore VkBufferCreateInfo::usage, per specification
3733+ // of the VK_KHR_maintenance5 extension.
3734+ const VkBufferUsageFlags2CreateInfoKHR* const usageFlags2 =
3735+ VmaPnextChainFind<VkBufferUsageFlags2CreateInfoKHR>(&createInfo, VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR);
3736+ if(usageFlags2 != VMA_NULL)
3737+ {
3738+ this->Value = usageFlags2->usage;
3739+ return;
3740+ }
3741+ }
3742+ #endif
3743+
3744+ this->Value = (BaseType)createInfo.usage;
3745+ }
3746+
3747+ VmaBufferImageUsage::VmaBufferImageUsage(const VkImageCreateInfo &createInfo)
3748+ : Value((BaseType)createInfo.usage)
3749+ {
3750+ // Maybe in the future there will be VK_KHR_maintenanceN extension with structure
3751+ // VkImageUsageFlags2CreateInfoKHR, like the one for buffers...
3752+ }
3753+
3754+ #endif // _VMA_BUFFER_IMAGE_USAGE
36753755
36763756#ifndef _VMA_FUNCTIONS
36773757
@@ -4085,82 +4165,6 @@ inline void VmaPnextChainPushFront(MainT* mainStruct, NewT* newStruct)
40854165 mainStruct->pNext = newStruct;
40864166}
40874167
4088- // Finds structure with s->sType == sType in mainStruct->pNext chain.
4089- // Returns pointer to it. If not found, returns null.
4090- template<typename FindT, typename MainT>
4091- inline const FindT* VmaPnextChainFind(const MainT* mainStruct, VkStructureType sType)
4092- {
4093- for(const VkBaseInStructure* s = (const VkBaseInStructure*)mainStruct->pNext;
4094- s != VMA_NULL; s = s->pNext)
4095- {
4096- if(s->sType == sType)
4097- {
4098- return (const FindT*)s;
4099- }
4100- }
4101- return VMA_NULL;
4102- }
4103-
4104- // An abstraction over buffer or image `usage` flags, depending on available extensions.
4105- struct VmaBufferImageUsage
4106- {
4107- #if VMA_KHR_MAINTENANCE5
4108- typedef uint64_t BaseType; // VkFlags64
4109- #else
4110- typedef uint32_t BaseType; // VkFlags32
4111- #endif
4112-
4113- static const VmaBufferImageUsage UNKNOWN;
4114-
4115- BaseType Value;
4116-
4117- VmaBufferImageUsage() { *this = UNKNOWN; }
4118- explicit VmaBufferImageUsage(BaseType usage) : Value(usage) { }
4119- VmaBufferImageUsage(const VkBufferCreateInfo &createInfo, bool useKhrMaintenance5);
4120- explicit VmaBufferImageUsage(const VkImageCreateInfo &createInfo);
4121-
4122- bool operator==(const VmaBufferImageUsage& rhs) const { return Value == rhs.Value; }
4123- bool operator!=(const VmaBufferImageUsage& rhs) const { return Value != rhs.Value; }
4124-
4125- bool Contains(BaseType flag) const { return (Value & flag) != 0; }
4126- bool ContainsDeviceAccess() const
4127- {
4128- // This relies on values of VK_IMAGE_USAGE_TRANSFER* being the same as VK_BUFFER_IMAGE_TRANSFER*.
4129- return (Value & ~BaseType(VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT)) != 0;
4130- }
4131- };
4132-
4133- const VmaBufferImageUsage VmaBufferImageUsage::UNKNOWN = VmaBufferImageUsage(0);
4134-
4135- VmaBufferImageUsage::VmaBufferImageUsage(const VkBufferCreateInfo &createInfo,
4136- bool useKhrMaintenance5)
4137- {
4138- #if VMA_KHR_MAINTENANCE5
4139- if(useKhrMaintenance5)
4140- {
4141- // If VkBufferCreateInfo::pNext chain contains VkBufferUsageFlags2CreateInfoKHR,
4142- // take usage from it and ignore VkBufferCreateInfo::usage, per specification
4143- // of the VK_KHR_maintenance5 extension.
4144- const VkBufferUsageFlags2CreateInfoKHR* const usageFlags2 =
4145- VmaPnextChainFind<VkBufferUsageFlags2CreateInfoKHR>(&createInfo, VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR);
4146- if(usageFlags2 != VMA_NULL)
4147- {
4148- this->Value = usageFlags2->usage;
4149- return;
4150- }
4151- }
4152- #endif
4153-
4154- this->Value = (BaseType)createInfo.usage;
4155- }
4156-
4157- VmaBufferImageUsage::VmaBufferImageUsage(const VkImageCreateInfo &createInfo)
4158- : Value((BaseType)createInfo.usage)
4159- {
4160- // Maybe in the future there will be VK_KHR_maintenanceN extension with structure
4161- // VkImageUsageFlags2CreateInfoKHR, like the one for buffers...
4162- }
4163-
41644168// This is the main algorithm that guides the selection of a memory type best for an allocation -
41654169// converts usage to required/preferred/not preferred flags.
41664170bool FindMemoryPreferences(
@@ -4610,8 +4614,8 @@ struct VmaStlAllocator
46104614 VmaStlAllocator(const VmaStlAllocator&) = default;
46114615 VmaStlAllocator& operator=(const VmaStlAllocator&) = delete;
46124616
4613- T* allocate(size_t n) { return VmaAllocateArray<T>(m_pCallbacks, n); }
4614- void deallocate(T* p, size_t n) { VmaFree(m_pCallbacks, p); }
4617+ T* allocate(size_t n);
4618+ void deallocate(T* p, size_t n);
46154619
46164620 template<typename U>
46174621 bool operator==(const VmaStlAllocator<U>& rhs) const
@@ -4624,6 +4628,12 @@ struct VmaStlAllocator
46244628 return m_pCallbacks != rhs.m_pCallbacks;
46254629 }
46264630};
4631+
4632+ template<typename T>
4633+ T* VmaStlAllocator<T>::allocate(size_t n) { return VmaAllocateArray<T>(m_pCallbacks, n); }
4634+
4635+ template<typename T>
4636+ void VmaStlAllocator<T>::deallocate(T* p, size_t n) { VmaFree(m_pCallbacks, p); }
46274637#endif // _VMA_STL_ALLOCATOR
46284638
46294639#ifndef _VMA_VECTOR
0 commit comments