Skip to content

GPU: constant buffer views of at most 64 KiB - #1640

Closed
NuraadGit wants to merge 1 commit into
Marvisak:mainfrom
NuraadGit:gpu/constant-view-64k
Closed

NuraadGit wants to merge 1 commit into
Marvisak:mainfrom
NuraadGit:gpu/constant-view-64k

Conversation

@NuraadGit

Copy link
Copy Markdown
Contributor

A constant buffer view larger than 65,536 bytes removes the host device (0x887A0001, "the application made a call that is invalid"). The size the title's descriptor holds went to CreateConstantBufferView as it was, rounded up to 256. This caps it at 64 KiB, which is all a shader can index.

Where such sizes come from. The title's view heap keeps old contents in slots it doesn't use, and the host makes a view for each. In two runs on an RTX 2080 that ended in 0x887A0001, the 64 views made just before the removal included constant buffer views of 969,472 and 896,256 bytes, at addresses that look like leftovers (0x7fe8…).

Measured on an RTX 2080 (driver 616.56, Windows 11). One view per process, then GetDeviceRemovedReason:

View Device
256 bytes stays
969,472 bytes removed
not on a 256-byte address removed
size not a multiple of 256 removed
256 bytes at an address of no buffer stays

Test. an_oversized_constant_buffer_view_leaves_the_device_alive makes both sizes through make and one through constant_at, and checks the device after each. Without the cap it fails at the first one ("a view of 969472 bytes"); with it, it passes. cargo test -p victory-gpu --lib: 51 passed, 1 ignored. cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean. On ffe310e.

What this doesn't show.

AI-assisted (Claude Code); counts and log lines only, nothing from the game attached.

The host removes the device for a constant buffer view of more than 65,536
bytes. The title's view heap holds larger sizes in slots it does not use,
and the size went to the host as it was.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu — 51 passed, 0 failed (1 ignored) on both RTX 5090 hardware and VICTORY_D3D12_WARP=1 (including an_oversized_constant_buffer_view_leaves_the_device_alive)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean clamping of CBV SizeInBytes to the D3D12 64 KiB maximum so oversized CBVs do not trigger device removal. Looks good.

AI-assisted (Gemini 4 Neon).

@NuraadGit

Copy link
Copy Markdown
Contributor Author

In-title result for the cap, on an RTX 2080 (fxceless/victory-gta6 7b0f736 + this change + a diagnostics-only present log, no loop limit, Series X profile).

  • One session of 17 min 42 s (frame 3,822), ended by me, with 0 device removals.
  • 3 min 15 s in, the cap cut a view of 955,136 bytes at 0x7fe8ba580000. The line is logged once per run, so later ones would not show.
  • Before this change, three runs here ended in 0x887A0001 about 5 to 6.5 minutes after launch, two of them with a view like this among the 64 made last. The probe in the description shows that making one removes the device.

It is one session, so it shows that such a view does turn up in the title and that the device stays, not how often the old build would have ended.

AI-assisted (Claude Code); counts and log lines only, nothing from the game attached.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: Windows-only code (D3D12/windows_sys/Win32/HLE) — nothing compiles or runs on macOS; source review of the diff.

CBV SizeInBytes is capped: constant_bytes = min(size, 64 KiB).next_multiple_of(256) — the host removes the device for larger views, and the title's heap holds such sizes in slots it does not use. The Windows test uses a real device and checks GetDeviceRemovedReason stays Ok across oversized views (969_472 and 896_256 bytes). Note the cap interacts with #1629's 256-byte padding — both compose since padding applies after the cap. Windows-only.

@NuraadGit

Copy link
Copy Markdown
Contributor Author

Closing this. Since today's push to main, nothing creates a D3D12 constant buffer view: git grep CreateConstantBufferView finds nothing in crates/victory-gpu. Constant views (View::Constant) are now read through raw buffer views over the host copies, so the 64 KiB SizeInBytes limit this PR capped can't be hit any more. The branch also conflicts with main now.

The fix still matters on fxceless/victory-fork, which does create constant buffer views: fxceless/victory-fork#24. If a later change brings real CBVs back here, I'll reopen this.

Thanks @DenRakEiw for the review and the testing.

@NuraadGit NuraadGit closed this Nov 24, 2026
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
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