GPU: a title buffer view takes a format the host takes, or stays null #2871

Open
0xkn0wh3r3 wants to merge 2 commits from upstream-pr/2873 into main
0xkn0wh3r3 commented 2026-11-25 22:51:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T22:51:43Z.


What

Title buffer views reach CreateShaderResourceView and CreateUnorderedAccessView with the title's own format. The title's heap holds views the host refuses: views made for its own runtime, or old ones in slots it doesn't use. I checked with the D3D12 debug layer on WARP:

Title view Debug layer
raw, R32_UINT "When creating a RAW Shader Resource View, the format must be DXGI_FORMAT_R32_TYPELESS", then device removal (DXGI_ERROR_INVALID_CALL) for the SRV
structured, with a format "it must be DXGI_FORMAT_UNKNOWN"
typed, typeless format "cannot be used when creating a typed View of a Buffer"
structured, stride 2, 6 or 4096 accepted

host_buffer_format now picks the host view's format:

  • A raw or structured view reads its bytes whatever its format says, so it's made in the format the host wants (R32_TYPELESS, UNKNOWN).
  • A raw view with a structure stride, or a typed view of no format or a typeless one, has no format the host takes. It stays null, with a warning once.

Structure strides are left alone, since the debug layer accepts any.

Where it came from

From DexNom's fork, DexNom/VIctory@570a941 (buffer_view_ok in descriptor/host.rs, which they link to a device removal in the title). It's credited with Co-authored-by: DexNom and reworked:

  • Views are corrected rather than refused where their bytes don't depend on the format.
  • DexNom's stride limits (≤ 2048, a multiple of 4) are left out; the debug layer doesn't ask for them.
  • The raw 16-byte first element is also left out; #123 covers that, and it needs re-aligning the copy rather than nulling the view.

Tested

  • New test descriptor::host::tests::buffer_views_take_a_format_the_host_takes.
  • I checked each rule above with a one-off probe: a WARP device with the debug layer, an InfoQueue, and CreateShaderResourceView/CreateUnorderedAccessView on a 64 KiB buffer. It isn't committed, because enabling the debug layer would affect every other device in the test process.
  • cargo test -p victory-gpu (Windows 11, RTX 5070 Ti): 228 passed. The 2 known NVIDIA failures are fixed by #2121.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --features diagnostics: clean.

Not tested

  • Not run with the title, so I don't know how many of its views are affected or whether the device removal DexNom saw is this one.

Changes after review

  • 5bd7e1c: the typed path also asks the device, once per format and kind, whether its buffer views take the format. A shader view needs buffer and shader-load support; an unordered view needs buffer and typed unordered-access support. So block-compressed, depth and sRGB formats (BC1_UNORM has no D3D12_FORMAT_SUPPORT1_BUFFER) stay null. New test typed_buffer_views_take_only_formats_the_device_buffers_take: R32_UINT is taken; BC1_UNORM and D32_FLOAT are refused for both kinds. cargo test -p victory-gpu: 229 passed, plus the 2 known NVIDIA failures.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6615378836 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2873). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T22:51:43Z. --- ## What Title buffer views reach `CreateShaderResourceView` and `CreateUnorderedAccessView` with the title's own format. The title's heap holds views the host refuses: views made for its own runtime, or old ones in slots it doesn't use. I checked with the D3D12 debug layer on WARP: | Title view | Debug layer | |---|---| | raw, `R32_UINT` | "When creating a RAW Shader Resource View, the format must be DXGI_FORMAT_R32_TYPELESS", then **device removal** (`DXGI_ERROR_INVALID_CALL`) for the SRV | | structured, with a format | "it must be DXGI_FORMAT_UNKNOWN" | | typed, typeless format | "cannot be used when creating a typed View of a Buffer" | | structured, stride 2, 6 or 4096 | accepted | `host_buffer_format` now picks the host view's format: - A **raw** or **structured** view reads its bytes whatever its format says, so it's made in the format the host wants (`R32_TYPELESS`, `UNKNOWN`). - A **raw view with a structure stride**, or a **typed view of no format or a typeless one**, has no format the host takes. It stays null, with a warning once. Structure strides are left alone, since the debug layer accepts any. ## Where it came from From DexNom's fork, [DexNom/VIctory@570a941](https://github.com/DexNom/VIctory/commit/570a941e9b4e945121c26eb30dfc10c126845207) (`buffer_view_ok` in `descriptor/host.rs`, which they link to a device removal in the title). It's credited with `Co-authored-by: DexNom` and reworked: - Views are corrected rather than refused where their bytes don't depend on the format. - DexNom's stride limits (≤ 2048, a multiple of 4) are left out; the debug layer doesn't ask for them. - The raw 16-byte first element is also left out; #123 covers that, and it needs re-aligning the copy rather than nulling the view. ## Tested - New test `descriptor::host::tests::buffer_views_take_a_format_the_host_takes`. - I checked each rule above with a one-off probe: a WARP device with the debug layer, an InfoQueue, and `CreateShaderResourceView`/`CreateUnorderedAccessView` on a 64 KiB buffer. It isn't committed, because enabling the debug layer would affect every other device in the test process. - `cargo test -p victory-gpu` (Windows 11, RTX 5070 Ti): 228 passed. The 2 known NVIDIA failures are fixed by #2121. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`, with and without `--features diagnostics`: clean. ## Not tested - Not run with the title, so I don't know how many of its views are affected or whether the device removal DexNom saw is this one. ## Changes after review - 5bd7e1c: the typed path also asks the device, once per format and kind, whether its buffer views take the format. A shader view needs buffer and shader-load support; an unordered view needs buffer and typed unordered-access support. So block-compressed, depth and sRGB formats (BC1_UNORM has no `D3D12_FORMAT_SUPPORT1_BUFFER`) stay null. New test `typed_buffer_views_take_only_formats_the_device_buffers_take`: R32_UINT is taken; BC1_UNORM and D32_FLOAT are refused for both kinds. `cargo test -p victory-gpu`: 229 passed, plus the 2 known NVIDIA failures.
kotekompotek commented 2026-11-25 23:05:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T22:53:15Z.

Review: COMMENTED


Correct D3D12 rules applied: raw views must be R32_TYPELESS with no stride, structured views must be DXGI_FORMAT_UNKNOWN, typed views need a real non-typeless format — and a refused view stays null rather than removing the device, which is exactly the right failure mode for views the title carries but doesn't use. The typeless test mirrors the family-check pattern used elsewhere. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066089154 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2873#pullrequestreview-6066089154). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T22:53:15Z. **Review:** COMMENTED --- Correct D3D12 rules applied: raw views must be R32_TYPELESS with no stride, structured views must be DXGI_FORMAT_UNKNOWN, typed views need a real non-typeless format — and a refused view stays null rather than removing the device, which is exactly the right failure mode for views the title carries but doesn't use. The typeless test mirrors the family-check pattern used elsewhere. LGTM.
AwsAli05 commented 2026-11-25 23:05:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AwsAli05 on 2026-11-25T23:04:41Z.

Review: COMMENTED


The raw and structured normalization looks useful. The typed branch still accepts a format the device explicitly declines for buffers. On the RTX 5070 Ti, CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT) reports no D3D12_FORMAT_SUPPORT1_BUFFER for BC1_UNORM. At 0c714c5, the new helper returns Some(BC1_UNORM) for a typed view, and element() gives it a nonzero element size, so it can reach the native view call.

Can the typed path gate on the device's buffer and corresponding SRV/UAV support, with a cached query or suitable allowlist? BC1 is a concrete rejection case to add alongside the current valid and typeless cases. Microsoft's D3D12 format requirements

AI-assisted review. I verified the helper result and device query with a local test.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066187858 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2873#pullrequestreview-6066187858). Originally posted by [AwsAli05](https://github.com/AwsAli05) on 2026-11-25T23:04:41Z. **Review:** COMMENTED --- The raw and structured normalization looks useful. The typed branch still accepts a format the device explicitly declines for buffers. On the RTX 5070 Ti, `CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT)` reports no `D3D12_FORMAT_SUPPORT1_BUFFER` for `BC1_UNORM`. At `0c714c5`, the new helper returns `Some(BC1_UNORM)` for a typed view, and `element()` gives it a nonzero element size, so it can reach the native view call. Can the typed path gate on the device's buffer and corresponding SRV/UAV support, with a cached query or suitable allowlist? BC1 is a concrete rejection case to add alongside the current valid and typeless cases. [Microsoft's D3D12 format requirements](https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/hardware-support-for-direct3d-12-1-formats#dxgi_format_bc1_unorm-fcc--71) AI-assisted review. I verified the helper result and device query with a local test.
fuzeofficlal commented 2026-11-25 23:06:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:04:58Z.


Reviewed and verified 0c714c52 on Windows 11 (RTX 5090 + VICTORY_D3D12_DEBUG=1 + WARP) against main (842b0cb):

  • host_buffer_format(format, stride, raw) consistently guards both buffer_srv and buffer_uav: raw views enforce stride == 0 and rewrite to R32_TYPELESS, structured views rewrite to UNKNOWN, and typed views reject UNKNOWN (0) and family typeless formats.
  • Local checks: RTX 5090 descriptor::host::tests 15/15 and draw::tests 20/20 passed; VICTORY_D3D12_DEBUG=1 buffer_views_take_a_format_the_host_takes passed with 0 debug errors; WARP draw::tests 20/20 passed; cargo clippy --locked -p victory-gpu --all-targets (default & --features diagnostics) 0 warnings; cargo xtask policy (190 files ok).
  • Non-blocking note for potential follow-up: for typed buffers (!raw && stride == 0), non-base typeless / depth / sRGB / BC formats (e.g. 21 R32_FLOAT_X8X24_TYPELESS, 46, 20/40/45, 29/91, 71..=84, or formats lacking TYPED_UAV) still pass the family(f) == f && family(f + 1) == f check if a title ever constructs one.

Looks clean and ready to merge.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177125804 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2873#issuecomment-7177125804). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:04:58Z. --- Reviewed and verified `0c714c52` on Windows 11 (RTX 5090 + `VICTORY_D3D12_DEBUG=1` + WARP) against `main` (`842b0cb`): - `host_buffer_format(format, stride, raw)` consistently guards both `buffer_srv` and `buffer_uav`: raw views enforce `stride == 0` and rewrite to `R32_TYPELESS`, structured views rewrite to `UNKNOWN`, and typed views reject `UNKNOWN (0)` and family typeless formats. - Local checks: RTX 5090 `descriptor::host::tests` 15/15 and `draw::tests` 20/20 passed; `VICTORY_D3D12_DEBUG=1` `buffer_views_take_a_format_the_host_takes` passed with 0 debug errors; WARP `draw::tests` 20/20 passed; `cargo clippy --locked -p victory-gpu --all-targets` (default & `--features diagnostics`) 0 warnings; `cargo xtask policy` (`190 files ok`). - Non-blocking note for potential follow-up: for typed buffers (`!raw && stride == 0`), non-base typeless / depth / sRGB / BC formats (e.g. `21` `R32_FLOAT_X8X24_TYPELESS`, `46`, `20`/`40`/`45`, `29`/`91`, `71..=84`, or formats lacking `TYPED_UAV`) still pass the `family(f) == f && family(f + 1) == f` check if a title ever constructs one. Looks clean and ready to merge.
Marvisak commented 2026-11-26 05:04:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:26:50Z.


Automated triage for the maintainers.

Merge candidate. buffer_srv/buffer_uav in descriptor/host.rs now fix or refuse title buffer views in formats the host rejects: raw views become R32_TYPELESS, structured views UNKNOWN, and raw views with a stride or typed views with no, typeless or unsupported formats stay null, with support cached per format via CheckFeatureSupport. These match the D3D12 view-creation rules and the debug-layer results listed. Note that #2885 also changes descriptor/host.rs.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182602825 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2873#issuecomment-7182602825). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:26:50Z. --- <!-- victory-triage v1 head=5bd7e1c9ce52842886e772096b13fc6d377466b6 verdict=merge-candidate at=2026-11-26T04:26:40Z --> Automated triage for the maintainers. **Merge candidate.** `buffer_srv`/`buffer_uav` in `descriptor/host.rs` now fix or refuse title buffer views in formats the host rejects: raw views become `R32_TYPELESS`, structured views `UNKNOWN`, and raw views with a stride or typed views with no, typeless or unsupported formats stay null, with support cached per format via `CheckFeatureSupport`. These match the D3D12 view-creation rules and the debug-layer results listed. Note that #2885 also changes `descriptor/host.rs`. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 11:03:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T10:08:06Z.

Review: APPROVED


Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: 23/23 passed on RTX 5090 and WARP (including buffer_views_take_a_format_the_host_takes and typed_buffer_views_take_only_formats_the_device_buffers_take).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly ensures typed buffer views only use formats supported by the host device, falling back to null otherwise.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6072117058 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2873#pullrequestreview-6072117058). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:08:06Z. **Review:** APPROVED --- Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: 23/23 passed on RTX 5090 and WARP (including `buffer_views_take_a_format_the_host_takes` and `typed_buffer_views_take_only_formats_the_device_buffers_take`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly ensures typed buffer views only use formats supported by the host device, falling back to null otherwise. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 11:03:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T10:52:58Z.

Review: APPROVED


Verified 5bd7e1c9 locally on Windows 11 (RTX 5090 and WARP, with VICTORY_D3D12_DEBUG=1):

  • cargo xtask policy and cargo clippy -p victory-gpu --tests -- -D warnings (default and --all-features): clean.
  • descriptor:: tests (including both new tests buffer_views_take_a_format_the_host_takes and typed_buffer_views_take_only_formats_the_device_buffers_take): 23/23 passed on RTX 5090, RTX 5090 + VICTORY_D3D12_DEBUG=1, and WARP + VICTORY_D3D12_DEBUG=1 (excluding the pre-existing dynamic_slots_are_held_until_released baseline failure).
  • draw::tests: 20/20 passed on RTX 5090 and WARP + VICTORY_D3D12_DEBUG=1.

The raw (R32_TYPELESS, rejecting stride > 0), structured (DXGI_FORMAT_UNKNOWN), and typed (BUFFER + SHADER_LOAD / TYPED_UNORDERED_ACCESS_VIEW, rejecting UNKNOWN and typeless formats) rules match D3D12 requirements cleanly.

Two minor non-blocking nits:

  • Running host_buffer_format before shadow::for_view in buffer_srv and buffer_uav would avoid lazily creating a host shadow buffer / Arena slice for stale or unsupported buffer views that are immediately rejected.
  • f.checked_add(1).is_some_and(|n| family(n) == f) in host_buffer_format avoids a debug overflow if it is ever called directly with DXGI_FORMAT(-1) (currently unreachable from buffer_srv/buffer_uav since element_size rejects unknown formats first).

Looks good to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6072838320 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2873#pullrequestreview-6072838320). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T10:52:58Z. **Review:** APPROVED --- Verified `5bd7e1c9` locally on Windows 11 (RTX 5090 and WARP, with `VICTORY_D3D12_DEBUG=1`): - `cargo xtask policy` and `cargo clippy -p victory-gpu --tests -- -D warnings` (default and `--all-features`): clean. - `descriptor::` tests (including both new tests `buffer_views_take_a_format_the_host_takes` and `typed_buffer_views_take_only_formats_the_device_buffers_take`): 23/23 passed on RTX 5090, RTX 5090 + `VICTORY_D3D12_DEBUG=1`, and WARP + `VICTORY_D3D12_DEBUG=1` (excluding the pre-existing `dynamic_slots_are_held_until_released` baseline failure). - `draw::tests`: 20/20 passed on RTX 5090 and WARP + `VICTORY_D3D12_DEBUG=1`. The raw (`R32_TYPELESS`, rejecting `stride > 0`), structured (`DXGI_FORMAT_UNKNOWN`), and typed (`BUFFER` + `SHADER_LOAD` / `TYPED_UNORDERED_ACCESS_VIEW`, rejecting `UNKNOWN` and typeless formats) rules match D3D12 requirements cleanly. Two minor non-blocking nits: - Running `host_buffer_format` before `shadow::for_view` in `buffer_srv` and `buffer_uav` would avoid lazily creating a host shadow buffer / Arena slice for stale or unsupported buffer views that are immediately rejected. - `f.checked_add(1).is_some_and(|n| family(n) == f)` in `host_buffer_format` avoids a debug overflow if it is ever called directly with `DXGI_FORMAT(-1)` (currently unreachable from `buffer_srv`/`buffer_uav` since `element_size` rejects unknown formats first). Looks good to merge.
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/2873:upstream-pr/2873'
git switch 'upstream-pr/2873'

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/2873'
git switch 'upstream-pr/2873'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2873'
git switch 'upstream-pr/2873'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2873'
git switch 'main'
git merge --squash 'upstream-pr/2873'
git switch 'main'
git merge --ff-only 'upstream-pr/2873'
git switch 'main'
git merge 'upstream-pr/2873'
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
Marvisak/VIctory!2871
No description provided.