egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 GrVkPipelineStateBuilder_DEFINED |
| 9 | #define GrVkPipelineStateBuilder_DEFINED |
| 10 | |
Greg Daniel | 54bfb18 | 2018-11-20 17:12:36 -0500 | [diff] [blame] | 11 | #include "GrVkVulkan.h" |
| 12 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 13 | #include "GrPipeline.h" |
Brian Salomon | 1471df9 | 2018-06-08 10:49:00 -0400 | [diff] [blame] | 14 | #include "GrProgramDesc.h" |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 15 | #include "GrVkPipelineState.h" |
| 16 | #include "GrVkUniformHandler.h" |
| 17 | #include "GrVkVaryingHandler.h" |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 18 | #include "SkSLCompiler.h" |
Brian Salomon | 1471df9 | 2018-06-08 10:49:00 -0400 | [diff] [blame] | 19 | #include "glsl/GrGLSLProgramBuilder.h" |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 20 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 21 | class GrVkGpu; |
| 22 | class GrVkRenderPass; |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 23 | |
| 24 | class GrVkPipelineStateBuilder : public GrGLSLProgramBuilder { |
| 25 | public: |
Brian Salomon | 1471df9 | 2018-06-08 10:49:00 -0400 | [diff] [blame] | 26 | /** |
| 27 | * For Vulkan we want to cache the entire VkPipeline 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 Vulkan we need to add to the GrProgramDesc to include the rest of the state on the |
| 34 | * pipline. This includes stencil settings, blending information, render pass format, draw face |
| 35 | * information, and primitive type. Note that some state is set dynamically on the pipeline for |
| 36 | * each draw and thus is not included in this descriptor. This includes the viewport, scissor, |
| 37 | * and blend constant. |
| 38 | */ |
| 39 | class Desc : public GrProgramDesc { |
| 40 | public: |
| 41 | static bool Build(Desc*, |
| 42 | const GrPrimitiveProcessor&, |
| 43 | const GrPipeline&, |
| 44 | const GrStencilSettings&, |
| 45 | GrPrimitiveType primitiveType, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame^] | 46 | GrVkGpu* gpu); |
Brian Salomon | 1471df9 | 2018-06-08 10:49:00 -0400 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | typedef GrProgramDesc INHERITED; |
| 50 | }; |
| 51 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 52 | /** Generates a pipeline state. |
| 53 | * |
| 54 | * The GrVkPipelineState implements what is specified in the GrPipeline and GrPrimitiveProcessor |
| 55 | * as input. After successful generation, the builder result objects are available to be used. |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 56 | * This function may modify the program key by setting the surface origin key to 0 (unspecified) |
| 57 | * if it turns out the program does not care about the surface origin. |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 58 | * @return true if generation was successful. |
| 59 | */ |
| 60 | static GrVkPipelineState* CreatePipelineState(GrVkGpu*, |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 61 | const GrPrimitiveProcessor&, |
Greg Daniel | 9a51a86 | 2018-11-30 10:18:14 -0500 | [diff] [blame] | 62 | const GrTextureProxy* const primProcProxies[], |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 63 | const GrPipeline&, |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 64 | const GrStencilSettings&, |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 65 | GrPrimitiveType, |
Brian Salomon | 1471df9 | 2018-06-08 10:49:00 -0400 | [diff] [blame] | 66 | Desc*, |
Greg Daniel | 99b88e0 | 2018-10-03 15:31:20 -0400 | [diff] [blame] | 67 | VkRenderPass compatibleRenderPass); |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 68 | |
| 69 | const GrCaps* caps() const override; |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 70 | |
| 71 | GrVkGpu* gpu() const { return fGpu; } |
| 72 | |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 73 | void finalizeFragmentOutputColor(GrShaderVar& outputColor) override; |
| 74 | void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override; |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 75 | |
| 76 | private: |
| 77 | GrVkPipelineStateBuilder(GrVkGpu*, |
| 78 | const GrPipeline&, |
| 79 | const GrPrimitiveProcessor&, |
Greg Daniel | 9a51a86 | 2018-11-30 10:18:14 -0500 | [diff] [blame] | 80 | const GrTextureProxy* const primProcProxies[], |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 81 | GrProgramDesc*); |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 82 | |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 83 | GrVkPipelineState* finalize(const GrStencilSettings&, |
| 84 | GrPrimitiveType primitiveType, |
Greg Daniel | 99b88e0 | 2018-10-03 15:31:20 -0400 | [diff] [blame] | 85 | VkRenderPass compatibleRenderPass, |
Brian Salomon | 1471df9 | 2018-06-08 10:49:00 -0400 | [diff] [blame] | 86 | Desc*); |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 87 | |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 88 | bool createVkShaderModule(VkShaderStageFlagBits stage, |
| 89 | const GrGLSLShaderBuilder& builder, |
| 90 | VkShaderModule* shaderModule, |
| 91 | VkPipelineShaderStageCreateInfo* stageInfo, |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 92 | const SkSL::Program::Settings& settings, |
Brian Salomon | 1471df9 | 2018-06-08 10:49:00 -0400 | [diff] [blame] | 93 | Desc* desc); |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 94 | |
| 95 | GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } |
| 96 | const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } |
| 97 | GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } |
| 98 | |
| 99 | GrVkGpu* fGpu; |
Brian Salomon | 1471df9 | 2018-06-08 10:49:00 -0400 | [diff] [blame] | 100 | GrVkVaryingHandler fVaryingHandler; |
| 101 | GrVkUniformHandler fUniformHandler; |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 102 | |
| 103 | typedef GrGLSLProgramBuilder INHERITED; |
| 104 | }; |
| 105 | |
| 106 | #endif |