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; |
| 24 | |
| 25 | class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder { |
| 26 | public: |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 27 | /** Generates a pipeline state. |
| 28 | * |
| 29 | * The GrMtlPipelineState implements what is specified in the GrPipeline and |
| 30 | * GrPrimitiveProcessor as input. After successful generation, the builder result objects are |
| 31 | * available to be used. This function may modify the program key by setting the surface origin |
| 32 | * key to 0 (unspecified) if it turns out the program does not care about the surface origin. |
| 33 | * @return true if generation was successful. |
| 34 | */ |
| 35 | static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*, |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 36 | GrRenderTarget*, |
| 37 | const GrProgramInfo&, |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame^] | 38 | GrProgramDesc*); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 39 | |
| 40 | private: |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 41 | GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 42 | |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame^] | 43 | GrMtlPipelineState* finalize(GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*); |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 44 | |
| 45 | const GrCaps* caps() const override; |
| 46 | |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 47 | void finalizeFragmentOutputColor(GrShaderVar& outputColor) override; |
| 48 | |
| 49 | void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override; |
| 50 | |
| 51 | id<MTLLibrary> createMtlShaderLibrary(const GrGLSLShaderBuilder& builder, |
| 52 | SkSL::Program::Kind kind, |
| 53 | const SkSL::Program::Settings& settings, |
| 54 | GrProgramDesc* desc); |
| 55 | |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 56 | GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } |
| 57 | const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } |
| 58 | GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 59 | |
| 60 | GrMtlGpu* fGpu; |
Timothy Liang | 057c390 | 2018-08-08 10:48:45 -0400 | [diff] [blame] | 61 | GrMtlUniformHandler fUniformHandler; |
| 62 | GrMtlVaryingHandler fVaryingHandler; |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 63 | |
| 64 | typedef GrGLSLProgramBuilder INHERITED; |
| 65 | }; |
| 66 | #endif |