Skip to content

Commit

Permalink
Remove the Queue from Metal PLS
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
csmartdalton and csmartdalton committed Mar 15, 2024
1 parent f633c6e commit 3da243c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
337f9df1c04ace751fe16ed2b014477155d9cbfc
e0e55a59eebeb44596d3dfdb669d85e7f656532d
30 changes: 18 additions & 12 deletions Source/Renderer/RenderContextManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ @implementation RiveRendererContext
rive::rcp<rive::pls::PLSRenderTargetMetal> _renderTarget;
}

static std::unique_ptr<rive::pls::PLSRenderContext> make_pls_context_native(
id<MTLDevice> gpu, id<MTLCommandQueue> queue)
static std::unique_ptr<rive::pls::PLSRenderContext> make_pls_context_native(id<MTLDevice> gpu)
{
if (![gpu supportsFamily:MTLGPUFamilyApple1])
{
Expand All @@ -191,8 +190,8 @@ @implementation RiveRendererContext
class PLSRenderContextNativeImpl : public rive::pls::PLSRenderContextMetalImpl
{
public:
PLSRenderContextNativeImpl(id<MTLDevice> gpu, id<MTLCommandQueue> queue) :
PLSRenderContextMetalImpl(gpu, queue, ContextOptions())
PLSRenderContextNativeImpl(id<MTLDevice> gpu) :
PLSRenderContextMetalImpl(gpu, ContextOptions())
{}

protected:
Expand All @@ -219,7 +218,7 @@ @implementation RiveRendererContext
}
};
auto plsContextImpl =
std::unique_ptr<PLSRenderContextNativeImpl>(new PLSRenderContextNativeImpl(gpu, queue));
std::unique_ptr<PLSRenderContextNativeImpl>(new PLSRenderContextNativeImpl(gpu));
return std::make_unique<rive::pls::PLSRenderContext>(std::move(plsContextImpl));
}

Expand All @@ -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<MTLDevice> s_plsGPU = MTLCreateSystemDefaultDevice();
static id<MTLCommandQueue> s_plsQueue = [s_plsGPU newCommandQueue];
static std::unique_ptr<rive::pls::PLSRenderContext> 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();
Expand Down Expand Up @@ -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<MTLCommandBuffer> flushCommandBuffer = [self.metalQueue commandBuffer];
_plsContext->flush({
.renderTarget = _renderTarget.get(),
.externalCommandBuffer = (__bridge void*)flushCommandBuffer,
});
[flushCommandBuffer commit];
}

@end
Expand Down
2 changes: 1 addition & 1 deletion submodules/rive-cpp

0 comments on commit 3da243c

Please sign in to comment.