gpu(native): keep colour attachment slots when a target has no host texture #61

Merged
ShadyUnderLight merged 3 commits from upstream-pr/61 into main 2026-11-26 12:58:22 +00:00
ShadyUnderLight commented 2026-11-26 12:07:07 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ShadyUnderLight on 2026-11-26T12:07:07Z.


Summary

OMSetRenderTargets dropped targets the host could not make, shortening the colour list so every later target moved down one slot; the binding is now refused instead.

Problem

  • glue::targets built the colour list with filter_map, so a target without a host texture (an unrepresentable format, or an RTV naming a resource with no texture) vanished from the middle of the list.
  • Metal binds rp.color[i] to colorAttachments[i], and the guessed pipeline is made from the same shortened format list, so SV_TargetN writes a surface an earlier slot owns.
  • The first filter_map has the same effect for an unknown or stale RTV handle.

Fix

  • Resolve every slot positionally; if any colour slot has no host texture, bind nothing, clear the recorded formats and refuse the draws that follow.
  • targets_ready on the title list records that state; graphics drops a draw while it is false.
  • A depth target that cannot be made is not renumbered and keeps today's behaviour (no depth attachment); left for a separate change.

Tests

a_target_the_host_cannot_make_does_not_shift_the_ones_after_it binds [format 12, format 28]; on main the bound format list has one entry (the second target moved into slot 0), here it is empty, and binding the makeable target again gives one.

Baseline failure:

thread 'native::tests::texture_tests::a_target_the_host_cannot_make_does_not_shift_the_ones_after_it' panicked at crates/victory-gpu/src/native/texture_tests.rs:348:5:
assertion `left == right` failed: a target without a host texture must not renumber the ones after it
  left: 1
 right: 0

With the change: test result: ok. 1 passed; 0 failed.

Verification

  • cargo test -p victory-gpu a_target_the_host_cannot_make_does_not_shift_the_ones_after_it — ok.
  • cargo test -p victory-gpu (native arm64) — 146 passed, 0 failed, 1 ignored.
  • cargo test -p victory-metal — 9 passed, 0 failed.
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings — clean.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings — the only errors are the two pre-existing unnecessary_cast findings in crates/victory-metal/src/present.rs:126,144; the same two appear on unmodified origin/main, so this change adds none.
  • cargo xtask policy — asset policy: 365 files ok.
  • cargo build --release --target x86_64-apple-darwin -p victory — ok.
  • Headless 60 s run on the current title: 0 occurrences of "a render target the host cannot make", recorded=13524 encoded=13524 no_pipeline=0 no_texture=0, 11 "frame presented" lines (last frame=1024). The title does not hit this path today, so the fix is a latent correctness fix; no frames were lost.

Risk

  • A title that binds a target the host cannot make now loses those draws instead of drawing them into the wrong surfaces.
  • No cost when every slot resolves: one Option collect and a bool.

Notes

All English, no game data in the repo. Found while auditing the native render-target path.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6626300800 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/61). Originally posted by [ShadyUnderLight](https://github.com/ShadyUnderLight) on 2026-11-26T12:07:07Z. --- ## Summary `OMSetRenderTargets` dropped targets the host could not make, shortening the colour list so every later target moved down one slot; the binding is now refused instead. ## Problem - `glue::targets` built the colour list with `filter_map`, so a target without a host texture (an unrepresentable format, or an RTV naming a resource with no texture) vanished from the middle of the list. - Metal binds `rp.color[i]` to `colorAttachments[i]`, and the guessed pipeline is made from the same shortened format list, so `SV_TargetN` writes a surface an earlier slot owns. - The first `filter_map` has the same effect for an unknown or stale RTV handle. ## Fix - Resolve every slot positionally; if any colour slot has no host texture, bind nothing, clear the recorded formats and refuse the draws that follow. - `targets_ready` on the title list records that state; `graphics` drops a draw while it is false. - A depth target that cannot be made is not renumbered and keeps today's behaviour (no depth attachment); left for a separate change. ## Tests `a_target_the_host_cannot_make_does_not_shift_the_ones_after_it` binds [format 12, format 28]; on main the bound format list has one entry (the second target moved into slot 0), here it is empty, and binding the makeable target again gives one. Baseline failure: ``` thread 'native::tests::texture_tests::a_target_the_host_cannot_make_does_not_shift_the_ones_after_it' panicked at crates/victory-gpu/src/native/texture_tests.rs:348:5: assertion `left == right` failed: a target without a host texture must not renumber the ones after it left: 1 right: 0 ``` With the change: `test result: ok. 1 passed; 0 failed`. ## Verification - `cargo test -p victory-gpu a_target_the_host_cannot_make_does_not_shift_the_ones_after_it` — ok. - `cargo test -p victory-gpu` (native arm64) — 146 passed, 0 failed, 1 ignored. - `cargo test -p victory-metal` — 9 passed, 0 failed. - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` — clean. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` — the only errors are the two pre-existing `unnecessary_cast` findings in `crates/victory-metal/src/present.rs:126,144`; the same two appear on unmodified `origin/main`, so this change adds none. - `cargo xtask policy` — `asset policy: 365 files ok`. - `cargo build --release --target x86_64-apple-darwin -p victory` — ok. - Headless 60 s run on the current title: 0 occurrences of "a render target the host cannot make", `recorded=13524 encoded=13524 no_pipeline=0 no_texture=0`, 11 "frame presented" lines (last `frame=1024`). The title does not hit this path today, so the fix is a latent correctness fix; no frames were lost. ## Risk - A title that binds a target the host cannot make now loses those draws instead of drawing them into the wrong surfaces. - No cost when every slot resolves: one `Option` collect and a bool. ## Notes All English, no game data in the repo. Found while auditing the native render-target path.
LakshanSivakumar commented 2026-11-26 12:48:23 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:48:23Z.

Review: APPROVED


Thanks. Positional colour-slot resolution with the whole binding refused when a slot is missing looks right, and the test fails on main. Approved.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6074387768 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/61#pullrequestreview-6074387768). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:48:23Z. **Review:** APPROVED --- Thanks. Positional colour-slot resolution with the whole binding refused when a slot is missing looks right, and the test fails on main. Approved.
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
LakshanSivakumar/Native-Victory-macOS!61
No description provided.