diff --git a/Makefile.am b/Makefile.am index 2666194a..7d589819 100644 --- a/Makefile.am +++ b/Makefile.am @@ -46,6 +46,7 @@ vkd3d_cross_tests = \ vkd3d_shader_tests = \ tests/hlsl/abs.shader_test \ tests/hlsl/all.shader_test \ + tests/hlsl/angle-unit.shader_test \ tests/hlsl/any.shader_test \ tests/hlsl/arithmetic-float-uniform.shader_test \ tests/hlsl/arithmetic-float.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 5e0d48d3..a9ff41aa 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3341,6 +3341,22 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx, return !!add_pow_expr(ctx, params->instrs, params->args[0], params->args[1], loc); } +static bool intrinsic_radians(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *arg, *rad; + + if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) + return false; + + /* 1 degree = pi/180 rad = 0.0174532925f rad */ + if (!(rad = hlsl_new_float_constant(ctx, 0.0174532925f, loc))) + return false; + hlsl_block_add_instr(params->instrs, rad); + + return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, arg, rad, loc); +} + static bool intrinsic_reflect(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -3869,6 +3885,7 @@ intrinsic_functions[] = {"mul", 2, true, intrinsic_mul}, {"normalize", 1, true, intrinsic_normalize}, {"pow", 2, true, intrinsic_pow}, + {"radians", 1, true, intrinsic_radians}, {"reflect", 2, true, intrinsic_reflect}, {"round", 1, true, intrinsic_round}, {"rsqrt", 1, true, intrinsic_rsqrt}, diff --git a/tests/hlsl/angle-unit.shader_test b/tests/hlsl/angle-unit.shader_test new file mode 100644 index 00000000..6e0538f9 --- /dev/null +++ b/tests/hlsl/angle-unit.shader_test @@ -0,0 +1,12 @@ +[pixel shader] +uniform float4 a; + +float4 main() : sv_target +{ + return radians(a); +} + +[test] +uniform 0 float4 0.0 30.0 150.0 180.0 +draw quad +probe all rgba (0.0, 0.52359877, 2.61799387, 3.14159265)