blob: fc322dff264206789496b198092106264589aea5 [file] [log] [blame]
egdaniel22281c12016-03-23 13:49:40 -07001/*
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
egdaniel22281c12016-03-23 13:49:40 -070011#include "GrPipeline.h"
Brian Salomon1471df92018-06-08 10:49:00 -040012#include "GrProgramDesc.h"
egdaniel22281c12016-03-23 13:49:40 -070013#include "GrVkPipelineState.h"
14#include "GrVkUniformHandler.h"
15#include "GrVkVaryingHandler.h"
Ethan Nicholas941e7e22016-12-12 15:33:30 -050016#include "SkSLCompiler.h"
Brian Salomon1471df92018-06-08 10:49:00 -040017#include "glsl/GrGLSLProgramBuilder.h"
Greg Daniel487132b2018-12-20 14:09:36 -050018#include "vk/GrVkTypes.h"
egdaniel22281c12016-03-23 13:49:40 -070019
egdaniel22281c12016-03-23 13:49:40 -070020class GrVkGpu;
21class GrVkRenderPass;
egdaniel22281c12016-03-23 13:49:40 -070022
23class GrVkPipelineStateBuilder : public GrGLSLProgramBuilder {
24public:
Brian Salomon1471df92018-06-08 10:49:00 -040025 /**
26 * For Vulkan we want to cache the entire VkPipeline for reuse of draws. The Desc here holds all
27 * the information needed to differentiate one pipeline from another.
28 *
29 * The GrProgramDesc contains all the information need to create the actual shaders for the
30 * pipeline.
31 *
32 * For Vulkan we need to add to the GrProgramDesc to include the rest of the state on the
33 * pipline. This includes stencil settings, blending information, render pass format, draw face
34 * information, and primitive type. Note that some state is set dynamically on the pipeline for
35 * each draw and thus is not included in this descriptor. This includes the viewport, scissor,
36 * and blend constant.
37 */
38 class Desc : public GrProgramDesc {
39 public:
40 static bool Build(Desc*,
41 const GrPrimitiveProcessor&,
42 const GrPipeline&,
43 const GrStencilSettings&,
44 GrPrimitiveType primitiveType,
Greg Daniel7a82edf2018-12-04 10:54:34 -050045 GrVkGpu* gpu);
Brian Salomon1471df92018-06-08 10:49:00 -040046
47 private:
48 typedef GrProgramDesc INHERITED;
49 };
50
egdaniel22281c12016-03-23 13:49:40 -070051 /** Generates a pipeline state.
52 *
53 * The GrVkPipelineState implements what is specified in the GrPipeline and GrPrimitiveProcessor
54 * as input. After successful generation, the builder result objects are available to be used.
Ethan Nicholas38657112017-02-09 17:01:22 -050055 * This function may modify the program key by setting the surface origin key to 0 (unspecified)
56 * if it turns out the program does not care about the surface origin.
egdaniel22281c12016-03-23 13:49:40 -070057 * @return true if generation was successful.
58 */
59 static GrVkPipelineState* CreatePipelineState(GrVkGpu*,
Brian Salomonff168d92018-06-23 15:17:27 -040060 const GrPrimitiveProcessor&,
Greg Daniel9a51a862018-11-30 10:18:14 -050061 const GrTextureProxy* const primProcProxies[],
egdaniel22281c12016-03-23 13:49:40 -070062 const GrPipeline&,
csmartdaltonc633abb2016-11-01 08:55:55 -070063 const GrStencilSettings&,
egdaniel22281c12016-03-23 13:49:40 -070064 GrPrimitiveType,
Brian Salomon1471df92018-06-08 10:49:00 -040065 Desc*,
Greg Daniel99b88e02018-10-03 15:31:20 -040066 VkRenderPass compatibleRenderPass);
egdaniel22281c12016-03-23 13:49:40 -070067
68 const GrCaps* caps() const override;
egdaniel22281c12016-03-23 13:49:40 -070069
70 GrVkGpu* gpu() const { return fGpu; }
71
Brian Salomon99938a82016-11-21 13:41:08 -050072 void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
73 void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
egdaniel22281c12016-03-23 13:49:40 -070074
75private:
76 GrVkPipelineStateBuilder(GrVkGpu*,
77 const GrPipeline&,
78 const GrPrimitiveProcessor&,
Greg Daniel9a51a862018-11-30 10:18:14 -050079 const GrTextureProxy* const primProcProxies[],
Ethan Nicholas38657112017-02-09 17:01:22 -050080 GrProgramDesc*);
egdaniel22281c12016-03-23 13:49:40 -070081
csmartdaltonc633abb2016-11-01 08:55:55 -070082 GrVkPipelineState* finalize(const GrStencilSettings&,
83 GrPrimitiveType primitiveType,
Greg Daniel99b88e02018-10-03 15:31:20 -040084 VkRenderPass compatibleRenderPass,
Brian Salomon1471df92018-06-08 10:49:00 -040085 Desc*);
egdaniel22281c12016-03-23 13:49:40 -070086
Ethan Nicholas92e01cf2018-12-19 13:12:10 -050087 // returns number of shader stages
88 int loadShadersFromCache(const SkData& cached,
89 VkShaderModule* outVertShaderModule,
90 VkShaderModule* outFragShaderModule,
91 VkShaderModule* outGeomShaderModule,
92 VkPipelineShaderStageCreateInfo* outStageInfo);
93
94 void storeShadersInCache(const SkSL::String& vert,
95 const SkSL::Program::Inputs& vertInputs,
96 const SkSL::String& frag,
97 const SkSL::Program::Inputs& fragInputs,
98 const SkSL::String& geom,
99 const SkSL::Program::Inputs& geomInputs);
100
Ethan Nicholas941e7e22016-12-12 15:33:30 -0500101 bool createVkShaderModule(VkShaderStageFlagBits stage,
102 const GrGLSLShaderBuilder& builder,
103 VkShaderModule* shaderModule,
104 VkPipelineShaderStageCreateInfo* stageInfo,
Ethan Nicholas38657112017-02-09 17:01:22 -0500105 const SkSL::Program::Settings& settings,
Ethan Nicholas92e01cf2018-12-19 13:12:10 -0500106 Desc* desc,
107 SkSL::String* outSPIRV,
108 SkSL::Program::Inputs* outInputs);
109
110 bool installVkShaderModule(VkShaderStageFlagBits stage,
111 const GrGLSLShaderBuilder& builder,
112 VkShaderModule* shaderModule,
113 VkPipelineShaderStageCreateInfo* stageInfo,
114 SkSL::String spirv,
115 SkSL::Program::Inputs inputs);
egdaniel22281c12016-03-23 13:49:40 -0700116
117 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
118 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
119 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
120
121 GrVkGpu* fGpu;
Brian Salomon1471df92018-06-08 10:49:00 -0400122 GrVkVaryingHandler fVaryingHandler;
123 GrVkUniformHandler fUniformHandler;
egdaniel22281c12016-03-23 13:49:40 -0700124
125 typedef GrGLSLProgramBuilder INHERITED;
126};
127
128#endif