From 3da243cb69ad110278fee78f450c9d3b638669a7 Mon Sep 17 00:00:00 2001 From: csmartdalton Date: Fri, 15 Mar 2024 19:38:14 +0000 Subject: [PATCH] Remove the Queue from Metal PLS Always require the client to supply and commit their own external command buffer. Diffs= e0e55a59e Remove the Queue from Metal PLS (#6852) Co-authored-by: Chris Dalton <99840794+csmartdalton@users.noreply.github.com> --- .rive_head | 2 +- Source/Renderer/RenderContextManager.mm | 30 +++++++++++++++---------- submodules/rive-cpp | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.rive_head b/.rive_head index 6076c3e5..747fdb36 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -337f9df1c04ace751fe16ed2b014477155d9cbfc +e0e55a59eebeb44596d3dfdb669d85e7f656532d diff --git a/Source/Renderer/RenderContextManager.mm b/Source/Renderer/RenderContextManager.mm index ab3622d8..f8822fb6 100644 --- a/Source/Renderer/RenderContextManager.mm +++ b/Source/Renderer/RenderContextManager.mm @@ -180,8 +180,7 @@ @implementation RiveRendererContext rive::rcp _renderTarget; } -static std::unique_ptr make_pls_context_native( - id gpu, id queue) +static std::unique_ptr make_pls_context_native(id gpu) { if (![gpu supportsFamily:MTLGPUFamilyApple1]) { @@ -191,8 +190,8 @@ @implementation RiveRendererContext class PLSRenderContextNativeImpl : public rive::pls::PLSRenderContextMetalImpl { public: - PLSRenderContextNativeImpl(id gpu, id queue) : - PLSRenderContextMetalImpl(gpu, queue, ContextOptions()) + PLSRenderContextNativeImpl(id gpu) : + PLSRenderContextMetalImpl(gpu, ContextOptions()) {} protected: @@ -219,7 +218,7 @@ @implementation RiveRendererContext } }; auto plsContextImpl = - std::unique_ptr(new PLSRenderContextNativeImpl(gpu, queue)); + std::unique_ptr(new PLSRenderContextNativeImpl(gpu)); return std::make_unique(std::move(plsContextImpl)); } @@ -228,13 +227,12 @@ - (instancetype)init // Make a single static PLSRenderContext, since it is also the factory and any objects it // creates may outlive this 'RiveContext' instance. static id s_plsGPU = MTLCreateSystemDefaultDevice(); - static id s_plsQueue = [s_plsGPU newCommandQueue]; static std::unique_ptr s_plsContext = - make_pls_context_native(s_plsGPU, s_plsQueue); + make_pls_context_native(s_plsGPU); self = [super init]; self.metalDevice = s_plsGPU; - self.metalQueue = s_plsQueue; + self.metalQueue = [s_plsGPU newCommandQueue]; self.depthStencilPixelFormat = MTLPixelFormatInvalid; self.framebufferOnly = YES; _plsContext = s_plsContext.get(); @@ -282,15 +280,23 @@ - (void)dealloc } _renderTarget->setTargetTexture(surface.texture); - rive::pls::PLSRenderContext::FrameDescriptor frameDescriptor; - frameDescriptor.renderTarget = _renderTarget; - _plsContext->beginFrame(std::move(frameDescriptor)); + _plsContext->beginFrame({ + .renderTargetWidth = _renderTarget->width(), + .renderTargetHeight = _renderTarget->height(), + .loadAction = rive::pls::LoadAction::clear, + .clearColor = 0, + }); return _renderer.get(); } - (void)endFrame { - _plsContext->flush(); + id flushCommandBuffer = [self.metalQueue commandBuffer]; + _plsContext->flush({ + .renderTarget = _renderTarget.get(), + .externalCommandBuffer = (__bridge void*)flushCommandBuffer, + }); + [flushCommandBuffer commit]; } @end diff --git a/submodules/rive-cpp b/submodules/rive-cpp index f21904e9..dcd45e12 160000 --- a/submodules/rive-cpp +++ b/submodules/rive-cpp @@ -1 +1 @@ -Subproject commit f21904e92e76d205b4280e3c4822a0f50df7d487 +Subproject commit dcd45e122000e551b87d6f4e5d4a13e493443751