[graphite] Rename RenderPipeline[Desc] to GraphicsPipeline[Desc]
Also updates MtlRenderPipeline to be MtlGraphicsPipeline to match the type it extends, although we could choose to have it stay matched with the backend object (MTLRenderPipeline) that it wraps instead. Bug: skia:12466 Change-Id: Ida118e68a93d737d21edca15a59f5e64e17b5fd0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/467780 Reviewed-by: Jim Van Verth <jvanverth@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
parent
a4dc43cdec
commit
497ac0fe23
@ -8,7 +8,7 @@
|
||||
#include "experimental/graphite/src/CommandBuffer.h"
|
||||
|
||||
#include "experimental/graphite/include/private/GraphiteTypesPriv.h"
|
||||
#include "experimental/graphite/src/RenderPipeline.h"
|
||||
#include "experimental/graphite/src/GraphicsPipeline.h"
|
||||
#include "src/core/SkTraceEvent.h"
|
||||
|
||||
#include "experimental/graphite/src/Buffer.h"
|
||||
@ -36,9 +36,9 @@ void CommandBuffer::beginRenderPass(const RenderPassDesc& renderPassDesc) {
|
||||
}
|
||||
}
|
||||
|
||||
void CommandBuffer::bindRenderPipeline(sk_sp<RenderPipeline> renderPipeline) {
|
||||
this->onBindRenderPipeline(renderPipeline.get());
|
||||
this->trackResource(std::move(renderPipeline));
|
||||
void CommandBuffer::bindGraphicsPipeline(sk_sp<GraphicsPipeline> graphicsPipeline) {
|
||||
this->onBindGraphicsPipeline(graphicsPipeline.get());
|
||||
this->trackResource(std::move(graphicsPipeline));
|
||||
fHasWork = true;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ struct SkIRect;
|
||||
namespace skgpu {
|
||||
class Buffer;
|
||||
class Gpu;
|
||||
class RenderPipeline;
|
||||
class GraphicsPipeline;
|
||||
class Texture;
|
||||
|
||||
struct AttachmentDesc {
|
||||
@ -59,7 +59,7 @@ public:
|
||||
//---------------------------------------------------------------
|
||||
// Can only be used within renderpasses
|
||||
//---------------------------------------------------------------
|
||||
void bindRenderPipeline(sk_sp<RenderPipeline> renderPipeline);
|
||||
void bindGraphicsPipeline(sk_sp<GraphicsPipeline> graphicsPipeline);
|
||||
void bindUniformBuffer(sk_sp<Buffer>, size_t bufferOffset);
|
||||
void bindVertexBuffers(sk_sp<Buffer> vertexBuffer, sk_sp<Buffer> instanceBuffer);
|
||||
void bindIndexBuffer(sk_sp<Buffer> indexBuffer, size_t bufferOffset);
|
||||
@ -103,7 +103,7 @@ private:
|
||||
|
||||
virtual void onBeginRenderPass(const RenderPassDesc&) = 0;
|
||||
|
||||
virtual void onBindRenderPipeline(const RenderPipeline*) = 0;
|
||||
virtual void onBindGraphicsPipeline(const GraphicsPipeline*) = 0;
|
||||
virtual void onBindUniformBuffer(const Buffer*, size_t bufferOffset) = 0;
|
||||
virtual void onBindVertexBuffers(const Buffer* vertexBuffer, const Buffer* instanceBuffer) = 0;
|
||||
virtual void onBindIndexBuffer(const Buffer* indexBuffer, size_t bufferOffset) = 0;
|
||||
|
@ -5,14 +5,14 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "experimental/graphite/src/RenderPipeline.h"
|
||||
#include "experimental/graphite/src/GraphicsPipeline.h"
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
RenderPipeline::RenderPipeline() {
|
||||
GraphicsPipeline::GraphicsPipeline() {
|
||||
}
|
||||
|
||||
RenderPipeline::~RenderPipeline() {
|
||||
GraphicsPipeline::~GraphicsPipeline() {
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
37
experimental/graphite/src/GraphicsPipeline.h
Normal file
37
experimental/graphite/src/GraphicsPipeline.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2021 Google LLC
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef skgpu_GraphicsPipeline_DEFINED
|
||||
#define skgpu_GraphicsPipeline_DEFINED
|
||||
|
||||
#include "include/core/SkRefCnt.h"
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
/**
|
||||
* GraphicsPipeline corresponds to a backend specific pipeline used for rendering (vs. compute),
|
||||
* e.g. MTLRenderPipelineState (Metal),
|
||||
* CreateRenderPipeline (Dawn),
|
||||
* CreateGraphicsPipelineState (D3D12),
|
||||
* or VkGraphicsPipelineCreateInfo (Vulkan).
|
||||
*
|
||||
* A GraphicsPipeline is created from the combination of a GraphicsPipelineDesc (representing draw
|
||||
* specific configuration) and a RenderPassDesc (representing the target of the draw).
|
||||
*/
|
||||
class GraphicsPipeline : public SkRefCnt {
|
||||
public:
|
||||
~GraphicsPipeline() override;
|
||||
|
||||
protected:
|
||||
GraphicsPipeline();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace skgpu
|
||||
|
||||
#endif // skgpu_GraphicsPipeline_DEFINED
|
@ -5,11 +5,11 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "experimental/graphite/src/RenderPipelineDesc.h"
|
||||
#include "experimental/graphite/src/GraphicsPipelineDesc.h"
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
RenderPipelineDesc::RenderPipelineDesc() {
|
||||
GraphicsPipelineDesc::GraphicsPipelineDesc() {
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
@ -5,8 +5,8 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef skgpu_RenderPipelineDesc_DEFINED
|
||||
#define skgpu_RenderPipelineDesc_DEFINED
|
||||
#ifndef skgpu_GraphicsPipelineDesc_DEFINED
|
||||
#define skgpu_GraphicsPipelineDesc_DEFINED
|
||||
|
||||
#include "include/core/SkTypes.h"
|
||||
|
||||
@ -15,9 +15,13 @@
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
class RenderPipelineDesc {
|
||||
/**
|
||||
* GraphicsPipelineDesc represents the state needed to create a backend specific GraphicsPipeline,
|
||||
* minus the target-specific properties that can be inferred from the DrawPass and RenderPassTask.
|
||||
*/
|
||||
class GraphicsPipelineDesc {
|
||||
public:
|
||||
RenderPipelineDesc();
|
||||
GraphicsPipelineDesc();
|
||||
|
||||
/** Describes a vertex or instance attribute. */
|
||||
class Attribute {
|
||||
@ -95,7 +99,7 @@ public:
|
||||
size_t stride() const { return fStride; }
|
||||
|
||||
private:
|
||||
friend class RenderPipelineDesc;
|
||||
friend class GraphicsPipelineDesc;
|
||||
void init(const Attribute* attrs, int count) {
|
||||
fAttributes = attrs;
|
||||
fRawCount = count;
|
||||
@ -126,11 +130,11 @@ public:
|
||||
return fKey.size() * sizeof(uint32_t);
|
||||
}
|
||||
|
||||
bool operator==(const RenderPipelineDesc& that) const {
|
||||
bool operator==(const GraphicsPipelineDesc& that) const {
|
||||
return this->fKey == that.fKey;
|
||||
}
|
||||
|
||||
bool operator!=(const RenderPipelineDesc& other) const {
|
||||
bool operator!=(const GraphicsPipelineDesc& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
@ -252,10 +256,10 @@ static constexpr inline size_t VertexAttribTypeSize(VertexAttribType type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
constexpr size_t RenderPipelineDesc::Attribute::size() const {
|
||||
constexpr size_t GraphicsPipelineDesc::Attribute::size() const {
|
||||
return VertexAttribTypeSize(fCPUType);
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
||||
|
||||
#endif // skgpu_RenderPipelineDesc_DEFINED
|
||||
#endif // skgpu_GraphicsPipelineDesc_DEFINED
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021 Google LLC
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef skgpu_RenderPipeline_DEFINED
|
||||
#define skgpu_RenderPipeline_DEFINED
|
||||
|
||||
#include "include/core/SkRefCnt.h"
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
class RenderPipeline : public SkRefCnt {
|
||||
public:
|
||||
~RenderPipeline() override;
|
||||
|
||||
protected:
|
||||
RenderPipeline();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace skgpu
|
||||
|
||||
#endif // skgpu_RenderPipeline_DEFINED
|
@ -9,50 +9,50 @@
|
||||
|
||||
#include "experimental/graphite/src/Buffer.h"
|
||||
#include "experimental/graphite/src/CommandBuffer.h"
|
||||
#include "experimental/graphite/src/RenderPipeline.h"
|
||||
#include "experimental/graphite/src/GraphicsPipeline.h"
|
||||
#include "experimental/graphite/src/Texture.h"
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
ResourceProvider::ResourceProvider(const Gpu* gpu) : fGpu(gpu) {
|
||||
fRenderPipelineCache.reset(new RenderPipelineCache(this));
|
||||
fGraphicsPipelineCache.reset(new GraphicsPipelineCache(this));
|
||||
}
|
||||
|
||||
ResourceProvider::~ResourceProvider() {
|
||||
fRenderPipelineCache.release();
|
||||
fGraphicsPipelineCache.release();
|
||||
}
|
||||
|
||||
sk_sp<RenderPipeline> ResourceProvider::findOrCreateRenderPipeline(const RenderPipelineDesc& desc) {
|
||||
return fRenderPipelineCache->refPipeline(desc);
|
||||
sk_sp<GraphicsPipeline> ResourceProvider::findOrCreateGraphicsPipeline(
|
||||
const GraphicsPipelineDesc& desc) {
|
||||
return fGraphicsPipelineCache->refPipeline(desc);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct ResourceProvider::RenderPipelineCache::Entry {
|
||||
Entry(sk_sp<RenderPipeline> pipeline)
|
||||
: fPipeline(std::move(pipeline)) {}
|
||||
struct ResourceProvider::GraphicsPipelineCache::Entry {
|
||||
Entry(sk_sp<GraphicsPipeline> pipeline) : fPipeline(std::move(pipeline)) {}
|
||||
|
||||
sk_sp<RenderPipeline> fPipeline;
|
||||
sk_sp<GraphicsPipeline> fPipeline;
|
||||
};
|
||||
|
||||
ResourceProvider::RenderPipelineCache::RenderPipelineCache(ResourceProvider* resourceProvider)
|
||||
ResourceProvider::GraphicsPipelineCache::GraphicsPipelineCache(ResourceProvider* resourceProvider)
|
||||
: fMap(16) // TODO: find a good value for this
|
||||
, fResourceProvider(resourceProvider) {}
|
||||
|
||||
ResourceProvider::RenderPipelineCache::~RenderPipelineCache() {
|
||||
ResourceProvider::GraphicsPipelineCache::~GraphicsPipelineCache() {
|
||||
SkASSERT(0 == fMap.count());
|
||||
}
|
||||
|
||||
void ResourceProvider::RenderPipelineCache::release() {
|
||||
void ResourceProvider::GraphicsPipelineCache::release() {
|
||||
fMap.reset();
|
||||
}
|
||||
|
||||
sk_sp<RenderPipeline> ResourceProvider::RenderPipelineCache::refPipeline(
|
||||
const RenderPipelineDesc& desc) {
|
||||
sk_sp<GraphicsPipeline> ResourceProvider::GraphicsPipelineCache::refPipeline(
|
||||
const GraphicsPipelineDesc& desc) {
|
||||
std::unique_ptr<Entry>* entry = fMap.find(desc);
|
||||
|
||||
if (!entry) {
|
||||
auto pipeline = fResourceProvider->onCreateRenderPipeline(desc);
|
||||
auto pipeline = fResourceProvider->onCreateGraphicsPipeline(desc);
|
||||
if (!pipeline) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -10,17 +10,15 @@
|
||||
|
||||
#include "experimental/graphite/include/private/GraphiteTypesPriv.h"
|
||||
#include "experimental/graphite/src/CommandBuffer.h"
|
||||
#include "experimental/graphite/src/RenderPipeline.h"
|
||||
#include "experimental/graphite/src/RenderPipelineDesc.h"
|
||||
#include "experimental/graphite/src/GraphicsPipelineDesc.h"
|
||||
#include "include/core/SkSize.h"
|
||||
#include "src/core/SkLRUCache.h"
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
class Buffer;
|
||||
class CommandBuffer;
|
||||
class Gpu;
|
||||
class RenderPipeline;
|
||||
class GraphicsPipeline;
|
||||
class Texture;
|
||||
class TextureInfo;
|
||||
|
||||
@ -30,7 +28,7 @@ public:
|
||||
|
||||
virtual sk_sp<CommandBuffer> createCommandBuffer() = 0;
|
||||
|
||||
sk_sp<RenderPipeline> findOrCreateRenderPipeline(const RenderPipelineDesc&);
|
||||
sk_sp<GraphicsPipeline> findOrCreateGraphicsPipeline(const GraphicsPipelineDesc&);
|
||||
|
||||
sk_sp<Texture> findOrCreateTexture(SkISize, const TextureInfo&);
|
||||
|
||||
@ -42,34 +40,34 @@ protected:
|
||||
const Gpu* fGpu;
|
||||
|
||||
private:
|
||||
virtual sk_sp<RenderPipeline> onCreateRenderPipeline(const RenderPipelineDesc&) = 0;
|
||||
virtual sk_sp<GraphicsPipeline> onCreateGraphicsPipeline(const GraphicsPipelineDesc&) = 0;
|
||||
virtual sk_sp<Texture> createTexture(SkISize, const TextureInfo&) = 0;
|
||||
virtual sk_sp<Buffer> createBuffer(size_t size, BufferType type, PrioritizeGpuReads) = 0;
|
||||
|
||||
class RenderPipelineCache {
|
||||
class GraphicsPipelineCache {
|
||||
public:
|
||||
RenderPipelineCache(ResourceProvider* resourceProvider);
|
||||
~RenderPipelineCache();
|
||||
GraphicsPipelineCache(ResourceProvider* resourceProvider);
|
||||
~GraphicsPipelineCache();
|
||||
|
||||
void release();
|
||||
sk_sp<RenderPipeline> refPipeline(const RenderPipelineDesc&);
|
||||
sk_sp<GraphicsPipeline> refPipeline(const GraphicsPipelineDesc&);
|
||||
|
||||
private:
|
||||
struct Entry;
|
||||
|
||||
struct DescHash {
|
||||
uint32_t operator()(const RenderPipelineDesc& desc) const {
|
||||
uint32_t operator()(const GraphicsPipelineDesc& desc) const {
|
||||
return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0);
|
||||
}
|
||||
};
|
||||
|
||||
SkLRUCache<const RenderPipelineDesc, std::unique_ptr<Entry>, DescHash> fMap;
|
||||
SkLRUCache<const GraphicsPipelineDesc, std::unique_ptr<Entry>, DescHash> fMap;
|
||||
|
||||
ResourceProvider* fResourceProvider;
|
||||
};
|
||||
|
||||
// Cache of RenderPipelines
|
||||
std::unique_ptr<RenderPipelineCache> fRenderPipelineCache;
|
||||
// Cache of GraphicsPipelines
|
||||
std::unique_ptr<GraphicsPipelineCache> fGraphicsPipelineCache;
|
||||
};
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -47,7 +47,7 @@ private:
|
||||
void onBeginRenderPass(const RenderPassDesc&) override;
|
||||
void endRenderPass() override;
|
||||
|
||||
void onBindRenderPipeline(const skgpu::RenderPipeline*) override;
|
||||
void onBindGraphicsPipeline(const skgpu::GraphicsPipeline*) override;
|
||||
void onBindUniformBuffer(const skgpu::Buffer*, size_t offset) override;
|
||||
void onBindVertexBuffers(const skgpu::Buffer* vertexBuffer,
|
||||
const skgpu::Buffer* instanceBuffer) override;
|
||||
|
@ -10,8 +10,8 @@
|
||||
#include "experimental/graphite/src/mtl/MtlBlitCommandEncoder.h"
|
||||
#include "experimental/graphite/src/mtl/MtlBuffer.h"
|
||||
#include "experimental/graphite/src/mtl/MtlGpu.h"
|
||||
#include "experimental/graphite/src/mtl/MtlGraphicsPipeline.h"
|
||||
#include "experimental/graphite/src/mtl/MtlRenderCommandEncoder.h"
|
||||
#include "experimental/graphite/src/mtl/MtlRenderPipeline.h"
|
||||
#include "experimental/graphite/src/mtl/MtlTexture.h"
|
||||
|
||||
namespace skgpu::mtl {
|
||||
@ -137,14 +137,14 @@ void CommandBuffer::endBlitCommandEncoder() {
|
||||
}
|
||||
}
|
||||
|
||||
void CommandBuffer::onBindRenderPipeline(const skgpu::RenderPipeline* renderPipeline) {
|
||||
void CommandBuffer::onBindGraphicsPipeline(const skgpu::GraphicsPipeline* graphicsPipeline) {
|
||||
SkASSERT(fActiveRenderCommandEncoder);
|
||||
|
||||
auto mtlRenderPipeline = static_cast<const RenderPipeline*>(renderPipeline);
|
||||
auto pipelineState = mtlRenderPipeline->mtlPipelineState();
|
||||
auto mtlPipeline = static_cast<const GraphicsPipeline*>(graphicsPipeline);
|
||||
auto pipelineState = mtlPipeline->mtlPipelineState();
|
||||
fActiveRenderCommandEncoder->setRenderPipelineState(pipelineState);
|
||||
fCurrentVertexStride = mtlRenderPipeline->vertexStride();
|
||||
fCurrentInstanceStride = mtlRenderPipeline->instanceStride();
|
||||
fCurrentVertexStride = mtlPipeline->vertexStride();
|
||||
fCurrentInstanceStride = mtlPipeline->instanceStride();
|
||||
}
|
||||
|
||||
void CommandBuffer::onBindUniformBuffer(const skgpu::Buffer* uniformBuffer,
|
||||
@ -154,9 +154,9 @@ void CommandBuffer::onBindUniformBuffer(const skgpu::Buffer* uniformBuffer,
|
||||
id<MTLBuffer> mtlBuffer = static_cast<const Buffer*>(uniformBuffer)->mtlBuffer();
|
||||
|
||||
fActiveRenderCommandEncoder->setVertexBuffer(mtlBuffer, uniformOffset,
|
||||
RenderPipeline::kUniformBufferIndex);
|
||||
GraphicsPipeline::kUniformBufferIndex);
|
||||
fActiveRenderCommandEncoder->setFragmentBuffer(mtlBuffer, uniformOffset,
|
||||
RenderPipeline::kUniformBufferIndex);
|
||||
GraphicsPipeline::kUniformBufferIndex);
|
||||
}
|
||||
|
||||
void CommandBuffer::onBindVertexBuffers(const skgpu::Buffer* vertexBuffer,
|
||||
@ -166,12 +166,12 @@ void CommandBuffer::onBindVertexBuffers(const skgpu::Buffer* vertexBuffer,
|
||||
if (vertexBuffer) {
|
||||
id<MTLBuffer> mtlBuffer = static_cast<const Buffer*>(vertexBuffer)->mtlBuffer();
|
||||
fActiveRenderCommandEncoder->setVertexBuffer(mtlBuffer, 0,
|
||||
RenderPipeline::kVertexBufferIndex);
|
||||
GraphicsPipeline::kVertexBufferIndex);
|
||||
}
|
||||
if (instanceBuffer) {
|
||||
id<MTLBuffer> mtlBuffer = static_cast<const Buffer*>(instanceBuffer)->mtlBuffer();
|
||||
fActiveRenderCommandEncoder->setVertexBuffer(mtlBuffer, 0,
|
||||
RenderPipeline::kInstanceBufferIndex);
|
||||
GraphicsPipeline::kInstanceBufferIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,7 +214,7 @@ void CommandBuffer::onDrawIndexed(PrimitiveType type, unsigned int baseIndex,
|
||||
auto mtlPrimitiveType = graphite_to_mtl_primitive(type);
|
||||
|
||||
fActiveRenderCommandEncoder->setVertexBufferOffset(baseVertex * fCurrentVertexStride,
|
||||
RenderPipeline::kVertexBufferIndex);
|
||||
GraphicsPipeline::kVertexBufferIndex);
|
||||
size_t indexOffset = fCurrentIndexBufferOffset + sizeof(uint16_t )* baseIndex;
|
||||
fActiveRenderCommandEncoder->drawIndexedPrimitives(mtlPrimitiveType, indexCount,
|
||||
MTLIndexTypeUInt16, fCurrentIndexBuffer,
|
||||
@ -241,9 +241,9 @@ void CommandBuffer::onDrawIndexedInstanced(PrimitiveType type, unsigned int base
|
||||
auto mtlPrimitiveType = graphite_to_mtl_primitive(type);
|
||||
|
||||
fActiveRenderCommandEncoder->setVertexBufferOffset(baseVertex * fCurrentVertexStride,
|
||||
RenderPipeline::kVertexBufferIndex);
|
||||
GraphicsPipeline::kVertexBufferIndex);
|
||||
fActiveRenderCommandEncoder->setVertexBufferOffset(baseInstance * fCurrentInstanceStride,
|
||||
RenderPipeline::kInstanceBufferIndex);
|
||||
GraphicsPipeline::kInstanceBufferIndex);
|
||||
size_t indexOffset = fCurrentIndexBufferOffset + sizeof(uint16_t) * baseIndex;
|
||||
fActiveRenderCommandEncoder->drawIndexedPrimitives(mtlPrimitiveType, indexCount,
|
||||
MTLIndexTypeUInt16, fCurrentIndexBuffer,
|
||||
|
@ -5,10 +5,10 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef skgpu_MtlRenderPipeline_DEFINED
|
||||
#define skgpu_MtlRenderPipeline_DEFINED
|
||||
#ifndef skgpu_MtlGraphicsPipeline_DEFINED
|
||||
#define skgpu_MtlGraphicsPipeline_DEFINED
|
||||
|
||||
#include "experimental/graphite/src/RenderPipeline.h"
|
||||
#include "experimental/graphite/src/GraphicsPipeline.h"
|
||||
|
||||
#include "include/ports/SkCFObject.h"
|
||||
#include <memory>
|
||||
@ -16,28 +16,27 @@
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
namespace skgpu {
|
||||
class RenderPipeline;
|
||||
class RenderPipelineDesc;
|
||||
class GraphicsPipelineDesc;
|
||||
} // namespace skgpu
|
||||
|
||||
namespace skgpu::mtl {
|
||||
class Gpu;
|
||||
|
||||
class RenderPipeline final : public skgpu::RenderPipeline {
|
||||
class GraphicsPipeline final : public skgpu::GraphicsPipeline {
|
||||
public:
|
||||
inline static constexpr unsigned int kUniformBufferIndex = 0;
|
||||
inline static constexpr unsigned int kVertexBufferIndex = 1;
|
||||
inline static constexpr unsigned int kInstanceBufferIndex = 2;
|
||||
|
||||
static sk_sp<RenderPipeline> Make(const Gpu*, const skgpu::RenderPipelineDesc&);
|
||||
~RenderPipeline() override {}
|
||||
static sk_sp<GraphicsPipeline> Make(const Gpu*, const skgpu::GraphicsPipelineDesc&);
|
||||
~GraphicsPipeline() override {}
|
||||
|
||||
id<MTLRenderPipelineState> mtlPipelineState() const { return fPipelineState.get(); }
|
||||
size_t vertexStride() const { return fVertexStride; }
|
||||
size_t instanceStride() const { return fInstanceStride; }
|
||||
|
||||
private:
|
||||
RenderPipeline(sk_cfp<id<MTLRenderPipelineState>> pso,
|
||||
GraphicsPipeline(sk_cfp<id<MTLRenderPipelineState>> pso,
|
||||
size_t vertexStride,
|
||||
size_t instanceStride)
|
||||
: fPipelineState(std::move(pso))
|
||||
@ -51,4 +50,4 @@ private:
|
||||
|
||||
} // namespace skgpu::mtl
|
||||
|
||||
#endif // skgpu_MtlRenderPipeline_DEFINED
|
||||
#endif // skgpu_MtlGraphicsPipeline_DEFINED
|
@ -5,9 +5,9 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "experimental/graphite/src/mtl/MtlRenderPipeline.h"
|
||||
#include "experimental/graphite/src/mtl/MtlGraphicsPipeline.h"
|
||||
|
||||
#include "experimental/graphite/src/RenderPipelineDesc.h"
|
||||
#include "experimental/graphite/src/GraphicsPipelineDesc.h"
|
||||
#include "experimental/graphite/src/mtl/MtlGpu.h"
|
||||
#include "experimental/graphite/src/mtl/MtlUtils.h"
|
||||
#include "include/private/SkSLString.h"
|
||||
@ -213,7 +213,7 @@ static inline MTLVertexFormat attribute_type_to_mtlformat(VertexAttribType type)
|
||||
SK_ABORT("Unknown vertex attribute type");
|
||||
}
|
||||
|
||||
static MTLVertexDescriptor* create_vertex_descriptor(const RenderPipelineDesc& desc) {
|
||||
static MTLVertexDescriptor* create_vertex_descriptor(const GraphicsPipelineDesc& desc) {
|
||||
auto vertexDescriptor = [[MTLVertexDescriptor alloc] init];
|
||||
int attributeIndex = 0;
|
||||
|
||||
@ -225,7 +225,7 @@ static MTLVertexDescriptor* create_vertex_descriptor(const RenderPipelineDesc& d
|
||||
SkASSERT(MTLVertexFormatInvalid != format);
|
||||
mtlAttribute.format = format;
|
||||
mtlAttribute.offset = vertexAttributeOffset;
|
||||
mtlAttribute.bufferIndex = RenderPipeline::kVertexBufferIndex;
|
||||
mtlAttribute.bufferIndex = GraphicsPipeline::kVertexBufferIndex;
|
||||
|
||||
vertexAttributeOffset += attribute.sizeAlign4();
|
||||
attributeIndex++;
|
||||
@ -234,7 +234,7 @@ static MTLVertexDescriptor* create_vertex_descriptor(const RenderPipelineDesc& d
|
||||
|
||||
if (vertexAttributeCount) {
|
||||
MTLVertexBufferLayoutDescriptor* vertexBufferLayout =
|
||||
vertexDescriptor.layouts[RenderPipeline::kVertexBufferIndex];
|
||||
vertexDescriptor.layouts[GraphicsPipeline::kVertexBufferIndex];
|
||||
vertexBufferLayout.stepFunction = MTLVertexStepFunctionPerVertex;
|
||||
vertexBufferLayout.stepRate = 1;
|
||||
vertexBufferLayout.stride = vertexAttributeOffset;
|
||||
@ -248,7 +248,7 @@ static MTLVertexDescriptor* create_vertex_descriptor(const RenderPipelineDesc& d
|
||||
SkASSERT(MTLVertexFormatInvalid != format);
|
||||
mtlAttribute.format = format;
|
||||
mtlAttribute.offset = instanceAttributeOffset;
|
||||
mtlAttribute.bufferIndex = RenderPipeline::kInstanceBufferIndex;
|
||||
mtlAttribute.bufferIndex = GraphicsPipeline::kInstanceBufferIndex;
|
||||
|
||||
instanceAttributeOffset += attribute.sizeAlign4();
|
||||
attributeIndex++;
|
||||
@ -257,7 +257,7 @@ static MTLVertexDescriptor* create_vertex_descriptor(const RenderPipelineDesc& d
|
||||
|
||||
if (instanceAttributeCount) {
|
||||
MTLVertexBufferLayoutDescriptor* instanceBufferLayout =
|
||||
vertexDescriptor.layouts[RenderPipeline::kInstanceBufferIndex];
|
||||
vertexDescriptor.layouts[GraphicsPipeline::kInstanceBufferIndex];
|
||||
instanceBufferLayout.stepFunction = MTLVertexStepFunctionPerInstance;
|
||||
instanceBufferLayout.stepRate = 1;
|
||||
instanceBufferLayout.stride = instanceAttributeOffset;
|
||||
@ -265,7 +265,8 @@ static MTLVertexDescriptor* create_vertex_descriptor(const RenderPipelineDesc& d
|
||||
return vertexDescriptor;
|
||||
}
|
||||
|
||||
sk_sp<RenderPipeline> RenderPipeline::Make(const Gpu* gpu, const skgpu::RenderPipelineDesc& desc) {
|
||||
sk_sp<GraphicsPipeline> GraphicsPipeline::Make(const Gpu* gpu,
|
||||
const skgpu::GraphicsPipelineDesc& desc) {
|
||||
sk_cfp<MTLRenderPipelineDescriptor*> psoDescriptor([[MTLRenderPipelineDescriptor alloc] init]);
|
||||
|
||||
// Temp pipeline for now that just fills the viewport with blue
|
||||
@ -307,7 +308,7 @@ sk_sp<RenderPipeline> RenderPipeline::Make(const Gpu* gpu, const skgpu::RenderPi
|
||||
SkDebugf("Errors:\n%s", error.debugDescription.UTF8String);
|
||||
return nullptr;
|
||||
}
|
||||
return sk_sp<RenderPipeline>(new RenderPipeline(std::move(pso), desc.vertexStride(),
|
||||
return sk_sp<GraphicsPipeline>(new GraphicsPipeline(std::move(pso), desc.vertexStride(),
|
||||
desc.instanceStride()));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ private:
|
||||
const Gpu* mtlGpu();
|
||||
|
||||
sk_sp<skgpu::CommandBuffer> createCommandBuffer() override;
|
||||
sk_sp<skgpu::RenderPipeline> onCreateRenderPipeline(const RenderPipelineDesc&) override;
|
||||
sk_sp<skgpu::GraphicsPipeline> onCreateGraphicsPipeline(const GraphicsPipelineDesc&) override;
|
||||
sk_sp<skgpu::Texture> createTexture(SkISize, const skgpu::TextureInfo&) override;
|
||||
sk_sp<skgpu::Buffer> createBuffer(size_t size, BufferType type, PrioritizeGpuReads) override;
|
||||
};
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include "experimental/graphite/src/mtl/MtlGpu.h"
|
||||
#include "experimental/graphite/src/mtl/MtlTexture.h"
|
||||
|
||||
#include "experimental/graphite/src/RenderPipelineDesc.h"
|
||||
#include "experimental/graphite/src/mtl/MtlRenderPipeline.h"
|
||||
#include "experimental/graphite/src/GraphicsPipelineDesc.h"
|
||||
#include "experimental/graphite/src/mtl/MtlGraphicsPipeline.h"
|
||||
|
||||
namespace skgpu::mtl {
|
||||
|
||||
@ -29,9 +29,9 @@ sk_sp<skgpu::CommandBuffer> ResourceProvider::createCommandBuffer() {
|
||||
return CommandBuffer::Make(this->mtlGpu());
|
||||
}
|
||||
|
||||
sk_sp<skgpu::RenderPipeline> ResourceProvider::onCreateRenderPipeline(
|
||||
const RenderPipelineDesc& desc) {
|
||||
return RenderPipeline::Make(this->mtlGpu(), desc);
|
||||
sk_sp<skgpu::GraphicsPipeline> ResourceProvider::onCreateGraphicsPipeline(
|
||||
const GraphicsPipelineDesc& desc) {
|
||||
return GraphicsPipeline::Make(this->mtlGpu(), desc);
|
||||
}
|
||||
|
||||
sk_sp<skgpu::Texture> ResourceProvider::createTexture(SkISize dimensions,
|
||||
|
@ -44,6 +44,10 @@ skia_graphite_sources = [
|
||||
"$_src/Gpu.cpp",
|
||||
"$_src/Gpu.h",
|
||||
"$_src/GpuWorkSubmission.h",
|
||||
"$_src/GraphicsPipeline.cpp",
|
||||
"$_src/GraphicsPipeline.h",
|
||||
"$_src/GraphicsPipelineDesc.cpp",
|
||||
"$_src/GraphicsPipelineDesc.h",
|
||||
"$_src/Image_Graphite.cpp",
|
||||
"$_src/Image_Graphite.h",
|
||||
"$_src/ProgramCache.cpp",
|
||||
@ -54,10 +58,6 @@ skia_graphite_sources = [
|
||||
"$_src/Recording.h",
|
||||
"$_src/RenderPassTask.cpp",
|
||||
"$_src/RenderPassTask.h",
|
||||
"$_src/RenderPipeline.cpp",
|
||||
"$_src/RenderPipeline.h",
|
||||
"$_src/RenderPipelineDesc.cpp",
|
||||
"$_src/RenderPipelineDesc.h",
|
||||
"$_src/Renderer.h",
|
||||
"$_src/ResourceProvider.cpp",
|
||||
"$_src/ResourceProvider.h",
|
||||
@ -102,9 +102,9 @@ skia_graphite_mtl_sources = [
|
||||
"$_src/mtl/MtlCommandBuffer.mm",
|
||||
"$_src/mtl/MtlGpu.h",
|
||||
"$_src/mtl/MtlGpu.mm",
|
||||
"$_src/mtl/MtlGraphicsPipeline.h",
|
||||
"$_src/mtl/MtlGraphicsPipeline.mm",
|
||||
"$_src/mtl/MtlRenderCommandEncoder.h",
|
||||
"$_src/mtl/MtlRenderPipeline.h",
|
||||
"$_src/mtl/MtlRenderPipeline.mm",
|
||||
"$_src/mtl/MtlResourceProvider.h",
|
||||
"$_src/mtl/MtlResourceProvider.mm",
|
||||
"$_src/mtl/MtlTexture.h",
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "experimental/graphite/src/Buffer.h"
|
||||
#include "experimental/graphite/src/CommandBuffer.h"
|
||||
#include "experimental/graphite/src/Gpu.h"
|
||||
#include "experimental/graphite/src/RenderPipeline.h"
|
||||
#include "experimental/graphite/src/GraphicsPipeline.h"
|
||||
#include "experimental/graphite/src/ResourceProvider.h"
|
||||
#include "experimental/graphite/src/Texture.h"
|
||||
|
||||
@ -77,16 +77,16 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(CommandBufferTest, reporter, context) {
|
||||
size_t uniformOffset = 0;
|
||||
|
||||
// Draw blue rectangle over entire rendertarget (which was red)
|
||||
RenderPipelineDesc pipelineDesc;
|
||||
GraphicsPipelineDesc pipelineDesc;
|
||||
pipelineDesc.setTestingOnlyShaderIndex(0);
|
||||
auto renderPipeline = gpu->resourceProvider()->findOrCreateRenderPipeline(pipelineDesc);
|
||||
commandBuffer->bindRenderPipeline(std::move(renderPipeline));
|
||||
auto graphicsPipeline = gpu->resourceProvider()->findOrCreateGraphicsPipeline(pipelineDesc);
|
||||
commandBuffer->bindGraphicsPipeline(std::move(graphicsPipeline));
|
||||
commandBuffer->draw(PrimitiveType::kTriangleStrip, 0, 4);
|
||||
|
||||
// Draw inset yellow rectangle using uniforms
|
||||
pipelineDesc.setTestingOnlyShaderIndex(1);
|
||||
renderPipeline = gpu->resourceProvider()->findOrCreateRenderPipeline(pipelineDesc);
|
||||
commandBuffer->bindRenderPipeline(std::move(renderPipeline));
|
||||
graphicsPipeline = gpu->resourceProvider()->findOrCreateGraphicsPipeline(pipelineDesc);
|
||||
commandBuffer->bindGraphicsPipeline(std::move(graphicsPipeline));
|
||||
UniformData* uniforms = (UniformData*)uniformBuffer->map();
|
||||
uniforms->fScale = SkPoint({1.8, 1.8});
|
||||
uniforms->fTranslate = SkPoint({-0.9, -0.9});
|
||||
@ -98,12 +98,12 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(CommandBufferTest, reporter, context) {
|
||||
|
||||
// Draw inset magenta rectangle with triangles in vertex buffer
|
||||
pipelineDesc.setTestingOnlyShaderIndex(2);
|
||||
skgpu::RenderPipelineDesc::Attribute vertexAttributes[1] = {
|
||||
skgpu::GraphicsPipelineDesc::Attribute vertexAttributes[1] = {
|
||||
{ "position", VertexAttribType::kFloat2, SLType::kFloat2 }
|
||||
};
|
||||
pipelineDesc.setVertexAttributes(vertexAttributes, 1);
|
||||
renderPipeline = gpu->resourceProvider()->findOrCreateRenderPipeline(pipelineDesc);
|
||||
commandBuffer->bindRenderPipeline(std::move(renderPipeline));
|
||||
graphicsPipeline = gpu->resourceProvider()->findOrCreateGraphicsPipeline(pipelineDesc);
|
||||
commandBuffer->bindGraphicsPipeline(std::move(graphicsPipeline));
|
||||
|
||||
struct VertexData {
|
||||
SkPoint fPosition;
|
||||
@ -136,15 +136,15 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(CommandBufferTest, reporter, context) {
|
||||
|
||||
// draw rects using instance buffer
|
||||
pipelineDesc.setTestingOnlyShaderIndex(3);
|
||||
skgpu::RenderPipelineDesc::Attribute instanceAttributes[3] = {
|
||||
skgpu::GraphicsPipelineDesc::Attribute instanceAttributes[3] = {
|
||||
{ "position", VertexAttribType::kFloat2, SLType::kFloat2 },
|
||||
{ "dims", VertexAttribType::kFloat2, SLType::kFloat2 },
|
||||
{ "color", VertexAttribType::kFloat4, SLType::kFloat4 }
|
||||
};
|
||||
pipelineDesc.setVertexAttributes(nullptr, 0);
|
||||
pipelineDesc.setInstanceAttributes(instanceAttributes, 3);
|
||||
renderPipeline = gpu->resourceProvider()->findOrCreateRenderPipeline(pipelineDesc);
|
||||
commandBuffer->bindRenderPipeline(std::move(renderPipeline));
|
||||
graphicsPipeline = gpu->resourceProvider()->findOrCreateGraphicsPipeline(pipelineDesc);
|
||||
commandBuffer->bindGraphicsPipeline(std::move(graphicsPipeline));
|
||||
|
||||
struct InstanceData {
|
||||
SkPoint fPosition;
|
||||
|
Loading…
Reference in New Issue
Block a user