From 90a5595bbe9ef96a069b011cfda17702132d3a67 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 7 Oct 2019 08:18:09 +0000 Subject: [PATCH] dawn_wsi: Pass the Metal queue to the SwapChainImpl If the swapchain creates its own queue, there can be races to determine whether the submit of the present happens first. The didn't show up in our samples but was an issue in real apps. Passing the queue to the swapchain makes it simple to keep operations well ordered. BUG=dawn:225 Change-Id: I9cc8e6e8140ad4a816373cffc9bda74ee826a41b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11640 Commit-Queue: Corentin Wallez Reviewed-by: Austin Eng Reviewed-by: Kai Ninomiya --- src/dawn_native/metal/DeviceMTL.h | 1 + src/dawn_native/metal/DeviceMTL.mm | 4 ++++ src/dawn_native/metal/SwapChainMTL.mm | 1 + src/include/dawn/dawn_wsi.h | 1 + src/utils/MetalBinding.mm | 2 +- 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dawn_native/metal/DeviceMTL.h b/src/dawn_native/metal/DeviceMTL.h index 0174e4af9c..4eff03f490 100644 --- a/src/dawn_native/metal/DeviceMTL.h +++ b/src/dawn_native/metal/DeviceMTL.h @@ -46,6 +46,7 @@ namespace dawn_native { namespace metal { void TickImpl() override; id GetMTLDevice(); + id GetMTLQueue(); id GetPendingCommandBuffer(); Serial GetPendingCommandSerial() const override; diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index 046ed13d47..a62aad825e 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -171,6 +171,10 @@ namespace dawn_native { namespace metal { return mMtlDevice; } + id Device::GetMTLQueue() { + return mCommandQueue; + } + id Device::GetPendingCommandBuffer() { TRACE_EVENT0(GetPlatform(), TRACE_DISABLED_BY_DEFAULT("gpu.dawn"), "DeviceMTL::GetPendingCommandBuffer"); diff --git a/src/dawn_native/metal/SwapChainMTL.mm b/src/dawn_native/metal/SwapChainMTL.mm index 0677ca0a25..c9552125d7 100644 --- a/src/dawn_native/metal/SwapChainMTL.mm +++ b/src/dawn_native/metal/SwapChainMTL.mm @@ -26,6 +26,7 @@ namespace dawn_native { namespace metal { const auto& im = GetImplementation(); DawnWSIContextMetal wsiContext = {}; wsiContext.device = ToBackend(GetDevice())->GetMTLDevice(); + wsiContext.queue = ToBackend(GetDevice())->GetMTLQueue(); im.Init(im.userData, &wsiContext); } diff --git a/src/include/dawn/dawn_wsi.h b/src/include/dawn/dawn_wsi.h index 832af4b929..ff83f722bf 100644 --- a/src/include/dawn/dawn_wsi.h +++ b/src/include/dawn/dawn_wsi.h @@ -69,6 +69,7 @@ typedef struct { typedef struct { id device = nil; + id queue = nil; } DawnWSIContextMetal; #endif diff --git a/src/utils/MetalBinding.mm b/src/utils/MetalBinding.mm index 4f9b5bed1a..0dbdb4d738 100644 --- a/src/utils/MetalBinding.mm +++ b/src/utils/MetalBinding.mm @@ -39,7 +39,7 @@ namespace utils { void Init(DawnWSIContextMetal* ctx) { mMtlDevice = ctx->device; - mCommandQueue = [mMtlDevice newCommandQueue]; + mCommandQueue = ctx->queue; } DawnSwapChainError Configure(DawnTextureFormat format,