Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrPipeline.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #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 Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 16 | |
Aaron O'Mullan | 829b6a0 | 2019-07-08 01:31:14 +0200 | [diff] [blame] | 17 | #import <Metal/Metal.h> |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 18 | |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 19 | class GrProgramDesc; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 20 | class GrProgramInfo; |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 21 | class GrMtlCaps; |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 22 | class GrMtlGpu; |
| 23 | class GrMtlPipelineState; |
Brian Osman | 9e4e4c7 | 2020-06-10 07:19:34 -0400 | [diff] [blame] | 24 | class SkReadBuffer; |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 25 | |
| 26 | class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder { |
| 27 | public: |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 28 | /** 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 White | b185785 | 2020-02-07 15:33:23 +0000 | [diff] [blame] | 32 | * available to be used. |
| 33 | * @return the created pipeline if generation was successful; nullptr otherwise |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 34 | */ |
| 35 | static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*, |
Stephen White | b185785 | 2020-02-07 15:33:23 +0000 | [diff] [blame] | 36 | const GrProgramDesc&, |
| 37 | const GrProgramInfo&); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 38 | |
Jim Van Verth | 07c8401 | 2021-02-26 14:42:11 -0500 | [diff] [blame] | 39 | static bool PrecompileShaders(GrMtlGpu*, const SkData&); |
| 40 | |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 41 | private: |
Jim Van Verth | 84ded4d | 2021-03-03 13:29:38 -0500 | [diff] [blame^] | 42 | GrMtlPipelineStateBuilder(GrMtlGpu*, const GrProgramDesc&, const GrProgramInfo&); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 43 | |
Jim Van Verth | 84ded4d | 2021-03-03 13:29:38 -0500 | [diff] [blame^] | 44 | GrMtlPipelineState* finalize(const GrProgramDesc&, const GrProgramInfo&); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 45 | |
| 46 | const GrCaps* caps() const override; |
| 47 | |
Ethan Nicholas | ee9cb6a | 2021-02-02 11:59:09 -0500 | [diff] [blame] | 48 | SkSL::Compiler* shaderCompiler() const override; |
| 49 | |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 50 | void finalizeFragmentOutputColor(GrShaderVar& outputColor) override; |
| 51 | |
| 52 | void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override; |
| 53 | |
Jim Van Verth | 36b86af | 2020-08-24 17:16:46 +0000 | [diff] [blame] | 54 | id<MTLLibrary> compileMtlShaderLibrary(const SkSL::String& shader, |
Robert Phillips | 797831c | 2020-11-20 22:35:55 +0000 | [diff] [blame] | 55 | SkSL::Program::Inputs inputs, |
| 56 | GrContextOptions::ShaderErrorHandler* errorHandler); |
Jim Van Verth | 9b2c06f | 2019-12-09 11:12:50 -0500 | [diff] [blame] | 57 | void storeShadersInCache(const SkSL::String shaders[], const SkSL::Program::Inputs inputs[], |
Jim Van Verth | 07c8401 | 2021-02-26 14:42:11 -0500 | [diff] [blame] | 58 | SkSL::Program::Settings*, bool isSkSL); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 59 | |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 60 | GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } |
| 61 | const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } |
| 62 | GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 63 | |
| 64 | GrMtlGpu* fGpu; |
Timothy Liang | 057c390 | 2018-08-08 10:48:45 -0400 | [diff] [blame] | 65 | GrMtlUniformHandler fUniformHandler; |
| 66 | GrMtlVaryingHandler fVaryingHandler; |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 67 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 68 | using INHERITED = GrGLSLProgramBuilder; |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 69 | }; |
| 70 | #endif |