Skip to content

Commit

Permalink
Remove xxHash source
Browse files Browse the repository at this point in the history
GFXReconstruct had a hash function already in place that wasn't
used.  It was only for returning 32-bit hash values, so it was
therefore improved to support 8-bit, 16-bit, 32-bit, 64-bit and
128-bit hash values.  Only use the 64-bit version for now in
place of the xxHash version.
  • Loading branch information
MarkY-LunarG committed Nov 27, 2023
1 parent 4857e70 commit 5aeeb60
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 5,942 deletions.
1 change: 0 additions & 1 deletion android/framework/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ target_sources(gfxrecon_util
${GFXRECON_SOURCE_DIR}/framework/util/file_path.h
${GFXRECON_SOURCE_DIR}/framework/util/file_path.cpp
${GFXRECON_SOURCE_DIR}/framework/util/hash.h
${GFXRECON_SOURCE_DIR}/framework/util/hash.cpp
${GFXRECON_SOURCE_DIR}/framework/util/image_writer.h
${GFXRECON_SOURCE_DIR}/framework/util/image_writer.cpp
${GFXRECON_SOURCE_DIR}/framework/util/keyboard.h
Expand Down
7 changes: 4 additions & 3 deletions framework/decode/vulkan_cpp_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "project_version.h"
#include "util/file_path.h"
#include "util/platform.h"
#include <util/xxhash64.h>
#include <util/hash.h>
#include "decode/vulkan_cpp_structs.h"
#include <generated/generated_vulkan_cpp_structs.h>
#include "generated/generated_vulkan_cpp_consumer_extension.h"
Expand Down Expand Up @@ -2504,8 +2504,9 @@ bool GfxToCppPlatformIsValid(const GfxToCppPlatform& platform)

std::string VulkanCppConsumerBase::AddStruct(const std::stringstream& content, const std::string& var_namePrefix)
{
const std::string str = content.str();
uint64_t hash_value = XXHash64::hash(str.c_str(), str.size(), 0);
const std::string content_string = content.str();
const uint64_t hash_value = util::hash::GenerateCheckSum<uint64_t>(
reinterpret_cast<const uint8_t*>(content_string.c_str()), content_string.size());

std::string var_name = var_namePrefix + "_" + std::to_string(GetNextId());
struct_map_[hash_value] = var_name;
Expand Down
1 change: 0 additions & 1 deletion framework/decode/vulkan_cpp_resource_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "format/platform_types.h"
#include "format/format.h"
#include "pointer_decoder.h"
#include "util/xxhash32.h"

#include <cstdint>
#include <map>
Expand Down
22 changes: 12 additions & 10 deletions framework/decode/vulkan_cpp_util_datapack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <functional>

#include "decode/vulkan_cpp_util_datapack.h"

#include "util/hash.h"
#include "util/file_path.h"
#include "util/platform.h"
#include "util/xxhash64.h"

GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(decode)
Expand All @@ -37,13 +39,12 @@ void DataFilePacker::Initialize(const std::string& outDir,
NewTargetFile();
}

const SavedFileInfo DataFilePacker::AddFileContents(const uint8_t* data, const uint64_t dataSize)
const SavedFileInfo DataFilePacker::AddFileContents(const uint8_t* data, const size_t dataSize)
{
uint64_t hashValue = XXHash64::hash(data, dataSize, 0);

SavedFileInfo& dataEntry = data_file_map_[hashValue];
const uint64_t hash_value = util::hash::GenerateCheckSum<uint64_t>(data, dataSize);
SavedFileInfo& data_entry = data_file_map_[hash_value];

if (dataEntry.file_path.empty())
if (data_entry.file_path.empty())
{
// The binary contents is not found in any previous chunk.
if (current_data_file_.current_size > size_limit_in_bytes_)
Expand All @@ -52,15 +53,16 @@ const SavedFileInfo DataFilePacker::AddFileContents(const uint8_t* data, const u
NewTargetFile();
}

dataEntry.file_path = current_data_file_.file_path;
dataEntry.byte_offset = current_data_file_.current_size;
data_entry.file_path = current_data_file_.file_path;
data_entry.byte_offset = current_data_file_.current_size;

WriteContentsToFile(util::filepath::Join(out_dir_, dataEntry.file_path), dataEntry.byte_offset, dataSize, data);
WriteContentsToFile(
util::filepath::Join(out_dir_, data_entry.file_path), data_entry.byte_offset, dataSize, data);

current_data_file_.current_size += dataSize;
}

return dataEntry;
return data_entry;
}

void DataFilePacker::NewTargetFile(void)
Expand Down
9 changes: 5 additions & 4 deletions framework/decode/vulkan_cpp_util_datapack.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#ifndef GFXRECON_DECODE_VULKAN_CPP_UTIL_DATAPACK_H
#define GFXRECON_DECODE_VULKAN_CPP_UTIL_DATAPACK_H

#include <map>
// #include <map> // Brainpain
#include <unordered_map>
#include <string>

#include "util/defines.h"
Expand All @@ -41,7 +42,7 @@ class DataFilePacker
const std::string& prefix,
const std::string& suffix,
uint32_t sizeLimitInBytes);
const SavedFileInfo AddFileContents(const uint8_t* data, const uint64_t dataSize);
const SavedFileInfo AddFileContents(const uint8_t* data, const size_t dataSize);

private:
void NewTargetFile(void);
Expand All @@ -59,8 +60,8 @@ class DataFilePacker
uint32_t size_limit_in_bytes_;
uint32_t data_file_counter_;

std::map<uint64_t, SavedFileInfo> data_file_map_;
SavedFile current_data_file_;
std::unordered_map<uint64_t, SavedFileInfo> data_file_map_;
SavedFile current_data_file_;
};

GFXRECON_END_NAMESPACE(decode)
Expand Down
1 change: 0 additions & 1 deletion framework/decode/vulkan_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "graphics/vulkan_device_util.h"
#include "graphics/vulkan_util.h"
#include "util/file_path.h"
#include "util/hash.h"
#include "util/platform.h"
#include "util/logging.h"

Expand Down
3 changes: 0 additions & 3 deletions framework/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ target_sources(gfxrecon_util
${CMAKE_CURRENT_LIST_DIR}/file_path.h
${CMAKE_CURRENT_LIST_DIR}/file_path.cpp
${CMAKE_CURRENT_LIST_DIR}/hash.h
${CMAKE_CURRENT_LIST_DIR}/hash.cpp
${CMAKE_CURRENT_LIST_DIR}/image_writer.h
${CMAKE_CURRENT_LIST_DIR}/image_writer.cpp
${CMAKE_CURRENT_LIST_DIR}/json_util.h
Expand Down Expand Up @@ -96,8 +95,6 @@ target_sources(gfxrecon_util
${CMAKE_CURRENT_LIST_DIR}/custom_common_to_string.cpp
${CMAKE_SOURCE_DIR}/framework/generated/generated_vulkan_enum_to_string.h
${CMAKE_SOURCE_DIR}/framework/generated/generated_vulkan_enum_to_string.cpp
${CMAKE_CURRENT_LIST_DIR}/xxhash64.h
${CMAKE_CURRENT_LIST_DIR}/xxhash32.h
$<$<BOOL:${XCB_FOUND}>:${CMAKE_CURRENT_LIST_DIR}/xcb_loader.h>
$<$<BOOL:${XCB_FOUND}>:${CMAKE_CURRENT_LIST_DIR}/xcb_loader.cpp>
$<$<BOOL:${XCB_FOUND}>:${CMAKE_CURRENT_LIST_DIR}/xcb_keysyms_loader.h>
Expand Down
45 changes: 0 additions & 45 deletions framework/util/hash.cpp

This file was deleted.

37 changes: 31 additions & 6 deletions framework/util/hash.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2020 Valve Corporation
** Copyright (c) 2020 LunarG, Inc.
** Copyright (c) 2020-2023 LunarG, Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand All @@ -21,21 +21,46 @@
** DEALINGS IN THE SOFTWARE.
*/

#ifndef GFXRECON_UTIL_HASH_H
#define GFXRECON_UTIL_HASH_H
#pragma once

#include "util/defines.h"

#include <cstddef>
#include <functional>

GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(util)
GFXRECON_BEGIN_NAMESPACE(hash)

uint32_t CheckSum(const uint32_t* code, size_t code_size);
template <class Type>
Type ClosestLowerPrime(void)
{
// Next lower prime indexed using the number of bits in the size of
// the return type to determine a prime number that can be used in the
// hash function multiplication.
// For example: the indices corresponding to the structure size are:
// [0] 0 bytes (not valid), [1] 1 byte, [2] 2 bytes, ...
// NOTE: Some of these sizes won't be valid for standard architectures, but
// implementing them in the array just made the indexing process
// easier.
uint8_t primes[] = { 0, 7, 13, 23, 31, 37, 43, 53, 61 };
size_t type_size = sizeof(Type);
assert(type_size < sizeof(primes));
return static_cast<Type>(primes[type_size]);
}

template <class Type>
Type GenerateCheckSum(const uint8_t* code, size_t code_size)
{
Type current_sum = code_size;
Type closest_prime = ClosestLowerPrime<Type>();
for (Type i = 0; i < code_size; ++i)
{
current_sum = (current_sum * closest_prime) + std::hash<uint8_t>{}(code[i]);
}
return current_sum;
}

GFXRECON_END_NAMESPACE(hash)
GFXRECON_END_NAMESPACE(util)
GFXRECON_END_NAMESPACE(gfxrecon)

#endif // GFXRECON_UTIL_HASH_H
43 changes: 0 additions & 43 deletions framework/util/xxhash.c

This file was deleted.

Loading

0 comments on commit 5aeeb60

Please sign in to comment.