Fix Nouveau reference counting with the Vinix SDK
@@ -8,6 +8,8 @@ Mesa 24.2.8 uses a native `intel_clc` to compile the built-in shaders for the x8
88
99The build-host generator’s Meson configure found LLVM 19.1.4, clang-cpp, libclc 0.2.0, SPIRV-Tools 2024.4.1 and LLVMSPIRVLib 19.1.0.0. Clang 19 compiled the generator’s `clc_helpers.cpp` with `CXXFLAGS="-O0 -g0"` on the 1 GiB worker. The configure log and compiler commands are in `xorg/llvm/work/intel-clc-02` on the release worker.
1010
11+Mesa 24.2.8's Nouveau build failed when GCC's atomic fast-integer type and the Vinix SDK's `uint_fast32_t` had different widths. The recipe uses `atomic_uint` with an `unsigned int` comparison value and builds the affected Ninja object before the rest of Mesa. The worker reproduced the original x86_64 compile error, then built and ran the corrected decrement test against the Vinix SDK on each architecture. Each probe decremented two to one and preserved one. See `foundation/mesa-nouveau-atomic-proof-01`, receipt SHA-256 `ed9f9b6416a151f6e44c6e187168ae06f8e42def55b82b12155e2fe4b3dda966`.
12+
1113Both target Mesa profiles build the Zink Gallium backend with Mesa's Vulkan headers. If a client selects Zink, the driver opens `libvulkan.so.1` at runtime. The loader is therefore a driver-specific dependency that an ELF `DT_NEEDED` scan cannot detect. The software EGL and GLX checks exercise the software Gallium backend. [Zink loader selection in Mesa 24.2.8](https://gitlab.freedesktop.org/mesa/mesa/-/blob/mesa-24.2.8/src/gallium/drivers/zink/zink_screen.c#L3293)
1214
1315## Sharing a builder
@@ -11,18 +11,23 @@ defpkgbuild(mesa,
1111 #:source, ["https://archive.mesa3d.org/mesa-24.2.8.tar.xz",
1212 "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/mesa/29401.patch",
1313 "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/mesa/23630.patch",
14- "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/mesa/riscv64-tls.patch"],
14+ "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/mesa/riscv64-tls.patch",
15+ "nouveau-atomic-refcount.patch"],
1516 #:sha256sums, ["999d0a854f43864fc098266aaf25600ce7961318a1e2e358bff94a7f53580e30",
1617 "2975b35c7cc0c66074bc38b906863c9b5da90718b2c7764f78b6486466f15061",
1718 "9f29a0cebfebdc8f9aab2452b86b289f863d128f67e197fcb5ad5a886c74dfc1",
18- "57cb89d086c4c3c0e4fbac3f84ab7409ac13df2a7c540f677d87c1ee8676076f"],
19+ "57cb89d086c4c3c0e4fbac3f84ab7409ac13df2a7c540f677d87c1ee8676076f",
20+ "7dbd1aa85acb5e818964fb44baf69bff1c3f065dee4141c8010d7975856d8438"],
1921 #:prepare, fn() {
2022 for-each(fn(file) {
2123 run("patch", "--batch", "-d", "mesa-24.2.8", "-p1", "-i", string-append("../", file))
2224 }, list("29401.patch", "23630.patch", "riscv64-tls.patch"))
25+ ; The bootstrap compiler and target libc can use different fast integer widths.
26+ run("patch", "--batch", "--fuzz=0", "-d", "mesa-24.2.8", "-p1", "-i", "../nouveau-atomic-refcount.patch")
2327 },
2428 #:build, fn() {
2529 run("vinix-mesa", "current", "mesa-24.2.8", "build")
30+ run("vinix-ninja", "build", "src/nouveau/winsys/libnouveau_ws.a.p/nouveau_bo.c.o")
2631 run("vinix-ninja", "build", "all")
2732 },
2833 #:check, fn() {
@@ -0,0 +1,24 @@
1+--- a/src/nouveau/winsys/nouveau_bo.c
2++++ b/src/nouveau/winsys/nouveau_bo.c
3+@@ -237,7 +237,7 @@
4+ static bool
5+-atomic_dec_not_one(atomic_uint_fast32_t *counter)
6++atomic_dec_not_one(atomic_uint *counter)
7+ {
8+- uint_fast32_t old = *counter;
9++ unsigned int old = *counter;
10+ while (1) {
11+ assert(old != 0);
12+ if (old == 1)
13+--- a/src/nouveau/winsys/nouveau_bo.h
14++++ b/src/nouveau/winsys/nouveau_bo.h
15+@@ -9,3 +9,3 @@
16+ #include <atomic>
17+-using std::atomic_uint_fast32_t;
18++using std::atomic_uint;
19+ #else
20+@@ -40,3 +40,3 @@
21+ enum nouveau_ws_bo_flags flags;
22+- atomic_uint_fast32_t refcnt;
23++ atomic_uint refcnt;
24+ };