Skip to content

tools: a native-D3D12 golden-image conformance harness for the Vulkan device - #3343

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
biglill:conformance-only
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
biglill:conformance-only

Conversation

@biglill

@biglill biglill commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Why

runtime/test/ covers the shim's device, resources, views, samplers, copies, clears, barriers and tiling — several of them against the host runtime, which is the right pattern (d3d12_copy_compare.h, d3d12_depth24_compare.h).

What nothing covers is the end of the chain: that a draw produces the same pixels D3D12 would. Until the first frame lands (#335), a rendering regression has nothing to fail against.

This adds the reference half of that check: a small, deterministic scene set, a native D3D12 renderer that produces the golden images, and a tool that checks a render against them. When the draw path arrives, the shim runs the same scenes and the two image sets are diffed.

What

spec/scenes.h — seven scenes: clear, fullscreen, depth_order, scissor, blend, indexed. Each names the exact pixels it must produce, so a mismatch is a coordinate, not an opinion.

The header also states the baseline pipeline state every scene inherits — cull mode, topology, sample mask, render-target write mask, viewport, scissor convention, clip-space z range and row order. That is deliberate: two implementers guessing differently produce two different images and neither is wrong on its own terms.

Two scenes are shaped by a specific failure:

  • depth_order draws the near quad first and the far quad second. The overlap stays green only if the depth test rejects the later draw. Drawing them in reach order would have let a shim with no depth test pass.
  • indexed stores its vertices out of draw order and addresses them with a non-identity index list, so a program that ignores the index buffer draws visibly different triangles.

native/ — renders all seven with D3D12 and WIC, no third-party code. It reads every declared pixel back from both the GPU and the PNG decoded off disk, prints one line per check with scene, coordinate, expected and actual, and exits non-zero on any mismatch.

compare.py — standard library only. expect checks a render against the contract; diff compares two renders and writes a heatmap; selftest proves the PNG reader and the metrics without external files.

native/scripts/negative-control.ps1 — the part that makes the scenes trustworthy: it disables the depth test, the blend state and the scissor rect in a throwaway copy and requires exactly depth_order, blend and scissor to fail, each at the pixel that names that state. It throws when a String.Replace stops matching, so a silenced edit cannot pass as evidence.

Evidence

native      readback 18 passed, 0 failed   png 18 passed, 0 failed   RESULT: PASS   exit 0
expect      6 scenes, 18 checks: 18 passed, 0 failed                                 exit 0
selftest    passed                                                                   exit 0
negative    NEGATIVE CONTROL PASSED: exactly blend, depth_order, scissor failed

Measured on an RTX 5070 Ti and on the AMD Radeon iGPU, 18/18 on both. Determinism verified by SHA-256 across two runs.

Against the shim today

The shim-side driver is not in this PR — it currently only reports blocked calls. Measured at 2e5c0f2:

clear          OK       3/3 pixel checks matched (row pitch 1024, readback 262144 bytes)
fullscreen     BLOCKED  ID3D12Device::CreateRootSignature (E_NOTIMPL 0x80004001)
depth_order    BLOCKED  ID3D12Device::CreateRootSignature (E_NOTIMPL 0x80004001)
scissor        BLOCKED  ID3D12Device::CreateRootSignature (E_NOTIMPL 0x80004001)
blend          BLOCKED  ID3D12Device::CreateRootSignature (E_NOTIMPL 0x80004001)
indexed        BLOCKED  ID3D12Device::CreateRootSignature (E_NOTIMPL 0x80004001)

clear already proves the full resource → clear → barrier → copy → readback chain on the Vulkan device. The five drawn scenes then become progress markers, in this order: CreateRootSignature → CreateGraphicsPipelineState → the SetPipelineState / root-binding group → viewport and scissor → vertex/index buffers → OMSetRenderTargets → DrawInstanced / DrawIndexedInstanced. I can add the driver here if it is wanted before the draw path exists.

Relationship to open work

Two things worth knowing before review

  • The shader format is a fork in the road. The reference renderer compiles HLSL to DXIL, because native D3D12 requires it. The shim's contract is SPIR-V, because the game's shaders arrive from the RDNA2 translator. When the draw path lands, the cheapest resolution is to compile each conformance shader twice (dxc -T vs_6_6 and dxc -spirv -T vs_6_6) and let each renderer take the blob it wants — one workload, one set of expected pixels, no DXIL translator in the shim.
  • This is not in CI, and should not be yet. It needs a real D3D12 device; root_signature_oracle_test is Windows-only for the same reason. It runs in about two seconds on hardware and on the Basic Render Driver.

Not in this PR

No draw path, no shim changes, no game data, no keys. D:\Leonida was not modified to produce this.

… device

The shim reimplements D3D12 on Vulkan. runtime/test/ covers the device, resources,
views, copies, clears and barriers, but nothing checks that a *draw* produces the
same pixels as the host's D3D12. This adds the reference half of that check.

Seven deterministic scenes (clear, fullscreen, depth_order, scissor, blend, indexed),
each naming the exact pixels it must produce, so a mismatch is a coordinate rather
than 'the picture looks off'. tools/conformance/spec/scenes.h states the baseline
pipeline state every scene inherits - cull mode, topology, sample mask, viewport,
scissor convention, clip-space z range, row order - because two implementers
guessing differently produce two different images and neither is wrong on its own
terms.

native/ renders all seven with D3D12 and WIC, reads every pixel back from both the
GPU and the PNG on disk, and exits non-zero on any mismatch: 18 checks, 18 passes, on
an RTX 5070 Ti and on the AMD iGPU. compare.py (standard library only) checks a
render against the contract and diffs two renders with a heatmap.

The scenes are proven non-vacuous by scripts/negative-control.ps1: it disables the
depth test, the blend state and the scissor rect in a throwaway copy and requires
exactly depth_order, blend and scissor to fail at the pixels that name that state.
The script throws when a replacement stops matching, so a silenced edit cannot pass.

Against the shim at 2e5c0f2 the same scenes report clear OK and the five drawn scenes
BLOCKED at ID3D12Device::CreateRootSignature (E_NOTIMPL), which is the order the draw
path has to arrive in.

No game data is read, nothing is downloaded, and the harness is not part of CI: it
needs a D3D12 device, like root_signature_oracle_test.
@biglill

biglill commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Cross-reference: #3340 (root signature oracle coverage) is the test-side half. #3343 does not depend on it, but a first draw will exercise both.

@whattheflop

Copy link
Copy Markdown
Contributor

Independent verification (AI-assisted) of open head df6188194aa14d4129f47b489a86c52b9d0f91d0.

  • Built the stock x64 Release conform_native target from that commit with VS 2022/MSVC 19.38 and Windows SDK 10.0.26100.0. Ran it headlessly twice against the Microsoft Basic Render Driver (WARP, d3d10warp.dll 10.0.26100.9818, Windows build 26200), each time into a fresh directory. Both runs exited 0 with 18/18 native readback checks and 18/18 WIC-decoded PNG checks.
  • With uv-managed Python 3.12.13, compare.py selftest passed, expect passed 18/18 on each run, and strict diff found zero differing pixels in all six 256×256 images. The six PNGs and manifest.json matched byte for byte and by SHA-256 across the two fresh destinations.
  • There are six scenes in the source table and generated manifest: clear, fullscreen, depth_order, scissor, blend, and indexed. The PR description and top-level conformance README say seven.
  • This head adds the native reference renderer, scene spec and CPU comparison tool under tools/conformance/. The README’s shim-driver status is historical. The base already contains d3d12_draw pixel-readback coverage, d3d12_bundle host/WARP and shim grid checks, and d3d12_m3_frame synthetic frame coverage. The run here covers the new native reference and CPU comparison only. Shim/runtime tests and Vulkan submissions were outside this run.

I checked the active coordination tracker (#3232), the D3D12 tracker (#313), and the PR discussion. #3232 lists #3343 for CPU review. I found no matching claim or duplicate verification.

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Reviewed and tested df618819 on Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), AMD Radeon RX 9070 XT (AMD 26.11.2), Python 3.12.10: changes suggested.

run result
python -m compileall -q make_game.py tools tests clean
python tools/conformance/compare.py selftest passed (21 ok lines, exit 0)
other repo tests none cover tools/conformance/; the native tool was not built

Review: I read compare.py (the selftest bodies only skimmed), spec/scenes.h, both HLSL files, CMakeLists.txt, the four scripts, and these renderer sources: main.cpp, scene_plan.cpp, verify.cpp, and the pipeline, clear and draw code in renderer.cpp. I did not build the native tool. From a temp copy, compare.py --help works and compare.py selftest passes (21 ok lines, exit 0). I mapped the depth_order and indexed check pixels to NDC at pixel centres, and did the scissor and blend arithmetic by hand. Those checks catch the failures the header names, except the indexed gap pixel (item 4). Main has no tools/conformance/, and no other open PR adds one. I agree with the earlier comment that there are six scenes, not seven (PR description, tools/conformance/README.md:24). Five problems:

  1. tools/conformance/compare.py:1839 calls traceback.print_exc(), but traceback is never imported (imports are at lines 16-26). Any unexpected exception therefore raises NameError inside the handler, and Python exits 1. That is the code for "pixels differ". main's docstring (lines 1826-1830) and COMPARE.md:393 both promise exit 2. Ran: a manifest.json holding 200000 nested [, passed to expect --manifest, raises RecursionError, then NameError: name 'traceback' is not defined, exit 1. Expected: a traceback and exit 2. Fix: import traceback.
  2. tools/conformance/native/scripts/negative-control.ps1:22-24,39 copies CMakeLists.txt and src/ into native/negative-control/ and configures from there. CMakeLists.txt:5 defaults CONFORM_SPEC_DIR to ${CMAKE_CURRENT_SOURCE_DIR}/../spec. From the copy that resolves to native/spec, and the head has no such directory (the spec is tools/conformance/spec). So configure should stop at the FATAL_ERROR at CMakeLists.txt:11-14, and the script then prints BUILD FAILED and exits 1. If so, the NEGATIVE CONTROL PASSED evidence in the description and native/README.md:151-162 cannot be reproduced at this head. Found by reading only; I did not build. Fix: pass -DCONFORM_SPEC_DIR=<tools/conformance/spec> on line 39 and check the configure exit code.
  3. tools/conformance/native/scripts/verify.ps1:41,76 requires adapter 0 to be named AMD Radeon and the default adapter to be RTX 5070 Ti. On any other machine the script reports BROKEN and exits 1, even when every render check passes. native/README.md:320 presents it as re-checking the README's claims, so the adapter names should come from parameters, or those two checks should be dropped.
  4. tools/conformance/spec/scenes.h:238: the indexed check at (128,240) says "the gap between the two triangles stays clear", but row 240 is NDC y ≈ -0.88. Both triangles end at y = -0.6 (about row 205), so the pixel is below them, not between them. It cannot catch a filled gap. Example: drawing the vertex buffer without indices produces triangle 3,4,5, which covers (128,200) but leaves (128,240) clear. Use (128,200), or another pixel between x 116 and 140 above row 204, if the gap is meant to be tested.
  5. The status sections are stale against current main (aa2988cc). tools/conformance/README.md:4-5,59-77 and the PR's "Against the shim today" say the shim stops at CreateRootSignature with E_NOTIMPL and that nothing checks draw pixels. On main, runtime/shims/d3d12_vulkan_device.cpp:4854 parses RTS0 blobs. runtime/test/d3d12_draw_test.cpp already records indexed draws through the Vulkan device, with a root CBV tint, culling and blends, and compares the readback pixel by pixel. Please re-measure the five drawn scenes against main, or drop the table.

AI-assisted (Claude Code); I checked the results.

@thirteenhustler

Copy link
Copy Markdown

Tested df61881 on Linux 6.12.113+, Python 3.12.3 (no GPU, no game data): compare.py selftest passes; changes suggested. The native renderer was not built.

Ran: python -m compileall -q make_game.py tools/conformance/compare.py tools tests; python -I tools/conformance/compare.py selftest → 21 ok lines, exit 0.

  1. tools/conformance/compare.py:1839 calls traceback.print_exc(), and traceback is not imported (:16-26). main's docstring (:1826-1830) and COMPARE.md:327 promise exit 2 for an unexpected failure. A manifest.json of 20000 nested [ passed to expect --manifest raises RecursionError, then NameError, and the process exits 1. Add import traceback.
  2. tools/conformance/native/scripts/negative-control.ps1:22-39 configures a copy of native/. CMakeLists.txt:5 defaults CONFORM_SPEC_DIR to ${CMAKE_CURRENT_SOURCE_DIR}/../spec, which from that copy is native/spec. The spec is tools/conformance/spec, so configure hits the FATAL_ERROR at CMakeLists.txt:11-14. The script then reports BUILD FAILED (negative-control.ps1:41) and exits 1. Found by reading; not executed. Pass -DCONFORM_SPEC_DIR to the spec directory.
  3. tools/conformance/spec/scenes.h:238: the indexed check at (128, 240) says the gap between the triangles stays clear. That pixel is NDC y ≈ -0.879. Both triangles end at y = -0.6 (about row 204), so it is below them. Drawing the vertex buffer in order (triangles 0,1,2 and 3,4,5) also leaves (128, 240) clear. (128, 128) and (128, 200) are in the gap and are covered by those wrong triangles. (80, 200) still fails an ignored index buffer on colour: the interpolated value there is about (202, 185, 78), not gold (240, 200, 40).
  4. tools/conformance/README.md:24 says seven scenes. kScenes has six: clear, fullscreen, depth_order, scissor, blend, indexed. verify.ps1:77 already expects 6.
  5. tools/conformance/README.md:4-5 and :61-69 say nothing checks draw pixels and that every drawn scene stops at CreateRootSignature with E_NOTIMPL. On this commit CreateRootSignature (runtime/shims/d3d12_vulkan_device.cpp:4662) parses an RTS0 blob, and runtime/test/d3d12_draw_test.cpp already compares indexed-draw readback pixels. The status table should be re-measured or removed.

tools/conformance/native/scripts/verify.ps1:41 and :76 also require adapter 0 to be named AMD Radeon and the default adapter to be RTX 5070 Ti, so the script exits 1 on any other machine even when the pixel checks pass.

@ItsNotRexed
ItsNotRexed merged commit f73164d into ItsNotRexed:main Nov 23, 2026
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.

5 participants