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; |
Jim Van Verth | 9b2c06f | 2019-12-09 11:12:50 -0500 | [diff] [blame] | 24 | class SkReader32; |
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 |
Austin Eng | 77fdf66 | 2020-02-07 01:26:16 +0000 | [diff] [blame] | 32 | * 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 Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 35 | */ |
| 36 | static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*, |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 37 | GrRenderTarget*, |
Austin Eng | 77fdf66 | 2020-02-07 01:26:16 +0000 | [diff] [blame] | 38 | const GrProgramInfo&, |
| 39 | GrProgramDesc*); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 40 | |
| 41 | private: |
Austin Eng | 77fdf66 | 2020-02-07 01:26:16 +0000 | [diff] [blame] | 42 | GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 43 | |
Austin Eng | 77fdf66 | 2020-02-07 01:26:16 +0000 | [diff] [blame] | 44 | GrMtlPipelineState* finalize(GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 45 | |
| 46 | const GrCaps* caps() const override; |
| 47 | |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 48 | void finalizeFragmentOutputColor(GrShaderVar& outputColor) override; |
| 49 | |
| 50 | void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override; |
| 51 | |
Jim Van Verth | 9b2c06f | 2019-12-09 11:12:50 -0500 | [diff] [blame] | 52 | id<MTLLibrary> generateMtlShaderLibrary(const SkSL::String& sksl, |
| 53 | SkSL::Program::Kind kind, |
| 54 | const SkSL::Program::Settings& settings, |
Austin Eng | 77fdf66 | 2020-02-07 01:26:16 +0000 | [diff] [blame] | 55 | GrProgramDesc* desc, |
Jim Van Verth | 9b2c06f | 2019-12-09 11:12:50 -0500 | [diff] [blame] | 56 | 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 Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 63 | |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 64 | GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } |
| 65 | const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } |
| 66 | GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 67 | |
| 68 | GrMtlGpu* fGpu; |
Timothy Liang | 057c390 | 2018-08-08 10:48:45 -0400 | [diff] [blame] | 69 | GrMtlUniformHandler fUniformHandler; |
| 70 | GrMtlVaryingHandler fVaryingHandler; |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 71 | |
| 72 | typedef GrGLSLProgramBuilder INHERITED; |
| 73 | }; |
| 74 | #endif |