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

Open
github-bot wants to merge 8 commits from github-bot/gh-33 into main AGit
Owner

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

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.
**@⁠Andretuta** on GitHub · 2026-11-24 02:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/33) `ubiquitarianism:old-pr/2906` → `main` · +782 −1 · 5 files · 8 commits · draft > 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.
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]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:41:45 +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/33/head:github-bot/gh-33'
git switch 'github-bot/gh-33'

Merge

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