st/mesa: cleanups after unification of st_vertex/common program
authorMarek Olšák <marek.olsak@amd.com>
Sat, 2 Nov 2019 02:46:11 +0000 (22:46 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 19 Nov 2019 23:02:06 +0000 (18:02 -0500)
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_shader_cache.c

index 0aad8a723e7b19e5fec48ac38b41b26d4aea4674..a236908c1b17edef92286cf17234bd4637f583e2 100644 (file)
@@ -520,29 +520,11 @@ set_st_program(struct gl_program *prog,
                struct gl_shader_program *shader_program,
                nir_shader *nir)
 {
-   struct st_program *stvp;
-   struct st_program *stp;
-
-   switch (prog->info.stage) {
-   case MESA_SHADER_VERTEX:
-      stvp = (struct st_program *)prog;
-      stvp->shader_program = shader_program;
-      stvp->state.type = PIPE_SHADER_IR_NIR;
-      stvp->state.ir.nir = nir;
-      break;
-   case MESA_SHADER_GEOMETRY:
-   case MESA_SHADER_TESS_CTRL:
-   case MESA_SHADER_TESS_EVAL:
-   case MESA_SHADER_COMPUTE:
-   case MESA_SHADER_FRAGMENT:
-      stp = (struct st_program *)prog;
-      stp->shader_program = shader_program;
-      stp->state.type = PIPE_SHADER_IR_NIR;
-      stp->state.ir.nir = nir;
-      break;
-   default:
-      unreachable("unknown shader stage");
-   }
+   struct st_program *stp = (struct st_program *)prog;
+
+   stp->shader_program = shader_program;
+   stp->state.type = PIPE_SHADER_IR_NIR;
+   stp->state.ir.nir = nir;
 }
 
 static void
index bc739ac228c4951c2de8036bdb351bfdae22153e..b6c2c2deb776ab43d83d9a9a3230c128e075846b 100644 (file)
@@ -7308,26 +7308,7 @@ get_mesa_program_tgsi(struct gl_context *ctx,
       return NULL;
    }
 
-   struct st_program *stvp;
-   struct st_program *stp;
-
-   switch (shader->Stage) {
-   case MESA_SHADER_VERTEX:
-      stvp = (struct st_program *)prog;
-      stvp->glsl_to_tgsi = v;
-      break;
-   case MESA_SHADER_FRAGMENT:
-   case MESA_SHADER_TESS_CTRL:
-   case MESA_SHADER_TESS_EVAL:
-   case MESA_SHADER_GEOMETRY:
-   case MESA_SHADER_COMPUTE:
-      stp = st_program(prog);
-      stp->glsl_to_tgsi = v;
-      break;
-   default:
-      assert(!"should not be reached");
-      return NULL;
-   }
+   st_program(prog)->glsl_to_tgsi = v;
 
    PRINT_STATS(v->print_stats());
 
index 2ee92d131563a7f602510960faa47a8de3555888..b90b16caf952a35117462c581ae83a1174e4ab45 100644 (file)
@@ -494,11 +494,8 @@ st_translate_stream_output_info(struct gl_program *prog)
    }
 
    /* Translate stream output info. */
-   struct pipe_stream_output_info *so_info = NULL;
-   if (prog->info.stage == MESA_SHADER_VERTEX)
-      so_info = &((struct st_program*)prog)->state.stream_output;
-   else
-      so_info = &((struct st_program*)prog)->state.stream_output;
+   struct pipe_stream_output_info *so_info =
+      &((struct st_program*)prog)->state.stream_output;
 
    for (unsigned i = 0; i < info->NumOutputs; i++) {
       so_info->output[i].register_index =
index 19b538eefd21f71df98f1dd231fe6fc5e565730a..b9c4556d634da8d356e036f99a3a700d1a7df042 100644 (file)
@@ -81,50 +81,30 @@ st_serialise_ir_program(struct gl_context *ctx, struct gl_program *prog,
    if (prog->driver_cache_blob)
       return;
 
+   struct st_program *stp = (struct st_program *)prog;
    struct blob blob;
    blob_init(&blob);
 
-   switch (prog->info.stage) {
-   case MESA_SHADER_VERTEX: {
-      struct st_program *stvp = (struct st_program *) prog;
-
-      blob_write_uint32(&blob, stvp->num_inputs);
-      blob_write_bytes(&blob, stvp->index_to_input,
-                       sizeof(stvp->index_to_input));
-      blob_write_bytes(&blob, stvp->input_to_index,
-                       sizeof(stvp->input_to_index));
-      blob_write_bytes(&blob, stvp->result_to_output,
-                       sizeof(stvp->result_to_output));
-
-      write_stream_out_to_cache(&blob, &stvp->state);
-
-      if (nir)
-         write_nir_to_cache(&blob, prog);
-      else
-         write_tgsi_to_cache(&blob, stvp->state.tokens, prog);
-      break;
-   }
-   case MESA_SHADER_TESS_CTRL:
-   case MESA_SHADER_TESS_EVAL:
-   case MESA_SHADER_GEOMETRY:
-   case MESA_SHADER_FRAGMENT:
-   case MESA_SHADER_COMPUTE: {
-      struct st_program *stcp = (struct st_program *) prog;
-
-      if (prog->info.stage == MESA_SHADER_TESS_EVAL ||
-          prog->info.stage == MESA_SHADER_GEOMETRY)
-         write_stream_out_to_cache(&blob, &stcp->state);
-
-      if (nir)
-         write_nir_to_cache(&blob, prog);
-      else
-         write_tgsi_to_cache(&blob, stcp->state.tokens, prog);
-      break;
-   }
-   default:
-      unreachable("Unsupported stage");
+   if (prog->info.stage == MESA_SHADER_VERTEX) {
+      blob_write_uint32(&blob, stp->num_inputs);
+      blob_write_bytes(&blob, stp->index_to_input,
+                       sizeof(stp->index_to_input));
+      blob_write_bytes(&blob, stp->input_to_index,
+                       sizeof(stp->input_to_index));
+      blob_write_bytes(&blob, stp->result_to_output,
+                       sizeof(stp->result_to_output));
    }
 
+   if (prog->info.stage == MESA_SHADER_VERTEX ||
+       prog->info.stage == MESA_SHADER_TESS_EVAL ||
+       prog->info.stage == MESA_SHADER_GEOMETRY)
+      write_stream_out_to_cache(&blob, &stp->state);
+
+   if (nir)
+      write_nir_to_cache(&blob, prog);
+   else
+      write_tgsi_to_cache(&blob, stp->state.tokens, prog);
+
    blob_finish(&blob);
 }
 
@@ -187,63 +167,38 @@ st_deserialise_ir_program(struct gl_context *ctx,
 
    assert(prog->driver_cache_blob && prog->driver_cache_blob_size > 0);
 
+   struct st_program *stp = st_program(prog);
    struct blob_reader blob_reader;
    blob_reader_init(&blob_reader, buffer, size);
 
-   switch (prog->info.stage) {
-   case MESA_SHADER_VERTEX: {
-      struct st_program *stvp = (struct st_program *) prog;
-
-      st_release_vp_variants(st, stvp);
-
-      stvp->num_inputs = blob_read_uint32(&blob_reader);
-      blob_copy_bytes(&blob_reader, (uint8_t *) stvp->index_to_input,
-                      sizeof(stvp->index_to_input));
-      blob_copy_bytes(&blob_reader, (uint8_t *) stvp->input_to_index,
-                      sizeof(stvp->input_to_index));
-      blob_copy_bytes(&blob_reader, (uint8_t *) stvp->result_to_output,
-                      sizeof(stvp->result_to_output));
-
-      read_stream_out_from_cache(&blob_reader, &stvp->state);
-
-      if (nir) {
-         stvp->state.type = PIPE_SHADER_IR_NIR;
-         stvp->shader_program = shProg;
-         stvp->state.ir.nir = nir_deserialize(NULL, options, &blob_reader);
-         prog->nir = stvp->state.ir.nir;
-      } else {
-         read_tgsi_from_cache(&blob_reader, &stvp->state.tokens);
-      }
-      break;
-   }
-   case MESA_SHADER_TESS_CTRL:
-   case MESA_SHADER_TESS_EVAL:
-   case MESA_SHADER_GEOMETRY:
-   case MESA_SHADER_FRAGMENT:
-   case MESA_SHADER_COMPUTE: {
-      struct st_program *stcp = st_program(prog);
-
-      if (prog->info.stage == MESA_SHADER_FRAGMENT)
-         st_release_fp_variants(st, stcp);
-      else
-         st_release_common_variants(st, stcp);
-
-      if (prog->info.stage == MESA_SHADER_TESS_EVAL ||
-          prog->info.stage == MESA_SHADER_GEOMETRY)
-         read_stream_out_from_cache(&blob_reader, &stcp->state);
-
-      if (nir) {
-         stcp->state.type = PIPE_SHADER_IR_NIR;
-         stcp->state.ir.nir = nir_deserialize(NULL, options, &blob_reader);
-         stcp->shader_program = shProg;
-         prog->nir = stcp->state.ir.nir;
-      } else {
-         read_tgsi_from_cache(&blob_reader, &stcp->state.tokens);
-      }
-      break;
+   if (prog->info.stage == MESA_SHADER_VERTEX) {
+      st_release_vp_variants(st, stp);
+
+      stp->num_inputs = blob_read_uint32(&blob_reader);
+      blob_copy_bytes(&blob_reader, (uint8_t *) stp->index_to_input,
+                      sizeof(stp->index_to_input));
+      blob_copy_bytes(&blob_reader, (uint8_t *) stp->input_to_index,
+                      sizeof(stp->input_to_index));
+      blob_copy_bytes(&blob_reader, (uint8_t *) stp->result_to_output,
+                      sizeof(stp->result_to_output));
+   } else if (prog->info.stage == MESA_SHADER_FRAGMENT) {
+      st_release_fp_variants(st, stp);
+   } else {
+      st_release_common_variants(st, stp);
    }
-   default:
-      unreachable("Unsupported stage");
+
+   if (prog->info.stage == MESA_SHADER_VERTEX ||
+       prog->info.stage == MESA_SHADER_TESS_EVAL ||
+       prog->info.stage == MESA_SHADER_GEOMETRY)
+      read_stream_out_from_cache(&blob_reader, &stp->state);
+
+   if (nir) {
+      stp->state.type = PIPE_SHADER_IR_NIR;
+      stp->state.ir.nir = nir_deserialize(NULL, options, &blob_reader);
+      stp->shader_program = shProg;
+      prog->nir = stp->state.ir.nir;
+   } else {
+      read_tgsi_from_cache(&blob_reader, &stp->state.tokens);
    }
 
    /* Make sure we don't try to read more data than we wrote. This should