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 "include/gpu/vk/GrVkTypes.h" 12 #include "src/gpu/GrPipeline.h" 13 #include "src/gpu/glsl/GrGLSLProgramBuilder.h" 14 #include "src/gpu/vk/GrVkPipelineState.h" 15 #include "src/gpu/vk/GrVkUniformHandler.h" 16 #include "src/gpu/vk/GrVkVaryingHandler.h" 17 #include "src/sksl/SkSLCompiler.h" 18 19 class GrProgramDesc; 20 class GrVkGpu; 21 class GrVkRenderPass; 22 class SkReadBuffer; 23 24 class GrVkPipelineStateBuilder : public GrGLSLProgramBuilder { 25 public: 26 /** Generates a pipeline state. 27 * 28 * The return GrVkPipelineState implements the supplied GrProgramInfo. 29 * 30 * @return the created pipeline if generation was successful; nullptr otherwise 31 */ 32 static GrVkPipelineState* CreatePipelineState(GrVkGpu*, 33 const GrProgramDesc&, 34 const GrProgramInfo&, 35 VkRenderPass compatibleRenderPass, 36 bool overrideSubpassForResolveLoad); 37 38 const GrCaps* caps() const override; 39 gpu()40 GrVkGpu* gpu() const { return fGpu; } 41 42 SkSL::Compiler* shaderCompiler() const override; 43 44 void finalizeFragmentOutputColor(GrShaderVar& outputColor) override; 45 void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override; 46 47 private: 48 GrVkPipelineStateBuilder(GrVkGpu*, const GrProgramDesc&, const GrProgramInfo&); 49 50 GrVkPipelineState* finalize(const GrProgramDesc&, VkRenderPass compatibleRenderPass, 51 bool overrideSupbassForResolveLoad); 52 53 // returns number of shader stages 54 int loadShadersFromCache(SkReadBuffer* cached, VkShaderModule outShaderModules[], 55 VkPipelineShaderStageCreateInfo* outStageInfo); 56 57 void storeShadersInCache(const SkSL::String shaders[], const SkSL::Program::Inputs inputs[], 58 bool isSkSL); 59 60 bool createVkShaderModule(VkShaderStageFlagBits stage, 61 const SkSL::String& sksl, 62 VkShaderModule* shaderModule, 63 VkPipelineShaderStageCreateInfo* stageInfo, 64 const SkSL::Program::Settings& settings, 65 SkSL::String* outSPIRV, 66 SkSL::Program::Inputs* outInputs); 67 68 bool installVkShaderModule(VkShaderStageFlagBits stage, 69 const GrGLSLShaderBuilder& builder, 70 VkShaderModule* shaderModule, 71 VkPipelineShaderStageCreateInfo* stageInfo, 72 SkSL::String spirv, 73 SkSL::Program::Inputs inputs); 74 uniformHandler()75 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } uniformHandler()76 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } varyingHandler()77 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } 78 79 GrVkGpu* fGpu; 80 GrVkVaryingHandler fVaryingHandler; 81 GrVkUniformHandler fUniformHandler; 82 83 using INHERITED = GrGLSLProgramBuilder; 84 }; 85 86 #endif 87