Flutter Engine
The Flutter Engine
VulkanResourceProvider.h
Go to the documentation of this file.
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
12
14#include "src/core/SkLRUCache.h"
15#include "src/core/SkTHash.h"
17
18#ifdef SK_BUILD_FOR_ANDROID
19extern "C" {
20 typedef struct AHardwareBuffer AHardwareBuffer;
21}
22#endif
23
24namespace skgpu::graphite {
25
26class VulkanCommandBuffer;
27class VulkanDescriptorSet;
28class VulkanFramebuffer;
29class VulkanGraphicsPipeline;
30class VulkanRenderPass;
31class VulkanSharedContext;
32class VulkanYcbcrConversion;
33
35public:
36 static constexpr size_t kIntrinsicConstantSize = sizeof(float) * 4;
37 static constexpr size_t kLoadMSAAVertexBufferSize = sizeof(float) * 8; // 4 points of 2 floats
38
41 uint32_t recorderID,
42 size_t resourceBudget,
43 sk_sp<Buffer> intrinsicConstantUniformBuffer,
45
46 ~VulkanResourceProvider() override;
47
49
50 const Buffer* loadMSAAVertexBuffer() const;
51
53 const VulkanYcbcrConversionInfo& ycbcrInfo) const;
54
55private:
56 const VulkanSharedContext* vulkanSharedContext() const;
57
58 sk_sp<GraphicsPipeline> createGraphicsPipeline(const RuntimeEffectDictionary*,
60 const RenderPassDesc&) override;
61 sk_sp<ComputePipeline> createComputePipeline(const ComputePipelineDesc&) override;
62
63 sk_sp<Texture> createTexture(SkISize,
64 const TextureInfo&,
65 skgpu::Budgeted) override;
66 sk_sp<Texture> onCreateWrappedTexture(const BackendTexture&) override;
67 sk_sp<Buffer> createBuffer(size_t size, BufferType type, AccessPattern) override;
68 sk_sp<Sampler> createSampler(const SamplerDesc&) override;
69
70 sk_sp<VulkanFramebuffer> createFramebuffer(
72 const skia_private::TArray<VkImageView>& attachmentViews,
73 const VulkanRenderPass&,
74 const int width,
75 const int height);
76
77 BackendTexture onCreateBackendTexture(SkISize dimensions, const TextureInfo&) override;
78#ifdef SK_BUILD_FOR_ANDROID
79 BackendTexture onCreateBackendTexture(AHardwareBuffer*,
80 bool isRenderable,
81 bool isProtectedContent,
82 SkISize dimensions,
83 bool fromAndroidWindow) const override;
84#endif
85 void onDeleteBackendTexture(const BackendTexture&) override;
86
87 sk_sp<VulkanDescriptorSet> findOrCreateDescriptorSet(SkSpan<DescriptorData>);
88
89 sk_sp<VulkanDescriptorSet> findOrCreateUniformBuffersDescriptorSet(
90 SkSpan<DescriptorData> requestedDescriptors,
91 SkSpan<BindUniformBufferInfo> bindUniformBufferInfo);
92
93 sk_sp<VulkanGraphicsPipeline> findOrCreateLoadMSAAPipeline(const RenderPassDesc&);
94
95 // Find or create a compatible (needed when creating a framebuffer and graphics pipeline) or
96 // full (needed when beginning a render pass from the command buffer) RenderPass.
97 sk_sp<VulkanRenderPass> findOrCreateRenderPass(const RenderPassDesc&, bool compatibleOnly);
98
99 // Use a predetermined RenderPass key for finding/creating a RenderPass to avoid recreating it
100 sk_sp<VulkanRenderPass> findOrCreateRenderPassWithKnownKey(
101 const RenderPassDesc&, bool compatibleOnly, const GraphiteResourceKey& rpKey);
102
103 VkPipelineCache pipelineCache();
104
106 VkPipelineCache fPipelineCache = VK_NULL_HANDLE;
107
108 // Each render pass will need buffer space to record rtAdjust information. To minimize costly
109 // allocation calls and searching of the resource cache, we find & store a uniform buffer upon
110 // resource provider creation. This way, render passes across all command buffers can simply
111 // update the value within this buffer as needed.
112 sk_sp<Buffer> fIntrinsicUniformBuffer;
113 // Similary, use a shared buffer b/w all renderpasses to store vertices for loading MSAA from
114 // resolve.
115 sk_sp<Buffer> fLoadMSAAVertexBuffer;
116
117 // The first value of the pair is a renderpass key. Graphics pipeline keys contain extra
118 // information that we do not need for identifying unique pipelines.
120 sk_sp<VulkanGraphicsPipeline>>> fLoadMSAAPipelines;
121 // All of the following attributes are the same between all msaa load pipelines, so they only
122 // need to be created once and can then be stored.
123 VkShaderModule fMSAALoadVertShaderModule = VK_NULL_HANDLE;
124 VkShaderModule fMSAALoadFragShaderModule = VK_NULL_HANDLE;
125 VkPipelineShaderStageCreateInfo fMSAALoadShaderStageInfo[2];
126 VkPipelineLayout fMSAALoadPipelineLayout = VK_NULL_HANDLE;
127
128 struct UniqueKeyHash {
129 uint32_t operator()(const skgpu::UniqueKey& key) const { return key.hash(); }
130 };
131 using DescriptorSetCache = SkLRUCache<UniqueKey, sk_sp<VulkanDescriptorSet>, UniqueKeyHash>;
132 DescriptorSetCache fUniformBufferDescSetCache;
133};
134
135} // namespace skgpu::graphite
136
137#endif // skgpu_graphite_VulkanResourceProvider_DEFINED
struct AHardwareBuffer AHardwareBuffer
GLenum type
sk_sp< VulkanYcbcrConversion > findOrCreateCompatibleYcbcrConversion(const VulkanYcbcrConversionInfo &ycbcrInfo) const
VulkanResourceProvider(SharedContext *sharedContext, SingleOwner *, uint32_t recorderID, size_t resourceBudget, sk_sp< Buffer > intrinsicConstantUniformBuffer, sk_sp< Buffer > loadMSAAVertexBuffer)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Budgeted
Definition: GpuTypes.h:35
int32_t height
int32_t width
Definition: SkSize.h:16
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46