Debian Codegraph @

src/gpu/graphite/dawn/DawnResourceProvider.h

raw ◀ ▶
1 Debian patch touch 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_DawnResourceProvider_DEFINED
9 #define skgpu_graphite_DawnResourceProvider_DEFINED
10
11 #include "include/gpu/graphite/dawn/DawnGraphiteTypes.h"
12 #include "src/core/SkLRUCache.h"
13 #include "src/core/SkTHash.h"
14 #include "src/gpu/graphite/PipelineData.h"
15 #include "src/gpu/graphite/ResourceProvider.h"
16
17 namespace skgpu::graphite {
18
19 class DawnGraphicsPipeline;
20 class DawnSampler;
21 class DawnSharedContext;
22 class DawnTexture;
23 class DawnBuffer;
24 class DawnCommandBuffer;
25
26 class DawnResourceProvider final : public ResourceProvider {
27 public:
28 template <size_t NumEntries>
29 using BindGroupKey = FixedSizeKey<2 * NumEntries>;
30
31 static constexpr size_t kNumUniformEntries = 3;
32
33 class BlitWithDrawEncoder {
34 public:
35 BlitWithDrawEncoder(wgpu::RenderPipeline pipeline,
36 bool srcIsMSAA);
37
38 operator bool() const { return fPipeline != nullptr; }
39
40 void EncodeBlit(const wgpu::Device& device,
41 const wgpu::RenderPassEncoder& encoder,
42 const wgpu::TextureView& srcTextureView,
43 const SkIPoint& srcOffset,
44 const SkIRect& dstBounds);
45
46 private:
47 wgpu::RenderPipeline fPipeline;
48 const bool fSrcIsMSAA;
49 };
50
51 DawnResourceProvider(SharedContext* sharedContext,
52 SingleOwner*,
53 uint32_t recorderID,
54 size_t resourceBudget);
55 ~DawnResourceProvider() override;
56
57 sk_sp<DawnTexture> findOrCreateDiscardableMSAALoadTexture(SkISize dimensions,
58 const TextureInfo& msaaInfo);
59
60 BlitWithDrawEncoder findOrCreateBlitWithDrawEncoder(const RenderPassDesc& renderPassDesc,
61 SampleCount srcSampleCount);
62
63 sk_sp<DawnBuffer> findOrCreateDawnBuffer(size_t size,
64 BufferType type,
65 AccessPattern,
66 std::string_view label);
67
•68 // Find or create a bind group containing the given buffer.
69 wgpu::BindGroup findOrCreateSingleUniformBindGroup(const BindBufferInfo&);
70
71 // Find or create a bind group containing the given sampler & texture.
72 const wgpu::BindGroup& findOrCreateSingleTextureSamplerBindGroup(const DawnSampler* sampler,
73 const DawnTexture* texture);
74
75 // Find the cached bind buffer info, or create a new one for the given intrinsic values.
76 BindBufferInfo findOrCreateIntrinsicBindBufferInfo(DawnCommandBuffer* cb,
77 UniformDataBlock intrinsicValues);
78
•79 // For BindGroupEntries, using this method to get a null buffer pointer rather than simply using
80 // nullptr allows for assigning a label (when enabled in Caps) for more clear debugging.
81 const wgpu::Buffer& getOrCreateNullBuffer();
82
83 private:
84 sk_sp<ComputePipeline> createComputePipeline(const ComputePipelineDesc&) override;
85
86 sk_sp<Texture> createTexture(SkISize, const TextureInfo&) override;
87 sk_sp<Buffer> createBuffer(size_t size, BufferType type, AccessPattern) override;
88
89 sk_sp<Texture> onCreateWrappedTexture(const BackendTexture&) override;
90
91 sk_sp<Sampler> createSampler(const SamplerDesc&) override;
92
93 BackendTexture onCreateBackendTexture(SkISize dimensions, const TextureInfo&) override;
94 void onDeleteBackendTexture(const BackendTexture&) override;
95
96 DawnSharedContext* dawnSharedContext() const;
97
98 void onFreeGpuResources() override;
99 void onPurgeResourcesNotUsedSince(StdSteadyClock::time_point purgeTime) override;
100
101 skia_private::THashMap<uint32_t, wgpu::RenderPipeline> fBlitWithDrawPipelines;
102
103 wgpu::Buffer fNullBuffer;
104
105 template <size_t NumEntries>
106 using BindGroupCache = SkLRUCache<BindGroupKey<NumEntries>,
107 wgpu::BindGroup,
108 typename BindGroupKey<NumEntries>::Hash>;
109
110 BindGroupCache<1> fSingleTextureSamplerBindGroups;
111
112 class IntrinsicBuffer;
113 class IntrinsicConstantsManager;
114 std::unique_ptr<IntrinsicConstantsManager> fIntrinsicConstantsManager;
115
116 SingleOwner* fSingleOwner = nullptr;
117 };
118
119 } // namespace skgpu::graphite
120
121 #endif // skgpu_graphite_DawnResourceProvider_DEFINED