Debian Codegraph @

src/gpu/graphite/dawn/DawnSharedContext.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_DawnSharedContext_DEFINED
9 #define skgpu_graphite_DawnSharedContext_DEFINED
10
11 #include "src/gpu/graphite/SharedContext.h"
12
13 #include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
14
15 #include "include/gpu/graphite/dawn/DawnBackendContext.h"
16 #include "src/gpu/graphite/ThreadSafeResourceProvider.h"
17 #include "src/gpu/graphite/dawn/DawnCaps.h"
18
19 namespace skgpu::graphite {
20
21 struct ContextOptions;
22 struct DawnBackendContext;
23
24 class DawnThreadSafeResourceProvider final : public ThreadSafeResourceProvider {
25 public:
26 DawnThreadSafeResourceProvider(std::unique_ptr<ResourceProvider>);
27 };
28
29 class DawnSharedContext final : public SharedContext {
30 public:
31 static sk_sp<SharedContext> Make(const DawnBackendContext&, const ContextOptions&);
32 ~DawnSharedContext() override;
33
34 DawnThreadSafeResourceProvider* threadSafeResourceProvider() const;
35
36 std::unique_ptr<ResourceProvider> makeResourceProvider(SingleOwner*,
37 uint32_t recorderID,
38 size_t resourceBudget) override;
39
40 const DawnCaps* dawnCaps() const { return static_cast<const DawnCaps*>(this->caps()); }
41 const wgpu::Device& device() const { return fDevice; }
42 const wgpu::Queue& queue() const { return fQueue; }
43 const wgpu::Instance& instance() const { return fInstance; }
44 const wgpu::ShaderModule& noopFragment() const { return fNoopFragment; }
45
46 bool hasTick() const { return fTick; }
47
48 void tick() const {
49 SkASSERT(this->hasTick());
50 fTick(fInstance);
51 }
52
53 void deviceTick(Context*) override;
54
55 const wgpu::BindGroupLayout& getUniformBuffersBindGroupLayout() const {
56 return fUniformBuffersBindGroupLayout;
57 }
58 const wgpu::BindGroupLayout& getSingleTextureSamplerBindGroupLayout() const {
59 return fSingleTextureSamplerBindGroupLayout;
60 }
61
62 private:
63 DawnSharedContext(const DawnBackendContext&,
64 std::unique_ptr<const DawnCaps>,
65 wgpu::ShaderModule noopFragment,
66 SkExecutor*,
67 SkSpan<sk_sp<SkRuntimeEffect>> userDefinedKnownRuntimeEffects);
68
69 void createUniformBuffersBindGroupLayout();
70 void createSingleTextureSamplerBindGroupLayout();
71
72 sk_sp<GraphicsPipeline> createGraphicsPipeline(const RuntimeEffectDictionary*,
73 const UniqueKey&,
74 const GraphicsPipelineDesc&,
75 const RenderPassDesc&,
76 SkEnumBitMask<PipelineCreationFlags>,
77 uint32_t compilationID) override;
78
79 wgpu::Instance fInstance;
80 wgpu::Device fDevice;
81 wgpu::Queue fQueue;
82 DawnTickFunction* fTick;
83 // A noop fragment shader, it is used to workaround dawn a validation error(dawn doesn't allow
84 // a pipeline with a color attachment but without a fragment shader).
85 wgpu::ShaderModule fNoopFragment;
86
87 wgpu::BindGroupLayout fUniformBuffersBindGroupLayout;
88 wgpu::BindGroupLayout fSingleTextureSamplerBindGroupLayout;
89 };
90
91 } // namespace skgpu::graphite
92
93 #endif // skgpu_graphite_DawnSharedContext_DEFINED