WebKit Bugzilla
Attachment 372730 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]
Use the asynchronous flavor of the MSL compiler
patch.txt (text/plain), 7.02 KB, created by
Myles C. Maxfield
on 2019-06-23 22:03:40 PDT
(
hide
)
Description:
Use the asynchronous flavor of the MSL compiler
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2019-06-23 22:03:40 PDT
Size:
7.02 KB
patch
obsolete
>commit 12ab5741e41c084e8618062a1cdcb534e803b53c >Author: Myles C. Maxfield <mmaxfield@apple.com> >Date: Sun Jun 23 17:28:03 2019 -0700 > > WIP > >diff --git a/Source/WebCore/platform/graphics/gpu/GPURenderPipeline.h b/Source/WebCore/platform/graphics/gpu/GPURenderPipeline.h >index 6e16532a95d..358daec090b 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPURenderPipeline.h >+++ b/Source/WebCore/platform/graphics/gpu/GPURenderPipeline.h >@@ -28,10 +28,13 @@ > #if ENABLE(WEBGPU) > > #include "GPURenderPipelineDescriptor.h" >+#include <wtf/Condition.h> >+#include <wtf/Lock.h> > #include <wtf/Optional.h> > #include <wtf/RefCounted.h> > #include <wtf/RefPtr.h> > #include <wtf/RetainPtr.h> >+#include <wtf/ThreadSafeRefCounted.h> > > #if USE(METAL) > OBJC_PROTOCOL(MTLDepthStencilState); >@@ -45,26 +48,39 @@ class GPUDevice; > using PlatformRenderPipeline = MTLRenderPipelineState; > using PlatformRenderPipelineSmartPtr = RetainPtr<MTLRenderPipelineState>; > >-class GPURenderPipeline : public RefCounted<GPURenderPipeline> { >+class GPURenderPipeline : public ThreadSafeRefCounted<GPURenderPipeline> { > public: > static RefPtr<GPURenderPipeline> tryCreate(const GPUDevice&, const GPURenderPipelineDescriptor&); > > #if USE(METAL) > MTLDepthStencilState *depthStencilState() const { return m_depthStencilState.get(); } > #endif >- PlatformRenderPipeline* platformRenderPipeline() const { return m_platformRenderPipeline.get(); } >+ PlatformRenderPipeline* platformRenderPipeline() const; > GPUPrimitiveTopology primitiveTopology() const { return m_primitiveTopology; } > Optional<GPUIndexFormat> indexFormat() const { return m_indexFormat; } > >+ enum class CompileStatus { >+ Compiling, >+ Succeeded, >+ Failed >+ }; >+ >+ CompileStatus compileStatus() const { return m_compileStatus; } >+ >+ void setPlatformRenderPipeline(PlatformRenderPipelineSmartPtr&&); >+ > private: > #if USE(METAL) >- GPURenderPipeline(RetainPtr<MTLDepthStencilState>&&, PlatformRenderPipelineSmartPtr&&, GPUPrimitiveTopology, Optional<GPUIndexFormat>); >+ GPURenderPipeline(RetainPtr<MTLDepthStencilState>&&, GPUPrimitiveTopology, Optional<GPUIndexFormat>); > > RetainPtr<MTLDepthStencilState> m_depthStencilState; > #endif // USE(METAL) > PlatformRenderPipelineSmartPtr m_platformRenderPipeline; > GPUPrimitiveTopology m_primitiveTopology; > Optional<GPUIndexFormat> m_indexFormat; >+ CompileStatus m_compileStatus { CompileStatus::Compiling }; >+ mutable Lock platformRenderPipelineAndStatusLock; >+ mutable Condition platformRenderPipelineAndStatusCondition; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >index f56661d6c28..23a5f92729c 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >@@ -39,6 +39,7 @@ > #import <wtf/BlockObjCExceptions.h> > #import <wtf/CheckedArithmetic.h> > #import <wtf/HashSet.h> >+#import <wtf/Locker.h> > #import <wtf/OptionSet.h> > #import <wtf/Optional.h> > >@@ -486,29 +487,29 @@ static RetainPtr<MTLRenderPipelineDescriptor> convertRenderPipelineDescriptor(co > return mtlDescriptor; > } > >-static RetainPtr<MTLRenderPipelineState> tryCreateMtlRenderPipelineState(const char* const functionName, const GPURenderPipelineDescriptor& descriptor, const GPUDevice& device) >+template <typename T> >+static bool tryCreateMtlRenderPipelineState(const char* const functionName, const GPURenderPipelineDescriptor& descriptor, const GPUDevice& device, T&& callback) > { > if (!device.platformDevice()) { > LOG(WebGPU, "GPUComputePipeline::tryCreate(): Invalid GPUDevice!"); >- return nullptr; >+ return false; > } > > auto mtlDescriptor = convertRenderPipelineDescriptor(functionName, descriptor, device); > if (!mtlDescriptor) >- return nullptr; >+ return false; > > RetainPtr<MTLRenderPipelineState> pipeline; > > BEGIN_BLOCK_OBJC_EXCEPTIONS; > >- NSError *error = nil; >- pipeline = adoptNS([device.platformDevice() newRenderPipelineStateWithDescriptor:mtlDescriptor.get() error:&error]); >- if (!pipeline) >- LOG(WebGPU, "%s: %s!", functionName, error.localizedDescription.UTF8String); >+ [device.platformDevice() newRenderPipelineStateWithDescriptor:mtlDescriptor.get() completionHandler:^(id<MTLRenderPipelineState> renderPipelineState, NSError *) { >+ callback(renderPipelineState); >+ }]; > > END_BLOCK_OBJC_EXCEPTIONS; > >- return pipeline; >+ return true; > } > > RefPtr<GPURenderPipeline> GPURenderPipeline::tryCreate(const GPUDevice& device, const GPURenderPipelineDescriptor& descriptor) >@@ -527,16 +528,42 @@ RefPtr<GPURenderPipeline> GPURenderPipeline::tryCreate(const GPUDevice& device, > > // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198387 depthStencilAttachmentDescriptor isn't implemented yet for WHLSL compiler. > >- auto pipeline = tryCreateMtlRenderPipelineState(functionName, descriptor, device); >- if (!pipeline) >+ auto result = adoptRef(new GPURenderPipeline(WTFMove(depthStencil), descriptor.primitiveTopology, descriptor.vertexInput.indexFormat)); >+ >+ auto success = tryCreateMtlRenderPipelineState(functionName, descriptor, device, [=](RetainPtr<MTLRenderPipelineState> mtlRenderPipelineState) { >+ result->setPlatformRenderPipeline(WTFMove(mtlRenderPipelineState)); >+ }); >+ if (!success) > return nullptr; > >- return adoptRef(new GPURenderPipeline(WTFMove(depthStencil), WTFMove(pipeline), descriptor.primitiveTopology, descriptor.vertexInput.indexFormat)); >+ return result; >+} >+ >+void GPURenderPipeline::setPlatformRenderPipeline(RetainPtr<MTLRenderPipelineState>&& mtlRenderPipelineState) >+{ >+ auto locker = holdLock(platformRenderPipelineAndStatusLock); >+ ASSERT(m_compileStatus == CompileStatus::Compiling); >+ m_platformRenderPipeline = WTFMove(mtlRenderPipelineState); >+ if (m_platformRenderPipeline) >+ m_compileStatus = CompileStatus::Succeeded; >+ else >+ m_compileStatus = CompileStatus::Failed; >+ platformRenderPipelineAndStatusCondition.notifyOne(); >+} >+ >+MTLRenderPipelineState *GPURenderPipeline::platformRenderPipeline() const >+{ >+ auto locker = holdLock(platformRenderPipelineAndStatusLock); >+ auto success = platformRenderPipelineAndStatusCondition.waitUntil(platformRenderPipelineAndStatusLock, Condition::Time::infinity(), [&]() { >+ return m_compileStatus != CompileStatus::Compiling; >+ }); >+ if (!success) >+ return nullptr; >+ return m_platformRenderPipeline.get(); > } > >-GPURenderPipeline::GPURenderPipeline(RetainPtr<MTLDepthStencilState>&& depthStencil, RetainPtr<MTLRenderPipelineState>&& pipeline, GPUPrimitiveTopology topology, Optional<GPUIndexFormat> format) >+GPURenderPipeline::GPURenderPipeline(RetainPtr<MTLDepthStencilState>&& depthStencil, GPUPrimitiveTopology topology, Optional<GPUIndexFormat> format) > : m_depthStencilState(WTFMove(depthStencil)) >- , m_platformRenderPipeline(WTFMove(pipeline)) > , m_primitiveTopology(topology) > , m_indexFormat(format) > {
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