st/mesa/i965: create link status enum
authorTimothy Arceri <tarceri@itsqueeze.com>
Fri, 3 Feb 2017 23:46:53 +0000 (10:46 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Thu, 9 Feb 2017 01:22:56 +0000 (12:22 +1100)
For the on-disk shader cache we want to be able to differentiate
between a program that was linked and one that was loaded from cache.

V2:
 - don't return the new enum directly to the application when queried,
   instead return GL_TRUE or GL_FALSE as required. Fixes google-chrome
   corruptions when using cache.

Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
13 files changed:
src/compiler/glsl/linker.cpp
src/compiler/glsl/standalone.cpp
src/mesa/drivers/dri/i965/brw_cs.c
src/mesa/drivers/dri/i965/brw_tcs.c
src/mesa/drivers/dri/i965/brw_tes.c
src/mesa/drivers/dri/i965/brw_vs.c
src/mesa/drivers/dri/i965/brw_wm.c
src/mesa/main/mtypes.h
src/mesa/main/program_resource.c
src/mesa/main/shaderapi.c
src/mesa/main/uniforms.c
src/mesa/program/ir_to_mesa.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index b768a6e528576dbe4b64e25b6dfd819e9b95345f..720c22baee0d7a11a25b5767c315b3e8c7c978a2 100644 (file)
@@ -421,7 +421,7 @@ linker_error(gl_shader_program *prog, const char *fmt, ...)
    ralloc_vasprintf_append(&prog->data->InfoLog, fmt, ap);
    va_end(ap);
 
-   prog->data->LinkStatus = false;
+   prog->data->LinkStatus = linking_failure;
 }
 
 
@@ -2190,7 +2190,7 @@ link_intrastage_shaders(void *mem_ctx,
                              _mesa_shader_stage_to_program(shader_list[0]->Stage),
                              prog->Name, false);
    if (!gl_prog) {
-      prog->data->LinkStatus = false;
+      prog->data->LinkStatus = linking_failure;
       _mesa_delete_linked_shader(ctx, linked);
       return NULL;
    }
@@ -4629,7 +4629,7 @@ linker_optimisation_loop(struct gl_context *ctx, exec_list *ir,
 void
 link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 {
-   prog->data->LinkStatus = true; /* All error paths will set this to false */
+   prog->data->LinkStatus = linking_success; /* All error paths will set this to false */
    prog->data->Validated = false;
 
    /* Section 7.3 (Program Objects) of the OpenGL 4.5 Core Profile spec says:
index 44f2c0f36b116cd96b6d27e0ccb7acf781146cc3..7a2d3d200f07ba0436906b91b6f5d71b9a187897 100644 (file)
@@ -509,7 +509,7 @@ standalone_compile_shader(const struct standalone_options *_options,
       } else {
          const gl_shader_stage stage = whole_program->Shaders[0]->Stage;
 
-         whole_program->data->LinkStatus = GL_TRUE;
+         whole_program->data->LinkStatus = linking_success;
          whole_program->_LinkedShaders[stage] =
             link_intrastage_shaders(whole_program /* mem_ctx */,
                                     ctx,
index 0f8d4ebcb83661e868f683908d00e625b2f95e43..16b7945bd7ef9632255dc93eef13215bfea3e57e 100644 (file)
@@ -66,7 +66,7 @@ brw_codegen_cs_prog(struct brw_context *brw,
    memset(&prog_data, 0, sizeof(prog_data));
 
    if (cp->program.info.cs.shared_size > 64 * 1024) {
-      cp->program.sh.data->LinkStatus = false;
+      cp->program.sh.data->LinkStatus = linking_failure;
       const char *error_str =
          "Compute shader used more than 64KB of shared variables";
       ralloc_strcat(&cp->program.sh.data->InfoLog, error_str);
@@ -119,7 +119,7 @@ brw_codegen_cs_prog(struct brw_context *brw,
                             &prog_data, cp->program.nir, st_index,
                             &program_size, &error_str);
    if (program == NULL) {
-      cp->program.sh.data->LinkStatus = false;
+      cp->program.sh.data->LinkStatus = linking_failure;
       ralloc_strcat(&cp->program.sh.data->InfoLog, error_str);
       _mesa_problem(NULL, "Failed to compile compute shader: %s\n", error_str);
 
index 858ecf99a84399efe102beae1e068190df076f14..64bfc40d4d1fe15f94bfddc7be9dd1c4a6074aca 100644 (file)
@@ -249,7 +249,7 @@ brw_codegen_tcs_prog(struct brw_context *brw, struct brw_program *tcp,
                       &program_size, &error_str);
    if (program == NULL) {
       if (tep) {
-         tep->program.sh.data->LinkStatus = false;
+         tep->program.sh.data->LinkStatus = linking_failure;
          ralloc_strcat(&tep->program.sh.data->InfoLog, error_str);
       }
 
index cb12b9c5a69e61c6a3708fc42d4bc2732313883a..3da53579ac0134a15925b34b5fd7c15fc83c5fdd 100644 (file)
@@ -124,7 +124,7 @@ brw_codegen_tes_prog(struct brw_context *brw,
       brw_compile_tes(compiler, brw, mem_ctx, key, &input_vue_map, &prog_data,
                       nir, &tep->program, st_index, &program_size, &error_str);
    if (program == NULL) {
-      tep->program.sh.data->LinkStatus = false;
+      tep->program.sh.data->LinkStatus = linking_failure;
       ralloc_strcat(&tep->program.sh.data->InfoLog, error_str);
 
       _mesa_problem(NULL, "Failed to compile tessellation evaluation shader: "
index a8225801858e4a83c6d788915376817399fed48b..3f11a76506e0e6e09b26f59cbe1242ab7ec6ed55 100644 (file)
@@ -226,7 +226,7 @@ brw_codegen_vs_prog(struct brw_context *brw,
                             st_index, &program_size, &error_str);
    if (program == NULL) {
       if (!vp->program.is_arb_asm) {
-         vp->program.sh.data->LinkStatus = false;
+         vp->program.sh.data->LinkStatus = linking_failure;
          ralloc_strcat(&vp->program.sh.data->InfoLog, error_str);
       }
 
index a774720202adde26f9259ef49a774a4daaef530c..4a07c14e80703d23b253559c7afebd7a4c315ac0 100644 (file)
@@ -194,7 +194,7 @@ brw_codegen_wm_prog(struct brw_context *brw,
 
    if (program == NULL) {
       if (!fp->program.is_arb_asm) {
-         fp->program.sh.data->LinkStatus = false;
+         fp->program.sh.data->LinkStatus = linking_failure;
          ralloc_strcat(&fp->program.sh.data->InfoLog, error_str);
       }
 
index a2280e2539f5d3377cbf3802d045db812bbb63f3..a845a394c8f7d4e788cea2b0478eb1f0d6b6aaf9 100644 (file)
@@ -2646,6 +2646,17 @@ struct gl_program_resource
    uint8_t StageReferences; /** Bitmask of shader stage references. */
 };
 
+/**
+ * Link status enum. linking_skipped is used to indicate linking
+ * was skipped due to the shader being loaded from the on-disk cache.
+ */
+enum gl_link_status
+{
+   linking_failure = 0,
+   linking_success,
+   linking_skipped
+};
+
 /**
  * A data structure to be shared by gl_shader_program and gl_program.
  */
@@ -2677,7 +2688,7 @@ struct gl_shader_program_data
    struct gl_program_resource *ProgramResourceList;
    unsigned NumProgramResourceList;
 
-   GLboolean LinkStatus;   /**< GL_LINK_STATUS */
+   enum gl_link_status LinkStatus;   /**< GL_LINK_STATUS */
    GLboolean Validated;
    GLchar *InfoLog;
 
index 4b5be6f52d858ceb205d6c040e95b8a562fcc8c6..4eacdfb9e9aeda6c09170220df369828799f102c 100644 (file)
@@ -76,7 +76,7 @@ lookup_linked_program(GLuint program, const char *caller)
    if (!prog)
       return NULL;
 
-   if (prog->data->LinkStatus == GL_FALSE) {
+   if (prog->data->LinkStatus == linking_failure) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(program not linked)",
                   caller);
       return NULL;
index 4667866ca06113190984a692697b5171058b8505..4406aaa9803ea622bc037980870057f5f29fe3ea 100644 (file)
@@ -636,7 +636,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname,
       *params = shProg->DeletePending;
       return;
    case GL_LINK_STATUS:
-      *params = shProg->data->LinkStatus;
+      *params = shProg->data->LinkStatus ? GL_TRUE : GL_FALSE;
       return;
    case GL_VALIDATE_STATUS:
       *params = shProg->data->Validated;
@@ -815,7 +815,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname,
    }
    case GL_PROGRAM_SEPARABLE:
       /* If the program has not been linked, return initial value 0. */
-      *params = (shProg->data->LinkStatus == GL_FALSE) ? 0 : shProg->SeparateShader;
+      *params = (shProg->data->LinkStatus == linking_failure) ? 0 : shProg->SeparateShader;
       return;
 
    /* ARB_tessellation_shader */
@@ -1160,7 +1160,7 @@ _mesa_link_program(struct gl_context *ctx, struct gl_shader_program *shProg)
       ralloc_free(filename);
    }
 
-   if (shProg->data->LinkStatus == GL_FALSE &&
+   if (shProg->data->LinkStatus == linking_failure &&
        (ctx->_Shader->Flags & GLSL_REPORT_ERRORS)) {
       _mesa_debug(ctx, "Error linking program %u:\n%s\n",
                   shProg->Name, shProg->data->InfoLog);
@@ -2095,7 +2095,7 @@ _mesa_ProgramBinary(GLuint program, GLenum binaryFormat,
     * Since any value of binaryFormat passed "is not one of those specified as
     * allowable for [this] command, an INVALID_ENUM error is generated."
     */
-   shProg->data->LinkStatus = GL_FALSE;
+   shProg->data->LinkStatus = linking_failure;
    _mesa_error(ctx, GL_INVALID_ENUM, "glProgramBinary");
 }
 
@@ -2270,7 +2270,7 @@ _mesa_CreateShaderProgramv(GLenum type, GLsizei count,
            /* Possibly... */
            if (active-user-defined-varyings-in-linked-program) {
               append-error-to-info-log;
-               shProg->data->LinkStatus = GL_FALSE;
+               shProg->data->LinkStatus = linking_failure;
            }
 #endif
         }
index a9540551053dd8203dcff8711da9b69aa4681afb..8376a9519f6a9fa545f968ebe92fbbf15667c926 100644 (file)
@@ -941,7 +941,7 @@ _mesa_GetUniformLocation(GLuint programObj, const GLcharARB *name)
     *     "If program has not been successfully linked, the error
     *     INVALID_OPERATION is generated."
     */
-   if (shProg->data->LinkStatus == GL_FALSE) {
+   if (shProg->data->LinkStatus == linking_failure) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                  "glGetUniformLocation(program not linked)");
       return -1;
index dc5f8016f3753128afc5b0c73685713f139455dc..ce58fbbd4604231187478333a51b79476e2b4126 100644 (file)
@@ -3096,7 +3096,7 @@ _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 
    _mesa_clear_shader_program_data(ctx, prog);
 
-   prog->data->LinkStatus = GL_TRUE;
+   prog->data->LinkStatus = linking_success;
 
    for (i = 0; i < prog->NumShaders; i++) {
       if (!prog->Shaders[i]->CompileStatus) {
@@ -3110,7 +3110,7 @@ _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 
    if (prog->data->LinkStatus) {
       if (!ctx->Driver.LinkShader(ctx, prog)) {
-         prog->data->LinkStatus = GL_FALSE;
+         prog->data->LinkStatus = linking_failure;
       }
    }
 
index 116f30c9446b5e025542c370465d994ac91a24ae..fc981ab0b2211a35ea169627b689fbc3dd9ca8fc 100644 (file)
@@ -588,7 +588,7 @@ fail_link(struct gl_shader_program *prog, const char *fmt, ...)
    ralloc_vasprintf_append(&prog->data->InfoLog, fmt, args);
    va_end(args);
 
-   prog->data->LinkStatus = GL_FALSE;
+   prog->data->LinkStatus = linking_failure;
 }
 
 static int