Skip to content

Commit

Permalink
Tweak IF/ELSE/ENDIF in nv2 profile.
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
icculus committed Jun 20, 2008
1 parent 25f81d9 commit bf3d8bc
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions mojoshader.c
Expand Up @@ -4313,18 +4313,25 @@ static void emit_ARB1_SINCOS(Context *ctx)
EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(REP)
EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(ENDREP)

static void nv2_if_branch(Context *ctx)
static void nv2_if(Context *ctx)
{
// there's no IF construct, but we can use a branch to a label.
const int label = allocate_if_label(ctx);
const char *failbranch = get_ARB1_if_label_name(ctx, label);
// The condition code register MUST be set up before this!
if (shader_is_pixel(ctx)) // nv2 fragment programs have a real IF.
output_line(ctx, "IF (EQ.x)");
else
{
// there's no IF construct, but we can use a branch to a label.
const int label = allocate_if_label(ctx);
const char *failbranch = get_ARB1_if_label_name(ctx, label);

assert(ctx->if_labels_stack_index < STATICARRAYLEN(ctx->if_labels_stack));
ctx->if_labels_stack[ctx->if_labels_stack_index++] = label;
assert(ctx->if_labels_stack_index < STATICARRAYLEN(ctx->if_labels_stack));
ctx->if_labels_stack[ctx->if_labels_stack_index++] = label;

// The condition code register MUST be set up before this!
output_line(ctx, "BRA %s (EQ.x);", failbranch);
} // nv2_if_branch
output_line(ctx, "BRA %s (EQ.x);", failbranch);
} // else

ctx->indent++;
} // nv2_if


static void emit_ARB1_IF(Context *ctx)
Expand All @@ -4334,20 +4341,21 @@ static void emit_ARB1_IF(Context *ctx)
const char *scratch = allocate_ARB1_scratch_reg_name(ctx);
const char *src0 = get_ARB1_srcarg_varname(ctx, 0);
output_line(ctx, "MOVC %s.x, %s;", scratch, src0);
if (shader_is_pixel(ctx)) // nv2 fragment programs have a real IF.
output_line(ctx, "IF (EQ.x)");
else
nv2_if_branch(ctx);
nv2_if(ctx);
} // if

else // stock ARB1 has no branching.
{
fail(ctx, "branching unsupported in this profile");
} // else

ctx->indent++;
} // emit_ARB1_IF

static void emit_ARB1_ELSE(Context *ctx)
{
ctx->indent--;

// nv2 fragment programs have a real ELSE.
if ( (ctx->support_nv2) && (shader_is_pixel(ctx)) )
output_line(ctx, "ELSE");
Expand All @@ -4359,7 +4367,9 @@ static void emit_ARB1_ELSE(Context *ctx)

// At the end of the IF block, unconditionally jump to the ENDIF.
const int endlabel = allocate_if_label(ctx);
ctx->indent++;
output_line(ctx, "BRA %s;", get_ARB1_if_label_name(ctx, endlabel));
ctx->indent--;

// Now mark the ELSE section with a lable.
const int elselabel = ctx->if_labels_stack[ctx->if_labels_stack_index-1];
Expand All @@ -4373,11 +4383,15 @@ static void emit_ARB1_ELSE(Context *ctx)
{
fail(ctx, "branching unsupported in this profile");
} // else

ctx->indent++;
} // emit_ARB1_ELSE


static void emit_ARB1_ENDIF(Context *ctx)
{
ctx->indent--;

// nv2 fragment programs have a real ENDIF.
if ( (ctx->support_nv2) && (shader_is_pixel(ctx)) )
output_line(ctx, "ENDIF");
Expand Down Expand Up @@ -4546,7 +4560,7 @@ static void emit_ARB1_IFC(Context *ctx)
const char *src0 = get_ARB1_srcarg_varname(ctx, 0);
const char *src1 = get_ARB1_srcarg_varname(ctx, 1);
output_line(ctx, "%s %s.x, %s, %s;", comp, scratch, src0, src1);
nv2_if_branch(ctx);
nv2_if(ctx);
} // if

else // stock ARB1 has no branching.
Expand Down

0 comments on commit bf3d8bc

Please sign in to comment.