From 3ab9c42b43d907696d2e18c5020a5abcaae47096 Mon Sep 17 00:00:00 2001 From: Qiang Yu Date: Wed, 18 May 2022 17:12:58 +0800 Subject: [PATCH] radeonsi: add si_create_passthrough_tcs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For replacing si_create_fixed_func_tcs. Reviewed-by: Marek Olšák Acked-by: Pierre-Eric Pelloux-Prayer Signed-off-by: Qiang Yu Part-of: --- src/gallium/drivers/radeonsi/si_pipe.h | 1 + src/gallium/drivers/radeonsi/si_shaderlib_nir.c | 79 +++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index 2b18772..80ec9ae 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -1552,6 +1552,7 @@ void si_resume_queries(struct si_context *sctx); void *si_create_copy_image_cs(struct si_context *sctx, bool src_is_1d_array, bool dst_is_1d_array); void *si_create_dcc_retile_cs(struct si_context *sctx, struct radeon_surf *surf); void *gfx9_create_clear_dcc_msaa_cs(struct si_context *sctx, struct si_texture *tex); +void *si_create_passthrough_tcs(struct si_context *sctx); /* si_shaderlib_tgsi.c */ void *si_get_blitter_vs(struct si_context *sctx, enum blitter_attrib_type type, diff --git a/src/gallium/drivers/radeonsi/si_shaderlib_nir.c b/src/gallium/drivers/radeonsi/si_shaderlib_nir.c index a62b246..f92218b 100644 --- a/src/gallium/drivers/radeonsi/si_shaderlib_nir.c +++ b/src/gallium/drivers/radeonsi/si_shaderlib_nir.c @@ -268,3 +268,82 @@ void *si_create_clear_buffer_rmw_cs(struct si_context *sctx) return create_shader_state(sctx, b.shader); } +/* This is used when TCS is NULL in the VS->TCS->TES chain. In this case, + * VS passes its outputs to TES directly, so the fixed-function shader only + * has to write TESSOUTER and TESSINNER. + */ +void *si_create_passthrough_tcs(struct si_context *sctx) +{ + const nir_shader_compiler_options *options = + sctx->b.screen->get_compiler_options(sctx->b.screen, PIPE_SHADER_IR_NIR, + PIPE_SHADER_TESS_CTRL); + + nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_TESS_CTRL, options, + "tcs passthrough"); + + unsigned num_inputs = 0; + unsigned num_outputs = 0; + + nir_variable *in_inner = + nir_variable_create(b.shader, nir_var_system_value, glsl_vec_type(2), + "tess inner default"); + in_inner->data.location = SYSTEM_VALUE_TESS_LEVEL_INNER_DEFAULT; + + nir_variable *out_inner = + nir_variable_create(b.shader, nir_var_shader_out, glsl_vec_type(2), + "tess inner"); + out_inner->data.location = VARYING_SLOT_TESS_LEVEL_INNER; + out_inner->data.driver_location = num_outputs++; + + nir_ssa_def *inner = nir_load_var(&b, in_inner); + nir_store_var(&b, out_inner, inner, 0x3); + + nir_variable *in_outer = + nir_variable_create(b.shader, nir_var_system_value, glsl_vec4_type(), + "tess outer default"); + in_outer->data.location = SYSTEM_VALUE_TESS_LEVEL_OUTER_DEFAULT; + + nir_variable *out_outer = + nir_variable_create(b.shader, nir_var_shader_out, glsl_vec4_type(), + "tess outer"); + out_outer->data.location = VARYING_SLOT_TESS_LEVEL_OUTER; + out_outer->data.driver_location = num_outputs++; + + nir_ssa_def *outer = nir_load_var(&b, in_outer); + nir_store_var(&b, out_outer, outer, 0xf); + + nir_ssa_def *id = nir_load_invocation_id(&b); + struct si_shader_info *info = &sctx->shader.vs.cso->info; + for (unsigned i = 0; i < info->num_outputs; i++) { + const struct glsl_type *type; + unsigned semantic = info->output_semantic[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) + type = glsl_array_type(glsl_vector_type(GLSL_TYPE_FLOAT16, 4), 0, 0); + else + continue; + + char name[10]; + snprintf(name, sizeof(name), "in_%u", 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_%u", 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++; + + /* no need to use copy_var to save a lower pass */ + nir_ssa_def *value = nir_load_array_var(&b, in, id); + nir_store_array_var(&b, out, id, value, 0xf); + } + + b.shader->num_inputs = num_inputs; + b.shader->num_outputs = num_outputs; + + b.shader->info.tess.tcs_vertices_out = sctx->patch_vertices; + + return create_shader_state(sctx, b.shader); +} -- 2.7.4