Skip to content

Commit 7804676

Browse files
committed
Synchronize via MTLSharedEvents
1 parent c113bc3 commit 7804676

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/state.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ function global_queue(dev::MTLDevice)
5555
end::MTLCommandQueue
5656
end
5757

58+
"""
59+
queue_event(queue::MTLCommandQueue)::MTLSharedEvent
60+
61+
Return the `MTLSharedEvent` used to synchronize a queue
62+
"""
63+
function queue_event(queue::MTLCommandQueue)
64+
get!(task_local_storage(), (:MTLSharedEvent, queue)) do
65+
MTLSharedEvent(queue.device)
66+
end::MTLSharedEvent
67+
end
68+
5869
# TODO: Increase performance (currently ~15us)
5970
"""
6071
synchronize(queue)
@@ -66,9 +77,13 @@ and simply wait for it to be completed. Since command buffers *should* execute i
6677
First-In-First-Out manner, this synchronizes the GPU.
6778
"""
6879
@autoreleasepool function synchronize(queue::MTLCommandQueue=global_queue(device()))
80+
ev = queue_event(queue)
81+
val = ev.signaledValue + 1
6982
cmdbuf = MTLCommandBuffer(queue)
83+
MTL.encode_signal!(cmdbuf, ev, val)
7084
commit!(cmdbuf)
71-
wait_completed(cmdbuf)
85+
MTL.waitUntilSignaledValue(ev, val)
86+
return
7287
end
7388

7489
"""

0 commit comments

Comments
 (0)