Debian Codegraph @

src/gpu/ganesh/mtl/GrMtlPipelineStateBuilder.h

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