Commit Graph

128 Commits

Author SHA1 Message Date
chrg6
ff8435ce34 Count the released textures' hold in seconds of play, not of the wall.
A window minimized for minutes, a frozen game or a long load aged every released texture past its hold while nothing could take it back, so the first frames after it would make again the textures the frames just before it released. A gap between two submissions now counts at most a second.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 00:12:46 -05:00
chrg6
08ad7402f7 Keep released textures by how long they went unused instead of by a small size bound.
A released texture now goes once nothing has used it for three minutes (six for content only the GPU made), measured
in wall seconds from a clock of the presents. In two players' sessions the game took released textures back within a
minute of the release or never, so the hold drops nothing it would ask for again. The size bound stays as the safety
net for a burst of area changes, and young textures may pass it, up to twice it, while the card and the system's
commit have room. vram_use defaults to low, which now means this hold; high turns it off and keeps the released
textures up to the bound as before, and balanced reads as low. The old low's values stay available as their own keys.
The reuse log line counts drops past the hold and splits its ages around it. tests/tex_release_check checks the rules
and the clock, and simulates sessions shaped by the logs against the old and new defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 00:12:31 -05:00
chrg6
2820781fb7 Log the memory by owner every 3600 frames, and how often released textures come back.
Every VMA allocation is counted under the file that made it until it is freed, so the new "mem: by owner" line
splits the device-local memory the driver reports into textures (live, GPU-drawn, idle, released, released too
lately to drop), pools and VRAM mirrors, upscalers, replay buffers, uniform snapshots, the device address table,
the ASTC decoder, present and post-processing, headroom spares, the free space inside VMA's blocks and what VMA
never allocated. "mem: host" gives the host-visible allocations, the process's commit and working set and the
game's heap. "vk: released textures" counts take-backs by how long the texture was released and textures made
again after a drop by a bound or a pressure, with the drop's reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 23:21:17 -05:00
chrg6
2571e180c8 Check the texture pool's set against the device's descriptor limits, and name the slot a carried translation reads.
The larger pool asks for 655,360 sampled images in one set where 524,288 were asked before. The start now logs the
device's limits for one set and one stage next to that count, warns when the count is over them, and a refused
layout ends the start with the limits named instead of a bare failure.

The log line for a slot registered past the pool names both slots a shader reads instead: the pool's last entry, and
the last of the old length for a translation carried over from the translator before. The comments say what they say
without an issue number.

The translator's identity changes with this pool size: after the update every install translates its shaders again
in the background, the earlier translations serve meanwhile, and a shader gets the ground fix once it is translated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 22:46:24 -05:00
Leyukaka
2388f1f581 Give the texture pool room for Ocarina's 33068 descriptors instead of 32768.
The game makes a texture pool of 33068 descriptors, and the translator clamped every pool handle to 32767, so the textures registered from 32768 up were drawn with whatever slot 32767 held, often an empty image: ground went see-through after an area load until the area was loaded again. VK_POOL_TEX and the translator's TexturePoolLength go to 40960, and a slot registered past it is logged once.
2026-11-12 22:45:06 -05:00
chrg6
ec9dd522b1 Add texture compaction behind NX2NAVI_TEX_COMPACT, off by default.
With the setting on, textures no shader sampled for ten seconds are copied on the GPU out of the emptiest allocator
blocks into the holes of fuller ones, so the emptied blocks go back to the driver. A pass starts when the free space
inside the device-local blocks reaches NX2NAVI_TEX_COMPACT_MIN_MB (one block under VRAM pressure) and the block
table has blocks that hold nothing but such textures, with room elsewhere for what moves. It takes at most four
textures and NX2NAVI_TEX_COMPACT_FRAME_MB a frame, and none in a frame that loads an area, already made or uploaded
textures, or follows a long one. A released texture the size cap would drop is dropped instead of moved.

Only a texture whose image holds what the game's memory holds moves: uploaded, never written by the GPU, single
sampled, not depth. The entry takes the new image under the texture lock and its address generation moves, so every
slot, pool descriptor and memo resolves again. The old image and its views stay until the texture pool has taken
every set of its ring and the GPU is past the submissions recorded until then, as a retired texture's do.

Each pass logs what it moved and dropped, the blocks and bytes given back, and the time it took. A block emptied of
textures that the allocator keeps is left alone for ten minutes, and a pass that gave nothing back doubles the wait.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 22:33:29 -05:00
chrg6
d668a62854 Log how much of the allocator's blocks is holes, and how much of that a texture compaction could give back.
A log without the perf trace said nothing about the free space inside the allocator's device-local blocks, which the
driver counts as in use. Every 3600 frames (600 with the perf trace) a "mem: holes" line now gives the blocks and the
allocations in them, and for the memory type the textures use most the blocks that hold a texture, the textures and
VRAM mirrors in them, the blocks at most half full, and those of them that hold nothing but textures that could be
copied elsewhere or dropped: emptying those is the most a compaction could return.

The counting is runtime/vk_tex_compact.h, which also chooses the blocks to empty, with tests/tex_compact_check.py.
A texture entry keeps the block its memory lies in, so the table is built without asking the allocator per entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 22:33:29 -05:00
chrg6
264dbe42cc Merge the stability and memory pass into the 0.10.0 line.
Conflicts: the settings key lists and section maps take both sides' entries.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 21:49:17 -05:00
chrg6
e3e4b2d650 Log what keeps the released textures above their size bound.
The bound on the released textures' memory only takes entries that are old enough and that no lookup reaches. The texture pool stamps every GPU-owned entry that a slot's last fill resolved to in each submission, a finalized slot's released entry included, so such an entry never counts as idle: in a session at 5120x2160 the released entries held 9.2 and then 10.1 GiB against a bound of 4,008 MiB, and its overwritten render targets were logged as "last used 1 presents ago". Nothing said which rule held how much. When the released entries stay a quarter over the bound after the drop, one line now splits them: released too lately, sampled lately, shown by a pool slot and not sampled (and of those, the ones another target was drawn over), reached by another lookup, next to go. No rule changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 15:21:43 -05:00
Vasilis Manetas
677eb5c242 Keep an area load's texture staging inside the staging pool's blocks made at boot, instead of making about 1.1 GiB of new host memory in the load frame.
The staging pool keeps 4 blocks of 64 MiB from its first use on a discrete GPU (2 on an integrated one, as before). A staging buffer or arena chunk that does not fit them takes the room of the kept staging buffers and idle arena chunks, then of the oldest upload batches in flight, which it waits for; an arena chunk a waited-for batch gives back is taken instead of a new one. Only when that makes no room (the open batch's own staging, staging buffers their callers hold, the blocks' fragmentation) does the pool grow by a block, and the log says so. The outermost vk_upload_end submits the open batch once it holds 64 MiB of staging, besides the NX2NAVI_UPLOAD_BATCH_MB limit; nothing is submitted or waited for once the device is lost. Entering Hyrule Field made 221 staging buffers (1,131 MiB) in one frame; on Linux each new 64 MiB block is a kernel allocation that tries 2-4 MiB pages first, and with the free 2 MiB blocks used up the kernel compacted memory inside those allocations: 30-360 ms each, and the load frame took up to 4.7 s instead of about 0.3 s (RX 6800 XT, amdgpu, 32 GB).
2026-11-12 14:59:47 -05:00
chrg6
ac3c43ba4d Make a small plain-format texture at its lookup, beside the creation budget.
The budget spreads the streamed, compressed pictures over frames. A texture that is not block-compressed is as often the game's data, a height map or a table, and a draw that reads the stand-in in its place for a frame misplaces geometry or lighting. Up to 24 of them a present, of at most 4 MiB each, are made at once; pool_data_first = 0 leaves them to the budget.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 14:52:26 -05:00
chrg6
16b0b46155 Keep a released texture that shaders still sample out of the idle drops.
A finalized slot shows its released entry while that holds the texture, and the pool's check passes released entries by, so no lookup reached such an entry and it counted as idle while every frame sampled it. Past the released entries' size cap or count it was dropped, and the slot showed the stand-in until the game registered it again. An entry sampled within the stale time is not idle now, and the count sweep leaves one that was used.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 13:12:58 -05:00
chrg6
e3cf0710c5 Record a draw's own texture binding that got the stand-in, and a sampled pool slot that is not registered.
In towns, kerb, stair and wall-top edges are drawn untextured for one frame when the game registers a round of streamed textures, and no pool entry of those textures goes to the stand-in in such a frame. A binding written into a draw's own set, and a slot that is unregistered when its marks are read, left no event until now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 13:08:16 -05:00
FIocker
58efccd883 Scale the slope-scaled depth bias with the shadow map scale, so the larger maps keep the bias the game asked for.
The slope term is a bias per unit of depth slope across one pixel of the target. A shadow map made k times larger on
each side (shadow_scale 2 to 4) has 1/k of the slope across each texel, so the game's factor alone gave k times less
bias on sloped surfaces than at the game's own size, which is what shows as acne. vk_exec_draw.c slope_bias
multiplies the factor by the pass's scale for both the direct draws (record_fixed) and the queued mesh draws; the
constant term counts the depth format's smallest steps and keeps its value. Nothing changes at shadow_scale 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 12:39:53 -05:00
chrg6
a464ffafbc Merge Tobim6's work for older graphics cards: mesh shaders emulated with compute, video memory kept within the heaps' budgets, staged mirror uploads and the submit wait that goes with them.
Conflicts: the settings key lists take both sides; frame generation keeps the camera-cut handling and logs its counters every 600 frames with the cuts among them; the pass-time mark moves into draw_viewport; mo_desc keeps the pose depth and notes the reader.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 12:14:58 -05:00
chrg6
f45273bfe5 Say in the flight recorder's blank-slot events what the slot resolves to, and whether any shader reads the pool as a volume.
Ten slots a frame are noted as having no picture when their submission ends: the 128x72 and 64x36 volumes the game registers under new slot numbers in every frame. The events now tell a slot whose entry cannot be viewed in any kind a shader reads from one whose lookup found nothing.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 11:28:22 -05:00
chrg6
a310940003 Merge branch 'claude/gfx-layer-perf-test' into ra-perf-test 2026-11-12 11:01:54 -05:00
chrg6
277f01375a Keep an overwritten texture that is still used.
A texture another target was drawn over is marked overwritten, dropped 600 presents later, and offered to the image reuse first. Neither asked whether anything still reads it. In a player's recording the entry of a second descriptor at the scene target's address was dropped that way and made again in the same frame from a released entry there, whose bits are the scene in another format: one frame nearly black with its colours exchanged, brightness 17 against 102 around it. An overwritten entry a draw, a read or the pool's marks used within those 600 presents now stays, and the image reuse passes over any released entry used within the last 16; tex_overwritten_used = 0 drops them as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 11:01:44 -05:00
chrg6
a389f2450f Add a switch that compares textures over 64 KiB by content before uploading them again, and hash eight chains at once.
While the player runs through a town the game moves about 32 textures to new storage every four or five frames, back to back in one block, and a frame after their first upload every page of the block shows a write again. A texture up to 64 KiB keeps a hash of its storage and is uploaded again only when its bytes changed: of those, 0 to 4 in a hundred are (9 of 440 in one recording of 600 frames). A larger one has no hash and 75 to 94 in a hundred are uploaded again, whatever the size and format: 3,034 second uploads in those 600 frames beside 4,233 first ones, the ASTC ones decoded and encoded on the GPU a second time. The frames of the second uploads take 0.9 to 2.5 ms longer than frames without uploads, and the frames after them wait 0.3 to 1.3 ms longer for the GPU (six recordings of one player).

tex_same_big = 1 has textures up to 8 MiB keep the hash too. It is off by default: the bytes are read once more at the first upload and once at the comparison, 15 us each for 300 KiB, which together is about what the second upload takes on the submitting thread (27 us), so what it gains is the GPU's work and whatever else a second upload costs its frame, and that is not measured in play. A texture whose comparisons found other bytes twice in a row takes no hash any more, and an area load takes none.

The hash runs eight chains side by side and folds them, 20 GB/s against 7 for the one chain on a Ryzen 7 9850X3D, which the small textures' comparisons get as well. Each step is still a bijection of its chain and of the word it takes.

The pool log's buckets line counts the hashed uploads and the comparisons when there are any. --probe-vkmem has a case that passes with the switch off and on: the same bytes written again, other bytes, and the same bytes after two rewrites in a row.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 10:49:54 -05:00
chrg6
65dacfa7c7 Ask the write watch once per run of regions in the texture pool's check, and pass released entries by.
At every submission that binds the texture pools the replay checks each listed texture for CPU writes, and takes the write-watch snapshot of the 2 MiB regions that have none yet as the list comes to them: one query a region, since the list is in no address order. Standing still that is 5 to 10 queries and the check takes 0.11 ms. While the player runs through Kakariko or Castle Town the game writes about 32 textures into new storage every four or five frames, a region the CPU wrote is not frozen again for 1,800 submissions, and the check asked for 100 to 500 regions one by one, 2.7 times a frame: 0.5 to 1.5 ms a check, about 3 us a query, in five sessions of one player. The regions are now collected for the whole list first and asked in one query per run of adjacent regions. On this machine 400 queries of 2 MiB take 727 us and one query over the same 800 MiB takes 360 us. The same regions are queried and the same pages stamped, all of them before the list is looked at, as each entry's were before its own look; a run across the edge of a watched reservation is left to the queries by range. pool_presnap_runs = 0 asks region by region as before.

A released entry stays in the list until it is destroyed, the check does nothing for it, and the stamp it compares stays as it was at the release, so one whose region took a write later missed the region check at every submission from then on and was fetched only to be passed by: 1,000 to 6,300 entries a check, with up to 8,192 released entries kept. The list now carries the released state, set at the release and cleared at the take-back, and the check passes such an entry by without touching it or asking for its regions.

The pool log's freshness line counts the released entries passed by, and its snapshot queries count the queries either way. --probe-vkmem has a case for the queries by run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 10:49:54 -05:00
chrg6
5ec1008709 Make a newly registered slot's texture at its first lookup too.
The rule for a slot that shows another texture left out the slots that showed nothing when the game registered them: the game takes slots whose texture it finalized some time ago for its next textures and draws with them at once. Past the 16 a refresh makes, such a slot kept its stand-in until the next round. One of them was an effect's texture with a transparent ground, which drawn with the stand-in was a flat grey patch for one frame, at each of two rounds of registrations four frames apart in a player's recording. A slot registered since its last lookup that found a texture now counts with the shown ones, within the same 64 a present.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 10:33:59 -05:00
chrg6
a374e778fa Keep a released texture's image while a registered slot still names it.
The game finalizes a texture object while another one it initialized at the same storage with the same parameters stays registered in the pool, and the entry the two share is released all the same. Two frames later its image went to the next texture of its parameters and the entry was dropped; the slot then had nothing to show, because the pool makes no entry for storage the CPU cannot read, and kept its stand-in until the game drew into the texture again. Ocarina's 384x384 shadow maps are such textures: a player's recording has four slots of them sampled as stand-ins in the frame after three of their images had gone to other shadow maps, and a house front without its shadow in that frame. The reuse now passes over a released entry that a slot which is not finalized names; tex_reuse_named = 1 restores the old choice.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 10:25:41 -05:00
Tobim6
01d81811a1 NX2NAVI_LOG_TEX_NEW: log the textures made from a frame on, with what destroyed the same key before
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:22:32 +01:00
Tobim6
4ed51cf7ff Overwritten textures: swizzle siblings follow the image that gets its own memory; other descriptors keep pool memory.
The game renders through one descriptor and samples through another that differs only in swizzle, and both read the
same pool memory. When one of them got memory of its own (read after an overwrite), the other kept reading the pool
bytes, which the first no longer updated. Now the image and its swizzle siblings become one image in memory of its own:
entry_of hands that image out for any swizzle of its key. If a live descriptor of another format or geometry reads the
same storage, the image stays in pool memory as before. The perf line counts both outcomes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:22:18 +01:00
Tobim6
703e9fecd9 Textures read after another image drew over their pool memory get memory of their own.
The game overlaps transient render targets in its memory pools, and the replay binds their images into that memory.
An image of another format or size drawn over an image's memory leaves the GPU's tiled, compressed texels of the
other image there. Ocarina's volumetric fog reads its 360x202 RGBA32F fog-volume texture at the start of a frame,
before drawing it again, and the 1440x810 R11G11B10F bloom target had been drawn over that memory at the end of the
previous frame: the fog lighting took those texels as volume distances and types (values from 1e-12 to 3e33 in a
frame dump where the texture holds 9 to 50000), and drew teal splotches in Kokiri Forest's fog on AMD and NVIDIA.

Each pool-bound image the GPU writes marks the pool-bound images of another layout that overlap it; one read while
marked is dropped and comes back with memory of its own from then on, so it keeps what it last drew (the read that
found it gets an empty image once). NX2NAVI_TEX_CLOBBER=0 keeps such images in pool memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:22:16 +01:00
Tobim6
3de5577512 Allocate texture images within the heaps' budgets, moving on to the next heap with room.
An RX 580 (8 GiB, AMD 23.10) shows its memory as a 6 GiB device-local heap and a 2 GiB device-local, host-visible
one. Asked for device-local memory without a budget, VMA chose the first heap every time: a save load put 5.6 GiB
there against a budget of 5.1 GiB while the second heap held 69 MiB, and the next submit failed with
VK_ERROR_OUT_OF_DEVICE_MEMORY. create_tex now allocates with VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT: device-local
memory of any heap first, then any memory type the image allows, and only then past the budget as before. The log
names images placed outside the first device-local heap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:21:45 +01:00
chrg6
fe468f7ec6 Make a slot's new texture at once when the slot is showing another one.
Ocarina streams its textures by detail level: while the player moves it registers about 32 pool slots with their next level every four or five frames. A pool refresh made 16 of them and wrote the stand-in into the set for the rest until its next round; the set is read as it is when its submission goes to the queue, so an object whose slot was among the rest could be drawn grey for a frame. A player's recording shows 1,525 such slots in 600 frames, each with its texture made later in the same frame. A slot whose entry in the set is a texture's view when it is looked up now has its texture made by that lookup, beside the count budget and the frame's creation time, 64 of them a present; pool_shown_first = 0 leaves them to the budget. The flight recorder also notes a slot that still had no picture when its submission ended.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 10:19:19 -05:00
chrg6
95fb707bcb Record a pool slot losing its picture in the flight recorder.
When the pool's entry of a slot goes from a texture's view to the stand-in, events.tsv gets a line with the slot and what its own texture was at that moment: finalized, released, superseded, overwritten, uploaded, its storage readable, held out. The set is written with update-after-bind, so every draw of the submission that samples the slot reads the stand-in from then on; the check at the marks' read-back comes a frame later and finds the slot resolved again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 10:12:23 -05:00
chrg6
bbaf732b81 Record what an upload read, slot registrations and sampled stand-ins in the flight recorder.
Three more texture events for a dump's events.tsv: after each upload a hash of 64 probes of the storage and how many of them were all zero, so a second upload a frame later tells new bytes from the same ones and a first upload of unfilled storage shows; a slot registered with a CPU-written texture, with what the slot named before; and a slot a shader sampled that has no image of its own and follows none, so its stand-in was on screen. They are for telling why a texture shows wrong for one frame while the game streams textures in.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 10:04:25 -05:00
chrg6
fe95c0b60b Count only the making of textures against a frame's texture creation time.
The limit on what a frame's pool refreshes may spend creating textures was charged with the whole refresh, including its check of every entry the pools hold. In Kakariko that check takes 0.8 ms a submission, six submissions a frame, so most of the 6 ms was gone before a texture was made and the frame's later refreshes made none: 87 refreshes in 600 frames, with 1,090 slots left between them. The game moves about thirty textures to new storage every four or five frames there, and the ones a refresh left were on screen as their grey stand-ins for a frame; a player's recording shows three lamp posts turn grey for one frame that way. The limit now counts the time the lookups spend making entries and uploading them the first time.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 09:47:27 -05:00
Sebastian Choperena
ee46a19ede Raise the limit of released textures by the card's video memory budget, from 2048 to 8192 entries (NX2NAVI_TEX_RELEASED_MAX). 2026-11-12 07:13:16 -05:00
bct8925
ca75294126 Let a texture slot follow another texture at its storage only when the two are the same size.
When a slot's own entry was released, slot_resolve took any live entry at the same address, and Ocarina's per-frame
render targets share storage. The half-size ambient occlusion term (640x360 at a 1280x720 scene) followed the bloom
pass's 480x270 target there every frame: the blur that writes the term kept its top-left 480x270, the upsample stretched
that over the screen, and every contact shadow sat 1.33 times further from the top-left corner than its object (doubled
shadows below and right of Link, shadows of terrain out of view). During a hit effect the same slots followed its
1130x86 strip instead, the term read zero over most of the screen, and the right 44% of the scene went black.

Block-compressed formats keep the old rule, as a GPU encoder renders their blocks through a smaller view of the same
storage. The first eight refusals are logged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 07:11:46 -05:00
chrg6
4956ef8365 Let a finalized slot sample its own texture's image while that still holds the texture, not the stand-in.
The game finalizes texture objects on its own thread ahead of the replay, which still draws the frame the game recorded
before that; on the console the memory still holds the texels those draws read. Kakariko moves about 30 of its
textures to new addresses every four or five frames, and each move finalized the old descriptors. The replay's draws
of the frame before then met finalized CPU-written slots, and the stale rule gave them the stand-in even when their
own entry was still there with its content. The village's haze dropped out of a frame a few times a minute, and the
haze sprites that met a stand-in left hard-edged clear patches. A play session in Kakariko logged up to 4,805 stand-in
lookups in 60 frames, 1,826 in the 60 frames around one haze dropout, and 612 in the 60 frames after a run of
patched frames.

Such a slot now resolves to its own entry while that entry was uploaded or drawn by the GPU, and was neither superseded
by another descriptor at its address nor overwritten. The lookup samples the image as it is: it neither takes the
entry back nor reads its storage, so freed storage is still never read (the access violation the stale rule was made
for). NX2NAVI_TEX_STALE_KEPT=0 gives the stand-in again. The perf log's finalize line counts these lookups.

In a replay of a recorded Kakariko walk, most 60-frame windows went from stand-ins to the kept image (up to 328 a
window, stand-ins 0). In play, stand-ins remain in short bursts where the entry was already gone (up to about 2,000 in
60 frames, against the kept image in most windows). The tester still sees flicker that the 640x360 frame recorder
does not catch; that is not settled by this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 05:42:43 -05:00
chrg6
4b87606f32 Keep released textures the game takes back intact for as long as their longest release, not 120 presents.
Once the released entries pass RELEASED_MAX, the sweep dropped an entry that comes back intact as soon as its 120
presents were up. Kakariko releases the ASTC textures of its hazy air and takes them back every few hundred frames, so
about 30 of them went each time, and the frame that needed one again sampled its stand-in while it was made and
uploaded anew. Such an entry now waits out GAP_TIMES the longest it stayed released before a take-back, as an entry
whose content lives only in its image does. NX2NAVI_TEX_KEEP_TAKEN=0 goes back to the old rule, and
NX2NAVI_TEX_RELEASED_MAX (a test) lowers the count from which the sweep starts, so a short run reaches it.

The haze still dropped out with this alone: most of those frames came from finalized slots, which the next commit
deals with.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 05:42:42 -05:00
epicmeme546
ffa599ef33 Let the submitting thread go on past the replay workers' groups, with up to four groups in flight.
With NX2NAVI_REPLAY_PIPE=1 (off by default) the submitting thread hands a group's chunks to the workers, takes chunks
of it itself until none is left to take, and goes on with the ops after the group in a new command buffer after the
chunks' places in the part (vk_sync_append_later), also into the next group's front pass.
Up to four groups are handed out and not in their part yet; their chunks wait in one queue in the order of the stream.
The submitting thread waits for them only where the order needs it: for room, before a part goes to the GPU, before
copies and texture or buffer clears, where DLAA's run or the contact shadows' hook acts, and where a lookup would make
a texture entry or take back a retired one (the op goes again afterwards, as a chunk's does in turn).

What the chunks read stays as the stream had it while the submitting thread runs ahead: uniform snapshot drops count
from their place in the stream, a chunk reads only the inline uniform updates before its group, the HDR present's
source goes by stream position, the texture pool set syncs under the chunks' lock, each group keeps its own render
conditions, occlusion segments and closed query slots, and the queries after a group's last report go into the next
segment made after it. A group's first chunk runs its pass hooks after the group before began its pass; turns wait
for every earlier chunk, of earlier groups too. Locks the chunks take, the submitting thread takes while it is behind.

Draws keep the sampled-texture descriptors they resolved per draw context and reuse them without the texture lock
while their slot is unchanged; the workers waited for that lock at nearly every draw. Texture lookups that change
nothing no longer wait for their turn. The perf line says where the submitting thread waited, what the chunks took,
and which texture lookups waited; NX2NAVI_GPU_TIMELINE also shows the chunks and the waits.

Off by default because it does not pay yet: in Hyrule Field with 3 workers it shortens the replay (11.5 against 12.1
ms a frame) but not the frame (49.2 against 49.6 fps in the same batch). The GPU gets a group's commands only once its
last chunk is recorded, so the main thread's wait for the GPU after the frame's first submission grew by 0.8 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 04:39:12 -05:00
chrg6
bd32077e54 Sample a flat texture that a shader reads as a 3D one through a one-slice 3D copy instead of a stand-in.
Maxwell samples a texture by its own descriptor, so a 2D texture under a 3D sample gives its texel at (u, v). Vulkan
has no 3D view of a 2D image, and get_view found no view for such a binding: the draw sampled a stand-in. Such a
texture (plain colour, one sample, up to 1024 x 1024 texels) now gets a 3D image of one slice with all of its levels,
made in the upload batch and copied again when the texture was uploaded or drawn into since, or another layer is
asked for (vk_texture.c vk_texture_flat3d_locked). NX2NAVI_TEX_FLAT3D=0 gives the stand-in as before.

Seen in Kakariko: two of the game's 4 x 4 RGBA8 textures are sampled as 3D textures, and each got its copy; the runs
through eight reloads at 60 and 144 fps ended without errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 03:54:21 -05:00
chrg6
7f5906c121 Keep the texture events of the recorded frames in the flight recorder and write them with each dump as events.tsv, before the thumbnails.
Each texture made (with how its content started), uploaded, uploaded again, released, taken back or destroyed is one line with its frame, address, format, size, layers and flags, so a one-frame flicker in the thumbnails can be matched to the textures of that frame. events.tsv is written first: the thumbnails take about five seconds, and a game closed meanwhile kept no frames.tsv.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 02:42:22 -05:00
epicmeme546
7534193b62 Record the large draw groups of a submission on several replay workers at once.
Stage 2 of NX2NAVI_REPLAY_WORKERS (default 0, the replay as before). A run of draws is cut into groups: a group ends
where the render targets change after its first draw or clear, and before an inline uniform update, a mesh draw and a
samples-passed counter op, which the submitting thread replays itself in the order of the stream. A group of 64 draws
or more is first walked by a front pass on the submitting thread: it applies the state and binds, settles the CPU side
of the timestamp reports and decides the render conditions in the order of the stream, and copies the replay state at
the first op of each chunk. The workers and the submitting thread then take the chunks in order and record each into a
command buffer of its own, which vk_sync_append puts into the part in the order of the stream.

The frame's pass hooks (contact shadows, DLSS) run in a group's first chunk, which the others start after. What still
depends on the order between chunks waits until every earlier chunk of the group is done: a texture lookup that would
make or take back an entry returns nothing and the chunk replays the op again in turn, and so do the contact shadows'
pass, per-object motion and the HDR pass's source. The tables the chunks share take locks (the shader table, the
descriptor lists, mirror use and GPU write notes, uniform snapshot drops, target frames, the DLAA camera votes and the
previous-frame motion notes); each chunk keeps its own occlusion query open, its own feedback memo and no pass marks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 02:14:37 -05:00
epicmeme546
4c5855ce43 Hold ASTC textures whose every block decodes opaque as BC1 instead of BC3: the same texels in half the video memory.
The BC3 encoder's colour half is a four-colour BC1 block (c0 above c1, or every index 0 when they are equal), so a BC1 image of an opaque texture decodes to exactly the texels the BC3 one did. The encoder writes that half alone with its specialization constant BC1 set; its push constants are as before, so the BC3 pipeline is unchanged.

Every ASTC texture the CPU provides is made BC3, and its first upload checks its blocks while it copies them into staging: when all decode with alpha 255 (tex_astc.c astc_blocks_opaque, from the block header for all but the endpoint modes with alpha, which are decoded), the entry gets a BC1 image in place of the BC3 one before the decode. Later uploads into a BC1 image check again and go back to BC3 for content with alpha. A large texture's copy and check run on the ASTC decode workers, so its first upload copies faster than before. A check of its own where the texture is made cost 1.7 s of the render thread over a seven-minute teleport tour.

On that tour (Kakariko Village, the Graveyard, Death Mountain Trail, Kokiri Forest, Hyrule Field, RX 7900 XT), against BC3 alone in the same batch: the ASTC textures in Hyrule Field at the end 2,568 instead of 3,104 MiB, video memory at its peak 11,814 instead of 12,374 MiB, process commit at its peak 25,539 instead of 26,139 MiB; the first 7,200 frames in 93.7 instead of 101.3 s and the run's slowest 1 % at 24.1 instead of 21.1 fps. --probe-astc checks the header test against a decode of every generated block, the loop, its copy and the worker pool against it, and each BC1 block against the colour half of its BC3 block. NX2NAVI_ASTC_BC1=0 (astc_bc1 = 0) keeps every ASTC texture BC3; the sampling probe NX2NAVI_ASTC_BC_PROBE it replaces is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 02:11:46 -05:00
chrg6
12d81ade9c Write a GPU-drawn texture back to its storage before dropping it, when the fence write-back would have.
An entry the GPU drew into since its last write-back holds texels its storage lacks; the fence write-back
(vk_texture_write_back_small) sends such targets back when the CPU waits, about once a frame. An entry dropped before
that, for a budget, a commit or video memory squeeze, its release or a replacement at its address, went without, and a
texture the game then made again from that storage started from what the storage held before the GPU drew. drop_tex
now writes such an entry back first when the fence write-back would take it (wb_wanted) and the CPU has not rewritten
the storage since. An entry another target drew over (its storage is the newer one's) and drops at shutdown are left
as they are. The commit drop pause counts the drop either way (comment beside commit_drop_note). The perf line of
texture origins counts the write-backs.

Checked: the runtime compiles; --probe-vkmem passes (164 GPU checks, 0 validation errors; it needs a writable TEMP).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 19:38:18 -05:00
chrg6
90e41c13d3 Pause the drops for a low commit while most of the textures they drop are made again within seconds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:09:16 -05:00
chrg6
e501ded816 Keep the ASTC decoder's scratch across upload batches and stage its blocks in the staging arena by default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:09:15 -05:00
ordinarybob
c51ac7c877 Keep released render targets between the limit of released textures and a hard limit: only stale entries that come back intact or were overwritten go there.
Past 2048 released entries the oldest one that nothing sampled lately went. A render target can be used again long after anything sampled it: in Kokiri Forest two targets released at the area's load went about two minutes later, were used again after that and made again empty. On an 85 s route there a frame came out black in 1 of 12 runs, with the two targets dropped in 7 of them; with such entries kept, in 0 of 18. The sampled-lately rule holds from 16384 released entries on.

Co-Authored-By: Claude Fable 5.2 <[EMAIL]>
2026-11-11 14:37:11 -05:00
epicmeme546
8c239ee4b5 Merge main: its fix for the see-through ground with its finalize counters, which take the place of the counter of this line, and the AppImage runner fixes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 12:55:32 -05:00
epicmeme546
7b201d868e Drop only stale released textures under VRAM pressure, let textures give way only when the system's commit runs low, and count the heightmap slots a finalize now leaves current.
Above the VRAM pressure threshold the released textures that come back intact were dropped oldest first, however recently released. The game releases and takes back hundreds a frame in towns, so the list is mostly those, and each drop was made and uploaded again within frames and freed nothing. With the budget taken as 7.5 GiB (NX2NAVI_VRAM_BUDGET_MB), seven minutes of teleports between Hyrule Field, Kakariko Village, the Graveyard, Death Mountain Trail and Kokiri Forest dropped 82,288 and stayed over the budget throughout; with 11 GiB, 178 draws met a texture that was gone. They now go by the rule drop_stale keeps (released STALE_FRAMES ago and idle): on the same tour 34,699 drops, a fifth fewer textures made again, a third less time the render thread waited on textures, 4 draws of a missing texture instead of 11, and the slowest 1 % of frames in Hyrule Field afterwards at 32 fps instead of 22.

Past the process's own commit bound (tex_proc_commit_mb), textures were dropped and idle live ones evicted as under a low system commit. The bound compares the commit less the video memory in use, and a dropped texture lowers both sides alike, so nothing a drop did could bring the process back under it: textures went one after the other for as long as the rest of the process stayed large, and the ground flickered white with the system's commit to spare (#434). The bound now only writes its line into the log.

The perf trace's texture origins line counts the slots a finalize leaves current because another texture of the same parameters was registered at the storage since (the terrain heightmaps of pull request #535): 173 at the load of a Hyrule Field save, and between 40 and 365 every 60 frames while Link runs through the field, each of which the old rule left stale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 12:53:58 -05:00
chrg6
ae0c8140a2 Finalize only the slots a texture object registered itself, so the next streamed piece of ground keeps its heightmap.
Ocarina streams its terrain heightmaps (R32F, 260x260) through a fixed set of storage. It initializes the next piece's texture at the storage of the one before, registers it in the texture pool, and only then finalizes the old texture object, which has the same parameters. vk_texture.c vk_texture_release marked every slot at the storage with the same parameters as finalized, the new registration too. A finalized CPU-written slot takes no image made from its storage again (slot_resolve's stale rule), so the new piece drew the zero stand-in and was drawn at height zero, far below the ground around it: the holes and stretched ground of issues #453 and #569, through which the sky shows. A finalize now marks only the slots registered with its own texture object (the initialization serial); a slot registered with another texture object at the same storage names that one, which is still live.

From pull request #535 by MartinIsla, in its final form, which no longer skips the whole release while another texture with the same parameters is live (that kept textures the game had released and drew dark lines in Kakariko's fog). --probe-vkmem gets the pull request's check: a release leaves another live texture's slot current and marks its own; it fails on the old rule and passes with this one, with and without shadow storage.

Added here: under the perf trace a line every 60 frames counts the slots a finalize marked, the slots of another live texture it left current and the lookups the stale rule answered with the stand-in, the terrain's heightmaps counted apart, so a run shows whether the case comes up and whether stand-ins are still drawn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 12:18:52 -05:00
epicmeme546
8afca0922a Merge the fix for sunken terrain chunks from pull request #535: a finalize marks stale only the slots its own texture object registered, so a streamed heightmap registered at the storage of the one before it keeps its slot.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 11:28:41 -05:00
chrg6
c308ee6510 Past the limit of released textures, drop one that nothing sampled lately, not one that no lookup reached.
The rule that spares a released entry the game still uses went by lookups, and the texture pool's refresh looks up
every registered slot in each submission that draws through the pool. With the game's own upscaler in use
(upscaler = fsr) its render targets move to new addresses in every frame and each leaves a released entry behind
whose descriptor stays registered: all 2,049 entries counted as looked up, the sweep fell back to the oldest lookup,
which among entries stamped in the same submission is no order, and took entries still drawn, 200 to 450 per 60
frames over a town, with buildings black or wrongly lit for single frames in a player's captures.
The entry that goes is now the oldest release that is overwritten or that nothing sampled or drew into for 120
presents (samp_frame: the pool marks and every lookup that is not the pool refresh), and only when all were sampled
within that time the one sampled longest ago.
Checked: it builds, and a player's hand test of 30,000 frames through eight areas with that upscaler kept the list at
its limit, dropped 50,182 entries past it and showed none of those frames. No scripted run was made, and which
entries pile up in a town was not traced to their kinds.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-11 08:58:13 -05:00
Martin
2765a752b0 Finalize only the slots a texture object registered itself, so a finalize no longer touches another live texture's slots at the same storage, and drop the early return that skipped the whole release when such a texture was live, which also kept textures the game expected released (Kakariko fog lines).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 09:30:37 -03:00
chrg6
83febb43ef Keep a released texture the game still looks up when the count of released ones passes its limit.
Past 2,048 released entries the oldest release was destroyed at each further release, whether or not a descriptor
still resolved to it. Ocarina reads its scene picture in every frame through a second descriptor at the picture's
address whose entry is released once, early in an area, and looked up from then on, so that entry headed the list:
when the count first reached the limit it went, was made again within the frame, and the frame came out with the 3D
scene black and the interface intact.
The entry that goes is now the oldest release that no lookup reaches any more or whose content is gone, and only
when every one is still looked up the one looked up longest ago.
Reproduced in Hyrule Field with the game's own upscaler in use (upscaler = fsr), where the render targets move to new
addresses in every frame and the released entries pile up: 8 black frames in 5 of 7 runs of 13,630 frames; in the
runs logged for it each black frame is the frame after that entry was made again, and the drop that took it is this
sweep. With the change one run of 18,730 frames dropped 834 released entries past the limit and showed no black
frame; two more runs are still to come.
A session with DLSS had the same black frame while its log showed 2,032 to 2,047 released entries. That it is the same
drop is read from those counts, not logged. Why the frame that remakes the entry is black was not traced.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-11 06:58:02 -05:00