From 253c9941556ff1bb9e3d8ee55d4941c3438de700 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Tue, 9 Apr 2024 13:07:54 -0400 Subject: [PATCH] vkd3d-shader/tpf: Write default values for SM4. --- libs/vkd3d-shader/d3dbc.c | 2 ++ libs/vkd3d-shader/tpf.c | 30 +++++++++++++++++++++++++++++- tests/hlsl_d3d12.c | 4 ++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 8e26fd8e..20c0e7db 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1744,6 +1744,8 @@ static void write_sm1_uniforms(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffe } put_u32(buffer, 0); /* type */ put_u32(buffer, 0); /* FIXME: default value */ + if (var->default_values) + FIXME("Write SM1 default values.\n"); } } diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 5df7bbe7..0340091d 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3522,7 +3522,7 @@ static void write_sm4_rdef(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc) put_u32(&buffer, var->data_type->reg_size[HLSL_REGSET_NUMERIC] * sizeof(float)); put_u32(&buffer, flags); put_u32(&buffer, 0); /* type */ - put_u32(&buffer, 0); /* FIXME: default value */ + put_u32(&buffer, 0); /* default value */ if (profile->major_version >= 5) { @@ -3546,6 +3546,34 @@ static void write_sm4_rdef(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc) set_u32(&buffer, var_offset, string_offset); write_sm4_type(ctx, &buffer, var->data_type); set_u32(&buffer, var_offset + 4 * sizeof(uint32_t), var->data_type->bytecode_offset); + + if (var->default_values) + { + unsigned int reg_size = var->data_type->reg_size[HLSL_REGSET_NUMERIC]; + unsigned int comp_count = hlsl_type_component_count(var->data_type); + unsigned int default_value_offset; + unsigned int k; + + default_value_offset = bytecode_reserve_bytes(&buffer, reg_size * sizeof(uint32_t)); + set_u32(&buffer, var_offset + 5 * sizeof(uint32_t), default_value_offset); + + for (k = 0; k < comp_count; ++k) + { + struct hlsl_type *comp_type = hlsl_type_get_component_type(ctx, var->data_type, k); + unsigned int comp_offset; + enum hlsl_regset regset; + + comp_offset = hlsl_type_get_component_offset(ctx, var->data_type, k, ®set); + if (regset == HLSL_REGSET_NUMERIC) + { + if (comp_type->e.numeric.type == HLSL_TYPE_DOUBLE) + hlsl_fixme(ctx, &var->loc, "Write double default values."); + + set_u32(&buffer, default_value_offset + comp_offset * sizeof(uint32_t), + var->default_values[k].value.u); + } + } + } ++j; } } diff --git a/tests/hlsl_d3d12.c b/tests/hlsl_d3d12.c index c06693cf..1292e100 100644 --- a/tests/hlsl_d3d12.c +++ b/tests/hlsl_d3d12.c @@ -1863,7 +1863,7 @@ static void test_default_values_reflection(void) if (expect->var_desc.DefaultValue) { - todo ok(var_desc.DefaultValue, "Didn't get default value.\n"); + ok(var_desc.DefaultValue, "Didn't get default value.\n"); if (var_desc.DefaultValue && var_desc.Size == expect->var_desc.Size) { @@ -1872,7 +1872,7 @@ static void test_default_values_reflection(void) unsigned int var_val = *((unsigned int *)var_desc.DefaultValue + k); unsigned int expect_val = *((unsigned int *)expect->var_desc.DefaultValue + k); - ok(var_val == expect_val, "Expected default value 0x%08x, but got 0x%08x, at offset %u.\n", + todo_if(var_val != expect_val) ok(var_val == expect_val, "Expected default value 0x%08x, but got 0x%08x, at offset %u.\n", expect_val, var_val, 4 * k); } }