From f2d0bd040177b58a9cb62b4d0bd4738e8a56d4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kro=C5=A1l=C3=A1k?= Date: Fri, 20 Dec 2019 15:52:48 -0500 Subject: [PATCH] Various style/redundancy fixes found during SPIR-V work --- mojoshader.c | 26 +++++++------------------- mojoshader_opengl.c | 3 +-- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 0b4e1b7d..bee34f20 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -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 @@ -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); @@ -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. @@ -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) { @@ -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) @@ -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) diff --git a/mojoshader_opengl.c b/mojoshader_opengl.c index 7fb3d8b8..11c8ec3b 100644 --- a/mojoshader_opengl.c +++ b/mojoshader_opengl.c @@ -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"); @@ -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);