feat(agc): let agc_shader_replay write a request's code words for other disassemblers

--code writes the shader's code as <request name>.code in the working directory, as raw
little-endian words for llvm-mc -triple amdgcn -mcpu=gfx1030 --disassemble. --asm prints only
the first word of each instruction.
This commit is contained in:
Dean Galvin
2026-10-03 21:02:34 +13:00
parent d3ec1f15fb
commit 8fafe96888
@@ -43,6 +43,7 @@ bool g_memory = false;
bool g_spirv = false;
bool g_graph = false;
bool g_maintenance8 = false;
bool g_code = false;
bool Replay(const char* path) {
auto request = ShaderRecompiler::RequestSerializer{}.Deserialize(ReadText(path));
@@ -75,6 +76,18 @@ bool Replay(const char* path) {
std::printf(" region 0x%llx + 0x%zx -> %s\n", static_cast<unsigned long long>(region.guestAddress), region.bytes.size(), name);
}
}
if (g_code) {
std::string name(path);
name = name.substr(name.find_last_of("/\\") + 1) + ".code";
const auto& code = request.request.shader.code;
std::ofstream file(name, std::ios::binary);
file.write(reinterpret_cast<const char*>(code.data()), static_cast<std::streamsize>(code.size() * sizeof(code[0])));
if (!file) {
std::printf(" could not write %s\n", name.c_str());
return false;
}
std::printf(" code -> %s\n", name.c_str());
}
if (g_assembly) {
const auto program = ShaderRecompiler::RdnaInstructionDecoder{}.Decode(request.request.shader.code);
// Raw first words carry what the text omits (branch offsets, waitcnt fields).
@@ -139,7 +152,7 @@ bool Replay(const char* path) {
int main(int argc, char** argv) {
if (argc < 2) {
std::fprintf(stderr, "usage: agc_shader_replay [--dis] [--asm] [--cfg] [--mem] [--spv] [--maintenance8] <shader.req>...\n the driver writes shader_<address>.req files when APS5_DUMP_SHADERS is set\n");
std::fprintf(stderr, "usage: agc_shader_replay [--dis] [--asm] [--cfg] [--mem] [--spv] [--code] [--maintenance8] <shader.req>...\n the driver writes shader_<address>.req files when APS5_DUMP_SHADERS is set\n");
return 2;
}
int failures = 0;
@@ -164,6 +177,10 @@ int main(int argc, char** argv) {
g_memory = true;
continue;
}
if (std::string(argv[i]) == "--code") {
g_code = true;
continue;
}
if (std::string(argv[i]) == "--spv") {
g_spirv = true;
continue;