vkd3d-shader/hlsl: Implement the faceforward() intrinsic.

This commit is contained in:
Petrichor Park 2024-06-21 10:19:17 -05:00 committed by Henri Verbeet
parent 60c8a813a3
commit 746222b349
Notes: Henri Verbeet 2024-07-09 21:11:07 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/929
3 changed files with 82 additions and 0 deletions

View File

@ -108,6 +108,7 @@ vkd3d_shader_tests = \
tests/hlsl/entry-point-semantics.shader_test \ tests/hlsl/entry-point-semantics.shader_test \
tests/hlsl/exp.shader_test \ tests/hlsl/exp.shader_test \
tests/hlsl/expr-indexing.shader_test \ tests/hlsl/expr-indexing.shader_test \
tests/hlsl/faceforward.shader_test \
tests/hlsl/float-comparison.shader_test \ tests/hlsl/float-comparison.shader_test \
tests/hlsl/floor.shader_test \ tests/hlsl/floor.shader_test \
tests/hlsl/fmod.shader_test \ tests/hlsl/fmod.shader_test \

View File

@ -3614,6 +3614,34 @@ static bool intrinsic_exp2(struct hlsl_ctx *ctx,
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_EXP2, arg, loc); return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_EXP2, arg, loc);
} }
static bool intrinsic_faceforward(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_function_decl *func;
struct hlsl_type *type;
char *body;
static const char template[] =
"%s faceforward(%s n, %s i, %s ng)\n"
"{\n"
" return dot(i, ng) < 0 ? n : -n;\n"
"}\n";
if (!(type = elementwise_intrinsic_get_common_type(ctx, params, loc)))
return false;
type = hlsl_get_numeric_type(ctx, type->class, HLSL_TYPE_FLOAT, type->dimx, type->dimy);
if (!(body = hlsl_sprintf_alloc(ctx, template,
type->name, type->name, type->name, type->name)))
return false;
func = hlsl_compile_internal_function(ctx, "faceforward", body);
vkd3d_free(body);
if (!func)
return false;
return add_user_call(ctx, func, params, loc);
}
static bool intrinsic_floor(struct hlsl_ctx *ctx, static bool intrinsic_floor(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)
{ {
@ -4687,6 +4715,7 @@ intrinsic_functions[] =
{"dot", 2, true, intrinsic_dot}, {"dot", 2, true, intrinsic_dot},
{"exp", 1, true, intrinsic_exp}, {"exp", 1, true, intrinsic_exp},
{"exp2", 1, true, intrinsic_exp2}, {"exp2", 1, true, intrinsic_exp2},
{"faceforward", 3, true, intrinsic_faceforward},
{"floor", 1, true, intrinsic_floor}, {"floor", 1, true, intrinsic_floor},
{"fmod", 2, true, intrinsic_fmod}, {"fmod", 2, true, intrinsic_fmod},
{"frac", 1, true, intrinsic_frac}, {"frac", 1, true, intrinsic_frac},

View File

@ -0,0 +1,52 @@
[pixel shader]
uniform float4 n;
uniform float4 i;
uniform float4 ng;
float4 main() : sv_target
{
return faceforward(n, i, ng);
}
[test]
uniform 0 float4 10.0 20.0 30.0 40.0
uniform 4 float4 1.0 0.0 0.0 0.0
uniform 8 float4 1.0 0.2 0.0 0.0
todo(glsl) draw quad
probe (0, 0) rgba (-10.0, -20.0, -30.0, -40.0)
uniform 0 float4 10.0 20.0 30.0 40.0
uniform 4 float4 1.0 0.0 0.0 0.0
uniform 8 float4 1.0 -0.2 0.0 0.0
todo(glsl) draw quad
probe (0, 0) rgba (-10.0, -20.0, -30.0, -40.0)
uniform 0 float4 10.0 20.0 30.0 40.0
uniform 4 float4 1.0 0.0 0.0 0.0
uniform 8 float4 -1.0 0.0 0.0 0.0
todo(glsl) draw quad
probe (0, 0) rgba (10.0, 20.0, 30.0, 40.0)
uniform 0 float4 10.0 20.0 30.0 40.0
uniform 4 float4 0.0 -1.0 0.0 0.0
uniform 8 float4 0.0 1.0 0.0 0.0
todo(glsl) draw quad
probe (0, 0) rgba (10.0, 20.0, 30.0, 40.0)
uniform 0 float4 10.0 20.0 30.0 40.0
uniform 4 float4 1.0 0.0 0.0 0.0
uniform 8 float4 0.0 1.0 0.0 0.0
todo(glsl) draw quad
probe (0, 0) rgba (-10.0, -20.0, -30.0, -40.0)
uniform 0 float4 10.0 20.0 30.0 40.0
uniform 4 float4 0.0 0.0 0.0 0.0
uniform 8 float4 0.0 1.0 0.0 0.0
todo(glsl) draw quad
probe (0, 0) rgba (-10.0, -20.0, -30.0, -40.0)
uniform 0 float4 10.0 20.0 30.0 40.0
uniform 4 float4 0.0 0.0 0.0 0.0
uniform 8 float4 0.0 0.0 0.0 0.0
todo(glsl) draw quad
probe (0, 0) rgba (-10.0, -20.0, -30.0, -40.0)