From 497ac0fe236bb0ce7e9cf11906f9ea1c63b6098b Mon Sep 17 00:00:00 2001 From: Michael Ludwig Date: Thu, 4 Nov 2021 13:09:22 -0400 Subject: [PATCH] [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 Reviewed-by: Greg Daniel Commit-Queue: Michael Ludwig --- experimental/graphite/src/CommandBuffer.cpp | 8 ++-- experimental/graphite/src/CommandBuffer.h | 6 +-- ...enderPipeline.cpp => GraphicsPipeline.cpp} | 6 +-- experimental/graphite/src/GraphicsPipeline.h | 37 +++++++++++++++++++ ...elineDesc.cpp => GraphicsPipelineDesc.cpp} | 4 +- ...rPipelineDesc.h => GraphicsPipelineDesc.h} | 22 ++++++----- experimental/graphite/src/RenderPipeline.h | 27 -------------- .../graphite/src/ResourceProvider.cpp | 30 +++++++-------- experimental/graphite/src/ResourceProvider.h | 26 ++++++------- .../graphite/src/mtl/MtlCommandBuffer.h | 2 +- .../graphite/src/mtl/MtlCommandBuffer.mm | 26 ++++++------- ...RenderPipeline.h => MtlGraphicsPipeline.h} | 23 ++++++------ ...nderPipeline.mm => MtlGraphicsPipeline.mm} | 21 ++++++----- .../graphite/src/mtl/MtlResourceProvider.h | 2 +- .../graphite/src/mtl/MtlResourceProvider.mm | 10 ++--- gn/graphite.gni | 12 +++--- tests/graphite/CommandBufferTest.cpp | 24 ++++++------ 17 files changed, 149 insertions(+), 137 deletions(-) rename experimental/graphite/src/{RenderPipeline.cpp => GraphicsPipeline.cpp} (58%) create mode 100644 experimental/graphite/src/GraphicsPipeline.h rename experimental/graphite/src/{RenderPipelineDesc.cpp => GraphicsPipelineDesc.cpp} (63%) rename experimental/graphite/src/{RenderPipelineDesc.h => GraphicsPipelineDesc.h} (92%) delete mode 100644 experimental/graphite/src/RenderPipeline.h rename experimental/graphite/src/mtl/{MtlRenderPipeline.h => MtlGraphicsPipeline.h} (64%) rename experimental/graphite/src/mtl/{MtlRenderPipeline.mm => MtlGraphicsPipeline.mm} (93%) diff --git a/experimental/graphite/src/CommandBuffer.cpp b/experimental/graphite/src/CommandBuffer.cpp index e4771a09d6..48176b12ea 100644 --- a/experimental/graphite/src/CommandBuffer.cpp +++ b/experimental/graphite/src/CommandBuffer.cpp @@ -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) { - this->onBindRenderPipeline(renderPipeline.get()); - this->trackResource(std::move(renderPipeline)); +void CommandBuffer::bindGraphicsPipeline(sk_sp graphicsPipeline) { + this->onBindGraphicsPipeline(graphicsPipeline.get()); + this->trackResource(std::move(graphicsPipeline)); fHasWork = true; } diff --git a/experimental/graphite/src/CommandBuffer.h b/experimental/graphite/src/CommandBuffer.h index 53aa2f6d68..05f0e74b24 100644 --- a/experimental/graphite/src/CommandBuffer.h +++ b/experimental/graphite/src/CommandBuffer.h @@ -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); + void bindGraphicsPipeline(sk_sp graphicsPipeline); void bindUniformBuffer(sk_sp, size_t bufferOffset); void bindVertexBuffers(sk_sp vertexBuffer, sk_sp instanceBuffer); void bindIndexBuffer(sk_sp 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; diff --git a/experimental/graphite/src/RenderPipeline.cpp b/experimental/graphite/src/GraphicsPipeline.cpp similarity index 58% rename from experimental/graphite/src/RenderPipeline.cpp rename to experimental/graphite/src/GraphicsPipeline.cpp index 016fcff2ae..1e5064325d 100644 --- a/experimental/graphite/src/RenderPipeline.cpp +++ b/experimental/graphite/src/GraphicsPipeline.cpp @@ -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 diff --git a/experimental/graphite/src/GraphicsPipeline.h b/experimental/graphite/src/GraphicsPipeline.h new file mode 100644 index 0000000000..3480d00a05 --- /dev/null +++ b/experimental/graphite/src/GraphicsPipeline.h @@ -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 diff --git a/experimental/graphite/src/RenderPipelineDesc.cpp b/experimental/graphite/src/GraphicsPipelineDesc.cpp similarity index 63% rename from experimental/graphite/src/RenderPipelineDesc.cpp rename to experimental/graphite/src/GraphicsPipelineDesc.cpp index d6fe5a3336..0931789613 100644 --- a/experimental/graphite/src/RenderPipelineDesc.cpp +++ b/experimental/graphite/src/GraphicsPipelineDesc.cpp @@ -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 diff --git a/experimental/graphite/src/RenderPipelineDesc.h b/experimental/graphite/src/GraphicsPipelineDesc.h similarity index 92% rename from experimental/graphite/src/RenderPipelineDesc.h rename to experimental/graphite/src/GraphicsPipelineDesc.h index 3a4d65a26d..6462968e2b 100644 --- a/experimental/graphite/src/RenderPipelineDesc.h +++ b/experimental/graphite/src/GraphicsPipelineDesc.h @@ -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 diff --git a/experimental/graphite/src/RenderPipeline.h b/experimental/graphite/src/RenderPipeline.h deleted file mode 100644 index 728a952562..0000000000 --- a/experimental/graphite/src/RenderPipeline.h +++ /dev/null @@ -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 diff --git a/experimental/graphite/src/ResourceProvider.cpp b/experimental/graphite/src/ResourceProvider.cpp index 35fda7904f..e07b7b50f5 100644 --- a/experimental/graphite/src/ResourceProvider.cpp +++ b/experimental/graphite/src/ResourceProvider.cpp @@ -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 ResourceProvider::findOrCreateRenderPipeline(const RenderPipelineDesc& desc) { - return fRenderPipelineCache->refPipeline(desc); +sk_sp ResourceProvider::findOrCreateGraphicsPipeline( + const GraphicsPipelineDesc& desc) { + return fGraphicsPipelineCache->refPipeline(desc); } //////////////////////////////////////////////////////////////////////////////////////////////// -struct ResourceProvider::RenderPipelineCache::Entry { - Entry(sk_sp pipeline) - : fPipeline(std::move(pipeline)) {} +struct ResourceProvider::GraphicsPipelineCache::Entry { + Entry(sk_sp pipeline) : fPipeline(std::move(pipeline)) {} - sk_sp fPipeline; + sk_sp 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 ResourceProvider::RenderPipelineCache::refPipeline( - const RenderPipelineDesc& desc) { +sk_sp ResourceProvider::GraphicsPipelineCache::refPipeline( + const GraphicsPipelineDesc& desc) { std::unique_ptr* entry = fMap.find(desc); if (!entry) { - auto pipeline = fResourceProvider->onCreateRenderPipeline(desc); + auto pipeline = fResourceProvider->onCreateGraphicsPipeline(desc); if (!pipeline) { return nullptr; } diff --git a/experimental/graphite/src/ResourceProvider.h b/experimental/graphite/src/ResourceProvider.h index ff58d0f5a1..da2a9d979e 100644 --- a/experimental/graphite/src/ResourceProvider.h +++ b/experimental/graphite/src/ResourceProvider.h @@ -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 createCommandBuffer() = 0; - sk_sp findOrCreateRenderPipeline(const RenderPipelineDesc&); + sk_sp findOrCreateGraphicsPipeline(const GraphicsPipelineDesc&); sk_sp findOrCreateTexture(SkISize, const TextureInfo&); @@ -42,34 +40,34 @@ protected: const Gpu* fGpu; private: - virtual sk_sp onCreateRenderPipeline(const RenderPipelineDesc&) = 0; + virtual sk_sp onCreateGraphicsPipeline(const GraphicsPipelineDesc&) = 0; virtual sk_sp createTexture(SkISize, const TextureInfo&) = 0; virtual sk_sp 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 refPipeline(const RenderPipelineDesc&); + sk_sp 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, DescHash> fMap; + SkLRUCache, DescHash> fMap; ResourceProvider* fResourceProvider; }; - // Cache of RenderPipelines - std::unique_ptr fRenderPipelineCache; + // Cache of GraphicsPipelines + std::unique_ptr fGraphicsPipelineCache; }; } // namespace skgpu diff --git a/experimental/graphite/src/mtl/MtlCommandBuffer.h b/experimental/graphite/src/mtl/MtlCommandBuffer.h index f67e2b2e0f..4bf69f71b8 100644 --- a/experimental/graphite/src/mtl/MtlCommandBuffer.h +++ b/experimental/graphite/src/mtl/MtlCommandBuffer.h @@ -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; diff --git a/experimental/graphite/src/mtl/MtlCommandBuffer.mm b/experimental/graphite/src/mtl/MtlCommandBuffer.mm index 644ccc2a40..656441d712 100644 --- a/experimental/graphite/src/mtl/MtlCommandBuffer.mm +++ b/experimental/graphite/src/mtl/MtlCommandBuffer.mm @@ -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(renderPipeline); - auto pipelineState = mtlRenderPipeline->mtlPipelineState(); + auto mtlPipeline = static_cast(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 = static_cast(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 = static_cast(vertexBuffer)->mtlBuffer(); fActiveRenderCommandEncoder->setVertexBuffer(mtlBuffer, 0, - RenderPipeline::kVertexBufferIndex); + GraphicsPipeline::kVertexBufferIndex); } if (instanceBuffer) { id mtlBuffer = static_cast(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, diff --git a/experimental/graphite/src/mtl/MtlRenderPipeline.h b/experimental/graphite/src/mtl/MtlGraphicsPipeline.h similarity index 64% rename from experimental/graphite/src/mtl/MtlRenderPipeline.h rename to experimental/graphite/src/mtl/MtlGraphicsPipeline.h index 68fd2e35ed..a0c1452380 100644 --- a/experimental/graphite/src/mtl/MtlRenderPipeline.h +++ b/experimental/graphite/src/mtl/MtlGraphicsPipeline.h @@ -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 @@ -16,30 +16,29 @@ #import 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 Make(const Gpu*, const skgpu::RenderPipelineDesc&); - ~RenderPipeline() override {} + static sk_sp Make(const Gpu*, const skgpu::GraphicsPipelineDesc&); + ~GraphicsPipeline() override {} id mtlPipelineState() const { return fPipelineState.get(); } size_t vertexStride() const { return fVertexStride; } size_t instanceStride() const { return fInstanceStride; } private: - RenderPipeline(sk_cfp> pso, - size_t vertexStride, - size_t instanceStride) + GraphicsPipeline(sk_cfp> pso, + size_t vertexStride, + size_t instanceStride) : fPipelineState(std::move(pso)) , fVertexStride(vertexStride) , fInstanceStride(instanceStride) {} @@ -51,4 +50,4 @@ private: } // namespace skgpu::mtl -#endif // skgpu_MtlRenderPipeline_DEFINED +#endif // skgpu_MtlGraphicsPipeline_DEFINED diff --git a/experimental/graphite/src/mtl/MtlRenderPipeline.mm b/experimental/graphite/src/mtl/MtlGraphicsPipeline.mm similarity index 93% rename from experimental/graphite/src/mtl/MtlRenderPipeline.mm rename to experimental/graphite/src/mtl/MtlGraphicsPipeline.mm index 2749245ffc..7ba662e524 100644 --- a/experimental/graphite/src/mtl/MtlRenderPipeline.mm +++ b/experimental/graphite/src/mtl/MtlGraphicsPipeline.mm @@ -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::Make(const Gpu* gpu, const skgpu::RenderPipelineDesc& desc) { +sk_sp GraphicsPipeline::Make(const Gpu* gpu, + const skgpu::GraphicsPipelineDesc& desc) { sk_cfp psoDescriptor([[MTLRenderPipelineDescriptor alloc] init]); // Temp pipeline for now that just fills the viewport with blue @@ -307,8 +308,8 @@ sk_sp RenderPipeline::Make(const Gpu* gpu, const skgpu::RenderPi SkDebugf("Errors:\n%s", error.debugDescription.UTF8String); return nullptr; } - return sk_sp(new RenderPipeline(std::move(pso), desc.vertexStride(), - desc.instanceStride())); + return sk_sp(new GraphicsPipeline(std::move(pso), desc.vertexStride(), + desc.instanceStride())); } } // namespace skgpu::mtl diff --git a/experimental/graphite/src/mtl/MtlResourceProvider.h b/experimental/graphite/src/mtl/MtlResourceProvider.h index 795cfa25ac..be1f5d455b 100644 --- a/experimental/graphite/src/mtl/MtlResourceProvider.h +++ b/experimental/graphite/src/mtl/MtlResourceProvider.h @@ -29,7 +29,7 @@ private: const Gpu* mtlGpu(); sk_sp createCommandBuffer() override; - sk_sp onCreateRenderPipeline(const RenderPipelineDesc&) override; + sk_sp onCreateGraphicsPipeline(const GraphicsPipelineDesc&) override; sk_sp createTexture(SkISize, const skgpu::TextureInfo&) override; sk_sp createBuffer(size_t size, BufferType type, PrioritizeGpuReads) override; }; diff --git a/experimental/graphite/src/mtl/MtlResourceProvider.mm b/experimental/graphite/src/mtl/MtlResourceProvider.mm index 38a1e7662d..2f4ca3a7cb 100644 --- a/experimental/graphite/src/mtl/MtlResourceProvider.mm +++ b/experimental/graphite/src/mtl/MtlResourceProvider.mm @@ -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 ResourceProvider::createCommandBuffer() { return CommandBuffer::Make(this->mtlGpu()); } -sk_sp ResourceProvider::onCreateRenderPipeline( - const RenderPipelineDesc& desc) { - return RenderPipeline::Make(this->mtlGpu(), desc); +sk_sp ResourceProvider::onCreateGraphicsPipeline( + const GraphicsPipelineDesc& desc) { + return GraphicsPipeline::Make(this->mtlGpu(), desc); } sk_sp ResourceProvider::createTexture(SkISize dimensions, diff --git a/gn/graphite.gni b/gn/graphite.gni index 98c48ccac0..ba8e8df83f 100644 --- a/gn/graphite.gni +++ b/gn/graphite.gni @@ -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", diff --git a/tests/graphite/CommandBufferTest.cpp b/tests/graphite/CommandBufferTest.cpp index d865cdf978..62f7ebfae1 100644 --- a/tests/graphite/CommandBufferTest.cpp +++ b/tests/graphite/CommandBufferTest.cpp @@ -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;