Files
mac_linuxgpu/scripts/test-surface-import.sh
geramyloveless a27677cf2c rt: import a client's memory as a GPU buffer and copy it into VRAM
rt/surface.h: memory of another process that the platform mapped for the
device (a display agent's IOSurface, mapped by the dext's IODMACommand),
given as DMA segments, is imported the way Linux imports any foreign
buffer: an exporter whose sg_table carries those DMA addresses,
amdgpu_gem_prime_import() (an SG BO), pinned in GTT and bound in the
GART. rt_surface_copy() copies dirty rectangles from it into an amdgpu
VRAM buffer with the SDMA buffer functions on the TTM entity: one copy
packet per contiguous run (whole rows with equal pitches are one range),
up to 1024 packets per job, the last fence added to both buffers and
waited for with a bound. The CPU touches no pixel and no other copy
mechanism exists.

The provider's release runs exactly once, when the dma-buf is released:
after the BO is destroyed, which TTM delays until its fences signalled.
A failed import never runs it.

The DART layer gains imported mappings (linuxu_dart_import): charged to
the budget and live for containment while imported.

test-surface-import runs it on the CS fixture device, whose software
SDMA engine reads system memory through the GART table upstream filled
and faults on anything the DART does not map: a surface in three
separately allocated segments, a whole frame with differing pitches (360
row copies, one job), damage rectangles with clipping, 1100 rectangles
(two jobs), a band with equal pitches (one packet), refused imports and
destinations, and the release after the BO is gone.
2026-10-03 14:43:55 -07:00

43 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Surface import offline: DMA segments imported as an amdgpu dma-buf (an SG
# BO in the GART) and copied into VRAM by the SDMA buffer functions, on the
# fixture device of cs_fixture.c (linuxu/tests/test_surface_import.c).
set -euo pipefail
cd "$(dirname "$0")/.."
make -s lib >/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"
cflags=("${hostcflags[@]}" -g -O1 "${includes[@]}")
# The fixture's GART table and VRAM are host memory. The library's host
# build routes readX/writeX through synthetic MMIO tokens, which would drop
# the GART PTE writes (amdgpu_gmc_set_pte_pde uses writeq); these two
# upstream files are rebuilt with plain-memory accessors, as the KFD session
# test builds its doorbell code, and take the archive members' place.
plain=()
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; do
object="$work/$(basename "$source" .c).o"
clang "${cflags[@]}" -c "$source" -o "$object"
plain+=("$object")
done
clang "${cflags[@]}" -fsanitize=address \
linuxu/tests/test_surface_import.c linuxu/tests/cs_fixture.c \
"${plain[@]}" build/libmacamgdu.a \
-lpthread -o "$work/test_surface_import"
# SURFACE_IMPORT_KEEP=<path> keeps the binary for a debugger; CS_FIXTURE_TRACE=1
# traces what the software engines execute.
if [ -n "${SURFACE_IMPORT_KEEP:-}" ]; then cp "$work/test_surface_import" "$SURFACE_IMPORT_KEEP"; fi
"$work/test_surface_import"