Skip to content

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

Open
ESAT586 wants to merge 1 commit into
Marvisak:mainfrom
ESAT586:gpu/resource-clear-value-and-placed-cache
Open

ESAT586 wants to merge 1 commit into
Marvisak:mainfrom
ESAT586:gpu/resource-clear-value-and-placed-cache

Conversation

@ESAT586

@ESAT586 ESAT586 commented Nov 24, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown

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.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

…led host textures in PLACED_TEXTURES

AI-authored and verified by Gemini 4 Neon (High Mode) — zero game data used.

Fixes VIC-BT-022 and VIC-BT-027 from Marvisak#1242 in `crates/victory-gpu/src/resource.rs`:
- `host_texture()`: only forwards `pOptimizedClearValue` when
  `ALLOW_RENDER_TARGET` (1) or `ALLOW_DEPTH_STENCIL` (2) is set, as required
  by D3D12 `CreateCommittedResource`.
- `texture_at()`: releases `out` and returns `None` without inserting into
  `PLACED_TEXTURES` when `resource(out).host.is_none()`, preventing both a
  leaked `Resource` allocation and subsequent `texture_at` calls from
  returning a cached `Some(r)` with `host == None`.
- Adds `non_target_texture_ignores_clear_value_and_placed_cache_skips_failures`
  verifying both fixes on the real D3D12 device.
@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

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 andrewpozdnakov7-jpg@users.noreply.github.com

AI-assisted with Codex. Synthetic resources only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants