-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathpalHasher.h
207 lines (184 loc) · 7.99 KB
/
palHasher.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
***********************************************************************************************************************
*
* Copyright (c) 2022-2024 Advanced Micro Devices, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**********************************************************************************************************************/
#pragma once
#include "palImage.h"
namespace Pal
{
/**
***********************************************************************************************************************
* @brief A wrapper class which has a Metrohash64 or MetroHash128 member. It provides Hash() methods for all the
* necessary struct or enum types to be called by hash calculation. Ultimately the metrohash library's
* default Update method which just treats every object like a raw byte array will be removed.
* Each time a new struct for hash caluclation is added or an existed struct for hash caluclation is changed,
* a Hash method need to be added or changed
*
***********************************************************************************************************************
*/
template<typename HashType >
class Hasher final
{
static_assert((std::is_same<HashType, Util::MetroHash64>::value ||
std::is_same<HashType, Util::MetroHash128>::value),
"Hash type HashType must be either MetroHash64 or MetroHash128.");
public:
Hasher() {}
~Hasher() {}
template<typename Type> inline
typename std::enable_if<std::is_enum<Type>::value, void>::type Hash(Type value)
{
m_hasher.Update(reinterpret_cast<const uint8*>(&value), sizeof(value));
}
template<typename Type> inline
typename std::enable_if<std::is_arithmetic<Type>::value, void>::type Hash(Type value)
{
m_hasher.Update(reinterpret_cast<const uint8*>(&value), sizeof(value));
}
void Hash(const ImageUsageFlags& value) { m_hasher.Update(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
void Hash(const SwizzledFormat& value) { m_hasher.Update(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
void Hash(const Extent3d& value) { m_hasher.Update(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
void Hash(const Rational& value) { m_hasher.Update(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
void Hash(const ClearColor& info)
{
Hash(info.type);
Hash(info.disabledChannelMask);
m_hasher.Update(reinterpret_cast<const uint8*>(&(info.u32Color[0])), 4*sizeof(uint32));
}
void Hash(const ImageCreateInfo& info)
{
// Note that one client is not able to guarantee that they consistently set the perSubresInit flag
// for all images that must be identical so we need to skip over the ImageCreateFlags.
Hash(info.usageFlags);
Hash(info.imageType);
Hash(info.swizzledFormat);
Hash(info.extent);
Hash(info.mipLevels);
Hash(info.arraySize);
Hash(info.samples);
Hash(info.fragments);
Hash(info.tiling);
Hash(info.tilingPreference);
Hash(info.tilingOptMode);
Hash(info.tileSwizzle);
Hash(info.metadataMode);
Hash(info.metadataTcCompatMode);
Hash(info.maxBaseAlign);
Hash(info.imageMemoryBudget);
Hash(info.prtPlus.mapType);
Hash(info.prtPlus.lodRegion);
Hash(info.rowPitch);
Hash(info.depthPitch);
Hash(info.refreshRate);
if ((info.pViewFormats != nullptr) && (info.viewFormatCount > 0))
{
m_hasher.Update(reinterpret_cast<const uint8*>(&(info.pViewFormats[0])), info.viewFormatCount*sizeof(SwizzledFormat));
}
}
void Hash(const PipelineCreateFlags& value) { m_hasher.Update(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
void Hash(const Util::MetroHash::Hash& value) { m_hasher.Update(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
void Hash(const RasterizerState& info)
{
Hash(info.pointCoordOrigin);
Hash(info.expandLineWidth);
Hash(info.shadeMode);
Hash(info.rasterizeLastLinePixel);
Hash(info.outOfOrderPrimsEnable);
Hash(info.perpLineEndCapsEnable);
Hash(info.binningOverride);
Hash(info.depthClampMode);
Hash(info.clipDistMask);
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION < 869
Hash(info.forcedShadingRate);
#endif
Hash(info.dx10DiamondTestDisable);
}
void Hash(const ViewportInfo& info)
{
Hash(info.depthClipNearEnable);
Hash(info.depthClipFarEnable);
Hash(info.depthRange);
}
void Hash(const ColorTargetInfo& info)
{
Hash(info.swizzledFormat);
Hash(info.channelWriteMask);
Hash(info.forceAlphaToOne);
}
void Hash(const GraphicsPipelineCreateInfo& info)
{
Hash(info.flags);
Hash(info.useLateAllocVsLimit);
if (info.useLateAllocVsLimit)
{
Hash(info.lateAllocVsLimit);
}
Hash(info.useLateAllocGsLimit);
if (info.useLateAllocGsLimit)
{
Hash(info.lateAllocGsLimit);
}
m_hasher.Update(reinterpret_cast<const uint8*>(&(info.iaState)), sizeof(info.iaState));
Hash(info.rsState);
Hash(info.cbState.alphaToCoverageEnable);
Hash(info.cbState.dualSourceBlendEnable);
Hash(info.cbState.logicOp);
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION < 904
Hash(info.cbState.uavExportSingleDraw);
#endif
Hash(info.viewportInfo);
for (uint32_t i = 0; i < Pal::MaxColorTargets; ++i)
{
if (info.cbState.target[i].swizzledFormat.format != Pal::ChNumFormat::Undefined)
{
Hash(info.cbState.target[i]);
}
}
if (info.viewInstancingDesc.viewInstanceCount > 0)
{
const Pal::ViewInstancingDescriptor& desc = info.viewInstancingDesc;
Hash(reinterpret_cast<const uint8_t*>(desc.viewId),
sizeof(desc.viewId[0]) * desc.viewInstanceCount);
Hash(reinterpret_cast<const uint8_t*>(desc.renderTargetArrayIdx),
sizeof(desc.renderTargetArrayIdx[0]) * desc.viewInstanceCount);
Hash(reinterpret_cast<const uint8_t*>(desc.viewportArrayIdx),
sizeof(desc.viewportArrayIdx[0]) * desc.viewInstanceCount);
Hash(desc.enableMasking);
}
if (info.coverageOutDesc.flags.enable == 1)
{
m_hasher.Update(reinterpret_cast<const uint8*>(&(info.coverageOutDesc)), sizeof(info.coverageOutDesc));
}
}
inline void Hash(const void* buffer, const uint64 length)
{
m_hasher.Update(reinterpret_cast<const uint8*>(buffer), length);
}
inline void Finalize(void* const hash) { m_hasher.Finalize(reinterpret_cast<uint8* const>(hash)); }
private:
HashType m_hasher;
PAL_DISALLOW_COPY_AND_ASSIGN(Hasher);
};
typedef Hasher<Util::MetroHash64> Hasher64;
typedef Hasher<Util::MetroHash128> Hasher128;
}