radv,aco: add a separate function to compile the trap handler shader

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32056>
This commit is contained in:
Samuel Pitoiset 2024-11-08 14:22:05 +01:00 committed by Marge Bot
parent 62e335c779
commit 44dfeb4479
5 changed files with 56 additions and 8 deletions

View file

@ -12451,7 +12451,7 @@ dump_sgpr_to_mem(isel_context* ctx, Operand rsrc, Operand data, uint32_t offset)
}
void
select_trap_handler_shader(Program* program, struct nir_shader* shader, ac_shader_config* config,
select_trap_handler_shader(Program* program, ac_shader_config* config,
const struct aco_compiler_options* options,
const struct aco_shader_info* info, const struct ac_shader_args* args)
{

View file

@ -269,10 +269,7 @@ aco_compile_shader(const struct aco_compiler_options* options, const struct aco_
program->debug.private_data = options->debug.private_data;
/* Instruction Selection */
if (info->is_trap_handler_shader)
select_trap_handler_shader(program.get(), shaders[0], &config, options, info, args);
else
select_program(program.get(), shader_count, shaders, &config, options, info, args);
select_program(program.get(), shader_count, shaders, &config, options, info, args);
std::string llvm_ir = aco_postprocess_shader(options, info, program);
@ -408,6 +405,38 @@ aco_compile_ps_prolog(const struct aco_compiler_options* options,
binary, true);
}
void
aco_compile_trap_handler(const struct aco_compiler_options* options,
const struct aco_shader_info* info, const struct ac_shader_args* args,
aco_callback* build_binary, void** binary)
{
init();
ac_shader_config config = {0};
std::unique_ptr<Program> program{new Program};
program->collect_statistics = false;
program->debug.func = NULL;
program->debug.private_data = NULL;
select_trap_handler_shader(program.get(), &config, options, info, args);
aco_postprocess_shader(options, info, program);
/* assembly */
std::vector<uint32_t> code;
code.reserve(align(program->blocks[0].instructions.size() * 2, 16));
unsigned exec_size = emit_program(program.get(), code);
bool get_disasm = options->dump_shader || options->record_ir;
std::string disasm;
if (get_disasm)
disasm = get_disasm_string(program.get(), code, exec_size);
(*build_binary)(binary, &config, NULL, 0, disasm.c_str(), disasm.size(), program->statistics, 0,
exec_size, code.data(), code.size(), NULL, 0, NULL, 0);
}
uint64_t
aco_get_codegen_flags()
{

View file

@ -72,6 +72,10 @@ void aco_compile_ps_prolog(const struct aco_compiler_options* options,
const struct ac_shader_args* args,
aco_shader_part_callback* build_prolog, void** binary);
void aco_compile_trap_handler(const struct aco_compiler_options* options,
const struct aco_shader_info* info, const struct ac_shader_args* args,
aco_callback* build_binary, void** binary);
uint64_t aco_get_codegen_flags();
bool aco_is_gpu_supported(const struct radeon_info* info);

View file

@ -2223,8 +2223,7 @@ void init_program(Program* program, Stage stage, const struct aco_shader_info* i
void select_program(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 ac_shader_args* args);
void select_trap_handler_shader(Program* program, struct nir_shader* shader,
ac_shader_config* config,
void select_trap_handler_shader(Program* program, ac_shader_config* config,
const struct aco_compiler_options* options,
const struct aco_shader_info* info,
const struct ac_shader_args* args);

View file

@ -3144,7 +3144,23 @@ radv_create_trap_handler_shader(struct radv_device *device)
struct radv_shader_args args;
radv_declare_shader_args(device, NULL, &info, stage, MESA_SHADER_NONE, &args);
struct radv_shader_binary *binary = shader_compile(device, &b.shader, 1, stage, &info, &args, &stage_key, &options);
#if AMD_LLVM_AVAILABLE
if (options.dump_shader || options.record_ir)
ac_init_llvm_once();
#endif
struct radv_shader_binary *binary = NULL;
struct aco_compiler_options ac_opts;
struct aco_shader_info ac_info;
radv_aco_convert_shader_info(&ac_info, &info, &args, &device->cache_key, options.info->gfx_level);
radv_aco_convert_opts(&ac_opts, &options, &args, &stage_key);
aco_compile_trap_handler(&ac_opts, &ac_info, &args.ac, &radv_aco_build_shader_binary, (void **)&binary);
binary->info = info;
radv_postprocess_binary_config(device, binary, &args);
struct radv_shader *shader;
radv_shader_create_uncached(device, binary, false, NULL, &shader);