[PR #1930] runtime/d3d12: the --bary-fallback geometry stage feeds computed I/J pairs (RT-BARY-FALLBACK-PER-VERTEX) #1938

Open
opened 2026-11-26 21:19:28 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1930
Author: @mrgenty
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: rt-bary-fallback-per-vertex


📝 Commits (7)

  • e7987db Translate computed I/J pairs when a GPU has no per-vertex inputs.
  • b9191a3 Merge remote-tracking branch 'origin/main' into fix/computed-ij-no-pervertex
  • 53df7d1 runtime/d3d12: synthesize --bary-fallback geometry shader in graphics PSOs
  • d36d9ef Merge #1497 into rt-bary-fallback-per-vertex
  • 52d6df8 Merge #1426 into rt-bary-fallback-per-vertex
  • 682de28 runtime/d3d12: the --bary-fallback geometry stage feeds computed I/J pairs (RT-BARY-FALLBACK-PER-VERTEX)
  • 0b75329 runtime/d3d12: computed I/J reads only the VS's raw outputs after f16 linking (RT-BARY-FALLBACK-PER-VERTEX)

📊 Changes

24 files changed (+2879 additions, -108 deletions)

View changed files

📝 docs/design.md (+2 -2)
📝 docs/testing.md (+4 -1)
📝 make_game.py (+22 -4)
📝 runtime/CMakeLists.txt (+10 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+95 -10)
📝 runtime/src/shader_library.h (+34 -0)
➕ runtime/src/spirv_bary_fallback.h (+551 -0)
📝 runtime/src/spirv_f16_halves.h (+16 -3)
➕ runtime/test/d3d12_bary_fallback_test.cpp (+1000 -0)
📝 runtime/test/shader_library_test.cpp (+86 -0)
📝 runtime/test/shaders/build.py (+9 -7)
📝 runtime/test/shaders/check.py (+5 -4)
➕ runtime/test/spirv_bary_fallback_test.cpp (+715 -0)
📝 runtime/test/vk_test_device.h (+2 -0)
📝 scripts/run_gpu_tests.py (+6 -5)
📝 tests/semantic/support.py (+4 -2)
📝 tests/semantic/test_interp_computed_ij.py (+153 -14)
📝 tests/test_make_game_translator_flags.py (+20 -5)
📝 tests/test_run_gpu_tests.py (+21 -18)
📝 tests/test_shader_build_fallbacks.py (+22 -14)

...and 4 more files

📄 Description

Claimed in the coordination issue as: RT-BARY-FALLBACK-PER-VERTEX (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167254678)

Depends on: #1497, #1426

What and why

The runtime half of the computed-I/J case of #1285, which #1497 leaves out (finding, confirmed in the reviews of #1497).

With --bary-fallback, #1426 translates a pixel shader that has a computed I/J pair so that the pair's attribute is a Flat vec4[3] input, at the first of three locations the index gives as bary_fallback_input.per_vertex (attribute → first location). #1497's builder reads only bary_fallback_input.location and expects every other PS input to be a vec4, so it refuses such a PS before the draw (PS pass-through Input at Location 0 is not vec4<f32>) and the PSO is never created.

This branch is main + #1497 + #1426 + one commit. Only the last commit, 07d06992, is this pull request; the rest of the diff goes away as those two land. #1426 conflicted with main in one docs/design.md row and I took its side, which is main's text plus its additions.

The commit:

  • runtime/src/shader_library.h: parses per_vertex into ShaderEntry::bary_fallback_per_vertex. Keys and values are exact u32s; one malformed entry drops the whole map, so the builder refuses the array instead of linking part of a mapping.
  • runtime/src/spirv_bary_fallback.h: build_bary_fallback_gs takes the map. For each mapped attribute the PS declares, the geometry stage reads the VS output at the attribute's number and writes the triangle's three values to a Flat vec4[3] output at the first location (element k = vertex k, the same at each of the three vertices it emits), as tools/bary_fallback_gs.py does. The three values are loaded once. An attribute the VS does not export is zero-filled, like an ordinary pass-through input. One GS input per VS location, shared when the PS also reads that location as an ordinary input.
    Refused: a vec4[3] input the map does not name, a mapped location that is not vec4<f32>[3], a block that runs into another PS input or the barycentric location, two attributes at one first location, and a block past the last location. A mapping the PS does not declare is ignored. The six-argument signature stays as a wrapper with an empty map.
  • runtime/shims/d3d12_vulkan_device.cpp: the two call sites (create_graphics and the lazy stage_words) pass the entry's map.
  • docs/design.md: the runtime builder in the "Barycentric fallback" row, with what was checked and what was not.

Tested

Native Windows 11 (build 26300), MSVC 19.44 RelWithDebInfo, Vulkan SDK 1.4.363.0. No game files.

  • ctest -C RelWithDebInfo -R "^(shader_library|spirv_bary_fallback|d3d12_bary_fallback)$": 3/3 pass, and again with LEONIDA_VK_VALIDATION=1; d3d12_bary_fallback also with LEONIDA_LAZY_GRAPHICS=0 and =1 under validation (the test fails on any validation error).
  • spirv_bary_fallback (CPU), five new cases: the block at the attribute's first locations, a relocated block next to ordinary inputs with a shared GS input, two attributes with one zero-filled, an undeclared mapping (module identical to the one built without it), and six refusals that leave the caller's words untouched.
  • spirv-val --target-env vulkan1.2 and vulkan1.3 on all 9 modules spirv_bary_fallback_test --dump-dir writes (the 6 from #1497 and 3 new): 18/18 clean.
  • shader_library, twelve new per_vertex parsing cases (non-numeric, signed and out-of-range keys; negative, fractional, string and overflowing values; two keys for one attribute; an array instead of an object).
  • d3d12_bary_fallback (GPU), new draws 5a–5c through the Xbox-ABI proxy: a VS that gives each vertex a different value, and a PS in the shape #1426 emits that weights the three with its own I/J (0.375, 0.5, 0.125). All 256 pixels match with the block at locations 0..2 and with it relocated to 4..6 next to an ordinary input; the barycentric channel is still the perspective-correct one. The same weights on any other order of the three vertices would be at least 15 LSB away (the test asserts that margin). The same PS with no per_vertex in its index entry is refused with E_FAIL.
  • python -I scripts/check_no_game_data.py on the touched files, tests/test_bary_fallback_gs.py, tests/test_ctest_registration.py, tests/test_docs_links.py, tests/test_docs_table_rows.py, git diff --check.

Not tested:

  • The game's 207 computed-I/J pixel shaders through this builder: the tests use hand-built SPIR-V in the same shape, not translated shaders. No retail run.
  • A GPU that needs the fallback (RX 5700 XT, Pascal). The RTX 3060 has fragmentShaderBarycentric; the test drives the fallback path on it directly. A run of d3d12_bary_fallback on such a card would be welcome.
  • ps_ij_computed from #1426 translated by rdna2spirv.py and drawn through the runtime (no llvm-mc with the AMDGPU target on this machine).
  • The rest of the runtime suite: only the three tests above were built and run.
  • A computed pair together with --f16-interp-fallback relocation in one PSO.

GPUs tested: NVIDIA GeForce RTX 3060, driver 621.24, Windows 11 (10.0.26300)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase). — based on main b0f3d399 plus #1497 and #1426; it will need a rebase as those land.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. — no translator rule; the runtime behaviour is recorded in the "Barycentric fallback" row.

🤖 Generated with Claude Code


🔄 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/1930 **Author:** [@mrgenty](https://github.com/mrgenty) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `rt-bary-fallback-per-vertex` --- ### 📝 Commits (7) - [`e7987db`](https://github.com/ubiquitarianism/leonida/commit/e7987db42050179a38945e3682e400252112ad96) Translate computed I/J pairs when a GPU has no per-vertex inputs. - [`b9191a3`](https://github.com/ubiquitarianism/leonida/commit/b9191a3186def22cf2eb10250045156264650d8b) Merge remote-tracking branch 'origin/main' into fix/computed-ij-no-pervertex - [`53df7d1`](https://github.com/ubiquitarianism/leonida/commit/53df7d1aee7c5fc53ee97a9ff320faa2aa7d13b2) runtime/d3d12: synthesize --bary-fallback geometry shader in graphics PSOs - [`d36d9ef`](https://github.com/ubiquitarianism/leonida/commit/d36d9ef1b0fb221e0913a4ef1bd695b8f2acd5e9) Merge #1497 into rt-bary-fallback-per-vertex - [`52d6df8`](https://github.com/ubiquitarianism/leonida/commit/52d6df8bd9151ce13f4978aafb03716bb7dcf5ba) Merge #1426 into rt-bary-fallback-per-vertex - [`682de28`](https://github.com/ubiquitarianism/leonida/commit/682de28946f27bcc6ddb404ce583df7797c9812e) runtime/d3d12: the --bary-fallback geometry stage feeds computed I/J pairs (RT-BARY-FALLBACK-PER-VERTEX) - [`0b75329`](https://github.com/ubiquitarianism/leonida/commit/0b7532951f91ee86512cbc7fc5a939ab7eac9b63) runtime/d3d12: computed I/J reads only the VS's raw outputs after f16 linking (RT-BARY-FALLBACK-PER-VERTEX) ### 📊 Changes **24 files changed** (+2879 additions, -108 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+2 -2) 📝 `docs/testing.md` (+4 -1) 📝 `make_game.py` (+22 -4) 📝 `runtime/CMakeLists.txt` (+10 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+95 -10) 📝 `runtime/src/shader_library.h` (+34 -0) ➕ `runtime/src/spirv_bary_fallback.h` (+551 -0) 📝 `runtime/src/spirv_f16_halves.h` (+16 -3) ➕ `runtime/test/d3d12_bary_fallback_test.cpp` (+1000 -0) 📝 `runtime/test/shader_library_test.cpp` (+86 -0) 📝 `runtime/test/shaders/build.py` (+9 -7) 📝 `runtime/test/shaders/check.py` (+5 -4) ➕ `runtime/test/spirv_bary_fallback_test.cpp` (+715 -0) 📝 `runtime/test/vk_test_device.h` (+2 -0) 📝 `scripts/run_gpu_tests.py` (+6 -5) 📝 `tests/semantic/support.py` (+4 -2) 📝 `tests/semantic/test_interp_computed_ij.py` (+153 -14) 📝 `tests/test_make_game_translator_flags.py` (+20 -5) 📝 `tests/test_run_gpu_tests.py` (+21 -18) 📝 `tests/test_shader_build_fallbacks.py` (+22 -14) _...and 4 more files_ </details> ### 📄 Description Claimed in the coordination issue as: RT-BARY-FALLBACK-PER-VERTEX (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167254678) Depends on: #1497, #1426 ### What and why The runtime half of the computed-I/J case of #1285, which #1497 leaves out ([finding](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151723423), confirmed in the reviews of #1497). With `--bary-fallback`, #1426 translates a pixel shader that has a computed I/J pair so that the pair's attribute is a `Flat` `vec4[3]` input, at the first of three locations the index gives as `bary_fallback_input.per_vertex` (attribute → first location). #1497's builder reads only `bary_fallback_input.location` and expects every other PS input to be a `vec4`, so it refuses such a PS before the draw (`PS pass-through Input at Location 0 is not vec4<f32>`) and the PSO is never created. **This branch is `main` + #1497 + #1426 + one commit.** Only the last commit, `07d06992`, is this pull request; the rest of the diff goes away as those two land. #1426 conflicted with `main` in one `docs/design.md` row and I took its side, which is `main`'s text plus its additions. The commit: - `runtime/src/shader_library.h`: parses `per_vertex` into `ShaderEntry::bary_fallback_per_vertex`. Keys and values are exact `u32`s; one malformed entry drops the whole map, so the builder refuses the array instead of linking part of a mapping. - `runtime/src/spirv_bary_fallback.h`: `build_bary_fallback_gs` takes the map. For each mapped attribute the PS declares, the geometry stage reads the VS output at the attribute's number and writes the triangle's three values to a `Flat` `vec4[3]` output at the first location (element k = vertex k, the same at each of the three vertices it emits), as `tools/bary_fallback_gs.py` does. The three values are loaded once. An attribute the VS does not export is zero-filled, like an ordinary pass-through input. One GS input per VS location, shared when the PS also reads that location as an ordinary input. Refused: a `vec4[3]` input the map does not name, a mapped location that is not `vec4<f32>[3]`, a block that runs into another PS input or the barycentric location, two attributes at one first location, and a block past the last location. A mapping the PS does not declare is ignored. The six-argument signature stays as a wrapper with an empty map. - `runtime/shims/d3d12_vulkan_device.cpp`: the two call sites (`create_graphics` and the lazy `stage_words`) pass the entry's map. - `docs/design.md`: the runtime builder in the "Barycentric fallback" row, with what was checked and what was not. ### Tested Native Windows 11 (build 26300), MSVC 19.44 `RelWithDebInfo`, Vulkan SDK 1.4.363.0. No game files. - `ctest -C RelWithDebInfo -R "^(shader_library|spirv_bary_fallback|d3d12_bary_fallback)$"`: 3/3 pass, and again with `LEONIDA_VK_VALIDATION=1`; `d3d12_bary_fallback` also with `LEONIDA_LAZY_GRAPHICS=0` and `=1` under validation (the test fails on any validation error). - `spirv_bary_fallback` (CPU), five new cases: the block at the attribute's first locations, a relocated block next to ordinary inputs with a shared GS input, two attributes with one zero-filled, an undeclared mapping (module identical to the one built without it), and six refusals that leave the caller's words untouched. - `spirv-val --target-env vulkan1.2` and `vulkan1.3` on all 9 modules `spirv_bary_fallback_test --dump-dir` writes (the 6 from #1497 and 3 new): 18/18 clean. - `shader_library`, twelve new `per_vertex` parsing cases (non-numeric, signed and out-of-range keys; negative, fractional, string and overflowing values; two keys for one attribute; an array instead of an object). - `d3d12_bary_fallback` (GPU), new draws 5a–5c through the Xbox-ABI proxy: a VS that gives each vertex a different value, and a PS in the shape #1426 emits that weights the three with its own I/J (0.375, 0.5, 0.125). All 256 pixels match with the block at locations 0..2 and with it relocated to 4..6 next to an ordinary input; the barycentric channel is still the perspective-correct one. The same weights on any other order of the three vertices would be at least 15 LSB away (the test asserts that margin). The same PS with no `per_vertex` in its index entry is refused with `E_FAIL`. - `python -I scripts/check_no_game_data.py` on the touched files, `tests/test_bary_fallback_gs.py`, `tests/test_ctest_registration.py`, `tests/test_docs_links.py`, `tests/test_docs_table_rows.py`, `git diff --check`. **Not tested:** - The game's 207 computed-I/J pixel shaders through this builder: the tests use hand-built SPIR-V in the same shape, not translated shaders. No retail run. - A GPU that needs the fallback (RX 5700 XT, Pascal). The RTX 3060 has `fragmentShaderBarycentric`; the test drives the fallback path on it directly. A run of `d3d12_bary_fallback` on such a card would be welcome. - `ps_ij_computed` from #1426 translated by `rdna2spirv.py` and drawn through the runtime (no `llvm-mc` with the AMDGPU target on this machine). - The rest of the runtime suite: only the three tests above were built and run. - A computed pair together with `--f16-interp-fallback` relocation in one PSO. GPUs tested: NVIDIA GeForce RTX 3060, driver 621.24, Windows 11 (10.0.26300) AI-assisted: yes (Claude Code) ### Checklist - [ ] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). — based on `main` `b0f3d399` plus #1497 and #1426; it will need a rebase as those land. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. — no translator rule; the runtime behaviour is recorded in the "Barycentric fallback" row. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#1938
No description provided.