Skip to content
Snippets Groups Projects

vkd3d-shader/hlsl: Implement faceforward intrinsic.

Merged Petrichor Park requested to merge petrathekat/vkd3d:impl-faceforward into master
1 unresolved thread
Files
3
+ 29
0
@@ -3554,6 +3554,34 @@ static bool intrinsic_exp2(struct hlsl_ctx *ctx,
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,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@@ -4586,6 +4614,7 @@ intrinsic_functions[] =
{"dot", 2, true, intrinsic_dot},
{"exp", 1, true, intrinsic_exp},
{"exp2", 1, true, intrinsic_exp2},
{"faceforward", 3, true, intrinsic_faceforward},
{"floor", 1, true, intrinsic_floor},
{"fmod", 2, true, intrinsic_fmod},
{"frac", 1, true, intrinsic_frac},
Loading