mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-10 00:23:43 +00:00
Normal behavior of ApiObjectBase's APIRelease() which only locks the device when last ref dropped is not thread safe if the object is cached as raw pointers by the device. Example of cached objects: bind group layout, pipeline, sampler, shader module. The following scenario could happen: - thread A: - shaderModuleA.APIRealease() - shaderModuleA.refCount.Decrement() == true (ref count has reached zero) - going to call shaderModuleA.LockAndDeleteThis(). - thread B: - device.CreateShaderModule(). - lock() - device.GetOrCreateShaderModule() - shaderModuleA is in the cache, so return it. - unlock() - thread A: - starting to call shaderModuleA.LockAndDeleteThis() - lock() - erase shaderModuleA from the cache. - delete shaderModuleA. - unlock() This CL disables caching when ImplicitDeviceSynchronization is turned on until we find a better solution. Bug: dawn:1769 Change-Id: Ideb2a717ece0a40e18bd1c2bef00817262bd25da Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127900 Commit-Queue: Quyen Le <lehoangquyen@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
1.7 KiB
1.7 KiB
Implicit Device Synchronization
implicit-device-sync
is an experimental feature that offers multithreading support for dawn_native
.
Additional functionality:
wgpu::Device
and most of its child objects are safe to be used on multiple threads, including:wgpu::Queue
.wgpu::BindGroup
.wgpu::BindGroupLayout
.wgpu::Buffer
. See Notes.wgpu::Texture
.wgpu::TextureView
.wgpu::ComputePipeline
.wgpu::RenderPipeline
.wgpu::PipelineLayout
.wgpu::Sampler
.wgpu::ShaderModule
.wgpu::SwapChain
.
- These objects are not safe to be used concurrently:
wgpu:CommandEncoder
.wgpu:ComputePassEncoder
.wgpu:RenderPassEncoder
.wgpu:RenderBundleEncoder
.- Except that the creation, referencing, releasing and destruction of these objects are guaranteed to be thread safe.
Notes:
- This feature is experimental, meaning currently it has some limitations:
- For
wgpu::Buffer
to be safe on multiple threads. Proper manual synchronization must be done by users to ensure that the buffer is not currently being mapped and being used by any render/compute pass encoder at the same time on different threads. - Enabling this feature will disable the compatibility between
wgpu::BindGroupLayout
. That means the two differentwgpu::BindGroupLayout
objects created with equivalentwgpu::BindGroupLayoutDescriptor
won't be considered "group-equivalent" anymore. You can only use awgpu::BindGroup
with awgpu::RenderPipeline
/wgpu::ComputePipeline
if they are both created with the samewgpu::BindGroupLayout
.- Consider using
wgpu::RenderPipeline::GetBindGroupLayout()
/wgpu::ComputePipeline::GetBindGroupLayout()
when creating awgpu::BindGroup
.
- Consider using
- For