Flutter Engine
The Flutter Engine
DawnSharedContext.cpp
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
9
14
15namespace skgpu::graphite {
16namespace {
17
18wgpu::ShaderModule CreateNoopFragment(const wgpu::Device& device) {
19 wgpu::ShaderModuleWGSLDescriptor wgslDesc;
20 wgslDesc.code =
21 "@fragment\n"
22 "fn main() {}\n";
23 wgpu::ShaderModuleDescriptor smDesc;
24 smDesc.nextInChain = &wgslDesc;
25 smDesc.label = "no-op";
26 auto fsModule = device.CreateShaderModule(&smDesc);
27 return fsModule;
28}
29
30}
31
33 const ContextOptions& options) {
34 if (!backendContext.fDevice || !backendContext.fQueue) {
35 return {};
36 }
37
38 auto noopFragment = CreateNoopFragment(backendContext.fDevice);
39 if (!noopFragment) {
40 return {};
41 }
42
43 auto caps = std::make_unique<const DawnCaps>(backendContext, options);
44
45 return sk_sp<SharedContext>(new DawnSharedContext(backendContext,
46 std::move(caps),
47 std::move(noopFragment)));
48}
49
50DawnSharedContext::DawnSharedContext(const DawnBackendContext& backendContext,
51 std::unique_ptr<const DawnCaps> caps,
52 wgpu::ShaderModule noopFragment)
53 : skgpu::graphite::SharedContext(std::move(caps), BackendApi::kDawn)
54 , fInstance(backendContext.fInstance)
55 , fDevice(backendContext.fDevice)
56 , fQueue(backendContext.fQueue)
57 , fTick(backendContext.fTick)
58 , fNoopFragment(std::move(noopFragment)) {}
59
61 // need to clear out resources before any allocator is removed
63}
64
65std::unique_ptr<ResourceProvider> DawnSharedContext::makeResourceProvider(
66 SingleOwner* singleOwner,
67 uint32_t recorderID,
68 size_t resourceBudget) {
69 return std::unique_ptr<ResourceProvider>(new DawnResourceProvider(this,
70 singleOwner,
71 recorderID,
72 resourceBudget));
73}
74
75} // namespace skgpu::graphite
const char * options
const wgpu::ShaderModule & noopFragment() const
std::unique_ptr< ResourceProvider > makeResourceProvider(SingleOwner *, uint32_t recorderID, size_t resourceBudget) override
static sk_sp< SharedContext > Make(const DawnBackendContext &, const ContextOptions &)
const Caps * caps() const
Definition: SharedContext.h:39
VkDevice device
Definition: main.cc:53
Definition: GpuTools.h:21
BackendApi
Definition: GpuTypes.h:22
Definition: ref_ptr.h:256