[graphite] Add CommandBuffer creation
Bug: skia:12466 Change-Id: I3a22d03e5042a94f2bf6d379b2fff17f0b48edb3 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/455217 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
parent
bedb69ccfb
commit
1f9be54238
@ -12,7 +12,7 @@ namespace skgpu {
|
||||
|
||||
class CommandBuffer {
|
||||
public:
|
||||
virtual ~CommandBuffer() = default;
|
||||
virtual ~CommandBuffer() {}
|
||||
|
||||
protected:
|
||||
CommandBuffer();
|
||||
|
@ -18,12 +18,6 @@ ResourceProvider::ResourceProvider() {
|
||||
ResourceProvider::~ResourceProvider() {
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandBuffer> ResourceProvider::createCommandBuffer() {
|
||||
auto cb = this->onCreateCommandBuffer();
|
||||
|
||||
return cb;
|
||||
}
|
||||
|
||||
Pipeline* ResourceProvider::findOrCreatePipeline(const PipelineDesc& desc) {
|
||||
// TODO: look through cache for matching pipeline
|
||||
|
||||
@ -34,8 +28,4 @@ Pipeline* ResourceProvider::findOrCreatePipeline(const PipelineDesc& desc) {
|
||||
return pso;
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandBuffer> onCreateCommandBuffer() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -20,13 +20,12 @@ class ResourceProvider {
|
||||
public:
|
||||
virtual ~ResourceProvider();
|
||||
|
||||
std::unique_ptr<CommandBuffer> createCommandBuffer();
|
||||
virtual std::unique_ptr<CommandBuffer> createCommandBuffer() { return nullptr; }
|
||||
Pipeline* findOrCreatePipeline(const PipelineDesc&);
|
||||
|
||||
protected:
|
||||
ResourceProvider();
|
||||
|
||||
virtual std::unique_ptr<CommandBuffer> onCreateCommandBuffer();
|
||||
virtual Pipeline* onCreatePipeline() { return nullptr; }
|
||||
|
||||
private:
|
||||
|
@ -10,16 +10,25 @@
|
||||
|
||||
#include "experimental/graphite/src/CommandBuffer.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "include/ports/SkCFObject.h"
|
||||
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
namespace skgpu::mtl {
|
||||
|
||||
class CommandBuffer final : public skgpu::CommandBuffer {
|
||||
public:
|
||||
CommandBuffer();
|
||||
static std::unique_ptr<CommandBuffer> Make(id<MTLCommandQueue>);
|
||||
~CommandBuffer() override {}
|
||||
|
||||
private:
|
||||
CommandBuffer(sk_cfp<id<MTLCommandBuffer>> cmdBuffer)
|
||||
: fCommandBuffer(std::move(cmdBuffer)) {}
|
||||
|
||||
sk_cfp<id<MTLCommandBuffer>> fCommandBuffer;
|
||||
};
|
||||
|
||||
} // namespace skgpu::mtl
|
||||
|
@ -9,7 +9,24 @@
|
||||
|
||||
namespace skgpu::mtl {
|
||||
|
||||
CommandBuffer::CommandBuffer() {
|
||||
std::unique_ptr<CommandBuffer> CommandBuffer::Make(id<MTLCommandQueue> queue) {
|
||||
sk_cfp<MTLCommandBufferDescriptor*> desc([[MTLCommandBufferDescriptor alloc] init]);
|
||||
(*desc).retainedReferences = NO;
|
||||
#ifdef SK_ENABLE_MTL_DEBUG_INFO
|
||||
(*desc).errorOptions = MTLCommandBufferErrorOptionEncoderExecutionStatus;
|
||||
#endif
|
||||
|
||||
// We add a retain here because the command buffer is set to autorelease (not alloc or copy)
|
||||
sk_cfp<id<MTLCommandBuffer>> cmdBuffer([[queue commandBufferWithDescriptor:desc.get()] retain]);
|
||||
if (cmdBuffer == nil) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef SK_ENABLE_MTL_DEBUG_INFO
|
||||
(*cmdBuffer).label = @"CommandBuffer::Make";
|
||||
#endif
|
||||
|
||||
return std::unique_ptr<CommandBuffer>(new CommandBuffer(std::move(cmdBuffer)));
|
||||
}
|
||||
|
||||
} // namespace skgpu::mtl
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
~Gpu() override;
|
||||
|
||||
id<MTLDevice> device() const { return fDevice.get(); }
|
||||
id<MTLCommandQueue> queue() const { return fQueue.get(); }
|
||||
|
||||
const Caps& mtlCaps() const { return static_cast<const Caps&>(*this->caps()); }
|
||||
|
||||
|
@ -12,14 +12,23 @@
|
||||
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
namespace skgpu {
|
||||
class CommandBuffer;
|
||||
}
|
||||
|
||||
namespace skgpu::mtl {
|
||||
|
||||
class Gpu;
|
||||
|
||||
class ResourceProvider final : public skgpu::ResourceProvider {
|
||||
public:
|
||||
ResourceProvider();
|
||||
ResourceProvider(const Gpu*);
|
||||
~ResourceProvider() override {}
|
||||
|
||||
std::unique_ptr<skgpu::CommandBuffer> createCommandBuffer() override;
|
||||
|
||||
private:
|
||||
const Gpu* fGpu;
|
||||
};
|
||||
|
||||
} // namespace skgpu::mtl
|
||||
|
@ -7,9 +7,17 @@
|
||||
|
||||
#include "experimental/graphite/src/mtl/MtlResourceProvider.h"
|
||||
|
||||
#include "experimental/graphite/src/mtl/MtlCommandBuffer.h"
|
||||
#include "experimental/graphite/src/mtl/MtlGpu.h"
|
||||
|
||||
namespace skgpu::mtl {
|
||||
|
||||
ResourceProvider::ResourceProvider() {
|
||||
ResourceProvider::ResourceProvider(const Gpu* gpu)
|
||||
: fGpu(gpu) {
|
||||
}
|
||||
|
||||
std::unique_ptr<skgpu::CommandBuffer> ResourceProvider::createCommandBuffer() {
|
||||
return CommandBuffer::Make(fGpu->queue());
|
||||
}
|
||||
|
||||
} // namespace skgpu::mtl
|
||||
|
Loading…
Reference in New Issue
Block a user