Files
reims-vgpu/scripts/browser-probe/chrome_gpu_report.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

82 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python3
"""Print Chrome's own GPU verdict, from `chrome://gpu`, as plain lines.
Runs inside the guest next to `cdp.py`. Kept as a file rather than a heredoc
piped through ssh: the report needs `\\n` inside a JS string literal, and a
double-quoted ssh command eats one level of backslash, which turns the
expression into a syntax error at a line number that points nowhere useful.
chrome://gpu renders its report inside a shadow root, so `document.body.innerText`
is empty and the tree has to be walked explicitly.
"""
import sys
import time
sys.path.insert(0, "/tmp")
import cdp # noqa: E402 (path is set above)
DEEP_TEXT = """(() => {
const out = [];
const walk = (root) => {
for (const el of root.querySelectorAll('*')) if (el.shadowRoot) walk(el.shadowRoot);
out.push(root instanceof ShadowRoot ? root.textContent : (root.innerText || ''));
};
walk(document.body);
return out.join(String.fromCharCode(10));
})()"""
FEATURES = (
"Canvas:",
"Compositing:",
"OpenGL:",
"Metal:",
"Rasterization:",
"WebGL:",
"WebGL2:",
"WebGPU:",
"Video Decode:",
"Video Encode:",
"Skia Graphite:",
"Direct Rendering Display Compositor:",
)
DRIVER = (
"GL_VENDOR",
"GL_RENDERER",
"GL_VERSION",
"Display type",
"GL implementation parts",
"GPU0",
"Skia Backend",
"GPU process crash count",
"Initialization time",
"Machine model name",
)
def main():
tgt = cdp.open_page(url="chrome://gpu")
time.sleep(4)
txt = tgt.evaluate(DEEP_TEXT)
tgt.close()
if not txt:
print("EMPTY chrome://gpu report", file=sys.stderr)
return 1
# The feature list is one text node with "* " separating entries.
for line in txt.replace("* ", "\n").split("\n"):
line = line.strip()
if not line:
continue
if line.startswith(FEATURES):
print("FEATURE " + line)
elif line.startswith(DRIVER):
print("DRIVER " + line[:220])
elif "has been disabled" in line or "unable to boot" in line or "is unavailable" in line:
print("PROBLEM " + line.split(" Disabled")[0])
return 0
if __name__ == "__main__":
sys.exit(main())