• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
32 class MtlGraphicsPipeline final : public GraphicsPipeline {
33 public:
34     inline static constexpr unsigned int kIntrinsicUniformBufferIndex = 0;
35     inline static constexpr unsigned int kRenderStepUniformBufferIndex = 1;
36     inline static constexpr unsigned int kPaintUniformBufferIndex = 2;
37     inline static constexpr unsigned int kVertexBufferIndex = 3;
38     inline static constexpr unsigned int kInstanceBufferIndex = 4;
39     inline static constexpr unsigned int kGradientBufferIndex = 5;
40 
41     using MSLFunction = std::pair<id<MTLLibrary>, std::string>;
42     static sk_sp<MtlGraphicsPipeline> Make(const MtlSharedContext*,
43                                            const std::string& label,
44                                            MSLFunction vertexMain,
45                                            SkSpan<const Attribute> vertexAttrs,
46                                            SkSpan<const Attribute> instanceAttrs,
47                                            MSLFunction fragmentMain,
48                                            sk_cfp<id<MTLDepthStencilState>>,
49                                            uint32_t stencilRefValue,
50                                            const BlendInfo& blendInfo,
51                                            const RenderPassDesc&,
52                                            PipelineInfo* pipelineInfo);
53 
~MtlGraphicsPipeline()54     ~MtlGraphicsPipeline() override {}
55 
mtlPipelineState()56     id<MTLRenderPipelineState> mtlPipelineState() const { return fPipelineState.get(); }
mtlDepthStencilState()57     id<MTLDepthStencilState> mtlDepthStencilState() const { return fDepthStencilState.get(); }
stencilReferenceValue()58     uint32_t stencilReferenceValue() const { return fStencilReferenceValue; }
59 
60 private:
61     MtlGraphicsPipeline(const skgpu::graphite::SharedContext* sharedContext,
62                         PipelineInfo* pipelineInfo,
63                         sk_cfp<id<MTLRenderPipelineState>> pso,
64                         sk_cfp<id<MTLDepthStencilState>> dss,
65                         uint32_t refValue);
66 
67     void freeGpuData() override;
68 
69     sk_cfp<id<MTLRenderPipelineState>> fPipelineState;
70     sk_cfp<id<MTLDepthStencilState>> fDepthStencilState;
71     uint32_t fStencilReferenceValue;
72 };
73 
74 } // namespace skgpu::graphite
75 
76 #endif // skgpu_graphite_MtlGraphicsPipeline_DEFINED
77