Debian Codegraph @

src/gpu/graphite/vk/VulkanResourceProvider.h

raw
1 /*
2 * Copyright 2022 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_VulkanResourceProvider_DEFINED
9 #define skgpu_graphite_VulkanResourceProvider_DEFINED
10
11 #include "src/gpu/graphite/ResourceProvider.h"
12 #include "src/gpu/graphite/vk/VulkanGraphicsPipeline.h"
13
14 #include "include/gpu/vk/VulkanTypes.h"
15 #include "src/core/SkLRUCache.h"
16 #include "src/core/SkTHash.h"
17 #include "src/gpu/graphite/DescriptorData.h"
18 #include "src/gpu/graphite/vk/VulkanRenderPass.h"
19
20 #ifdef SK_BUILD_FOR_ANDROID
21 extern "C" {
22 typedef struct AHardwareBuffer AHardwareBuffer;
23 }
24 #endif
25
26 namespace skgpu::graphite {
27
28 class VulkanCommandBuffer;
29 class VulkanDescriptorSet;
30 class VulkanFramebuffer;
31 class VulkanGraphicsPipeline;
32 class VulkanSharedContext;
33 class VulkanTexture;
34 class VulkanYcbcrConversion;
35
36 class VulkanResourceProvider final : public ResourceProvider {
37 public:
38 static constexpr size_t kIntrinsicConstantSize = sizeof(float) * 8; // float4 + 2xfloat2
39 // Intrinsic constant rtAdjust value is needed by the vertex shader. Dst copy bounds are needed
40 // in the frag shader.
41 static constexpr VkShaderStageFlagBits kIntrinsicConstantStageFlags =
42 VkShaderStageFlagBits(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT);
43
44 static constexpr size_t kLoadMSAAPushConstantSize = sizeof(float) * 4;
45 static constexpr VkShaderStageFlagBits kLoadMSAAPushConstantStageFlags =
46 VK_SHADER_STAGE_VERTEX_BIT;
47
48
49 using UniformBindGroupKey = FixedSizeKey<2 * VulkanGraphicsPipeline::kNumUniformBuffers>;
50
51 VulkanResourceProvider(SharedContext* sharedContext,
52 SingleOwner*,
53 uint32_t recorderID,
54 size_t resourceBudget);
55
56 ~VulkanResourceProvider() override;
57
58 sk_sp<VulkanYcbcrConversion> findOrCreateCompatibleYcbcrConversion(
59 const VulkanYcbcrConversionInfo& ycbcrInfo) const;
60
61 sk_sp<VulkanDescriptorSet> findOrCreateDescriptorSet(SkSpan<DescriptorData>);
62
63 sk_sp<VulkanDescriptorSet> findOrCreateUniformBuffersDescriptorSet(
64 SkSpan<DescriptorData> requestedDescriptors,
65 SkSpan<BindBufferInfo> bindUniformBufferInfo);
66
67 sk_sp<VulkanGraphicsPipeline> findOrCreateLoadMSAAPipeline(const RenderPassDesc&);
68
69 // Find or create a compatible (needed when creating a framebuffer and graphics pipeline) or
70 // full (needed when beginning a render pass from the command buffer) RenderPass.
71 sk_sp<VulkanRenderPass> findOrCreateRenderPass(const RenderPassDesc&, bool compatibleOnly);
72
73 VkPipelineLayout mockPipelineLayout() const { return fMockPipelineLayout; }
74
75 sk_sp<VulkanFramebuffer> findOrCreateFramebuffer(const VulkanSharedContext*,
76 VulkanTexture* colorTexture,
77 VulkanTexture* resolveTexture,
78 VulkanTexture* depthStencilTexture,
79 const RenderPassDesc&,
80 const VulkanRenderPass&,
81 const int width,
82 const int height);
83
84 private:
85 const VulkanSharedContext* vulkanSharedContext() const;
86 // VulkanSharedContext::pipelineCompileWasRequired() - which drives PipelineCache persistence
87 // - modifies the SharedContext so, when creating Pipelines, the ResourceProvider must
88 // provide a non-const SharedContext.
89 VulkanSharedContext* nonConstVulkanSharedContext();
90
91 sk_sp<ComputePipeline> createComputePipeline(const ComputePipelineDesc&) override;
92
93 sk_sp<Texture> createTexture(SkISize, const TextureInfo&) override;
94 sk_sp<Texture> onCreateWrappedTexture(const BackendTexture&) override;
95 sk_sp<Buffer> createBuffer(size_t size, BufferType type, AccessPattern) override;
96 sk_sp<Sampler> createSampler(const SamplerDesc&) override;
97
98 BackendTexture onCreateBackendTexture(SkISize dimensions, const TextureInfo&) override;
99 #ifdef SK_BUILD_FOR_ANDROID
100 BackendTexture onCreateBackendTexture(AHardwareBuffer*,
101 bool isRenderable,
102 bool isProtectedContent,
103 SkISize dimensions,
104 bool fromAndroidWindow) const override;
105 #endif
106 void onDeleteBackendTexture(const BackendTexture&) override;
107
108 // Certain operations only need to occur once per renderpass (updating push constants and, if
109 // necessary, binding the dst texture as an input attachment). It is useful to have a
110 // mock pipeline layout that has compatible push constant parameters and input attachment
111 // descriptor set with all other real pipeline layouts such that it can be reused across command
112 // buffers to perform these operations even before we bind any pipelines.
113 VkPipelineLayout fMockPipelineLayout;
114
115 // The first value of the pair is a hash of the render pass excluding state that make the render
116 // pass compatible, as calcualted by VulkanCaps::GetRenderPassDescKeyForPipeline.
117 skia_private::TArray<std::pair<uint32_t, sk_sp<VulkanGraphicsPipeline>>> fLoadMSAAPipelines;
118 // The shader modules and pipeline layout can be shared for all loadMSAA pipelines.
119 std::unique_ptr<VulkanProgramInfo> fLoadMSAAProgram;
120
121 SkLRUCache<UniformBindGroupKey, sk_sp<VulkanDescriptorSet>,
122 UniformBindGroupKey::Hash> fUniformBufferDescSetCache;
123 };
124
125 } // namespace skgpu::graphite
126
127 #endif // skgpu_graphite_VulkanResourceProvider_DEFINED