GrVkPipelineStateBuilder.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #ifndef GrVkPipelineStateBuilder_DEFINED
  8. #define GrVkPipelineStateBuilder_DEFINED
  9. #include "include/gpu/vk/GrVkTypes.h"
  10. #include "src/gpu/GrPipeline.h"
  11. #include "src/gpu/GrProgramDesc.h"
  12. #include "src/gpu/glsl/GrGLSLProgramBuilder.h"
  13. #include "src/gpu/vk/GrVkPipelineState.h"
  14. #include "src/gpu/vk/GrVkUniformHandler.h"
  15. #include "src/gpu/vk/GrVkVaryingHandler.h"
  16. #include "src/sksl/SkSLCompiler.h"
  17. class GrVkGpu;
  18. class GrVkRenderPass;
  19. class GrVkPipelineStateBuilder : public GrGLSLProgramBuilder {
  20. public:
  21. /**
  22. * For Vulkan we want to cache the entire VkPipeline for reuse of draws. The Desc here holds all
  23. * the information needed to differentiate one pipeline from another.
  24. *
  25. * The GrProgramDesc contains all the information need to create the actual shaders for the
  26. * pipeline.
  27. *
  28. * For Vulkan we need to add to the GrProgramDesc to include the rest of the state on the
  29. * pipline. This includes stencil settings, blending information, render pass format, draw face
  30. * information, and primitive type. Note that some state is set dynamically on the pipeline for
  31. * each draw and thus is not included in this descriptor. This includes the viewport, scissor,
  32. * and blend constant.
  33. */
  34. class Desc : public GrProgramDesc {
  35. public:
  36. static bool Build(Desc*,
  37. GrRenderTarget*,
  38. const GrPrimitiveProcessor&,
  39. const GrPipeline&,
  40. const GrStencilSettings&,
  41. GrPrimitiveType primitiveType,
  42. GrVkGpu* gpu);
  43. size_t shaderKeyLength() const { return fShaderKeyLength; }
  44. private:
  45. size_t fShaderKeyLength;
  46. typedef GrProgramDesc INHERITED;
  47. };
  48. /** Generates a pipeline state.
  49. *
  50. * The GrVkPipelineState implements what is specified in the GrPipeline and GrPrimitiveProcessor
  51. * as input. After successful generation, the builder result objects are available to be used.
  52. * This function may modify the program key by setting the surface origin key to 0 (unspecified)
  53. * if it turns out the program does not care about the surface origin.
  54. * @return true if generation was successful.
  55. */
  56. static GrVkPipelineState* CreatePipelineState(GrVkGpu*,
  57. GrRenderTarget*, GrSurfaceOrigin,
  58. const GrPrimitiveProcessor&,
  59. const GrTextureProxy* const primProcProxies[],
  60. const GrPipeline&,
  61. const GrStencilSettings&,
  62. GrPrimitiveType,
  63. Desc*,
  64. VkRenderPass compatibleRenderPass);
  65. const GrCaps* caps() const override;
  66. GrVkGpu* gpu() const { return fGpu; }
  67. void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
  68. void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
  69. private:
  70. GrVkPipelineStateBuilder(GrVkGpu*, GrRenderTarget*, GrSurfaceOrigin,
  71. const GrPipeline&,
  72. const GrPrimitiveProcessor&,
  73. const GrTextureProxy* const primProcProxies[],
  74. GrProgramDesc*);
  75. GrVkPipelineState* finalize(const GrStencilSettings&,
  76. GrPrimitiveType primitiveType,
  77. VkRenderPass compatibleRenderPass,
  78. Desc*);
  79. // returns number of shader stages
  80. int loadShadersFromCache(const SkData& cached, VkShaderModule outShaderModules[],
  81. VkPipelineShaderStageCreateInfo* outStageInfo);
  82. void storeShadersInCache(const SkSL::String shaders[], const SkSL::Program::Inputs inputs[],
  83. bool isSkSL);
  84. bool createVkShaderModule(VkShaderStageFlagBits stage,
  85. const SkSL::String& sksl,
  86. VkShaderModule* shaderModule,
  87. VkPipelineShaderStageCreateInfo* stageInfo,
  88. const SkSL::Program::Settings& settings,
  89. Desc* desc,
  90. SkSL::String* outSPIRV,
  91. SkSL::Program::Inputs* outInputs);
  92. bool installVkShaderModule(VkShaderStageFlagBits stage,
  93. const GrGLSLShaderBuilder& builder,
  94. VkShaderModule* shaderModule,
  95. VkPipelineShaderStageCreateInfo* stageInfo,
  96. SkSL::String spirv,
  97. SkSL::Program::Inputs inputs);
  98. GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
  99. const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
  100. GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
  101. GrVkGpu* fGpu;
  102. GrVkVaryingHandler fVaryingHandler;
  103. GrVkUniformHandler fUniformHandler;
  104. typedef GrGLSLProgramBuilder INHERITED;
  105. };
  106. #endif