Skip to content

Commit

Permalink
metal: Fix RCP and RSQ output to match GLSL.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 21, 2020
1 parent 26d4e3e commit 910ee02
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions profiles/mojoshader_profile_metal.c
Expand Up @@ -1120,19 +1120,27 @@ void emit_METAL_MUL(Context *ctx)

void emit_METAL_RCP(Context *ctx)
{
char src0[64]; make_METAL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask);
char cast[16] = { '\0' };
if (vecsize != 1)
snprintf(cast, sizeof (cast), "float%d", vecsize);
char src0[64]; make_METAL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0));
char code[128];
ctx->metal_need_header_math = 1;
make_METAL_destarg_assign(ctx, code, sizeof (code), "(%s == 0.0) ? FLT_MAX : 1.0 / %s", src0, src0);
make_METAL_destarg_assign(ctx, code, sizeof (code), "%s((%s == 0.0) ? FLT_MAX : 1.0 / %s)", cast, src0, src0);
output_line(ctx, "%s", code);
} // emit_METAL_RCP

void emit_METAL_RSQ(Context *ctx)
{
char src0[64]; make_METAL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask);
char cast[16] = { '\0' };
if (vecsize != 1)
snprintf(cast, sizeof (cast), "float%d", vecsize);
char src0[64]; make_METAL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0));
char code[128];
ctx->metal_need_header_math = 1;
make_METAL_destarg_assign(ctx, code, sizeof (code), "(%s == 0.0) ? FLT_MAX : rsqrt(abs(%s))", src0, src0);
make_METAL_destarg_assign(ctx, code, sizeof (code), "%s((%s == 0.0) ? FLT_MAX : rsqrt(abs(%s)))", cast, src0, src0);
output_line(ctx, "%s", code);
} // emit_METAL_RSQ

Expand Down

0 comments on commit 910ee02

Please sign in to comment.