radv,aco: disable opts if VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 28 Aug 2020 06:41:20 +0000 (08:41 +0200)
committerMarge Bot <eric+marge@anholt.net>
Fri, 4 Sep 2020 06:59:45 +0000 (06:59 +0000)
Sounds useful to determine if ACO breaks a specific pipeline
because of various optimizations.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6487>

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

index 4b0ea2ff5d042c888415b9b6349dfbff28d7725c..27a072ce6bbd27e12681bd57bab14533ec01620c 100644 (file)
@@ -89,10 +89,12 @@ void aco_compile_shader(unsigned shader_count,
       validate(program.get());
 
       /* Optimization */
       validate(program.get());
 
       /* Optimization */
-      if (!(aco::debug_flags & aco::DEBUG_NO_VN))
-         aco::value_numbering(program.get());
-      if (!(aco::debug_flags & aco::DEBUG_NO_OPT))
-         aco::optimize(program.get());
+      if (!args->options->disable_optimizations) {
+         if (!(aco::debug_flags & aco::DEBUG_NO_VN))
+            aco::value_numbering(program.get());
+         if (!(aco::debug_flags & aco::DEBUG_NO_OPT))
+            aco::optimize(program.get());
+      }
 
       /* cleanup and exec mask handling */
       aco::setup_reduce_temp(program.get());
 
       /* cleanup and exec mask handling */
       aco::setup_reduce_temp(program.get());
@@ -123,7 +125,8 @@ void aco_compile_shader(unsigned shader_count,
       aco::collect_presched_stats(program.get());
 
    if (!args->is_trap_handler_shader) {
       aco::collect_presched_stats(program.get());
 
    if (!args->is_trap_handler_shader) {
-      if (!(aco::debug_flags & aco::DEBUG_NO_SCHED))
+      if (!args->options->disable_optimizations &&
+          !(aco::debug_flags & aco::DEBUG_NO_SCHED))
          aco::schedule_program(program.get(), live_vars);
       validate(program.get());
 
          aco::schedule_program(program.get(), live_vars);
       validate(program.get());
 
index c6d029159c78d5a50ed7d983a4ef6d602dfebac3..e56b0ec5fddee83a85cfb508d824961dc3541ad2 100644 (file)
@@ -2840,6 +2840,7 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline,
        bool keep_statistic_info = (flags & VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR) ||
                                   (device->instance->debug_flags & RADV_DEBUG_DUMP_SHADER_STATS) ||
                                   device->keep_shader_info;
        bool keep_statistic_info = (flags & VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR) ||
                                   (device->instance->debug_flags & RADV_DEBUG_DUMP_SHADER_STATS) ||
                                   device->keep_shader_info;
+       bool disable_optimizations = flags & VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
 
        radv_start_feedback(pipeline_feedback);
 
 
        radv_start_feedback(pipeline_feedback);
 
@@ -3003,7 +3004,8 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline,
                        pipeline->gs_copy_shader = radv_create_gs_copy_shader(
                                        device, nir[MESA_SHADER_GEOMETRY], &info,
                                        &gs_copy_binary, keep_executable_info, keep_statistic_info,
                        pipeline->gs_copy_shader = radv_create_gs_copy_shader(
                                        device, nir[MESA_SHADER_GEOMETRY], &info,
                                        &gs_copy_binary, keep_executable_info, keep_statistic_info,
-                                       keys[MESA_SHADER_GEOMETRY].has_multiview_view_index);
+                                       keys[MESA_SHADER_GEOMETRY].has_multiview_view_index,
+                                       disable_optimizations);
                }
 
                if (!keep_executable_info && !keep_statistic_info && pipeline->gs_copy_shader) {
                }
 
                if (!keep_executable_info && !keep_statistic_info && pipeline->gs_copy_shader) {
@@ -3030,7 +3032,8 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline,
                                                          pipeline->layout, keys + MESA_SHADER_FRAGMENT,
                                                          infos + MESA_SHADER_FRAGMENT,
                                                          keep_executable_info, keep_statistic_info,
                                                          pipeline->layout, keys + MESA_SHADER_FRAGMENT,
                                                          infos + MESA_SHADER_FRAGMENT,
                                                          keep_executable_info, keep_statistic_info,
-                                                         &binaries[MESA_SHADER_FRAGMENT]);
+                                                         disable_optimizations,
+                                                         &binaries[MESA_SHADER_FRAGMENT]);
 
                        radv_stop_feedback(stage_feedbacks[MESA_SHADER_FRAGMENT], false);
                }
 
                        radv_stop_feedback(stage_feedbacks[MESA_SHADER_FRAGMENT], false);
                }
@@ -3047,7 +3050,9 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline,
                        pipeline->shaders[MESA_SHADER_TESS_CTRL] = radv_shader_variant_compile(device, modules[MESA_SHADER_TESS_CTRL], combined_nir, 2,
                                                                                              pipeline->layout,
                                                                                              &key, &infos[MESA_SHADER_TESS_CTRL], keep_executable_info,
                        pipeline->shaders[MESA_SHADER_TESS_CTRL] = radv_shader_variant_compile(device, modules[MESA_SHADER_TESS_CTRL], combined_nir, 2,
                                                                                              pipeline->layout,
                                                                                              &key, &infos[MESA_SHADER_TESS_CTRL], keep_executable_info,
-                                                                                             keep_statistic_info, &binaries[MESA_SHADER_TESS_CTRL]);
+                                                                                             keep_statistic_info,
+                                                                                             disable_optimizations,
+                                                                                             &binaries[MESA_SHADER_TESS_CTRL]);
 
                        radv_stop_feedback(stage_feedbacks[MESA_SHADER_TESS_CTRL], false);
                }
 
                        radv_stop_feedback(stage_feedbacks[MESA_SHADER_TESS_CTRL], false);
                }
@@ -3066,7 +3071,9 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline,
                        pipeline->shaders[MESA_SHADER_GEOMETRY] = radv_shader_variant_compile(device, modules[MESA_SHADER_GEOMETRY], combined_nir, 2,
                                                                                             pipeline->layout,
                                                                                             &keys[pre_stage], &infos[MESA_SHADER_GEOMETRY], keep_executable_info,
                        pipeline->shaders[MESA_SHADER_GEOMETRY] = radv_shader_variant_compile(device, modules[MESA_SHADER_GEOMETRY], combined_nir, 2,
                                                                                             pipeline->layout,
                                                                                             &keys[pre_stage], &infos[MESA_SHADER_GEOMETRY], keep_executable_info,
-                                                                                            keep_statistic_info, &binaries[MESA_SHADER_GEOMETRY]);
+                                                                                            keep_statistic_info,
+                                                                                            disable_optimizations,
+                                                                                            &binaries[MESA_SHADER_GEOMETRY]);
 
                        radv_stop_feedback(stage_feedbacks[MESA_SHADER_GEOMETRY], false);
                }
 
                        radv_stop_feedback(stage_feedbacks[MESA_SHADER_GEOMETRY], false);
                }
@@ -3088,7 +3095,9 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline,
                        pipeline->shaders[i] = radv_shader_variant_compile(device, modules[i], &nir[i], 1,
                                                                          pipeline->layout,
                                                                          keys + i, infos + i, keep_executable_info,
                        pipeline->shaders[i] = radv_shader_variant_compile(device, modules[i], &nir[i], 1,
                                                                          pipeline->layout,
                                                                          keys + i, infos + i, keep_executable_info,
-                                                                         keep_statistic_info, &binaries[i]);
+                                                                         keep_statistic_info,
+                                                                         disable_optimizations,
+                                                                         &binaries[i]);
 
                        radv_stop_feedback(stage_feedbacks[i], false);
                }
 
                        radv_stop_feedback(stage_feedbacks[i], false);
                }
index aff3249da9572177ac1f90e70d637f628dc7aaaf..c76975c22526d09edf175127dbb209d171054899 100644 (file)
@@ -1324,6 +1324,7 @@ radv_shader_variant_compile(struct radv_device *device,
                           const struct radv_shader_variant_key *key,
                           struct radv_shader_info *info,
                           bool keep_shader_info, bool keep_statistic_info,
                           const struct radv_shader_variant_key *key,
                           struct radv_shader_info *info,
                           bool keep_shader_info, bool keep_statistic_info,
+                          bool disable_optimizations,
                           struct radv_shader_binary **binary_out)
 {
        gl_shader_stage stage =  shaders[shader_count - 1]->info.stage;
                           struct radv_shader_binary **binary_out)
 {
        gl_shader_stage stage =  shaders[shader_count - 1]->info.stage;
@@ -1335,6 +1336,7 @@ radv_shader_variant_compile(struct radv_device *device,
 
        options.explicit_scratch_args = !radv_use_llvm_for_stage(device, stage);
        options.robust_buffer_access = device->robust_buffer_access;
 
        options.explicit_scratch_args = !radv_use_llvm_for_stage(device, stage);
        options.robust_buffer_access = device->robust_buffer_access;
+       options.disable_optimizations = disable_optimizations;
 
        return shader_variant_compile(device, module, shaders, shader_count, stage, info,
                                      &options, false, false,
 
        return shader_variant_compile(device, module, shaders, shader_count, stage, info,
                                      &options, false, false,
@@ -1347,13 +1349,14 @@ radv_create_gs_copy_shader(struct radv_device *device,
                           struct radv_shader_info *info,
                           struct radv_shader_binary **binary_out,
                           bool keep_shader_info, bool keep_statistic_info,
                           struct radv_shader_info *info,
                           struct radv_shader_binary **binary_out,
                           bool keep_shader_info, bool keep_statistic_info,
-                          bool multiview)
+                          bool multiview, bool disable_optimizations)
 {
        struct radv_nir_compiler_options options = {0};
        gl_shader_stage stage = MESA_SHADER_VERTEX;
 
        options.explicit_scratch_args = !radv_use_llvm_for_stage(device, stage);
        options.key.has_multiview_view_index = multiview;
 {
        struct radv_nir_compiler_options options = {0};
        gl_shader_stage stage = MESA_SHADER_VERTEX;
 
        options.explicit_scratch_args = !radv_use_llvm_for_stage(device, stage);
        options.key.has_multiview_view_index = multiview;
+       options.disable_optimizations = disable_optimizations;
 
        return shader_variant_compile(device, NULL, &shader, 1, stage,
                                      info, &options, true, false,
 
        return shader_variant_compile(device, NULL, &shader, 1, stage,
                                      info, &options, true, false,
index 81f620140092c2006505f6165ec7aa36d00545fb..59497891ffd219912317fea5a3fec8a33e5c1c99 100644 (file)
@@ -148,6 +148,7 @@ struct radv_nir_compiler_options {
        bool has_ls_vgpr_init_bug;
        bool use_ngg_streamout;
        bool enable_mrt_output_nan_fixup;
        bool has_ls_vgpr_init_bug;
        bool use_ngg_streamout;
        bool enable_mrt_output_nan_fixup;
+       bool disable_optimizations; /* only used by ACO */
        enum radeon_family family;
        enum chip_class chip_class;
        uint32_t tess_offchip_block_dw_size;
        enum radeon_family family;
        enum chip_class chip_class;
        uint32_t tess_offchip_block_dw_size;
@@ -479,6 +480,7 @@ radv_shader_variant_compile(struct radv_device *device,
                            const struct radv_shader_variant_key *key,
                            struct radv_shader_info *info,
                            bool keep_shader_info, bool keep_statistic_info,
                            const struct radv_shader_variant_key *key,
                            struct radv_shader_info *info,
                            bool keep_shader_info, bool keep_statistic_info,
+                           bool disable_optimizations,
                            struct radv_shader_binary **binary_out);
 
 struct radv_shader_variant *
                            struct radv_shader_binary **binary_out);
 
 struct radv_shader_variant *
@@ -486,7 +488,8 @@ radv_create_gs_copy_shader(struct radv_device *device, struct nir_shader *nir,
                           struct radv_shader_info *info,
                           struct radv_shader_binary **binary_out,
                           bool multiview,  bool keep_shader_info,
                           struct radv_shader_info *info,
                           struct radv_shader_binary **binary_out,
                           bool multiview,  bool keep_shader_info,
-                          bool keep_statistic_info);
+                          bool keep_statistic_info,
+                          bool disable_optimizations);
 
 struct radv_shader_variant *
 radv_create_trap_handler_shader(struct radv_device *device);
 
 struct radv_shader_variant *
 radv_create_trap_handler_shader(struct radv_device *device);