From 7410e0d2d752068b6b754b10fcd908242df846c4 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Sun, 8 Nov 2026 04:26:18 -0500 Subject: [PATCH] Frame dumps also keep each shader's translator request, which reproduces its SPIR-V and can write its GLSL. Next to sh_.code the dump writes sh_.code.job: the request line the runtime sends nx2navi_xlate --serve for that program. Run by hand with "glsl_out" or "lowered_out" added to its job (and "out" pointed elsewhere), it writes the shader as GLSL or as the lowered Maxwell code; its SPIR-V is the same bytes the game ran. Co-Authored-By: Claude Opus 5.5 --- runtime/gfx_shader.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/runtime/gfx_shader.c b/runtime/gfx_shader.c index e804fe3c..4a517b0e 100644 --- a/runtime/gfx_shader.c +++ b/runtime/gfx_shader.c @@ -1876,12 +1876,25 @@ const uint32_t *gfx_shader_spirv(const GfxShader *s, uint64_t *words) { } // The guest program a shader was translated from, as its stored inputs hold it (the whole program: NVN2 code from its -// first byte), written to path for a disassembler (NX2NAVI_DUMP's sh_.code). 0: no stored inputs for it. +// first byte), written to path for a disassembler (NX2NAVI_DUMP's sh_.code), and next to it .job, the +// translator request that translates it (one line for nx2navi_xlate --serve; its "out" names the shader cache, and +// "glsl_out" or "lowered_out" added to the job write the GLSL or the lowered Maxwell code). 0: no stored inputs. int gfx_shader_write_code(const GfxShader *s, const char *path) { Inputs in; paths(); if (!s || !cache_dir[0] || !in_load(s->iid, &in)) return 0; int ok = write_file(path, in.code, (size_t)in.length); + const char *st = in.stage == GFX_STAGE_VS ? "vs" : in.stage == GFX_STAGE_FS ? "ps" : in.stage == GFX_STAGE_CS ? "cs" + : in.stage == GFX_STAGE_TS ? "ts" : in.stage == GFX_STAGE_MS ? "ms" : NULL; + size_t cap = 2 * PATH_CAP * 6 + 2 * (size_t)in.c1_len + 8192; + char *req = st ? malloc(cap) : NULL, job[PATH_CAP + 80], hex[65]; + if (ok && req) { + key_hex(s->key, hex); + build_request(req, hex, st, path, in.c1, in.c1_len, &in.a, in.control); + snprintf(job, sizeof job, "%s.job", path); + write_file(job, req, strlen(req)); + } + free(req); free(in.buf); return ok; }