Definitions for VK_KHR_dedicated_allocation
authorBoris Zanin <boris.zanin@mobica.com>
Thu, 18 May 2017 06:45:39 +0000 (08:45 +0200)
committerAlexander Galazin <alexander.galazin@arm.com>
Fri, 23 Jun 2017 21:16:29 +0000 (23:16 +0200)
Add definitions for VK_KHR_dedicated_allocation.

Components: Vulkan

VK-GL-CTS issue: 153

Change-Id: I062e3eb03edfd4d785d5d93775915541bcd4aa02

external/vulkancts/framework/vulkan/vkMemUtil.cpp
external/vulkancts/framework/vulkan/vkMemUtil.hpp
external/vulkancts/scripts/src/vulkan.h.in

index cf5c9ae..f091a51 100644 (file)
@@ -201,6 +201,73 @@ MovePtr<Allocation> SimpleAllocator::allocate (const VkMemoryRequirements& memRe
        return MovePtr<Allocation>(new SimpleAllocation(mem, hostPtr));
 }
 
        return MovePtr<Allocation>(new SimpleAllocation(mem, hostPtr));
 }
 
+static MovePtr<Allocation> allocateDedicated (const InstanceInterface&         vki,
+                                                                                         const DeviceInterface&                vkd,
+                                                                                         const VkPhysicalDevice&               physDevice,
+                                                                                         const VkDevice                                device,
+                                                                                         const VkMemoryRequirements&   memReqs,
+                                                                                         const MemoryRequirement               requirement,
+                                                                                         const void*                                   pNext)
+{
+       const VkPhysicalDeviceMemoryProperties  memoryProperties        = getPhysicalDeviceMemoryProperties(vki, physDevice);
+       const deUint32                                                  memoryTypeNdx           = selectMatchingMemoryType(memoryProperties, memReqs.memoryTypeBits, requirement);
+       const VkMemoryAllocateInfo                              allocInfo                       =
+       {
+               VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, //      VkStructureType sType
+               pNext,                                                                  //      const void*             pNext
+               memReqs.size,                                                   //      VkDeviceSize    allocationSize
+               memoryTypeNdx,                                                  //      deUint32                memoryTypeIndex
+       };
+       Move<VkDeviceMemory>                                    mem                                     = allocateMemory(vkd, device, &allocInfo);
+       MovePtr<HostPtr>                                                hostPtr;
+
+       if (requirement & MemoryRequirement::HostVisible)
+       {
+               DE_ASSERT(isHostVisibleMemory(memoryProperties, allocInfo.memoryTypeIndex));
+               hostPtr = MovePtr<HostPtr>(new HostPtr(vkd, device, *mem, 0u, allocInfo.allocationSize, 0u));
+       }
+
+       return MovePtr<Allocation>(new SimpleAllocation(mem, hostPtr));
+}
+
+de::MovePtr<Allocation> allocateDedicated (const InstanceInterface&    vki,
+                                                                                  const DeviceInterface&       vkd,
+                                                                                  const VkPhysicalDevice&      physDevice,
+                                                                                  const VkDevice                       device,
+                                                                                  const VkBuffer                       buffer,
+                                                                                  MemoryRequirement            requirement)
+{
+       const VkMemoryRequirements                                      memoryRequirements              = getBufferMemoryRequirements(vkd, device, buffer);
+       const VkMemoryDedicatedAllocateInfoKHR          dedicatedAllocationInfo =
+       {
+               VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR,                           // VkStructureType              sType
+               DE_NULL,                                                                                                                        // const void*                  pNext
+               DE_NULL,                                                                                                                        // VkImage                              image
+               buffer                                                                                                                          // VkBuffer                             buffer
+       };
+
+       return allocateDedicated(vki, vkd, physDevice, device, memoryRequirements, requirement, &dedicatedAllocationInfo);
+}
+
+de::MovePtr<Allocation> allocateDedicated (const InstanceInterface&    vki,
+                                                                                  const DeviceInterface&       vkd,
+                                                                                  const VkPhysicalDevice&      physDevice,
+                                                                                  const VkDevice                       device,
+                                                                                  const VkImage                        image,
+                                                                                  MemoryRequirement            requirement)
+{
+       const VkMemoryRequirements                              memoryRequirements              = getImageMemoryRequirements(vkd, device, image);
+       const VkMemoryDedicatedAllocateInfoKHR  dedicatedAllocationInfo =
+       {
+               VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR,                   // VkStructureType              sType
+               DE_NULL,                                                                                                                // const void*                  pNext
+               image,                                                                                                                  // VkImage                              image
+               DE_NULL                                                                                                                 // VkBuffer                             buffer
+       };
+
+       return allocateDedicated(vki, vkd, physDevice, device, memoryRequirements, requirement, &dedicatedAllocationInfo);
+}
+
 void* mapMemory (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags)
 {
        void* hostPtr = DE_NULL;
 void* mapMemory (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags)
 {
        void* hostPtr = DE_NULL;
index 3c1a55e..54345dd 100644 (file)
@@ -133,11 +133,13 @@ private:
        const VkPhysicalDeviceMemoryProperties  m_memProps;
 };
 
        const VkPhysicalDeviceMemoryProperties  m_memProps;
 };
 
-void*          mapMemory                                       (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags);
-void           flushMappedMemoryRange          (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size);
-void           invalidateMappedMemoryRange     (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size);
+de::MovePtr<Allocation>        allocateDedicated                       (const InstanceInterface& vki, const DeviceInterface& vkd, const VkPhysicalDevice& physDevice, const VkDevice device, const VkBuffer buffer, MemoryRequirement requirement);
+de::MovePtr<Allocation>        allocateDedicated                       (const InstanceInterface& vki, const DeviceInterface& vkd, const VkPhysicalDevice& physDevice, const VkDevice device, const VkImage image, MemoryRequirement requirement);
 
 
-deUint32       getCompatibleMemoryTypes        (const VkPhysicalDeviceMemoryProperties& deviceMemProps, MemoryRequirement requirement);
+void*                                  mapMemory                                       (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags);
+void                                   flushMappedMemoryRange          (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size);
+void                                   invalidateMappedMemoryRange     (const DeviceInterface& vkd, VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size);
+deUint32                               getCompatibleMemoryTypes        (const VkPhysicalDeviceMemoryProperties& deviceMemProps, MemoryRequirement requirement);
 
 } // vk
 
 
 } // vk
 
index e4369f0..71125aa 100644 (file)
@@ -4337,6 +4337,7 @@ typedef struct VkMemoryDedicatedAllocateInfoKHR {
     VkBuffer           buffer;
 } VkMemoryDedicatedAllocateInfoKHR;
 
     VkBuffer           buffer;
 } VkMemoryDedicatedAllocateInfoKHR;
 
+
 #define VK_KHR_get_memory_requirements2 1
 #define VK_KHR_GET_MEMORY_REQUIREMENTS_2_SPEC_VERSION 1
 #define VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME "VK_KHR_get_memory_requirements2"
 #define VK_KHR_get_memory_requirements2 1
 #define VK_KHR_GET_MEMORY_REQUIREMENTS_2_SPEC_VERSION 1
 #define VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME "VK_KHR_get_memory_requirements2"
@@ -4394,6 +4395,8 @@ VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements2KHR(
     VkSparseImageMemoryRequirements2KHR*        pSparseMemoryRequirements);
 #endif
 
     VkSparseImageMemoryRequirements2KHR*        pSparseMemoryRequirements);
 #endif
 
+
+
 #define VK_EXT_debug_report 1
 VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugReportCallbackEXT)
 
 #define VK_EXT_debug_report 1
 VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugReportCallbackEXT)