BDA reads that cross a range boundary crash agc_driver_bda_device_tests on lavapipe #1044
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-07T03:09:50Z.
agc_driver_bda_device_tests(tests/BdaDevice.cppwithtests/BdaExecution.cpp) is built but not registered in ctest, and on main (ab9437e3) it segfaults on lavapipe inside the JIT-compiled compute shader ofRunBdaExecutionTests.Adding a print before each
run(...)shows the first two cases pass and the third one crashes:That case is a 32-bit
LoadAddressU32atguest + 1that straddles the two ranges of the test table:firstcoversguest .. guest + 3with a 3-byte buffer andsecondcoversguest + 3 .. guest + 5. The test expects the four bytes to be assembled from both buffers (0x22 0x33fromfirst,0x44 0x55fromsecond). The crash suggests the generated code reads all four bytes through the pointer of the first range, which runs past the end of its 3-byte buffer. A real GPU may just read whatever follows in memory, so it could go unnoticed there, but the result would still be wrong for a read that crosses a range boundary.The shader comes from the real BDA path (
DefineGetBdaPointerand theLoadAddressU32emitter inSpirvBackend), not hand-written test SPIR-V, so this looks like a product issue rather than a stale test. I haven't checked on hardware, and I couldn't tell whether cross-range reads are meant to be supported or should report a fault. If they're meant to work, this test is the reproduction, and registering it in ctest would catch regressions on lavapipe in CI.Imported from boykopovar/AnyPS5. Originally posted by Adin-bima on 2026-10-07T08:13:42Z.
Does not reproduce here on main
80d4f6b7: agc_driver_bda_device_tests passes 30/30 on lavapipe (Mesa 25.2.8, LLVM 20.1.2, forced with VK_DRIVER_FILES and confirmed llvmpipe via VK_LOADER_DEBUG), including the run(guest + 1, 32, 0x55443322, 0) case, and also passes on an RTX 5070 Ti (595.91.07). Could the crash depend on the Mesa/LLVM version in CI, or on where the 3-byte buffer is placed?Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-07T11:34:58Z.
Adding a third data point, because it lands between the two of you and explains the disagreement.
It reproduces here, on
main, with lavapipe Mesa 26.2.4 / LLVM 23.1.1:So the matrix is now:
That makes it track the Mesa/LLVM version rather than the emitter being unconditionally wrong: the same generated shader passes on the older llvmpipe and on real hardware, and faults on the newer llvmpipe.
What the crash looks like under gdb:
The fault is on an llvmpipe worker thread, and
0x7ffff6495938is mapped — it falls inside an anonymous 0x7ffff6495000-0x7ffff64a2000 region, one of the 80 anonymous mappings in the process, i.e. the JIT'd shader rather than the test's own code. The frames above it are gone (return address 0), so this is the bottom of the fault, not an unwind through AnyPS5 code.@NahuelGenchi's reading — a 32-bit load assembled through the first range's 3-byte pointer — is consistent with that, but the version split means I would not conclude the emitter is wrong from this alone. It could equally be llvmpipe 26.2.4/LLVM 23 mis-JITting the address arithmetic, which is what the older driver passing suggests.
On registering it in ctest: I would not do that unconditionally. The CI runner image's Mesa is a third version again, and this test proves the outcome swings with it — registering it as-is would make the Linux job fail or pass depending on the runner image, which is the kind of flake #1012/#1028 just went to some trouble to make visible. If it is worth running, it wants to be gated on the driver version, or run only where it is known to pass.
Happy to bisect the Mesa/LLVM axis further if that would settle which side is at fault — the package (
vulkan-swrast3:26.2.4) is a self-contained tarball, so several versions can be extracted side by side without touching the system.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-07T14:29:39Z.
Reproduced deterministically — the variable is the driver's CPU-capability target, not the Mesa/LLVM version.
I can turn this crash on and off on one machine, one build, one SPIR-V, with
GALLIUM_OVERRIDE_CPU_CAPS(lavapipe Mesa 26.2.4 / LLVM 23.1.1):GALLIUM_OVERRIDE_CPU_CAPSavx(what CI sets)sse2sse4_2avx2avx512fThat this is the driver and not the emitter is provable, not inferred: the module AnyPS5 emits is byte-identical under every one of those settings, because
GALLIUM_OVERRIDE_CPU_CAPSis a Gallium variable and nothing in the tree reads it (grep -rn GALLIUM core/ tools/is empty). Dumping the test's own shader under each setting:One module in, five behaviours out. The fault is in llvmpipe's generated code, not in what we hand it.
Which case, and where it faults. It is the third
run—run(guest + 1, 32, 0x55443322, 0), the cross-range dword — as you reported; I confirmed it by printing before eachrun(the first two print, it dies on the third). In gdb:0x7ffff6495938is inside one of the process's anonymous mappings — the JIT'd shader — and the load is from a null address, reached from llvmpipe's masked-gather lowering (vmovdqa %ymm3,0x860(%rsp)…mov 0x860(%rsp,%rsi,8),%rcx…vpbroadcastd (%rcx)).On the two readings in the report. Both are ruled out by the above:
EmitBdaByte— theOpBranchConditional mappedinSpirvBdaRead.cpp), and the cross-range span does not even reach that path:probe_bda_pointerreturns 0 for a span that leaves its range, so the byte fallback runs, and there all four bytes are mapped. The null llvmpipe loads through is one it manufactured.avxversusavx2on this box: what decides it is the ISA llvmpipe compiles the shader for.Localized to the probe. With
APS5_BDA_BYTE_READS=1— which omitsprobe_bda_pointerentirely — the same run passes underavx(0/5), while with the probe it segfaults 5/5. So it is llvmpipe's codegen for the probe's binary-search loop, not the byte loads.Still live on
main. I rebuiltagc_driver_bda_device_testsat3c054008(which includes #1043) and it is unchanged:avxandsse2still segfault 5/5, the others pass, same instruction, samercx=0.On registering it in ctest. This is now the part that needs a decision, because CI sets exactly the crashing value. If the runner's llvmpipe shares this codegen, registering the test makes the Linux job fail deterministically — and #1012/#1028 exist precisely so a job does not report green while tests do not really run. I would not register it unconditionally; it wants a driver fix first, or a gate on the driver. I am filing the driver bug separately.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-07T16:00:27Z.
Following up my previous comment: the driver bug is filed upstream as mesa/mesa#16515, and because the crash reproduces from the dumped shader alone I packaged it self-contained — the test's
.spvplus a ~250-line Vulkan harness, no AnyPS5 code:https://github.com/Dextroid17/llvmpipe-caps-crash
The harness takes the
SPIR-Vmodule and runs it underGALLIUM_OVERRIDE_CPU_CAPS, so the driver-side claim is checkable without this tree (avx/sse2→ SIGSEGV,sse4_2/avx2/avx512→ output0x55443322, identical module every time).That is also the answer to the ctest question for now: register
agc_driver_bda_device_testsonly after the driver is fixed, or behind a gate, since CI sets exactly the crashingGALLIUM_OVERRIDE_CPU_CAPS=avx. Registering it as-is would make the Linux job fail deterministically on this codegen.Imported from boykopovar/AnyPS5. Originally posted by polysius on 2026-10-07T17:51:58Z.
I looked into this, and I think the crash is a lavapipe bug rather than a read through the wrong range.
Setup. A debug branch on my fork builds only
agc_driver_bda_device_testsonubuntu-latestand runs it on the lavapipe CI installs: Mesa25.2.8-0ubuntu0.24.04.4, withGALLIUM_OVERRIDE_CPU_CAPS=avx. I also ran the same binary on a Qualcomm Adreno X1-45 (Windows, MinGW GCC 15.2.0). Every variant below changes onlyEmitBdaDwordReads, behind a debug switch. Results forrun(guest + 1, 32, 0x55443322):mainrax = rcx = rdx = rsi = 0)APS5_BDA_BYTE_READS=1(no probe)0, as expected for a span that crosses ranges0bdaStopsInvocations = false(no early return in the byte path)Volatileon the wide loadsSo the probe returns 0,
mapped && alignedis false, and the shader still faults whenever the untaken branch contains a load through that null pointer. The SPIR-V only loads through it under that condition, so nothing should be dereferenced. #1043 reports these cases passing on NVIDIA and on Mesa 26.2.4 lavapipe on Windows.What lavapipe does. In
visit_load_global(src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c), a load whose address divergence analysis marks uniform becomes a scalar load with no exec-mask check. Small if-sides are flattened bylp_should_flatten_cf_list, so they run under the mask without a real branch. Here the address is uniform and the wide side is small, so the load runs with the mask empty.This came in with a57e8b2e (!32963, Mesa 25.1). It's still open upstream:
The code path is the same in 26.2.4, so the pass there is probably a different NIR shape, not a fix.
Options I see:
agc_driver_bda_device_testsout of ctest until CI's lavapipe has the fix.OpSelectionMerge, e.g.OpSelect(wide, physical, dummy), as mesa#16217 suggests. That needs a device address the shader can always read, such as a zero page the host adds to the BDA table. That's an ABI change, and it would also protect titles' BDA reads on lavapipe.Which would you prefer? I can send a PR for any of them.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by polysius on 2026-10-07T17:53:38Z.
Sorry, I posted that without seeing @Dextroid17's comments above. You had already shown this is driver-side and filed mesa/mesa#16515.
Two corrections to mine:
avx/sse2and passes withsse4_2/avx2/avx512. Together with themov 0x860(%rsp,%rsi,8),%rcx; vpbroadcastd (%rcx)sequence, that points at the per-lane masked-gather lowering, so please treat my explanation as unconfirmed.mapped && alignedbranch are replaced by constants. So the faulting load is the wide-branch load through the probe's null result, run under an empty mask.mesa#16217 (a BDA pointer dereferenced in a loop that never runs) and mesa#15667 might be the same bug as #16515, if that helps upstream.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T08:26:21Z.
Closing: the shader is valid and passes everywhere except lavapipe with the
avx/sse2CPU caps, so it's the driver (mesa/mesa#16515). The test can be registered once Mesa fixes it; comment here if it fails on another driver.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T20:23:55Z.
I carried the focused cross-range regression test onto current
mainin fork branchcodex/fix-bda-cross-range-timeout, without opening a PR.The test is registered separately as
agc_bda_cross_range, has a 30-second timeout, and returns CTest's skip code on CPU Vulkan devices. This avoids running the known lavapipe CPU-cap case described above; on a hardware Vulkan device it exercises the cross-range shader path. The target builds locally and conventions pass. On this host CTest reports the test as skipped because only a CPU Vulkan device is available, so I have not validated the cross-range read on GPU hardware.