From f2f44b054d84fe248633807a4aa227214cd4b9d1 Mon Sep 17 00:00:00 2001 From: Shaun Ren Date: Fri, 21 Mar 2025 17:45:50 -0400 Subject: [PATCH] vkd3d-shader/hlsl: Allocate registers for stream output objects. All stream output objects need to have a stream index allocated, whether they are used or not. We allocate stream outputs here, before other objects are allocated, because the stream index is needed to create the appropriate output semantic variables during append_output_copy(), which will be called in a lowering pass for the Append() method. --- libs/vkd3d-shader/hlsl_codegen.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 73a56a0a5..392dda886 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -6881,6 +6881,28 @@ static void allocate_objects(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl } } +static void allocate_stream_outputs(struct hlsl_ctx *ctx) +{ + struct hlsl_ir_var *var; + uint32_t index = 0; + + LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry) + { + if (!var->data_type->reg_size[HLSL_REGSET_STREAM_OUTPUTS]) + continue; + + /* We should have ensured that all stream output objects are single-element. */ + VKD3D_ASSERT(var->data_type->reg_size[HLSL_REGSET_STREAM_OUTPUTS] == 1); + + var->regs[HLSL_REGSET_STREAM_OUTPUTS].space = 0; + var->regs[HLSL_REGSET_STREAM_OUTPUTS].index = index; + var->regs[HLSL_REGSET_STREAM_OUTPUTS].id = index; + var->regs[HLSL_REGSET_STREAM_OUTPUTS].allocated = true; + + ++index; + } +} + bool hlsl_component_index_range_from_deref(struct hlsl_ctx *ctx, const struct hlsl_deref *deref, unsigned int *start, unsigned int *count) { @@ -13265,7 +13287,7 @@ static void process_entry_function(struct hlsl_ctx *ctx, /* TODO: check that maxvertexcount * component_count(element_type) <= 1024. */ - continue; + prepend_uniform_copy(ctx, body, var); } else { @@ -13379,6 +13401,9 @@ static void process_entry_function(struct hlsl_ctx *ctx, else sort_synthetic_separated_samplers_first(ctx); + if (profile->type == VKD3D_SHADER_TYPE_GEOMETRY) + allocate_stream_outputs(ctx); + if (profile->major_version < 4) { while (lower_ir(ctx, lower_nonconstant_array_loads, body));