mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-18 06:59:57 -04:00
Check that a part's CPU inputs reach the GPU ahead of its own noted writes, and let a frame dump pick shaders and keep raw texels.
This pull request fixed lighting that added up frame after frame under shadow storage on Linux: a GPU write noted while a part was recorded kept that part's CPU inputs (the game's resets of its lighting accumulators) out of the shadow. Its fix marked noted ranges as submitted in vk_memory.c; the base copies that came with the black-world fix already move every CPU-changed byte in before the part runs, so that part is not taken and no SHADOW_PENDING_INPUTS setting is added. Taken from it: - tex_probe.c (--probe-vkmem): a range noted as a future GPU write still gets the CPU's bytes before the GPU reads it. The pull request's other check, that a CPU write made after a GPU result loses to it until the write-back, is left out: with base copies the later CPU write wins, as it does on the console. - vk_dump.c: NX2NAVI_DUMP_SHADERS=<hash>,... copies images only for passes that use those shaders, and NX2NAVI_DUMP_RAW=1 also saves each copied image's texel bytes. - tools/fix_linux_ambient_power.py, as it is: patches one translated shader of a player's own cache so a zero exponent no longer gives NaN. It holds two hashes and no shader data. Pull request #264 by intellq. The Windows files compile; the probe was not run, and nothing was run on Linux here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
// before the submission (vk_exec_draw.c upd_note).
|
||||
// NX2NAVI_DUMP_SKIP_RUNS=1: a render pass with the same targets as the render pass before it is logged but not copied
|
||||
// (the terrain decals draw one pass each into the G-buffer and would use up both caps).
|
||||
// NX2NAVI_DUMP_SHADERS=<hash>,...: copy images only for passes using those shader hashes; metadata covers the whole frame.
|
||||
// NX2NAVI_DUMP_RAW=1: also save each copied image's native texel bytes as .bin, for numerical analysis.
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
@@ -60,6 +62,8 @@ static uint64_t dump_after; // NX2NAVI_DUMP_AFTER
|
||||
static FILE *passes_f, *images_f;
|
||||
static int seq, finished, copied; // copied: passes and dispatches of the dump frame whose images were copied
|
||||
static int skip_runs, dump_ubo; // NX2NAVI_DUMP_SKIP_RUNS, NX2NAVI_DUMP_UBO (vec4 per block, 0 for none)
|
||||
static int dump_raw, ncopy_shaders;
|
||||
static uint64_t copy_shaders[16];
|
||||
static uint32_t want_tex[16][2]; // NX2NAVI_DUMP_TEX: slot id and 0, or width and height
|
||||
static int nwant_tex;
|
||||
static uint64_t last_targets; // targets_sig of the last render pass; 0 after a dispatch
|
||||
@@ -288,10 +292,10 @@ static void job_done(void *arg) {
|
||||
VmaAllocator vma = vk_ctx()->vma;
|
||||
vmaInvalidateAllocation(vma, j->alloc, 0, VK_WHOLE_SIZE);
|
||||
write_images(j);
|
||||
// A BC texture's raw blocks also go to <name>.bin, packed rows of blocks, so a script can decode them: the PNG
|
||||
// shows the block words through the integer mapping, which loses their bits.
|
||||
// Raw captures retain the exact texel bytes. BC blocks always get a .bin because the PNG's integer mapping
|
||||
// loses their bits; other formats get one when DUMP_RAW is enabled.
|
||||
size_t nl = strlen(j->name);
|
||||
if (nl > 7 && !strcmp(j->name + nl - 7, "_blocks")) {
|
||||
if (dump_raw || (nl > 7 && !strcmp(j->name + nl - 7, "_blocks"))) {
|
||||
char path[600];
|
||||
snprintf(path, sizeof path, "%s/%s.bin", dir, j->name);
|
||||
FILE *f = fopen(path, "wb");
|
||||
@@ -524,9 +528,10 @@ static void queue_lut(const VkTexImage *t, int id) {
|
||||
if (frame_now() != dump_frame) return;
|
||||
for (int i = 0; i < nluts_done; i++)
|
||||
if (luts_done[i] == t->image) return;
|
||||
if (nluts_done == MAX_LUTS) return;
|
||||
luts_done[nluts_done++] = t->image;
|
||||
uint32_t nl = t->type != VK_IMAGE_TYPE_3D && t->layers > 1 ? t->layers : 1; // a 2D array: one copy per layer
|
||||
for (int i = 0; i < nluts; i++)
|
||||
if (luts[i].image == t->image) return;
|
||||
if (nluts_done == MAX_LUTS || nluts == MAX_LUTS) return;
|
||||
uint32_t nl = t->type != VK_IMAGE_TYPE_3D && t->layers > 1 ? t->layers : 1;
|
||||
for (uint32_t k = 0; k < nl && nluts < MAX_LUTS; k++)
|
||||
luts[nluts++] = (Lut){t->image, t->format, t->width, t->height, t->type == VK_IMAGE_TYPE_3D ? t->depth : 1, id,
|
||||
t->type != VK_IMAGE_TYPE_3D, k, nl};
|
||||
@@ -559,6 +564,11 @@ static void flush_luts(VkExec *ex, int n) {
|
||||
: copy_out(ex, l->image, l->format, asp, 0, l->layer, l->w, l->h, l->d, name);
|
||||
fprintf(passes_f, " %s tex %d -> %s.png%s%s\n", l->is2d ? "2D" : "3D", l->id, name, why ? " skipped: " : "",
|
||||
why ? why : "");
|
||||
if (!why && nluts_done < MAX_LUTS) {
|
||||
int known = 0;
|
||||
for (int k = 0; k < nluts_done; k++) known |= luts_done[k] == l->image;
|
||||
if (!known) luts_done[nluts_done++] = l->image;
|
||||
}
|
||||
}
|
||||
nluts = 0;
|
||||
}
|
||||
@@ -909,9 +919,30 @@ static uint64_t targets_sig(const VkExec *ex) {
|
||||
}
|
||||
|
||||
// Sets pass_skip for the pass or dispatch being logged and counts it when it copies.
|
||||
static void pass_decide(int same_targets) {
|
||||
static int render_copy_selected(void) {
|
||||
if (!ncopy_shaders) return 1;
|
||||
for (int k = 0; k < ncopy_shaders; k++) {
|
||||
char vertex[24], fragment[24];
|
||||
snprintf(vertex, sizeof vertex, "vs %016llx", (unsigned long long)copy_shaders[k]);
|
||||
snprintf(fragment, sizeof fragment, "fs %016llx", (unsigned long long)copy_shaders[k]);
|
||||
for (int i = 0; i < nents; i++)
|
||||
if (strstr(ents[i].text, vertex) || strstr(ents[i].text, fragment)) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compute_copy_selected(const GfxShader *cs) {
|
||||
if (!ncopy_shaders) return 1;
|
||||
uint64_t h = shader_hash(cs);
|
||||
for (int k = 0; k < ncopy_shaders; k++)
|
||||
if (copy_shaders[k] == h) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pass_decide(int same_targets, int selected) {
|
||||
if (frame_now() != dump_frame) copied = 0;
|
||||
pass_skip = copied >= MAX_PASSES ? "pass cap" : same_targets ? "same targets as the previous pass" : NULL;
|
||||
pass_skip = !selected ? "shader not selected" : copied >= MAX_PASSES ? "pass cap" :
|
||||
same_targets ? "same targets as the previous pass" : NULL;
|
||||
if (!pass_skip) copied++;
|
||||
}
|
||||
|
||||
@@ -928,7 +959,7 @@ void vk_dump_pass_end(VkExec *ex) {
|
||||
if (!active()) goto out;
|
||||
int n = seq++;
|
||||
uint64_t sig = targets_sig(ex);
|
||||
pass_decide(skip_runs && sig == last_targets);
|
||||
pass_decide(skip_runs && sig == last_targets, render_copy_selected());
|
||||
last_targets = sig;
|
||||
fprintf(passes_f, "pass %04d: render pass, draws %d, area %ux%u layers %u, fence %llu, frame %llu\n", n, pass_draws,
|
||||
ex->pass_w, ex->pass_h, ex->pass_layers, (unsigned long long)ex->fence, (unsigned long long)frame_now());
|
||||
@@ -958,7 +989,7 @@ void vk_dump_dispatch(VkExec *ex, const GfxShader *cs, VkPipeline p, const VkPip
|
||||
plat_mutex_lock(&rec_lock);
|
||||
if (!active()) goto out;
|
||||
int n = seq++;
|
||||
pass_decide(0);
|
||||
pass_decide(0, compute_copy_selected(cs));
|
||||
last_targets = 0;
|
||||
Str b = {0};
|
||||
describe_bindings(&b, ex, info);
|
||||
@@ -1143,6 +1174,16 @@ void vk_dump_init(void) {
|
||||
if (dump_ubo == 1) dump_ubo = 16;
|
||||
if (dump_ubo > 4096) dump_ubo = 4096;
|
||||
if (dump_ubo < 0) dump_ubo = 0;
|
||||
const char *raw = cfg_get("NX2NAVI_DUMP_RAW");
|
||||
dump_raw = raw && *raw && *raw != '0';
|
||||
const char *shaders = cfg_get("NX2NAVI_DUMP_SHADERS");
|
||||
for (const char *p = shaders; p && *p && ncopy_shaders < 16;) {
|
||||
char *end;
|
||||
uint64_t h = strtoull(p, &end, 16);
|
||||
if (end == p) break;
|
||||
copy_shaders[ncopy_shaders++] = h;
|
||||
p = *end ? end + 1 : end;
|
||||
}
|
||||
const char *wt = cfg_get("NX2NAVI_DUMP_TEX");
|
||||
for (char *q = (char *)wt; q && *q && nwant_tex < 16; q += *q == ',') {
|
||||
uint32_t *w = want_tex[nwant_tex++];
|
||||
|
||||
Reference in New Issue
Block a user