Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Various style/redundancy fixes found during SPIR-V work
  • Loading branch information
krolli committed Dec 20, 2019
1 parent e5cc3e8 commit f2d0bd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
26 changes: 7 additions & 19 deletions mojoshader.c
Expand Up @@ -521,7 +521,7 @@ static void determine_constants_arrays(Context *ctx)
var->emit_position = -1;
var->next = ctx->variables;
ctx->variables = var;
} // else
} // if

start = i; // set this as new start of sequence.
} // if
Expand Down Expand Up @@ -1267,7 +1267,7 @@ static void state_DCL(Context *ctx)
if (ctx->instruction_count != 0)
fail(ctx, "DCL token must come before any instructions");

else if (shader_is_vertex(ctx))
else if (shader_is_vertex(ctx) || shader_is_pixel(ctx))
{
if (regtype == REG_TYPE_SAMPLER)
add_sampler(ctx, regnum, (TextureType) ctx->dwords[0], 0);
Expand All @@ -1284,18 +1284,6 @@ static void state_DCL(Context *ctx)
} // else
} // if

else if (shader_is_pixel(ctx))
{
if (regtype == REG_TYPE_SAMPLER)
add_sampler(ctx, regnum, (TextureType) ctx->dwords[0], 0);
else
{
const MOJOSHADER_usage usage = (MOJOSHADER_usage) ctx->dwords[0];
const int index = ctx->dwords[1];
add_attribute_register(ctx, regtype, regnum, usage, index, wmask, mods);
} // else
} // else if

else
{
fail(ctx, "unsupported shader type."); // should be caught elsewhere.
Expand Down Expand Up @@ -3557,8 +3545,7 @@ static void process_definitions(Context *ctx)
} // while

// okay, now deal with uniform/constant arrays...
VariableList *var;
for (var = ctx->variables; var != NULL; var = var->next)
for (VariableList *var = ctx->variables; var != NULL; var = var->next)
{
if (var->used)
{
Expand All @@ -3580,6 +3567,7 @@ static void process_definitions(Context *ctx)
for (item = ctx->uniforms.next; item != NULL; item = item->next)
{
int arraysize = -1;
VariableList *var = NULL;

// check if this is a register contained in an array...
if (item->regtype == REG_TYPE_CONST)
Expand Down Expand Up @@ -3694,13 +3682,13 @@ const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,

verify_swizzles(ctx);

if (!ctx->mainfn)
ctx->mainfn = StrDup(ctx, "main");

// Version token always comes first.
ctx->current_position = 0;
rc = parse_version_token(ctx, profile);

if (!ctx->mainfn)
ctx->mainfn = StrDup(ctx, "main");

// drop out now if this definitely isn't bytecode. Saves lots of
// meaningless errors flooding through.
if (rc < 0)
Expand Down
3 changes: 1 addition & 2 deletions mojoshader_opengl.c
Expand Up @@ -577,7 +577,6 @@ static GLuint impl_GLSL_LinkProgram(MOJOSHADER_glShader *vshader,

static void impl_GLSL_FinalInitProgram(MOJOSHADER_glProgram *program)
{

program->vs_float4_loc = glsl_uniform_loc(program, "vs_uniforms_vec4");
program->vs_int4_loc = glsl_uniform_loc(program, "vs_uniforms_ivec4");
program->vs_bool_loc = glsl_uniform_loc(program, "vs_uniforms_bool");
Expand Down Expand Up @@ -708,7 +707,7 @@ static int impl_ARB1_CompileShader(const MOJOSHADER_parseData *pd, GLuint *s)
shaderlen, pd->output);

if (ctx->glGetError() == GL_INVALID_OPERATION)
{
{
GLint pos = 0;
ctx->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
const GLubyte *errstr = ctx->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
Expand Down

0 comments on commit f2d0bd0

Please sign in to comment.