From 133acdc120058a1879e8bd748dfc2f4c1ebf4cb7 Mon Sep 17 00:00:00 2001 From: psucien Date: Fri, 17 May 2024 23:31:55 +0200 Subject: [PATCH] video_out: added vblank event --- src/core/libraries/videoout/driver.cpp | 7 ++++++ src/core/libraries/videoout/driver.h | 1 + src/core/libraries/videoout/video_out.cpp | 27 +++++++++++++++++++++++ src/core/libraries/videoout/video_out.h | 1 + 4 files changed, 36 insertions(+) diff --git a/src/core/libraries/videoout/driver.cpp b/src/core/libraries/videoout/driver.cpp index cb4fecd3..d114b9c8 100644 --- a/src/core/libraries/videoout/driver.cpp +++ b/src/core/libraries/videoout/driver.cpp @@ -243,6 +243,13 @@ void VideoOutDriver::Vblank() { vblank_status.count++; vblank_status.processTime = Libraries::Kernel::sceKernelGetProcessTime(); vblank_status.tsc = Libraries::Kernel::sceKernelReadTsc(); + + // Trigger flip events for the port. + for (auto& event : main_port.vblank_events) { + if (event != nullptr) { + event->triggerEvent(SCE_VIDEO_OUT_EVENT_VBLANK, Kernel::EVFILT_VIDEO_OUT, nullptr); + } + } } } // namespace Libraries::VideoOut diff --git a/src/core/libraries/videoout/driver.h b/src/core/libraries/videoout/driver.h index f8b9ea81..5c2bef68 100644 --- a/src/core/libraries/videoout/driver.h +++ b/src/core/libraries/videoout/driver.h @@ -25,6 +25,7 @@ struct VideoOutPort { FlipStatus flip_status; SceVideoOutVblankStatus vblank_status; std::vector flip_events; + std::vector vblank_events; int flip_rate = 0; s32 FindFreeGroup() const { diff --git a/src/core/libraries/videoout/video_out.cpp b/src/core/libraries/videoout/video_out.cpp index 6f5ccc39..a1f971b5 100644 --- a/src/core/libraries/videoout/video_out.cpp +++ b/src/core/libraries/videoout/video_out.cpp @@ -60,6 +60,31 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Kernel::SceKernelEqueue eq, s32 handle, return eq->addEvent(event); } +s32 PS4_SYSV_ABI sceVideoOutAddVblankEvent(Kernel::SceKernelEqueue eq, s32 handle, void* udata) { + LOG_INFO(Lib_VideoOut, "handle = {}", handle); + + auto* port = driver->GetPort(handle); + if (port == nullptr) { + return ORBIS_VIDEO_OUT_ERROR_INVALID_HANDLE; + } + + if (eq == nullptr) { + return ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE; + } + + Kernel::EqueueEvent event{}; + event.isTriggered = false; + event.event.ident = SCE_VIDEO_OUT_EVENT_VBLANK; + event.event.filter = Kernel::EVFILT_VIDEO_OUT; + event.event.udata = udata; + event.event.fflags = 0; + event.event.data = 0; + event.filter.data = port; + + port->vblank_events.push_back(eq); + return eq->addEvent(event); +} + s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum, const BufferAttribute* attribute) { if (!addresses || !attribute) { @@ -243,6 +268,8 @@ void RegisterLib(Core::Loader::SymbolsResolver* sym) { sceVideoOutRegisterBuffers); LIB_FUNCTION("HXzjK9yI30k", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutAddFlipEvent); + LIB_FUNCTION("Xru92wHJRmg", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, + sceVideoOutAddVblankEvent); LIB_FUNCTION("CBiu4mCE1DA", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSetFlipRate); LIB_FUNCTION("i6-sR91Wt-4", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, diff --git a/src/core/libraries/videoout/video_out.h b/src/core/libraries/videoout/video_out.h index 00ea6afb..b36520a2 100644 --- a/src/core/libraries/videoout/video_out.h +++ b/src/core/libraries/videoout/video_out.h @@ -88,6 +88,7 @@ void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(BufferAttribute* attribute, Pixe u32 tilingMode, u32 aspectRatio, u32 width, u32 height, u32 pitchInPixel); s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Kernel::SceKernelEqueue eq, s32 handle, void* udata); +s32 PS4_SYSV_ABI sceVideoOutAddVBlankEvent(Kernel::SceKernelEqueue eq, s32 handle, void* udata); s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum, const BufferAttribute* attribute); s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate);