Skip to content

Commit

Permalink
Replicate D3D's div by 0 behavior for RCP/RSQ
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpydog committed Nov 26, 2019
1 parent e838e55 commit 7454de7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions profiles/mojoshader_profile_metal.c
Expand Up @@ -1122,7 +1122,8 @@ void emit_METAL_RCP(Context *ctx)
{
char src0[64]; make_METAL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
char code[128];
make_METAL_destarg_assign(ctx, code, sizeof (code), "1.0 / %s", src0);
ctx->metal_need_header_math = 1;
make_METAL_destarg_assign(ctx, code, sizeof (code), "(%s == 0.0) ? FLT_MAX : 1.0 / %s", src0, src0);
output_line(ctx, "%s", code);
} // emit_METAL_RCP

Expand All @@ -1131,7 +1132,7 @@ void emit_METAL_RSQ(Context *ctx)
char src0[64]; make_METAL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
char code[128];
ctx->metal_need_header_math = 1;
make_METAL_destarg_assign(ctx, code, sizeof (code), "rsqrt(%s)", src0);
make_METAL_destarg_assign(ctx, code, sizeof (code), "(%s == 0.0) ? FLT_MAX : rsqrt(abs(%s))", src0, src0);
output_line(ctx, "%s", code);
} // emit_METAL_RSQ

Expand Down

0 comments on commit 7454de7

Please sign in to comment.