vkd3d-shader/hlsl: Support refract() intrinsic.

With some changes by Giovanni Mascellani.
This commit is contained in:
Nikolay Sivov 2023-09-07 14:16:15 +02:00 committed by Alexandre Julliard
parent fd9e1a87ff
commit 8d78e3a821
Notes: Alexandre Julliard 2024-04-11 17:05:13 -05: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/769
2 changed files with 75 additions and 21 deletions

View File

@ -3740,6 +3740,59 @@ static bool intrinsic_reflect(struct hlsl_ctx *ctx,
return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, i, neg, loc); return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, i, neg, loc);
} }
static bool intrinsic_refract(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
struct hlsl_type *r_type = params->args[0]->data_type;
struct hlsl_type *n_type = params->args[1]->data_type;
struct hlsl_type *i_type = params->args[2]->data_type;
struct hlsl_type *res_type, *idx_type, *scal_type;
struct parse_initializer mut_params;
struct hlsl_ir_function_decl *func;
enum hlsl_base_type base;
char *body;
static const char template[] =
"%s refract(%s r, %s n, %s i)\n"
"{\n"
" %s d, t;\n"
" d = dot(r, n);\n"
" t = 1 - i.x * i.x * (1 - d * d);\n"
" return t >= 0.0 ? i.x * r - (i.x * d + sqrt(t)) * n : 0;\n"
"}";
if (r_type->class == HLSL_CLASS_MATRIX
|| n_type->class == HLSL_CLASS_MATRIX
|| i_type->class == HLSL_CLASS_MATRIX)
{
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Matrix arguments are not supported.");
return false;
}
assert(params->args_count == 3);
mut_params = *params;
mut_params.args_count = 2;
if (!(res_type = elementwise_intrinsic_get_common_type(ctx, &mut_params, loc)))
return false;
base = expr_common_base_type(res_type->base_type, i_type->base_type);
base = base == HLSL_TYPE_HALF ? HLSL_TYPE_HALF : HLSL_TYPE_FLOAT;
res_type = convert_numeric_type(ctx, res_type, base);
idx_type = convert_numeric_type(ctx, i_type, base);
scal_type = hlsl_get_scalar_type(ctx, base);
if (!(body = hlsl_sprintf_alloc(ctx, template, res_type->name, res_type->name,
res_type->name, idx_type->name, scal_type->name)))
return false;
func = hlsl_compile_internal_function(ctx, "refract", body);
vkd3d_free(body);
if (!func)
return false;
return add_user_call(ctx, func, params, loc);
}
static bool intrinsic_round(struct hlsl_ctx *ctx, static bool intrinsic_round(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)
{ {
@ -4255,6 +4308,7 @@ intrinsic_functions[] =
{"pow", 2, true, intrinsic_pow}, {"pow", 2, true, intrinsic_pow},
{"radians", 1, true, intrinsic_radians}, {"radians", 1, true, intrinsic_radians},
{"reflect", 2, true, intrinsic_reflect}, {"reflect", 2, true, intrinsic_reflect},
{"refract", 3, true, intrinsic_refract},
{"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},

View File

@ -1,4 +1,4 @@
[pixel shader todo(sm<6)] [pixel shader]
float4 r; float4 r;
float4 n; float4 n;
float i; float i;
@ -12,13 +12,13 @@ float4 main() : sv_target
uniform 0 float4 0.5 -0.1 0.2 0.3 uniform 0 float4 0.5 -0.1 0.2 0.3
uniform 4 float4 0.6 0.4 -0.3 1.0 uniform 4 float4 0.6 0.4 -0.3 1.0
uniform 8 float 0.2 uniform 8 float 0.2
todo(sm<6 | glsl) draw quad todo(glsl) draw quad
probe all rgba (-0.550931, -0.453954, 0.3654653, -1.0248856) 32 probe all rgba (-0.550931, -0.453954, 0.3654653, -1.0248856) 32
uniform 8 float 100.0 uniform 8 float 100.0
todo(sm<6 | glsl) draw quad todo(glsl) draw quad
probe all rgba (0.0, 0.0, 0.0, 0.0) probe all rgba (0.0, 0.0, 0.0, 0.0)
[pixel shader todo(sm<6)] [pixel shader]
float4 r; float4 r;
float4 n; float4 n;
float i; float i;
@ -34,13 +34,13 @@ float4 main() : sv_target
uniform 0 float4 0.5 -0.1 0.2 0.3 uniform 0 float4 0.5 -0.1 0.2 0.3
uniform 4 float4 0.6 0.4 -0.3 1.0 uniform 4 float4 0.6 0.4 -0.3 1.0
uniform 8 float 0.2 uniform 8 float 0.2
todo(sm<6 | glsl) draw quad todo(sm<4 | glsl) draw quad
probe all rgba (-0.519904912, -0.4332699, 0.0, 0.0) 32 probe all rgba (-0.519904912, -0.4332699, 0.0, 0.0) 32
uniform 8 float 100.0 uniform 8 float 100.0
todo(sm<6 | glsl) draw quad todo(sm<4 | glsl) draw quad
probe all rgba (0.0, 0.0, 0.0, 0.0) probe all rgba (0.0, 0.0, 0.0, 0.0)
[pixel shader todo(sm<6)] [pixel shader]
float4 r; float4 r;
float4 n; float4 n;
float i; float i;
@ -55,13 +55,13 @@ float4 main() : sv_target
uniform 0 float4 0.5 -0.1 0.2 0.3 uniform 0 float4 0.5 -0.1 0.2 0.3
uniform 4 float4 0.6 0.4 -0.3 1.0 uniform 4 float4 0.6 0.4 -0.3 1.0
uniform 8 float 0.2 uniform 8 float 0.2
todo(sm<6 | glsl) draw quad todo(sm<4 | glsl) draw quad
probe all rgba (-0.519904912, -0.4332699, 0.0, 0.0) 32 probe all rgba (-0.519904912, -0.4332699, 0.0, 0.0) 32
uniform 8 float 100.0 uniform 8 float 100.0
todo(sm<6 | glsl) draw quad todo(sm<4 | glsl) draw quad
probe all rgba (0.0, 0.0, 0.0, 0.0) probe all rgba (0.0, 0.0, 0.0, 0.0)
[pixel shader todo(sm<6)] [pixel shader]
float4 r; float4 r;
float4 n; float4 n;
float i; float i;
@ -76,13 +76,13 @@ float4 main() : sv_target
uniform 0 float4 0.5 -0.1 0.2 0.3 uniform 0 float4 0.5 -0.1 0.2 0.3
uniform 4 float4 0.6 0.4 -0.3 1.0 uniform 4 float4 0.6 0.4 -0.3 1.0
uniform 8 float 0.2 uniform 8 float 0.2
todo(sm<6 | glsl) draw quad todo(sm<4 | glsl) draw quad
probe all rgba (-0.519904912, -0.4332699, 0.0, 0.0) 32 probe all rgba (-0.519904912, -0.4332699, 0.0, 0.0) 32
uniform 8 float 100.0 uniform 8 float 100.0
todo(sm<6 | glsl) draw quad todo(sm<4 | glsl) draw quad
probe all rgba (0.0, 0.0, 0.0, 0.0) probe all rgba (0.0, 0.0, 0.0, 0.0)
[pixel shader todo(sm<6)] [pixel shader]
float4 r; float4 r;
float4 n; float4 n;
float i; float i;
@ -98,13 +98,13 @@ float4 main() : sv_target
uniform 0 float4 0.5 -0.1 0.2 0.3 uniform 0 float4 0.5 -0.1 0.2 0.3
uniform 4 float4 0.6 0.4 -0.3 1.0 uniform 4 float4 0.6 0.4 -0.3 1.0
uniform 8 float 0.2 uniform 8 float 0.2
todo(sm<6 | glsl) draw quad todo(glsl) draw quad
probe all rgba (-0.524978, 0.0, 0.0, 0.0) 32 probe all rgba (-0.524978, 0.0, 0.0, 0.0) 32
uniform 8 float 100.0 uniform 8 float 100.0
todo(sm<6 | glsl) draw quad todo(glsl) draw quad
probe all rgba (0.0, 0.0, 0.0, 0.0) probe all rgba (0.0, 0.0, 0.0, 0.0)
[pixel shader todo(sm<6)] [pixel shader]
float4 r; float4 r;
float4 n; float4 n;
float i; float i;
@ -118,13 +118,13 @@ float4 main() : sv_target
uniform 0 float4 0.5 -0.1 0.2 0.3 uniform 0 float4 0.5 -0.1 0.2 0.3
uniform 4 float4 0.6 0.4 -0.3 1.0 uniform 4 float4 0.6 0.4 -0.3 1.0
uniform 8 float 0.2 uniform 8 float 0.2
todo(sm<6 | glsl) draw quad todo(glsl) draw quad
probe all rgba (-0.5562381, -0.6762381, -0.6162381, -0.5962381) 32 probe all rgba (-0.5562381, -0.6762381, -0.6162381, -0.5962381) 32
uniform 8 float 100.0 uniform 8 float 100.0
todo(sm<6 | glsl) draw quad todo(glsl) draw quad
probe all rgba (0.0, 0.0, 0.0, 0.0) probe all rgba (0.0, 0.0, 0.0, 0.0)
[pixel shader fail(sm>=6) todo(sm<6)] [pixel shader fail(sm>=6)]
float4 r; float4 r;
float4 n; float4 n;
float4 i; float4 i;
@ -138,10 +138,10 @@ float4 main() : sv_target
uniform 0 float4 0.5 -0.1 0.2 0.3 uniform 0 float4 0.5 -0.1 0.2 0.3
uniform 4 float4 0.6 0.4 -0.3 1.0 uniform 4 float4 0.6 0.4 -0.3 1.0
uniform 8 float4 0.2 0.3 0.4 0.5 uniform 8 float4 0.2 0.3 0.4 0.5
if(sm<6) todo(sm<6 | glsl) draw quad if(sm<6) todo(glsl) draw quad
if(sm<6) probe all rgba (-0.550931, -0.453954, 0.3654653, -1.0248856) 32 if(sm<6) probe all rgba (-0.550931, -0.453954, 0.3654653, -1.0248856) 32
uniform 8 float 100.0 uniform 8 float 100.0
if(sm<6) todo(sm<6 | glsl) draw quad if(sm<6) todo(glsl) draw quad
if(sm<6) probe all rgba (0.0, 0.0, 0.0, 0.0) if(sm<6) probe all rgba (0.0, 0.0, 0.0, 0.0)
[pixel shader fail] [pixel shader fail]