Fix #120579: incorrect compute context hashes
The problem was that `XXH3_128bits` was called on `len` bytes
and not `HashSizeInBytes + len` as before 51f8bf53b2.
This lead to more compute context duplicates that one would expect.
I changed the code a little bit to make this mistake less likely in case
the hash function is ever changed to something else.
This commit is contained in:
@@ -47,7 +47,6 @@ namespace blender {
|
||||
* have enough bits to make collisions practically impossible.
|
||||
*/
|
||||
struct ComputeContextHash {
|
||||
static constexpr int64_t HashSizeInBytes = 16;
|
||||
uint64_t v1 = 0;
|
||||
uint64_t v2 = 0;
|
||||
|
||||
@@ -63,8 +62,6 @@ struct ComputeContextHash {
|
||||
friend std::ostream &operator<<(std::ostream &stream, const ComputeContextHash &hash);
|
||||
};
|
||||
|
||||
static_assert(sizeof(ComputeContextHash) == ComputeContextHash::HashSizeInBytes);
|
||||
|
||||
/**
|
||||
* Identifies the context in which a computation happens. This context can be used to identify
|
||||
* values logged during the computation. For more details, see the comment at the top of the file.
|
||||
|
||||
@@ -11,12 +11,14 @@ namespace blender {
|
||||
|
||||
void ComputeContextHash::mix_in(const void *data, int64_t len)
|
||||
{
|
||||
DynamicStackBuffer<> buffer_owner(HashSizeInBytes + len, 8);
|
||||
const int64_t hash_size = sizeof(ComputeContextHash);
|
||||
const int64_t buffer_len = hash_size + len;
|
||||
DynamicStackBuffer<> buffer_owner(buffer_len, 8);
|
||||
char *buffer = static_cast<char *>(buffer_owner.buffer());
|
||||
memcpy(buffer, this, HashSizeInBytes);
|
||||
memcpy(buffer + HashSizeInBytes, data, len);
|
||||
memcpy(buffer, this, hash_size);
|
||||
memcpy(buffer + hash_size, data, len);
|
||||
|
||||
const XXH128_hash_t hash = XXH3_128bits(buffer, len);
|
||||
const XXH128_hash_t hash = XXH3_128bits(buffer, buffer_len);
|
||||
memcpy(this, &hash, sizeof(hash));
|
||||
static_assert(sizeof(ComputeContextHash) == sizeof(hash));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user