Debian Codegraph @

src/gpu/graphite/mtl/MtlGraphicsPipeline.h

raw
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 kCombinedUniformIndex = 1; // Paint AND rendersteps!
37 inline static constexpr unsigned int kStaticDataBufferIndex = 2;
38 inline static constexpr unsigned int kAppendDataBufferIndex = 3;
39 inline static constexpr unsigned int kGradientBufferIndex = 4;
40
41 static sk_sp<MtlGraphicsPipeline> Make(const MtlSharedContext*,
42 const RuntimeEffectDictionary*,
43 const UniqueKey&,
44 const GraphicsPipelineDesc&,
45 const RenderPassDesc&,
46 SkEnumBitMask<PipelineCreationFlags>,
47 uint32_t compilationID);
48
49 static sk_sp<MtlGraphicsPipeline> MakeLoadMSAAPipeline(const MtlSharedContext*,
50 const RenderPassDesc&);
51
52 ~MtlGraphicsPipeline() override {}
53
54 id<MTLRenderPipelineState> mtlPipelineState() const { return fPipelineState.get(); }
55 id<MTLDepthStencilState> mtlDepthStencilState() const { return fDepthStencilState.get(); }
56 uint32_t stencilReferenceValue() const { return fStencilReferenceValue; }
57
58 private:
59 MtlGraphicsPipeline(const skgpu::graphite::SharedContext* sharedContext,
60 const PipelineInfo& pipelineInfo,
61 std::string_view pipelineLabel,
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 MTLVertexStepFunction appendStepFunc,
72 SkSpan<const Attribute> staticAttrs,
73 SkSpan<const Attribute> appendAttrs,
74 MSLFunction fragmentMain,
75 sk_cfp<id<MTLDepthStencilState>>,
76 uint32_t stencilRefValue,
77 const BlendInfo& blendInfo,
78 const RenderPassDesc&);
79
80 void freeGpuData() override;
81
82 sk_cfp<id<MTLRenderPipelineState>> fPipelineState;
83 sk_cfp<id<MTLDepthStencilState>> fDepthStencilState;
84 uint32_t fStencilReferenceValue;
85 };
86
87 } // namespace skgpu::graphite
88
89 #endif // skgpu_graphite_MtlGraphicsPipeline_DEFINED