Repository navigation
runtime: forward mixed clip and cull distances in the fallback geometry shader - #2304
ecox982745 wants to merge 8 commits into
Conversation
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>
… 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)
# Conflicts: # docs/design.md
…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>
wavehs
left a comment
There was a problem hiding this comment.
macOS arm64 check of #2304 (RT-BARY-FALLBACK-PER-VERTEX). A translator rule, a Python geometry-shader builder and the runtime builder; the branch is far behind and does not apply to main, so what I could verify is the translator half and the generated modules.
Tested head 096a26220 (7 commits, 3 of them merges of main from when the branch was current), 533 commits behind main bdbc7e923.
It does not apply to main any more. git merge-tree --write-tree ubi/main 096a26220 exits 1 with conflicts in docs/design.md, runtime/shims/d3d12_vulkan_device.cpp, runtime/test/vk_test_device.h and tools/vk_subgroup_info.py. The branch's own diff against its merge-base (b0f3d3998, 533 commits back) fails git apply --check on main in those four plus docs/testing.md and tests/test_vk_subgroup_info.py. So a rebase is needed before CI can run it; I tested two things that can be separated:
- The translator half transplanted onto
main(tools/rdna2spirv.py,tools/bary_fallback_gs.py,tests/semantic/support.py,tests/semantic/test_interp_computed_ij.py,tests/test_shader_build_fallbacks.py,tests/test_run_gpu_tests.py,scripts/run_gpu_tests.pyapplied bypatch -p1, clean).tests/semantic/test_interp_computed_ij.py: 28 tests, OK - including theComputedIJBaryFallbackcases that compare every computed form against thePerVertexKHRpath and the geometry shader's ownspirv-val.- Whole semantic suite: 500 files / 6,373 tests / 0 files failed (main is 500 / 6,367, so the change adds 6 cases and breaks none).
tests/test_shader_build_fallbacks.py: 3 failures,tests/test_run_gpu_tests.py: 2 failures - not defects of the rule: they assert the build-side wording and selection that live in the runtime/make_game half, which I did not transplant (e.g. the test expectsper-vertex inputswheremainprintscomputed I/J pairs need PerVertexKHR inputs). They are a reminder that the whole PR has to be rebased before those suites mean anything.
- The branch tree as-is on this machine, to exercise the generator end to end. Built the macOS harness from
096a26220(vk_compute_test,vk_store_test,vk_harness) and ran the project's own runner withLEONIDA_BARY_FALLBACK=1and KosmicKrisp:274 shaders: 274 translated, 274 pass spirv-val.- Five fallback geometry shaders built:
ps_bary,ps_ij_computed,ps_persp_bary,ps_scc_mask32,ps_uniform_branch(<name>.bary_gs.spv). Each passesspirv-val --target-env vulkan1.2independently (the builder already validates them; I re-ran the check on the artefacts of this run). - Suite:
158/264 passed, 72 skipped; the five GS fixtures reportSKIP (unsupported: no geometryShader). That is the honest outcome on this device.
What this GPU cannot verify, and why it matters. vk_subgroup_info.py reports geometry_shader: false, per_vertex_inputs: false, barycentric_fallback: false for KosmicKrisp on an Apple M3 Pro: Apple GPUs have no geometry stage, so the pass-through GS this PR adds cannot be created here at all. The design row already lists "a GPU that needs the fallback" as unverified; this machine needs the fallback but cannot run it, so it does not close that gap. What I can say positively: under --bary-fallback every fixture translates, the PS values of the computed-I/J forms match the PerVertexKHR path in the mini interpreter, and all five generated GS modules are valid Vulkan 1.2 SPIR-V.
Review of the rule as far as it can be read
- Location allocation cannot collide:
assemble()rents three consecutive free locations per per-vertex attribute, excluding the attribute's own location, and rejects a block that overlaps any other input (tools/rdna2spirv.py:15798-15808); the loop's search boundlen(taken) + 3is always enough because at mostlen(taken)of its candidates can be taken. The index keeps the attribute number ininputsfor those attributes (:19199) and records the block underbary_fallback_input.per_vertex(:19206), which is what both the Python GS builder and the runtime builder consume. - The GS writes vertex k's value into element k at every emitted vertex, so the flat array is order-independent, as the docstring says; the PS then weights
P0 + I·(P1−P0) + J·(P2−P0)with its own I/J. --f16-interp-fallbackplus--bary-fallback(the Pascal combination) is covered by the new semantic cases; the 16-bit reads decode the raw words of the array rather than the producer's halves, which is the only consistent choice since there are no halves on that path.
Findings
- Rebase needed (same commit as the last one I saw for it): the file list above;
runtime/src/arena_blocks.handruntime/shims/d3d12_vulkan_device.cpphave moved under it, andtools/vk_subgroup_info.pynow conflicts, so the automatic fallback selection changes need re-checking againstmain's version after the rebase. - No macOS-executable verification of the new path. Stated above so nobody reads this as a green run: the fixture that would draw it skips on this device. A Linux run on a driver with geometry shaders but no
VK_KHR_fragment_shader_barycentric(or Pascal) remains the way to execute it; the author already reports such a check on a GTX 1060. - Small operational note: with the fallback forced on a device without a geometry stage,
run_gpu_tests.py --require-passexits 1 withno GPU tests passedbecause the only fixture skipped. That is the runner's contract, but a first-time user on Apple Silicon may read it as a failure; a line in the message when the skip isno geometryShaderwould explain it.
python -I scripts/check_no_game_data.py on the seven transplanted files: clean. I did not run the shader corpus or GPU fixtures against main (the translator change cannot be applied there beyond the files above), so no baseline deltas are claimed beyond the semantic counts.
No game files. AI-assisted.
|
I followed up on the macOS review. The full dependency stack merges cleanly with main To reproduce the tested tree, start at #1930 head
The RTX reports |
|
I tested this patch against the updated dependency in #1930, including a draw that needs both changes in the same geometry shader. Cherry-picking RTX 4090, Windows 11, NVIDIA 616.64. The synthetic vertex shader writes two clip distances and one cull distance. The fragment shader reads the per-vertex attribute at 29 alongside decoded FP16 halves of 0.25 and 0.75. I compared all four channels at every pixel of each 64 × 64 readback with the expected values.
The two FP16 channels kept their expected values in every drawn pixel, and every unshaded pixel retained the clear color. As a control I omitted the raw-export set from the generator for one full draw. The linked high half at location 29 then appeared as 0.75 instead of 0 in all 4,096 pixels. All seven draws ran with Khronos validation and produced no validation errors. The stock Retest on the updated #1930 dependency. I replayed the two commits of this draft (
The integration is local and the draft still depends on #1930. AI-assisted with OpenAI Codex (GPT-6.2 Sol). |
Check the D3D12 eight-component budget before generating a fallback geometry shader. Cover an unequal split at the limit and the first disallowed total. AI-assisted-by: OpenAI Codex (GPT-6)
|
Verified the mixed clip/cull change against the updated geometry-limit check in #1930. I applied this PR’s two-file diff at I exercised the D3D12 pipeline creation and readback path on Windows with a physical RTX 4090 (616.64). The hardware reports 128 geometry input and output components. I set both runtime limit overrides to 64. The shader used Position, five clip distances and three cull distances, which contribute 12 built-in components.
The stock CPU geometry-generator test passed. Vulkan validation reported zero errors in the five cases. The two refusal checks exercised the runtime guard. The three accepted cases exercised physical GPU rendering under the advertised limit override. AI-assisted with OpenAI Codex (GPT-6). |
Claimed in the coordination issue as RT-BARY-FALLBACK-MIXED-DISTANCES.
Depends on: #1930 (which builds on #1426).
What changed
The fallback geometry shader now forwards both
ClipDistanceandCullDistancewhen a vertex shader writes both arrays. Each array keeps its own length. This allows the rasterizer to clip part of a primitive and to cull a whole primitive.ZroIsHere wrote the implementation and CPU test in mrgenty/leonida#1. This draft brings that work upstream at the request of the #1930 author. The original commit is
096a26220. Commit3d34b0c0f5adds the combined eight-component D3D12 limit and a boundary test. Review the two-file change.Verification
I reapplied the original commit locally on top of the updated #1930 head
682de2894. The resulting commitfcbc57c0dhas a byte-identical two-file diff and merges cleanly with main at73516a290.spirv-val --target-env vulkan1.2.git diff --checkboth passed. All fixtures were synthetic.Current head and integration
At
3d34b0c0f5the generator accepts five clip distances plus three cull distances, and rejects five plus four before emitting a geometry shader. The rejection test failed on the preceding head. Microsoft's HLSL specification counts the two arrays together. Clip and cull semantics · D3D12 constantsI applied the cumulative two-file change locally to #1930 at
c6aa38942e. Only the opening header comment needed manual reconciliation. The resulting Git tree was04f4b81461e30df41db123d3617f875bd4156130. The generator's CPU test passed on both trees. All 11 modules on the published head and all 15 on the integration passed SPIR-V validation for Vulkan 1.2 and 1.3.On that integration, a synthetic 64 × 64 draw used the fifth clip distance and the third cull distance alongside the computed interpolation fallback. On Windows 11 with an RTX 4090 and NVIDIA 616.64, all 12,288 pixels matched the expected values across three draws. The full triangle covered 4,096 pixels, clipping left 2,048, and culling left zero. Khronos validation produced no messages during those draws.
The draft still depends on #1930. Only the two-file feature update is on the public branch. The earlier push that brought in upstream CI workflow changes required GitHub's workflow permission. Previous integration and hardware results
AI-assisted: Yes. The original author disclosed AI assistance. OpenAI Codex (GPT-6) added and tested the combined-limit check, performed hardware verification, and submitted the upstream draft.