diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 9ad9f735..27aec124 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1958,6 +1958,84 @@ static void write_sm1_unary_op(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffe write_sm1_instruction(ctx, buffer, &instr); } +static void write_sm1_cast(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, + const struct hlsl_ir_node *instr) +{ + struct hlsl_ir_expr *expr = hlsl_ir_expr(instr); + const struct hlsl_ir_node *arg1 = expr->operands[0].node; + const struct hlsl_type *dst_type = expr->node.data_type; + const struct hlsl_type *src_type = arg1->data_type; + + /* Narrowing casts were already lowered. */ + assert(src_type->dimx == dst_type->dimx); + + switch (dst_type->base_type) + { + case HLSL_TYPE_HALF: + case HLSL_TYPE_FLOAT: + switch (src_type->base_type) + { + case HLSL_TYPE_INT: + case HLSL_TYPE_UINT: + /* Integers are internally represented as floats, so no change is necessary.*/ + case HLSL_TYPE_HALF: + case HLSL_TYPE_FLOAT: + write_sm1_unary_op(ctx, buffer, D3DSIO_MOV, &instr->reg, &arg1->reg, 0, 0); + break; + + case HLSL_TYPE_BOOL: + hlsl_fixme(ctx, &instr->loc, "SM1 cast from bool to float."); + break; + + case HLSL_TYPE_DOUBLE: + hlsl_fixme(ctx, &instr->loc, "SM1 cast from double to float."); + break; + + default: + vkd3d_unreachable(); + } + break; + + case HLSL_TYPE_INT: + case HLSL_TYPE_UINT: + switch(src_type->base_type) + { + case HLSL_TYPE_INT: + case HLSL_TYPE_UINT: + write_sm1_unary_op(ctx, buffer, D3DSIO_MOV, &instr->reg, &arg1->reg, 0, 0); + break; + + case HLSL_TYPE_HALF: + case HLSL_TYPE_FLOAT: + hlsl_fixme(ctx, &instr->loc, "SM1 cast from float to integer."); + break; + + case HLSL_TYPE_BOOL: + hlsl_fixme(ctx, &instr->loc, "SM1 cast from bool to integer."); + break; + + case HLSL_TYPE_DOUBLE: + hlsl_fixme(ctx, &instr->loc, "SM1 cast from double to integer."); + break; + + default: + vkd3d_unreachable(); + } + break; + + case HLSL_TYPE_DOUBLE: + hlsl_fixme(ctx, &instr->loc, "SM1 cast to double."); + break; + + case HLSL_TYPE_BOOL: + /* Casts to bool should have already been lowered. */ + default: + hlsl_fixme(ctx, &expr->node.loc, "SM1 cast from %s to %s.\n", + debug_hlsl_type(ctx, src_type), debug_hlsl_type(ctx, dst_type)); + break; + } +} + static void write_sm1_constant_defs(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer) { unsigned int i, x; @@ -2179,6 +2257,10 @@ static void write_sm1_expr(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *b write_sm1_unary_op(ctx, buffer, D3DSIO_ABS, &instr->reg, &arg1->reg, 0, 0); break; + case HLSL_OP1_CAST: + write_sm1_cast(ctx, buffer, instr); + break; + case HLSL_OP1_DSX: write_sm1_unary_op(ctx, buffer, D3DSIO_DSX, &instr->reg, &arg1->reg, 0, 0); break; diff --git a/tests/hlsl/distance.shader_test b/tests/hlsl/distance.shader_test index bf2423c7..3f544645 100644 --- a/tests/hlsl/distance.shader_test +++ b/tests/hlsl/distance.shader_test @@ -13,7 +13,7 @@ uniform 4 float4 2.0 -1.0 4.0 5.0 draw quad probe all rgba (7.483983, 7.483983, 7.483983, 7.483983) 1 -[pixel shader todo(sm<4)] +[pixel shader] uniform int4 x; uniform int4 y; diff --git a/tests/hlsl/half.shader_test b/tests/hlsl/half.shader_test index 8cf7a756..fe7074e4 100644 --- a/tests/hlsl/half.shader_test +++ b/tests/hlsl/half.shader_test @@ -9,7 +9,7 @@ float4 main() : sv_target [require] options: backcompat -[pixel shader todo(sm<4)] +[pixel shader] uniform half h; float4 main() : sv_target @@ -19,5 +19,5 @@ float4 main() : sv_target [test] uniform 0 float 10.0 -todo(sm<4) draw quad +draw quad probe all rgba (10.0, 10.0, 10.0, 10.0) diff --git a/tests/hlsl/ldexp.shader_test b/tests/hlsl/ldexp.shader_test index 2d778e07..75492b66 100644 --- a/tests/hlsl/ldexp.shader_test +++ b/tests/hlsl/ldexp.shader_test @@ -14,7 +14,7 @@ draw quad probe all rgba (2.0, 0.00292968750, 4096.0, 6.33825300e+030) 2 -[pixel shader todo(sm<4)] +[pixel shader] uniform int4 x; uniform int4 y; @@ -28,7 +28,7 @@ if(sm<4) uniform 0 float4 2 3 4 5 if(sm<4) uniform 4 float4 0 -10 10 100 if(sm>=4) uniform 0 int4 2 3 4 5 if(sm>=4) uniform 4 int4 0 -10 10 100 -todo(sm<4) draw quad +draw quad probe all rgba (2.0, 0.00292968750, 4096.0, 6.33825300e+030) 2 diff --git a/tests/hlsl/lerp.shader_test b/tests/hlsl/lerp.shader_test index 901857df..ae6ef534 100644 --- a/tests/hlsl/lerp.shader_test +++ b/tests/hlsl/lerp.shader_test @@ -16,7 +16,7 @@ draw quad probe all rgba (2.0, -10.0, -2.0, 76.25) -[pixel shader todo(sm<4)] +[pixel shader] uniform int4 x; uniform int4 y; uniform int4 s; @@ -33,8 +33,8 @@ if(sm<4) uniform 8 float4 0 1 -1 1000000 if(sm>=4) uniform 0 int4 2 3 4 0 if(sm>=4) uniform 4 int4 0 -10 10 1000000 if(sm>=4) uniform 8 int4 0 1 -1 1000000 -todo(sm<4) draw quad -probe all rgba (2.0, -10.0, -2.0, 1e12) +draw quad +probe all rgba (2.0, -10.0, -2.0, 1e12) 4 [pixel shader]