blob: b70539eaf1f31489ba7d363bd4ba101a4960e7b6 [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
Greg Daniel54bfb182018-11-20 17:12:36 -050011#include "GrVkVulkan.h"
12
egdaniel22281c12016-03-23 13:49:40 -070013#include "GrPipeline.h"
Brian Salomon1471df92018-06-08 10:49:00 -040014#include "GrProgramDesc.h"
egdaniel22281c12016-03-23 13:49:40 -070015#include "GrVkPipelineState.h"
16#include "GrVkUniformHandler.h"
17#include "GrVkVaryingHandler.h"
Ethan Nicholas941e7e22016-12-12 15:33:30 -050018#include "SkSLCompiler.h"
Brian Salomon1471df92018-06-08 10:49:00 -040019#include "glsl/GrGLSLProgramBuilder.h"
egdaniel22281c12016-03-23 13:49:40 -070020
egdaniel22281c12016-03-23 13:49:40 -070021class GrVkGpu;
22class GrVkRenderPass;
egdaniel22281c12016-03-23 13:49:40 -070023
24class GrVkPipelineStateBuilder : public GrGLSLProgramBuilder {
25public:
Brian Salomon1471df92018-06-08 10:49:00 -040026 /**
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 Daniel7a82edf2018-12-04 10:54:34 -050046 GrVkGpu* gpu);
Brian Salomon1471df92018-06-08 10:49:00 -040047
48 private:
49 typedef GrProgramDesc INHERITED;
50 };
51
egdaniel22281c12016-03-23 13:49:40 -070052 /** 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 Nicholas38657112017-02-09 17:01:22 -050056 * 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.
egdaniel22281c12016-03-23 13:49:40 -070058 * @return true if generation was successful.
59 */
60 static GrVkPipelineState* CreatePipelineState(GrVkGpu*,
Brian Salomonff168d92018-06-23 15:17:27 -040061 const GrPrimitiveProcessor&,
Greg Daniel9a51a862018-11-30 10:18:14 -050062 const GrTextureProxy* const primProcProxies[],
egdaniel22281c12016-03-23 13:49:40 -070063 const GrPipeline&,
csmartdaltonc633abb2016-11-01 08:55:55 -070064 const GrStencilSettings&,
egdaniel22281c12016-03-23 13:49:40 -070065 GrPrimitiveType,
Brian Salomon1471df92018-06-08 10:49:00 -040066 Desc*,
Greg Daniel99b88e02018-10-03 15:31:20 -040067 VkRenderPass compatibleRenderPass);
egdaniel22281c12016-03-23 13:49:40 -070068
69 const GrCaps* caps() const override;
egdaniel22281c12016-03-23 13:49:40 -070070
71 GrVkGpu* gpu() const { return fGpu; }
72
Brian Salomon99938a82016-11-21 13:41:08 -050073 void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
74 void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
egdaniel22281c12016-03-23 13:49:40 -070075
76private:
77 GrVkPipelineStateBuilder(GrVkGpu*,
78 const GrPipeline&,
79 const GrPrimitiveProcessor&,
Greg Daniel9a51a862018-11-30 10:18:14 -050080 const GrTextureProxy* const primProcProxies[],
Ethan Nicholas38657112017-02-09 17:01:22 -050081 GrProgramDesc*);
egdaniel22281c12016-03-23 13:49:40 -070082
csmartdaltonc633abb2016-11-01 08:55:55 -070083 GrVkPipelineState* finalize(const GrStencilSettings&,
84 GrPrimitiveType primitiveType,
Greg Daniel99b88e02018-10-03 15:31:20 -040085 VkRenderPass compatibleRenderPass,
Brian Salomon1471df92018-06-08 10:49:00 -040086 Desc*);
egdaniel22281c12016-03-23 13:49:40 -070087
Ethan Nicholas941e7e22016-12-12 15:33:30 -050088 bool createVkShaderModule(VkShaderStageFlagBits stage,
89 const GrGLSLShaderBuilder& builder,
90 VkShaderModule* shaderModule,
91 VkPipelineShaderStageCreateInfo* stageInfo,
Ethan Nicholas38657112017-02-09 17:01:22 -050092 const SkSL::Program::Settings& settings,
Brian Salomon1471df92018-06-08 10:49:00 -040093 Desc* desc);
egdaniel22281c12016-03-23 13:49:40 -070094
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 Salomon1471df92018-06-08 10:49:00 -0400100 GrVkVaryingHandler fVaryingHandler;
101 GrVkUniformHandler fUniformHandler;
egdaniel22281c12016-03-23 13:49:40 -0700102
103 typedef GrGLSLProgramBuilder INHERITED;
104};
105
106#endif