[PR #33] TEST-524: first light with a texture — the real model through a game PS that samples a T# #85

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/33
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/2906


📝 Commits (8)

  • 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)

📊 Changes

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

View changed files

📝 docs/first_light.md (+59 -1)
📝 runtime/CMakeLists.txt (+6 -0)
➕ runtime/test/d3d12_first_light_textured_test.cpp (+414 -0)
📝 tests/test_first_light.py (+141 -0)
📝 tools/first_light.py (+162 -0)

📄 Description

Carried over from old PR 2906 by rafaelpssz in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/2906, 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):

TEST-524, claim. It follows the first light work in #1906 and #2001.

Depends on: #2887: merged in round 44, so this PR now sits directly on main.

What

The first textured draw of a real game model through translated game shaders and the D3D12 layer. The model is the data.rpf mesh from #1906/#2001 and the VS is the same VS_main_170e32e6. The PS is a game pixel shader that samples a texture.

The PS, picked by census rather than by hand (counts over the full carve):

  • 780 of the 12,101 PS do exactly one image_sample and no other memory access.
  • 148 of those link with this VS (shader_link_check.py batch).
  • The pick is $PS_PassthroughCopy. It interpolates TEXCOORD, s_loads the T# through the 32-bit table pointer in user SGPR s8, samples with a literal S# (0x92, 0xC00000, 0x14500000, 0: CLAMP_LAST_TEXEL, bilinear, mip point, MAX_LOD 12) and exports with v_cvt_pkrtz_f16_f32.

The draw (runtime/test/d3d12_first_light_textured_test.cpp, ctest d3d12_first_light_textured, package-gated):

  • The root signature is [0] eight 32-bit constants (s0..s7) and [1] a one-SRV table. The layer's packing (docs/d3d12_vulkan.md 3.5) lands the table at s8:s9, exactly where the game's PS reads it.
  • The texture goes through an upload heap and CopyTextureRegion into a DEFAULT texture, and CreateShaderResourceView writes its T# into a shader-visible heap.
  • The literal S# is registered by PSO creation (#2887).

The oracle.

  • first_light.py --texture ramp writes texture.bin, a 64×64 R16G16B16A16_FLOAT coordinate ramp in which texel (x, y) holds its own centre. Bilinear sampling with clamp therefore gives back the UV, clamped to the outer texel centres.
  • It also writes expected.raw, the CPU reference: the ramp sampled at every covered pixel's interpolated UV (uv_map, the same last-triangle-wins rule as uv_at).
  • The test compares every pixel and its coverage. The tolerance is 0.002, under half a texel (1/128 = 0.0078), so a point-sampled draw fails.

Result: RTX 3060, Windows 11, driver 616.64, Vulkan SDK 1.4.363.1

covered coverage mismatches worst error mean error channels over 0.002
this PR (with #2887) 12,804 / 16,384 0 0.00028 0.000045 0
without #2887 12,804 / 16,384 0 0.0078 0.00195 19,041 → fails

The coverage is the same 12,804 pixels as d3d12_first_light, which still passes, as do the other D3D12 tests (d3d12_m2_textured, d3d12_descriptor, d3d12_vulkan_device, d3d12_translated_draw, d3d12_pipeline_library, shader_library).

This test is how #2887 was found. Every value came out as a texel centre, which is point sampling, because the literal S# had never been registered and the lookup found the fallback sampler.

Tests without the package

tests/test_first_light.py adds TexturedOracleTests:

  • the ramp's bytes and texel values;
  • bilinear sampling of the ramp returning the UV and clamping at the edges;
  • point sampling failing the 0.002 tolerance;
  • uv_map equal to uv_at at every pixel of two overlapping triangles;
  • UV-seam pixels reported, not guessed: on @whattheflop's diagonal quad, both draw orders give the same 24 seam pixels and identical pixels everywhere else.

15 tests run; the 3 package-gated ones skip.

Not in this PR

A real albedo. The path a game texture takes is the same T#, table and literal S#; what remains is decoding the model's own TTPF texture into texture.bin and comparing it with a CPU bilinear reference. docs/first_light.md §7 lists this as the next step.

No game data in the PR. The mesh, shaders, texture and drawn image stay in the user's work folder.

Thanks

  • @whattheflop for the review and the diagonal-quad fixture that showed a UV seam could fail a correct draw; seam pixels are now reported and that fixture is a unit test.
  • @JRamos1993 for the RTX 5090 run (131/131, both textured tests 20/20 and clean under validation) and the C4996 report.
  • @kapitche for the RTX 4080 SUPER (130/130) and Intel UHD 770 runs, the first non-NVIDIA pass of both textured tests.
  • @zzEmmazz for rebuilding the inputs from their own copy and the first AMD run (Ryzen RDNA2 iGPU: worst 0.00077) next to an RTX 3070, red and green on both.
  • @nschlaepfer for the RTX 5090 run and the first Apple result (M3 Max through MoltenVK), with a point-sampling and missing-literal-sampler sensitivity check (19,041 channels over on both).
  • @Vonsek for the 10d3eb4 run on an AMD RDNA2 iGPU (26.10.1) and an RTX 5080 (616.92).
  • @Ayinaki for the first independent run of the textured draw on their own package (RTX 5070, another model: 2,615 pixels, worst 0.00031).
  • @sh1shu1 for the 9410b624 run on an RTX 4070 SUPER with MSVC: pass, with the full ctest and GPU suite compared against main.

🔄 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/33 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/2906` --- ### 📝 Commits (8) - [`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) ### 📊 Changes **5 files changed** (+782 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/first_light.md` (+59 -1) 📝 `runtime/CMakeLists.txt` (+6 -0) ➕ `runtime/test/d3d12_first_light_textured_test.cpp` (+414 -0) 📝 `tests/test_first_light.py` (+141 -0) 📝 `tools/first_light.py` (+162 -0) </details> ### 📄 Description > Carried over from **old PR 2906** by `rafaelpssz` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/2906`, 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): TEST-524, [claim](https://github.com/ItsNotRexed/Leonida/issues/2716#issuecomment-7083417033). It follows the first light work in `#1906` and `#2001`. ~~Depends on: `#2887`~~: merged in round 44, so this PR now sits directly on `main`. ### What The first **textured** draw of a real game model through translated game shaders and the D3D12 layer. The model is the `data.rpf` mesh from `#1906`/#2001 and the VS is the same `VS_main_170e32e6`. The PS is a game pixel shader that samples a texture. **The PS, picked by census rather than by hand** (counts over the full carve): - 780 of the 12,101 PS do exactly one `image_sample` and no other memory access. - 148 of those link with this VS (`shader_link_check.py batch`). - The pick is `$PS_PassthroughCopy`. It interpolates TEXCOORD, `s_load`s the T# through the 32-bit table pointer in user SGPR `s8`, samples with a **literal S#** (`0x92, 0xC00000, 0x14500000, 0`: CLAMP_LAST_TEXEL, bilinear, mip point, MAX_LOD 12) and exports with `v_cvt_pkrtz_f16_f32`. **The draw** (`runtime/test/d3d12_first_light_textured_test.cpp`, ctest `d3d12_first_light_textured`, package-gated): - The root signature is [0] eight 32-bit constants (`s0..s7`) and [1] a one-SRV table. The layer's packing (`docs/d3d12_vulkan.md` 3.5) lands the table at `s8:s9`, exactly where the game's PS reads it. - The texture goes through an upload heap and `CopyTextureRegion` into a DEFAULT texture, and `CreateShaderResourceView` writes its T# into a shader-visible heap. - The literal S# is registered by PSO creation (`#2887`). **The oracle.** - `first_light.py --texture ramp` writes `texture.bin`, a 64×64 R16G16B16A16_FLOAT **coordinate ramp** in which texel (x, y) holds its own centre. Bilinear sampling with clamp therefore gives back the UV, clamped to the outer texel centres. - It also writes `expected.raw`, the CPU reference: the ramp sampled at every covered pixel's interpolated UV (`uv_map`, the same last-triangle-wins rule as `uv_at`). - The test compares every pixel and its coverage. The tolerance is 0.002, under half a texel (1/128 = 0.0078), so a point-sampled draw fails. ### Result: RTX 3060, Windows 11, driver 616.64, Vulkan SDK 1.4.363.1 | | covered | coverage mismatches | worst error | mean error | channels over 0.002 | |---|---:|---:|---:|---:|---:| | this PR (with `#2887`) | 12,804 / 16,384 | 0 | 0.00028 | 0.000045 | 0 | | without `#2887` | 12,804 / 16,384 | 0 | 0.0078 | 0.00195 | 19,041 → **fails** | The coverage is the same 12,804 pixels as `d3d12_first_light`, which still passes, as do the other D3D12 tests (`d3d12_m2_textured`, `d3d12_descriptor`, `d3d12_vulkan_device`, `d3d12_translated_draw`, `d3d12_pipeline_library`, `shader_library`). **This test is how `#2887` was found.** Every value came out as a texel centre, which is point sampling, because the literal S# had never been registered and the lookup found the fallback sampler. ### Tests without the package `tests/test_first_light.py` adds `TexturedOracleTests`: - the ramp's bytes and texel values; - bilinear sampling of the ramp returning the UV and clamping at the edges; - point sampling failing the 0.002 tolerance; - `uv_map` equal to `uv_at` at every pixel of two overlapping triangles; - UV-seam pixels reported, not guessed: on `@whattheflop`'s diagonal quad, both draw orders give the same 24 seam pixels and identical pixels everywhere else. 15 tests run; the 3 package-gated ones skip. ### Not in this PR A real albedo. The path a game texture takes is the same T#, table and literal S#; what remains is decoding the model's own TTPF texture into `texture.bin` and comparing it with a CPU bilinear reference. `docs/first_light.md` §7 lists this as the next step. No game data in the PR. The mesh, shaders, texture and drawn image stay in the user's work folder. ### Thanks - `@whattheflop` for the review and the diagonal-quad fixture that showed a UV seam could fail a correct draw; seam pixels are now reported and that fixture is a unit test. - `@JRamos1993` for the RTX 5090 run (131/131, both textured tests 20/20 and clean under validation) and the C4996 report. - `@kapitche` for the RTX 4080 SUPER (130/130) and Intel UHD 770 runs, the first non-NVIDIA pass of both textured tests. - `@zzEmmazz` for rebuilding the inputs from their own copy and the first AMD run (Ryzen RDNA2 iGPU: worst 0.00077) next to an RTX 3070, red and green on both. - `@nschlaepfer` for the RTX 5090 run and the first Apple result (M3 Max through MoltenVK), with a point-sampling and missing-literal-sampler sensitivity check (19,041 channels over on both). - `@Vonsek` for the `10d3eb4` run on an AMD RDNA2 iGPU (26.10.1) and an RTX 5080 (616.92). - `@Ayinaki` for the first independent run of the textured draw on their own package (RTX 5070, another model: 2,615 pixels, worst 0.00031). - `@sh1shu1` for the `9410b624` run on an RTX 4070 SUPER with MSVC: pass, with the full ctest and GPU suite compared against main. --- <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#85
No description provided.