Skip to content

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

Open
douline wants to merge 1 commit into
fxceless:mainfrom
douline:fix/cbv-64k
Open

douline wants to merge 1 commit into
fxceless:mainfrom
douline:fix/cbv-64k

Conversation

@douline

@douline douline commented Nov 25, 2026

Copy link
Copy Markdown

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

…for a larger one)

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.
@avt0m4t48

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

clquwu added a commit to clquwu/leonida-ultimate that referenced this pull request Nov 25, 2026
…ceInfo::arena_size

- Expose VulkanDeviceInfo::arena_size in runtime/shims/d3d12_com.h and populate
  state_.info.arena_size = arena.size in Device::create_arena() so callers and
  merge glue (set_heap_base) can read the actual GPU address arena size.
- Clamp CreateConstantBufferView / write_constant_buffer_view() to the D3D12
  64 KiB cap (65536 bytes = 4096 * 16), rounded up to a 256-byte multiple,
  adapted from fxceless/victory-fork#911 (GPL-3.0, author douline). Log once
  when clamped and pass the clamped byte size to both buffer.num_records and
  resolve_vsharp_address() so oversized retail CBVs (>1 MiB) neither fault
  the GPU nor allocate oversized title-VA windows.
- Add unit tests in d3d12_vulkan_device_test for 64 KiB CBV clamping (PC and
  Xbox vector-row paths) and VulkanDeviceInfo::arena_size (0 without BDA and
  non-zero on standalone BDA).
- Update large (>64 KiB) title-window tests in d3d12_xmem_shadow_test to drive
  512 KiB / 1 MiB / 2 MiB window installation via TitleVaAliases::table_view
  while keeping CBV calls within the legal 64 KiB cap.
simnJS added a commit to MiamiGame/XTP that referenced this pull request Nov 25, 2026
…pty ones, at most 64 KiB

- Table CBVs filled into the list's scratch or own memory (upload fill or
  GPU copy) zero the bytes from the title's size to the 256-byte end the
  host view takes, as the console reads zeros past a view's size; before,
  they read what earlier recordings left there. A CBV copy is reused only
  where its bytes past the asked length are zeros.
- A constant view of no address or no bytes is a null CBV (dynamic slots:
  HostHeap::null_constant; title slots: `make` declines it, `null_for`
  makes a null CBV), not a 0-byte view, a null 2D SRV, or a fill from
  title address 0. create_cbv without a description records
  View::Constant(0, 0) instead of leaving the slot's old view.
- Host CBVs take at most 64 KiB (constant_bytes, capped_constant): larger
  ones remove the device on NVIDIA (0x887A0001). Title sizes over 64 KiB
  are logged (counted, with the largest seen), and only 64 KiB is copied.

Tests (WARP): draw::tests::table_cbvs_read_zeros_past_their_size,
descriptor::tests::a_constant_view_without_a_description_is_a_null_one,
descriptor::host::tests::constant_views_are_capped_at_64_kib_and_null_when_empty.

Ported from Marvisak/VIctory#1629 (head 111b773) by ESAT586
Ported from Marvisak/VIctory#1640 (head b916a9c) by NuraadGit
Ported from fxceless/victory-fork#911 (1087538) by douline
AlexMiu2083 added a commit to AlexMiu2083/victory-MBT that referenced this pull request Nov 25, 2026
…r runs across the cursor, snapshots flushed before a copy goes, changed runs reused, texture checks side by side, the card-copy census and its write-combining experiment

From fxceless/victory-fork's open pull requests:

- fxceless#911 (douline): a constant buffer view is at most 64 KiB; the title names
  larger ones and NVIDIA removes the device for them.
- fxceless#932 (avt0m4t48): the search for free dynamic descriptor slots finds a run
  that lies across its starting point.
- fxceless#936 (faycalbaklouti): queued snapshots are taken before a host copy is
  dropped (a use after free); its test's imports added for this tree.
- fxceless#925 (alpz1000): changed-byte runs are found into one buffer reused across
  pages, the merge gap joined in the same pass.
- fxceless#768 (KyleS98): a submission's texture checks run several at a time
  (`VICTORY_WIDE_TEXTURES=1`, off by default).
- fxceless#868 (Chipsraine): a census of the card copies (`VICTORY_CENSUS=1`) and an
  EXPERIMENT, off by default: `VICTORY_SKIP_WC_COMPARE=1` leaves copies of
  write-combining title memory out of the compare and the copy-back. Here
  (RTX 4070, first gameplay scene) it took the median from 213 to 186 ms a
  frame, best 150 ms; not exact (the title must never read that memory
  after the card wrote it).

With them gameplay went from a median of 233 to 213 ms a frame here.

Tried and left off: `VICTORY_CARD_REHASH_RUNS=1` (1,735 passes a frame
joined to about 220, no gain).

victory-gpu: 174 tests pass (`inplace::...shows_its_bytes_at_its_offset`
fails now and then, as before these); victory-hle: 99 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
e4glevlr added a commit to e4glevlr/victory-fork that referenced this pull request Nov 25, 2026
…APS flush, fxceless#827 skip_frames) + test fixes

- PR fxceless#911: clamp HostHeap::constant_at CBV SizeInBytes to <= 64 KiB via constant_view_size()
- PR fxceless#936: flush SNAPS via take_snapshots() before dropping Shadow to prevent UAF
- PR fxceless#827 (crash-fix part): add opt-in VICTORY_TABLED_SKIP_FRAMES check in HostHeap::tabled_lately (omits copy_or_make VRAM growth and unsafe COPY_FAST)
- Align merged unit tests in shadow.rs, host.rs, indirect.rs, indirect/bench.rs, texture.rs and deduplicate record_print_tests
ExoCalibra added a commit to ExoCalibra/victory-exo that referenced this pull request Nov 25, 2026
RyanCase94 added a commit to RyanCase94/victory-Rycas that referenced this pull request Nov 25, 2026
…ear u32::MAX)

On top of fork PRs fxceless#911 (constant buffer views at most 64 KiB) and fxceless#868 (card
copies census, VICTORY_SKIP_WC_BACK), both merged here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
wolfattack199 added a commit to wolfattack199/victory-fork that referenced this pull request Nov 25, 2026
…t, page arrays waited for, views of at most 64 KiB

- The card's compare takes 64 threads a 64 KiB piece, and fills of upload
  memory are kept in their own lists (fxceless#929 by AlexMiu, d07e1eb).
- Constant tables read on the card in place (VICTORY_TABLE_CBV_DIRECT=1;
  off by default here) (fxceless#929).
- A DirectStorage request whose page array the title fills late waits up to
  100 ms for it (fxceless#929).
- A constant buffer view is at most 64 KiB (fxceless#911 by douline).
- A shadow that goes takes its queued snapshots first (fxceless#936 by
  faycalbaklouti).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fxceless added a commit that referenced this pull request Nov 25, 2026
… PR #911)

The title names constant views of more than 4,096 vectors (the PR's author logged one of 1,306,368 bytes in the world); CreateConstantBufferView with such a size is an invalid call, and its author's NVIDIA card removed the device for it, found while buffer views of the heap were made. Logged once when it caps. Read whole (27 lines + a test), applied as it is. Whether the title names such views in OUR runs is not known: the once-line will say.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
dkdknight pushed a commit to dkdknight/victory-fork that referenced this pull request Nov 26, 2026
… PR fxceless#911)

The title names constant views of more than 4,096 vectors (the PR's author logged one of 1,306,368 bytes in the world); CreateConstantBufferView with such a size is an invalid call, and its author's NVIDIA card removed the device for it, found while buffer views of the heap were made. Logged once when it caps. Read whole (27 lines + a test), applied as it is. Whether the title names such views in OUR runs is not known: the once-line will say.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
(cherry picked from commit 2ba6e1f)
DiogoPCastelos pushed a commit to DiogoPCastelos/victory-fork that referenced this pull request Nov 26, 2026
… PR fxceless#911)

The title names constant views of more than 4,096 vectors (the PR's author logged one of 1,306,368 bytes in the world); CreateConstantBufferView with such a size is an invalid call, and its author's NVIDIA card removed the device for it, found while buffer views of the heap were made. Logged once when it caps. Read whole (27 lines + a test), applied as it is. Whether the title names such views in OUR runs is not known: the once-line will say.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
(cherry picked from commit 2ba6e1f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants