2 * Copyright 2018 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrMtlPipelineStateBuilder_DEFINED
9 #define GrMtlPipelineStateBuilder_DEFINED
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/SkSLCompiler.h"
18 #import <Metal/Metal.h>
24 class GrMtlPipelineState;
27 struct GrMtlPrecompiledLibraries {
28 // TODO: wrap these in sk_cfp<> or unique_ptr<> when we remove ARC
29 id<MTLLibrary> fVertexLibrary;
30 id<MTLLibrary> fFragmentLibrary;
34 class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder {
36 /** Generates a pipeline state.
38 * The returned GrMtlPipelineState implements the supplied GrProgramInfo.
40 * @return the created pipeline if generation was successful; nullptr otherwise
42 static GrMtlPipelineState* CreatePipelineState(
46 const GrMtlPrecompiledLibraries* precompiledLibs = nullptr);
48 static bool PrecompileShaders(GrMtlGpu*, const SkData&,
49 GrMtlPrecompiledLibraries* precompiledLibs);
52 GrMtlPipelineStateBuilder(GrMtlGpu*, const GrProgramDesc&, const GrProgramInfo&);
54 GrMtlPipelineState* finalize(const GrProgramDesc&, const GrProgramInfo&,
55 const GrMtlPrecompiledLibraries* precompiledLibraries);
57 const GrCaps* caps() const override;
59 SkSL::Compiler* shaderCompiler() const override;
61 void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
63 void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
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::Program::Settings*, sk_sp<SkData>, bool isSkSL);
71 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
72 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
73 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
76 GrMtlUniformHandler fUniformHandler;
77 GrMtlVaryingHandler fVaryingHandler;
79 using INHERITED = GrGLSLProgramBuilder;