blob: 8a44de73cfb12f46856e81d2109f8771a591c8c2 [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
13#include "src/gpu/mtl/GrMtlUniformHandler.h"
14#include "src/gpu/mtl/GrMtlVaryingHandler.h"
15#include "src/sksl/SkSLCompiler.h"
Timothy Liang7ac582e2018-08-06 09:47:23 -040016
Aaron O'Mullan829b6a02019-07-08 01:31:14 +020017#import <Metal/Metal.h>
Timothy Liang7ac582e2018-08-06 09:47:23 -040018
Robert Phillips03e4c952019-11-26 16:20:22 -050019class GrProgramDesc;
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;
Jim Van Verth9b2c06f2019-12-09 11:12:50 -050024class SkReader32;
Timothy Liang7ac582e2018-08-06 09:47:23 -040025
26class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder {
27public:
Jim Van Verth1223e7f2019-02-28 17:38:35 -050028 /** Generates a pipeline state.
29 *
30 * The GrMtlPipelineState implements what is specified in the GrPipeline and
31 * GrPrimitiveProcessor as input. After successful generation, the builder result objects are
Austin Eng77fdf662020-02-07 01:26:16 +000032 * available to be used. This function may modify the program key by setting the surface origin
33 * key to 0 (unspecified) if it turns out the program does not care about the surface origin.
34 * @return true if generation was successful.
Jim Van Verth1223e7f2019-02-28 17:38:35 -050035 */
36 static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*,
Robert Phillips901aff02019-10-08 12:32:56 -040037 GrRenderTarget*,
Austin Eng77fdf662020-02-07 01:26:16 +000038 const GrProgramInfo&,
39 GrProgramDesc*);
Timothy Liang7ac582e2018-08-06 09:47:23 -040040
41private:
Austin Eng77fdf662020-02-07 01:26:16 +000042 GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*);
Jim Van Verth1223e7f2019-02-28 17:38:35 -050043
Austin Eng77fdf662020-02-07 01:26:16 +000044 GrMtlPipelineState* finalize(GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*);
Timothy Liang7ac582e2018-08-06 09:47:23 -040045
46 const GrCaps* caps() const override;
47
Timothy Liang7ac582e2018-08-06 09:47:23 -040048 void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
49
50 void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
51
Jim Van Verth9b2c06f2019-12-09 11:12:50 -050052 id<MTLLibrary> generateMtlShaderLibrary(const SkSL::String& sksl,
53 SkSL::Program::Kind kind,
54 const SkSL::Program::Settings& settings,
Austin Eng77fdf662020-02-07 01:26:16 +000055 GrProgramDesc* desc,
Jim Van Verth9b2c06f2019-12-09 11:12:50 -050056 SkSL::String* msl,
57 SkSL::Program::Inputs* inputs);
58 id<MTLLibrary> compileMtlShaderLibrary(const SkSL::String& shader,
59 SkSL::Program::Inputs inputs);
60 void storeShadersInCache(const SkSL::String shaders[], const SkSL::Program::Inputs inputs[],
61 bool isSkSL);
62 void loadShadersFromCache(SkReader32* cached, __strong id<MTLLibrary> outLibraries[]);
Timothy Liang7ac582e2018-08-06 09:47:23 -040063
Jim Van Verth1223e7f2019-02-28 17:38:35 -050064 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
65 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
66 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
Timothy Liang7ac582e2018-08-06 09:47:23 -040067
68 GrMtlGpu* fGpu;
Timothy Liang057c3902018-08-08 10:48:45 -040069 GrMtlUniformHandler fUniformHandler;
70 GrMtlVaryingHandler fVaryingHandler;
Timothy Liang7ac582e2018-08-06 09:47:23 -040071
72 typedef GrGLSLProgramBuilder INHERITED;
73};
74#endif