Various style/redundancy fixes found during SPIR-V work
authorMartin Krošlák <kroslakma@gmail.com>
Fri, 20 Dec 2019 15:52:48 -0500
changeset 1223 32ab7e4fbdc6
parent 1222 c6e847dd9d4b
child 1224 21cd84f1aa0a
Various style/redundancy fixes found during SPIR-V work
mojoshader.c
mojoshader_opengl.c
--- a/mojoshader.c	Mon Dec 16 00:08:35 2019 -0500
+++ b/mojoshader.c	Fri Dec 20 15:52:48 2019 -0500
@@ -521,7 +521,7 @@
                 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 @@
     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 @@
         } // 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 @@
     } // 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 @@
     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 @@
 
     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)
--- a/mojoshader_opengl.c	Mon Dec 16 00:08:35 2019 -0500
+++ b/mojoshader_opengl.c	Fri Dec 20 15:52:48 2019 -0500
@@ -577,7 +577,6 @@
 
 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 @@
                                 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);