Skip to content

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

Open
rafaelpssz wants to merge 13 commits into
ProjectLeonida:mainfrom
rafaelpssz:test/layer-game-formats
Open

rafaelpssz wants to merge 13 commits into
ProjectLeonida:mainfrom
rafaelpssz:test/layer-game-formats

Conversation

@rafaelpssz

@rafaelpssz rafaelpssz commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

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 d3d12: a pipeline registers its shaders' literal S#s (they sampled through the fallback) #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).

@rafaelpssz rafaelpssz changed the title Every texture format the game uses, from a real game texture, through the D3D12 layer (17 of 20 formats) Every texture format the game uses, from a real game texture, through the D3D12 layer (all 20 formats) Nov 23, 2026
@CaravelaLabs

Copy link
Copy Markdown
Contributor

Automated test: b90d802b merged onto main aa2988cc on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5), Mesa 25.2.8, Ubuntu 24.04, runtime rebuilt from this branch in a clean sandbox. Result: new GPU test failed on this machine; existing tests matched main.

  • scripts/run_gpu_tests.py: 192/210 passed, 15 skipped (plain main: 192/209 passed, 15 skipped).
    • new test ps_m2_literal: fail

Same machine and setup as my earlier manual reports. AI-assisted (Claude Code).

@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

Thanks @CaravelaLabs. That failure was in the runner, not the layer: ps_m2_literal (the new M2 shader from #2887) wasn't in scripts/run_gpu_tests.py's OTHER_HARNESS, so the generic runner ran it as a self-checking shader. It belongs to d3d12_m2_textured_test like ps_m2 and ps_m2_uoff, which checks it there (no sampler key before the PSO, a registered sampler after).

Fixed in #2887 (5cd7fe73), and this PR plus #2906 are restacked on it (head 81f91972). test_run_gpu_tests and test_run_gpu_tests_paths pass. A rerun on RADV should give 192/209 like main, with ps_m2_literal covered by d3d12_m2_textured. You're in Thanks here and on #2887.

@SweatierKey

Copy link
Copy Markdown
Contributor

Independent code read + CPU unit/assembly check at 81f91972 on Linux (WSL2, Python 3.13.5, llvm-mc 18.1.8, no Windows/GPU host, no game files): pass (Windows D3D12/Vulkan GPU run of d3d12_m2_textured_test and d3d12_first_light_textured_test not run here).

  • Code read (shader_library.h, d3d12_vulkan_device.cpp, tools/first_light.py, docs/design.md):
    • shader_library.h parses literal_samplers safely (requires an array of 4-element arrays) into ShaderEntry::literal_samplers.
    • d3d12_vulkan_device.cpp: register_literal_samplers calls idempotent device.bind_sampler(words) on both graphics (per stage with bindings) and compute (entry->binding_count) pipeline creation, logging once if the bindless sampler array is unavailable/full.
    • tools/first_light.py UV seam ambiguity detection (uv_map, AMBIGUOUS) cleanly flags shared-edge UV seams rather than guessing rasterizer tie-break rules.
    • docs/design.md updates only the Literal samplers contract row.
  • Checks run (clean worktree on 03b09a08):
    • python3 -I tests/test_first_light.py -v: 32 tests run, 28 passed, 4 skipped (all 13 new LayerTexturedOracleTests pass).
    • python3 -I tests/test_run_gpu_tests.py -v: 40/40 OK.
    • llvm-mc -triple=amdgcn-- -mcpu=gfx1013 -show-encoding < runtime/test/shaders/ps_m2_literal.asm: exit 0.
    • git diff --check, test_ctest_registration.py (4/4), test_docs_links.py (6/6), test_docs_repo_paths.py (2/2), test_text_write_line_endings.py (3/3), test_text_encoding.py (2/2): all pass.
  • Not run here: Windows MSVC build, Vulkan GPU execution, or game-texture export.

AI-assisted review.

@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

Thanks @SweatierKey, a full read of the stack and the CPU checks on Linux are a useful complement to the GPU runs. You're in Thanks.

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 81f9197 on NVIDIA RTX 4080, driver 610.88, Windows 11: fail. The test fails on some real textures in 6 formats; I found no layer error (the format mapping looks right).

Ran (MSVC 19.44 / VS 2022 BuildTools, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0, base aa2988cc):

  • Built d3d12_first_light_textured_test at this head.
  • Used my own 1.0.2.1 copy: the §7 VS and PS pair from my carve, and a different exported model from yours. It covers 7,217 of 16,384 pixels, not 12,804.
  • For each case: tools/first_light.py --vs … --ps=… --obj <model> --out <dir> (--texture ramp | --texture-dds <exported DDS>), then LEONIDA_FIRST_LIGHT_TEX_DIR=<dir> d3d12_first_light_textured_test.exe. The card was idle, and the numbers repeat exactly on rerun.

Ramp: pass. Worst 0.00110, mean 0.000028, 0 channels over 0.002, 0 coverage mismatches.

One exported texture per format (the first 2D DX10 DDS of each format I found, not chosen for content):

DXGI result worst channels over tolerance
61 R8, 71 BC1, 72 BC1 sRGB, 74 BC2, 77 BC3, 80 BC4, 83 BC5, 87 BGRA8, 95 BC6H UF16, 98 BC7, 99 BC7 sRGB pass ≤ 0.016 0–2
28 RGBA8 fail 0.035 114
29 RGBA8 sRGB fail 0.074 26
54 R16F fail 0.371 249
65 A8 fail 0.041 13
78 BC3 sRGB fail 0.140 13
96 BC6H SF16 fail 0.398 45

Formats 41 and 56 are refused by --texture-dds ("not one d3d12_first_light_textured uploads"), as expected. I found no 2D texture of formats 10, 11 or 91 in my export, so those weren't run.

The pass/fail depends on the texture, not the format. For the six failing formats I ran 4 textures each:

DXGI pass / fail failing runs
28 1 / 3 21–114 channels over, worst 0.019–0.035
29 1 / 3 9–26 over, worst 0.012–0.074
54 2 / 2 80–249 over, worst 0.32–0.37
65 1 / 3 13–42 over, worst 0.041–0.052
78 3 / 1 13 over, worst 0.14
96 3 / 1 45 over, worst 0.40

Every failing run has a tiny mean error (≤ 0.0008) and at most 249 of about 29,000 channels over. Your missed-sRGB control gives 28,829 over, so these don't look like a wrong format or decode. A hypothesis I haven't checked: my model covers fewer pixels, so 256–512-texel textures are minified by 3× or more with only mip 0 bound. On high-contrast content, a tiny difference between the GPU's and the CPU's interpolated UV then lands on a different texel. Your tolerances were set on one texture per format, picked for ≥ 64 distinct values on a larger footprint.

As written, the gate (over <= compared / 1000, runtime/test/d3d12_first_light_textured_test.cpp:433) passes or fails depending on which texture and model the tester picks. Possible fixes:

  • name the texture-selection rule (size, footprint) in §8;
  • compare against a reference that samples the GPU's own UVs;
  • for the CPU reference, use the bilinear filter's quantised weights, or tolerate a neighbour-texel hit at high-contrast edges.

Game data stayed local; formats, counts and error magnitudes only. AI-assisted.

@traeb0n

traeb0n commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 81f9197 on NVIDIA GeForce RTX 5070, driver 621.01, Windows 11 Pro 26300, i7-14700K / 64 GB, MSVC 14.44 RelWithDebInfo (scripts/build_runtime.ps1, llvm-mc 23.1.6 so the translated-shader targets build), Vulkan SDK 1.4.363, LEONIDA_VK_VALIDATION=1 for ctest: the parts that need no game files pass. The main result needs a game texture, which I don't have.

  • Build: exit 0, 0 compiler warnings. Full ctest -E loader -j 4: 150/150.
  • Run alone: d3d12_m2_textured (with the new ps_m2_literal) passes. d3d12_first_light and d3d12_first_light_textured skip without a game texture, as expected.
  • pytest tests/test_first_light.py: 29 passed, 3 skipped, 4 subtests passed.
  • scripts/run_gpu_tests.py: 164/211 passed, 47 skipped, 0 failed. main gives 164/210 with 46 skipped. The one extra skip is the new ps_m2_literal ("run by d3d12_m2_textured_test"). All 215 shaders translate and pass spirv-val.

Baseline on main 03b09a0, same machine and settings: 150/150 ctest, 0 compiler warnings.

No game files. AI-assisted (Claude Code).

@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

Thanks @throny, this is the review the gate needed. You're right: as written, pass or fail depends on which texture and model the tester picks. My tolerances were set on one texture per format with my model's footprint, and that doesn't hold in general. Two things already show it on my side:

  • Float formats need a relative tolerance. The BC6H textures I ran go up to 19.4 (UF16) and 34.3 (SF16), so an absolute 0.04 is tight on bright texels and loose on dark ones. Your R16F and BC6H SF16 misses (worst 0.37–0.40 with a tiny mean) look like the same thing on HDR content.
  • The reference has no position uncertainty. It samples at the exact UV of each pixel centre, while the GPU snaps vertices to sub-pixel precision before interpolating. Under 3× minification with only mip 0 bound, a high-contrast texel boundary turns that small shift into a large colour change. That fits your "few channels, tiny mean" pattern.

The plan, to be checked against a reproduction before I push:

  • The CPU reference gets a per-pixel, per-channel allowance: how much its own bilinear sample changes when the pixel's position moves by the hardware's sub-pixel step (the UV derivatives come from the triangle).
  • Float formats get a tolerance relative to the texel value.
  • §8 states the texture-selection rule.

A wrong format, swizzle or missed sRGB decode is a global error, so it still fails by orders of magnitude (I'll keep the BC1-sRGB-as-UNORM control in the tests).

I'm exporting the first 4 textures of each of your six formats now to reproduce it here.

Thanks too @traeb0n: 150/150 under validation, and the one extra runner skip being ps_m2_literal is the expected result after 5cd7fe73. You're both going in Thanks.

@CaravelaLabs

Copy link
Copy Markdown
Contributor

Follow-up at 81f91972 (runner now skips ps_m2_literal for d3d12_m2_textured_test):

Automated test: 81f91972 merged onto main 03b09a08 on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5), Mesa 25.2.8, Ubuntu 24.04, runtime rebuilt from this branch in a clean sandbox. Result: pass.

  • scripts/run_gpu_tests.py: 192/210 passed, 16 skipped (plain main: 192/209 passed, 15 skipped).
    • new test ps_m2_literal: skip

Same machine and setup as my earlier manual reports. AI-assisted (Claude Code).

rafaelpssz added a commit to rafaelpssz/Leonida that referenced this pull request Nov 23, 2026
…apping

@throny's run on another model failed 6 formats on a few hundred of 29,000
channels with a tiny mean (ItsNotRexed#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 <noreply@anthropic.com>
@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

@throny, fixed in f50b4844. Your diagnosis pointed the right way. I reproduced it here with three more game models; at first 3 of 4 failed, on the same pattern (a few channels, tiny mean). Two rasteriser effects explained every failing channel:

  1. Edge ownership. On one model the big errors (up to 0.58) were pixel centres 1e-5 px off a triangle edge. The reference gave them to the upper triangle by exact float weights. The GPU snaps vertices to 1/256 px and gave them to the layer behind. uv_map now measures edge distance in pixels: a sample within 1/128 px is an edge sample, and it is reported, not compared, when the triangles there give different UVs.
  2. Minification with only mip 0. On another model the texture covers about 37 texels per pixel. Every failing channel there was the reference moved by 0.002–0.02 px. first_light.py now also writes expected_band.raw: per pixel and channel, how much the reference changes when the sample moves 1/32 px along the triangle's UV gradient. The harness adds that to the format's tolerance, so it widens only where the texture changes fast at that pixel's scale.

Also as planned: float formats (R16F, RGBA16F, BC6H, values up to 34) get a relative tolerance. A seam-heavy flattened model may report up to 5% of its pixels instead of 1% (one model measures 1.4%).

Result (RTX 3060):

  • 4 models × 37 textures, covering all 20 formats, 4,900–10,300 covered pixels each: 148/148 pass, 0 channels over.
  • The missed-sRGB control (BC1 sRGB declared as UNORM) still fails with the band: 9,992 channels over on the most minified model.
  • Three new unit tests fail on the previous code:
    • a sample 0.001 px off an edge is reported;
    • the band is zero on a flat texture and wide across a hard edge at 16 texels per pixel;
    • only the float formats are relative.

A rerun with your model and textures would be the real confirmation. You and @traeb0n are in Thanks.

@CaravelaLabs, thanks for the follow-up: RADV 192/210 with ps_m2_literal skipped is the expected result.

@SpositoDouglas

Copy link
Copy Markdown
Contributor

Tested on an AMD Radeon RX 9060 XT (RDNA4), AMD Software 26.11.2 (Vulkan driver 2.0.416), Windows 11 26H2 (26300), MSVC 19.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8: pass for everything that runs without a game copy. This is AMD's Windows driver, next to the RTX 5070 and RADV runs above.

At f50b4844:

  • d3d12_m2_textured_test: pass, plain and with LEONIDA_VK_VALIDATION=1 (0 validation messages). 4096/4096 pixels, error 0, and the sampler control differs in 1536 pixels. The new ps_m2_literal checks pass: the index lists its S# under literal_samplers, and the hash table has no key for it before CreateGraphicsPipelineState and a sampler index after.
  • tests/test_first_light.py: 35 tests OK, 3 skipped (the ones that need a first-light work folder).
  • d3d12_first_light_textured_test: SKIP (exit 77) without LEONIDA_FIRST_LIGHT_TEX_DIR, as documented.

At 81f91972 (f50b4844 changes only the first-light files):

  • scripts/run_gpu_tests.py, native wave64 and with LEONIDA_W64_EMULATE=1: 215 translated, 215 pass spirv-val; 196/211 passed, 15 skipped. On main (03b09a08) the same runs give 214, 196/210 and 14. The only difference is ps_m2_literal, now SKIP (run by d3d12_m2_textured_test).
  • ctest: 154/154, the same with validation. d3d12_m2_textured and d3d12_m2_formats pass.

I didn't run the ramp or the game-texture cases: both draw with the game's VS and PS from a work folder, and I didn't use a game copy for this check.

AI-assisted (Claude Code). No game files.

@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

Thanks @SpositoDouglas. That is the first AMD Windows driver run (RDNA4) of this stack, and it agrees with the NVIDIA and RADV runs. The ps_m2_literal checks are exactly what the test pins: no key before the PSO, a sampler index after. You're in Thanks.

rafaelpssz added a commit to rafaelpssz/Leonida that referenced this pull request Nov 23, 2026
…apping

@throny's run on another model failed 6 formats on a few hundred of 29,000
channels with a tiny mean (ProjectLeonida#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 <noreply@anthropic.com>
@rafaelpssz
rafaelpssz force-pushed the test/layer-game-formats branch from f50b484 to 8820f1f Compare November 23, 2026 03:50
rafaelpssz added a commit to rafaelpssz/Leonida that referenced this pull request Nov 23, 2026
…apping

@throny's run on another model failed 6 formats on a few hundred of 29,000
channels with a tiny mean (ItsNotRexed#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 <noreply@anthropic.com>
@rafaelpssz
rafaelpssz force-pushed the test/layer-game-formats branch from 8820f1f to 96eb48d Compare November 23, 2026 03:51
@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

Rebased the stack on main 2d3369a4, after round 43:

On an RTX 3060: test_first_light.py 40 passed, 8 skipped; d3d12_m2_textured passes; the textured draw with a game texture passes.

@Vonsek

Vonsek commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 96eb48d on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran ctest -R "^d3d12_first_light_textured$": package-gated, so SKIPPED on both GPUs (no game package here); the textured draw was not exercised. No game files.

AI-assisted.

rafaelpssz and others added 9 commits November 23, 2026 12:23
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 <noreply@anthropic.com>
…h _dupenv_s

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 <noreply@anthropic.com>
…mes no option that doesn't exist

Reported by @zzEmmazz.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s harness path

Since the rebase onto 7e1aecf, --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 ItsNotRexed#2887 is 19,041 channels (measured here and
on three other GPUs). Found by @zzEmmazz.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… PS (13 game copy shaders pass)

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 <noreply@anthropic.com>
… through the D3D12 layer

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 <noreply@anthropic.com>
…ayer

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 <noreply@anthropic.com>
…apping

@throny's run on another model failed 6 formats on a few hundred of 29,000
channels with a tiny mean (ProjectLeonida#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 <noreply@anthropic.com>
…n landed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

Rebased onto main 1cc6e3c1, on top of #2906's new head. The formats section is now §9 of docs/first_light.md, and the two comments that point at it say so. test_first_light.py passes 58, and the textured draw with a game texture passes on the RTX 3060. @AirKyzzZ, it's up: bd7b4567, if you want to run it on your package.

@465d6a0eac

Copy link
Copy Markdown
Contributor

Re-tested the current head bd7b45678, merged onto main 8575d36ed, on Windows 11 (build 26300), RTX 3070 Ti (Ampere, driver 610.88), with game files from my own 1.0.2.1 copy: pass. Build: MSVC 19.44.35230, Windows SDK 10.0.26100, RelWithDebInfo with Ninja, Vulkan SDK 1.4.363. Shaders were translated with llvm-mc 21.1.8 through WSL. Counts only; the textures and images stay on my machine.

Without the package

With the package

  • Textures. One 2D texture per format, from the TTPF pools (ttpf_mips.py export … --mips 1). That covers 14 of the 20 formats:
    • The BC3 and BC6H SF16 textures I picked need the provisional BCPack history, so I left those two out.
    • I found no RGBA16F, RGBA16 UNORM, RGBA8 sRGB or BC2 texture in the first 4,000 descriptors of each pool.
  • Models. Two models from rpf9dump models data.rpf:
    • A: 3,555 vertices, 5,312 pixels covered, 25 on a seam.
    • B: 4,348 vertices, 1,629 pixels covered, 3 on a seam.
  • Result. All 28 draws pass, with 0 channels over and 0 coverage mismatches.
format worst A worst B tolerance
RGBA8 0.0010 0.0015 2/255
R8 0.2006 0.0077 2/255
R16F 0.0011 0.0013 2/255 (relative)
A8 0.0186 0.0076 2/255
BGRA8 0.0125 0.0042 2/255
BGRA8 sRGB 0.1145 0.0860 2/255
BC1 0.0162 0.0161 6/255
BC1 sRGB 0.0054 0.0063 7/255
BC3 sRGB 0.0231 0.0195 7/255
BC4 0.0149 0.0101 3/255
BC5 0.0106 0.0045 3/255
BC6H UF16 0.0005 0.3438 0.04 (relative)
BC7 0.0170 0.0214 2/255
BC7 sRGB 0.0000 0.0000 2/255 (this texture is close to uniform, so it's a weak case)

Where the worst error is above the format's tolerance, the count over the tolerance is still 0. Those pixels are within the per-pixel expected_band the reference adds, or the relative float tolerance. The means are all at or below 0.0023.

Negative control. I kept the BC1 sRGB folder's expected.raw and changed only texture.bin's format word from 72 to 71 (BC1 UNORM), which is a layer that drops the sRGB decode. It fails on both models, as it should: worst 0.290 with 15,861 channels over on A, and worst 0.291 with 4,878 over on B (line 446: over <= compared / 1000).

An observation for anyone choosing a model. Before A and B, I tried 10 random data.rpf models of 3.5k–8k vertices with the BC1 texture. All 10 had 0 colour channels over. Four failed line 442: ambiguous <= covered / 20: they are thin, seam-heavy models with 26–85 seam pixels out of 516–1,569 covered (5–8%). That guard is in the CPU reference, so it depends on the model, not the GPU. It might be worth a line in §9 saying to pick a model that covers a few thousand pixels.

AI-assisted (Claude Code).

…ixels

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 <noreply@anthropic.com>
@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

@465d6a0eac Thanks for the re-run and the negative control. Good point on model choice: §9 now says to pick a model that covers a few thousand pixels, since thin models of 500 to 1,600 covered pixels can reach 5 to 8% seam pixels and fail that check before any colour is compared (39c6360).

@elderdragon0

Copy link
Copy Markdown

Tested bd7b4567 on an AMD Radeon RX 5700 XT (RDNA 1), driver 26.11.2, Windows 11 build 26300. Built d3d12_first_light_textured_test with MSVC 19.44 in Release mode. Used the repository’s Python shader disassembler. Both translated shaders passed spirv-val.

7/7 cases passed using the same exported OBJ and shader pair throughout. Each run compared 12,732 pixels, with zero coverage mismatches and zero color channels over tolerance.

Input Cases Largest channel error
Generated ramp (control) 1 0.00046
RGBA8 1 0.00071
R16F 2 0.00112
BC3 sRGB 2 0.01018
BC6H signed float 1 0.03839

The six DDS textures came from my local 1.0.2.1 export. Game files and raw GPU output stayed local. AI-assisted.

@paulo-lang

Copy link
Copy Markdown

PR cleanup, #8919 — this is stacked on #2906 (the branch contains 9410b62). Suggest merging #2906 first, then rebasing this and getting one non-author pass at 39c6360.

Independent of #4136 and #4055 conceptually, but it conflicts with #4136 in the manifest write, so land #4136 first if both go in. Thanks!

@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

@paulo-lang agreed on the order: #2906 first, then this one on top of it. Both were closed in the cleanup and are reopened now.

On the non-author pass at 39c63602: the only change since bd7b4567 is three lines in docs/first_light.md (section 9 says to pick a model that covers a few thousand pixels). The code and tests are the ones @elderdragon0 ran on an RX 5700 XT (7/7 cases) and @465d6a0eac re-ran on an RTX 3070 Ti (28/28 draws). So the head is covered for everything that executes; the doc line is the part nobody else has read.

On #4136: it is closed, so the manifest-write conflict is gone unless it comes back. If it is reopened and lands first, I will redo the manifest hunk on top of it.

@elderdragon0 thanks for the RDNA 1 run, the first on that generation. You are in Thanks.

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.