Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Regarding gpu context sharing across threads

62 views
Skip to first unread message

Sowmyyy Reanz

unread,
Jan 23, 2025, 7:19:58 AMJan 23
to skia-discuss
Team,
To render skimage in gpu, we need to generate and render it using the same GrDirectContext.
We generate image in background thread and try to render it in main thread where same context cant be shared
We need to share the GrDirectContext::MakeDirect3D (for windows) across threads for gpu rendering, is this possible or not?

Greg Daniel

unread,
Jan 23, 2025, 9:25:00 AMJan 23
to skia-d...@googlegroups.com
GrDirectContext is not thread safe so you cannot use one or any classes created from one on simultaneous on different threads. There are a few options here to achieve what you're looking to do however.

1) Make two different GrDirectContexts on each thread. Manage any created texture by using GrBackendTextures (either importing or exporting them). They will eventually need to be deleted on the same GrDirectContext in which they were made. However, they then should be able to be created on one GrDirectContext and then read on a different one. Now you will need to make sure that uses of these on the different threads are manually synchronized. This can be done heavy handed using CPU synchronization or by using GPU semaphores which will need to be exported from the create Context and imported into the Read context.

2) You can try to use the SkImages::CrossContextTextureFromPixmap API. This sort of wraps up and manages what I described in 1) for you. However, it is much more limited on what it can do, is more fragile, and not as heavily tested. But if it works it is probably easier.

3) Skia's new GPU backend, Graphite, does support this type of multithreaded work, by using Recorders on different threads. There isn't a dedicated D3D backend for Graphite however there is a Dawn backend (Chrome's WebGPU implementation) that does have a D3D11/12 backend. We haven't fully shipped anything using either of these Dawn backends yet, so there could still be some bugs in them, but they also may just fully work for your use cases.

Thanks
Greg

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/skia-discuss/ef612372-1af2-4f78-9029-fcb3c24e79d3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages