15 Commits
Author SHA1 Message Date
geramyloveless 4f5573483d Merge feature/llama-staged-inputs (37aa287) into display-c
llama.cpp: graph inputs queued in the Vulkan stream with no empty submits
(3dc1b9a), and the patch measuring where host copies leave the compute
stream (37aa287): the patch files and their manifest.
2026-10-04 10:02:05 -07:00
geramyloveless b004eb754d radv, libdrm-mlg: windowed frames follow the window, clipped, off when it leaves
- drmMlgPlaceWindow (libdrm-mlg) places one frame: the window's content
  and the monitor's screen in global points (CoreGraphics' space), the
  output's mode and the image. A screen point is crtc/screen pixels, which
  is the backing scale and the mode in one factor. A window that fills the
  screen (or is in native full screen there) gets the primary plane;
  otherwise an overlay plane at its rectangle in CRTC pixels, clipped to
  the CRTC with the matching crop of the image on every edge. A window off
  the monitor, or with less of it there than DC's 12-pixel smallest
  viewport (which DC would grow without saying), gets nothing, with the
  reason. No window or no screen keeps the old rules.
- LX_SCANOUT HIDE: the client's frames off the screen (the desktop back,
  the overlay off) while it stays attached and keeps its overlay plane.
- The WSI (radv-macos-display-wsi.patch) reads the window at every
  present, in global points, and uses drmMlgPlaceWindow. Off the monitor
  it hides once, logs it, keeps the game running paced at the refresh
  rate, and shows the frames again when the window comes back; going full
  screen on the monitor when the window is elsewhere is gone. A place that
  changed is checked with TEST before it is presented; a refusal names the
  rectangles and the scale. A layer at another size than the images makes
  presents VK_SUBOPTIMAL_KHR, so a resized window or a full-screen toggle
  gets new images.
- Tests: test-mlg-place (1x and 2x, screens at any global position, full
  screen, clipping on each edge and a corner, a scaled window clipped, off
  the screen, the viewport minimum, modes, refusals); test-scanout (HIDE,
  a cropped present after it, a crop past the framebuffer refused);
  test-radv-scanout (suboptimal presents for a layer of another size).
2026-10-04 09:32:48 -07:00
geramyloveless 37aa287df3 llama.cpp patch: measure where host copies leave the compute stream
The patch put host-to-device copies up to a fixed 1 MiB in the compute
stream. The crossover is where a copy's own transfer-queue submission
and the compute queue's semaphore wait cost as much as the copy they
let overlap, so ggml-vulkan now measures it once per device on first
use: that overhead with the host clock, times the host-to-device
bandwidth from GPU timestamps around a staged copy. It aborts with the
reason when a queue family has no timestamps, and
GGML_VK_COMPUTE_STREAM_COPY_MAX sets the size instead. On the R9700
here: 130 to 170 us and 1.2 GB/s, so about 150 to 200 KB.

test-backend-sched-inputs also copies a tensor computed on the CPU to
the device at 16 KiB and 4 MiB, on both sides of a 64 KiB limit (or
the measured one with --measured). One comment in ggml-vulkan-types.h
is dropped.
2026-10-04 08:14:11 -07:00
geramyloveless 3dc1b9af99 llama.cpp: queue graph inputs in the Vulkan stream, no empty submits
Each request to the GPU is a round trip to the driver process, and
llama.cpp's Vulkan backend made about thirty per decoded token outside
the graph itself: every graph input was written with a blocking
set_tensor (a submission, a fence wait and a reset each, since no VRAM
is CPU-visible on Apple silicon), and ggml_vk_synchronize signalled its
fence with an empty submission, which RADV turns into eight syncobj
requests when it also waits for the transfer queue.

patches/llama.cpp/sched-staged-inputs.patch adds an optional backend
function that queues a write of host data after the backend's pending
work and copies the data before it returns; the scheduler uses it for
user inputs. Vulkan stages the data in host memory owned by the
backend context and copies it in the compute stream. The fence goes
with the last compute submission, transfer-only work is waited for on
the host, and small host copies stay in the compute stream. The new
test-backend-sched-inputs checks that inputs are taken when the graph
is queued and ordered against the device's queued work.

bootstrap.sh gains --reset-llama and removes the files patches add
when it resets a tree; verify-upstream.py accepts patches that add
files.
2026-10-04 08:13:40 -07:00
geramyloveless d197adc7e7 radv: VK_MVK_macos_surface for SDL2 before 2.26
T2 on 239: Quake3e's bundled SDL2 2.24.1 refused RADV as its Vulkan
library ("Installed Vulkan Portability library doesn't implement the
VK_MVK_macos_surface extension"); its Cocoa backend requires that
extension at load, and every window creation failed ("Couldn't get a
visual"). RADV now also advertises VK_MVK_macos_surface on the macOS
platform; vkCreateMacOSSurfaceMVK takes an NSView backed by a
CAMetalLayer, or the layer, and makes the same Metal surface (a view
without one is refused). test-radv-scanout checks the extension, both
kinds of pView and the refusal.
2026-10-04 08:08:16 -07:00
geramyloveless fb0fb232ab mlg-run: --basepath and --basegame for Quake3e's game data
With --quake3, --basepath DIR and --basegame NAME become fs_basepath and
fs_basegame, which Quake3e reads at start. mlg-run first checks that
DIR/NAME (baseq3 without --basegame) holds .pk3 files and stops with what
is missing otherwise; both are refused without --quake3. OpenArena 0.8.8,
free data kept outside the repository, runs as --basegame baseoa (its game
VM and maps load in a Quake3e dedicated server from this pin).
test-mlg-run covers the settings and the refusals.
2026-10-04 07:24:39 -07:00
geramyloveless c4ef3c0f23 Merge display-c (7150b0c, build 238) into feature/quake3-direct-scanout 2026-10-03 22:36:36 -07:00
geramyloveless 6621098334 mlg-run: a Vulkan program on RADV, scanned out on the display output
tools/mlg-run runs a program so that it renders with RADV and the GPU
scans its frames out on the monitor the driver's display output drives,
whatever the program would pick: VK_DRIVER_FILES and VK_ICD_FILENAMES
name only RADV's ICD, SDL_VULKAN_LIBRARY the Khronos loader,
MLG_WSI_OUTPUT the output's connector (asked of the driver; --output
checks it) and MLG_WSI_MODE the mode, and SDL keeps full screen in a
window on its own screen. --quake3 adds Quake3e's renderer, vsync, mode
and window placement on the monitor's macOS display (CGDisplayBounds of
the display drmMlgConnectorDisplay finds). A missing ICD, loader, driver
or output is an error naming it; --dry-run prints the plan.

test-mlg-run checks the plan (plan.c): the environment, the Quake3e
settings full screen and windowed, with and without a macOS display, and
the refusals.
2026-10-03 22:30:07 -07:00
geramyloveless 2ea6aeea12 radv: present Metal surfaces with the GPU's display engine
patches/mesa/radv-macos-display-wsi.patch: RADV advertises
VK_EXT_metal_surface and swapchains on the macOS platform, and presents
them through libdrm-mlg's drmMlgScanout on the driver's display output.
The images stay in VRAM as framebuffers of the primary node, with
modifiers the output's planes scan out; a present goes on the primary
plane in place of the desktop (the window fills its screen, or is not on
the monitor's screen) or on an overlay plane at the window's rectangle,
or where MLG_WSI_MODE says. MLG_WSI_OUTPUT names the output; without it
the surface reports no presentation support and nothing is presented
another way. FIFO, a syncobj per image signalled at its vblank; the
window is moved to the monitor's screen at swapchain creation; the last
swapchain gives the screen back to the desktop. Failures print the step
and errno and lose the surface.

scripts/build-radv.sh builds the macOS platform. test-radv-scanout runs
RADV on the fixture's display output: no support without MLG_WSI_OUTPUT,
a refused connector, capabilities, FIFO frames of tiled images on the
primary plane, the desktop given back, a windowed overlay.
2026-10-03 22:27:26 -07:00
geramyloveless bffa8423bc radv offline test waits for the shader upload; stats split syncobj polls
vkCreateComputePipelines returns once the shader's SDMA copy is
submitted; the fixture engine runs it after. The test read the engine
counters once and passed only while the driver was slow enough. It now
waits up to 10 s for the copy.

LIBDRM_MLG_STATS counts zero-timeout SYNCOBJ_WAIT and
SYNCOBJ_TIMELINE_WAIT (polls; a failure is "not yet") apart from the
waits that may sleep.
2026-10-03 21:56:53 -07:00
geramyloveless a91b51d6c2 radv: upload shaders to VRAM by SDMA when no VRAM is CPU-visible
With no CPU-visible VRAM (Apple silicon), the winsys moved shader arenas
to GTT along with every other CPU-mapped buffer. Each instruction fetch
that missed the GPU's caches then crossed the PCIe link. On the R9700,
RADV_PERFTEST=dmashaders, which keeps shader code in NO_CPU_ACCESS VRAM
and uploads it by SDMA, raised llama.cpp decode from 12.96 to 17.97
tokens/s.

The Apple-silicon Mesa patch now selects that path whenever the device
has dedicated VRAM and none of it is CPU-visible, so no flag is needed.

The CS fixture runs a userspace driver's SDMA packets (copy linear,
write, constant fill, fence) in client IBs when driver streams are
modeled; the kernel's IBs keep the fixture's own packets.
test-radv-offline checks that a compiled pipeline reaches VRAM through
an SDMA copy.
2026-10-03 21:24:49 -07:00
geramyloveless f498511cca radv: keep buffers the CPU maps out of VRAM on Apple silicon
First run on the R9700: vkCreateDevice died with SIGBUS
(EXC_ARM_DA_ALIGN) in memmove, writing RADV's graphics preamble into a
command buffer. RADV places command buffers in CPU-visible VRAM, and
resizable BAR makes all of it visible. Apple silicon gives the CPU only
Device memory attributes for PCIe BARs, even for a write-combined mapping,
so unaligned stores fault. A probe of each mapping on the R9700: GTT,
cached or USWC, takes aligned and unaligned stores, unaligned memcpy and
memset; VRAM through BAR0 takes aligned stores but faults on unaligned
stores and unaligned memcpy.

No mapping option makes BAR space normal memory, so the third Mesa patch
(radv-apple-silicon-vram.patch) keeps the CPU out of VRAM on Apple
silicon. RADV's winsys reports no CPU-visible VRAM (no host-visible
device-local memory type; all VRAM is one device-local heap), and places
every buffer that is not NO_CPU_ACCESS in GTT: command buffers,
descriptor pools, shader arenas and upload buffers. Buffers only the GPU
touches, such as images, device-local memory and model weights, stay in
VRAM.

On the R9700, vulkaninfo now completes, and llama.cpp's test-backend-ops
passes on the GPU: ADD 103/103 and MUL_MAT 1132/1132. test-radv-offline
now checks that no memory type is both host-visible and device-local on
Apple silicon.
2026-10-03 18:00:23 -07:00
geramyloveless 1c8cc5bc3a Document the Vulkan path
vulkan/README.md: how RADV reaches the GPU (the loader, the ICD,
libdrm-mlg, libmlg_drm, the Linux-file transport), why a libdrm and not a
new ac_drm backend, DRM descriptors as sockets, the Mesa pin and its two
patches, building, what runs offline (RADV and llama.cpp on the fixture),
the test plan for the R9700, and the remaining gaps: presentation,
sync_file poll, external and fixed-address memory, eventfd, and what the
fixture cannot cover.

README.md: the Vulkan path in "What works" and the build table, the
optional Mesa and llama.cpp submodules, and the layout.
2026-10-03 11:20:02 -07:00
geramyloveless cdb75b6ff4 Pin llama.cpp b11379 and build its Vulkan backend for RADV
llama.cpp is the first application of the Vulkan path. third_party/llama.cpp
pins b11379 as an optional, unpatched upstream (sparse, update = none);
scripts/bootstrap.sh --llama-only fetches it and verify-upstream.py checks
it once checked out.

scripts/build-llama-vulkan.sh (make llama-vulkan) builds it with
GGML_VULKAN against the Vulkan loader (Homebrew's or the LunarG SDK's),
Metal, BLAS and libcurl off, into build/llama.cpp/bin: llama-bench,
llama-completion and test-backend-ops. Its shaders need shaderc's glslc.
scripts/llama-radv.sh runs any program with the loader pointed at the RADV
ICD alone, so a MoltenVK installation is not used.

test-llama-offline brings the CS fixture device up inside llama.cpp's own
test-backend-ops (vulkan/tests/fixture_preload.c, inserted through
MLG_PRELOAD) so its Vulkan backend runs on RADV on the software GPU:
llama.cpp lists the R9700, and in performance mode ADD and the Q4_0/Q4_K
matrix multiplications of a feed-forward layer (matrix-vector and
matrix-matrix pipelines) are compiled by ACO, allocated, submitted and
fenced. It skips unless RADV and llama.cpp are built.
2026-10-03 11:19:41 -07:00
geramyloveless 8c105a22ef radv: build Mesa's Vulkan driver for macOS, and test it offline
scripts/build-radv.sh (make radv) builds RADV from third_party/mesa on
libdrm-mlg: Meson with the ACO compiler and no LLVM, no window-system
platform (headless WSI), no GL, video, zstd or SPIRV-Tools, so the driver
links only the system and libdrm-mlg. It installs a relocatable ICD into
build/radv/install (libvulkan_radeon.dylib, libdrm_mlg.dylib,
libmlg_drm.dylib, share/vulkan/icd.d/radeon_icd.json with a relative
library path) and fails if any symbol other than the weak layer
entrypoints is left unresolved. Mesa's Python generators get a virtualenv
when python3 lacks mako, PyYAML or packaging.

test-radv-offline (vulkan/tests/test_radv_offline.c) loads the ICD as the
loader does and runs it on the CS fixture device through libdrm-mlg and
the loopback transport, against unmodified upstream DRM/amdgpu: instance
and enumeration ("AMD Radeon AI Pro R9700 (RADV GFX1201)", Vulkan 1.4, PCI
bus info), device creation, host-visible memory, an empty submit with a
fence, vkCmdFillBuffer and vkCmdUpdateBuffer executed by the software GPU
and checked through the mapping, a compute pipeline compiled by ACO, and a
dispatch submitted with a timeline semaphore and a fence (the software GPU
runs no shaders, so its result is not checked). It skips when RADV has not
been built.
2026-10-03 11:19:30 -07:00