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 UniqueKey&, 46 const GraphicsPipelineDesc&, 47 const RenderPassDesc&, 48 SkEnumBitMask<PipelineCreationFlags>, 49 uint32_t compilationID); 50 51 static sk_sp<MtlGraphicsPipeline> MakeLoadMSAAPipeline(const MtlSharedContext*, 52 MtlResourceProvider*, 53 const RenderPassDesc&); 54 ~MtlGraphicsPipeline()55 ~MtlGraphicsPipeline() override {} 56 mtlPipelineState()57 id<MTLRenderPipelineState> mtlPipelineState() const { return fPipelineState.get(); } mtlDepthStencilState()58 id<MTLDepthStencilState> mtlDepthStencilState() const { return fDepthStencilState.get(); } stencilReferenceValue()59 uint32_t stencilReferenceValue() const { return fStencilReferenceValue; } 60 61 private: 62 MtlGraphicsPipeline(const skgpu::graphite::SharedContext* sharedContext, 63 const PipelineInfo& pipelineInfo, 64 sk_cfp<id<MTLRenderPipelineState>> pso, 65 sk_cfp<id<MTLDepthStencilState>> dss, 66 uint32_t refValue); 67 68 using MSLFunction = std::pair<id<MTLLibrary>, std::string>; 69 static sk_sp<MtlGraphicsPipeline> Make(const MtlSharedContext*, 70 const std::string& label, 71 const PipelineInfo&, 72 MSLFunction vertexMain, 73 SkSpan<const Attribute> vertexAttrs, 74 SkSpan<const Attribute> instanceAttrs, 75 MSLFunction fragmentMain, 76 sk_cfp<id<MTLDepthStencilState>>, 77 uint32_t stencilRefValue, 78 const BlendInfo& blendInfo, 79 const RenderPassDesc&); 80 81 void freeGpuData() override; 82 83 sk_cfp<id<MTLRenderPipelineState>> fPipelineState; 84 sk_cfp<id<MTLDepthStencilState>> fDepthStencilState; 85 uint32_t fStencilReferenceValue; 86 }; 87 88 } // namespace skgpu::graphite 89 90 #endif // skgpu_graphite_MtlGraphicsPipeline_DEFINED 91