mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-02 07:22:24 +00:00
Dump IR program
This commit is contained in:
parent
5abec2a291
commit
da118e3bd9
@ -6,13 +6,30 @@
|
|||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include "common/config.h"
|
||||||
|
#include "common/io_file.h"
|
||||||
|
#include "common/path_util.h"
|
||||||
#include "shader_recompiler/ir/basic_block.h"
|
#include "shader_recompiler/ir/basic_block.h"
|
||||||
#include "shader_recompiler/ir/program.h"
|
#include "shader_recompiler/ir/program.h"
|
||||||
#include "shader_recompiler/ir/value.h"
|
#include "shader_recompiler/ir/value.h"
|
||||||
|
|
||||||
namespace Shader::IR {
|
namespace Shader::IR {
|
||||||
|
|
||||||
std::string DumpProgram(const Program& program) {
|
void DumpProgram(const Program& program, const Info& info) {
|
||||||
|
using namespace Common::FS;
|
||||||
|
|
||||||
|
if (!Config::dumpShaders()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto dump_dir = GetUserPath(PathType::ShaderDir) / "dumps";
|
||||||
|
if (!std::filesystem::exists(dump_dir)) {
|
||||||
|
std::filesystem::create_directories(dump_dir);
|
||||||
|
}
|
||||||
|
const auto filename = fmt::format("{}_{:#018x}.irprogram.txt", info.stage, info.pgm_hash);
|
||||||
|
const auto file = IOFile{dump_dir / filename, FileAccessMode::Write, FileType::TextFile};
|
||||||
|
|
||||||
|
|
||||||
size_t index{0};
|
size_t index{0};
|
||||||
std::map<const IR::Inst*, size_t> inst_to_index;
|
std::map<const IR::Inst*, size_t> inst_to_index;
|
||||||
std::map<const IR::Block*, size_t> block_to_index;
|
std::map<const IR::Block*, size_t> block_to_index;
|
||||||
@ -21,11 +38,11 @@ std::string DumpProgram(const Program& program) {
|
|||||||
block_to_index.emplace(block, index);
|
block_to_index.emplace(block, index);
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
std::string ret;
|
|
||||||
for (const auto& block : program.blocks) {
|
for (const auto& block : program.blocks) {
|
||||||
ret += IR::DumpBlock(*block, block_to_index, inst_to_index, index) + '\n';
|
std::string s = IR::DumpBlock(*block, block_to_index, inst_to_index, index) + '\n';
|
||||||
|
file.WriteString(s);
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Shader::IR
|
} // namespace Shader::IR
|
||||||
|
@ -21,6 +21,6 @@ struct Program {
|
|||||||
Info& info;
|
Info& info;
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] std::string DumpProgram(const Program& program);
|
void DumpProgram(const Program& program, const Info& info);
|
||||||
|
|
||||||
} // namespace Shader::IR
|
} // namespace Shader::IR
|
||||||
|
@ -82,6 +82,8 @@ IR::Program TranslateProgram(std::span<const u32> code, Pools& pools, Info& info
|
|||||||
Shader::Optimization::ConstantPropagationPass(program.post_order_blocks);
|
Shader::Optimization::ConstantPropagationPass(program.post_order_blocks);
|
||||||
Shader::Optimization::CollectShaderInfoPass(program);
|
Shader::Optimization::CollectShaderInfoPass(program);
|
||||||
|
|
||||||
|
Shader::IR::DumpProgram(program, info);
|
||||||
|
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user