radv: Add ycbcr conversion structs.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 2 Dec 2018 22:58:58 +0000 (23:58 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Thu, 25 Apr 2019 19:56:20 +0000 (19:56 +0000)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/vulkan/radv_descriptor_set.c
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_private.h

index 6c6b88a45532aadb6472854dad544a806d8df45e..7374f94d260d73348ee91aafcf5a6bc7e2572018 100644 (file)
@@ -1216,19 +1216,40 @@ void radv_UpdateDescriptorSetWithTemplate(VkDevice _device,
 }
 
 
-VkResult radv_CreateSamplerYcbcrConversion(VkDevice device,
+VkResult radv_CreateSamplerYcbcrConversion(VkDevice _device,
                                           const VkSamplerYcbcrConversionCreateInfo* pCreateInfo,
                                           const VkAllocationCallbacks* pAllocator,
                                           VkSamplerYcbcrConversion* pYcbcrConversion)
 {
-       *pYcbcrConversion = VK_NULL_HANDLE;
+       RADV_FROM_HANDLE(radv_device, device, _device);
+       struct radv_sampler_ycbcr_conversion *conversion = NULL;
+
+       conversion = vk_zalloc2(&device->alloc, pAllocator, sizeof(*conversion), 8,
+                               VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+
+       if (conversion == NULL)
+               return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
+
+       conversion->format = pCreateInfo->format;
+       conversion->ycbcr_model = pCreateInfo->ycbcrModel;
+       conversion->ycbcr_range = pCreateInfo->ycbcrRange;
+       conversion->components = pCreateInfo->components;
+       conversion->chroma_offsets[0] = pCreateInfo->xChromaOffset;
+       conversion->chroma_offsets[1] = pCreateInfo->yChromaOffset;
+       conversion->chroma_filter = pCreateInfo->chromaFilter;
+
+       *pYcbcrConversion = radv_sampler_ycbcr_conversion_to_handle(conversion);
        return VK_SUCCESS;
 }
 
 
-void radv_DestroySamplerYcbcrConversion(VkDevice device,
+void radv_DestroySamplerYcbcrConversion(VkDevice _device,
                                        VkSamplerYcbcrConversion ycbcrConversion,
                                        const VkAllocationCallbacks* pAllocator)
 {
-       /* Do nothing. */
+       RADV_FROM_HANDLE(radv_device, device, _device);
+       RADV_FROM_HANDLE(radv_sampler_ycbcr_conversion, ycbcr_conversion, ycbcrConversion);
+
+       if (ycbcr_conversion)
+               vk_free2(&device->alloc, pAllocator, ycbcr_conversion);
 }
index 7a6735e68a4850c9f3d1538e967219748778a313..2f20c4f46b2fe5708056f04f1190820d01dfbd60 100644 (file)
@@ -4837,6 +4837,10 @@ VkResult radv_CreateSampler(
        RADV_FROM_HANDLE(radv_device, device, _device);
        struct radv_sampler *sampler;
 
+       const struct VkSamplerYcbcrConversionInfo *ycbcr_conversion =
+               vk_find_struct_const(pCreateInfo->pNext,
+                                    SAMPLER_YCBCR_CONVERSION_INFO);
+
        assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
 
        sampler = vk_alloc2(&device->alloc, pAllocator, sizeof(*sampler), 8,
@@ -4845,6 +4849,8 @@ VkResult radv_CreateSampler(
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
        radv_init_sampler(device, sampler, pCreateInfo);
+
+       sampler->ycbcr_sampler = ycbcr_conversion ? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion->conversion): NULL;
        *pSampler = radv_sampler_to_handle(sampler);
 
        return VK_SUCCESS;
index 852dfd259c601db952ab7e8cbd9755ffb0b641c8..4bccb88aa17bf1f08d5be3d693061d9a8bc08006 100644 (file)
@@ -1716,6 +1716,15 @@ void radv_image_view_init(struct radv_image_view *view,
 
 VkFormat radv_get_aspect_format(struct radv_image *image, VkImageAspectFlags mask);
 
+struct radv_sampler_ycbcr_conversion {
+       VkFormat format;
+       VkSamplerYcbcrModelConversion ycbcr_model;
+       VkSamplerYcbcrRange ycbcr_range;
+       VkComponentMapping components;
+       VkChromaLocation chroma_offsets[2];
+       VkFilter chroma_filter;
+};
+
 struct radv_buffer_view {
        struct radeon_winsys_bo *bo;
        VkFormat vk_format;
@@ -1771,6 +1780,7 @@ radv_image_extent_compare(const struct radv_image *image,
 
 struct radv_sampler {
        uint32_t state[4];
+       struct radv_sampler_ycbcr_conversion *ycbcr_sampler;
 };
 
 struct radv_color_buffer_info {
@@ -2041,6 +2051,7 @@ RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, VkPipelineLayout)
 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, VkQueryPool)
 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, VkRenderPass)
 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, VkSampler)
+RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler_ycbcr_conversion, VkSamplerYcbcrConversion)
 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_shader_module, VkShaderModule)
 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_semaphore, VkSemaphore)