gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 549 forks source link

Revise Metal thread safety #1984

Open kvark opened 6 years ago

kvark commented 6 years ago

In light of #1976, we need to go through all the unsafe impl Send+Sync entries and verify if they make sense. In general, ObjC doesn't guarantee thread safety, and Apple documentation is explicit about which Cocoa objects can be used from multiple threads: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html

As for Metal, the only documented thread-safe object appears to be MTLCommandQueue (so far). This is different from Vulkan, where VkDevice can be shared concurrently to create resources from multiple threads.

zakarumych commented 6 years ago

To follow Vulkan API all unsafe impl Send + Sync must stay. But implementations must be synchronized manually where needed.