From 1a5dd6cdfe594cf3f1d3dd6b101f7750c3037f77 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 26 Sep 2023 16:00:13 +0300 Subject: [PATCH] added XXH3_64bits and calculate memory obj hashes --- .gitmodules | 4 ++++ CMakeLists.txt | 1 + src/Core/PS4/GPU/gpu_memory.cpp | 24 ++++++++++++++++++++++-- src/Core/PS4/GPU/gpu_memory.h | 10 +++++++++- src/Core/PS4/GPU/video_out_buffer.h | 18 +++++++++++++++++- third-party/xxHash | 1 + 6 files changed, 54 insertions(+), 4 deletions(-) create mode 160000 third-party/xxHash diff --git a/.gitmodules b/.gitmodules index 9f2d7480..9cfbedd0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,3 +37,7 @@ path = third-party/vulkan url = https://github.com/shadps4/vulkan.git branch = main +[submodule "third-party/xxHash"] + path = third-party/xxHash + url = https://github.com/Cyan4973/xxHash.git + branch = dev diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d751971..a5a0fe28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ include_directories(third-party/magic_enum/include) include_directories(third-party/zydis/include/Zydis) include_directories(third-party/winpthread/include) include_directories(third-party/vulkan/include) +include_directories(third-party/xxhash/include) add_subdirectory("third-party") #=================== EXAMPLE =================== include_directories(src) diff --git a/src/Core/PS4/GPU/gpu_memory.cpp b/src/Core/PS4/GPU/gpu_memory.cpp index fd5c0ca0..41a73896 100644 --- a/src/Core/PS4/GPU/gpu_memory.cpp +++ b/src/Core/PS4/GPU/gpu_memory.cpp @@ -1,8 +1,11 @@ #include "gpu_memory.h" +#include + #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::Instance(); 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); } +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 index = 0; 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) { 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(virtual_addr[h]), size[h]); + } else { + hash[h] = 0; + } + } return nullptr; } diff --git a/src/Core/PS4/GPU/gpu_memory.h b/src/Core/PS4/GPU/gpu_memory.h index 2f2fa4c2..a13697f8 100644 --- a/src/Core/PS4/GPU/gpu_memory.h +++ b/src/Core/PS4/GPU/gpu_memory.h @@ -16,6 +16,9 @@ struct MemoryHeap { u64 allocated_size = 0; }; +struct ObjInfo { + u64 obj_params[8] = {}; +}; class GPUMemory { public: GPUMemory() {} @@ -30,10 +33,15 @@ class GPUObject { public: 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* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, /*CommandBuffer* buffer*/ void* todo, u64 virtual_addr, u64 size, const GPUObject& info); - +u64 calculate_hash(const u08* buf, u64 size); } // namespace GPU \ No newline at end of file diff --git a/src/Core/PS4/GPU/video_out_buffer.h b/src/Core/PS4/GPU/video_out_buffer.h index e07496c9..7d9478b9 100644 --- a/src/Core/PS4/GPU/video_out_buffer.h +++ b/src/Core/PS4/GPU/video_out_buffer.h @@ -1,6 +1,7 @@ #pragma once #include + #include "gpu_memory.h" namespace GPU { @@ -13,7 +14,22 @@ enum class VideoOutBufferFormat : u64 { class VideoOutBufferObj : public GPUObject { 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) { + obj_params[PIXEL_FORMAT_PARAM] = static_cast(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 diff --git a/third-party/xxHash b/third-party/xxHash new file mode 160000 index 00000000..058e54b1 --- /dev/null +++ b/third-party/xxHash @@ -0,0 +1 @@ +Subproject commit 058e54b10b10c658fd50862e6f65f55522afa182