Quantize RGB565 render-target clears at each channel width #2268

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

@⁠Bonchaloo on GitHub · 2026-11-26 11:52 UTC · original
Bonchaloo:fix/rgb565-rtv-clear → main · +3 −0 · 2 files · 1 commits · open

Claimed in the coordination issue as RT-CLEAR-RGB565-UNORM.

What and why

The RTV replay path already pre-rounds normalized clear values so the conversion is independent of the driver’s tie handling. RGB565 fell through to the raw float path. Apply the existing converter with channel maxima of 31, 63 and 31. Cover full and rectangle clears, midpoint rounding, NaN and clamping.

Tested

On the parent revision the new midpoint case failed (red 0.5, expected 16/31). With the change all 519 clear replay checks passed. The no-game-data check passed for both changed files.

GPUs tested: Apple M5 Max, Apple Metal driver on macOS 27.3. A separate native Metal RGB565 clear and readback produced 0x8410 for both the raw and pre-rounded midpoint. That device already rounds this case the same way. The failing regression was at the renderer’s Vulkan command boundary; the replay test uses synthetic inputs and captures the clear without a GPU.

Full native runtime CTest suite on Apple M5 Max with MoltenVK 1.4.2: 105 passed, 0 failed, 3 skipped (shader_library_corpus, vk_device_markers, vk_sync_validation).

AI-assisted: yes.

**@⁠Bonchaloo** on GitHub · 2026-11-26 11:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2268) `Bonchaloo:fix/rgb565-rtv-clear` → `main` · +3 −0 · 2 files · 1 commits · open Claimed in the coordination issue as [RT-CLEAR-RGB565-UNORM](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608). ### What and why The RTV replay path already pre-rounds normalized clear values so the conversion is independent of the driver’s tie handling. RGB565 fell through to the raw float path. Apply the existing converter with channel maxima of 31, 63 and 31. Cover full and rectangle clears, midpoint rounding, NaN and clamping. ### Tested On the parent revision the new midpoint case failed (red 0.5, expected 16/31). With the change all 519 clear replay checks passed. The no-game-data check passed for both changed files. GPUs tested: Apple M5 Max, Apple Metal driver on macOS 27.3. A separate native Metal RGB565 clear and readback produced 0x8410 for both the raw and pre-rounded midpoint. That device already rounds this case the same way. The failing regression was at the renderer’s Vulkan command boundary; the replay test uses synthetic inputs and captures the clear without a GPU. Full native runtime CTest suite on Apple M5 Max with MoltenVK 1.4.2: 105 passed, 0 failed, 3 skipped (shader_library_corpus, vk_device_markers, vk_sync_validation). AI-assisted: yes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:53:07 +00:00
Author
Owner

@⁠Bonchaloo on GitHub · 2026-11-26 12:21 UTC · original

My Discord username is bonchalo.

**@⁠Bonchaloo** on GitHub · 2026-11-26 12:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2268#issuecomment-7191891558) My Discord username is `bonchalo`.
Author
Owner

@⁠real-rusher on GitHub · 2026-11-26 12:23 UTC · original

Verified on main a73a57e1 (Ubuntu 24.04 x86-64, GCC 13.3, CMake 3.28, Ninja, no GPU). Merges cleanly. ctest -R '^clear_color$' passes with this PR; the PR's runtime/test/clear_color_test.cpp built against main's vulkan_replay.h fails, so the new case fails on main and passes with the change.

AI-assisted: yes (Claude Code)

**@⁠real-rusher** on GitHub · 2026-11-26 12:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2268#issuecomment-7191950807) Verified on main a73a57e1 (Ubuntu 24.04 x86-64, GCC 13.3, CMake 3.28, Ninja, no GPU). Merges cleanly. ctest -R '^clear_color$' passes with this PR; the PR's runtime/test/clear_color_test.cpp built against main's vulkan_replay.h fails, so the new case fails on main and passes with the change. AI-assisted: yes (Claude Code)
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 12:49 UTC · original

Confirmed that the patch changes the stored RGB565 bits on an RTX 4090. For an RGB clear of (0.5, 0.5, 0.5), the Vulkan layer wrote 0x7bef on parent a73a57e13 and 0x8410 on head 1e0de21b0. The head matches the proposed nearest-even conversion, (16, 32, 16). Native D3D12 on the same card wrote 0x7bef, and Microsoft WARP wrote 0x8410.

I exercised ClearRenderTargetView through the D3D12 layer on Windows 11, NVIDIA 616.64, with Khronos validation. The same test-only probe ran on both revisions. It covered 199 input vectors, including primaries, clamping, NaN, and the float32 values at and immediately around the 5- and 6-bit rounding thresholds. Each input was used once as a whole-target clear and once as a rectangular clear on a 5×3 image. Every texel inside and outside the rectangle was checked.

Readback path Packed words matching nearest-even after exact scaling Packed words matching nearest-even after float32 scaling
Leonida Vulkan, parent 8/199 8/199
Leonida Vulkan, PR head 199/199 137/199
Native D3D12, RTX 4090 8/199 8/199
Native D3D12, WARP 137/199 199/199

Here “exact scaling” means multiplying each supplied float32 by 31, 63 or 31 in double precision before rounding. “Float32 scaling” rounds that product to float32 first. The WARP result is an observation on this build. The two calculations can pick neighboring codes near a half-step. The 62 head/WARP disagreements were at most one code per channel. These inputs deliberately concentrate on thresholds, so the counts describe this test set.

The full and rectangular readbacks agreed across all paths. Repeating the matrix gave identical results and no Vulkan validation errors. The PR's 519 CPU replay checks also passed. This verifies the layer's stated rounding rule on a Vulkan device where the midpoint changes.

**@⁠ecox982745** on GitHub · 2026-11-26 12:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2268#issuecomment-7192510670) Confirmed that the patch changes the stored RGB565 bits on an RTX 4090. For an RGB clear of (0.5, 0.5, 0.5), the Vulkan layer wrote `0x7bef` on parent `a73a57e13` and `0x8410` on head `1e0de21b0`. The head matches the proposed nearest-even conversion, (16, 32, 16). Native D3D12 on the same card wrote `0x7bef`, and Microsoft WARP wrote `0x8410`. I exercised `ClearRenderTargetView` through the D3D12 layer on Windows 11, NVIDIA 616.64, with Khronos validation. The same test-only probe ran on both revisions. It covered 199 input vectors, including primaries, clamping, NaN, and the float32 values at and immediately around the 5- and 6-bit rounding thresholds. Each input was used once as a whole-target clear and once as a rectangular clear on a 5×3 image. Every texel inside and outside the rectangle was checked. | Readback path | Packed words matching nearest-even after exact scaling | Packed words matching nearest-even after float32 scaling | | --- | ---: | ---: | | Leonida Vulkan, parent | 8/199 | 8/199 | | Leonida Vulkan, PR head | **199/199** | 137/199 | | Native D3D12, RTX 4090 | 8/199 | 8/199 | | Native D3D12, WARP | 137/199 | **199/199** | Here “exact scaling” means multiplying each supplied float32 by 31, 63 or 31 in double precision before rounding. “Float32 scaling” rounds that product to float32 first. The WARP result is an observation on this build. The two calculations can pick neighboring codes near a half-step. The 62 head/WARP disagreements were at most one code per channel. These inputs deliberately concentrate on thresholds, so the counts describe this test set. The full and rectangular readbacks agreed across all paths. Repeating the matrix gave identical results and no Vulkan validation errors. The PR's 519 CPU replay checks also passed. This verifies the layer's stated rounding rule on a Vulkan device where the midpoint changes.
Author
Owner

@⁠Bonchaloo on GitHub · 2026-11-26 13:55 UTC · original

Ready for maintainer review. The RTX 4090 readback confirms the patch applies Leonida’s existing normalized-clear rounding rule. Native D3D12 on that GPU and WARP differed near rounding thresholds, as documented above. Is the existing Leonida rule the intended behavior for RGB565?

The fork CI run reports action_required with zero jobs. Could a maintainer approve it if CI is wanted for review? The M5 Max suite completed with 105 passed and 3 skipped.

I’ve kept the independent viewport fix (#2271) in draft. Should it enter review now or after this one lands?

AI-assisted: yes.

**@⁠Bonchaloo** on GitHub · 2026-11-26 13:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2268#issuecomment-7194036773) Ready for maintainer review. The RTX 4090 readback confirms the patch applies Leonida’s existing normalized-clear rounding rule. Native D3D12 on that GPU and WARP differed near rounding thresholds, as documented above. Is the existing Leonida rule the intended behavior for RGB565? The fork CI run reports action_required with zero jobs. Could a maintainer approve it if CI is wanted for review? The M5 Max suite completed with 105 passed and 3 skipped. I’ve kept the independent viewport fix (#2271) in draft. Should it enter review now or after this one lands? AI-assisted: yes.
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/2268/head:github-bot/gh-2268'
git switch 'github-bot/gh-2268'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2268'
git switch 'github-bot/gh-2268'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2268'
git switch 'github-bot/gh-2268'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2268'
git switch 'main'
git merge --squash 'github-bot/gh-2268'
git switch 'main'
git merge --ff-only 'github-bot/gh-2268'
git switch 'main'
git merge 'github-bot/gh-2268'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.