blob: 67d6f500cf9b5a1d4aaf90f7324d71c921c697a7 [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
40private:
Stephen Whiteb1857852020-02-07 15:33:23 +000041 GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*,
42 const GrProgramDesc&, const GrProgramInfo&);
Jim Van Verth1223e7f2019-02-28 17:38:35 -050043
Stephen Whiteb1857852020-02-07 15:33:23 +000044 GrMtlPipelineState* finalize(GrRenderTarget*, const GrProgramDesc&, const GrProgramInfo&);
Timothy Liang7ac582e2018-08-06 09:47:23 -040045
46 const GrCaps* caps() const override;
47
Ethan Nicholasee9cb6a2021-02-02 11:59:09 -050048 SkSL::Compiler* shaderCompiler() const override;
49
Timothy Liang7ac582e2018-08-06 09:47:23 -040050 void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
51
52 void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
53
Jim Van Verth36b86af2020-08-24 17:16:46 +000054 id<MTLLibrary> generateMtlShaderLibrary(const SkSL::String& sksl,
55 SkSL::Program::Kind kind,
56 const SkSL::Program::Settings& settings,
57 SkSL::String* msl,
Robert Phillips797831c2020-11-20 22:35:55 +000058 SkSL::Program::Inputs* inputs,
59 GrContextOptions::ShaderErrorHandler* errorHandler);
Jim Van Verth36b86af2020-08-24 17:16:46 +000060 id<MTLLibrary> compileMtlShaderLibrary(const SkSL::String& shader,
Robert Phillips797831c2020-11-20 22:35:55 +000061 SkSL::Program::Inputs inputs,
62 GrContextOptions::ShaderErrorHandler* errorHandler);
Jim Van Verth9b2c06f2019-12-09 11:12:50 -050063 void storeShadersInCache(const SkSL::String shaders[], const SkSL::Program::Inputs inputs[],
64 bool isSkSL);
Timothy Liang7ac582e2018-08-06 09:47:23 -040065
Jim Van Verth1223e7f2019-02-28 17:38:35 -050066 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
67 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
68 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
Timothy Liang7ac582e2018-08-06 09:47:23 -040069
70 GrMtlGpu* fGpu;
Timothy Liang057c3902018-08-08 10:48:45 -040071 GrMtlUniformHandler fUniformHandler;
72 GrMtlVaryingHandler fVaryingHandler;
Timothy Liang7ac582e2018-08-06 09:47:23 -040073
John Stiles7571f9e2020-09-02 22:42:33 -040074 using INHERITED = GrGLSLProgramBuilder;
Timothy Liang7ac582e2018-08-06 09:47:23 -040075};
76#endif