added XXH3_64bits and calculate memory obj hashes

This commit is contained in:
georgemoralis 2023-09-26 16:00:13 +03:00
parent 7570576aa2
commit 1a5dd6cdfe
6 changed files with 54 additions and 4 deletions

4
.gitmodules vendored
View File

@ -37,3 +37,7 @@
path = third-party/vulkan path = third-party/vulkan
url = https://github.com/shadps4/vulkan.git url = https://github.com/shadps4/vulkan.git
branch = main branch = main
[submodule "third-party/xxHash"]
path = third-party/xxHash
url = https://github.com/Cyan4973/xxHash.git
branch = dev

View File

@ -18,6 +18,7 @@ include_directories(third-party/magic_enum/include)
include_directories(third-party/zydis/include/Zydis) include_directories(third-party/zydis/include/Zydis)
include_directories(third-party/winpthread/include) include_directories(third-party/winpthread/include)
include_directories(third-party/vulkan/include) include_directories(third-party/vulkan/include)
include_directories(third-party/xxhash/include)
add_subdirectory("third-party") add_subdirectory("third-party")
#=================== EXAMPLE =================== #=================== EXAMPLE ===================
include_directories(src) include_directories(src)

View File

@ -1,8 +1,11 @@
#include "gpu_memory.h" #include "gpu_memory.h"
#include <xxhash/xxh3.h>
#include "Util/Singleton.h" #include "Util/Singleton.h"
void* GPU::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo /*CommandBuffer?*/, u64 virtual_addr, u64 size, const GPUObject& info) { void* GPU::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo /*CommandBuffer?*/, u64 virtual_addr, u64 size,
const GPUObject& info) {
auto* gpumemory = Singleton<GPUMemory>::Instance(); auto* gpumemory = Singleton<GPUMemory>::Instance();
return gpumemory->memoryCreateObj(submit_id, ctx, nullptr, &virtual_addr, &size, 1, info); return gpumemory->memoryCreateObj(submit_id, ctx, nullptr, &virtual_addr, &size, 1, info);
@ -20,6 +23,8 @@ void GPU::memorySetAllocArea(u64 virtual_addr, u64 size) {
gpumemory->m_heaps.push_back(h); gpumemory->m_heaps.push_back(h);
} }
u64 GPU::calculate_hash(const u08* buf, u64 size) { return (size > 0 && buf != nullptr ? XXH3_64bits(buf, size) : 0); }
int GPU::GPUMemory::getHeapId(u64 virtual_addr, u64 size) { int GPU::GPUMemory::getHeapId(u64 virtual_addr, u64 size) {
int index = 0; int index = 0;
for (const auto& heap : m_heaps) { for (const auto& heap : m_heaps) {
@ -44,6 +49,21 @@ void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::Graphi
if (heap_id < 0) { if (heap_id < 0) {
return nullptr; return nullptr;
} }
// TODO not finished!
ObjInfo obj = {};
// copy parameters from info to obj
for (int i = 0; i < 8; i++) {
obj.obj_params[i] = info.obj_params[i];
}
u64 hash[3] = {}; // assuming virtual_addr_num shouldn't be more that 3
for (int h = 0; h < virtual_addr_num; h++) {
if (info.hasHash) {
hash[h] = GPU::calculate_hash(reinterpret_cast<const u08*>(virtual_addr[h]), size[h]);
} else {
hash[h] = 0;
}
}
return nullptr; return nullptr;
} }

View File

@ -16,6 +16,9 @@ struct MemoryHeap {
u64 allocated_size = 0; u64 allocated_size = 0;
}; };
struct ObjInfo {
u64 obj_params[8] = {};
};
class GPUMemory { class GPUMemory {
public: public:
GPUMemory() {} GPUMemory() {}
@ -30,10 +33,15 @@ class GPUObject {
public: public:
GPUObject() = default; GPUObject() = default;
virtual ~GPUObject() = default; virtual ~GPUObject() = default;
u64 obj_params[8] = {};
bool hasHash = false;
bool isReadOnly = false;
MemoryObjectType objectType = MemoryObjectType::InvalidObj;
}; };
void memorySetAllocArea(u64 virtual_addr, u64 size); void memorySetAllocArea(u64 virtual_addr, u64 size);
void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, /*CommandBuffer* buffer*/ void* todo, u64 virtual_addr, u64 size, void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, /*CommandBuffer* buffer*/ void* todo, u64 virtual_addr, u64 size,
const GPUObject& info); const GPUObject& info);
u64 calculate_hash(const u08* buf, u64 size);
} // namespace GPU } // namespace GPU

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <types.h> #include <types.h>
#include "gpu_memory.h" #include "gpu_memory.h"
namespace GPU { namespace GPU {
@ -13,7 +14,22 @@ enum class VideoOutBufferFormat : u64 {
class VideoOutBufferObj : public GPUObject { class VideoOutBufferObj : public GPUObject {
public: public:
static constexpr int PIXEL_FORMAT_PARAM = 0;
static constexpr int WIDTH_PARAM = 1;
static constexpr int HEIGHT_PARAM = 2;
static constexpr int IS_TILE_PARAM = 3;
static constexpr int IS_NEO_PARAM = 4;
static constexpr int PITCH_PARAM = 5;
explicit VideoOutBufferObj(VideoOutBufferFormat pixel_format, u32 width, u32 height, bool is_tiled, bool is_neo, u32 pitch) { explicit VideoOutBufferObj(VideoOutBufferFormat pixel_format, u32 width, u32 height, bool is_tiled, bool is_neo, u32 pitch) {
obj_params[PIXEL_FORMAT_PARAM] = static_cast<uint64_t>(pixel_format);
obj_params[WIDTH_PARAM] = width;
obj_params[HEIGHT_PARAM] = height;
obj_params[IS_TILE_PARAM] = is_tiled ? 1 : 0;
obj_params[IS_NEO_PARAM] = is_neo ? 1 : 0;
obj_params[PITCH_PARAM] = pitch;
hasHash = true;
objectType = GPU::MemoryObjectType::VideoOutBufferObj;
} }
}; };
} } // namespace GPU

1
third-party/xxHash vendored Submodule

@ -0,0 +1 @@
Subproject commit 058e54b10b10c658fd50862e6f65f55522afa182