From 7b634ebb63c52dad88f13294a8415f8c7b81938a Mon Sep 17 00:00:00 2001 From: Sagar Ghuge Date: Mon, 21 Jul 2025 22:27:19 -0700 Subject: [PATCH] vulkan/runtime: Add VK_SHADER_CREATE_UNALIGNED_DISPATCH_BIT_MESA flag Drivers that doesn't support direct unaligned dispatches, they can use the shader creation flag to lower unaligned dispatches. Suggested-by: Alyssa Rosenzweig Signed-off-by: Sagar Ghuge Reviewed-by: Alyssa Rosenzweig Reviewed-by: Konstantin Seurer Part-of: --- src/amd/vulkan/radv_acceleration_structure.c | 2 +- .../vulkan/genX_acceleration_structure.c | 2 +- .../runtime/vk_acceleration_structure.c | 24 +++++++++++++------ .../runtime/vk_acceleration_structure.h | 3 ++- src/vulkan/runtime/vk_shader.h | 1 + 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/amd/vulkan/radv_acceleration_structure.c b/src/amd/vulkan/radv_acceleration_structure.c index 1b129bfab47..7c178670876 100644 --- a/src/amd/vulkan/radv_acceleration_structure.c +++ b/src/amd/vulkan/radv_acceleration_structure.c @@ -297,7 +297,7 @@ radv_bvh_build_bind_pipeline(VkCommandBuffer commandBuffer, enum radv_meta_objec VkPipeline pipeline; VkResult result = vk_get_bvh_build_pipeline_spv( &device->vk, &device->meta_state.device, (enum vk_meta_object_key_type)type, spirv, spirv_size, - push_constants_size, &device->meta_state.accel_struct_build.build_args, flags, &pipeline); + push_constants_size, &device->meta_state.accel_struct_build.build_args, flags, &pipeline, false); if (result != VK_SUCCESS) { vk_command_buffer_set_error(&cmd_buffer->vk, result); diff --git a/src/intel/vulkan/genX_acceleration_structure.c b/src/intel/vulkan/genX_acceleration_structure.c index d9ebb2f3cdb..255c20e36b3 100644 --- a/src/intel/vulkan/genX_acceleration_structure.c +++ b/src/intel/vulkan/genX_acceleration_structure.c @@ -317,7 +317,7 @@ anv_bvh_build_bind_pipeline(VkCommandBuffer commandBuffer, (enum anv_object_key_bvh_type)type, spirv, spirv_size, push_constant_size, &device->accel_struct_build.build_args, - flags, &pipeline); + flags, &pipeline, false); if (result != VK_SUCCESS) { vk_command_buffer_set_error(&cmd_buffer->vk, result); return; diff --git a/src/vulkan/runtime/vk_acceleration_structure.c b/src/vulkan/runtime/vk_acceleration_structure.c index b4b0960304f..7620da916fa 100644 --- a/src/vulkan/runtime/vk_acceleration_structure.c +++ b/src/vulkan/runtime/vk_acceleration_structure.c @@ -30,6 +30,7 @@ #include "vk_command_buffer.h" #include "vk_log.h" #include "vk_meta.h" +#include "vk_shader.h" #include "bvh/vk_build_interface.h" #include "bvh/vk_bvh.h" @@ -277,7 +278,8 @@ vk_get_bvh_build_pipeline_spv(struct vk_device *device, struct vk_meta_device *m enum vk_meta_object_key_type type, const uint32_t *spv, uint32_t spv_size, unsigned push_constant_size, const struct vk_acceleration_structure_build_args *args, - uint32_t flags, VkPipeline *pipeline) + uint32_t flags, VkPipeline *pipeline, + bool unaligned_dispatch) { VkPipelineLayout layout; VkResult result = vk_get_bvh_build_pipeline_layout(device, meta, push_constant_size, &layout); @@ -347,10 +349,14 @@ vk_get_bvh_build_pipeline_spv(struct vk_device *device, struct vk_meta_device *m .requiredSubgroupSize = args->subgroup_size, }; + uint32_t shader_flags = VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT; + if (unaligned_dispatch) + shader_flags |= VK_SHADER_CREATE_UNALIGNED_DISPATCH_BIT_MESA; + VkPipelineShaderStageCreateInfo shader_stage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .pNext = &rssci, - .flags = VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT, + .flags = shader_flags, .stage = VK_SHADER_STAGE_COMPUTE_BIT, .pName = "main", .pSpecializationInfo = &spec_info, @@ -504,7 +510,8 @@ build_leaves(VkCommandBuffer commandBuffer, VkResult result = vk_get_bvh_build_pipeline_spv(device, meta, VK_META_OBJECT_KEY_LEAF, spirv, spirv_size, sizeof(struct leaf_args), args, flags, - &pipeline); + &pipeline, + true /* unaligned_dispatch */); if (result != VK_SUCCESS) return result; @@ -573,7 +580,8 @@ morton_generate(VkCommandBuffer commandBuffer, struct vk_device *device, VkResult result = vk_get_bvh_build_pipeline_spv(device, meta, VK_META_OBJECT_KEY_MORTON, morton_spv, sizeof(morton_spv), sizeof(struct morton_args), args, 0, - &pipeline); + &pipeline, + true /* unaligned_dispatch */); if (result != VK_SUCCESS) return result; @@ -866,7 +874,8 @@ lbvh_build_internal(VkCommandBuffer commandBuffer, VkResult result = vk_get_bvh_build_pipeline_spv(device, meta, VK_META_OBJECT_KEY_LBVH_MAIN, lbvh_main_spv, sizeof(lbvh_main_spv), sizeof(struct lbvh_main_args), args, flags, - &pipeline); + &pipeline, + true /* unaligned_dispatch */); if (result != VK_SUCCESS) return result; @@ -910,7 +919,7 @@ lbvh_build_internal(VkCommandBuffer commandBuffer, result = vk_get_bvh_build_pipeline_spv(device, meta, VK_META_OBJECT_KEY_LBVH_GENERATE_IR, lbvh_generate_ir_spv, sizeof(lbvh_generate_ir_spv), sizeof(struct lbvh_generate_ir_args), args, flags, - &pipeline); + &pipeline, true /* unaligned_dispatch */); if (result != VK_SUCCESS) return result; @@ -959,7 +968,8 @@ ploc_build_internal(VkCommandBuffer commandBuffer, VkResult result = vk_get_bvh_build_pipeline_spv(device, meta, VK_META_OBJECT_KEY_PLOC, ploc_spv, sizeof(ploc_spv), sizeof(struct ploc_args), - args, flags, &pipeline); + args, flags, &pipeline, + false /* unaligned_dispatch */); if (result != VK_SUCCESS) return result; diff --git a/src/vulkan/runtime/vk_acceleration_structure.h b/src/vulkan/runtime/vk_acceleration_structure.h index b582bbdc6e5..a454c93cd00 100644 --- a/src/vulkan/runtime/vk_acceleration_structure.h +++ b/src/vulkan/runtime/vk_acceleration_structure.h @@ -146,7 +146,8 @@ VkResult vk_get_bvh_build_pipeline_spv(struct vk_device *device, struct vk_meta_ enum vk_meta_object_key_type type, const uint32_t *spv, uint32_t spv_size, unsigned push_constant_size, const struct vk_acceleration_structure_build_args *args, - uint32_t flags, VkPipeline *pipeline); + uint32_t flags, VkPipeline *pipeline, + bool unaligned_dispatch); void vk_cmd_build_acceleration_structures(VkCommandBuffer cmdbuf, struct vk_device *device, diff --git a/src/vulkan/runtime/vk_shader.h b/src/vulkan/runtime/vk_shader.h index 37e01233233..fd39c141e15 100644 --- a/src/vulkan/runtime/vk_shader.h +++ b/src/vulkan/runtime/vk_shader.h @@ -49,6 +49,7 @@ struct vk_pipeline_robustness_state; int vk_shader_cmp_graphics_stages(mesa_shader_stage a, mesa_shader_stage b); #define VK_SHADER_CREATE_CAPTURE_INTERNAL_REPRESENTATIONS_BIT_MESA 0x1000 +#define VK_SHADER_CREATE_UNALIGNED_DISPATCH_BIT_MESA 0x2000 struct vk_shader_compile_info { mesa_shader_stage stage;