event queue events now process nicely

This commit is contained in:
georgemoralis 2023-09-11 13:14:13 +03:00
parent 0c39b808bf
commit ab932e7503
7 changed files with 82 additions and 6 deletions

View File

@ -1,4 +1,5 @@
#include "video_out_ctx.h"
#include <Core/PS4/HLE/LibKernel.h>
namespace HLE::Graphics::Objects {
@ -62,5 +63,41 @@ bool FlipQueue::submitFlip(VideoConfigInternal* cfg, s32 index, s64 flip_arg) {
return true;
}
}; // namespace HLE::Graphics::Objects
bool FlipQueue::flip(u32 micros) {
m_mutex.LockMutex();
if (m_requests.size() == 0) {
m_submit_cond.WaitCondVarFor(&m_mutex, micros);
if (m_requests.size() == 0) {
m_mutex.UnlockMutex();
return false;
}
}
auto request = m_requests.at(0); // proceed first request
m_mutex.UnlockMutex();
request.cfg->m_mutex.LockMutex();
for (auto& flip_eq : request.cfg->m_flip_evtEq) {
if (flip_eq != nullptr) {
flip_eq->triggerEvent(SCE_VIDEO_OUT_EVENT_FLIP, HLE::Kernel::Objects::EVFILT_VIDEO_OUT, reinterpret_cast<void*>(request.flip_arg));
}
}
request.cfg->m_mutex.UnlockMutex();
m_requests.erase(m_requests.begin());
m_done_cond.SignalCondVar();
request.cfg->m_flip_status.count++;
//TODO request.cfg->m_flip_status.processTime = LibKernel::KernelGetProcessTime();
request.cfg->m_flip_status.tsc = HLE::Libs::LibKernel::sceKernelReadTsc();
request.cfg->m_flip_status.submitTsc = request.submit_tsc;
request.cfg->m_flip_status.flipArg = request.flip_arg;
request.cfg->m_flip_status.currentBuffer = request.index;
request.cfg->m_flip_status.flipPendingNum = static_cast<int>(m_requests.size());
m_mutex.UnlockMutex();
return false;
}
}; // namespace HLE::Graphics::Objects

View File

@ -25,6 +25,7 @@ class FlipQueue {
void getFlipStatus(VideoConfigInternal* cfg, SceVideoOutFlipStatus* out);
bool submitFlip(VideoConfigInternal* cfg, s32 index, s64 flip_arg);
bool flip(u32 micros);
private:
struct Request {
VideoConfigInternal* cfg;

View File

@ -21,6 +21,12 @@ void videoOutInit(u32 width, u32 height) {
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
videoOut->Init(width, height);
}
bool videoOutFlip(u32 micros) {
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
return videoOut->getFlipQueue().flip(micros);
}
std::string getPixelFormatString(s32 format) {
switch (format) {
case SCE_VIDEO_OUT_PIXEL_FORMAT_A8R8G8B8_SRGB: return "PIXEL_FORMAT_A8R8G8B8_SRGB";
@ -64,6 +70,15 @@ static void flip_reset_event_func(HLE::Kernel::Objects::EqueueEvent* event) {
event->event.fflags = 0;
event->event.data = 0;
}
static void flip_trigger_event_func(HLE::Kernel::Objects::EqueueEvent* event, void* trigger_data) {
event->isTriggered = true;
event->event.fflags++;
event->event.data = reinterpret_cast<intptr_t>(trigger_data);
}
static void flip_delete_event_func(LibKernel::EventQueues::SceKernelEqueue eq, HLE::Kernel::Objects::EqueueEvent* event) {
BREAKPOINT(); // TODO
}
s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue eq, s32 handle, void* udata) {
PRINT_FUNCTION_NAME();
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
@ -86,9 +101,9 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue
event.event.udata = udata;
event.event.fflags = 0;
event.event.data = 0;
// event.filter.delete_event_func = flip_event_delete_func;//called in sceKernelDeleteEvent //TODO
event.filter.delete_event_func = flip_delete_event_func;
event.filter.reset_event_func = flip_reset_event_func;
// event.filter.trigger_event_func = flip_event_trigger_func;//called in sceKernelTriggerEvent //TODO
event.filter.trigger_event_func = flip_trigger_event_func;
event.filter.data = ctx;
int result = eq->addEvent(event);

View File

@ -90,6 +90,7 @@ struct SceVideoOutVblankStatus {
void videoOutInit(u32 width, u32 height);
std::string getPixelFormatString(s32 format);
void videoOutRegisterLib(SymbolsResolver* sym);
bool videoOutFlip(u32 micros);
void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attribute, u32 pixelFormat, u32 tilingMode, u32 aspectRatio, u32 width,
u32 height, u32 pitchInPixel);

View File

@ -49,6 +49,25 @@ int EqueueInternal::waitForEvents(SceKernelEvent* ev, int num, u32 micros) {
return 0;
}
bool EqueueInternal::triggerEvent(u64 ident, s16 filter, void* trigger_data) {
Lib::LockMutexGuard lock(m_mutex);
if (m_events.size() > 1) {
BREAKPOINT(); // we currently support one event
}
auto& event = m_events[0];
if (event.filter.trigger_event_func != nullptr) {
event.filter.trigger_event_func(&event, trigger_data);
} else {
event.isTriggered = true;
}
m_cond.SignalCondVar();
return true;
}
int EqueueInternal::getTriggeredEvents(SceKernelEvent* ev, int num) {
Lib::LockMutexGuard lock(m_mutex);

View File

@ -67,6 +67,7 @@ class EqueueInternal {
void setName(const std::string& m_name) { this->m_name = m_name; }
int addEvent(const EqueueEvent& event);
int waitForEvents(SceKernelEvent* ev, int num, u32 micros);
bool triggerEvent(u64 ident, s16 filter, void* trigger_data);
int getTriggeredEvents(SceKernelEvent* ev, int num);
private:
std::string m_name;

View File

@ -1,9 +1,11 @@
#include "emulator.h"
#include "Core/PS4/HLE/Graphics/video_out.h"
namespace Emulator {
void emuInit() {}
void emuRun() {
for (;;) {
HLE::Libs::Graphics::VideoOut::videoOutFlip(100000);//flip every 0.1 sec
}
}
} // namespace emulator