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