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 "include/private/base/SkTArray.h" 15 #include "src/gpu/Blend.h" 16 #include "src/gpu/graphite/DrawTypes.h" 17 #include "src/gpu/graphite/GraphicsPipeline.h" 18 #include "src/gpu/graphite/vk/VulkanGraphiteUtils.h" 19 #include "src/gpu/graphite/vk/VulkanSampler.h" 20 21 namespace SkSL { 22 class Compiler; 23 } 24 25 namespace skgpu::graphite { 26 27 class Attribute; 28 class GraphicsPipelineDesc; 29 class RuntimeEffectDictionary; 30 class VulkanResourceProvider; 31 class VulkanSharedContext; 32 struct RenderPassDesc; 33 class TextureInfo; 34 class VulkanRenderPass; 35 36 class VulkanGraphicsPipeline final : public GraphicsPipeline { 37 public: 38 inline static constexpr unsigned int kRenderStepUniformBufferIndex = 0; 39 inline static constexpr unsigned int kPaintUniformBufferIndex = 1; 40 inline static constexpr unsigned int kGradientBufferIndex = 2; 41 inline static constexpr unsigned int kNumUniformBuffers = 3; 42 43 // For now, rigidly assign all descriptor types to be at statically-defined set indices. 44 // TODO(b/274762935): Make the bindings and descriptor set organization more flexible. 45 inline static constexpr unsigned int kDstAsInputDescSetIndex = 0; 46 inline static constexpr unsigned int kUniformBufferDescSetIndex = 1; 47 inline static constexpr unsigned int kTextureBindDescSetIndex = 2; 48 inline static constexpr unsigned int kLoadMsaaFromResolveInputDescSetIndex = 3; 49 inline static constexpr unsigned int kMaxNumDescSets = 4; 50 51 inline static constexpr unsigned int kVertexBufferIndex = 0; 52 inline static constexpr unsigned int kInstanceBufferIndex = 1; 53 inline static constexpr unsigned int kNumInputBuffers = 2; 54 55 // Define a static DescriptorData to represent input attachments which have the same values 56 // across all pipelines (we currently only ever use one input attachment within a set). 57 inline static const DescriptorData kInputAttachmentDescriptor = { 58 DescriptorType::kInputAttachment, /*count=*/1, 59 /*bindingIdx=*/0, // We only expect to encounter one input attachment 60 PipelineStageFlags::kFragmentShader}; 61 62 static sk_sp<VulkanGraphicsPipeline> Make(VulkanResourceProvider*, 63 const RuntimeEffectDictionary*, 64 const UniqueKey&, 65 const GraphicsPipelineDesc&, 66 const RenderPassDesc&, 67 SkEnumBitMask<PipelineCreationFlags>, 68 uint32_t compilationID); 69 70 static sk_sp<VulkanGraphicsPipeline> MakeLoadMSAAPipeline( 71 const VulkanSharedContext*, 72 VkShaderModule vsModule, 73 VkShaderModule fsModule, 74 VkPipelineShaderStageCreateInfo* pipelineShaderStages, 75 VkPipelineLayout, 76 sk_sp<VulkanRenderPass> compatibleRenderPass, 77 VkPipelineCache, 78 const TextureInfo& dstColorAttachmentTexInfo); 79 80 static bool InitializeMSAALoadPipelineStructs( 81 const VulkanSharedContext*, 82 VkShaderModule* outVertexShaderModule, 83 VkShaderModule* outFragShaderModule, 84 VkPipelineShaderStageCreateInfo* outShaderStageInfo, 85 VkPipelineLayout* outPipelineLayout); 86 ~VulkanGraphicsPipeline()87 ~VulkanGraphicsPipeline() override {} 88 layout()89 VkPipelineLayout layout() const { 90 SkASSERT(fPipelineLayout != VK_NULL_HANDLE); 91 return fPipelineLayout; 92 } 93 pipeline()94 VkPipeline pipeline() const { 95 SkASSERT(fPipeline != VK_NULL_HANDLE); 96 return fPipeline; 97 } 98 99 private: 100 VulkanGraphicsPipeline(const VulkanSharedContext* sharedContext, 101 const PipelineInfo& pipelineInfo, 102 VkPipelineLayout, 103 VkPipeline, 104 bool ownsPipelineLayout, 105 skia_private::TArray<sk_sp<VulkanSampler>> immutableSamplers); 106 107 void freeGpuData() override; 108 109 VkPipelineLayout fPipelineLayout = VK_NULL_HANDLE; 110 VkPipeline fPipeline = VK_NULL_HANDLE; 111 bool fOwnsPipelineLayout = true; 112 113 // Hold a ref to immutable samplers used such that their lifetime is properly managed. 114 const skia_private::TArray<sk_sp<VulkanSampler>> fImmutableSamplers; 115 }; 116 117 } // namespace skgpu::graphite 118 119 #endif // skgpu_graphite_MtlGraphicsPipeline_DEFINED 120