From 21120ac0ae1880a4a9840a2d04a7333960530021 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Wed, 27 Sep 2023 07:45:05 +0300 Subject: [PATCH] finished gpu buffer creation --- src/Core/PS4/GPU/gpu_memory.cpp | 24 ++++++++++++++++++++++-- src/Core/PS4/GPU/gpu_memory.h | 23 +++++++++++++++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/Core/PS4/GPU/gpu_memory.cpp b/src/Core/PS4/GPU/gpu_memory.cpp index c96183ff..a17e0469 100644 --- a/src/Core/PS4/GPU/gpu_memory.cpp +++ b/src/Core/PS4/GPU/gpu_memory.cpp @@ -82,6 +82,7 @@ void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::Graphi if (heap_id < 0) { return nullptr; } + auto& heap = m_heaps[heap_id]; ObjInfo objInfo = {}; @@ -105,6 +106,25 @@ void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::Graphi objInfo.gpu_object.obj = info.getCreateFunc()(ctx, objInfo.obj_params, virtual_addr, size, virtual_addr_num, &objInfo.mem); - // TODO we need more ... - return nullptr; + int index = static_cast(heap.objects.size()); + + HeapObject hobj{}; + hobj.block = createHeapBlock(virtual_addr, size, virtual_addr_num, heap_id, index); + hobj.info = objInfo; + hobj.free = false; + heap.objects.push_back(hobj); + + return objInfo.gpu_object.obj; +} + +GPU::HeapBlock GPU::GPUMemory::createHeapBlock(const u64* virtual_addr, const u64* size, int virtual_addr_num, int heap_id, int obj_id) { + auto& heap = m_heaps[heap_id]; + + GPU::HeapBlock heapBlock{}; + heapBlock.virtual_addr_num = virtual_addr_num; + for (int vi = 0; vi < virtual_addr_num; vi++) { + heapBlock.virtual_addr[vi] = virtual_addr[vi]; + heapBlock.size[vi] = size[vi]; + } + return heapBlock; } diff --git a/src/Core/PS4/GPU/gpu_memory.h b/src/Core/PS4/GPU/gpu_memory.h index eb234b44..7690cd06 100644 --- a/src/Core/PS4/GPU/gpu_memory.h +++ b/src/Core/PS4/GPU/gpu_memory.h @@ -11,10 +11,7 @@ class GPUObject; enum class MemoryMode : u32 { NoAccess = 0, Read = 1, Write = 2, ReadWrite = 3 }; enum class MemoryObjectType : u64 { InvalidObj, VideoOutBufferObj }; -struct MemoryHeap { - u64 allocated_virtual_addr = 0; - u64 allocated_size = 0; -}; + struct GpuMemoryObject { MemoryObjectType objectType = MemoryObjectType::InvalidObj; @@ -30,6 +27,23 @@ struct ObjInfo { HLE::Libs::Graphics::VulkanMemory mem; }; +struct HeapBlock { + u64 virtual_addr[3] = {}; + u64 size[3] = {}; + int virtual_addr_num = 0; +}; + +struct HeapObject { + HeapBlock block; + ObjInfo info; + bool free = true; +}; + +struct MemoryHeap { + u64 allocated_virtual_addr = 0; + u64 allocated_size = 0; + std::vector objects; +}; class GPUMemory { public: @@ -40,6 +54,7 @@ class GPUMemory { std::vector m_heaps; void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, /*CommandBuffer* buffer*/ void* todo, const u64* virtual_addr, const u64* size, int virtual_addr_num, const GPUObject& info); + HeapBlock createHeapBlock(const u64* virtual_addr, const u64* size, int virtual_addr_num, int heap_id, int obj_id); }; class GPUObject { public: