From: Samuel Pitoiset Date: Tue, 18 Aug 2020 16:44:07 +0000 (+0200) Subject: radv: add a small interface for creating the trap handler shader X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8fd2f5c16d902708136764f7121aad471559fb23;p=mesa.git radv: add a small interface for creating the trap handler shader Similar to the GS copy shader except that NIR is unused because the shader is written directly using ACO IR. Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Part-of: --- diff --git a/src/amd/compiler/aco_interface.cpp b/src/amd/compiler/aco_interface.cpp index 5d402495ae5..8f45f503a82 100644 --- a/src/amd/compiler/aco_interface.cpp +++ b/src/amd/compiler/aco_interface.cpp @@ -72,6 +72,8 @@ void aco_compile_shader(unsigned shader_count, /* Instruction Selection */ if (args->is_gs_copy_shader) aco::select_gs_copy_shader(program.get(), shaders[0], &config, args); + else if (args->is_trap_handler_shader) + aco::select_trap_handler_shader(program.get(), shaders[0], &config, args); else aco::select_program(program.get(), shader_count, shaders, &config, args); if (args->options->dump_preoptir) { diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 1d227efe4af..8d0cd9d4feb 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -1202,6 +1202,7 @@ shader_variant_compile(struct radv_device *device, struct radv_shader_info *info, struct radv_nir_compiler_options *options, bool gs_copy_shader, + bool trap_handler_shader, bool keep_shader_info, bool keep_statistic_info, struct radv_shader_binary **binary_out) @@ -1234,6 +1235,8 @@ shader_variant_compile(struct radv_device *device, args.options = options; args.shader_info = info; args.is_gs_copy_shader = gs_copy_shader; + args.is_trap_handler_shader = trap_handler_shader; + radv_declare_shader_args(&args, gs_copy_shader ? MESA_SHADER_VERTEX : shaders[shader_count - 1]->info.stage, @@ -1271,7 +1274,7 @@ shader_variant_compile(struct radv_device *device, if (keep_shader_info) { variant->nir_string = radv_dump_nir_shaders(shaders, shader_count); - if (!gs_copy_shader && !module->nir) { + if (!gs_copy_shader && !trap_handler_shader && !module->nir) { variant->spirv = malloc(module->size); if (!variant->spirv) { free(variant); @@ -1314,7 +1317,8 @@ radv_shader_variant_compile(struct radv_device *device, options.robust_buffer_access = device->robust_buffer_access; return shader_variant_compile(device, module, shaders, shader_count, stage, info, - &options, false, keep_shader_info, keep_statistic_info, binary_out); + &options, false, false, + keep_shader_info, keep_statistic_info, binary_out); } struct radv_shader_variant * @@ -1332,7 +1336,33 @@ radv_create_gs_copy_shader(struct radv_device *device, options.key.has_multiview_view_index = multiview; return shader_variant_compile(device, NULL, &shader, 1, stage, - info, &options, true, keep_shader_info, keep_statistic_info, binary_out); + info, &options, true, false, + keep_shader_info, keep_statistic_info, binary_out); +} + +struct radv_shader_variant * +radv_create_trap_handler_shader(struct radv_device *device) +{ + struct radv_nir_compiler_options options = {0}; + struct radv_shader_variant *shader = NULL; + struct radv_shader_binary *binary = NULL; + struct radv_shader_info info = {0}; + + nir_builder b; + nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_COMPUTE, NULL); + b.shader->info.name = ralloc_strdup(b.shader, "meta_trap_handler"); + + options.explicit_scratch_args = true; + info.wave_size = 64; + + shader = shader_variant_compile(device, NULL, &b.shader, 1, + MESA_SHADER_COMPUTE, &info, &options, + false, true, true, false, &binary); + + ralloc_free(b.shader); + free(binary); + + return shader; } void diff --git a/src/amd/vulkan/radv_shader.h b/src/amd/vulkan/radv_shader.h index cb76e635dc5..1638614091c 100644 --- a/src/amd/vulkan/radv_shader.h +++ b/src/amd/vulkan/radv_shader.h @@ -488,6 +488,9 @@ radv_create_gs_copy_shader(struct radv_device *device, struct nir_shader *nir, bool multiview, bool keep_shader_info, bool keep_statistic_info); +struct radv_shader_variant * +radv_create_trap_handler_shader(struct radv_device *device); + void radv_shader_variant_destroy(struct radv_device *device, struct radv_shader_variant *variant); diff --git a/src/amd/vulkan/radv_shader_args.h b/src/amd/vulkan/radv_shader_args.h index 451077a9ede..f01c63ffa1a 100644 --- a/src/amd/vulkan/radv_shader_args.h +++ b/src/amd/vulkan/radv_shader_args.h @@ -69,6 +69,7 @@ struct radv_shader_args { struct ac_arg ngg_gs_state; bool is_gs_copy_shader; + bool is_trap_handler_shader; }; static inline struct radv_shader_args *