WebKit Bugzilla
Attachment 372731 Details for
Bug 199142
: [WHLSL] Compiles should be asynchronous
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Wrap each use of MTLDevice in a mutex
patch.txt (text/plain), 31.34 KB, created by
Myles C. Maxfield
on 2019-06-23 22:04:15 PDT
(
hide
)
Description:
Wrap each use of MTLDevice in a mutex
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2019-06-23 22:04:15 PDT
Size:
31.34 KB
patch
obsolete
>commit be1c666840809411b8b6015119dd509789f25c7d >Author: Myles C. Maxfield <mmaxfield@apple.com> >Date: Sun Jun 23 19:00:11 2019 -0700 > > threadsafe wrapper > >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index da288703ba7..b3ffb90f5bc 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -6371,6 +6371,7 @@ > 1BE5BFC11D515715001666D9 /* MediaConstraints.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaConstraints.cpp; sourceTree = "<group>"; }; > 1C0106FE192594DF008A4201 /* InlineTextBoxStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InlineTextBoxStyle.cpp; sourceTree = "<group>"; }; > 1C0106FF192594DF008A4201 /* InlineTextBoxStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineTextBoxStyle.h; sourceTree = "<group>"; }; >+ 1C067E1822C0550800660B88 /* GPUThreadSafePlatformDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUThreadSafePlatformDevice.h; sourceTree = "<group>"; }; > 1C0939E81A13E12900B788E5 /* CachedSVGFont.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedSVGFont.cpp; sourceTree = "<group>"; }; > 1C0939E91A13E12900B788E5 /* CachedSVGFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedSVGFont.h; sourceTree = "<group>"; }; > 1C09D04B1E31C32800725F18 /* PAL.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = PAL.xcodeproj; path = PAL/PAL.xcodeproj; sourceTree = "<group>"; }; >@@ -18341,6 +18342,7 @@ > 498770D81242C535002226BA /* Texture.h */, > 498770D91242C535002226BA /* TilingData.cpp */, > 498770DA1242C535002226BA /* TilingData.h */, >+ 1C067E1822C0550800660B88 /* GPUThreadSafePlatformDevice.h */, > ); > path = gpu; > sourceTree = "<group>"; >diff --git a/Source/WebCore/platform/graphics/gpu/GPUBuffer.h b/Source/WebCore/platform/graphics/gpu/GPUBuffer.h >index 42508bc7617..065c8f0f7ac 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUBuffer.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUBuffer.h >@@ -108,7 +108,7 @@ private: > }; > > GPUBuffer(PlatformBufferSmartPtr&&, Ref<GPUDevice>&&, size_t, OptionSet<GPUBufferUsage::Flags>, bool); >- static bool validateBufferUsage(const GPUDevice&, OptionSet<GPUBufferUsage::Flags>); >+ static bool validateBufferUsage(OptionSet<GPUBufferUsage::Flags>); > > JSC::ArrayBuffer* stagingBufferForRead(); > JSC::ArrayBuffer* stagingBufferForWrite(); >diff --git a/Source/WebCore/platform/graphics/gpu/GPUDevice.h b/Source/WebCore/platform/graphics/gpu/GPUDevice.h >index a7139541d0b..39331d3aeec 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUDevice.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUDevice.h >@@ -29,6 +29,8 @@ > > #include "GPUQueue.h" > #include "GPUSwapChain.h" >+#include "GPUThreadSafePlatformDevice.h" >+#include <functional> > #include <wtf/RefCounted.h> > #include <wtf/RetainPtr.h> > #include <wtf/WeakPtr.h> >@@ -80,14 +82,16 @@ public: > > RefPtr<GPUQueue> tryGetQueue() const; > >- PlatformDevice* platformDevice() const { return m_platformDevice.get(); } >+ const GPUThreadSafePlatformDevice& platformDevice() const { return m_platformDevice; } >+ GPUThreadSafePlatformDevice& platformDevice() { return m_platformDevice; } >+ template <typename T> void withPlatformDevice(T&& callback) const { m_platformDevice->withPlatformDevice(callback); } > GPUSwapChain* swapChain() const { return m_swapChain.get(); } > void setSwapChain(RefPtr<GPUSwapChain>&&); > > private: > explicit GPUDevice(PlatformDeviceSmartPtr&&); > >- PlatformDeviceSmartPtr m_platformDevice; >+ Ref<GPUThreadSafePlatformDevice> m_platformDevice; > mutable RefPtr<GPUQueue> m_queue; > RefPtr<GPUSwapChain> m_swapChain; > }; >diff --git a/Source/WebCore/platform/graphics/gpu/GPUThreadSafePlatformDevice.h b/Source/WebCore/platform/graphics/gpu/GPUThreadSafePlatformDevice.h >new file mode 100644 >index 00000000000..da5588af737 >--- /dev/null >+++ b/Source/WebCore/platform/graphics/gpu/GPUThreadSafePlatformDevice.h >@@ -0,0 +1,68 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(WEBGPU) >+ >+#include <wtf/Lock.h> >+#include <wtf/ThreadSafeRefCounted.h> >+#include <functional> >+ >+OBJC_PROTOCOL(MTLDevice); >+ >+namespace WebCore { >+ >+using PlatformDevice = MTLDevice; >+using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>; >+ >+class GPUThreadSafePlatformDevice : public ThreadSafeRefCounted<GPUThreadSafePlatformDevice> { >+public: >+ static Ref<GPUThreadSafePlatformDevice> create(PlatformDeviceSmartPtr&& platformDevice) >+ { >+ ASSERT(platformDevice); >+ return adoptRef(*new GPUThreadSafePlatformDevice(WTFMove(platformDevice))); >+ } >+ >+ template <typename T> >+ void withPlatformDevice(T&& callback) const >+ { >+ auto locker = holdLock(m_lock); >+ callback(m_platformDevice.get()); >+ } >+ >+private: >+ GPUThreadSafePlatformDevice(PlatformDeviceSmartPtr&& platformDevice) >+ : m_platformDevice(WTFMove(platformDevice)) >+ { >+ } >+ >+ PlatformDeviceSmartPtr m_platformDevice; >+ mutable Lock m_lock; >+}; >+ >+} // namespace WebCore >+ >+#endif // ENABLE(WEBGPU) >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm >index 8020163554e..1904efb80db 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm >@@ -63,12 +63,15 @@ static void appendArgumentToArray(ArgumentArray& array, RetainPtr<MTLArgumentDes > END_BLOCK_OBJC_EXCEPTIONS; > } > >-static RetainPtr<MTLArgumentEncoder> tryCreateMtlArgumentEncoder(const GPUDevice& device, ArgumentArray array) >+static RetainPtr<MTLArgumentEncoder> tryCreateMtlArgumentEncoder(const GPUThreadSafePlatformDevice& platformDevice, ArgumentArray array) > { > RetainPtr<MTLArgumentEncoder> encoder; > > BEGIN_BLOCK_OBJC_EXCEPTIONS; >- encoder = adoptNS([device.platformDevice() newArgumentEncoderWithArguments:array.get()]); >+ >+ platformDevice.withPlatformDevice([&](MTLDevice *platformDevice) { >+ encoder = adoptNS([platformDevice newArgumentEncoderWithArguments:array.get()]); >+ }); > END_BLOCK_OBJC_EXCEPTIONS; > if (!encoder) { > LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Unable to create MTLArgumentEncoder!"); >@@ -91,11 +94,6 @@ static RetainPtr<MTLArgumentDescriptor> argumentDescriptor(MTLDataType dataType, > > RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device, const GPUBindGroupLayoutDescriptor& descriptor) > { >- if (!device.platformDevice()) { >- LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Invalid MTLDevice!"); >- return nullptr; >- } >- > ArgumentArray vertexArgs, fragmentArgs, computeArgs, vertexLengths, fragmentLengths, computeLengths; > BindingsMapType bindingsMap; > >@@ -165,11 +163,11 @@ RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device > > RetainPtr<MTLArgumentEncoder> vertex, fragment, compute; > >- if (vertexArgs && !(vertex = tryCreateMtlArgumentEncoder(device, vertexArgs))) >+ if (vertexArgs && !(vertex = tryCreateMtlArgumentEncoder(device.platformDevice(), vertexArgs))) > return nullptr; >- if (fragmentArgs && !(fragment = tryCreateMtlArgumentEncoder(device, fragmentArgs))) >+ if (fragmentArgs && !(fragment = tryCreateMtlArgumentEncoder(device.platformDevice(), fragmentArgs))) > return nullptr; >- if (computeArgs && !(compute = tryCreateMtlArgumentEncoder(device, computeArgs))) >+ if (computeArgs && !(compute = tryCreateMtlArgumentEncoder(device.platformDevice(), computeArgs))) > return nullptr; > > return adoptRef(new GPUBindGroupLayout(WTFMove(bindingsMap), WTFMove(vertex), WTFMove(fragment), WTFMove(compute))); >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm >index 59a07ff9ceb..855ae724f2c 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm >@@ -42,13 +42,8 @@ namespace WebCore { > static constexpr auto readOnlyFlags = OptionSet<GPUBufferUsage::Flags> { GPUBufferUsage::Flags::Index, GPUBufferUsage::Flags::Vertex, GPUBufferUsage::Flags::Uniform, GPUBufferUsage::Flags::TransferSource }; > > >-bool GPUBuffer::validateBufferUsage(const GPUDevice& device, OptionSet<GPUBufferUsage::Flags> usage) >+bool GPUBuffer::validateBufferUsage(OptionSet<GPUBufferUsage::Flags> usage) > { >- if (!device.platformDevice()) { >- LOG(WebGPU, "GPUBuffer::tryCreate(): Invalid GPUDevice!"); >- return false; >- } >- > if (usage.containsAll({ GPUBufferUsage::Flags::MapWrite, GPUBufferUsage::Flags::MapRead })) { > LOG(WebGPU, "GPUBuffer::tryCreate(): Buffer cannot have both MAP_READ and MAP_WRITE usage!"); > return false; >@@ -72,7 +67,7 @@ RefPtr<GPUBuffer> GPUBuffer::tryCreate(Ref<GPUDevice>&& device, const GPUBufferD > } > > auto usage = OptionSet<GPUBufferUsage::Flags>::fromRaw(descriptor.usage); >- if (!validateBufferUsage(device.get(), usage)) >+ if (!validateBufferUsage(usage)) > return nullptr; > > #if PLATFORM(MAC) >@@ -97,7 +92,9 @@ RefPtr<GPUBuffer> GPUBuffer::tryCreate(Ref<GPUDevice>&& device, const GPUBufferD > > BEGIN_BLOCK_OBJC_EXCEPTIONS; > >- mtlBuffer = adoptNS([device->platformDevice() newBufferWithLength:static_cast<NSUInteger>(descriptor.size) options:resourceOptions]); >+ device->withPlatformDevice([&](MTLDevice *platformDevice) { >+ mtlBuffer = adoptNS([platformDevice newBufferWithLength:static_cast<NSUInteger>(descriptor.size) options:resourceOptions]); >+ }); > > END_BLOCK_OBJC_EXCEPTIONS; > >@@ -230,7 +227,9 @@ void GPUBuffer::copyStagingBufferToGPU() > > BEGIN_BLOCK_OBJC_EXCEPTIONS; > // GPUBuffer creation validation ensures m_byteSize fits in NSUInteger. >- stagingMtlBuffer = adoptNS([m_device->platformDevice() newBufferWithLength:static_cast<NSUInteger>(m_byteLength) options:MTLResourceCPUCacheModeDefaultCache]); >+ m_device->withPlatformDevice([&](MTLDevice *platformDevice) { >+ stagingMtlBuffer = adoptNS([platformDevice newBufferWithLength:static_cast<NSUInteger>(m_byteLength) options:MTLResourceCPUCacheModeDefaultCache]); >+ }); > END_BLOCK_OBJC_EXCEPTIONS; > > if (!stagingMtlBuffer) { >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm >index 43a2650e833..1509031e022 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm >@@ -41,11 +41,6 @@ namespace WebCore { > > RefPtr<GPUCommandBuffer> GPUCommandBuffer::tryCreate(const GPUDevice& device) > { >- if (!device.platformDevice()) { >- LOG(WebGPU, "GPUCommandBuffer::create(): Invalid GPUDevice!"); >- return nullptr; >- } >- > auto gpuCommandQueue = device.tryGetQueue(); > if (!gpuCommandQueue) > return nullptr; >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm >index e81f7cadd27..b11fb3cc38c 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm >@@ -65,7 +65,7 @@ static bool trySetMetalFunctions(const char* const functionName, MTLLibrary *com > return false; > } > >-static Optional<WHLSL::ComputeDimensions> trySetFunctions(const char* const functionName, const GPUPipelineStageDescriptor& computeStage, const GPUDevice& device, MTLComputePipelineDescriptor* mtlDescriptor, Optional<WHLSL::ComputePipelineDescriptor>& whlslDescriptor) >+static Optional<WHLSL::ComputeDimensions> trySetFunctions(const char* const functionName, const GPUPipelineStageDescriptor& computeStage, const GPUThreadSafePlatformDevice& platformDevice, MTLComputePipelineDescriptor* mtlDescriptor, Optional<WHLSL::ComputePipelineDescriptor>& whlslDescriptor) > { > #if LOG_DISABLED > UNUSED_PARAM(functionName); >@@ -90,7 +90,9 @@ static Optional<WHLSL::ComputeDimensions> trySetFunctions(const char* const func > NSError *error = nil; > > BEGIN_BLOCK_OBJC_EXCEPTIONS; >- computeLibrary = adoptNS([device.platformDevice() newLibraryWithSource:whlslCompileResult->metalSource options:nil error:&error]); >+ platformDevice.withPlatformDevice([&](MTLDevice *platformDevice) { >+ computeLibrary = adoptNS([platformDevice newLibraryWithSource:whlslCompileResult->metalSource options:nil error:&error]); >+ }); > END_BLOCK_OBJC_EXCEPTIONS; > #ifndef NDEBUG > if (!computeLibrary) >@@ -114,7 +116,7 @@ struct ConvertResult { > RetainPtr<MTLComputePipelineDescriptor> pipelineDescriptor; > WHLSL::ComputeDimensions computeDimensions; > }; >-static Optional<ConvertResult> convertComputePipelineDescriptor(const char* const functionName, const GPUComputePipelineDescriptor& descriptor, const GPUDevice& device) >+static Optional<ConvertResult> convertComputePipelineDescriptor(const char* const functionName, const GPUComputePipelineDescriptor& descriptor, const GPUThreadSafePlatformDevice& platformDevice) > { > RetainPtr<MTLComputePipelineDescriptor> mtlDescriptor; > >@@ -146,7 +148,7 @@ static Optional<ConvertResult> convertComputePipelineDescriptor(const char* cons > } > } > >- if (auto computeDimensions = trySetFunctions(functionName, computeStage, device, mtlDescriptor.get(), whlslDescriptor)) >+ if (auto computeDimensions = trySetFunctions(functionName, computeStage, platformDevice, mtlDescriptor.get(), whlslDescriptor)) > return {{ mtlDescriptor, *computeDimensions }}; > > return WTF::nullopt; >@@ -156,14 +158,9 @@ struct CreateResult { > RetainPtr<MTLComputePipelineState> pipelineState; > WHLSL::ComputeDimensions computeDimensions; > }; >-static Optional<CreateResult> tryCreateMTLComputePipelineState(const char* const functionName, const GPUDevice& device, const GPUComputePipelineDescriptor& descriptor) >+static Optional<CreateResult> tryCreateMTLComputePipelineState(const char* const functionName, const GPUThreadSafePlatformDevice& platformDevice, const GPUComputePipelineDescriptor& descriptor) > { >- if (!device.platformDevice()) { >- LOG(WebGPU, "GPUComputePipeline::tryCreate(): Invalid GPUDevice!"); >- return WTF::nullopt; >- } >- >- auto convertResult = convertComputePipelineDescriptor(functionName, descriptor, device); >+ auto convertResult = convertComputePipelineDescriptor(functionName, descriptor, platformDevice); > if (!convertResult) > return WTF::nullopt; > ASSERT(convertResult->pipelineDescriptor); >@@ -174,7 +171,9 @@ static Optional<CreateResult> tryCreateMTLComputePipelineState(const char* const > BEGIN_BLOCK_OBJC_EXCEPTIONS; > > NSError *error = nil; >- pipeline = adoptNS([device.platformDevice() newComputePipelineStateWithDescriptor:mtlDescriptor.get() options:MTLPipelineOptionNone reflection:nil error:&error]); >+ platformDevice.withPlatformDevice([&](MTLDevice *platformDevice) { >+ pipeline = adoptNS([platformDevice newComputePipelineStateWithDescriptor:mtlDescriptor.get() options:MTLPipelineOptionNone reflection:nil error:&error]); >+ }); > if (!pipeline) { > LOG(WebGPU, "GPUComputePipeline::tryCreate(): %s!", error ? error.localizedDescription.UTF8String : "Unable to create MTLComputePipelineState!"); > return WTF::nullopt; >@@ -189,7 +188,7 @@ RefPtr<GPUComputePipeline> GPUComputePipeline::tryCreate(const GPUDevice& device > { > const char* const functionName = "GPURenderPipeline::create()"; > >- auto createResult = tryCreateMTLComputePipelineState(functionName, device, descriptor); >+ auto createResult = tryCreateMTLComputePipelineState(functionName, device.platformDevice(), descriptor); > if (!createResult) > return nullptr; > >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm >index f55947ebaf3..c9954ac0cfb 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm >@@ -71,7 +71,7 @@ RefPtr<GPUDevice> GPUDevice::tryCreate(const Optional<GPURequestAdapterOptions>& > } > > GPUDevice::GPUDevice(RetainPtr<MTLDevice>&& device) >- : m_platformDevice(WTFMove(device)) >+ : m_platformDevice(GPUThreadSafePlatformDevice::create(WTFMove(device))) > { > } > >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm >index a9ea3cbee58..413e023e755 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm >@@ -43,16 +43,13 @@ static NSString * const commandQueueLabelPrefix = @"com.apple.WebKit."; > > RefPtr<GPUQueue> GPUQueue::tryCreate(const GPUDevice& device) > { >- if (!device.platformDevice()) { >- LOG(WebGPU, "GPUQueue::tryCreate(): Invalid GPUDevice!"); >- return nullptr; >- } >- > RetainPtr<MTLCommandQueue> queue; > > BEGIN_BLOCK_OBJC_EXCEPTIONS; > >- queue = adoptNS([device.platformDevice() newCommandQueue]); >+ device.withPlatformDevice([&](MTLDevice *platformDevice) { >+ queue = adoptNS([platformDevice newCommandQueue]); >+ }); > [queue setLabel:commandQueueDefaultLabel]; > > END_BLOCK_OBJC_EXCEPTIONS; >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >index 23a5f92729c..6d5947c3151 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >@@ -45,7 +45,7 @@ > > namespace WebCore { > >-static RetainPtr<MTLDepthStencilState> tryCreateMtlDepthStencilState(const char* const functionName, const GPUDepthStencilStateDescriptor& descriptor, const GPUDevice& device) >+static RetainPtr<MTLDepthStencilState> tryCreateMtlDepthStencilState(const char* const functionName, const GPUDepthStencilStateDescriptor& descriptor, const GPUThreadSafePlatformDevice& platformDevice) > { > #if LOG_DISABLED > UNUSED_PARAM(functionName); >@@ -73,7 +73,9 @@ static RetainPtr<MTLDepthStencilState> tryCreateMtlDepthStencilState(const char* > > BEGIN_BLOCK_OBJC_EXCEPTIONS; > >- state = adoptNS([device.platformDevice() newDepthStencilStateWithDescriptor:mtlDescriptor.get()]); >+ platformDevice.withPlatformDevice([&](MTLDevice *platformDevice) { >+ state = adoptNS([platformDevice newDepthStencilStateWithDescriptor:mtlDescriptor.get()]); >+ }); > > END_BLOCK_OBJC_EXCEPTIONS; > >@@ -390,7 +392,7 @@ static bool trySetMetalFunctions(const char* const functionName, MTLLibrary *ver > return false; > } > >-static bool trySetFunctions(const char* const functionName, const GPUPipelineStageDescriptor& vertexStage, const Optional<GPUPipelineStageDescriptor>& fragmentStage, const GPUDevice& device, MTLRenderPipelineDescriptor* mtlDescriptor, Optional<WHLSL::RenderPipelineDescriptor>& whlslDescriptor) >+static bool trySetFunctions(const char* const functionName, const GPUPipelineStageDescriptor& vertexStage, const Optional<GPUPipelineStageDescriptor>& fragmentStage, const GPUThreadSafePlatformDevice& platformDevice, MTLRenderPipelineDescriptor* mtlDescriptor, Optional<WHLSL::RenderPipelineDescriptor>& whlslDescriptor) > { > #if LOG_DISABLED > UNUSED_PARAM(functionName); >@@ -414,7 +416,10 @@ static bool trySetFunctions(const char* const functionName, const GPUPipelineSta > NSError *error = nil; > > BEGIN_BLOCK_OBJC_EXCEPTIONS; >- vertexLibrary = adoptNS([device.platformDevice() newLibraryWithSource:whlslCompileResult->metalSource options:nil error:&error]); >+ // newLibraryWithSource:options:completionHandler: >+ platformDevice.withPlatformDevice([&](MTLDevice *platformDevice) { >+ vertexLibrary = adoptNS([platformDevice newLibraryWithSource:whlslCompileResult->metalSource options:nil error:&error]); >+ }); > END_BLOCK_OBJC_EXCEPTIONS; > > #ifndef NDEBUG >@@ -439,7 +444,7 @@ static bool trySetFunctions(const char* const functionName, const GPUPipelineSta > return trySetMetalFunctions(functionName, vertexLibrary.get(), fragmentLibrary.get(), mtlDescriptor, vertexEntryPoint, fragmentEntryPoint); > } > >-static RetainPtr<MTLRenderPipelineDescriptor> convertRenderPipelineDescriptor(const char* const functionName, const GPURenderPipelineDescriptor& descriptor, const GPUDevice& device) >+static RetainPtr<MTLRenderPipelineDescriptor> convertRenderPipelineDescriptor(const char* const functionName, const GPURenderPipelineDescriptor& descriptor, const GPUThreadSafePlatformDevice& platformDevice) > { > RetainPtr<MTLRenderPipelineDescriptor> mtlDescriptor; > >@@ -481,21 +486,16 @@ static RetainPtr<MTLRenderPipelineDescriptor> convertRenderPipelineDescriptor(co > } > } > >- if (!trySetFunctions(functionName, vertexStage, fragmentStage, device, mtlDescriptor.get(), whlslDescriptor)) >+ if (!trySetFunctions(functionName, vertexStage, fragmentStage, platformDevice, mtlDescriptor.get(), whlslDescriptor)) > return nullptr; > > return mtlDescriptor; > } > > template <typename T> >-static bool tryCreateMtlRenderPipelineState(const char* const functionName, const GPURenderPipelineDescriptor& descriptor, const GPUDevice& device, T&& callback) >+static bool tryCreateMtlRenderPipelineState(const char* const functionName, const GPURenderPipelineDescriptor& descriptor, const GPUThreadSafePlatformDevice& platformDevice, T&& callback) > { >- if (!device.platformDevice()) { >- LOG(WebGPU, "GPUComputePipeline::tryCreate(): Invalid GPUDevice!"); >- return false; >- } >- >- auto mtlDescriptor = convertRenderPipelineDescriptor(functionName, descriptor, device); >+ auto mtlDescriptor = convertRenderPipelineDescriptor(functionName, descriptor, platformDevice); > if (!mtlDescriptor) > return false; > >@@ -503,9 +503,12 @@ static bool tryCreateMtlRenderPipelineState(const char* const functionName, cons > > BEGIN_BLOCK_OBJC_EXCEPTIONS; > >- [device.platformDevice() newRenderPipelineStateWithDescriptor:mtlDescriptor.get() completionHandler:^(id<MTLRenderPipelineState> renderPipelineState, NSError *) { >- callback(renderPipelineState); >- }]; >+ >+ platformDevice.withPlatformDevice([&](MTLDevice *platformDevice) { >+ [platformDevice newRenderPipelineStateWithDescriptor:mtlDescriptor.get() completionHandler:^(id<MTLRenderPipelineState> renderPipelineState, NSError *) { >+ callback(renderPipelineState); >+ }]; >+ }); > > END_BLOCK_OBJC_EXCEPTIONS; > >@@ -516,21 +519,16 @@ RefPtr<GPURenderPipeline> GPURenderPipeline::tryCreate(const GPUDevice& device, > { > const char* const functionName = "GPURenderPipeline::create()"; > >- if (!device.platformDevice()) { >- LOG(WebGPU, "%s: Invalid GPUDevice!", functionName); >- return nullptr; >- } >- > RetainPtr<MTLDepthStencilState> depthStencil; > >- if (descriptor.depthStencilState && !(depthStencil = tryCreateMtlDepthStencilState(functionName, *descriptor.depthStencilState, device))) >+ if (descriptor.depthStencilState && !(depthStencil = tryCreateMtlDepthStencilState(functionName, *descriptor.depthStencilState, device.platformDevice()))) > return nullptr; > > // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198387 depthStencilAttachmentDescriptor isn't implemented yet for WHLSL compiler. > > auto result = adoptRef(new GPURenderPipeline(WTFMove(depthStencil), descriptor.primitiveTopology, descriptor.vertexInput.indexFormat)); > >- auto success = tryCreateMtlRenderPipelineState(functionName, descriptor, device, [=](RetainPtr<MTLRenderPipelineState> mtlRenderPipelineState) { >+ auto success = tryCreateMtlRenderPipelineState(functionName, descriptor, device.platformDevice(), [=](RetainPtr<MTLRenderPipelineState> mtlRenderPipelineState) { > result->setPlatformRenderPipeline(WTFMove(mtlRenderPipelineState)); > }); > if (!success) >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSamplerMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUSamplerMetal.mm >index d740518e95c..cf8c368529b 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSamplerMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUSamplerMetal.mm >@@ -75,13 +75,8 @@ static MTLSamplerMipFilter mtlMipFilterForFilterMode(GPUFilterMode mode) > ASSERT_NOT_REACHED(); > } > >-static RetainPtr<MTLSamplerState> tryCreateMtlSamplerState(const GPUDevice& device, const GPUSamplerDescriptor& descriptor) >+static RetainPtr<MTLSamplerState> tryCreateMtlSamplerState(const GPUThreadSafePlatformDevice& platformDevice, const GPUSamplerDescriptor& descriptor) > { >- if (!device.platformDevice()) { >- LOG(WebGPU, "GPUSampler::tryCreate(): Invalid GPUDevice!"); >- return nullptr; >- } >- > RetainPtr<MTLSamplerDescriptor> mtlDescriptor; > > BEGIN_BLOCK_OBJC_EXCEPTIONS; >@@ -109,7 +104,9 @@ static RetainPtr<MTLSamplerState> tryCreateMtlSamplerState(const GPUDevice& devi > > [mtlDescriptor setSupportArgumentBuffers:YES]; > >- sampler = adoptNS([device.platformDevice() newSamplerStateWithDescriptor:mtlDescriptor.get()]); >+ platformDevice.withPlatformDevice([&](MTLDevice *platformDevice) { >+ sampler = adoptNS([platformDevice newSamplerStateWithDescriptor:mtlDescriptor.get()]); >+ }); > END_BLOCK_OBJC_EXCEPTIONS; > > if (!sampler) >@@ -120,11 +117,9 @@ static RetainPtr<MTLSamplerState> tryCreateMtlSamplerState(const GPUDevice& devi > > RefPtr<GPUSampler> GPUSampler::tryCreate(const GPUDevice& device, const GPUSamplerDescriptor& descriptor) > { >- auto sampler = tryCreateMtlSamplerState(device, descriptor); >- if (!sampler) >- return nullptr; >- >- return adoptRef(new GPUSampler(WTFMove(sampler))); >+ if (auto sampler = tryCreateMtlSamplerState(device.platformDevice(), descriptor)) >+ return adoptRef(new GPUSampler(WTFMove(sampler))); >+ return nullptr; > } > > GPUSampler::GPUSampler(RetainPtr<MTLSamplerState>&& sampler) >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm >index b7f56c8327c..c3373a31303 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm >@@ -39,11 +39,6 @@ namespace WebCore { > > RefPtr<GPUShaderModule> GPUShaderModule::tryCreate(const GPUDevice& device, const GPUShaderModuleDescriptor& descriptor) > { >- if (!device.platformDevice()) { >- LOG(WebGPU, "GPUShaderModule::create(): Invalid GPUDevice!"); >- return nullptr; >- } >- > if (descriptor.isWHLSL) > return adoptRef(new GPUShaderModule(String(descriptor.code))); > >@@ -51,8 +46,10 @@ RefPtr<GPUShaderModule> GPUShaderModule::tryCreate(const GPUDevice& device, cons > > BEGIN_BLOCK_OBJC_EXCEPTIONS; > >- NSError *error = [NSError errorWithDomain:@"com.apple.WebKit.GPU" code:1 userInfo:nil]; >- module = adoptNS([device.platformDevice() newLibraryWithSource:descriptor.code options:nil error:&error]); >+ NSError *error = nil; >+ device.withPlatformDevice([&](MTLDevice *platformDevice) { >+ module = adoptNS([platformDevice newLibraryWithSource:descriptor.code options:nil error:&error]); >+ }); > if (!module) > LOG(WebGPU, "Shader compilation error: %s", [[error localizedDescription] UTF8String]); > >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >index bf3e3729684..80d98f87fef 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >@@ -87,11 +87,6 @@ static RetainPtr<WebGPULayer> tryCreateWebGPULayer(MTLDevice *device, MTLPixelFo > > RefPtr<GPUSwapChain> GPUSwapChain::tryCreate(const GPUSwapChainDescriptor& descriptor, int width, int height) > { >- if (!descriptor.device->platformDevice()) { >- LOG(WebGPU, "GPUSwapChain::tryCreate(): Invalid GPUDevice!"); >- return nullptr; >- } >- > auto pixelFormat = tryGetSupportedPixelFormat(descriptor.format); > if (!pixelFormat) > return nullptr; >@@ -102,7 +97,11 @@ RefPtr<GPUSwapChain> GPUSwapChain::tryCreate(const GPUSwapChainDescriptor& descr > return nullptr; > } > >- auto layer = tryCreateWebGPULayer(descriptor.device->platformDevice(), *pixelFormat, usageOptions); >+ RetainPtr<WebGPULayer> layer; >+ // FIXME: GPUSwapChainMetal and WebGPULayer will need additional work to be thread safe. >+ descriptor.device->withPlatformDevice([&](MTLDevice *platformDevice) { >+ layer = tryCreateWebGPULayer(platformDevice, *pixelFormat, usageOptions); >+ }); > if (!layer) > return nullptr; > >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm >index ee48928618d..660f819c50e 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm >@@ -143,11 +143,6 @@ RefPtr<GPUTexture> GPUTexture::tryCreate(const GPUDevice& device, const GPUTextu > { > const char* const functionName = "GPUTexture::tryCreate()"; > >- if (!device.platformDevice()) { >- LOG(WebGPU, "%s: Invalid GPUDevice!", functionName); >- return nullptr; >- } >- > auto usage = OptionSet<GPUTextureUsage::Flags>::fromRaw(descriptor.usage); > auto mtlDescriptor = tryCreateMtlTextureDescriptor(functionName, descriptor, usage); > if (!mtlDescriptor) >@@ -157,7 +152,9 @@ RefPtr<GPUTexture> GPUTexture::tryCreate(const GPUDevice& device, const GPUTextu > > BEGIN_BLOCK_OBJC_EXCEPTIONS; > >- mtlTexture = adoptNS([device.platformDevice() newTextureWithDescriptor:mtlDescriptor.get()]); >+ device.withPlatformDevice([&](MTLDevice *platformDevice) { >+ mtlTexture = adoptNS([platformDevice newTextureWithDescriptor:mtlDescriptor.get()]); >+ }); > > END_BLOCK_OBJC_EXCEPTIONS; >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 199142
:
372730
| 372731