Always render DOM and WebGL in the GPU process on Cocoa platforms
Component: WebKit GPU Process | 12f9fee
Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp
Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp
WebKit은 DOM content를 두 가지 방식으로 그릴 수 있습니다. 하나는 web process 안에서 IOSurface 기반 backing store를 사용하는 방식입니다. 다른 하나는 RemoteRenderingBackend와 RemoteImageBufferSet을 거쳐 GPU process로 display list를 전달하는 방식입니다. WebGL도 같은 구조로 나뉘는데, GPU process 쪽의 RemoteGraphicsContextGL이 stream IPC connection을 통해 구동됩니다. 다만 Cocoa에서는 web content sandbox가 이미 두 경우 모두 GPU process 사용을 요구하고 있었습니다. 결과적으로 preference로 선택되던 in-process 경로는 더 이상 동작할 수 없는 상태였습니다.
이 commit은 Cocoa에서 UseGPUProcessForDOMRenderingEnabled와 UseGPUProcessForWebGLEnabled를 컴파일 대상에서 제외했습니다. ENABLE_GPU_PROCESS_DOM_RENDERING_BY_DEFAULT, ENABLE_GPU_PROCESS_WEBGL_BY_DEFAULT 매크로도 함께 제거되었습니다. 이와 함께 RemoteLayerWithInProcessRenderingBackingStore와 RemoteLayerWithRemoteRenderingBackingStore는 RemoteLayerBackingStore로 통합되었고, ImageBufferSet은 RemoteImageBufferSet에 병합되었습니다.
한편 삭제된 항목도 있습니다. RemoteVideoFrameObjectHeap::PixelBuffer message와 GetVideoFrameBuffer의 canSendIOSurface 인자가 제거되었습니다. ImageBuffer::backendGeneration()과 BufferAndBackendInfo::fromImageBuffer()도 함께 삭제되었습니다. 마지막으로 allocateImageBuffer는 backing store가 제공된 Accelerated 요청에 대해 IOSurface를 감싸지 않고 nullptr를 반환하도록 변경되었습니다.
Before (Cocoa): After (Cocoa):
WebContent WebContent
├─ pref: DOM/WebGL in GPUP? ├─ DOM: display lists
│ ├─ no: in-process BackingStore └─ WebGL: GL stream
│ │ (IOSurface alloc in WCP) │ IPC
│ └─ yes: RemoteBackingStore ▼
│ └─► GPUP GPU Process
│ IPC ├─ RemoteRenderingBackend
▼ │ (Accelerated + provided
GPU Process │ backing store => nullptr)
├─ allocateImageBuffer accepts ├─ RemoteImageBufferSet (merged)
│ IOSurface-backed store └─ RemoteGraphicsContextGL
└─ RemoteVideoFrameObjectHeap::PixelBuffer (PixelBuffer msg removed)
Significance
Cocoa에서 in-process 경로는 사실상 dead code였습니다. 이를 삭제하면서 remote 경로가 유일한 구현으로 남게 되었습니다. 이제 Cocoa에서 남은 rendering trust boundary는 web process가 전달한 parameter를 GPU process가 검증하는 지점 하나뿐입니다. GPU process는 더 이상 web process로부터 IOSurface 기반 buffer를 받지 않습니다. 반대로 web process 역시 remote image buffer용 IOSurface를 직접 allocate하지 않게 되었습니다.
Audit directions
Rendering 코드를 process 경계에 걸쳐 대규모로 리팩터링하면, 작업의 초점이 아니었던 쪽에 낡은 전제가 남기 쉽습니다. 이번 commit에서 위험이 집중되는 지점은 다음과 같습니다.
- 병합된
RemoteImageBufferSet은 이제 GPU 측의 buffer swap과 copy-forward 로직(swapBuffersForDisplay,prepareBufferForDisplay)을 담당합니다. 이 과정에서 web process가 전달한 dirty region과 configuration을 받아 처리합니다. 먼저 rect와 size 계산을 점검할 필요가 있습니다. 또한updateConfiguration이 front, back, secondary buffer를 초기화할 때m_previouslyPaintedRect나m_frontBufferIsCleared같은 stale state가 남는지도 확인해야 합니다. 참고로computePaintingRects()는PrepareBackingStoreBuffersData로 옮겨졌으며, 이 코드는 이제 web process도 함께 사용합니다. Accelerated와 제공된 backing store의 조합이면 buffer가 생성된다고 가정하던 web process 측 proxy 경로가 있습니다.RemoteRenderingBackendProxy의createBackendForSerializedBuffer,createImageBuffer가 여기에 해당하며, 새로 생긴 null 반환을 반드시 처리해야 합니다.CreateGraphicsContextGL과RemoteGraphicsContextGLmessage는 이제WebGLEnabled로만 gating됩니다. 이때 Cocoa에서GPUConnectionToWebProcess::createGraphicsContextGL이 수행하는 GPU 측 검사는 lockdown mode와 draft extensions에 대한MESSAGE_CHECK에 해당합니다.GetVideoFrameBuffer는 이제canSendIOSurface에 항상false를 전달합니다. 이 message와, 제거된 synchronousPixelBuffermessage를 사용하던 proxy 측 코드에는 video frame buffer 형식에 대한 낡은 전제가 남아 있을 가능성이 있습니다.markInProcessBackingStoreVolatile이 제거된 이후의RemoteLayerBackingStoreCollectionvolatility 처리도 살펴볼 만합니다. use-after-purge나 stale buffer identifier 버그를 찾아볼 수 있는 위치입니다.- Cocoa에서
allowsExitUnderMemoryPressure는 이제 항상 false를 반환합니다. 그래서 memory pressure 상황에서도 GPU process가 종료되지 않고 상주하게 됩니다. 결과적으로 이 process에서의 leak이나 memory exhaustion에 도달하기가 더 쉬워집니다.