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

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

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


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

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:03:08Z.


Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7310574237 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/33#issuecomment-7310574237). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:03:08Z. --- Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 17:19:41 +00:00 (Migrated from github.com)

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


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