Coverage Report

Created: 2024-05-20 07:14

/src/skia/src/gpu/graphite/PipelineData.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "src/gpu/graphite/PipelineData.h"
9
10
#include "src/core/SkChecksum.h"
11
#include "src/gpu/graphite/ShaderCodeDictionary.h"
12
13
namespace skgpu::graphite {
14
15
PipelineDataGatherer::PipelineDataGatherer(const Caps* caps, Layout layout)
16
0
        : fCaps(caps), fUniformManager(layout) {}
17
18
0
void PipelineDataGatherer::resetWithNewLayout(Layout layout) {
19
0
    fUniformManager.resetWithNewLayout(layout);
20
0
    fTextureDataBlock.reset();
21
0
}
22
23
#ifdef SK_DEBUG
24
0
void PipelineDataGatherer::checkReset() {
25
0
    SkASSERT(fTextureDataBlock.empty());
26
0
    SkASSERT(fUniformManager.isReset());
27
0
}
28
29
0
void PipelineDataGatherer::setExpectedUniforms(SkSpan<const Uniform> expectedUniforms) {
30
0
    fUniformManager.setExpectedUniforms(expectedUniforms);
31
0
}
32
#endif // SK_DEBUG
33
34
////////////////////////////////////////////////////////////////////////////////////////////////////
35
0
UniformDataBlock* UniformDataBlock::Make(const UniformDataBlock& other, SkArenaAlloc* arena) {
36
0
    static constexpr size_t kUniformAlignment = alignof(void*);
37
0
    char* mem = static_cast<char*>(arena->makeBytesAlignedTo(other.size(), kUniformAlignment));
38
0
    memcpy(mem, other.data(), other.size());
39
40
0
    return arena->make([&](void* ptr) {
41
0
        return new (ptr) UniformDataBlock(SkSpan<const char>(mem, other.size()));
42
0
    });
43
0
}
44
45
0
uint32_t UniformDataBlock::hash() const {
46
0
    return SkChecksum::Hash32(fData.data(), fData.size());
47
0
}
48
49
////////////////////////////////////////////////////////////////////////////////////////////////////
50
TextureDataBlock* TextureDataBlock::Make(const TextureDataBlock& other,
51
0
                                             SkArenaAlloc* arena) {
52
0
    return arena->make([&](void *ptr) {
53
0
        return new (ptr) TextureDataBlock(other);
54
0
    });
55
0
}
56
57
0
bool TextureDataBlock::operator==(const TextureDataBlock& other) const {
58
0
    if (fTextureData.size() != other.fTextureData.size()) {
59
0
        return false;
60
0
    }
61
62
0
    for (size_t i = 0; i < fTextureData.size(); ++i) {
63
0
        if (fTextureData[i] != other.fTextureData[i]) {
64
0
            return false;
65
0
        }
66
0
    }
67
68
0
    return true;
69
0
}
70
71
0
uint32_t TextureDataBlock::hash() const {
72
0
    uint32_t hash = 0;
73
74
0
    for (auto& d : fTextureData) {
75
0
        SamplerDesc samplerKey = std::get<1>(d);
76
0
        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
0
        uintptr_t proxy = reinterpret_cast<uintptr_t>(std::get<0>(d).get());
82
0
        hash = SkChecksum::Hash32(&proxy, sizeof(proxy), hash);
83
0
    }
84
85
0
    return hash;
86
0
}
87
88
#ifdef SK_DEBUG
89
UniformExpectationsValidator::UniformExpectationsValidator(PipelineDataGatherer *gatherer,
90
                                                           SkSpan<const Uniform> expectedUniforms)
91
0
        : fGatherer(gatherer) {
92
0
    fGatherer->setExpectedUniforms(expectedUniforms);
93
0
}
94
#endif
95
96
} // namespace skgpu::graphite