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 | |
Jim Van Verth | 7d195ff | 2021-03-09 14:59:58 -0500 | [diff] [blame] | 26 | struct GrMtlPrecompiledLibraries { |
| 27 | // TODO: wrap these in sk_cfp<> or unique_ptr<> when we remove ARC |
| 28 | id<MTLLibrary> fVertexLibrary; |
| 29 | id<MTLLibrary> fFragmentLibrary; |
| 30 | bool fRTHeight = false; |
| 31 | }; |
| 32 | |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 33 | class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder { |
| 34 | public: |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 35 | /** Generates a pipeline state. |
| 36 | * |
| 37 | * The GrMtlPipelineState implements what is specified in the GrPipeline and |
| 38 | * GrPrimitiveProcessor as input. After successful generation, the builder result objects are |
Stephen White | b185785 | 2020-02-07 15:33:23 +0000 | [diff] [blame] | 39 | * available to be used. |
| 40 | * @return the created pipeline if generation was successful; nullptr otherwise |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 41 | */ |
Jim Van Verth | 7d195ff | 2021-03-09 14:59:58 -0500 | [diff] [blame] | 42 | static GrMtlPipelineState* CreatePipelineState( |
| 43 | GrMtlGpu*, |
| 44 | const GrProgramDesc&, |
| 45 | const GrProgramInfo&, |
| 46 | const GrMtlPrecompiledLibraries* precompiledLibs = nullptr); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 47 | |
Jim Van Verth | 7d195ff | 2021-03-09 14:59:58 -0500 | [diff] [blame] | 48 | static bool PrecompileShaders(GrMtlGpu*, const SkData&, |
| 49 | GrMtlPrecompiledLibraries* precompiledLibs); |
Jim Van Verth | 07c8401 | 2021-02-26 14:42:11 -0500 | [diff] [blame] | 50 | |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 51 | private: |
Jim Van Verth | 84ded4d | 2021-03-03 13:29:38 -0500 | [diff] [blame] | 52 | GrMtlPipelineStateBuilder(GrMtlGpu*, const GrProgramDesc&, const GrProgramInfo&); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 53 | |
Jim Van Verth | 7d195ff | 2021-03-09 14:59:58 -0500 | [diff] [blame] | 54 | GrMtlPipelineState* finalize(const GrProgramDesc&, const GrProgramInfo&, |
| 55 | const GrMtlPrecompiledLibraries* precompiledLibraries); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 56 | |
| 57 | const GrCaps* caps() const override; |
| 58 | |
Ethan Nicholas | ee9cb6a | 2021-02-02 11:59:09 -0500 | [diff] [blame] | 59 | SkSL::Compiler* shaderCompiler() const override; |
| 60 | |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 61 | void finalizeFragmentOutputColor(GrShaderVar& outputColor) override; |
| 62 | |
| 63 | void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override; |
| 64 | |
Jim Van Verth | 36b86af | 2020-08-24 17:16:46 +0000 | [diff] [blame] | 65 | id<MTLLibrary> compileMtlShaderLibrary(const SkSL::String& shader, |
Robert Phillips | 797831c | 2020-11-20 22:35:55 +0000 | [diff] [blame] | 66 | SkSL::Program::Inputs inputs, |
| 67 | GrContextOptions::ShaderErrorHandler* errorHandler); |
Jim Van Verth | 9b2c06f | 2019-12-09 11:12:50 -0500 | [diff] [blame] | 68 | void storeShadersInCache(const SkSL::String shaders[], const SkSL::Program::Inputs inputs[], |
Jim Van Verth | 07c8401 | 2021-02-26 14:42:11 -0500 | [diff] [blame] | 69 | SkSL::Program::Settings*, bool isSkSL); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 70 | |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 71 | GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } |
| 72 | const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } |
| 73 | GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 74 | |
| 75 | GrMtlGpu* fGpu; |
Timothy Liang | 057c390 | 2018-08-08 10:48:45 -0400 | [diff] [blame] | 76 | GrMtlUniformHandler fUniformHandler; |
| 77 | GrMtlVaryingHandler fVaryingHandler; |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 78 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 79 | using INHERITED = GrGLSLProgramBuilder; |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 80 | }; |
| 81 | #endif |