Skip to content

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

Open
rafaelpssz wants to merge 8 commits into
ItsNotRexed:mainfrom
rafaelpssz:test/first-light-textured
Open

rafaelpssz wants to merge 8 commits into
ItsNotRexed:mainfrom
rafaelpssz:test/first-light-textured

Conversation

@rafaelpssz

@rafaelpssz rafaelpssz commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

By @rafaelpssz, with Claude Code (AI-assisted).

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted CPU review on ad04d5672a4f8d8913d9d8efcb9338e4c8bc0bf9 with uv CPython 3.12.13 and hand-built inputs. The unchanged tests/test_first_light.py suite had 8 passes and 3 package-gated skips. An independent affine reference matched every pixel of a 16x12 overlapping-triangle fixture (70 covered, 122 clear, 18 overlap), including both clamp limits and the order reversal in the overlap. A nearest-texel reference put 106 channels over 0.002.

The expected image can falsely reject a correct draw at a UV seam. uv_map accepts both triangles on their common edge and overwrites the earlier UV. Vulkan rasterization gives each shared-edge sample to exactly one triangle. The stock uv_map comparison uses uv_at, which shares the inclusive edge predicate. Vulkan polygon rasterization rules

I fed write_textured_inputs a quad with framebuffer corners (4,4), (28,4), (28,28), (4,28) on a 32x32 target. The two triangles share the (4,4) to (28,28) diagonal and have constant UVs (0.25,0.75) and (0.75,0.25). Reversing triangle order changes 24 diagonal pixels in expected.raw. Comparing against either fixed edge owner gives 576 covered pixels and zero coverage mismatches in both orders, but one order has 48 channels over tolerance. The C++ comparison permits zero at that size. This suggests an independent shared-edge fixture and an explicit edge policy for the color comparison.

@rafaelpssz

Copy link
Copy Markdown
Contributor Author

Thanks @whattheflop, that's a real hole. Fixed in the latest commit:

  • uv_map now also reports the UV-seam pixels. A pixel is reported when its sample lies on an edge (a barycentric weight ≤ 1e-6) of a triangle covering it, and the covering triangles give that sample different UVs. Overlapping interiors still follow draw order (the last one wins, as uv_at and the harness do).
  • expected.raw marks those pixels with alpha -2. The C++ test still checks their coverage, skips their colour, counts them and prints the count, and fails if there are more than 1% of the covered pixels (a seam is an edge, so a large count means the reference is wrong).
  • Your diagonal quad is now test_uv_seam_pixels_are_not_guessed: 32×32, corners (4,4)–(28,28), constant UVs (0.25, 0.75) / (0.75, 0.25). Both draw orders give the same 24 seam pixels and 576 covered, and every other pixel is identical between the two orders.

On the real model there are 0 seam pixels (its UVs are continuous across shared edges), and the RTX 3060 result is unchanged: 12,804 compared, worst 0.00028, 0 over.

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted CPU re-review of 949923188ef33ece57b0c348214c444e76592a0b with uv CPython 3.12.13. The stock suite had 9 passes and 3 package-gated skips. The diagonal quad writes identical expected.raw bytes in both orders (24 marked samples, 576 covered), and the C++ loop checks coverage before the alpha -2 color exemption. An independent interior-overlap fixture confirmed that the later triangle still wins at all 18 overlapping samples.

An earlier edge can exempt the color of a later triangle whose interior covers the pixel. uv_map omits the first hit when it is an interior, but records it when it is an edge. It then treats any recorded edge with a differing UV as ambiguous, even when a later interior fixes the color.

I verified this on a 128x128 target. In framebuffer coordinates, the outer triangle is (8,8), (104,8), (8,103) at UV (0.25,0.75), and the inner triangle is (24.5,20), (56,20), (24.5,68) at UV (0.75,0.25). Outer-then-inner writes zero seam markers. Inner-then-outer marks 48 samples along x = 24.5, even though the outer triangle wins every one of them regardless of edge inclusion. Against the independent solid-outer reference, all 4,560 covered samples agree in coverage and all compared channels are within tolerance, yet applying the C++ limits on CPU rejects it because 48 exceeds the seam cap of 45. Shortening the edge to y = 36 leaves 16 exemptions below the cap and hides a deliberate UV swap at those pixels.

One way to preserve the existing seam intent is to examine hits from latest to earliest, retain the possible edge winners, and stop at the first strict-interior hit. Any older hit is hidden by that interior.

@rafaelpssz

Copy link
Copy Markdown
Contributor Author

Right again, thanks. With the nested triangles, an earlier edge exempted a pixel that a later interior owns. That leaves room for a real error to hide, as your y = 36 variant showed. Fixed in the latest commit, starting from your suggestion:

  • Walk from the latest hit back to the first strict-interior hit. That interior owns the sample and hides everything older.
  • Edge hits after that interior are the candidates. If there are two or more and they share one UV, it's an edge both triangles share, and the tie-break gives the sample to exactly one of them, so that UV is the colour's: not ambiguous. Otherwise the pixel is ambiguous when the candidates' UVs differ. That covers a UV seam, and a lone edge over an older interior with another UV.

I needed the shared-edge step because without it the real model regressed. The first-light dome is flattened, so its front layer is drawn over its back layer, and the front layer's internal edges over back-layer interiors marked 188 pixels (over the 1% cap). With it, 0 are marked and all 12,804 are compared. The RTX 3060 result is unchanged: worst 0.00028, 0 over.

Tests (14 run, 3 package-gated skips):

  • The diagonal seam: 24 ambiguous samples in both draw orders, everything else identical.
  • Your nested triangles, inner-then-outer: no ambiguous samples, and the image equals the solid-outer reference.
  • Outer-then-inner: exactly the 48 samples on the inner's left edge, column 24, are ambiguous. The inner is drawn last and owns those samples or not depending on the edge rule, so they really are undetermined.
  • New: a front quad (shared diagonal, continuous UVs) over an older back triangle. Its diagonal samples aren't ambiguous; its outer edge over the back triangle is.

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted CPU retest of df58e8c672a4aa5339d1713a62370adb1fe801f4. The earlier concern is fixed. With the outer interior drawn last, both fixtures have zero exemptions and compare all 4,560 covered pixels. The deliberate UV swap now counts 32 wrong channels in the short fixture and 96 in the long one. With the inner edge drawn last, the masks have 16 and 48 samples respectively.

One remaining assumption in the new shortcut is that two later edge hits with equal UVs guarantee that one of them covers the sample. The Vulkan rule guarantees one owner for polygons on opposite sides of a common edge with identical endpoints. Equal UVs alone do not establish that geometry. uv_map shortcut

On the same 128x128 outer triangle at UV (0.25,0.75), I drew two front triangles at UV (0.75,0.25), with framebuffer vertices [(16,20),(32.5,20),(32.5,52)] and [(12,16),(32.5,16),(32.5,56)]. Their right edges overlap for 32 sample centers and both interiors lie to the left. A top-left reference excludes both right edges, so the older triangle supplies all 32 colors. The generated expected.raw compares the front color there in either front draw order. The CPU reproduction of the C++ checks gives zero coverage mismatches, 8 exemptions (cap 45), and 64 channels over tolerance (cap 4). Top-left rule

This is reachable with valid overlapping projected triangles and a top-left rasterizer. I verified it with synthetic geometry and a CPU reference. Whether the packaged dome has this configuration remains unverified.

@rafaelpssz

Copy link
Copy Markdown
Contributor Author

Agreed: equal UVs don't establish a shared edge. Fixed in the latest commit.

  • Each edge hit now records which edge it's on (its two endpoint positions) and which side of it the triangle's third vertex lies.
  • The shortcut needs a pair among the later edge hits on the same edge with identical endpoints and opposite sides, the case the rule guarantees one owner for, and still needs all of those hits to give one UV.
  • A sample on a vertex (two zero weights) never takes the shortcut.

Your overlapping right edges (different endpoints, same side) are now test_overlapping_edges_on_the_same_side_are_ambiguous. In both front draw orders, all 32 samples in column 32 are ambiguous, so their colour isn't asserted. 15 tests run, with 3 package-gated skips, and the earlier fixtures are unchanged.

On the real dome this marks 8 samples (vertices, or edges without a geometric partner) and compares the other 12,796. The RTX 3060 result is unchanged: worst 0.00028, 0 over, 0 coverage mismatches.

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted CPU retest on 700a478b3e09dece0f96d5650ecb09f0d1da5417 closes my prior same-side-edge finding. In both front draw orders, the generated expected.raw marks all 32 samples that previously expected the wrong color. Applying the C++ checks to the independent top-left reference now passes with 4,560 covered, 4,520 compared, 40 exemptions (cap 45), and zero coverage or color errors. In the continuous-UV shared-edge control, all 31 non-vertex diagonal samples still compare at the analytic UV in both orders, and the corner vertex over the older interior stays marked. Stock suite under uv Python 3.12.13: 12 passed, 3 package-gated skips.

@JRamos1993

JRamos1993 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested 700a478 merged onto main 1628210 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 131/131.
  • d3d12_first_light_textured and d3d12_m2_textured: pass 20 of 20 runs, and pass under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • One new MSVC warning: C4996 at runtime/test/d3d12_first_light_textured_test.cpp:63 ('getenv': ... Consider using _dupenv_s instead). runtime/test/pe_loader_test.cpp already reads its environment through _dupenv_s; doing the same here would keep the build quiet.

AI-assisted (Claude Code).

@rafaelpssz

Copy link
Copy Markdown
Contributor Author

Thanks @JRamos1993, the RTX 5090 runs are a big help (and the 20/20 repeat runs).

Fixed the C4996 in the latest commit. The test now reads LEONIDA_FIRST_LIGHT_TEX_DIR with _dupenv_s, as pe_loader_test does. It still exits 77 with SKIP when the variable is unset, and the RTX 3060 result is unchanged.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51):

No problems found. ctest on the RTX 4080 SUPER: 130/130 passed (including the new textured first-light and m2 textured tests). Intel UHD 770 ctest: only the two known base failures, d3d12_descriptor (fixed by #2948) and d3d12_subgroup (fixed by #2934). The new textured tests pass on Intel too.

@rafaelpssz

Copy link
Copy Markdown
Contributor Author

Thanks @kapitche, the Intel UHD 770 run is the first non-NVIDIA result for both textured tests. It also confirms that the literal-S# path (#2887) and the bindless lookup behave the same on a second vendor. Noted that the two Intel failures are the known base ones (#2948, #2934).

@zzEmmazz

Copy link
Copy Markdown
Contributor

Tested 700a478b and the current head 22c3f812, applied alone on main 16282101: pass.
Windows 11 (26200), MSVC 14.50 (VS 2026), Ninja RelWithDebInfo. Two GPUs: Ryzen 7 9700X iGPU (RDNA2, AMD 32.0.21042.62) and RTX 3070 (NVIDIA 610.74), picked with LEONIDA_VK_DEVICE.

Inputs came from my own copy of the 1.0.2.1 package (all 108 files match game/xbox-1.0.2.1.json), not from yours:

  • rpf9dump models data.rpf exported 3,175 models. Exactly one OBJ has SHA-256 a7178cf4…d6b9: 4,213 vertices, 7,968 triangles, as docs/first_light.md says.
  • first_light.py --obj <model> --no-fit --vs VS_main_170e32e6_Wrapped --ps '$PS_PassthroughCopy_1a08fc46_Wrapped' --texture ramp wrote a manifest with VS FSSM 128867d3…77f4, PS FSSM 90fb6271…d138, expected_covered 12,804 and expected_ambiguous 8. The PS index entry has literal_samplers [[0x92, 0xC00000, 0x14500000, 0]].

d3d12_first_light_textured (the same numbers and the same image bytes at 700a478b and 22c3f812; at 700a478b also under LEONIDA_VK_VALIDATION=1, with no validation errors):

GPU covered compared worst error mean error channels over 0.002 coverage mismatches on a UV seam
RTX 3060, from the PR 12,804 / 16,384 12,796 0.00028 0.000045 0 0 8
RTX 3070 12,804 / 16,384 12,796 0.00028 0.000045 0 0 8
Ryzen iGPU (RDNA2, AMD driver) 12,804 / 16,384 12,796 0.00077 0.000074 0 0 8
either GPU, without the d3d12_vulkan_device.cpp change 12,804 / 16,384 12,796 0.00781 0.001949 19,041 (fails at line 386) 0 8
  • The AMD driver's worst error is 2.7 times NVIDIA's and still under half the 0.002 tolerance. Between the two GPUs' d3d12_textured.raw, 6,990 of 16,384 pixels are bit-identical and the largest channel difference is 0.000488, one f16 step.
  • Without the layer change, d3d12_m2_textured also fails on both GPUs, at line 189 (bindless_hash_lookup(device.p, key) != 0). With it, it passes on both.
  • d3d12_first_light (the untextured pair) against vk_harness's image: iGPU 16,384 of 16,384 bit-exact; RTX 3070 16,383 bit-exact and 1 one f16 step apart.
  • ctest -R "^(d3d12_|shader_library$)" with the PR: 55 of 55 pass on each GPU (d3d12_rgb9e5_rtv skips on the RTX 3070).
  • tests/test_first_light.py: with only the test file applied, the 8 TexturedOracleTests error (first_light has no ramp_texture / uv_map). With the PR, 15 run, 12 pass and 3 skip; with LEONIDA_FIRST_LIGHT_DIR set, 15 of 15 pass on each GPU.
  • 22c3f812 builds d3d12_first_light_textured_test.cpp without C4996, and the test still prints SKIP and exits 77 when the variable is unset.

One thing read, not measured: the comment at d3d12_first_light_textured_test.cpp:338 says d3d12_textured.raw is for first_light.py --check-textured, and the tool has no such option.

Not checked: the census figures (780 and 148), and main f847748c, where the PR now conflicts in docs/design.md, runtime/src/shader_library.h and tests/test_first_light.py.

@rafaelpssz

Copy link
Copy Markdown
Contributor Author

Thanks @zzEmmazz, this is the most complete check this PR has had. You rebuilt the inputs from your own copy, and that copy matches every hash. It is also the first AMD (RDNA2) run of both textured tests: a 0.00077 worst error on the iGPU, which stays under half the tolerance, and one f16 step between the two GPUs' images. The red run without the layer change also fails on both of your GPUs.

  • The stale comment: you're right that there's no --check-textured. The comment now says the file is written so one GPU's image can be compared with another's byte for byte, and that nothing in the repository reads it.
  • The conflicts with f847748c: I resolved all three, keeping f16_halves next to literal_samplers, the ReadObjTests next to TexturedOracleTests, and the newer design.md row. That build is green here. It goes up together with this fix once my fork is synced, since main touched a workflow file.

@rafaelpssz

Copy link
Copy Markdown
Contributor Author

Note: TEST-524 belongs to @al3xar (#2806, claimed first). I have proposed in #3574 that this PR become the D3D12-layer follow-up of #2806 and be rebased onto it once it lands: #3574

@nschlaepfer

Copy link
Copy Markdown
Contributor

Independent hardware verification of @rafaelpssz’s textured first-light test at b7c1406, using the documented model and synthetic coordinate ramp.

  • On Windows 11 with an RTX 5090 (driver 621.14), the PR’s D3D12 test covered 12,804 of 16,384 pixels. Coverage matched the CPU reference everywhere. Of the 12,796 covered pixels used for the color check, zero channels exceeded 0.002. The maximum error was 0.00028. The comparison excluded eight UV seam pixels from color checks.
  • On an M3 Max I independently rebuilt the fixture from the verified 1.0.2.1 package. A native MoltenVK harness explicitly bound the same texture and sampler. Coverage was identical to Windows, all 12,796 comparable pixels passed the CPU check, and the largest Mac-to-Windows channel difference was 0.00048828125. This Mac run exercises translated shader sampling through a Vulkan harness. The Windows run exercises the PR’s D3D12 path.
  • As a sensitivity check, using point sampling on Mac preserved the silhouette but produced 19,041 channels over tolerance. Removing the literal sampler record on a private Windows fixture also produced 19,041 failing channels.

AI-assisted verification. Only aggregate measurements are included.

@rafaelpssz

Copy link
Copy Markdown
Contributor Author

Thanks @nschlaepfer. The RTX 5090 run matches mine to the digit, and the M3 Max run through MoltenVK is the first Apple result for this path: the same coverage, all 12,796 pixels pass, and the largest Mac-to-Windows difference is one f16 step. Your sensitivity check is a strong confirmation too: point sampling on the Mac and the missing literal-sampler record on Windows both give the same 19,041 failing channels, which is what this test measures for #2887.

@rafaelpssz
rafaelpssz force-pushed the test/first-light-textured branch from b7c1406 to a6effdf Compare November 22, 2026 22:24
@rafaelpssz

Copy link
Copy Markdown
Contributor Author

Rebased onto main, which now has @al3xar's TEST-524 first_light.py (7e1aecf0). The two paths now live side by side, and none of the measured results changed:

  • --dds (First light: add textured draw path with T#/S# bindless set and CPU oracle (TEST-524) #2806, harness path) and --texture ramp (this PR, D3D12 layer) are separate options.
  • docs/first_light.md: their section stays §6, and this one becomes §7, "With a texture, through the D3D12 layer". Limits move to §8, and the real-albedo bullet is dropped since §6 covers it.
  • This PR's oracle tests are renamed LayerTexturedOracleTests so they don't clash with theirs.

RTX 3060: d3d12_first_light_textured still gives 12,796 compared, worst 0.00028, 0 over. d3d12_first_light, d3d12_m2_textured, d3d12_descriptor and shader_library pass. tests/test_first_light.py is OK, with the package-gated tests skipped.

@zzEmmazz

Copy link
Copy Markdown
Contributor

Tested a6effdfb (on main aa2988cc): one finding.
Windows 11 (26200), MSVC 14.50 (VS 2026), Ninja RelWithDebInfo. Two GPUs: Ryzen 7 9700X iGPU (RDNA2, AMD 32.0.21042.62) and RTX 3070 (NVIDIA 610.74), picked with LEONIDA_VK_DEVICE.

The draws pass on both GPUs after the rebase, with the same numbers as before it. The finding is in the tool that writes their inputs.

Finding: first_light.py --texture ramp exits 1 since the rebase.

  • The §7 command ends with TypeError: string indices must be integers, not 'str' at tools/first_light.py:312 (harness_env), exit code 1, both without and with --run.
  • write_textured_inputs returns "texture": "ramp" (line 493) and main merges it into the manifest (line 901). harness_env, which came in with 7e1aecf0, reads manifest["texture"] as the --dds dict (tex["ptr_sgpr"]). manifest["files"]["texture"] is shared the same way (line 902 against line 885). The pre-rebase head 22c3f812 had no harness_env, so the key was harmless there.
  • All nine files are written before the exception, so the ctest does not see it: the results below come from that folder. The runs without and with --run wrote identical manifest.json, index.json, mesh.bin, vs.spv, ps.spv, texture.bin and expected.raw.
  • It reproduces without game files: harness_env on a manifest updated from write_textured_inputs(...) raises the same error. No unit test calls main with --texture.
  • Same cause: with LEONIDA_FIRST_LIGHT_DIR pointing at a --texture ramp folder, tests/test_first_light.py gives 2 errors in 27 (test_draw_matches_the_manifest, test_check_cli_matches_the_oracle).

Measured

Inputs were rebuilt at this head from my own copy of the 1.0.2.1 package: the OBJ with SHA-256 a7178cf4…d6b9 (4,213 vertices, 7,968 triangles), VS FSSM 128867d3…77f4, PS FSSM 90fb6271…d138, expected_covered 12,804, expected_ambiguous 8, literal_samplers [[0x92, 0xC00000, 0x14500000, 0]], texture.bin SHA-256 d6ec440c…2d4f.

d3d12_first_light_textured:

GPU covered compared worst error mean error channels over 0.002 coverage mismatches on a UV seam validation errors
Ryzen iGPU (RDNA2, AMD driver) 12,804 / 16,384 12,796 0.00077 0.000074 0 0 8 0
RTX 3070 12,804 / 16,384 12,796 0.00028 0.000045 0 0 8 0
either GPU, 41a64893 reverted 12,804 / 16,384 12,796 0.00781 0.001949 19,041 in 11,938 pixels (fails at line 394) 0 8 not run
  • The validation column is a second run with LEONIDA_VK_VALIDATION=1 (the log says "validation on"); it wrote the same image bytes as the first run on each GPU.
  • Between the two GPUs' d3d12_textured.raw, 6,990 of 16,384 pixels are bit-identical and the largest channel difference is 0.000488, one f16 step.
  • Without 41a64893 I get 19,041 channels over on both GPUs; docs/first_light.md §7 and the description say 18,616.
  • d3d12_first_light against vk_harness's image: iGPU 16,384 of 16,384 bit-exact; RTX 3070 16,383 bit-exact and 1 one f16 step apart. d3d12_m2_textured, d3d12_descriptor and shader_library pass on both GPUs.
  • Both stages are 64-wide. On the RTX 3070 (subgroup 32..32) the layer logs for each that it runs at the device's size; on the iGPU (32..64) it logs nothing. The numbers above are with that.
  • tests/test_first_light.py: without the package 27 run, 24 pass, 3 skip. With LEONIDA_FIRST_LIGHT_DIR on the untextured folder, 27 of 27 pass on each GPU.
  • The build has no errors and no warning from d3d12_first_light_textured_test.cpp.

Read, not measured

  • docs/first_light.md §7: the command has no --out, and the next line reads first_light/out_tex. Without --out the tool writes to first_light/out, the folder of §3 and §5.
  • runtime/shims/d3d12_vulkan_device.cpp:2306: pick_entry's comment now sits above register_literal_samplers (from d3d12: a pipeline registers its shaders' literal S#s (they sampled through the fallback) #2887).
  • runtime/shims/d3d12_vulkan_device.cpp:2316: the message ends in "words" and logs the number of literal samplers.
  • docs/design.md, Literal samplers: "0.00049 once registered"; §7 says 0.00028, and the iGPU gives 0.00077.

Not checked: the census figures (780 and 148), the --dds path of §6, and the rest of ctest. GitHub reports the PR as mergeable.

AI-assisted; measured on my PC.

@rafaelpssz

Copy link
Copy Markdown
Contributor 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.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested 1756292 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$" (the test this PR touches): package-gated, so SKIPPED on both GPUs (no game package here); the new textured draw was not exercised at this head. No game files.

AI-assisted.

@Ayinaki

Ayinaki commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 1756292 on RTX 5070, driver 616.86, Windows 10.0.26200: pass.

Built runtime (MSVC 14.52, Visual Studio 18 2026, x64, RelWithDebInfo) and produced the test's inputs from this head's own tools/first_light.py, outside the package folder:

  • shader_carve.py over the package's shaders.rpf (26,503 shaders carved), then tools/first_light.py --texture ramp --vs VS_main_170e32e6_Wrapped --ps '$PS_PassthroughCopy_1a08fc46_Wrapped' on an OBJ exported with rpf9dump models from data.rpf (881 vertices, 424 triangles), 128x128.
  • LEONIDA_FIRST_LIGHT_TEX_DIR=<that out dir> ./runtime/build/RelWithDebInfo/d3d12_first_light_textured_test exits 0:
device: NVIDIA GeForce RTX 5070
covered 2615/16384; 2615 pixels compared with the CPU reference: worst 0.00031, mean 0.000040,
0 channels over 0.00200; 0 coverage mismatches; 0 on a UV seam (colour not compared)
first light with a texture: the game's VS + texture-sampling PS drew 424 triangles

So the ramp oracle holds through the layer's CopyTextureRegion + CreateShaderResourceView path on this GPU: every covered pixel is within 0.00031 of expected.raw against the 0.002 tolerance, with no coverage mismatch and no over-tolerance channel.

@rafaelpssz

Copy link
Copy Markdown
Contributor Author

Thanks @Ayinaki. That's the first run of the textured draw on another package copy and another model: 424 triangles, worst 0.00031, nothing over tolerance and no coverage mismatch. Exactly what the gate is meant to show on a different machine. You're in Thanks.

rafaelpssz and others added 8 commits November 23, 2026 12:23
…ples a T# (TEST-524)

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 ItsNotRexed#2887.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d reference

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

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

Copy link
Copy Markdown
Contributor Author

Rebased onto main 1cc6e3c1, after rounds 43/44 (#2887 has landed, so this PR now sits directly on main). The camera section that landed in docs/first_light.md (§7) moves this stack's sections: §8 is the layer path, §9 the formats and §10 Limits. test_first_light.py passes: 52 here, 58 on #4251.

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.

8 participants