Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e7987db
Translate computed I/J pairs when a GPU has no per-vertex inputs.
Dashhhhhhhh Nov 24, 2026
b9191a3
Merge remote-tracking branch 'origin/main' into fix/computed-ij-no-pe…
Dashhhhhhhh Nov 25, 2026
53df7d1
runtime/d3d12: synthesize --bary-fallback geometry shader in graphics…
robot00f Nov 25, 2026
d36d9ef
Merge #1497 into rt-bary-fallback-per-vertex
mrgenty Nov 26, 2026
52d6df8
Merge #1426 into rt-bary-fallback-per-vertex
mrgenty Nov 26, 2026
682de28
runtime/d3d12: the --bary-fallback geometry stage feeds computed I/J …
mrgenty Nov 25, 2026
0b75329
runtime/d3d12: computed I/J reads only the VS's raw outputs after f16…
mrgenty Nov 26, 2026
9ecd526
Merge remote-tracking branch 'origin/main' into feat/rt-bary-fallback…
robot00f Nov 27, 2026
961d719
runtime/d3d12: prune unread bary-fallback PS inputs and enforce GS co…
robot00f Nov 27, 2026
cc5ccff
Merge #1497 (961d719d) into rt-bary-fallback-per-vertex
mrgenty Nov 27, 2026
bb49e3a
Merge main (3d6050b9) into rt-bary-fallback-per-vertex
mrgenty Nov 27, 2026
c6aa389
runtime/d3d12: count computed-I/J blocks in the geometry-limit check …
mrgenty Nov 27, 2026
fcfc1ee
Merge main 33db04a7 into rt-bary-fallback-per-vertex
mrgenty Nov 28, 2026
9a51aff
rdna2spirv: find contiguous per-vertex locations across sparse inputs
codex Nov 28, 2026
32b2d6e
runtime/d3d12: count the GS built-ins in the geometry-limit check (RT…
mrgenty Nov 28, 2026
fefb586
Merge main 1a7a30b4 into rt-bary-fallback-per-vertex
mrgenty Nov 28, 2026
2ed4c2d
Merge main d48a957b into rt-bary-fallback-per-vertex
mrgenty Nov 28, 2026
0ce4df8
Merge main cc0f662a into rt-bary-fallback-per-vertex
mrgenty Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/design.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,9 @@ llvmpipe and some other drivers. Where the device lacks it those four are skippe
To test the fallback that runs them anyway, set `LEONIDA_BARY_FALLBACK=1`, **for both `build.py` and `check.py`**
(or for `run_gpu_tests.py`; CI does this on llvmpipe). The shaders are then translated with `--bary-fallback` and
drawn through a pass-through geometry shader that supplies the barycentrics (`docs/design.md`, "Barycentric
fallback"), so the device needs geometry shaders instead.
fallback"), so the device needs geometry shaders instead. `ps_ij_computed` (a computed I/J pair) also
runs that way: the geometry shader passes it the three vertices' values of the attribute, with or without
`LEONIDA_F16_INTERP_FALLBACK`; only that fallback on its own (Macs) skips it.

`ps_interp_f16_high` and `ms_f16_pack` read 16-bit interpolants as `PerVertexKHR` inputs, which need the extension
too and which `--bary-fallback` can't express. With `LEONIDA_F16_INTERP_FALLBACK=1` they read halves the producer
Expand Down Expand Up @@ -915,6 +917,7 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin
| `ps_imgatomic` fails in about two of three runs on a Mac with MoltenVK 1.4.2: 1 to 6 of the 256 image-atomic texels are wrong while the render target is exact, for example `2D umax texel 48: got 0x00000d45, want 0x00000dc7` | MoltenVK 1.4.2 lowers the four `OpAtomic*` on image texels to Metal's texture atomics (`atomic_fetch_max`, `atomic_fetch_min` and `atomic_fetch_or` on `access::read_write` textures), and the texels read back the way a read-modify-write that is not atomic between two groups of fragment threads leaves them. A wrong `umax` texel always holds the id of one of its own 64 pixels, the largest of only some of them: on an Apple M5 it was the last pixel of the texel's first four rows in 43 of 90 cases, with all 32 larger ids gone. A wrong `umin` texel mirrors that (the first pixel of its last four rows in 39 of 48). The `or` image did not differ in 150 runs there. It is not the translator's first-lane broadcast of the descriptor index (54 of 60 runs fail with the index used directly) and not the readback (42 of 60 fail with the copies in a submission of their own after the draw). Measured on an Apple M5 (macOS 27.2.1, 101 of 150 runs fail) and an M5 Pro (#543) | Expected with MoltenVK 1.4.2. KosmicKrisp passed the same module and binary 10 times of 10 on the M5 Pro (#543). The macOS CI job does not reach it: on the runner's paravirtual device the test skips because its bindless set does not fit the descriptor limits. Do not weaken the test's expected texels |
| `gs_tri` and `ms_tri` fail on a Mac | MoltenVK has no geometry stage and no `VK_EXT_mesh_shader` | Current `main` reports them as skipped |
| With `LEONIDA_W64_EMULATE=1` on llvmpipe, the `ms_*` tests fail. Measured with Mesa 26.3.1: on x86_64 at 256-bit vectors (the default there) all six abort with "LLVM ERROR: Cannot emit physreg copy instruction"; on arm64 (128-bit) `ms_tri` draws nothing (the frame stays at the clear color); on x86_64 at 128 bits (`LP_NATIVE_VECTOR_WIDTH=128`) `ms_tri` happened to draw correctly, but with Mesa 26.0.3 `ms_wave_info_s3` and `ms_v5_workgroup` draw nothing there (4 of 6 pass, [measured by @TreXito](https://github.com/ItsNotRexed/Leonida/pull/3838#issuecomment-7086696759)) ([measured runs](https://github.com/ItsNotRexed/Leonida/issues/3127#issuecomment-7086469679)) | An llvmpipe bug: a mesh shader's runtime `CullPrimitiveEXT` is stored through an invalid `bitcast <N x i1> to <N x float>` (TEST-782, #3127; see "Without a GPU: Mesa llvmpipe") | Run the mesh tests on llvmpipe without `LEONIDA_W64_EMULATE`, or add `LEONIDA_MESH_COMPUTE=1` (the compute fallback): with it all 6 `ms_*` pass emulated on llvmpipe (x86_64, 256-bit) |
| `ps_ij_computed` is skipped on a Mac, with or without `LEONIDA_BARY_FALLBACK=1` ("computed I/J pairs need per-vertex inputs", or `unsupported: no geometryShader`) | A computed I/J pair needs the three vertices' values of the attribute: `PerVertexKHR` inputs, or under `--bary-fallback` the geometry shader that passes them (`docs/design.md`, "Barycentric fallback"). MoltenVK has neither, and `--f16-interp-fallback` alone has no per-vertex inputs | Expected; nothing to do. Devices with geometry shaders (NVIDIA Pascal, for one) run it with `LEONIDA_BARY_FALLBACK=1` |
| On a Mac, `valu_fuzz.py --family f16` reads `+0` where the model wants `-0`, from a multiply whose exact product is -0 (`v_mul_f16`, `v_pk_mul_f16`) or from an FMA whose product and addend are both -0 (`v_fma_f16`, `v_fmac_f16`, `v_pk_fma_f16`) | MoltenVK computes a `NoContraction` multiply as `fma(l, r, +0)`, which drops the sign. MoltenVK 1.4.2 and `main` up to at least `5189f8de` are affected (SHADER-182, [design notes](design.md#translator-status-and-runtime-contract)) | Expected with these MoltenVK versions. To run the rest of the fuzzer clean, add `--skip-op` for each of the five ops. To see them match, install Homebrew's `mesa` and use its KosmicKrisp driver: `LEONIDA_VULKAN_LOADER=/opt/homebrew/opt/vulkan-loader/lib/libvulkan.1.dylib VK_DRIVER_FILES=/opt/homebrew/share/vulkan/icd.d/kosmickrisp_mesa_icd.aarch64.json python3 -I tools/valu_fuzz.py --family f16 --build runtime/build/linux`. Or build MoltenVK with SPIRV-Cross `300681bb` or newer in `ExternalRevisions/SPIRV-Cross_repo_revision`, and point `LEONIDA_VULKAN_LOADER` at its `libMoltenVK.dylib` |
| A pixel shader exporting non-canonical f32 NaNs reads back `0x7fc00000` from an RGBA32F color attachment | KosmicKrisp (Mesa 26.3.1), reproduced on Apple M3 Max, M2 Ultra and M1 Pro ([#3125](https://github.com/ItsNotRexed/Leonida/issues/3125)): `nir_to_msl` emits `(NAN)` for `float`-typed NaN constants (`MESA_KK_DEBUG=msl`); MoltenVK 1.4.2 preserved both tested payloads on the same hardware | `ps_nan_payload` allows the measured canonical word only for the NaN channels and only when `vk_harness` reports `driver: KosmicKrisp`. Finite channels and other drivers still require exact words. Integer or storage-buffer readback still canonicalizes constants that NIR infers as `float` (see the `cs_bvh` row below). |
| `cs_bvh` and `cs_bvh32` fail on a Mac with KosmicKrisp: `out[3]` reads `0x7fc00000`, want `0xffffffff` | KosmicKrisp's `nir_to_msl` compiler (Mesa 26.3.1, measured on Apple M2 Ultra, macOS 27.3), not the translator or the buffer format. The triangle branch writes bitcast `float` words and the box branch writes `OpSelect %uint` with `0xffffffff` (`-1`) into the same VGPRs; NIR erases `OpBitcast`, type inference marks the shared register and `bcsel` as `float`, and `nir_to_msl` prints any `float`-typed 32-bit constant in the IEEE-754 NaN range (`0x7f800001..0x7fffffff`, `0xff800001..0xffffffff`) as `(NAN)` (`0x7fc00000`) | Expected with KosmicKrisp in Mesa 26.3.1; MoltenVK 1.4.2 and llvmpipe (Mesa 26.3.1) return `0xffffffff` on the same machine. Do not weaken `vk_compute_test`'s expected BVH words |
Expand Down
26 changes: 22 additions & 4 deletions make_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,15 @@ def runtime_gpu_barycentric_fallback():
return None


def runtime_gpu_geometry_shader():
"""geometryShader as tools/vk_subgroup_info.py answers for the GPU the runtime would use, or None."""
try:
v = runtime_gpu_info().get("geometry_shader")
return v if isinstance(v, bool) else None
except (AttributeError, TypeError):
return None


def barycentric_fallback_override():
"""LEONIDA_BARY_FALLBACK=1/0 forces the same barycentric path as the GPU test runner; None leaves it automatic."""
v = (os.environ.get("LEONIDA_BARY_FALLBACK") or "").strip().lower()
Expand Down Expand Up @@ -3542,6 +3551,7 @@ def main() -> int:
a.mesh_compute = keep_recorded_fallback("--mesh-compute", work)
emulate, keep_emulated = (wave64_settings(a.wave64_emulate, mesh_compute=a.mesh_compute) if "shaders" in stages
else (False, a.wave64_emulate == "auto"))
per_vertex = None
if "shaders" in stages and not a.f16_interp_fallback:
per_vertex = runtime_gpu_per_vertex()
if per_vertex is False:
Expand All @@ -3564,11 +3574,19 @@ def main() -> int:
a.bary_fallback = False
else:
bary_fallback = runtime_gpu_barycentric_fallback()
if bary_fallback is True:
log("shaders: this GPU's driver has a known BaryCoordKHR bug (Mesa ANV, or AMD's Windows driver "
"on gfx90c): translating with --bary-fallback")
# A GPU with geometry shaders but no PerVertexKHR inputs (no fragmentShaderBarycentric; #1285)
# needs the pass-through geometry shader, not only the f16-half fallback. MoltenVK has neither
# geometry shaders nor PerVertexKHR, so it stays on --f16-interp-fallback alone.
geometry = runtime_gpu_geometry_shader() if per_vertex is False else None
if bary_fallback is True or geometry is True:
if bary_fallback is True:
log("shaders: this GPU's driver has a known BaryCoordKHR bug (Mesa ANV, or AMD's Windows driver "
"on gfx90c): translating with --bary-fallback")
else:
log("shaders: the GPU the runtime would use has geometry shaders but can't take PerVertexKHR "
"inputs: translating with --bary-fallback")
a.bary_fallback = True
elif bary_fallback is None:
elif bary_fallback is None or geometry is None and per_vertex is False:
a.bary_fallback = keep_recorded_fallback("--bary-fallback", work)
if "shaders" in stages and not a.pc_tail_ubo:
need_pc = 152 if a.mesh_compute else 144
Expand Down
10 changes: 10 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,8 @@ if(BUILD_TESTING)
add_test(NAME spirv_f16_halves COMMAND spirv_f16_halves_test)
add_executable(dual_source_fragment_test test/dual_source_fragment_test.cpp)
add_test(NAME dual_source_fragment COMMAND dual_source_fragment_test)
add_executable(spirv_bary_fallback_test test/spirv_bary_fallback_test.cpp)
add_test(NAME spirv_bary_fallback COMMAND spirv_bary_fallback_test)
# Optional: skips unless LEONIDA_SHADERS names a translated work folder (<work>/shaders/spirv).
add_executable(shader_library_corpus_test test/shader_library_corpus_test.cpp)
add_test(NAME shader_library_corpus COMMAND shader_library_corpus_test)
Expand Down Expand Up @@ -3640,6 +3642,14 @@ if(TARGET Vulkan::Headers)
add_test(NAME d3d12_f16_halves COMMAND d3d12_f16_halves_test)
set_tests_properties(d3d12_f16_halves PROPERTIES SKIP_RETURN_CODE 77)

# Per-pipeline --bary-fallback GS synthesis (RT-BARY-FALLBACK-PSO): perspective barycentrics + ClipDistance + f16 halves.
add_executable(d3d12_bary_fallback_test test/d3d12_bary_fallback_test.cpp shims/d3d12_xs_device.cpp)
target_link_libraries(d3d12_bary_fallback_test PRIVATE gta6rt_d3d12_com d3d12 dxgi)
target_compile_definitions(d3d12_bary_fallback_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
target_compile_options(d3d12_bary_fallback_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_bary_fallback COMMAND d3d12_bary_fallback_test)
set_tests_properties(d3d12_bary_fallback PROPERTIES SKIP_RETURN_CODE 77)

# PresentX and the frame events on the Vulkan device (shims/xbox_present.h), checked on swapchain pixels.
add_executable(xbox_present_test test/xbox_present_test.cpp)
target_link_libraries(xbox_present_test PRIVATE gta6rt_d3d12_com user32)
Expand Down
3 changes: 3 additions & 0 deletions runtime/shims/d3d12_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ struct VulkanDeviceInfo {
bool push_constants_need_fallback = false;
// Top location for relocated f16 halves (0: read from device limits; non-zero: override for testing low-limit devices).
std::uint32_t f16_half_top_location = 0;
// Geometry shader per-vertex interface component limits (0: read from physical device; non-zero: test override).
std::uint32_t max_geometry_input_components = 0;
std::uint32_t max_geometry_output_components = 0;
// maxBufferSize and maxMemoryAllocationSize, which cap the GPU address arena (src/arena_size.h). 0: read from
// the physical device when the D3D12 device is created; a test sets smaller ones to simulate a device.
VkDeviceSize max_buffer_size = 0;
Expand Down
Loading