[pr-fix][shaders][NVIDIA][RAYTRACING] Constant reads stay inside real constant buffer views (LDC device losses) #292

Open
Pipodi wants to merge 3 commits from Pipodi/Darner:pr/nvidia-constant-reads into main
First-time contributor

Refs #84

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: hardware RT device losses on NVIDIA with nvlddmkm event 13 in the System log, Graphics SM Warp Exception ... Invalid Constant Address LDC, then event 153; the game reports 0x887A0006. Aftermath dumps 0xc43ad96c52d44542 (dxil:1275, the one in #84) and 0x455825034071ee88 (mesh programs of an ExecuteIndirect batch), plus one in the tiled shadow cascades compute. The evidence is in my comment on #84.

On NVIDIA a constant load (LDC) through a descriptor that is not a constant buffer view with bytes, or past the view's size, stops the card. The console reads zeros there. darner issued three kinds of such reads:

  1. Constant reads through slots holding no constant buffer view. The indirect mesh draws read the title's heap slots directly (the host builds no table for them), and the faulting entries held a null texture view or a buffer view. The translator now reads a descriptor-table entry as a constant buffer only where the host's slot word (SLOT_STRIDES) says VIEW_CONSTANT, a new value (stride 0, VIEW_SIGNED alone, which no buffer view has); zeros otherwise. This covers the scalar and per-lane paths, and descriptors chosen by control flow among table loads. Switch: DARNER_CBV_SLOT_GUARD (on; 0 restores the old reads).
  2. Inactive lanes and rows past 4095. A per-lane constant load runs for every lane; lanes the instruction does not run for read at whatever their address held (row 4095 of a 768-byte view in the shadow dump). Those lanes now read row 0, and rows past 4095 read row 0 and give 0 (a static row past 4095 gives 0 with no load). Addresses that wrap past u32::MAX read 0 too. Switch: DARNER_CB_ROWS (on).
  3. The host's word over views it had not made. A constant view the title writes into a slot waits for a draw's table to name it, and shows a null stand-in until then; mirror_inner still wrote VIEW_CONSTANT for it, so (1) alone did not stop the read (the 0x455825034071ee88 loss, on row 0). The word now follows the made view, in both DARNER_VIEW_START_REMAINDER modes, is cleared before the descriptor changes, and a 0-byte view never gets it. Constant views made for dynamic tables (constant_at_with_base, constant_raw_at) write it.

Both switches are in the shader cache's KEYED list, and README rows document them.

Not in this PR, and noted for review:

  • The ResourceHeap pick path (lower.rs, descriptors picked straight from the resource heap) still reads stride-0 slots with no guard.
  • With DARNER_PORT_CBV=1 (off by default), constant_twinned can show a null view for a made one and still get VIEW_CONSTANT.
  • This does nothing for the traceless 0x887A0005 losses (empty breadcrumbs, no driver event, no dump) discussed in #84. On my card those stopped with the 2 GiB shader-heap profile (darner nv-profile), but others report they don't.

How it was tested

  • Tested revision: d91b0992 (on 53817d27, 914fceff) on main f3840d73. The game runs were on 53817d27; d91b0992 changes only reads at addresses that wrap past u32::MAX (unit-tested). The same fix ran earlier as part of a local investigation branch.

  • Commands and results:

    • cbv_loads_of_inactive_lanes_stay_inside_the_view (new): lane 0 reads byte 16 of a 256-byte CBV, the other lanes skip it holding byte 0xfff0. With DARNER_CB_ROWS=0 (the old load) this lost the device on the RTX 4090 ("device removed", nvlddmkm event 153); with the fix it passes on the 4090 and WARP. On WARP or AMD the old load passes too, so on a runner without an NVIDIA card it only checks the result.
    • cbv_reads_that_wrap_past_u32_max_read_zeros (new): a scalar and a per-lane dwordx2 at 0xfffffffc and a halfword at 0xffffffff read 0, row 0 beside them its bytes. Without the wrap fix it reads 0x1111/0x1100 on the RTX 4090.
    • cbv_loads_read_zeros_where_the_slot_word_is_not_a_constant_view (new): slot word 0 gives zeros on every backend (with the guard removed lane 0 would read 0xabcd).
    • constant_views_not_made_do_not_publish_a_constant_word and constant_buffer_views_of_no_bytes_have_no_constant_word (new, host): pass with DARNER_VIEW_START_REMAINDER at its default and at 0.
    • Existing table-CBV tests pass the slot word: cbv_byte_and_halfword_loads_read_the_addressed_bytes, table_constant_buffers_read_as_raw_bytes_through_their_twins. All five shader tests pass with DARNER_CBV_SLOT_GUARD on and at 0.
    • cargo test -p darner-gpu --lib descriptor:: shader_cache: 163 passed, 2 ignored.
  • Changes a default: yes, for every card (both switches are on). The reads it changes only gave zeros on the console; on AMD they read whatever the descriptor held; on NVIDIA they lost the device.

  • A/B result: RTX 4090, Series X profile, 2560x1440, DLSS quality, frame generation 3x, hardware RT, the same route from a new game, through the point a few minutes in where these losses came, and on.

    A (before) B (with the fix)
    runs 12-03/04: about 3 of 4 runs that reached that point lost the device there, each with the LDC event 4 runs since the complete fix: 3 on the older base (2 ended in the traceless 0x887A0005 before the shader-heap profile; 1 ran ~8 min with it), 1 on 53817d27 (7 min preload, then ~23 min of play)
    LDC events every loss of this kind 0

    The ~8 min run and the run on 53817d27 both ended in a process exit with no log line, dump or Windows record, with the PC nearly out of RAM (1-2 GB free of 32). I treat that exit as a separate problem and am looking at it (#301).
    Speed: not measured. Each guarded read adds a slot-word load and a branch, and shaders with table CBVs now bind the slot-word SRV. No frame-time A/B yet.

  • Gates run on 914fceff: all three, on Windows (there is no CI). On d91b0992: gates 1 and 2 clean, policy ok, darner-shader lib tests 559 passed / 1 known failure (below); gate 3 not rerun in full (darner-shader only).

    • Gate 1 cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
    • Gate 2 cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.
    • Gate 3 cargo test --workspace --locked --no-fail-fast -- --skip oracle64 (oracle64 left out: its exhaustive loops run for hours in a debug build): 3,345 passed, 2 failed, 121 ignored. Both failures also fail on main f3840d73 without this change:
      • emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders (DXIL validation failed: "Not all elements of output SV_Depth were written.").
      • gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback (one readback for the block, not eight, left 3): fails with the other gpu_owned:: tests in the same run, passes alone.
    • cargo xtask policy: 555 files ok.
  • Gameplay: RTX 4090 24 GB, driver 621.40, Core i9-13900K, 32 GB, Windows 11 26300; Series X profile, 2560x1440, DLSS quality, frame generation 3x (DARNER_FORCE_MFG_RTX40=1), ray tracing hardware, shader-heap profile 2 GiB.

  • Shader wave sizes tested: the defaults on the 4090 (the unit tests run wave32).

  • Hardware dependence: the faults are NVIDIA's (Turing and later bindless constant handles carry the view size). The change applies to every card; elsewhere it only turns reads of nothing into zeros.

  • Coverage gaps: one card; no frame-time A/B; no AMD or Intel run in the game.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: 555 files ok).
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #164 (opt-in NVIDIA shader heap profile) and #187 (culling for CS_RaytracingResolve indirect dispatches): both for the traceless 0x887A0005 losses, not the LDC ones.
  • Replaces or overlaps: #223 (rows ≥ 4096 → row 0 in cbuffer_dword and the static path). This PR does that too (part 2), and also covers what #223 does not: inactive lanes below row 4096 past a small view (the shadow dump faulted at row 4095 of a 768-byte view), and reads through slots that hold no constant buffer view at all, which fault at row 0 (parts 1 and 3). If #223 merges first, I'll rebase onto it.

🤖 Generated with Claude Code

Refs #84 ## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: hardware RT device losses on NVIDIA with `nvlddmkm` event 13 in the System log, **`Graphics SM Warp Exception ... Invalid Constant Address LDC`**, then event 153; the game reports `0x887A0006`. Aftermath dumps `0xc43ad96c52d44542` (`dxil:1275`, the one in #84) and `0x455825034071ee88` (mesh programs of an `ExecuteIndirect` batch), plus one in the tiled shadow cascades compute. The evidence is in [my comment on #84](https://git.gtahub.st/TrustNo1/Darner/issues/84#issuecomment-862485). On NVIDIA a constant load (LDC) through a descriptor that is not a constant buffer view with bytes, or past the view's size, stops the card. The console reads zeros there. darner issued three kinds of such reads: 1. **Constant reads through slots holding no constant buffer view.** The indirect mesh draws read the title's heap slots directly (the host builds no table for them), and the faulting entries held a null texture view or a buffer view. The translator now reads a descriptor-table entry as a constant buffer only where the host's slot word (`SLOT_STRIDES`) says `VIEW_CONSTANT`, a new value (stride 0, `VIEW_SIGNED` alone, which no buffer view has); zeros otherwise. This covers the scalar and per-lane paths, and descriptors chosen by control flow among table loads. Switch: `DARNER_CBV_SLOT_GUARD` (on; `0` restores the old reads). 2. **Inactive lanes and rows past 4095.** A per-lane constant load runs for every lane; lanes the instruction does not run for read at whatever their address held (row 4095 of a 768-byte view in the shadow dump). Those lanes now read row 0, and rows past 4095 read row 0 and give 0 (a static row past 4095 gives 0 with no load). Addresses that wrap past `u32::MAX` read 0 too. Switch: `DARNER_CB_ROWS` (on). 3. **The host's word over views it had not made.** A constant view the title writes into a slot waits for a draw's table to name it, and shows a null stand-in until then; `mirror_inner` still wrote `VIEW_CONSTANT` for it, so (1) alone did not stop the read (the `0x455825034071ee88` loss, on row 0). The word now follows the made view, in both `DARNER_VIEW_START_REMAINDER` modes, is cleared before the descriptor changes, and a 0-byte view never gets it. Constant views made for dynamic tables (`constant_at_with_base`, `constant_raw_at`) write it. Both switches are in the shader cache's `KEYED` list, and README rows document them. Not in this PR, and noted for review: - The `ResourceHeap` pick path (`lower.rs`, descriptors picked straight from the resource heap) still reads stride-0 slots with no guard. - With `DARNER_PORT_CBV=1` (off by default), `constant_twinned` can show a null view for a made one and still get `VIEW_CONSTANT`. - This does nothing for the traceless `0x887A0005` losses (empty breadcrumbs, no driver event, no dump) discussed in #84. On my card those stopped with the 2 GiB shader-heap profile (`darner nv-profile`), but others report they don't. ## How it was tested - Tested revision: `d91b0992` (on `53817d27`, `914fceff`) on main `f3840d73`. The game runs were on `53817d27`; `d91b0992` changes only reads at addresses that wrap past `u32::MAX` (unit-tested). The same fix ran earlier as part of a local investigation branch. - Commands and results: - `cbv_loads_of_inactive_lanes_stay_inside_the_view` (new): lane 0 reads byte 16 of a 256-byte CBV, the other lanes skip it holding byte 0xfff0. **With `DARNER_CB_ROWS=0` (the old load) this lost the device on the RTX 4090** ("device removed", nvlddmkm event 153); with the fix it passes on the 4090 and WARP. On WARP or AMD the old load passes too, so on a runner without an NVIDIA card it only checks the result. - `cbv_reads_that_wrap_past_u32_max_read_zeros` (new): a scalar and a per-lane `dwordx2` at `0xfffffffc` and a halfword at `0xffffffff` read 0, row 0 beside them its bytes. Without the wrap fix it reads `0x1111`/`0x1100` on the RTX 4090. - `cbv_loads_read_zeros_where_the_slot_word_is_not_a_constant_view` (new): slot word 0 gives zeros on every backend (with the guard removed lane 0 would read 0xabcd). - `constant_views_not_made_do_not_publish_a_constant_word` and `constant_buffer_views_of_no_bytes_have_no_constant_word` (new, host): pass with `DARNER_VIEW_START_REMAINDER` at its default and at `0`. - Existing table-CBV tests pass the slot word: `cbv_byte_and_halfword_loads_read_the_addressed_bytes`, `table_constant_buffers_read_as_raw_bytes_through_their_twins`. All five shader tests pass with `DARNER_CBV_SLOT_GUARD` on and at `0`. - `cargo test -p darner-gpu --lib descriptor:: shader_cache`: 163 passed, 2 ignored. - Changes a default: yes, for every card (both switches are on). The reads it changes only gave zeros on the console; on AMD they read whatever the descriptor held; on NVIDIA they lost the device. - A/B result: RTX 4090, Series X profile, 2560x1440, DLSS quality, frame generation 3x, hardware RT, the same route from a new game, through the point a few minutes in where these losses came, and on. | | A (before) | B (with the fix) | |---|---|---| | runs | 12-03/04: about 3 of 4 runs that reached that point lost the device there, each with the LDC event | 4 runs since the complete fix: 3 on the older base (2 ended in the traceless `0x887A0005` before the shader-heap profile; 1 ran ~8 min with it), 1 on `53817d27` (7 min preload, then ~23 min of play) | | LDC events | every loss of this kind | **0** | The ~8 min run and the run on `53817d27` both ended in a process exit with no log line, dump or Windows record, with the PC nearly out of RAM (1-2 GB free of 32). I treat that exit as a separate problem and am looking at it (#301). **Speed: not measured.** Each guarded read adds a slot-word load and a branch, and shaders with table CBVs now bind the slot-word SRV. No frame-time A/B yet. - Gates run on `914fceff`: all three, on Windows (there is no CI). On `d91b0992`: gates 1 and 2 clean, policy ok, darner-shader lib tests 559 passed / 1 known failure (below); gate 3 not rerun in full (darner-shader only). - Gate 1 `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. - Gate 2 `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean. - Gate 3 `cargo test --workspace --locked --no-fail-fast -- --skip oracle64` (oracle64 left out: its exhaustive loops run for hours in a debug build): 3,345 passed, 2 failed, 121 ignored. Both failures also fail on `main` `f3840d73` without this change: - `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders` (`DXIL validation failed: "Not all elements of output SV_Depth were written."`). - `gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback` (`one readback for the block, not eight`, left 3): fails with the other `gpu_owned::` tests in the same run, passes alone. - `cargo xtask policy`: 555 files ok. - Gameplay: RTX 4090 24 GB, driver 621.40, Core i9-13900K, 32 GB, Windows 11 26300; Series X profile, 2560x1440, DLSS quality, frame generation 3x (`DARNER_FORCE_MFG_RTX40=1`), ray tracing hardware, shader-heap profile 2 GiB. - Shader wave sizes tested: the defaults on the 4090 (the unit tests run wave32). - Hardware dependence: the faults are NVIDIA's (Turing and later bindless constant handles carry the view size). The change applies to every card; elsewhere it only turns reads of nothing into zeros. - Coverage gaps: one card; no frame-time A/B; no AMD or Intel run in the game. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: 555 files ok). - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #164 (opt-in NVIDIA shader heap profile) and #187 (culling for `CS_RaytracingResolve` indirect dispatches): both for the traceless `0x887A0005` losses, not the LDC ones. - Replaces or overlaps: **#223** (rows ≥ 4096 → row 0 in `cbuffer_dword` and the static path). This PR does that too (part 2), and also covers what #223 does not: inactive lanes below row 4096 past a small view (the shadow dump faulted at row 4095 of a 768-byte view), and reads through slots that hold no constant buffer view at all, which fault at row 0 (parts 1 and 3). If #223 merges first, I'll rebase onto it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
On NVIDIA cards a constant load (LDC) through a descriptor that is not a
constant buffer view with bytes, or past the view's size, stops the card
("Graphics SM Warp Exception: Invalid Constant Address LDC", 0x887A0006);
the console reads zeros there. Three such reads, all seen on an RTX 4090:

- Table entries read as constant buffers through slots holding a null or a
  buffer view (the indirect mesh draws read the title's slots directly).
  The translator now reads a table entry as constants only where the host's
  slot word is VIEW_CONSTANT, zeros otherwise (DARNER_CBV_SLOT_GUARD, on).
- Per-lane constant loads ran for inactive lanes at their own address, past
  the view; rows past 4095 were read as they were. Inactive lanes and rows
  past 4095 now read row 0, and rows past 4095 give 0 (DARNER_CB_ROWS, on).
- The host wrote VIEW_CONSTANT over constant views it had not made yet (a
  null stand-in until a draw's table names them) and over 0-byte ones. The
  word now follows the made view, in both view-start modes, and is cleared
  before the descriptor changes.

Both switches are keyed in the shader cache.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qV4hjy6QugZNpPP8o97Wf
First-time contributor

Independent Windows build, gate, and code-read review of 914fceff6 (based on main f3840d73d). Not run in-game.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS
  • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS
  • cargo xtask policy: PASS (asset policy: 555 files ok)
  • cargo test --locked -p darner-shader --lib cbv: PASS (4 passed; 0 failed in 2.33 s)
  • cargo test --locked -p darner-shader --lib emit::bitcode::opt::tests: PASS (31 passed; 0 failed; 1 ignored in 6.09 s)
  • cargo test --locked -p darner-gpu --lib descriptor::host: PASS (107 passed; 0 failed; 1 ignored in 1.16 s)
  • cargo test --locked -p darner-gpu --lib shader_cache: PASS (13 passed; 0 failed in 2.93 s)
  • Matrix checks on the 4 table-CBV shader tests (cbv_byte_and_halfword_loads_read_the_addressed_bytes, cbv_loads_of_inactive_lanes_stay_inside_the_view, cbv_loads_read_zeros_where_the_slot_word_is_not_a_constant_view, table_constant_buffers_read_as_raw_bytes_through_their_twins): PASS with defaults (4 passed in 1.62 s) and DARNER_CBV_SLOT_GUARD=0 (4 passed in 1.31 s).
  • Matrix check on the 2 new host tests (constant_views_not_made_do_not_publish_a_constant_word, constant_buffer_views_of_no_bytes_have_no_constant_word) with DARNER_VIEW_START_REMAINDER=0: PASS (2 passed in 0.53 s).

Code-read audit

Overall this is a strong, well-tested fix that cleanly supersedes #223 (and avoids #223's wrapping_add bug in the static smem path by using base.saturating_add(4 * k) >> 4 > 4095). Checked and verified sound:

  • VIEW_CONSTANT = VIEW_SIGNED = 1 << 30 (without VIEW_INTEGER) does not collide with slot_stride, view_bias, or integer_view (where VIEW_INTEGER gates signed).
  • Both "DARNER_CB_ROWS" and "DARNER_CBV_SLOT_GUARD" are in shader_cache::KEYED and pass every_switch_of_the_translator_is_in_the_key.
  • opt.rs simplify_guarded_uses will not unwrap select(g, byte, 0) or select(inside, ri, 0) because cbufferLoadLegacy is not in is_speculatable_pure_call, and under default DARNER_LICM_CBUF=1 guarded table CBV handles remain inside begin_guarded.

Beyond the three deferred items already noted in the PR description (ResourceHeap pick path, DARNER_PORT_CBV=1 constant_twinned, and DARNER_LICM_CBUF=2), three concrete gaps remain:

  1. Missed VIEW_CONSTANT clear-before-put ordering on title-slot overwrite paths (crates/darner-gpu/src/descriptor/host.rs):
    • Part 3 clears VIEW_CONSTANT before overwriting the descriptor in make_null (host.rs:6395) and mirror_inner's main path (host.rs:7145).
    • However, when an unmade texture view overwrites a title slot that previously held a made View::Constant, mirror_inner (host.rs:7071-7096) enters stand_in_title and returns early without calling clear_constant_word(index). Inside stand_in_title (host.rs:4593-4595, 4666-4668), self.put(index) writes the texture/neutral/null descriptor before self.write_stride(index, 0) clears VIEW_CONSTANT.
    • The same put()-before-write_stride() window exists in unmake (host.rs:5292-5294), unmake_neutral (host.rs:5319-5321), and publish_uploaded_slot (host.rs:4939-4944). Calling clear_constant_word(index) (or moving write_stride(index, 0)) ahead of self.put(index) in those paths closes the remaining concurrent-reader window consistently.
  2. 32-bit address wrap-around in dynamic / per-lane / subword CBV load paths (crates/darner-shader/src/emit/lower.rs):
    • Static smem handles wrap-around cleanly with base.saturating_add(4 * k) >> 4 > 4095.
    • Dynamic smem (lower.rs:8181-8183), per-lane vector CBV loads (lower.rs:13861-13865, where view_bounds(h, src) is None for CBVs so view_byte emits a wrapping Bin::Add(byte, 4 * k)), and 16-bit CBV subword loads (load_subword, lower.rs:8350-8353, (byte + 1) & !3) all use wrapping 32-bit addition before cbuffer_dword. For an out-of-range base near u32::MAX (e.g. 0xFFFF_FFF8 on a dwordx4 load), later dwords wrap back to row 0 and return row-0 bytes instead of 0 (safe from LDC since row 0 is in-bounds, but diverges from the console's 0).
  3. constant_slot_guard unnecessarily skips dynamically-indexed RootType::Table CBVs (crates/darner-shader/src/emit/lower.rs, tabled check):
    • a.dynamic.is_none() excludes dynamically-indexed table entries even though slot_word -> heap_index and fetched_index already compute runtime heap indices and SLOT_TABLE_STRIDES covers the full heap. Dropping a.dynamic.is_none() guards dynamic table CBV arrays and waterfall loops over tables as well.

Minor non-blocking notes

  • In crates/darner-shader/src/emit/bitcode/opt.rs:2465-2470, gating the licm_cbuf() >= 2 arm on !super::super::shader::cbv_slot_guard() in code (not just in the comment) would prevent DARNER_LICM_CBUF=2 from silently breaking DARNER_CBV_SLOT_GUARD.
  • clear_constant_word (host.rs:5759-5769) performs a read_volatile() on Write-Combined upload heap memory when DARNER_STRIDES_WB is off (the default).
  • Adding a unit test directly asserting 0 for a static or dynamic row >= 4096 read would also exercise the 4096-row clamp on non-NVIDIA backends (where cbv_loads_of_inactive_lanes_stay_inside_the_view passes even without the clamp).

Verdict: Changes requested (close the missed put()-before-write_stride() window in stand_in_title/unmake/unmake_neutral/publish_uploaded_slot, remove a.dynamic.is_none() in constant_slot_guard, and guard dynamic addr + 4*k wrap-around if console 0 semantics near u32::MAX are desired).

AI-assisted: yes (Gemini 4 Neon).

Independent Windows build, gate, and code-read review of `914fceff6` (based on `main` `f3840d73d`). Not run in-game. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS** - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS** - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`) - `cargo test --locked -p darner-shader --lib cbv`: **PASS** (`4 passed; 0 failed` in 2.33 s) - `cargo test --locked -p darner-shader --lib emit::bitcode::opt::tests`: **PASS** (`31 passed; 0 failed; 1 ignored` in 6.09 s) - `cargo test --locked -p darner-gpu --lib descriptor::host`: **PASS** (`107 passed; 0 failed; 1 ignored` in 1.16 s) - `cargo test --locked -p darner-gpu --lib shader_cache`: **PASS** (`13 passed; 0 failed` in 2.93 s) - Matrix checks on the 4 table-CBV shader tests (`cbv_byte_and_halfword_loads_read_the_addressed_bytes`, `cbv_loads_of_inactive_lanes_stay_inside_the_view`, `cbv_loads_read_zeros_where_the_slot_word_is_not_a_constant_view`, `table_constant_buffers_read_as_raw_bytes_through_their_twins`): **PASS** with defaults (`4 passed` in 1.62 s) and `DARNER_CBV_SLOT_GUARD=0` (`4 passed` in 1.31 s). - Matrix check on the 2 new host tests (`constant_views_not_made_do_not_publish_a_constant_word`, `constant_buffer_views_of_no_bytes_have_no_constant_word`) with `DARNER_VIEW_START_REMAINDER=0`: **PASS** (`2 passed` in 0.53 s). ### Code-read audit Overall this is a strong, well-tested fix that cleanly supersedes #223 (and avoids #223's `wrapping_add` bug in the static `smem` path by using `base.saturating_add(4 * k) >> 4 > 4095`). Checked and verified sound: - `VIEW_CONSTANT = VIEW_SIGNED = 1 << 30` (without `VIEW_INTEGER`) does not collide with `slot_stride`, `view_bias`, or `integer_view` (where `VIEW_INTEGER` gates `signed`). - Both `"DARNER_CB_ROWS"` and `"DARNER_CBV_SLOT_GUARD"` are in `shader_cache::KEYED` and pass `every_switch_of_the_translator_is_in_the_key`. - `opt.rs` `simplify_guarded_uses` will not unwrap `select(g, byte, 0)` or `select(inside, ri, 0)` because `cbufferLoadLegacy` is not in `is_speculatable_pure_call`, and under default `DARNER_LICM_CBUF=1` guarded table CBV handles remain inside `begin_guarded`. Beyond the three deferred items already noted in the PR description (`ResourceHeap` pick path, `DARNER_PORT_CBV=1` `constant_twinned`, and `DARNER_LICM_CBUF=2`), three concrete gaps remain: 1. **Missed `VIEW_CONSTANT` clear-before-`put` ordering on title-slot overwrite paths (`crates/darner-gpu/src/descriptor/host.rs`):** - Part 3 clears `VIEW_CONSTANT` *before* overwriting the descriptor in `make_null` (`host.rs:6395`) and `mirror_inner`'s main path (`host.rs:7145`). - However, when an unmade texture view overwrites a title slot that previously held a made `View::Constant`, `mirror_inner` (`host.rs:7071-7096`) enters `stand_in_title` and returns early without calling `clear_constant_word(index)`. Inside `stand_in_title` (`host.rs:4593-4595`, `4666-4668`), `self.put(index)` writes the texture/neutral/null descriptor *before* `self.write_stride(index, 0)` clears `VIEW_CONSTANT`. - The same `put()`-before-`write_stride()` window exists in `unmake` (`host.rs:5292-5294`), `unmake_neutral` (`host.rs:5319-5321`), and `publish_uploaded_slot` (`host.rs:4939-4944`). Calling `clear_constant_word(index)` (or moving `write_stride(index, 0)`) ahead of `self.put(index)` in those paths closes the remaining concurrent-reader window consistently. 2. **32-bit address wrap-around in dynamic / per-lane / subword CBV load paths (`crates/darner-shader/src/emit/lower.rs`):** - Static `smem` handles wrap-around cleanly with `base.saturating_add(4 * k) >> 4 > 4095`. - Dynamic `smem` (`lower.rs:8181-8183`), per-lane vector CBV loads (`lower.rs:13861-13865`, where `view_bounds(h, src)` is `None` for CBVs so `view_byte` emits a wrapping `Bin::Add(byte, 4 * k)`), and 16-bit CBV subword loads (`load_subword`, `lower.rs:8350-8353`, `(byte + 1) & !3`) all use wrapping 32-bit addition before `cbuffer_dword`. For an out-of-range base near `u32::MAX` (e.g. `0xFFFF_FFF8` on a `dwordx4` load), later dwords wrap back to row `0` and return row-0 bytes instead of `0` (safe from LDC since row 0 is in-bounds, but diverges from the console's `0`). 3. **`constant_slot_guard` unnecessarily skips dynamically-indexed `RootType::Table` CBVs (`crates/darner-shader/src/emit/lower.rs`, `tabled` check):** - `a.dynamic.is_none()` excludes dynamically-indexed table entries even though `slot_word` -> `heap_index` and `fetched_index` already compute runtime heap indices and `SLOT_TABLE_STRIDES` covers the full heap. Dropping `a.dynamic.is_none()` guards dynamic table CBV arrays and waterfall loops over tables as well. ### Minor non-blocking notes - In `crates/darner-shader/src/emit/bitcode/opt.rs:2465-2470`, gating the `licm_cbuf() >= 2` arm on `!super::super::shader::cbv_slot_guard()` in code (not just in the comment) would prevent `DARNER_LICM_CBUF=2` from silently breaking `DARNER_CBV_SLOT_GUARD`. - `clear_constant_word` (`host.rs:5759-5769`) performs a `read_volatile()` on Write-Combined upload heap memory when `DARNER_STRIDES_WB` is off (the default). - Adding a unit test directly asserting `0` for a static or dynamic `row >= 4096` read would also exercise the 4096-row clamp on non-NVIDIA backends (where `cbv_loads_of_inactive_lanes_stay_inside_the_view` passes even without the clamp). **Verdict:** Changes requested (close the missed `put()`-before-`write_stride()` window in `stand_in_title`/`unmake`/`unmake_neutral`/`publish_uploaded_slot`, remove `a.dynamic.is_none()` in `constant_slot_guard`, and guard dynamic `addr + 4*k` wrap-around if console `0` semantics near `u32::MAX` are desired). AI-assisted: yes (Gemini 4 Neon).
- The slot paths that replaced a title slot's descriptor before clearing
  its VIEW_CONSTANT word (stand_in_title, unmake, unmake_neutral,
  publish_uploaded_slot, texture_slots_flip, and mirror_inner before a
  descriptor made in place or a stand-in) clear it first now, so GPU work
  in flight never reads the new descriptor as a constant buffer. Other
  words keep their place after the descriptor: they still fit the old
  view. A fence follows the clear (the table may be write-combined).
- clear_constant_word no longer reads the table (upload memory, slow to
  read): HostHeap keeps a bit per slot whose word is VIEW_CONSTANT,
  set and cleared in write_stride.
- constant_slot_guard also guards table entries the program computes: the
  slot word it reads is the slot handle reads (heap_index on the load's
  own registers, descriptor_phi, lane_heap_index, the same clamp).
- DARNER_LICM_CBUF=2 hoists descriptor handles only with
  DARNER_CBV_SLOT_GUARD=0, so a row read cannot leave the guarded block.
- Tests: cbv_loads_at_a_computed_table_entry_follow_that_slots_word,
  cbv_rows_past_4095_read_zeros (every backend, WARP included) and
  constant_words_are_cleared_without_reading_the_table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
First-time contributor

Thanks for the careful review. All points are addressed in 53817d276, on top of 914fceff:

1. put() before the word on title-slot paths. Right. stand_in_title, unmake, unmake_neutral and publish_uploaded_slot now clear a VIEW_CONSTANT word before the descriptor changes. The same order problem was also in texture_slots_flip and in mirror_inner for descriptors made in place (DARNER_VIEW_COPY=0), so the clear moved ahead of make_twinned there. Only a constant word is cleared early. Other words (stride, start remainder, integer flag) stay until the new descriptor is in, as before, because they still fit the old view. A fence(SeqCst) follows the clear, because the table can be write-combined memory, which x86 doesn't keep in order. Left as they were: the dynamic-slot writers (make_at, raw_at, constant_at*, ...), whose slots belong to one list until it is submitted, and refresh_tlas / texture_views_remade, whose slots never hold a constant word.

2. a.dynamic.is_none(). Agreed, removed. For every source kind, the guard computes the slot with the same function and arguments as handle: heap_index on the load's own base/offset/soffset registers, descriptor_phi for phis, and lane_heap_index for per-lane and SCC-chosen descriptors, with the same clamp to the null slot. New test cbv_loads_at_a_computed_table_entry_follow_that_slots_word: entry 2 is read through a computed soffset, both scalar and per-lane. It reads the bytes with word VIEW_CONSTANT and zeros with word 0. Slot 0 holds another CBV with word 0, so a guard reading the wrong slot fails. With the exclusion put back, the word-0 run reads 0xabcd and the test fails.

3. Wrap-around near u32::MAX. Your reading is right. I've left it as it is: a wrapped address lands on a low row inside the view, so it can't fault, and I haven't verified what the console reads there.

Minor notes:

  • DARNER_LICM_CBUF=2 now hoists handles only when cbv_slot_guard() is off. This is enforced in opt.rs, not just stated in a comment.
  • clear_constant_word no longer reads the table: HostHeap keeps one bit per slot whose word is VIEW_CONSTANT, maintained in write_stride. New host test: constant_words_are_cleared_without_reading_the_table.
  • New test cbv_rows_past_4095_read_zeros: a real view with word VIEW_CONSTANT, read at byte 0x10000 by a fixed scalar offset, a computed one and a per-lane load. All three give 0, and row 0 (0x1111) is read alongside so a clamp that kept row 0's bytes would show. It passes on the RTX 4090 and WARP.

Tested on 53817d276:

  • Gates: Gate 1 and Gate 2 clean. Gate 3 (--no-fail-fast -- --skip oracle64): 3,349 passed, 1 failed, 121 ignored. The failure is sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, which also fails on main f3840d73 (see the description). gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback passed this time. cargo xtask policy: 555 files ok.
  • cargo test -p darner-shader --lib cbv_ table_constant_buffers emit::bitcode::opt::tests: 38 passed, 1 ignored (7 passed for cbv_ table_constant_buffers with DARNER_CBV_SLOT_GUARD=0).
  • cargo test -p darner-gpu --lib descriptor:: shader_cache: 164 passed, 2 ignored; descriptor::host with DARNER_VIEW_START_REMAINDER=0: 108 passed, 1 ignored.
  • In game: RTX 4090, the full shader preload (the translator change invalidates the cache), then about 20 minutes of hardware RT. No LDC event, no device loss, no translation failures. The run ended in the heap-corruption exit from #301, which is unrelated to this change and is tracked there.

Not in this PR, and already listed in the description: the ResourceHeap pick path. As far as I can see, it reads any stride-0 slot as a constant buffer, null slots included, so in principle it could hit the same fault. I'd rather do that separately.

Thanks for the careful review. All points are addressed in `53817d276`, on top of `914fceff`: **1. `put()` before the word on title-slot paths.** Right. `stand_in_title`, `unmake`, `unmake_neutral` and `publish_uploaded_slot` now clear a `VIEW_CONSTANT` word before the descriptor changes. The same order problem was also in `texture_slots_flip` and in `mirror_inner` for descriptors made in place (`DARNER_VIEW_COPY=0`), so the clear moved ahead of `make_twinned` there. Only a constant word is cleared early. Other words (stride, start remainder, integer flag) stay until the new descriptor is in, as before, because they still fit the old view. A `fence(SeqCst)` follows the clear, because the table can be write-combined memory, which x86 doesn't keep in order. Left as they were: the dynamic-slot writers (`make_at`, `raw_at`, `constant_at*`, ...), whose slots belong to one list until it is submitted, and `refresh_tlas` / `texture_views_remade`, whose slots never hold a constant word. **2. `a.dynamic.is_none()`.** Agreed, removed. For every source kind, the guard computes the slot with the same function and arguments as `handle`: `heap_index` on the load's own base/offset/soffset registers, `descriptor_phi` for phis, and `lane_heap_index` for per-lane and SCC-chosen descriptors, with the same clamp to the null slot. New test `cbv_loads_at_a_computed_table_entry_follow_that_slots_word`: entry 2 is read through a computed soffset, both scalar and per-lane. It reads the bytes with word `VIEW_CONSTANT` and zeros with word 0. Slot 0 holds another CBV with word 0, so a guard reading the wrong slot fails. With the exclusion put back, the word-0 run reads `0xabcd` and the test fails. **3. Wrap-around near `u32::MAX`.** Your reading is right. I've left it as it is: a wrapped address lands on a low row inside the view, so it can't fault, and I haven't verified what the console reads there. **Minor notes:** - `DARNER_LICM_CBUF=2` now hoists handles only when `cbv_slot_guard()` is off. This is enforced in `opt.rs`, not just stated in a comment. - `clear_constant_word` no longer reads the table: `HostHeap` keeps one bit per slot whose word is `VIEW_CONSTANT`, maintained in `write_stride`. New host test: `constant_words_are_cleared_without_reading_the_table`. - New test `cbv_rows_past_4095_read_zeros`: a real view with word `VIEW_CONSTANT`, read at byte `0x10000` by a fixed scalar offset, a computed one and a per-lane load. All three give 0, and row 0 (`0x1111`) is read alongside so a clamp that kept row 0's bytes would show. It passes on the RTX 4090 and WARP. **Tested on ``53817d276``:** - Gates: Gate 1 and Gate 2 clean. Gate 3 (`--no-fail-fast -- --skip oracle64`): 3,349 passed, 1 failed, 121 ignored. The failure is `sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, which also fails on `main` `f3840d73` (see the description). `gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback` passed this time. `cargo xtask policy`: 555 files ok. - `cargo test -p darner-shader --lib cbv_ table_constant_buffers emit::bitcode::opt::tests`: 38 passed, 1 ignored (7 passed for `cbv_ table_constant_buffers` with `DARNER_CBV_SLOT_GUARD=0`). - `cargo test -p darner-gpu --lib descriptor:: shader_cache`: 164 passed, 2 ignored; `descriptor::host` with `DARNER_VIEW_START_REMAINDER=0`: 108 passed, 1 ignored. - In game: RTX 4090, the full shader preload (the translator change invalidates the cache), then about 20 minutes of hardware RT. No LDC event, no device loss, no translation failures. The run ended in the heap-corruption exit from #301, which is unrelated to this change and is tracked there. Not in this PR, and already listed in the description: the `ResourceHeap` pick path. As far as I can see, it reads any stride-0 slot as a constant buffer, null slots included, so in principle it could hit the same fault. I'd rather do that separately.
Contributor

Test result on an Intel Arc A770 16 GB (Series S, 1920x1080, XeSS ultra performance, DARNER_LATE_WAIT=2), with this PR's commit added to our Intel branch:

  • Black flickering ground textures are gone. They showed in every earlier Arc run. With this PR's switches set off (DARNER_CBV_SLOT_GUARD=0 DARNER_CB_ROWS=0), in the same build, the flicker came back.
  • The Arc's device removals remain. The device was still lost after 53.5 minutes (0x887A0006, page fault at an address nothing of Darner's owns). DRED stopped in an indirect mesh draw (kind 10, max 1) of MS_VS_LinearDepthPreSkin_e7e88680 (824dc1956e7e38b6), whose only user data is a table address. Runs without this PR stopped in the same programs (another LinearDepthPreSkin variant, and MSNC_VS_CascadeShadows_drawskinnedTexture). So on Arc that loss has another cause than the constant reads fixed here.
  • This PR's two new tests pass on the A770.

🤖 Generated with Claude Code

Test result on an Intel Arc A770 16 GB (Series S, 1920x1080, XeSS ultra performance, `DARNER_LATE_WAIT=2`), with this PR's commit added to our Intel branch: - **Black flickering ground textures are gone.** They showed in every earlier Arc run. With this PR's switches set off (`DARNER_CBV_SLOT_GUARD=0 DARNER_CB_ROWS=0`), in the same build, the flicker came back. - **The Arc's device removals remain.** The device was still lost after 53.5 minutes (0x887A0006, page fault at an address nothing of Darner's owns). DRED stopped in an indirect mesh draw (kind 10, max 1) of `MS_VS_LinearDepthPreSkin_e7e88680` (`824dc1956e7e38b6`), whose only user data is a table address. Runs without this PR stopped in the same programs (another `LinearDepthPreSkin` variant, and `MSNC_VS_CascadeShadows_drawskinnedTexture`). So on Arc that loss has another cause than the constant reads fixed here. - This PR's two new tests pass on the A770. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
First-time contributor

CHANGES NEEDED

Follow-up verification of 53817d276b7f29073661bf71ed69e11bb67477fc (base f3840d73d3504c30218debfbc8795b9225447317).

Environment

Windows 11 Pro 26H2 build 26300.10075; Intel Core i9-14900K; NVIDIA RTX A2000 12 GB (driver 621.47); Rust 1.98.1 x86_64-pc-windows-msvc; MSVC 19.44.35230.

Measured results

  • cargo clippy --workspace --all-targets --locked -- -D warnings: PASS.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: PASS.
  • cargo xtask policy: PASS (555 files ok).
  • cargo test --locked -p darner-gpu --lib descriptor::host: 108 passed, 0 failed, 1 ignored.
  • cargo test --locked -p darner-shader --lib emit::bitcode::opt::tests: 31 passed, 0 failed, 1 ignored.
  • cargo test --locked -p darner-shader --lib emit::valu_tests::cbv_: 6 passed, 0 failed with defaults and with DARNER_CBV_SLOT_GUARD=0.
  • cargo test --locked -p darner-shader --lib emit::valu_tests::unaligned_raw_table_views_add_the_remainder_and_obey_logical_bounds: 1 passed by default; with DARNER_VIEW_START_REMAINDER=0, 0 passed and 1 failed at valu_tests.rs:2667 because the test requires the feature-only SLOT_TABLE_STRIDES root SRV.
  • With DARNER_VIEW_START_REMAINDER=0, the two no-constant-word descriptor tests passed; cargo test --locked -p darner-gpu --lib shader_cache passed all 13 tests with both DARNER_VIEW_START_REMAINDER=0 and DARNER_CBV_SLOT_GUARD=0.

Code-read audit

  • stand_in_title clears the constant-view marker before exposing a stand-in; unmake and unmake_neutral clear that marker before replacing the descriptor and then update the twin, stride, and retained-view state (crates/darner-gpu/src/descriptor/host.rs:4588-4618, 5296-5353). publish_uploaded_slot validates the current record under the slot lock before publishing and updates tracking only after the synchronous upload (:4940-4974).
  • constant_slot_guard recognizes table-derived and computed descriptor sources and guards the constant load using that slot's type word (crates/darner-shader/src/emit/lower.rs:8778-8829). The default and disabled-guard CBV test matrix passes.
  • Computed-address overflow remains: the scalar path adds 4*k to the 32-bit byte address before cbuffer_dword checks whether the row is within 4095 (crates/darner-shader/src/emit/lower.rs:8191-8193, 8320-8368). For an address of 0xfffffffc and k=1, that addition wraps to row 0 and passes the row check instead of returning zero. The halfword path similarly adds 1 to byte before its row check (:8386-8397), so a halfword crossing the u32 boundary can incorporate row-0 data. Add overflow-aware address handling and boundary tests for both paths.

Not run in-game.

AI-assisted: yes (GitHub Copilot, Auto mode).

**CHANGES NEEDED** Follow-up verification of `53817d276b7f29073661bf71ed69e11bb67477fc` (base `f3840d73d3504c30218debfbc8795b9225447317`). ### Environment Windows 11 Pro 26H2 build 26300.10075; Intel Core i9-14900K; NVIDIA RTX A2000 12 GB (driver 621.47); Rust 1.98.1 x86_64-pc-windows-msvc; MSVC 19.44.35230. ### Measured results - `cargo clippy --workspace --all-targets --locked -- -D warnings`: PASS. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: PASS. - `cargo xtask policy`: PASS (`555 files ok`). - `cargo test --locked -p darner-gpu --lib descriptor::host`: 108 passed, 0 failed, 1 ignored. - `cargo test --locked -p darner-shader --lib emit::bitcode::opt::tests`: 31 passed, 0 failed, 1 ignored. - `cargo test --locked -p darner-shader --lib emit::valu_tests::cbv_`: 6 passed, 0 failed with defaults and with `DARNER_CBV_SLOT_GUARD=0`. - `cargo test --locked -p darner-shader --lib emit::valu_tests::unaligned_raw_table_views_add_the_remainder_and_obey_logical_bounds`: 1 passed by default; with `DARNER_VIEW_START_REMAINDER=0`, 0 passed and 1 failed at `valu_tests.rs:2667` because the test requires the feature-only `SLOT_TABLE_STRIDES` root SRV. - With `DARNER_VIEW_START_REMAINDER=0`, the two no-constant-word descriptor tests passed; `cargo test --locked -p darner-gpu --lib shader_cache` passed all 13 tests with both `DARNER_VIEW_START_REMAINDER=0` and `DARNER_CBV_SLOT_GUARD=0`. ### Code-read audit - `stand_in_title` clears the constant-view marker before exposing a stand-in; `unmake` and `unmake_neutral` clear that marker before replacing the descriptor and then update the twin, stride, and retained-view state (`crates/darner-gpu/src/descriptor/host.rs:4588-4618`, `5296-5353`). `publish_uploaded_slot` validates the current record under the slot lock before publishing and updates tracking only after the synchronous upload (`:4940-4974`). - `constant_slot_guard` recognizes table-derived and computed descriptor sources and guards the constant load using that slot's type word (`crates/darner-shader/src/emit/lower.rs:8778-8829`). The default and disabled-guard CBV test matrix passes. - **Computed-address overflow remains:** the scalar path adds `4*k` to the 32-bit byte address before `cbuffer_dword` checks whether the row is within 4095 (`crates/darner-shader/src/emit/lower.rs:8191-8193`, `8320-8368`). For an address of `0xfffffffc` and `k=1`, that addition wraps to row 0 and passes the row check instead of returning zero. The halfword path similarly adds 1 to `byte` before its row check (`:8386-8397`), so a halfword crossing the `u32` boundary can incorporate row-0 data. Add overflow-aware address handling and boundary tests for both paths. Not run in-game. AI-assisted: yes (GitHub Copilot, Auto mode).
A 32-bit address that wraps past u32::MAX landed on a low row of the
view and read its bytes, where the row check (DARNER_CB_ROWS) only saw
the wrapped row. With the check on, those reads now give 0:
- the scalar paths at a computed address (dword k at addr + 4k), the
  per-lane path (byte + 4k), through cbuffer_dword_at/cbuffer_dword_unless
  and no_wrap;
- a halfword at byte 0xffffffff takes nothing from byte 0
  (load_subword's wraps_to_zero, constant buffers only);
- the constant-offset path adds with wrapping_add (past u32::MAX only
  with DARNER_CB_ROWS=0, where a debug build would have panicked).
With DARNER_CB_ROWS=0 the reads are as before.
- Test: cbv_reads_that_wrap_past_u32_max_read_zeros (a scalar and a
  per-lane dwordx2 at 0xfffffffc, a halfword at 0xffffffff, row 0 beside
  them). Without the fix it reads 0x1111/0x1100 on the RTX 4090.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
First-time contributor

Thanks, you were right that wrapping needed handling. Fixed in d91b0992, on top of 53817d27:

  • Computed addresses: the scalar paths read dword k at addr + 4k through cbuffer_dword_at, which also reads 0 when that sum would pass u32::MAX (no_wrap: addr <= u32::MAX - 4k). The per-lane path had the same wrap (byte + 4k) and gets the same check.
  • Halfword: a halfword at byte 0xffffffff takes nothing from byte 0 (load_subword's wraps_to_zero, constant buffers only). Its low dword, at row 0x0fffffff, already read 0.
  • The constant-offset path adds with wrapping_add. It only gets past u32::MAX with DARNER_CB_ROWS=0, where a debug build would have panicked. With DARNER_CB_ROWS=0 every read is as before.
  • New test cbv_reads_that_wrap_past_u32_max_read_zeros: a scalar and a per-lane dwordx2 at 0xfffffffc, a halfword at 0xffffffff, and row 0 (0x1111) read beside them. On the RTX 4090 it reads 0x1111/0x1100 without the fix and 0 with it.

Results on d91b0992 (RTX 4090, driver 621.40):

  • cargo test --locked -p darner-shader --lib emit::valu_tests::cbv_: 7 passed with defaults and with DARNER_CBV_SLOT_GUARD=0.
  • With DARNER_CB_ROWS=0, cbv_loads_of_inactive_lanes_stay_inside_the_view fails as described (the old load loses the device here).
  • cargo test --locked -p darner-shader --lib -- --skip oracle64: 559 passed, 1 failed (sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, which also fails on main).
  • cargo test --locked -p darner-gpu --lib shader_cache: 13 passed.
  • Gates 1 and 2 (cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings): clean. cargo xtask policy: 555 files ok.

Not in this PR: raw-view reads (rawBufferLoad: SRVs, and constant buffers read raw under DARNER_PORT_CBV=1, off by default) still add 4k without a wrap check when the view has no start bias. They aren't constant loads, so they can't hit LDC, and they were like this before. Also, under DARNER_PORT_CBV=1 the byte/halfword path calls cbuffer_dword on a raw handle. That looks wrong, but it's older than this PR; I can open an issue for it.

Thanks, you were right that wrapping needed handling. Fixed in `d91b0992`, on top of `53817d27`: - **Computed addresses:** the scalar paths read dword k at `addr + 4k` through `cbuffer_dword_at`, which also reads 0 when that sum would pass `u32::MAX` (`no_wrap`: `addr <= u32::MAX - 4k`). The per-lane path had the same wrap (`byte + 4k`) and gets the same check. - **Halfword:** a halfword at byte `0xffffffff` takes nothing from byte 0 (`load_subword`'s `wraps_to_zero`, constant buffers only). Its low dword, at row `0x0fffffff`, already read 0. - **The constant-offset path** adds with `wrapping_add`. It only gets past `u32::MAX` with `DARNER_CB_ROWS=0`, where a debug build would have panicked. With `DARNER_CB_ROWS=0` every read is as before. - **New test** `cbv_reads_that_wrap_past_u32_max_read_zeros`: a scalar and a per-lane `dwordx2` at `0xfffffffc`, a halfword at `0xffffffff`, and row 0 (`0x1111`) read beside them. On the RTX 4090 it reads `0x1111`/`0x1100` without the fix and 0 with it. Results on `d91b0992` (RTX 4090, driver 621.40): - `cargo test --locked -p darner-shader --lib emit::valu_tests::cbv_`: 7 passed with defaults and with `DARNER_CBV_SLOT_GUARD=0`. - With `DARNER_CB_ROWS=0`, `cbv_loads_of_inactive_lanes_stay_inside_the_view` fails as described (the old load loses the device here). - `cargo test --locked -p darner-shader --lib -- --skip oracle64`: 559 passed, 1 failed (`sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, which also fails on `main`). - `cargo test --locked -p darner-gpu --lib shader_cache`: 13 passed. - Gates 1 and 2 (`cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings`): clean. `cargo xtask policy`: 555 files ok. Not in this PR: raw-view reads (`rawBufferLoad`: SRVs, and constant buffers read raw under `DARNER_PORT_CBV=1`, off by default) still add `4k` without a wrap check when the view has no start bias. They aren't constant loads, so they can't hit LDC, and they were like this before. Also, under `DARNER_PORT_CBV=1` the byte/halfword path calls `cbuffer_dword` on a raw handle. That looks wrong, but it's older than this PR; I can open an issue for it.
Contributor

Code review only (read the diff at d91b0992), nothing built or run. I agree with lewis499's two reviews and the fixes in 53817d27/d91b0992. Two new points:

  • Table-constant rows in loops likely no longer leave the loop. LICM moves an instruction only when its operands are defined outside the loop (opt.rs operands_invariant). With the guard, each table-constant read and its handle sit in their own conditional block (begin_guarded), and at DARNER_LICM_CBUF=1 a handle is not moved from a conditional block. So a cbufferLoadLegacy at a constant row through a table entry now stays inside the loop. Before, the handle and then the row could leave it. licm_cbuf's doc credits that hoist with 2.8 ms of a 2080 Ti frame (boat scene, lighting gathers). If those rows come through table entries, the boat scene with DARNER_CBV_SLOT_GUARD=1 vs =0 should show it.
  • Zeros, not a crash, where a constant view is never made (likely, not seen in game). A title constant view that waits for a draw's table keeps word 0. If the indirect mesh draws read a slot that no draw names, they now get 0 where the console has the real constants. That is far better than a device loss, but a look at those draws (skinned meshes, shadow cascades) would show whether anything is missing.

Checked and fine: every path that makes a constant view or writes a slot word (make_twinned, make_at, constant_at_with_base, constant_raw_at, mirror_inner, stand_in_title, unmake*, publish_uploaded_slot, texture_slots_flip, table_slot_unmade) ends with the right word; the list-view cache refuses constant views; the handle cache is keyed by block, so a guarded read cannot reuse an unguarded handle.

Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.

Code review only (read the diff at `d91b0992`), nothing built or run. I agree with lewis499's two reviews and the fixes in `53817d27`/`d91b0992`. Two new points: - **Table-constant rows in loops likely no longer leave the loop.** LICM moves an instruction only when its operands are defined outside the loop (`opt.rs` `operands_invariant`). With the guard, each table-constant read and its handle sit in their own conditional block (`begin_guarded`), and at `DARNER_LICM_CBUF=1` a handle is not moved from a conditional block. So a `cbufferLoadLegacy` at a constant row through a table entry now stays inside the loop. Before, the handle and then the row could leave it. `licm_cbuf`'s doc credits that hoist with 2.8 ms of a 2080 Ti frame (boat scene, lighting gathers). If those rows come through table entries, the boat scene with `DARNER_CBV_SLOT_GUARD=1` vs `=0` should show it. - **Zeros, not a crash, where a constant view is never made (likely, not seen in game).** A title constant view that waits for a draw's table keeps word 0. If the indirect mesh draws read a slot that no draw names, they now get 0 where the console has the real constants. That is far better than a device loss, but a look at those draws (skinned meshes, shadow cascades) would show whether anything is missing. Checked and fine: every path that makes a constant view or writes a slot word (`make_twinned`, `make_at`, `constant_at_with_base`, `constant_raw_at`, `mirror_inner`, `stand_in_title`, `unmake*`, `publish_uploaded_slot`, `texture_slots_flip`, `table_slot_unmade`) ends with the right word; the list-view cache refuses constant views; the handle cache is keyed by block, so a guarded read cannot reuse an unguarded handle. Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.
Contributor

Testing this now in-game (head d91b099 on main f3840d7, release build with bench-remote).

Setup: RTX 5070 Ti 16 GB, driver 621.47, Ryzen 7 7800X3D, 31 GB RAM, Series X profile, 1080p upscaled to 1440p with DLSS Quality, DLSS frame generation 2x, hardware RT on. Automated camera flight over the city (same route and save every run, own home/data/cache folders, cache preloaded with the play switches for both arms).

Plan: same build, alternated runs, default vs DARNER_CBV_SLOT_GUARD=0, to measure the loop-hoist cost iBooM72 asked about and to watch for device losses with RT on. I'll post fps / p99 / any loss when it's done.

Testing this now in-game (head d91b099 on main f3840d7, release build with bench-remote). Setup: RTX 5070 Ti 16 GB, driver 621.47, Ryzen 7 7800X3D, 31 GB RAM, Series X profile, 1080p upscaled to 1440p with DLSS Quality, DLSS frame generation 2x, hardware RT on. Automated camera flight over the city (same route and save every run, own home/data/cache folders, cache preloaded with the play switches for both arms). Plan: same build, alternated runs, default vs DARNER_CBV_SLOT_GUARD=0, to measure the loop-hoist cost iBooM72 asked about and to watch for device losses with RT on. I'll post fps / p99 / any loss when it's done.
Contributor

Test report for d91b099 (on main f3840d7, release build with bench-remote).

PC: RTX 5070 Ti 16 GB, NVIDIA driver 621.47, Ryzen 7 7800X3D, 31 GB RAM, Windows 11. Series X profile, 1080p scene upscaled to 1440p with DLSS Quality, DLSS frame generation 2x, hardware RT on.

Method: automated camera flight over the city (cam-city60, same save and route each run, own home/data folders). Same build in both arms; DARNER_CBV_SLOT_GUARD=0 for the other arm. Because the switch is in KEYED, each arm had its own cache folder, each preloaded with the play switches beforehand (no translation during the runs). 6 runs alternated: on, off, on, off, on, off.

Device losses: none in 9 runs with RT on (these 6, plus 3 earlier runs at 1440p DLAA by mistake), none during the two preloads (7,048 of 7,050 pipelines built each). This PC had no RT device loss on main tonight either (6 runs for #367), so this says nothing about the fix itself, only that it breaks nothing here.

median of 3 runs [spread] guard on (default) DARNER_CBV_SLOT_GUARD=0
fps median 14.1 [0.1] 13.0 [0.3]
fps p10 10.8 [0.3] 9.7 [0.4]
p99 frame 142 ms [19] 138 ms [50]
frames over 100 ms 6.6 % [2.4] 12.8 % [3.2]
peak VRAM 15.0 GB 14.6 GB
peak commit 52.4 GB 52.1 GB

On iBooM72's loop-hoist question: on this route no cost from the guard shows; the default was faster in all 6 runs. I would not read that as a gain: the two arms ran from different cache folders (needed because of KEYED), and on this route an A/A pair on #367 tonight differed by about 1.5 fps. This is a city flight, not the boat scene licm_cbuf was measured on, so a cost there is still possible.

Seen in passing: the driver refused one pipeline with E_OUTOFMEMORY during the default-arm preload (the refusal #367 is about), not related to this PR.

Not run: the three gates (cargo clippy x2, cargo test), and no visual check of the indirect mesh draws iBooM72 mentions.

Test report for d91b099 (on main f3840d7, release build with `bench-remote`). **PC:** RTX 5070 Ti 16 GB, NVIDIA driver 621.47, Ryzen 7 7800X3D, 31 GB RAM, Windows 11. Series X profile, 1080p scene upscaled to 1440p with DLSS Quality, DLSS frame generation 2x, hardware RT on. **Method:** automated camera flight over the city (`cam-city60`, same save and route each run, own home/data folders). Same build in both arms; `DARNER_CBV_SLOT_GUARD=0` for the other arm. Because the switch is in `KEYED`, each arm had its own cache folder, each preloaded with the play switches beforehand (no translation during the runs). 6 runs alternated: on, off, on, off, on, off. **Device losses:** none in 9 runs with RT on (these 6, plus 3 earlier runs at 1440p DLAA by mistake), none during the two preloads (7,048 of 7,050 pipelines built each). This PC had no RT device loss on main tonight either (6 runs for #367), so this says nothing about the fix itself, only that it breaks nothing here. | median of 3 runs [spread] | guard on (default) | `DARNER_CBV_SLOT_GUARD=0` | |---|---|---| | fps median | 14.1 [0.1] | 13.0 [0.3] | | fps p10 | 10.8 [0.3] | 9.7 [0.4] | | p99 frame | 142 ms [19] | 138 ms [50] | | frames over 100 ms | 6.6 % [2.4] | 12.8 % [3.2] | | peak VRAM | 15.0 GB | 14.6 GB | | peak commit | 52.4 GB | 52.1 GB | **On iBooM72's loop-hoist question:** on this route no cost from the guard shows; the default was faster in all 6 runs. I would not read that as a gain: the two arms ran from different cache folders (needed because of `KEYED`), and on this route an A/A pair on #367 tonight differed by about 1.5 fps. This is a city flight, not the boat scene `licm_cbuf` was measured on, so a cost there is still possible. Seen in passing: the driver refused one pipeline with `E_OUTOFMEMORY` during the default-arm preload (the refusal #367 is about), not related to this PR. Not run: the three gates (`cargo clippy` x2, `cargo test`), and no visual check of the indirect mesh draws iBooM72 mentions.
This pull request has changes conflicting with the target branch.
  • crates/darner-gpu/src/shader_cache.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/nvidia-constant-reads:Pipodi-pr/nvidia-constant-reads'
git switch 'Pipodi-pr/nvidia-constant-reads'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'Pipodi-pr/nvidia-constant-reads'
git switch 'Pipodi-pr/nvidia-constant-reads'
git rebase 'main'
git switch 'main'
git merge --ff-only 'Pipodi-pr/nvidia-constant-reads'
git switch 'Pipodi-pr/nvidia-constant-reads'
git rebase 'main'
git switch 'main'
git merge --no-ff 'Pipodi-pr/nvidia-constant-reads'
git switch 'main'
git merge --squash 'Pipodi-pr/nvidia-constant-reads'
git switch 'main'
git merge --ff-only 'Pipodi-pr/nvidia-constant-reads'
git switch 'main'
git merge 'Pipodi-pr/nvidia-constant-reads'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
5 participants
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
TrustNo1/Darner!292
No description provided.