From 1dfb6e19d56f502c7b0c7353da4b456565436364 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Tue, 13 Aug 2024 10:23:09 +0200 Subject: [PATCH] radv/meta: create itoi layouts on-demand Signed-off-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/meta/radv_meta_bufimage.c | 152 ++++++++++++++--------- 1 file changed, 90 insertions(+), 62 deletions(-) diff --git a/src/amd/vulkan/meta/radv_meta_bufimage.c b/src/amd/vulkan/meta/radv_meta_bufimage.c index d502a8d9bc3..b2507431a3c 100644 --- a/src/amd/vulkan/meta/radv_meta_bufimage.c +++ b/src/amd/vulkan/meta/radv_meta_bufimage.c @@ -511,13 +511,57 @@ build_nir_itoi_compute_shader(struct radv_device *dev, bool src_3d, bool dst_3d, return b.shader; } +static VkResult +create_itoi_layout(struct radv_device *device) +{ + VkResult result = VK_SUCCESS; + + if (!device->meta_state.itoi.img_ds_layout) { + const VkDescriptorSetLayoutBinding bindings[] = { + { + .binding = 0, + .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, + .descriptorCount = 1, + .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, + }, + { + .binding = 1, + .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + .descriptorCount = 1, + .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, + }, + }; + + result = radv_meta_create_descriptor_set_layout(device, 2, bindings, &device->meta_state.itoi.img_ds_layout); + if (result != VK_SUCCESS) + return result; + } + + if (!device->meta_state.itoi.img_p_layout) { + const VkPushConstantRange pc_range = { + .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, + .size = 24, + }; + + result = radv_meta_create_pipeline_layout(device, &device->meta_state.itoi.img_ds_layout, 1, &pc_range, + &device->meta_state.itoi.img_p_layout); + } + + return result; +} + static VkResult create_itoi_pipeline(struct radv_device *device, bool src_3d, bool dst_3d, int samples, VkPipeline *pipeline) { struct radv_meta_state *state = &device->meta_state; - nir_shader *cs = build_nir_itoi_compute_shader(device, src_3d, dst_3d, samples); VkResult result; + result = create_itoi_layout(device); + if (result != VK_SUCCESS) + return result; + + nir_shader *cs = build_nir_itoi_compute_shader(device, src_3d, dst_3d, samples); + result = radv_meta_create_compute_pipeline(device, cs, state->itoi.img_p_layout, pipeline); ralloc_free(cs); return result; @@ -564,35 +608,6 @@ radv_device_init_meta_itoi_state(struct radv_device *device, bool on_demand) { VkResult result; - const VkDescriptorSetLayoutBinding bindings[] = { - { - .binding = 0, - .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - .descriptorCount = 1, - .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, - }, - { - .binding = 1, - .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, - .descriptorCount = 1, - .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, - }, - }; - - result = radv_meta_create_descriptor_set_layout(device, 2, bindings, &device->meta_state.itoi.img_ds_layout); - if (result != VK_SUCCESS) - return result; - - const VkPushConstantRange pc_range = { - .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, - .size = 24, - }; - - result = radv_meta_create_pipeline_layout(device, &device->meta_state.itoi.img_ds_layout, 1, &pc_range, - &device->meta_state.itoi.img_p_layout); - if (result != VK_SUCCESS) - return result; - if (on_demand) return VK_SUCCESS; @@ -693,10 +708,55 @@ build_nir_itoi_r32g32b32_compute_shader(struct radv_device *dev) } /* Image to image - special path for R32G32B32 */ +static VkResult +create_itoi_r32g32b32_layout(struct radv_device *device) +{ + VkResult result = VK_SUCCESS; + + if (!device->meta_state.itoi_r32g32b32.img_ds_layout) { + const VkDescriptorSetLayoutBinding bindings[] = { + { + .binding = 0, + .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, + .descriptorCount = 1, + .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, + }, + { + .binding = 1, + .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, + .descriptorCount = 1, + .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, + }, + }; + + result = + radv_meta_create_descriptor_set_layout(device, 2, bindings, &device->meta_state.itoi_r32g32b32.img_ds_layout); + if (result != VK_SUCCESS) + return result; + } + + if (!device->meta_state.itoi_r32g32b32.img_p_layout) { + const VkPushConstantRange pc_range = { + .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, + .size = 24, + }; + + result = radv_meta_create_pipeline_layout(device, &device->meta_state.itoi_r32g32b32.img_ds_layout, 1, &pc_range, + &device->meta_state.itoi_r32g32b32.img_p_layout); + } + + return result; +} + static VkResult create_itoi_r32g32b32_pipeline(struct radv_device *device, VkPipeline *pipeline) { VkResult result; + + result = create_itoi_r32g32b32_layout(device); + if (result != VK_SUCCESS) + return result; + nir_shader *cs = build_nir_itoi_r32g32b32_compute_shader(device); result = radv_meta_create_compute_pipeline(device, cs, device->meta_state.itoi_r32g32b32.img_p_layout, pipeline); @@ -728,38 +788,6 @@ fail: static VkResult radv_device_init_meta_itoi_r32g32b32_state(struct radv_device *device, bool on_demand) { - VkResult result; - - const VkDescriptorSetLayoutBinding bindings[] = { - { - .binding = 0, - .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, - .descriptorCount = 1, - .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, - }, - { - .binding = 1, - .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, - .descriptorCount = 1, - .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, - }, - }; - - result = - radv_meta_create_descriptor_set_layout(device, 2, bindings, &device->meta_state.itoi_r32g32b32.img_ds_layout); - if (result != VK_SUCCESS) - return result; - - const VkPushConstantRange pc_range = { - .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, - .size = 24, - }; - - result = radv_meta_create_pipeline_layout(device, &device->meta_state.itoi_r32g32b32.img_ds_layout, 1, &pc_range, - &device->meta_state.itoi_r32g32b32.img_p_layout); - if (result != VK_SUCCESS) - return result; - if (on_demand) return VK_SUCCESS;