mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 08:19:56 -04:00
Frame dumps keep each shader's guest program, and a test switch runs an edited SPIR-V in place of a compute shader.
NX2NAVI_DUMP writes sh_<hash>.code next to sh_<hash>.spv: the guest program the shader was translated from, as its stored inputs hold it, for a disassembler (a compute program as it is, a graphics stage after its 128-byte header). NX2NAVI_SPV_OVERRIDE=<dir> runs <dir>/<hash>.spv in place of the compute shader whose SPIR-V has that hash, an edited copy with the same interface, to look at a shader's intermediate values in a frame dump. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2836,12 +2836,37 @@ static void prebuild_start(void) {
|
||||
plat_mutex_unlock(&P.lock);
|
||||
}
|
||||
|
||||
// NX2NAVI_SPV_OVERRIDE=<dir> (test): a compute shader whose SPIR-V hashes (FNV-1a over its bytes, the name vk_dump.c
|
||||
// gives it) to a file <dir>/<hash>.spv runs that SPIR-V instead, an edited copy with the same interface, to see a
|
||||
// shader's intermediate values in a frame dump. NULL: no override (malloc'd words otherwise).
|
||||
static uint32_t *spv_override(const uint32_t *code, uint64_t words, uint64_t *out) {
|
||||
const char *dir = cfg_get("NX2NAVI_SPV_OVERRIDE");
|
||||
if (!dir || !*dir) return NULL;
|
||||
uint64_t h = 0xcbf29ce484222325ull;
|
||||
for (uint64_t i = 0; i < words * 4; i++) h = (h ^ ((const uint8_t *)code)[i]) * 0x100000001b3ull;
|
||||
char path[600];
|
||||
snprintf(path, sizeof path, "%s/%016llx.spv", dir, (unsigned long long)h);
|
||||
FILE *f = fopen(path, "rb");
|
||||
if (!f) return NULL;
|
||||
fseek(f, 0, SEEK_END);
|
||||
long n = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
uint32_t *w = n > 20 && n % 4 == 0 ? malloc((size_t)n) : NULL;
|
||||
if (w && fread(w, 1, (size_t)n, f) != (size_t)n) free(w), w = NULL;
|
||||
fclose(f);
|
||||
if (w) *out = (uint64_t)n / 4, rt_log("vk_pipeline: compute shader %016llx replaced by %s", (unsigned long long)h, path);
|
||||
return w;
|
||||
}
|
||||
|
||||
// A compute pipeline for cs in layout l; VK_NULL_HANDLE on failure. No lock needed (P.cache is driver-synchronised).
|
||||
static VkPipeline compute_create(const GfxShader *cs, const Layout *l) {
|
||||
uint64_t words;
|
||||
const uint32_t *code = gfx_shader_spirv(cs, &words);
|
||||
uint64_t ow = 0;
|
||||
uint32_t *over = spv_override(code, words, &ow);
|
||||
if (over) code = over, words = ow;
|
||||
VkShaderModule m = make_module(code, words);
|
||||
if (!m) return VK_NULL_HANDLE;
|
||||
if (!m) return free(over), VK_NULL_HANDLE;
|
||||
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo rqc;
|
||||
VkComputePipelineCreateInfo ci = {.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
|
||||
.stage = {.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||
@@ -2859,6 +2884,7 @@ static VkPipeline compute_create(const GfxShader *cs, const Layout *l) {
|
||||
if (vkCreateComputePipelines(P.device, P.cache, 1, &ci, NULL, &pipe) != VK_SUCCESS) pipe = VK_NULL_HANDLE;
|
||||
plat_crash_context(NULL);
|
||||
vkDestroyShaderModule(P.device, m, NULL);
|
||||
free(over);
|
||||
return pipe;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user