Preserve sRGB midtones on the SDR UNORM swapchain fallback #2001

Closed
lgr123 wants to merge 1 commit from upstream-pr/2001 into main
lgr123 commented 2026-11-25 17:55:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lgr123 on 2026-11-25T17:55:04Z.


Claimed as RT-PRESENT-SRGB-UNORM-FALLBACK.

On the RTX 5070, restricting surface formats to the driver's advertised SDR UNORM formats made the native presenter turn synthetic grey bytes 128/188 into 55/128. The swapchain still used nonlinear sRGB, so these linearized bytes darkened midtones. The default sRGB swapchain and composed controls preserved 128/188.

Copy encoded bytes for matching format layouts at 1:1. For scaling or channel reordering, keep the existing filtered blit through a reusable matching sRGB image before copying the encoded bytes to the UNORM swapchain. This also works for transfer-only source images. If the intermediate cannot be created, keep presenting through the previous blit and emit a warning.

Reviewer check

Run ctest -R ^xbox_present$ --output-on-failure from the configured Windows runtime build. The synthetic surface-format test forces SDR UNORM and checks RGBA/BGRA at 1:1 and with crop/scale. No game files required.

Tested

  • Windows, NVIDIA RTX 5070, driver 621.24. The aligned public main build at b9320a1 passed xbox_present (1 of 1).
  • A separate production-presenter matrix confirmed the default native sRGB path, forced UNORM, direct and intermediary transfer-only paths, filtered midpoints, compositor, repeated scaled frames and the injected allocation-failure warning.
  • The display did not offer ST.2084. The routine HDR10 swapchain case skipped, and SDR tone-map and PQ encoder tests ran.
  • Source-only check and git diff --check passed.

GPUs tested: NVIDIA RTX 5070, driver 621.24, Windows.

AI-assisted: yes.

Checklist

  • Based on public main.
  • One topic.
  • No game data, keys or protection workarounds.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5496416764 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2001). Originally posted by [lgr123](https://github.com/lgr123) on 2026-11-25T17:55:04Z. --- Claimed as [RT-PRESENT-SRGB-UNORM-FALLBACK](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7169658698). On the RTX 5070, restricting surface formats to the driver's advertised SDR UNORM formats made the native presenter turn synthetic grey bytes **128/188 into 55/128**. The swapchain still used nonlinear sRGB, so these linearized bytes darkened midtones. The default sRGB swapchain and composed controls preserved **128/188**. Copy encoded bytes for matching format layouts at 1:1. For scaling or channel reordering, keep the existing filtered blit through a reusable matching sRGB image before copying the encoded bytes to the UNORM swapchain. This also works for transfer-only source images. If the intermediate cannot be created, keep presenting through the previous blit and emit a warning. ### Reviewer check Run `ctest -R ^xbox_present$ --output-on-failure` from the configured Windows runtime build. The synthetic surface-format test forces SDR UNORM and checks RGBA/BGRA at 1:1 and with crop/scale. No game files required. ### Tested - Windows, NVIDIA RTX 5070, driver 621.24. The aligned public main build at `b9320a1` passed `xbox_present` (1 of 1). - A separate production-presenter matrix confirmed the default native sRGB path, forced UNORM, direct and intermediary transfer-only paths, filtered midpoints, compositor, repeated scaled frames and the injected allocation-failure warning. - The display did not offer ST.2084. The routine HDR10 swapchain case skipped, and SDR tone-map and PQ encoder tests ran. - Source-only check and `git diff --check` passed. GPUs tested: NVIDIA RTX 5070, driver 621.24, Windows. AI-assisted: yes. ### Checklist - [x] Based on public main. - [x] One topic. - [x] No game data, keys or protection workarounds.
djrolfes commented 2026-11-27 19:37:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-11-27T19:37:59Z.


Independent Linux/Wine + NVIDIA GPU verification at head cec9d96dc (applied cleanly onto main 43a9d562d, Profile M, no game files).

  • Environment: NVIDIA GeForce RTX 3070 Ti 8 GB (desktop), driver 620.73.04, Arch Linux 7.2.15, wine-11.22 (XWayland), clang-cl 23.1.5 + xwin SDK 10.0.26100 cross-build, Ryzen 7 5800X, 31 GiB RAM.
  • Build & test: xbox_present_test.exe cross-compiled cleanly and ran under Wine with LEONIDA_PRESENT_PLANE1=0 alongside a clean main (43a9d562d) control build.
  • Measured result:
    • The new SDR UNORM fallback check passed: 1 plane, sRGB source on an SDR UNORM swapchain: 1:1, crop/scale, RGBA and BGRA ok.
    • All other single-plane, 2-plane compose, alpha, SDR EOTF, and HDR10 tone-map checks passed identically to main.
    • One unrelated pre-existing resize check (line 1300: present_planes(&one, 1), matching main line 1226) failed under our unfocused Hyprland workspace environment; HDR10 swapchain skipped (no ST.2084 surface format).
  • Not tested: native Windows or an HDR10-capable ST.2084 output.

AI-assisted: Antigravity (Gemini 4 Neon); no game data.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7226718698 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2001#issuecomment-7226718698). Originally posted by [djrolfes](https://github.com/djrolfes) on 2026-11-27T19:37:59Z. --- Independent Linux/Wine + NVIDIA GPU verification at head `cec9d96dc` (applied cleanly onto `main` `43a9d562d`, Profile M, no game files). - **Environment:** NVIDIA GeForce RTX 3070 Ti 8 GB (desktop), driver `620.73.04`, Arch Linux `7.2.15`, `wine-11.22` (XWayland), `clang-cl 23.1.5` + `xwin` SDK `10.0.26100` cross-build, Ryzen 7 5800X, 31 GiB RAM. - **Build & test:** `xbox_present_test.exe` cross-compiled cleanly and ran under Wine with `LEONIDA_PRESENT_PLANE1=0` alongside a clean `main` (`43a9d562d`) control build. - **Measured result:** - The new SDR UNORM fallback check **passed**: `1 plane, sRGB source on an SDR UNORM swapchain: 1:1, crop/scale, RGBA and BGRA ok`. - All other single-plane, 2-plane compose, alpha, SDR EOTF, and HDR10 tone-map checks passed identically to `main`. - One unrelated pre-existing resize check (`line 1300: present_planes(&one, 1)`, matching `main` `line 1226`) failed under our unfocused Hyprland workspace environment; `HDR10 swapchain` skipped (no ST.2084 surface format). - **Not tested:** native Windows or an HDR10-capable ST.2084 output. AI-assisted: Antigravity (Gemini 4 Neon); no game data.
lixonik commented 2026-11-28 08:47:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T08:47:37Z.

Review: APPROVED


Reviewed the diff and tested merged onto main (493867366) with Ninja Release (MSVC).

The SDR UNORM swapchain fallback path cleanly preserves sRGB midtones without altering existing presentation paths.

Tests run

  • xbox_present_test.exe (with LEONIDA_PRESENT_PLANE1=0): the new sRGB-on-SDR-UNORM fallback case passed on real Vulkan hardware (1 plane, sRGB source on an SDR UNORM swapchain: 1:1, crop/scale, RGBA and BGRA ok).
  • Note: later in the same binary, case F hits the pre-existing main resize readback failure (present_planes(&one, 1)), unrelated to this PR (tracked in #2507).

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally).

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6096822884 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2001#pullrequestreview-6096822884). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T08:47:37Z. **Review:** APPROVED --- Reviewed the diff and tested merged onto `main` (`493867366`) with Ninja Release (MSVC). The SDR UNORM swapchain fallback path cleanly preserves sRGB midtones without altering existing presentation paths. ### Tests run - `xbox_present_test.exe` (with `LEONIDA_PRESENT_PLANE1=0`): the new sRGB-on-SDR-UNORM fallback case passed on real Vulkan hardware (`1 plane, sRGB source on an SDR UNORM swapchain: 1:1, crop/scale, RGBA and BGRA ok`). - Note: later in the same binary, case F hits the pre-existing `main` resize readback failure (`present_planes(&one, 1)`), unrelated to this PR (tracked in #2507). GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally). AI-assisted (Antigravity, Gemini).
zmasi commented 2026-11-28 23:57:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T23:57:18Z.


#2001 | head cec9d96dcc (merged cleanly with main ba8b77b390 — no conflicts on current main, and merges cleanly with #2014) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(xbox_present|d3d12_present|vk_presenter_sync)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: building xbox_present_test against main's runtime/src/vulkan_present.h fails xbox_present at line 677: check_srgb_fallback(srgb) (pixel 0,0 is 64,128,192, expected 137,188,225) | green on PR+main: d3d12_present and vk_presenter_sync pass (rc=0), and xbox_present passes 1 plane, sRGB source on an SDR UNORM swapchain: 1:1, crop/scale, RGBA and BGRA ok as well as compose: HDR10 plane to an HDR10 (ST.2084) swapchain: R, G and B codes within 1 of the source: ok on an HDR10 ST.2084 RTX 3090 output with 0 Khronos validation errors (the trailing present_planes(&one, 1) window-resize VkResult -11 at line 1300 matches plain main line 1226 identically); check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247773169 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2001#issuecomment-7247773169). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T23:57:18Z. --- #2001 | head cec9d96dcc38cd0318aca0a0054fcdf4243b3c69 (merged cleanly with main ba8b77b390b278cfb05510a4fc2922fb0fb9a11c — no conflicts on current `main`, and merges cleanly with `#2014`) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(xbox_present|d3d12_present|vk_presenter_sync)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red on main: building `xbox_present_test` against `main`'s `runtime/src/vulkan_present.h` fails `xbox_present` at `line 677: check_srgb_fallback(srgb)` (`pixel 0,0 is 64,128,192, expected 137,188,225`) | green on PR+main: `d3d12_present` and `vk_presenter_sync` pass (`rc=0`), and `xbox_present` passes `1 plane, sRGB source on an SDR UNORM swapchain: 1:1, crop/scale, RGBA and BGRA ok` as well as `compose: HDR10 plane to an HDR10 (ST.2084) swapchain: R, G and B codes within 1 of the source: ok` on an HDR10 ST.2084 RTX 3090 output with `0` Khronos validation errors (the trailing `present_planes(&one, 1)` window-resize `VkResult -11` at `line 1300` matches plain `main` `line 1226` identically); `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
OreoFR commented 2026-11-29 14:59:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T14:59:57Z.


TAKEN by OreoFR (Windows, RTX 4070 8 GB)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7257738937 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2001#issuecomment-7257738937). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T14:59:57Z. --- TAKEN by OreoFR (Windows, RTX 4070 8 GB)
OreoFR commented 2026-11-29 21:33:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T21:33:08Z.


Verified by OreoFR — READY

  • Base: main c22a0a732 + this PR (head cec9d96dc) merged with --no-ff
  • Red (main + only this PR's test): xbox_present fails on main at line 678 (check_srgb_fallback(srgb)): the sRGB source on the SDR UNORM swapchain comes out darker. (xbox_present also fails on main later, at present_planes(&one, 1) with VkResult -11; that check is the same with or without this PR.)
  • Green (merge): 1 plane, sRGB source on an SDR UNORM swapchain: 1:1, crop/scale, RGBA and BGRA ok, and every check before main's failure passes; the run stops at the same present_planes(&one, 1) failure as main (now line 1394). ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p2 = main + #2184 + #2001 (no shared files): 507 tests, new failures vs main: none. dxgi_waitable_latency failed in the parallel run and passes when re-run alone (main alone: 505 tests, 6 failures: big_compile_gate and api_ref_state and d3d12_queue_wait_timeout timeouts, xs_proxy_mock, vk_compile_gate_calibration, xbox_present)
  • gta6rt.exe links without the XMA decoder (LEONIDA_CARGO=OFF, LEONIDA_XMA2_DECODER_LIB empty) in package p2; imports unchanged vs main (25 DLLs, 755 functions, no WS2_32)
  • Diff read: no issue. release() frees the old scratch image before srgb_transfer_format_ is set for the new swapchain, and the scratch is waited on with a transfer barrier before each reuse.
  • Other runs: Consistent with djrolfes's and zmasi's runs and lixonik's approval.
  • Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44

Ready to merge per the maintainers' plan.

AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7262965299 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2001#issuecomment-7262965299). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T21:33:08Z. --- **Verified by OreoFR** — READY - Base: main c22a0a732 + this PR (head cec9d96dc) merged with --no-ff - Red (main + only this PR's test): `xbox_present` fails on main at line 678 (`check_srgb_fallback(srgb)`): the sRGB source on the SDR UNORM swapchain comes out darker. (`xbox_present` also fails on main later, at `present_planes(&one, 1)` with VkResult -11; that check is the same with or without this PR.) - Green (merge): `1 plane, sRGB source on an SDR UNORM swapchain: 1:1, crop/scale, RGBA and BGRA ok`, and every check before main's failure passes; the run stops at the same `present_planes(&one, 1)` failure as main (now line 1394). ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p2 = main + #2184 + #2001 (no shared files): 507 tests, new failures vs main: none. `dxgi_waitable_latency` failed in the parallel run and passes when re-run alone (main alone: 505 tests, 6 failures: big_compile_gate and api_ref_state and d3d12_queue_wait_timeout timeouts, xs_proxy_mock, vk_compile_gate_calibration, xbox_present) - gta6rt.exe links without the XMA decoder (`LEONIDA_CARGO=OFF`, `LEONIDA_XMA2_DECODER_LIB` empty) in package p2; imports unchanged vs main (25 DLLs, 755 functions, no WS2_32) - Diff read: no issue. `release()` frees the old scratch image before `srgb_transfer_format_` is set for the new swapchain, and the scratch is waited on with a transfer barrier before each reuse. - Other runs: Consistent with djrolfes's and zmasi's runs and lixonik's approval. - Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44 Ready to merge per the maintainers' plan. AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
aslan2142 commented 2026-12-01 16:41:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:41:01Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318028011 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2001#issuecomment-7318028011). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:41:01Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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
ProjectLeonida/mandy!2001
No description provided.