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 <alyssa@rosenzweig.io>
Signed-off-by: Sagar Ghuge <sagar.ghuge@intel.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36245>
This commit is contained in:
Sagar Ghuge 2025-07-21 22:27:19 -07:00 committed by Marge Bot
parent 349de5b0be
commit 7b634ebb63
5 changed files with 22 additions and 10 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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,

View file

@ -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;