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