-- v3: vkd3d-shader/hlsl: Support all() intrinsic.
From: Nikolay Sivov nsivov@codeweavers.com
--- Makefile.am | 1 + libs/vkd3d-shader/hlsl.y | 32 ++++++++++++++++++++ tests/all.shader_test | 63 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 tests/all.shader_test
diff --git a/Makefile.am b/Makefile.am index f9199472..f7a149ee 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,6 +43,7 @@ vkd3d_cross_tests = \
vkd3d_shader_tests = \ tests/abs.shader_test \ + tests/all.shader_test \ tests/arithmetic-float.shader_test \ tests/arithmetic-float-uniform.shader_test \ tests/arithmetic-int.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 76b0eae7..f003aac1 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2370,6 +2370,37 @@ static bool intrinsic_abs(struct hlsl_ctx *ctx, return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ABS, params->args[0], loc); }
+static bool intrinsic_all(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *arg = params->args[0], *mul; + struct hlsl_ir_constant *one, *zero; + struct hlsl_ir_load *load; + unsigned int i, count; + + if (!(one = hlsl_new_float_constant(ctx, 1.0f, loc))) + return false; + list_add_tail(params->instrs, &one->node.entry); + + if (!(zero = hlsl_new_float_constant(ctx, 0.0f, loc))) + return false; + list_add_tail(params->instrs, &zero->node.entry); + + mul = &one->node; + + count = hlsl_type_component_count(arg->data_type); + for (i = 0; i < count; ++i) + { + if (!(load = add_load_component(ctx, params->instrs, arg, i, loc))) + return false; + + if (!(mul = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, &load->node, mul, loc))) + return false; + } + + return !!add_binary_comparison_expr(ctx, params->instrs, HLSL_OP2_NEQUAL, mul, &zero->node, loc); +} + /* Find the type corresponding to the given source type, with the same * dimensions but a different base type. */ static struct hlsl_type *convert_numeric_type(const struct hlsl_ctx *ctx, @@ -2965,6 +2996,7 @@ intrinsic_functions[] = { /* Note: these entries should be kept in alphabetical order. */ {"abs", 1, true, intrinsic_abs}, + {"all", 1, true, intrinsic_all}, {"asuint", -1, true, intrinsic_asuint}, {"clamp", 3, true, intrinsic_clamp}, {"cos", 1, true, intrinsic_cos}, diff --git a/tests/all.shader_test b/tests/all.shader_test new file mode 100644 index 00000000..7bdb0dc8 --- /dev/null +++ b/tests/all.shader_test @@ -0,0 +1,63 @@ +[require] +shader model >= 4.0 + +[pixel shader] +uniform float4 f; + +float4 main() : sv_target +{ + return all(f); +} + +[test] +uniform 0 float4 -1.1 1.6 1.3 0.5 +draw quad +probe all rgba (1.0, 1.0, 1.0, 1.0) + +[test] +uniform 0 float4 0.0 1.6 1.3 0.5 +draw quad +probe all rgba (0.0, 0.0, 0.0, 0.0) + +[test] +uniform 0 float4 1.0 0.0 1.3 0.5 +draw quad +probe all rgba (0.0, 0.0, 0.0, 0.0) + +[pixel shader] +uniform float f; + +float4 main() : sv_target +{ + return all(f); +} + +[test] +uniform 0 float4 1.0 0.0 0.0 0.0 +draw quad +probe all rgba (1.0, 1.0, 1.0, 1.0) + +[test] +uniform 0 float4 0.0 0.0 0.0 0.0 +draw quad +probe all rgba (0.0, 0.0, 0.0, 0.0) + +[pixel shader] +uniform float2x2 f; + +float4 main() : sv_target +{ + return all(f); +} + +[test] +uniform 0 float4 1.0 2.0 0.0 0.0 +uniform 4 float4 3.0 4.0 0.0 0.0 +draw quad +probe all rgba (1.0, 1.0, 1.0, 1.0) + +[test] +uniform 0 float4 1.0 2.0 0.0 0.0 +uniform 4 float4 0.0 4.0 0.0 0.0 +draw quad +probe all rgba (0.0, 0.0, 0.0, 0.0)
On Thu Feb 16 21:20:12 2023 +0000, Nikolay Sivov wrote:
changed this line in [version 3 of the diff](/wine/vkd3d/-/merge_requests/97/diffs?diff_id=32983&start_sha=43037823fab84225538a2ea2abc57a2e4fc1c4b5#9155b9453b4ec8ea0b9b025dfb55c061bd931610_2397_2394)
I like single loop better, thanks.
This merge request was approved by Henri Verbeet.