Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions core/libs/prx/libSceVideoOut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ if(BUILD_TESTING)
set_tests_properties(guest_video_out_high_frame_rate PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
add_test_executable(guest_video_out_cursor_tests ${LIBS_INCLUDE_DIR}/tests/GuestVideoOutCursor.cpp)
target_include_directories(guest_video_out_cursor_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_video_out_cursor_tests PRIVATE libSceVideoOut libkernel libc)
configure_windows_unwind(guest_video_out_cursor_tests)
add_test(NAME guest_video_out_cursor COMMAND guest_video_out_cursor_tests)
set_tests_properties(guest_video_out_cursor PROPERTIES TIMEOUT 20)
if(WIN32)
set_tests_properties(guest_video_out_cursor PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
if(WIN32)
set(videoOutTestDriver "windows")
else()
Expand All @@ -102,7 +92,7 @@ if(BUILD_TESTING)
endforeach()

set_target_properties(video_out_flip_tests PROPERTIES EXCLUDE_FROM_ALL OFF)
foreach(flipMode IN ITEMS lifetime reopen decode controls overlay unopened ps4 resolution resolution_override)
foreach(flipMode IN ITEMS lifetime reopen decode controls overlay unopened ps4 resolution resolution_override fresh)
if(flipMode STREQUAL "lifetime")
add_test(NAME video_out_flip_${flipMode} COMMAND video_out_flip_tests)
else()
Expand Down
20 changes: 0 additions & 20 deletions core/libs/prx/libSceVideoOut/Unimplemented.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,6 @@ int APS5_VABI sceVideoOutClearFlipMaster(std::int32_t handle) {
return 0;
}

int APS5_VABI sceVideoOutCursorEnable(int32_t, int32_t, const void*) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI sceVideoOutCursorDisable(int32_t, int32_t) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI sceVideoOutCursorSetImageAddress(int32_t, int32_t, const void*) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI sceVideoOutCursorSetPosition(int32_t, int32_t, uint32_t, uint32_t) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI sceDbgVideoOutAddOutputModeVr60Privilege() {
NotImplemented_nid_no_patch(__func__);
return 0;
Expand Down
50 changes: 43 additions & 7 deletions core/libs/prx/libSceVideoOut/src/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ int APS5_VABI sceVideoOutSetFlipRate(int handle, int rate) try {
}

int APS5_VABI sceVideoOutGetFlipStatus(int handle, VideoOutFlipStatus* status) try {
const bool open = VideoOutDriver::Get().HasConfig(handle);
if (status == nullptr) {
throw std::runtime_error(std::string(__func__) + ": VIDEO_OUT_ERROR_INVALID_ADDRESS");
if (!open) {
throw std::runtime_error(std::string(__func__) + ": a null output with an invalid handle is not measured");
}
return VIDEO_OUT_ERROR_INVALID_ADDRESS;
}
if (!open) return VIDEO_OUT_ERROR_INVALID_HANDLE;
auto cfg = VideoOutDriver::Get().GetConfig(handle);
if (cfg == nullptr) {
throw std::runtime_error(std::string(__func__) + ": VIDEO_OUT_ERROR_INVALID_HANDLE");
}
std::unique_lock lock(cfg->mutex);
cfg->Check();
if (cfg->ps4) {
Expand Down Expand Up @@ -225,17 +227,51 @@ int APS5_VABI sceVideoOutGetResolutionStatus(int handle, VideoOutResolutionStatu
}

int APS5_VABI sceVideoOutIsFlipPending(int handle) try {
if (!VideoOutDriver::Get().HasConfig(handle)) return VIDEO_OUT_ERROR_INVALID_HANDLE;
auto cfg = VideoOutDriver::Get().GetConfig(handle);
if (cfg == nullptr) {
throw std::runtime_error(std::string(__func__) + ": VIDEO_OUT_ERROR_INVALID_HANDLE");
}
std::unique_lock lock(cfg->mutex);
cfg->Check();
return cfg->flipStatus.flipPendingNum;
} catch (const ProcessShutdown&) {
LibcAwaitExit_nid_postfix();
}

static int cursorHandleError(const char* function, int handle, int index) {
if (index != 0) NotImplemented_nid_no_patch(function);
if (!VideoOutDriver::Get().HasConfig(handle)) return VIDEO_OUT_ERROR_INVALID_HANDLE;
return 0;
}

int APS5_VABI sceVideoOutCursorEnable(int32_t handle, int32_t index, const void* address) try {
if (const int error = cursorHandleError(__func__, handle, index)) return error;
if (address == nullptr) return VIDEO_OUT_ERROR_INVALID_ADDRESS;
NotImplemented_nid_no_patch(__func__);
} catch (const ProcessShutdown&) {
LibcAwaitExit_nid_postfix();
}

int APS5_VABI sceVideoOutCursorDisable(int32_t handle, int32_t index) try {
if (const int error = cursorHandleError(__func__, handle, index)) return error;
return 0;
} catch (const ProcessShutdown&) {
LibcAwaitExit_nid_postfix();
}

int APS5_VABI sceVideoOutCursorSetImageAddress(int32_t handle, int32_t index, const void* address) try {
if (const int error = cursorHandleError(__func__, handle, index)) return error;
if (address == nullptr) return VIDEO_OUT_ERROR_INVALID_ADDRESS;
NotImplemented_nid_no_patch(__func__);
} catch (const ProcessShutdown&) {
LibcAwaitExit_nid_postfix();
}

int APS5_VABI sceVideoOutCursorSetPosition(int32_t handle, int32_t index, uint32_t, uint32_t) try {
if (const int error = cursorHandleError(__func__, handle, index)) return error;
return 0;
} catch (const ProcessShutdown&) {
LibcAwaitExit_nid_postfix();
}

int APS5_VABI sceVideoOutWaitVblank(int handle) try {
auto cfg = VideoOutDriver::Get().GetConfig(handle);
if (cfg == nullptr) {
Expand Down
34 changes: 34 additions & 0 deletions core/libs/prx/libSceVideoOut/tests/Flip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,39 @@ void testOneDevice() {
check(next.Serial() == 2, "the GPU work and the flip used more than one device");
}

void testFreshHandleCalls() {
static_assert(sizeof(VideoOutFlipStatus) == 128);
const int handle = sceVideoOutOpen(255, 0, 0, nullptr);
std::array<std::byte, 128> raw;
raw.fill(std::byte{0xaa});
check(sceVideoOutGetFlipStatus(handle, reinterpret_cast<VideoOutFlipStatus*>(raw.data())) == 0, "the flip status of a fresh handle was not returned");
std::array<std::byte, 128> expected{};
std::fill_n(expected.begin() + 24, 8, std::byte{0xff});
std::fill_n(expected.begin() + 56, 4, std::byte{0xff});
check(raw == expected, "a fresh handle's flip status differs from the measured bytes");
check(sceVideoOutGetFlipStatus(handle, nullptr) == VIDEO_OUT_ERROR_INVALID_ADDRESS, "a null flip status output was accepted");
check(sceVideoOutIsFlipPending(handle) == 0, "a fresh handle reported a pending flip");

const std::uint32_t image[64 * 64] = {};
check(sceVideoOutCursorEnable(handle, 0, nullptr) == VIDEO_OUT_ERROR_INVALID_ADDRESS, "a cursor was enabled without an image address");
check(sceVideoOutCursorSetPosition(handle, 0, 100, 100) == 0, "the cursor position was refused");
check(sceVideoOutCursorSetImageAddress(handle, 0, nullptr) == VIDEO_OUT_ERROR_INVALID_ADDRESS, "a null cursor image address was accepted");
check(sceVideoOutCursorDisable(handle, 0) == 0, "the cursor was not disabled");

std::array<std::byte, 128> untouched;
untouched.fill(std::byte{0xaa});
check(sceVideoOutGetFlipStatus(-1, reinterpret_cast<VideoOutFlipStatus*>(untouched.data())) == VIDEO_OUT_ERROR_INVALID_HANDLE, "an invalid handle's flip status was returned");
check(std::all_of(untouched.begin(), untouched.end(), [](std::byte value) { return value == std::byte{0xaa}; }), "an invalid handle's flip status wrote the output");
check(sceVideoOutIsFlipPending(-1) == VIDEO_OUT_ERROR_INVALID_HANDLE, "an invalid handle's pending flip was reported");
check(sceVideoOutCursorEnable(-1, 0, nullptr) == VIDEO_OUT_ERROR_INVALID_HANDLE, "an invalid handle was checked after the cursor image address");
check(sceVideoOutCursorEnable(-1, 0, image) == VIDEO_OUT_ERROR_INVALID_HANDLE, "a cursor was enabled on an invalid handle");
check(sceVideoOutCursorSetPosition(-1, 0, 100, 100) == VIDEO_OUT_ERROR_INVALID_HANDLE, "an invalid handle's cursor was positioned");
check(sceVideoOutCursorSetImageAddress(-1, 0, nullptr) == VIDEO_OUT_ERROR_INVALID_HANDLE, "an invalid handle's cursor image was set");
check(sceVideoOutCursorDisable(-1, 0) == VIDEO_OUT_ERROR_INVALID_HANDLE, "an invalid handle's cursor was disabled");
check(sceVideoOutClose(handle) == 0, "the fresh handle was not closed");
LibcRunShutdown_nid_postfix();
}

void testOutputResolution() {
const int handle = sceVideoOutOpen(255, 0, 0, nullptr);
auto cfg = VideoOutDriver::Get().GetConfig(handle);
Expand Down Expand Up @@ -1137,6 +1170,7 @@ int main(int argc, char** argv) {
else if (argc == 2 && std::string(argv[1]) == "cpuflip") testCpuFlipOrder();
else if (argc == 2 && std::string(argv[1]) == "resolution") testOutputResolution();
else if (argc == 2 && std::string(argv[1]) == "resolution_override") testOutputResolutionOverride();
else if (argc == 2 && std::string(argv[1]) == "fresh") testFreshHandleCalls();
else testLifetime(argc == 2 && std::string(argv[1]) == "reopen");
std::puts("VideoOut flip tests passed");
return 0;
Expand Down
29 changes: 0 additions & 29 deletions core/libs/tests/GuestVideoOutCursor.cpp

This file was deleted.

5 changes: 3 additions & 2 deletions docs/dev/debt/libSceVideoOut.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

### Unknown function info

- PPSA29866 imports declared without parameters, signatures unknown, added without an implementation because the title fails to load without them: [sceVideoOutSetFlipMaster and sceVideoOutClearFlipMaster](../../../core/libs/prx/libSceVideoOut/Unimplemented.cpp) (libSceVideoOut)
- PPSA29866 imports declared without parameters, signatures unknown, added without an implementation because the title fails to load without them: [sceVideoOutSetFlipMaster and sceVideoOutClearFlipMaster](../../../core/libs/prx/libSceVideoOut/Unimplemented.cpp) (libSceVideoOut) - the shapes and what flip-master ownership means are unknown, so both report that they are not implemented. Measured in a payload process on a PS5 (firmware 12.70) on a handle from `sceVideoOutOpen(0xff, 0, 0, NULL)`: `sceVideoOutSetFlipMaster` with (handle), (handle, 0) and (handle, 1) returned 0x8029000b, `sceVideoOutClearFlipMaster(handle)` returned 0x8029001c, and both returned 0x8029000b for handle -1
- [sceVideoOutColorSpaceConversionSettingsSetDefaultSdrToHdrConversion_, sceVideoOutColorSpaceConversionSettingsSetSdrToHdrConversion_, sceVideoOutAdjustColorSpaceConversion_, sceVideoOutSetGlobalBlendSpace](../../../core/libs/prx/libSceVideoOut/src/Output.cpp) (libSceVideoOut) - PPSA30630 imports these to configure color space conversion and global blend space. Color space conversion settings are accepted with size validation (32 bytes) but conversion blocks and blend space parameters are not applied to the presentation swapchain
- [sceVideoOutDeleteVrrActiveStatusEvent](../../../core/libs/prx/libSceVideoOut/src/Event.cpp) (libSceVideoOut, NID `-q-vbO859Tw`) - the name hashes to the NID PPSA02530 imports and is listed in [sce_symbols](https://github.com/zecoxao/sce_symbols) `aerolib.csv` at `fe2cc2948e`. The signature `(eq, handle)` and the behaviour, removing the handle's VRR status registration from the queue as the other `Delete*Event` calls do, follow sceVideoOutAddVrrActiveStatusEvent; no title has been observed calling it
- [sceVideoOutCursorEnable, sceVideoOutCursorDisable, sceVideoOutCursorSetImageAddress, sceVideoOutCursorSetPosition](../../../core/libs/prx/libSceVideoOut/Unimplemented.cpp) (libSceVideoOut, NIDs `UPZWCH8qTM4`, `fEPEwROdCwM`, `u-9bhWQApq8`, `N17AK88NdD0`) - the names hash to the NIDs Prospero Win (PPSA99995) imports, and the parameter lists `(handle, index, address)`, `(handle, index)`, `(handle, index, address)` and `(handle, index, x, y)` follow its [declarations](https://github.com/mpereiraesaa/prospero-win/blob/644e32e400c555e340d507383398c5d21b39b0b0/wine/ps5/pw_vulkan_radv.c#L65-L68). The cursor image's format and size and the console's return values are not known; the functions report that they are not implemented.
- [sceVideoOutCursorEnable, sceVideoOutCursorDisable, sceVideoOutCursorSetImageAddress, sceVideoOutCursorSetPosition](../../../core/libs/prx/libSceVideoOut/src/Output.cpp) - no cursor is shown: the image format and size are unknown, so a non-null image address and a cursor index other than 0 report not implemented, and `CursorSetPosition` returns 0 for every position but only (100, 100) was measured. Measured in a payload process on a PS5 (firmware 12.70) on a handle from `sceVideoOutOpen(0xff, 0, 0, NULL)` with no buffer registered: `CursorEnable` and `CursorSetImageAddress` with (handle, 0, NULL) returned 0x80290002, `CursorSetPosition(handle, 0, 100, 100)` and `CursorDisable(handle, 0)` returned 0, and all four returned 0x8029000b for handle -1. A closed handle is unmeasured and answered like -1. Parameters follow Prospero Win's [declarations](https://github.com/mpereiraesaa/prospero-win/blob/644e32e400c555e340d507383398c5d21b39b0b0/wine/ps5/pw_vulkan_radv.c#L65-L68).
- [sceVideoOutGetOutputStatusWithVrr](../../../core/libs/prx/libSceVideoOut/src/Output.cpp) (libSceVideoOut, NID `gWT7X8H0bYs`) - bytes 48-53 are written as zero, where a PS5 (firmware 13.40, measured 2026-10-19 inside a retail title) with a 4K TV that takes 120 Hz returned the 16-bit values 48, 60 and 60 (0x30, 0x3C, 0x3C); their meaning is not established, so the value at byte 52 never adjusts `refreshRate`. `(int handle, void* status)`, the 80-byte layout and the return codes follow the clean-room description in #2746: bytes 0-47 are `sceVideoOutGetOutputStatus`'s and the rest 0, a null `status` returns `0x80290002` and an unknown handle `0x8029000B`, all as that console answered. The console's earlier global-flag check (`0x8029001C`) and its object-field check (`0x8029001B`) test states that are not modelled and are never reported.
- [sceVideoOutRegisterBuffers2](../../../core/libs/prx/libSceVideoOut/src/Buffer.cpp) (libSceVideoOut) - buffer option 8 (STRICT_COLORIMETRY) is presented as option 0, with the stored values unchanged; what the console changes for it is unknown. Only options 0 and 8 are accepted
- [sceVideoOutAddBufferAttributeOption](../../../core/libs/prx/libSceVideoOut/src/Buffer.cpp) (libSceVideoOut, NID `MBlv8YWoyOk`) - the signature `(VideoOutBufferAttribute2*, uint64_t option)` comes from [SharpProspero](https://github.com/SvenGDK/SharpProspero/blob/60977b29103452b9681ae10c7a9011d44965bf16/src/SharpProspero/Interop/VideoOut/VideoOut.cs#L174-L176) and the call site in PPSA25380, which passes 0x20 and ignores the result. The option is ORed into `attribute->option`; whether the console validates the bits, keeps them elsewhere or fails on an unknown option is unknown. A null attribute throws. Option 0x20 makes `sceVideoOutRegisterBuffers2` throw, as every option other than 0 and 8; what it selects for an overlay buffer is unknown
Expand All @@ -27,6 +27,7 @@
- [sceVideoOutGetVblankStatus](../../../core/libs/prx/libSceVideoOut/src/Output.cpp) (libSceVideoOut) - the third 64-bit word of the PS5 status (`reserved` in [SceTypes.hpp](../../../core/libs/SceTypes.hpp)) is written 0. On a PS5 (firmware 13.40, measured 2026-10-19) a retail title's own call, caught inside it, got count 0xb16b, `processTime` 0x381a8790 (941 s), third word 0x1c485ffaadc, `processTimeCounter` 0x15dd63c364b, flags 0x04 and phase 0: the third word is a running counter, about 970 s at ~2 GHz, consistent with a TSC, not zero. Its clock and what it counts from are not established. Closes when: the third word's source is measured and written
- [sceVideoOutAddPreVblankStartEvent](../../../core/libs/prx/libSceVideoOut/src/Event.cpp) (libSceVideoOut) - how long before the vblank the console signals pre-vblank start is unknown. The event is triggered on each emulated vblank tick immediately before the vblank event, with its own count as the event data
- [sceVideoOutRegisterBuffers, sceVideoOutGetFlipStatus, sceVideoOutGetVblankStatus](../../../core/libs/prx/libSceVideoOut/src/Buffer.cpp) (libSceVideoOut) - PS4 callers. A handle is treated as PS4 once buffers are registered through the PS4 `sceVideoOutRegisterBuffers`; from then on its flip and vblank status are written in the PS4 64- and 32-byte layouts, with `tsc` and `submitTsc` 0. A PS4 title that reads a status before it registers buffers gets the larger PS5 layout. The PS4 function accepts only linear A8R8G8B8_SRGB (0x80000000) and A8B8G8R8_SRGB (0x80002200) buffers without options; tiled PS4 buffers throw, as their layout differs from the PS5 tiling. Linear PS4 buffers may be 4 KiB aligned: the OpenOrbis graphics sample registers its second 1920x1080 buffer 8,294,400 bytes after the first. The PS4 alignment rule is not known
- [sceVideoOutGetFlipStatus, sceVideoOutIsFlipPending](../../../core/libs/prx/libSceVideoOut/src/Output.cpp) (libSceVideoOut) - a null output together with an invalid handle throws, as only each alone was measured; a closed handle is unmeasured and answered like an invalid one. Measured in a payload process on a PS5 (firmware 12.70) on a handle from `sceVideoOutOpen(0xff, 0, 0, NULL)` with no buffer registered: `sceVideoOutGetFlipStatus` returned 0 and wrote 128 bytes, all zero except `flipArg` and `currentBuffer`, which were -1; a null output returned 0x80290002 and handle -1 returned 0x8029000b without writing the output; `sceVideoOutIsFlipPending` returned 0, and 0x8029000b for handle -1

### Functional

Expand Down
Loading