mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 19:29:57 -04:00
Release pass: fix crashes, freezes and races, cut VRAM use, and translate more shaders.
Crashes: the render-target heap (HeapDef DynamicTextureAllocatorMem and its parent) grows with the widescreen picture, so the pause menu no longer reads a null block at 5120x2160; texture uploads keep the game's memory mapped while they copy it, so UnmapPhysicalMemory no longer pulls it away mid-copy; DLSS Frame Generation no longer crashes in Streamline's set-up (physical devices and the window surface go through its proxies, its swapchain images are counted first, resources are tagged per frame); a stale core-wait target is cleared before its thread is freed. Freezes and races: a resize during a swapchain rebuild is kept, a failed frame generation swapchain is retried instead of replaced by a plain one, three acquire timeouts in a row rebuild the swapchain, device waits take the queue lock, a translator child that stops answering times out, an in-flight compute pipeline builds at normal priority, a save Commit started before the window closes finishes and none starts after, a settings change just before closing is saved, and a movie sample taken before a flush is dropped. HDR: Enhanced HDR extends the game's own tonemap so highlights go above the picture's white (the hue slider, which no longer applies, is gone from the menu); frame generation gets a HUD-less picture, the HDR flag and the HDR10 metadata under HDR too. Memory: ASTC textures are encoded to BC3 unless the PC has 20 GiB of VRAM and 48 GiB of RAM, as Windows charges video memory to the commit charge (a long session held 17 GiB of RGBA8 textures and 45.7 GiB of commit on a 32 GiB PC). Shaders: the translator lowers spill-mode programs with more than eight uniform register groups in a wider spill layout, and local loads and stores with a uniform-register address (36029 of the game's 36031 variants translate, 20 failed before). The launcher release ships the shader tools and AMD's FidelityFX library (make_launcher.py --ffx); windres there gets the toolchain on PATH. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -762,13 +762,18 @@ static void upload(Tex *e) {
|
||||
const nvn_texdesc *d = &t->d;
|
||||
int bw, bh, bpb = nvn_fmt_bpb(d->format, &bw, &bh);
|
||||
if (!bpb || !t->mem) return;
|
||||
if (!mem_readable(e->pub.addr, e->t.L.size)) { // a stale slot (the bindless pools look every slot up): no upload;
|
||||
static volatile int32_t n_unmapped; // a later write to mapped storage uploads it (make_fresh_snap)
|
||||
// A stale slot (the bindless pools look every slot up): no upload; a later write to mapped storage uploads it
|
||||
// (make_fresh_snap).
|
||||
if (!mem_readable(e->pub.addr, e->t.L.size)) {
|
||||
static volatile int32_t n_unmapped;
|
||||
log_limited(&n_unmapped, "texture %#llx (%llu bytes): storage not mapped; not uploaded",
|
||||
(unsigned long long)e->pub.addr, (unsigned long long)e->t.L.size);
|
||||
e->uploaded = 1;
|
||||
return;
|
||||
}
|
||||
static __thread char ctx[160]; // what this thread copies, for a crash report
|
||||
snprintf(ctx, sizeof ctx, "texture upload %#llx (%llu bytes, fmt %#x %ux%u)", (unsigned long long)e->pub.addr,
|
||||
(unsigned long long)e->t.L.size, d->format, d->width, d->height);
|
||||
uint64_t p0 = perf_begin(), u0 = kern_now_ns();
|
||||
int linear = nvn_tex_is_linear(d), is3d = d->target == NVN_TEXTURE_TARGET_3D, one_d = e->pub.type == VK_IMAGE_TYPE_1D;
|
||||
uint32_t levels = linear ? 1 : e->pub.levels, layers = linear ? 1 : e->pub.layers;
|
||||
@@ -803,6 +808,18 @@ static void upload(Tex *e) {
|
||||
VkCommandBuffer cb = vk_upload_begin();
|
||||
uint8_t *stg = vk_staging(size, &sb, NULL);
|
||||
if (acheck) rmap = vk_staging(decoded, &rbuf, &ralloc);
|
||||
// The part's copies out of the storage, with it held mapped (mem_read_hold): the game releases a texture's
|
||||
// memory on its own thread, and a decommit in the middle of a copy faulted (tex_bl_copy). Only the copies run
|
||||
// held, so a waiting unmap and the guest's memory calls behind it never wait for the staging block or a decode.
|
||||
// Storage released since the check above uploads as zeros, as the game no longer has that texture.
|
||||
uint8_t **tmps = calloc(k1 - k0, sizeof *tmps);
|
||||
int held = mem_read_hold(e->pub.addr, e->t.L.size);
|
||||
if (held) plat_crash_context(ctx);
|
||||
else {
|
||||
static volatile int32_t n_gone;
|
||||
log_limited(&n_gone, "texture %#llx (%llu bytes): storage released during the upload; uploaded as zeros",
|
||||
(unsigned long long)e->pub.addr, (unsigned long long)e->t.L.size);
|
||||
}
|
||||
for (k = k0; k < k1; k++) {
|
||||
uint32_t lv = rg[k].imageSubresource.mipLevel, ly = rg[k].imageSubresource.baseArrayLayer;
|
||||
uint32_t w = rg[k].imageExtent.width, h = rg[k].imageExtent.height, sl = rg[k].imageExtent.depth;
|
||||
@@ -810,11 +827,24 @@ static void upload(Tex *e) {
|
||||
size_t raw = (size_t)rb * rows * sl;
|
||||
rg[k].bufferOffset -= base;
|
||||
uint8_t *dst = stg + rg[k].bufferOffset, *tmp = (astc && !agpu) || rgb ? malloc(raw) : NULL;
|
||||
if (nvn_deswizzle(d, lv, ly, t->mem, tmp ? tmp : dst, rb)) {
|
||||
tmps[k - k0] = tmp;
|
||||
if (!held) {
|
||||
memset(tmp ? tmp : dst, 0, raw);
|
||||
} else if (nvn_deswizzle(d, lv, ly, t->mem, tmp ? tmp : dst, rb)) {
|
||||
log_limited(&n_bad, "texture %#llx fmt %#x target %d: level %u layer %u has no CPU layout; uploaded as zeros",
|
||||
(unsigned long long)e->pub.addr, d->format, d->target, lv, ly);
|
||||
memset(tmp ? tmp : dst, 0, raw);
|
||||
}
|
||||
}
|
||||
if (held) {
|
||||
plat_crash_context(NULL);
|
||||
mem_read_release(); // the part's reads of the storage are done
|
||||
}
|
||||
for (k = k0; k < k1; k++) { // the decodes, from the copies
|
||||
uint32_t lv = rg[k].imageSubresource.mipLevel, ly = rg[k].imageSubresource.baseArrayLayer;
|
||||
uint32_t w = rg[k].imageExtent.width, h = rg[k].imageExtent.height, sl = rg[k].imageExtent.depth;
|
||||
uint32_t rb = (w + bw - 1) / bw * (uint32_t)bpb, rows = (h + bh - 1) / bh;
|
||||
uint8_t *dst = stg + rg[k].bufferOffset, *tmp = tmps[k - k0];
|
||||
if (agpu) {
|
||||
ar[k] = (VkAstcRegion){.src = rg[k].bufferOffset, .w = w, .h = h, .slices = sl, .level = lv, .layer = ly};
|
||||
} else if (astc) {
|
||||
@@ -832,6 +862,7 @@ static void upload(Tex *e) {
|
||||
}
|
||||
free(tmp);
|
||||
}
|
||||
free(tmps);
|
||||
if (acheck) {
|
||||
raw_copy = malloc(size);
|
||||
memcpy(raw_copy, stg, size);
|
||||
|
||||
Reference in New Issue
Block a user