From 55723e97f1f4e830a8a0f05ed4dd85108c658a45 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 14 Jul 2015 14:59:39 -0700 Subject: [PATCH] vk: Split the memory requirements/binding functions --- include/vulkan/vulkan.h | 27 +++++++++---- src/vulkan/device.c | 88 +++++++++++++++++++++++------------------ src/vulkan/x11.c | 7 ++-- 3 files changed, 71 insertions(+), 51 deletions(-) diff --git a/include/vulkan/vulkan.h b/include/vulkan/vulkan.h index 2ace82ed3a0..68704a43fb4 100644 --- a/include/vulkan/vulkan.h +++ b/include/vulkan/vulkan.h @@ -2017,8 +2017,10 @@ typedef VkResult (VKAPI *PFN_vkUnmapMemory)(VkDevice device, VkDeviceMemory mem) typedef VkResult (VKAPI *PFN_vkFlushMappedMemoryRanges)(VkDevice device, uint32_t memRangeCount, const VkMappedMemoryRange* pMemRanges); typedef VkResult (VKAPI *PFN_vkInvalidateMappedMemoryRanges)(VkDevice device, uint32_t memRangeCount, const VkMappedMemoryRange* pMemRanges); typedef VkResult (VKAPI *PFN_vkDestroyObject)(VkDevice device, VkObjectType objType, VkObject object); -typedef VkResult (VKAPI *PFN_vkBindObjectMemory)(VkDevice device, VkObjectType objType, VkObject object, VkDeviceMemory mem, VkDeviceSize memOffset); -typedef VkResult (VKAPI *PFN_vkGetObjectMemoryRequirements)(VkDevice device, VkObjectType objType, VkObject object, VkMemoryRequirements* pMemoryRequirements); +typedef VkResult (VKAPI *PFN_vkBindBufferMemory)(VkDevice device, VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memOffset); +typedef VkResult (VKAPI *PFN_vkBindImageMemory)(VkDevice device, VkImage image, VkDeviceMemory mem, VkDeviceSize memOffset); +typedef VkResult (VKAPI *PFN_vkGetBufferMemoryRequirements)(VkDevice device, VkBuffer buffer, VkMemoryRequirements* pMemoryRequirements); +typedef VkResult (VKAPI *PFN_vkGetImageMemoryRequirements)(VkDevice device, VkImage image, VkMemoryRequirements* pMemoryRequirements); typedef VkResult (VKAPI *PFN_vkQueueBindSparseBufferMemory)(VkQueue queue, VkBuffer buffer, VkDeviceSize rangeOffset, VkDeviceSize rangeSize, VkDeviceMemory mem, VkDeviceSize memOffset); typedef VkResult (VKAPI *PFN_vkQueueBindSparseImageMemory)(VkQueue queue, VkImage image, const VkImageMemoryBindInfo* pBindInfo, VkDeviceMemory mem, VkDeviceSize memOffset); typedef VkResult (VKAPI *PFN_vkCreateFence)(VkDevice device, const VkFenceCreateInfo* pCreateInfo, VkFence* pFence); @@ -2267,17 +2269,26 @@ VkResult VKAPI vkDestroyObject( VkObjectType objType, VkObject object); -VkResult VKAPI vkBindObjectMemory( +VkResult VKAPI vkBindBufferMemory( VkDevice device, - VkObjectType objType, - VkObject object, + VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memOffset); -VkResult VKAPI vkGetObjectMemoryRequirements( +VkResult VKAPI vkBindImageMemory( VkDevice device, - VkObjectType objType, - VkObject object, + VkImage image, + VkDeviceMemory mem, + VkDeviceSize memOffset); + +VkResult VKAPI vkGetBufferMemoryRequirements( + VkDevice device, + VkBuffer buffer, + VkMemoryRequirements* pMemoryRequirements); + +VkResult VKAPI vkGetImageMemoryRequirements( + VkDevice device, + VkImage image, VkMemoryRequirements* pMemoryRequirements); VkResult VKAPI vkQueueBindSparseBufferMemory( diff --git a/src/vulkan/device.c b/src/vulkan/device.c index 2aa9aee9e50..d566bb0b092 100644 --- a/src/vulkan/device.c +++ b/src/vulkan/device.c @@ -1282,12 +1282,12 @@ VkResult anv_DestroyObject( } } -VkResult anv_GetObjectMemoryRequirements( +VkResult anv_GetBufferMemoryRequirements( VkDevice device, - VkObjectType objType, - VkObject object, + VkBuffer _buffer, VkMemoryRequirements* pMemoryRequirements) { + ANV_FROM_HANDLE(anv_buffer, buffer, _buffer); /* The Vulkan spec (git aaed022) says: * @@ -1300,52 +1300,62 @@ VkResult anv_GetObjectMemoryRequirements( */ pMemoryRequirements->memoryTypeBits = 1; - switch (objType) { - case VK_OBJECT_TYPE_BUFFER: { - struct anv_buffer *buffer = anv_buffer_from_handle(object); - pMemoryRequirements->size = buffer->size; - pMemoryRequirements->alignment = 16; - break; - } - case VK_OBJECT_TYPE_IMAGE: { - struct anv_image *image = anv_image_from_handle(object); - pMemoryRequirements->size = image->size; - pMemoryRequirements->alignment = image->alignment; - break; - } - default: - pMemoryRequirements->size = 0; - break; - } + pMemoryRequirements->size = buffer->size; + pMemoryRequirements->alignment = 16; return VK_SUCCESS; } -VkResult anv_BindObjectMemory( +VkResult anv_GetImageMemoryRequirements( VkDevice device, - VkObjectType objType, - VkObject object, + VkImage _image, + VkMemoryRequirements* pMemoryRequirements) +{ + ANV_FROM_HANDLE(anv_image, image, _image); + + /* The Vulkan spec (git aaed022) says: + * + * memoryTypeBits is a bitfield and contains one bit set for every + * supported memory type for the resource. The bit `1<memoryTypeBits = 1; + + pMemoryRequirements->size = image->size; + pMemoryRequirements->alignment = image->alignment; + + return VK_SUCCESS; +} + +VkResult anv_BindBufferMemory( + VkDevice device, + VkBuffer _buffer, VkDeviceMemory _mem, VkDeviceSize memOffset) { ANV_FROM_HANDLE(anv_device_memory, mem, _mem); - struct anv_buffer *buffer; - struct anv_image *image; + ANV_FROM_HANDLE(anv_buffer, buffer, _buffer); - switch (objType) { - case VK_OBJECT_TYPE_BUFFER: - buffer = anv_buffer_from_handle(object); - buffer->bo = &mem->bo; - buffer->offset = memOffset; - break; - case VK_OBJECT_TYPE_IMAGE: - image = anv_image_from_handle(object); - image->bo = &mem->bo; - image->offset = memOffset; - break; - default: - break; - } + buffer->bo = &mem->bo; + buffer->offset = memOffset; + + return VK_SUCCESS; +} + +VkResult anv_BindImageMemory( + VkDevice device, + VkImage _image, + VkDeviceMemory _mem, + VkDeviceSize memOffset) +{ + ANV_FROM_HANDLE(anv_device_memory, mem, _mem); + ANV_FROM_HANDLE(anv_image, image, _image); + + image->bo = &mem->bo; + image->offset = memOffset; return VK_SUCCESS; } diff --git a/src/vulkan/x11.c b/src/vulkan/x11.c index 7b6cee011a4..d1eaab3bf46 100644 --- a/src/vulkan/x11.c +++ b/src/vulkan/x11.c @@ -148,10 +148,9 @@ VkResult anv_CreateSwapChainWSI( }, (VkDeviceMemory *) &memory); - anv_BindObjectMemory(VK_NULL_HANDLE, - VK_OBJECT_TYPE_IMAGE, - (VkImage) image, - (VkDeviceMemory) memory, 0); + anv_BindImageMemory(VK_NULL_HANDLE, + anv_image_to_handle(image), + anv_device_memory_to_handle(memory), 0); ret = anv_gem_set_tiling(device, memory->bo.gem_handle, surface->stride, I915_TILING_X); -- 2.30.2