Skip to content

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

Open
mrgenty wants to merge 18 commits into
ProjectLeonida:mainfrom
mrgenty:rt-bary-fallback-per-vertex
Open

mrgenty wants to merge 18 commits into
ProjectLeonida:mainfrom
mrgenty:rt-bary-fallback-per-vertex

Conversation

@mrgenty

@mrgenty mrgenty commented Nov 25, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: RT-BARY-FALLBACK-PER-VERTEX (#1608 (comment))

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 runtime/d3d12: synthesize --bary-fallback geometry shader in graphics PSOs #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 rdna2spirv: computed I/J pairs under --bary-fallback (SHADER-COMPUTED-IJ-NO-PERVERTEX) #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 rdna2spirv: computed I/J pairs under --bary-fallback (SHADER-COMPUTED-IJ-NO-PERVERTEX) #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

🤖 Generated with Claude Code

Dashhhhhhhh and others added 2 commits November 24, 2026 18:58
Those pixel shaders were refused under both fallbacks, so the shaders stage stopped on a geometry-capable GPU without fragmentShaderBarycentric. The barycentric fallback now supplies the three vertex values, and make_game selects it there.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ZroIsHere

Copy link
Copy Markdown
Contributor

I found one remaining coverage gap in the fallback GS builder: spirv_bary_fallback.h records both VS ClipDistance and CullDistance, then rejects the shader when both arrays are present (clip_count && cull_count, around line 188). Vulkan permits both in one stage, subject to maxCombinedClipAndCullDistances; the GS would need to forward two independent built-ins/capabilities rather than choosing one dist_builtin. This is a safe refusal today, but it leaves valid pipelines unavailable on the fallback path. Could this be tracked as a follow-up, or is mixed clip/cull intentionally outside the fallback contract? Spec: https://docs.vulkan.org/spec/latest/chapters/vertexpostproc.html#vertexpostproc-clipping

@ZroIsHere

Copy link
Copy Markdown
Contributor

I implemented this follow-up in a stacked PR against your integration branch: mrgenty#1. It forwards ClipDistance and CullDistance independently and updates the generator coverage. Local tests were not run; the PR checks should validate it.

@ecox982745

Copy link
Copy Markdown

I checked the two open test cases in the PR description on 07d069924bffc3d103a7fcd4a4eef341d4517dd7. The translated ps_ij_computed fixture and a second shader combining computed I/J with f16 location relocation both rendered through the Xbox D3D12 proxy on an RTX 4090 (Windows 11, NVIDIA 616.64).

Translated synthetic inputs Check GPU readback
vs_ids + ps_ij_computed, --bary-fallback Computed I/J from attribute 0 4,096/4,096 pixels
Same sources, both fallback flags Same reference with f16 fallback enabled 4,096/4,096 pixels
Computed I/J on attribute 0 plus low/high f16 interpolation on attribute 7 VS exports raw locations 14 and 15, which the PS requests for attribute 7's halves. The linker must relocate the pair. 4,096/4,096 pixels

All four RGBA32F channels matched bit for bit. On the mixed case the low/high channels were exactly 0.25 and 0.75, the computed channel varied by row, and the control was 0.5. Each draw passed with Khronos validation on and off. Removing only bary_fallback_input.per_vertex from the index made the same pipeline fail creation as expected. The stock CPU tests spirv_bary_fallback and shader_library also passed.

For reproduction, I built the assembly with this head's runtime/test/shaders/build.py. The draw fixture supplied just the resulting VS, PS and index, with synthetic lookup hashes for its two test containers. It did not supply an offline geometry shader. For the mixed case I added a packed 0x3a003400 at VS param7.x, raw exports at 14 and 15, and low/high v_interp_p1ll_f16 + v_interp_p2_f16 on attr7.x before the existing computed-I/J operations.

@zmasi, for the 207 refusals in your Vega report, this head includes #1426 and its runtime dependencies. If your Vulkan backend reports geometryShader=true, a before/after count with both fallback flags would test whether this covers the same class in your corpus. The geometry fallback requires that feature for drawing. My counts above cover synthetic shaders on NVIDIA.

AI-assisted with OpenAI Codex (gpt-6.2-astra).

… 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)
@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 26, 2026
@zmasi

zmasi commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

@ecox982745 — yes. The earlier Vega report and this rerun are missing exactly the same 207 pixel shaders before the change. On 07d069924bffc3d103a7fcd4a4eef341d4517dd7, all 207 are recovered.

AMD Radeon Pro Vega II (Vega 20 / gfx906), Mesa RADV 26.0.8, Ubuntu 26.04, Vulkan 1.4.335. geometryShader=true; subgroup range 64..64. Fresh output directories, the same 26,503 inputs, --f16-interp-fallback --bary-fallback on both revisions, no --wave64-emulate.

Revision Translated Passed spirv-val Refused
b0f3d399 (base before the stack) 26,296 26,296 207
07d06992 (PR head, includes #1426) 26,503 26,503 0

I compared the index entries locally: 0 previously accepted shaders lost; all 26,296 common SPIR-V modules were byte-identical. All 207 additions are pixel shaders with bary_fallback_input.per_vertex. A separate vk_pipeline_check over exactly those additions on RADV created 207/207 PS pipelines: 0 failed, 0 skipped.

That last check uses partner stubs; it is not a claim that 207 retail draws rendered correctly. Separately, a synthetic ps_ij_computed draw using the C++ builder test's matching per-vertex geometry shader passed the repository's 4,096-pixel readback check on Vega.

The full-corpus before/after RADV pipeline scan is still running. I’ll follow up here with its complete creation, failure and skip counts. Aggregate corpus results only. AI-assisted.

@zmasi

zmasi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@ecox982745 — the full-corpus Vega 20 scan has finished. Both unfiltered vk_pipeline_check runs exited 0 on the same Radeon Pro Vega II (gfx906, Mesa RADV 26.0.8, fixed subgroup 64), with --f16-interp-fallback --bary-fallback used for both translations.

Revision Shader modules created Pipelines created Pipeline failures Pipelines skipped
b0f3d399 (before the stack) 26,296 17,014 0 9,282
07d06992 (tested PR head) 26,503 17,221 0 9,282

All 207 additional pipelines were pixel pipelines: 11,894 before, 12,101 after. Compute (2,689), vertex (2,236) and geometry (195) counts were unchanged. Neither run had a shader-module failure. All 9,282 skips in each run were mesh pipelines: RADV created their shader modules, but this GPU does not expose VK_EXT_mesh_shader.

This confirms driver pipeline creation for the same 207 recovered pixel shaders. The checker uses partner stubs for graphics; these counts are not a retail draw or pixel-correctness result.

AI-assisted.

@ecox982745

Copy link
Copy Markdown

I tested the stacked mixed clip/cull change linked above. On an RTX 4090 (Windows 11, NVIDIA 616.64), the generated fallback geometry shader produced byte-identical RGBA32F readback to the direct vertex-to-fragment path in all 22 comparisons. This covers 90,112 pixel comparisons across 44 draws.

I used the generator at 096a26220f15 with synthetic vertex and fragment stages. The four clip/cull array-length pairs were (1,1), (2,1), (1,2), and (4,4). The generator at its parent, 07d069924bff (this PR), refused all four pairs before pipeline creation. On the stacked head the stock CPU test passed, all ten modules it dumped passed spirv-val --target-env vulkan1.2, and every generated stage in the draw matrix passed the same validator.

64×64 draw Expected and observed pixels painted per path
All distances positive 4,096
Last clip distance cuts the triangle in half 2,048
Last cull distance negative at every vertex, including with an active clip plane 0
Last cull distance negative at only one vertex 4,096
Two perpendicular clip planes plus a negative cull distance at one vertex 1,024

The fragment shader wrote both interpolated UV and barycentric values. The largest absolute channel error against the pixel-center formula was 5.96e−8, and the Khronos validation layer reported no errors. This check exercises simultaneous clipping and primitive culling on synthetic draws. The stacked change is still separate from the head of #1930.

@mrgenty

mrgenty commented Nov 26, 2026

Copy link
Copy Markdown
Author

Thanks @zmasi and @ecox982745 for the runs. The Vega 20 corpus numbers are the measurement this PR was missing: 207 refusals to 0, no accepted shader lost, the 26,296 common modules byte-identical and 207/207 pixel pipelines created on RADV. The 4090 draws cover the computed I/J path together with the f16 relocation, which I had only tested separately. I'm noting your caveat that this is pipeline creation, not a retail draw.

@ZroIsHere: right, the builder refuses a VS that writes both ClipDistance and CullDistance. That refusal predates this PR, so it stays out of this one. @ecox982745 already implemented it in mrgenty/leonida#1 and tested it (22/22 byte-identical on the 4090). Thanks for that. To keep one topic per PR I won't merge it into this branch. Could you open it against ubiquitarianism/leonida as its own PR, with Depends on: #1930? I'll close the one on my fork once it's up.

This branch needs a rebase on current main. I'll push it and rerun shader_library, spirv_bary_fallback and d3d12_bary_fallback on the RTX 3060.

mrgenty and others added 3 commits November 26, 2026 14:07
…pairs (RT-BARY-FALLBACK-PER-VERTEX)

A pixel shader with a computed I/J pair, translated with --bary-fallback, reads the pair's attribute as a Flat
vec4[3] at the first of three locations its index entry gives under bary_fallback_input.per_vertex. The runtime's
geometry-stage builder read only bary_fallback_input.location and refused that input ("PS pass-through Input at
Location 0 is not vec4<f32>"), so such a PSO was never created.

- shader_library.h: parse per_vertex (attribute -> first location) into ShaderEntry::bary_fallback_per_vertex; one
  malformed entry drops the whole map.
- spirv_bary_fallback.h: build_bary_fallback_gs takes the map and writes the triangle's three values of each mapped
  VS output to the PS's Flat vec4[3] (element k = vertex k, the same at every emitted vertex), as
  tools/bary_fallback_gs.py does. An attribute the VS does not export is zero-filled. A vec4[3] the map does not
  name, a block that runs into another input or the barycentric location, and two attributes at one first location
  are refused. The old signature stays as a wrapper with an empty map.
- d3d12_vulkan_device.cpp: both call sites (eager and lazy) pass the entry's map.
- Tests: spirv_bary_fallback (five per-vertex cases), shader_library (twelve per_vertex parsing cases),
  d3d12_bary_fallback (two draws of a synthetic computed-I/J PS and one refusal).
- docs/design.md: the runtime builder in the "Barycentric fallback" row, with what was and was not checked.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@ecox982745

Copy link
Copy Markdown

Opened #2304 against upstream main as a draft with Depends on: #1930. ZroIsHere wrote the implementation and generator test. My contribution was the RTX 4090 verification and upstream submission. The new PR preserves the original commit 096a26220 and links the 22 draw comparisons. I'll track the rebase there when #1930 updates.

@mrgenty

mrgenty commented Nov 26, 2026

Copy link
Copy Markdown
Author

Rebased on main 73516a29 (head now 682de289), with #1497 at its current head 53df7d1a and #1426 unchanged. The conflicts were in #1426's tools/vk_subgroup_info.py and docs/design.md, where both sides are kept; this PR's code applied unchanged. On the RTX 3060 (NVIDIA 621.24, validation on), shader_library, spirv_bary_fallback and d3d12_bary_fallback pass, and run_semantic_tests.py passes: 498 files, 6,357 tests, 0 failed.

@ecox982745 the stack is updated, so #2304 can be rebased on it. Thanks for opening it, and @ZroIsHere for the implementation. I credited ecox982745 for the code above; that was my mistake. I'm closing mrgenty#1 in favour of #2304.

@ecox982745

Copy link
Copy Markdown

Thanks for updating the stack and the attribution. I rebased #2304 locally on your exact head 682de2894. The two-file diff matches ZroIsHere’s original patch byte for byte. All 22 pairs of RTX 4090 draws matched across 90,112 pixels, and all ten generated shaders passed SPIR-V validation.

The remaining step is publishing that rebase. GitHub rejected the branch update because it carries upstream workflow changes and the connected OAuth credential lacks the required permission. The public draft still points to 096a26220. Anyone reviewing the combined tree can reproduce it by cherry-picking that commit onto 682de2894. Results and integration status.

… linking (RT-BARY-FALLBACK-PER-VERTEX)

With both --bary-fallback and --f16-interp-fallback, create_graphics (and the lazy stage_words) links the f16
halves into the VS before the geometry stage is built. Linking may place a decoded half on a Location no raw VS
output used; when that Location is a computed-I/J attribute the VS does not export, build_bary_fallback_gs read the
half as that attribute and forwarded it instead of zero-filling the array.

- link_f16_halves can return the Locations of the VS's raw outputs as they were before linking, and
  build_bary_fallback_gs forwards a computed-I/J attribute only from one of them. Both call sites pass the set when
  the halves were linked.
- link_f16_halves also keeps halves off the second and third Locations of a per_vertex vec4[3] block, which has a
  Location decoration on its first only.

spirv_bary_fallback_test 7f-7h: a relocated half and a static half on a missing attribute's Location (zero-filled;
without the set the half is forwarded), and a block whose third Location linking would otherwise choose (the
builder refused it).

Reported, with a GPU reproduction, by @marcelofrayha in #2; the fix follows his commit 7f63a48,
and the block reservation his bdff821, adapted to this branch without the geometry-input packing.

Co-authored-by: Marcelo Frayha <marcelofrayha@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mrgenty

mrgenty commented Nov 26, 2026

Copy link
Copy Markdown
Author

Pushed 0b753295 with a fix @marcelofrayha found and reproduced on a GPU (mrgenty#2): with both fallbacks on, f16 linking can put a decoded half on the Location of a computed-I/J attribute the VS does not export, and the geometry stage then forwarded that half instead of zero-filling the array. link_f16_halves now returns the VS's raw output Locations from before linking, and the builder forwards an attribute only from one of them. Linking also keeps halves off all three Locations of a vec4[3] block, not just the first. The commit follows his 7f63a4876 and the block-reservation part of bdff821c1, with him as co-author.

Tested on the RTX 3060 (validation on): shader_library, spirv_f16_halves, spirv_bary_fallback (new cases 7f–7h; 7f also checks that the half is forwarded without the fix, and 7h fails if the block reservation is removed), d3d12_f16_halves and d3d12_bary_fallback pass, and the 12 dumped modules pass spirv-val for Vulkan 1.2 and 1.3.

@zmasi

zmasi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@mrgenty — verified 0b753295 against its immediate parent 682de289 on Radeon Pro Vega II (gfx906, Mesa RADV 26.0.8) with both fallbacks. At Vega’s geometry-stage half-location ceiling of 14, one more synthetic pipeline drew, and three previously wrong draws became correct.

Synthetic collision cases (64×64) 682de289 0b753295
Relocated high half, relocated low half, static VS half (7f/7g) 3 pipelines drew; 0/12,288 pixels matched 3 drew; 12,288/12,288 matched
Three-location per-vertex block (7h) C++ builder refused it; no driver call Pipeline drew; 4,096/4,096 matched

These were native Vulkan readbacks using the revision’s C++ f16 linker and fallback GS builder, not the Windows D3D12 proxy. Separately, the original 207 recovered pixel shaders still translated, passed spirv-val, and created 207/207 RADV pipelines (0 failed, 0 skipped). That was the targeted cohort, not a new full-corpus scan.

AI-assisted.

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>
@ecox982745

Copy link
Copy Markdown

When bringing the new geometry-limit checks from #1497 into #1930, the per-vertex arrays need to count towards those limits. I tested #1497 at 961d719d54 combined with #1930 at 0b7532951f. Git merges spirv_bary_fallback.h cleanly (blob 6bf9da14bb), but the resulting builder reports a footprint smaller than the geometry shader it emits.

CPU check. With the barycentric vector at location 3, a VS attribute at 16, and its computed-I/J vec4[3] block starting at 14, the builder reported input/output location bounds of 0/15 components. The emitted SPIR-V requires 68/68: the input occupies location 16 and the output spans locations 14–16. A 64-component profile would therefore pass the new precheck. Moving the attribute to 15 and the block to 13 gives a legitimate 64/64 boundary case.

Counting inputs from the final id_in_loc map includes attributes used only by computed I/J and counts a shared ordinary input once. On output, each emitted id_out_pv array adds 12 scalar components per vertex and occupies locations base through base + 2, even when zero-filled. A local adjustment to those counts matched independent SPIR-V reflection in five fixtures and kept all five generated shaders byte-identical.

RTX 4090 check. This card reports limits of 128 input and 128 output components. All five synthetic fixtures rendered the expected values across 20,480 pixels with Vulkan validation enabled. The 64-component comparison was CPU-only. The emitted modules also passed spirv-val for Vulkan 1.2 and 1.3.

I tested the merged builder in isolation. The full merge still has conflicts in the runtime and two test files. In the D3D12 test, several fixture program IDs overlap across the two branches (for example, vs_10p_prog and vs_ij_prog have identical input bytes); giving those distinct IDs will keep both cases independently testable. AI-assisted verification.

@zmasi

zmasi commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

@ecox982745 — confirmed the merged-builder limit issue on a real 64-input-component device. Vega 20 reports geometry limits of 64 input, 128 output, 1,024 total output components (RADV Mesa 26.0.8).

For the merged header 6bf9da14bb (#1497 961d719d + #1930 0b753295), attribute 16 with the block at 14 reported location bounds 0/15; independent reflection of the emitted GS gave 68/68. The merged precheck would admit it. That case was CPU-only: no over-limit module went to the driver. At the legal edge (attribute 15, block 13–15), reflection gave 64/64, the pipeline was created, and 4,096/4,096 pixels matched. Counting the final input map and all three locations of each emitted block matched reflection in all five fixtures.

This is an integration issue in the combined header, not a new failure of either standalone head.

AI-assisted.

# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
#	runtime/test/d3d12_bary_fallback_test.cpp
#	runtime/test/spirv_bary_fallback_test.cpp
…(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.
@mrgenty

mrgenty commented Nov 27, 2026

Copy link
Copy Markdown
Author

Updated: merged #1497 at 961d719d and main 3d6050b9, then c6aa3894 counts the computed-I/J blocks in #1497's geometry-limit check, as @ecox982745 and @zmasi worked out. Inputs come from the GS's final Input map, and each block adds its three output Locations (12 components), zero-filled or not. The 16/14 case now reports 68/68 and the 15/13 edge 64/64; the new test 7i fails with the old count. The overlapping D3D12 fixture IDs now differ (vs_ij 0x5653ba06, ps_ij* 0x5053ba06..08).

RTX 3060, NVIDIA 621.24, validation on: shader_library, spirv_f16_halves, spirv_bary_fallback, d3d12_f16_halves and d3d12_bary_fallback pass (all of #1497's cases and ours), the 13 dumped modules pass spirv-val for Vulkan 1.2 and 1.3, and run_semantic_tests.py passes (502 files, 6,393 tests). Not tested on a 64-component device here: this card reports 128/128.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 27, 2026
@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

@mrgenty @ecox982745 — tested c6aa3894 on physical gfx906, RADV Mesa 26.0.8 (geometry limits: 64 input / 128 output / 1,024 total output components). The 68-input refusal works. The nominal 64-input edge draws correctly, but is not validation-clean.

Computed-I/J case Result on hardware
15/13, location end 64 Non-null PSO, successful driver pipeline, 256/256 pixels matched (center RGBA 112, 135, 112, 49). spirv-val passed. Khronos validation 1.4.341 reported VUID-RuntimeSpirv-Location-06272 once: it counts the four built-in Position components in addition to the occupied location end.
16/14, location end 68 E_NOTIMPL, null PSO, zero geometry modules and zero graphics pipeline calls, in both eager and lazy modes.
14/12, location end 60 A separate hand-written fixture translated with both --bary-fallback and --f16-interp-fallback: computed I/J plus another f16 varying. Eager and lazy each matched all 256 expected pixels (center RGBA 191, 48, 135, 135), with zero validation messages. Its 16/14 counterpart also refused before a geometry module or pipeline.

The practical remaining boundary is the built-in accounting in the geometry precheck, not a pixel mismatch. Layer check in the tested SDK · interface limit in the spec. I did not resubmit the flagged module.

AI-assisted.

mrgenty and others added 3 commits November 28, 2026 11:00
Search for the lowest available block of three until one is found. The number of occupied locations does not bound the start of the first free block. Exercise two computed attributes after sparse reads at locations 0, 1, 2, 4, 6 and 8.

Reported in ProjectLeonida#1608 (issuecomment-7234323048).

AI-assisted-by: OpenAI Codex (GPT-6)
(cherry picked from commit d1361e9)
…-BARY-FALLBACK-PER-VERTEX)

The Khronos validation layer checks VUID-RuntimeSpirv-Location-06272 for a geometry shader as the last
interface slot plus the components of its built-in variables (sl_spirv.cpp, SDK 1.4.341), so the fallback GS's
Position (4) and any forwarded ClipDistance/CullDistance count on top of the Location end. The precheck compared
the Location end alone: a block at 13..15 (end 64) passed on a 64-component device and drew correctly, but the
layer reported 06272 (68 components).

BaryFallbackGsInfo gains builtin_components (4 + dist_count), and the precheck refuses a stage whose Location end
plus built-ins is above maxGeometryInput/OutputComponents. spirv_bary_fallback_test 7i checks the 68 of the 13..15
block, the 64 edge at 12..14 and a ClipDistance[2] adding 2.

Reported by @zmasi on a Vega 20 (RADV) in ProjectLeonida#1930.
@mrgenty

mrgenty commented Nov 28, 2026

Copy link
Copy Markdown
Author

Updated, thanks @zmasi and @ecox982745:

  • 32b2d6e66 counts the built-ins in the geometry-limit check. The layer adds the components of the GS's built-in variables to the last interface slot (the line you linked), so the fallback GS's Position (4) and any forwarded Clip/CullDistance now count on top of the Location end. On a 64-component device the 15/13 case (64 + 4) is refused like 16/14, and 14/12 (60 + 4) is the edge. Test 7i checks those and a ClipDistance[2] adding 2.
  • 9a51aff6d is @ecox982745's d1361e9c for the sparse-location StopIteration that @zmasi reported in Coordinating who works on what (continued from #14) #1608, cherry-picked unchanged.
  • fcfc1eefd merges main 33db04a7 (the conflict was docs/design.md: kept both rows).

RTX 3060, NVIDIA 621.24, validation on: shader_library, spirv_f16_halves, spirv_bary_fallback, d3d12_f16_halves and d3d12_bary_fallback pass, the 13 dumped modules pass spirv-val for Vulkan 1.2 and 1.3, and run_semantic_tests.py passes (506 files, 6,407 tests, including the new sparse-location test). Not tested on a 64-component device here.

@github-actions github-actions Bot added needs rebase Conflicts with the base branch: rebase it on main and removed needs rebase Conflicts with the base branch: rebase it on main labels Nov 28, 2026
main now lowers a computed I/J pair under --f16-interp-fallback alone with quad derivatives (ProjectLeonida#2239), while this
branch lowers it under --bary-fallback (alone or with --f16-interp-fallback) from the Flat vec4[3] its geometry
shader fills. The two cover different modes, so the merge keeps both: the per-vertex path when --bary-fallback is on
or there is no f16 fallback, Gen.ij_quad_eval otherwise, and no refusal of a computed pair in either. build.py,
check.py and run_gpu_tests.py build and run ps_ij_computed in every mode, and the tests that expected a refusal
under one of the fallbacks check the translation instead. Also keeps main's bary_fallback_gs validation, driver
version in vk_subgroup_info and <memory> in shader_library.h.
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
@mrgenty

mrgenty commented Nov 29, 2026

Copy link
Copy Markdown
Author

Merged main cc0f662a (0ce4df8a). #2239 now lowers a computed I/J pair under --f16-interp-fallback alone with quad derivatives, and this PR lowers it under --bary-fallback (alone or with the f16 fallback) from the geometry shader's Flat vec4[3]. They cover different modes, so the merge keeps both and refuses a computed pair in neither: the per-vertex path when --bary-fallback is on or there is no f16 fallback, Gen.ij_quad_eval otherwise. build.py, check.py and run_gpu_tests.py build and run ps_ij_computed in every mode, and the two tests that expected a refusal under one of the fallbacks (ours for the f16 one, #2239's for --bary-fallback) now check the translation. @zmasi, in case you want to look at the resolution in tools/rdna2spirv.py.

RTX 3060, NVIDIA 621.24, validation on: run_gpu_tests.py --filter ps_ij_computed passes in all four modes (no fallback, --bary-fallback, both, --f16-interp-fallback alone); shader_library, spirv_f16_halves, spirv_bary_fallback, d3d12_f16_halves and d3d12_bary_fallback pass and the 13 dumped modules pass spirv-val; run_semantic_tests.py runs 529 files and 6,532 tests with the same 4 failures as main cc0f662a alone (2 in test_valu_cvt_f16_int16_mods, 2 in test_interp_computed_ij_fallback).

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.

7 participants