Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
glsl: Correct RCP and RSQ output.
  • Loading branch information
icculus committed Jul 20, 2020
1 parent 8bf914f commit 301d9fd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions profiles/mojoshader_profile_glsl.c
Expand Up @@ -1194,19 +1194,28 @@ void emit_GLSL_MUL(Context *ctx)

void emit_GLSL_RCP(Context *ctx)
{
char src0[64]; make_GLSL_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), "vec%d", vecsize);
char src0[64]; make_GLSL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0));
char code[128];
ctx->need_max_float = 1;
make_GLSL_destarg_assign(ctx, code, sizeof (code), "(%s == 0.0) ? FLT_MAX : 1.0 / %s", src0, src0);
make_GLSL_destarg_assign(ctx, code, sizeof (code), "%s((%s == 0.0) ? FLT_MAX : 1.0 / %s)", cast, src0, src0);
output_line(ctx, "%s", code);
} // emit_GLSL_RCP

void emit_GLSL_RSQ(Context *ctx)
{
char src0[64]; make_GLSL_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), "vec%d", vecsize);

char src0[64]; make_GLSL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0));
char code[128];
ctx->need_max_float = 1;
make_GLSL_destarg_assign(ctx, code, sizeof (code), "(%s == 0.0) ? FLT_MAX : inversesqrt(abs(%s))", src0, src0);
make_GLSL_destarg_assign(ctx, code, sizeof (code), "%s((%s == 0.0) ? FLT_MAX : inversesqrt(abs(%s)))", cast, src0, src0);
output_line(ctx, "%s", code);
} // emit_GLSL_RSQ

Expand Down

0 comments on commit 301d9fd

Please sign in to comment.