Commit Graph
597 Commits
  • Shaders: 64-bit integer compares on their dwords (AMD orders a shared-dword i64 compare wrong) (#1599)
    * Shaders: 64-bit integer compares on their dwords
    
    v_cmp_{lt,le,gt,ge}_{i64,u64} lowered to one i64 icmp give the wrong
    answer on AMD's D3D12 driver when the operands share a dword: `v_cmp_lt_i64
    s20, v[1:2], v[2:3]` with v1 = v2 = 0, v3 = 1 (0 < 0x1_00000000) is false
    on an RX 9070 (32.0.32029.2010) and on a Ryzen 7700 iGPU, gfx1036
    (32.0.21045.29003), as if the dwords were swapped; WARP gets it right.
    Disjoint pairs are fine there, and so is equality.
    
    The compare now runs on the dwords: the high ones decide (signed for
    i64), equal ones leave it to the low ones (unsigned). It needs no INT64.
    The GPU test runs all twelve compares over values whose dword orders
    disagree, on disjoint and on shared registers; without the change it fails
    on the AMD hardware.
    
    Found by a cross-device fuzzer that compares single VALU instructions on
    every adapter and WARP.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    
    * Shaders: a signed 64-bit compare's literal sign-extends in the dword split too
    
    main's src64 now sign-extends the 32-bit literal of an _i64 operand
    (signed_64_bit_operands_sign_extend_their_literal). The dword compare
    read the literal's high dword as zero, so v_cmp_lt_i64 v[1:2], -100
    compared against 0x00000000_FFFFFF9C. It now takes the same high dword
    src64 would.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    
    ---------
    
    Co-authored-by: alexdeliu <240865807+alexdeliu@users.noreply.github.com>
    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
  • Input: ignore all-zero XInput slots until they report input (#1430)
    A wireless receiver with its controller switched off still answers
    XInputGetState with an all-zero state, which connected the empty slot
    and disconnected the keyboard stand-in pad.
    
    Keep each host slot disconnected until its current connection reports
    non-rest input, reset that flag on disconnect, and keep scripted
    diagnostic keys on the stand-in while no host pad has reported input.
    
    Fixes #845.
    
    Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>
  • Pipeline: accept existing entry when concurrent cache publication races on Windows (#1324)
    * Pipeline: accept existing entry when concurrent cache publication races on Windows
    
    * Pipeline: exercise the blocked Windows cache publication path
    
    Keep the published entry open without delete sharing and assert that replacement is blocked. The regression fails with the pre-fix publication code and passes with the current implementation.
    
    Validation: 5 pipeline tests passed on x86_64-pc-windows-msvc; pipeline Clippy with warnings denied and formatting checks passed.
    
    * Pipeline: adapt concurrent publication test to new tempfile_in signature
  • Shader tests: v_med3 orders -0 below +0 (f32 and f16) (#1259)
    * Shaders: v_med3 orders -0 below +0, as RDNA2 does
    
    The ISA defines v_med3_f32/v_med3_f16 over v_min_f32/v_max_f32, which order
    -0 below +0 (#448 settled those), so of three zeros the median is the sign
    two of them share; DXIL's plain FMin/FMax chain gives either zero. The zero
    the chain leaves now takes that majority's sign (11 instructions). A NaN
    still gives the minimum of the three.
    
    Noticed while porting the idea of ivall/xcl#1348 (DavidM1911).
    
    Tests: hardware execution tests in valu_tests for both operand orders and
    the halves.
    
    Written with an AI assistant.
    
    * Shaders: keep main's med3 lowering, leave only the signed-zero test
    
    main's max_min_flushed chain (77053a0c) already orders -0 below +0, so the
    majority-sign select this branch added gives the same result.
    
    ---------
    
    Co-authored-by: pgm1207 <104554896+pgm1207@users.noreply.github.com>
    Co-authored-by: pablogonz12 <pablogonz12@users.noreply.github.com>
  • GPU: no blending on integer render targets in host pipelines (#1152)
    The console ignores blending on integer render targets and the title
    leaves it on (the world has a mesh pipeline blending into an R8_UINT
    target). D3D12 does not allow it: vkd3d-proton refuses such a pipeline
    with E_INVALIDARG and its draws are lost. The host pipeline now turns
    blending off on integer targets; with one description for all targets,
    each target gets its own copy so the others keep theirs.
    
    (cherry picked from commit 169efcb84eb5d9d83c0af7fe525a54ada86f3a0d)
    
    Co-authored-by: pgm1207 <104554896+pgm1207@users.noreply.github.com>
    Co-authored-by: pablogonz12 <pablogonz12@users.noreply.github.com>
  • victory-shader: build the per-instruction read/write lists once (#1033)
    ir::build fills every instruction's register lists twice. `effects()`
    collects `Vec<Reg>` (two allocations), and the caller immediately maps
    each one into `Vec<(Reg, Value)>` (two more), freeing the first pair. For
    lists that are almost always two to four entries, that is four
    allocations and two copies per instruction, on every instruction of every
    program.
    
    Have `effects()` and its helpers collect the `(Reg, Value)` pairs
    directly, with the placeholder the SSA pass fills in. Two allocations per
    instruction instead of four; `Inst` and everything downstream are
    unchanged.
    
    Measured with the synthetic bench in #1002 (no game data), ten
    interleaved rounds per arm, nanoseconds per instruction, at 256/1k/4k/16k
    instructions:
    
      ir::build   308 -> 269, 375 -> 324, 407 -> 340, 402 -> 353  (0.835-0.878)
      translation 898 -> 872, 898 -> 825, 951 -> 875, 956 -> 912  (0.919-0.971)
    
    gfx10::decode, structure, lower and the rest are unchanged. The emitted
    DXIL is byte-identical at all four sizes.
    
    cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
    Both clippy configurations clean; cargo xtask policy ok.
    
    Co-authored-by: pes7 <pes7@users.noreply.github.com>
  • xmem: keep the space below 4 GiB for the title's 32-bit memory (#1009)
    * xmem: keep the space below 4 GiB for the title's 32-bit memory
    
    XMemVirtualAlloc with the 32-bit address flag has to fit below 4 GiB, where
    Windows also puts the host's own memory first (it allocates bottom up). With
    a large pipeline cache read at startup, the driver's, heap and cache memory
    left 22 MB there, in pieces of at most 14 MB, when Grand Theft Auto VI asked
    for a 185 MB 32-bit placeholder; the request was refused
    (ERROR_NOT_ENOUGH_MEMORY) and the title stopped at an assertion
    (+0x19f4f58). The D3D12 debug layer's memory did the same.
    
    `low_guards::install`, at the start of `run`, reserves the free space below
    4 GiB but the lowest 256 MB (left to the host). A 32-bit request that finds
    no room releases the smallest guard that fits it (else the largest) and
    tries again, then guards what is still free of it.
    
    Tested: the new test releases a guard, takes part of the hole and checks the
    rest is guarded again. In the title (RTX 2080, a build with a large cache):
    without this the startup failed 2 of 3 times; with it, 5 of 5 starts passed,
    3.7 GB below 4 GiB kept for the title.
    
    * Bound low-address allocation retries to existing guards
    
    * xmem: safety comments and formatting for the bounded guard retry
    
    ---------
    
    Co-authored-by: swarm <swarm@swarm.swarm>
    Co-authored-by: NuraadGit <NuraadGit@users.noreply.github.com>
  • GPU: a full early pipeline list drops the oldest runs' keys (#983)
    The early list keeps this run's keys first, then earlier runs' others,
    but those came from a HashSet, so once the list was full the keys that
    made room were any earlier ones, not the oldest.
    
    Earlier keys now keep their place in the list as loaded. The list is
    saved most recent run first, so sorting by that place drops the oldest
    runs' keys and keeps the order across saves. A list saved by an earlier
    build (in no order) still reads.
    
    `save` also reads the list through `used()`, so a save before anything
    read it in this run keeps the saved list instead of writing an empty one.
  • Shaders: v_mul_legacy_f32 treats denormal operands as zero (#682)
    RDNA2 flushes denormal operands of the legacy multiplies to zero, so
    0 x anything = 0 also holds for them. The lowering only tested for an exact
    float zero, whose result also depends on the host's denormal mode. Test the
    exponent bits instead. Follow-up to #2.
  • GPU: mirror placed unordered texture views (#1273)
    * GPU: mirror placed unordered texture views (#921)
    
    Resolve `View::Placed(true, ...)` texture descriptors through
    `placed_texture` to `View::Unordered` on the shared host texture for
    that memory so placed unordered texture views bind real D3D12 UAVs and
    transition to `UNORDERED_ACCESS` instead of falling back to null UAVs.
    
    Refresh an already-mirrored placed texture slot when a later unordered
    or renderable view upgrades that memory's `HostTexture`, and apply
    `alias_source` copies to explicit SRVs superseded in `MEMORY` as well
    as placed SRVs so compute writes at one guest address stay visible
    regardless of view creation order.
    
    Also resolve `DXGI_FORMAT_UNKNOWN` (`0`) view descriptions from
    `resource::view_format` when the host copy is typeless or castable, and
    check `typed_store` as well as typed-depth/typeless view exclusions in
    `fits` before creating host SRVs/UAVs.
    
    * GPU tests: dispatch a guest shader through a placed texture UAV
    
    * GPU tests: declare the placed UAV tests beside the other pipeline modules
    
    ---------
    
    Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>
  • Shaders: share and serialize WARP host operations across threads (#244)
    Fixes #181.
    
    Concurrent WARP (d3d10warp.dll) usage across threads crashes with
    0xC0000005 on Windows 11, both when creating/tearing down separate
    WARP devices and when compiling pipelines or executing work concurrently
    on a single shared WARP device.
    
    Keep one process-wide WARP ID3D12Device in Host::new (for explicit
    warp = true, VICTORY_WARP=1, and systems whose default DXGI adapter
    has DXGI_ADAPTER_FLAG_SOFTWARE) and serialize WARP root signature
    creation, pipeline compilation, draws, and dispatches behind a
    process-wide mutex. Hardware D3D12 devices remain unserialized.
    
    Route diff_tests's direct CreateRootSignature calls through
    Host::root_signature_bytes so they share the same serialization, and
    add a multi-threaded WARP regression test (parallel_warp_pipelines_and_draws).
    
    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: reuse SSA sums when tracing memory addresses (#139)
    * Shaders: reuse SSA sums when tracing memory addresses
    
    Co-Authored-By: GPT 6.2 Sol <noreply@openai.com>
    
    * Shader tests: an address from no root parameter is title memory
    
    Main reads such an address as title memory instead of refusing it.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    
    ---------
    
    Co-authored-by: GPT 6.2 Sol <noreply@openai.com>
    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
  • XAsync: run a failed call's cleanup without the completion lock (#114)
    XAsyncComplete held the call's `done` lock while the title's provider
    ran OP_CLEANUP. A cleanup that waits for a worker thread which is itself
    completing the same call (it took the call before the cleanup removed
    it) deadlocked: the worker blocks on `done`. The first completion now
    claims the call with an atomic flag and runs unlocked; the status is
    still published after the cleanup, while the block is valid, and `done`
    is set only for the waiters.
    
    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
  • Shader tests: the compute harness zeroes its UAVs
    A new committed resource is not always zeroed: on the CI's WARP the
    512 KiB mark buffer of heap_direct_texture_reads_mark_their_heap_index
    came back holding the page table an earlier test had uploaded and
    freed, so the test saw 16,389 bits besides the one the shader set.
    Buffers, root UAVs and UAV textures are now made as copy destinations
    and get zeros from an upload buffer before the dispatch.
    
    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
  • Shader: normalized buffer codes convert to the float nearest their quotient
    What was wrong: buffer and typed-buffer loads of normalized formats
    (UNORM, SNORM) converted a code by dividing it on the host. The host's
    division is not exact. On the RX 6700 XT, 125 of the 256 8-bit codes
    loaded one ulp high, and 16-bit codes such as 257, 261, ..., 32896
    loaded one ulp low; WARP was exact. The console's buffer unit gives the
    float nearest the exact quotient, and titles rely on it in decisions:
    Grand Theft Auto VI's mesh programs read a material index from a vertex
    colour's alpha as `v_mul_legacy_f32 255.0` then `v_cvt_u32_f32`. A
    quotient one ulp low truncates to the code below (the 16-bit codes above
    did), so another material is picked.
    
    What changed: for formats up to 16 bits per channel the quotient
    a / (2^n - 1) is worked out from integers: Q = floor(a * 2^32 / d) as
    a * K plus a correction (none when n divides 32), rounded to 24 bits up
    exactly when its highest dropped bit is set (the quotient is never
    exact, so never a tie), and that integer, at most 2^24 and so exact as a
    float on any host, scaled by a power of two. The reference is the exact
    quotient rounded to the nearest float, which removes the dependence on
    how the host rounds a division or converts a large integer (WARP rounds
    integers above 2^31 otherwise). Signed formats convert their magnitude
    the same way; their two lowest codes stay -1.0. The 11- and 12-bit
    widths, whose smallest codes need more bits, are rounded fully in
    integers.
    
    Cost: about 18-21 DXIL operations a channel where the division was 2 (a
    division by a constant more where n does not divide 32), so a 4-channel
    8-bit fetch is about 80 operations instead of about 12. The car body's
    mesh program grows from 4,616 to 5,103 instructions (+487 for about 23
    normalized channels). In the title it is not measurable: in a run of
    the intro cutscene with this commit (cost2, on the previous main
    4015a182), on world windows with no pipelines being made, the frame
    median was 881 ms and the GPU 349 ms a frame (median 335), against
    1,013 and 389 (365) for the same tree without it (s1a). Two runs of one
    tree have differed by 132 ms of GPU a frame, so the difference is
    within run-to-run noise.
    
    Evidence: tests `normalized_buffer_formats_load_correctly_rounded_quotients`
    (every 8- and 10-bit code and a 16-bit sample, unsigned and signed,
    bit-exact on hardware and WARP; it failed on the RX 6700 XT before, at
    8-bit code 3) and `normalized_codes_truncate_back_to_themselves` (the
    title's truncation gives every code back; 16-bit code 257 came back as
    256 before). Offline, the integer arithmetic as emitted matches the exact
    quotient for every code of every width 2 to 16.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: descriptors joined by nested control flow, again
    Brings back PR #1012's recursive heap index (taken back by fbac5bb6): 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; its heap index is
    a phi at each join of what each predecessor computes at its end. It lets
    `indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays` (39f0e9aeb156a61c,
    issued every cutscene frame) through, whose host pipeline the AMD driver
    could not make before the two commits ahead of this one.
    
    The program itself is large: 74,700 GFX10 instructions, 11,896 branches
    (488 backward), 1,889 typed buffer loads, each after a reload of the same
    descriptor. Its DXIL, and what the AMD driver (RX 6700 XT, 32.0.21045)
    does with it:
    
    | | #1012 alone | now |
    |---|---|---|
    | lines (dxc -dumpbin) | 151,610 | 24,896 |
    | branches (conditional) | 22,382 (10,040) | 3,070 (1,295) |
    | blocks | 22,384 | 3,072 |
    | heap handles | 2,608 | 65 |
    | size queries | 2,477 | 0 |
    | phis | 2,883 | 1,124 |
    | DXIL bytes | 864 K | 144 K |
    | validator | passes | passes |
    | host pipeline | over 6 GB at 64 s, never finished (26.7 GB unwatched) | 2.36-2.45 GB, 78-107 s (with other work on the machine) |
    
    What remains costly is the program's shape: one loop of 2,941 blocks
    holding 1,239 of its 1,295 conditional branches, an inner one of
    1,440 (the largest loop of the largest program by DXIL bytes,
    RTShadowTrace32TemporalHQ_OneOver4RPP_Tiled, has 110 blocks; it compiles in
    14 s, 353 MB). Making every branch uniform (an experiment) took the compile
    to 1.9 GB and 54 s, so divergence is not most of it. The pipeline library
    keeps it after the first make.
    
    WARP refuses the pipeline at once (E_INVALIDARG): the program declares the
    console's wave size (32), which WARP's 4-lane waves cannot run, as for every
    compute program that declares one.
    
    Whole list, translate --list --validate: 0 newly failing, 1 newly emitted
    and validated (this program). Test: the nested-join lowering test is back
    (`descriptors_joined_by_nested_control_flow_lower_to_one_uniform_handle`).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: barriers start from the states resources are in: prelude order, the clamp's own buffer
    The debug layer reported ~16 resource-state errors a second in the world
    on main (run light21) and with the queue order (light19), four kinds:
    
    Depth twins, and 16-bit depth textures with twins (COPY_SOURCE, UNORDERED_
    ACCESS and COMMON against DEPTH_WRITE): a list's prelude swapped each
    texture's real state for the one the list leaves before recording the
    twin copies it owed, so those copies moved the textures from the wrong
    states. The prelude now records the copies from the real states, then the
    list's moves from them, and only then stores the states the list leaves.
    
    The title's 174 MB GPU heap, bound as a vertex buffer while in UNORDERED_
    ACCESS, and barriers on it disagreeing with the state an earlier vertex
    binding promoted it to: our only transitions on a title buffer's copy were
    the indirect clamp's, UAV to INDIRECT_ARGUMENT and back to UAV. The clamp
    now reads the title's records through a root view and writes the clamped
    ones into an argument buffer of the list's own, which the execution reads;
    only that buffer is transitioned (common, unordered access, indirect
    argument, common). Title buffers' copies are never transitioned: common
    between submissions, promoted by every use, ordered by unordered-access
    barriers (the shortcut is in indirect.rs). The clamp no longer writes the
    copy of the title's memory; the capture's read-back reads the clamped
    records from the list's buffer.
    
    Tests: a transition log (every barrier built on the test thread) replayed
    in GPU order by the debug layer's rule: twin::tests::prelude_copies_start_
    from_the_real_states (fails on the old order: "before COPY_SOURCE, the
    resource is in COMMON", run light21's message) and indirect::tests::
    argument_buffers_move_from_their_current_states (two lists in either
    order; the title's copy untouched); the clamp tests now also check the
    whole title copy is as written.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: quad reads in pixel programs reach the helpers at triangle edges
    The console runs pixel programs in whole-quad mode: in every quad a
    triangle edge crosses, the pixels outside the triangle run as helpers, and
    the compiler takes derivatives of computed values (and quad reads) by
    reading the neighbour's register with DPP `quad_perm` or `ds_swizzle`. We
    lowered those reads to `WaveReadLaneAt` unless the program discards. Wave
    operations leave helper lanes out on the host, and on AMD a read of one
    gives 0: every pixel whose quad neighbour lies outside the triangle took a
    wrong derivative, along every triangle edge. WARP includes helpers in wave
    reads, so the tests passed there.
    
    Quad-local reads in pixel programs now always go through quad reads
    (`QuadReadLaneAt`), as they already did after a discard. What the host
    guarantees there: helper lanes execute the program so that derivatives
    can be taken, and quad operations include them (wave operations do not),
    so a quad read of a helper gives the value that helper computed, as the
    console's DPP read of a whole-quad-mode lane does. A discarded pixel stays
    a helper in the same way.
    
    Tests: two control-flow cases draw a triangle whose diagonal crosses
    quads (`ddx_fine`, `ddy_fine`, `QuadReadAcrossDiagonal`, `QuadReadLaneAt`
    of a computed value, console compiler against PC DXC). "derivatives and
    quad reads across a triangle edge": before, RX 6700 XT 24 of 256 texels
    differ (texel (0, 0): ddx -1 instead of 15, the helper read as 0), WARP 0;
    now 0 and 0. "discard, then derivatives and quad reads across a triangle
    edge" discards some neighbours before the reads (the path that used quad
    reads already): 0 and 0.
    
    Whole list (translate --list --validate): 3,005 pixel programs change,
    84,589 read sites (median 15 per program, at most 732); no program changes
    outcome. DXIL 1,197,299,944 -> 1,203,716,752 bytes (+0.54 %) on top of
    the writer folding (on main without it: 1,423,424,800 -> 1,429,871,224),
    blocks unchanged.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: vertex, geometry and mesh programs with UAVs say so in their flags
    Since the read marks, every vertex, geometry and mesh program that reads a
    texture from the resource heap writes the marks' UAV (the write marks do
    the same for programs writing through views), and its shader flags did not
    declare "UAVs at every stage" (ShaderFlags bit 16, SFI0 0x4): the validator
    refused 5,046 programs of the title's list with "Flags must match usage"
    (VS_OctaWindFire_e6901d4b: declared 0x40000010, actual 0x40010010). The
    runtime does not validate, so their pipelines were made, but a driver may
    trust the flags.
    
    The validator counts UAV ranges the module declares, not UAVs indexed from
    the heap: `finish` sets the flag (and the SFI0 bit) when a program that is
    neither a pixel nor a compute program declares any (root UAVs, the memory
    bitmap, the marks). Counting every handle annotated as a UAV instead set it
    wrongly for 26 mesh and vertex programs whose only UAVs come from the heap
    (`MST_DS_TerrainTransform` and others: declared 0x40092000, actual
    0x40082000).
    
    Whole list (translate --list --validate), validated: vertex and pixel
    13,313 -> 14,254 of 14,254, mesh 4,625 -> 8,694 of 8,765 (the other 71
    have outputs over 32 KB), compute 1,984 of 2,732 unchanged (748 sample
    with implicit LOD); no program newly fails.
    
    Test: `emit::shader::tests::uavs_outside_pixel_and_compute_programs_are_declared`
    (a marked vertex, pixel and compute program and a vertex program writing a
    heap-indexed UAV each pass the validator; the marked vertex program fails
    as the list's did without the flag, the heap one with it).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shader tests: the differential harness binds the view-stride table
    Since 4243a96a ("16-bit typed buffer accesses pass bits through integer
    views") a 16-bit typed buffer access reads its view's format kind from the
    host's view-stride table, root SRV `t255` (`VIEW_STRIDES`), also for views
    in tables. The differential harness asserted that a translated program's
    root views are only the case's own (slots 4 and 5), so the case "16-bit and
    64-bit arithmetic" (`RWBuffer<half4>` stores through
    `buffer_store_format_d16`) failed on its root SRV 255 before anything ran,
    in every run with the console compiler since that commit (eed16700 passes,
    4243a96a fails).
    
    `host::view_strides` builds the table as `victory_gpu` fills it for the
    harness's view heap (element sizes, the integer and signed bits of typed
    views of integer formats), and the harness binds it where a program asks.
    The case now runs and matches the console compiler's program on the RX 6700
    XT.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: one handle per descriptor at a fixed address, and per join
    The console compiler reloads a descriptor before each use rather than keep
    it (`indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays` loads table
    offset 0x640 2,399 times, once before each of its typed buffer loads), and
    lowering made a heap handle at each load: index arithmetic, for heap
    buffers the host-view guard, `createHandleFromHeap`, `annotateHandle`.
    
    A descriptor resource tracking finds at a fixed address (a table or heap
    entry, no dynamic term, not a waterfall loop's per-lane load) now gets one
    handle for the program, made in the entry block from the root parameter's
    user data. A descriptor chosen by control flow (a phi of heap indices at a
    join) gets one handle made in its join block, shared by every access the
    join dominates, instead of one per access. Read marks still go with each
    access, at the handle's index.
    
    ActivateRays (with nested joins allowed, the commit after this one):
    2,608 heap handles before the DXIL writer's folding, 674 after it, 65 with
    this. Whole list, translate --list --validate: 0 newly failing; DXIL
    bitcode 1,246,729,828 -> 1,197,299,944 (-4.0 %) bytes.
    
    Tests: `descriptors_reloaded_from_a_root_table_share_one_handle` (a
    descriptor loaded in a branch and again after it: one handle), written heap
    handles counted from the module (`Module::written_calls`).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shaders: the DXIL writer leaves out what no edge or reader reaches
    Lowering leaves much in the DXIL that never runs or counts: branches on
    constants (lane conditions structurisation already knows, edges no lane
    takes) and the code only their other edge reaches, empty blocks that only
    forward to the next, size queries for descriptor words no path reads. The
    host driver compiles all of it. `indirect_diffuse_lighting:CS_ScreenProbes_
    ActivateRays` (with nested descriptor joins, PR #1012) is where it showed:
    8,745 of its 10,040 conditional branches were on constants, 10,061 of its
    22,384 blocks empty forwarders, about 70 % of its instructions reachable only
    through constant branches' dead edges, and 556 of the 587 size queries in
    the rest unread; the AMD driver never finished it (over 6 GB at 64 s).
    
    The writer (`Module::plan`, `Module::kept`) now:
    * takes a branch on a constant as a branch to its one target: blocks only
      the other edge reaches are not written, and phis lose the entries of edges
      that are gone (their other entries stay);
    * folds an empty block with one predecessor into it (the predecessor
      branches to its target), unless it splits a critical edge (lowering keeps
      loops' exits and preheaders dedicated, as DXC emits them) or its
      predecessor would then reach the target twice (one phi entry per
      predecessor); empty latches fold as before;
    * writes only instructions with effects (stores, atomics, calls neither
      read-none nor read-only: barriers, discard, wave operations, the write and
      read marks) and what they read, transitively (it dropped only unread phis
      before);
    * declares only the functions it calls and the constant globals it reads
      (the validator refuses the others);
    * and the shader flags of heap handles, wave operations and 64-bit integers
      follow what is written (`Module::uses`; the validator refuses a flag
      whose use is gone, "Flags must match usage").
    
    Whole list (shaders.rpf, the exe, XboxBvhBuilder, the upscaler;
    translate --list --validate, against 8ff79135): 0 programs change outcome
    (14,254 VS/PS, 2,732 compute, 8,765 mesh emitted; 13,313 / 1,984 / 4,625
    validated, as before); DXIL bitcode 1,423,424,800 -> 1,246,729,828 bytes
    (-12.4 %), blocks 3,624,448 -> 3,554,816 (-1.9 %).
    
    ActivateRays itself is still refused here (nested joins); its table is in
    the commit that lets it through.
    
    Tests (`emit::bitcode`): a constant branch drops its other side and that
    side's phi entry only; a loop whose back edge is never taken; empty blocks
    before a phi fold only where the entry can move; only values with effects or
    readers are written (read-none and read-only calls, stores, atomics,
    barriers); constant globals nothing reads are left out; uses count only
    what is written. The writer's pinned
    bytes are pinned anew (its test module's last call became one with effects).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a texture refresh reads title memory into its thread's own buffer
    What was wrong: each refresh of a tracked texture read the changed
    title memory into a buffer allocated for it, the texture's whole size
    (5.6 MB for a BC7 2048), zero-filled and touched page by page: a
    zero-fill and a page fault per 4 KiB for every texture brought up
    (129,071 page faults while preparing in one frame of run placed1). The
    detile itself is not the cost: a BC7 2048 64KB_D texture detiles at
    0.04 ms per MB on this machine, as fast as a plain copy of its bytes,
    against ~2.2 ms per MB for a whole refresh.
    
    What changed: the read goes into a buffer the worker thread keeps for
    its next refresh (up to 32 MiB; larger ones are not kept). Only the
    touched spans are written, and only they are hashed and detiled, as
    before. In diagnostics builds, the scan of each texture read for all
    zeros runs only when its debug message is wanted.
    
    Evidence: the texture upload tests, which refresh several textures and
    single mips on the same threads, pass (victory-gpu 193 passed, twice).
    Run scratch1 (240 s of the intro cutscene, quiet, on the same main as
    run placed1): texture refreshes 177 ms of worker time for 98 MB a frame
    (1.8 ms per MB) against 235 ms for 105 MB (2.2 ms per MB). Its whole
    frame was slower (median 1,010 ms against 894) through GPU time (mean
    450 ms against 318) and after-work, which this change does not touch:
    one run each, run-to-run variance not separated.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: lists wait on memory values; queues hold work until its waits hold
    What was wrong: Wait32/64BitValueX were ignored and every submission ran
    when the title made it. Grand Theft Auto VI's four compute queues start
    each list with a wait for the frame's value of a word that a list on
    another queue writes at its end (Write64BitValueBottomOfPipeX), and some
    lists wait again after their first commands. Run light17's trace, one world
    frame (F = the frame counter, all comparisons GREATER_EQUAL):
    
      compute lists (kind 2), 22 queue submissions of one list each:
        wait [0xd0417fe00 + 16k] >= F at the start, write [+8] = F at the end
        (0xd0417fe00 .. 0xd04180070); the depth-processing list
        [w fe10][HBO dispatch, barrier][write fe18 at its end][w fe68, fee8]...
      graphics lists (kind 0) of 32-33-list submissions wait on words the
        compute lists write (list 1 after 7-8 commands for [0xd0417ff80],
        lists 3, 5, 7, ... at their start for [..ff90], [..ffa0], [..ffb0])
    
    So CS_DepthProcessingHBO ran before the character G-buffer it reads, and
    CS_MaterialTilesInitial classified the head and hair as sky: the white-grey
    hair blob, faces dark or patched, the erased building bodies, the black
    shards in the sky and part of the skin's leopard patches.
    
    What changed: a wait recorded after commands cuts the title list into a
    new host list (`list::wait`, `State::cut` replays the fixed-function state
    and lets the next draw rebind the rest); each queue keeps a FIFO of list
    segments, Signals and fence Waits (`hold.rs`). The pump runs a queue's
    head once its waits hold, consecutive runnable segments as one host
    submission (a piece, its own submission for refreshes, marks, withholding
    and copy-back), and tests every queue again after each piece until none
    can move. Order within a queue never changes, only the interleaving across
    queues. A queue Signal behind held work is delivered after it (its fence
    is kept alive meanwhile); CPU fence Signals, GetCompletedValue and
    SetEventOnCompletion, PresentX, every submission and a 2 ms timer (values
    the title writes from the CPU) pump. D3D12 lets a list be reset as soon as
    it is submitted, which the title does up to 21 times a frame while its
    work is held: the held part keeps its own host list, its title list's draw
    state (dynamic descriptor slots, title-memory page table) and 0x4a0
    memory, freed after it ran; host lists back from a queue are reused.
    Counted shortcuts (`shortcut:`): a head held 10 s runs anyway (valve);
    an unknown comparison holds; CopyPageMappingsBatchX and PresentX do not
    wait behind held work. The frame line (when work waited or is held):
    submissions, pieces, segments, cuts, early resets, segments that waited
    and what released them, the pump's own time, the title's fence-event
    waits, what is held at the present with the unmet waits.
    
    Evidence: run light18 (240 s, survived): per world frame 16-42 title
    submissions, pieces = submissions + 1, 188-266 segments, 0-11 cuts, 5-10
    segments waited (55-1060 ms, every one released by a later submission);
    held at the present 0, valve 0, unknown comparisons 0, page mappings with
    work held 0. Hair whole against the sky, buildings whole, sky clean, skin
    clean, every face present and lit (13 faces in 8 close shots; act3 2700,
    without this, has a dark patch over the same woman's face). light19 (the
    debug layer, 240 s; median per world frame 30 submissions, 31 pieces,
    236 segments, 9 waited; pump 1.1 ms a frame; no fence event left
    pending) and light20 (240 s, with the stale-upload fix now in main: 30,
    31, 241, 9; pump 1.8 ms) survived; held at the present, valve, unknown
    comparisons and page mappings with work held 0 in all three. The debug
    layer's resource-state errors of light19 are on main alone too (light21,
    same kinds and rate): not from the new order.
    Tests: hold::tests (comparisons, a wait across queues, a wait that holds
    defers nothing, chained waits across two queues, order kept, a Signal
    after held work, a fence wait, work held at the frame's end, unknown
    comparisons, the valve) and the GPU test
    resource::tests::a_list_waiting_for_another_queues_write_reads_what_it_wrote
    (a compute list cut at its wait and reset while held reads back the plain
    texture the graphics list fills, as that list left it; on the old code it
    reads zeros).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: textures fed from title memory are placed in heaps made ahead
    What was wrong: every host texture was a committed resource, made one
    by one. A new shot brings hundreds of textures at once (the placed
    textures of slots shaders read for the first time, made after the
    submission), and making them took most of the copying-back phase:
    windows that made 337 / 134 / 110 MB of placed textures a frame spent
    351 / 926 / 300 ms there (run shots2). Measured on the RX 6700 XT, 300
    textures of a new shot's sizes (430 MB): committed 255 ms (not zeroed:
    274 ms); one heap 32 ms, then placed 3 ms.
    
    What changed: textures without render-target, depth, unordered-access
    or simultaneous use, up to 16 MiB, are placed in 64 MiB heaps (default
    heaps for textures that are neither render targets nor depth), first
    fit, with castable formats through `CreatePlacedResource2` as the
    committed path uses `CreateCommittedResource3`; others stay committed,
    and so does a texture whose placement the host refuses. A texture's
    range is free again only once nothing else holds its resource (views'
    slots keep it until the running submission has run, lists until they
    are reset), checked at each placement and eviction pass; empty heaps
    past two are released. The eviction budget counts free heap space as
    unused. A texture whose memory is not committed when first read gets
    zeros, as a committed one starts (a placed one starts with what its
    range held); every other first refresh already uploads every
    subresource. The host-textures statistics line gives the heaps held
    and their used and free bytes.
    
    Evidence: tests `placement::tests::ranges_are_taken_first_fit_and_joined_when_given_back`
    and `a_range_is_reused_only_once_nothing_holds_its_texture`; the
    texture upload tests, whose textures are now placed, pass (victory-gpu
    182 passed, twice). Run placed1 (240 s of the intro cutscene, quiet,
    on main with the narrower withholding of 0a5be3c7 and the host-write
    fix): making the read slots' textures 23 ms a frame (median 12; the
    largest new shots 406 / 568 / 871 slots in 107 / 68 / 43 ms), against
    up to 926 ms before; copying back 109 ms against 223 (run shots2);
    world frame median 894 ms against 964. The whole-frame gain shares its
    main with the withholding change; the read-slot part is placement's
    alone. No device removal, no stale texels seen.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a texture a host copy writes is the host's from the copy's submission
    What was wrong: `texture::host_written` marked a texture as written by
    the host (a copy, copy-region or resolve into it) when the list holding
    the copy was recorded, and textures read through tables were checked
    only then, by `texture::upload` at record time. A list recorded before
    the writer but submitted after it kept its upload due: its submission
    uploaded title memory over the texels the host copy had written.
    Submissions need not run in the order their lists were recorded
    (`light` is changing the order to the title's own waits between
    queues), so this decision belongs to the submission.
    
    What changed: `texture::host_writes(list, resource)` marks the texture
    from the submission that runs the writing list (a deferred host step),
    and the submission's upload gathering skips table-read textures so
    marked, as the heap path already did. A reader submitted before the
    writer still gets its upload; one submitted after keeps the host's
    texels.
    
    Evidence: test `draw::tests::a_list_run_after_a_host_write_keeps_the_host_texels`
    (a reader recorded, title memory written, a later-recorded writer
    submitted first, then the reader: the host's texels stay). Without the
    submission-time check it fails (the title's new bytes, 0.502, uploaded
    over 0.251). victory-gpu tests 179 passed; workspace clippy clean.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: only what programs using title memory write is withheld when their list misses
    A list in which a program using title memory read or wrote memory with no
    copy had every range its shaders declared withheld from title memory (and,
    since ec9e750e, dropped from the host copies right after the submission),
    whichever program declared it. The BVH builder's list also holds ordinary
    programs (run light13, one list: ~1,000 builder dispatches beside
    billboard_nobump:CS_ComputeImposterTransform x250, CSGenerateHairVB/IB,
    bvh_skinning, CS_InstanceRotationFixup), so their output never reached title
    memory and, after the drop, never reached the frame's later draws either.
    
    Now each declared range records whether its program uses title memory (the
    draw or dispatch being bound, `HostList::writer_uses_memory`), and only
    those ranges are withheld when their list misses. Other programs write
    through bounded views from their own inputs: their ranges go back as before
    the withholding. An ordinary range overlapping a withheld range of the same
    copy is withheld with it, since its copy-back would take the other's bytes
    along.
    
    Test: host::withholding::only_programs_using_title_memory_are_withheld (a
    missing list with an ordinary write, a title-memory program's write and an
    overlapping ordinary write; fails with the whole list withheld).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a submission's texture uploads become readable in one barrier batch
    What was wrong: the upload list a submission runs first recorded, for
    each texture it brought up, the copies and then that texture's barrier
    back to shader reads, so every barrier sat between one texture's copies
    and the next one's. In a new shot the list holds hundreds of textures
    (154 MB a frame in run shots1), and each barrier kept the GPU from
    overlapping the copies around it.
    
    What changed: record_upload returns the barrier instead of recording
    it, and the upload list records all of them in one call after the last
    copy.
    
    Evidence: textures_uploaded_together_each_read_their_own_bytes (two
    textures uploaded by one submission each read their own bytes) and the
    other upload tests pass. Measured together with the staging chunks (run
    shots2, 240 s of the intro cutscene, quiet): world frame median 964 ms
    against 1,169 ms without the two (run shots1); GPU 313 ms against 351.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: the textures of slots shaders read are made several at a time
    What was wrong: after a submission, the placed textures of heap slots its
    shaders read for the first time were made one after the other on the
    submitting thread, and `texture_at` held its map's lock while making
    each host texture: in a new shot, hundreds of committed textures, 7 % of
    the submitting thread (run evict5).
    
    What changed: `texture_at` makes the host texture after letting go of its
    map's lock, and the read slots' placed textures are made on up to four
    threads (a quarter of the CPUs), with the helper the texture refreshes
    use.
    
    Evidence: test `resource::tests::placed_textures_made_side_by_side_are_one_each`
    (four threads asking for four memories: one resource and one host
    texture each) and `descriptor::host::tests::views_written_while_read_slots_get_their_textures_do_not_wait`;
    the crate's tests twice with 8 threads.
    
    Measured alone (run shots1: main 8ff79135 and this commit, 240 s of the
    intro cutscene, quiet): world frame median 1,169 ms against 1,206 ms
    before (run evict6), preparing 706 ms against 709: a small gain; the
    staging chunks and the barrier batch carry the rest (run shots2).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: textures' staging space is carved from large upload buffers
    What was wrong: each texture brought up took a staging buffer of its own
    size class from a pool, and the pool's free buffers rarely fit a new
    shot's sizes: making upload buffers was 10 % of the submitting thread
    in a new shot (run evict5), one committed resource per texture.
    
    What changed: staging space up to 32 MiB is carved, front to back, from
    32 MiB upload buffers, 512-byte aligned as texture copies need; the
    copies read their footprints at that offset. The chunks are rewound at
    each submission (the last one has run, as for the pool) and 16 are kept.
    Larger textures keep a buffer of their own from the pool.
    
    Evidence: test `draw::tests::textures_uploaded_together_each_read_their_own_bytes`
    (two textures brought up in one submission, the second at an offset in
    the same chunk, each read back with its own bytes) and the upload tests;
    the crate's tests twice with 8 threads (a timing test of frame waits,
    `frame::tests::waits_end_on_ticks_and_count_frames`, failed once while a
    title run loaded the machine, and passed in the other run).
    
    Measured together with the upload barrier batch (next commits' run
    shots2, 240 s of the intro cutscene, quiet): world frame median 964 ms
    (mean 1,038) against 1,169 ms with only the parallel creation (run
    shots1) and 1,206 ms before (run evict6); preparing 497 ms against 706;
    texture refreshes 264 ms for 135 MB a frame against 745 ms for 154 MB.
    The two were not measured apart.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shader: rectangles complete opposite their right angle, wherever it is
    A console rectangle list gives three corners per rectangle and the
    hardware adds the fourth opposite the right angle. The geometry shader
    that completes them on the host (and the CPU expansion used without it)
    took the right angle to be at v1, as the blits give it (top left, bottom
    left, bottom right). The tiled lighting's vertex shader
    (VS_TiledLighting, 3 vertices per tile: corner c = vertex % 3 at x + bit
    1, y + bit 0) gives top left, bottom left, top right, the right angle at
    v0, so every lighting tile drew its upper-left half and the lower-right
    half of the tile above: tiles whose neighbour below was in another list
    lost their lower-right half and lit the one above, the right-triangle
    wedges along silhouettes and kerbs of runs shards22 (frames 1603, 1615,
    1627; their depth is clean there).
    
    Now the right angle is the corner opposite the longest side
    (`emit::right_angle`, ties and NaN keep v1), the fourth corner is
    va + vb - vc and the second triangle (va, vb, v3), turning as the first
    for any three points; the CPU expansion takes the same rule from the
    first float element of two or more components.
    
    Tests: emit::rect::rule_tests::right_angles_are_found_in_any_order;
    emit::rect::tests::rectangles_get_their_fourth_corner draws the three
    orders (and three points on a line, which draw nothing) on hardware and
    WARP, and fails with the old rule; primitive::tests::
    rectangles_complete_opposite_their_right_angle.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: what a submission that missed title memory withheld leaves the copies at once
    What lists using title memory write while the frame withholds stays in the
    host copies until the frame's end: through the page table, through root
    views (byte for byte) and through marked views. When a list of the
    submission read or wrote memory with no copy, those results are garbage
    computed from zeros (BVH builder nodes: +-inf bounds, 0xffffffff, rising u16
    pairs), and later submissions of the same frame read them from the copies:
    in run shards20 the meshlet culling read such bytes in its per-batch meshlet
    buffers (stale copies with no title-side event after their take; 95.59 % of
    the batches walked equal to title memory). Now what such a submission
    withheld counts as changed in every buffer copy holding it right after it
    completes (`drop_withheld`, which takes the place of `drop_at_frame_end`),
    so the next submission's refresh takes it from title memory again. What
    submissions that missed nothing withheld keeps the frame-end retake.
    
    Run shards21 (29210929 + the page-table part alone + branch-only
    diagnostics, same listing as shards20): one list per world frame wrote
    through the page table, every one missed and was retaken at once (34-19,446
    pages); stale copies written through the page table are gone, 98.12 % of
    13,509 batches walked equal title memory. Every sampled stale batch left
    was last written through a declared, unmarked view with no retake after it
    (the builder's root UAVs, which the page-table path leaves to the
    byte-for-byte path), hence the root and marked views here too.
    
    Test: memory::tests::a_submission_that_missed_leaves_the_copies_at_once
    (a write through the page table beside a miss; fails before the change: the
    next submission reads the write instead of title memory's bytes).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: textures are brought up outside the heaps' locks, several at a time
    What was wrong: at each submission the textures to bring up were read
    from title memory, detiled into staging buffers and copied one after the
    other on the submitting thread, while the heaps' view registry stayed
    locked: in a new shot that was about a third of the submitting thread
    (reading memory 19 %, making staging buffers 10 %, detiling 6 %, run
    evict5), frames grew 6-10 ms per MB uploaded, and title threads setting
    views waited on the lock throughout.
    
    What changed: what to bring up is collected under the heaps' locks, then
    refreshed without them on up to four threads (a quarter of the CPUs),
    those whose trackers are clean skipped, then recorded. Staging buffers
    come in powers of two (at least 64 KiB), so a buffer serves other sizes,
    and are made without the pool's lock. The tracker still decides the
    bytes: its pages are taken (and guarded) before they are read, so a
    title write during the read or detile marks them again and the next
    refresh brings them up (`watch::tests::writes_mark_every_tracker_of_their_page`).
    
    Evidence: tests `host::tests::heap_textures_brought_up_together_each_get_their_upload`
    (six textures refreshed side by side, each uploaded once, none again
    when unchanged) and the upload tests; the crate's tests three times with
    8 threads.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: what a view needs is made before its slot's lock is taken
    What was wrong: making a heap slot's view held the heap's slot lock
    throughout, including making the texture it views (on first use) or the
    host copy of the buffer memory it views: title threads binding views for
    draws and writing views waited on that lock (119 of 307 samples of title
    threads in our code, run evict5).
    
    What changed: a slot whose view is unchanged is answered under the lock
    as before. One to make again releases the lock, makes what the view needs
    without it, takes it again and, if the slot still holds the record it
    prepared for, makes the view (cheap now); if the title wrote another
    record there meanwhile, that record is made instead.
    
    Evidence: tests `descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait`
    (a thread binds a view while another slot's texture is made, bounded
    wait) and `a_slot_rewritten_while_its_view_is_prepared_views_the_new_record`
    (the title writes another record into the slot during the prepare; the
    slot views the new record's texture); the crate's tests three times with
    8 threads.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a texture's refresh asks its tracker's clean bit before taking its pages
    What was wrong: textures the heaps view are refreshed at every submission
    where the title used them lately: 123,000 refreshes a frame (run evict3),
    each taking its tracker's lock to find, almost always, nothing changed.
    
    What changed: a refresh of a tracked texture first reads the tracker's
    dense clean bit, which needs no lock, and stops there if it is clean.
    
    Evidence: the upload tests (`draw::tests::a_texture_is_uploaded_once_per_submission_and_only_when_written`,
    `a_texture_owning_its_pages_is_uploaded_on_any_write`,
    `a_write_into_one_mip_uploads_that_mip_alone`); the crate's tests twice
    with 8 threads.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: a slot the title rewrites keeps no per-texture list of slots
    What was wrong: every slot the title rewrote updated a map from each host
    texture to the slots viewing it (for giving textures up), searching the
    texture's whole list to take the slot out. A texture viewed in thousands
    of slots made each rewrite cost ~25 us; the title rewrites ~62,000 slots
    a frame (it copies per-draw descriptor tables into its heap), so heap
    syncs took 0.6-2.9 s a frame and held the heaps' lock that title threads
    writing views wait on (run evict3: 62,208 stale slots a frame at 25.7 us
    each, 16 us rising to 34 us as the lists grew).
    
    What changed: no map; giving textures up walks the heap's slots once per
    pass that gives any up.
    
    Evidence: tests `descriptor::host::tests::a_slot_viewing_a_texture_given_up_is_made_again_when_read`
    and the eviction tests; the crate's tests twice with 8 threads.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: textures for heap slots shaders read are made outside the heaps' lock
    What was wrong: after each submission, the views of heap slots shaders
    read for the first time (read marks) were made under `SHADER_HEAPS`,
    which every title thread writing a view takes: making a placed texture
    (its resource and host texture) took up to milliseconds each, and title
    threads waited 1-6 s a frame to write views (runs evict2, noevict1; main
    0.2-0.3 s).
    
    What changed: the slots are looked up under the lock, the placed textures
    they view are made without it (they are never released, so they outlive
    it), and the lock is taken again only to make the views.
    
    Evidence: test `descriptor::host::tests::views_written_while_read_slots_get_their_textures_do_not_wait`
    (another thread writes a view while a read slot's texture is being made
    and finishes within a bounded wait); the crate's tests twice with 8
    threads.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: textures the heaps view are brought up to date only when shaders read them lately
    What was wrong: at every submission (about 30 a frame), every texture any
    heap slot of a heap-indexing list viewed was brought up to date: its
    staging refreshed and, where its pages had changed, detiled and uploaded,
    read or not. With placed textures made when read (4-8k textures, 5-8 GB
    viewed by the heaps) that re-uploaded about 4 GB in 30-46 world frames
    and took 0.3-3.7 s a frame (runs evict2, noevict1; main 5-25 ms).
    
    What changed: a heap-viewed texture is brought up only if the title used
    it in this presented frame or the last (made then, named by one of its
    lists, or read through the heap as the eviction pass's stamps found).
    Textures lists read through tables keep their own rule (the list names
    them). Uploads of heap-viewed textures are counted with the others.
    shortcut: a texture read again after a gap is brought up after the
    submission that read it, which can see bytes one refresh old.
    
    Evidence: test `host::tests::heap_textures_unread_lately_are_not_brought_up`
    (a viewed texture whose pages changed is not uploaded while not read
    lately; stamped as read, it is); the crate's tests twice with 8 threads.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: host textures fed from title memory are given up when unused, and past the card's budget
    What was wrong: a host texture, once made, lived as long as its title
    texture; placed textures (made when shaders read them) for the whole run.
    The title views far more textures than one frame reads (8.4-8.9 GB of
    placed textures left null in run textures1), so making them as they are
    read only grows video memory until the card pages or the process runs
    out of commit (30.8-32.2 GB with the read marks alone).
    
    What changed: a title texture's host texture can be given up and made
    again on its next use (the owner is a resettable slot; host copies are
    returned owned). Host textures fed from title memory (no render target,
    depth or unordered access, nothing written by host copies) carry use
    stamps: a list of the title's naming them (tables, copies; our own
    upload lists do not stamp), and, at each pass, every read mark set since
    the last pass on a heap slot viewing them (the marks are then cleared; a
    slot's read is reported as new only once, so stamping on the first read
    alone gave up textures read every frame: run evict1 gave up and made
    again hundreds a frame). Once per presented frame, before a submission,
    those unused for 120 s and 300 presented frames are given up (shorter
    idle times gave up textures read again within a minute, runs evict2 to
    evict4), and past 90 % of the card's budget the least recently used
    others until 85 %. Giving one up first gives every heap slot viewing it
    a null view of its kind (retired until the running submission has run;
    the record stays noted, so heap syncs pass it by and a draw's or shader's
    read makes it again), then the title textures let go of it; lists
    recorded before hold it until they are reset, so no GPU work reads it
    freed. The next use makes it again from title memory (a fresh upload).
    Uploads of heap-viewed textures skip those not made. GPU-written
    textures are never given up; they go with their title texture. The cap
    on placed texture bytes is gone (the budget bounds video memory instead).
    
    Measured, 240 s of the intro cutscene each. With giving up (run evict2)
    against without (noevict1, the same tree with the pass off): card memory
    flat at 7.6-9.5 GB against 6.4 GB rising to 10.4 GB (86 % of the budget)
    at the end; host textures 6.1-7.8 GB against 5.2 GB rising to 8.6 GB;
    process commit 26.2 GB against 27.7 GB on average (29.7 GB and rising at
    the end). With the rest of its stack (run evict6) against main (perf13):
    median world frame 1,206 ms against 475 ms; frames uploading under 50 MB
    of textures 559 ms (+18 %, run evict4); a new shot's uploads cost 3-4 ms
    of frame per MB.
    
    Evidence: tests `host::tests::textures_read_every_frame_stay_and_title_lists_stamp_theirs`,
    `host::tests::heap_reads_since_the_last_pass_name_their_textures`,
    `draw::tests::a_texture_given_up_is_made_again_with_its_bytes_and_recorded_lists_keep_it`,
    `descriptor::host::tests::a_slot_viewing_a_texture_given_up_is_made_again_when_read`,
    `resource::tests::only_textures_fed_from_title_memory_are_given_up` and
    `resource::tests::idle_textures_go_and_past_the_budget_the_least_recently_used`;
    the crate's tests three times with 8 threads.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shader: the read-mark test's doc comment is no list
    Clippy (doc_lazy_continuation) took the wrapped "1." for a list item.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • GPU: read marks are taken from both written-page bitmaps
    What was wrong: shaders that use title memory got a bitmap of their own
    (the withholding rule), but `take_reads` still read one bitmap through
    `bitmap()`, which no longer exists: the stack did not compile, and
    reading only one bitmap would lose the reads those shaders mark.
    
    What changed: `take_reads` ORs the read-mark words of both bitmaps and
    clears a forgotten slot's mark in both.
    
    Evidence: test `host::tests::read_marks_of_both_bitmaps_are_taken` (a
    read marked in each bitmap is taken, each once; a forgotten slot's mark
    is cleared and its next read taken again).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Shader: read marks only for texture views taken from the heap itself
    Every image instruction reading a texture view from the resource heap
    loaded the read-marks bitmap word (system memory) after it, tables
    included. A view read through a table cannot be a slot left null: the
    host makes table slots for the draw. Marks are now emitted only where the
    program takes the descriptor from the heap itself.
    
    Test: `heap_direct_texture_reads_mark_their_heap_index` (a table read
    marks nothing, a heap-direct read sets exactly its slot's bit).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>