diff --git a/src/amd/compiler/aco_instruction_selection.cpp b/src/amd/compiler/aco_instruction_selection.cpp index 7f079209d09..ec45c1a6d36 100644 --- a/src/amd/compiler/aco_instruction_selection.cpp +++ b/src/amd/compiler/aco_instruction_selection.cpp @@ -12012,7 +12012,7 @@ select_program(Program* program, unsigned shader_count, struct nir_shader* const const struct aco_shader_info* info, const struct radv_shader_args* args) { - isel_context ctx = setup_isel_context(program, shader_count, shaders, config, options, info, args, false, false); + isel_context ctx = setup_isel_context(program, shader_count, shaders, config, options, info, args, false); if_context ic_merged_wave_info; bool ngg_gs = ctx.stage.hw == HWStage::NGG && ctx.stage.has(SWStage::GS); @@ -12130,105 +12130,6 @@ select_program(Program* program, unsigned shader_count, struct nir_shader* const cleanup_cfg(program); } -void -select_gs_copy_shader(Program* program, struct nir_shader* gs_shader, ac_shader_config* config, - const struct aco_compiler_options* options, - const struct aco_shader_info* info, - const struct radv_shader_args* args) -{ - isel_context ctx = setup_isel_context(program, 1, &gs_shader, config, options, info, args, true, false); - - ctx.block->fp_mode = program->next_fp_mode; - - add_startpgm(&ctx); - append_logical_start(ctx.block); - - Builder bld(ctx.program, ctx.block); - - Temp gsvs_ring = bld.smem(aco_opcode::s_load_dwordx4, bld.def(s4), - program->private_segment_buffer, Operand::c32(RING_GSVS_VS * 16u)); - - Operand stream_id = Operand::zero(); - if (program->info.so.num_outputs) - stream_id = bld.sop2(aco_opcode::s_bfe_u32, bld.def(s1), bld.def(s1, scc), - get_arg(&ctx, ctx.args->ac.streamout_config), Operand::c32(0x20018u)); - - Temp vtx_offset = bld.vop2(aco_opcode::v_lshlrev_b32, bld.def(v1), Operand::c32(2u), - get_arg(&ctx, ctx.args->ac.vertex_id)); - - std::stack> if_contexts; - - for (unsigned stream = 0; stream < 4; stream++) { - if (stream_id.isConstant() && stream != stream_id.constantValue()) - continue; - - unsigned num_components = program->info.gs.num_stream_output_components[stream]; - if (stream > 0 && (!num_components || !program->info.so.num_outputs)) - continue; - - memset(ctx.outputs.mask, 0, sizeof(ctx.outputs.mask)); - - if (!stream_id.isConstant()) { - Temp cond = - bld.sopc(aco_opcode::s_cmp_eq_u32, bld.def(s1, scc), stream_id, Operand::c32(stream)); - if_contexts.emplace(); - begin_uniform_if_then(&ctx, &if_contexts.top(), cond); - bld.reset(ctx.block); - } - - unsigned offset = 0; - for (unsigned i = 0; i <= VARYING_SLOT_VAR31; ++i) { - if ((program->info.gs.output_streams[i] & 0x3) != stream) - continue; - - unsigned output_usage_mask = program->info.gs.output_usage_mask[i]; - unsigned length = util_last_bit(output_usage_mask); - for (unsigned j = 0; j < length; ++j) { - if (!(output_usage_mask & (1 << j))) - continue; - - Temp val = bld.tmp(v1); - unsigned const_offset = offset * program->info.gs.vertices_out * 16 * 4; - load_vmem_mubuf(&ctx, val, gsvs_ring, vtx_offset, Temp(), Temp(), const_offset, 4, 1, 0, true, - true, memory_sync_info()); - - ctx.outputs.mask[i] |= 1 << j; - ctx.outputs.temps[i * 4u + j] = val; - - offset++; - } - } - - if (program->info.so.num_outputs) { - emit_streamout(&ctx, stream); - bld.reset(ctx.block); - } - - if (stream == 0) { - create_vs_exports(&ctx); - } - - if (!stream_id.isConstant()) { - begin_uniform_if_else(&ctx, &if_contexts.top()); - bld.reset(ctx.block); - } - } - - while (!if_contexts.empty()) { - end_uniform_if(&ctx, &if_contexts.top()); - if_contexts.pop(); - } - - program->config->float_mode = program->blocks[0].fp_mode.val; - - append_logical_end(ctx.block); - ctx.block->kind |= block_kind_uniform; - bld.reset(ctx.block); - bld.sopp(aco_opcode::s_endpgm); - - cleanup_cfg(program); -} - void select_trap_handler_shader(Program* program, struct nir_shader* shader, ac_shader_config* config, const struct aco_compiler_options* options, @@ -12645,7 +12546,7 @@ select_ps_epilog(Program* program, const struct aco_ps_epilog_key* key, ac_shade const struct aco_shader_info* info, const struct radv_shader_args* args) { - isel_context ctx = setup_isel_context(program, 0, NULL, config, options, info, args, false, true); + isel_context ctx = setup_isel_context(program, 0, NULL, config, options, info, args, true); ctx.block->fp_mode = program->next_fp_mode; diff --git a/src/amd/compiler/aco_instruction_selection.h b/src/amd/compiler/aco_instruction_selection.h index 5370034303c..bc2ff89a413 100644 --- a/src/amd/compiler/aco_instruction_selection.h +++ b/src/amd/compiler/aco_instruction_selection.h @@ -128,8 +128,7 @@ isel_context setup_isel_context(Program* program, unsigned shader_count, struct nir_shader* const* shaders, ac_shader_config* config, const struct aco_compiler_options* options, const struct aco_shader_info* info, - const struct radv_shader_args* args, - bool is_gs_copy_shader, bool is_ps_epilog); + const struct radv_shader_args* args, bool is_ps_epilog); } // namespace aco diff --git a/src/amd/compiler/aco_instruction_selection_setup.cpp b/src/amd/compiler/aco_instruction_selection_setup.cpp index 61064622988..c7356e452e3 100644 --- a/src/amd/compiler/aco_instruction_selection_setup.cpp +++ b/src/amd/compiler/aco_instruction_selection_setup.cpp @@ -435,7 +435,7 @@ init_context(isel_context* ctx, nir_shader* shader) /* we'll need these for isel */ nir_metadata_require(impl, nir_metadata_block_index); - if (!ctx->stage.has(SWStage::GSCopy) && ctx->options->dump_preoptir) { + if (ctx->options->dump_preoptir) { fprintf(stderr, "NIR shader before instruction selection:\n"); nir_print_shader(shader, stderr); } @@ -805,8 +805,7 @@ isel_context setup_isel_context(Program* program, unsigned shader_count, struct nir_shader* const* shaders, ac_shader_config* config, const struct aco_compiler_options* options, const struct aco_shader_info* info, - const struct radv_shader_args* args, bool is_gs_copy_shader, - bool is_ps_epilog) + const struct radv_shader_args* args, bool is_ps_epilog) { SWStage sw_stage = SWStage::None; for (unsigned i = 0; i < shader_count; i++) { @@ -814,9 +813,7 @@ setup_isel_context(Program* program, unsigned shader_count, struct nir_shader* c case MESA_SHADER_VERTEX: sw_stage = sw_stage | SWStage::VS; break; case MESA_SHADER_TESS_CTRL: sw_stage = sw_stage | SWStage::TCS; break; case MESA_SHADER_TESS_EVAL: sw_stage = sw_stage | SWStage::TES; break; - case MESA_SHADER_GEOMETRY: - sw_stage = sw_stage | (is_gs_copy_shader ? SWStage::GSCopy : SWStage::GS); - break; + case MESA_SHADER_GEOMETRY: sw_stage = sw_stage | SWStage::GS; break; case MESA_SHADER_FRAGMENT: sw_stage = sw_stage | SWStage::FS; break; case MESA_SHADER_COMPUTE: sw_stage = sw_stage | SWStage::CS; break; case MESA_SHADER_TASK: sw_stage = sw_stage | SWStage::TS; break; @@ -845,8 +842,6 @@ setup_isel_context(Program* program, unsigned shader_count, struct nir_shader* c hw_stage = HWStage::FS; else if (sw_stage == SWStage::CS) hw_stage = HWStage::CS; - else if (sw_stage == SWStage::GSCopy) - hw_stage = HWStage::VS; else if (sw_stage == SWStage::TS) hw_stage = HWStage::CS; /* Task shaders are implemented with compute shaders. */ else if (sw_stage == SWStage::MS) @@ -898,19 +893,14 @@ setup_isel_context(Program* program, unsigned shader_count, struct nir_shader* c calc_min_waves(program); unsigned scratch_size = 0; - if (program->stage == gs_copy_vs) { - assert(shader_count == 1); - setup_vs_output_info(&ctx, shaders[0]); - } else { - for (unsigned i = 0; i < shader_count; i++) { - nir_shader* nir = shaders[i]; - setup_nir(&ctx, nir); - } - - for (unsigned i = 0; i < shader_count; i++) - scratch_size = std::max(scratch_size, shaders[i]->scratch_size); + for (unsigned i = 0; i < shader_count; i++) { + nir_shader* nir = shaders[i]; + setup_nir(&ctx, nir); } + for (unsigned i = 0; i < shader_count; i++) + scratch_size = std::max(scratch_size, shaders[i]->scratch_size); + ctx.program->config->scratch_bytes_per_wave = align(scratch_size * ctx.program->wave_size, 1024); unsigned nir_num_blocks = 0; diff --git a/src/amd/compiler/aco_interface.cpp b/src/amd/compiler/aco_interface.cpp index eebad656a97..7b55151f768 100644 --- a/src/amd/compiler/aco_interface.cpp +++ b/src/amd/compiler/aco_interface.cpp @@ -256,7 +256,6 @@ aco_compile_shader(const struct aco_compiler_options* options, (*build_binary)(binary, shaders[shader_count - 1]->info.stage, - args->is_gs_copy_shader, &config, llvm_ir.c_str(), llvm_ir.size(), diff --git a/src/amd/compiler/aco_interface.h b/src/amd/compiler/aco_interface.h index 7bef7727cf5..b894da8945c 100644 --- a/src/amd/compiler/aco_interface.h +++ b/src/amd/compiler/aco_interface.h @@ -46,7 +46,6 @@ struct aco_compiler_statistic_info { typedef void (aco_callback)(void **priv_ptr, gl_shader_stage stage, - bool is_gs_copy_shader, const struct ac_shader_config *config, const char *llvm_ir_str, unsigned llvm_ir_size, diff --git a/src/amd/compiler/aco_ir.h b/src/amd/compiler/aco_ir.h index 18ed836c437..0b08ccf07da 100644 --- a/src/amd/compiler/aco_ir.h +++ b/src/amd/compiler/aco_ir.h @@ -2025,7 +2025,6 @@ enum class SWStage : uint16_t { CS = 1 << 5, /* Compute Shader */ TS = 1 << 6, /* Task Shader */ MS = 1 << 7, /* Mesh Shader */ - GSCopy = 1 << 8, /* GS Copy Shader (internal) */ /* Stage combinations merged to run on a single HWStage */ VS_GS = VS | GS, @@ -2090,7 +2089,6 @@ static constexpr Stage vertex_vs(HWStage::VS, SWStage::VS); static constexpr Stage fragment_fs(HWStage::FS, SWStage::FS); static constexpr Stage compute_cs(HWStage::CS, SWStage::CS); static constexpr Stage tess_eval_vs(HWStage::VS, SWStage::TES); -static constexpr Stage gs_copy_vs(HWStage::VS, SWStage::GSCopy); /* Mesh shading pipeline */ static constexpr Stage task_cs(HWStage::CS, SWStage::TS); static constexpr Stage mesh_ngg(HWStage::NGG, SWStage::MS); @@ -2252,10 +2250,6 @@ void select_program(Program* program, unsigned shader_count, struct nir_shader* ac_shader_config* config, const struct aco_compiler_options* options, const struct aco_shader_info* info, const struct radv_shader_args* args); -void select_gs_copy_shader(Program* program, struct nir_shader* gs_shader, ac_shader_config* config, - const struct aco_compiler_options* options, - const struct aco_shader_info* info, - const struct radv_shader_args* args); void select_trap_handler_shader(Program* program, struct nir_shader* shader, ac_shader_config* config, const struct aco_compiler_options* options, diff --git a/src/amd/compiler/aco_print_ir.cpp b/src/amd/compiler/aco_print_ir.cpp index 2dcf088a701..b0f4ae471c1 100644 --- a/src/amd/compiler/aco_print_ir.cpp +++ b/src/amd/compiler/aco_print_ir.cpp @@ -869,8 +869,6 @@ print_stage(Stage stage, FILE* output) fprintf(output, "compute_cs"); else if (stage == fragment_fs) fprintf(output, "fragment_fs"); - else if (stage == gs_copy_vs) - fprintf(output, "gs_copy_vs"); else if (stage == vertex_ls) fprintf(output, "vertex_ls"); else if (stage == vertex_es) diff --git a/src/amd/vulkan/radv_nir_to_llvm.c b/src/amd/vulkan/radv_nir_to_llvm.c index eecd8f1d53b..a0a44d489e4 100644 --- a/src/amd/vulkan/radv_nir_to_llvm.c +++ b/src/amd/vulkan/radv_nir_to_llvm.c @@ -1013,8 +1013,9 @@ radv_llvm_export_vs(struct radv_shader_context *ctx, struct radv_shader_output_v } static void -handle_vs_outputs_post(struct radv_shader_context *ctx) +radv_llvm_visit_export_vertex(struct ac_shader_abi *abi) { + struct radv_shader_context *ctx = radv_shader_context_from_abi(abi); const struct radv_vs_output_info *outinfo = &ctx->shader_info->outinfo; const bool export_clip_dists = outinfo->export_clip_dists; struct radv_shader_output_values *outputs; @@ -1183,14 +1184,6 @@ ac_llvm_finalize_module(struct radv_shader_context *ctx, LLVMPassManagerRef pass ac_llvm_context_dispose(&ctx->ac); } -static void -radv_llvm_visit_export_vertex(struct ac_shader_abi *abi) -{ - struct radv_shader_context *ctx = radv_shader_context_from_abi(abi); - - handle_vs_outputs_post(ctx); -} - static void ac_setup_rings(struct radv_shader_context *ctx) { @@ -1623,134 +1616,6 @@ radv_compile_nir_shader(struct ac_llvm_compiler *ac_llvm, options); } -static void -ac_gs_copy_shader_emit(struct radv_shader_context *ctx) -{ - LLVMValueRef vtx_offset = - LLVMBuildMul(ctx->ac.builder, ac_get_arg(&ctx->ac, ctx->args->ac.vertex_id), - LLVMConstInt(ctx->ac.i32, 4, false), ""); - LLVMValueRef stream_id; - - /* Fetch the vertex stream ID. */ - if (ctx->shader_info->so.num_outputs) { - stream_id = - ac_unpack_param(&ctx->ac, ac_get_arg(&ctx->ac, ctx->args->ac.streamout_config), 24, 2); - } else { - stream_id = ctx->ac.i32_0; - } - - LLVMBasicBlockRef end_bb; - LLVMValueRef switch_inst; - - end_bb = LLVMAppendBasicBlockInContext(ctx->ac.context, ctx->main_function.value, "end"); - switch_inst = LLVMBuildSwitch(ctx->ac.builder, stream_id, end_bb, 4); - - for (unsigned stream = 0; stream < 4; stream++) { - unsigned num_components = ctx->shader_info->gs.num_stream_output_components[stream]; - LLVMBasicBlockRef bb; - unsigned offset; - - if (stream > 0 && !num_components) - continue; - - if (stream > 0 && !ctx->shader_info->so.num_outputs) - continue; - - bb = LLVMInsertBasicBlockInContext(ctx->ac.context, end_bb, "out"); - LLVMAddCase(switch_inst, LLVMConstInt(ctx->ac.i32, stream, 0), bb); - LLVMPositionBuilderAtEnd(ctx->ac.builder, bb); - - offset = 0; - for (unsigned i = 0; i < AC_LLVM_MAX_OUTPUTS; ++i) { - unsigned output_usage_mask = ctx->shader_info->gs.output_usage_mask[i]; - unsigned output_stream = ctx->shader_info->gs.output_streams[i] & 0x3; - int length = util_last_bit(output_usage_mask); - - if (!(ctx->output_mask & (1ull << i)) || output_stream != stream) - continue; - - for (unsigned j = 0; j < length; j++) { - LLVMValueRef value, soffset; - - if (!(output_usage_mask & (1 << j))) - continue; - - soffset = LLVMConstInt(ctx->ac.i32, offset * ctx->shader->info.gs.vertices_out * 16 * 4, - false); - - offset++; - - value = ac_build_buffer_load(&ctx->ac, ctx->gsvs_ring[0], 1, ctx->ac.i32_0, vtx_offset, - soffset, ctx->ac.f32, ac_glc | ac_slc, true, false); - - LLVMTypeRef type = LLVMGetAllocatedType(ctx->abi.outputs[ac_llvm_reg_index_soa(i, j)]); - if (ac_get_type_size(type) == 2) { - value = LLVMBuildBitCast(ctx->ac.builder, value, ctx->ac.i32, ""); - value = LLVMBuildTrunc(ctx->ac.builder, value, ctx->ac.i16, ""); - } - - LLVMBuildStore(ctx->ac.builder, ac_to_float(&ctx->ac, value), - ctx->abi.outputs[ac_llvm_reg_index_soa(i, j)]); - } - } - - if (ctx->shader_info->so.num_outputs) - radv_emit_streamout(ctx, stream); - - if (stream == 0) { - handle_vs_outputs_post(ctx); - } - - LLVMBuildBr(ctx->ac.builder, end_bb); - } - - LLVMPositionBuilderAtEnd(ctx->ac.builder, end_bb); -} - -static void -radv_compile_gs_copy_shader(struct ac_llvm_compiler *ac_llvm, - const struct radv_nir_compiler_options *options, - const struct radv_shader_info *info, - struct nir_shader *geom_shader, - struct radv_shader_binary **rbinary, - const struct radv_shader_args *args) -{ - struct radv_shader_context ctx = {0}; - ctx.args = args; - ctx.options = options; - ctx.shader_info = info; - - assert(args->is_gs_copy_shader); - - ac_llvm_context_init(&ctx.ac, ac_llvm, options->gfx_level, options->family, - options->has_3d_cube_border_color_mipmap, - AC_FLOAT_MODE_DEFAULT, 64, 64); - ctx.context = ctx.ac.context; - - ctx.stage = MESA_SHADER_VERTEX; - ctx.shader = geom_shader; - - create_function(&ctx, MESA_SHADER_VERTEX, false); - - ac_setup_rings(&ctx); - - nir_foreach_shader_out_variable(variable, geom_shader) - { - scan_shader_output_decl(&ctx, variable, geom_shader, MESA_SHADER_VERTEX); - ac_handle_shader_output_decl(&ctx.ac, &ctx.abi, geom_shader, variable, MESA_SHADER_VERTEX); - } - - ac_gs_copy_shader_emit(&ctx); - - LLVMBuildRetVoid(ctx.ac.builder); - - ac_llvm_finalize_module(&ctx, ac_llvm->passmgr); - - ac_compile_llvm_module(ac_llvm, ctx.ac.module, rbinary, MESA_SHADER_VERTEX, "GS Copy Shader", - options); - (*rbinary)->is_gs_copy_shader = true; -} - void llvm_compile_shader(const struct radv_nir_compiler_options *options, const struct radv_shader_info *info, unsigned shader_count, diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 58ee3deb3cc..300fe904c15 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -2045,8 +2045,7 @@ radv_open_rtld_binary(struct radv_device *device, const struct radv_shader *shad unsigned num_lds_symbols = 0; if (device->physical_device->rad_info.gfx_level >= GFX9 && - (binary->stage == MESA_SHADER_GEOMETRY || binary->info.is_ngg) && - !binary->is_gs_copy_shader) { + (binary->stage == MESA_SHADER_GEOMETRY || binary->info.is_ngg)) { struct ac_rtld_symbol *sym = &lds_symbols[num_lds_symbols++]; sym->name = "esgs_ring"; sym->size = binary->info.ngg_info.esgs_ring_size; @@ -2295,7 +2294,6 @@ radv_dump_nir_shaders(struct nir_shader *const *shaders, int shader_count) static void radv_aco_build_shader_binary(void **bin, gl_shader_stage stage, - bool is_gs_copy_shader, const struct ac_shader_config *config, const char *llvm_ir_str, unsigned llvm_ir_size, @@ -2322,7 +2320,6 @@ radv_aco_build_shader_binary(void **bin, struct radv_shader_binary_legacy *legacy_binary = (struct radv_shader_binary_legacy *)calloc(size, 1); legacy_binary->base.type = RADV_BINARY_TYPE_LEGACY; legacy_binary->base.stage = stage; - legacy_binary->base.is_gs_copy_shader = is_gs_copy_shader; legacy_binary->base.total_size = size; legacy_binary->base.config = *config; diff --git a/src/amd/vulkan/radv_shader.h b/src/amd/vulkan/radv_shader.h index 0efe7e32b5f..f9a5ed50f2b 100644 --- a/src/amd/vulkan/radv_shader.h +++ b/src/amd/vulkan/radv_shader.h @@ -429,7 +429,6 @@ enum radv_shader_binary_type { RADV_BINARY_TYPE_LEGACY, RADV_BINARY_TYPE_RTLD }; struct radv_shader_binary { enum radv_shader_binary_type type; gl_shader_stage stage; - bool is_gs_copy_shader; struct ac_shader_config config; struct radv_shader_info info;