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" |
| 12 | #include "src/gpu/GrProgramDesc.h" |
| 13 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
| 14 | #include "src/gpu/mtl/GrMtlUniformHandler.h" |
| 15 | #include "src/gpu/mtl/GrMtlVaryingHandler.h" |
| 16 | #include "src/sksl/SkSLCompiler.h" |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 17 | |
Aaron O'Mullan | 829b6a0 | 2019-07-08 01:31:14 +0200 | [diff] [blame] | 18 | #import <Metal/Metal.h> |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 19 | |
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; |
| 24 | |
| 25 | class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder { |
| 26 | public: |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 27 | /** |
| 28 | * For Metal we want to cache the entire pipeline for reuse of draws. The Desc here holds all |
| 29 | * the information needed to differentiate one pipeline from another. |
| 30 | * |
| 31 | * The GrProgramDesc contains all the information need to create the actual shaders for the |
| 32 | * pipeline. |
| 33 | * |
| 34 | * For Metal we need to add to the GrProgramDesc to include the rest of the state on the |
| 35 | * pipeline. This includes blending information and primitive type. The pipeline is immutable |
| 36 | * so any remaining dynamic state is set via the MtlRenderCmdEncoder. |
| 37 | */ |
| 38 | class Desc : public GrProgramDesc { |
| 39 | public: |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 40 | static bool Build(Desc*, GrRenderTarget*, const GrProgramInfo&, const GrMtlCaps&); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 41 | private: |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 42 | typedef GrProgramDesc INHERITED; |
| 43 | }; |
| 44 | |
| 45 | /** Generates a pipeline state. |
| 46 | * |
| 47 | * The GrMtlPipelineState implements what is specified in the GrPipeline and |
| 48 | * GrPrimitiveProcessor as input. After successful generation, the builder result objects are |
| 49 | * available to be used. This function may modify the program key by setting the surface origin |
| 50 | * key to 0 (unspecified) if it turns out the program does not care about the surface origin. |
| 51 | * @return true if generation was successful. |
| 52 | */ |
| 53 | static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*, |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 54 | GrRenderTarget*, |
| 55 | const GrProgramInfo&, |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 56 | Desc*); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 57 | |
| 58 | private: |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 59 | GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 60 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 61 | GrMtlPipelineState* finalize(GrRenderTarget*, const GrProgramInfo&, Desc*); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 62 | |
| 63 | const GrCaps* caps() const override; |
| 64 | |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 65 | void finalizeFragmentOutputColor(GrShaderVar& outputColor) override; |
| 66 | |
| 67 | void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override; |
| 68 | |
| 69 | id<MTLLibrary> createMtlShaderLibrary(const GrGLSLShaderBuilder& builder, |
| 70 | SkSL::Program::Kind kind, |
| 71 | const SkSL::Program::Settings& settings, |
| 72 | GrProgramDesc* desc); |
| 73 | |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 74 | GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } |
| 75 | const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } |
| 76 | GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 77 | |
| 78 | GrMtlGpu* fGpu; |
Timothy Liang | 057c390 | 2018-08-08 10:48:45 -0400 | [diff] [blame] | 79 | GrMtlUniformHandler fUniformHandler; |
| 80 | GrMtlVaryingHandler fVaryingHandler; |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 81 | |
| 82 | typedef GrGLSLProgramBuilder INHERITED; |
| 83 | }; |
| 84 | #endif |