1 /* 2 * Copyright 2021 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef skgpu_graphite_MtlGraphicsPipeline_DEFINED 9 #define skgpu_graphite_MtlGraphicsPipeline_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/core/SkSpan.h" 13 #include "include/ports/SkCFObject.h" 14 #include "src/gpu/graphite/GraphicsPipeline.h" 15 #include <memory> 16 17 #import <Metal/Metal.h> 18 19 namespace skgpu { 20 struct BlendInfo; 21 } 22 23 namespace skgpu::graphite { 24 25 class Attribute; 26 class Context; 27 class GraphicsPipelineDesc; 28 class MtlResourceProvider; 29 class MtlSharedContext; 30 struct RenderPassDesc; 31 class RuntimeEffectDictionary; 32 33 class MtlGraphicsPipeline final : public GraphicsPipeline { 34 public: 35 inline static constexpr unsigned int kIntrinsicUniformBufferIndex = 0; 36 inline static constexpr unsigned int kRenderStepUniformBufferIndex = 1; 37 inline static constexpr unsigned int kPaintUniformBufferIndex = 2; 38 inline static constexpr unsigned int kVertexBufferIndex = 3; 39 inline static constexpr unsigned int kInstanceBufferIndex = 4; 40 inline static constexpr unsigned int kGradientBufferIndex = 5; 41 42 static sk_sp<MtlGraphicsPipeline> Make(const MtlSharedContext*, 43 MtlResourceProvider*, 44 const RuntimeEffectDictionary*, 45 const GraphicsPipelineDesc&, 46 const RenderPassDesc&, 47 SkEnumBitMask<PipelineCreationFlags>); 48 49 static sk_sp<MtlGraphicsPipeline> MakeLoadMSAAPipeline(const MtlSharedContext*, 50 MtlResourceProvider*, 51 const RenderPassDesc&); 52 ~MtlGraphicsPipeline()53 ~MtlGraphicsPipeline() override {} 54 mtlPipelineState()55 id<MTLRenderPipelineState> mtlPipelineState() const { return fPipelineState.get(); } mtlDepthStencilState()56 id<MTLDepthStencilState> mtlDepthStencilState() const { return fDepthStencilState.get(); } stencilReferenceValue()57 uint32_t stencilReferenceValue() const { return fStencilReferenceValue; } 58 59 private: 60 MtlGraphicsPipeline(const skgpu::graphite::SharedContext* sharedContext, 61 const PipelineInfo& pipelineInfo, 62 sk_cfp<id<MTLRenderPipelineState>> pso, 63 sk_cfp<id<MTLDepthStencilState>> dss, 64 uint32_t refValue); 65 66 using MSLFunction = std::pair<id<MTLLibrary>, std::string>; 67 static sk_sp<MtlGraphicsPipeline> Make(const MtlSharedContext*, 68 const std::string& label, 69 const PipelineInfo&, 70 MSLFunction vertexMain, 71 SkSpan<const Attribute> vertexAttrs, 72 SkSpan<const Attribute> instanceAttrs, 73 MSLFunction fragmentMain, 74 sk_cfp<id<MTLDepthStencilState>>, 75 uint32_t stencilRefValue, 76 const BlendInfo& blendInfo, 77 const RenderPassDesc&); 78 79 void freeGpuData() override; 80 81 sk_cfp<id<MTLRenderPipelineState>> fPipelineState; 82 sk_cfp<id<MTLDepthStencilState>> fDepthStencilState; 83 uint32_t fStencilReferenceValue; 84 }; 85 86 } // namespace skgpu::graphite 87 88 #endif // skgpu_graphite_MtlGraphicsPipeline_DEFINED 89