From cf92d9f398da81a7be526c5767bef2f5ae835cb0 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Sat, 5 Oct 2024 23:27:56 +0200 Subject: [PATCH] vkd3d-shader/ir: Store the thread group size in struct vsir_program. --- libs/vkd3d-shader/dxil.c | 1 + libs/vkd3d-shader/ir.c | 1 + libs/vkd3d-shader/spirv.c | 10 ++++------ libs/vkd3d-shader/tpf.c | 5 ++++- libs/vkd3d-shader/vkd3d_shader_private.h | 5 +++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c index d4296ef4..4c22493e 100644 --- a/libs/vkd3d-shader/dxil.c +++ b/libs/vkd3d-shader/dxil.c @@ -9637,6 +9637,7 @@ static enum vkd3d_result sm6_parser_emit_thread_group(struct sm6_parser *sm6, co ins->declaration.thread_group_size.x = group_sizes[0]; ins->declaration.thread_group_size.y = group_sizes[1]; ins->declaration.thread_group_size.z = group_sizes[2]; + sm6->p.program->thread_group_size = ins->declaration.thread_group_size; return VKD3D_OK; } diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index 0602bae8..a116713c 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -681,6 +681,7 @@ static enum vkd3d_result vsir_program_lower_instructions(struct vsir_program *pr case VKD3DSIH_DCL_CONSTANT_BUFFER: case VKD3DSIH_DCL_SAMPLER: case VKD3DSIH_DCL_TEMPS: + case VKD3DSIH_DCL_THREAD_GROUP: vkd3d_shader_instruction_make_nop(ins); break; diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 10a9f844..76fe149a 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -6890,10 +6890,9 @@ static void spirv_compiler_emit_tessellator_partitioning(struct spirv_compiler * spirv_compiler_emit_execution_mode(compiler, mode, NULL, 0); } -static void spirv_compiler_emit_dcl_thread_group(struct spirv_compiler *compiler, - const struct vkd3d_shader_instruction *instruction) +static void spirv_compiler_emit_thread_group_size(struct spirv_compiler *compiler, + const struct vsir_thread_group_size *group_size) { - const struct vkd3d_shader_thread_group_size *group_size = &instruction->declaration.thread_group_size; const uint32_t local_size[] = {group_size->x, group_size->y, group_size->z}; spirv_compiler_emit_execution_mode(compiler, @@ -10227,9 +10226,6 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler, spirv_compiler_emit_tessellator_partitioning(compiler, instruction->declaration.tessellator_partitioning); break; - case VKD3DSIH_DCL_THREAD_GROUP: - spirv_compiler_emit_dcl_thread_group(compiler, instruction); - break; case VKD3DSIH_HS_CONTROL_POINT_PHASE: case VKD3DSIH_HS_FORK_PHASE: case VKD3DSIH_HS_JOIN_PHASE: @@ -10649,6 +10645,8 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, struct spirv_compiler_emit_temps(compiler, program->temp_count); if (program->ssa_count) spirv_compiler_allocate_ssa_register_ids(compiler, program->ssa_count); + if (compiler->shader_type == VKD3D_SHADER_TYPE_COMPUTE) + spirv_compiler_emit_thread_group_size(compiler, &program->thread_group_size); spirv_compiler_emit_descriptor_declarations(compiler); diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 4139c67d..43d416c4 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -1289,11 +1289,14 @@ static void shader_sm5_read_dcl_hs_max_tessfactor(struct vkd3d_shader_instructio } static void shader_sm5_read_dcl_thread_group(struct vkd3d_shader_instruction *ins, uint32_t opcode, - uint32_t opcode_token, const uint32_t *tokens, unsigned int token_count, struct vkd3d_shader_sm4_parser *priv) + uint32_t opcode_token, const uint32_t *tokens, unsigned int token_count, struct vkd3d_shader_sm4_parser *sm4) { + struct vsir_program *program = sm4->p.program; + ins->declaration.thread_group_size.x = *tokens++; ins->declaration.thread_group_size.y = *tokens++; ins->declaration.thread_group_size.z = *tokens++; + program->thread_group_size = ins->declaration.thread_group_size; } static void shader_sm5_read_dcl_uav_raw(struct vkd3d_shader_instruction *ins, uint32_t opcode, uint32_t opcode_token, diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 06b97d2b..45bfe875 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1164,7 +1164,7 @@ struct vkd3d_shader_tgsm_structured bool zero_init; }; -struct vkd3d_shader_thread_group_size +struct vsir_thread_group_size { unsigned int x, y, z; }; @@ -1243,7 +1243,7 @@ struct vkd3d_shader_instruction struct vkd3d_shader_structured_resource structured_resource; struct vkd3d_shader_tgsm_raw tgsm_raw; struct vkd3d_shader_tgsm_structured tgsm_structured; - struct vkd3d_shader_thread_group_size thread_group_size; + struct vsir_thread_group_size thread_group_size; enum vkd3d_tessellator_domain tessellator_domain; enum vkd3d_shader_tessellator_output_primitive tessellator_output_primitive; enum vkd3d_shader_tessellator_partitioning tessellator_partitioning; @@ -1390,6 +1390,7 @@ struct vsir_program bool free_parameters; unsigned int input_control_point_count, output_control_point_count; + struct vsir_thread_group_size thread_group_size; unsigned int flat_constant_count[3]; unsigned int block_count; unsigned int temp_count;