Skip to content

runtime/d3d12: synthesize --bary-fallback geometry shader in graphics PSOs - #1497

Open
robot00f wants to merge 3 commits into
ProjectLeonida:mainfrom
robot00f:feat/rt-bary-fallback-pso
Open

robot00f wants to merge 3 commits into
ProjectLeonida:mainfrom
robot00f:feat/rt-bary-fallback-pso

Conversation

@robot00f

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-BARY-FALLBACK-PSO (#14 (comment))

What and why

On GPUs without VK_KHR_fragment_shader_barycentric (for example NVIDIA Pascal), rdna2spirv.py --bary-fallback emits a pixel shader's raw barycentrics as an ordinary perspective-interpolated vec3<f32> Input and records "bary_fallback_input": {"location": N} in spirv/index.json. Offline tools/bary_fallback_gs.py already specified the triangle pass-through geometry shader shape, and PipelineState::create_graphics already supported explicit geometry stages (#2109), rectangle-list geometry stages (#984) and per-pipeline --f16-interp-fallback linking (spirv_f16_halves.h), but ShaderLibrary did not read bary_fallback_input and create_graphics did not insert the pass-through geometry stage — leaving any graphics PSO with a --bary-fallback PS without a stage writing bary_location.

This PR wires --bary-fallback pixel shaders end to end into D3D12→Vulkan graphics PSO creation:

  1. runtime/src/shader_library.h: parses "bary_fallback_input": {"location": N} (exact non-negative uint32_t) into ShaderEntry::bary_fallback_location.
  2. runtime/src/spirv_bary_fallback.h: pure C++20 leonida::build_bary_fallback_gs(vs_words, ps_words, bary_location, gs_words, &info, &error) synthesizing a SPIR-V 1.5 Geometry module (Triangles in, Invocations 1, OutputTriangleStrip, OutputVertices 3) for the (VS, PS) pair:
    • copies BuiltIn Position across the three triangle vertices and writes (1, 0, 0), (0, 1, 0), (0, 0, 1) to Output vec3<f32> at bary_location;
    • forwards every vec4<f32> Location input the PS declares (other than bary_location) that the VS exports, leaves unread VS outputs unconsumed on VS -> GS (even if the VS exports an unread output at bary_location), and zero-fills any unexported PS Location input via OpConstantNull without declaring a dangling GS Input (VUID-RuntimeSpirv-OpEntryPoint-08743);
    • inspects the VS for BuiltIn ClipDistance or BuiltIn CullDistance (float[1..8]) and forwards it with the matching capability, rejecting mixed ClipDistance + CullDistance and ShaderLayer / ShaderViewportIndex.
  3. runtime/shims/d3d12_vulkan_device.cpp: in PipelineState::create_graphics and stage_words (StageSource::bary_fallback for lazy graphics pipeline builds), runs build_bary_fallback_gs after link_f16_halves on the post-link (vs, ps) words (clamping top_location against maxGeometryInputComponents / maxGeometryOutputComponents) so relocated/synthesized f16_halves locations are forwarded automatically through the GS. Refuses mesh PSOs, explicit desc.GS, rectangle-list PSOs, disabled geometryShader / shaderClipDistance / shaderCullDistance (E_NOTIMPL via stream_unsupported), and non-triangle PrimitiveTopologyType (E_INVALIDARG).
  4. Tests (runtime/CMakeLists.txt, runtime/test/vk_test_device.h, runtime/test/*):
    • extends shader_library_test with bary_fallback_input index parsing checks;
    • adds spirv_bary_fallback (spirv_bary_fallback_test.cpp), a portable pure-CPU test covering pass-through locations, unread VS locations, unexported PS Flat zero-fill, ClipDistance[2], CullDistance[3], combined link_f16_halves + build_bary_fallback_gs, and clean refusals;
    • enables shaderClipDistance and shaderCullDistance where available in vktest::Device and adds d3d12_bary_fallback (d3d12_bary_fallback_test.cpp), exercising real Vulkan GPU draws through the Xbox-ABI proxy.

Tested

  • 3 consecutive runs + eager & lazy graphics pipeline modes (ctest --output-on-failure -R "^(shader_library|spirv_bary_fallback|d3d12_bary_fallback)$", plus LEONIDA_LAZY_GRAPHICS=0 and LEONIDA_LAZY_GRAPHICS=1): 3/3 passed on all runs:
    • d3d12_bary_fallback verified all 256 pixels of: (1) a non-uniform-W (w = 1, 2, 4) triangle checking perspective-correct (b0, b1, b2) + pass-through Location 0 (center=(184,49,22,191) vs affine (128,64,64,191)), (2) ClipDistance[1] clipping ndc_x < 0 while preserving barycentrics on ndc_x > 0, (3) a 16-param VS + colliding f16_halves + bary_fallback_input PSO combining link_f16_halves relocation/synthesis with build_bary_fallback_gs, plus E_INVALIDARG / E_NOTIMPL refusal checks.
  • SPIR-V validation: dumped all 6 synthesized GS variants from spirv_bary_fallback_test --dump-dir (gs_basic, gs_unread_vs, gs_zero_fill, gs_clip2, gs_cull3, gs_f16_linked) and validated each with spirv-val --target-env vulkan1.2 and spirv-val --target-env vulkan1.3 (0 errors).
  • Neighbor tests: spirv_f16_halves, d3d12_f16_halves, d3d12_geometry, d3d12_translated_draw (4/4 passed).
  • Repo / policy checks: python -I scripts/check_no_game_data.py on all touched files, tests/test_bary_fallback_gs.py (29), tests/test_ctest_registration.py (5), tests/test_docs_links.py (16), tests/test_docs_table_rows.py (2), git diff --check.
  • Not tested: VK_LAYER_KHRONOS_validation is not installed on this Windows 10 host; no game shaders or executable were run.

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 (a conflicting pull request is labeled needs rebase).
  • 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.

@ecox982745

Copy link
Copy Markdown

I checked how this runtime builder handles the two kinds of fallback shader produced by #1426 (b9191a31). The ordinary barycentric case works on my RTX 4090. The computed-I/J case needs an additional runtime change before these PRs together cover the RX 5700 XT report in #1285.

I built vs_ids, ps_bary and ps_ij_computed at the translator head with both fallbacks enabled. I passed the resulting VS/PS modules and the location in their index directly to build_bary_fallback_gs from this PR's head, bff50180. Neither PS had f16-halves relocation metadata.

Synthetic fixture Runtime builder on this head RTX 4090 readback
ps_bary, location 1 Produced a valid GS Runtime and offline GS frames were byte-identical. All 4,096 pixels matched the expected RGBA.
ps_ij_computed, location 3 with per_vertex: {"0": 0} Refused before drawing: PS pass-through Input at Location 0 is not vec4<f32> With the offline GS from #1426, all 4,096 pixels matched the expected RGBA.

The computed input at location 0 is a flat array of three vec4s. The runtime currently reads only bary_fallback_input.location and expects the other inputs to be ordinary vec4s. The integration needs to carry the per_vertex mapping into GS generation and fill each array element from the corresponding vertex, as #1426's offline builder does. The existing ps_ij_computed fixture would make a regression test for that link.

The GPU draws used this PR's vk_harness on Windows 11, NVIDIA 616.64. I tested the runtime builder directly; the computed-case refusal occurred on CPU before a Vulkan pipeline was created. AI-assisted verification.

@robot00f
robot00f force-pushed the feat/rt-bary-fallback-pso branch from bff5018 to 31ff719 Compare November 25, 2026 03:35
@ytsodacan

ytsodacan commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

[KEEP]

@whoalin1

Copy link
Copy Markdown
Contributor

Independent verification (native Windows 11, validation on):

  • CPU: spirv_bary_fallback + shader_library pass; all 6 dumped GS SPIR-V modules pass spirv-val under both vulkan1.2 and vulkan1.3 targets (12/12 clean).
  • NVIDIA RTX 4070 SUPER: 4/4 pass — d3d12_bary_fallback, d3d12_f16_halves, d3d12_geometry, spirv_f16_halves; also d3d12_bary_fallback passes with LEONIDA_LAZY_GRAPHICS=1.
  • AMD Radeon iGPU: the d3d12 graphics tests fail at PSO creation with the known 144>128 push-constant limit — identical on the untouched baseline, environmental not a regression.
  • Code review: the diff refuses mesh/explicit-GS/rect-list PSOs, clamps f16-half top location vs geometry limits, zero-fills unexported PS inputs, forwards Clip/CullDistance with feature checks, and the lazy StageSource::bary_fallback rebuild path is included. Looks careful.

One scope note confirmed independently: this PR does not include #1426's per-vertex attribute mapping (git merge-base --is-ancestor negative), so the computed-I/J per_vertex case from the original report still needs that carry-over — matching @ecox982745's comment. #1426 is itself currently conflicting vs main.

AI-assisted verification.

@aslan2142

Copy link
Copy Markdown
Collaborator

Tested 483f0128e merged onto main, Windows build under Wine, on Mesa lavapipe and RADV (gfx1036 iGPU):

  • spirv_bary_fallback passes on both.
  • d3d12_bary_fallback passes on lavapipe but fails on RADV, 3 of 3 runs, at d3d12_bary_fallback_test.cpp:623: CreateGraphicsPipelineState fails for case 3 (vs_16p + ps_bary_f16). Cases 1 and 2 pass.
  • Nothing is logged for the failure.
  • Likely cause (not confirmed): the synthesized geometry shader takes every VS output, 30 locations, but RADV reports maxGeometryInputComponents = 64. Lavapipe reports 128.

Could the runtime either forward only the locations the pixel shader reads, or refuse with a logged reason when the inputs exceed the limit? The test should then skip case 3 on such devices rather than fail.

AI-assisted (Claude Code, Claude Opus 5.5).

robot00f added a commit to robot00f/pascalVI that referenced this pull request Nov 25, 2026
When `tools/rdna2spirv.py --bary-fallback` translates a pixel shader (for GPUs
without `VK_KHR_fragment_shader_barycentric` or drivers with broken
`BaryCoordKHR`), the emitted Fragment SPIR-V reads perspective barycentrics from
an ordinary 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 `stubs/vs_<inputs>.spv`.
Previously `vk_pipeline_check` ignored `"bary_fallback_input"` and built a
2-stage `VS_stub + PS` pipeline, leaving `Location N` unwritten by the preceding
stage (`VUID-RuntimeSpirv-OpEntryPoint-08743`), omitting the `geometryShader` /
`shaderClipDistance` / `shaderCullDistance` feature gates, and writing a 2-stage
entry into `pipeline_cache.bin` that misses the runtime's 3-stage `VS + GS + PS`
pipeline key.

- Parse `"bary_fallback_input"` in `vk_pipeline_check`'s `JsonParser` into
  `ShaderMeta::bary_fallback_location` (accepting `null` or an object with an
  unsigned 32-bit `"location" < 32`, rejecting non-objects, missing `"location"`,
  and out-of-range locations with exit code 2 before loading Vulkan).
- Cache each loaded partner stub's SPIR-V words alongside its `VkShaderModule`
  in `stub_cache` without re-reading disk per shader.
- Skip `--bary-fallback` `ps` entries with `no geometryShader` when the selected
  device lacks `geometryShader`; otherwise synthesize the triangle pass-through
  `VK_SHADER_STAGE_GEOMETRY_BIT` module in memory via
  `leonida::build_bary_fallback_gs` (`runtime/src/spirv_bary_fallback.h`), gate
  forwarded VS `ClipDistance` / `CullDistance` on `shaderClipDistance` /
  `shaderCullDistance` before creating the GS module, compile the 3-stage
  `VS + GS + PS` graphics pipeline, and fail the check (`PIPELINE FAIL`, exit 1)
  if `build_bary_fallback_gs` rejects an incompatible `VS`/`PS` interface.
- Add CTest `vk_pipeline_check_bary_fallback`
  (`runtime/test/check_vk_pipeline_bary_fallback.py`), index parser cases in
  `tests/test_vk_pipeline_check_index.py`, and documentation in
  `docs/pipeline_check.md`.

Depends on: ProjectLeonida#1497
Claim: ProjectLeonida#14 (comment)
AI-assisted: yes (Antigravity)
@ZroIsHere

Copy link
Copy Markdown
Contributor

I opened a focused stacked follow-up for the low maxGeometryInputComponents case: robot00f#1. It preserves the PS interface outputs while zero-filling declared inputs the PS never loads, so the synthesized GS only reads needed values from the VS.

… PSOs

When a translated pixel shader carries `"bary_fallback_input": {"location": N}`
in `spirv/index.json` (`rdna2spirv.py --bary-fallback` for GPUs without
`VK_KHR_fragment_shader_barycentric`), `PipelineState::create_graphics` now
synthesizes the triangle pass-through Geometry SPIR-V 1.5 module in memory
(`leonida::build_bary_fallback_gs` in `runtime/src/spirv_bary_fallback.h`)
after `--f16-interp-fallback` VS/PS location linking:

- Parses `bary_fallback_input.location` in `ShaderLibrary::load_index` into
  `ShaderEntry::bary_fallback_location`.
- Copies `BuiltIn Position` and every `vec4<f32>` `Location` input read by the
  PS (other than `bary_location`) that the VS exports, while zero-filling any
  unexported PS `Location` input without declaring a dangling GS `Input` and
  leaving unread VS outputs unconsumed (`VUID-RuntimeSpirv-OpEntryPoint-08743`).
- Forwards a VS `BuiltIn ClipDistance` or `BuiltIn CullDistance` `float[1..8]`
  array (checking `shaderClipDistance` / `shaderCullDistance`), and emits
  `(1, 0, 0)`, `(0, 1, 0)`, `(0, 0, 1)` at `bary_location` across the 3 strip
  vertices so perspective interpolation matches `BaryCoordKHR`.
- Supports both eager and lazy graphics pipeline builds (`StageSource::bary_fallback`
  in `stage_words`), clamps `--f16-interp-fallback` `top_location` against
  `maxGeometryInputComponents` / `maxGeometryOutputComponents`, and refuses
  mesh PSOs, explicit GS or rectangle-list stages, missing `geometryShader`, or
  non-triangle topologies with clear HRESULTs (`E_NOTIMPL` / `E_INVALIDARG`).
- Adds `spirv_bary_fallback` (portable CPU test) and `d3d12_bary_fallback`
  (end-to-end Vulkan GPU D3D12 PSO test).

Claim: RT-BARY-FALLBACK-PSO
AI-assisted: yes (Antigravity)
@robot00f
robot00f force-pushed the feat/rt-bary-fallback-pso branch from 483f012 to 53df7d1 Compare November 26, 2026 04:41
robot00f added a commit to robot00f/pascalVI that referenced this pull request Nov 26, 2026
When `tools/rdna2spirv.py --bary-fallback` translates a pixel shader (for GPUs
without `VK_KHR_fragment_shader_barycentric` or drivers with broken
`BaryCoordKHR`), the emitted Fragment SPIR-V reads perspective barycentrics from
an ordinary 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 `stubs/vs_<inputs>.spv`.
Previously `vk_pipeline_check` ignored `"bary_fallback_input"` and built a
2-stage `VS_stub + PS` pipeline, leaving `Location N` unwritten by the preceding
stage (`VUID-RuntimeSpirv-OpEntryPoint-08743`), omitting the `geometryShader` /
`shaderClipDistance` / `shaderCullDistance` feature gates, and writing a 2-stage
entry into `pipeline_cache.bin` that misses the runtime's 3-stage `VS + GS + PS`
pipeline key.

- Parse `"bary_fallback_input"` in `vk_pipeline_check`'s `JsonParser` into
  `ShaderMeta::bary_fallback_location` (accepting `null` or an object with an
  unsigned 32-bit `"location" < 32`, rejecting non-objects, missing `"location"`,
  and out-of-range locations with exit code 2 before loading Vulkan).
- Cache each loaded partner stub's SPIR-V words alongside its `VkShaderModule`
  in `stub_cache` without re-reading disk per shader.
- Skip `--bary-fallback` `ps` entries with `no geometryShader` when the selected
  device lacks `geometryShader`; otherwise synthesize the triangle pass-through
  `VK_SHADER_STAGE_GEOMETRY_BIT` module in memory via
  `leonida::build_bary_fallback_gs` (`runtime/src/spirv_bary_fallback.h`), gate
  forwarded VS `ClipDistance` / `CullDistance` on `shaderClipDistance` /
  `shaderCullDistance` before creating the GS module, compile the 3-stage
  `VS + GS + PS` graphics pipeline, and fail the check (`PIPELINE FAIL`, exit 1)
  if `build_bary_fallback_gs` rejects an incompatible `VS`/`PS` interface.
- Add CTest `vk_pipeline_check_bary_fallback`
  (`runtime/test/check_vk_pipeline_bary_fallback.py`), index parser cases in
  `tests/test_vk_pipeline_check_index.py`, and documentation in
  `docs/pipeline_check.md`.

Depends on: ProjectLeonida#1497
Claim: ProjectLeonida#14 (comment)
AI-assisted: yes (Antigravity)
mrgenty added a commit to mrgenty/leonida that referenced this pull request Nov 26, 2026
@mrgenty

mrgenty commented Nov 26, 2026

Copy link
Copy Markdown

Tested at your current head 53df7d1a, merged onto main 73516a29 together with #1426: this is the base of #1930, which builds on both. On an RTX 3060 (NVIDIA 621.24, Windows 11, MSVC 19.44, Vulkan validation on), shader_library, spirv_bary_fallback and d3d12_bary_fallback pass with no validation message, and run_semantic_tests.py passes: 498 files, 6,357 tests, 0 failed. The merge onto main had no conflict in this PR's files. The run includes #1930's commit on top, so these are this PR's tests on the combined tree, not this head alone.

robot00f and others added 2 commits November 26, 2026 21:07
…mponent limits

- Prune declared-but-unread PS Input variables on the VS -> GS interface in
  build_bary_fallback_gs (tracking pointer aliases through OpAccessChain,
  OpCopyObject, OpSelect, and OpPhi into OpLoad, GLSL.std.450 InterpolateAt*,
  OpFunctionCall, and OpCopyMemory*), zero-filling unread FSSM table inputs in
  the synthesized GS instead of reading them from the VS.
- Record per-vertex input/output scalar component totals and highest
  4 * Location + components bounds (VUID-RuntimeSpirv-Location-06272) in
  BaryFallbackGsInfo, and check them against maxGeometryInputComponents,
  maxGeometryOutputComponents, and maxGeometryTotalOutputComponents in
  create_graphics with explicit [rt] d3d12: refusal diagnostics.
- Extend spirv_bary_fallback_test and d3d12_bary_fallback_test to cover
  unused-input pruning, 10-param f16 relocation within 64 geometry input
  components, simulated maxGeometryInputComponents=64 acceptance/refusal on any
  GPU, and clean refusal + draw skip on <120-component devices (such as RADV
  gfx1036) for the 16-param relocated f16 case.

Co-authored-by: ZroFreaks <42916282+ZroIsHere@users.noreply.github.com>
@robot00f

Copy link
Copy Markdown
Contributor Author

Thanks for testing on RADV gfx1036 and catching both the silent failure and VUID-RuntimeSpirv-Location-06272, @aslan2142 (and thanks @ZroIsHere for robot00f/leonida#1)!

Updated in 961d719d (merged current main with no rebase/force-push):

  1. Merged main to clear the unrelated baseline CI failures (vk_null_descriptor_test.cpp and cs_dpp_cmp.asm).
  2. Pruned unread PS Inputs on VS -> GS (runtime/src/spirv_bary_fallback.h, co-authored with @ZroIsHere): build_bary_fallback_gs now tracks pointer aliases rooted at PS Input variables (through OpAccessChain/OpPtrAccessChain, OpCopyObject, OpSelect, and OpPhi into OpLoad, GLSL.std.450 InterpolateAt*, OpFunctionCall, and OpCopyMemory*) and zero-fills unread FSSM table declarations in the synthesized GS without declaring GS Inputs from the VS.
  3. Checked geometry stage component & location limits up front with [rt] d3d12: diagnostics (runtime/shims/d3d12_vulkan_device.cpp):
    • Recorded maxGeometryInputComponents, maxGeometryOutputComponents, and maxGeometryTotalOutputComponents from VkPhysicalDeviceProperties::limits.
    • BaryFallbackGsInfo now reports both per-vertex scalar component totals and highest 4 * Location + components bounds (VUID-RuntimeSpirv-Location-06272), and create_graphics refuses pipelines that exceed device geometry limits before vkCreateShaderModule / vkCreateGraphicsPipelines while logging the shader names, location/component count, and device limit (including when --bary-fallback caps f16_halves top_location).
  4. Updated spirv_bary_fallback_test & d3d12_bary_fallback_test for maxGeometryInputComponents = 64 GPUs:
    • Added ps_bary_pruned (16-param VS + 25 unread PS inputs pruned so live inputs stay < 16) and ps_bary_f16_low (10-param VS + f16_halves relocated into 0..14), both running within 64 geometry input components.
    • For the 16-param vs_16p + ps_bary_f16 case (where raw VS outputs occupy 0..15, so relocated f16_halves sit at [28, 29] and genuinely require >= 120 geometry components), devices with maxGeometryInputComponents < 120 or maxGeometryOutputComponents < 120 now assert clean refusal and SKIP that draw check instead of failing.
    • Added a max_geometry_input_components = 64 test block exercising both the pruned/10-param passes and the Location 16 (4 * 16 + 4 = 68 > 64) / 16-param refusals on all GPUs.

Validated locally on NVIDIA GeForce GTX 1050 Ti (driver 582.28, Windows 10 19045) with spirv_bary_fallback, d3d12_bary_fallback (eager + lazy), d3d12_f16_halves, d3d12_geometry, spirv_f16_halves, shader_library, spirv-val (vulkan1.2 + vulkan1.3 on all 7 synthesized GS binaries), and the Python/semantic test suites.

AI-assisted: yes

mrgenty added a commit to mrgenty/leonida that referenced this pull request Nov 27, 2026
# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
#	runtime/test/d3d12_bary_fallback_test.cpp
#	runtime/test/spirv_bary_fallback_test.cpp
mrgenty added a commit to mrgenty/leonida that referenced this pull request Nov 27, 2026
…(RT-BARY-FALLBACK-PER-VERTEX)

ProjectLeonida#1497's precheck compares BaryFallbackGsInfo with maxGeometryInput/OutputComponents, but the info left out the
per_vertex blocks: an attribute read only by a block had a GS Input that was not counted, and each vec4[3] output
(Locations base..base+2, 12 components, zero-filled or not) was missing from the output bounds. Attribute 16 with
its block at 14..16 reported 0/15 while the module needs 68/68, so a 64-component device would get it.

Inputs are now counted from the GS's final Input map (a location shared by an ordinary output and a block once),
and each block adds 12 output components and its last Location to the output bound. spirv_bary_fallback_test 7i
checks 68/68, the 64/64 edge and a zero-filled block; it fails with the old count.

Also fixes two leftovers of the ProjectLeonida#1497 merge in the tests: build_ps declared its uint type twice when a PS had both
a block and an access chain, and an extra brace closed the D3D12 test's index.json early.

Found by @ecox982745 and confirmed on a Vega 20 by @zmasi in ProjectLeonida#1930.
@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Independent Windows 11 + NVIDIA GeForce RTX 3090 Verification (961d719d54 merged onto main 53b77df14f)

Environment: Windows 11 (10.0.26200), MSVC 19.44.35228, Python 3.12.10 (-I), SPIRV-Tools / VK_LAYER_KHRONOS_validation 1.4.363.1, physical NVIDIA GeForce RTX 3090 (Ampere, driver 610.88, Vulkan 1.4, maxGeometryInputComponents = 128, maxGeometryOutputComponents = 128). Synthetic in-memory SPIR-V fixtures only; no game files.

Results — PASS (0 validation errors)

  • Red check on main (5825b02ff8): ShaderLibrary does not parse bary_fallback_input, leaving graphics PSOs whose pixel shader expects a synthesized --bary-fallback geometry stage without a producer for bary_location.
  • Synthesized GS SPIR-V validation (spirv_bary_fallback_test --dump-dir):
    • spirv_bary_fallback_test: rc=0 across all 7 cases (gs_basic, gs_unread_vs, gs_zero_fill, gs_clip2, gs_cull3, gs_f16_linked, gs_pruned_unused, including the new unread-PS-input pointer-alias pruning).
    • spirv-val (--target-env vulkan1.2 and --target-env vulkan1.3): 14/14 clean (0 errors) across all 7 dumped GS binaries.
  • End-to-end GPU PSO & pixel verification on RTX 3090 (LEONIDA_VK_VALIDATION=1):
    • Ran d3d12_bary_fallback_test under both LEONIDA_LAZY_GRAPHICS=0 (eager create_graphics path) and LEONIDA_LAZY_GRAPHICS=1 (StageSource::bary_fallback lazy rebuild path) — rc=0, 0 VUID- errors on both:
      • ps_bary (non-uniform clip w = 1, 2, 4): center=(184,49,22,191) exact across all 256 pixels.
      • ps_bary + ClipDistance[1]: left half clipped to (0,0,0,0), right half perspective-interpolated across all pixels.
      • ps_bary_pruned (25 unread PS Inputs pruned, live Location 7 + bary 14): all 256 pixels exact.
      • ps_bary_f16_low (10-param VS + f16_halves relocation <= 14 + bary GS): all 256 pixels exact.
      • ps_bary_f16 (16-param VS + f16_halves relocated to [28, 29] + bary GS — active on RTX 3090 since 128 >= 120): all 256 pixels exact.
      • Simulated max_geometry_input_components = 64 (RADV limit): pruned & 10-param PSOs succeed, while 16-param and live Location 16 (4 * 16 + 4 = 68 > 64) refuse cleanly with E_NOTIMPL.
  • Neighbor CTest & Python suites:
    • ctest -R "^(shader_library|spirv_bary_fallback|d3d12_bary_fallback|spirv_f16_halves|d3d12_f16_halves|d3d12_geometry)$" (LEONIDA_VK_VALIDATION=1): 6/6 passed (2.16s).
    • tests/test_bary_fallback_gs.py (34/34 OK) and tests/test_ctest_registration.py (7/7 OK).

(Confirmed the scope note from earlier comments: per_vertex array forwarding for computed-I/J --bary-fallback pixel shaders remains separate follow-up work.)

AI-assisted.

@enlight3d

Copy link
Copy Markdown
Contributor

RUN of #1497 (red/green, GPU box, PR head only: it conflicts with main)

Heads: PR head 961d719d544, main 54b2a81e95c4. git merge --no-ff of the PR into main conflicts in runtime/src/shader_library.h (the other touched files auto-merge), so I aborted the merge and tested the PR head as it is (detached, based on d1dff7949be6, the merge-base with main). The results below are for that base, not for current main.

Commands (VS 2022 x64 environment, from the worktree root):
cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build -j 8 --target shader_library_test spirv_bary_fallback_test d3d12_bary_fallback_test spirv_f16_halves_test d3d12_f16_halves_test d3d12_geometry_test d3d12_translated_draw_test gta6rt
ctest -R "^(shader_library|spirv_bary_fallback|d3d12_bary_fallback|spirv_f16_halves|d3d12_f16_halves|d3d12_geometry|d3d12_translated_draw)$" --output-on-failure -j1

  • Red 1, API (the PR's non-test files reverted to the merge-base: shader_library.h, d3d12_com.h, d3d12_vulkan_device.cpp, and spirv_bary_fallback.h removed; tests and CMake registration kept): build failures only, bary_fallback_location is not a member of ShaderEntry (shader_library_test) and spirv_bary_fallback.h is missing (spirv_bary_fallback_test, d3d12_bary_fallback_test). That only proves the new API is needed.
  • Red 2, behavioural (only d3d12_vulkan_device.cpp reverted to the merge-base, the new header, the index parsing and the tests kept, so everything compiles): d3d12_bary_fallback fails on the first pixel check, persp (0,0): got (0,0,0,191) want (203,3,49,191), i.e. no geometry stage is inserted so the barycentrics are never written. That is the wiring this PR adds.
  • Green at PR head: shader_library, spirv_f16_halves, spirv_bary_fallback, d3d12_f16_halves, d3d12_bary_fallback, d3d12_translated_draw, d3d12_geometry: 7 of 7 Passed on the RTX 3090, none skipped (so geometryShader, shaderClipDistance and shaderCullDistance were available).
  • Link: no new imports vs the merge-base build (dumpbin /imports of gta6rt.exe, DLL!symbol, sorted: 700 entries before and after the PR).
  • Not run: the other d3d12_* and vk_* tests that include vk_test_device.h (the PR only adds two feature enables there, gated on the device having them).

Author: this branch conflicts with current main in runtime/src/shader_library.h; could you merge main into it? Thank you.

Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo, -DLEONIDA_REQUIRE_VULKAN=ON, Vulkan SDK 1.4.363.1.

@ecox982745

Copy link
Copy Markdown

I tested a local merge of PR head 961d719d544065e08053e758d256de53bd2eea34 with main 54b2a81e95c470c953ddee6177fd6255cbaf041d. Git reported one conflict, in the include block of runtime/src/shader_library.h. Keep both headers in the resolution. <memory> supports main's block index reader and <optional> supports the fallback metadata.

#include <map>
#include <memory>
#include <optional>
#include <span>

The other changes merged cleanly. The resulting tree was c80ebbecfd12b7372c22de74fb9dea83094f4c26.

  • CPU. shader_library, spirv_bary_fallback and spirv_f16_halves passed. The generator dumped seven geometry modules. Each passed spirv-val for both Vulkan 1.2 and 1.3.
  • GPU. d3d12_bary_fallback, d3d12_f16_halves, d3d12_geometry and d3d12_translated_draw all passed with NVIDIA RTX 4090, driver 616.64, Windows 11 build 26300, MSVC 19.44 Release and Khronos Vulkan validation enabled. All four ran on the named GPU and CTest reported zero failures. The changed-file game-data check passed.

Coordination claim

AI-assisted with OpenAI Codex (GPT-6.2 Sol).

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants