← All reports

WebGPU render pipeline states serialized directly from the C++ API

Component: WebGPU | 7507a7a

Source/WebKit/Shared/WebGPU/WebGPUColorTargetState.cpp

- auto writeMask = OptionSet<::WebGPU::ColorWrite>::fromRaw(colorTargetState.writeMask & WebCore::webGPUColorWriteMaskAll);
- // A bit that is not a color channel is carried along, so that the pipeline rejects the mask.
- if (colorTargetState.writeMask & ~WebCore::webGPUColorWriteMaskAll)
- writeMask.add(::WebGPU::ColorWrite::Invalid);

Source/WebKit/Shared/WebGPU/WebGPUColorTargetState.serialization.in

-[AdditionalEncoder=StreamConnectionEncoder] struct WebKit::WebGPU::ColorTargetState {
- uint32_t writeMask
+[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct ::WebGPU::ColorTargetState {
+ OptionSet<::WebGPU::ColorWrite> writeMask;

Source/WebCore/Modules/WebGPU/WebGPU.serialization.in

-enum class ::WebGPU::ColorWrite : uint8_t {
+[OptionSet] enum class ::WebGPU::ColorWrite : uint8_t {

WebContent builds WebGPU pipeline descriptors from JS and sends them over IPC to the GPU process, which creates the Metal-backed pipelines. The WebKit::WebGPU namespace held parallel backing structs mirroring the ::WebGPU C++ API types, with field-by-field converters. The one non-trivial converter was ColorTargetState: writeMask crossed IPC as a raw uint32_t, and the GPU side masked it to the known channels and added ColorWrite::Invalid for any stray bit, so pipeline creation rejected it.

The IPC copies of BlendComponent, BlendState, StencilFaceState, DepthStencilState, MultisampleState, PrimitiveState, VertexAttribute, and ColorTargetState become using aliases of the ::WebGPU types and are serialized directly. The per-type .cpp converters are deleted, and ::WebGPU::ColorWrite becomes [OptionSet] so it serializes as an OptionSet.

The one behavioral change is writeMask handling, which moves from a hand-written converter that forwarded stray bits as Invalid into the generated OptionSet decoder. The rest removes duplicated structs and copy code between WebContent and the GPU process.

This is the decode path for WebContent-controlled pipeline descriptors in the GPU process, a sandbox-escape-relevant boundary. Determine what the generated OptionSet decoder does with bits outside the four channels (reject, mask, or pass through), whether pipeline creation still ever sees ColorWrite::Invalid, and whether any consumer, such as the conversion to MTLColorWriteMask, assumes only known bits. The same question generalizes to every enum in the now-direct structs (BlendOperation, BlendFactor, StencilOperation, CompareFunction, PrimitiveTopology, FrontFace, CullMode, IndexFormat, VertexFormat): confirm each has a generated validity check. Numeric fields now land straight in API structs: multisample count and mask, stencil masks, depth bias (NaN/inf), and vertex attribute offset/shaderLocation. The removed converters didn't range-check these either, so the GPU-process consumers must. Also watch for default member initializers that differ between the old IPC structs and the API structs, and for callers that relied on the removed converters' std::optional failure return.