blob: e4b5179c968537d311d25f891ab269b48282f6ad [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;
Brian Osman9e4e4c72020-06-10 07:19:34 -040024class SkReadBuffer;
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
Stephen Whiteb1857852020-02-07 15:33:23 +000032 * available to be used.
33 * @return the created pipeline if generation was successful; nullptr otherwise
Jim Van Verth1223e7f2019-02-28 17:38:35 -050034 */
35 static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*,
Robert Phillips901aff02019-10-08 12:32:56 -040036 GrRenderTarget*,
Stephen Whiteb1857852020-02-07 15:33:23 +000037 const GrProgramDesc&,
38 const GrProgramInfo&);
Timothy Liang7ac582e2018-08-06 09:47:23 -040039
Jim Van Verth07c84012021-02-26 14:42:11 -050040 static bool PrecompileShaders(GrMtlGpu*, const SkData&);
41
Timothy Liang7ac582e2018-08-06 09:47:23 -040042private:
Stephen Whiteb1857852020-02-07 15:33:23 +000043 GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*,
44 const GrProgramDesc&, const GrProgramInfo&);
Jim Van Verth1223e7f2019-02-28 17:38:35 -050045
Stephen Whiteb1857852020-02-07 15:33:23 +000046 GrMtlPipelineState* finalize(GrRenderTarget*, const GrProgramDesc&, const GrProgramInfo&);
Timothy Liang7ac582e2018-08-06 09:47:23 -040047
48 const GrCaps* caps() const override;
49
Ethan Nicholasee9cb6a2021-02-02 11:59:09 -050050 SkSL::Compiler* shaderCompiler() const override;
51
Timothy Liang7ac582e2018-08-06 09:47:23 -040052 void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
53
54 void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
55
Jim Van Verth36b86af2020-08-24 17:16:46 +000056 id<MTLLibrary> compileMtlShaderLibrary(const SkSL::String& shader,
Robert Phillips797831c2020-11-20 22:35:55 +000057 SkSL::Program::Inputs inputs,
58 GrContextOptions::ShaderErrorHandler* errorHandler);
Jim Van Verth9b2c06f2019-12-09 11:12:50 -050059 void storeShadersInCache(const SkSL::String shaders[], const SkSL::Program::Inputs inputs[],
Jim Van Verth07c84012021-02-26 14:42:11 -050060 SkSL::Program::Settings*, bool isSkSL);
Timothy Liang7ac582e2018-08-06 09:47:23 -040061
Jim Van Verth1223e7f2019-02-28 17:38:35 -050062 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
63 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
64 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
Timothy Liang7ac582e2018-08-06 09:47:23 -040065
66 GrMtlGpu* fGpu;
Timothy Liang057c3902018-08-08 10:48:45 -040067 GrMtlUniformHandler fUniformHandler;
68 GrMtlVaryingHandler fVaryingHandler;
Timothy Liang7ac582e2018-08-06 09:47:23 -040069
John Stiles7571f9e2020-09-02 22:42:33 -040070 using INHERITED = GrGLSLProgramBuilder;
Timothy Liang7ac582e2018-08-06 09:47:23 -040071};
72#endif