Skip to content

Commit

Permalink
Note whether a given register was written to by the shader.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 15, 2012
1 parent 513131a commit ae90cc4
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions mojoshader.c
Expand Up @@ -45,6 +45,7 @@ typedef struct RegisterList
unsigned int index;
int writemask;
int misc;
int written;
const VariableList *array;
struct RegisterList *next;
} RegisterList;
Expand Down Expand Up @@ -563,11 +564,15 @@ static inline const RegisterList *reglist_exists(RegisterList *prev,
} // reglist_exists

static inline void set_used_register(Context *ctx, const RegisterType regtype,
const int regnum)
const int regnum, const int written)
{
RegisterList *reg = NULL;
if ((regtype == REG_TYPE_COLOROUT) && (regnum > 0))
ctx->have_multi_color_outputs = 1;
reglist_insert(ctx, &ctx->used_registers, regtype, regnum);

reg = reglist_insert(ctx, &ctx->used_registers, regtype, regnum);
if (reg && written)
reg->written = 1;
} // set_used_register

static inline int get_used_register(Context *ctx, const RegisterType regtype,
Expand Down Expand Up @@ -2166,7 +2171,7 @@ static void emit_GLSL_end(Context *ctx)
if (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 2, 0))
{
const char *shstr = ctx->shader_type_str;
set_used_register(ctx, REG_TYPE_COLOROUT, 0);
set_used_register(ctx, REG_TYPE_COLOROUT, 0, 1);
output_line(ctx, "%s_oC0 = %s_r0;", shstr, shstr);
} // if

Expand Down Expand Up @@ -4043,7 +4048,7 @@ static void emit_ARB1_end(Context *ctx)
// RET isn't available before ps_2_0.
if (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 2, 0))
{
set_used_register(ctx, REG_TYPE_COLOROUT, 0);
set_used_register(ctx, REG_TYPE_COLOROUT, 0, 1);
output_line(ctx, "MOV oC0, r0;");
} // if

Expand Down Expand Up @@ -5526,7 +5531,7 @@ static int parse_destination_token(Context *ctx, DestArgInfo *info)
fail(ctx, "Register type is out of range");

if (!isfail(ctx))
set_used_register(ctx, info->regtype, info->regnum);
set_used_register(ctx, info->regtype, info->regnum, 1);

return 1;
} // parse_destination_token
Expand Down Expand Up @@ -5792,7 +5797,7 @@ static int parse_source_token(Context *ctx, SourceArgInfo *info)
{
var->used = 1;
info->relative_array = var;
set_used_register(ctx, info->relative_regtype, info->relative_regnum);
set_used_register(ctx, info->relative_regtype, info->relative_regnum, 0);
} // else
} // else
} // if
Expand Down Expand Up @@ -5849,7 +5854,7 @@ static int parse_source_token(Context *ctx, SourceArgInfo *info)
// None of the constant floating-point registers can use the abs modifier.

if (!isfail(ctx))
set_used_register(ctx, info->regtype, info->regnum);
set_used_register(ctx, info->regtype, info->regnum, 0);

return retval;
} // parse_source_token
Expand Down Expand Up @@ -6374,7 +6379,7 @@ static void srcarg_matrix_replicate(Context *ctx, const int idx,
{
memcpy(dst, src, sizeof (SourceArgInfo));
dst->regnum += (i + 1);
set_used_register(ctx, dst->regtype, dst->regnum);
set_used_register(ctx, dst->regtype, dst->regnum, 0);
} // for
} // srcarg_matrix_replicate

Expand Down

0 comments on commit ae90cc4

Please sign in to comment.