st/mesa: deduplicate cases in st_deserialise_ir_program
authorMarek Olšák <marek.olsak@amd.com>
Mon, 30 Sep 2019 21:13:32 +0000 (17:13 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 17 Oct 2019 00:10:47 +0000 (20:10 -0400)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/state_tracker/st_shader_cache.c

index 901918eb7b29962494371ed3c8491b2a302c9a0e..c149e2c14f038e8295d7e5f8c339ab61e5e641fc 100644 (file)
@@ -227,66 +227,33 @@ st_deserialise_ir_program(struct gl_context *ctx,
 
       break;
    }
-   case MESA_SHADER_TESS_CTRL: {
-      struct st_common_program *sttcp = st_common_program(prog);
-
-      st_release_basic_variants(st, sttcp);
-
-      if (nir) {
-         sttcp->tgsi.type = PIPE_SHADER_IR_NIR;
-         sttcp->shader_program = shProg;
-         sttcp->tgsi.ir.nir = nir_deserialize(NULL, options, &blob_reader);
-         prog->nir = sttcp->tgsi.ir.nir;
-      } else {
-         read_tgsi_from_cache(&blob_reader, &sttcp->tgsi.tokens,
-                              &sttcp->num_tgsi_tokens);
-      }
-
-      if (st->tcp == sttcp)
-         st->dirty |= sttcp->affected_states;
-
-      break;
-   }
-   case MESA_SHADER_TESS_EVAL: {
-      struct st_common_program *sttep = st_common_program(prog);
-
-      st_release_basic_variants(st, sttep);
-      read_stream_out_from_cache(&blob_reader, &sttep->tgsi);
-
-      if (nir) {
-         sttep->tgsi.type = PIPE_SHADER_IR_NIR;
-         sttep->shader_program = shProg;
-         sttep->tgsi.ir.nir = nir_deserialize(NULL, options, &blob_reader);
-         prog->nir = sttep->tgsi.ir.nir;
-      } else {
-         read_tgsi_from_cache(&blob_reader, &sttep->tgsi.tokens,
-                              &sttep->num_tgsi_tokens);
-      }
-
-      if (st->tep == sttep)
-         st->dirty |= sttep->affected_states;
+   case MESA_SHADER_TESS_CTRL:
+   case MESA_SHADER_TESS_EVAL:
+   case MESA_SHADER_GEOMETRY:
+   case MESA_SHADER_COMPUTE: {
+      struct st_common_program *stcp = st_common_program(prog);
 
-      break;
-   }
-   case MESA_SHADER_GEOMETRY: {
-      struct st_common_program *stgp = st_common_program(prog);
+      st_release_basic_variants(st, stcp);
 
-      st_release_basic_variants(st, stgp);
-      read_stream_out_from_cache(&blob_reader, &stgp->tgsi);
+      if (prog->info.stage == MESA_SHADER_TESS_EVAL ||
+          prog->info.stage == MESA_SHADER_GEOMETRY)
+         read_stream_out_from_cache(&blob_reader, &stcp->tgsi);
 
       if (nir) {
-         stgp->tgsi.type = PIPE_SHADER_IR_NIR;
-         stgp->shader_program = shProg;
-         stgp->tgsi.ir.nir = nir_deserialize(NULL, options, &blob_reader);
-         prog->nir = stgp->tgsi.ir.nir;
+         stcp->tgsi.type = PIPE_SHADER_IR_NIR;
+         stcp->tgsi.ir.nir = nir_deserialize(NULL, options, &blob_reader);
+         stcp->shader_program = shProg;
+         prog->nir = stcp->tgsi.ir.nir;
       } else {
-         read_tgsi_from_cache(&blob_reader, &stgp->tgsi.tokens,
-                              &stgp->num_tgsi_tokens);
+         read_tgsi_from_cache(&blob_reader, &stcp->tgsi.tokens,
+                              &stcp->num_tgsi_tokens);
       }
 
-      if (st->gp == stgp)
-         st->dirty |= stgp->affected_states;
-
+      if ((prog->info.stage == MESA_SHADER_TESS_CTRL && st->tcp == stcp) ||
+          (prog->info.stage == MESA_SHADER_TESS_EVAL && st->tep == stcp) ||
+          (prog->info.stage == MESA_SHADER_GEOMETRY && st->gp == stcp) ||
+          (prog->info.stage == MESA_SHADER_COMPUTE && st->cp == stcp))
+         st->dirty |= stcp->affected_states;
       break;
    }
    case MESA_SHADER_FRAGMENT: {
@@ -309,26 +276,6 @@ st_deserialise_ir_program(struct gl_context *ctx,
 
       break;
    }
-   case MESA_SHADER_COMPUTE: {
-      struct st_common_program *stcp = (struct st_common_program *) prog;
-
-      st_release_basic_variants(st, stcp);
-
-      if (nir) {
-         stcp->tgsi.type = PIPE_SHADER_IR_NIR;
-         stcp->tgsi.ir.nir = nir_deserialize(NULL, options, &blob_reader);
-         stcp->shader_program = shProg;
-         prog->nir = (nir_shader *) stcp->tgsi.ir.nir;
-      } else {
-         read_tgsi_from_cache(&blob_reader, &stcp->tgsi.tokens,
-                              &stcp->num_tgsi_tokens);
-      }
-
-      if (st->cp == stcp)
-         st->dirty |= stcp->affected_states;
-
-      break;
-   }
    default:
       unreachable("Unsupported stage");
    }