Skip to content

feat(🗿): add createSecondaryDevice() to DawnContext#3768

Open
kbrandwijk wants to merge 3 commits intoShopify:mainfrom
kbrandwijk:feat/secondary-dawn-device
Open

feat(🗿): add createSecondaryDevice() to DawnContext#3768
kbrandwijk wants to merge 3 commits intoShopify:mainfrom
kbrandwijk:feat/secondary-dawn-device

Conversation

@kbrandwijk
Copy link
Copy Markdown
Contributor

@kbrandwijk kbrandwijk commented Mar 23, 2026

Summary

  • Adds createSecondaryDevice() method to DawnContext that creates an independent Dawn device from the same GPU adapter
  • The secondary device has its own command queue and does not enable ImplicitDeviceSynchronization, so it won't contend with the primary rendering device's mutex
  • Enables concurrent GPU workloads (e.g. ML inference via ONNX Runtime WebGPU EP) alongside the Skia rendering pipeline without frame drops

Platform features requested on secondary device:

  • BufferMapExtendedUsages — for staging buffer readback workflows
  • Apple: SharedTextureMemoryIOSurface — zero-copy camera frame import
  • Apple: DawnMultiPlanarFormats — multi-planar YUV texture support

Use case

We use this in react-native-webgpu-camera to run ONNX Runtime inference (YOLOv8, depth estimation) on a secondary device while the camera pipeline renders at 120fps on the primary device. Without a secondary device, ImplicitDeviceSynchronization serializes all Dawn API calls across threads, causing multi-second freezes during shader compilation.

Test plan

  • Call createSecondaryDevice() and verify it returns a valid wgpu::Device
  • Run GPU compute work on secondary device concurrently with Skia rendering on primary device
  • Verify no frame drops or mutex contention on primary device during secondary device workloads
  • Verify SharedTextureMemoryIOSurface import works on secondary device (Apple)

Creates an independent Dawn device from the same adapter with its own
command queue. Enables concurrent GPU workloads (e.g. ML inference via
ONNX Runtime) without mutex contention from ImplicitDeviceSynchronization
on the primary rendering device.

Includes platform-specific features:
- Apple: SharedTextureMemoryIOSurface, DawnMultiPlanarFormats
- BufferMapExtendedUsages for staging buffer workflows

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wcandillon wcandillon self-requested a review March 25, 2026 09:13
Copy link
Copy Markdown
Contributor

@wcandillon wcandillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Shouldn't the logic of this be in RNDawnUtils and then we can factorize also the duplication with the code in createDawnBackendContext, so we have a generic high level function to request the device?

I noticed that createSecondaryDevice request its own adapter, the idea being that it would be the same adapter anyways? That makes sense to me.

…awnUtils

Move shared adapter discovery and device creation logic out of
createDawnBackendContext into reusable helpers. createSecondaryDevice
now delegates to DawnUtils::requestDevice() instead of duplicating
the adapter enumeration, toggles, and device descriptor setup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor Author

@kbrandwijk kbrandwijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored — extracted getMatchedAdapter() and requestDevice() into RNDawnUtils.h as shared helpers. Both createDawnBackendContext (primary) and createSecondaryDevice (secondary) now use the same adapter discovery and device creation path.

The difference between the two is just the feature list passed to requestDevice() and the fatalOnDeviceLost flag (primary uses SK_ABORT, secondary logs only).

And yes — each device requests its own adapter, but it resolves to the same GPU. Keeps things simple and avoids coupling the two lifecycles.

Copy link
Copy Markdown
Contributor

@wcandillon wcandillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants