From fa560b589e7a7401795e1ec85ff6b344c403e7b3 Mon Sep 17 00:00:00 2001 From: Shaun Ren Date: Fri, 27 Jun 2025 11:11:01 -0400 Subject: [PATCH] vkd3d-shader/hlsl: Emit dcl_tgsm_raw instructions for raw groupshared variables. --- libs/vkd3d-shader/hlsl_codegen.c | 30 +++++++++++++++++++++++++++++- libs/vkd3d-shader/tpf.c | 21 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 11d1aabd0..f7fb540ef 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -12577,6 +12577,34 @@ static void sm4_generate_vsir_add_dcl_texture(struct hlsl_ctx *ctx, } } +static void sm4_generate_vsir_add_dcl_tgsm(struct hlsl_ctx *ctx, + struct vsir_program *program, const struct hlsl_ir_var *var) +{ + struct vkd3d_shader_dst_param *dst_param; + struct vkd3d_shader_instruction *ins; + + if (!hlsl_is_numeric_type(var->data_type)) + { + hlsl_fixme(ctx, &var->loc, "Structured TGSM declaration."); + return; + } + + if (!(ins = generate_vsir_add_program_instruction(ctx, program, &var->loc, VSIR_OP_DCL_TGSM_RAW, 0, 0))) + { + ctx->result = VKD3D_ERROR_OUT_OF_MEMORY; + return; + } + + dst_param = &ins->declaration.tgsm_raw.reg; + + vsir_dst_param_init(dst_param, VKD3DSPR_GROUPSHAREDMEM, VSIR_DATA_F32, 1); + dst_param->reg.dimension = VSIR_DIMENSION_NONE; + dst_param->reg.idx[0].offset = var->regs[HLSL_REGSET_NUMERIC].id; + + ins->declaration.tgsm_raw.byte_count = var->data_type->reg_size[HLSL_REGSET_NUMERIC] * 4; + ins->declaration.tgsm_raw.zero_init = false; +} + static void sm4_generate_vsir_add_dcl_stream(struct hlsl_ctx *ctx, struct vsir_program *program, const struct hlsl_ir_var *var) { @@ -12659,7 +12687,7 @@ static void sm4_generate_vsir(struct hlsl_ctx *ctx, LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry) { if (var->is_tgsm && var->regs[HLSL_REGSET_NUMERIC].allocated) - hlsl_fixme(ctx, &var->loc, "Groupshared variable."); + sm4_generate_vsir_add_dcl_tgsm(ctx, program, var); } if (version->type == VKD3D_SHADER_TYPE_GEOMETRY && version->major >= 5) diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index ed19faf94..ea15c1a9a 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3910,6 +3910,23 @@ static void tpf_dcl_texture(const struct tpf_compiler *tpf, const struct vkd3d_s write_sm4_instruction(tpf, &instr); } +static void tpf_dcl_tgsm_raw(const struct tpf_compiler *tpf, const struct vkd3d_shader_instruction *ins) +{ + const struct vkd3d_shader_tgsm_raw *tgsm = &ins->declaration.tgsm_raw; + struct sm4_instruction instr = + { + .opcode = VKD3D_SM5_OP_DCL_TGSM_RAW, + + .dsts[0] = tgsm->reg, + .dst_count = 1, + + .idx[0] = tgsm->byte_count, + .idx_count = 1, + }; + + write_sm4_instruction(tpf, &instr); +} + static void write_sm4_dcl_global_flags(const struct tpf_compiler *tpf, uint32_t flags) { struct sm4_instruction instr = @@ -4199,6 +4216,10 @@ static void tpf_handle_instruction(struct tpf_compiler *tpf, const struct vkd3d_ tpf_dcl_sampler(tpf, ins); break; + case VSIR_OP_DCL_TGSM_RAW: + tpf_dcl_tgsm_raw(tpf, ins); + break; + case VSIR_OP_DCL: case VSIR_OP_DCL_RESOURCE_RAW: case VSIR_OP_DCL_UAV_RAW: