Module: vkd3d Branch: master Commit: e5b40092c21da07bab2506cadb0fa6c7c5bb2b96 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/e5b40092c21da07bab2506cadb0fa6...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Wed Feb 15 19:38:47 2023 +0100
vkd3d-shader/hlsl: Support all() intrinsic.
---
Makefile.am | 1 + libs/vkd3d-shader/hlsl.y | 32 ++++++++++++++++++++++++ tests/all.shader_test | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+)
diff --git a/Makefile.am b/Makefile.am index 8822e9eb..c5c75bef 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 2f001611..2b62eccf 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, @@ -2986,6 +3017,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)