• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc.
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 GrMtlPipelineStateBuilder_DEFINED
9 #define GrMtlPipelineStateBuilder_DEFINED
10 
11 #include "src/gpu/GrPipeline.h"
12 #include "src/gpu/GrProgramDesc.h"
13 #include "src/gpu/glsl/GrGLSLProgramBuilder.h"
14 #include "src/gpu/mtl/GrMtlUniformHandler.h"
15 #include "src/gpu/mtl/GrMtlVaryingHandler.h"
16 #include "src/sksl/SkSLCompiler.h"
17 
18 #import <Metal/Metal.h>
19 
20 class GrMtlGpu;
21 class GrMtlPipelineState;
22 
23 class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder {
24 public:
25     /**
26      * For Metal we want to cache the entire pipeline for reuse of draws. The Desc here holds all
27      * the information needed to differentiate one pipeline from another.
28      *
29      * The GrProgramDesc contains all the information need to create the actual shaders for the
30      * pipeline.
31      *
32      * For Metal we need to add to the GrProgramDesc to include the rest of the state on the
33      * pipeline. This includes blending information and primitive type. The pipeline is immutable
34      * so any remaining dynamic state is set via the MtlRenderCmdEncoder.
35      */
36     class Desc : public GrProgramDesc {
37     public:
38         static bool Build(Desc*,
39                           GrRenderTarget*,
40                           const GrPrimitiveProcessor&,
41                           const GrPipeline&,
42                           GrPrimitiveType,
43                           GrMtlGpu* gpu);
44 
shaderKeyLength()45         size_t shaderKeyLength() const { return fShaderKeyLength; }
46 
47     private:
48         size_t fShaderKeyLength;
49 
50         typedef GrProgramDesc INHERITED;
51     };
52 
53     /** Generates a pipeline state.
54      *
55      * The GrMtlPipelineState implements what is specified in the GrPipeline and
56      * GrPrimitiveProcessor as input. After successful generation, the builder result objects are
57      * available to be used. This function may modify the program key by setting the surface origin
58      * key to 0 (unspecified) if it turns out the program does not care about the surface origin.
59      * @return true if generation was successful.
60      */
61     static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*,
62                                                    GrRenderTarget*, GrSurfaceOrigin,
63                                                    const GrPrimitiveProcessor&,
64                                                    const GrTextureProxy* const primProcProxies[],
65                                                    const GrPipeline&,
66                                                    Desc*);
67 
68 private:
69     GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*, GrSurfaceOrigin,
70                               const GrPipeline&,
71                               const GrPrimitiveProcessor&,
72                               const GrTextureProxy* const primProcProxies[],
73                               GrProgramDesc*);
74 
75     GrMtlPipelineState* finalize(GrRenderTarget* renderTarget,
76                                  const GrPrimitiveProcessor& primProc,
77                                  const GrPipeline& pipeline,
78                                  Desc*);
79 
80     const GrCaps* caps() const override;
81 
82     void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
83 
84     void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
85 
86     id<MTLLibrary> createMtlShaderLibrary(const GrGLSLShaderBuilder& builder,
87                                           SkSL::Program::Kind kind,
88                                           const SkSL::Program::Settings& settings,
89                                           GrProgramDesc* desc);
90 
uniformHandler()91     GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
uniformHandler()92     const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
varyingHandler()93     GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
94 
95     GrMtlGpu* fGpu;
96     GrMtlUniformHandler fUniformHandler;
97     GrMtlVaryingHandler fVaryingHandler;
98 
99     typedef GrGLSLProgramBuilder INHERITED;
100 };
101 #endif
102