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

Closed
Andretuta wants to merge 13 commits from upstream-pr/35 into main
Andretuta commented 2026-11-24 02:04:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:04:33Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464685437 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/35). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:04:33Z. --- > 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.
aslan2142 commented 2026-12-01 17:19:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T17:19:44Z.


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:7319124060 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/35#issuecomment-7319124060). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T17:19:44Z. --- 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!35
No description provided.