From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- Makefile.am | 1 + libs/vkd3d-shader/hlsl.c | 1 + libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 8 ++++++++ libs/vkd3d-shader/hlsl_sm4.c | 4 ++++ tests/round.shader_test | 26 ++++++++++++++++++++++++++ 6 files changed, 41 insertions(+) create mode 100644 tests/round.shader_test
diff --git a/Makefile.am b/Makefile.am index 3e083b0a..6d392e1d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -91,6 +91,7 @@ vkd3d_shader_tests = \ tests/preproc-invalid.shader_test \ tests/preproc-macro.shader_test \ tests/preproc-misc.shader_test \ + tests/round.shader_test \ tests/sampler.shader_test \ tests/saturate.shader_test \ tests/swizzle-0.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 1eee4278..9824c56d 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1156,6 +1156,7 @@ const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op) [HLSL_OP1_NEG] = "-", [HLSL_OP1_NRM] = "nrm", [HLSL_OP1_RCP] = "rcp", + [HLSL_OP1_ROUND] = "round", [HLSL_OP1_RSQ] = "rsq", [HLSL_OP1_SAT] = "sat", [HLSL_OP1_SIGN] = "sign", diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 365ef980..e7bdb45e 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -299,6 +299,7 @@ enum hlsl_ir_expr_op HLSL_OP1_NEG, HLSL_OP1_NRM, HLSL_OP1_RCP, + HLSL_OP1_ROUND, HLSL_OP1_RSQ, HLSL_OP1_SAT, HLSL_OP1_SIGN, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index b7e0409d..abf5da91 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1611,6 +1611,12 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx, return true; }
+static bool intrinsic_round(struct hlsl_ctx *ctx, + const struct parse_initializer *params, struct vkd3d_shader_location loc) +{ + return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ROUND, params->args[0], &loc); +} + static bool intrinsic_saturate(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { @@ -1626,10 +1632,12 @@ static const struct intrinsic_function } intrinsic_functions[] = { + /* Note: these entries should be kept in alphabetical order. */ {"abs", 1, true, intrinsic_abs}, {"clamp", 3, true, intrinsic_clamp}, {"max", 2, true, intrinsic_max}, {"pow", 2, true, intrinsic_pow}, + {"round", 1, true, intrinsic_round}, {"saturate", 1, true, intrinsic_saturate}, };
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index a95503ee..c0c26f80 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1305,6 +1305,10 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, VKD3D_SM4_REGISTER_MODIFIER_NEGATE); break;
+ case HLSL_OP1_ROUND: + write_sm4_unary_op(buffer, VKD3D_SM4_OP_ROUND_NE, &expr->node, arg1, 0); + break; + case HLSL_OP1_SAT: write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV | (VKD3D_SM4_INSTRUCTION_FLAG_SATURATE << VKD3D_SM4_INSTRUCTION_FLAGS_SHIFT), diff --git a/tests/round.shader_test b/tests/round.shader_test new file mode 100644 index 00000000..d8eb11b7 --- /dev/null +++ b/tests/round.shader_test @@ -0,0 +1,26 @@ +[pixel shader] +float4 main(uniform float4 u) : sv_target +{ + return round(u); +} + +[test] +uniform 0 float4 -0.5 6.5 7.5 3.4 +draw quad +probe all rgba (0.0, 6.0, 8.0, 3.0) 4 + + + +[pixel shader] +float4 main(uniform float4 u) : sv_target +{ + float a = round(u.r); + int2 b = round(u.gb); + float4 res = float4(b, a, u.a); + return round(res); +} + +[test] +uniform 0 float4 -0.5 6.5 7.5 3.4 +draw quad +probe all rgba (6.0, 8.0, 0.0, 3.0) 4
From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v5: More rebase action...
Nice patch btw.
Makefile.am | 2 ++ libs/vkd3d-shader/hlsl.y | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
diff --git a/Makefile.am b/Makefile.am index 6d392e1d..be3d8ec1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,6 +64,7 @@ vkd3d_shader_tests = \ tests/hlsl-bool-cast.shader_test \ tests/hlsl-clamp.shader_test \ tests/hlsl-comma.shader_test \ + tests/hlsl-cross.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function-overload.shader_test \ @@ -290,6 +291,7 @@ XFAIL_TESTS = \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ tests/hlsl-comma.shader_test \ + tests/hlsl-cross.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function-overload.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index abf5da91..ff35c09e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1586,6 +1586,60 @@ static bool intrinsic_clamp(struct hlsl_ctx *ctx, return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MIN, &max->node, params->args[2], &loc); }
+static bool intrinsic_cross(struct hlsl_ctx *ctx, + const struct parse_initializer *params, struct vkd3d_shader_location loc) +{ + struct hlsl_ir_swizzle *arg1_swzl1, *arg1_swzl2, *arg2_swzl1, *arg2_swzl2; + struct hlsl_ir_node *arg1 = params->args[0], *arg2 = params->args[1]; + struct hlsl_ir_node *arg1_cast, *arg2_cast, *mul1_neg; + struct hlsl_ir_expr *mul1, *mul2; + struct hlsl_type *cast_type; + enum hlsl_base_type base; + + if (arg1->data_type->base_type == HLSL_TYPE_HALF && arg2->data_type->base_type == HLSL_TYPE_HALF) + base = HLSL_TYPE_HALF; + else + base = HLSL_TYPE_FLOAT; + + cast_type = hlsl_get_vector_type(ctx, base, 3); + + if (!(arg1_cast = add_implicit_conversion(ctx, params->instrs, arg1, cast_type, &loc))) + return false; + + if (!(arg2_cast = add_implicit_conversion(ctx, params->instrs, arg2, cast_type, &loc))) + return false; + + if (!(arg1_swzl1 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Z, X, Y, Z), 3, arg1_cast, &loc))) + return false; + list_add_tail(params->instrs, &arg1_swzl1->node.entry); + + if (!(arg2_swzl1 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Y, Z, X, Y), 3, arg2_cast, &loc))) + return false; + list_add_tail(params->instrs, &arg2_swzl1->node.entry); + + if (!(mul1 = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, + &arg1_swzl1->node, &arg2_swzl1->node, &loc))) + return false; + + if (!(mul1_neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, &mul1->node, loc))) + return false; + list_add_tail(params->instrs, &mul1_neg->entry); + + if (!(arg1_swzl2 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Y, Z, X, Y), 3, arg1_cast, &loc))) + return false; + list_add_tail(params->instrs, &arg1_swzl2->node.entry); + + if (!(arg2_swzl2 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Z, X, Y, Z), 3, arg2_cast, &loc))) + return false; + list_add_tail(params->instrs, &arg2_swzl2->node.entry); + + if (!(mul2 = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, + &arg1_swzl2->node, &arg2_swzl2->node, &loc))) + return false; + + return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, &mul2->node, mul1_neg, &loc); +} + static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { @@ -1635,6 +1689,7 @@ intrinsic_functions[] = /* Note: these entries should be kept in alphabetical order. */ {"abs", 1, true, intrinsic_abs}, {"clamp", 3, true, intrinsic_clamp}, + {"cross", 2, true, intrinsic_cross}, {"max", 2, true, intrinsic_max}, {"pow", 2, true, intrinsic_pow}, {"round", 1, true, intrinsic_round},
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
On 19/11/21 15:38, Matteo Bruni wrote:
From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com
v5: More rebase action...
Nice patch btw.
Makefile.am | 2 ++ libs/vkd3d-shader/hlsl.y | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
diff --git a/Makefile.am b/Makefile.am index 6d392e1d..be3d8ec1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,6 +64,7 @@ vkd3d_shader_tests = \ tests/hlsl-bool-cast.shader_test \ tests/hlsl-clamp.shader_test \ tests/hlsl-comma.shader_test \
- tests/hlsl-cross.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function-overload.shader_test \
@@ -290,6 +291,7 @@ XFAIL_TESTS = \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ tests/hlsl-comma.shader_test \
- tests/hlsl-cross.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function-overload.shader_test \
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index abf5da91..ff35c09e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1586,6 +1586,60 @@ static bool intrinsic_clamp(struct hlsl_ctx *ctx, return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MIN, &max->node, params->args[2], &loc); }
+static bool intrinsic_cross(struct hlsl_ctx *ctx,
const struct parse_initializer *params, struct vkd3d_shader_location loc)
+{
- struct hlsl_ir_swizzle *arg1_swzl1, *arg1_swzl2, *arg2_swzl1, *arg2_swzl2;
- struct hlsl_ir_node *arg1 = params->args[0], *arg2 = params->args[1];
- struct hlsl_ir_node *arg1_cast, *arg2_cast, *mul1_neg;
- struct hlsl_ir_expr *mul1, *mul2;
- struct hlsl_type *cast_type;
- enum hlsl_base_type base;
- if (arg1->data_type->base_type == HLSL_TYPE_HALF && arg2->data_type->base_type == HLSL_TYPE_HALF)
base = HLSL_TYPE_HALF;
- else
base = HLSL_TYPE_FLOAT;
- cast_type = hlsl_get_vector_type(ctx, base, 3);
- if (!(arg1_cast = add_implicit_conversion(ctx, params->instrs, arg1, cast_type, &loc)))
return false;
- if (!(arg2_cast = add_implicit_conversion(ctx, params->instrs, arg2, cast_type, &loc)))
return false;
- if (!(arg1_swzl1 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Z, X, Y, Z), 3, arg1_cast, &loc)))
return false;
- list_add_tail(params->instrs, &arg1_swzl1->node.entry);
- if (!(arg2_swzl1 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Y, Z, X, Y), 3, arg2_cast, &loc)))
return false;
- list_add_tail(params->instrs, &arg2_swzl1->node.entry);
- if (!(mul1 = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL,
&arg1_swzl1->node, &arg2_swzl1->node, &loc)))
return false;
- if (!(mul1_neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, &mul1->node, loc)))
return false;
- list_add_tail(params->instrs, &mul1_neg->entry);
- if (!(arg1_swzl2 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Y, Z, X, Y), 3, arg1_cast, &loc)))
return false;
- list_add_tail(params->instrs, &arg1_swzl2->node.entry);
- if (!(arg2_swzl2 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Z, X, Y, Z), 3, arg2_cast, &loc)))
return false;
- list_add_tail(params->instrs, &arg2_swzl2->node.entry);
- if (!(mul2 = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL,
&arg1_swzl2->node, &arg2_swzl2->node, &loc)))
return false;
- return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, &mul2->node, mul1_neg, &loc);
+}
- static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) {
@@ -1635,6 +1689,7 @@ intrinsic_functions[] = /* Note: these entries should be kept in alphabetical order. */ {"abs", 1, true, intrinsic_abs}, {"clamp", 3, true, intrinsic_clamp},
- {"cross", 2, true, intrinsic_cross}, {"max", 2, true, intrinsic_max}, {"pow", 2, true, intrinsic_pow}, {"round", 1, true, intrinsic_round},
On 11/19/21 8:38 AM, Matteo Bruni wrote:
From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com
v5: More rebase action...
Nice patch btw.
Makefile.am | 2 ++ libs/vkd3d-shader/hlsl.y | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
You seem to have dropped the tests from this one...
On Fri, Nov 19, 2021 at 6:30 PM Zebediah Figura zfigura@codeweavers.com wrote:
On 11/19/21 8:38 AM, Matteo Bruni wrote:
From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com
v5: More rebase action...
Nice patch btw.
Makefile.am | 2 ++ libs/vkd3d-shader/hlsl.y | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
You seem to have dropped the tests from this one...
Excellent... I was sure that I amended the commit before sending, I guess not...
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
On 19/11/21 15:38, Matteo Bruni wrote:
From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Makefile.am | 1 + libs/vkd3d-shader/hlsl.c | 1 + libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 8 ++++++++ libs/vkd3d-shader/hlsl_sm4.c | 4 ++++ tests/round.shader_test | 26 ++++++++++++++++++++++++++ 6 files changed, 41 insertions(+) create mode 100644 tests/round.shader_test
diff --git a/Makefile.am b/Makefile.am index 3e083b0a..6d392e1d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -91,6 +91,7 @@ vkd3d_shader_tests = \ tests/preproc-invalid.shader_test \ tests/preproc-macro.shader_test \ tests/preproc-misc.shader_test \
- tests/round.shader_test \ tests/sampler.shader_test \ tests/saturate.shader_test \ tests/swizzle-0.shader_test \
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 1eee4278..9824c56d 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1156,6 +1156,7 @@ const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op) [HLSL_OP1_NEG] = "-", [HLSL_OP1_NRM] = "nrm", [HLSL_OP1_RCP] = "rcp",
[HLSL_OP1_ROUND] = "round", [HLSL_OP1_RSQ] = "rsq", [HLSL_OP1_SAT] = "sat", [HLSL_OP1_SIGN] = "sign",
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 365ef980..e7bdb45e 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -299,6 +299,7 @@ enum hlsl_ir_expr_op HLSL_OP1_NEG, HLSL_OP1_NRM, HLSL_OP1_RCP,
- HLSL_OP1_ROUND, HLSL_OP1_RSQ, HLSL_OP1_SAT, HLSL_OP1_SIGN,
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index b7e0409d..abf5da91 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1611,6 +1611,12 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx, return true; }
+static bool intrinsic_round(struct hlsl_ctx *ctx,
const struct parse_initializer *params, struct vkd3d_shader_location loc)
+{
- return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ROUND, params->args[0], &loc);
+}
- static bool intrinsic_saturate(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) {
@@ -1626,10 +1632,12 @@ static const struct intrinsic_function } intrinsic_functions[] = {
- /* Note: these entries should be kept in alphabetical order. */ {"abs", 1, true, intrinsic_abs}, {"clamp", 3, true, intrinsic_clamp}, {"max", 2, true, intrinsic_max}, {"pow", 2, true, intrinsic_pow},
- {"round", 1, true, intrinsic_round}, {"saturate", 1, true, intrinsic_saturate}, };
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index a95503ee..c0c26f80 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1305,6 +1305,10 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, VKD3D_SM4_REGISTER_MODIFIER_NEGATE); break;
case HLSL_OP1_ROUND:
write_sm4_unary_op(buffer, VKD3D_SM4_OP_ROUND_NE, &expr->node, arg1, 0);
break;
case HLSL_OP1_SAT: write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV | (VKD3D_SM4_INSTRUCTION_FLAG_SATURATE << VKD3D_SM4_INSTRUCTION_FLAGS_SHIFT),
diff --git a/tests/round.shader_test b/tests/round.shader_test new file mode 100644 index 00000000..d8eb11b7 --- /dev/null +++ b/tests/round.shader_test @@ -0,0 +1,26 @@ +[pixel shader] +float4 main(uniform float4 u) : sv_target +{
- return round(u);
+}
+[test] +uniform 0 float4 -0.5 6.5 7.5 3.4 +draw quad +probe all rgba (0.0, 6.0, 8.0, 3.0) 4
+[pixel shader] +float4 main(uniform float4 u) : sv_target +{
- float a = round(u.r);
- int2 b = round(u.gb);
- float4 res = float4(b, a, u.a);
- return round(res);
+}
+[test] +uniform 0 float4 -0.5 6.5 7.5 3.4 +draw quad +probe all rgba (6.0, 8.0, 0.0, 3.0) 4