Flutter Engine
The Flutter Engine
ComputeStep.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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
11
12#include <atomic>
13#include <unordered_set>
14
15namespace skgpu::graphite {
16namespace {
17
18static uint32_t next_id() {
19 static std::atomic<uint32_t> nextId{0};
20 // Not worried about overflow since a Context isn't expected to have that many ComputeSteps.
21 // Even if this it wraps around to 0, that ComputeStep will not be in the same Context as the
22 // original 0.
23 return nextId.fetch_add(1, std::memory_order_relaxed);
24}
25
26} // namespace
27
29 WorkgroupSize localDispatchSize,
31 SkSpan<const WorkgroupBufferDesc> workgroupBuffers,
32 Flags baseFlags)
33 : fUniqueID(next_id())
34 , fFlags(baseFlags)
35 , fName(name)
36 , fResources(resources.data(), resources.size())
37 , fWorkgroupBuffers(workgroupBuffers.data(), workgroupBuffers.size())
38 , fLocalDispatchSize(localDispatchSize) {
39#ifdef SK_DEBUG
40 std::unordered_set<int> slots;
41 for (const ResourceDesc& r : fResources) {
42 // Validate that slot assignments within a ComputeStep are unique.
43 if (r.fFlow == DataFlow::kShared) {
44 SkASSERT(r.fSlot > -1);
46 auto [_, inserted] = slots.insert(r.fSlot);
47 SkASSERT(inserted);
48 }
49 }
50#endif // SK_DEBUG
51}
52
53void ComputeStep::prepareStorageBuffer(int, const ResourceDesc&, void*, size_t) const {
54 SK_ABORT("ComputeSteps that initialize a mapped storage buffer must override "
55 "prepareStorageBuffer()");
56}
57
59 SK_ABORT("ComputeSteps that initialize a uniform buffer must override prepareUniformBuffer()");
60}
61
62std::string ComputeStep::computeSkSL() const {
63 SK_ABORT("ComputeSteps must override computeSkSL() unless they support native shader source");
64 return "";
65}
66
68 SK_ABORT("ComputeSteps that support native shader source must override nativeShaderSource()");
69 return {};
70}
71
73 SK_ABORT("ComputeSteps that initialize a storage buffer must override calculateBufferSize()");
74 return 0u;
75}
76
77std::tuple<SkISize, SkColorType> ComputeStep::calculateTextureParameters(
78 int, const ResourceDesc&) const {
79 SK_ABORT("ComputeSteps that initialize a texture must override calculateTextureParameters()");
81}
82
84 SK_ABORT("ComputeSteps that initialize a sampler must override calculateSamplerParameters()");
85 constexpr SkTileMode kTileModes[2] = {SkTileMode::kClamp, SkTileMode::kClamp};
86 return {{}, kTileModes};
87}
88
90 SK_ABORT("ComputeSteps must override calculateGlobalDispatchSize() unless "
91 "the workgroup count is determined out-of-band");
92 return WorkgroupSize();
93}
94
95} // namespace skgpu::graphite
const char * fName
uint16_t fFlags
Definition: ShapeLayer.cpp:106
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
SkTileMode
Definition: SkTileMode.h:13
virtual SamplerDesc calculateSamplerParameters(int resourceIndex, const ResourceDesc &) const
Definition: ComputeStep.cpp:83
virtual std::string computeSkSL() const
Definition: ComputeStep.cpp:62
virtual WorkgroupSize calculateGlobalDispatchSize() const
Definition: ComputeStep.cpp:89
virtual void prepareStorageBuffer(int resourceIndex, const ResourceDesc &resource, void *buffer, size_t bufferSize) const
Definition: ComputeStep.cpp:53
virtual std::tuple< SkISize, SkColorType > calculateTextureParameters(int resourceIndex, const ResourceDesc &) const
Definition: ComputeStep.cpp:77
ComputeStep(std::string_view name, WorkgroupSize localDispatchSize, SkSpan< const ResourceDesc > resources, SkSpan< const WorkgroupBufferDesc > workgroupBuffers={}, Flags baseFlags=Flags::kNone)
Definition: ComputeStep.cpp:28
virtual NativeShaderSource nativeShaderSource(NativeShaderFormat) const
Definition: ComputeStep.cpp:67
virtual void prepareUniformBuffer(int resourceIndex, const ResourceDesc &, UniformManager *) const
Definition: ComputeStep.cpp:58
virtual size_t calculateBufferSize(int resourceIndex, const ResourceDesc &) const
Definition: ComputeStep.cpp:72
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
constexpr int kMaxComputeDataFlowSlots
Definition: ComputeTypes.h:16
static uint32_t next_id()
Definition: DrawAtlas.cpp:70
static constexpr SkISize MakeEmpty()
Definition: SkSize.h:22
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63