r600/sfn: Allow skipping backend shader optimization for a subset of shaders

This comes in handy when debugging problems with the backend optimizer

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25846>
This commit is contained in:
Gert Wollny 2023-10-22 20:28:49 +02:00 committed by Marge Bot
parent 777c25255b
commit 5de814171b
4 changed files with 29 additions and 6 deletions

View file

@ -45,6 +45,7 @@
#include "sfn_scheduler.h"
#include "sfn_shader.h"
#include "sfn_split_address_loads.h"
#include "util/u_debug.h"
#include "util/u_prim.h"
#include <vector>
@ -746,6 +747,9 @@ r600_finalize_nir_common(nir_shader *nir, enum amd_gfx_level gfx_level)
;
}
DEBUG_GET_ONCE_NUM_OPTION(skip_opt_start, "R600_SFN_SKIP_OPT_START", -1);
DEBUG_GET_ONCE_NUM_OPTION(skip_opt_end, "R600_SFN_SKIP_OPT_END", -1);
void
r600_lower_and_optimize_nir(nir_shader *sh,
const union r600_shader_key *key,
@ -893,9 +897,17 @@ r600_finalize_and_optimize_shader(r600::Shader *shader)
shader->print(std::cerr);
}
if (!r600::sfn_log.has_debug_flag(r600::SfnLog::noopt)) {
optimize(*shader);
auto sfn_skip_opt_start = debug_get_option_skip_opt_start();
auto sfn_skip_opt_end = debug_get_option_skip_opt_end();
bool skip_shader_opt_per_id = sfn_skip_opt_start >= 0 &&
sfn_skip_opt_start <= shader->shader_id() &&
sfn_skip_opt_end >= shader->shader_id();
bool skip_shader_opt = r600::sfn_log.has_debug_flag(r600::SfnLog::noopt) ||
skip_shader_opt_per_id;
if (!skip_shader_opt) {
optimize(*shader);
if (r600::sfn_log.has_debug_flag(r600::SfnLog::steps)) {
std::cerr << "Shader after optimization\n";
shader->print(std::cerr);
@ -909,9 +921,8 @@ r600_finalize_and_optimize_shader(r600::Shader *shader)
shader->print(std::cerr);
}
if (!r600::sfn_log.has_debug_flag(r600::SfnLog::noopt)) {
if (!skip_shader_opt) {
optimize(*shader);
if (r600::sfn_log.has_debug_flag(r600::SfnLog::steps)) {
std::cerr << "Shader after optimization\n";
shader->print(std::cerr);

View file

@ -151,12 +151,15 @@ ShaderInput::set_uses_interpolate_at_centroid()
m_uses_interpolate_at_centroid = true;
}
int64_t Shader::s_next_shader_id = 1;
Shader::Shader(const char *type_id, unsigned atomic_base):
m_current_block(nullptr),
m_type_id(type_id),
m_chip_class(ISA_CC_R600),
m_next_block(0),
m_atomic_base(atomic_base)
m_atomic_base(atomic_base),
m_shader_id(s_next_shader_id++)
{
m_instr_factory = new InstrFactory();
m_chain_instr.this_shader = this;
@ -1615,6 +1618,7 @@ void
Shader::print_header(std::ostream& os) const
{
assert(m_chip_class <= ISA_CC_CAYMAN);
os << "Shader: " << m_shader_id << "\n";
os << m_type_id << "\n";
os << "CHIPCLASS " << chip_class_names[m_chip_class] << "\n";
print_properties(os);

View file

@ -149,6 +149,10 @@ public:
virtual ~Shader() {}
auto shader_id() const {return m_shader_id;}
// Needed for testing
void reset_shader_id() {m_shader_id = 0;}
bool add_info_from_string(std::istream& is);
static Shader *translate_from_nir(nir_shader *nir,
@ -378,6 +382,9 @@ private:
uint32_t m_nloops{0};
uint32_t m_required_registers{0};
int64_t m_shader_id;
static int64_t s_next_shader_id;
class InstructionChain : public InstrVisitor {
public:
void visit(AluGroup *instr) override { (void)instr; }
@ -414,7 +421,6 @@ private:
std::list<Instr *, Allocator<Instr *>> m_loops;
int m_control_flow_depth{0};
std::list<nir_intrinsic_instr*> m_register_allocations;
};
} // namespace r600

View file

@ -3244,6 +3244,8 @@ TestShader::from_string(const std::string& s)
else
return nullptr;
shader->reset_shader_id();
while (std::getline(is, line)) {
if (line.find_first_not_of(" \t") == std::string::npos)
continue;