`scripts/browser-probe/guest_angle_metal.py` (measurement only). With `--use-angle=metal`, Chrome's GPU process died reporting only "Initialization of all (1) EGL display types failed" — Chrome counting failures, not ANGLE explaining one. On the OpenGL backend ANGLE's diagnostics reach the Chrome log through `angle_platform_impl`; on the Metal backend nothing is printed at all, because the failure happens before that channel carries anything. The single line that would name the cause is the one Chrome never gets, which is why this was previously recorded as an unexplained dead end. This drives Chrome's own `libEGL.dylib` directly with an `EGL_KHR_debug` callback installed, asks for a Metal display, and initializes the OpenGL backend afterwards as a control — if Metal fails and OpenGL succeeds in the same process, the failure belongs to the Metal path and not to the harness. Measured in the live guest: metal : eglGetPlatformDisplayEXT -> EGL_NO_DISPLAY, eglGetError EGL_SUCCESS opengl: eglInitialize OK, EGL 1.5, ANGLE 2.1.28226 EGL_NO_DISPLAY together with EGL_SUCCESS is the finding. ANGLE is not failing to create the display; it is declining to offer one, from a capability check that runs before creation. That relocates the question from "why does Metal device creation fail" — it does not fail, the device resolves — to "which capability does this guest's Metal device not have". Two notes for whoever runs this next. The probe loads CoreGraphics before any Metal call, because a bare ctypes process otherwise latches a nil system-default device and would manufacture the failure it is diagnosing. And `eglDebugMessageControlKHR` takes `EGLAttrib*` (`intptr_t`, 64-bit) while `eglGetPlatformDisplayEXT` takes the EXT spelling `EGLint*` (32-bit); passing one width for both walks ANGLE off the end of the array and segfaults the process, which reads as "the Metal backend crashed" rather than "the probe passed the wrong type". Both cost a debugging cycle here and are commented at their sites. Verification: run against the live x86 guest (macOS 13.7.8, `reims-vgpu-pci`), output above. The OpenGL control arm is what rules out the harness. Not verified: which capability ANGLE is testing. That is a property of ANGLE, not of this device, and is being read out of the ANGLE binary separately. Co-Authored-By: Claude <noreply@anthropic.com>
162 lines
6.9 KiB
Python
162 lines
6.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Make ANGLE say, in its own words, why its Metal display will not initialize.
|
|
|
|
Run inside the guest: python3 guest_angle_metal.py
|
|
|
|
WHY THIS EXISTS
|
|
|
|
With `--use-angle=metal`, Chrome's GPU process dies reporting only
|
|
|
|
Initialization of all (1) EGL display types failed.
|
|
GLDisplayEGL::Initialize failed.
|
|
|
|
That message is Chrome counting failures, not ANGLE explaining one. On the
|
|
OpenGL backend ANGLE's own diagnostics reach the Chrome log through
|
|
`angle_platform_impl`; on the Metal backend **nothing** is printed, because the
|
|
failure happens inside `eglInitialize` before that channel carries anything. So
|
|
the one line that would name the cause is exactly the line Chrome never gets.
|
|
|
|
ANGLE implements `EGL_KHR_debug`, which delivers those messages to a callback.
|
|
This driver loads Chrome's own `libEGL.dylib`, installs that callback, asks for
|
|
a Metal display explicitly, and prints whatever ANGLE says — with no browser,
|
|
no sandbox and no GPU process in the way. The OpenGL backend is initialized
|
|
afterwards as a control: if Metal fails and OpenGL succeeds in the same process,
|
|
the failure is specific to the Metal path rather than to this harness.
|
|
"""
|
|
import ctypes
|
|
import sys
|
|
|
|
CHROME_LIBS = ("/Applications/Google Chrome.app/Contents/Frameworks/"
|
|
"Google Chrome Framework.framework/Versions/Current/Libraries/")
|
|
|
|
# A bare ctypes process has no CoreGraphics, and Metal's system-default-device
|
|
# lookup then latches nil for the life of the process behind a dispatch_once.
|
|
# ANGLE asks for that device, so without this line the probe would manufacture
|
|
# the very failure it is trying to diagnose. See guest_metal_caps.py.
|
|
ctypes.CDLL("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics")
|
|
ctypes.CDLL("/System/Library/Frameworks/Metal.framework/Metal")
|
|
|
|
# EGL constants (from the EGL and EGL_ANGLE_platform_angle headers).
|
|
EGL_NO_DISPLAY = 0
|
|
EGL_PLATFORM_ANGLE_ANGLE = 0x3202
|
|
EGL_PLATFORM_ANGLE_TYPE_ANGLE = 0x3203
|
|
EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE = 0x320D
|
|
EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE = 0x3489
|
|
EGL_NONE = 0x3038
|
|
EGL_DEBUG_MSG_CRITICAL_KHR = 0x33B9
|
|
EGL_DEBUG_MSG_ERROR_KHR = 0x33BA
|
|
EGL_DEBUG_MSG_WARN_KHR = 0x33BB
|
|
EGL_DEBUG_MSG_INFO_KHR = 0x33BC
|
|
EGL_TRUE = 1
|
|
EGL_VENDOR = 0x3053
|
|
EGL_VERSION = 0x3054
|
|
|
|
EGL_ERROR_NAMES = {
|
|
0x3000: "EGL_SUCCESS", 0x3001: "EGL_NOT_INITIALIZED",
|
|
0x3002: "EGL_BAD_ACCESS", 0x3003: "EGL_BAD_ALLOC",
|
|
0x3004: "EGL_BAD_ATTRIBUTE", 0x3005: "EGL_BAD_CONFIG",
|
|
0x3006: "EGL_BAD_CONTEXT", 0x3007: "EGL_BAD_CURRENT_SURFACE",
|
|
0x3008: "EGL_BAD_DISPLAY", 0x3009: "EGL_BAD_MATCH",
|
|
0x300A: "EGL_BAD_NATIVE_PIXMAP", 0x300B: "EGL_BAD_NATIVE_WINDOW",
|
|
0x300C: "EGL_BAD_PARAMETER", 0x300D: "EGL_BAD_SURFACE",
|
|
0x300E: "EGL_CONTEXT_LOST",
|
|
}
|
|
|
|
DEBUGPROC = ctypes.CFUNCTYPE(
|
|
None, ctypes.c_uint32, ctypes.c_char_p, ctypes.c_int32,
|
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p)
|
|
|
|
|
|
def load_egl():
|
|
# libGLESv2 first: libEGL depends on it, and loading it by absolute path
|
|
# avoids relying on @loader_path resolution from a foreign process.
|
|
ctypes.CDLL(CHROME_LIBS + "libGLESv2.dylib", mode=ctypes.RTLD_GLOBAL)
|
|
return ctypes.CDLL(CHROME_LIBS + "libEGL.dylib", mode=ctypes.RTLD_GLOBAL)
|
|
|
|
|
|
def main():
|
|
egl = load_egl()
|
|
egl.eglGetProcAddress.restype = ctypes.c_void_p
|
|
egl.eglGetProcAddress.argtypes = [ctypes.c_char_p]
|
|
egl.eglGetError.restype = ctypes.c_int32
|
|
egl.eglInitialize.restype = ctypes.c_uint32
|
|
egl.eglInitialize.argtypes = [ctypes.c_void_p,
|
|
ctypes.POINTER(ctypes.c_int32),
|
|
ctypes.POINTER(ctypes.c_int32)]
|
|
egl.eglQueryString.restype = ctypes.c_char_p
|
|
egl.eglQueryString.argtypes = [ctypes.c_void_p, ctypes.c_int32]
|
|
|
|
messages = []
|
|
|
|
@DEBUGPROC
|
|
def on_message(error, command, msg_type, _thread, _object, message):
|
|
text = (message or b"").decode(errors="replace").strip()
|
|
cmd = (command or b"").decode(errors="replace")
|
|
messages.append(f" ANGLE[{EGL_ERROR_NAMES.get(error, hex(error))}] {cmd}: {text}")
|
|
|
|
ctl = egl.eglGetProcAddress(b"eglDebugMessageControlKHR")
|
|
if ctl:
|
|
# `eglDebugMessageControlKHR` takes `const EGLAttrib *`, and EGLAttrib is
|
|
# `intptr_t` — 64-bit here. `eglGetPlatformDisplayEXT` below takes the
|
|
# EXT spelling, `const EGLint *`, which is 32-bit. Using one width for
|
|
# both makes ANGLE walk off the end of the array and segfault the
|
|
# process, which reads as "the Metal backend crashed" rather than "the
|
|
# probe passed the wrong type".
|
|
fn = ctypes.CFUNCTYPE(ctypes.c_int32, DEBUGPROC,
|
|
ctypes.POINTER(ctypes.c_ssize_t))(ctl)
|
|
attrs = (ctypes.c_ssize_t * 9)(
|
|
EGL_DEBUG_MSG_CRITICAL_KHR, EGL_TRUE,
|
|
EGL_DEBUG_MSG_ERROR_KHR, EGL_TRUE,
|
|
EGL_DEBUG_MSG_WARN_KHR, EGL_TRUE,
|
|
EGL_DEBUG_MSG_INFO_KHR, EGL_TRUE,
|
|
EGL_NONE)
|
|
fn(on_message, attrs)
|
|
print("EGL_KHR_debug callback: installed")
|
|
else:
|
|
print("EGL_KHR_debug callback: UNAVAILABLE (messages will be absent, "
|
|
"so an empty reason below means unreported, not none)")
|
|
|
|
get_display = egl.eglGetProcAddress(b"eglGetPlatformDisplayEXT")
|
|
if not get_display:
|
|
print("eglGetPlatformDisplayEXT missing — cannot select a backend")
|
|
return 2
|
|
get_display_fn = ctypes.CFUNCTYPE(
|
|
ctypes.c_void_p, ctypes.c_uint32, ctypes.c_void_p,
|
|
ctypes.POINTER(ctypes.c_int32))(get_display)
|
|
|
|
failures = 0
|
|
for label, backend in (("metal", EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE),
|
|
("opengl", EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)):
|
|
messages.clear()
|
|
print(f"\n=== ANGLE backend: {label} ===")
|
|
attrs = (ctypes.c_int32 * 3)(EGL_PLATFORM_ANGLE_TYPE_ANGLE, backend, EGL_NONE)
|
|
dpy = get_display_fn(EGL_PLATFORM_ANGLE_ANGLE, None, attrs)
|
|
if not dpy:
|
|
err = egl.eglGetError()
|
|
print(f" eglGetPlatformDisplayEXT -> EGL_NO_DISPLAY "
|
|
f"({EGL_ERROR_NAMES.get(err, hex(err))})")
|
|
print("\n".join(messages) or " (ANGLE said nothing)")
|
|
failures += 1
|
|
continue
|
|
major, minor = ctypes.c_int32(), ctypes.c_int32()
|
|
ok = egl.eglInitialize(dpy, ctypes.byref(major), ctypes.byref(minor))
|
|
if ok != EGL_TRUE:
|
|
err = egl.eglGetError()
|
|
print(f" eglInitialize -> FAILED ({EGL_ERROR_NAMES.get(err, hex(err))})")
|
|
print("\n".join(messages) or " (ANGLE said nothing)")
|
|
failures += 1
|
|
continue
|
|
vendor = egl.eglQueryString(dpy, EGL_VENDOR)
|
|
version = egl.eglQueryString(dpy, EGL_VERSION)
|
|
print(f" eglInitialize -> OK, EGL {major.value}.{minor.value}")
|
|
print(f" vendor : {(vendor or b'').decode(errors='replace')}")
|
|
print(f" version: {(version or b'').decode(errors='replace')}")
|
|
if messages:
|
|
print("\n".join(messages))
|
|
|
|
return 1 if failures else 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|