shaders: bound CBV row loads to 4096 rows and guard u32 wrap #660

Open
Nyutt wants to merge 1 commit from nyutt/merge-cbv-row-bounds into post-merge AGit
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on Merge: read from crates/darner-shader/src/emit/lower.rs. Dynamic and constant cbufferLoadLegacy.i32 loads do not clamp row indices to the 4,096 rows (64 KiB) a D3D12 CBV can hold, nor do they guard against 32-bit address wraparound (addr + 4*k), which can cause NVIDIA driver LDC device losses (DXGI_ERROR_DEVICE_REMOVED) when out-of-bounds reads hit row >= 4096 or wrap back to row 0.

Port of PR #292 onto Merge:

  • Add DARNER_CB_ROWS (on by default; "0" disables) to darner_shader::SWITCHES (included in the shader cache key) and emit::shader::cb_rows_bounded().
  • Replace cbuffer_dword with cbuffer_dword_at, no_wrap, and cbuffer_dword_unless, clamping ri <= 4095 and returning 0 when ri > 4095 or addr + delta wraps past u32::MAX.
  • Guard constant-offset s_load_dword* CBV loads similarly with saturating_add/wrapping_add.

How it was tested

  • Tested revision: 25189ee (based on origin/Merge 28a9b42)
  • Commands and results: Not yet run in the game on Merge.
  • Changes a default: yes, for dynamic/constant-offset CBV row reads above row 4095 (previously returned by PR #292 review on main to fix NVIDIA LDC device losses).
  • A/B result: not yet measured on Merge (reversible via DARNER_CB_ROWS=0).
  • Checks run on that revision:
    • cargo test -p darner-shader --lib --locked -> compiles and passes (0 tests in darner-shader --lib)
    • cargo clippy -p darner-shader --all-targets --locked -> 0 new warnings in lib.rs, shader.rs, or lower.rs
  • Hardware dependence: primarily protects NVIDIA GPUs against Invalid Constant Address LDC; general 32-bit wrap safety.
  • Coverage gaps: no DXIL unit tests exist in darner-shader --lib on Merge; needs in-game RTX verification.

Checklist

  • I ran this change in the game, or say below why it can't be (compile + clippy verified; not yet tested in-game on Merge).
  • This PR contains one change based on Merge.
  • The diff contains no game files, code or assets.
  • 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: #632 (view/heap index bounds)
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: <!-- paste your !myid here if wanted --> ## What it changes - The problem on `Merge`: read from `crates/darner-shader/src/emit/lower.rs`. Dynamic and constant `cbufferLoadLegacy.i32` loads do not clamp row indices to the 4,096 rows (64 KiB) a D3D12 CBV can hold, nor do they guard against 32-bit address wraparound (`addr + 4*k`), which can cause NVIDIA driver `LDC` device losses (`DXGI_ERROR_DEVICE_REMOVED`) when out-of-bounds reads hit row `>= 4096` or wrap back to row `0`. Port of PR #292 onto `Merge`: - Add `DARNER_CB_ROWS` (on by default; `"0"` disables) to `darner_shader::SWITCHES` (included in the shader cache key) and `emit::shader::cb_rows_bounded()`. - Replace `cbuffer_dword` with `cbuffer_dword_at`, `no_wrap`, and `cbuffer_dword_unless`, clamping `ri <= 4095` and returning `0` when `ri > 4095` or `addr + delta` wraps past `u32::MAX`. - Guard constant-offset `s_load_dword*` CBV loads similarly with `saturating_add`/`wrapping_add`. ## How it was tested - Tested revision: `25189ee` (based on `origin/Merge` `28a9b42`) - Commands and results: Not yet run in the game on `Merge`. - Changes a default: yes, for dynamic/constant-offset CBV row reads above row 4095 (previously returned by PR #292 review on `main` to fix NVIDIA `LDC` device losses). - A/B result: not yet measured on `Merge` (reversible via `DARNER_CB_ROWS=0`). - Checks run on that revision: - `cargo test -p darner-shader --lib --locked` -> compiles and passes (`0 tests` in `darner-shader --lib`) - `cargo clippy -p darner-shader --all-targets --locked` -> 0 new warnings in `lib.rs`, `shader.rs`, or `lower.rs` - Hardware dependence: primarily protects NVIDIA GPUs against `Invalid Constant Address LDC`; general 32-bit wrap safety. - Coverage gaps: no DXIL unit tests exist in `darner-shader --lib` on `Merge`; needs in-game RTX verification. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (compile + clippy verified; not yet tested in-game on `Merge`). - [x] This PR contains one change based on `Merge`. - [x] The diff contains no game files, code or assets. - [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: #632 (view/heap index bounds) - Replaces or overlaps: none found
TrustNo1 changed title from [pr-fix][shaders][NVIDIA] shaders: bound CBV row loads to 4096 rows and guard u32 wrap to shaders: bound CBV row loads to 4096 rows and guard u32 wrap 2026-12-06 03:25:26 +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/660/head:nyutt/merge-cbv-row-bounds'
git switch 'nyutt/merge-cbv-row-bounds'

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 'post-merge'
git merge --no-ff 'nyutt/merge-cbv-row-bounds'
git switch 'nyutt/merge-cbv-row-bounds'
git rebase 'post-merge'
git switch 'post-merge'
git merge --ff-only 'nyutt/merge-cbv-row-bounds'
git switch 'nyutt/merge-cbv-row-bounds'
git rebase 'post-merge'
git switch 'post-merge'
git merge --no-ff 'nyutt/merge-cbv-row-bounds'
git switch 'post-merge'
git merge --squash 'nyutt/merge-cbv-row-bounds'
git switch 'post-merge'
git merge --ff-only 'nyutt/merge-cbv-row-bounds'
git switch 'post-merge'
git merge 'nyutt/merge-cbv-row-bounds'
git push origin 'post-merge'
Sign in to join this conversation.
No reviewers
No milestone
No project
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
TrustNo1/Darner!660
No description provided.