Drawing a WebGL canvas into a 2D canvas produces transparent black on Windows without D3D11 fence support
Categories
(Core :: Graphics: Canvas2D, defect)
Tracking
()
People
(Reporter: aosmond, Assigned: aosmond)
References
Details
Attachments
(2 external files)
On Windows, when D3D11 fences are not available, drawing a WebGL canvas into an accelerated 2D canvas (drawImage(webglCanvas), and readbacks such as getImageData or toDataURL on the result) produces transparent black instead of the WebGL content. Each draw also waits about 100 ms. This happens with remote WebGL and accelerated Canvas2D in the GPU process.
Without fence support, SharedSurface_ANGLEShareHandle::Create synchronizes the WebGL snapshot texture with a keyed mutex instead of a fence. In the GPU process:
WebGLContext::GetBackBufferSnapshotSharedSurfacewrites the snapshot and releases the keyed mutex.CanvasTranslator::ResolveExternalSnapshotcallsBeginRead()on the snapshot, which acquires the keyed mutex again for the producer and holds it untilEndRead().- While it is held, the snapshot is imported into the 2D canvas.
GLBlitHelper::BlitDescriptor(const SurfaceDescriptorD3D10&)opens the texture andBindAnglePlanescallsAcquireSync(0, 100), which times out. WAIT_TIMEOUTis not a failure code, soBindAnglePlanesonly checksFAILED(hr)and blits from a texture it does not own, which reads as zeros. Its destructor then releases a mutex it never acquired.
With fences, BeginRead() takes no lock and the import waits on the write fence, so the default path on fence-capable hardware works.
Steps to reproduce:
- Set
gfx.direct3d11.fences-enabled=false(added in bug 2083416; it makesFenceD3D11::IsSupportedreturn false, as on hardware without fence support). - Run
dom/canvas/test/webgl-conf/generated/test_conformance__canvas__webgl-to-2d-canvas.htmlortest_conformance__canvas__draw-webgl-to-canvas-test.html(WebGL 1 or 2).
Actual: 38 of 45 checks fail with drawImage: Should be [...], reading transparent black.
Expected: all checks pass, as they do with fences enabled.
This was found on a try push for bug 2083416, which also fails draw-static-webgl-to-multiple-canvas-test and context-attribute-preserve-drawing-buffer.
Proposed fix, verified locally (all of the tests above pass with fences off, and still pass with fences on):
ResolveExternalSnapshot: do not callBeginRead()/EndRead()forSurfaceDescriptorD3D10snapshots withhasKeyedMutex, since the import acquires the mutex itself and the producer already released it.BindAnglePlanes: treat anyAcquireSyncresult other thanS_OKas failure, and release exactly the mutexes that were acquired, so this cannot silently read an unowned texture again.
| Assignee | ||
Comment 1•1 month ago
|
||
Without D3D11 fences, WebGL snapshots are synchronized with a keyed mutex.
ResolveExternalSnapshot acquired it for the producer with BeginRead while
importing the snapshot, but the import acquires the same mutex to read the
texture, so it timed out and read transparent black. The producer already
released the mutex after writing the snapshot, so let the import acquire it.
| Assignee | ||
Comment 2•1 month ago
|
||
AcquireSync returns WAIT_TIMEOUT and WAIT_ABANDONED as success codes, so
BindAnglePlanes went on to read textures it did not own and then released
mutexes it never acquired. Only S_OK now counts, and only the mutexes that were
acquired are released, including when a later plane fails.
Description
•