From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v5: Rebased on top of current git.
libs/vkd3d-shader/hlsl.y | 19 ++++++++++++++++++- tests/round.shader_test | 13 +++++++++++++ tests/shader_runner.c | 8 ++++++++ 3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index be24a749..8d7b1243 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1570,6 +1570,18 @@ static const struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *c return args.decl; }
+static struct hlsl_ir_node *intrinsic_float_convert_arg(struct hlsl_ctx *ctx, + const struct parse_initializer *params, struct hlsl_ir_node *arg, const struct vkd3d_shader_location *loc) +{ + struct hlsl_type *type = arg->data_type; + + if (type->base_type == HLSL_TYPE_FLOAT || type->base_type == HLSL_TYPE_HALF) + return arg; + + type = hlsl_get_numeric_type(ctx, type->type, HLSL_TYPE_FLOAT, type->dimx, type->dimy); + return add_implicit_conversion(ctx, params->instrs, arg, type, loc); +} + static bool intrinsic_abs(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -1675,7 +1687,12 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx, static bool intrinsic_round(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { - return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ROUND, params->args[0], loc); + struct hlsl_ir_node *arg; + + if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) + return false; + + return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ROUND, arg, loc); }
static bool intrinsic_saturate(struct hlsl_ctx *ctx, diff --git a/tests/round.shader_test b/tests/round.shader_test index d8eb11b7..cc5a6975 100644 --- a/tests/round.shader_test +++ b/tests/round.shader_test @@ -24,3 +24,16 @@ float4 main(uniform float4 u) : sv_target 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 + + + +[pixel shader] +float4 main(uniform int4 u) : sv_target +{ + return round(u); +} + +[test] +uniform 0 int4 -1 0 2 10 +draw quad +probe all rgba (-1.0, 0.0, 2.0, 10.0) 4 diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 5af4628e..558d074d 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -368,6 +368,14 @@ static void parse_test_directive(struct shader_context *context, const char *lin fatal_error("Malformed float constant '%s'.\n", line); set_uniforms(context, offset, 1, &f); } + else if (match_string(line, "int4", &line)) + { + int v[4]; + + if (sscanf(line, "%d %d %d %d", &v[0], &v[1], &v[2], &v[3]) < 4) + fatal_error("Malformed int4 constant '%s'.\n", line); + set_uniforms(context, offset, 4, v); + } else if (match_string(line, "int", &line)) { int i;
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v5: Unchanged.
libs/vkd3d-shader/hlsl.y | 7 ++++++- tests/saturate.shader_test | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8d7b1243..dd2a93e1 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1698,7 +1698,12 @@ static bool intrinsic_round(struct hlsl_ctx *ctx, static bool intrinsic_saturate(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { - return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_SAT, params->args[0], loc); + struct hlsl_ir_node *arg; + + if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) + return false; + + return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_SAT, arg, loc); }
static const struct intrinsic_function diff --git a/tests/saturate.shader_test b/tests/saturate.shader_test index 0a954e7f..e99df5b3 100644 --- a/tests/saturate.shader_test +++ b/tests/saturate.shader_test @@ -8,3 +8,14 @@ float4 main(uniform float2 u) : sv_target uniform 0 float4 0.7 -0.1 0.0 0.0 draw quad probe all rgba (0.7, 0.0, 1.0, 0.0) + +[pixel shader] +float4 main(uniform int4 u) : sv_target +{ + return saturate(u); +} + +[test] +uniform 0 int4 -2 0 2 -1 +draw quad +probe all rgba (0.0, 0.0, 1.0, 0.0)
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v5: Unchanged.
Makefile.am | 1 + libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 12 ++++++++++++ libs/vkd3d-shader/hlsl_sm4.c | 4 ++++ tests/floor.shader_test | 38 ++++++++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 tests/floor.shader_test
diff --git a/Makefile.am b/Makefile.am index 82807a42..5bcee677 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,6 +57,7 @@ vkd3d_shader_tests = \ tests/cast-to-int.shader_test \ tests/cast-to-uint.shader_test \ tests/conditional.shader_test \ + tests/floor.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ tests/hlsl-clamp.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 2319895a..5b69186c 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -293,6 +293,7 @@ enum hlsl_ir_expr_op HLSL_OP1_DSX, HLSL_OP1_DSY, HLSL_OP1_EXP2, + HLSL_OP1_FLOOR, HLSL_OP1_FRACT, HLSL_OP1_LOG2, HLSL_OP1_LOGIC_NOT, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index dd2a93e1..5b98b569 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1653,6 +1653,17 @@ static bool intrinsic_cross(struct hlsl_ctx *ctx, return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, &mul2->node, mul1_neg, loc); }
+static bool intrinsic_floor(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *arg; + + if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) + return false; + + return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_FLOOR, arg, loc); +} + static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -1720,6 +1731,7 @@ intrinsic_functions[] = {"abs", 1, true, intrinsic_abs}, {"clamp", 3, true, intrinsic_clamp}, {"cross", 2, true, intrinsic_cross}, + {"floor", 1, true, intrinsic_floor}, {"max", 2, true, intrinsic_max}, {"min", 2, true, intrinsic_min}, {"pow", 2, true, intrinsic_pow}, diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 4eebd583..b66a2258 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1432,6 +1432,10 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, write_sm4_unary_op(buffer, VKD3D_SM4_OP_EXP, &expr->node, arg1, 0); break;
+ case HLSL_OP1_FLOOR: + write_sm4_unary_op(buffer, VKD3D_SM4_OP_ROUND_NI, &expr->node, arg1, 0); + break; + case HLSL_OP1_LOG2: write_sm4_unary_op(buffer, VKD3D_SM4_OP_LOG, &expr->node, arg1, 0); break; diff --git a/tests/floor.shader_test b/tests/floor.shader_test new file mode 100644 index 00000000..033d759c --- /dev/null +++ b/tests/floor.shader_test @@ -0,0 +1,38 @@ +[pixel shader] +float4 main(uniform float4 u) : sv_target +{ + return floor(u); +} + +[test] +uniform 0 float4 -0.5 6.5 7.5 3.4 +draw quad +probe all rgba (-1.0, 6.0, 7.0, 3.0) 4 + +[pixel shader] +float4 main(uniform float4 u) : sv_target +{ + float a = floor(u.r); + int2 b = floor(u.gb); + float4 res = float4(b, a, u.a); + return floor(res); +} + +[test] +uniform 0 float4 -0.5 6.5 7.5 3.4 +draw quad +probe all rgba (6.0, 7.0, -1.0, 3.0) 4 + +[pixel shader] +float4 main(uniform int4 u) : sv_target +{ + float a = floor(u.r); + int2 b = floor(u.gb); + float4 res = float4(b, a, u.a); + return floor(res); +} + +[test] +uniform 0 int4 -1 6 7 3 +draw quad +probe all rgba (6.0, 7.0, -1.0, 3.0) 4
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Zebediah Figura zfigura@codeweavers.com
Technically we shouldn't allow "uu" or "ll" either, but we also don't really handle preprocessor parsing errors the way we should.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v2: Unchanged.
libs/vkd3d-shader/preproc.l | 7 ++++--- tests/preproc-if-expr.shader_test | 33 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index bf4d669f..54542331 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -57,6 +57,7 @@ static void update_location(struct preproc_ctx *ctx); NEWLINE \r?\n WS [ \t] IDENTIFIER [A-Za-z_][A-Za-z0-9_]* +INT_SUFFIX [uUlL]{0,2}
%%
@@ -92,9 +93,9 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* <INITIAL>[0-9]+.([eE][+-]?[0-9]+)?[hHfF]? {return T_TEXT;} <INITIAL>[0-9]+([eE][+-]?[0-9]+)?[hHfF] {return T_TEXT;} <INITIAL>[0-9]+[eE][+-]?[0-9]+ {return T_TEXT;} -<INITIAL,LINE>0[xX][0-9a-fA-f]+[ul]{0,2} {return T_INTEGER;} -<INITIAL,LINE>0[0-7]*[ul]{0,2} {return T_INTEGER;} -<INITIAL,LINE>[1-9][0-9]*[ul]{0,2} {return T_INTEGER;} +<INITIAL,LINE>0[xX][0-9a-fA-f]+{INT_SUFFIX} {return T_INTEGER;} +<INITIAL,LINE>0[0-7]*{INT_SUFFIX} {return T_INTEGER;} +<INITIAL,LINE>[1-9][0-9]*{INT_SUFFIX} {return T_INTEGER;}
<INITIAL>## {return T_CONCAT;}
diff --git a/tests/preproc-if-expr.shader_test b/tests/preproc-if-expr.shader_test index 61c5a397..823b9b0e 100644 --- a/tests/preproc-if-expr.shader_test +++ b/tests/preproc-if-expr.shader_test @@ -99,6 +99,39 @@ pass pass #endif
+[preproc] +#if 2u == 2 +pass +#else +fail +#endif + +[preproc] +#if 2l == 2 +pass +#else +fail +#endif + +[preproc] +#if 2Ul == 2 +pass +#else +fail +#endif + +[preproc] +#if 2uL == 2 +pass +#else +fail +#endif + +[preproc] +#if 012lu == 10 +pass +#endif + [preproc] /* All math is done using unsigned 32-bit integers. */ #if 8 / -3 == 2
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
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: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v3: Rebased on top of current git.
Makefile.am | 4 ++ .../hlsl-initializer-local-array.shader_test | 35 ++++++++++++++++++ .../hlsl-initializer-static-array.shader_test | 37 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 tests/hlsl-initializer-local-array.shader_test create mode 100644 tests/hlsl-initializer-static-array.shader_test
diff --git a/Makefile.am b/Makefile.am index 5bcee677..84c7b859 100644 --- a/Makefile.am +++ b/Makefile.am @@ -68,6 +68,8 @@ vkd3d_shader_tests = \ tests/hlsl-function-overload.shader_test \ tests/hlsl-gather-offset.shader_test \ tests/hlsl-gather.shader_test \ + tests/hlsl-initializer-local-array.shader_test \ + tests/hlsl-initializer-static-array.shader_test \ tests/hlsl-intrinsic-override.shader_test \ tests/hlsl-invalid.shader_test \ tests/hlsl-majority-pragma.shader_test \ @@ -295,6 +297,8 @@ XFAIL_TESTS = \ tests/cast-to-int.shader_test \ tests/cast-to-uint.shader_test \ tests/hlsl-array-dimension.shader_test \ + tests/hlsl-initializer-local-array.shader_test \ + tests/hlsl-initializer-static-array.shader_test \ tests/hlsl-bool-cast.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ diff --git a/tests/hlsl-initializer-local-array.shader_test b/tests/hlsl-initializer-local-array.shader_test new file mode 100644 index 00000000..0862d4c9 --- /dev/null +++ b/tests/hlsl-initializer-local-array.shader_test @@ -0,0 +1,35 @@ +[pixel shader] +float4 main() : SV_TARGET +{ + float4 array_loc[3] = { + 11, 12, 13, 14, + 21, 22, 23, 24, + 31, 32, 33, 34 + }; + return array_loc[1]; +} + +[test] +draw quad +probe all rgba (21, 22, 23, 24) + + +[pixel shader] +float4 main() : SV_TARGET +{ + float4 array_loc[2][4] = { + 11, 12, 13, 14, + 21, 22, 23, 24, + 31, 32, 33, 34, + 41, 42, 43, 44, + 51, 52, 53, 54, + 61, 62, 63, 64, + 71, 72, 73, 74, + 81, 82, 83, 84, + }; + return array_loc[1][2]; +} + +[test] +draw quad +probe all rgba (71, 72, 73, 74) diff --git a/tests/hlsl-initializer-static-array.shader_test b/tests/hlsl-initializer-static-array.shader_test new file mode 100644 index 00000000..57733502 --- /dev/null +++ b/tests/hlsl-initializer-static-array.shader_test @@ -0,0 +1,37 @@ +[pixel shader] +static const float4 array_st[3] = { + 11, 12, 13, 14, + 21, 22, 23, 24, + 31, 32, 33, 34 +}; + +float4 main() : SV_TARGET +{ + return array_st[1]; +} + +[test] +draw quad +probe all rgba (21, 22, 23, 24) + + +[pixel shader] +static const float4 array_st[4][2] = { + 11, 12, 13, 14, + 21, 22, 23, 24, + 31, 32, 33, 34, + 41, 42, 43, 44, + 51, 52, 53, 54, + 61, 62, 63, 64, + 71, 72, 73, 74, + 81, 82, 83, 84, +}; + +float4 main() : SV_TARGET +{ + return array_st[2][1]; +} + +[test] +draw quad +probe all rgba (61, 62, 63, 64)
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com