Skip to content

runtime: limit bary fallback inputs to used PS values - #1

Closed
ZroIsHere wants to merge 2 commits into
robot00f:feat/rt-bary-fallback-psofrom
ZroIsHere:fix/bary-fallback-only-required-inputs
Closed

ZroIsHere wants to merge 2 commits into
robot00f:feat/rt-bary-fallback-psofrom
ZroIsHere:fix/bary-fallback-only-required-inputs

Conversation

@ZroIsHere

Copy link
Copy Markdown

Claimed: RT-BARY-FALLBACK-ONLY-REQUIRED-INPUTS

Depends on: ProjectLeonida#1497

The translator declares interpolant locations from the FSSM table even when the pixel shader never loads them. The synthesized geometry stage was reading those locations from every vertex, which can exceed maxGeometryInputComponents on devices with a 64-component limit. Keep all PS interface outputs matched, but zero-fill declared inputs with no load and read only statically loaded values from the VS.

Validation: git diff --check passed. Tests/build not run.
GPUs tested: none (static runtime change).
AI-assisted: yes.

robot00f and others added 2 commits November 25, 2026 11:26
… 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)
@ecox982745

Copy link
Copy Markdown

Case 3 still fails with a 64-component geometry input limit at 83c0c6813. The runtime runs out of locations in link_f16_halves, before it calls build_bary_fallback_gs. I compared the head with its parent 483f0128e using the synthetic d3d12_bary_fallback CTest on an RTX 4090 (Windows 11, NVIDIA 616.64).

What the runtime sees Parent PR head
Native 128 geometry input components All three draw cases passed All three passed
64 geometry input components, original fixture Cases 1 and 2 passed. Case 3 refused pipeline creation Same results and diagnostic
64 components, two unused locations freed in the fixture before linking — All three passed, including 256/256 expected pixels in case 3

For the 64-component runs I wrapped the test's VulkanDeviceInfo::get_instance_proc and changed only limits.maxGeometryInputComponents in the result of vkGetPhysicalDeviceProperties. Geometry output stayed at its native 128. Each result repeated with Khronos validation on and off. This exercises the runtime's limit handling on NVIDIA. A rerun on the original RADV hardware is still needed.

The diagnostic on both commits was f16_halves: need 2 free locations in 0..14, only 0 available. In the control I omitted unused raw locations 12 and 13 from both case-3 fixture shaders, including their VS stores, leaving its actual pixel calculations unchanged. This gave the linker two usable slots and the readback passed. A fix for this case needs to free or remap unused locations before half-location allocation.

Separately, the stock CPU test spirv_bary_fallback passes on the parent and fails at line 371 on this head. Its build_ps helper declares inputs 0 and 2 but never loads either, while the assertion expects both to be forwarded. Giving the fixture one loaded and one unloaded input would exercise the new behavior explicitly.

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

@robot00f

Copy link
Copy Markdown
Owner

Incorporated (with Co-authored-by attribution and extended pointer-alias/limit coverage + unit/GPU tests) in 961d719 on ProjectLeonida#1497 — thank you @ZroIsHere!

@robot00f robot00f closed this Nov 27, 2026
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.

3 participants