-- v5: vkd3d-shader/hlsl: Support log() intrinsic. vkd3d-shader/hlsl: Support log10() intrinsic. vkd3d-shader/hlsl: Support log2() intrinsic. vkd3d-shader/hlsl: Write 'log' instruction for SM1.
From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/hlsl_sm1.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_sm1.c b/libs/vkd3d-shader/hlsl_sm1.c index 4a62d804..a8dbfcfb 100644 --- a/libs/vkd3d-shader/hlsl_sm1.c +++ b/libs/vkd3d-shader/hlsl_sm1.c @@ -723,6 +723,10 @@ static void write_sm1_expr(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *b write_sm1_per_component_unary_op(ctx, buffer, instr, D3DSIO_EXP); break;
+ case HLSL_OP1_LOG2: + write_sm1_per_component_unary_op(ctx, buffer, instr, D3DSIO_LOG); + break; + case HLSL_OP1_NEG: write_sm1_unary_op(ctx, buffer, D3DSIO_MOV, &instr->reg, &arg1->reg, D3DSPSM_NEG, 0); break;
From: Nikolay Sivov nsivov@codeweavers.com
--- Makefile.am | 1 + libs/vkd3d-shader/hlsl.y | 12 ++++++++++++ tests/log.shader_test | 12 ++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 tests/log.shader_test
diff --git a/Makefile.am b/Makefile.am index 6ac8ffb2..2e649496 100644 --- a/Makefile.am +++ b/Makefile.am @@ -121,6 +121,7 @@ vkd3d_shader_tests = \ tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing-uniform.shader_test \ tests/lit.shader_test \ + tests/log.shader_test \ tests/logic-operations.shader_test \ tests/majority-syntax.shader_test \ tests/math.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index fd1eaf6e..512c828c 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2779,6 +2779,17 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx, return true; }
+static bool intrinsic_log2(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_LOG2, arg, loc); +} + static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -3236,6 +3247,7 @@ intrinsic_functions[] = {"length", 1, true, intrinsic_length}, {"lerp", 3, true, intrinsic_lerp}, {"lit", 3, true, intrinsic_lit}, + {"log2", 1, true, intrinsic_log2}, {"max", 2, true, intrinsic_max}, {"min", 2, true, intrinsic_min}, {"mul", 2, true, intrinsic_mul}, diff --git a/tests/log.shader_test b/tests/log.shader_test new file mode 100644 index 00000000..9ba0af76 --- /dev/null +++ b/tests/log.shader_test @@ -0,0 +1,12 @@ +[pixel shader] +uniform float4 x; + +float4 main() : sv_target +{ + return log2(x); +} + +[test] +uniform 0 float4 2.0 4.0 5.0 0.4 +draw quad +probe all rgba (1.0, 2.0, 2.32192802, -1.32192802) 1
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 20 ++++++++++++++++++++ tests/log.shader_test | 13 +++++++++++++ 2 files changed, 33 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 512c828c..da6f8777 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2779,6 +2779,25 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx, return true; }
+static bool intrinsic_log10(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_constant *coeff; + struct hlsl_ir_node *log, *arg; + + if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) + return false; + + if (!(log = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_LOG2, arg, loc))) + return false; + + /* 1 / log2(10) */ + if (!(coeff = hlsl_new_float_constant(ctx, 0.301029996f, loc))) + return false; + + return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, log, &coeff->node, loc); +} + static bool intrinsic_log2(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -3247,6 +3266,7 @@ intrinsic_functions[] = {"length", 1, true, intrinsic_length}, {"lerp", 3, true, intrinsic_lerp}, {"lit", 3, true, intrinsic_lit}, + {"log10", 1, true, intrinsic_log10}, {"log2", 1, true, intrinsic_log2}, {"max", 2, true, intrinsic_max}, {"min", 2, true, intrinsic_min}, diff --git a/tests/log.shader_test b/tests/log.shader_test index 9ba0af76..0a99904a 100644 --- a/tests/log.shader_test +++ b/tests/log.shader_test @@ -10,3 +10,16 @@ float4 main() : sv_target uniform 0 float4 2.0 4.0 5.0 0.4 draw quad probe all rgba (1.0, 2.0, 2.32192802, -1.32192802) 1 + +[pixel shader] +uniform float4 x; + +float4 main() : sv_target +{ + return log10(x); +} + +[test] +uniform 0 float4 10.0 100.0 1.0 0.1 +draw quad +probe all rgba (1.0, 2.0, 0.0, -1.0) 1
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 20 ++++++++++++++++++++ tests/log.shader_test | 13 +++++++++++++ 2 files changed, 33 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index da6f8777..9f420a7f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2779,6 +2779,25 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx, return true; }
+static bool intrinsic_log(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_constant *coeff; + struct hlsl_ir_node *log, *arg; + + if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) + return false; + + if (!(log = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_LOG2, arg, loc))) + return false; + + /* ln(2) */ + if (!(coeff = hlsl_new_float_constant(ctx, 0.69314718055f, loc))) + return false; + + return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, log, &coeff->node, loc); +} + static bool intrinsic_log10(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -3266,6 +3285,7 @@ intrinsic_functions[] = {"length", 1, true, intrinsic_length}, {"lerp", 3, true, intrinsic_lerp}, {"lit", 3, true, intrinsic_lit}, + {"log", 1, true, intrinsic_log}, {"log10", 1, true, intrinsic_log10}, {"log2", 1, true, intrinsic_log2}, {"max", 2, true, intrinsic_max}, diff --git a/tests/log.shader_test b/tests/log.shader_test index 0a99904a..b0f405d1 100644 --- a/tests/log.shader_test +++ b/tests/log.shader_test @@ -23,3 +23,16 @@ float4 main() : sv_target uniform 0 float4 10.0 100.0 1.0 0.1 draw quad probe all rgba (1.0, 2.0, 0.0, -1.0) 1 + +[pixel shader] +uniform float4 x; + +float4 main() : sv_target +{ + return log(x); +} + +[test] +uniform 0 float4 3.0 10.0 1.0 0.1 +draw quad +probe all rgba (1.0986123, 2.302585, 0.0, -2.302585) 2