From 5c53c6e693c1067065d2fe12bfe94066af93f2fe Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Wed, 26 Nov 2025 15:12:42 +0200 Subject: [PATCH] vulkan/runtime: track dynamic descriptor offsets for RT pipelines Dynamic descriptors are mapped an array of offsets provided through vkCmdBindDescriptorSets*() commands. When pipelines are compiled with independent sets layouts, the implementation might have to do additional runtime calculation to figure out what offset in the contiguous array maps to what dynamic descriptor in the pipeline layout. For graphics pipelines you can always compute that information when binding the shaders. There is always a limited amount of shaders (5 max). For ray tracing pipelines, there could be lots of shaders to process at every pipeline binding call. Besides there is no interface from the runtime to the driver to list all the shaders used at the moment. So do that tracking in the runtime and pass the information down to the driver through the cmd_set_rt_state() vfunc. Signed-off-by: Lionel Landwerlin Fixes: 69a04151db ("vulkan/runtime: add ray tracing pipeline support") Acked-by: Alyssa Rosenzweig Part-of: --- src/intel/vulkan/anv_cmd_buffer.c | 3 ++- src/intel/vulkan/anv_private.h | 3 ++- src/vulkan/runtime/vk_pipeline.c | 16 +++++++++++++++- src/vulkan/runtime/vk_shader.h | 3 ++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index 2115d3e3026..0c53d252d04 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -1247,7 +1247,8 @@ void anv_CmdPushDescriptorSetWithTemplate2KHR( void anv_cmd_buffer_set_rt_state(struct vk_command_buffer *vk_cmd_buffer, VkDeviceSize scratch_size, - uint32_t ray_queries) + uint32_t ray_queries, + const uint8_t *dynamic_descriptor_offsets) { struct anv_cmd_buffer *cmd_buffer = container_of(vk_cmd_buffer, struct anv_cmd_buffer, vk); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 533049220ca..71a0d5f2310 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -6125,7 +6125,8 @@ anv_cmd_buffer_ensure_rcs_companion(struct anv_cmd_buffer *cmd_buffer); void anv_cmd_buffer_set_rt_state(struct vk_command_buffer *vk_cmd_buffer, VkDeviceSize scratch_size, - uint32_t ray_queries); + uint32_t ray_queries, + const uint8_t *dynamic_descriptor_offsets); void anv_cmd_buffer_set_stack_size(struct vk_command_buffer *vk_cmd_buffer, diff --git a/src/vulkan/runtime/vk_pipeline.c b/src/vulkan/runtime/vk_pipeline.c index 645dd6cce27..ab260b94492 100644 --- a/src/vulkan/runtime/vk_pipeline.c +++ b/src/vulkan/runtime/vk_pipeline.c @@ -2679,6 +2679,8 @@ struct vk_rt_pipeline { VkDeviceSize stack_size; VkDeviceSize scratch_size; uint32_t ray_queries; + + uint8_t dynamic_descriptor_offsets[MESA_VK_MAX_DESCRIPTOR_SETS]; }; static struct vk_rt_stage @@ -2736,7 +2738,8 @@ vk_rt_pipeline_cmd_bind(struct vk_command_buffer *cmd_buffer, ops->cmd_set_rt_state(cmd_buffer, rt_pipeline->scratch_size, - rt_pipeline->ray_queries); + rt_pipeline->ray_queries, + rt_pipeline->dynamic_descriptor_offsets); if (rt_pipeline->stack_size > 0) ops->cmd_set_stack_size(cmd_buffer, rt_pipeline->stack_size); @@ -3490,6 +3493,17 @@ vk_create_rt_pipeline(struct vk_device *device, goto fail_pipeline; } + if (pipeline_layout != NULL) { + uint32_t dynamic_desc_offset = 0; + for (uint32_t i = 0; i < pipeline_layout->set_count; i++) { + if (pipeline_layout->set_layouts[i] != NULL) { + pipeline->dynamic_descriptor_offsets[i] = dynamic_desc_offset; + dynamic_desc_offset += + pipeline_layout->set_layouts[i]->dynamic_descriptor_count; + } + } + } + pipeline->stages = pipeline_stages; pipeline->groups = pipeline_groups; diff --git a/src/vulkan/runtime/vk_shader.h b/src/vulkan/runtime/vk_shader.h index 12040c38c5f..145473b18d4 100644 --- a/src/vulkan/runtime/vk_shader.h +++ b/src/vulkan/runtime/vk_shader.h @@ -329,7 +329,8 @@ struct vk_device_shader_ops { /** Sets scratch size & ray query count for RT pipelines */ void (*cmd_set_rt_state)(struct vk_command_buffer *cmd_buffer, VkDeviceSize scratch_size, - uint32_t ray_queries); + uint32_t ray_queries, + const uint8_t *dynamic_descriptor_offsets); /** Sets stack size for RT pipelines */ void (*cmd_set_stack_size)(struct vk_command_buffer *cmd_buffer,