Add support for dual-source-blending
Component: WebGPU WGSL | e53c6f0
Source/WebGPU/WGSL/AttributeValidator.cpp
WebGPU shaders are written in WGSL. WebKit's WGSL compiler, running in the GPU process, parses source into an AST, type-checks it (inferring types and folding constants), runs attribute and IO validation on those results, and emits Metal Shading Language; the web content process only forwards descriptors over IPC. Render pipeline blend state is a descriptor of per-target blend factors and operations that the GPU process validates and maps to Metal enums. Dual-source blending lets one fragment output location carry two values, where the second can be used as a blend factor, which couples shader output layout to pipeline blend state and color-target count.
This commit adds the optional dual-source-blending feature and the WGSL dual_source_blending extension with a new @blend_src(n) struct-member attribute, spanning the parser, AST, attribute/type/IO validation and the Metal function writer. On the host side it adds the src1-family blend factors to the IDL and serialization, plus pipeline creation logic that detects use of a second blend source. The per-member check shown above rejects @blend_src without the extension, requires a constant, and rejects values outside 0..1; validateBlendSrc(AST::Structure&) is called from visit(AST::Structure&).
Significance
Fragment shaders can now emit two outputs at one color location and blend with the second, enabling effects like per-channel, LCD-style alpha. It adds a new shader attribute, feature gate and IPC-carried enum values to the WebGPU stack in the GPU process, coupling shader output layout to pipeline state.
Audit directions
The points touching RenderPipeline.mm, IOValidator, ShaderModule.mm and the Metal writer follow the commit description; confirm each against those files:
- Index validation edge cases. The member check calls
integerValue()on whatever follows@blend_src; probe non-integer or non-const arguments (float, bool, override-declared values, abstract-int overflow), whether the type is validated before the range check, and whether the constant is always populated by the time the validator runs. - Cross-member rules in
validateBlendSrc. Duplicate indices, a lone 0 or 1 with no partner, mismatched types between the pair, differing@locationvalues,@blend_srccombined with@builtin, and use outside a fragment output struct; check thatIOValidator::validateStructIOagrees. - Pipeline/shader agreement.
src1factors must require a shader using@blend_srcand exactly one color target; try overrides, multiple fragment entry points in one module, and pipelines built from a different entry point than the oneparseFragmentReturnTypeinspected, where a per-moduleusesDualSourceBlendingflag could go stale. - Feature gating over IPC. A compromised web process can send descriptors directly, so confirm the GPU process rejects the new
GPUBlendFactor/WebGPU::BlendFactorvalues when the device lacks the feature. - Metal codegen. Check the attribute emitted for the second source against Metal's attachment index and count limits.
- Fuzzing. WGSL fuzzing around
enabledirectives andParser::parseAttribute, plus descriptor fuzzing of blend state against shader modules.