From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/tpf.c | 40 +++++++++++++++++++++++++++++--- tests/bool-semantics.shader_test | 2 +- tests/cast-to-int.shader_test | 2 +- tests/cast-to-uint.shader_test | 2 +- tests/hlsl-bool-cast.shader_test | 2 +- 5 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index ae4b4aff..a669dbfb 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4343,19 +4343,53 @@ static void write_sm4_jump(struct hlsl_ctx *ctx, write_sm4_instruction(buffer, &instr); }
+/* Does this variable's data come directly from the API user, rather than being + * temporary or from a previous shader stage? + * I.e. is it a uniform or VS input? */ +static bool var_is_user_input(struct hlsl_ctx *ctx, const struct hlsl_ir_var *var) +{ + if (var->is_uniform) + return true; + + return var->is_input_semantic && ctx->profile->type == VKD3D_SHADER_TYPE_VERTEX; +} + static void write_sm4_load(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_load *load) { + const struct hlsl_type *type = load->node.data_type; struct sm4_instruction instr;
memset(&instr, 0, sizeof(instr)); - instr.opcode = VKD3D_SM4_OP_MOV;
sm4_dst_from_node(&instr.dsts[0], &load->node); instr.dst_count = 1;
- sm4_src_from_deref(ctx, &instr.srcs[0], &load->src, load->node.data_type, instr.dsts[0].writemask); - instr.src_count = 1; + assert(type->class <= HLSL_CLASS_LAST_NUMERIC); + if (type->base_type == HLSL_TYPE_BOOL && var_is_user_input(ctx, load->src.var)) + { + struct hlsl_constant_value value; + + /* Uniform bools can be specified as anything, but internal bools always + * have 0 for false and ~0 for true. Normalize that here. */ + + instr.opcode = VKD3D_SM4_OP_MOVC; + + sm4_src_from_deref(ctx, &instr.srcs[0], &load->src, type, instr.dsts[0].writemask); + + memset(&value, 0xff, sizeof(value)); + sm4_src_from_constant_value(&instr.srcs[1], &value, type->dimx, instr.dsts[0].writemask); + memset(&value, 0, sizeof(value)); + sm4_src_from_constant_value(&instr.srcs[2], &value, type->dimx, instr.dsts[0].writemask); + instr.src_count = 3; + } + else + { + instr.opcode = VKD3D_SM4_OP_MOV; + + sm4_src_from_deref(ctx, &instr.srcs[0], &load->src, type, instr.dsts[0].writemask); + instr.src_count = 1; + }
write_sm4_instruction(buffer, &instr); } diff --git a/tests/bool-semantics.shader_test b/tests/bool-semantics.shader_test index 0e42fdf9..bcbd9f9b 100644 --- a/tests/bool-semantics.shader_test +++ b/tests/bool-semantics.shader_test @@ -50,4 +50,4 @@ float4 main(struct input i) : sv_target
[test] draw triangle strip 4 -todo probe all rgba (0.0, 2.0, 2.0, 2.0) +probe all rgba (0.0, 2.0, 2.0, 2.0) diff --git a/tests/cast-to-int.shader_test b/tests/cast-to-int.shader_test index 4c5d0e2f..fe8c79a3 100644 --- a/tests/cast-to-int.shader_test +++ b/tests/cast-to-int.shader_test @@ -20,7 +20,7 @@ uniform 1 int -2 uniform 2 int -2 uniform 3 float -3.6 draw quad -todo probe all rgba (0.5, 0.5, 0.5, 0.5) +probe all rgba (0.5, 0.5, 0.5, 0.5)
[pixel shader]
diff --git a/tests/cast-to-uint.shader_test b/tests/cast-to-uint.shader_test index 66f7267e..4ffc041a 100644 --- a/tests/cast-to-uint.shader_test +++ b/tests/cast-to-uint.shader_test @@ -20,7 +20,7 @@ uniform 1 int 2 uniform 2 int -2 uniform 3 float -3.6 draw quad -todo probe all rgba (0.5, 0.5, 0.5, 0.5) +probe all rgba (0.5, 0.5, 0.5, 0.5)
[pixel shader]
diff --git a/tests/hlsl-bool-cast.shader_test b/tests/hlsl-bool-cast.shader_test index b0913bb8..09ca12e2 100644 --- a/tests/hlsl-bool-cast.shader_test +++ b/tests/hlsl-bool-cast.shader_test @@ -45,4 +45,4 @@ float4 main() : sv_target [test] uniform 0 uint4 0x00000001 0x00000002 0x80000000 0x00000000 draw quad -todo probe all rgba (2.0, 2.0, 2.0, 0.0) +probe all rgba (2.0, 2.0, 2.0, 0.0)