From 5d3895d13b58f5cae29fea7ef754bda93801cca1 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Fri, 28 Oct 2022 10:22:27 -0700 Subject: [PATCH] nir: Add way to create passthrough TCS without VS nir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Marek Olšák Part-of: --- src/compiler/nir/nir.h | 3 ++ src/compiler/nir/nir_passthrough_tcs.c | 31 ++++++++++++++----- .../drivers/radeonsi/si_shaderlib_nir.c | 12 +++++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index af5fbfb6f55..2342662ad21 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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); diff --git a/src/compiler/nir/nir_passthrough_tcs.c b/src/compiler/nir/nir_passthrough_tcs.c index f03ee0a6f4c..d0ddca21adc 100644 --- a/src/compiler/nir/nir_passthrough_tcs.c +++ b/src/compiler/nir/nir_passthrough_tcs.c @@ -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); +} diff --git a/src/gallium/drivers/radeonsi/si_shaderlib_nir.c b/src/gallium/drivers/radeonsi/si_shaderlib_nir.c index 00ff8102ea5..0c01f0179b1 100644 --- a/src/gallium/drivers/radeonsi/si_shaderlib_nir.c +++ b/src/gallium/drivers/radeonsi/si_shaderlib_nir.c @@ -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); }