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

Manually merged
github merged 3 commits from gh-pr/61/head into gh-pr/61/base 2026-11-26 14:44:43 +00:00
Owner

@⁠ShadyUnderLight on GitHub · 2026-11-26 12:07 UTC · original
ShadyUnderLight:fix/target-slots → main · +72 −7 · 4 files · 3 commits · merged 2026-11-26 12:58 UTC

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.

**@⁠ShadyUnderLight** on GitHub · 2026-11-26 12:07 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/61) `ShadyUnderLight:fix/target-slots` → `main` · +72 −7 · 4 files · 3 commits · merged 2026-11-26 12:58 UTC ## 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.
OMSetRenderTargets built the colour list with filter_map, so a target the
host could not make (an unrepresentable format, or an RTV naming a resource
with no host texture) vanished from the middle of the list and every later
target moved down one slot. Metal binds rp.color[i] to colorAttachments[i]
and the guessed pipeline is made from the same shortened formats, so
SV_TargetN wrote a surface an earlier slot owns.

Resolve every slot positionally and, if any colour slot has no host
texture, bind nothing, clear the recorded formats and refuse the draws that
follow until the title binds a set the host can make. A depth target that
cannot be made does not renumber colour slots and keeps its current
behaviour (no depth attachment).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:44:42 +00:00
github manually merged commit a3345cdb1d into gh-pr/61/base 2026-11-26 14:44:43 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 12:48 UTC · original · approved these changes

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

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 12:48 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/61#pullrequestreview-6074387768) · **approved these changes** Thanks. Positional colour-slot resolution with the whole binding refused when a slot is missing looks right, and the test fails on main. Approved.
This discussion has been locked. Commenting is limited to contributors.
No description provided.