[graphite] Some clean up in CommandBuffer creation
Makes the Make() method consistent with other methods by passing in Gpu, and adds hooks for command buffer tracking. Bug: skia:12466 Change-Id: If93c2126b1296dcbf788b5471916051fe90dafdf Reviewed-on: https://skia-review.googlesource.com/c/skia/+/457319 Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
parent
cd2f207a2e
commit
89457e9237
@ -21,6 +21,12 @@ ResourceProvider::~ResourceProvider() {
|
||||
fRenderPipelineCache.release();
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandBuffer> ResourceProvider::createCommandBuffer() {
|
||||
// TODO: cache the commandbuffer in an active list and return raw pointer instead
|
||||
|
||||
return this->onCreateCommandBuffer();
|
||||
}
|
||||
|
||||
RenderPipeline* ResourceProvider::findOrCreateRenderPipeline(const RenderPipelineDesc& desc) {
|
||||
return fRenderPipelineCache->refPipeline(desc);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class ResourceProvider {
|
||||
public:
|
||||
virtual ~ResourceProvider();
|
||||
|
||||
virtual std::unique_ptr<CommandBuffer> createCommandBuffer() { return nullptr; }
|
||||
std::unique_ptr<CommandBuffer> createCommandBuffer();
|
||||
RenderPipeline* findOrCreateRenderPipeline(const RenderPipelineDesc&);
|
||||
|
||||
sk_sp<Texture> findOrCreateTexture(SkISize, const TextureInfo&);
|
||||
@ -32,13 +32,11 @@ public:
|
||||
protected:
|
||||
ResourceProvider(const Gpu* gpu);
|
||||
|
||||
virtual std::unique_ptr<RenderPipeline> onCreateRenderPipeline(const RenderPipelineDesc&) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Gpu* fGpu;
|
||||
|
||||
private:
|
||||
virtual std::unique_ptr<CommandBuffer> onCreateCommandBuffer() = 0;
|
||||
virtual std::unique_ptr<RenderPipeline> onCreateRenderPipeline(const RenderPipelineDesc&) = 0;
|
||||
virtual sk_sp<Texture> createTexture(SkISize, const TextureInfo&) = 0;
|
||||
|
||||
class RenderPipelineCache {
|
||||
|
@ -18,10 +18,11 @@
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
namespace skgpu::mtl {
|
||||
class Gpu;
|
||||
|
||||
class CommandBuffer final : public skgpu::CommandBuffer {
|
||||
public:
|
||||
static std::unique_ptr<CommandBuffer> Make(id<MTLCommandQueue>);
|
||||
static std::unique_ptr<CommandBuffer> Make(const Gpu*);
|
||||
~CommandBuffer() override {}
|
||||
|
||||
private:
|
||||
|
@ -7,10 +7,13 @@
|
||||
|
||||
#include "experimental/graphite/src/mtl/MtlCommandBuffer.h"
|
||||
|
||||
#include "experimental/graphite/src/mtl/MtlGpu.h"
|
||||
|
||||
namespace skgpu::mtl {
|
||||
|
||||
std::unique_ptr<CommandBuffer> CommandBuffer::Make(id<MTLCommandQueue> queue) {
|
||||
std::unique_ptr<CommandBuffer> CommandBuffer::Make(const Gpu* gpu) {
|
||||
sk_cfp<id<MTLCommandBuffer>> cmdBuffer;
|
||||
id<MTLCommandQueue> queue = gpu->queue();
|
||||
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
|
||||
sk_cfp<MTLCommandBufferDescriptor*> desc([[MTLCommandBufferDescriptor alloc] init]);
|
||||
(*desc).retainedReferences = NO;
|
||||
|
@ -25,11 +25,10 @@ public:
|
||||
ResourceProvider(const skgpu::Gpu* gpu);
|
||||
~ResourceProvider() override {}
|
||||
|
||||
std::unique_ptr<skgpu::CommandBuffer> createCommandBuffer() override;
|
||||
|
||||
private:
|
||||
const Gpu* mtlGpu();
|
||||
|
||||
std::unique_ptr<skgpu::CommandBuffer> onCreateCommandBuffer() override;
|
||||
std::unique_ptr<skgpu::RenderPipeline> onCreateRenderPipeline(
|
||||
const RenderPipelineDesc&) override;
|
||||
sk_sp<skgpu::Texture> createTexture(SkISize, const skgpu::TextureInfo&) override;
|
||||
|
@ -24,8 +24,8 @@ const Gpu* ResourceProvider::mtlGpu() {
|
||||
return static_cast<const Gpu*>(fGpu);
|
||||
}
|
||||
|
||||
std::unique_ptr<skgpu::CommandBuffer> ResourceProvider::createCommandBuffer() {
|
||||
return CommandBuffer::Make(this->mtlGpu()->queue());
|
||||
std::unique_ptr<skgpu::CommandBuffer> ResourceProvider::onCreateCommandBuffer() {
|
||||
return CommandBuffer::Make(this->mtlGpu());
|
||||
}
|
||||
|
||||
std::unique_ptr<skgpu::RenderPipeline> ResourceProvider::onCreateRenderPipeline(
|
||||
|
Loading…
Reference in New Issue
Block a user