mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
Mesa's amdgpu drivers reach the kernel through libdrm's core API, through libdrm_amdgpu (devices, buffers, GPU virtual address ranges) and through a few system calls on the DRM descriptors. libmlg_drm/libdrm provides the part of xf86drm.h, amdgpu.h and libsync.h they use, over libmlg_drm, with libdrm's names, types and return conventions, so RADV's stock amdgpu winsys and Mesa's native ac_linux_drm path build and run unchanged. The driver's files live in the dext's per-client Linux process. Each one the library hands out (an opened render node, and every syncobj, sync_file and dma-buf descriptor a request returns) is represented by one end of a socket pair, the library keeping the other end: close, dup, fcntl and fork work on it as on any descriptor, and when the last copy is closed a watcher thread sees end-of-file and closes the driver's file, the lifetime a kernel file has. Requests carrying descriptors are translated both ways, with O_CLOEXEC in Linux's value. drmFileOpen, drmFileStat, drmFileMmap and drmFileMunmap, declared under LIBDRM_FILE_OPS, stand in for the system calls that cannot reach the driver. sync_wait and sync_merge work through temporary syncobjs of an open render node. The amdgpu part follows libdrm_amdgpu (MIT), from which its VA manager and buffer handling are derived: device deduplication, the PRT half-range reservation, dma-buf import by GEM_OP rather than lseek, no userptr. LIBDRM_MLG_DEBUG=1 reports refused requests and descriptor lifetimes. make libdrm-mlg installs build/libdrm-mlg with the uapi headers as the kernel installs them and libdrm.pc and libdrm_amdgpu.pc for Meson. test-libdrm-mlg runs it end to end against the CS fixture device. The Makefile's depfile search now skips the Meson and CMake trees the Vulkan builds will put under build/.
50 lines
2.5 KiB
Bash
Executable File
50 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# libdrm-mlg, the libdrm and libdrm_amdgpu API over libmlg_drm, end to end
|
|
# through the loopback transport into upstream DRM/amdgpu on the CS fixture
|
|
# device (libmlg_drm/libdrm/tests/test_libdrm_mlg.c). Links the host
|
|
# library (make lib) and the shared libdrm-mlg (make libdrm-mlg).
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
make -s lib libdrm-mlg >/dev/null
|
|
work=$(mktemp -d)
|
|
trap 'rm -rf "$work"' EXIT
|
|
cat > "$work/flags.mk" <<'MAKE'
|
|
.PHONY: print-includes
|
|
print-includes:
|
|
@printf '%s\n' $(INCPATHS)
|
|
.PHONY: print-hostcflags
|
|
print-hostcflags:
|
|
@printf '%s\n' $(filter-out -MMD -MP -DLINUXU_RT_HOST_SHADOW=1,$(HOSTCFLAGS))
|
|
MAKE
|
|
include_string=$(make -s -f Makefile -f "$work/flags.mk" print-includes | tr '\n' ' ')
|
|
read -r -a includes <<< "$include_string"
|
|
host_string=$(make -s -f Makefile -f "$work/flags.mk" print-hostcflags | tr '\n' ' ')
|
|
read -r -a hostcflags <<< "$host_string"
|
|
kernel=("${hostcflags[@]}" -g -O1 "${includes[@]}")
|
|
objects=()
|
|
# Plain-memory GART and VRAM accessors for the fixture (test-cs-selftest.sh).
|
|
for source in third_party/linux/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c \
|
|
third_party/linux/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c \
|
|
linuxu/tests/cs_fixture.c linuxu/tests/lx_loopback.c; do
|
|
object="$work/k_$(basename "$source" .c).o"
|
|
clang "${kernel[@]}" -Ilibmlg_drm/include -c "$source" -o "$object"
|
|
objects+=("$object")
|
|
done
|
|
# The client builds as a Mesa driver does (libdrm-mlg's headers, this
|
|
# platform's <drm.h>) into a library of its own linked against libdrm-mlg,
|
|
# so its libdrm_amdgpu calls cannot bind to same-named kernel functions of
|
|
# the program; the fixture helpers it calls are the program's.
|
|
prefix=build/libdrm-mlg
|
|
lib=$(cd $prefix/lib && pwd)
|
|
clang -std=c11 -Wall -Wextra -Werror -Wno-missing-field-initializers -g -O1 \
|
|
-fsanitize=address -I$prefix/include -I$prefix/include/libdrm -Ilinuxu/tests \
|
|
-dynamiclib -install_name @rpath/libtest_libdrm_mlg.dylib \
|
|
libmlg_drm/libdrm/tests/test_libdrm_mlg.c -L"$lib" -ldrm_mlg -lmlg_drm \
|
|
-Wl,-undefined,dynamic_lookup -o "$work/libtest_libdrm_mlg.dylib"
|
|
clang -std=c11 -Wall -Wextra -Werror -g -O1 -Ilibmlg_drm/include -Ilinuxu/tests \
|
|
-c libmlg_drm/libdrm/tests/test_libdrm_mlg_main.c -o "$work/main.o"
|
|
clang -fsanitize=address "${objects[@]}" "$work/main.o" build/libmacamgdu.a \
|
|
-L"$work" -ltest_libdrm_mlg -L"$lib" -lmlg_drm -Wl,-rpath,"$lib" -Wl,-rpath,"$work" \
|
|
-framework IOKit -framework CoreFoundation -lpthread -o "$work/test_libdrm_mlg"
|
|
"$work/test_libdrm_mlg"
|