Skip to content

d3d12: keep console-format structures for the ray walks in one buffer - #586

Merged
brcly merged 3 commits into
brcly:mainfrom
3kynox:pr-console-heap
Dec 1, 2026
Merged

brcly merged 3 commits into
brcly:mainfrom
3kynox:pr-console-heap

Conversation

@3kynox

@3kynox 3kynox commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

For #382, the second of the pieces agreed there: the buffer the console-format structures live in, and the bookkeeping of its places. It follows #536 (the expansion of the packed bottom-level structures) and is independent of it: the two can be reviewed and merged in either order.

A translated ray walk reads every scene from one raw buffer and takes each scene's place in it from a block of offsets. Today that buffer is the empty one compute_scene makes for each walk. device::console_heap is the real one, one per device:

  • bytes 0 to 511 stay zero: a walk tests an address against zero for none, and offset 256 is the scene of no instance;
  • a structure, a scene or a block of offsets is copied whole into a place of its own, at a 256-byte step, and only then named;
  • a place is given up when what it holds is replaced or forgotten: a scene when the title builds another at its address, a structure when no address names it any more and no scene still seen holds it in its instance records;
  • a walk the GPU runs later may still read a place given up, so nothing else is written there until four more presents have gone by and the queues have finished what they had been given by then. Then it is free: joined to the free places it touches, taken again smallest-fit first, and returned to the unused end of the buffer when it is the last one;
  • when nothing is large enough, nothing is placed, what was named at those addresses is no longer seen, and one line in the log says so.

Review fixes, 351fbb4 (the three remarks of the automatic review):

  • a scene holds the place of every structure its instance records name, so a structure rebuilt or forgotten at its address is not written over while a scene still leads a walk to it;
  • places rest on the GPU's progress, not on the count of presents alone: at each present the clock notes what the queues still had to run (queue_trace::pending_fences), and a place given up at present N is free once every batch submitted by present N + 4 has run;
  • a structure that finds no place is forgotten at every address it was given, instead of leaving the one before it named there.

Not covered, and the module comment says so: a list recorded before a place is given up and handed to its queue more than four presents later. Only the list could hold what it binds, which belongs with the wiring.

Nothing calls it yet, so behaviour does not change. The file is marked allow(dead_code) until the wiring PR, which removes the marker.

Why the places are reused at all: a first version only ever took new places. ProjectScarlett builds its scenes again every frame, and in a local build that also wrote the structures the title builds while it runs (an experiment, not in these PRs) a 1,920 MiB buffer was full after about five minutes of the world; after that the walks read nothing new. With the reuse here, the same load held about 1,080 MiB after 16 minutes (one run, RTX 4070 Ti SUPER, before the rebase onto current main; the bookkeeping code is unchanged since). Both numbers are from that experiment, which writes hundreds of structures a frame. With what these PRs write (the rehydrated structures and the scenes), the buffer holds 84 to 126 MiB when the world starts and 140 to 223 MiB ten minutes later: it grows with the number of structures the title loads, not with the scenes written again every frame (the comment of 2026-11-30 has the runs).

TUXBOX_CONSOLE_HEAP_MB (1 to 4096, default 1024) sizes the buffer, and is in docs/ENVIRONMENT.md. A walk's offsets are 32 bits, so the buffer never passes 4 GiB.

Tested

Run the checks relevant to this change.

  • The checks relevant to this change passed: the code checks did, except one Python test of the launcher that fails the same way on main on this machine (below)
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: none of the GPU suites was run, on either vendor. Nothing calls this code yet.

No Lanes scenario: nothing calls the buffer yet. The part that needs no device (the places, the clock they rest by, and what is named or held by what) has eighteen unit tests, among them a buffer written again every frame for 150 presents, ten times its size in all, that must not fill, and a place that waits for a GPU twenty frames behind. 32 errors planted one at a time (a place freed at once or never, free places not joined, the first fit taken instead of the smallest, a name counted twice, a scene that holds none of its structures or keeps holding them, a clock past a present that still waits and so on) each fail at least one test. The part that makes and maps the upload buffer has no test here; it ran in the game (below).

In the game, before the review fixes, with #536, the wiring and #566 on top: two 9-minute runs made the buffer (1,024 MiB), placed 256 and 485 structures by their last counts and 5 and 10 scenes in it (58 MiB held at most), and bound it to the walks. Both ended on a GPU loss a minute into the world, one in a walk given the buffer and one in mesh-shader draws; a run without the switch went 25 minutes. I can't tell yet whether the two are related; more runs come before the wiring PR does.

Before the rebase, from a local build that also has the wiring: a dump of the buffer taken in the world was walked on the CPU, 4,399,968 rays through the scenes it held. No ray failed to read what it followed, and none ended at another distance than in a scene written anew from the same records by #525's encoder: at that instant no place still in use had been written over.

GPU, driver and backend: none needed for the checks below. The game runs: GeForce RTX 4070 Ti SUPER, 620.73.04, GE-Proton11-14, Core i9-12900K, ProjectScarlett 1.0.2.1 offline.

The Evidence: line tuxbox.py check prints last, one per card (it names the commit it tested; run it on this pull request's head):

Evidence: TuxBox check of 351fbb4aabff, no uncommitted changes, no GPU checks: 12 passed, 1 failed, 0 not run

Everything below was run on the head commit, 351fbb4. The review fixes have not run in the game yet.

Commands run and their results:

python tuxbox.py check --no-gpu        (Rust 1.98.1: the nearest toolchain I have to CI's 1.95)
  12 passed, 1 failed:
  FAILED   Python tests: 759 ran, 1 failed, 11 skipped
           test_stage_baseline.GuestWatch.test_a_guest_that_died_stops_the_sandbox_instead_of_waiting_out_the_timeout
           It fails the same way on main (checked at e5d2e913) without this change on this machine (NixOS), as noted in #486.

RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --document-private-items
  no warning

cargo test --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --lib   (run under Wine)
  483 passed, 3 failed, 8 ignored
  The failures are scene_publication tests this PR does not touch; they ask for a hardware device my Wine prefix does not give them.

cargo +nightly-2026-11-03 miri test --locked --target x86_64-pc-windows-msvc --lib -p tuxbox-d3d12 -- console_heap   (CI's MIRIFLAGS)
  18 passed, 0 failed, in 35 s. Under Miri the every-frame test writes 30 presents instead of 150: with all of them it took over a minute.
  I ran Miri on this module's tests only, not on the whole crate.

Checks

CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, a Windows typecheck of every crate, and clippy.

@3kynox
3kynox marked this pull request as ready for review November 30, 2026 11:16
Copilot AI balanced review requested due to automatic review settings November 30, 2026 11:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Placement reuse can overwrite geometry still referenced by recorded commands or live scenes before all readers retire, and failed rebuilds leave stale address mappings accessible.

3 open issues
What changed in this PR

Adds shared-buffer storage and address bookkeeping for the console-format structures used by translated ray walks (#382). The module is not yet wired into builds or dispatches, so runtime behavior remains unchanged.

Changes:

  • Adds 256-byte-aligned placements, address mappings, and reuse after a four-present delay.
  • Adds 13 unit tests covering allocation, reuse, and naming behavior.
  • Documents the configurable buffer capacity, defaulting to 1,024 MiB.
File Description
runtime/​d3d12/​src/​tests/​device/​console_heap.rs Tests placement allocation, reuse, limits, and address bookkeeping.
runtime/​d3d12/​src/​device/​console_heap.rs Implements the upload buffer, placement allocator, and structure/scene mappings.
runtime/​d3d12/​src/​device.rs Registers the console heap module.
docs/​ENVIRONMENT.md Documents TUXBOX_CONSOLE_HEAP_MB and its current unwired status.

Review effort: Balanced

Comment on lines +118 to +122
if now < since.saturating_add(REST) {
break;
}
self.resting.pop_front();
self.release(at, size);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that four presents counted on the CPU say nothing of how far behind the GPU is. In 351fbb4 the places rest by a clock that follows the GPU. At each present it notes what the queues still have to run (queue_trace::pending_fences, which blas/lifetime.rs reads at retirement), and a place given up at present N is free only once every batch submitted by present N + 4 has run (a queue's mark moves after each batch, submit.rs). A GPU twenty frames behind keeps the place twenty frames longer (a_place_given_up_waits_for_a_gpu_that_is_frames_behind).

What this does not cover, and the module comment now says so: a list recorded before the place was given up and handed to its queue more than four presents later. Only the list itself could hold what it binds. That belongs with the wiring PR, where bind is called at a dispatch and the list is at hand; I would rather do it there than guess the list's side from here.

Comment on lines +285 to +287
if entry.1 == 0 {
let bytes = self.named.remove(&offset).map_or(0, |(bytes, _)| bytes);
self.places.give(offset, bytes, now);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. A scene now holds the place of every structure its instance records name: scene takes those places, and a structure's place is given up only when no address names it and no scene still seen holds it. It then rests from the same present as the scene's own old place, so the two cannot be written over in the wrong order. A scene that names a place given up since the caller read it is not placed at all. Tests: a_scene_holds_the_places_of_the_structures_it_names and a_structure_two_scenes_name_keeps_its_place_until_both_let_go.

pub(crate) fn structure(&self, device: &ID3D12Device, addresses: &[u64], bytes: &[u8]) -> bool {
let Some(header) = bytes.get(..64).and_then(|header| <[u8; 64]>::try_from(header).ok()) else { return false };
let mut inner = self.lock();
let Some(offset) = inner.write(device, bytes) else { return false };

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and the early return on a short header had the same hole. Book::structure now forgets every address it was given when the structure finds no place, so placed answers none for them, as the module comment promises (a_structure_that_finds_no_place_is_no_longer_seen_at_its_addresses).

@brcly

brcly commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Thanks. The reuse with a four-present rest, the smallest-fit choice, and the 18 planted errors each caught by a test all look right.

I'm holding this together with #536 until the wiring PR is up (reasons there): nothing calls it yet, and the switched-on runs on #382 end in GPU losses. Two things to have answered by then:

  1. The slow growth (about 1,080 MiB after 16 minutes, still rising). Before merging, it should either level off over a longer run or have a known cause. A buffer that fills in a long session ends with the walks reading nothing new, which is the failure this PR exists to prevent.
  2. The default size. 1,024 MiB of upload memory is a lot on 8 GB cards, where we already spill (ProjectScarlett at 3840x2160: native copies of guest textures reach 9.2 GB by the loading screen, and a 12 GB card runs out of memory #292). Say what the buffer actually needs for ProjectScarlett, and whether it can grow on demand rather than being reserved at full size.

@brcly brcly added the waiting-on-author Changes or answers requested from the author label Nov 30, 2026
@DrArroway

Copy link
Copy Markdown
Contributor

Heads-up for @3kynox and @brcly: on an RX 6900 XT (main 87298944 + #389/#589/#590), two RADV_DEBUG=hang captures hit a 100%-reproducible TCP GPUVM read fault in console ray-walk compute shader 571d96cad08597a9.dxil (DISPATCH_INDIRECT) where pointer_words (tools/shader-compiler/src/hlsl/emitter/scalar_memory.rs) and bvh_node::emit (tools/shader-compiler/src/hlsl/bvh_node.rs) issue tb_bvh_heap.Load / Load4 unconditionally on inactive lanes whose address VGPR still holds stale float bits (e.g. 0xbc07e000), reading ~3 GiB past the tb_bvh_heap root SRV; tb_bvh_intersect also fetches nodes.Load4 before checking invalid type sentinels (2/3/6/7, e.g. 0xffffffff). This may explain the GPU loss "in a walk given the buffer" seen in your game runs—I've claimed the xshader fix for those inactive-lane/invalid-pointer loads on #533.

@3kynox

3kynox commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Answers to the two questions, and where the runs stand. All on ProjectScarlett 1.0.2.1 offline, RTX 4070 Ti SUPER 16 GB, 620.73.04, GE-Proton11-14: a2650681 with #536, #586 and the wiring, and #389 ported on top except where I say otherwise.

1. The slow growth. The 1,080 MiB came from a local build that also wrote the structures the title builds every frame, which none of these PRs do. That number should not stand next to this PR and I'll reword the description. With what the PRs do (rehydrated structures and the scenes), the buffer holds 84 to 126 MiB when the world starts (920 to 1,016 structures) and 140 to 223 MiB five to ten minutes later (about 1,700 structures). The bytes held per structure stay the same within a run (0.12 then 0.13 MiB in one, 0.09 then 0.08 in another) while some 500 scenes are written again, so the scenes do not add to it and the reuse does what it is for. What grows is the number of structures: a place is given back when the title rehydrates or builds at the same address again, and nothing tells the provider that the title has dropped a structure. So it does not level off while the opening streams the world in: 8 to 16 MiB a minute. Two ways to bound it, neither done: give up what a new structure overlaps in title memory, or give up a structure no scene has named for a while and expand it again when one does. I want to measure which structures stay unnamed before choosing.

2. The default size. It can grow on demand, because a scene's offsets are relative to the buffer: a larger buffer that begins with a copy of the smaller one reads the same to a walk. I have that written and not pushed: 64 MiB at first, twice the size when nothing fits, TUXBOX_CONSOLE_HEAP_MB as the most it may be; two more tests, 39 planted errors of 39 caught, Miri clean. One run in the game made the three buffers (64, 128, 256 MiB in the first twenty seconds of the world) and went on placing, 1,007 structures and 119 MiB with two walks bound; I have not walked a dump taken after a growth. It is not pushed because of one gap: the wiring binds the buffer's address into the list and does not make the list hold the buffer, so a list that waits longer than the rest would read an address that is gone, where today it reads old bytes. I'll close that first.

What the size costs on this card, measured: the title fills video memory by itself (the card sits at 15.3 of 16 GiB in a run without the switch, desktop included) and vkd3d-proton puts UPLOAD heaps in host-visible video memory. The 1,024 MiB buffer never fit: in five runs of five, "Memory allocation failed, falling back to system memory" is the line just before the buffer's own. A 320 MiB one was made without that line, and 208 allocations fell back after it; the 35-minute run without the switch had one in all. So reserved whole it lands in system memory here, and smaller it takes video memory from the title. I do not know which of the two this buffer should be on a card this full, and would like your view.

The runs. With TUXBOX_CONSOLE_STRUCTURES=1 and #389, six runs of seven lost the GPU (Xid 13): 2.4, 7.9, 8.7, 9.0, 15.5 and 19.1 minutes after the first structures. The seventh reached its 25-minute limit; it is the only one made with a local switch that keeps the host from building any structure, and I do not read much into one run. Without the structures, two runs went to their limit: 25 minutes before #389 was ported, 35 minutes after. In frames presented in the world: 6 losses in 913 with the switch, none in 631 without. No setting I tried holds: four walks given the buffer, two, none; a buffer of 1,024 MiB, 320, 1, or growing.

So on this card the switch brings a loss that the two runs without it did not show in an hour, through something other than the walks' reads: what is left is the work on the CPU at each rehydration and scene build, and the buffer's allocation. I have not told those apart, and with losses anywhere between 2 and 19 minutes one more run says little.

DrArroway, thank you for the capture. Loads on inactive lanes would fit the loss we had earlier with a walk's dispatch in flight, and a read 3 GiB past a root SRV lands on whatever else is mapped, which this buffer changes. #594 is in since; the next runs are on main with it, and I'll report here.

Visible effect. None I can show. The opening is a cinematic that advances with the frames presented, one every five seconds here, so two runs do not show the same shot at the same moment. In the one static shot I can compare, the picture with two walks bound is the picture without. About 2,050 of the 3,250 instances of the main scene name structures the title builds while it runs, which these PRs do not write.

Neither of your two conditions is met, then. The wiring PR is up as a draft, #596, on current main and stacked on these two, so the three can be read side by side. Everything above was run on a2650681, before #594 and #595.

@3kynox

3kynox commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

A correction to what I wrote above about #389, and three runs on tonight's main.

#389. I wrote that it does not separate anything here. That holds for how long a run lasts, not for where it ends. Without #389, both losses have only VS 281b4977 / PS 96e8aaaa in flight: 3.2 minutes after the first structures on a2650681, and 36 seconds on 0b889d74 with this stack, which is #596 as it stands. With #389, none of the five losses whose list of commands in flight is complete has those draws (two more lists were cut at 48). Small numbers, but it does take one fault away, and #596 will not hold here without it.

The 36-second run had VKD3D_CONFIG=fault: ReadInvalid at 0x48140000, offset 0 of a 64 KiB range (VkBuffer [global-buffer]) bound two seconds before the report, with no unbind in its history. vkd3d-proton says the address "is currently mapped" and "should not normally page fault".

On 0b889d74 with #389, one run each, so read them as such:

  • Switch on, two walks given the buffer: device lost 39 seconds after the first structures, no Xid and no fault report, one command in flight, dispatch CS 1a703579.
  • The same with TUXBOX_SKIP_SHADERS=1a703579: no device loss; the title's own crash handler ran 2.4 minutes after the first structures.
  • Switch off: device lost after 9 minutes of the world, Xid 109 then 31, mesh-shader draws in flight, ReadInvalid at 0xdc01afa000 in a range that images were bound to and unbound from twice before.

So tonight's main does not hold on this card without the structures either, where a2650681 went 25 and 35 minutes, and I cannot measure the switch against it yet. I'll put the last report on #232 if it is of use there.

@3kynox

3kynox commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Runs on main 717a74c4, as promised above. ProjectScarlett 1.0.2.1 offline, RTX 4070 Ti SUPER 16 GB, 620.73.04, GE-Proton11-14 (kept so that the caches stay; main pins 11-15). The stack is #596 rebased on main, which applies cleanly, plus a local commit that also writes the structures the title builds from packed positions. One run per line; the time is counted from the first ray dispatch of the world.

Main does not hold here with or without the switch, and the switch does not shorten it.

world before the loss frames end
switch off 158 s 153 Xid 13 in a mesh-shader draw (PS fd6b23dd MS e0a84bdc), then 109
switch off 13 s 63 Xid 13 (PS 8c407793 MS 4db9a403, 20 draws), then 109
switch on, four distant-shadow walks 165 s 152 Xid 13 (PS 1b5fcea8 MS b91b86fc, 24 draws), then 109
switch on, the same 558 s 115 Xid 13 (PS 8f67a984 MS a4b9766d, 10 draws), then 109
switch on, the same, alternating, float-position builds written too (both described below) 1,201 s 351 Xid 13 (PS c040ab25 MS 0e904b85, 6 draws), then 109
switch on, boxes in place of the structures (the control described below) 661 s 172 Xid 13 (PS 8da78bbb MS baf207f9, 20 draws), then 109

In all six, video memory is nearly full begins before the world or within a minute of it, and frames then take seconds (61 frames in the last 536 s of the 558-second run). That is the timeline @brcly gave on #533 for this card. So the first condition cannot be measured against main for now. What these six runs say is only that the switch does not bring the loss forward.

No dispatch is in flight at any of these six losses, only draws. Yesterday's 39-second loss on 0b889d74 had one command in flight, the dispatch of request 13757b64… (CS 1a703579 there). Main emits that program differently: several structured loops where 0b889d74 emitted one loop that dispatches on a program counter.

The walks for indirect light and reflections cannot be given the buffer yet. With every walk given it, the device is lost as soon as the walks are bound (one run, on 0b889d74 with #389; not tried on main): Xid 109, no fault address, one command in flight, dispatch CS d2a8237e (request e2e6f99b…). That program reads neither the node buffer nor a ray query. It is the one that consumes the hits: 26 loops over heap indices, each under the translator's 65,536 guard, loading through ResourceDescriptorHeap. Its HLSL is the same on main. I have not looked further; until it holds I leave those five walks on their empty buffers. Two of the five are null passes in any case: main's translator refuses requests fb8e97e0… and ee98fc5f… with "raw buffer IDXEN needs the console descriptor stride".

Visible effect: none seen from the four distant-shadow walks in the yard scene of the intro. The runs without the switch die before the shots worth comparing, so the 1,201-second run alternates instead: a local switch gives the walks the buffer for 45 s, then their empty buffers for 45 s, and the log dates each change. In the yard shots I compared eight pairs of captures taken 30 to 60 s apart, one with and one without, at a quarter of their size and with the camera drifting. Seven show the same picture; in the eighth the yard's geometry is missing from one capture altogether. As a control I ran the same alternation with closed boxes around each scene in place of its structures, so that every ray hits (661 s of the world, 172 frames, the same end): the two pairs taken within one shot show the same picture too. On an older base (97f21fad, November 30) those boxes turned a sunset shot bright yellow. So in this scene what these walks return does not reach the picture, whatever they are given. I do not know yet whether that is the scene or something that changed since.

The structures the title builds. Not in #596; this is the local commit, and where I am going next. Builds in packed positions are written from title memory at the call. In the 1,201-second run, builds in float positions are written at the call too, then read again once the GPU is past that frame: this host's profile says section-import=aliased, so the CPU then sees what the GPU wrote. Of 8,192 such builds read again, 5,777 were written at the second reading, either because their bytes had changed or because the call had found bytes that are not positions and written nothing; 946 could not be read then either. The main scene then holds 2,550 to 2,590 of about 3,250 instances, against 765 to 779 of about 2,700 with packed positions only (the 558-second run). I have not checked those structures against a reference, and a host that substitutes the import would see no change at the second reading. The buffer held 999 MiB of its 1,024 after those 20 minutes: nothing bounds it yet, so the growth you asked about comes first.

@NickStallman

Copy link
Copy Markdown
Contributor

@3kynox one candidate for the Xid 13 in mesh-shader draws, not tested against your fault: on main the mesh and amplification stages of a mapped-root pipeline are translated without the index map, so under descriptor paging they read other descriptors. #617 (draft) fixes that; its Lanes scenario fails on main and passes with the change. If you try it on your card, the pipelines in your loss lines would be the ones to watch.

@3kynox

3kynox commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@NickStallman thank you. Tried on this card: main 717a74c4 with #617 applied, same setup as above, one run per line, time counted from the first ray dispatch of the world.

world before the end frames end
switch off 1,217 s 251 the 25-minute limit, no Xid
switch on, four distant-shadow walks 143 s 29 device lost, PS 8f67a984 MS a4b9766d (25 draws) in flight
switch on, the same 117 s 122 device lost, PS b56093d0 MS 7b9b4f4e (16 draws), PS 9d0710ae MS 9e6ae248 (9)

Without #617 the two runs with the switch off lost the device after 158 s and 13 s, so it looks like the fix for those here. One run, but it is the first on today's main to reach its limit on this card.

With #617 the switch brings a loss the run without it no longer has, which this morning's runs could not show since both sides died. VKD3D_CONFIG=fault gives ReadInvalid at 0x10602e000 and 0x10a565000. In both the nearest bound range ends at 0x100000000 (2 MiB and 4 MiB long), so the reads land 96 and 165 MiB past it. I do not know yet what in the switch does this; it is what I look at next, and #596 stays a draft until I do.

The indirect-light walks, to complete the paragraph above. Six runs of six with every walk given the buffer end about 15 s after the walks are bound: Xid 109, one command in flight, each time a hit-resolve program dispatched through ExecuteIndirect (requests e2e6f99b…, 4bada859…, b09437b6…, two runs each; five of the six on main). Reading the argument buffers back from title memory when the device is lost: the program of request 1859cab3… asks for 95,048 and then 100,976 groups in X, over the 65,535 a host dispatch takes in one dimension. Main splits a direct dispatch that large; nothing does for an indirect one. The resolve program in flight reads (0, 0, 1) by then, which need not be what the GPU read when it started. The title's signature for these dispatches is type 105 with a stride of 12 and a flags word of 0.

@NickStallman

Copy link
Copy Markdown
Contributor

@3kynox thanks for trying it. I have added your run to #617. For comparison: our builds have carried that change all evening, and we still see intermittent device losses on the first world scene change, 125-200 s in, on a 32 GB card: Xid 109 with mesh draws or compute (shadow rays, culling) in flight, and twice Xid 13. It is a different program each time, and runs with extra diagnostics on fail far more often than plain runs. We are still narrowing it down and will post when it is measured.

@3kynox

3kynox commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Narrowing what in the switch brings the loss back with #617. Same setup as above, one run per value, time from the first ray dispatch of the world.

switch walks given the buffer buffer world before the end end
off 1,217 s the 25-minute limit
on none 1 MiB 1,248 s the 25-minute limit
on four 256 MiB 740 s device lost
on none 1,024 MiB 536 s device lost
on four 1,024 MiB 143 s and 117 s device lost

It is not the CPU work at each rehydration and scene build: the 1 MiB run does all of it (1,703 structures expanded, nearly all left out for lack of room) and reaches its limit. It is not the walks' reads either: the run with no walk given the buffer is lost too. It follows the size of the buffer. The 1,024 MiB one falls back to system memory when it is created, in every run; the 256 MiB one does not and lasts longer.

Every loss has only mesh-shader draws in flight, and VKD3D_CONFIG=fault reports a ReadInvalid in memory that was never mapped, 29 to 177 MiB past a range of 2 or 4 MiB. On a card the title already fills, that reads as memory pressure rather than as anything in the buffer, which is @brcly's second question on this PR. One run per line, and @NickStallman's intermittent loss falls in the same window, so the two short runs prove little by themselves; the two that reach the limit and the order of the others are what I go by.

The buffer that starts at 64 MiB and doubles when nothing fits is merged locally on top of #596 (two more tests). I'll push it here once it has run in the game.

@3kynox

3kynox commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Two runs with the buffer starting at 64 MiB and doubling when nothing fits (local, on top of #596 and #617), four distant-shadow walks given the buffer, same setup and same clock as above.

world before the end frames end
247 s 72 device lost: ReadInvalid in a 0.7 MiB range that had been bound and unbound before; 31 dispatches of the title's skinning programs in flight (requests 00fed6ad…, c026151c…, 5d56eda2…), no draw
1,247 s 524 the 25-minute limit; a device loss is reported 5 s before the launcher's interrupt, ReadInvalid in a 192 KiB range bound and unbound before, 140 draws in flight

In both the buffer went 64, 128, 256 MiB, with 990 and 1,507 structures placed, none left out and no fall back to system memory. Neither fault is in memory that was never mapped, which every loss with the fixed-size buffers was; both are the freed-then-read kind, far from the buffer.

So with #617 and the buffer starting small, the walks read the structures for 20.8 minutes of the world in one run of two, and the other ended on what looks like the intermittent loss @NickStallman describes. @brcly, is that enough for the first condition while that loss is open, or would you rather see it repeated once it is fixed? The second condition stands as written above: no picture yet from these four walks in the scenes these runs reach.

The growing buffer is not pushed yet: one case is still open, a list that waits more than four presents between recording and execution could read a buffer already given back. It needs the wiring to make the list hold the buffer, which belongs in #596.

@brcly

brcly commented Dec 1, 2026

Copy link
Copy Markdown
Owner

@3kynox thanks for narrowing it down so carefully. The fixed-size runs show the losses follow the buffer's size, and the growing buffer removes the never-mapped reads, which is real progress.

On your question: one run of two isn't enough for the first condition yet, so I'd keep #586 until the remaining loss is understood. What would settle it is the same build and settings with the switch off: if those runs lose the device at about the same rate with the same freed-then-read kind of fault, the loss isn't from the structures, and #586 can go in with the growing buffer. If the losses only come with the switch on, they're ours to find first.

#536 is merged on its own (see there), so #586 can rebase onto main. Please put the growing buffer and the list holding its buffer into #586 and #596 as you describe, since a list that waits more than four presents reading a buffer already given back would be the same use-after-free class we're chasing in #603. The second condition (a picture from these walks) stays as it was.

…ing fits

The buffer was reserved whole, 1,024 MiB by default. It now starts at
64 MiB and is made again at twice the size when no place fits, up to
TUXBOX_CONSOLE_HEAP_MB, which becomes the most it may be. A scene's
offsets are relative to the buffer, so the larger buffer begins with a
copy of the smaller one and a walk reads the same from either. The
smaller one is kept for the lists that bound it, by the same rest as a
place given up.
@brcly
brcly merged commit bb52b9b into brcly:main Dec 1, 2026
5 checks passed
@3kynox

3kynox commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@brcly the switch-off control you asked for, now that #625 is fixed.

Setup. One tree, the same settings on both sides, 25-minute limit, runs alternated. RTX 4070 Ti SUPER 16 GB, 620.73.04, Intel CPU. The tree is 6d4f1cd7 with #647 on top, because d2985fb3, the main I started from, exits before the world here (#533); no other change. GE-Proton11-14, not the pinned 11-15. Default settings otherwise, VKD3D_CONFIG=fault and TUXBOX_TRACE_GPU_FAULT=1 in every run. The only difference is TUXBOX_CONSOLE_STRUCTURES=1 with the four distant-shadow walks listed. "World" counts from the first ray dispatch.

switch world frames end
off 1,223 s 1,905 the 25-minute limit
off 356 s 373 device lost, freed-then-read, 48 draws in flight (a player was moving the character)
off 172 s 59 device lost, freed-then-read, 14 draws
off 121 s 28 device lost, Xid 109, one dispatch (8d02ef34)
off 73 s 141 device lost, Xid 13, 43 draws, no data address
on 1,218 s 1,961 the 25-minute limit
on 1,197 s 1,916 the 25-minute limit
on 513 s 525 device lost, freed-then-read, 48 draws
on 212 s 138 device lost, freed-then-read, one draw
on 134 s 18 title crash after inline ray scene or geometry changed after recording, rejecting submission

Four of five end early with the switch off, three of five with it on. The freed-then-read fault comes twice on each side. The rejected submission also ended a run with the switch off at other settings, and #382 has it from builds without this code. The spread is wide, so five runs a side give no rate, but I see no loss that comes only with the switch.

Correction. I wrote on this PR that the 95,048-group indirect dispatch is over the host's limit. vulkaninfo gives 2,147,483,647 groups in X on this card (65,535 in Y and Z), so it is not over Vulkan's limit here.

The indirect-light walks. On this tree the hit-resolve programs are emitted with 11 or 12 loops instead of 27. With every walk given the buffer the device is still lost soon after the walks are bound: Xid 109, one command in flight, d2a8237e. So the second condition stays open: no visible effect to show yet.

@3kynox

3kynox commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@brcly the three things you asked for before the console structures become a default.

A visible effect: yes. In ProjectScarlett's first playable scene, the right side of the room (the drawings on the wall, the bunk) is lit by indirect light with the structures on and goes black with them off. All nine walks are served, the programs that shade their hits run, and nothing is skipped. Alternating every 45 s from a still camera, it switched 5 times out of 5 each way in one run and again in a second, shorter one (TUXBOX_READ_RESIDENCY=0 in both). I haven't compared the colour with a console. A picture of the same view on and off follows in the next comment.

What blocked it was in the translator: a ballot branched on the lane around its operand, and NVIDIA's compiled program never ended. The five-line change is #670.

The list that holds its buffer: merged in #644.

The off/on control: done for four walks, not met yet for all nine. The four-walk control is my previous comment here: ten runs, no loss that comes only with the switch, and that result stands. With nine walks and the shading programs running, three pairs on the same build: the device was lost in three runs of three with the switch on, and in one of three with it off. Most of those losses look like #603. One looks like ours: the fault address points to a walk reading outside the structures buffer, and I haven't found the cause. So the switch should stay off by default until I have, and I'll redo the control then.

@3kynox

3kynox commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author
image

Left: structures on. Right: off. Same run, same still camera, TUXBOX_READ_RESIDENCY=0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on-author Changes or answers requested from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants