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

Open
github-bot wants to merge 13 commits from github-bot/gh-35 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:04 UTC · original
ubiquitarianism:old-pr/4251 → main · +1168 −1 · 5 files · 13 commits · draft

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.
**@⁠Andretuta** on GitHub · 2026-11-24 02:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/35) `ubiquitarianism:old-pr/4251` → `main` · +1168 −1 · 5 files · 13 commits · draft > 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.
d3d12_first_light_textured_test draws the first-light mesh through the
D3D12 layer with the game's VS and $PS_PassthroughCopy, picked by census
(780 of 12,101 PS do one image_sample and nothing else; 148 of those link
with the VS). The PS loads its T# through the table pointer in s8 and
samples with a literal S#; the root signature puts a one-SRV table at
s8:s9 behind eight padding constants.

first_light.py --texture ramp writes texture.bin, a 64x64 coordinate ramp
(texel (x, y) holds its own centre, so bilinear sampling gives back the
UV), and expected.raw, the CPU reference at every covered pixel's UV.

RTX 3060: 12,804 pixels, the same coverage as d3d12_first_light, worst
channel error 0.00028 against a 0.002 tolerance; point sampling is off by
up to 1/128, which is what this draw gave before #2887.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A sample on a shared edge between triangles that give it different UVs
belongs to whichever triangle the rasteriser's tie-break rule picks;
uv_map let the last one win, so a correct draw could fail at a seam.
Those pixels are now marked in expected.raw (alpha -2): coverage is
still checked, the colour is not, and the test counts them. Found by
@whattheflop's diagonal-quad fixture, which is now a unit test.

The first-light model has no seam pixels; its result is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An earlier edge no longer exempts a pixel that a later interior owns
(@whattheflop's nested-triangle fixture), and a lone edge over an older
interior with another UV is ambiguous. Edge hits after the last interior
that share one UV are an edge both triangles share, which the tie-break
gives to one of them: not ambiguous. Without that rule the flattened
first-light model's front layer, drawn over its back layer, marked 188
pixels; with it, 0, and all 12,804 are compared.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Equal UVs don't make two triangles share an edge. The rasteriser gives
one owner only to triangles on opposite sides of a common edge with
identical endpoints, so the shortcut now requires such a pair among the
later edge hits; a sample on a vertex never takes it. @whattheflop's
overlapping right edges (same side, different endpoints) stay ambiguous.
The first-light model: 8 ambiguous samples, 12,796 compared, unchanged
worst error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
MSVC warns about std::getenv (C4996); pe_loader_test reads its
environment the same way. Reported by @JRamos1993.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reported by @zzEmmazz.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since the rebase onto 7e1aecf0, --texture ramp exited with a TypeError:
write_textured_inputs stored "texture": "ramp" and files["texture"],
which harness_env reads as the --dds dict. The ramp's keys are now
layer_texture*; a unit test feeds harness_env a ramp manifest (fails on
the old keys). The vk_harness tests skip a ramp folder, which only the
D3D12-layer test can draw. docs/first_light.md §7: the command names its
--out, and the count without #2887 is 19,041 channels (measured here and
on three other GPUs). Found by @zzEmmazz.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
d3d12_first_light_textured fixed the table at s8 and the T# at slot 0.
It now reads layer_ptr_sgpr (from the index's user_sgpr_reads) and
layer_tsharp_offset (the PS's first s_load_dwordx8 offset), pads the root
signature to that SGPR and puts the SRV in that slot, so any 2D copy PS
can be checked. Of the 24 copy PS that link with the first-light VS, all
13 comparable ones pass on an RTX 3060 with worst error 0.00028 (11 plain
copies, 2 that remap channels, checked per channel); 7 transform the UV
and 4 use array/cube textures. docs/first_light.md §7 has the table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
first_light.py --texture-dds writes a DDS's mip 0 in its own format (BC
blocks included) and a CPU reference from ttpf_mips.decode_pixels with
each format's channel rules (sRGB linearised before filtering, A8, R8,
BC4, BC5); d3d12_first_light_textured uploads block formats and skips the
channels the reference can't predict. Tolerances are per format, set by
measurement: the BC1/BC3 palette and BC6H are where hardware rounding
legitimately differs from the CPU decode, and a missed sRGB decode (the
negative control) is off by 0.31.

On an RTX 3060, one game texture per format (17 of the package's 20
formats, all but 10 textures): every one passes. docs/first_light.md §8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RGBA16F (256x2) and RGBA16 UNORM (128x4) pass; RGBA8 sRGB's only 2D
texture is a uniform 4x4, so its row is marked as weak (its sRGB decode is
covered by BGRA8 sRGB and the BC sRGB rows).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@throny's run on another model failed 6 formats on a few hundred of 29,000
channels with a tiny mean (#4251). Reproduced here on three more game models;
two rasteriser effects explained every failing channel:

- A pixel centre 1e-5 px off an edge went to one triangle by the exact float
  test, while the GPU (vertices snapped to 1/256 px) gave it to the one behind.
  uv_map now measures edge distance in pixels: within EDGE_PX (1/128 px) a
  sample is an edge sample, reported when the candidates' UVs differ.
- At up to 37 texels per pixel (mip 0 only) the same shift moves the UV by a
  tenth of a texel. expected_band.raw holds, per pixel and channel, how much
  the reference changes when the sample moves BAND_PX (1/32 px) along the
  triangle's UV gradient; the harness adds it to the tolerance.

Float formats (values up to 34) get a relative tolerance, and a flattened 3D
model may report up to 5% of its pixels (1.4% measured). 4 models x 37
textures (all 20 formats): 148/148 pass on an RTX 3060; the missed-sRGB control
still fails (9,992 channels over).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The 5% seam-pixel limit depends on the model: thin models covering 500 to
1,600 pixels reached 5 to 8% and failed it before any colour was compared.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:41:48 +00:00
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/35/head:github-bot/gh-35'
git switch 'github-bot/gh-35'

Merge

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