Files
reims-vgpu/scripts/browser-probe/guest_gl_renderers.py
T
Anees Iqbal 1e1875e643 ✨ Probes that measure Metal, CGL and WebGL from inside the guest
Follow-on to the CDP client. Three questions kept coming back unanswerable
from the host side, so each now has a probe that asks the guest directly.

`guest_gl_renderers.py` enumerates CGL renderers. On this guest the answer is
one renderer, the Apple Software Renderer, `accelerated=0` — which is the whole
explanation for every OpenGL-based browser reporting software rendering at
once. Note the constants: `kCGLRP*` are small integers, and the first version
of this file used the `kCGLPFA*` values in the 1600s by mistake, which makes
`CGLDescribeRenderer` fail every query and reads as a dead GPU rather than a
dead probe.

`guest_metal_caps.py` reports the Metal device. It drives `objc_msgSend`
through ctypes with explicit per-call argtypes — derived argtypes cannot
express an out-parameter, since `ctypes.byref` yields a CArgObject with no
`from_param`.

`gpu-probe.html` + `probe_server.py` + `web-gpu-probe.sh` ask each browser
whether WebGL/WebGPU came up and how many frames it sustained. The page posts
its own result back to the server that served it: Safari has no debugging
protocol, and AppleScript into Safari or Finder times out on this guest waiting
for an automation-consent click that an unattended run cannot give. Serving
over http rather than file:// is required for that POST to be same-origin.

Measured with these, x86/Vulkan, macOS 13.7.8, one boot:

  Safari 16.6   WebGL1+2 "Apple GPU", hardware, 119.4 fps, worst frame 13 ms
  Chrome 151    WebGL1+2 unavailable, WebGPU no adapter, 134.6 fps rAF only
  Firefox 153   WebGL1+2 unavailable, no navigator.gpu, 122.5 fps rAF only

So Metal works and the fault is not general. Chrome's GPU process exits during
init with "Initialization of all (1) EGL display types failed", including when
ANGLE is forced to Metal from a GUI-session launch with the blocklist ignored.
The device is fully usable — it compiles MSL and creates a command queue — but
`MTLCreateSystemDefaultDevice()` returns nil while `MTLCopyAllDevices()`
returns it, and ANGLE-Metal asks for the system default.

Tooling only; no crate code touched.
2026-08-01 22:26:55 +03:00

81 lines
3.0 KiB
Python
Executable File

#!/usr/bin/env python3
"""Enumerate the guest's CGL renderers and say which are hardware.
Runs inside the macOS guest. Browsers do not report *why* they are on a software
renderer, only that they are; this asks the OS directly, through
`CGLQueryRendererInfo`, which is the same enumeration OpenGL.framework uses to
pick a renderer. `ctypes` is enough — the guest has no compiler and installing
one would change the snapshot under measurement.
The property that matters is `kCGLRPAccelerated` (1636). A renderer list whose
only entry is the Apple Software Renderer is the whole explanation for
"hardware acceleration disabled" in every OpenGL-based browser at once.
"""
import ctypes
import ctypes.util
import sys
OGL = ctypes.CDLL("/System/Library/Frameworks/OpenGL.framework/OpenGL")
# CGLRendererProperty, from CGLTypes.h. These are the renderer-property
# enumerators (small integers) — NOT the CGLPixelFormatAttribute values in the
# 1600s, which is an easy and silent confusion: CGLDescribeRenderer just returns
# an error for every one of them and the whole report reads as "no properties",
# which looks like a broken GPU rather than a broken probe.
PROPS = {
"rendererID": 70,
"accelerated": 73,
"backingStore": 76,
"window": 80,
"compliant": 83,
"displayMask": 84,
"gpuVertexProcessing": 122,
"gpuFragmentProcessing": 123,
"online": 129,
"acceleratedCompute": 130,
"videoMemoryMegabytes": 131,
"textureMemoryMegabytes": 132,
"majorGLVersion": 133,
}
# kCGLRendererGenericFloatID — the Apple Software Renderer, which is what a
# machine with no accelerated driver falls back to.
APPLE_SOFTWARE_RENDERER_ID = 0x00020400
def query():
info = ctypes.c_void_p()
count = ctypes.c_int(0)
# display mask 0xffffffff = "any display"
err = OGL.CGLQueryRendererInfo(ctypes.c_uint32(0xFFFFFFFF), ctypes.byref(info), ctypes.byref(count))
if err != 0:
print(f"CGLQueryRendererInfo failed: {err}", file=sys.stderr)
return 1
print(f"renderers: {count.value}")
accelerated = 0
for i in range(count.value):
vals = {}
for name, prop in PROPS.items():
out = ctypes.c_int(0)
if OGL.CGLDescribeRenderer(info, ctypes.c_int(i), ctypes.c_int(prop), ctypes.byref(out)) == 0:
vals[name] = out.value
rid = vals.get("rendererID", 0)
soft = (rid & 0x00FFFF00) == (APPLE_SOFTWARE_RENDERER_ID & 0x00FFFF00)
if vals.get("accelerated"):
accelerated += 1
print(
f" [{i}] rendererID=0x{rid:08x} accelerated={vals.get('accelerated')} "
f"online={vals.get('online')} window={vals.get('window')} "
f"vram_mb={vals.get('videoMemoryMegabytes')} "
f"gl_major={vals.get('majorGLVersion')} "
f"{'APPLE_SOFTWARE_RENDERER' if soft else ''}"
)
OGL.CGLDestroyRendererInfo(info)
print(f"accelerated_renderers: {accelerated}")
return 0
if __name__ == "__main__":
sys.exit(query())