From: Samuel Pitoiset Date: Tue, 17 Aug 2021 15:44:32 +0000 (+0200) Subject: vulkan: add common entrypoints for sparse image requirements/properties X-Git-Tag: upstream/22.3.5~18415 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f695171e383efb6774cbe475c8f4e68e66fe2906;p=platform%2Fupstream%2Fmesa.git vulkan: add common entrypoints for sparse image requirements/properties Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Part-of: --- diff --git a/src/vulkan/util/vk_cmd_copy.c b/src/vulkan/util/vk_cmd_copy.c index 5c71dbb..9fcb0c2 100644 --- a/src/vulkan/util/vk_cmd_copy.c +++ b/src/vulkan/util/vk_cmd_copy.c @@ -23,15 +23,7 @@ #include "vk_common_entrypoints.h" #include "vk_device.h" - -#define STACK_ARRAY_SIZE 8 - -#define STACK_ARRAY(type, name, size) \ - type _stack_##name[STACK_ARRAY_SIZE], *const name = \ - (size) <= STACK_ARRAY_SIZE ? _stack_##name : malloc((size) * sizeof(type)) - -#define STACK_ARRAY_FINISH(name) \ - if (name != _stack_##name) free(name) +#include "vk_util.h" VKAPI_ATTR void VKAPI_CALL vk_common_CmdCopyBuffer(VkCommandBuffer commandBuffer, diff --git a/src/vulkan/util/vk_device.c b/src/vulkan/util/vk_device.c index cfaebc5..42f571c 100644 --- a/src/vulkan/util/vk_device.c +++ b/src/vulkan/util/vk_device.c @@ -26,6 +26,7 @@ #include "vk_common_entrypoints.h" #include "vk_instance.h" #include "vk_physical_device.h" +#include "vk_util.h" #include "util/hash_table.h" #include "util/ralloc.h" @@ -219,3 +220,42 @@ vk_common_BindImageMemory(VkDevice _device, return device->dispatch_table.BindImageMemory2(_device, 1, &bind); } + +VKAPI_ATTR void VKAPI_CALL +vk_common_GetImageSparseMemoryRequirements(VkDevice _device, + VkImage image, + uint32_t *pSparseMemoryRequirementCount, + VkSparseImageMemoryRequirements *pSparseMemoryRequirements) +{ + VK_FROM_HANDLE(vk_device, device, _device); + + VkImageSparseMemoryRequirementsInfo2 info = { + .sType = VK_STRUCTURE_TYPE_IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2, + .image = image, + }; + + if (!pSparseMemoryRequirements) { + device->dispatch_table.GetImageSparseMemoryRequirements2(_device, + &info, + pSparseMemoryRequirementCount, + NULL); + return; + } + + STACK_ARRAY(VkSparseImageMemoryRequirements2, mem_reqs2, *pSparseMemoryRequirementCount); + + for (unsigned i = 0; i < *pSparseMemoryRequirementCount; ++i) { + mem_reqs2[i].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2; + mem_reqs2[i].pNext = NULL; + } + + device->dispatch_table.GetImageSparseMemoryRequirements2(_device, + &info, + pSparseMemoryRequirementCount, + mem_reqs2); + + for (unsigned i = 0; i < *pSparseMemoryRequirementCount; ++i) + pSparseMemoryRequirements[i] = mem_reqs2[i].memoryRequirements; + + STACK_ARRAY_FINISH(mem_reqs2); +} diff --git a/src/vulkan/util/vk_physical_device.c b/src/vulkan/util/vk_physical_device.c index 868d2d1..e6504c8 100644 --- a/src/vulkan/util/vk_physical_device.c +++ b/src/vulkan/util/vk_physical_device.c @@ -205,3 +205,50 @@ vk_common_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice return result; } + +VKAPI_ATTR void VKAPI_CALL +vk_common_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, + VkFormat format, + VkImageType type, + uint32_t samples, + VkImageUsageFlags usage, + VkImageTiling tiling, + uint32_t *pNumProperties, + VkSparseImageFormatProperties *pProperties) +{ + VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); + + VkPhysicalDeviceSparseImageFormatInfo2 info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2, + .format = format, + .type = type, + .samples = samples, + .usage = usage, + .tiling = tiling + }; + + if (!pProperties) { + pdevice->dispatch_table.GetPhysicalDeviceSparseImageFormatProperties2(physicalDevice, + &info, + pNumProperties, + NULL); + return; + } + + STACK_ARRAY(VkSparseImageFormatProperties2, props2, *pNumProperties); + + for (unsigned i = 0; i < *pNumProperties; ++i) { + props2[i].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2; + props2[i].pNext = NULL; + } + + pdevice->dispatch_table.GetPhysicalDeviceSparseImageFormatProperties2(physicalDevice, + &info, + pNumProperties, + props2); + + for (unsigned i = 0; i < *pNumProperties; ++i) + pProperties[i] = props2[i].properties; + + STACK_ARRAY_FINISH(props2); +} diff --git a/src/vulkan/util/vk_util.h b/src/vulkan/util/vk_util.h index 5dbce23..0e98b71 100644 --- a/src/vulkan/util/vk_util.h +++ b/src/vulkan/util/vk_util.h @@ -278,6 +278,15 @@ struct nir_spirv_specialization* vk_spec_info_to_nir_spirv(const VkSpecializationInfo *spec_info, uint32_t *out_num_spec_entries); +#define STACK_ARRAY_SIZE 8 + +#define STACK_ARRAY(type, name, size) \ + type _stack_##name[STACK_ARRAY_SIZE], *const name = \ + (size) <= STACK_ARRAY_SIZE ? _stack_##name : malloc((size) * sizeof(type)) + +#define STACK_ARRAY_FINISH(name) \ + if (name != _stack_##name) free(name) + #ifdef __cplusplus } #endif