blob: 82427028a4e50de54096bb2931710ea7652afd9b [file] [log] [blame]
Timothy Liang7ac582e2018-08-06 09:47:23 -04001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#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"
Timothy Liang7ac582e2018-08-06 09:47:23 -040017
Aaron O'Mullan829b6a02019-07-08 01:31:14 +020018#import <Metal/Metal.h>
Timothy Liang7ac582e2018-08-06 09:47:23 -040019
20class GrMtlGpu;
21class GrMtlPipelineState;
22
23class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder {
24public:
Jim Van Verth1223e7f2019-02-28 17:38:35 -050025 /**
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
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,
Robert Phillipsd0fe8752019-01-31 14:13:59 -050063 const GrPrimitiveProcessor&,
Greg Daniel9a51a862018-11-30 10:18:14 -050064 const GrTextureProxy* const primProcProxies[],
Timothy Liang7ac582e2018-08-06 09:47:23 -040065 const GrPipeline&,
Jim Van Verth1223e7f2019-02-28 17:38:35 -050066 Desc*);
Timothy Liang7ac582e2018-08-06 09:47:23 -040067
68private:
Jim Van Verth1223e7f2019-02-28 17:38:35 -050069 GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*, GrSurfaceOrigin,
70 const GrPipeline&,
Robert Phillipsd0fe8752019-01-31 14:13:59 -050071 const GrPrimitiveProcessor&,
Greg Daniel9a51a862018-11-30 10:18:14 -050072 const GrTextureProxy* const primProcProxies[],
Jim Van Verth1223e7f2019-02-28 17:38:35 -050073 GrProgramDesc*);
74
Jim Van Verth2e4287f2019-03-05 12:16:11 -050075 GrMtlPipelineState* finalize(GrRenderTarget* renderTarget,
76 const GrPrimitiveProcessor& primProc,
Jim Van Verth1223e7f2019-02-28 17:38:35 -050077 const GrPipeline& pipeline,
78 Desc*);
Timothy Liang7ac582e2018-08-06 09:47:23 -040079
80 const GrCaps* caps() const override;
81
Timothy Liang7ac582e2018-08-06 09:47:23 -040082 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
Jim Van Verth1223e7f2019-02-28 17:38:35 -050091 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
92 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
93 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
Timothy Liang7ac582e2018-08-06 09:47:23 -040094
95 GrMtlGpu* fGpu;
Timothy Liang057c3902018-08-08 10:48:45 -040096 GrMtlUniformHandler fUniformHandler;
97 GrMtlVaryingHandler fVaryingHandler;
Timothy Liang7ac582e2018-08-06 09:47:23 -040098
99 typedef GrGLSLProgramBuilder INHERITED;
100};
101#endif