Rolls up everything since 43c46ac8 into a single commit. Its tree is
identical to the tree of private master at
b3c77f2d2b20a432be10591a2129547c10b1c24b.
- A Cargo workspace of five crates under crates/: metal2vulkan (the
translator and the metal2vulkan command), metal2vulkan-runtime (the
Metal API on Vulkan), metal2vulkan-air (the AIR front end),
metal2vulkan-validation and metal2vulkan-devtools.
- Dual license: GPL-2.0-or-later OR LGPL-3.0-or-later.
- docs/: API, architecture, fast paths, how-to, Metal coverage,
refusals, runtime porting and validation guides.
Private-Commit: b3c77f2d2b20a432be10591a2129547c10b1c24b
60 lines
3.0 KiB
Bash
Executable File
60 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Run one command against a Mesa drm-shim device, inside `scripts/linux-gate --recipe drm-shim`
|
|
# only.
|
|
#
|
|
# scripts/drm-shim-exec <command> [args...]
|
|
#
|
|
# scripts/linux-gate passes M2V_DRM_SHIM_{LIBRARY,CHIP_VAR,CHIP} for the selected driver and
|
|
# scripts/linux-gate-vulkan resolves its ICD manifest into M2V_DRM_SHIM_ICD. This wrapper applies
|
|
# them to exactly one process tree (never to cargo or rustc):
|
|
#
|
|
# - LD_PRELOAD the driver's noop drm-shim, which answers the kernel ioctls for the chosen GPU and
|
|
# never touches hardware (the container has no /dev/dri and no GPU passthrough);
|
|
# - select the GPU (`AMDGPU_GPU_ID`, `INTEL_STUB_GPU_PLATFORM`, or `NOUVEAU_CHIPSET`, the only
|
|
# variables accepted);
|
|
# - make the driver's ICD the only one the loader sees (VK_DRIVER_FILES);
|
|
# - turn Mesa's on-disk shader cache off (MESA_SHADER_CACHE_DISABLE), so every pipeline is
|
|
# compiled by the driver rather than served from an earlier compile.
|
|
#
|
|
# The shim stands in for real hardware, so this refuses (exit 69, before it reads any
|
|
# M2V_DRM_SHIM_* variable) unless every one of these holds, checked in this order: the kernel is
|
|
# Linux (on macOS /dev/dri is also absent, and MoltenVK is a real GPU), the process is inside a
|
|
# container (/.dockerenv or /run/.containerenv), the drm-shim image's marker
|
|
# /etc/m2v-drm-shim-image exists, and /dev/dri does not. Exporting the M2V_DRM_SHIM_* variables on
|
|
# a host therefore never preloads a shim next to a real GPU. crates/metal2vulkan-validation/tests/integration/drm_shim.rs checks
|
|
# the refusal wherever the tests run.
|
|
#
|
|
# Use it only for commands that create pipelines and never submit work (`corpus-pipeline`).
|
|
set -euo pipefail
|
|
|
|
[ "$#" -ge 1 ] || { echo "usage: scripts/drm-shim-exec <command> [args...]" >&2; exit 64; }
|
|
refuse() {
|
|
echo "drm-shim-exec: $1; it runs only inside scripts/linux-gate --recipe drm-shim" >&2
|
|
exit 69
|
|
}
|
|
[ "$(uname -s)" = Linux ] || refuse "not Linux ($(uname -s))"
|
|
[ -e /.dockerenv ] || [ -e /run/.containerenv ] || refuse "not inside a container"
|
|
[ -f /etc/m2v-drm-shim-image ] || refuse "not the drm-shim image (no /etc/m2v-drm-shim-image)"
|
|
if [ -e /dev/dri ]; then
|
|
refuse "/dev/dri exists; a shim is never preloaded next to real hardware"
|
|
fi
|
|
for var in M2V_DRM_SHIM_LIBRARY M2V_DRM_SHIM_CHIP_VAR M2V_DRM_SHIM_CHIP M2V_DRM_SHIM_ICD; do
|
|
if [ -z "${!var:-}" ]; then
|
|
echo "drm-shim-exec: $var is unset; run inside scripts/linux-gate --recipe drm-shim" >&2
|
|
exit 69
|
|
fi
|
|
done
|
|
case "$M2V_DRM_SHIM_CHIP_VAR" in
|
|
AMDGPU_GPU_ID|INTEL_STUB_GPU_PLATFORM|NOUVEAU_CHIPSET) ;;
|
|
*) echo "drm-shim-exec: $M2V_DRM_SHIM_CHIP_VAR selects no drm-shim GPU" >&2; exit 69 ;;
|
|
esac
|
|
[ -f "$M2V_DRM_SHIM_LIBRARY" ] || { echo "drm-shim-exec: no $M2V_DRM_SHIM_LIBRARY" >&2; exit 69; }
|
|
[ -f "$M2V_DRM_SHIM_ICD" ] || { echo "drm-shim-exec: no $M2V_DRM_SHIM_ICD" >&2; exit 69; }
|
|
|
|
exec env \
|
|
LD_PRELOAD="$M2V_DRM_SHIM_LIBRARY" \
|
|
"$M2V_DRM_SHIM_CHIP_VAR=$M2V_DRM_SHIM_CHIP" \
|
|
VK_DRIVER_FILES="$M2V_DRM_SHIM_ICD" \
|
|
MESA_SHADER_CACHE_DISABLE=true \
|
|
"$@"
|