GPU: ignore clear values on non-target textures and avoid caching failed host textures in PLACED_TEXTURES #1421

Open
ESAT586 wants to merge 1 commit from upstream-pr/1422 into main
ESAT586 commented 2026-11-24 17:55:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-24T17:55:43Z.


AI Transparency Notice: This PR was authored, implemented, and hardware-tested by Gemini 4 Neon (High Mode) (an AI coding agent, not a human engineer), using zero game files or proprietary console SDK data.

Summary

Fixes two resource-creation bugs tracked in #1242 (VIC-BT-022 and VIC-BT-027) in crates/victory-gpu/src/resource.rs:

  1. Optimized clear value on non-target textures (VIC-BT-022):

    • D3D12 CreateCommittedResource rejects a non-null pOptimizedClearValue unless D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET or D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL is set.
    • host_texture() now ignores clear whenever d.flags & (1 | 2) == 0.
  2. Failed host textures cached in PLACED_TEXTURES (VIC-BT-027):

    • texture_at() previously inserted out into PLACED_TEXTURES before checking resource(out).host.is_some(). If host texture creation failed, the first call returned None while leaking the Resource box, and every subsequent lookup for that (address, desc) returned Some(r) with host == None.
    • texture_at() now checks resource(out).host.is_none() first, releases out via object::release_boxed::<Resource>(out), and returns None without poisoning PLACED_TEXTURES.

Verification

Tested locally on Windows 11 with NVIDIA GeForce RTX 3060 Ti (Driver 32.0.16.1656), Rust 1.98.1 MSVC:

  • cargo clippy --workspace --all-targets --locked -- -D warnings — 0 warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — 0 warnings
  • cargo test -p victory-gpu --all-features --locked — 54 passed, 0 failed, 1 ignored (including non_target_texture_ignores_clear_value_and_placed_cache_skips_failures on RTX 3060 Ti)
  • cargo xtask policy — 154 files ok
<!-- greyfinch-sync:Marvisak/VIctory:issue:6588088766 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1422). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-24T17:55:43Z. --- > **AI Transparency Notice:** This PR was authored, implemented, and hardware-tested by **Gemini 4 Neon (High Mode)** (an AI coding agent, not a human engineer), using **zero game files or proprietary console SDK data**. ## Summary Fixes two resource-creation bugs tracked in #1242 (`VIC-BT-022` and `VIC-BT-027`) in `crates/victory-gpu/src/resource.rs`: 1. **Optimized clear value on non-target textures (`VIC-BT-022`):** - D3D12 `CreateCommittedResource` rejects a non-null `pOptimizedClearValue` unless `D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET` or `D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL` is set. - `host_texture()` now ignores `clear` whenever `d.flags & (1 | 2) == 0`. 2. **Failed host textures cached in `PLACED_TEXTURES` (`VIC-BT-027`):** - `texture_at()` previously inserted `out` into `PLACED_TEXTURES` before checking `resource(out).host.is_some()`. If host texture creation failed, the first call returned `None` while leaking the `Resource` box, and every subsequent lookup for that `(address, desc)` returned `Some(r)` with `host == None`. - `texture_at()` now checks `resource(out).host.is_none()` first, releases `out` via `object::release_boxed::<Resource>(out)`, and returns `None` without poisoning `PLACED_TEXTURES`. ## Verification Tested locally on Windows 11 with **NVIDIA GeForce RTX 3060 Ti** (`Driver 32.0.16.1656`), Rust `1.98.1` MSVC: - `cargo clippy --workspace --all-targets --locked -- -D warnings` — **0 warnings** - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` — **0 warnings** - `cargo test -p victory-gpu --all-features --locked` — **54 passed, 0 failed, 1 ignored** (including `non_target_texture_ignores_clear_value_and_placed_cache_skips_failures` on RTX 3060 Ti) - `cargo xtask policy` — **154 files ok**
wbkepler commented 2026-11-24 21:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T20:56:20Z.


Interaction note: the VIC-BT-027 half of this PR matches the texture_at hunk in #1353. Both release out before inserting into PLACED_TEXTURES and return None. object::release_boxed::<Resource> is exactly what resource_release does, so the two versions behave the same. Releasing while holding the PLACED_TEXTURES lock is also safe: Drop for Resource only touches texture::forget, descriptor::forget and shadow, never that map. Only one of the two needs to land.

The VIC-BT-022 half is only in this PR and looks right. The check runs after d.flags &= PC_FLAGS, so the RT (1) and DS (2) bits it tests are the ones the host will actually see.

AI-assisted review (Claude Code); checked on Windows 11 / RTX 5090.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144257952 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1422#issuecomment-7144257952). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T20:56:20Z. --- Interaction note: the VIC-BT-027 half of this PR matches the `texture_at` hunk in #1353. Both release `out` before inserting into `PLACED_TEXTURES` and return `None`. `object::release_boxed::<Resource>` is exactly what `resource_release` does, so the two versions behave the same. Releasing while holding the `PLACED_TEXTURES` lock is also safe: `Drop for Resource` only touches `texture::forget`, `descriptor::forget` and `shadow`, never that map. Only one of the two needs to land. The VIC-BT-022 half is only in this PR and looks right. The check runs after `d.flags &= PC_FLAGS`, so the RT (1) and DS (2) bits it tests are the ones the host will actually see. _AI-assisted review (Claude Code); checked on Windows 11 / RTX 5090._
acetonahard-code commented 2026-11-24 21:28:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by acetonahard-code on 2026-11-24T21:08:01Z.


Partial overlap: #1353 also stops texture_at from caching a placed texture whose host texture failed, as part of a larger change. The two conflict in resource.rs.

Tested on Windows 11, RTX 4070 SUPER (driver 621.14), with the repo toolchain, merged into current main (ffe310e):

cargo test -p victory-gpu passed failed ignored
main 50 0 1
main + this PR 51 0 1
main, --all-features 53 0 -
main + this PR, --all-features 54 0 -
  • The new test passes.
  • No GPU test skipped for lack of a device.
  • cargo clippy --all-targets -- -D warnings, with and without --all-features: clean.
  • Minor: cargo fmt --check would rewrap 2 blocks this PR adds (resource.rs). main isn't rustfmt-clean either, so take it or leave it.

I didn't test with game data.


Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144519662 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1422#issuecomment-7144519662). Originally posted by [acetonahard-code](https://github.com/acetonahard-code) on 2026-11-24T21:08:01Z. --- Partial overlap: #1353 also stops `texture_at` from caching a placed texture whose host texture failed, as part of a larger change. The two conflict in `resource.rs`. Tested on Windows 11, RTX 4070 SUPER (driver 621.14), with the repo toolchain, merged into current `main` (ffe310e): | `cargo test -p victory-gpu` | passed | failed | ignored | |---|---|---|---| | `main` | 50 | 0 | 1 | | `main` + this PR | 51 | 0 | 1 | | `main`, `--all-features` | 53 | 0 | - | | `main` + this PR, `--all-features` | 54 | 0 | - | - The new test passes. - No GPU test skipped for lack of a device. - `cargo clippy --all-targets -- -D warnings`, with and without `--all-features`: clean. - Minor: `cargo fmt --check` would rewrap 2 blocks this PR adds (`resource.rs`). `main` isn't rustfmt-clean either, so take it or leave it. I didn't test with game data. --- <sub>Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.</sub>
Marvisak commented 2026-11-25 04:06:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:27:17Z.


Automated triage for the maintainers.

Needs work.

The clear-value half looks right. In make_texture (crates/victory-gpu/src/resource.rs), the PR drops the optimized clear value unless the host flags include render target or depth-stencil. D3D12 rejects a clear value on any other texture.

The texture_at half changes behaviour, and the stated reason does not match main. On main, a resource whose host texture failed is not leaked. It stays in PLACED_TEXTURES, and Resource::host caches the failure as Some(None). So later lookups get the same resource without another attempt, and callers such as placed_texture already handle a resource with no host copy. With this PR, every lookup for such memory runs create_at_address and a failing host texture creation again. That is a repeated failing D3D12 call on each descriptor write. The PR also creates the resource before inserting it, so concurrent callers now each build one and all but one are thrown away.

To move forward, either drop the texture_at change and keep the clear-value fix, or show a case where retrying succeeds (for example a transient budget failure) and limit how often it retries.

CI (check) passes on this head.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151929132 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1422#issuecomment-7151929132). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:27:17Z. --- <!-- victory-triage v1 head=4e3e66904e72b46a402bc0253653e8a05a85e5a3 verdict=needs-work at=2026-11-25T16:42:19Z --> Automated triage for the maintainers. **Needs work.** The clear-value half looks right. In `make_texture` (`crates/victory-gpu/src/resource.rs`), the PR drops the optimized clear value unless the host flags include render target or depth-stencil. D3D12 rejects a clear value on any other texture. The `texture_at` half changes behaviour, and the stated reason does not match main. On main, a resource whose host texture failed is not leaked. It stays in `PLACED_TEXTURES`, and `Resource::host` caches the failure as `Some(None)`. So later lookups get the same resource without another attempt, and callers such as `placed_texture` already handle a resource with no host copy. With this PR, every lookup for such memory runs `create_at_address` and a failing host texture creation again. That is a repeated failing D3D12 call on each descriptor write. The PR also creates the resource before inserting it, so concurrent callers now each build one and all but one are thrown away. To move forward, either drop the `texture_at` change and keep the clear-value fix, or show a case where retrying succeeds (for example a transient budget failure) and limit how often it retries. CI (`check`) passes on this head. --- _Generated by [Claude Code](https://claude.ai/code)_
andrewpozdnakov7-jpg commented 2026-11-26 03:05:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T02:38:20Z.


I tested the clear-value half separately in response to the review. 14f1028 is a fast-forward from your exact HEAD 4e3e669. It keeps your clear-value guard and restores the previous texture_at behavior.

The same synthetic Windows/WARP test calls create_committed and fetches the D3D12 resource. On upstream 63bcca4, the sampled and UAV textures given a clear value have no host resource. With the narrowed change both get one. The sampled texture given a null clear value and the render-target and depth-stencil controls succeed in both builds. Six paired runs gave the same result, and the fixture verifies the flags of each returned resource.

The fork commit passed 199 GPU tests with one ignored. Its clean merge with 63bcca4 matches the source used for the current-main test, which passed 247 GPU tests with one ignored. Strict GPU Clippy and the asset policy passed.

Please retain the Git author if you cherry-pick the follow-up. If you fold the test or other changes from this commit into yours, please include:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

AI-assisted with Codex. Synthetic resources only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180986062 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1422#issuecomment-7180986062). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T02:38:20Z. --- I tested the clear-value half separately in response to the [review](https://github.com/Marvisak/VIctory/pull/1422#issuecomment-7151929132). [14f1028](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/14f10284430854c7d3b846ff5aae1e31eb045747) is a fast-forward from your exact HEAD `4e3e669`. It keeps your clear-value guard and restores the previous `texture_at` behavior. The same synthetic Windows/WARP test calls `create_committed` and fetches the D3D12 resource. On upstream `63bcca4`, the sampled and UAV textures given a clear value have no host resource. With the narrowed change both get one. The sampled texture given a null clear value and the render-target and depth-stencil controls succeed in both builds. Six paired runs gave the same result, and the fixture verifies the flags of each returned resource. The fork commit passed 199 GPU tests with one ignored. Its clean merge with `63bcca4` matches the source used for the current-main test, which passed 247 GPU tests with one ignored. Strict GPU Clippy and the asset policy passed. Please retain the Git author if you cherry-pick the follow-up. If you fold the test or other changes from this commit into yours, please include: Co-authored-by: andrewpozdnakov7-jpg <[email protected]> AI-assisted with Codex. Synthetic resources only.
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/1422:upstream-pr/1422'
git switch 'upstream-pr/1422'

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