From 1f0beb0ec3afff81ebb0d69a6bfacff76b6b45e2 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 25 Sep 2023 12:04:40 +0300 Subject: [PATCH] gpumemory works --- src/Core/PS4/GPU/gpu_memory.cpp | 3 +++ src/Core/PS4/GPU/gpu_memory.h | 11 +++++++++++ src/Core/PS4/GPU/video_out_buffer.h | 3 ++- src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h | 11 +++++++++++ src/Core/PS4/HLE/Graphics/video_out.cpp | 8 ++++++-- src/emulator.cpp | 13 +++++++++++-- src/emulator.h | 1 + 7 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/Core/PS4/GPU/gpu_memory.cpp b/src/Core/PS4/GPU/gpu_memory.cpp index 873f43b5..6b51f022 100644 --- a/src/Core/PS4/GPU/gpu_memory.cpp +++ b/src/Core/PS4/GPU/gpu_memory.cpp @@ -2,4 +2,7 @@ namespace GPU { void MemorySetAllocArea(u64 virtual_addr, u64 size) {} +void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo, u64 virtual_addr, u64 size, const GPUObject& info) { + return nullptr; +} } // namespace GPU \ No newline at end of file diff --git a/src/Core/PS4/GPU/gpu_memory.h b/src/Core/PS4/GPU/gpu_memory.h index 14084de9..043c075d 100644 --- a/src/Core/PS4/GPU/gpu_memory.h +++ b/src/Core/PS4/GPU/gpu_memory.h @@ -1,9 +1,20 @@ #pragma once #include +#include namespace GPU { enum class MemoryMode : u32 { NoAccess = 0, Read = 1, Write = 2, ReadWrite = 3 }; enum class MemoryObjectType : u64 { InvalidObj, VideoOutBufferObj }; void MemorySetAllocArea(u64 virtual_addr, u64 size); + +class GPUObject { + public: + GPUObject() = default; + virtual ~GPUObject() = default; +}; + +void* memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, /*CommandBuffer* buffer*/void* todo, u64 virtual_addr, u64 size, + const GPUObject& info); + } // 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 e3624178..e07496c9 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 { @@ -10,7 +11,7 @@ enum class VideoOutBufferFormat : u64 { B8G8R8A8Srgb, }; -class VideoOutBufferObj { +class VideoOutBufferObj : public GPUObject { public: explicit VideoOutBufferObj(VideoOutBufferFormat pixel_format, u32 width, u32 height, bool is_tiled, bool is_neo, u32 pitch) { } diff --git a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h index c586063c..6ce3c755 100644 --- a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h +++ b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h @@ -2,6 +2,7 @@ #include #include #include +#include using namespace HLE::Libs::Graphics::VideoOut; @@ -59,9 +60,19 @@ class VideoOutCtx { int Open(); VideoConfigInternal* getCtx(int handle); FlipQueue& getFlipQueue() { return m_flip_queue; } + HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { + Lib::LockMutexGuard lock(m_mutex); + + if (m_graphic_ctx == nullptr) { + m_graphic_ctx = Emulator::getGraphicCtx(); + } + + return m_graphic_ctx; + } private: Lib::Mutex m_mutex; VideoConfigInternal m_video_out_ctx; FlipQueue m_flip_queue; + HLE::Libs::Graphics::GraphicCtx* m_graphic_ctx = nullptr; }; }; // namespace HLE::Graphics::Objects \ No newline at end of file diff --git a/src/Core/PS4/HLE/Graphics/video_out.cpp b/src/Core/PS4/HLE/Graphics/video_out.cpp index ac0749d1..52b1e034 100644 --- a/src/Core/PS4/HLE/Graphics/video_out.cpp +++ b/src/Core/PS4/HLE/Graphics/video_out.cpp @@ -15,6 +15,7 @@ #include "Objects/video_out_ctx.h" #include "Util/Singleton.h" #include "emulator.h" +#include namespace HLE::Libs::Graphics::VideoOut { @@ -162,7 +163,7 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co int registration_index = ctx->buffers_registration_index++; Emulator::checkAndWaitForGraphicsInit(); - // TODO Graphics::RenderCreateCxt(); + // TODO Graphics::RenderCreateCtx(); // try to calculate buffer size u64 buffer_size = 1280 * 720 * 4; // TODO hardcoded value should be redone @@ -197,7 +198,10 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co ctx->buffers[i + startIndex].buffer = addresses[i]; ctx->buffers[i + startIndex].buffer_size = buffer_size; ctx->buffers[i + startIndex].buffer_pitch = buffer_pitch; - // ctx->buffers[i + startIndex].buffer_vulkan = TODO!!! + ctx->buffers[i + startIndex].buffer_render = static_cast( + GPU::memoryCreateObj( + 0, videoOut->getGraphicCtx(), nullptr, reinterpret_cast(addresses[i]), buffer_size, buffer_info)); + LOG_INFO_IF(log_file_videoout, "buffers[{}] = {}\n", i + startIndex, reinterpret_cast(addresses[i])); } diff --git a/src/emulator.cpp b/src/emulator.cpp index 91d7b055..dc02102a 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -1,8 +1,9 @@ #include "emulator.h" -#include "Core/PS4/HLE/Graphics/video_out.h" -#include #include +#include + +#include "Core/PS4/HLE/Graphics/video_out.h" namespace Emulator { @@ -91,4 +92,12 @@ void emuRun() { } std::exit(0); } + +HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { + auto* window_ctx = Singleton::Instance(); + Lib::LockMutexGuard lock(window_ctx->m_mutex); + + return &window_ctx->m_graphic_ctx; +} + } // namespace Emulator \ No newline at end of file diff --git a/src/emulator.h b/src/emulator.h index 39e960e6..ff17a31f 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -79,4 +79,5 @@ struct EmuPrivate { void emuInit(u32 width, u32 height); void emuRun(); void checkAndWaitForGraphicsInit(); +HLE::Libs::Graphics::GraphicCtx* getGraphicCtx(); } // namespace Emulator \ No newline at end of file