← All reports

WebGPU: Make WebCore and WebKit use WebGPU C++ API

Component: WebGPU | b6ab04a

Source/WebCore/Modules/WebGPU/GPUAdapter.cpp

-GPUAdapter::GPUAdapter(Ref<WebGPU::Adapter>&& backing)
+GPUAdapter::GPUAdapter(Ref<WebGPU::Adapter>&& backing, Ref<WebGPUIntegration>&& gpu)
: m_backing(WTF::move(backing))
+ , m_gpu(WTF::move(gpu))
+ , m_adapterInfo(m_backing->info())
...
+static std::optional<::WebGPU::Limits> requiredLimits(const WebGPUDeviceDescriptor& descriptor, const ::WebGPU::Limits& supportedLimits)
+{
+ auto limits = ::WebGPU::defaultLimits();
+ for (const auto& pair : descriptor.requiredLimits) {
+ ...
+ if (pair.value > supportedLimits.LIMIT || !setMaxIntegerValue(limits.LIMIT, pair.value))
+ return std::nullopt;

WebGPU in WebKit is split across processes: the Web Process runs the JS bindings (GPUDevice, GPUBuffer, …), which talk to proxies that serialize calls over IPC to the GPU Process, where RemoteX objects hold the Metal-backed implementation. Handles crossing IPC resolve through an object heap and descriptors convert field by field, so type definitions and converters define what the GPU Process accepts from an untrusted renderer.

WebCore and WebKit now use the WebGPU C++ API (WebGPU::X, from WebGPU/WebGPUCpp.h) as the only interface to the implementations and no longer touch any wgpu* function or WGPU* type. WebCore::GPUX holds a Ref<WebGPU::X>, RemoteXProxy implements WebGPU::X in the Web Process, and RemoteX wraps WebGPU::Metal::X. The XImpl classes, isRemoteXProxy()/isXImpl() checks, C API conversion helpers and InternalAPI directory are gone, and IPC converters target the API types.

Before:
WebCore (JS binding) └─► WebCore::WebGPU::X (abstract)
        ├─► XImpl ──► ConvertToBackingContext ──► wgpu*/WGPU* C API
        └─► RemoteXProxy ──IPC──► RemoteX ──► WebGPU::XImpl ──► WGPU* C API
After:
WebCore::GPUX { Ref<WebGPU::X>, label } └─► WebGPU::X (WebGPUCpp.h)
        ├─► WebGPU::Metal::X (in-process)
        └─► RemoteXProxy ──IPC (API structs)──► RemoteX { WebGPU::Metal::X as WebGPU::X }

This rewrites the WebContent-to-GPU-process WebGPU object model and its IPC serialization in one change. Unknown GPUBufferUsage bits, previously dropped from bit 16 up, now map to an Invalid sentinel that fails validation. Color write masks wider than the four channel bits likewise become WebGPU::ColorWrite::Invalid.