← All reports

WebGPU distinct identifier type and map per object type

Component: WebGPU | 9c8b36b

LayoutTests/ipc/webgpu-bind-group-update-external-textures-open-encoder.html

entries: [{
binding: 0,
- bufferBinding: { buffer: boundTextureId, offset: 0, size: { } },
- identifier: boundTextureId,
- type: 4, // BindingResourceType::ExternalTexture
+ resource: { variantType: 'WebKit::WebGPUExternalTextureIdentifier', variant: boundTextureId },
}],

Source/WebKit/GPUProcess/GPUConnectionToWebProcess.messages.in

- [EnabledBy=WebGPUEnabled] void CreateGPU(WebKit::WebGPUIdentifier identifier, ...)
- [EnabledBy=WebGPUEnabled] void ReleaseGPU(WebKit::WebGPUIdentifier identifier)
+ [EnabledBy=WebGPUEnabled] void CreateGPU(WebKit::RemoteGPUIdentifier identifier, ...)
+ [EnabledBy=WebGPUEnabled] void ReleaseGPU(WebKit::RemoteGPUIdentifier identifier)

WebContent process는 streaming IPC를 통해 GPU 측 WebGPU 객체를 identifier로 참조합니다. GPU process는 이 identifier를 WebGPU::ObjectHeap에서 조회해 실제 객체로 해석합니다. 이때 신뢰할 수 없는 송신자는 WebContent 쪽입니다. 따라서 전달되는 모든 identifier는 타입이 틀렸거나, stale하거나, 이미 destroy되었거나, 애초에 생성된 적이 없는 값일 수 있습니다. 기존에는 모든 identifier가 하나의 타입을 공유했고, 16바이트 Variant를 담는 단일 map에 저장되었습니다. 그래서 타입 불일치는 Variant 변환 실패로 드러났고, 결과적으로 null이 반환되었습니다.

이번 변경으로 heap은 객체 타입마다 별도의 map을 두게 되었습니다. 각 map은 해당 타입 전용 identifier를 key로 사용하며, RemoteGPU에는 RemoteGPUIdentifier가 새로 부여되었습니다. 한편 BindGroupEntry의 bufferBinding/identifier/type 세 필드는 하나의 resource Variant로 통합되었고, BindingResourceType은 제거되었습니다. Render pass attachment view 역시 texture view 또는 texture를 담는 Variant로 변경되었습니다.

다만 RemoteGPU::IsValid는 타입이 없는 WebGPUIdentifier를 그대로 유지합니다. 타입별 map 중 어느 하나라도 해당 값을 갖고 있으면 객체가 존재한다고 판단합니다. 그리고 발견된 객체가 모두 valid할 때에만 valid로 판정하는 방식입니다.

객체가 100개 이상인 경우 ObjectHeap의 메모리 사용량이 25-66% 줄어들고, lookup마다 뒤따르던 중복 variant-to-type 매핑도 사라졌습니다. 동시에 WebGPU trust boundary에서 객체 참조를 인코딩하고 해석하는 방식 자체가 새로 작성되었습니다.

이제는 서로 다른 타입의 identifier가 같은 값을 가질 수 있습니다. 즉 "identifier 하나에 객체 하나"라는 전제가 더 이상 성립하지 않습니다. 그래서 raw 값이나 타입이 없는 WebGPUIdentifier를 받는 모든 호출 지점을 살펴볼 필요가 있으며, 특히 RemoteGPU::IsValid가 우선 점검 대상입니다. 어떤 값이 한 map에서는 살아 있고 다른 map에서는 destroy되었거나 invalid한 상태일 때, 잘못된 판정을 반환하는지 확인해야 합니다.

새로 도입된 bind group Variant의 deserialization과 WebGPUBindGroupEntry.cpp의 WTF::switchOn 변환도 다시 점검해야 합니다. LayoutTests/ipc에 이미 존재하는 external texture IPC 테스트들을 보면, 이 경로들이 중요하다는 점을 알 수 있습니다.

기존 attachment 변환은 같은 identifier로 texture view를 먼저 시도하고, 그다음 texture를 시도했습니다. 따라서 view와 resolve target을 처리하는 타입별 대체 로직에서 누락되거나 일관되지 않게 처리되는 경우가 없는지 확인이 필요합니다. 둘 이상의 map을 건드리는 destroy/release 경로는 순서와 lifetime 변화 측면에서 살펴봐야 합니다. 마지막으로, raw identifier를 전송하던 기존 IPC fuzzer와 PoC는 새로운 메시지 형식에 맞춰 다시 작성해야 합니다.