Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PipelineData.h
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
8#ifndef skgpu_graphite_PipelineData_DEFINED
9#define skgpu_graphite_PipelineData_DEFINED
10
11#include <vector>
12#include "include/core/SkM44.h"
16#include "include/core/SkSpan.h"
23
24class SkArenaAlloc;
25
26namespace skgpu::graphite {
27
28class Uniform;
29
31public:
33
35 UniformDataBlock() = default;
36
37 const char* data() const { return fData.data(); }
38 size_t size() const { return fData.size(); }
39
40 uint32_t hash() const;
41
42 bool operator==(const UniformDataBlock& that) const {
43 return fData.size() == that.fData.size() &&
44 !memcmp(fData.data(), that.fData.data(), fData.size());
45 }
46 bool operator!=(const UniformDataBlock& that) const { return !(*this == that); }
47
48private:
50};
51
53public:
54 using SampledTexture = std::pair<sk_sp<TextureProxy>, SamplerDesc>;
55
57 TextureDataBlock() = default;
58
59 bool empty() const { return fTextureData.empty(); }
60 int numTextures() const { return SkTo<int>(fTextureData.size()); }
61 const SampledTexture& texture(int index) const { return fTextureData[index]; }
62
63 bool operator==(const TextureDataBlock&) const;
64 bool operator!=(const TextureDataBlock& other) const { return !(*this == other); }
65 uint32_t hash() const;
66
67 void add(const SkSamplingOptions& sampling,
68 const SkTileMode tileModes[2],
69 sk_sp<TextureProxy> proxy) {
70 fTextureData.push_back({std::move(proxy), SamplerDesc{sampling, tileModes}});
71 }
72
73 void reset() {
74 fTextureData.clear();
75 }
76
77private:
78 // TODO: Move this into a SkSpan that's managed by the gatherer or copied into the arena.
79 std::vector<SampledTexture> fTextureData;
80};
81
82// The PipelineDataGatherer is just used to collect information for a given PaintParams object.
83// The UniformData is added to a cache and uniquified. Only that unique ID is passed around.
84// The TextureData is also added to a cache and uniquified. Only that ID is passed around.
85
86// TODO: The current plan for fixing uniform padding is for the PipelineDataGatherer to hold a
87// persistent uniformManager. A stretch goal for this system would be for this combination
88// to accumulate all the uniforms and then rearrange them to minimize padding. This would,
89// obviously, vastly complicate uniform accumulation.
91public:
93
94 void resetWithNewLayout(Layout layout);
95
96 // Check that the gatherer has been reset to its initial state prior to collecting new data.
97 SkDEBUGCODE(void checkReset();)
98
99 void add(const SkSamplingOptions& sampling,
102 fTextureDataBlock.add(sampling, tileModes, std::move(proxy));
103 }
104 bool hasTextures() const { return !fTextureDataBlock.empty(); }
105
106 const TextureDataBlock& textureDataBlock() { return fTextureDataBlock; }
107
108 // Mimic the type-safe API available in UniformManager
109 template <typename T> void write(const T& t) { fUniformManager.write(t); }
110 template <typename T> void writeHalf(const T& t) { fUniformManager.writeHalf(t); }
111 template <typename T> void writeArray(SkSpan<const T> t) { fUniformManager.writeArray(t); }
112 template <typename T> void writeHalfArray(SkSpan<const T> t) {
113 fUniformManager.writeHalfArray(t);
114 }
115
116 void write(const Uniform& u, const void* data) { fUniformManager.write(u, data); }
117
118 void writePaintColor(const SkPMColor4f& color) { fUniformManager.writePaintColor(color); }
119
120 bool hasUniforms() const { return fUniformManager.size(); }
121
122 // Returns the uniform data written so far. Will automatically pad the end of the data as needed
123 // to the overall required alignment, and so should only be called when all writing is done.
125
126private:
127#ifdef SK_DEBUG
128 friend class UniformExpectationsValidator;
129
130 void setExpectedUniforms(SkSpan<const Uniform> expectedUniforms);
131 void doneWithExpectedUniforms() { fUniformManager.doneWithExpectedUniforms(); }
132#endif // SK_DEBUG
133
134 TextureDataBlock fTextureDataBlock;
135 UniformManager fUniformManager;
136};
137
138#ifdef SK_DEBUG
139class UniformExpectationsValidator {
140public:
141 UniformExpectationsValidator(PipelineDataGatherer *gatherer,
142 SkSpan<const Uniform> expectedUniforms);
143
144 ~UniformExpectationsValidator() {
145 fGatherer->doneWithExpectedUniforms();
146 }
147
148private:
149 PipelineDataGatherer *fGatherer;
150
151 UniformExpectationsValidator(UniformExpectationsValidator &&) = delete;
152 UniformExpectationsValidator(const UniformExpectationsValidator &) = delete;
153 UniformExpectationsValidator &operator=(UniformExpectationsValidator &&) = delete;
154 UniformExpectationsValidator &operator=(const UniformExpectationsValidator &) = delete;
155};
156#endif // SK_DEBUG
157
158} // namespace skgpu::graphite
159
160#endif // skgpu_graphite_PipelineData_DEFINED
SkColor4f color
SkTileMode
Definition SkTileMode.h:13
constexpr T * data() const
Definition SkSpan_impl.h:94
constexpr size_t size() const
Definition SkSpan_impl.h:95
const SkTileMode sk_sp< TextureProxy > proxy
void write(const Uniform &u, const void *data)
void writeHalfArray(SkSpan< const T > t)
SkDEBUGCODE(void checkReset();) void add(const SkSamplingOptions &sampling
void writeArray(SkSpan< const T > t)
const TextureDataBlock & textureDataBlock()
void writePaintColor(const SkPMColor4f &color)
std::pair< sk_sp< TextureProxy >, SamplerDesc > SampledTexture
bool operator==(const TextureDataBlock &) const
static TextureDataBlock * Make(const TextureDataBlock &, SkArenaAlloc *)
bool operator!=(const TextureDataBlock &other) const
void add(const SkSamplingOptions &sampling, const SkTileMode tileModes[2], sk_sp< TextureProxy > proxy)
const SampledTexture & texture(int index) const
UniformDataBlock(SkSpan< const char > data)
static UniformDataBlock * Make(const UniformDataBlock &, SkArenaAlloc *)
bool operator!=(const UniformDataBlock &that) const
bool operator==(const UniformDataBlock &that) const
void writeArray(SkSpan< const SkV4 > v)
UniformDataBlock finishUniformDataBlock()
void writeHalfArray(SkSpan< const SkPMColor4f > c)
void writePaintColor(const SkPMColor4f &color)
#define T