From 9586b509903c34e16573a26ad6db179bc8a41f06 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 (cherry picked from commit 5c53c6e693c1067065d2fe12bfe94066af93f2fe) Part-of: --- .pick_status.json | 2 +- 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 ++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 983f7f99c13..4e0ba027fa0 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -64,7 +64,7 @@ "description": "vulkan/runtime: track dynamic descriptor offsets for RT pipelines", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "69a04151db48e4d06072dab38e33129b6681230a", "notes": null diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index 0aa70819fb2..12b0711a888 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 572041c428b..16f26065ca1 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -6113,7 +6113,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 6eecd1e3923..2d58ae83750 100644 --- a/src/vulkan/runtime/vk_pipeline.c +++ b/src/vulkan/runtime/vk_pipeline.c @@ -2352,6 +2352,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 @@ -2409,7 +2411,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); @@ -2900,6 +2903,17 @@ vk_create_rt_pipeline(struct vk_device *device, goto fail_stages; } + 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 a2caea1c667..38d82eed52f 100644 --- a/src/vulkan/runtime/vk_shader.h +++ b/src/vulkan/runtime/vk_shader.h @@ -331,7 +331,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,