radv: add a small interface for creating the trap handler shader
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 18 Aug 2020 16:44:07 +0000 (18:44 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 24 Aug 2020 11:08:24 +0000 (11:08 +0000)
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 <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6384>

src/amd/compiler/aco_interface.cpp
src/amd/vulkan/radv_shader.c
src/amd/vulkan/radv_shader.h
src/amd/vulkan/radv_shader_args.h

index 5d402495ae545fa9ecbf79a5887c5eaad29f14d6..8f45f503a824e6dabf9847f006240fc70cc337e7 100644 (file)
@@ -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) {
index 1d227efe4afeea6fe66c0ca05a12b5e325a33df0..8d0cd9d4feb7d60a32361d68dc3c97f94439751c 100644 (file)
@@ -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
index cb76e635dc5f7f75cff70bfdcc3e4259aa1d17e9..1638614091cebe822d3c368fb46ede8f231aa638 100644 (file)
@@ -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);
index 451077a9ede049a444e7a5d07be6bc4b334390a9..f01c63ffa1acd842677c44a33f495e949dc066df 100644 (file)
@@ -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 *