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

Open
douline wants to merge 1 commit from upstream-pr/911 into main
douline commented 2026-11-25 12:28:14 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by douline on 2026-11-25T12:28:14Z.


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).

<!-- greyfinch-sync:fxceless/victory-fork:issue:6604475512 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/911). Originally posted by [douline](https://github.com/douline) on 2026-11-25T12:28:14Z. --- ## 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).
avt0m4t48 commented 2026-11-25 13:06:03 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-25T12:50:25Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7162929517 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/911#issuecomment-7162929517). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-25T12:50:25Z. --- 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.
ArturoWolff commented 2026-11-25 13:06:05 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ArturoWolff on 2026-11-25T12:56:03Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7163057965 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/911#issuecomment-7163057965). Originally posted by [ArturoWolff](https://github.com/ArturoWolff) on 2026-11-25T12:56:03Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/911:upstream-pr/911'
git switch 'upstream-pr/911'

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 'upstream-pr/911'
git switch 'upstream-pr/911'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/911'
git switch 'upstream-pr/911'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/911'
git switch 'main'
git merge --squash 'upstream-pr/911'
git switch 'main'
git merge --ff-only 'upstream-pr/911'
git switch 'main'
git merge 'upstream-pr/911'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!910
No description provided.