mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-12-14 07:38:49 +00:00
core: Library cleanup (#1631)
* core: Split error codes into separate files * Reduces build times and is cleaner * core: Bring structs and enums to codebase style * core: More style changes
This commit is contained in:
@@ -8,10 +8,9 @@
|
||||
#include "common/debug.h"
|
||||
#include "common/thread.h"
|
||||
#include "core/debug_state.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/kernel/time.h"
|
||||
#include "core/libraries/videoout/driver.h"
|
||||
#include "core/platform.h"
|
||||
#include "core/libraries/videoout/videoout_error.h"
|
||||
#include "video_core/renderer_vulkan/vk_presenter.h"
|
||||
|
||||
extern std::unique_ptr<Vulkan::Presenter> presenter;
|
||||
@@ -42,10 +41,10 @@ constexpr u32 PixelFormatBpp(PixelFormat pixel_format) {
|
||||
}
|
||||
|
||||
VideoOutDriver::VideoOutDriver(u32 width, u32 height) {
|
||||
main_port.resolution.fullWidth = width;
|
||||
main_port.resolution.fullHeight = height;
|
||||
main_port.resolution.paneWidth = width;
|
||||
main_port.resolution.paneHeight = height;
|
||||
main_port.resolution.full_width = width;
|
||||
main_port.resolution.full_height = height;
|
||||
main_port.resolution.pane_width = width;
|
||||
main_port.resolution.pane_height = height;
|
||||
present_thread = std::jthread([&](std::stop_token token) { PresentThread(token); });
|
||||
}
|
||||
|
||||
@@ -174,20 +173,21 @@ void VideoOutDriver::Flip(const Request& req) {
|
||||
std::unique_lock lock{port->port_mutex};
|
||||
auto& flip_status = port->flip_status;
|
||||
flip_status.count++;
|
||||
flip_status.processTime = Libraries::Kernel::sceKernelGetProcessTime();
|
||||
flip_status.process_time = Libraries::Kernel::sceKernelGetProcessTime();
|
||||
flip_status.tsc = Libraries::Kernel::sceKernelReadTsc();
|
||||
flip_status.flipArg = req.flip_arg;
|
||||
flip_status.currentBuffer = req.index;
|
||||
flip_status.flip_arg = req.flip_arg;
|
||||
flip_status.current_buffer = req.index;
|
||||
if (req.eop) {
|
||||
--flip_status.gcQueueNum;
|
||||
--flip_status.gc_queue_num;
|
||||
}
|
||||
--flip_status.flipPendingNum;
|
||||
--flip_status.flip_pending_num;
|
||||
}
|
||||
|
||||
// Trigger flip events for the port.
|
||||
for (auto& event : port->flip_events) {
|
||||
if (event != nullptr) {
|
||||
event->TriggerEvent(SCE_VIDEO_OUT_EVENT_FLIP, Kernel::SceKernelEvent::Filter::VideoOut,
|
||||
event->TriggerEvent(u64(OrbisVideoOutEventId::Flip),
|
||||
Kernel::SceKernelEvent::Filter::VideoOut,
|
||||
reinterpret_cast<void*>(req.flip_arg));
|
||||
}
|
||||
}
|
||||
@@ -211,16 +211,16 @@ bool VideoOutDriver::SubmitFlip(VideoOutPort* port, s32 index, s64 flip_arg,
|
||||
bool is_eop /*= false*/) {
|
||||
{
|
||||
std::unique_lock lock{port->port_mutex};
|
||||
if (index != -1 && port->flip_status.flipPendingNum >= port->NumRegisteredBuffers()) {
|
||||
if (index != -1 && port->flip_status.flip_pending_num >= port->NumRegisteredBuffers()) {
|
||||
LOG_ERROR(Lib_VideoOut, "Flip queue is full");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_eop) {
|
||||
++port->flip_status.gcQueueNum;
|
||||
++port->flip_status.gc_queue_num;
|
||||
}
|
||||
++port->flip_status.flipPendingNum; // integral GPU and CPU pending flips counter
|
||||
port->flip_status.submitTsc = Libraries::Kernel::sceKernelReadTsc();
|
||||
++port->flip_status.flip_pending_num; // integral GPU and CPU pending flips counter
|
||||
port->flip_status.submit_tsc = Libraries::Kernel::sceKernelReadTsc();
|
||||
}
|
||||
|
||||
if (!is_eop) {
|
||||
@@ -298,9 +298,9 @@ void VideoOutDriver::PresentThread(std::stop_token token) {
|
||||
|
||||
{
|
||||
// Needs lock here as can be concurrently read by `sceVideoOutGetVblankStatus`
|
||||
std::unique_lock lock{main_port.vo_mutex};
|
||||
std::scoped_lock lock{main_port.vo_mutex};
|
||||
vblank_status.count++;
|
||||
vblank_status.processTime = Libraries::Kernel::sceKernelGetProcessTime();
|
||||
vblank_status.process_time = Libraries::Kernel::sceKernelGetProcessTime();
|
||||
vblank_status.tsc = Libraries::Kernel::sceKernelReadTsc();
|
||||
main_port.vblank_cv.notify_all();
|
||||
}
|
||||
@@ -308,7 +308,7 @@ void VideoOutDriver::PresentThread(std::stop_token token) {
|
||||
// Trigger flip events for the port.
|
||||
for (auto& event : main_port.vblank_events) {
|
||||
if (event != nullptr) {
|
||||
event->TriggerEvent(SCE_VIDEO_OUT_EVENT_VBLANK,
|
||||
event->TriggerEvent(u64(OrbisVideoOutEventId::Vblank),
|
||||
Kernel::SceKernelEvent::Filter::VideoOut, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
#include "common/assert.h"
|
||||
#include "common/config.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/system/userservice.h"
|
||||
#include "core/libraries/videoout/driver.h"
|
||||
#include "core/libraries/videoout/video_out.h"
|
||||
#include "core/loader/symbols_resolver.h"
|
||||
#include "core/libraries/videoout/videoout_error.h"
|
||||
#include "core/platform.h"
|
||||
#include "video_core/renderer_vulkan/vk_presenter.h"
|
||||
|
||||
@@ -51,7 +50,7 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Kernel::SceKernelEqueue eq, s32 handle,
|
||||
}
|
||||
|
||||
Kernel::EqueueEvent event{};
|
||||
event.event.ident = SCE_VIDEO_OUT_EVENT_FLIP;
|
||||
event.event.ident = u64(OrbisVideoOutEventId::Flip);
|
||||
event.event.filter = Kernel::SceKernelEvent::Filter::VideoOut;
|
||||
// The library only sets EV_ADD but kernel driver forces EV_CLEAR
|
||||
event.event.flags = Kernel::SceKernelEvent::Flags::Clear;
|
||||
@@ -78,7 +77,7 @@ s32 PS4_SYSV_ABI sceVideoOutAddVblankEvent(Kernel::SceKernelEqueue eq, s32 handl
|
||||
}
|
||||
|
||||
Kernel::EqueueEvent event{};
|
||||
event.event.ident = SCE_VIDEO_OUT_EVENT_VBLANK;
|
||||
event.event.ident = u64(OrbisVideoOutEventId::Vblank);
|
||||
event.event.filter = Kernel::SceKernelEvent::Filter::VideoOut;
|
||||
// The library only sets EV_ADD but kernel driver forces EV_CLEAR
|
||||
event.event.flags = Kernel::SceKernelEvent::Flags::Clear;
|
||||
@@ -118,7 +117,7 @@ s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle) {
|
||||
LOG_TRACE(Lib_VideoOut, "called");
|
||||
auto* port = driver->GetPort(handle);
|
||||
std::unique_lock lock{port->port_mutex};
|
||||
s32 pending = port->flip_status.flipPendingNum;
|
||||
s32 pending = port->flip_status.flip_pending_num;
|
||||
return pending;
|
||||
}
|
||||
|
||||
@@ -156,7 +155,7 @@ s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode
|
||||
|
||||
int PS4_SYSV_ABI sceVideoOutGetEventId(const Kernel::SceKernelEvent* ev) {
|
||||
if (ev == nullptr) {
|
||||
return SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS;
|
||||
return ORBIS_VIDEO_OUT_ERROR_INVALID_ADDRESS;
|
||||
}
|
||||
if (ev->filter != Kernel::SceKernelEvent::Filter::VideoOut) {
|
||||
return ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE;
|
||||
@@ -166,7 +165,7 @@ int PS4_SYSV_ABI sceVideoOutGetEventId(const Kernel::SceKernelEvent* ev) {
|
||||
|
||||
int PS4_SYSV_ABI sceVideoOutGetEventData(const Kernel::SceKernelEvent* ev, int64_t* data) {
|
||||
if (ev == nullptr || data == nullptr) {
|
||||
return SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS;
|
||||
return ORBIS_VIDEO_OUT_ERROR_INVALID_ADDRESS;
|
||||
}
|
||||
if (ev->filter != Kernel::SceKernelEvent::Filter::VideoOut) {
|
||||
return ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE;
|
||||
@@ -204,7 +203,7 @@ s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, FlipStatus* status) {
|
||||
|
||||
s32 PS4_SYSV_ABI sceVideoOutGetVblankStatus(int handle, SceVideoOutVblankStatus* status) {
|
||||
if (status == nullptr) {
|
||||
return SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS;
|
||||
return ORBIS_VIDEO_OUT_ERROR_INVALID_ADDRESS;
|
||||
}
|
||||
|
||||
auto* port = driver->GetPort(handle);
|
||||
|
||||
@@ -40,36 +40,32 @@ constexpr int SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_NONE = 0;
|
||||
constexpr int SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_VR = 7;
|
||||
constexpr int SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_STRICT_COLORIMETRY = 8;
|
||||
|
||||
enum SceVideoOutEventId : s16 {
|
||||
SCE_VIDEO_OUT_EVENT_FLIP = 0,
|
||||
SCE_VIDEO_OUT_EVENT_VBLANK = 1,
|
||||
SCE_VIDEO_OUT_EVENT_PRE_VBLANK_START = 2
|
||||
};
|
||||
enum class OrbisVideoOutEventId : s16 { Flip = 0, Vblank = 1, PreVblankStart = 2 };
|
||||
|
||||
enum AspectRatioMode : s32 {
|
||||
SCE_VIDEO_OUT_ASPECT_RATIO_16_9 = 0,
|
||||
enum class AspectRatioMode : s32 {
|
||||
Ratio16_9 = 0,
|
||||
};
|
||||
|
||||
struct FlipStatus {
|
||||
u64 count = 0;
|
||||
u64 processTime = 0;
|
||||
u64 process_time = 0;
|
||||
u64 tsc = 0;
|
||||
s64 flipArg = -1;
|
||||
u64 submitTsc = 0;
|
||||
s64 flip_arg = -1;
|
||||
u64 submit_tsc = 0;
|
||||
u64 reserved0 = 0;
|
||||
s32 gcQueueNum = 0;
|
||||
s32 flipPendingNum = 0;
|
||||
s32 currentBuffer = -1;
|
||||
s32 gc_queue_num = 0;
|
||||
s32 flip_pending_num = 0;
|
||||
s32 current_buffer = -1;
|
||||
u32 reserved1 = 0;
|
||||
};
|
||||
|
||||
struct SceVideoOutResolutionStatus {
|
||||
s32 fullWidth = 1280;
|
||||
s32 fullHeight = 720;
|
||||
s32 paneWidth = 1280;
|
||||
s32 paneHeight = 720;
|
||||
u64 refreshRate = SCE_VIDEO_OUT_REFRESH_RATE_59_94HZ;
|
||||
float screenSizeInInch = 50;
|
||||
s32 full_width = 1280;
|
||||
s32 full_height = 720;
|
||||
s32 pane_width = 1280;
|
||||
s32 pane_height = 720;
|
||||
u64 refresh_rate = SCE_VIDEO_OUT_REFRESH_RATE_59_94HZ;
|
||||
float screen_size_in_inch = 50;
|
||||
u16 flags = 0;
|
||||
u16 reserved0 = 0;
|
||||
u32 reserved1[3] = {0};
|
||||
@@ -77,7 +73,7 @@ struct SceVideoOutResolutionStatus {
|
||||
|
||||
struct SceVideoOutVblankStatus {
|
||||
u64 count = 0;
|
||||
u64 processTime = 0;
|
||||
u64 process_time = 0;
|
||||
u64 tsc = 0;
|
||||
u64 reserved[1] = {0};
|
||||
u8 flags = 0;
|
||||
|
||||
35
src/core/libraries/videoout/videoout_error.h
Normal file
35
src/core/libraries/videoout/videoout_error.h
Normal file
@@ -0,0 +1,35 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/libraries/error_codes.h"
|
||||
|
||||
// VideoOut library
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_PIXEL_FORMAT = 0x80290003;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_PITCH = 0x80290004;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_RESOLUTION = 0x80290005;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_FLIP_MODE = 0x80290006;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_TILING_MODE = 0x80290007;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_ASPECT_RATIO = 0x80290008;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_RESOURCE_BUSY = 0x80290009;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_INDEX = 0x8029000A;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_HANDLE = 0x8029000B;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE = 0x8029000C;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT = 0x8029000D;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_NO_EMPTY_SLOT = 0x8029000F;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_MEMORY = 0x80290013;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_MEMORY_NOT_PHYSICALLY_CONTIGUOUS = 0x80290014;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_MEMORY_INVALID_ALIGNMENT = 0x80290015;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_UNSUPPORTED_OUTPUT_MODE = 0x80290016;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_OVERFLOW = 0x80290017;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_NO_DEVICE = 0x80290018;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_UNAVAILABLE_OUTPUT_MODE = 0x80290019;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_UNKNOWN = 0x802900FE;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_FATAL = 0x802900FF;
|
||||
constexpr int ORBIS_VIDEO_OUT_ERROR_ENOMEM = 0x8029100C;
|
||||
Reference in New Issue
Block a user