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 GrVkProgramBuilder_DEFINED 9 #define GrVkProgramBuilder_DEFINED 10 11 #include "glsl/GrGLSLProgramBuilder.h" 12 13 #include "GrPipeline.h" 14 #include "vk/GrVkUniformHandler.h" 15 #include "vk/GrVkVaryingHandler.h" 16 17 #include "shaderc/shaderc.h" 18 #include "vulkan/vulkan.h" 19 20 class GrVkGpu; 21 class GrVkRenderPass; 22 class GrVkProgram; 23 24 class GrVkProgramBuilder : public GrGLSLProgramBuilder { 25 public: 26 /** Generates a shader program. 27 * 28 * The program implements what is specified in the stages given as input. 29 * After successful generation, the builder result objects are available 30 * to be used. 31 * @return true if generation was successful. 32 */ 33 static GrVkProgram* CreateProgram(GrVkGpu*, 34 const DrawArgs&, 35 GrPrimitiveType, 36 const GrVkRenderPass& renderPass); 37 38 const GrCaps* caps() const override; 39 const GrGLSLCaps* glslCaps() const override; 40 gpu()41 GrVkGpu* gpu() const { return fGpu; } 42 43 void finalizeFragmentOutputColor(GrGLSLShaderVar& outputColor) override; 44 45 private: 46 GrVkProgramBuilder(GrVkGpu*, const DrawArgs&); 47 48 void emitSamplers(const GrProcessor&, 49 GrGLSLTextureSampler::TextureSamplerArray* outSamplers) override; 50 51 GrVkProgram* finalize(const DrawArgs& args, 52 GrPrimitiveType primitiveType, 53 const GrVkRenderPass& renderPass); 54 55 static bool CreateVkShaderModule(const GrVkGpu* gpu, 56 VkShaderStageFlagBits stage, 57 const GrGLSLShaderBuilder& builder, 58 VkShaderModule* shaderModule, 59 VkPipelineShaderStageCreateInfo* stageInfo); 60 uniformHandler()61 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } uniformHandler()62 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } varyingHandler()63 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } 64 65 GrVkGpu* fGpu; 66 GrVkVaryingHandler fVaryingHandler; 67 GrVkUniformHandler fUniformHandler; 68 69 SkTArray<UniformHandle> fSamplerUniforms; 70 71 typedef GrGLSLProgramBuilder INHERITED; 72 }; 73 74 #endif