Merge candidate: triaged ready-to-merge PRs built and tested together (draft, in progress) #3327

Open
github-bot wants to merge 284 commits from github-bot/gh-3327 into main AGit
Owner

@⁠pes7 on GitHub · 2026-11-26 18:16 UTC · original
pes7:merge/best-2026-11-26 → main · +12235 −2362 · 78 files · 284 commits · draft

Draft, work in progress. A merge candidate: main plus the open pull requests that a triage marked ready to merge, merged together, built and tested together, conflicts between them resolved by hand. Posted so others can see the merge work and not repeat it; coordination in #1633.

Nothing here closes or replaces any pull request: each one stays open and is closed only when it lands in main. This PR is not meant to be merged as is; it shows which set works together and which pull requests need a rebase.

How the set was chosen

1 494 open pull requests (26.11) → 1 004 mergeable into main, with a green check, not drafts → 968 touching code. Left out: diagnostics and opt-in switches, benchmarks, CI, README/CLI, Wine/Linux-only, stacked pull requests, more than 600 changed lines or 6 files, known duplicates, build-profile changes. The rest scored on: a correctness/crash/performance fix, its author already merged upstream, small, has tests. 134 picked, merged oldest first after ours.

Unlike the Forge train (#1624, every PR that merges and passes cargo check), this is a triaged subset, and each step runs clippy and the full test suite, plus the title itself.

Status (base 63bcca43c)

merged cleanly 97 (this branch, merge/best-2026-11-26)
merged with conflicts resolved by hand 18 more on merge/pass2, not yet built
already covered by a merged PR 2
need a rebase (semantic conflicts) 17

Checked locally on Windows for this branch:

  • cargo build --release --workspace: ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: ok
  • cargo test --workspace --locked --no-fail-fast: 30 test binaries, 1 019 passed, 0 failed, 10 ignored
  • the title (diagnostics build, Series X, Enter only): reaches the first playable scene with a correct picture, no device removal; frame-time A/B against the #2936 branch build is running, numbers to follow.

Two commits of mine on top, both needed by the set, not by any single PR:

  • the per-translation library check (#2706) looks for the sharded library of #1653 (the two did not build together);
  • lower.rs grows past the 512 KiB asset policy with the set (520 563 → 544 760 bytes), so its tests move to lower_tests.rs, as #3097 does (#3097 itself conflicts with the set).

In this branch (97)

  • #2634 victory-gpu: say once, not per slot, that the title's heap outgrew the host's (first frame 21 s -> 33 ms)
  • #2696 victory-gpu: VICTORY_SKIP_PIPELINES works in release builds, where the removals are
  • #2683 victory-shader: clamp heap indices to the largest heap a host can make (no descriptor read past the heap)
  • #1623 gfx10: keep an instruction's words inline instead of in a heap vector (decode -18..-45%, translation -1..-5%)
  • #1734 victory-shader: make the test dispatches cheap - an event wait and reused command objects (emit suite -33% wall, -48% CPU)
  • #2848 victory-gpu: take per-frame allocations, locks and system calls off the frame paths (7 places the profile points at)
  • #1653 victory-gpu: split the pipeline library into shards so a save writes only what changed (was 600 MB per save)
  • #2706 victory-gpu: keep a pipeline library per translation, not one shared one (a translator edit destroyed a 926 MB / 7.5 min cache)
  • #3295 victory-gpu: a copy of title memory in video memory, prepared and tested
  • #2936 victory-gpu: 16-bit packed colour widens for the host (the second crash between the account screen and gameplay), and the two tools it took
  • #324 fix(pe): detect incomplete TLS callback arrays
  • #379 Shaders: lower v_div_fixup_f16
  • #477 Shaders: fix DXIL validator UB on null error blobs, unchecked GetStatus, and COM/DLL handle leaks
  • #590 HLE: reject duplicate blob changes in one save update
  • #1123 Validate XGameSave blob count before reading
  • #1194 HLE: extract installed_package and add focused xstore license/package tests
  • #1196 HLE: fix self-closing XML element body parsing in runtime.rs and add unit tests
  • #1253 Shaders: ignore pre-loop table loads when proving waterfall offsets
  • #1263 Shader: the loop limit switch works in every build
  • #1327 Shaders: apply bitwise modifiers to v_cmp_class_f32 source operands
  • #1540 Shaders: guard both back edges when a conditional branch targets two …
  • #1543 GPU: avoid shift and arithmetic overflow panics in subresource and copyable_footprints (victory-gpu)
  • #1564 GPU: MakeResident succeeds, as the console's memory is always resident
  • #1621 Shaders: bound the bytes one part's native blobs unpack to and hand out
  • #1787 GPU: textures drop unordered access in formats the host cannot write (NVIDIA B5G5R5A1)
  • #1827 HLE: enumerate the current installation for XPackageKind::Game
  • #1859 GPU: reject overflowing and non-buffer descriptor spans before shadow…
  • #1944 Shaders: reject a dxbc part inside the header or part table
  • #1993 GPU: hash DXIL shader slices zero-copy in HostPipeline::new
  • #2037 Shaders: byte and half format loads at a constant offset load the aligned dword directly (NVIDIA)
  • #2063 Shaders: lower s_ff0_i32_b32 and s_ff0_i32_b64 in pure 32-bit DXIL
  • #2070 Shaders: refuse the image instructions DXIL has no form of
  • #2077 Shaders: lower s_sext_i32_i8 and s_sext_i32_i16 in pure 32-bit DXIL
  • #2083 Shaders: lower s_bitreplicate_b64_b32 in pure 32-bit DXIL
  • #2111 GPU: the frame's wait for pipelines is one budget for all recording threads
  • #2122 Shaders: query a buffer's size through a handle of its own
  • #2141 HLE: registry lookups through kernelbase.dll reach the device-type overrides
  • #2150 Shaders: one instruction for one value (13.5 % fewer emitted instructions, no program lost)
  • #2184 xmem: 32-bit XMemAllocDefault blocks get the alignment they ask for
  • #2224 GPU: validate execute_indirect buffer offsets against buffer bounds and u64 overflow
  • #2229 Shaders: v_pk_fmac_f16 with DPP reads src0 from the selected lane
  • #2240 GPU: title memory copies are brought up to date again after a title write
  • #2254 Shaders: v_mad_i64_i32 sign-extends a 32-bit literal addend
  • #2269 GPU: marks in the last dword of the written-pages bitmap are not discarded
  • #2274 GPU: aliased textures copy only the subresources that have the same bytes per row
  • #2276 GPU: a depth texture used before it got a twin is copied to the twin in the list
  • #2278 GPU: a plain heap description is not read past its 16 bytes without checking they are mapped
  • #2295 GPU: the fifth dword of a root constants parameter is read as a constant
  • #2299 GPU: harden CopyMemoryToMemoryX against unmapped or read-only pages
  • #2303 GPU: page mapping copies wait for the submission that is running
  • #2361 Shaders: lower SOP2 s_pack_{ll,lh,hh}_b32_b16 (#815)
  • #2404 XG: preserve packed mip swizzle/positions and fix array subresource tiling (fixes issue 2400)
  • #2444 HLE: keep refilling XMA PCM buffer across zero-sample decode steps
  • #2445 Loader: clamp VEH instruction reads to the faulting page in emulate_amd_only and sse4a
  • #2450 Shader: check device removal before FMad readback
  • #2476 Discover shaders and pipeline packs through file symlinks
  • #2501 Shaders: a BVH node offset from a root descriptor is computed in 64 bits
  • #2504 HLE: physical-page writes open the title's views before they write
  • #2515 Shaders: VOP3 f16 interpolation attr63.w is not a 32-bit literal
  • #2553 HLE: avoid data race in DirectStorage late page-list polling
  • #2554 Loader: guard null C++ exception pointers in crash::thrown and Rsp overflow/alignment in unwind_into
  • #2576 GPU: read marks of slots forgotten before a submission are cleared before it runs
  • #2598 GPU: giving up a texture leaves the dynamic slots of recorded lists alone
  • #2622 Shaders: a constant branch through a folded block drops its untaken phi entry
  • #2630 PE: refuse a tls directory that runs outside the image
  • #2639 GPU: texture bytes off the runtime's memory are read at each refresh, as buffer copies' are (#2638)
  • #2677 App: keep run paths stable when the title changes directory
  • #2724 Shaders: texture reads at a computed table entry keep their read mark (#2722)
  • #2727 GPU: reject overflowing rectangle vertex ranges
  • #2776 shader: lower non-sum wave prefix operations to DXIL
  • #2831 Shaders: dwords read from the first lane outside a waterfall's own reads are one lane's (#2829)
  • #2869 Shaders: a buffer descriptor made raw from first-lane reads needs its waterfall (#2867)
  • #2882 GPU: heaps are bound again after a cut when ours stand in for both kinds (#2881)
  • #2886 Shaders: preserve round mode changes in whole-wave sections
  • #2893 Shaders: find the normalized load rounding shift with one bit scan
  • #2896 GPU: a list that binds no view heap gets ours before the root signature (#2894)
  • #2924 Shaders: reuse source-lane activity ballots
  • #2954 Shaders: lower v_bfe_u32/v_bfe_i32 to one Ubfe/Ibfe
  • #2980 GPU: a panic while making a host pipeline refuses it instead of ending the worker
  • #3005 GPU: make already-used pipeline lookups read-only
  • #3007 Shaders: lower the 32-bit mul_hi forms to one UMul/IMul
  • #3084 GPU: wait for queued presentation before resizing the swap chain
  • #3092 Loader: keep concurrent crash records whole
  • #3098 GPU: reject truncated or corrupted shader refusal entries
  • #3131 Game: fix stencil write-mask reachability for NEVER/ALWAYS funcs
  • #3141 GPU: flush queued segments before evaluating memory and fence waits
  • #3195 HLE: keep async status waits attached through provider cleanup
  • #3221 fix(shader): preserve signed zero when f32 div:2 underflows
  • #3243 Loader: skip DIR64 relocation addresses that overflow u32
  • #3245 GPU: return pinned HostTexture from alias_source to avoid source Release UAF
  • #3248 GPU: preparing a view heap's page table scans the change tracker a word at a time
  • #3257 GPU: fix PresentX subresource copy and plane format handling
  • #3266 GPU: back off texture heap growth after out-of-memory
  • #3272 HLE: wait for in-flight lifecycle callbacks on unregister
  • #3280 Fix issue 2412: reject out-of-range export addresses in parse_exports
  • #3309 formats: guard XMA Bits::read and Bits::signed against shift overflow
  • #3316 Shaders: decode fixed 4-VGPR data and 4-SGPR rsrc for image_bvh_intersect_ray

Conflicts resolved on merge/pass2 (18, building next)

  • #1565 GPU: Evict succeeds, as the console's memory is never evicted (with #1564)
  • #1566 GPU: SetStablePowerState is accepted and ignored (with #1564)
  • #2272 GPU: a page a copy holds in part is taken after its marked copy-back (with #2269)
  • #2297 GPU: a texture sampled before an in-list title memory copy is uploaded again after it (with #2276)
  • #2415 GPU: remapping one mapping of aliased pages leaves the others guarded (with #2269)
  • #2437 GPU: a marked copy-back advances the snapshot of declared ranges over its page (with #2269)
  • #2474 GPU: refreshes of two parts of one page do not make it current whole (with #2240)
  • #2296 GPU: rectangle vertices are read from title memory through the kernel at submission (with #2295)
  • #2329 GPU: a list that binds a heap's view-address table keeps it until reset (with #2295)
  • #1668 Shaders: read inline floats as f32 bits in 16-bit integer ops (with #1327)
  • #1685 Shaders: lower v_cmp_{f,t}_{i64,u64} constant 64-bit compares (with #1327)
  • #2792 fix(shader): allow untracked scalar lane masks in v_cndmask_b32 (with #1327)
  • #2915 Shaders: f16 results ignore their output modifier, as RDNA2 does with half denormals kept (with #1327)
  • #2457 Shaders: return zero for unused image_get_resinfo extents (with #1253)
  • #2587 Shaders: bind a zero dword for empty root-constant slices (with #2515)
  • #2774 Shaders: validate raw fixtures and signed MAD64 with full-word regression (with #2254)
  • #2953 Shaders: lower binary64 division fixup in DXIL (with #2936)
  • #2958 Shaders: one lane of a wave sets a mark its wave shares (frames 411 -> 283 ms on an RTX 4070 SUPER) (with #2936)

Covered by a merged PR

  • #2327 GPU: a save that fails gives its changes back for the next one: #1653 already serialises saves under one lock and keeps the marks of a failed save
  • #2328 GPU: pipeline library saves run one at a time: #1653 already holds one lock from serialising to the last file

Need a rebase onto this set

  • #1437 Shaders: preserve the unwritten high half of packed D16 image loads (conflicts with #1253) — calls a helper main no longer has
  • #1577 Shaders: expand 64-bit inline constants as signed ints and binary64 floats (conflicts with #1327 #2831)
  • #2104 Shaders: lower s_wqm_b32 and s_wqm_b64 in pure 32-bit DXIL (conflicts with #2083 #2361)
  • #2178 GPU+shader: back structured buffer views with raw descriptors for NVIDIA rawBufferLoad (conflicts with #1859)
  • #2238 Watch: dropping a tracker keeps a mapping guarded while a tracker holds its alias (conflicts with #2848)
  • #2293 GPU: a slot rewritten during a run keeps its view's copy of title memory until the run is over (conflicts with #1859)
  • #2294 GPU: a typed depth format in a shader resource view is made in the readable colour format (conflicts with #1859)
  • #2363 GPU: descriptor dwords read as data — the record count and the format (conflicts with #1859)
  • #2435 GPU: give screen passes dedicated pipeline workers and wait budget (fixes issue 2433) (conflicts with #1993 #2111)
  • #2788 Audio: XMA decoding keeps up while frames are slow (MMCSS thread, the mixer never waits for a decode) (conflicts with #2444)
  • #2821 GPU: title threads recording lists no longer wait on descriptor and buffer-copy locks (conflicts with #2848 #2936 #2598)
  • #2943 Shaders: pack half FMA NaNs directly (conflicts with #2893 #2954 #3007)
  • #3151 Shaders: pass SignedOpKind::Signed for float dx.op.wavePrefixOp (conflicts with #2936 #1540 #2893 #2954 #3007)
  • #3155 Shader: a load through a built CODE descriptor starts the constant table at the byte it reads (conflicts with #1540)
  • #3227 GPU: keep fences alive while queues wait on them (conflicts with #3141)
  • #3247 GPU: the held-work pump reads each wait's word once, and answers its own blocked question (conflicts with #3141)
  • #3300 gpu: scale dynamic descriptor pool on capped heaps (NVIDIA) (conflicts with #2683)

🤖 Generated with Claude Code

**@⁠pes7** on GitHub · 2026-11-26 18:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/3327) `pes7:merge/best-2026-11-26` → `main` · +12235 −2362 · 78 files · 284 commits · draft **Draft, work in progress.** A merge candidate: `main` plus the open pull requests that a triage marked ready to merge, merged together, built and tested together, conflicts between them resolved by hand. Posted so others can see the merge work and not repeat it; coordination in #1633. Nothing here closes or replaces any pull request: each one stays open and is closed only when it lands in `main`. This PR is not meant to be merged as is; it shows which set works together and which pull requests need a rebase. ## How the set was chosen 1 494 open pull requests (26.11) → 1 004 mergeable into `main`, with a green `check`, not drafts → 968 touching code. Left out: diagnostics and opt-in switches, benchmarks, CI, README/CLI, Wine/Linux-only, stacked pull requests, more than 600 changed lines or 6 files, known duplicates, build-profile changes. The rest scored on: a correctness/crash/performance fix, its author already merged upstream, small, has tests. 134 picked, merged oldest first after ours. Unlike the Forge train (#1624, every PR that merges and passes `cargo check`), this is a triaged subset, and each step runs clippy and the full test suite, plus the title itself. ## Status (base `63bcca43c`) | | | |---|---| | merged cleanly | **97** (this branch, `merge/best-2026-11-26`) | | merged with conflicts resolved by hand | **18** more on [`merge/pass2`](https://github.com/pes7/VIctory/tree/merge/pass2), not yet built | | already covered by a merged PR | 2 | | need a rebase (semantic conflicts) | 17 | Checked locally on Windows for this branch: - `cargo build --release --workspace`: ok - `cargo clippy --workspace --all-targets --locked -- -D warnings`, and with `--all-features`: ok - `cargo test --workspace --locked --no-fail-fast`: 30 test binaries, 1 019 passed, 0 failed, 10 ignored - the title (diagnostics build, Series X, Enter only): reaches the first playable scene with a correct picture, no device removal; frame-time A/B against the #2936 branch build is running, numbers to follow. Two commits of mine on top, both needed by the set, not by any single PR: - the per-translation library check (#2706) looks for the sharded library of #1653 (the two did not build together); - `lower.rs` grows past the 512 KiB asset policy with the set (520 563 → 544 760 bytes), so its tests move to `lower_tests.rs`, as #3097 does (#3097 itself conflicts with the set). ## In this branch (97) - #2634 victory-gpu: say once, not per slot, that the title's heap outgrew the host's (first frame 21 s -> 33 ms) - #2696 victory-gpu: VICTORY_SKIP_PIPELINES works in release builds, where the removals are - #2683 victory-shader: clamp heap indices to the largest heap a host can make (no descriptor read past the heap) - #1623 gfx10: keep an instruction's words inline instead of in a heap vector (decode -18..-45%, translation -1..-5%) - #1734 victory-shader: make the test dispatches cheap - an event wait and reused command objects (emit suite -33% wall, -48% CPU) - #2848 victory-gpu: take per-frame allocations, locks and system calls off the frame paths (7 places the profile points at) - #1653 victory-gpu: split the pipeline library into shards so a save writes only what changed (was 600 MB per save) - #2706 victory-gpu: keep a pipeline library per translation, not one shared one (a translator edit destroyed a 926 MB / 7.5 min cache) - #3295 victory-gpu: a copy of title memory in video memory, prepared and tested - #2936 victory-gpu: 16-bit packed colour widens for the host (the second crash between the account screen and gameplay), and the two tools it took - #324 fix(pe): detect incomplete TLS callback arrays - #379 Shaders: lower v_div_fixup_f16 - #477 Shaders: fix DXIL validator UB on null error blobs, unchecked GetStatus, and COM/DLL handle leaks - #590 HLE: reject duplicate blob changes in one save update - #1123 Validate XGameSave blob count before reading - #1194 HLE: extract installed_package and add focused xstore license/package tests - #1196 HLE: fix self-closing XML element body parsing in runtime.rs and add unit tests - #1253 Shaders: ignore pre-loop table loads when proving waterfall offsets - #1263 Shader: the loop limit switch works in every build - #1327 Shaders: apply bitwise modifiers to v_cmp_class_f32 source operands - #1540 Shaders: guard both back edges when a conditional branch targets two … - #1543 GPU: avoid shift and arithmetic overflow panics in subresource and copyable_footprints (victory-gpu) - #1564 GPU: MakeResident succeeds, as the console's memory is always resident - #1621 Shaders: bound the bytes one part's native blobs unpack to and hand out - #1787 GPU: textures drop unordered access in formats the host cannot write (NVIDIA B5G5R5A1) - #1827 HLE: enumerate the current installation for XPackageKind::Game - #1859 GPU: reject overflowing and non-buffer descriptor spans before shadow… - #1944 Shaders: reject a dxbc part inside the header or part table - #1993 GPU: hash DXIL shader slices zero-copy in HostPipeline::new - #2037 Shaders: byte and half format loads at a constant offset load the aligned dword directly (NVIDIA) - #2063 Shaders: lower s_ff0_i32_b32 and s_ff0_i32_b64 in pure 32-bit DXIL - #2070 Shaders: refuse the image instructions DXIL has no form of - #2077 Shaders: lower s_sext_i32_i8 and s_sext_i32_i16 in pure 32-bit DXIL - #2083 Shaders: lower s_bitreplicate_b64_b32 in pure 32-bit DXIL - #2111 GPU: the frame's wait for pipelines is one budget for all recording threads - #2122 Shaders: query a buffer's size through a handle of its own - #2141 HLE: registry lookups through kernelbase.dll reach the device-type overrides - #2150 Shaders: one instruction for one value (13.5 % fewer emitted instructions, no program lost) - #2184 xmem: 32-bit XMemAllocDefault blocks get the alignment they ask for - #2224 GPU: validate execute_indirect buffer offsets against buffer bounds and u64 overflow - #2229 Shaders: v_pk_fmac_f16 with DPP reads src0 from the selected lane - #2240 GPU: title memory copies are brought up to date again after a title write - #2254 Shaders: v_mad_i64_i32 sign-extends a 32-bit literal addend - #2269 GPU: marks in the last dword of the written-pages bitmap are not discarded - #2274 GPU: aliased textures copy only the subresources that have the same bytes per row - #2276 GPU: a depth texture used before it got a twin is copied to the twin in the list - #2278 GPU: a plain heap description is not read past its 16 bytes without checking they are mapped - #2295 GPU: the fifth dword of a root constants parameter is read as a constant - #2299 GPU: harden CopyMemoryToMemoryX against unmapped or read-only pages - #2303 GPU: page mapping copies wait for the submission that is running - #2361 Shaders: lower SOP2 s_pack_{ll,lh,hh}_b32_b16 (#815) - #2404 XG: preserve packed mip swizzle/positions and fix array subresource tiling (fixes issue 2400) - #2444 HLE: keep refilling XMA PCM buffer across zero-sample decode steps - #2445 Loader: clamp VEH instruction reads to the faulting page in emulate_amd_only and sse4a - #2450 Shader: check device removal before FMad readback - #2476 Discover shaders and pipeline packs through file symlinks - #2501 Shaders: a BVH node offset from a root descriptor is computed in 64 bits - #2504 HLE: physical-page writes open the title's views before they write - #2515 Shaders: VOP3 f16 interpolation attr63.w is not a 32-bit literal - #2553 HLE: avoid data race in DirectStorage late page-list polling - #2554 Loader: guard null C++ exception pointers in crash::thrown and Rsp overflow/alignment in unwind_into - #2576 GPU: read marks of slots forgotten before a submission are cleared before it runs - #2598 GPU: giving up a texture leaves the dynamic slots of recorded lists alone - #2622 Shaders: a constant branch through a folded block drops its untaken phi entry - #2630 PE: refuse a tls directory that runs outside the image - #2639 GPU: texture bytes off the runtime's memory are read at each refresh, as buffer copies' are (#2638) - #2677 App: keep run paths stable when the title changes directory - #2724 Shaders: texture reads at a computed table entry keep their read mark (#2722) - #2727 GPU: reject overflowing rectangle vertex ranges - #2776 shader: lower non-sum wave prefix operations to DXIL - #2831 Shaders: dwords read from the first lane outside a waterfall's own reads are one lane's (#2829) - #2869 Shaders: a buffer descriptor made raw from first-lane reads needs its waterfall (#2867) - #2882 GPU: heaps are bound again after a cut when ours stand in for both kinds (#2881) - #2886 Shaders: preserve round mode changes in whole-wave sections - #2893 Shaders: find the normalized load rounding shift with one bit scan - #2896 GPU: a list that binds no view heap gets ours before the root signature (#2894) - #2924 Shaders: reuse source-lane activity ballots - #2954 Shaders: lower v_bfe_u32/v_bfe_i32 to one Ubfe/Ibfe - #2980 GPU: a panic while making a host pipeline refuses it instead of ending the worker - #3005 GPU: make already-used pipeline lookups read-only - #3007 Shaders: lower the 32-bit mul_hi forms to one UMul/IMul - #3084 GPU: wait for queued presentation before resizing the swap chain - #3092 Loader: keep concurrent crash records whole - #3098 GPU: reject truncated or corrupted shader refusal entries - #3131 Game: fix stencil write-mask reachability for NEVER/ALWAYS funcs - #3141 GPU: flush queued segments before evaluating memory and fence waits - #3195 HLE: keep async status waits attached through provider cleanup - #3221 fix(shader): preserve signed zero when f32 div:2 underflows - #3243 Loader: skip DIR64 relocation addresses that overflow u32 - #3245 GPU: return pinned HostTexture from alias_source to avoid source Release UAF - #3248 GPU: preparing a view heap's page table scans the change tracker a word at a time - #3257 GPU: fix PresentX subresource copy and plane format handling - #3266 GPU: back off texture heap growth after out-of-memory - #3272 HLE: wait for in-flight lifecycle callbacks on unregister - #3280 Fix issue 2412: reject out-of-range export addresses in parse_exports - #3309 formats: guard XMA Bits::read and Bits::signed against shift overflow - #3316 Shaders: decode fixed 4-VGPR data and 4-SGPR rsrc for image_bvh_intersect_ray ## Conflicts resolved on `merge/pass2` (18, building next) - #1565 GPU: Evict succeeds, as the console's memory is never evicted (with #1564) - #1566 GPU: SetStablePowerState is accepted and ignored (with #1564) - #2272 GPU: a page a copy holds in part is taken after its marked copy-back (with #2269) - #2297 GPU: a texture sampled before an in-list title memory copy is uploaded again after it (with #2276) - #2415 GPU: remapping one mapping of aliased pages leaves the others guarded (with #2269) - #2437 GPU: a marked copy-back advances the snapshot of declared ranges over its page (with #2269) - #2474 GPU: refreshes of two parts of one page do not make it current whole (with #2240) - #2296 GPU: rectangle vertices are read from title memory through the kernel at submission (with #2295) - #2329 GPU: a list that binds a heap's view-address table keeps it until reset (with #2295) - #1668 Shaders: read inline floats as f32 bits in 16-bit integer ops (with #1327) - #1685 Shaders: lower v_cmp_{f,t}_{i64,u64} constant 64-bit compares (with #1327) - #2792 fix(shader): allow untracked scalar lane masks in v_cndmask_b32 (with #1327) - #2915 Shaders: f16 results ignore their output modifier, as RDNA2 does with half denormals kept (with #1327) - #2457 Shaders: return zero for unused image_get_resinfo extents (with #1253) - #2587 Shaders: bind a zero dword for empty root-constant slices (with #2515) - #2774 Shaders: validate raw fixtures and signed MAD64 with full-word regression (with #2254) - #2953 Shaders: lower binary64 division fixup in DXIL (with #2936) - #2958 Shaders: one lane of a wave sets a mark its wave shares (frames 411 -> 283 ms on an RTX 4070 SUPER) (with #2936) ## Covered by a merged PR - #2327 GPU: a save that fails gives its changes back for the next one: #1653 already serialises saves under one lock and keeps the marks of a failed save - #2328 GPU: pipeline library saves run one at a time: #1653 already holds one lock from serialising to the last file ## Need a rebase onto this set - #1437 Shaders: preserve the unwritten high half of packed D16 image loads (conflicts with #1253) — calls a helper `main` no longer has - #1577 Shaders: expand 64-bit inline constants as signed ints and binary64 floats (conflicts with #1327 #2831) - #2104 Shaders: lower s_wqm_b32 and s_wqm_b64 in pure 32-bit DXIL (conflicts with #2083 #2361) - #2178 GPU+shader: back structured buffer views with raw descriptors for NVIDIA rawBufferLoad (conflicts with #1859) - #2238 Watch: dropping a tracker keeps a mapping guarded while a tracker holds its alias (conflicts with #2848) - #2293 GPU: a slot rewritten during a run keeps its view's copy of title memory until the run is over (conflicts with #1859) - #2294 GPU: a typed depth format in a shader resource view is made in the readable colour format (conflicts with #1859) - #2363 GPU: descriptor dwords read as data — the record count and the format (conflicts with #1859) - #2435 GPU: give screen passes dedicated pipeline workers and wait budget (fixes issue 2433) (conflicts with #1993 #2111) - #2788 Audio: XMA decoding keeps up while frames are slow (MMCSS thread, the mixer never waits for a decode) (conflicts with #2444) - #2821 GPU: title threads recording lists no longer wait on descriptor and buffer-copy locks (conflicts with #2848 #2936 #2598) - #2943 Shaders: pack half FMA NaNs directly (conflicts with #2893 #2954 #3007) - #3151 Shaders: pass SignedOpKind::Signed for float dx.op.wavePrefixOp (conflicts with #2936 #1540 #2893 #2954 #3007) - #3155 Shader: a load through a built CODE descriptor starts the constant table at the byte it reads (conflicts with #1540) - #3227 GPU: keep fences alive while queues wait on them (conflicts with #3141) - #3247 GPU: the held-work pump reads each wait's word once, and answers its own blocked question (conflicts with #3141) - #3300 gpu: scale dynamic descriptor pool on capped heaps (NVIDIA) (conflicts with #2683) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The ISA's special cases in its order: a NaN numerator or denominator comes
back quieted, 0/0 and inf/inf give NaN, x/0 and inf/x a signed infinity,
0/x and x/inf a signed zero, otherwise |S0| with the quotient's sign.
Worked on the f32 values of the f16 operands, which are exact.
The ISA's "exponent of S0 all ones -> overflow" check runs before the
final |S0| case, so a NaN quotient with a finite, non-zero numerator and
denominator gives sign | infinity, as measured on gfx1036 hardware. The
zero, infinity and invalid checks still come first.
XGameSave permits only one write or delete per blob in an update. WriteBlob and DeleteBlob accepted repeats and submit silently kept the last one, so a title could pass locally but fail on a console. Refuse a second change to a blob already in the update, update the existing test that relied on write-then-delete, and keep the first change.
VICTORY_SHADER_LOOP_LIMIT was read only with the diagnostics feature, so a
release build could not run the experiment another VIctory fork reports as a
~6x GPU time win. It is now honoured in every build, with the default (2^20)
unchanged, values from 2^31 clamped to i32::MAX (the emitted counter is an i32
compared unsigned, so a bigger constant would act as no limit), and the same
parse rules. The shader cache already hashes the limit into its key, so
translations made with different limits never mix; the warning says so.

The 256/1024 advice and the risk of 32 are in xcl-bin/notes/loop.md.
Hosts differ in which formats take unordered access: NVIDIA has none
for B5G5R5A1_UNORM, AMD has. host_desc kept the title's UAV flag for
such a texture, so on an NVIDIA card the host description was invalid,
and the size query shared_texture makes with it removed the device
(DXGI_ERROR_INVALID_CALL) in the menus, about 50 s after start.

A texture in a format the host cannot write from shaders (asked once
per format with CheckFeatureSupport, typed unordered access views) is
now made without that use; typeless formats keep it, their views decide.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
64 index entries could name one blob and 8 stage slots one code range,
so a small container inflated up to 1 GiB and had about 8 GiB of code
copied out. the bytes a part's blobs unpack to and the code and raw
table bytes read out of them now come off one 16 MiB budget.
format_load aligned the offset of a field narrower than a dword with
`off & !3` even when the offset was a constant. vkd3d-proton turns a raw
load at a computed offset into a per-component raw access chain
(stride 0), and on NVIDIA that load did not see the dword the same
invocation had just stored through the buffer's other access (stride 16,
per element): it read 0. A constant offset now gives a constant aligned
address and shift, and the load takes the same access as the store.

Fixes on an RTX 5080 (vkd3d-proton 3.2.0, Proton):
normalized_buffer_formats_load_their_ends_exactly and
tbuffer_d16_loads_pack_two_channels_per_dword.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`BUDGET` is "waiting allowed per title frame, over all threads", but each
wait took what was left of it when the wait began and counted its own time
only on return. The title records its lists on several threads: a thread
that began to wait while another still waited got the whole budget again,
from its own start. The frame then stood still for up to twice the budget
(a thread that begins just before the first returns), and its threads
waited a budget each.

The waits of a frame now end together (`Waits`): time counts while any
thread waits, once however many do; waits one after the other share what
is left; a thread still naming the frame before brings no budget back.

The frame line prints the time waited: these waits are on the recording
threads, outside the submissions, so they were in none of its times.

Tests, no GPU: waits_of_a_frame_share_its_budget (the accounting, on given
instants) and a_thread_that_waits_while_another_does_gets_no_budget_of_its_own
(four threads waiting on pipelines never made).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Include kernelbase.dll in xsystem::device_type::module().dlls alongside advapi32.dll and api-ms-win-core-registry-*, matching kernel::module() and files::module(). On Windows, api-ms-win-core-registry-l1-1-0.dll resolves to kernelbase.dll, so dynamic lookups via GetProcAddress (through kernel::host_override) and direct imports from kernelbase.dll bypassed the emulated OEM ConsoleMode registry key and fell through to the host registry.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The lowering writes code as the console instructions name it: a register
read as a float is cast again at each read, a descriptor's handle is made
and its index clamped again in each block, an address is shifted and
masked again for each access. `bitcode::reuse` runs on the finished
module: an instruction that computes what an earlier one computed, where
every path to it has run that earlier one, is left out and its readers
take the earlier result.

It takes integer arithmetic and compares, integer selects, width and bit
casts, extractvalue, getelementptr, handle creation and annotation, the
integer `readnone` operations, `getDimensions`, and raw loads from the
host's own tables (page table, view addresses, view marks, view
strides). Float arithmetic, float compares, conversions, every other
load, samples, atomics and wave operations stay as written.

What goes is always a copy of an instruction that stays, so no operation
and no declaration loses its last use: shader flags and declarations
stay valid without being recomputed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
XMemAllocDefault previously forwarded ALLOC_32BIT requests straight to
XMemVirtualAlloc without passing the alignment field from attributes, so
MEM_ADDRESS_REQUIREMENTS::Alignment was always 0 (64 KiB granularity)
and alignments above 64 KiB (128 KiB, 256 KiB, 2 MiB, ...) were ignored.

Extract a virtual_alloc helper taking an explicit Alignment and pass
`1 << ((attributes >> 24) & 0x1f)` when it exceeds 64 KiB (0 otherwise,
as required by MEM_ADDRESS_REQUIREMENTS).

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lower::valu puts a DPP instruction's cross-lane src0 in self.src0 before
lowering the operation; fsrc, src, half_src and v_cndmask_b32 read it for
source 0, but fmac_half read the operand directly, so v_pk_fmac_f16_dpp
multiplied the lane's own src0 in both halves. Read self.src0 for source
0 as the other readers do.

The test draws a 2x2 quad whose pixels swap their packed src0 through
quad_perm:[1,0,3,2].

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mips with the same footprint and rows but another row width were copied
through a buffer sized for one of them.
src64 sign-extends a literal for operations named *_i64 (#447), but
v_mad_i64_i32's addend is S2.i64 too, and its name ends in _i32, so a
negative literal there was zero-extended: 0 * 0 + -100 gave 0xffffff9c
with a high dword of 0. RDNA 2 ISA 6.2.1: a 64-bit signed integer source
sign-extends its literal. v_mad_u64_u32 keeps zero-extending.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review on #1787: host textures are made with their castable formats, and
D3D12 allows ALLOW_UNORDERED_ACCESS when a format the texture can be cast
to takes typed unordered access (B5G5R5A1_UNORM's 16-bit aliases such as
R16_UINT on NVIDIA). Dropping the use whenever the texture's own format
lacks it lost writes through those aliases.

host_desc now drops it only when neither the format nor any castable
format takes typed unordered access. make_texture's fallback without
castable formats (CreateCommittedResource3 refused or no Device10) drops
it when the format alone lacks it, since there the alias is gone and the
flag is illegal. The test makes the textures through make_texture.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adapt fxceless/victory-fork#971 to cover translate, its cache warm-up,
pipeline pack discovery, and shader-info. Resolve file symlinks for
type and size checks while preserving each caller's regular-file
metadata policy and shader-info's warning for large regular files.

Thanks to avt0m4t48 for independently verifying the translate fix and
identifying the remaining shader-info gap in fxceless/victory-fork#971.
With the node's base taken from a root descriptor ("Built"), the node's byte
offset was shifted and added in 32 bits and then zero-extended to 64: a BVH
larger than 2 GiB has offsets that do not fit, and any negative intermediate
(the adds are signed) became about 4 GiB too large instead of sign-extending.
The explicit-descriptor path next to it already does the shift in 64 bits,
so the two halves of the same instruction disagreed.

The offset is now built in 64 bits for a raw (title-memory) base — shift,
constant, and the computed part — and only the buffer-view path keeps the
32-bit form D3D12 takes for a buffer's offset.

`intersections_with_64_bit_pointers_on_the_gpu_equal_the_reference` covers
this path on the card; it and the rest of the lib suite are green (247
passed, 3 ignored). A case that *fails* before this needs a BVH of more than
2 GiB, which this machine does not hold, so the change is argued from the
arithmetic rather than from a red test — if a title-side repro shows up, this
is the first place to look.
Review feedback on #2501: the comment said the 64-bit shift also fixed a
negative offset becoming about 4 GiB too large, but `built_offset` gives `k`
as `u32` and the computed part goes through `Cast::ZExt`, so the new code
zero-extends too; the old 32-bit add wrapped instead. Drop the claim.

Add the test the review asked for: `run_cases` gains a `high` mode that sets
bit 29 of the node pointer and maps the page 4 GiB higher in the page table to
a second copy of the nodes, with zeros in the page below. With the old 32-bit
shift the offset wraps back to the zeros and no case matches the reference;
with the 64-bit shift the pointer reaches its copy. `page_table_high` adds the
level-1 entry for the 256 MiB region 4 GiB up and a block for it.
Since 52d14b1 a heap slot whose texture view is left null (a placed
texture written into the heap, or one given up since 69d1e8e) is
forgotten (forget_read) so that its next read marks it again and
take_reads, after the submission, has its view made. Both happen before
the submission runs (sync_heaps, evict_unused), but the forgotten marks
were only cleared inside take_reads, after it ran: the mark a shader of
that very submission had just set was wiped with them. The slot was made
only after a later submission read it again (another frame of a null
view), or never if nothing read it again.

The marks of slots forgotten since the last submission are now cleared
just before the next one runs (clear_forgotten_reads); take_reads still
clears those forgotten while it ran.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since 69d1e8e, giving up a host texture (idle, or past the card's
budget) nulls every heap slot viewing it (HostHeap::evict). Since
ed25c0e it finds them by scanning `kept`, which covers the dynamic slots
too: the descriptor tables lists build for their draws. A recorded list
not yet reset still uses those (the dynamic slots it took are not
released until then), and its table is not made again before it runs,
so its draws read a null 2D view, and the slot no longer held the
texture. resource.rs: "Lists recorded before hold it until they are
reset, so no GPU work reads it freed".

evict now leaves dynamic slots a list still holds (taken in `next`), and
holds `made` and `next` across the scan and the clearing.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Until the slot is next made, not until its list is reset (review by
fyernald).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since 286a00e the DXIL writer takes a branch on a constant as a branch to
its one target, drops phi entries of edges that are gone, and folds an
empty block with one predecessor into it. Plan::edge decided whether a
phi of block x keeps its entry from b by following b's successors
through folded blocks (`to`). For `CondBr(true, empty, join)` with
`empty` folded (`empty` branches to `join`) and a phi in `join` with
entries from `empty` and from the untaken direct edge, the direct entry
was kept as well: the phi got two entries for its one predecessor,
which is invalid IR.

An entry stays when b's own terminator, constant branches taken as
branches, still has x among its successors; a folded block's entry
still stays and is written from the block it was folded into.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The title asks for 1 245 184 descriptor slots, more than the 1 000 000 a host
heap holds, and it walks them in increasing order. "Log when the high-water
mark moves" is therefore one line per distinct slot: 199 846 of the first
200 000 lines of a run, ~8 000 a second, on the thread recording the frame.

That was the whole of the first frame's stall:

    before   310 932 lines in the run, first frame 21 433 ms
    after        231 lines in the run, first frame     33 ms

Same build, same warm caches (926 MB pipeline library, 1 347 MB shader cache),
same 150 s window. What the line said - that slots above the host heap's count
are not mirrored - is what the one line now says.

The underlying problem is not this change: 245 184 title slots can never be
mirrored because they exceed the tier-2 heap limit, which needs either several
host heaps with the index arithmetic adjusted or the views above 1 M placed
elsewhere. That is why the first world frames get null views.

cargo test --workspace --locked; both clippy configurations with -D warnings;
cargo xtask policy.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
What was wrong: a tracker leaves pages that touch memory other than the
runtime's untracked, "copied whole at each use" (280b150), and such a
tracker is never clean. A texture's refresh asked only the tracker's
changed pages (`Tracked::take`) and, since cc5f961, re-detiled only the
subresources those pages touch: a subresource lying wholly in untracked
pages was never touched, so it was not uploaded at all, not even the
first time (before cc5f961 the first refresh read the whole texture).

What changed: the refresh also takes the tracker's untracked parts
(`Tracked::untracked`) as candidates. Subresources in them are read and
their bytes decide by hash, as for a page shared with other data; the
"a whole changed page" shortcut still looks at tracked pages only.

Test: `draw::tests::a_mip_off_the_runtimes_memory_is_uploaded` (a
two-mip linear texture whose mip 0 lies in plain committed memory after a
reserved page: both mips uploaded at first, mip 0 again after a write).
On main it fails: "both mips at first", left 1, right 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Translated shaders clamp every heap index they compute below HEAP_VIEWS,
and NULL_BUFFER_VIEW = HEAP_VIEWS - 2 is the slot a shader reads instead of
a slot with no buffer view. HEAP_VIEWS was 1 << 21 = 2 097 152, the
console-shaped heap the indices were first written for, but
D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_2 is 1 000 000
(victory-gpu's PORTABLE_VIEWS): the clamp allowed an index 32 MB past the
end of any heap that can exist, and what is there is read as a descriptor.
The code knew - "a host that caps its heaps below HEAP_VIEWS (NVIDIA)
faults on an index past them" - and on the title it never got as far as
the null slots:

    host view heap capped at 1000000 count=1245184
    no room for the null buffer views: ... count=934464 total=1000000

HEAP_VIEWS is now the largest heap a host may create (1 000 000), so every
index the clamp can produce is inside the heap and NULL_BUFFER_VIEW is
999 998. A heap capped at PORTABLE_VIEWS keeps the top of itself for those
two slots (MIN_DYNAMIC - NULL_RESERVE dynamic slots), so the title slots
and the dynamic ones end below them and the warning above no longer
happens; measured on the title, warm caches: "null buffer views: 0".

The title asks for 1 245 184 slots, more than a host will hold, so slots
above the capped heap's title region are still unmirrored - they read a
null slot now, which is the safe answer the clamp was meant to give, not a
read outside the heap.

HEAP_VIEWS is baked into translated shaders, so the shader cache is
translated once more (SOURCE_HASH changes); the pipeline library is keyed
by the title's shaders and is unaffected.

cargo test --workspace --locked; both clippy configurations with -D
warnings; cargo xtask policy.
What was wrong: since 2d6c0df only texture views the program takes from
the resource heap itself set a read mark; reads through a table set none,
because "the host makes table slots for the draw". The host makes only the
entries the used-resource list names (`draw::State::tables`: one `table_entry`
per entry, the whole range only for tables made afresh). A table read at
a computed offset (a descriptor array indexed by data: `s_load_dwordx8`
with an SGPR soffset, a per-lane or waterfall load) may reach any slot
past those, and a slot there holding a placed texture left null was made
by its read mark before 2d6c0df; now nothing makes it and the view reads
null for good.

What changed: a texture read sets its mark unless its descriptor is a
table entry at a fixed offset on every path (`Lower::fixed_table_entry`),
the case 2d6c0df meant to skip. Heap-direct reads mark as before.

Test: `heap_direct_texture_reads_mark_their_heap_index` gains a table
read at a computed entry (soffset from `v_readfirstlane`, shifted by 5);
it was not marked before, it is now. The fixed-entry table read still
marks nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The host rewrites table entries while the GPU runs (the heap's
write_stride, set_mark and note_address), so the notes no longer say it
does not. The pass needs no such promise: inside one invocation the
reads of one entry it merges give the first read's value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reserve was applied in the capped path only, so the two successful
layouts (count + DYNAMIC, count + MIN_DYNAMIC) put 999 997/999 998 inside
the dynamic slots, the guard refused the null views there, and a clamp to
HEAP_VIEWS - 1 named a written slot. Every layout now stops its dynamic
range NULL_RESERVE slots below the end of the heap it got.
`Tracer::classify` traced every `v_readfirstlane_b32` result as the
dwords each lane holds. That is right only for the reads a waterfall
loop at the access compares, which `track` proves. Reads reached another
way were never proven:

- copied back to VGPRs before a loop (`v_readfirstlane_b32 s24, v4`,
  `v_mov_b32 v4, s24`): a per-lane source (a `global_load` entry) came
  out as each lane's own, though every lane holds the first lane's;
- picked by `s_cselect` or joined at an SGPR phi: the dwords had to be
  the same only in the lanes that access the descriptor, but the first
  lane may be another (lane 0 kept its old VGPRs, the accessing lanes
  overwrote theirs under EXEC).

RDNA2 ISA, V_READFIRSTLANE_B32: "Copy one VGPR value to one SGPR ...
Lane# = FindFirst1fromLSB(exec)".

The access's own reads are now traced in `descriptor` as before. Others
must give the same descriptor in every lane that runs the reads (the
reach of their block); a per-lane source is refused as "a descriptor
read from the first lane outside a waterfall loop".

Test: `first_lane_reads_no_waterfall_loop_proves_are_not_each_lanes_own`
(both shapes; on main the first traces to `Fetched`, the second to
`Select` of the first and second buffers).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Read src0 of v_cmp_class_f32 and v_cmpx_class_f32 as raw 32-bit bits (with SDWA sub-dword selection when present) and apply VOP3/SDWA abs and neg modifiers in integer bits rather than through fsrc float operations. This prevents D3D12 FTZ from flushing negated +denormals to -0.0 and prevents float ops from quieting signalling NaNs.
copy_back_page, copy_back_or_not and copy_back_marked each made a fresh
Vec for the bytes they read from title memory, up to 64 KiB a call, and a
world frame copies dozens of ranges back. A fresh buffer is committed and
touched from scratch, which is one page fault per 4 KiB: the frame report
counted about 1 900 page faults per frame in copy-back alone, and the
allocator traffic on top.

The buffers now come from the same pool the snapshots use and go back to
it (the pool keeps what fits, so nothing is dropped in practice), and the
pages a copy-back took are filtered where they are instead of being
collected into a second Vec.

(cherry picked from commit b0bb0dcdbaf3c503640adc839167bc38a61f6001)
`HostHeap::sync_slots` collected the record of every slot it was asked
about into a Vec, then a Vec<bool> of which name a current view, then a
Vec of the slots that differ. A world frame asks about ~800 000 slots
(`copystat`: "heap slots the title copied"), so that is tens of megabytes
of allocation and copying per frame, for records that are read once.

512 slots at a time now, in buffers on the stack: read, checked against
the records the slots hold, and the differing ones mirrored, which is a
few hundred a frame. `views_current` fills a slice instead of building a
Vec, and takes one lock of the view list per pass as it did per call.

(cherry picked from commit 341a051e9d2a02f35e627b216deed1ba29ae93fa)
`SHADER_HEAPS` guards the list of shader-visible heaps: which heap a
handle is in. Two kinds of caller read it and never change it - every
title thread that writes a view into a heap (`mirror`) and each
submission's heap sync, which walks every slot of the pages the title
wrote (`sync_heaps`, ~800 000 slots a frame). With one mutex they took
turns, and the frame report put 48 ms per world frame into title threads
waiting for it (`copystat`: "title threads waiting to write views").

Readers share an `RwLock` now; only a heap's registration and its release
(`Heap::drop`) take it alone, and a drop still waits for readers, so a
heap cannot be freed while `mirror` or a sync holds its address. The slot
work itself was never serialized by this lock: each host heap has its own
`made`/`kept` locks, and `mirror` already re-checks a slot after dropping
`made` because another thread may have made it meanwhile.

(cherry picked from commit 9fe32dd749df24d987bf9f0c1fb460418c6d5480)
`Shadow::update` is called for every range a submission's lists refresh
(thousands to tens of thousands a frame) and locked `pending` - the set of
ranges shaders of the submission may be writing - to see whether the range
meets any. Most refresh ranges meet none, and outside the window between a
GPU-write step and the submission's copy-back the set is empty.

An atomic count beside the set now answers that without the lock; the lock
is taken only when there is something to look at. The count moves where the
set moves (`writing` inserts, the copy-back removes).

(cherry picked from commit 98a7a935478282daedb7d69b26ea1b61401fca55)
A heap sync asks, for every slot of every page the title wrote, whether the
record there still names a current view: ~800 000 slots a world frame
(`copystat`: "heap slots the title copied"), one `Vec` lookup each into
`Views::list`, whose entries are a whole `View` (tens of bytes) and a
generation. The generation now lives in a `Vec<u32>` of its own, so the
answer is one 4-byte read instead of a cache line of view data; only the
slots that do name a current view need the view itself, and those are the
few hundred that get mirrored.

(cherry picked from commit 20db67d0d19e5df272dcce613a86d2e0133e2a8a)
`open` gave access back one page at a time: a `VirtualProtect` per page,
plus a set removal. World frames open tens of thousands of pages
(`copystat`: "pages opened", 13 624, and 75.95 ms in the guard handler),
and the pages a write or a copy covers are consecutive - the title writes
runs of them, and so does our own copy-back.

Consecutive guarded pages are given back in one call now, both where a
write of ours opens what it covers (`changed_here`) and where a released
tracker opens what nothing else watches.

(cherry picked from commit 1ce5a606f1e9676359f92e07ccd7ca1f243fc798)
The dwords a stage's user data sets were collected into a fresh `vec!` for
every stage of every draw (a few dwords at most, thousands of draws a
frame). Up to 64 of them now live in an array on the stack; a title that
asks for more still gets a Vec.

(cherry picked from commit 65f9815f639efbad912d8b33d04f1910244d49c0)
DirectStorage's page destinations are written through our own views of
the physical pages (xmem::page_window, write_physical), which the GPU
write watch's guards on the title's views do not see. xmem tells the
watch where the pages show when the write ends (report_written), but
kernel_will_write is meant to come first as well: "Before our own write
into title memory [...] opens its guarded blocks, marks them changed and
keeps them open while the result lives", saving an armed page's bytes
before the write lands. Told only afterwards, an armed page kept the
streamed bytes as its old ones, and copy_back_marked put the copy's
stale bytes back over the streamed data.

PhysicalWrite opens the title views showing the pages when the write
begins and holds them until it is done; the end-of-write report still
tells views mapped in the meantime.

victory-gpu exposes its trackers (Tracked, track) under a new
`test-hooks` feature, which only victory-hle's tests enable.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
One `Vec<u32>` per instruction was one allocation and one cache miss for
the dword or two most instructions have. The words live in a fixed
`[u32; MAX_WORDS]` with a length now: five dwords covers the longest
instruction here (an MIMG with its three extra address dwords), and the
decoder refuses anything longer rather than truncating it.

Decode -18..45% depending on program size; whole translation -1..5%,
since decode is a small part of it.

Now that #1180 is in `main`, this applies on its own: an `Instruction`
carries both the inline `words`/`len` and the cached `name`, and neither
costs the other its win.

cargo test --workspace --locked; both clippy configurations with
-D warnings; cargo xtask policy.
#2143 (merged today) reads `i.machine.words.len()` in `code_table_start`,
and this branch made `words` an inline array behind an accessor, so the two
textually disjoint hunks do not build together. The accessor returns the
slice, so `.len()` is the same number; no behaviour change.
Restore comment encoding and drop unrelated rustfmt churn.
`draw` and `dispatch` poll `fence.GetCompletedValue()` and call
`GetDeviceRemovedReason` on every iteration while a thread spins. One
event per submission, `SetEventOnCompletion`, and `WaitForSingleObject`
in 100 ms slices: the same device-removal report, no CPU burned while the
GPU works, and no device call in a hot loop.

The 100 ms timeout is what keeps that check: a removed device never
signals, so an INFINITE wait would hang the run instead of reporting it.
`WAIT_FAILED` returns an error rather than looping.

Interleaved A/B, 9 runs each, `emit::` with --test-threads=8:

    wall           9 080 ms  ->  9 084 ms
    CPU (median)   5 562 ms  ->  4 438 ms   -20%

Every event run stayed under 4.66 s of CPU; eight of the nine spin runs
were at 4.88 s or above.

`draw` and `dispatch` are `#[cfg(test)]`, so nothing in the game changes.
Cargo.toml gains Win32_Security and Win32_System_Threading for the
optional windows dependency (CreateEventW sits behind both); victory-gpu
already enables them.

cargo test --workspace --locked; both clippy configurations with
-D warnings; cargo xtask policy.
A dispatch made a new queue, allocator, list, fence and event every call.
Making those five costs 4.19 ms of an 8.35 ms dispatch (200 iterations,
release, hardware device), and emit::valu_tests runs hundreds of
dispatches for one shader: every f16 pattern, two opcodes, two backends.

Keep them in `Host`, bump the fence value per dispatch, and reset the list
with the dispatch's own PSO. That is safe here because the GPU tests run
one at a time (ONE_AT_A_TIME) and every dispatch waits for its fence, so
the allocator is never in use when it is reset. `Drop for Reused` closes
the event; `draw` still makes its own, since it is not on this path.

    v_cvt_norm_i16_and_u16_f16_round_the_exact_product   4.81 s -> 2.17 s
    emit:: suite, wall                                  9 084 -> 6 053 ms
    emit:: suite, CPU                                   4 438 -> 2 891 ms

Together with the event wait, against the original code: emit:: wall
9 080 -> 6 053 ms and CPU 5 562 -> 2 891 ms.

cargo test --workspace --locked; both clippy configurations with
-D warnings; cargo xtask policy.
Two things the triage found in the `Reused` cache.

The allocator was never reset, so it kept the memory of every dispatch
recorded since the host was made - hundreds per `valu_tests` case.
`ID3D12CommandAllocator::Reset` now runs before the list is reset, which
is safe because the previous dispatch waited for its fence. It costs
nothing measurable: four interleaved pairs of the `emit` suite gave
10.5 s of CPU with the reset against 11.1 s without it.

An error between `list.Reset` and `Close` left the cached list recording,
so the next dispatch's `Reset` failed too and one bad case turned every
later GPU test on that host into a failure with a misleading message.
`Reused` now notes that a recording is open and is thrown away instead of
reused if it is.

cargo test --workspace --locked; both clippy configurations with
-D warnings; cargo xtask policy.
The switch answers one question - "is this shader the one that removes the
device (or paints the wrong picture)?" - and it could only be asked of a
diagnostics build. That is the build in which the removal does not
reproduce on the machines seen so far: a diagnostics build does more work
per submission, so the frame that hangs the GPU in a release build never
gets there (measured here: release removes the device 10 s in, the same
build with `--features diagnostics` and no debug layer runs 180 s and does
not remove it at all).

So `is_skipped`, `skipped_shader` and `parse_skip_hashes` are no longer
behind the feature, and the three call sites keep the skip but gate only
their reporting (`note_drop`, `dropped`, `shaders_of`). A release build
now answers the question testers are actually asking:

    VICTORY_SKIP_PIPELINES=0602c2384acbb3b2  -> dropped 1/frame in the menu

and a skipped pipeline is dropped the way one with no host pipeline is
(the frame's "dropped N without a host pipeline" counter moves).

No behaviour change without the variable: `is_skipped` reads it once, and
an empty list is the `false` it was before.

cargo test --workspace --locked; both clippy configurations with -D
warnings; cargo xtask policy.
The library's pipelines are named after the shaders they are made from, so
a change to the translator (`victory_shader::SOURCE_HASH`) makes every name
in it useless - and the first run after one wrote the few pipelines it made
over the old library. Measured on the title:

    warm:  host pipeline library loaded bytes=970507898 ms=57   (926 MB, 27 160 pipelines)
    after a translator change, the next start-up says:
           host pipeline library loaded bytes=626800            (612 KB)

That 926 MB was a 7.5 minute warm-up (`translate --cache --pipelines`,
made=23057 on a cold library). It is not a truncated write -
`write_atomically` is already there, and so is the translator hash in the
pre build's list - the new library is simply small and replaces the old
one. The cost lands on the loop that needs the cache most: bisecting
between two builds paid the warm-up for each of them, in turn, every time.

So each translation keeps its library in `dir/<SOURCE_HASH>`, and the two
newest are kept (`KEPT`): the one in use and the previous build's, which is
what a bisection needs. A run only ever writes its own directory, and
pruning takes a directory only when its name is 16 lowercase hex digits and
it holds `host-pipelines.bin`, so a `backup/` someone keeps in the cache
directory is left alone (there is a test with a sentinel file in one).

Measured (retail title, two runs in a row, `O:\tmp\victory-cache\pipelines`):

    run 1:  host pipeline library saved  bytes=3086   (no load: first use of this key)
            host pipeline library saved  bytes=7488
    run 2:  host pipeline library loaded bytes=7488 ms=0
    -> O:\tmp\victory-cache\pipelines\94ef170ae2f5e8da\host-pipelines.bin

Nothing else moves: `use_pipeline_cache` still takes the same directory, and
the pipeline library of a build that is not the current one is now left
alone instead of being overwritten.

Rebased onto today's `main`: the file gained `tag()` (which holds the
translator hash for the pre build's list) and `write_atomically`, so this
is the directory part only, applied to those.

cargo test --release -p victory-gpu (229 tests); clippy clean; both
`victory` configurations build.
# Conflicts:
#	crates/victory-shader/src/emit/valu_tests.rs
`descriptor` traces a buffer descriptor made raw before a byte access
(stride cleared, records times stride, bounds in bytes) to the words it
was made from. When those are `v_readfirstlane_b32` results, `classify`
takes them as each lane's own. But `track` looked for first-lane reads in
the access's own SGPRs, where dwords 1-3 are the s_and/s_mul/s_or
results, so it found none and proved no waterfall loop. With no loop the
console uses the first lane's buffer in every lane, yet each lane read
its own.

`first_lane_words` now reads the same words as `descriptor` (the new
`words`). With no loop the access is refused, as other first-lane reads
are. Inside a waterfall loop the proof now holds and the loop runs in one
pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Three image instructions translated into DXIL operations the validator
rejects (and a driver may refuse, or run wrongly), where refusing them
is the right outcome:

- a gather (`image_gather4_lz`, `_l`, `_lz_o`, `_l_o`) from a 1D or 3D
  image: "gather requires resource declared as texture/2D/Cube/2DArray/
  CubeArray";
- a gather with offsets (`_o`) from a cube or cube array: "out of bound
  offset must be undef";
- `image_load_mip` from a UAV, which is one level of its resource: "uav
  load don't support mipLevel/sampleIndex" (and the typed-UAV-load flag
  was left out, so "Flags must match usage" too).

They are now refused with those reasons, as the gathers DXIL cannot do
already are ("a gather with implicit level", "a gather of several
channels").

Found by validating random programs (the generator of #1335, with a
validation pass, validator 1.6): 5 of 16,207 programs that translated
out of 200,000; with this and #2056 every one of them validates. The new
test lowers each into LDS, so the refusal ends the translation, and the
2D gather and the plain UAV load next to them, which still lower; it
fails on `main`, and without either of the checks.
`image_sample_c_lz` and the other comparison samples (`sampleCmp`,
`sampleCmpLevelZero`) of a 3D image translated into a DXIL operation the
validator rejects ("samplec requires resource declared as texture1D/2D/
Cube/1DArray/2DArray/CubeArray"): D3D compares samples of every kind of
texture but 3D. They are now refused, as the other image forms DXIL has
no form of.

Found by the same random-program validation, over 2,000,000 more
programs: 3 of 164,934 that translated. The image test now also lowers
the same comparison sample of a 2D image, and refuses it of a 3D one (it
translates on `main`).
#1778 made the sampler heap we bind when the title binds none
SAMPLERS_OURS = usize::MAX. Our view heap for title memory, MEMORY_HEAP
(memory::OURS), is usize::MAX too, and host_state_lost marks the host
list's heaps unknown with [usize::MAX; 2]. A draw or dispatch that wants
both of ours (the title binds no heap, its shaders use title memory or
root views) then wants exactly that marker, so bind_heaps found nothing to
change: after a cut at a Wait32/64BitValueX the new host list starts with
no heaps and none were set before the root signature, which indexes both
directly (SetDescriptorHeaps must come first: the debug layer's 1419,
INVALID_CALL on NVIDIA); after external::record the heaps of the other
recorder stayed bound. Before #1778 such a list wanted [usize::MAX, 0].

SAMPLERS_OURS is now usize::MAX - 1, which neither a title heap nor the
marker takes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On current main the test took lower.rs past the repository's 512 KiB
source-file limit (CI's policy check). It moves unchanged into
lower/tests/image_refusals.rs, a child of lower's test module, so it
keeps its helpers.
Use FirstbitHi to count the leading zeros in the runtime quotient. A synthetic 11-bit UNORM load emits 60 DXIL instructions, down from 78.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Only its last bit takes the marks of offsets past it; clearing the whole
dword dropped the writes to the 31 pages before it.
The placement of a newer title's extended description is read through the
kernel, so an older title's description at the end of its memory does not
fault.
Remapping title pages under a submission's reads and copy-backs could
fault it; the host's submission lock now covers the remap.
State::rectangles previously evaluated u64::from(first + count) * stride, adding first and count in u32 before widening so overflowing draw arguments could panic in debug builds (or wrap in release). Widen both operands to u64 before adding and check the expanded D3D12_VERTEX_BUFFER_VIEW::SizeInBytes conversion via rectangle_vertex_bounds.
A list's Step::Memory (crate::memory::prepare) was queued once, by bind at the list's first title-memory draw, while a buffer range (defer_refresh) or a heap's views (defer_heap) are queued again after a step that writes title memory. A draw after an in-list copy into a title buffer then read the copy's old bytes through the page table. defer_memory now queues once until a title write (like defer_heap), and State::memory_map asks again on its cached path.
The list's first use of the twin counted as the list's first use of the
texture, so the prelude copied the depth side before the draws that wrote
it.
Use host::write_mapped under watch::writing so CopyMemoryToMemoryX does not fault if pages are unmapped or read-only between the committed check and the copy. Disjoint ranges copy directly in one pass with no temporary buffer; overlapping ranges keep a committed-bounded staging buffer for memmove order.
Any user-data entry at the view-offset dword was taken for a root view's
offset, so a draw reading that constant was dropped.
Share the ballot for the same EXEC predicate within a DXIL block. Two dependent DPP8 instructions emit one ballot instead of two.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every root signature we make indexes both heaps directly
(CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | SAMPLER_HEAP_DIRECTLY_INDEXED), and
the SM 6.6 spec has SetDescriptorHeaps pass "the corresponding heaps"
before such a signature is set. #1778 made bind_heaps bind a sampler heap
of ours when the title binds none, but the view half still bound ours
only when the shaders read title memory or root views: a list with no
view heap whose shaders read only constants set the signature with no
view heap bound (State::wanted([0, 0], false) == [0, SAMPLERS_OURS]).

Such a list now gets our view heap (crate::memory::heap) as well, which
root views and the write-mark table already use when the title binds
none.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`VICTORY_DUMP_SHADER=8bbcbda6008eaa37` (or `all`) writes each named
shader's DXIL to `%TEMP%\victory-<hash>.dxil` as it is translated; `dxc
-dumpbin` reads it as LLVM IR. The pipeline log and the breadcrumb reports
name shaders by this hash, and until now there was no way to see what our
translation of one looks like - which is what a frame spent in a compute
dispatch that asks for 746 tiny groups needs.

Found with it in the prologue: `8bbcbda6008eaa37` (NumThreads 8x4x1) is a
ray march whose exit is a float comparison and whose only other way out is
the loop limit (1 << 20), and `00167d58cc5a78d7` (4x4x4) has no loops and
no barriers at all yet stops the queue - two different causes behind the
same "GPU hang".
The title renders to a 2560x1440 B4G4R4A4_UNORM texture and makes a typed
unordered view of a B5G5R5A1_UNORM one. D3D12 supports neither, and the
debug layer says so while the run is going:

    CreateCommittedResource: A texture that has
    D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET set ... must be created with a
    format that either can be used as a render target, or cast to a format
    that could be

    CreateUnorderedAccessView: The format (0x56, B5G5R5A1_UNORM) cannot be
    used with a Typed Unordered Access View. This is because the current
    graphics implementation does not even support this Format.

    RemoveDevice: DXGI_ERROR_INVALID_CALL

so the run ended a minute after the account screen, in the first scene of
the prologue, with the device removed. (The 16-bit render target's creation
was already failing quietly - `no host texture` - and the unordered view
above removed the device.)

`pc_format` now widens B5G6R5, B5G5R5A1 and B4G4R4A4 (85, 86, 115) to
B8G8R8A8_UNORM (87): the same channel order, legal for render targets,
unordered access and shader reads, and it is the one function resources,
views, twins and pipeline target formats all go through, so they agree. The
title loses the console's 5 or 4 bits a channel, not the picture's layout.

With it the title reaches gameplay and the numbers the frame report then
prints for the first time: 2 555 draws a frame (before: the device was
removed in the loading screen), 3 969 ms a frame, 1 674 draws dropped for
want of a host pipeline, 621 MB of title memory copied and 139 MB of
textures uploaded a frame. That frame's 3.6 s on the GPU is the next
problem - and, being over the 2 s TDR, the next removal.

Found with the debug layer (`VICTORY_D3D12_DEBUG=1`) in a diagnostics
build: `fail()` now drains the layer's stored messages, which name the
call instead of only its code.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	crates/victory-shader/src/emit/valu_tests.rs
The pipeline log says how long a translation took but not who ran it: with
the prologue's cold cache 1 725 translations of ~110 ms each add up to the
20-25 s the first gameplay frame spends, and the question that decides the
fix is whether that is one thread (move it off the recorder) or the eight
pipeline workers (a translator throughput problem). It is the workers:
victory-pipelines-3..7 took 181-288 translations and 18 000-27 000 ms of
wall time each in the same run, so the batch is already spread and the
stall is per-translation cost.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two diagnostics (the `diagnostics` feature only) that answer why a cold
shader cache costs the first gameplay frame 20-25 s:

    shader phases (us): stage=Cs blocks=1542 range=342 resource=99315 io=5255 emit=8126713
    lowering passes: 74 blocks=1542 setup_us=5561 run_us=85672

- a translation is 74 % structurisation/resource tracing and 25 % lowering
  in the aggregate, but the *worst* shaders are lowering: 8.1 s of 8.2 s for
  the biggest one;
- `emit::lower` re-runs the whole lowering once per phi that does not
  settle (`Stop::Retry`): 74 passes for one shader, 222 extra passes over 17
  shaders in a batch of 1 725. At ~86 ms a pass on 1 542 blocks that is
  6.7 s for one shader alone - the whole cold batch is 160 s of CPU across
  eight workers, 25 s of wall.

Nothing changes in a release build (no `diagnostics`): the phases are
`Instant`s behind `cfg` and the pass count is not compiled at all.
Main's #1320 gave `Pending::new` the diagnostics build's shader hashes to
skip; the test passes none, as the module's other tests do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Extract the high dword directly from DXIL UMul or IMul. The 24-bit forms use the same lowering after extending their operands.

Each synthetic shader emits three fewer DXIL instructions and clears its INT64 feature bit. The high dwords match main bit for bit on AMD hardware and WARP.
A command that hangs the GPU cannot be read back afterwards: the
breadcrumbs name it, the record dump (`read_indirect`) needs the list to
have run, and that is exactly what it did not do. The arguments live in the
*host copy* of title memory, though, and the refresh that fills it runs
just before the list: so a deferred step logs the record's dwords at
submission time, from the copy the GPU will read.

    indirect arguments {kind, max, count, dwords, name}

For the two dispatches that stop the prologue (`00167d58cc5a78d7`,
`f607780aa8e502d0`) and whatever the breadcrumbs name next, this says
whether the long loops are fed by huge counts or by garbage, which is the
question the read-back could not answer.

Diagnostics only; nothing runs without the switch.
`VICTORY_GPU_TIMING` gives per-command GPU times only by submitting every
list on its own and waiting for it, which reads ~10x the real frame and
therefore cannot say what a *batched* submission spent its time on. Its
stamps did not help either: every list resolves into offset 0 of its
read-back buffer, so only the list that closed last kept its times.

`VICTORY_GPU_STAMPS` (diagnostics) turns the timestamps on without the
one-list-per-submission mode, and a submission of all lists that takes over
200 ms now reports the two longest commands of every list in it:

    slow host submission ms=...
    slow list 7 command, 918.6 ms: dispatch 8x16x2 [compute ...]

That is the report the loading needs: the frame is 15 s of GPU work with a
batched submission, and nothing could name the command inside it.

Diagnostics only; the release build is unchanged.
268 of those lines printed without a single per-command line, and nothing in
them said why: now they carry how many commands the lists noted and whether
the timestamp heap exists, which is the difference between 'no markers were
recorded' and 'the read-back is empty'.
\Map\ returns the start of a read-back resource, not of the range asked
for, so after every list took its own slot the report read offset 0 - the
slot of whichever list had id 0, or zeroes - and every command came out as
0.0 ms while 7 439 notes and a live timestamp heap were there. With the
slot read, the loading says:

    5251  ms: dispatch 1x1x1 [compute caa78b8ca62bc3d6]
     123.1 ms: indirect kind 2 max 1 [compute 8bbcbda6008eaa37]
     111.2 ms: draw 3x1 [vertex ce57291b5a1750ca, pixel ...]

a single workgroup of 64 threads is what costs the loading its five
seconds, and it is the same 2^20-iteration shape.
The two searches of \caa78b8ca62bc3d6\ exit on \loaded != key\ and the cap
is the only other way out; whether the key is missing from our copy or the
comparison is wrong needs the values, and those live in title memory that
the shader reads - not in anything a read-back can report after the hang.

With \VICTORY_DUMP_VIEWS\ (diagnostics) and \VICTORY_TRACE_SHADERS\ naming
the shader, every constant or placed buffer view its pipeline binds has the
first sixteen dwords of its copy logged at submission, after the refresh
that fills it.

First run printed nothing for that shader, so it binds its data some other
way (root views or user data rather than tables) - the next step is to log
which kind it does use.
The 6 s dispatch of \caa78b8ca62bc3d6\ binds neither a descriptor table
(nothing printed) nor a root view (nothing printed either): its only
bindings are the user-data dwords, which are now logged at submission -

    traced user data [compute caa78b8ca62bc3d6] user_data=[... 18816, 4294966592, 768 ...]
    traced user data [compute caa78b8ca62bc3d6] user_data=[... 27520, 4294966208, 1024 ...]

6 005 lines in one loading run, and the values are small and structured
(an offset, a negative offset, a size: 18816 / -2048 / 768), not garbage.
So the table the two searches walk is *title memory* (the page-table path),
which puts the memory refresh and its withhold/miss accounting next in
line.
The copy-list fence precedes Present. On a size or format change, signal the presentation queue again and wait before DXGI releases the old back buffers in ResizeBuffers. Keep the wait inside the resize retry so unchanged frames continue as before.
The title's 3 444 host copies of its memory span more than 1 030 distinct
256 MiB regions of its address space, while `CAPACITY` gave a list's page
table room for 512 - "the world's ~4 100 copies use a few dozen", which held
for the world and not for this title. Every region past the cap reads as
absent, and the diagnostics said so plainly:

    title memory this frame: 18 447 withheld and 1 098.1 MB of views kept,
    missed 120 539 pages and 23 256 MiB regions with no copy

A compute shader that searches a table in that memory then reads zeros,
never matches its key and runs its loop to the 2^20 cap. The one that cost
the loading its five seconds is `caa78b8ca62bc3d6` (64 threads, three nested
loops), and with the capacity raised it does not appear in the slow-command
report at all:

    before, CAPACITY 512 : dispatch 1x1x1  [compute caa78b8ca62bc3d6]  6 012.2 ms
    after,  CAPACITY 2048: (below the report's threshold)
    loading run, no VICTORY_SKIP_PIPELINES and the default loop limit:
        120 world frames, 0 device removals, the full 420 s window
        frames 1.8-2.6 s: GPU 1.2-1.7 s, copies 137-240 ms / 1.4-2.0 GB

Until this, the prologue only ran with two dispatches skipped or with the
loop limit cut to 1024 (both diagnostics); with the capacity raised it runs
on an unmodified build.

Cost: a table is `(CAPACITY + 1) * 32 KiB` beside the level-1 entries, so
67 MB instead of 17 MB per table, and the run keeps one or two of them.
Raising it further only helps the remaining 6-19 regions and grows linearly,
so the next change there is to allocate level-2 blocks per submission for
the regions a submission's views reach, not a bigger constant.

The corpus A/B is unchanged, as it must be - the translator is not touched:
25 889 per-program outcome lines, 0 differences, 47 s. cargo test --release
--workspace: 30 suites, 0 failures; clippy -D warnings clean with
diagnostics.
WriteFile only promises atomicity for a single sector, and a crash
record spans many: another reporter can write between its bytes even
with FILE_APPEND_DATA, and under Wine the concurrent-records test saw
it happen. Each record is written in one append under a process-local
lock. A handler never waits on it for long, since an exception may come
from the thread that holds it: one that cannot take it still writes, as
a rare interleaving beats losing the report.
This reverts commit 1e53e9132e.
Three prologue compute pipelines read a *root view's* offset while the title
had bound that root as 32-bit constants, and every such draw or dispatch was
dropped:

    dropped 1-2.4/frame without a host pipeline:
      dispatch: a root view's offset: no root view, or outside title buffers
      [compute 35e51bb27a463294], [compute f94e5d8bf4e1cf05], ...

A diagnostics count of the two halves of that reason says which it is: over a
whole run, `no_view` fires and `no_copy` never does - the slot holds
`Root::Constants(...)`, not `Root::View(...)`. The console lets a title pass a
descriptor itself as root constants, and the ones here hold their buffer's
address in dword 0 (`Constants([1915200512, 13, 0, 0, 190980448, 16, 8, ...])`).

`State::root_address` now answers "the title address this root stands for" for
both forms: the view's address, or the first dword of the constants when that
address lies in a host copy (`shadow::find`), and `root_view_at` binds the view
at that address exactly as it did for a view root. When the address is in no
copy the old drop stands, so nothing is invented.

Measured on the prologue scenario (play driver, 560 s window, diagnostics):

    before: 2.4/frame dropped for this reason, run ends on the title's int3
    after:  0 dropped for this reason
    after, with the diagnostic loop cap 1024 (so the unrelated 5-6 s loop
    class does not end the run first): 208 world frames, 0 device removals,
    0 drops, the whole 560 s window, no title exception

The visible checkerboard patches in the credits frame are the shape this
should fix; the fix is not yet shown to remove them (the run above has no
screenshots), which is the next check.
In Held::pump, Item::Signal flushed the accumulated piece on the current queue before running, while Item::Segment (with non-empty ValueWaits) and Item::FenceWait evaluated their wait conditions while earlier segments on the same queue were still unexecuted in piece.

Because an earlier segment on the same queue can modify the waited memory (via Write32/64BitValueBottomOfPipeX, GPU writebacks, or direct writes to fence::gpu_address), evaluating a wait against stale pre-segment memory caused two bugs:
- A wait after a segment that clears or rewrites a previously satisfied flag read the stale value, erroneously passed, and batched the waiting segment into the same host submission instead of holding it until a peer queue satisfied it.
- A wait satisfied by an earlier segment on the same queue initially read the stale value, falsely marked itself blocked, and recorded a spurious wait entry.

Flush any pending piece before testing non-empty ValueWaits on Item::Segment and before testing Item::FenceWait. Consecutive wait-free segments continue to batch into a single host submission.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A refusal carries `at 0x14dc`, and until now the offset was all it said: the
program is 12 000 words of native code and the instruction at that offset was
the one thing the message did not have. It has it now, in the same line:

    bvh_skinning:CSComputeSkinningPedBlendShapesVelocity_1c34db0a_Wrapped Cs
      at 0x14dc  [s_cbranch_execz Sopp { imm: 92 }]  emit: a lane mask read as data

That names the prologue's remaining functional hole instead of hinting at it:
four programs of the whole pack (`CSComputeSkinningPedBlendShapes`,
`...SecMotion`, `...Velocity`, `...SecMotionVelocity` - the character skinning
with blend shapes) fail on the same opcode, and the one the prologue binds
(`compute 82a2ad6d07417d36`) is dropped 4 times a frame in the interior scene
that the play run then stands in for four minutes. The other three shader
families that refuse at an offset get the same line for free.
A program's refusal is usually not the instruction the message names: the
emitter gives up on an instruction, marks its writes missing and goes on, so a
branch can report a reason that came from something dozens of instructions
earlier (the prologue's character skinning reports `s_cbranch_execz` at
0x14dc while the first thing it cannot do is a mask copy at 0x5c).

Two switches for that:

- `VICTORY_ONLY=@0x<offset>` (`translate --list`): translate only that
  container, so one program's log is its own;
- `VICTORY_TRACE_FAILS=1`: log every instruction the emitter gives up on, with
  its offset, block, reason and reads.

Together they give the ordered list, which is what says where to look:

    FAIL s_setreg_imm32_b32 at 0x1c (block 0): a register the emitter does not model
    FAIL s_mov_b32 at 0x5c (block 1): a lane mask read as data reads [(S(126), Value(8))]
    ...

Both are read at run time only, so a normal run pays nothing.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
`sop()` refused every scalar instruction whose destination is a lane mask -

    if inst.write(Reg::S(EXEC)).is_some() || self.is_mask(lo) {
        return Err(LANE_MASK);
    }

- so a program that copies exec before its first branch was refused at that
branch, and the whole pipeline was dropped. That is the prologue's character
skinning with blend shapes (`CSComputeSkinningPedBlendShapes`, `...SecMotion`,
`...Velocity`, `...SecMotionVelocity`), dropped four dispatches a frame in the
scene where the play run then stands still.

Now the op lowers the mask the structure already has for what it writes,
instead of refusing. Three details make it hold:

* only the writes the structure names as masks get a bit; a write it does not
  name (the saved exec of an `s_and_saveexec`, a register the compiler reuses
  for data) carries the destination's mask, because the branch that follows
  would otherwise read a value with no definition at all;
* a phi registered while such an evaluation runs is *lenient*: an edge the
  structure cannot name gives it no lanes instead of failing the program, so
  `a_scalar_result_needs_no_exec` (a copy of exec that only guards a
  `v_readlane`) keeps translating;
* every other mask join keeps its refusal, so a mask holding lanes off its edge
  joined with data still does not translate
  (`a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there`, second half).

Measured over the whole shader pack (`translate --list`, 26 084 programs),
against a baseline taken with this change stashed:

    before 25889 program lines, after 25889
    only before: 4   only after: 4      (the same four, now emitted)
    compute programs 2658 -> 2662

Nothing else changes. `cargo test --release --workspace`: 30 suites, 0
failures; clippy `-D warnings` clean.

`lower.rs` is at the repository's 512 KiB asset-policy limit, so the two new
methods live in `emit/lower/masks.rs`.
`VICTORY_KEYS=<seconds>:<key>` held each key for 200 ms, which is enough for a
menu press and not for walking. The entries now take a third field, the hold
in milliseconds:

    VICTORY_KEYS=200:W:6000,215:A:1200,10:Enter:300,20:Enter:300

Both the keyboard device and the stand-in pad see the keys (the HLE merges
them in `poll`), so a run can be driven while the title's window stays in the
background: nothing calls `SetForegroundWindow` or `keybd_event`, and the
person using the machine keeps their focus. Enter is the pad's A and W the
left stick up, so the account screen, the menu and walking all work this way.

First run with it (`nofocus`): the title reached the world without any window
activation - 1 862 draws/frame at 153 s, 4 657 at 196 s - where every earlier
driver had to attach to the window's input queue and steal focus at 15/40/70 s.
Translated shaders clamp heap indices below `HEAP_VIEWS` (1 000 000), so a
heap shorter than that lets the clamp name a slot the heap does not have. The
small-dynamic-range path still asked for `count + MIN_DYNAMIC` with no floor:
800 000 title views made an 865 536-slot heap, and every index in
865 536..999 999 was out of bounds (review on #2683, from a title count of
737 856..934 463).

The layout decisions are now two pure functions, so the boundaries can be
checked without a GPU:

* `capped_layout(count)` - `Some((slots, dynamic))` when the title's slots
  plus even the small dynamic range do not fit `HEAP_VIEWS`: the capped
  layout, taken on **every** host including tier-3 ones whose heaps are
  larger, so the layout (and the clamp's bound) is the same everywhere and the
  null buffer views keep the top of the heap;
* `small_request(count, views)` - `(count + MIN_DYNAMIC).max(views)`, the heap
  a host that refuses the large dynamic range is asked for: never below the
  clamp.

Tests: `the_capped_layout_and_the_small_range_fit_the_clamp_shaders_use` pins
the review's counts (737 856, 800 000, 934 464 fit; 934 465, 1 000 000,
1 050 000 take the capped layout, whose `slots + dynamic + NULL_RESERVE`
closes inside `HEAP_VIEWS`) and fails on the previous expression (checked by
putting it back: "a heap of 65536 is short of the clamp 1000000");
`a_heap_has_every_slot_shaders_clamp_to` checks the same invariants on a real
host's heap, and skips where no heap can be made.
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
`watch::open_runs` took each page out of `Guards::protected` *before* asking
the kernel for write access, and ignored what the call returned. A page that
only left the set that way is read-only for good - no tracker holds it any
more, so nothing opens it again - and the title's next write there faults with
no guard to take it (review on #2848: reproduced in-game under Wine,
`crashbashash`).

Now the set changes only after the protection is off, and a run the kernel
refuses - a range crossing two allocations, 487 on Windows - is retried one
page at a time, the pages it does open leaving the set and the rest staying
in it for the next take (or the fault handler). How many opened is logged when
some did not, and counted in `copystat`'s "pages opened".
`Shadow::writing` inserted into `pending` and then bumped `pending_len` after
the mutex was already released; `copy_back` reads that count to decide whether
the fast path (nothing pending) applies. A reader could therefore see 0 while
a range is in the set, take the snapshot path without it, and the count could
drift below the set's size - the review's "underflow or a missed insert".

The bump is now inside the lock the set moves under, the add/sub use Release
and the load Acquire: the counter is a hint, and a hint has to be published
with the set it describes.
The batched report named two commands a list, and only for submissions over
200 ms, so a frame's ~350 commands were ranked by their two longest - which is
why the biggest pipeline looked like 44 % of the frame when it is 7 %.

Two switches now say how much to list and when:

    VICTORY_GPU_REPORT=40           commands per list (default 2)
    VICTORY_GPU_REPORT_MIN_MS=250   submission length that triggers it (default 200)

With 40, a 1 150 ms submission lists 354 commands summing to 1 144 ms, i.e. the
report accounts for the submission's whole time. On the prologue's frames it
gives the family table the next optimization needs - no single shader:

    indirect 25ebc92075b62822   2 453 ms   (an indirect draw: geometry)
    dispatch 39f0e9aeb156a61c   2 019
    indirect 7a071f906f98311b   1 749
    draw     05e958b19269d596   1 126
    dispatch 5cf00dc39042edaf     538
    mesh     04b9be3756e8f41c     475

over the sampled submissions, each family 200-600 ms of a ~3 s frame: geometry
and compute in similar measure, not one bad pass.

Diagnostics only (the switches are read at run time, nothing changes without
them); clippy `-D warnings` clean, `cargo test --release -p victory-gpu` 231
passed.
resource::alias_source previously looked up a GPU-written aliased texture under TEXTURES_AT, dropped the Arc<HostTexture> and lock, and returned a raw *const Object (This) with no COM reference. If another thread legally called ID3D12Resource::Release() on the aliased source texture before texture::alias_copy ran, alias_copy dereferenced the freed Box<Resource> (or a recycled allocation at the same address) in resource::host_resource and list::ensure_state.

Return Option<Arc<HostTexture>> cloned while holding TEXTURES_AT, route pinned host-texture transitions (including depth twins) through HostList::transition_copy and list::ensure_copy_state, and pin the destination HostTexture once inside texture::alias_copy so concurrent eviction cannot split destination identity across GetDesc, host_writes, state tracking and CopyTextureRegion.
`memory::prepare` ran once per list that binds a title-memory view heap,
per submission, and asked `watch::clean_bit` once per copy the layout
names — about 4,700 in the world, nearly all clean — so a submission of
tens of lists paid hundreds of thousands of single-bit loads a frame.

The layout now keeps its copies' tracker bits as `(bit, index)` pairs
ordered by bit plus the words they span, and `dirty_indices` walks the
tracker a word at a time with `trailing_zeros`, asking only for the
changed bits. A layout costs the words its bits span (~74 for 4,700
contiguous bits) instead of the copies, and the set of copies handed to
`add` is exactly the one the per-copy loop found.

Arithmetic, not a title measurement: ~4,700 loads at ~4 ns becomes ~74,
i.e. ~19 µs to ~0.3 µs per list per submission; the frame line's
`StepMemoryUs` counter already reports the total, so a run with this merged
shows it directly.

Verification: `cargo clippy -p victory-gpu --all-targets --locked -- -D
warnings` and `--all-features` both clean; `cargo test -p victory-gpu --lib
--locked --no-fail-fast` 231 passed, 2 failed — both the known Intel
baseline failures pristine main also fails (#1744/#1829). New test
`memory::tests::the_dirty_scan_finds_each_changed_copy_once_in_tracker_order`
covers order, clean trackers, foreign bits in the same words and an empty
layout. `rustfmt --edition 2024 --check` hunks against main: memory.rs 30/30,
watch.rs 39/39.

Synthetic tests only; no game data.
Every indirect command is clamped by a compute dispatch between two global
unordered-access barriers, and the world runs 2 600 of them a frame - so the
barriers are a candidate for a large part of a frame. Measuring them needs an
A/B that keeps the commands running, which `VICTORY_NO_CLAMP` could not: it
returned `None`, the command was dropped, and the run then compared a frame
with 5 018 indirect commands against one with none.

Two switches replace it, neither changing anything unless set:

    VICTORY_ONE_BARRIER=1   after the clamp, only the transition out of
                            unordered access (which already flushes that
                            buffer) - the global barrier after it ordered
                            nothing the command needs;
    VICTORY_NO_BARRIERS=1   both global barriers gone: the ceiling of what
                            they cost together, for the measurement only (the
                            title's writes then need not be visible to the
                            clamp).

`VICTORY_NO_CLAMP` is removed: it measured a different program.

No numbers claimed: the A/B was started and stopped early (base 47 and 13 world
frames, one-barrier 3), so nothing here says the change is faster. It says how
to find out.
Every world frame of every run so far reports the same three numbers:

    0 pages copied back, 20 000-31 000 withheld, missed 70 000-112 000 pages
    and 27-50 region marks with no copy (first: 0x740000000 0x750000000 ...)

`copy_back` withholds *all* of a frame's write-backs as soon as one page of
title memory was read by a shader with no copy (`withholding()`), and that is
the state of every frame: the title reads 0x740000000-0x780000000 - a gigabyte
with no host copy - so

* the title's memory never receives what its shaders wrote, and the host copy
  the title's own reads are answered from (and that a refresh pushes back) is
  what the GPU wrote a while ago or never;
* the per-frame work is real: 100 000 page marks read back and walked, 20 000
  pages dropped, every frame.

Whether that is what keeps the game from advancing (the prologue's first scene
waits for input and never moves on) cannot be told from the logs. The new
switch copies back even while pages are missing, so one run says it:

    VICTORY_ALLOW_COPYBACK=1

Diagnostics only: the rule above is unchanged unless the switch is set.

No behaviour change and no numbers claimed.
Every world frame reports thousands of pages of title memory a shader read
with no copy (`memory`'s frame line), and the first four addresses have been
the same four gigabyte-apart regions for every run - so the next question is
what those addresses are, which the line could not say.

`shadow::describe(address)` answers it: the registered title buffer that holds
the address and whether a copy of it was made, or how far the nearest
registered buffers are. The first four missed pages of a frame log it at
`debug`:

    title memory a shader read with no copy page=0x740000000
        what="no registered title buffer at 0x740000000; nearest below ..."

That separates "the title never registered a buffer there" (a use we do not
translate into a buffer access at all, so no copy exists to make) from "the
buffer is registered but its copy was never made or was released".

Diagnostics only, no behaviour change, no numbers claimed.
A save serialised the whole library - over 600 MB once the world's
pipelines are in it - and wrote it in one piece every SAVE_EVERY, even
when a run added a handful of pipelines. The host can only serialise a
library whole, so the only way to write less is to keep less together:
the library is now SHARDS files, and a pipeline always lands in the same
one, because its name is a hash.

A save serialises and writes only the shards that gained pipelines, with
the pre-build's list kept per shard beside the bytes it holds for. Two
things the review of the previous revision asked for are kept: the SAVING
lock spans serialising and publishing, so two saves cannot publish an
older snapshot over a newer one, and a shard's dirty flags are cleared
only after its bytes are published, by what was serialised - a failed
write leaves the shard for the next save, and a store during the write
keeps it dirty.

Synthetic control, 16 MiB payload, one/4/16 dirty shards (aycow):
1.56/5.59/24.15 ms against 8.21/7.85/8.55 ms for one blob. Sharding wins
in the steady state - one to four dirty shards - and loses when every
shard is dirty, which is the first run after the upgrade.

cargo test --workspace --locked; both clippy configurations with
-D warnings; cargo xtask policy.
A save snapshots a shard's prebuilt keys, releases the lock and writes the
files. A key recorded while it writes was not in the file, but clearing the
flag by "was it set at snapshot time" marked it saved anyway, so the next
save skipped the shard and the published list never gained the key.

Acknowledge only what was published: the shard stays dirty when its key
count changed while the write ran. `save_shard` is split out so the race is
testable, and the regression test injects a key from inside the write - it
fails on the old check and passes on this one.

`USED_CHANGED` had the same shape, so the early list is acknowledged the
same way: a generation counter bumped by `note_used` decides whether the
list that was written is still the whole list.

Fix and regression test by andrewpozdnakov7-jpg, from the analysis on #1653.

Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
Use CopyTextureRegion on subresource 0 instead of CopyResource for single-plane PresentX so mipmapped and array textures present without D3D12 error #944 or WARP process abort.

Route format-converting planes (such as R16G16B16A16_UNORM/SNORM into R16G16B16A16_FLOAT) through the compositor and resolve plane SRV formats without casting across incompatible float/UNORM types or passing typeless/unsampleable formats (such as B8G8R8X8_TYPELESS or integer overlays) to CreateShaderResourceView.
The branch was 160 commits behind, and three of them change this file. The
rebase could only go through by taking this side of `pipeline/library.rs`
whole, which dropped them - so they are ported onto the sharded code here, one
per section:

* `zeroed(n)` (`321a4bc1`, Kevin Pratap): a shard's serialise buffer is
  reserved fallibly. A shard holds each pipeline's machine code (about 1.7 GB
  in all on NVIDIA after `--cache --pipelines`), and the infallible
  `vec![0u8; size]` aborted the process mid-run ("memory allocation of
  2650101862 bytes failed"). Without the memory the shard stays dirty and a
  later save writes it.

* lock-free loads (`555c112e`, winne42): each shard keeps its interface a
  second time (`Shared { loads, state }`), and `pipeline` loads through that
  one without taking the lock a save holds while it serialises a shard.
  Before this, a load cloned the interface under the lock, so every load of a
  shard waited out its save (230-600 MB in the world). Ported with its test:
  `a_pipeline_loads_while_a_save_holds_the_library` holds a shard's lock and
  requires a stored pipeline to load anyway (30 s bound), which the cloning
  version fails.

* the ordered early list (`e9ea9a45`, Danilo Mori Schuler): `Used::before` is
  a map from key to its place in the list as loaded, and `Used::list` sorts by
  it, so a full list drops the *oldest* runs' keys rather than any of them (a
  set gave no order to drop by); a list saved by an earlier build, in no
  order, still reads. `the_early_list_keeps_this_run_first` now asserts both
  ends: the most recent earlier key is kept and the oldest is the one that
  made room.

This branch's own two races stay as they were: a save acknowledges only what
it snapped (`d09b71bf`), snapshot and publish are one transaction under
`SAVING`, and the early list is published with a generation check.

Verification: `cargo test --release -p victory-gpu pipeline::library` - 11
passed (both GPU tests among them); clippy `--all-targets -D warnings` clean.

Co-authored-by: Kevin Pratap <[email protected]>
Co-authored-by: winne42 <[email protected]>
Co-authored-by: Danilo Mori Schuler <[email protected]>
Reviewer on #3248: copies with no tracker bit (untracked memory, or a full
bit pool) have `dirty_bit() == None`, and `clean_bit(None)` is false — never
clean — so the old per-copy loop asked for them every time. Building
`by_bit` with filter_map dropped them, which would have treated them as
permanently clean and stopped refreshing them.

`Layout` now keeps those indices in `untracked`, and `prepare` asks for them
unconditionally before the word-at-a-time scan of the tracked ones.
`dirty_indices` also returns before reading any word when `by_bit` is empty.

Synthetic tests only; no game data.
`is_translation` decided whether a directory in the cache is one this crate
wrote by looking for `host-pipelines.bin`. #1653 splits that library into
`host-pipelines.NN.bin` shards and drops the single file, so the two changes
read each other's directories as foreign: pruned ones would never be pruned,
and with #1653 first this file does not even compile (`LIBRARY_FILE` is gone).

`library_in(dir)` accepts either, and the pruning test writes the file by its
name, so this lands the same way before or after the split - checked by
merging the two branches and running `cargo test -p victory-gpu pipeline::`
(24 passed, both the shard tests and the pruning test among them).
Co-authored-by: LooperSalty <[email protected]>
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
UnregisterAppStateChangeNotification and UnregisterAppConstrainedChangeNotification previously only removed the registration from the vector while end_title dispatched cloned snapshots on a background thread. A title freeing callback context immediately after unregistering could hit a heap use-after-free from either an in-flight invocation or a stale snapshot entry not yet started (including suspend callbacks unregistered during the constrained phase).

Track registered entries and in-flight (id, ThreadId) invocations behind a shared Notifications mutex+condvar, re-checking each entry before invoking it and waiting in unregister for any in-flight call on another thread to return via an unwind-safe RAII guard while allowing same-thread self-unregistration without deadlocking.
Nine switches were added by the prologue work and none was in the table a bug
report is written from: `VICTORY_GPU_STAMPS`, `VICTORY_GPU_REPORT` and its
`_MIN_MS`, `VICTORY_DUMP_SHADER`, `VICTORY_DUMP_ARGUMENTS`,
`VICTORY_TRACE_FAILS`, `VICTORY_ALLOW_COPYBACK`, and the two clamp-barrier
measurements (`VICTORY_ONE_BARRIER`, `VICTORY_NO_BARRIERS`).

They are the ones a report like the prologue's device removal needed: the
pipeline log names a shader hash and `VICTORY_DUMP_SHADER` gives its code; the
attribution of a 3 s frame needs the whole command list, not the two slowest
commands of it; and "why does this shader not translate" is `VICTORY_TRACE_FAILS`
rather than guessing from a dump.

Rows only, no behaviour change.
# Conflicts:
#	apps/victory/src/run.rs
`shadow`'s copies of title memory live in system memory (`Host::shared_buffer`
is a `CUSTOM`/`L0` buffer): the title's memory is host memory, so the copy is
something the CPU refreshes and compares, and every shader read of it crosses
PCIe. On the console the same read is GDDR6. The one experiment so far
(`VICTORY_COPIES_IN_VIDEO_MEMORY`) put them in a `GPU_UPLOAD` heap and measured
*worse* (3 196 -> 4 289 ms a frame in the world): that is a BAR window, not
video memory.

This is the mechanism for the other arrangement, small enough to review on its
own and not wired into the frame path:

    VramCopy::new(len)                    a buffer in D3D12_HEAP_TYPE_DEFAULT
    upload(list, offset, bytes)           staged now, copied when the list runs
    read(list, offset, len) -> Read        a readback after the list ran
    gpu()                                 the address a shader reads

Nothing is committed to using it yet - `#![allow(dead_code)]` and the module
doc say where it plugs in (`Shadow` gaining an `Option<VramCopy>`, `Batch::flush`
staging instead of memcpying, `Shadow::copy_back_page` reading through `read`).
Landing it separately means the integration PR can be a measured before/after
rather than a rewrite nobody can A/B.

The tests are the semantics the integration depends on (and they are what found
the one non-obvious rule):

* `uploaded_bytes_reach_a_shader_and_its_result_reads_back` - bytes the host
  stages arrive at a shader that reads the copy by GPU address, and the
  shader's result reads back;
* `what_a_shader_writes_reads_back` - what a shader writes is what the
  write-back path would see;
* `two_ranges_in_one_list_do_not_overwrite_each_other` - staged ranges are not
  shared behind the caller's back;
* `a_range_past_the_end_is_refused`, `a_copy_is_whole_pages`,
  `an_upload_reads_back_without_a_shader` - the edges, and the copy path with
  no shader in it at all.

**What the tests found:** a copy from `COMMON` is not ordered against a shader
access on either side of it. The first version of `upload`/`read` copied from
`COMMON` and the readback came back zeroed - the shader read the buffer before
the copy landed. Both now enter and leave an explicit state
(`COMMON -> COPY_DEST -> COMMON`, `COMMON -> COPY_SOURCE -> COMMON`), which is
the same shape `capture.rs` uses for its readback and the reason its comment
says a title buffer's copy, never transitioned, is only ever read.

Verification: `cargo test --release -p victory-gpu` - 237 passed, 1 ignored
(the new six among them); clippy `--all-targets -D warnings` clean on `main`.

No frame-time claim: nothing in the frame path changes here.
A synthetic measurement, no title involved: the same copy of 128 MiB read by a
compute shader, once from video memory (`VramCopy`) and once from the system
memory `shadow`'s copies live in today (`Host::shared_buffer`), with two
access shapes - a stride-1 scan and a random 16-byte line a thread - one 16-byte
read a thread and no stores, so the timing is the reads.

Measured here (RX 9070 XT, shared machine, best of three, ten dispatches a
list):

    128 MiB read        video     system    ratio
    stride-1 scan      3.829ms    4.021ms   1.05x
    random lines      56.301ms   57.100ms   1.01x

Earlier shapes agreed before the parallism was raised (1.21x / 1.04x), and the
one in-game experiment that exists - `VICTORY_COPIES_IN_VIDEO_MEMORY`, a
`GPU_UPLOAD` heap - measured *worse* (3 196 -> 4 289 ms a frame).

So: on this machine, putting these copies in video memory does not make
shader reads faster, in either access shape. Two readings of that, and both
matter before anyone writes the integration:

* either the reads are not what the frame spends its time on (then variant A
  would have bought nothing, and the frame's cost is elsewhere), or
* the `CUSTOM`/`L0` copies already come back at PCIe speed on this machine
  (~32 GB/s measured) and video memory has no headroom left to give.

Either way the number that decides the integration now exists, and it says no.
The unit stays (its own tests hold the mechanism), and this test is the record
of why it is not wired in - and the thing to re-run on a machine whose result
differs.

Verification: `cargo test --release -p victory-gpu` - 238 passed, 1 ignored;
`clippy --all-targets -D warnings` clean.
Whether a frame draws the scene several times over is not visible from the
draw count: the world reports 5 000-10 000 draws a frame for a prison cell,
which is a few hundred on a console, and the frame line said nothing about
what those draws cover. `take_work` counts, per frame, vertices
(`DrawInstanced`), indices (`DrawIndexedInstanced`), dispatch threads
(groups x 64) and mesh groups (x 128), and the report logs them:

    work a frame: 96 000 vertices, 74 000 indices, 734 000 dispatch threads,
                  5 700 mesh groups

The counters are the two atomics a draw already pays (`DRAWN`); the line is
printed by the diagnostics report, beside the draw count and the dropped ones.
Indirect records are not counted here - their arguments are read out by
`VICTORY_DUMP_ARGUMENTS`, which names the work per record.

No behaviour change; the numbers are what the next run is for.
Match depth_stencil_desc's D3D12 BOOL semantics for StencilEnable (c[3] != 0) instead of checking c[3] == 1, and cover non-1 non-zero values (2 and u8::MAX) as well as 0 in stencil_write_mask_requires_a_reachable_op.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two arms with it set (ncb1/cb1 and cb2 in one A/B) died before the world:
`0xc0000005` reading `0x8` and `0x80000003`, both in the title's own image, and
both arms without it ran 6-7 minutes each with 0 removals and 0 exceptions.

That is what the rule beside it already said in words - a list that computed
from zeros hands the title garbage pointers - so the switch is documented as
the demonstration of that, not as something to use.

Measured on the same driver, same scene, 240 s arms: withholding is not what
keeps the game from advancing; the missing copies are the problem, and the
switch shows fixing it the wrong way round breaks the title.
The merged PRs grow lower.rs from 520 563 to 544 760 bytes; the asset
policy test refuses files past 524 288. #3097 does the same move but
conflicts with the merged set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:17:58 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3327/head:github-bot/gh-3327'
git switch 'github-bot/gh-3327'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3327'
git switch 'github-bot/gh-3327'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3327'
git switch 'github-bot/gh-3327'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3327'
git switch 'main'
git merge --squash 'github-bot/gh-3327'
git switch 'main'
git merge --ff-only 'github-bot/gh-3327'
git switch 'main'
git merge 'github-bot/gh-3327'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3327
No description provided.