Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
#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
virtual std::string computeSkSL() const
virtual WorkgroupSize calculateGlobalDispatchSize() const
virtual void prepareStorageBuffer(int resourceIndex, const ResourceDesc &resource, void *buffer, size_t bufferSize) const
virtual std::tuple< SkISize, SkColorType > calculateTextureParameters(int resourceIndex, const ResourceDesc &) const
ComputeStep(std::string_view name, WorkgroupSize localDispatchSize, SkSpan< const ResourceDesc > resources, SkSpan< const WorkgroupBufferDesc > workgroupBuffers={}, Flags baseFlags=Flags::kNone)
virtual NativeShaderSource nativeShaderSource(NativeShaderFormat) const
virtual void prepareUniformBuffer(int resourceIndex, const ResourceDesc &, UniformManager *) const
virtual size_t calculateBufferSize(int resourceIndex, const ResourceDesc &) const
const char * name
Definition fuchsia.cc:50
constexpr int kMaxComputeDataFlowSlots
static uint32_t next_id()
Definition DrawAtlas.cpp:69
static constexpr SkISize MakeEmpty()
Definition SkSize.h:22