Files
reims-vgpu/guest/kext/tests/pci_class_test.cpp
T
Anees Iqbal e7095c3004 🐛 State the GPU's PCI class as an x86 Mac's GPU states it
On macOS 11, Safari's WebGL runs on WebKit's ANGLE over OpenGL, and ANGLE
refused to start on our device ("Unable to query ANGLE's SystemInfo."), so
Safari 14.1.3 made no WebGL context. ANGLE lists the Mac's GPUs by their PCI
devices' class-code, which reads 0x038000 for ours, a display controller of
class "other"; both GPUs of an Intel Mac state 0x030000 (measured, macOS
26.7.1).

The accelerator now sets class-code to 0x030000 on its PCI device's registry
entry when it starts. Configuration space keeps the device's own class, so
the firmware and the PCI family's matching see what they saw. On a macOS
11.7.11 guest, ANGLE then starts, in a plain process, without WindowServer
and inside the web content sandbox, and Safari makes its WebGL context.
2026-11-08 15:03:34 -08:00

34 lines
1.1 KiB
C++

// The native test of RgfxPciClass.hpp: the `class-code` the kext states on the PCI device reads
// 0x030000, a VGA-compatible display controller's, as both GPUs of an Intel Mac state it
// (measured, macOS 26.7.1); a display controller as the device's own class is, of another
// subclass.
#include "RgfxPciClass.hpp"
#include <cstdio>
#include <cstdlib>
namespace {
int checks = 0;
void check(bool ok, const char *what)
{
checks++;
if (!ok) {
std::fprintf(stderr, "pci_class_test: FAILED: %s\n", what);
std::exit(1);
}
}
} // namespace
int main()
{
const uint32_t stated = rgfxClassCodeValue(kRgfxMacGpuClassCode);
check(stated == 0x030000, "class-code reads 0x030000");
check(stated >> 16 == RGFX_PCI_CLASS >> 8, "the same base class as the device's, a display controller");
check((stated >> 8 & 0xff) != (RGFX_PCI_CLASS & 0xff), "another subclass than the device's");
const uint8_t device[4] = {0x00, RGFX_PCI_CLASS & 0xff, RGFX_PCI_CLASS >> 8, 0x00};
check(rgfxClassCodeValue(device) == 0x038000, "the device's own class reads 0x038000");
std::printf("pci_class_test: %d checks passed\n", checks);
return 0;
}