Readable VideoOutEvent data packing

Inspired by the work of former shadPS4 devs and mostly based on red_prig's current code.
This commit is contained in:
Stephen Miller 2025-04-26 18:13:29 -05:00
parent e816bc4b99
commit f2cebf7284

View File

@ -5,6 +5,7 @@
#include <condition_variable>
#include <mutex>
#include <bit>
#include <string>
#include <vector>
#include <boost/asio/steady_timer.hpp>
@ -61,6 +62,18 @@ struct SceKernelEvent {
void* udata = nullptr; /* opaque user data identifier */
};
struct DceHint {
u64 event_id : 8;
u64 video_id : 8;
u64 flip_arg : 48;
};
struct DceData {
u64 time : 12;
u64 count : 4;
u64 flip_arg : 48;
};
struct EqueueEvent {
SceKernelEvent event;
void* data = nullptr;
@ -84,19 +97,17 @@ struct EqueueEvent {
void TriggerDisplay(void* data) {
is_triggered = true;
auto hint = reinterpret_cast<u64>(data);
if (hint != 0) {
auto hint_h = static_cast<u32>(hint >> 8) & 0xFFFFFF;
auto ident_h = static_cast<u32>(event.ident >> 40);
if ((static_cast<u32>(hint) & 0xFF) == event.ident && event.ident != 0xFE &&
((hint_h ^ ident_h) & 0xFF) == 0) {
if (data != nullptr) {
auto event_data = static_cast<DceData>(event.data);
auto event_hint_raw = reinterpret_cast<u64>(data);
auto event_hint = static_cast<DceHint>(event_hint_raw);
if (event_hint.event_id == event.ident && event.ident != 0xfe) {
auto time = Common::FencedRDTSC();
auto mask = 0xF000;
if ((static_cast<u32>(event.data) & 0xF000) != 0xF000) {
mask = (static_cast<u32>(event.data) + 0x1000) & 0xF000;
auto counter = event_data.count;
if (counter != 0xf) {
counter++;
}
event.data = (mask | static_cast<u64>(static_cast<u32>(time) & 0xFFF) |
(hint & 0xFFFFFFFFFFFF0000));
event.data = (time & 0xfff) | (counter << 12) | (event_hint_raw & 0xffffffffffff);
}
}
}