Debian Codegraph @

src/gpu/graphite/ResourceProvider.h

raw
1 /*
2 * Copyright 2021 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_ResourceProvider_DEFINED
9 #define skgpu_graphite_ResourceProvider_DEFINED
10
11 #include "include/core/SkSize.h"
12 #include "include/core/SkTileMode.h"
13 #include "src/core/SkLRUCache.h"
14 #include "src/gpu/ResourceKey.h"
15 #include "src/gpu/graphite/CommandBuffer.h"
16 #include "src/gpu/graphite/GraphicsPipeline.h"
17 #include "src/gpu/graphite/ResourceCache.h"
18 #include "src/gpu/graphite/ResourceTypes.h"
19
20 struct AHardwareBuffer;
21 struct SkSamplingOptions;
22 class SkTraceMemoryDump;
23
24 namespace skgpu {
25 class SingleOwner;
26 }
27
28 namespace SkSL {
29 class Compiler;
30 }
31
32 namespace skgpu::graphite {
33
34 class BackendTexture;
35 class Buffer;
36 class Caps;
37 class ComputePipeline;
38 class ComputePipelineDesc;
39 class GlobalCache;
40 class GraphicsPipelineDesc;
41 class GraphicsPipelineHandle;
42 class GraphiteResourceKey;
43 class ResourceCache;
44 class RuntimeEffectDictionary;
45 class ShaderCodeDictionary;
46 class Sampler;
47 class SharedContext;
48 class Texture;
49 class TextureInfo;
50
51 class ResourceProvider {
52 public:
53 virtual ~ResourceProvider();
54
55 GraphicsPipelineHandle createGraphicsPipelineHandle(
56 const GraphicsPipelineDesc&,
57 const RenderPassDesc&,
58 SkEnumBitMask<PipelineCreationFlags>);
59 void startPipelineCreationTask(sk_sp<const RuntimeEffectDictionary>,
60 const GraphicsPipelineHandle&);
61 sk_sp<GraphicsPipeline> resolveHandle(const GraphicsPipelineHandle&);
62
63 sk_sp<ComputePipeline> findOrCreateComputePipeline(const ComputePipelineDesc&);
64
65 sk_sp<Texture> findOrCreateShareableTexture(SkISize,
66 const TextureInfo&,
67 std::string_view label);
68
69 sk_sp<Texture> findOrCreateNonShareableTexture(SkISize,
70 const TextureInfo&,
71 std::string_view label,
72 Budgeted);
73 sk_sp<Texture> findOrCreateScratchTexture(SkISize,
74 const TextureInfo&,
75 std::string_view label,
76 const ResourceCache::ScratchResourceSet& unavailable);
77
78 sk_sp<Texture> createWrappedTexture(const BackendTexture&, std::string_view label);
79
80 sk_sp<Buffer> findOrCreateNonShareableBuffer(size_t size,
81 BufferType type,
82 AccessPattern,
83 std::string_view label);
84 sk_sp<Buffer> findOrCreateScratchBuffer(size_t size,
85 BufferType type,
86 AccessPattern,
87 std::string_view label,
88 const ResourceCache::ScratchResourceSet& unavailable);
89
90
91 sk_sp<Sampler> findOrCreateCompatibleSampler(const SamplerDesc&);
92
93 BackendTexture createBackendTexture(SkISize dimensions, const TextureInfo&);
94 void deleteBackendTexture(const BackendTexture&);
95
96 ProxyCache* proxyCache() { return fResourceCache->proxyCache(); }
97
98 void setResourceCacheLimit(size_t bytes) { return fResourceCache->setMaxBudget(bytes); }
99 size_t getResourceCacheLimit() const { return fResourceCache->getMaxBudget(); }
100 size_t getResourceCacheCurrentBudgetedBytes() const {
101 return fResourceCache->currentBudgetedBytes();
102 }
103 size_t getResourceCacheCurrentPurgeableBytes() const {
104 return fResourceCache->currentPurgeableBytes();
105 }
106
107 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
108 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
109 }
110
111 void freeGpuResources();
112 void purgeResourcesNotUsedSince(StdSteadyClock::time_point purgeTime);
113 void forceProcessReturnedResources() { fResourceCache->forceProcessReturnedResources(); }
114
115 #if defined(GPU_TEST_UTILS)
116 ResourceCache* resourceCache() { return fResourceCache.get(); }
117 const SharedContext* sharedContext() { return fSharedContext; }
118 #endif
119
120 const Caps* caps() const;
121
122 #ifdef SK_BUILD_FOR_ANDROID
123 virtual BackendTexture createBackendTexture(AHardwareBuffer*,
124 bool isRenderable,
125 bool isProtectedContent,
126 SkISize dimensions,
127 bool fromAndroidWindow) const;
128 #endif
129
130 protected:
131 ResourceProvider(SharedContext* sharedContext,
132 SingleOwner* singleOwner,
133 uint32_t recorderID,
134 size_t resourceBudget);
135
136 SharedContext* fSharedContext;
137 // Each ResourceProvider owns one local cache; for some resources it also refers out to the
138 // global cache of the SharedContext, which is assumed to outlive the ResourceProvider.
139 sk_sp<ResourceCache> fResourceCache;
140
141 private:
142 virtual sk_sp<ComputePipeline> createComputePipeline(const ComputePipelineDesc&) = 0;
143 virtual sk_sp<Texture> createTexture(SkISize, const TextureInfo&) = 0;
144 virtual sk_sp<Buffer> createBuffer(size_t size, BufferType type, AccessPattern) = 0;
145 virtual sk_sp<Sampler> createSampler(const SamplerDesc&) = 0;
146
147 sk_sp<Texture> findOrCreateTexture(SkISize dimensions,
148 const TextureInfo& info,
149 std::string_view label,
150 Budgeted,
151 Shareable,
152 const ResourceCache::ScratchResourceSet* = nullptr);
153
154 sk_sp<Buffer> findOrCreateBuffer(size_t size,
155 BufferType type,
156 AccessPattern,
157 std::string_view label,
158 Shareable,
159 const ResourceCache::ScratchResourceSet* = nullptr);
160
161 virtual sk_sp<Texture> onCreateWrappedTexture(const BackendTexture&) = 0;
162
163 virtual BackendTexture onCreateBackendTexture(SkISize dimensions, const TextureInfo&) = 0;
164 #ifdef SK_BUILD_FOR_ANDROID
165 virtual BackendTexture onCreateBackendTexture(AHardwareBuffer*,
166 bool isRenderable,
167 bool isProtectedContent,
168 SkISize dimensions,
169 bool fromAndroidWindow) const;
170 #endif
171 virtual void onDeleteBackendTexture(const BackendTexture&) = 0;
172
173 virtual void onFreeGpuResources() {}
174 virtual void onPurgeResourcesNotUsedSince(StdSteadyClock::time_point purgeTime) {}
175 };
176
177 } // namespace skgpu::graphite
178
179 #endif // skgpu_graphite_ResourceProvider_DEFINED