• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 Google LLC
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 skgpu_graphite_VulkanGraphicsPipeline_DEFINED
9 #define skgpu_graphite_VulkanGraphicsPipeline_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkSpan.h"
13 #include "include/gpu/vk/VulkanTypes.h"
14 #include "src/gpu/Blend.h"
15 #include "src/gpu/graphite/DrawTypes.h"
16 #include "src/gpu/graphite/GraphicsPipeline.h"
17 #include "src/gpu/graphite/vk/VulkanGraphiteUtilsPriv.h"
18 
19 namespace SkSL {
20     class Compiler;
21 }
22 
23 namespace skgpu::graphite {
24 
25 class Attribute;
26 class GraphicsPipelineDesc;
27 class RuntimeEffectDictionary;
28 class VulkanSharedContext;
29 struct RenderPassDesc;
30 class TextureInfo;
31 class VulkanRenderPass;
32 
33 class VulkanGraphicsPipeline final : public GraphicsPipeline {
34 public:
35     inline static constexpr unsigned int kIntrinsicUniformBufferIndex = 0;
36     inline static constexpr unsigned int kRenderStepUniformBufferIndex = 1;
37     inline static constexpr unsigned int kPaintUniformBufferIndex = 2;
38     inline static constexpr unsigned int kNumUniformBuffers = 3;
39 
40     // For now, rigidly assign all uniform buffer descriptors to be in set 0 and all
41     // texture/samplers to be in set 1.
42     // TODO(b/274762935): Make the bindings and descriptor set organization more flexible.
43     inline static constexpr unsigned int kUniformBufferDescSetIndex = 0;
44     inline static constexpr unsigned int kTextureBindDescSetIndex = 1;
45     // Currently input attachments are only used for loading MSAA from resolve, so we can use the
46     // descriptor set index normally assigned to uniform desc sets.
47     inline static constexpr unsigned int kInputAttachmentDescSetIndex = kUniformBufferDescSetIndex;
48 
49     inline static constexpr unsigned int kVertexBufferIndex = 0;
50     inline static constexpr unsigned int kInstanceBufferIndex = 1;
51     inline static constexpr unsigned int kNumInputBuffers = 2;
52 
53     inline static const DescriptorData kIntrinsicUniformBufferDescriptor = {
54             DescriptorType::kUniformBuffer, /*count=*/1,
55             kIntrinsicUniformBufferIndex,
56             PipelineStageFlags::kVertexShader | PipelineStageFlags::kFragmentShader};
57 
58     inline static const DescriptorData kRenderStepUniformDescriptor = {
59             DescriptorType::kUniformBuffer, /*count=*/1,
60             kRenderStepUniformBufferIndex,
61             PipelineStageFlags::kVertexShader | PipelineStageFlags::kFragmentShader};
62 
63     inline static const DescriptorData kPaintUniformDescriptor = {
64             DescriptorType::kUniformBuffer, /*count=*/1,
65             kPaintUniformBufferIndex,
66             PipelineStageFlags::kFragmentShader};
67 
68     // Currently we only ever have one input attachment descriptor by itself within a set, so its
69     // binding index will always be 0.
70     inline static constexpr unsigned int kInputAttachmentBindingIndex = 0;
71     inline static const DescriptorData kInputAttachmentDescriptor = {
72             DescriptorType::kInputAttachment, /*count=*/1,
73             kInputAttachmentBindingIndex,
74             PipelineStageFlags::kFragmentShader};
75 
76     static sk_sp<VulkanGraphicsPipeline> Make(const VulkanSharedContext*,
77                                               const RuntimeEffectDictionary*,
78                                               const GraphicsPipelineDesc&,
79                                               const RenderPassDesc&,
80                                               const sk_sp<VulkanRenderPass>& compatibleRenderPass,
81                                               VkPipelineCache);
82 
83     static sk_sp<VulkanGraphicsPipeline> MakeLoadMSAAPipeline(
84             const VulkanSharedContext*,
85             VkShaderModule vsModule,
86             VkShaderModule fsModule,
87             VkPipelineShaderStageCreateInfo* pipelineShaderStages,
88             VkPipelineLayout,
89             sk_sp<VulkanRenderPass> compatibleRenderPass,
90             VkPipelineCache,
91             const TextureInfo& dstColorAttachmentTexInfo);
92 
93     static bool InitializeMSAALoadPipelineStructs(
94             const VulkanSharedContext*,
95             VkShaderModule* outVertexShaderModule,
96             VkShaderModule* outFragShaderModule,
97             VkPipelineShaderStageCreateInfo* outShaderStageInfo,
98             VkPipelineLayout* outPipelineLayout);
99 
~VulkanGraphicsPipeline()100     ~VulkanGraphicsPipeline() override {}
101 
layout()102     VkPipelineLayout layout() const {
103         SkASSERT(fPipelineLayout != VK_NULL_HANDLE);
104         return fPipelineLayout;
105     }
106 
pipeline()107     VkPipeline pipeline() const {
108         SkASSERT(fPipeline != VK_NULL_HANDLE);
109         return fPipeline;
110     }
111 
hasFragmentUniforms()112     bool hasFragmentUniforms() const { return fHasFragmentUniforms; }
hasStepUniforms()113     bool hasStepUniforms() const { return fHasStepUniforms; }
numTextureSamplers()114     int numTextureSamplers() const { return fNumTextureSamplers; }
115 
116 private:
117     VulkanGraphicsPipeline(const skgpu::graphite::SharedContext* sharedContext,
118                            PipelineInfo* pipelineInfo,
119                            VkPipelineLayout,
120                            VkPipeline,
121                            bool hasFragmentUniforms,
122                            bool hasStepUniforms,
123                            int numTextureSamplers,
124                            bool ownsPipelineLayout);
125 
126     void freeGpuData() override;
127 
128     VkPipelineLayout fPipelineLayout = VK_NULL_HANDLE;
129     VkPipeline fPipeline = VK_NULL_HANDLE;
130     bool fHasFragmentUniforms = false;
131     bool fHasStepUniforms = false;
132     int fNumTextureSamplers = 0;
133     bool fOwnsPipelineLayout = true;
134 };
135 
136 } // namespace skgpu::graphite
137 
138 #endif // skgpu_graphite_MtlGraphicsPipeline_DEFINED
139