[PR #35] TEST-924: every texture format the game uses, from a real game texture, through the D3D12 layer (all 20 formats) #88

Open
opened 2026-11-26 20:16:45 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/35
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/4251


📝 Commits (10+)

  • c838d60 First light with a texture: the real model through a game PS that samples a T# (TEST-524)
  • 996591f first_light: UV-seam pixels are reported, not guessed, in the textured reference
  • 178d4c8 first_light: a seam is judged from the latest hit back to the first interior one
  • 44db1ed first_light: the shared-edge shortcut needs a real shared edge
  • 16003a6 d3d12_first_light_textured_test: read LEONIDA_FIRST_LIGHT_TEX_DIR with _dupenv_s
  • 7a08f9f d3d12_first_light_textured_test: the comment on d3d12_textured.raw names no option that doesn't exist
  • 5cb119c first_light: the ramp's manifest keys no longer collide with the --dds harness path
  • 9410b62 first_light textured: the PS's pointer SGPR and T# slot come from the PS (13 game copy shaders pass)
  • cbe4c99 first light: every texture format the game uses, from a real texture, through the D3D12 layer
  • a52ce94 docs/first_light.md §8: all 20 game texture formats run through the layer

📊 Changes

5 files changed (+1168 additions, -1 deletions)

View changed files

📝 docs/first_light.md (+124 -1)
📝 runtime/CMakeLists.txt (+6 -0)
➕ runtime/test/d3d12_first_light_textured_test.cpp (+453 -0)
📝 tests/test_first_light.py (+229 -0)
📝 tools/first_light.py (+356 -0)

📄 Description

Carried over from old PR 4251 by rafaelpssz in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/4251, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
rafaelpssz: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claim (new TEST item).

Depends on: #2906 (and through it on #2887). Its commits are the base here; only the top commit, b90d802b, is new.

What

This checks every texture format the game actually uses by sampling a real game texture through the D3D12 layer, each in its own format, BC blocks included.

The package's 357,115 TTPF descriptors use 20 DXGI formats, counted on my 1.0.2.1 copy:

  • BC1: 174,674, plus 82,177 sRGB.
  • BC7: 52,612, plus 25,226 sRGB.
  • BC5: 6,904. BC4: 4,656. BC3: 3,045, plus 3,880 sRGB.
  • BC6H: 1,000 UF16 and 25 SF16.
  • RGBA8: 1,774. R16F: 947. A8: 121. BGRA8: 50, plus 4 sRGB. R8: 8.
  • RGBA16 UNORM: 5. RGBA16F: 3. BC2: 2. RGBA8 sRGB: 2.

The changes:

  • first_light.py --texture-dds <file> reads a DX10 DDS's mip 0 (as ttpf_mips.py export writes it) into texture.bin in its own format. It writes the CPU reference to expected.raw, decoded with ttpf_mips.decode_pixels and these per-format rules:
    • sRGB is linearised before filtering, as the hardware does.
    • A8 samples as (0, 0, 0, a). R8, BC4 and R16F sample as (r, 0, 0, 1). BC5 samples as (r, g, 0, 1).
    • An alpha the decoder doesn't give is left out of the comparison (NaN).
  • d3d12_first_light_textured uploads block-compressed formats (rows of 4×4 blocks) and skips NaN channels.
  • Tolerances are per format and set by measurement (dds_tolerance).

Result: RTX 3060, driver 616.64, one game texture per format with ≥ 64 distinct values

formats worst error tolerance result
RGBA8, R8, R16F, BC7, BC7 sRGB, BC2 ≤ 0.003 2/255 pass
A8, BGRA8, BGRA8 sRGB ≤ 2/255 except ≤ 4 edge texels 2/255 pass
BC4, BC5 0.0089 3/255 pass
BC1, BC3 0.020 6/255 pass
BC1 sRGB, BC3 sRGB 0.026 7/255 pass
BC6H UF16, SF16 0.033 0.04 pass

| RGBA16F (256×2), RGBA16 UNORM (128×4) | ≤ 0.0045 | 2/255 | pass |
| RGBA8 sRGB (4×4, uniform: a weak case) | 0 | 2/255 | pass |

All 20 formats pass. RGBA8 sRGB's only 2D texture in the package is a uniform 4×4. Its sRGB decode is the same one that BGRA8 sRGB and the BC sRGB rows exercise with real content.

Why some tolerances are wider (a measurement, not a guess). It's the decoder arithmetic, not the layer. I regenerated the BC1/BC3 reference with different palette arithmetic: integer weights (43a + 21b + 32) >> 6 match the RTX 3060's output 5–7× better than the exact (2a + b) / 3 that ttpf_mips uses (the channels over 2/255 drop from 287 to 40 for BC1 and from 892 to 355 for BC3). BC4/BC5 interpolate their palette above 8 bits.

Negative control. I declared the BC1 sRGB texture as BC1 UNORM, the bug a layer that drops the sRGB decode would have. That gives a worst error of 0.31 with 28,829 channels over, and the test fails. Every tolerance is under 0.05, which a unit test pins.

Tests without the package

tests/test_first_light.py, 32 run (4 package-gated skips):

  • The DDS channel rules (A8, R8, BGRA8 sRGB, and one synthetic BC1 block).
  • Rejection of an unsupported format and of a cut-short payload.
  • The tolerance ceiling.

The ramp result from #2906 is unchanged (worst 0.00028).

No texture data, shaders or images are in the PR; everything stays in the user's work folder.

Thanks

  • @CaravelaLabs for the AMD RADV run (GFX1151) that caught ps_m2_literal missing from the GPU runner's harness map (fixed in #2887, 5cd7fe73).
  • @SweatierKey for the code read and CPU checks of the whole stack at 81f91972 (Linux).
  • @throny for the RTX 4080 run with another model and 24 textures that showed the reference needed to allow for the GPU's sub-pixel snapping (fixed in f50b4844).
  • @traeb0n for the RTX 5070 run of everything that needs no game files (150/150 under validation).
  • @SpositoDouglas for the AMD RDNA4 Windows run (RX 9060 XT, 154/154 ctest with validation, ps_m2_literal checks pass).
  • @KorahX365 for the AMD RX 6600 Windows build and test run.
  • @465d6a0eac for the RTX 3070 Ti re-run of bd7b4567 with two models (28/28 draws, plus the missed-sRGB control), and for the note on model choice, now in §9 (39c63602).
  • @elderdragon0 for the bd7b4567 run on an RX 5700 XT (RDNA 1) with six textures from a local export: 7/7 cases, the first RDNA 1 result.

Update: the reference allows for sub-pixel snapping (f50b4844)

@throny's run on another model failed on a few hundred channels. Two rasteriser effects explained every one:

  • a pixel centre 1e-5 px off an edge, which the GPU's 1/256-px vertex snapping can give to the triangle behind;
  • minification up to 37 texels per pixel (mip 0 only), where the same shift moves the UV by a tenth of a texel.

The reference now treats a sample within 1/128 px of an edge as an edge sample. It also writes a per-pixel band, expected_band.raw: how much its value changes when the sample moves 1/32 px along the UV gradient. Float formats get a relative tolerance.

Re-run on 4 game models × 37 textures (all 20 formats): 148/148 pass, 0 channels over. The missed-sRGB control still fails (9,992 channels over).

  • @elderdragon0: tested on RX 5700 XT.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/35 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/4251` --- ### 📝 Commits (10+) - [`c838d60`](https://github.com/ubiquitarianism/leonida/commit/c838d6018181d0831b42ef8dea111d70476e4226) First light with a texture: the real model through a game PS that samples a T# (TEST-524) - [`996591f`](https://github.com/ubiquitarianism/leonida/commit/996591f284e15c8712f2f92ab4615c3ec351a6ad) first_light: UV-seam pixels are reported, not guessed, in the textured reference - [`178d4c8`](https://github.com/ubiquitarianism/leonida/commit/178d4c86587691e2cbf3c3bc8c5cdfc1f1b6540f) first_light: a seam is judged from the latest hit back to the first interior one - [`44db1ed`](https://github.com/ubiquitarianism/leonida/commit/44db1edf2d6a72d118113da2b864a3938ea0e667) first_light: the shared-edge shortcut needs a real shared edge - [`16003a6`](https://github.com/ubiquitarianism/leonida/commit/16003a633004a39565c7421552a81a50aa3fc9b7) d3d12_first_light_textured_test: read LEONIDA_FIRST_LIGHT_TEX_DIR with _dupenv_s - [`7a08f9f`](https://github.com/ubiquitarianism/leonida/commit/7a08f9fbcf58f9ecd9df9c8546f94d022e0db871) d3d12_first_light_textured_test: the comment on d3d12_textured.raw names no option that doesn't exist - [`5cb119c`](https://github.com/ubiquitarianism/leonida/commit/5cb119cc3a53ed54438e5c3df23a614ff2bd7c51) first_light: the ramp's manifest keys no longer collide with the --dds harness path - [`9410b62`](https://github.com/ubiquitarianism/leonida/commit/9410b624281ca854a732750ce9145b6856b12747) first_light textured: the PS's pointer SGPR and T# slot come from the PS (13 game copy shaders pass) - [`cbe4c99`](https://github.com/ubiquitarianism/leonida/commit/cbe4c99bcc2cfe26b5a97423e047a725dfc31894) first light: every texture format the game uses, from a real texture, through the D3D12 layer - [`a52ce94`](https://github.com/ubiquitarianism/leonida/commit/a52ce948e2f0b50cb6c0f5bb01f453bfeca65caa) docs/first_light.md §8: all 20 game texture formats run through the layer ### 📊 Changes **5 files changed** (+1168 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/first_light.md` (+124 -1) 📝 `runtime/CMakeLists.txt` (+6 -0) ➕ `runtime/test/d3d12_first_light_textured_test.cpp` (+453 -0) 📝 `tests/test_first_light.py` (+229 -0) 📝 `tools/first_light.py` (+356 -0) </details> ### 📄 Description > Carried over from **old PR 4251** by `rafaelpssz` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/4251`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `rafaelpssz`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): [Claim](https://github.com/ItsNotRexed/Leonida/issues/4084#issuecomment-7088096356) (new TEST item). **Depends on: `#2906`** (and through it on `#2887`). Its commits are the base here; only the top commit, `b90d802b`, is new. ### What This checks every texture format the game actually uses by sampling a **real game texture** through the D3D12 layer, each in its own format, BC blocks included. The package's 357,115 TTPF descriptors use 20 DXGI formats, counted on my 1.0.2.1 copy: - BC1: 174,674, plus 82,177 sRGB. - BC7: 52,612, plus 25,226 sRGB. - BC5: 6,904. BC4: 4,656. BC3: 3,045, plus 3,880 sRGB. - BC6H: 1,000 UF16 and 25 SF16. - RGBA8: 1,774. R16F: 947. A8: 121. BGRA8: 50, plus 4 sRGB. R8: 8. - RGBA16 UNORM: 5. RGBA16F: 3. BC2: 2. RGBA8 sRGB: 2. The changes: - `first_light.py --texture-dds <file>` reads a DX10 DDS's mip 0 (as `ttpf_mips.py export` writes it) into `texture.bin` in its own format. It writes the CPU reference to `expected.raw`, decoded with `ttpf_mips.decode_pixels` and these per-format rules: - sRGB is linearised before filtering, as the hardware does. - A8 samples as (0, 0, 0, a). R8, BC4 and R16F sample as (r, 0, 0, 1). BC5 samples as (r, g, 0, 1). - An alpha the decoder doesn't give is left out of the comparison (NaN). - `d3d12_first_light_textured` uploads block-compressed formats (rows of 4×4 blocks) and skips NaN channels. - Tolerances are per format and set by measurement (`dds_tolerance`). ### Result: RTX 3060, driver 616.64, one game texture per format with ≥ 64 distinct values | formats | worst error | tolerance | result | |---|---:|---:|---| | RGBA8, R8, R16F, BC7, BC7 sRGB, BC2 | ≤ 0.003 | 2/255 | pass | | A8, BGRA8, BGRA8 sRGB | ≤ 2/255 except ≤ 4 edge texels | 2/255 | pass | | BC4, BC5 | 0.0089 | 3/255 | pass | | BC1, BC3 | 0.020 | 6/255 | pass | | BC1 sRGB, BC3 sRGB | 0.026 | 7/255 | pass | | BC6H UF16, SF16 | 0.033 | 0.04 | pass | | RGBA16F (256×2), RGBA16 UNORM (128×4) | ≤ 0.0045 | 2/255 | pass | | RGBA8 sRGB (4×4, uniform: a weak case) | 0 | 2/255 | pass | **All 20 formats pass.** RGBA8 sRGB's only 2D texture in the package is a uniform 4×4. Its sRGB decode is the same one that BGRA8 sRGB and the BC sRGB rows exercise with real content. **Why some tolerances are wider (a measurement, not a guess).** It's the decoder arithmetic, not the layer. I regenerated the BC1/BC3 reference with different palette arithmetic: integer weights `(43a + 21b + 32) >> 6` match the RTX 3060's output **5–7× better** than the exact `(2a + b) / 3` that `ttpf_mips` uses (the channels over 2/255 drop from 287 to 40 for BC1 and from 892 to 355 for BC3). BC4/BC5 interpolate their palette above 8 bits. **Negative control.** I declared the BC1 sRGB texture as BC1 UNORM, the bug a layer that drops the sRGB decode would have. That gives a worst error of **0.31** with 28,829 channels over, and the test fails. Every tolerance is under 0.05, which a unit test pins. ### Tests without the package `tests/test_first_light.py`, 32 run (4 package-gated skips): - The DDS channel rules (A8, R8, BGRA8 sRGB, and one synthetic BC1 block). - Rejection of an unsupported format and of a cut-short payload. - The tolerance ceiling. The ramp result from `#2906` is unchanged (worst 0.00028). No texture data, shaders or images are in the PR; everything stays in the user's work folder. ### Thanks - `@CaravelaLabs` for the AMD RADV run (GFX1151) that caught `ps_m2_literal` missing from the GPU runner's harness map (fixed in `#2887`, `5cd7fe73`). - `@SweatierKey` for the code read and CPU checks of the whole stack at `81f91972` (Linux). - `@throny` for the RTX 4080 run with another model and 24 textures that showed the reference needed to allow for the GPU's sub-pixel snapping (fixed in `f50b4844`). - `@traeb0n` for the RTX 5070 run of everything that needs no game files (150/150 under validation). - `@SpositoDouglas` for the AMD RDNA4 Windows run (RX 9060 XT, 154/154 ctest with validation, `ps_m2_literal` checks pass). - `@KorahX365` for the AMD RX 6600 Windows build and test run. - `@465d6a0eac` for the RTX 3070 Ti re-run of `bd7b4567` with two models (28/28 draws, plus the missed-sRGB control), and for the note on model choice, now in §9 (`39c63602`). - `@elderdragon0` for the `bd7b4567` run on an RX 5700 XT (RDNA 1) with six textures from a local export: 7/7 cases, the first RDNA 1 result. ### Update: the reference allows for sub-pixel snapping (`f50b4844`) `@throny`'s run on another model failed on a few hundred channels. Two rasteriser effects explained every one: - a pixel centre 1e-5 px off an edge, which the GPU's 1/256-px vertex snapping can give to the triangle behind; - minification up to 37 texels per pixel (mip 0 only), where the same shift moves the UV by a tenth of a texel. The reference now treats a sample within 1/128 px of an edge as an edge sample. It also writes a per-pixel band, `expected_band.raw`: how much its value changes when the sample moves 1/32 px along the UV gradient. Float formats get a relative tolerance. Re-run on 4 game models × 37 textures (all 20 formats): **148/148 pass**, 0 channels over. The missed-sRGB control still fails (9,992 channels over). - `@elderdragon0`: tested on RX 5700 XT. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#88
No description provided.