Commit Graph
578 Commits
  • GPU: texture staging buffers come from a small shared pool, not one per texture
    What was wrong: each uploaded texture kept an upload buffer of its own
    size for life, in system memory: 0.2 GB on main (run textures5),
    2.6-2.8 GB once placed textures are made when shaders read them (run
    integ2). Making a buffer for every upload instead (066fbbeb, run
    textures8) released them, but the menu movie, which rewrites 12.7 MB of
    textures every frame, then paid ~5 ms a frame for fresh buffers: texture
    preparation 12.7-13.8 ms in textures8 against 8.0-8.4 in textures7.
    
    What changed: every upload is recorded at submission by the submission's
    own list (23a4b62b), and `Host::execute` waits for each submission, so a
    staging buffer is free again from the next submission on. Detiles take a
    buffer of the same size from a pool shared by all textures, or make one;
    the buffers one submission used go back to the pool before the next
    one's uploads, and the pool keeps at most 64 MiB of free buffers (oldest
    dropped). The staging state keeps only the layout, the change tracking
    and the last hash. The memory line no longer gives "texture staging".
    
    Evidence: textures8 (one buffer per upload) ended at 7,871 MB of system
    memory and 24,771 MB of commit against textures7's 8,254 and 25,130
    (206 MB of staging gone), no out-of-memory and no removal in 200 s. Test
    `draw::tests::a_texture_owning_its_pages_is_uploaded_on_any_write` now
    also checks that a reused buffer carries the new bytes (WARP).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • HLE: writes into physical pages are reported where the pages show when the write ends
    DirectStorage writes streamed data into physical pages through views of
    its own and then tells the title views showing those pages, so that the
    GPU side's host copies of them take the new bytes. The list of addresses
    was looked up when the write started. A page window's decode (zlib or
    BCPack) takes milliseconds, and the title maps streamed pages into its
    GPU heap meanwhile (CopyPageMappingsBatchX): the remap marks the copies
    there, a refresh can take the page before the bytes land (zeros, or part
    of them), and the report at the end named only the old addresses, so the
    copy at the new one stayed stale with a clean tracker for good.
    
    The addresses are now looked up when the write ends (PageWindow::drop,
    after the copy in write_physical). An address mapped during the write is
    reported; one that stopped showing the page during the write is not, and
    needs not be: the unmap itself marked the copies there, and they read the
    address's new contents at their next refresh. A mapping made after the
    report is marked by its own remap.
    
    Test page_windows_report_where_the_pages_show_when_done: a page shown at
    A is mapped at B and unmapped from A while a window writes it; the drop
    reports B only (and write_physical the same). On the previous code it
    reports A.
    
    Found with the meshlet culling's copies: in title runs 5-8 % of culled
    batches read meshlet buffers whose host copies (4 MiB windows over the GPU
    heap's mapped pages) held zeros where title memory held the buffer, with
    the tracker clean: whole batches culled, run-dependent.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a retake marks host buffer copies alone, not textures' staging
    What was wrong: a retake (what a frame withheld leaves the host copies)
    marked the memory changed in every tracker holding it: host buffer
    copies, but also textures' staging and descriptor heaps, whose contents
    come from title memory, which did not change, and which shaders' writes
    never reach. Placed textures over withheld ranges (every world frame
    withholds 280-9,300 pages) were detiled and uploaded again each frame:
    97 MB a frame, 19 % of all texture uploads (run evict3, by each page's
    last reason).
    
    What changed: trackers of host buffer copies are made by
    `watch::track_copy`, and a retake marks only those.
    
    Evidence: test `watch::tests::a_retake_marks_buffer_copies_alone` (a
    copy's and a texture's tracker over one range: the retake marks the
    copy's alone, a later title write marks both); the retake test now
    uses copies' trackers. The crate's tests twice with 8 threads.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a retake marks the copies without opening their guards
    At every presented frame the copies of title memory a withholding frame's
    shaders wrote take it again (`retake_dropped`). `retake` did that through
    `changed`, which also gives write access back to every guarded 64 KiB page
    of the range, one VirtualProtect each, under the guard lock that title
    threads' guard faults wait on. Title memory did not change, so opening
    the guards bought nothing: the next take only re-guarded them, and title
    writes meanwhile went through unseen by the guard (marked anyway by the
    retake). Run perf15 (stack samples every second over the intro, main
    38994e53): 15.4 % of the submitting thread's samples were in
    retake -> changed_here, waiting in the kernel, the largest item after the
    GPU wait (30.8 %) and the refresh copies (23.1 %).
    
    Now a retake marks the pages changed in every tracker holding them and in
    the trackers of their other mappings, and leaves the guards in place: the
    next refresh copies the pages from title memory, `take` finds them guarded
    already, and a later title write still faults and marks them. The test
    fails with the old body (the page comes back read-write).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: the statistics line no longer walks the process heaps
    The video-memory line of diagnostics builds gave the committed bytes of
    every process heap through HeapSummary, once per stats window. That walks
    the multi-gigabyte process heap under its lock: in run perf15 (stack
    samples every second over the intro) it was 7.7 % of the submitting
    thread's samples, about half a second each time, and a title audio thread
    was waiting in our counting allocator's alloc_zeroed for the same share
    meanwhile. Every measured run had one such stall per window, in the frame
    time of the window it fell in. The line keeps the Rust heap's bytes, which
    the allocator counts for free.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: what a frame withholds leaves the host copies at the frame's end
    The withholding rule keeps what lists using title memory wrote out of
    title memory while frames miss, but not out of the host copies: the GPU
    keeps reading it there, and since the title never rewrites that memory the
    copies kept it for good. In a later frame without misses, whose writes go
    back, a BVH builder program reading such stale results (its record arrays
    hold its destination addresses) wrote where they pointed: run textures9
    died 15 s into the world on a title object holding f16 +-inf pairs, a
    box16 node's empty bounds, written by the root-UAV byte ranges of a frame
    four frames after the last miss (title+0x4b6b75).
    
    Now everything a frame withholds (the page table's marked pages, root-UAV
    byte ranges, write marks of shaders using title memory) is noted
    (`memory::drop_at_frame_end`), and at the frame's end the memory counts as
    changed in every host copy holding it, aliases too (`watch::retake`), so
    each takes title memory's bytes at its next refresh, through its tracker.
    Results computed from memory with no copy live through their own frame
    only.
    
    What the tracers lose: within a frame they still read what the builder
    wrote; from the next frame on they read the title's memory where the
    builder's results were withheld, an unbuilt BVH instead of one built from
    zeros. Both miss everything.
    
    Test: `shadow::tests::what_a_frame_withholds_leaves_the_copies_at_its_end`
    (frame N withholds a record written into a title buffer's copy and an
    inner buffer's copy; frame N+1 reads title memory's bytes in both; fails
    without the change).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: upload tests count their own texture's uploads
    What was wrong: the upload tests read a process-wide count of texture
    uploads, so another test's uploads between their `before` and their
    submission landed in it: `a_texture_is_uploaded_once_per_submission_and_only_when_written`
    failed in a parallel run of the crate's tests and passed alone.
    
    What changed: each texture's staging state counts its own uploads; the
    tests read those of their texture (`texture::uploads`, tests only). The
    process-wide counter had no other reader and is gone.
    
    Evidence: the crate's tests three times in a row with 8 threads, 157
    passed each time; clippy clean on both feature sets.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: dropping a tracker keeps guards another mapping's tracker relies on
    A take guards a tracked page and every other mapping of the same physical
    page (the runtime links them when it maps them), so that a write through
    the title's pool view marks the copy of its tiled heap. But when a tracker
    went away, every page no tracker held any more got write access back,
    including a page guarded for a tracker of another mapping: after an exact
    or buffer copy over the pool view was dropped, the title's writes there
    went unseen by the loose window over the tiled heap, which stayed clean
    with stale bytes (shards' sweep: 9,520 such pages, ~620 MB, all guarded at
    the window's own address; for 2,789 a newer copy held the fresh bytes).
    
    Now a page stays guarded while a linked mapping of it is held; the next
    write there faults once, marks that tracker and opens it. The new test
    fails without the change (the write through the other view goes unseen).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: while lists using title memory miss, none of their writes go back
    What a list using title memory wrote stayed out of title memory only
    when that list itself read or wrote memory with no host copy. Lists after
    it compute from its results in the host copies, the BVH builder's write
    addresses among them (its record arrays), so their writes went back:
    with every builder program running (the bind fix after this one), drops1
    died 97 s into the world on a title pointer holding +inf/-inf, an empty
    AABB's floats (title+0x35a4245, then title+0x10823c).
    
    Now any miss of such a list marks its frame (`memory::note_missed`), and
    from then through the next presented frame (`memory::withholding`: the
    next frame's lists read this one's results before its own first miss)
    no list using title memory sends anything back, by any path: the page
    table's marked pages, root-UAV byte ranges, and write marks, which
    shaders using title memory now set in a bitmap of their own
    (`shadow::view_writes(true)`). Their results stay in the host copies for
    the GPU. With misses in every world frame this gives the title's CPU the
    same view as before the builder ran; it lifts itself when the misses stop.
    
    Tests: `memory::tests::a_miss_holds_back_its_frame_and_the_next`,
    `shadow::tests::marks_of_shaders_using_title_memory_are_held_back`.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • victory: the exe's bytes are dropped once the image is mapped
    What was wrong: `run` kept the exe as read (114 MB) and its patched copy
    (another 114 MB) alive until the title exited, though nothing reads them
    after the loader writes the patched copy and maps it: ~228 MB of the
    Rust heap for the whole run (large-allocation stacks of run textures8).
    
    What changed: the read bytes are a temporary of `prepare`, and the
    prepared image is dropped right after `load`. The mapped image, its
    path (`GetModuleFileName`), title DLLs and crash reports come from the
    loaded image and the files, not from these buffers.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a frame wait begun after its tick passed ends at once
    A frame-event wait (the title's flip wait before each present) always
    slept until the next tick after now, even when the frame had run long
    past the tick it was waiting for: in the intro cutscene, where frames take
    0.5 s against a 33 ms interval, that added 0-33 ms to every frame (4 % of
    the submitting thread's samples, run perf3). A wait now takes the latest
    tick passed when that is after the last tick its kind took (still one wait
    per tick per kind), as an event signalled at each tick and left signalled
    until a wait takes it would; the next wait waits for the next tick as
    before, so a title that keeps up is paced as before. That a late wait
    returns at once on the console is an assumption: nothing at hand says
    what a wait begun after its event does.
    
    Diagnostics: per stats window, frame waits and those that ended at once,
    and presents whose flip tick was the previous present's (should stay 0).
    Test: after two missed ticks a flip wait ends at once on the latest one,
    the next on the tick after.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: pages with nothing mapped are zeroed in host copies without failing copies
    When a copy's refresh met a page with nothing mapped (tiled memory the
    title unmapped, placeholders), the kernel read failed and the copy was
    redone by 64 KiB and then 4 KiB pieces, each failing again: 10-22 MB of
    unmapped memory a frame took 7-30 ms (run perf4). The tracker already
    learns which pages are unmapped when it fails to guard them; `take_split`
    now returns those runs apart, and the refresh zeroes them in the copy as
    the piecewise copy did, with no kernel read. Test: of a reservation with
    one page committed, the committed page is to copy and the other to zero.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a texture written in pages of its own is uploaded without hashing it
    What was wrong: since 23a4b62b every upload of a tracked texture hashed
    the texture's bytes (BLAKE3) to skip uploads whose bytes did not change.
    That pays for small textures sharing 64 KiB pages with other data the
    title writes, but not for textures the title rewrites every frame: the
    menu movie's Bink planes (3840x2160 Y plane plus chroma, 12.7 MB a frame)
    took 12.7-13.8 ms a frame of texture preparation in run textures8
    (12.0-12.9 in integ3), against 3.7-5.2 ms before 23a4b62b (mk3, perf5).
    
    What changed: when a changed page lies wholly inside the texture (it
    holds nothing but texture bytes), the write itself says the texture
    changed: no hash, and the stored hash is forgotten. Textures whose
    changed pages are shared still compare their bytes.
    
    Evidence: tests `draw::tests::a_texture_owning_its_pages_is_uploaded_on_any_write`
    (new) and `a_texture_is_uploaded_once_per_submission_and_only_when_written`
    (now also: the same bytes in a shared page are not uploaded) on WARP.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shader: 16-bit typed buffer accesses pass bits through integer views
    On GFX10 a typed buffer access converts by the buffer format of its
    descriptor, and `_d16` only packs the 16-bit results: through a UINT or
    SINT view, `buffer_load_format_d16_*` and `buffer_store_format_d16_*` move
    the 16-bit integers as they are. The lowering always converted them as
    halves (f32 to f16 on loads, f16 to f32 on stores) through a float-typed
    handle, so through an integer view a store wrote a float's bit pattern
    into the 16-bit element and a load turned the integer's bits into a
    denormal and then to 0.
    
    Grand Theft Auto VI's compute graph (the 65 compute_graph_ops programs:
    the face network's matrix products, activations, reductions, copies; the
    only users of these accesses in the title's world set) keeps its halves
    in R16G16B16A16_UINT and R16_UINT views. Its output was bit soup that
    changed from frame to frame (shards6: 0x0011 0x0001 0x0015 0x006D 0x80EC
    ... at frame 1658, 0xD8A8 0xA388 0x2F30 0x0472 ... at 1670 in the same
    place), the blendshape extract turned that into the head's translations,
    and the main character's head came out as a flat slab or not at all.
    
    The view's format kind now rides in the view-stride table, beside the
    stride: bit 31 an integer format, bit 30 a signed one (VIEW_INTEGER,
    VIEW_SIGNED; stride readers mask them off). The host sets them for typed
    buffer views of UINT and SINT formats. A d16 typed load through such a
    view keeps each channel's low 16 bits; a d16 typed store zero- or
    sign-extends the 16-bit integer. Float, normalized, raw and structured
    views keep the conversion they had. The integer path still uses the
    float-typed handle and relies on the driver passing a mismatched
    component type's bits through (shortcut comment; checked on the RX 6700
    XT and WARP by the new tests).
    
    RESULTS
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a listed frame's trace shows the title's barrier calls
    Diagnostics only. The trace of a listed frame named every command but not
    the barriers between them, so whether the title orders two dependent
    dispatches could not be read from it. Each barrier call now notes itself
    in its list: the enhanced form as its groups' (kind, count) pairs (0
    global, 1 texture, 2 buffer), the legacy form as its barriers' kinds.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: inputs a counted v_movreld loop overwrites first need no value
    `PS_DownSampleBloomFilter(Karis)_557ae3d7` (the bloom downsample, 3 draws
    a frame in the intro cutscene) fills a register array v0.. with
    `v_movreld` in a uniform loop counted from a constant start to an `eq`
    bound. v0/v1 hold the raw barycentrics on entry, which have no host form
    ("barycentrics read directly"), so the loop header's phi refused the
    program although no lane ever reads those values: the loop's first passes
    overwrite them.
    
    PR #457's proof, ported onto the current lowering: the loop-carried
    register's only use is the unguarded `v_movreld` at index M0, M0 a copy
    of a scalar phi starting at a constant and stepping by 1 to an `s_cmp_eq`
    bound that exits through the one exit block; the register's slot lies in
    [start, bound), so the move writes it before anything can read it, and
    the entry edge's value is undefined. Every other shape keeps the refusal
    (the PR's 15-case test: wrong start, skipped slot, decrement, wrap,
    unknown start, short loop, clobbered SCC, early or divergent exit, masked
    write, old value as source, reads before the write or on the back edge).
    
    Shader list against f6cd0144: 0 newly failing; `PS_DownSampleBloomFilter
    Karis_557ae3d7` and `PS_DownSampleBloomFilter_557ae3d7` emit, validate and
    make pipelines (1-2 s, under 0.1 GB).
    
    Ported from PR #457 (efcd753a, 08b681c2, Jeremy Goldberg): the fill-phis
    arm now takes the edge's liveness from `live_edges`.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: descriptors joined by nested control flow stay refused for now
    Takes back PR #1012's recursive heap index (an edge into a descriptor's
    join that is itself a join). Across the title's shader list it lets one
    program through, `indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays`
    (issued every cutscene frame), and that program's host pipeline does not
    fit the machine: the DXIL validates in 4 s, but the AMD driver's compile
    passed 6 GB after 64 s under a watchdog (unwatched it reached 26.7 GB
    commit and starved a title run, drops2). Its DXIL has 22,382 branches,
    2,609 heap handles and 2,478 size queries (151k lines), against 3,857
    branches for the next largest newly emitted program, which compiles in
    24 s and 0.8 GB.
    
    The refusal is "a descriptor chosen by control flow" again, as on `main`;
    edges no lane takes still join no heap index (previous commit). The
    change can come back once pipelines this costly stay off the title's
    pipeline worker (`shortcut:` at the arm).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: a lane mask joined with data at a uniform join is its number
    The title's wave-uniform BVH walks (`shadowmask:CS_TraceShadowRays_
    Checkerboard`, `deferred_tiled:CS_LaserLightShadowRaytracing`, the four
    `rtdirectionalshadows:CS_RTDistantShadow*_Tiled`) keep the lanes of the
    node being visited in an SGPR: a lane mask on entry, a number popped from
    an LDS stack (`v_readfirstlane_b32`) on the loop's back edges, read both
    as a number (`v_and_b32` with the lane's bit, `s_cmp`) and as a mask. The
    join was refused: "a register joining a lane mask and data, read as data"
    (40 programs), then "a lane-mask join of an untracked mask".
    
    At a join where every branch in is uniform (SCC), every lane comes along
    the edge the console's wave took, so the register holds that edge's
    value. In compute (console lanes) a mask's number on its edge is its
    ballot there (`mask_dword`), exact; read as a mask, a number gives each
    lane its own bit (`lane_bit`, as `Atom::Opaque` does). A per-lane branch
    into the join (an EXEC skip, a per-lane loop exit: where lanes would take
    edges the wave did not; the console compiler's if/else always enters its
    join that way) keeps the refusal.
    
    Tests: `a_mask_joined_with_data_needs_a_uniform_join` (the per-lane loop
    still refused, the uniform one lowers);
    `synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number`
    (a mask shifted through a VGPR around a uniform loop, read as a number and
    as each lane's bit; values checked on the GPU, hardware and WARP; fails
    without each half of the change). Shader list against `main`: 0
    newly failing, 29 newly emit; all 40 "a register joining a lane mask and
    data" programs pass it (16 stop at a later mask join).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: a descriptor no lane brings along an edge needs no source there
    A uniform descriptor joined at a block was traced along every
    predecessor edge, so an edge no lane takes stopped it with the registers
    it would bring: `indirect_light_probes:CS_Alpha_Schedule` and
    `alphaResolve:CS_AlphTransmissionPrefilterMip` load a texture under the
    lanes that ran before `s_wqm` and skip the load when there are none; in
    compute every lane runs from the start, so nothing takes the skip, but
    the skip edge's stale input SGPRs made "a descriptor neither loaded nor
    built".
    
    `resource.rs` now gives such an edge (structurisation's lane conditions:
    the edge's reach and branch condition cannot hold) a taken edge's source,
    and lowering joins a 0 heap index there (`never_taken`, the same test),
    so nothing is computed on an edge no lane runs.
    
    Test: `a_descriptor_skipped_only_by_lanes_that_never_run_needs_no_source`
    (the `s_wqm` / `s_and_saveexec` / skipped load / sample shape; refused
    without the change). Shader list against `main`: 0 newly failing;
    `CS_AlphTransmissionPrefilterMip` and
    `shadowmask:CS_TraceShadowRays_ScreenSpaceOnlyCheckerboard` emit,
    `CS_Alpha_Schedule` stops later ("an address into a descriptor heap with
    an untracked high half": the address's high half is set inside the same
    skipped region).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: descriptors joined by nested control flow
    A descriptor every lane shares, chosen by an if/else nested in another,
    reaches the outer join with an edge that is itself a join. Such an edge
    was refused with "a descriptor chosen by control flow": each edge had to
    be a heap load. The heap index is now computed recursively: a load's
    index, or a phi at the join of what each predecessor computes at its end.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a drop counted by its reason names the pipeline's shaders
    The per-frame drop ranking (diagnostics) counted draws and dispatches
    that have a host pipeline but cannot be bound by reason alone, so a
    reason's hundreds of drops a frame could not be traced to the programs
    behind them without a traced list. The key now ends with the pipeline's
    shaders, as the "no host pipeline" keys already do.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a texture is uploaded once per submission, and only when its bytes changed
    Every list that read a title-written texture through a table recorded the
    copy of its staging buffer into the host texture, changed or not: run
    perf7 counted 3,195 texture copy commands in one frame for 149 textures
    (a 64x64x32 R16 array 24 times, a 512x512 BC7 18 times), 17 ms of GPU
    time, the largest single GPU item.
    
    A list now only defers the texture (staging and host texture). At
    submission the textures of all its lists are brought up to date once, and
    those whose memory changed are copied by the submission's own upload list
    (the one heap-indexed textures already had), which runs first. For memory
    the change journal follows, a flagged page uploads the texture only if the
    texture's own bytes changed (a 64 KiB page holds other data too). As for
    heap-indexed textures, a title copy into texture memory recorded in the
    same submission shows from the next one on.
    
    Test: two lists of one submission upload a texture once, the next
    submission not at all, and again once the title writes it.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: large heap allocations name their caller; list upload memory in the memory line (diagnostics)
    The counting allocator logs the stack of the first allocation of each
    power-of-two size class from 32 MiB (who holds our 1.8 GB of large
    blocks, run textures6), and the video-memory line counts the live list
    upload blocks (list 0x4a0) and their bytes.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a heap's merged view ranges are kept current, not rebuilt whole after each change
    Each list running heap-indexing shaders asks for the ranges every view of
    the heap reaches, merged per host copy; they were rebuilt from all ~9,000
    copies whenever one range came or went, which the title's view writes do
    between most lists: the heap step still took 13-27 ms a frame in run
    perf4 although it now passes clean copies by.
    
    The merged range of a copy is now updated where its ranges are counted,
    only for that copy, and the step walks the current set.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: diagnostics: title threads' wait for the heaps' lock; host copies in video memory
    * copystat: time title threads spend waiting for the shader-visible heaps'
      lock when they write a view (held by each submission's heap sync).
    * `VICTORY_COPIES_IN_VIDEO_MEMORY=1`: shared buffers, host copies of
      title memory among them, in a GPU upload heap (video memory the CPU
      maps) where the host has one, to measure how much of the GPU's time is
      shaders reading copies across the bus. CPU reads of the copies get slow
      (snapshots, copy-backs): for that measurement only.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: copies of single views share large buffers
    A view the title places off its buffer copy's elements gets a host copy
    of its own bytes (`shadow::exact`), and each was a committed buffer of
    its own: a kernel call to make it (and one to free it) on the title's
    recording threads and on the submitting thread during heap syncs, 240-820
    a frame in the cutscene, and 64 KiB of memory each for ~2 KB of data
    (~5,000 live). A stack sample of a `drops` run caught the submitting
    thread in that kernel call inside the heap sync, which holds the heaps'
    lock, while three title threads waited for that lock to write views.
    
    Such copies now take runs of shared 16 MiB buffers (first fit; a run
    starts at a multiple of the view's element and of 256 bytes, so the view's
    first element stays exact; a copy larger than a buffer gets one of its
    size); a run goes back, joined to its free neighbours, when its copy goes.
    A host copy knows where it starts in its buffer (`offset` adds it; its
    mapping and host address point at the run), so the views made over it are
    unchanged. Copies are now keyed by element size too. Test: runs are
    aligned to their elements, disjoint, and joined again.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: diagnostics: copies redone piece by piece are timed; GPU timing keys keep the pipeline
    * copystat: time spent in copies that met an unmapped page and were redone
      by 64 KiB and 4 KiB pieces (10-22 MB of unmapped memory a frame in run
      perf3, thousands of failing kernel reads, not counted before).
    * `VICTORY_GPU_TIMING`'s per-pipeline table dropped every word starting
      with a digit, so pipeline hashes starting with one vanished from its
      keys; the key is now the command's kind and the pipeline's name.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: change trackers keep their "written since taken" flag in one dense bitmap
    The flag from 19533398 let a submission skip host copies the title had not
    written, but reading it still touched each copy (copy, tracker, flag: a
    cache miss or more each) and the heap step cloned its ~9,000 merged ranges
    first: the heap and page-table steps still took 25-41 and 16-26 ms a
    frame (run perf3) to find the few written copies among ~14,000.
    
    Each tracker now owns a bit in a static bitmap (set and cleared under its
    lock as before, read without one; given back when the tracker goes). The
    heap's merged ranges and the page table's copy list keep each copy's bit
    beside it, and both steps read the bits, walk their lists in place and
    pass only written copies to the batch. Test: a new tracker starts dirty,
    a taken one reads clean, a tracker with no bit is never clean.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a heap sync looks at a page's slots under one lock and makes only the changed ones
    Each submission's heap sync (descriptors the title copies into its heaps
    as bytes) mirrored every slot of every heap page written since the last
    sync: ~700,000 slots a frame in the intro cutscene (run perf3), two lock
    takings and a view clone each, 76 ms a frame after the placed-texture fix
    (113 ms before it, run perf2).
    
    `HostHeap::sync_slots` reads a page's records, asks the view registry once
    whether each names a current view, compares them with what the slots hold
    under one lock, and calls `mirror` only for slots whose record differs
    from what the slot holds: the decisions `mirror` makes for the others are
    to do nothing, so the result is the same. Test: a record copied as bytes
    and a record cleared are made at the next sync, the others passed by.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: change tracking guards only the runtime's memory, region by region
    `watch::track` decided from a range's first page whether the whole range
    was the runtime's GPU memory. Memory outside title buffers gets a host copy
    of its 4 MiB-aligned window (`shadow::loose`); a window whose first page was
    free memory was tracked whole, and taking it guarded (made read-only) every
    committed page in it, other allocations' too. In the crate's tests a
    constant view of a heap block did that to the process heap: threads faulted
    inside RtlFreeHeap/RtlAllocateHeap while holding the heap lock and waited in
    the guard handler for the guard lock, whose holder (a take in another test's
    submission) waited for the heap lock. The suite hung about one run in two
    on a branch that added such a test (stacks of two hung runs; the reading of
    who held which lock is inferred from them).
    
    The decision is now made for every region the range covers: write-watched
    pool memory, or with views anything but plain committed memory and images,
    as before for the first page. A 64 KiB page touching any other memory is
    not tracked: never guarded, and copied whole at each use, as a copy of
    memory with no tracker always was (such a copy is never clean). One
    write-watch query still answers the common case (the range in one pool)
    without `VirtualQuery`, which costs milliseconds in the runtime's big
    pools; the region walk runs once, when a copy is made. In boot-to-world
    runs no memory was copied whole (perf2, perf3, mk3: 0.0 MB in every
    window), so this is about robustness. Tests: a window from free memory
    over a plain allocation into a pool guards the pool only; a title buffer
    over a pool and a plain allocation copies the plain part at each use, its
    bytes and their later change, and leaves it writable.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: our heap bytes and the process heaps in the memory line (diagnostics)
    The video-memory line also gives the bytes committed in every process heap
    (Rust code's and the title's C runtime's) and, through a counting global
    allocator the binary installs in diagnostics builds, the bytes Rust code
    holds: the 12.5 GB of plain private commit not yet attributed (run
    textures5).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: the snapshot pool keeps at most 512 MiB
    Snapshot buffers kept for reuse were capped at 2 GiB of private commit.
    Since shaders mark the pages they write (cd94d353), the cutscene snapshots
    0.1-0.8 GB a frame over 26-45 submissions (run textures5: 402 MB a frame;
    mk2/mk3: 10-134 ms of snapshots), the largest single one the 174 MiB
    GPU-heap buffer; 512 MiB keeps two of those and frees up to 1.5 GiB of
    the process's commit (the title's world runs at 25.6-26.9 GB on a 32 GB
    machine).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: the console's 16-bit depth with stencil is float depth on the host
    The console's 16-bit depth with stencil (formats 118-120; Grand Theft Auto
    VI's material depth) was a host D24S8 texture. CS_GenerateMaterialMasks and
    CS_MaterialTilesInitial write it through 16-bit unordered views (the depth
    twin), the 180 tiled-lighting draws then test it EQUAL at z = the material
    index times the title's 1/65535 (0x37800080), and the twin reached the depth
    plane as 24-bit unorm by copy. On the RX 6700 XT a draw at those depths
    passed EQUAL for k = 258 only of 1..4096: the driver keeps 24-bit depth as
    floats (AMD hardware has no 24-bit depth), so a copy stores d24 / (2^24 - 1)
    and the rasteriser the unquantised z, and the two agree only by accident.
    Every tiled-lighting draw failed its depth test on every pixel.
    
    Now 118-120 are D32_FLOAT_S8X24 (20-22) on the host, and the twin converter
    writes the float the title's own shaders compute for 16-bit value u,
    f32(u) * 0x37800080 (back: round(f * 65535)), so the depth plane holds the
    very float a draw rasterises. That float equals the correctly rounded
    u / 65535 (what the console's R16_UNORM view reads) for every u but 512
    values from 257 up (1 ULP); every float rounds back to its u.
    
    Evidence: a_depth_texture_written_through_unordered_views_reads_as_depth
    now draws a square (two triangles, as the title's rectangles become) per
    pixel at the title's depth for k = 1..4096 against the UAV-written plane
    and asserts all pass (24-bit: only k = 258), on the RX 6700 XT (suite 147
    passed) and WARP (150 passed, with diagnostics); the twin round trip,
    stencil and clear-to-16-bit checks still pass. Runs light5-light7 (240 s,
    warm, with the luminance read-back): no crash or removal. Run light7, frame
    1515 (raw dumps): the lighting records with an instance (0, 1, 5, 7, 29)
    are exactly the material indices present; pixels whose 128x120 group lets
    their draw run are 86-99 % exactly zero after the lighting submission
    (index 5: 1.31 M pixels, 99 %), pixels whose group culls it only 41-60 %;
    the lighting pipelines test depth EQUAL, write no depth, use no stencil,
    depth bounds or blending. So the draws now pass and overwrite the target
    with their own result.
    
    Expect DARKER surfaces in the cutscene until the shadow tracing runs; not a
    regression of this change. Before it, those pixels kept what the material
    mask pass had written into the lighting target (light3's "lit-looking"
    buildings were those leftovers, not light). The tiled-lighting shader's
    per-light shadow factor reads a tile map and atlas (15360x180 R32_UINT,
    4096x3640 R8_UINT) that are all zero because CS_TraceShadowRays_Checkerboard
    is dropped untranslated, so every shadowed light is skipped and the result
    is 0 there.
    
    Shortcut (comment at pc_format): a depth bias on such targets counts in
    float steps, not 1/65535.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: 8-bit RGBA dumps log their alpha range and zero counts
    The dumps write 8-bit colour as is and drop alpha; a line per dump now
    gives each channel's range and how many texels hold zero there (the grass
    trail map's alpha, for the missing ground).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: the title memory read to detile a tracked texture is not kept
    A journal-tracked texture's detiling read its title memory into a buffer
    the texture's staging kept for its whole life: each such texture took its
    size once more in system memory, besides its upload buffer. The read is now
    a temporary. Texture staging in the cutscene: 414 MB (run textures2, read
    buffers kept) against 195 MB (run textures3, not kept).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: texture to buffer copies read back into the title's buffer
    The title reads textures back from the world's first frame on
    (CopyTextureRegion, texture to a placed footprint in a buffer) and VIctory
    dropped every such copy ("texture to buffer copies not implemented",
    TODO.md since 2026-11-23): whatever the title computes from those bytes
    on the CPU used stale memory.
    
    The region is now copied on the host into readback memory laid out as
    the title's footprint (offset 0, the title's 256-byte pitch), and once the
    list has run, before its bottom-of-pipe writes and so before the title
    can see its fence, each row of the region goes into the title's buffer
    (watch::writing + write_mapped, as copy-backs do). Refused with a reason,
    once: depth or stencil textures, pitches not a multiple of 256, regions
    outside the footprint. Diagnostics: the first read back of each
    (texture, buffer) pair is logged with the texture's memory, size and
    format, and every 5 s "texture read backs: N/frame, KB/frame".
    
    Measured (run shards5, this on 5622159f): the title reads back two
    textures from the world's first frame on, each into one of two buffers it
    alternates between: a 5x1 R32G32B32A32_FLOAT (80 bytes, written by
    avgLuminanceCompute:LuminanceMinMaxDownsampleFinalCS) and a 1x1
    R32G32B32A32_FLOAT (16 bytes, written by
    ComputeAverageDepthWeightedLuminanceFromHistogramCS): the auto-exposure
    values its CPU side adapts with, so far read stale. 4.0 read backs a
    frame, 0.2 KB a frame; nothing refused.
    
    Tests: a footprint's row ranges, and a round trip through the title's API
    (a texture filled from a buffer through our list's copy slot, a region of
    it read back into a second title buffer through the same slot, run by our
    queue; the region's rows land at the footprint's offset and pitch, the
    rest of the buffer is untouched). The round trip caught a first version
    whose readback memory ended at the region's last row: the host copies
    into a footprint only in a buffer that holds all of it, so the list
    failed and the process ended.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: debug lines for sampled texture uploads
    At `victory_gpu::texture=debug` (diagnostics builds): every detiling of a
    sampled texture says whether its memory was all zero, and a sampled
    texture that keeps what the host copied into it (never uploaded from
    title memory again) is named once. For the terrain's mesh-stage texture
    that `shards` found holding zeros (run shards2).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: host textures made on first use
    Every title texture got a host texture (VRAM) when the title created it.
    Run textures1's census in the intro cutscene: of 11.6 GB of host textures,
    4.8 GB were textures fed from title memory that no list ever used and no
    heap slot ever viewed, and the card's usage was 12.3-12.4 GB against a
    10.78 GB budget.
    
    A title texture's host texture is now made the first time anything asks
    for it: a list's barrier, binding, copy or upload, a heap slot's view. As
    textures of one memory can now be made in any order, the first one made
    takes the uses (render target, depth, unordered access) of every title
    texture of that memory, so a later one with more uses shares it instead of
    replacing it (which had left the first one's views on a texture the GPU
    never writes). The creation's state and clear value are kept for it.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: process memory and a host texture census in the statistics
    Diagnostics builds, every 5 s: the video-memory line also gives the
    process's private commit and working set, texture staging bytes (upload
    buffers and title memory read for them) and the console bytes of placed
    textures made; a second line gives host texture bytes by writer (the GPU:
    render target, depth or unordered access; or title memory) and by reach
    (used by a list, only viewed by a heap slot, neither). The heap census
    also names the placed textures left null: distinct addresses and bytes.
    
    Run textures1 (cutscene, with a since-dropped eager step for small placed
    textures): card 12.3-12.4 GB used of a 10.78 GB budget, system 6.8-7.1 of
    16.3 GB; GPU-written 2.29 GB used by lists, 2.10 GB only viewed, 0 neither;
    from title memory 1.63 GB used, 0.43 viewed, 4.8 GB neither; placed
    textures left null 12-16k slots at ~12.5k addresses, 8.4-8.9 GB.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a placed texture's slot left null is not made again at every heap sync
    `HostHeap::mirror` left a placed texture's view null until a draw reads it
    through a table, and recorded its slot as never made, so every heap sync
    (one per submission, over every page the title wrote) processed the slot
    again: a null view written and the heap census updated each time. `perf`'s
    profile of run perf1 put `sync_heaps` at 120-180 ms a frame (13 % of the
    frame thread), most of it these slots (9,000-16,000 placed-texture slots
    left null in the cutscene, run textures1).
    
    The slot's record is now noted like any other; a draw's mirror still makes
    it (its slot holds no host view yet).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • HLE: DirectStorage reads into physical pages wait for the title's Submit
    A request into the engine's physical pool carries as its page list a
    pointer into the engine's own page-number table (sub_144ffd8c0), and
    Grand Theft Auto VI fills that table for a batch's pages only in its
    submit path, right before Submit (sub_1400e88f0 runs the batch's page
    mappings, sub_140f2c470 -> sub_1455aa6a0, then EnqueueStatus and
    Submit). A queue that submitted itself at half capacity started such
    reads early: they found page 0 and failed after the 8 ms retry (93-498
    requests a run, every one with an all-zero page list in shards2), or
    found the page's previous number and wrote the data into a page that
    now belongs to something else, silently.
    
    A half-full queue still submits itself, but its reads into physical
    pages, and the status entries behind them, now wait for the title's
    Submit; a full queue submits everything, so a title that never submits
    cannot deadlock. The page list is still read when the data is written.
    The failure warning names the list, options, file and offset, and an
    info line counts self-submits (capacity, reads held).
    
    Measured: shards2 (before) 33 failed page writes, all with an all-zero page
    list, and 5 written late; shards3 (after, same build otherwise) 0 and 0,
    to the 200 s time-out. Self-submits in shards3: 2 by the world's start,
    the second holding 2,079 reads into physical pages (capacity 4,159):
    the title's streaming batch is larger than half its queue.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: traced shaders' indirect records are logged in every frame
    VICTORY_TRACE_SHADERS now also reads back the records of every indirect
    execution whose pipeline holds a listed shader, in every frame, not only in
    dumped capture frames, and the line names the frame. Traced commands are
    logged without the 500 cap in listed capture frames.
    
    Why: whether the tiled-lighting draws get instances could only be seen in
    frames with VICTORY_DUMP_TARGETS, which cost ~40 s each and at today's
    speeds never reached a cutscene shot with geometry. Run light2 (traced
    VS_TiledLighting 25ebc92075b62822): 2,760 executions over world frames
    1678-1723, 10-16 of the 60 per frame with an instance in cutscene shots, 2
    in sky shots.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: D3D12 objects freed after a submission are released on a thread of their own
    Releasing a resource is a kernel call. In run perf1 (intro cutscene) ~5 %
    of the title's submitting thread went into releases inside the
    submission: resources retired while the GPU ran, host copies whose last
    holder was the submission's own bookkeeping, and (diagnostics) a
    read-back buffer made and freed at every present for the black-frame
    probe.
    
    Retired resources and the submission's batch, copy-back list and heap
    list now go to a `victory-release` thread once the submission has run
    (nothing in flight uses them); the probe keeps one buffer (presents are
    waited for one by one).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a submission skips host copies the title has not written since they took it
    Every world submission asks for every host copy its heaps' views and page
    tables reach (~9,000 copies) to be brought up to date, and almost none
    changed: run perf1 (intro cutscene) made 140-240k change checks a frame,
    each taking two locks, a set range query and allocations, plus per-copy
    timing and statistics: ~18 % of the submitting thread's time (refresh
    batches 195-405 ms a frame in all, the copying itself ~12 %).
    
    Each tracker now keeps a flag "some page changed since taken", set where
    pages are marked changed and cleared where they are taken, all under the
    tracker's lock, read without one. A batch leaves out clean copies and
    `Shadow::update` returns at once for them: the same result as before (a
    take finds nothing), minus the work. A write racing the flag is found by
    the next submission, as one racing a take always was.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: diagnostics for the frame's cost: heap sync time, video memory, GPU time per pipeline
    The fps line left a share of "preparing" and of the GPU time unexplained.
    Three diagnostics (diagnostics builds only):
    
    * copystat: time making the descriptors the title copies into its heaps
      as bytes (`sync_heaps`, start of every submission). Run perf1 (intro
      cutscene, DRED off): 120-180 ms a frame, 13 % of the submitting
      thread's time, unattributed before.
    * A "video memory" line: use and budget on the card and in system memory
      (`QueryVideoMemoryInfo`), to tell whether the memory manager pages at
      submissions.
    * With `VICTORY_GPU_TIMING`: GPU time per kind of command and pipeline
      over each stats window (the 25 costliest), and the lists' wall time
      against the sum of their commands'.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a draw dropped because a root view cannot be bound says why
    `bind()` returned false without a reason when a root view's address lay
    in no host copy, was not set by the title, sat 4 GiB or more into its
    copy, had no host view heap or found no dynamic slot. The drop ranking
    then showed such draws as dropped "()": in the intro cutscene about 310
    dispatches a frame (run mk3), almost all compute programs of the BVH
    builder whose root view address is in no host copy.
    
    Every such return now records its reason through `not_run`.
    
    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
  • GPU: shaders mark the pages they write through views; copy-backs compare only those
    The world snapshotted every buffer range declared as written before each
    submission and compared it after (2.8-4.5 GB a frame, 98 % unchanged,
    0.45-0.7 s of a 1.5-1.7 s intro-cutscene frame), almost all the title's
    174 MB GPU-heap buffer.
    
    Translations made with `emit::Options::view_marks` (the shader cache's)
    set a bit per 64 KiB title page in a bitmap for every store or atomic
    through an unordered buffer view (tables, the heap, root UAVs), looked
    up through a per-slot view-mark table each host view heap keeps. Each
    tracked host copy owns a run of bits; after a submission only the marked
    pages are compared and written back. A page the title writes while
    shaders may write it keeps its bytes from before (saved by the guard on
    the first write), so both writers' bytes survive. Untracked copies and
    the host's own writes keep the snapshot path.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Tests: a machine with no GPU has no hardware adapter to check shaders on
    `main` at 42363ab is red in CI, on the same two tests, and its own fix did not
    cover it:
    
      emit::synthetic_tests::gathers_at_a_level_match_the_hardware ... FAILED
        hardware: lane 4 against its gather  left [66, 67, 35, 34]  right [65, 66, 34, 33]
      emit::synthetic_tests::permutes_read_the_lane_named_and_zero_from_lanes_left_out ... FAILED
        hardware: no pipeline for a wave of 32
    
    Both are hardware-only: the first asks the hardware for its rounding, the
    second needs a wave of 32, which WARP refuses. 42363ab refuses a default
    adapter flagged DXGI_ADAPTER_FLAG_SOFTWARE, but on the runner the default
    adapter is not flagged software and its device still refuses a wave of 32,
    so `Host::new(false)` succeeded and the "hardware" runs were not hardware.
    
    The test host now asks for an adapter that is a GPU by two signs: not flagged
    software, and with dedicated video memory of its own (WARP and the basic
    render driver report none). It walks the adapters to the first one that is,
    and fails with "no hardware adapter" when there is none, which is the skip
    these tests already know how to take.
    
    On this machine (RTX 4090 and an integrated AMD, both with dedicated memory)
    nothing changes: `cargo test -p victory-shader --locked --lib` 246 passed,
    3 ignored, and the two tests run and pass as before.
  • Tests: hardware-only shader checks skip on a machine without a GPU
    GitHub's Windows runner has no GPU, so the default adapter the shader
    tests call "hardware" was WARP. The gather test then ran its
    hardware-only rounding check on WARP, and the permute test (a wave of
    32, which WARP refuses) ran on no device; both failed every CI run.
    
    The test host now refuses a software default adapter, and the permute
    test skips when only WARP is there (a refused pipeline on hardware is
    an error).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>