-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reuse cached MTLCommandQueue across multiple MetalRedrawer's #1127
Conversation
|
||
private class CachedCommandQueue( | ||
val queue: MTLCommandQueueProtocol, | ||
var refCount: Int = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
atomic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assumed to be used from the main thread.
@@ -461,6 +464,46 @@ internal class MetalRedrawer( | |||
companion object { | |||
private val renderingDispatchQueue = | |||
dispatch_queue_create("RenderingDispatchQueue", null) | |||
|
|||
private class CachedCommandQueue( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move it out from companion object
and expose methods instead of public properties
* Get an existing command queue associated with the device or create a new one and cache it. | ||
* Assumed to be run on the main thread. | ||
*/ | ||
fun getCachedCommandQueue(device: MTLDeviceProtocol): MTLCommandQueueProtocol { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be private in current impl
## Proposed Changes `MTLCommandQueue` is not a transient object and internal pools of them can be starved. It leads to Metal being unable to allocate a new one when GC hasn't collected the previously created queues. Cache it for reuse purposes. ## Testing Test: N/A ## Issues Fixed Fixes: [COMPOSE-1022](https://youtrack.jetbrains.com/issue/COMPOSE-1022/)
Speculative fix for [a case](JetBrains/compose-multiplatform#4761), where a lot of windows are created and dismissed. Caches command queue per device [similar to iOS](JetBrains/compose-multiplatform-core#1127)
Proposed Changes
MTLCommandQueue
is not a transient object and internal pools of them can be starved. It leads to Metal being unable to allocate a new one when GC hasn't collected the previously created queues.Cache it for reuse purposes.
Testing
Test: N/A
Issues Fixed
Fixes: COMPOSE-1022