Flutter Engine
The Flutter Engine
PipelineData.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
10#include "src/core/SkChecksum.h"
12
13namespace skgpu::graphite {
14
16 : fUniformManager(layout) {}
17
19 fUniformManager.resetWithNewLayout(layout);
20 fTextureDataBlock.reset();
21}
22
23#ifdef SK_DEBUG
24void PipelineDataGatherer::checkReset() {
25 SkASSERT(fTextureDataBlock.empty());
26 SkASSERT(fUniformManager.isReset());
27}
28
29void PipelineDataGatherer::setExpectedUniforms(SkSpan<const Uniform> expectedUniforms) {
30 fUniformManager.setExpectedUniforms(expectedUniforms);
31}
32#endif // SK_DEBUG
33
34////////////////////////////////////////////////////////////////////////////////////////////////////
36 static constexpr size_t kUniformAlignment = alignof(void*);
37 char* mem = static_cast<char*>(arena->makeBytesAlignedTo(other.size(), kUniformAlignment));
38 memcpy(mem, other.data(), other.size());
39
40 return arena->make([&](void* ptr) {
41 return new (ptr) UniformDataBlock(SkSpan<const char>(mem, other.size()));
42 });
43}
44
45uint32_t UniformDataBlock::hash() const {
46 return SkChecksum::Hash32(fData.data(), fData.size());
47}
48
49////////////////////////////////////////////////////////////////////////////////////////////////////
51 SkArenaAlloc* arena) {
52 return arena->make([&](void *ptr) {
53 return new (ptr) TextureDataBlock(other);
54 });
55}
56
58 if (fTextureData.size() != other.fTextureData.size()) {
59 return false;
60 }
61
62 for (size_t i = 0; i < fTextureData.size(); ++i) {
63 if (fTextureData[i] != other.fTextureData[i]) {
64 return false;
65 }
66 }
67
68 return true;
69}
70
71uint32_t TextureDataBlock::hash() const {
72 uint32_t hash = 0;
73
74 for (auto& d : fTextureData) {
75 SamplerDesc samplerKey = std::get<1>(d);
76 hash = SkChecksum::Hash32(&samplerKey, sizeof(samplerKey), hash);
77
78 // Because the lifetime of the TextureDataCache is for just one Recording and the
79 // TextureDataBlocks hold refs on their proxies, we can just use the proxy's pointer
80 // for the hash here.
81 uintptr_t proxy = reinterpret_cast<uintptr_t>(std::get<0>(d).get());
82 hash = SkChecksum::Hash32(&proxy, sizeof(proxy), hash);
83 }
84
85 return hash;
86}
87
88#ifdef SK_DEBUG
89UniformExpectationsValidator::UniformExpectationsValidator(PipelineDataGatherer *gatherer,
90 SkSpan<const Uniform> expectedUniforms)
91 : fGatherer(gatherer) {
92 fGatherer->setExpectedUniforms(expectedUniforms);
93}
94#endif
95
96} // namespace skgpu::graphite
#define SkASSERT(cond)
Definition: SkAssert.h:116
void * makeBytesAlignedTo(size_t size, size_t align)
Definition: SkArenaAlloc.h:200
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
constexpr T * data() const
Definition: SkSpan_impl.h:94
constexpr size_t size() const
Definition: SkSpan_impl.h:95
bool operator==(const TextureDataBlock &) const
static TextureDataBlock * Make(const TextureDataBlock &, SkArenaAlloc *)
static UniformDataBlock * Make(const UniformDataBlock &, SkArenaAlloc *)
void resetWithNewLayout(Layout layout)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
Definition: SkChecksum.cpp:113
const myers::Point & get< 1 >(const myers::Segment &s)
Definition: Myers.h:81
const myers::Point & get< 0 >(const myers::Segment &s)
Definition: Myers.h:80