From 6b30cdac09e03efa33e9d47a39901a17cd04ae55 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Wed, 22 Feb 2023 22:14:40 +0100 Subject: [PATCH] Use u64 for system_time_t, as s64 doesn't make much sense in a microsecond context. --- rpcs3/Emu/Cell/Modules/cellCamera.cpp | 14 ++++++------- rpcs3/Emu/Cell/Modules/cellCamera.h | 8 ++++---- rpcs3/Emu/Cell/Modules/cellGem.cpp | 26 ++++++++++++++++-------- rpcs3/Emu/Cell/Modules/cellGem.h | 8 ++++---- rpcs3/Emu/Cell/Modules/cellRtc.cpp | 2 +- rpcs3/Emu/Cell/Modules/sceNp.h | 2 +- rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_timer.h | 2 +- rpcs3/Emu/savestate_utils.cpp | 2 +- 9 files changed, 38 insertions(+), 28 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellCamera.cpp b/rpcs3/Emu/Cell/Modules/cellCamera.cpp index 708f88753c..acca4f0846 100644 --- a/rpcs3/Emu/Cell/Modules/cellCamera.cpp +++ b/rpcs3/Emu/Cell/Modules/cellCamera.cpp @@ -147,7 +147,7 @@ void camera_context::save(utils::serial& ar) GET_OR_USE_SERIALIZATION_VERSION(ar.is_writing(), cellCamera); - ar(notify_data_map, start_timestamp, read_mode, is_streaming, is_attached, is_open, info, attr, frame_num); + ar(notify_data_map, start_timestamp_us, read_mode, is_streaming, is_attached, is_open, info, attr, frame_num); } static bool check_dev_num(s32 dev_num) @@ -1268,7 +1268,7 @@ error_code cellCameraStart(s32 dev_num) // TODO: Yet another CELL_CAMERA_ERROR_TIMEOUT - g_camera.start_timestamp = get_guest_system_time(); + g_camera.start_timestamp_us = get_guest_system_time(); g_camera.is_streaming = true; return CELL_OK; @@ -1385,18 +1385,18 @@ error_code cellCameraReadEx(s32 dev_num, vm::ptr read) if (has_new_frame) { - g_camera.frame_timestamp = ::narrow(get_guest_system_time() - g_camera.start_timestamp); + g_camera.frame_timestamp_us = get_guest_system_time() - g_camera.start_timestamp_us; } if (read) // NULL returns CELL_OK { - read->timestamp = g_camera.frame_timestamp; + read->timestamp = g_camera.frame_timestamp_us; read->frame = g_camera.frame_num; read->bytesread = g_camera.bytes_read; auto& shared_data = g_fxo->get(); - shared_data.frame_timestamp.store(read->timestamp); + shared_data.frame_timestamp_us.store(read->timestamp); } return CELL_OK; @@ -1672,7 +1672,7 @@ void camera_context::operator()() const u64 camera_id = 0; data2 = image_data_size << 32 | buffer_number << 16 | camera_id; - data3 = get_guest_system_time() - start_timestamp; // timestamp + data3 = get_guest_system_time() - start_timestamp_us; // timestamp } else // CELL_CAMERA_READ_FUNCCALL, also default { @@ -1801,7 +1801,7 @@ void camera_context::reset_state() pbuf_locked[0] = false; pbuf_locked[1] = false; has_new_frame = false; - frame_timestamp = 0; + frame_timestamp_us = 0; bytes_read = 0; if (info.buffer) diff --git a/rpcs3/Emu/Cell/Modules/cellCamera.h b/rpcs3/Emu/Cell/Modules/cellCamera.h index 6c4bd35f62..ae4786cdcc 100644 --- a/rpcs3/Emu/Cell/Modules/cellCamera.h +++ b/rpcs3/Emu/Cell/Modules/cellCamera.h @@ -384,7 +384,7 @@ struct CellCameraReadEx be_t version; be_t frame; be_t bytesread; - be_t timestamp; + be_t timestamp; // system_time_t (microseconds) vm::bptr pbuf; }; @@ -422,7 +422,7 @@ public: shared_mutex mutex; shared_mutex mutex_notify_data_map; - u64 start_timestamp = 0; + u64 start_timestamp_us = 0; atomic_t read_mode{CELL_CAMERA_READ_FUNCCALL}; atomic_t is_streaming{false}; @@ -444,7 +444,7 @@ public: attr_t attr[500]{}; atomic_t has_new_frame = false; atomic_t frame_num = 0; - atomic_t frame_timestamp = 0; + atomic_t frame_timestamp_us = 0; atomic_t bytes_read = 0; atomic_t init = 0; @@ -471,7 +471,7 @@ using camera_thread = named_thread; /// Shared data between cellGem and cellCamera struct gem_camera_shared { - atomic_t frame_timestamp{}; // latest read timestamp from cellCamera (cellCameraRead(Ex)) + atomic_t frame_timestamp_us{}; // latest read timestamp from cellCamera (cellCameraRead(Ex)) atomic_t width{640}; atomic_t height{480}; atomic_t size{0}; diff --git a/rpcs3/Emu/Cell/Modules/cellGem.cpp b/rpcs3/Emu/Cell/Modules/cellGem.cpp index 491aafee72..d92eba49d9 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGem.cpp @@ -215,7 +215,7 @@ public: shared_mutex mtx; - u64 start_timestamp = 0; + u64 start_timestamp_us = 0; // helper functions bool is_controller_ready(u32 gem_num) const @@ -299,10 +299,20 @@ public: return; } - GET_OR_USE_SERIALIZATION_VERSION(ar.is_writing(), cellGem); + [[maybe_unused]] const s32 version = GET_OR_USE_SERIALIZATION_VERSION(ar.is_writing(), cellGem); ar(attribute, vc_attribute, status_flags, enable_pitch_correction, inertial_counter, controllers - , connected_controllers, update_started, camera_frame, memory_ptr, start_timestamp); + , connected_controllers, update_started, camera_frame, memory_ptr); + + if (version == 1 && !ar.is_writing()) + { + u32 ts = ar; + start_timestamp_us = ts; + } + else + { + ar(start_timestamp_us); + } } gem_config_data(utils::serial& ar) @@ -1328,7 +1338,7 @@ error_code cellGemGetImageState(u32 gem_num, vm::ptr gem_imag if (g_cfg.io.move != move_handler::null) { auto& shared_data = g_fxo->get(); - gem_image_state->frame_timestamp = shared_data.frame_timestamp.load(); + gem_image_state->frame_timestamp = shared_data.frame_timestamp_us.load(); gem_image_state->timestamp = gem_image_state->frame_timestamp + 10; gem_image_state->r = gem.controllers[gem_num].radius; // Radius in camera pixels gem_image_state->distance = gem.controllers[gem_num].distance; // 1.5 meters away from camera @@ -1385,7 +1395,7 @@ error_code cellGemGetInertialState(u32 gem_num, u32 state_flag, u64 timestamp, v { ds3_input_to_ext(gem_num, gem.controllers[gem_num], inertial_state->ext); - inertial_state->timestamp = (get_guest_system_time() - gem.start_timestamp); + inertial_state->timestamp = (get_guest_system_time() - gem.start_timestamp_us); inertial_state->counter = gem.inertial_counter++; inertial_state->accelerometer[0] = 10; // Current gravity in m/s² @@ -1561,7 +1571,7 @@ error_code cellGemGetState(u32 gem_num, u32 flag, u64 time_parameter, vm::ptrtracking_flags = tracking_flags; - gem_state->timestamp = (get_guest_system_time() - gem.start_timestamp); + gem_state->timestamp = (get_guest_system_time() - gem.start_timestamp_us); gem_state->camera_pitch_angle = 0.f; gem_state->quat[3] = 1.f; @@ -1763,7 +1773,7 @@ error_code cellGemInit(ppu_thread& ppu, vm::cptr attribute) } // TODO: is this correct? - gem.start_timestamp = get_guest_system_time(); + gem.start_timestamp_us = get_guest_system_time(); return CELL_OK; } @@ -1939,7 +1949,7 @@ error_code cellGemReset(u32 gem_num) gem.reset_controller(gem_num); // TODO: is this correct? - gem.start_timestamp = get_guest_system_time(); + gem.start_timestamp_us = get_guest_system_time(); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/cellGem.h b/rpcs3/Emu/Cell/Modules/cellGem.h index f518ae2d90..b5e03db5fc 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.h +++ b/rpcs3/Emu/Cell/Modules/cellGem.h @@ -200,8 +200,8 @@ struct CellGemExtPortData struct CellGemImageState { - be_t frame_timestamp; // time the frame was captured by libCamera (usecs) - be_t timestamp; // time processing of the frame was finished (usecs) + be_t frame_timestamp; // time the frame was captured by libCamera. system_time_t (usecs) + be_t timestamp; // time processing of the frame was finished. system_time_t (usecs) be_t u; // horizontal screen position in pixels be_t v; // vertical screen position in pixels be_t r; // size of sphere on screen in pixels @@ -226,7 +226,7 @@ struct CellGemInertialState be_t gyro_bias[4]; // gyro bias (radians/s) CellGemPadData pad; CellGemExtPortData ext; - be_t timestamp; + be_t timestamp; // system_time_t (microseconds) be_t counter; be_t temperature; }; @@ -256,7 +256,7 @@ struct CellGemState be_t handle_accel[4]; // acceleration of controller handle (mm/s²) CellGemPadData pad; CellGemExtPortData ext; - be_t timestamp; + be_t timestamp; // system_time_t (microseconds) be_t temperature; be_t camera_pitch_angle; be_t tracking_flags; diff --git a/rpcs3/Emu/Cell/Modules/cellRtc.cpp b/rpcs3/Emu/Cell/Modules/cellRtc.cpp index a686f549ca..1d66817c8f 100644 --- a/rpcs3/Emu/Cell/Modules/cellRtc.cpp +++ b/rpcs3/Emu/Cell/Modules/cellRtc.cpp @@ -1351,7 +1351,7 @@ error_code cellRtcSetCurrentTick(vm::cptr pTick) // TODO syscall not implemented /* - u32 tmp2 = sys_time_get_system_time(tmp / cellRtcGetTickResolution(), (tmp % cellRtcGetTickResolution()) * 1000); + u64 tmp2 = sys_time_get_system_time(tmp / cellRtcGetTickResolution(), (tmp % cellRtcGetTickResolution()) * 1000); return (tmp2 & (tmp2 | tmp2 - 1) >> 0x1f); */ diff --git a/rpcs3/Emu/Cell/Modules/sceNp.h b/rpcs3/Emu/Cell/Modules/sceNp.h index 48d3fc177b..9cd0cf667e 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp.h +++ b/rpcs3/Emu/Cell/Modules/sceNp.h @@ -20,7 +20,7 @@ struct np_in_addr using sys_memory_container_t = u32; -using system_time_t = s64; +using system_time_t = u64; // s64 in documentation. But since this is in microseconds, it doesn't seem to make much sense. using second_t = u32; using usecond_t = u64; diff --git a/rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp b/rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp index 2d093b16a8..483fcfe1e9 100644 --- a/rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp @@ -16,7 +16,7 @@ vm::gvar> g_ppu_atexitspawn; vm::gvar> g_ppu_at_Exitspawn; extern vm::gvar g_ppu_exit_mutex; -s64 sys_time_get_system_time() +u64 sys_time_get_system_time() { sysPrxForUser.trace("sys_time_get_system_time()"); diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.h b/rpcs3/Emu/Cell/lv2/sys_timer.h index 3b976ed519..df92cb0964 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.h +++ b/rpcs3/Emu/Cell/lv2/sys_timer.h @@ -15,7 +15,7 @@ enum : u32 struct sys_timer_information_t { - be_t next_expire; + be_t next_expire; // system_time_t be_t period; be_t timer_state; be_t pad; diff --git a/rpcs3/Emu/savestate_utils.cpp b/rpcs3/Emu/savestate_utils.cpp index 669d2675c2..7a4249c92e 100644 --- a/rpcs3/Emu/savestate_utils.cpp +++ b/rpcs3/Emu/savestate_utils.cpp @@ -65,7 +65,7 @@ SERIALIZATION_VER(sceNp, 11) SERIALIZATION_VER(cellVdec, 12, 1) SERIALIZATION_VER(cellAudio, 13, 1) SERIALIZATION_VER(cellCamera, 14, 1) -SERIALIZATION_VER(cellGem, 15, 1) +SERIALIZATION_VER(cellGem, 15, 1, 2/*frame_timestamp u32->u64*/) SERIALIZATION_VER(sceNpTrophy, 16, 1) SERIALIZATION_VER(cellMusic, 17, 1) SERIALIZATION_VER(cellVoice, 18, 1)