gpu(native): honor rectangular render-target color clears #206

Manually merged
github merged 1 commit from github-bot/gh-206 into main 2026-11-27 01:32:03 +00:00 AGit
Owner

@⁠evan-kolberg on GitHub · 2026-11-27 00:31 UTC · original
evan-kolberg:codex/native-rectangular-color-clear → main · +244 −22 · 7 files · 4 commits · merged 2026-11-27 00:58 UTC

Change

Carry the rectangles supplied to ClearRenderTargetView into the Native command list, clip them to the selected color view, and clear each surviving region. The command list owns the rectangle values from recording time. Empty or out-of-view rectangles leave the view alone. A zero rectangle count uses the existing whole-view clear.

The partial path clears a private Metal scratch attachment in the view's pixel format and copies the clipped regions via the ordered texture blit. This keeps Metal's sRGB and integer clear conversion and preserves the mip and slice selected by #171. The partial path covers single-sampled 2D and 2D array color views.

Verification

The checks used Native main f4030084.

  • M4 Pro, macOS 27.2.1, with Metal API Validation. The new Native command-list fixture passed 18 cases across RGBA8 UNORM, an sRGB RTV over linear RGBA8 storage, and RGBA8 UINT. It checked interior, clipped, empty, outside, multi-rectangle and zero-count calls at mip 1, slice 1, including adjacent subresources and writes to the caller's rectangle storage after recording.
  • The existing Native whole-view, view-format and mip/slice tests and the existing Metal texture blit test passed on the same tree.
  • The victory-gpu Windows cross-compile passed with --target x86_64-pc-windows-msvc --features blake3/pure.

Scratch cost

A separate generated fixture measured eight paired batches of 16 clears on the same 128×96 RGBA8 target, with a 32×24 partial rectangle. Median partial versus whole-view times were 359 vs 119 µs for CPU encoding, 224 vs 120 µs for GPU execution, and 380 vs 289 µs from commit to completion. Upload and readback were outside the timers, Metal API Validation was off for timing, and each sample checked every target pixel.

The partial path allocates one scratch texture per nonempty clear. Metal reported 4,224 allocated bytes for a matching 32×24 scratch, or 16 resources and 67,584 matching bytes per partial batch. Scratch dimensions use the maximum clipped width and height across the rectangles, so small crossed regions can require a larger allocation. Gameplay behavior and peak memory under queue backlog remain unmeasured.

Thanks to Sheffy007 for the ordered GPU texture copy in #183, merged at ae11992b9c25944940ce0b2987dfb7330839226d. This builds on #171's RTV mip and slice selection.

Prepared and tested with Codex.

**@⁠evan-kolberg** on GitHub · 2026-11-27 00:31 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/206) `evan-kolberg:codex/native-rectangular-color-clear` → `main` · +244 −22 · 7 files · 4 commits · merged 2026-11-27 00:58 UTC ## Change Carry the rectangles supplied to `ClearRenderTargetView` into the Native command list, clip them to the selected color view, and clear each surviving region. The command list owns the rectangle values from recording time. Empty or out-of-view rectangles leave the view alone. A zero rectangle count uses the existing whole-view clear. The partial path clears a private Metal scratch attachment in the view's pixel format and copies the clipped regions via the ordered texture blit. This keeps Metal's sRGB and integer clear conversion and preserves the mip and slice selected by #171. The partial path covers single-sampled 2D and 2D array color views. ## Verification The checks used Native main [`f4030084`](https://github.com/LakshanSivakumar/Native-Victory-macOS/commit/f4030084bca1defb424cef046b01147c47e52312). - M4 Pro, macOS 27.2.1, with Metal API Validation. The new Native command-list fixture passed 18 cases across RGBA8 UNORM, an sRGB RTV over linear RGBA8 storage, and RGBA8 UINT. It checked interior, clipped, empty, outside, multi-rectangle and zero-count calls at mip 1, slice 1, including adjacent subresources and writes to the caller's rectangle storage after recording. - The existing Native whole-view, view-format and mip/slice tests and the existing Metal texture blit test passed on the same tree. - The `victory-gpu` Windows cross-compile passed with `--target x86_64-pc-windows-msvc --features blake3/pure`. ## Scratch cost A separate generated fixture measured eight paired batches of 16 clears on the same 128×96 RGBA8 target, with a 32×24 partial rectangle. Median partial versus whole-view times were **359 vs 119 µs** for CPU encoding, **224 vs 120 µs** for GPU execution, and **380 vs 289 µs** from commit to completion. Upload and readback were outside the timers, Metal API Validation was off for timing, and each sample checked every target pixel. The partial path allocates one scratch texture per nonempty clear. Metal reported 4,224 allocated bytes for a matching 32×24 scratch, or 16 resources and 67,584 matching bytes per partial batch. Scratch dimensions use the maximum clipped width and height across the rectangles, so small crossed regions can require a larger allocation. Gameplay behavior and peak memory under queue backlog remain unmeasured. Thanks to Sheffy007 for the ordered GPU texture copy in [#183](https://git.gtahub.st/github/LakshanSivakumar--Native-Victory-macOS/pulls/183), merged at [`ae11992b9c25944940ce0b2987dfb7330839226d`](https://github.com/LakshanSivakumar/Native-Victory-macOS/commit/ae11992b9c25944940ce0b2987dfb7330839226d). This builds on [#171's RTV mip and slice selection](https://git.gtahub.st/github/LakshanSivakumar--Native-Victory-macOS/pulls/171). Prepared and tested with Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:54:59 +00:00
github manually merged commit ba8e44941d into main 2026-11-27 01:32:03 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 00:58 UTC · original · approved these changes

Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). I merged main into this branch (the texture_tests.rs conflict kept both sides) and pushed one small fix: since #198, encode_render takes the command buffer's attached-heaps list, so encode_color_clear_rects now takes it too and passes it on. Thanks!

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 00:58 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/206#pullrequestreview-6082116922) · **approved these changes** Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). I merged main into this branch (the texture_tests.rs conflict kept both sides) and pushed one small fix: since #198, `encode_render` takes the command buffer's attached-heaps list, so `encode_color_clear_rects` now takes it too and passes it on. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.