← All reports

WebGPU texture-component-swizzle support

Component: WebGPU | 2ff8261

Source/WebGPU/WebGPU/Texture.mm

+ if (!descriptor.swizzle.isIdentity() && !m_device->hasFeature(WebGPU::FeatureName::TextureComponentSwizzle))
+ return ERROR_STRING(@"swizzle is not \"rgba\" and the texture-component-swizzle feature is not enabled");

Source/WebGPU/WebGPU/BindGroup.mm

- id<MTLTexture> texture = apiTextureView->texture();
+ id<MTLTexture> texture = (textureEntry && !externalTextureEntry) ? apiTextureView->sampledTexture() : apiTextureView->texture();
...
+ if (storageTextureEntry && apiTextureView->hasSwizzle()) {
+ VALIDATION_ERROR(@"Storage textures must be bound through a view whose swizzle is \"rgba\"");
+ return BindGroup::createInvalid(object);
+ }

A WebGPU texture view aliases a texture with its own format, mip/layer range, and aspect, and bind groups and render attachments consume these views. The JS-facing objects live in WebContent, while Source/WebGPU in the GPU process validates descriptors and creates the real MTLTextures.

GPUTextureViewDescriptor gains a swizzle field, which WebCore parses and IPC carries to the GPU process. There, Texture.mm validates it, composes it with any format-imposed base swizzle, and creates a swizzled Metal view. TextureView, BindGroup, HardwareCapabilities, and ShaderModule are updated. Bind groups now pick sampledTexture() for sampled entries, and storage bindings reject swizzled views. Three new layout tests cover depth, sampling, and validation.

Web content can now permute texture channels, including constant 0 and 1, at view creation, and depth aspects read as (V,0,0,1) instead of Metal's (V,V,V,1). The capability is gated behind a device feature.

New attacker-controlled descriptor state now crosses into Metal view creation. Confirm that WebGPUTextureViewDescriptor.serialization.in and convertFromBacking reject out-of-range swizzle enums from a compromised WebContent process, and that the feature gate applies to descriptors arriving over IPC, not just through the WebCore parser. composeComponentSwizzle, resolveComponentSwizzle, and composedSwizzleChannels need checking across every format/aspect combination, especially depth, stencil, and depth-stencil formats and formats with a non-identity base swizzle. errorValidatingTextureViewCreation and hasRenderableTextureViewProperties should still exclude swizzled views from render attachments and storage. Finally, check that every bind-group entry type gets the intended MTLTexture, and that the swizzled sampledTexture() stays correctly retained through TextureView destroy and setLabel.