WebGPU texture-component-swizzle support
Component: WebGPU | 2ff8261
Source/WebGPU/WebGPU/Texture.mm
Source/WebGPU/WebGPU/BindGroup.mm
WebGPU의 texture view는 하나의 texture를 별도의 format, mip/layer 범위, aspect로 바라보는 alias 객체입니다. Bind group과 render attachment는 texture 대신 이 view를 사용합니다. 이때 JS에 노출되는 객체는 WebContent에 존재하고, 실제 처리는 GPU process 쪽 Source/WebGPU가 담당합니다. 즉 descriptor 검증과 실제 MTLTexture 생성은 모두 GPU process에서 이루어집니다.
이번 commit에서 GPUTextureViewDescriptor에 swizzle 필드가 추가되었습니다. WebCore가 이 값을 파싱하면, IPC를 통해 GPU process로 전달됩니다. GPU process에서는 Texture.mm이 값을 검증한 뒤, format이 요구하는 base swizzle이 있다면 이와 합성합니다. 그 결과를 바탕으로 swizzle이 적용된 Metal view가 생성됩니다. 이를 위해 TextureView, BindGroup, HardwareCapabilities, ShaderModule도 함께 수정되었습니다. 한편 bind group은 이제 sampled entry에 대해 sampledTexture()를 선택하고, storage binding에서는 swizzle이 적용된 view를 거부합니다. Depth, sampling, validation을 다루는 layout test 세 개도 추가되었습니다.
Significance
이제 web content가 view 생성 시점에 texture channel 순서를 재배치할 수 있으며, 상수 0과 1도 지정할 수 있습니다. Depth aspect 역시 Metal 기본값인 (V,V,V,1) 대신 (V,0,0,1)로 읽히게 됩니다. 다만 이 기능은 해당 device feature가 활성화된 경우에만 사용할 수 있습니다.
Audit directions
이번 변경으로 공격자가 제어하는 descriptor 상태가 Metal view 생성 단계까지 새로 넘어가게 되었습니다. 먼저 compromised WebContent process가 범위를 벗어난 swizzle enum 값을 보내는 경우를 살펴봐야 합니다. WebGPUTextureViewDescriptor.serialization.in과 convertFromBacking이 이런 값을 거부하는지 확인이 필요합니다. 또한 feature gate가 WebCore parser 경로뿐 아니라, IPC로 직접 들어오는 descriptor에도 적용되는지 점검해야 합니다.
composeComponentSwizzle, resolveComponentSwizzle, composedSwizzleChannels는 모든 format/aspect 조합에 대해 검토할 필요가 있습니다. 특히 depth, stencil, depth-stencil format과 base swizzle이 identity가 아닌 format이 주요 점검 대상입니다. 이와 함께 errorValidatingTextureViewCreation과 hasRenderableTextureViewProperties가 여전히 swizzle된 view를 render attachment와 storage에서 배제하는지도 확인해 볼 만합니다. 마지막으로, 모든 bind-group entry type이 의도한 MTLTexture를 받는지 살펴봐야 합니다. Swizzle된 sampledTexture()가 TextureView의 destroy와 setLabel 과정에서도 올바르게 retain되는지 역시 점검 대상입니다.