[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();
|
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) {
|
RenderPipeline* ResourceProvider::findOrCreateRenderPipeline(const RenderPipelineDesc& desc) {
|
||||||
return fRenderPipelineCache->refPipeline(desc);
|
return fRenderPipelineCache->refPipeline(desc);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class ResourceProvider {
|
|||||||
public:
|
public:
|
||||||
virtual ~ResourceProvider();
|
virtual ~ResourceProvider();
|
||||||
|
|
||||||
virtual std::unique_ptr<CommandBuffer> createCommandBuffer() { return nullptr; }
|
std::unique_ptr<CommandBuffer> createCommandBuffer();
|
||||||
RenderPipeline* findOrCreateRenderPipeline(const RenderPipelineDesc&);
|
RenderPipeline* findOrCreateRenderPipeline(const RenderPipelineDesc&);
|
||||||
|
|
||||||
sk_sp<Texture> findOrCreateTexture(SkISize, const TextureInfo&);
|
sk_sp<Texture> findOrCreateTexture(SkISize, const TextureInfo&);
|
||||||
@ -32,13 +32,11 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
ResourceProvider(const Gpu* gpu);
|
ResourceProvider(const Gpu* gpu);
|
||||||
|
|
||||||
virtual std::unique_ptr<RenderPipeline> onCreateRenderPipeline(const RenderPipelineDesc&) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Gpu* fGpu;
|
const Gpu* fGpu;
|
||||||
|
|
||||||
private:
|
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;
|
virtual sk_sp<Texture> createTexture(SkISize, const TextureInfo&) = 0;
|
||||||
|
|
||||||
class RenderPipelineCache {
|
class RenderPipelineCache {
|
||||||
|
@ -18,10 +18,11 @@
|
|||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
|
|
||||||
namespace skgpu::mtl {
|
namespace skgpu::mtl {
|
||||||
|
class Gpu;
|
||||||
|
|
||||||
class CommandBuffer final : public skgpu::CommandBuffer {
|
class CommandBuffer final : public skgpu::CommandBuffer {
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<CommandBuffer> Make(id<MTLCommandQueue>);
|
static std::unique_ptr<CommandBuffer> Make(const Gpu*);
|
||||||
~CommandBuffer() override {}
|
~CommandBuffer() override {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -7,10 +7,13 @@
|
|||||||
|
|
||||||
#include "experimental/graphite/src/mtl/MtlCommandBuffer.h"
|
#include "experimental/graphite/src/mtl/MtlCommandBuffer.h"
|
||||||
|
|
||||||
|
#include "experimental/graphite/src/mtl/MtlGpu.h"
|
||||||
|
|
||||||
namespace skgpu::mtl {
|
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;
|
sk_cfp<id<MTLCommandBuffer>> cmdBuffer;
|
||||||
|
id<MTLCommandQueue> queue = gpu->queue();
|
||||||
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
|
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
|
||||||
sk_cfp<MTLCommandBufferDescriptor*> desc([[MTLCommandBufferDescriptor alloc] init]);
|
sk_cfp<MTLCommandBufferDescriptor*> desc([[MTLCommandBufferDescriptor alloc] init]);
|
||||||
(*desc).retainedReferences = NO;
|
(*desc).retainedReferences = NO;
|
||||||
|
@ -25,11 +25,10 @@ public:
|
|||||||
ResourceProvider(const skgpu::Gpu* gpu);
|
ResourceProvider(const skgpu::Gpu* gpu);
|
||||||
~ResourceProvider() override {}
|
~ResourceProvider() override {}
|
||||||
|
|
||||||
std::unique_ptr<skgpu::CommandBuffer> createCommandBuffer() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Gpu* mtlGpu();
|
const Gpu* mtlGpu();
|
||||||
|
|
||||||
|
std::unique_ptr<skgpu::CommandBuffer> onCreateCommandBuffer() override;
|
||||||
std::unique_ptr<skgpu::RenderPipeline> onCreateRenderPipeline(
|
std::unique_ptr<skgpu::RenderPipeline> onCreateRenderPipeline(
|
||||||
const RenderPipelineDesc&) override;
|
const RenderPipelineDesc&) override;
|
||||||
sk_sp<skgpu::Texture> createTexture(SkISize, const skgpu::TextureInfo&) 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);
|
return static_cast<const Gpu*>(fGpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<skgpu::CommandBuffer> ResourceProvider::createCommandBuffer() {
|
std::unique_ptr<skgpu::CommandBuffer> ResourceProvider::onCreateCommandBuffer() {
|
||||||
return CommandBuffer::Make(this->mtlGpu()->queue());
|
return CommandBuffer::Make(this->mtlGpu());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<skgpu::RenderPipeline> ResourceProvider::onCreateRenderPipeline(
|
std::unique_ptr<skgpu::RenderPipeline> ResourceProvider::onCreateRenderPipeline(
|
||||||
|
Loading…
Reference in New Issue
Block a user