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 
11 #include "glsl/GrGLSLProgramBuilder.h"
12 
13 #include "GrPipeline.h"
14 #include "GrVkPipelineState.h"
15 #include "GrVkUniformHandler.h"
16 #include "GrVkVaryingHandler.h"
17 #include "SkSLCompiler.h"
18 
19 #include "vk/GrVkDefines.h"
20 
21 class GrProgramDesc;
22 class GrVkGpu;
23 class GrVkRenderPass;
24 
25 class GrVkPipelineStateBuilder : public GrGLSLProgramBuilder {
26 public:
27     /** Generates a pipeline state.
28     *
29     * The GrVkPipelineState implements what is specified in the GrPipeline and GrPrimitiveProcessor
30     * as input. After successful generation, the builder result objects are available to be used.
31     * This function may modify the program key by setting the surface origin key to 0 (unspecified)
32     * if it turns out the program does not care about the surface origin.
33     * @return true if generation was successful.
34     */
35     static GrVkPipelineState* CreatePipelineState(GrVkGpu*,
36                                                   const GrPipeline&,
37                                                   const GrStencilSettings&,
38                                                   const GrPrimitiveProcessor&,
39                                                   GrPrimitiveType,
40                                                   GrVkPipelineState::Desc*,
41                                                   const GrVkRenderPass& renderPass);
42 
43     const GrCaps* caps() const override;
44 
gpu()45     GrVkGpu* gpu() const { return fGpu; }
46 
47     void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
48     void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
49 
50 private:
51     GrVkPipelineStateBuilder(GrVkGpu*,
52                              const GrPipeline&,
53                              const GrPrimitiveProcessor&,
54                              GrProgramDesc*);
55 
56     GrVkPipelineState* finalize(const GrStencilSettings&,
57                                 GrPrimitiveType primitiveType,
58                                 const GrVkRenderPass& renderPass,
59                                 GrVkPipelineState::Desc*);
60 
61     bool createVkShaderModule(VkShaderStageFlagBits stage,
62                               const GrGLSLShaderBuilder& builder,
63                               VkShaderModule* shaderModule,
64                               VkPipelineShaderStageCreateInfo* stageInfo,
65                               const SkSL::Program::Settings& settings,
66                               GrVkPipelineState::Desc* desc);
67 
uniformHandler()68     GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
uniformHandler()69     const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
varyingHandler()70     GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
71 
72     GrVkGpu* fGpu;
73     GrVkVaryingHandler        fVaryingHandler;
74     GrVkUniformHandler        fUniformHandler;
75 
76     typedef GrGLSLProgramBuilder INHERITED;
77 };
78 
79 #endif
80