blob: 829f5aa33932e2fd7c711837dd7e32e8a5e04def [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
Robert Phillips901aff02019-10-08 12:32:56 -040020class GrProgramInfo;
Robert Phillips323471e2019-11-11 11:33:37 -050021class GrMtlCaps;
Timothy Liang7ac582e2018-08-06 09:47:23 -040022class GrMtlGpu;
23class GrMtlPipelineState;
24
25class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder {
26public:
Jim Van Verth1223e7f2019-02-28 17:38:35 -050027 /**
28 * For Metal we want to cache the entire pipeline for reuse of draws. The Desc here holds all
29 * the information needed to differentiate one pipeline from another.
30 *
31 * The GrProgramDesc contains all the information need to create the actual shaders for the
32 * pipeline.
33 *
34 * For Metal we need to add to the GrProgramDesc to include the rest of the state on the
35 * pipeline. This includes blending information and primitive type. The pipeline is immutable
36 * so any remaining dynamic state is set via the MtlRenderCmdEncoder.
37 */
38 class Desc : public GrProgramDesc {
39 public:
Robert Phillips323471e2019-11-11 11:33:37 -050040 static bool Build(Desc*, GrRenderTarget*, const GrProgramInfo&, const GrMtlCaps&);
Jim Van Verth1223e7f2019-02-28 17:38:35 -050041 private:
Jim Van Verth1223e7f2019-02-28 17:38:35 -050042 typedef GrProgramDesc INHERITED;
43 };
44
45 /** Generates a pipeline state.
46 *
47 * The GrMtlPipelineState implements what is specified in the GrPipeline and
48 * GrPrimitiveProcessor as input. After successful generation, the builder result objects are
49 * available to be used. This function may modify the program key by setting the surface origin
50 * key to 0 (unspecified) if it turns out the program does not care about the surface origin.
51 * @return true if generation was successful.
52 */
53 static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*,
Robert Phillips901aff02019-10-08 12:32:56 -040054 GrRenderTarget*,
55 const GrProgramInfo&,
Jim Van Verth1223e7f2019-02-28 17:38:35 -050056 Desc*);
Timothy Liang7ac582e2018-08-06 09:47:23 -040057
58private:
Robert Phillips901aff02019-10-08 12:32:56 -040059 GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*);
Jim Van Verth1223e7f2019-02-28 17:38:35 -050060
Robert Phillips901aff02019-10-08 12:32:56 -040061 GrMtlPipelineState* finalize(GrRenderTarget*, const GrProgramInfo&, Desc*);
Timothy Liang7ac582e2018-08-06 09:47:23 -040062
63 const GrCaps* caps() const override;
64
Timothy Liang7ac582e2018-08-06 09:47:23 -040065 void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
66
67 void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
68
69 id<MTLLibrary> createMtlShaderLibrary(const GrGLSLShaderBuilder& builder,
70 SkSL::Program::Kind kind,
71 const SkSL::Program::Settings& settings,
72 GrProgramDesc* desc);
73
Jim Van Verth1223e7f2019-02-28 17:38:35 -050074 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
75 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
76 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
Timothy Liang7ac582e2018-08-06 09:47:23 -040077
78 GrMtlGpu* fGpu;
Timothy Liang057c3902018-08-08 10:48:45 -040079 GrMtlUniformHandler fUniformHandler;
80 GrMtlVaryingHandler fVaryingHandler;
Timothy Liang7ac582e2018-08-06 09:47:23 -040081
82 typedef GrGLSLProgramBuilder INHERITED;
83};
84#endif