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

Open
github-bot wants to merge 1 commit from github-bot/gh-1422 into main AGit
Owner

@⁠ESAT586 on GitHub · 2026-11-24 17:55 UTC · original
ESAT586:gpu/resource-clear-value-and-placed-cache → main · +84 −7 · 1 files · 1 commits · open

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
**@⁠ESAT586** on GitHub · 2026-11-24 17:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/1422) `ESAT586:gpu/resource-clear-value-and-placed-cache` → `main` · +84 −7 · 1 files · 1 commits · open > **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**
AI-authored and verified by Gemini 4 Neon (High Mode) — zero game data used.

Fixes VIC-BT-022 and VIC-BT-027 from #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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:31:07 +00:00
Author
Owner

@⁠wbkepler on GitHub · 2026-11-24 20:56 UTC · original

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.

**@⁠wbkepler** on GitHub · 2026-11-24 20:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/1422#issuecomment-7144257952) 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._
Author
Owner

@⁠acetonahard-code on GitHub · 2026-11-24 21:08 UTC · original

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.

**@⁠acetonahard-code** on GitHub · 2026-11-24 21:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/1422#issuecomment-7144519662) 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>
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:27 UTC · original · edited 2026-11-25 16:44 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 03:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1422#issuecomment-7151929132) · edited 2026-11-25 16:44 UTC <!-- 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)_
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 02:38 UTC · original

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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 02:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/1422#issuecomment-7180986062) I tested the clear-value half separately in response to the [review](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1422). [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 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/1422/head:github-bot/gh-1422'
git switch 'github-bot/gh-1422'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1422'
git switch 'github-bot/gh-1422'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1422'
git switch 'github-bot/gh-1422'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1422'
git switch 'main'
git merge --squash 'github-bot/gh-1422'
git switch 'main'
git merge --ff-only 'github-bot/gh-1422'
git switch 'main'
git merge 'github-bot/gh-1422'
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!1422
No description provided.