Debian Codegraph @

src/gpu/graphite/dawn/DawnResourceProvider.h

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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 the cached bind group or create a new one based on the bound buffers and their
69 // binding sizes (boundBuffersAndSizes) for these uniforms (in order):
70 // - Intrinsic constants.
71 // - Render step uniforms.
72 // - Paint uniforms.
73 const wgpu::BindGroup& findOrCreateUniformBuffersBindGroup(
74 const std::array<std::pair<const DawnBuffer*, uint32_t>, kNumUniformEntries>&
75 boundBuffersAndSizes);
76
77 // Find or create a bind group containing the given sampler & texture.
78 const wgpu::BindGroup& findOrCreateSingleTextureSamplerBindGroup(const DawnSampler* sampler,
79 const DawnTexture* texture);
80
81 // Find the cached bind buffer info, or create a new one for the given intrinsic values.
82 BindBufferInfo findOrCreateIntrinsicBindBufferInfo(DawnCommandBuffer* cb,
83 UniformDataBlock intrinsicValues);
84
85 private:
86 sk_sp<ComputePipeline> createComputePipeline(const ComputePipelineDesc&) override;
87
88 sk_sp<Texture> createTexture(SkISize, const TextureInfo&) override;
89 sk_sp<Buffer> createBuffer(size_t size, BufferType type, AccessPattern) override;
90
91 sk_sp<Texture> onCreateWrappedTexture(const BackendTexture&) override;
92
93 sk_sp<Sampler> createSampler(const SamplerDesc&) override;
94
95 BackendTexture onCreateBackendTexture(SkISize dimensions, const TextureInfo&) override;
96 void onDeleteBackendTexture(const BackendTexture&) override;
97
98 const wgpu::Buffer& getOrCreateNullBuffer();
99
100 DawnSharedContext* dawnSharedContext() const;
101
102 void onFreeGpuResources() override;
103 void onPurgeResourcesNotUsedSince(StdSteadyClock::time_point purgeTime) override;
104
105 skia_private::THashMap<uint32_t, wgpu::RenderPipeline> fBlitWithDrawPipelines;
106
107 wgpu::Buffer fNullBuffer;
108
109 template <size_t NumEntries>
110 using BindGroupCache = SkLRUCache<BindGroupKey<NumEntries>,
111 wgpu::BindGroup,
112 typename BindGroupKey<NumEntries>::Hash>;
113
114 BindGroupCache<kNumUniformEntries> fUniformBufferBindGroupCache;
115 BindGroupCache<1> fSingleTextureSamplerBindGroups;
116
117 class IntrinsicBuffer;
118 class IntrinsicConstantsManager;
119 std::unique_ptr<IntrinsicConstantsManager> fIntrinsicConstantsManager;
120
121 SingleOwner* fSingleOwner = nullptr;
122 };
123
124 } // namespace skgpu::graphite
125
126 #endif // skgpu_graphite_DawnResourceProvider_DEFINED