From 6fbf2b3e75ed7f85c413233a3326b79e0631d9d8 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Fri, 13 Jan 2023 15:58:15 -0300 Subject: [PATCH] vkd3d-shader/hlsl: Parse sqrt() intrinsic. --- libs/vkd3d-shader/hlsl.y | 12 ++++++++++++ tests/sqrt.shader_test | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 35be0f12..88bfabe4 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2817,6 +2817,17 @@ static bool intrinsic_smoothstep(struct hlsl_ctx *ctx, return true; } +static bool intrinsic_sqrt(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_SQRT, arg, loc); +} + static bool intrinsic_transpose(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -2905,6 +2916,7 @@ intrinsic_functions[] = {"saturate", 1, true, intrinsic_saturate}, {"sin", 1, true, intrinsic_sin}, {"smoothstep", 3, true, intrinsic_smoothstep}, + {"sqrt", 1, true, intrinsic_sqrt}, {"transpose", 1, true, intrinsic_transpose}, }; diff --git a/tests/sqrt.shader_test b/tests/sqrt.shader_test index 81bf99a4..5d048b4f 100644 --- a/tests/sqrt.shader_test +++ b/tests/sqrt.shader_test @@ -1,4 +1,4 @@ -[pixel shader todo] +[pixel shader] uniform float4 f; float4 main() : sv_target @@ -8,5 +8,5 @@ float4 main() : sv_target [test] uniform 0 float4 1.0 9.0 32.3 46.5 -todo draw quad -todo probe all rgba (1.0, 3.0, 5.683309, 6.819091) 1 +draw quad +probe all rgba (1.0, 3.0, 5.683309, 6.819091) 1