nir: Add way to create passthrough TCS without VS nir
authorRob Clark <robdclark@chromium.org>
Fri, 28 Oct 2022 17:22:27 +0000 (10:22 -0700)
committerMarge Bot <emma+marge@anholt.net>
Sat, 29 Oct 2022 17:46:23 +0000 (17:46 +0000)
In the case of disk-cache hits, radeonsi no longer has the nir shader
around.  So add a way to create a passthrough TCS with just the VS
output locations.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7567
Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19382>

src/compiler/nir/nir.h
src/compiler/nir/nir_passthrough_tcs.c
src/gallium/drivers/radeonsi/si_shaderlib_nir.c

index af5fbfb..2342662 100644 (file)
@@ -4917,6 +4917,9 @@ void nir_lower_io_to_scalar(nir_shader *shader, nir_variable_mode mask);
 bool nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask);
 bool nir_lower_io_to_vector(nir_shader *shader, nir_variable_mode mask);
 bool nir_vectorize_tess_levels(nir_shader *shader);
+nir_shader * nir_create_passthrough_tcs_impl(const nir_shader_compiler_options *options,
+                                             unsigned *locations, unsigned num_locations,
+                                             uint8_t patch_vertices);
 nir_shader * nir_create_passthrough_tcs(const nir_shader_compiler_options *options,
                                         const nir_shader *vs, uint8_t patch_vertices);
 
index f03ee0a..d0ddca2 100644 (file)
@@ -35,8 +35,9 @@
  */
 
 nir_shader *
-nir_create_passthrough_tcs(const nir_shader_compiler_options *options,
-                           const nir_shader *vs, uint8_t patch_vertices)
+nir_create_passthrough_tcs_impl(const nir_shader_compiler_options *options,
+                                unsigned *locations, unsigned num_locations,
+                                uint8_t patch_vertices)
 {
    nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_TESS_CTRL, options,
                                                   "tcs passthrough");
@@ -73,9 +74,9 @@ nir_create_passthrough_tcs(const nir_shader_compiler_options *options,
    nir_store_var(&b, out_outer, outer, 0xf);
 
    nir_ssa_def *id = nir_load_invocation_id(&b);
-   nir_foreach_shader_out_variable(var, vs) {
+   for (unsigned i = 0; i < num_locations; i++) {
       const struct glsl_type *type;
-      unsigned semantic = var->data.location;
+      unsigned semantic = locations[i];
       if (semantic < VARYING_SLOT_VAR31 && semantic != VARYING_SLOT_EDGE)
          type = glsl_array_type(glsl_vec4_type(), 0, 0);
       else if (semantic >= VARYING_SLOT_VAR0_16BIT)
@@ -83,13 +84,13 @@ nir_create_passthrough_tcs(const nir_shader_compiler_options *options,
       else
          continue;
 
-      char name[1024];
-      snprintf(name, sizeof(name), "in_%s", var->name);
+      char name[10];
+      snprintf(name, sizeof(name), "in_%d", i);
       nir_variable *in = nir_variable_create(b.shader, nir_var_shader_in, type, name);
       in->data.location = semantic;
       in->data.driver_location = num_inputs++;
 
-      snprintf(name, sizeof(name), "out_%s", var->name);
+      snprintf(name, sizeof(name), "out_%d", i);
       nir_variable *out = nir_variable_create(b.shader, nir_var_shader_out, type, name);
       out->data.location = semantic;
       out->data.driver_location = num_outputs++;
@@ -108,3 +109,19 @@ nir_create_passthrough_tcs(const nir_shader_compiler_options *options,
 
    return b.shader;
 }
+
+
+nir_shader *
+nir_create_passthrough_tcs(const nir_shader_compiler_options *options,
+                           const nir_shader *vs, uint8_t patch_vertices)
+{
+   unsigned locations[MAX_VARYING];
+   unsigned num_outputs = 0;
+
+   nir_foreach_shader_out_variable (var, vs) {
+      assert(num_outputs < ARRAY_SIZE(locations));
+      locations[num_outputs++] = var->data.location;
+   }
+
+   return nir_create_passthrough_tcs_impl(options, locations, num_outputs, patch_vertices);
+}
index 00ff810..0c01f01 100644 (file)
@@ -284,8 +284,16 @@ void *si_create_passthrough_tcs(struct si_context *sctx)
       sctx->b.screen->get_compiler_options(sctx->b.screen, PIPE_SHADER_IR_NIR,
                                            PIPE_SHADER_TESS_CTRL);
 
-   nir_shader *tcs = nir_create_passthrough_tcs(options, sctx->shader.vs.cso->nir,
-                                                sctx->patch_vertices);
+   unsigned locations[PIPE_MAX_SHADER_OUTPUTS];
+
+   struct si_shader_info *info = &sctx->shader.vs.cso->info;
+   for (unsigned i = 0; i < info->num_outputs; i++) {
+      locations[i] = info->output_semantic[i];
+   }
+
+   nir_shader *tcs =
+         nir_create_passthrough_tcs_impl(options, locations, info->num_outputs,
+                                         sctx->patch_vertices);
 
    return create_shader_state(sctx, tcs);
 }