i965: Make a helper for finding an existing shader variant.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vs.c
index f9044ebf3e347a92bedec6985a6558b49d46cfcf..5d1993931819838fbd3e758a55ac0013ddc59861 100644 (file)
@@ -88,26 +88,14 @@ static void
 brw_vs_debug_recompile(struct brw_context *brw, struct gl_program *prog,
                        const struct brw_vs_prog_key *key)
 {
-   struct brw_cache_item *c = NULL;
-   const struct brw_vs_prog_key *old_key = NULL;
-   bool found = false;
-
    perf_debug("Recompiling vertex shader for program %d\n", prog->Id);
 
-   for (unsigned int i = 0; i < brw->cache.size; i++) {
-      for (c = brw->cache.items[i]; c; c = c->next) {
-         if (c->cache_id == BRW_CACHE_VS_PROG) {
-            old_key = c->key;
-
-            if (old_key->program_string_id == key->program_string_id)
-               break;
-         }
-      }
-      if (c)
-         break;
-   }
+   bool found = false;
+   const struct brw_vs_prog_key *old_key =
+      brw_find_previous_compile(&brw->cache, BRW_CACHE_VS_PROG,
+                                key->program_string_id);
 
-   if (!c) {
+   if (!old_key) {
       perf_debug("  Didn't find previous compile in the shader cache for "
                  "debug\n");
       return;
@@ -137,9 +125,8 @@ brw_vs_debug_recompile(struct brw_context *brw, struct gl_program *prog,
    }
 }
 
-bool
+static bool
 brw_codegen_vs_prog(struct brw_context *brw,
-                    struct gl_shader_program *prog,
                     struct brw_program *vp,
                     struct brw_vs_prog_key *key)
 {
@@ -156,7 +143,7 @@ brw_codegen_vs_prog(struct brw_context *brw,
    memset(&prog_data, 0, sizeof(prog_data));
 
    /* Use ALT floating point mode for ARB programs so that 0^0 == 1. */
-   if (!prog)
+   if (vp->program.is_arb_asm)
       stage_prog_data->use_alt_mode = true;
 
    mem_ctx = ralloc_context(NULL);
@@ -186,8 +173,8 @@ brw_codegen_vs_prog(struct brw_context *brw,
                     stage_prog_data->nr_image_params);
    stage_prog_data->nr_params = param_count;
 
-   if (prog) {
-      brw_nir_setup_glsl_uniforms(vp->program.nir, prog, &vp->program,
+   if (!vp->program.is_arb_asm) {
+      brw_nir_setup_glsl_uniforms(vp->program.nir, &vp->program,
                                   &prog_data.base.base,
                                   compiler->scalar_stage[MESA_SHADER_VERTEX]);
    } else {
@@ -219,15 +206,14 @@ brw_codegen_vs_prog(struct brw_context *brw,
    }
 
    if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
-      if (!prog)
+      if (vp->program.is_arb_asm)
          brw_dump_arb_asm("vertex", &vp->program);
    }
 
    int st_index = -1;
    if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
-      bool is_glsl_sh = prog != NULL;
       st_index = brw_get_shader_time_index(brw, &vp->program, ST_VS,
-                                           is_glsl_sh);
+                                           !vp->program.is_arb_asm);
    }
 
    /* Emit GEN4 code.
@@ -239,7 +225,7 @@ brw_codegen_vs_prog(struct brw_context *brw,
                             !_mesa_is_gles3(&brw->ctx),
                             st_index, &program_size, &error_str);
    if (program == NULL) {
-      if (prog) {
+      if (!vp->program.is_arb_asm) {
          vp->program.sh.data->LinkStatus = false;
          ralloc_strcat(&vp->program.sh.data->InfoLog, error_str);
       }
@@ -344,8 +330,6 @@ brw_vs_populate_key(struct brw_context *brw,
 void
 brw_upload_vs_prog(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->ctx;
-   struct gl_shader_program **current = ctx->_Shader->CurrentProgram;
    struct brw_vs_prog_key key;
    /* BRW_NEW_VERTEX_PROGRAM */
    struct brw_program *vp = (struct brw_program *)brw->vertex_program;
@@ -358,17 +342,14 @@ brw_upload_vs_prog(struct brw_context *brw)
    if (!brw_search_cache(&brw->cache, BRW_CACHE_VS_PROG,
                         &key, sizeof(key),
                         &brw->vs.base.prog_offset, &brw->vs.base.prog_data)) {
-      bool success = brw_codegen_vs_prog(brw, current[MESA_SHADER_VERTEX],
-                                         vp, &key);
+      bool success = brw_codegen_vs_prog(brw, vp, &key);
       (void) success;
       assert(success);
    }
 }
 
 bool
-brw_vs_precompile(struct gl_context *ctx,
-                  struct gl_shader_program *shader_prog,
-                  struct gl_program *prog)
+brw_vs_precompile(struct gl_context *ctx, struct gl_program *prog)
 {
    struct brw_context *brw = brw_context(ctx);
    struct brw_vs_prog_key key;
@@ -387,7 +368,7 @@ brw_vs_precompile(struct gl_context *ctx,
        (VARYING_BIT_COL0 | VARYING_BIT_COL1 | VARYING_BIT_BFC0 |
         VARYING_BIT_BFC1));
 
-   success = brw_codegen_vs_prog(brw, shader_prog, bvp, &key);
+   success = brw_codegen_vs_prog(brw, bvp, &key);
 
    brw->vs.base.prog_offset = old_prog_offset;
    brw->vs.base.prog_data = old_prog_data;