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