• 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 "include/gpu/GrContextOptions.h"
12 #include "src/gpu/ganesh/GrPipeline.h"
13 #include "src/gpu/ganesh/glsl/GrGLSLProgramBuilder.h"
14 #include "src/gpu/ganesh/mtl/GrMtlUniformHandler.h"
15 #include "src/gpu/ganesh/mtl/GrMtlVaryingHandler.h"
16 #include "src/sksl/ir/SkSLProgram.h"
17 
18 #import <Metal/Metal.h>
19 
20 class GrProgramDesc;
21 class GrProgramInfo;
22 class GrMtlCaps;
23 class GrMtlGpu;
24 class GrMtlPipelineState;
25 class SkReadBuffer;
26 
27 namespace SkSL { class Compiler; }
28 
29 struct GrMtlPrecompiledLibraries {
30     // TODO: wrap these in sk_cfp<> or unique_ptr<> when we remove ARC
31     id<MTLLibrary> fVertexLibrary;
32     id<MTLLibrary> fFragmentLibrary;
33     bool fRTFlip = false;
34 };
35 
36 class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder {
37 public:
38     /** Generates a pipeline state.
39      *
40      * The returned GrMtlPipelineState implements the supplied GrProgramInfo.
41      *
42      * @return the created pipeline if generation was successful; nullptr otherwise
43      */
44     static GrMtlPipelineState* CreatePipelineState(
45                                        GrMtlGpu*,
46                                        const GrProgramDesc&,
47                                        const GrProgramInfo&,
48                                        const GrMtlPrecompiledLibraries* precompiledLibs = nullptr);
49 
50     static bool PrecompileShaders(GrMtlGpu*, const SkData&,
51                                   GrMtlPrecompiledLibraries* precompiledLibs);
52 
53 private:
54     GrMtlPipelineStateBuilder(GrMtlGpu*, const GrProgramDesc&, const GrProgramInfo&);
55 
56     GrMtlPipelineState* finalize(const GrProgramDesc&, const GrProgramInfo&,
57                                  const GrMtlPrecompiledLibraries* precompiledLibraries);
58 
59     const GrCaps* caps() const override;
60 
61     SkSL::Compiler* shaderCompiler() const override;
62 
63     void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
64 
65     id<MTLLibrary> compileMtlShaderLibrary(const std::string& shader,
66                                            SkSL::Program::Inputs inputs,
67                                            GrContextOptions::ShaderErrorHandler* errorHandler);
68     void storeShadersInCache(const std::string shaders[], const SkSL::Program::Inputs inputs[],
69                              SkSL::ProgramSettings*, sk_sp<SkData>, bool isSkSL);
70 
uniformHandler()71     GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
uniformHandler()72     const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
varyingHandler()73     GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
74 
75     GrMtlGpu* fGpu;
76     GrMtlUniformHandler fUniformHandler;
77     GrMtlVaryingHandler fVaryingHandler;
78 
79     using INHERITED = GrGLSLProgramBuilder;
80 };
81 #endif
82