GPU: constant buffer views at most 64 KiB (NVIDIA removed the device for a larger one) #911

Open
github-bot wants to merge 1 commit from github-bot/gh-911 into main AGit
Owner

@⁠douline on GitHub · 2026-11-25 12:28 UTC · original
douline:fix/cbv-64k → main · +29 −2 · 1 files · 1 commits · open

What

CreateConstantBufferView is called with sizes over 64 KiB: the title names constant buffer views of more than 4,096 vectors (the one we caught: 1,306,368 bytes, in the world, minutes after entering it). D3D12 takes at most D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT × 16 = 65,536 bytes; on NVIDIA the call is invalid and the device is removed on the spot with DXGI_ERROR_INVALID_CALL (0x887A0001).

Both places that make constant views (make for View::Constant, and HostHeap::constant_at) now cap the size at 64 KiB (constant_view_size). A shader cannot read more than 4,096 vectors through a constant view, so nothing it can read is lost. Logged once when it happens.

How it was found

RTX 5070 Ti, release build, world entry with VICTORY_LATE_WAIT=3: the device was removed every 5-20 minutes, always detected in the heap-views pass ("the host device went while buffer views of the heap were made"), without the debug layer able to catch it (diagnostics builds were too slow to reach it). A local check of GetDeviceRemovedReason right before and after each view/resource creation named the call: View::Constant(…, 1306368).

Measured

Same machine and settings, after the fix: 30 minutes in the world without a device loss (it could not get past 5-20 before), 2.5 frames a second steady; then 50 minutes in a diagnostics build with the D3D12 debug layer and DRED on: no removal, no debug-layer error.

cargo test -p victory-gpu --lib constant_views: passes (new test constant_views_are_at_most_64_kib).

AI-assisted (Claude).

**@⁠douline** on GitHub · 2026-11-25 12:28 UTC · [original](https://github.com/fxceless/victory-fork/pull/911) `douline:fix/cbv-64k` → `main` · +29 −2 · 1 files · 1 commits · open ## What `CreateConstantBufferView` is called with sizes over 64 KiB: the title names constant buffer views of more than 4,096 vectors (the one we caught: 1,306,368 bytes, in the world, minutes after entering it). D3D12 takes at most `D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT` × 16 = 65,536 bytes; on NVIDIA the call is invalid and the device is removed on the spot with `DXGI_ERROR_INVALID_CALL` (0x887A0001). Both places that make constant views (`make` for `View::Constant`, and `HostHeap::constant_at`) now cap the size at 64 KiB (`constant_view_size`). A shader cannot read more than 4,096 vectors through a constant view, so nothing it can read is lost. Logged once when it happens. ## How it was found RTX 5070 Ti, release build, world entry with `VICTORY_LATE_WAIT=3`: the device was removed every 5-20 minutes, always detected in the heap-views pass ("the host device went while buffer views of the heap were made"), without the debug layer able to catch it (diagnostics builds were too slow to reach it). A local check of `GetDeviceRemovedReason` right before and after each view/resource creation named the call: `View::Constant(…, 1306368)`. ## Measured Same machine and settings, after the fix: 30 minutes in the world without a device loss (it could not get past 5-20 before), 2.5 frames a second steady; then 50 minutes in a diagnostics build with the D3D12 debug layer and DRED on: no removal, no debug-layer error. `cargo test -p victory-gpu --lib constant_views`: passes (new test `constant_views_are_at_most_64_kib`). AI-assisted (Claude).
The title names constant buffer views of more than 4,096 vectors (one of
1,306,368 bytes, in the world). CreateConstantBufferView with a size over
65,536 bytes is an invalid call; NVIDIA removes the device for it
(DXGI_ERROR_INVALID_CALL, 0x887A0001) in the frame the view is made. Both
places that make constant views (make, HostHeap::constant_at) now cap the
size at 64 KiB, the most a shader can read through one.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:53:42 +00:00
Author
Owner

@⁠avt0m4t48 on GitHub · 2026-11-25 12:50 UTC · original

One boundary case in constant_view_size: round after capping the input. I ran the exact helper on an authored u32::MAX size with Rust 1.98.1. The checked build overflows in next_multiple_of and the optimized build returns zero. A 64 KiB pre-cap gives 65,536 in both cases. Moving the existing warning and early return ahead of the alignment also preserves the warning for every oversized request.

#104 covers the adjacent staging path: it applies the cap before sizing the scratch allocation and deferred copy, so the unused tail never reaches constant_at.

AI-assisted source review and synthetic helper test.

**@⁠avt0m4t48** on GitHub · 2026-11-25 12:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/911#issuecomment-7162929517) One boundary case in `constant_view_size`: round after capping the input. I ran the exact helper on an authored `u32::MAX` size with Rust 1.98.1. The checked build overflows in `next_multiple_of` and the optimized build returns zero. A 64 KiB pre-cap gives 65,536 in both cases. Moving the existing warning and early return ahead of the alignment also preserves the warning for every oversized request. #104 covers the adjacent staging path: it applies the cap before sizing the scratch allocation and deferred copy, so the unused tail never reaches `constant_at`. AI-assisted source review and synthetic helper test.
Author
Owner

@⁠ArturoWolff on GitHub · 2026-11-25 12:56 UTC · original

One follow-up for memory pressure, separate from the invalid D3D12 call this fixes and the staging cap in #104. On 1087538, make(View::Constant) still passes the original size to shadow::find before capping SizeInBytes. If no registered buffer covers the full ask, lookup falls back to loose, where the ask determines the window key.

I ran the branch's window_of unchanged on Linux with the 1,306,368-byte size reported above and the default 4 MiB grid. At synthetic address 0x1003e0000, the original ask selects an 8 MiB window; the 65,536-byte prefix selects a 4 MiB window. Control at 0x100000000: both select 4 MiB. This is a window-selection result, not a measured allocation or a Linux device-loss reproduction. The title address and backing of the reported CBV are unknown.

I'd treat that as a separate optimization, not a blocker for the descriptor fix. If narrowing the shadow lookup, check that descriptor creation and any later refresh resolve the same backing, particularly when only the capped prefix fits a registered buffer. The boundary case above would make a small regression fixture.

AI disclosure: Hermes Agent traced the lookup and ran the CPU fixture on ArturoWolff's behalf.

**@⁠ArturoWolff** on GitHub · 2026-11-25 12:56 UTC · [original](https://github.com/fxceless/victory-fork/pull/911#issuecomment-7163057965) One follow-up for memory pressure, separate from the invalid D3D12 call this fixes and the staging cap in #104. On `1087538`, `make(View::Constant)` still passes the original `size` to `shadow::find` before capping `SizeInBytes`. If no registered buffer covers the full ask, `lookup` falls back to `loose`, where the ask determines the window key. I ran the branch's `window_of` unchanged on Linux with the 1,306,368-byte size reported above and the default 4 MiB grid. At synthetic address `0x1003e0000`, the original ask selects an 8 MiB window; the 65,536-byte prefix selects a 4 MiB window. Control at `0x100000000`: both select 4 MiB. This is a window-selection result, **not** a measured allocation or a Linux device-loss reproduction. The title address and backing of the reported CBV are unknown. I'd treat that as a separate optimization, not a blocker for the descriptor fix. If narrowing the shadow lookup, check that descriptor creation and any later refresh resolve the **same backing**, particularly when only the capped prefix fits a registered buffer. The boundary case above would make a small regression fixture. AI disclosure: Hermes Agent traced the lookup and ran the CPU fixture on ArturoWolff's behalf.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.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 origin '+refs/pull/911/head:github-bot/gh-911'
git switch 'github-bot/gh-911'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-911'
git switch 'github-bot/gh-911'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-911'
git switch 'github-bot/gh-911'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-911'
git switch 'main'
git merge --squash 'github-bot/gh-911'
git switch 'main'
git merge --ff-only 'github-bot/gh-911'
git switch 'main'
git merge 'github-bot/gh-911'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.