[PR #1890] vk_pipeline_check: synthesize --bary-fallback GS stage for PS pipelines (VK-PIPELINE-CHECK-BARY-FALLBACK) #1902

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

📋 Pull Request Information

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

Base: main ← Head: feat/vk-pipeline-check-bary-fallback


📝 Commits (2)

  • 53df7d1 runtime/d3d12: synthesize --bary-fallback geometry shader in graphics PSOs
  • 79a2437 vk_pipeline_check: synthesize --bary-fallback GS stage for PS pipelines

📊 Changes

12 files changed (+2413 additions, -28 deletions)

View changed files

📝 docs/pipeline_check.md (+11 -4)
📝 runtime/CMakeLists.txt (+16 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+90 -10)
📝 runtime/src/shader_library.h (+10 -0)
➕ runtime/src/spirv_bary_fallback.h (+428 -0)
➕ runtime/test/check_vk_pipeline_bary_fallback.py (+524 -0)
➕ runtime/test/d3d12_bary_fallback_test.cpp (+678 -0)
📝 runtime/test/shader_library_test.cpp (+34 -0)
➕ runtime/test/spirv_bary_fallback_test.cpp (+495 -0)
📝 runtime/test/vk_pipeline_check.cpp (+110 -14)
📝 runtime/test/vk_test_device.h (+2 -0)
📝 tests/test_vk_pipeline_check_index.py (+15 -0)

📄 Description

Claimed in the coordination issue as: VK-PIPELINE-CHECK-BARY-FALLBACK (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7152197322; continued in #1608)

Depends on: #1497

What and why

When tools/rdna2spirv.py --bary-fallback translates a pixel shader (for GPUs without VK_KHR_fragment_shader_barycentric, such as NVIDIA Pascal, or drivers with broken BaryCoordKHR), the Fragment SPIR-V reads perspective barycentrics from a smooth vec3<f32> Input recorded under "bary_fallback_input": {"location": N} in index.json, while "inputs" lists only the vec4<f32> user param locations exported by <spirv dir>/stubs/vs_<inputs>.spv (tools/spirv_stubs.py).

Previously runtime/test/vk_pipeline_check.cpp ignored "bary_fallback_input" and built a 2-stage VS_stub + PS graphics pipeline (runtime/test/vk_pipeline_check.cpp:1748-1764), which:

  1. Left Location N unwritten by the preceding stage (VUID-RuntimeSpirv-OpEntryPoint-08743);
  2. Skipped checking geometryShader (shaderClipDistance / shaderCullDistance); and
  3. Seeded a 2-stage pipeline entry into pipeline_cache.bin that misses the runtime's 3-stage VS + synthesized GS + PS pipeline (#1497).

Changes:

  • runtime/test/vk_pipeline_check.cpp:
    • Parses "bary_fallback_input" in JsonParser into ShaderMeta::bary_fallback_location (accepting null or {"location": 0..31} and rejecting non-objects, missing "location", or out-of-range locations before loading Vulkan).
    • Caches each partner stub's SPIR-V words alongside its VkShaderModule in stub_cache without re-reading disk per shader.
    • Skips --bary-fallback ps entries with no geometryShader when f2.features.geometryShader is unavailable; otherwise synthesizes the triangle pass-through VK_SHADER_STAGE_GEOMETRY_BIT module in memory via leonida::build_bary_fallback_gs (runtime/src/spirv_bary_fallback.h), gates forwarded VS ClipDistance / CullDistance on shaderClipDistance / shaderCullDistance before vkCreateShaderModule, compiles the 3-stage VS + GS + PS graphics pipeline, and fails the check (PIPELINE FAIL, exit 1) if build_bary_fallback_gs rejects an incompatible VS/PS interface.
  • Tests & docs: Adds CTest vk_pipeline_check_bary_fallback (runtime/test/check_vk_pipeline_bary_fallback.py, pure Python stdlib SPIR-V fixtures so Windows/Linux/macOS CI need no llvm-mc), index parser tests in tests/test_vk_pipeline_check_index.py, and docs in docs/pipeline_check.md.

Tested

  • Before vs after on ps_bary.asm (--bary-fallback, VK_LOADER_LAYERS_DISABLE=~implicit~, __GL_SHADER_DISK_CACHE=0):
Check Before (2-stage VS_stub + PS) After (3-stage VS_stub + bary_GS + PS)
Stage interface link (tools/shader_link_check.py) Incompatible (Location 1 unwritten by vs_0.spv, VUID-RuntimeSpirv-OpEntryPoint-08743) 1 compatible, 0 incompatible, 0 invalid (2 links checked)
3-stage pipeline seeded from old 2-stage cache (--cache-feedback) n/a 0 hits, 1 no hit reported (confirms 2-stage cache missed 3-stage pipeline)
3-stage pipeline seeded from new 3-stage cache (--cache-feedback) n/a 1 hits, 0 no hit reported
  • CTest (3/3 consecutive passes on GTX 1050 Ti):
    • vk_pipeline_check_bary_fallback, vk_pipeline_check_cli, pipeline_cache_seed, vk_pipeline_check_stack, spirv_bary_fallback, d3d12_bary_fallback — all PASS 3/3
  • Python & repository checks:
    • python -I runtime/test/check_vk_pipeline_bary_fallback.py -v — PASS (valid 3-stage VS + GS + PS compile + cache write, incompatible vec4 bary_fallback_input rejected with PIPELINE FAIL exit 1, malformed index.json bary_fallback_input rejected with exit 2)
    • python -I tests/test_vk_pipeline_check_index.py -v — 13/13 PASS
    • python -I tests/test_ctest_registration.py, tests/test_docs_links.py, tests/test_docs_table_rows.py, tests/test_text_write_line_endings.py — PASS
    • python -I scripts/check_no_game_data.py on all touched files — PASS
  • Not tested: Full retail shader corpus (no game files used) and a device without geometryShader (MoltenVK; covered by CI's macos job).

GPUs tested: NVIDIA GeForce GTX 1050 Ti (Pascal, 4 GB), driver 582.28, Vulkan 1.4.312, Windows 10 Pro 10.0.19045

AI-assisted: yes (Antigravity)

Checklist

  • Based on current main and merges cleanly (rebased onto #1497, which is rebased onto current main).
  • 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 (n/a: vk_pipeline_check checker change, no translator change).

🔄 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/1890 **Author:** [@robot00f](https://github.com/robot00f) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/vk-pipeline-check-bary-fallback` --- ### 📝 Commits (2) - [`53df7d1`](https://github.com/ubiquitarianism/leonida/commit/53df7d1aee7c5fc53ee97a9ff320faa2aa7d13b2) runtime/d3d12: synthesize --bary-fallback geometry shader in graphics PSOs - [`79a2437`](https://github.com/ubiquitarianism/leonida/commit/79a24375f8e7e84d2e59550e3191f9464e01d493) vk_pipeline_check: synthesize --bary-fallback GS stage for PS pipelines ### 📊 Changes **12 files changed** (+2413 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `docs/pipeline_check.md` (+11 -4) 📝 `runtime/CMakeLists.txt` (+16 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+90 -10) 📝 `runtime/src/shader_library.h` (+10 -0) ➕ `runtime/src/spirv_bary_fallback.h` (+428 -0) ➕ `runtime/test/check_vk_pipeline_bary_fallback.py` (+524 -0) ➕ `runtime/test/d3d12_bary_fallback_test.cpp` (+678 -0) 📝 `runtime/test/shader_library_test.cpp` (+34 -0) ➕ `runtime/test/spirv_bary_fallback_test.cpp` (+495 -0) 📝 `runtime/test/vk_pipeline_check.cpp` (+110 -14) 📝 `runtime/test/vk_test_device.h` (+2 -0) 📝 `tests/test_vk_pipeline_check_index.py` (+15 -0) </details> ### 📄 Description Claimed in the coordination issue as: `VK-PIPELINE-CHECK-BARY-FALLBACK` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7152197322; continued in #1608) Depends on: #1497 ### What and why When `tools/rdna2spirv.py --bary-fallback` translates a pixel shader (for GPUs without `VK_KHR_fragment_shader_barycentric`, such as NVIDIA Pascal, or drivers with broken `BaryCoordKHR`), the Fragment SPIR-V reads perspective barycentrics from a smooth `vec3<f32>` `Input` recorded under `"bary_fallback_input": {"location": N}` in `index.json`, while `"inputs"` lists only the `vec4<f32>` user `param` locations exported by `<spirv dir>/stubs/vs_<inputs>.spv` (`tools/spirv_stubs.py`). Previously `runtime/test/vk_pipeline_check.cpp` ignored `"bary_fallback_input"` and built a 2-stage `VS_stub + PS` graphics pipeline (`runtime/test/vk_pipeline_check.cpp:1748-1764`), which: 1. Left `Location N` unwritten by the preceding stage (`VUID-RuntimeSpirv-OpEntryPoint-08743`); 2. Skipped checking `geometryShader` (`shaderClipDistance` / `shaderCullDistance`); and 3. Seeded a 2-stage pipeline entry into `pipeline_cache.bin` that misses the runtime's 3-stage `VS + synthesized GS + PS` pipeline (#1497). Changes: - **`runtime/test/vk_pipeline_check.cpp`:** - Parses `"bary_fallback_input"` in `JsonParser` into `ShaderMeta::bary_fallback_location` (accepting `null` or `{"location": 0..31}` and rejecting non-objects, missing `"location"`, or out-of-range locations before loading Vulkan). - Caches each partner stub's SPIR-V words alongside its `VkShaderModule` in `stub_cache` without re-reading disk per shader. - Skips `--bary-fallback` `ps` entries with `no geometryShader` when `f2.features.geometryShader` is unavailable; otherwise synthesizes the triangle pass-through `VK_SHADER_STAGE_GEOMETRY_BIT` module in memory via `leonida::build_bary_fallback_gs` (`runtime/src/spirv_bary_fallback.h`), gates forwarded VS `ClipDistance` / `CullDistance` on `shaderClipDistance` / `shaderCullDistance` before `vkCreateShaderModule`, compiles the 3-stage `VS + GS + PS` graphics pipeline, and fails the check (`PIPELINE FAIL`, exit 1) if `build_bary_fallback_gs` rejects an incompatible `VS`/`PS` interface. - **Tests & docs:** Adds CTest `vk_pipeline_check_bary_fallback` (`runtime/test/check_vk_pipeline_bary_fallback.py`, pure Python stdlib SPIR-V fixtures so Windows/Linux/macOS CI need no `llvm-mc`), index parser tests in `tests/test_vk_pipeline_check_index.py`, and docs in `docs/pipeline_check.md`. ### Tested - **Before vs after on `ps_bary.asm` (`--bary-fallback`, `VK_LOADER_LAYERS_DISABLE=~implicit~`, `__GL_SHADER_DISK_CACHE=0`):** | Check | Before (2-stage `VS_stub + PS`) | After (3-stage `VS_stub + bary_GS + PS`) | |---|---|---| | Stage interface link (`tools/shader_link_check.py`) | Incompatible (`Location 1` unwritten by `vs_0.spv`, `VUID-RuntimeSpirv-OpEntryPoint-08743`) | `1 compatible, 0 incompatible, 0 invalid` (2 links checked) | | 3-stage pipeline seeded from old 2-stage cache (`--cache-feedback`) | n/a | `0 hits, 1 no hit reported` (confirms 2-stage cache missed 3-stage pipeline) | | 3-stage pipeline seeded from new 3-stage cache (`--cache-feedback`) | n/a | `1 hits, 0 no hit reported` | - **CTest (3/3 consecutive passes on GTX 1050 Ti):** - `vk_pipeline_check_bary_fallback`, `vk_pipeline_check_cli`, `pipeline_cache_seed`, `vk_pipeline_check_stack`, `spirv_bary_fallback`, `d3d12_bary_fallback` — all PASS 3/3 - **Python & repository checks:** - `python -I runtime/test/check_vk_pipeline_bary_fallback.py -v` — PASS (valid 3-stage `VS + GS + PS` compile + cache write, incompatible `vec4` `bary_fallback_input` rejected with `PIPELINE FAIL` exit 1, malformed `index.json` `bary_fallback_input` rejected with exit 2) - `python -I tests/test_vk_pipeline_check_index.py -v` — 13/13 PASS - `python -I tests/test_ctest_registration.py`, `tests/test_docs_links.py`, `tests/test_docs_table_rows.py`, `tests/test_text_write_line_endings.py` — PASS - `python -I scripts/check_no_game_data.py` on all touched files — PASS - **Not tested:** Full retail shader corpus (no game files used) and a device without `geometryShader` (MoltenVK; covered by CI's `macos` job). GPUs tested: NVIDIA GeForce GTX 1050 Ti (Pascal, 4 GB), driver 582.28, Vulkan 1.4.312, Windows 10 Pro 10.0.19045 AI-assisted: yes (Antigravity) ### Checklist - [x] Based on current `main` and merges cleanly (rebased onto #1497, which is rebased onto current `main`). - [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 (n/a: `vk_pipeline_check` checker change, no translator change). --- <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#1902
No description provided.