Metal: Expose function to wait for commands to be scheduled.

This is to allow proper synchronization with other devices and APIs on
macOS. There is a global graphics queue so we usually don't need
synchronization but on Metal, commands are inserted on this queue only
when the command buffer is scheduled.

Metal's schedule and completed handlers can be fired on a different
thread so this CL also makes the code there data-race free.

BUG=chromium:938895
BUG=dawn:112

Change-Id: Id45a66fb4d13216b9d01f75e0766732f6e09ddf0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5700
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez
2019-03-22 07:36:34 +00:00
committed by Commit Bot service account
parent e105f962cf
commit 07950e80fe
5 changed files with 76 additions and 27 deletions

View File

@@ -345,18 +345,8 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase {
dawn::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
// Use a fence to know that GPU rendering is finished.
// TODO(cwallez@chromium.org): IOSurfaceLock should wait for previous GPU use of the
// IOSurface to be completed but this appears to not be the case.
// Maybe it is because the Metal command buffer has been submitted but not "scheduled" yet?
dawn::FenceDescriptor fenceDescriptor;
fenceDescriptor.initialValue = 0u;
dawn::Fence fence = queue.CreateFence(&fenceDescriptor);
queue.Signal(fence, 1);
while (fence.GetCompletedValue() < 1) {
WaitABit();
}
// Wait for the commands touching the IOSurface to be scheduled
dawn_native::metal::WaitForCommandsToBeScheduled(device.Get());
// Check the correct data was written
IOSurfaceLock(ioSurface, kIOSurfaceLockReadOnly, nullptr);