Skip to content

BUILD-1151: sample explicit sRGB DDS textures correctly in First Light - #4055

Open
jeremygold02 wants to merge 2 commits into
ItsNotRexed:mainfrom
jeremygold02:fix/first-light-dds-srgb
Open

jeremygold02 wants to merge 2 commits into
ItsNotRexed:mainfrom
jeremygold02:fix/first-light-dds-srgb

Conversation

@jeremygold02

@jeremygold02 jeremygold02 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

BUILD-1151. First Light decoded explicitly sRGB and linear DDS inputs into the same RGBA8 upload layout and always sampled that upload as UNORM. In the independent BC1 control, changing only the DDS declaration between DXGI 71 and 72 produced identical frames on the original implementation. Coordination claim

The manifest now records texture.srgb from the DDS DXGI format. First Light passes the sampling mode to the Vulkan harness, which uses the corresponding format for the sampled image, view and T# descriptor. The CPU reference converts each RGB texel to linear light before bilinear interpolation. Alpha stays linear. Explicit linear formats, legacy DDS headers and old manifests use UNORM, including when the parent process has an sRGB override. The texture.rgba byte layout is unchanged.

Based directly on main aa2988cc. #2806 and #2906 cover earlier textured draw paths. #3863 concerns filtering PNG previews. This PR has no open PR dependency.

Verification at 6d39884183c39926f6a19189c5870bce8e6b3f8e

  • CPU, synthetic DDS. All seven supported explicit sRGB DXGI formats and their seven linear counterparts selected the expected sampling mode. Running CLI preparation on RGBA8 (28/29) and BC1 (71/72) produced byte-identical uploads within each pair and matched 20/20 centre and additional probe values. The two-color regression covers a black/white midpoint, the nonlinear and low-intensity branches of the transfer curve, and changing alpha. The two new tests reject the parent implementation.
  • GPU, entirely synthetic draw. A hand-written shader pair sampled a two-texel RGBA8 texture on a quad with varying UVs. Across all 2,304 geometrically covered pixels in each 64 × 64 draw, maximum absolute RGBA error against the CPU reference was 0.001140 (linear) and 0.001926 (sRGB), below the existing 0.02 tolerance. Replaying a manifest without the transfer field reproduced the explicit-linear frame byte-for-byte even with VKH_TEX_SRGB=1 inherited.
  • Independent GPU replay. The coordinating chat built the unmodified harness from this head and used the documented private reference mesh and translated programs with three synthetic DDS inputs: BC1 UNORM, the same BC1 payload marked sRGB, and two-color sRGB RGBA8 with varying alpha. Each 128 × 128 draw matched its independent reference frame byte-for-byte, including all 12,804 covered pixels. A fourth check replayed a legacy BC1 manifest and reproduced the original UNORM frame. In total, 1,048,576 readback bytes matched across four draws. Only aggregate results are reported.
  • Suites. First Light discovery with the rebuilt harness passed 31 tests with 3 package-gated skips. The two DDS PNG suites passed 81 tests and 124 subtests. All 20 documentation tests and git diff --check passed.

Windows 11 Home 25H2 (26200.9974), Python 3.12.10, Intel Core Ultra 7 265K. GPU draws ran on NVIDIA GeForce RTX 5070, driver 621.01, subgroup 32. Integrated Intel Graphics (32.0.101.9150) was present and unused. GPT-6 Luna implemented the native harness format selection. A separate GPT-6.2 Astra chat performed the independent reference-scene replay.

AI-assisted by GPT-6.2 Astra.

Carry the DDS transfer function to the sampled Vulkan image, view and texture descriptor. Decode RGB before bilinear interpolation in the CPU reference and preserve linear alpha and legacy manifest behavior.

Refs: ItsNotRexed#3918

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 6d398841 on Windows 11: python -I tests/test_first_light.py -> 21 tests, OK (4 skipped); compileall and git diff --check clean.

The new unit case distinguishes the two orders exactly: encoded-byte filtering gives ~0.214 for the green midpoint, while decoding the sRGB endpoints first gives 0.5; the test pins 0.5 (red), the sRGB transfer for green/blue, and alpha staying linear. The manifest override case covers inherited VKH_TEX_SRGB for None/False/True, and the legacy DDS path asserts srgb false. The 4 skips are the host/GPU-only cases.

The only coupling worth knowing is dds_png._SRGB_TO_LINEAR (private but in the same tools tree); no blocking issue.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 6d39884. I independently ran python -I tests/test_first_light.py: 21 tests passed with 4 expected host/GPU skips; git diff --check is clean. The change consistently carries the explicit DDS sRGB declaration through the Vulkan format, descriptor, manifest, and linear-light CPU reference, while preserving the legacy UNORM default.

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 6d39884 on NVIDIA RTX 4080, driver 610.88, Windows 11: pass

This covers the four GPU/package-gated tests the two earlier checks skipped. Ran (MSVC 19.44 / VS 2022 BuildTools, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0):

  • Built vk_harness at this head (LEONIDA_VK_HARNESS set to it).
  • tools/first_light.py --obj <exported model> --dds <exported texture> --run, with the default VS/PS pair from my own 1.0.2.1 carve, twice:
    • BC1 texture declared sRGB (DXGI 72): manifest texture.srgb = true; --run exit 0, --check exit 0.
    • BC1 texture declared linear (DXGI 71): manifest texture.srgb = false; --run exit 0, --check exit 0.
    • The model I picked covers 0.44 of the 128×128 frame, so both runs used --min-coverage 0.3; that gate is unrelated to this change.
  • LEONIDA_FIRST_LIGHT_DIR=<that out> python -I tests/test_first_light.py, for each output: 21 tests, OK, 0 skipped.
  • Negative control: the sRGB output with only texture.srgb flipped to false (so the harness samples UNORM while the stored probes are linear-light): --check exits 1 at the centre probe, outside the 0.02 tolerance. So the oracle tells the two modes apart on a real texture.

Review: no findings. Explicit linear formats, legacy headers and manifests without the field all map to VKH_TEX_SRGB=0 (tools/first_light.py harness_env), and vk_harness refuses any value other than 0 or 1.

Game data stayed local; counts and exit codes only. AI-assisted.

@lunarminus

Copy link
Copy Markdown

Tested 6d398841 (based on main aa2988cc) on an AMD Radeon 760M (RDNA3 iGPU, gfx1103), RADV Mesa 26.3.1, CachyOS Linux: pass.

  • Built runtime/ (Linux Vulkan programs) from the head. python -I tests/test_first_light.py: 21 tests OK, 3 package-gated skips; both new tests run.
  • scripts/run_gpu_tests.py: 196/210 passed, 14 skipped, 0 failed. The result is identical per test to aa2988cc on the same machine.
  • GPU draw with real translated game shaders. I used my own 1.0.2.1 copy, with VS_main_170e32e6_Wrapped and PS_Copy_3ea4b38a_Wrapped translated by make_game.py --stages shaders (wave64 emulation off, subgroup 64). The mesh is a synthetic 48-triangle disc OBJ. The textures are two synthetic 4×4 RGBA8 DX10 DDS files, identical except for DXGI 28 vs 29, with dark/bright neighbours and alpha from 64 to 208. I ran first_light.py --dds ... --check at 128×128 and compared all 10,388 covered pixels with sample_rgba_bilinear at each pixel's UV:
build DDS max error vs UNORM reference max error vs sRGB reference
PR 28 (UNORM) 0.0027 (10,388/10,388 within 0.02) 0.2640 (0 within)
PR 29 (sRGB) 0.2637 (0 within) 0.0032 (10,388/10,388 within 0.02)
main 28 0.0027 0.2640
main 29 0.0027 0.2640

On main the DXGI 28 and 29 frames are byte-identical, which is the bug. The PR's DXGI 28 frame is byte-identical to main's. The manifest records srgb: false/true accordingly.

One thing I noticed, which is not this PR's doing and is already on main: check_image counts coverage as alpha > 0.5. With --dds, PS_Copy writes the texture's alpha, so a texture with low alpha under-reports coverage. My disc covers 10,388 pixels (clear is -1), but --check reported 5,768 (0.352). It took --min-coverage 0.3 to pass. Comparing against the clear value would avoid this. I see you've already claimed this in the coordination issue, so this is one more data point for it.

AI-assisted (Claude Code).

@jeremygold02

Copy link
Copy Markdown
Contributor Author

Merged upstream 98fa503f into this PR at ff53bd38 to resolve the overlap with #3577. First Light now applies the DDS transfer mode to the off-centre RGBA probes introduced there. The added regression uses a triangle with default UVs, an uncovered centre pixel and a low-alpha texture.

I rebuilt the Vulkan harness with MSVC and ran the stock First Light CLI on a synthetic off-centre triangle with two otherwise identical RGBA8 DDS files. Each 64×64 draw covered 253 pixels and passed all four probes. Across every covered pixel, RGB was 0.215820 with the sRGB header and 0.501953 with the linear header. Alpha was 0.250977 in both. Flipping only the prepared sRGB manifest’s transfer flag made the first RGBA probe fail, as expected.

GPU execution used the NVIDIA GeForce RTX 5070 (621.01, subgroup 32) on Windows 11 Home 25H2 build 26200.9974 with an Intel Core Ultra 7 265K. With the harness and prepared output configured, the focused Windows suite ran 30 tests with four symlink cases skipped for local privileges.

AI-assisted by GPT-6.2 Astra.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested ff53bd380cfc6efafed69e1ad41e3b321819e0d8 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

I checked the sampling path with a synthetic 2×2 RGBA8 texture whose four texels differ in every channel. I rendered it twice at 64×64 with the harness built from this head, changing only VKH_TEX_SRGB. The reference for sRGB decoded each RGB texel before bilinear interpolation and interpolated alpha directly.

All 4,096 pixels in each draw were within 2/255 per channel of the reference. Maximum absolute channel error was 0.00173 or less for linear sampling and 0.00406 or less for sRGB. Alpha was identical between draws at every pixel. Both shaders passed spirv-val. The separate First Light Python suite had 26 passes and 4 skips. The GPU comparison supplied raw synthetic texels directly to the harness.

AI-assisted verification.

@Kev-Ball

Copy link
Copy Markdown

Tested ff53bd38 on RTX 3080 Ti, NVIDIA 620.73.04, CachyOS Linux. Pass. With the harness built from this head and a prepared textured draw, python -I tests/test_first_light.py ran 30/30 with no skips, including the Linux symlink cases.

I also combined the two-texel filtering control with the off-centre probe path through the stock First Light CLI. I used the translated shader pair from my 1.0.2.1 copy, a synthetic triangle with UV (0.5, 0.5) at all three vertices, and identical two-texel DDS payloads. Each 64×64 draw left the centre clear and passed four off-centre probes. Every one of the 253 covered pixels returned the same raw RGBA within each draw:

DXGI format R G B A
28 (linear) 0.5 0.501953 0.039215 0.501953
29 (sRGB) 0.5 0.215820 0.003052 0.501953

The black/white red channel retained its 0.5 midpoint, the mid-grey and low-intensity channels followed their respective transfer branches, and alpha retained its midpoint. Flipping only the prepared sRGB manifest’s transfer flag made --check exit 1 at probe (6, 6) on the first draw. This exercises the probe and sampling changes together after the merge with #3577.

AI-assisted.

@KkelebekK

Copy link
Copy Markdown

Tested ff53bd3 (merge base 98fa503) on AMD Radeon 780M (RADV PHOENIX, Mesa 26.2.6) and NVIDIA GeForce RTX 4070 Laptop (620.70.06), CachyOS Linux 7.3.4: pass.

Harness built from the PR tree; it merges cleanly with current main 3faac55.

  • run_gpu_tests.py: 780M 202/217 passed, 15 skipped; 4070 170/217, 47 skipped; 4070 with LEONIDA_W64_EMULATE=1 201/217, 16 skipped. No FAIL, same as main at 98fa503 (the PR adds no run_gpu_tests fixture).
  • tests/test_first_light.py: 30 OK, 3 skips that need the game package. pytest of test_first_light*, test_dds_png*, test_docs_{design_rows,links,env_vars,cli_flags}: 149 passed, 3 skipped. The new tests fail against main's tools/ (2 failures, 4 errors).
  • Synthetic GPU draw: a ps of my own that samples attr0.xy, the vs_ids full-screen triangle, a 2x2 RGBA8 texture with differing texels and alpha, drawn at 64x64. All 4096 pixels were compared with first_light.sample_rgba_bilinear:
    • 780M, PR harness: with VKH_TEX_SRGB=0, max abs error 0.000001 against the linear reference (0.286 against sRGB); with VKH_TEX_SRGB=1, 0.000545 against the sRGB reference (0.286 against linear).
    • 4070, PR harness: 0.002508 (=0, linear) and 0.006340 (=1, sRGB); the crossed pairings are 0.286.
    • Harness built from 98fa503: the VKH_TEX_SRGB=0 and =1 frames are bit-identical on both GPUs (the bug); with the PR they differ.
  • Not run: tools/first_light.py --run end to end (needs the game package).

Synthetic inputs only, no game data. AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants