fix(gpu): add RTV/UAV format fallbacks and restrict format 67 promotion for placed views #2832

Open
github-bot wants to merge 6 commits from github-bot/gh-2832 into main AGit
Owner

@⁠legayclightning22 on GitHub · 2026-11-25 21:40 UTC · original
legayclightning22:fix/placed-view-format-67 → main · +251 −10 · 3 files · 6 commits · open

Why This Change Is Needed & What It Improves

Prevents D3D12 resource creation failures, placed-view format mismatches, and GPU device hangs/TDRs when titles bind textures with formats that lack native RTV/UAV hardware support or alias placed SRVs over existing texture memory.

Specifically, this improves:

  • Render Target & UAV Compatibility: Titles creating render targets or unordered access views with formats 67, 86, or 115 cleanly promote to hardware-supported D3D12 formats (26 / 87) instead of failing resource creation or triggering D3D12 validation errors.
  • Placed View Aliasing Stability: Placed SRVs aliasing format 67 textures keep their expected format unless RTV/UAV promotion is strictly required, preventing silent format mismatches during draw calls (including the draw.rs format 67 -> 26 placed-view failure).
  • Host Texture Reuse: Placed views accurately match existing HostTexture allocations via t.castable, reducing redundant texture allocations and preventing incompatible view bindings.

What Was Happening & Root Cause

  1. Unsupported RTV/UAV Formats (67, 86, 115): Certain translated texture formats do not natively support RTV or UAV usage flags on D3D12 hardware. Previously, make_texture attempted to allocate these formats directly without checking format_support, leading to failed resource creation, invalid view bindings, and downstream device removal/TDRs during rendering passes.
  2. Over-Aggressive Format 67 Promotion on Placed Views: Promoting format 67 unconditionally to 26 broke placed SRV views that alias the underlying memory as format 67, causing a format mismatch (67 vs. 26) at draw time.
  3. Strict Format Equality on Placed Views: HostTexture::takes checked exact format equality rather than checking whether the requested format was in t.castable, rejecting valid placed-view aliases over compatible typeless/castable backing textures.

Changes Made

  • RTV/UAV Fallback Promotion (crates/victory-gpu/src/resource.rs): Added format_support queries in make_texture to promote unsupported RTV/UAV formats (67 -> 26, 86 -> 87, 115 -> 26) when required by resource usage flags.
  • Scoped Format 67 Promotion: Restricted format 67 -> 26 promotion to need_rtv || (need_uav && d.flags & !UNORDERED != 0) so placed SRVs do not get unexpectedly promoted to format 26.
  • Castable Placed-View Matching: Updated HostTexture::takes to check t.castable.contains(&d.format) for placed views.

Verification

  • Ported unit test host_texture_handles_unsupported_rtv_and_uav_formats in crates/victory-gpu/src/resource.rs.
  • Verified cargo test -p victory-gpu --lib --features diagnostics on WARP (199 passed; 0 failed) and cargo clippy -p victory-gpu --all-targets (0 errors; 0 warnings).

(Split from #1799 into a single-topic PR as requested.)

**@⁠legayclightning22** on GitHub · 2026-11-25 21:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2832) `legayclightning22:fix/placed-view-format-67` → `main` · +251 −10 · 3 files · 6 commits · open ### Why This Change Is Needed & What It Improves Prevents D3D12 resource creation failures, placed-view format mismatches, and GPU device hangs/TDRs when titles bind textures with formats that lack native RTV/UAV hardware support or alias placed SRVs over existing texture memory. Specifically, this improves: - **Render Target & UAV Compatibility:** Titles creating render targets or unordered access views with formats `67`, `86`, or `115` cleanly promote to hardware-supported D3D12 formats (`26` / `87`) instead of failing resource creation or triggering D3D12 validation errors. - **Placed View Aliasing Stability:** Placed SRVs aliasing format `67` textures keep their expected format unless RTV/UAV promotion is strictly required, preventing silent format mismatches during draw calls (including the `draw.rs` format `67 -> 26` placed-view failure). - **Host Texture Reuse:** Placed views accurately match existing `HostTexture` allocations via `t.castable`, reducing redundant texture allocations and preventing incompatible view bindings. ### What Was Happening & Root Cause 1. **Unsupported RTV/UAV Formats (`67`, `86`, `115`):** Certain translated texture formats do not natively support RTV or UAV usage flags on D3D12 hardware. Previously, `make_texture` attempted to allocate these formats directly without checking `format_support`, leading to failed resource creation, invalid view bindings, and downstream device removal/TDRs during rendering passes. 2. **Over-Aggressive Format `67` Promotion on Placed Views:** Promoting format `67` unconditionally to `26` broke placed SRV views that alias the underlying memory as format `67`, causing a format mismatch (`67` vs. `26`) at draw time. 3. **Strict Format Equality on Placed Views:** `HostTexture::takes` checked exact format equality rather than checking whether the requested format was in `t.castable`, rejecting valid placed-view aliases over compatible typeless/castable backing textures. ### Changes Made - **RTV/UAV Fallback Promotion (`crates/victory-gpu/src/resource.rs`):** Added `format_support` queries in `make_texture` to promote unsupported RTV/UAV formats (`67 -> 26`, `86 -> 87`, `115 -> 26`) when required by resource usage flags. - **Scoped Format `67` Promotion:** Restricted format `67 -> 26` promotion to `need_rtv || (need_uav && d.flags & !UNORDERED != 0)` so placed SRVs do not get unexpectedly promoted to format `26`. - **Castable Placed-View Matching:** Updated `HostTexture::takes` to check `t.castable.contains(&d.format)` for placed views. ### Verification - Ported unit test `host_texture_handles_unsupported_rtv_and_uav_formats` in `crates/victory-gpu/src/resource.rs`. - Verified `cargo test -p victory-gpu --lib --features diagnostics` on WARP (`199 passed; 0 failed`) and `cargo clippy -p victory-gpu --all-targets` (`0 errors; 0 warnings`). *(Split from #1799 into a single-topic PR as requested.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:15:21 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 22:47 UTC · original

Tested 2f949b38 on Windows 11 (RTX 5090 + WARP) and found a deterministic RTX 5090 test regression plus three format/view-compatibility issues:

1. Deterministic RTX 5090 regression (draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view)

  • Passes on base 13f91ca, passes on commits 06a1633 and 9445274, and passes on WARP, but fails 5/5 runs on RTX 5090 at HEAD 2f949b38 (including with VICTORY_D3D12_DEBUG=1): crates/victory-gpu/src/draw.rs:2396: round 0: one host texture left: false right: true.
  • Root cause: round 0 registers object (R32_UINT 42, flags=4 lazy) first, then placed_view (R9G9B9E5_SHAREDEXP 67, flags=0) triggers .host() via placed_texture -> texture_at. shared_texture merges object's UNORDERED onto format 67; on RTX 5090 format_support(67) lacks TYPED_UNORDERED_ACCESS_VIEW, so 2f949b38 skips 67 -> 26 promotion and strips UNORDERED (d.flags &= !UNORDERED) even though UNORDERED came from the castable sibling R32_UINT (42). When host_copy(object) then calls takes(), the host texture lacks UNORDERED, forcing a second HostTexture and breaking shared-texture aliasing.

2. Silent cross-family & cross-bpp promotion breaks views and copies

  • Mutating only the local d.format in make_texture (67 -> 26, 86/115 -> 87) without updating Resource::desc causes:
    • descriptor::host::fits() to reject views in the original format family as mismatched and null them out;
    • CreateRenderTargetView with original format 86/115/67 against an 87/26 host resource to violate D3D12 format rules;
    • 86/115 (16-bit, 2 B/px) -> 87 (32-bit, 4 B/px) to double bytes-per-pixel, breaking upload/alias_copy/read_back strides.

3. HostTexture::takes regression (resource.rs:1305)

  • Changing t.castable.iter().any(|&c| family(c) == family(d.format)) to t.castable.contains(&d.format) breaks typeless cross-family placed matches (e.g. 27/90) because castable() excludes typeless formats.

4. Minor

  • CheckFeatureSupport is called uncached on every make_texture, and host_texture_handles_unsupported_rtv_and_uav_formats only asserts make_texture(...).is_some() without testing RTV/SRV/UAV creation or copies.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 22:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2832#issuecomment-7176790500) Tested `2f949b38` on Windows 11 (RTX 5090 + WARP) and found a **deterministic RTX 5090 test regression** plus three format/view-compatibility issues: ### 1. Deterministic RTX 5090 regression (`draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view`) - Passes on base `13f91ca`, passes on commits `06a1633` and `9445274`, and passes on WARP, **but fails 5/5 runs on RTX 5090 at HEAD `2f949b38`** (including with `VICTORY_D3D12_DEBUG=1`): `crates/victory-gpu/src/draw.rs:2396: round 0: one host texture left: false right: true`. - **Root cause**: `round 0` registers `object` (`R32_UINT` 42, `flags=4` lazy) first, then `placed_view` (`R9G9B9E5_SHAREDEXP` 67, `flags=0`) triggers `.host()` via `placed_texture -> texture_at`. `shared_texture` merges `object`'s `UNORDERED` onto format `67`; on RTX 5090 `format_support(67)` lacks `TYPED_UNORDERED_ACCESS_VIEW`, so `2f949b38` skips `67 -> 26` promotion and strips `UNORDERED` (`d.flags &= !UNORDERED`) even though `UNORDERED` came from the castable sibling `R32_UINT (42)`. When `host_copy(object)` then calls `takes()`, the host texture lacks `UNORDERED`, forcing a second `HostTexture` and breaking shared-texture aliasing. ### 2. Silent cross-family & cross-bpp promotion breaks views and copies - Mutating only the local `d.format` in `make_texture` (`67 -> 26`, `86/115 -> 87`) without updating `Resource::desc` causes: - `descriptor::host::fits()` to reject views in the original format family as mismatched and null them out; - `CreateRenderTargetView` with original format `86`/`115`/`67` against an `87`/`26` host resource to violate D3D12 format rules; - `86`/`115` (16-bit, 2 B/px) -> `87` (32-bit, 4 B/px) to double bytes-per-pixel, breaking `upload`/`alias_copy`/`read_back` strides. ### 3. `HostTexture::takes` regression (`resource.rs:1305`) - Changing `t.castable.iter().any(|&c| family(c) == family(d.format))` to `t.castable.contains(&d.format)` breaks typeless cross-family placed matches (e.g. `27`/`90`) because `castable()` excludes typeless formats. ### 4. Minor - `CheckFeatureSupport` is called uncached on every `make_texture`, and `host_texture_handles_unsupported_rtv_and_uav_formats` only asserts `make_texture(...).is_some()` without testing RTV/SRV/UAV creation or copies.
Author
Owner

@⁠legayclightning22 on GitHub · 2026-11-26 01:05 UTC · original

Thank you both for the thorough review and RTX 5090 hardware verification!

@kotecompotek

  • Thank you for mapping out how this overlaps with #2773, #2834, and #2442 and confirming why handling unsupported RTV/UAV formats at make_texture avoids #2834's family-members trap while keeping the !typeless guard scoped to standalone formats.
  • Good call on aligning with #2442's host_desc-side flag drop so format promotion vs. flag dropping stays consistent across the pipeline.

@fuzeofficial

Thank you for catching the deterministic RTX 5090 failure and the three format/view-compatibility issues that WARP didn't surface:

  1. RTX 5090 shared_texture / UNORDERED stripping regression (a_texture_written_in_one_format_reads_in_another_through_a_placed_view):
    • Root cause confirmed: when shared_texture merges UNORDERED from a castable sibling (R32_UINT 42) onto format 67, skipping 67 -> 26 promotion and stripping UNORDERED (d.flags &= !UNORDERED) breaks HostTexture::takes() on subsequent host_copy calls and forces a duplicate HostTexture, breaking shared-texture aliasing.
  2. Silent cross-family & cross-bpp promotion (67 -> 26, 86/115 -> 87):
    • Agreed: mutating only the local d.format inside make_texture without updating Resource::desc causes descriptor::host::fits() to null out views in the original format family, violates D3D12 format rules on CreateRenderTargetView, and doubles bytes-per-pixel (86/115 16-bit -> 87 32-bit), breaking upload / alias_copy / read_back strides.
  3. HostTexture::takes typeless cross-family regression (resource.rs:1305):
    • Agreed: narrowing t.castable.iter().any(|&c| family(c) == family(d.format)) to t.castable.contains(&d.format) rejects valid typeless cross-family placed matches (such as 27 / 90) because castable() excludes typeless formats.
  4. Caching & test coverage:
    • Valid point on caching CheckFeatureSupport rather than querying uncached per make_texture, and extending unit tests beyond make_texture(...).is_some() to exercise actual RTV/SRV/UAV view creation and copies.

I am updating fix/placed-view-format-67 to resolve these four items and coordinate cleanly with #2442.

**@⁠legayclightning22** on GitHub · 2026-11-26 01:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2832#issuecomment-7179418314) Thank you both for the thorough review and RTX 5090 hardware verification! ### `@kotecompotek` - Thank you for mapping out how this overlaps with `#2773`, `#2834`, and `#2442` and confirming why handling unsupported RTV/UAV formats at `make_texture` avoids `#2834`'s family-members trap while keeping the `!typeless` guard scoped to standalone formats. - Good call on aligning with `#2442`'s `host_desc`-side flag drop so format promotion vs. flag dropping stays consistent across the pipeline. ### `@fuzeofficial` Thank you for catching the deterministic RTX 5090 failure and the three format/view-compatibility issues that WARP didn't surface: 1. **RTX 5090 `shared_texture` / `UNORDERED` stripping regression (`a_texture_written_in_one_format_reads_in_another_through_a_placed_view`):** - Root cause confirmed: when `shared_texture` merges `UNORDERED` from a castable sibling (`R32_UINT` `42`) onto format `67`, skipping `67 -> 26` promotion and stripping `UNORDERED` (`d.flags &= !UNORDERED`) breaks `HostTexture::takes()` on subsequent `host_copy` calls and forces a duplicate `HostTexture`, breaking shared-texture aliasing. 2. **Silent cross-family & cross-bpp promotion (`67 -> 26`, `86/115 -> 87`):** - Agreed: mutating only the local `d.format` inside `make_texture` without updating `Resource::desc` causes `descriptor::host::fits()` to null out views in the original format family, violates D3D12 format rules on `CreateRenderTargetView`, and doubles bytes-per-pixel (`86/115` 16-bit -> `87` 32-bit), breaking `upload` / `alias_copy` / `read_back` strides. 3. **`HostTexture::takes` typeless cross-family regression (`resource.rs:1305`):** - Agreed: narrowing `t.castable.iter().any(|&c| family(c) == family(d.format))` to `t.castable.contains(&d.format)` rejects valid typeless cross-family placed matches (such as `27` / `90`) because `castable()` excludes typeless formats. 4. **Caching & test coverage:** - Valid point on caching `CheckFeatureSupport` rather than querying uncached per `make_texture`, and extending unit tests beyond `make_texture(...).is_some()` to exercise actual RTV/SRV/UAV view creation and copies. I am updating `fix/placed-view-format-67` to resolve these four items and coordinate cleanly with `#2442`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 03:19 UTC · original

Automated triage for the maintainers.

Verdict: needs work. It merges cleanly, but the approach in make_texture (crates/victory-gpu/src/resource.rs) changes data, not just flags. It swaps d.format for the host texture only. 86/115 are 2 bytes per texel and become 87 at 4 bytes, so uploads, alias copies and readbacks of title memory use the wrong stride. 67 (R9G9B9E5) becomes 26 (R11G11B10_FLOAT), which reads the same bits as a different encoding. Resource::desc keeps the old format, so views made in the original format no longer match the texture. In takes, castable.contains(&d.format) rejects typeless placed matches that the family check accepted. fuzeofficlal also reports draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view failing 5/5 on an RTX 5090. The new test only checks that make_texture returns Some.

You said you are reworking this. Please also check #2442, #2626 and #2767, which handle the same formats. To change this verdict, a stand-in format needs matching conversion on upload and readback, plus tests that write through the view and read the data back.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 03:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2832#issuecomment-7181612565) <!-- victory-triage v1 head=2f949b389b15dfd0f434b35572fece483b5428c1 verdict=needs-work at=2026-11-26T03:19:36Z --> Automated triage for the maintainers. **Verdict: needs work.** It merges cleanly, but the approach in `make_texture` (`crates/victory-gpu/src/resource.rs`) changes data, not just flags. It swaps `d.format` for the host texture only. `86`/`115` are 2 bytes per texel and become `87` at 4 bytes, so uploads, alias copies and readbacks of title memory use the wrong stride. `67` (R9G9B9E5) becomes `26` (R11G11B10_FLOAT), which reads the same bits as a different encoding. `Resource::desc` keeps the old format, so views made in the original format no longer match the texture. In `takes`, `castable.contains(&d.format)` rejects typeless placed matches that the family check accepted. fuzeofficlal also reports `draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view` failing 5/5 on an RTX 5090. The new test only checks that `make_texture` returns `Some`. You said you are reworking this. Please also check #2442, #2626 and #2767, which handle the same formats. To change this verdict, a stand-in format needs matching conversion on upload and readback, plus tests that write through the view and read the data back. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 21:58 UTC · original · reviewed

Noting the overlap: this is the third concurrent take on the unsupported-RTV/UAV space (after #2773's view-side guard, #2834, and #2442's flag-drop in host_desc). Doing it in make_texture avoids #2834's family-members trap — the !typeless guard means only standalone formats reach the drop, where no cast path exists anyway; and the takes() narrowing to exact castable.contains is stricter and correct (a family member not in the creation's castable list is not a legal view format). The 67 promotion gate — promote only when RTV is needed, or UAV plus OTHER uses — is right: a UAV-only 67 texture can't be rescued by promotion since 26 lacks typed UAV there anyway, so it keeps its format and just loses the use. Query-failure->support=0 errs toward dropping uses rather than crashing creation, which is the safe direction given a NULL descriptor beats a removed device. LGTM; worth coordinating with #2442's host_desc-side drop so the two don't diverge on which formats get promoted vs flagged.

**@⁠kotekompotek** on GitHub · 2026-11-25 21:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2832#pullrequestreview-6065560474) · **reviewed** Noting the overlap: this is the third concurrent take on the unsupported-RTV/UAV space (after #2773's view-side guard, #2834, and #2442's flag-drop in host_desc). Doing it in make_texture avoids #2834's family-members trap — the !typeless guard means only standalone formats reach the drop, where no cast path exists anyway; and the takes() narrowing to exact castable.contains is stricter and correct (a family member not in the creation's castable list is not a legal view format). The 67 promotion gate — promote only when RTV is needed, or UAV plus OTHER uses — is right: a UAV-only 67 texture can't be rescued by promotion since 26 lacks typed UAV there anyway, so it keeps its format and just loses the use. Query-failure->support=0 errs toward dropping uses rather than crashing creation, which is the safe direction given a NULL descriptor beats a removed device. LGTM; worth coordinating with #2442's host_desc-side drop so the two don't diverge on which formats get promoted vs flagged.
Author
Owner

@⁠legayclightning22 on GitHub · 2026-11-26 14:39 UTC · original

Updated fix/placed-view-format-67 (cfd2a4f):

  • Removed all d.format and clear_value format mutations (67 -> 26, 86/115 -> 87, and sibling format swaps) so Resource::desc and texel strides remain unchanged.
  • Updated host_desc to strip unsupported standalone RENDER_TARGET and UNORDERED flags on non-typeless textures via cached Host::format_support (CheckFeatureSupport).
  • Updated shared_texture so placed views (format = 67) sharing memory with an UNORDERED resource reuse the underlying HostTexture without forcing unsupported flags onto format 67.
  • Verified a_texture_written_in_one_format_reads_in_another_through_a_placed_view, host_texture_handles_unsupported_rtv_and_uav_formats, cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics), and cargo xtask policy.
**@⁠legayclightning22** on GitHub · 2026-11-26 14:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2832#issuecomment-7195127036) Updated `fix/placed-view-format-67` (`cfd2a4f`): - Removed all `d.format` and `clear_value` format mutations (`67 -> 26`, `86/115 -> 87`, and sibling format swaps) so `Resource::desc` and texel strides remain unchanged. - Updated `host_desc` to strip unsupported standalone `RENDER_TARGET` and `UNORDERED` flags on non-typeless textures via cached `Host::format_support` (`CheckFeatureSupport`). - Updated `shared_texture` so placed views (`format = 67`) sharing memory with an `UNORDERED` resource reuse the underlying `HostTexture` without forcing unsupported flags onto format `67`. - Verified `a_texture_written_in_one_format_reads_in_another_through_a_placed_view`, `host_texture_handles_unsupported_rtv_and_uav_formats`, `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`), and `cargo xtask policy`.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2832/head:github-bot/gh-2832'
git switch 'github-bot/gh-2832'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2832'
git switch 'github-bot/gh-2832'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2832'
git switch 'github-bot/gh-2832'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2832'
git switch 'main'
git merge --squash 'github-bot/gh-2832'
git switch 'main'
git merge --ff-only 'github-bot/gh-2832'
git switch 'main'
git merge 'github-bot/gh-2832'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2832
No description provided.