mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Add support for sign() intrinsic.
Signed-off-by: Ethan Lee <flibitijibibo@gmail.com>
This commit is contained in:
committed by
Alexandre Julliard
parent
109f7094bc
commit
5d735f3b0e
Notes:
Alexandre Julliard
2023-05-01 22:25:17 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/178
@@ -3165,6 +3165,42 @@ static bool intrinsic_saturate(struct hlsl_ctx *ctx,
|
|||||||
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_SAT, arg, loc);
|
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_SAT, arg, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool intrinsic_sign(struct hlsl_ctx *ctx,
|
||||||
|
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
|
||||||
|
{
|
||||||
|
struct hlsl_ir_node *lt, *neg, *op1, *op2, *arg = params->args[0];
|
||||||
|
struct hlsl_ir_constant *zero;
|
||||||
|
|
||||||
|
struct hlsl_type *int_type = hlsl_get_numeric_type(ctx, arg->data_type->class, HLSL_TYPE_INT,
|
||||||
|
arg->data_type->dimx, arg->data_type->dimy);
|
||||||
|
|
||||||
|
if (!(zero = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, arg->data_type->base_type), loc)))
|
||||||
|
return false;
|
||||||
|
list_add_tail(params->instrs, &zero->node.entry);
|
||||||
|
|
||||||
|
/* Check if 0 < arg, cast bool to int */
|
||||||
|
|
||||||
|
if (!(lt = add_binary_comparison_expr(ctx, params->instrs, HLSL_OP2_LESS, &zero->node, arg, loc)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!(op1 = add_implicit_conversion(ctx, params->instrs, lt, int_type, loc)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* Check if arg < 0, cast bool to int and invert (meaning true is -1) */
|
||||||
|
|
||||||
|
if (!(lt = add_binary_comparison_expr(ctx, params->instrs, HLSL_OP2_LESS, arg, &zero->node, loc)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!(op2 = add_implicit_conversion(ctx, params->instrs, lt, int_type, loc)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!(neg = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_NEG, op2, loc)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* Adding these two together will make 1 when > 0, -1 when < 0, and 0 when neither */
|
||||||
|
return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, neg, op1, loc);
|
||||||
|
}
|
||||||
|
|
||||||
static bool intrinsic_sin(struct hlsl_ctx *ctx,
|
static bool intrinsic_sin(struct hlsl_ctx *ctx,
|
||||||
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
|
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
@@ -3483,6 +3519,7 @@ intrinsic_functions[] =
|
|||||||
{"round", 1, true, intrinsic_round},
|
{"round", 1, true, intrinsic_round},
|
||||||
{"rsqrt", 1, true, intrinsic_rsqrt},
|
{"rsqrt", 1, true, intrinsic_rsqrt},
|
||||||
{"saturate", 1, true, intrinsic_saturate},
|
{"saturate", 1, true, intrinsic_saturate},
|
||||||
|
{"sign", 1, true, intrinsic_sign},
|
||||||
{"sin", 1, true, intrinsic_sin},
|
{"sin", 1, true, intrinsic_sin},
|
||||||
{"smoothstep", 3, true, intrinsic_smoothstep},
|
{"smoothstep", 3, true, intrinsic_smoothstep},
|
||||||
{"sqrt", 1, true, intrinsic_sqrt},
|
{"sqrt", 1, true, intrinsic_sqrt},
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
[pixel shader notimpl]
|
[pixel shader]
|
||||||
uniform float f;
|
uniform float f;
|
||||||
|
|
||||||
float4 main() : sv_target
|
float4 main() : sv_target
|
||||||
@@ -8,16 +8,16 @@ float4 main() : sv_target
|
|||||||
|
|
||||||
[test]
|
[test]
|
||||||
uniform 0 float4 1.0 0.0 0.0 0.0
|
uniform 0 float4 1.0 0.0 0.0 0.0
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (1.0, 1.0, 1.0, 1.0)
|
probe all rgba (1.0, 1.0, 1.0, 1.0)
|
||||||
uniform 0 float4 -1.0 0.0 0.0 0.0
|
uniform 0 float4 -1.0 0.0 0.0 0.0
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (-1.0, -1.0, -1.0, -1.0)
|
probe all rgba (-1.0, -1.0, -1.0, -1.0)
|
||||||
uniform 0 float4 0.0 0.0 0.0 0.0
|
uniform 0 float4 0.0 0.0 0.0 0.0
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (0.0, 0.0, 0.0, 0.0)
|
probe all rgba (0.0, 0.0, 0.0, 0.0)
|
||||||
|
|
||||||
[pixel shader notimpl]
|
[pixel shader]
|
||||||
uniform float4 f;
|
uniform float4 f;
|
||||||
|
|
||||||
float4 main() : sv_target
|
float4 main() : sv_target
|
||||||
@@ -27,10 +27,10 @@ float4 main() : sv_target
|
|||||||
|
|
||||||
[test]
|
[test]
|
||||||
uniform 0 float4 1.0 2.0 3.0 4.0
|
uniform 0 float4 1.0 2.0 3.0 4.0
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (1.0, 1.0, 1.0, 1.0)
|
probe all rgba (1.0, 1.0, 1.0, 1.0)
|
||||||
|
|
||||||
[pixel shader notimpl]
|
[pixel shader]
|
||||||
uniform float2x2 f;
|
uniform float2x2 f;
|
||||||
|
|
||||||
float4 main() : sv_target
|
float4 main() : sv_target
|
||||||
@@ -41,10 +41,10 @@ float4 main() : sv_target
|
|||||||
[test]
|
[test]
|
||||||
uniform 0 float4 1.0 2.0 0.0 0.0
|
uniform 0 float4 1.0 2.0 0.0 0.0
|
||||||
uniform 4 float4 3.0 4.0 0.0 0.0
|
uniform 4 float4 3.0 4.0 0.0 0.0
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (1.0, 1.0, 1.0, 1.0)
|
probe all rgba (1.0, 1.0, 1.0, 1.0)
|
||||||
|
|
||||||
[pixel shader notimpl]
|
[pixel shader]
|
||||||
uniform int f;
|
uniform int f;
|
||||||
|
|
||||||
float4 main() : sv_target
|
float4 main() : sv_target
|
||||||
@@ -54,16 +54,16 @@ float4 main() : sv_target
|
|||||||
|
|
||||||
[test]
|
[test]
|
||||||
uniform 0 int4 1 0 0 0
|
uniform 0 int4 1 0 0 0
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (1, 1, 1, 1)
|
probe all rgba (1, 1, 1, 1)
|
||||||
uniform 0 int4 -1 0 0 0
|
uniform 0 int4 -1 0 0 0
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (-1, -1, -1, -1)
|
probe all rgba (-1, -1, -1, -1)
|
||||||
uniform 0 int4 0 0 0 0
|
uniform 0 int4 0 0 0 0
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (0, 0, 0, 0)
|
probe all rgba (0, 0, 0, 0)
|
||||||
|
|
||||||
[pixel shader notimpl]
|
[pixel shader]
|
||||||
uniform int4 f;
|
uniform int4 f;
|
||||||
|
|
||||||
float4 main() : sv_target
|
float4 main() : sv_target
|
||||||
@@ -73,10 +73,10 @@ float4 main() : sv_target
|
|||||||
|
|
||||||
[test]
|
[test]
|
||||||
uniform 0 int4 1 2 3 4
|
uniform 0 int4 1 2 3 4
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (1, 1, 1, 1)
|
probe all rgba (1, 1, 1, 1)
|
||||||
|
|
||||||
[pixel shader notimpl]
|
[pixel shader]
|
||||||
uniform int2x2 f;
|
uniform int2x2 f;
|
||||||
|
|
||||||
float4 main() : sv_target
|
float4 main() : sv_target
|
||||||
@@ -87,5 +87,5 @@ float4 main() : sv_target
|
|||||||
[test]
|
[test]
|
||||||
uniform 0 int4 1 2 0 0
|
uniform 0 int4 1 2 0 0
|
||||||
uniform 4 int4 3 4 0 0
|
uniform 4 int4 3 4 0 0
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (1, 1, 1, 1)
|
probe all rgba (1, 1, 1, 1)
|
||||||
|
Reference in New Issue
Block a user