From e0f3149c76636e7bf2a587091aee1eb903c89572 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Tue, 6 Feb 2024 18:55:25 +0100 Subject: [PATCH] early-access version 4118 --- README.md | 2 +- src/core/hle/service/hid/hid_debug_server.cpp | 173 ++---- src/core/hle/service/hid/hid_debug_server.h | 24 +- src/core/hle/service/hid/irs.cpp | 574 ++++++------------ src/core/hle/service/hid/irs.h | 84 ++- .../service/nvdrv/devices/nvhost_as_gpu.cpp | 6 +- .../irsensor/image_transfer_processor.cpp | 5 +- .../irsensor/image_transfer_processor.h | 4 +- src/video_core/control/scheduler.cpp | 94 +-- src/video_core/control/scheduler.h | 25 - src/video_core/engines/puller.cpp | 12 +- src/video_core/gpu.cpp | 8 - src/video_core/gpu.h | 9 +- src/video_core/gpu_thread.cpp | 14 +- src/video_core/gpu_thread.h | 9 +- src/video_core/host1x/host1x.cpp | 2 +- src/video_core/memory_manager.cpp | 17 +- src/video_core/memory_manager.h | 8 +- src/yuzu/configuration/configure_hotkeys.cpp | 41 +- src/yuzu/configuration/configure_hotkeys.h | 13 +- 20 files changed, 411 insertions(+), 713 deletions(-) diff --git a/README.md b/README.md index 03b05f686..e3e4b65c3 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 4117. +This is the source code for early-access 4118. ## Legal Notice diff --git a/src/core/hle/service/hid/hid_debug_server.cpp b/src/core/hle/service/hid/hid_debug_server.cpp index 610af34dd..4e2663672 100755 --- a/src/core/hle/service/hid/hid_debug_server.cpp +++ b/src/core/hle/service/hid/hid_debug_server.cpp @@ -3,6 +3,7 @@ #include +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/hid/hid_debug_server.h" #include "core/hle/service/ipc_helpers.h" #include "hid_core/hid_types.h" @@ -11,7 +12,6 @@ #include "hid_core/resources/touch_screen/gesture.h" #include "hid_core/resources/touch_screen/touch_screen.h" -#include "hid_core/resources/touch_screen/touch_types.h" namespace Service::HID { @@ -24,14 +24,14 @@ IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptr, "DeactivateTouchScreen"}, + {11, C<&IHidDebugServer::SetTouchScreenAutoPilotState>, "SetTouchScreenAutoPilotState"}, + {12, C<&IHidDebugServer::UnsetTouchScreenAutoPilotState>, "UnsetTouchScreenAutoPilotState"}, + {13, C<&IHidDebugServer::GetTouchScreenConfiguration>, "GetTouchScreenConfiguration"}, + {14, C<&IHidDebugServer::ProcessTouchScreenAutoTune>, "ProcessTouchScreenAutoTune"}, + {15, C<&IHidDebugServer::ForceStopTouchScreenManagement>, "ForceStopTouchScreenManagement"}, + {16, C<&IHidDebugServer::ForceRestartTouchScreenManagement>, "ForceRestartTouchScreenManagement"}, + {17, C<&IHidDebugServer::IsTouchScreenManaged>, "IsTouchScreenManaged"}, {20, nullptr, "DeactivateMouse"}, {21, nullptr, "SetMouseAutoPilotState"}, {22, nullptr, "UnsetMouseAutoPilotState"}, @@ -47,7 +47,7 @@ IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptr, "DeactivateGesture"}, {110, nullptr, "DeactivateHomeButton"}, {111, nullptr, "SetHomeButtonAutoPilotState"}, {112, nullptr, "UnsetHomeButtonAutoPilotState"}, @@ -160,169 +160,122 @@ IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptrIsDeviceManaged()) { - result = GetResourceManager()->GetTouchScreen()->Deactivate(); + R_RETURN(GetResourceManager()->GetTouchScreen()->Deactivate()); } - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IHidDebugServer::SetTouchScreenAutoPilotState(HLERequestContext& ctx) { +Result IHidDebugServer::SetTouchScreenAutoPilotState( + InArray auto_pilot_buffer) { AutoPilotState auto_pilot{}; - auto_pilot.count = ctx.GetReadBufferNumElements(); - const auto buffer = ctx.ReadBuffer(); - auto_pilot.count = std::min(auto_pilot.count, static_cast(auto_pilot.state.size())); - memcpy(auto_pilot.state.data(), buffer.data(), auto_pilot.count * sizeof(TouchState)); + auto_pilot.count = + static_cast(std::min(auto_pilot_buffer.size(), auto_pilot.state.size())); + memcpy(auto_pilot.state.data(), auto_pilot_buffer.data(), + auto_pilot.count * sizeof(TouchState)); LOG_INFO(Service_HID, "called, auto_pilot_count={}", auto_pilot.count); - const Result result = - GetResourceManager()->GetTouchScreen()->SetTouchScreenAutoPilotState(auto_pilot); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetTouchScreen()->SetTouchScreenAutoPilotState(auto_pilot)); } -void IHidDebugServer::UnsetTouchScreenAutoPilotState(HLERequestContext& ctx) { +Result IHidDebugServer::UnsetTouchScreenAutoPilotState() { LOG_INFO(Service_HID, "called"); - - const Result result = GetResourceManager()->GetTouchScreen()->UnsetTouchScreenAutoPilotState(); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetTouchScreen()->UnsetTouchScreenAutoPilotState()); } -void IHidDebugServer::GetTouchScreenConfiguration(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IHidDebugServer::GetTouchScreenConfiguration( + Out out_touchscreen_config, + ClientAppletResourceUserId aruid) { + LOG_INFO(Service_HID, "called, applet_resource_user_id={}", aruid.pid); - LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + R_TRY(GetResourceManager()->GetTouchScreen()->GetTouchScreenConfiguration( + *out_touchscreen_config, aruid.pid)); - Core::HID::TouchScreenConfigurationForNx touchscreen_config{}; - const Result result = GetResourceManager()->GetTouchScreen()->GetTouchScreenConfiguration( - touchscreen_config, applet_resource_user_id); - - if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 && - touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) { - touchscreen_config.mode = Core::HID::TouchScreenModeForNx::UseSystemSetting; + if (out_touchscreen_config->mode != Core::HID::TouchScreenModeForNx::Heat2 && + out_touchscreen_config->mode != Core::HID::TouchScreenModeForNx::Finger) { + out_touchscreen_config->mode = Core::HID::TouchScreenModeForNx::UseSystemSetting; } - IPC::ResponseBuilder rb{ctx, 6}; - rb.Push(result); - rb.PushRaw(touchscreen_config); + R_SUCCEED(); } -void IHidDebugServer::ProcessTouchScreenAutoTune(HLERequestContext& ctx) { +Result IHidDebugServer::ProcessTouchScreenAutoTune() { LOG_INFO(Service_HID, "called"); - - Result result = GetResourceManager()->GetTouchScreen()->ProcessTouchScreenAutoTune(); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_RETURN(GetResourceManager()->GetTouchScreen()->ProcessTouchScreenAutoTune()); } -void IHidDebugServer::ForceStopTouchScreenManagement(HLERequestContext& ctx) { +Result IHidDebugServer::ForceStopTouchScreenManagement() { LOG_INFO(Service_HID, "called"); if (!firmware_settings->IsDeviceManaged()) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); - return; + R_SUCCEED(); } - Result result = ResultSuccess; - bool is_touch_active{}; - bool is_gesture_active{}; auto touch_screen = GetResourceManager()->GetTouchScreen(); auto gesture = GetResourceManager()->GetGesture(); if (firmware_settings->IsTouchI2cManaged()) { - result = touch_screen->IsActive(is_touch_active); - if (result.IsSuccess()) { - result = gesture->IsActive(is_gesture_active); + bool is_touch_active{}; + bool is_gesture_active{}; + R_TRY(touch_screen->IsActive(is_touch_active)); + R_TRY(gesture->IsActive(is_gesture_active)); + + if (is_touch_active) { + R_TRY(touch_screen->Deactivate()); } - if (result.IsSuccess() && is_touch_active) { - result = touch_screen->Deactivate(); - } - if (result.IsSuccess() && is_gesture_active) { - result = gesture->Deactivate(); + if (is_gesture_active) { + R_TRY(gesture->Deactivate()); } } - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IHidDebugServer::ForceRestartTouchScreenManagement(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - u32 basic_gesture_id; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IHidDebugServer::ForceRestartTouchScreenManagement(u32 basic_gesture_id, + ClientAppletResourceUserId aruid) { LOG_INFO(Service_HID, "called, basic_gesture_id={}, applet_resource_user_id={}", - parameters.basic_gesture_id, parameters.applet_resource_user_id); + basic_gesture_id, aruid.pid); - Result result = ResultSuccess; auto touch_screen = GetResourceManager()->GetTouchScreen(); auto gesture = GetResourceManager()->GetGesture(); if (firmware_settings->IsDeviceManaged() && firmware_settings->IsTouchI2cManaged()) { - result = gesture->Activate(); - if (result.IsSuccess()) { - result = - gesture->Activate(parameters.applet_resource_user_id, parameters.basic_gesture_id); - } - if (result.IsSuccess()) { - result = touch_screen->Activate(); - } - if (result.IsSuccess()) { - result = touch_screen->Activate(parameters.applet_resource_user_id); - } + R_TRY(gesture->Activate()); + R_TRY(gesture->Activate(aruid.pid, basic_gesture_id)); + R_TRY(touch_screen->Activate()); + R_TRY(touch_screen->Activate(aruid.pid)); } - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IHidDebugServer::IsTouchScreenManaged(HLERequestContext& ctx) { +Result IHidDebugServer::IsTouchScreenManaged(Out out_is_managed) { LOG_INFO(Service_HID, "called"); bool is_touch_active{}; bool is_gesture_active{}; + R_TRY(GetResourceManager()->GetTouchScreen()->IsActive(is_touch_active)); + R_TRY(GetResourceManager()->GetGesture()->IsActive(is_gesture_active)); - Result result = GetResourceManager()->GetTouchScreen()->IsActive(is_touch_active); - if (result.IsSuccess()) { - result = GetResourceManager()->GetGesture()->IsActive(is_gesture_active); - } - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(result); - rb.Push(is_touch_active | is_gesture_active); + *out_is_managed = is_touch_active || is_gesture_active; + R_SUCCEED(); } -void IHidDebugServer::DeactivateGesture(HLERequestContext& ctx) { +Result IHidDebugServer::DeactivateGesture() { LOG_INFO(Service_HID, "called"); - Result result = ResultSuccess; - if (!firmware_settings->IsDeviceManaged()) { - result = GetResourceManager()->GetGesture()->Deactivate(); + R_RETURN(GetResourceManager()->GetGesture()->Deactivate()); } - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } std::shared_ptr IHidDebugServer::GetResourceManager() { diff --git a/src/core/hle/service/hid/hid_debug_server.h b/src/core/hle/service/hid/hid_debug_server.h index 7d5b082b3..3a483f07e 100755 --- a/src/core/hle/service/hid/hid_debug_server.h +++ b/src/core/hle/service/hid/hid_debug_server.h @@ -3,7 +3,9 @@ #pragma once +#include "core/hle/service/cmif_types.h" #include "core/hle/service/service.h" +#include "hid_core/resources/touch_screen/touch_types.h" namespace Core { class System; @@ -20,15 +22,19 @@ public: ~IHidDebugServer() override; private: - void DeactivateTouchScreen(HLERequestContext& ctx); - void SetTouchScreenAutoPilotState(HLERequestContext& ctx); - void UnsetTouchScreenAutoPilotState(HLERequestContext& ctx); - void GetTouchScreenConfiguration(HLERequestContext& ctx); - void ProcessTouchScreenAutoTune(HLERequestContext& ctx); - void ForceStopTouchScreenManagement(HLERequestContext& ctx); - void ForceRestartTouchScreenManagement(HLERequestContext& ctx); - void IsTouchScreenManaged(HLERequestContext& ctx); - void DeactivateGesture(HLERequestContext& ctx); + Result DeactivateTouchScreen(); + Result SetTouchScreenAutoPilotState( + InArray auto_pilot_buffer); + Result UnsetTouchScreenAutoPilotState(); + Result GetTouchScreenConfiguration( + Out out_touchscreen_config, + ClientAppletResourceUserId aruid); + Result ProcessTouchScreenAutoTune(); + Result ForceStopTouchScreenManagement(); + Result ForceRestartTouchScreenManagement(u32 basic_gesture_id, + ClientAppletResourceUserId aruid); + Result IsTouchScreenManaged(Out out_is_managed); + Result DeactivateGesture(); std::shared_ptr GetResourceManager(); diff --git a/src/core/hle/service/hid/irs.cpp b/src/core/hle/service/hid/irs.cpp index 18f3775e1..b01f74796 100755 --- a/src/core/hle/service/hid/irs.cpp +++ b/src/core/hle/service/hid/irs.cpp @@ -9,6 +9,7 @@ #include "core/hle/kernel/k_shared_memory.h" #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/hid/irs.h" #include "core/hle/service/ipc_helpers.h" #include "core/memory.h" @@ -28,24 +29,24 @@ namespace Service::IRS { IRS::IRS(Core::System& system_) : ServiceFramework{system_, "irs"} { // clang-format off static const FunctionInfo functions[] = { - {302, &IRS::ActivateIrsensor, "ActivateIrsensor"}, - {303, &IRS::DeactivateIrsensor, "DeactivateIrsensor"}, - {304, &IRS::GetIrsensorSharedMemoryHandle, "GetIrsensorSharedMemoryHandle"}, - {305, &IRS::StopImageProcessor, "StopImageProcessor"}, - {306, &IRS::RunMomentProcessor, "RunMomentProcessor"}, - {307, &IRS::RunClusteringProcessor, "RunClusteringProcessor"}, - {308, &IRS::RunImageTransferProcessor, "RunImageTransferProcessor"}, - {309, &IRS::GetImageTransferProcessorState, "GetImageTransferProcessorState"}, - {310, &IRS::RunTeraPluginProcessor, "RunTeraPluginProcessor"}, - {311, &IRS::GetNpadIrCameraHandle, "GetNpadIrCameraHandle"}, - {312, &IRS::RunPointingProcessor, "RunPointingProcessor"}, - {313, &IRS::SuspendImageProcessor, "SuspendImageProcessor"}, - {314, &IRS::CheckFirmwareVersion, "CheckFirmwareVersion"}, - {315, &IRS::SetFunctionLevel, "SetFunctionLevel"}, - {316, &IRS::RunImageTransferExProcessor, "RunImageTransferExProcessor"}, - {317, &IRS::RunIrLedProcessor, "RunIrLedProcessor"}, - {318, &IRS::StopImageProcessorAsync, "StopImageProcessorAsync"}, - {319, &IRS::ActivateIrsensorWithFunctionLevel, "ActivateIrsensorWithFunctionLevel"}, + {302, C<&IRS::ActivateIrsensor>, "ActivateIrsensor"}, + {303, C<&IRS::DeactivateIrsensor>, "DeactivateIrsensor"}, + {304, C<&IRS::GetIrsensorSharedMemoryHandle>, "GetIrsensorSharedMemoryHandle"}, + {305, C<&IRS::StopImageProcessor>, "StopImageProcessor"}, + {306, C<&IRS::RunMomentProcessor>, "RunMomentProcessor"}, + {307, C<&IRS::RunClusteringProcessor>, "RunClusteringProcessor"}, + {308, C<&IRS::RunImageTransferProcessor>, "RunImageTransferProcessor"}, + {309, C<&IRS::GetImageTransferProcessorState>, "GetImageTransferProcessorState"}, + {310, C<&IRS::RunTeraPluginProcessor>, "RunTeraPluginProcessor"}, + {311, C<&IRS::GetNpadIrCameraHandle>, "GetNpadIrCameraHandle"}, + {312, C<&IRS::RunPointingProcessor>, "RunPointingProcessor"}, + {313, C<&IRS::SuspendImageProcessor>, "SuspendImageProcessor"}, + {314, C<&IRS::CheckFirmwareVersion>, "CheckFirmwareVersion"}, + {315, C<&IRS::SetFunctionLevel>, "SetFunctionLevel"}, + {316, C<&IRS::RunImageTransferExProcessor>, "RunImageTransferExProcessor"}, + {317, C<&IRS::RunIrLedProcessor>, "RunIrLedProcessor"}, + {318, C<&IRS::StopImageProcessorAsync>, "StopImageProcessorAsync"}, + {319, C<&IRS::ActivateIrsensorWithFunctionLevel>, "ActivateIrsensorWithFunctionLevel"}, }; // clang-format on @@ -57,489 +58,292 @@ IRS::IRS(Core::System& system_) : ServiceFramework{system_, "irs"} { } IRS::~IRS() = default; -void IRS::ActivateIrsensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}", - applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IRS::ActivateIrsensor(ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}", aruid.pid); + R_SUCCEED(); } -void IRS::DeactivateIrsensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}", - applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IRS::DeactivateIrsensor(ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}", aruid.pid); + R_SUCCEED(); } -void IRS::GetIrsensorSharedMemoryHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; +Result IRS::GetIrsensorSharedMemoryHandle(OutCopyHandle out_shared_memory, + ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_IRS, "called, applet_resource_user_id={}", aruid.pid); - LOG_DEBUG(Service_IRS, "called, applet_resource_user_id={}", applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(&system.Kernel().GetIrsSharedMem()); + *out_shared_memory = &system.Kernel().GetIrsSharedMem(); + R_SUCCEED(); } -void IRS::StopImageProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IRS::StopImageProcessor(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - auto result = IsIrCameraHandleValid(parameters.camera_handle); - if (result.IsSuccess()) { - // TODO: Stop Image processor - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::Active); - result = ResultSuccess; - } + R_TRY(IsIrCameraHandleValid(camera_handle)); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + // TODO: Stop Image processor + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); + R_SUCCEED(); } -void IRS::RunMomentProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - Core::IrSensor::PackedMomentProcessorConfig processor_config; - }; - static_assert(sizeof(Parameters) == 0x30, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IRS::RunMomentProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedMomentProcessorConfig& processor_config) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - const auto result = IsIrCameraHandleValid(parameters.camera_handle); + R_TRY(IsIrCameraHandleValid(camera_handle)); - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); - MakeProcessorWithCoreContext(parameters.camera_handle, device); - auto& image_transfer_processor = GetProcessor(parameters.camera_handle); - image_transfer_processor.SetConfig(parameters.processor_config); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessorWithCoreContext(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IRS::RunClusteringProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - Core::IrSensor::PackedClusteringProcessorConfig processor_config; - }; - static_assert(sizeof(Parameters) == 0x38, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IRS::RunClusteringProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedClusteringProcessorConfig& processor_config) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - auto result = IsIrCameraHandleValid(parameters.camera_handle); + R_TRY(IsIrCameraHandleValid(camera_handle)); - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); - MakeProcessorWithCoreContext(parameters.camera_handle, device); - auto& image_transfer_processor = - GetProcessor(parameters.camera_handle); - image_transfer_processor.SetConfig(parameters.processor_config); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessorWithCoreContext(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IRS::RunImageTransferProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - Core::IrSensor::PackedImageTransferProcessorConfig processor_config; - u32 transfer_memory_size; - }; - static_assert(sizeof(Parameters) == 0x30, "Parameters has incorrect size."); +Result IRS::RunImageTransferProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedImageTransferProcessorConfig& processor_config, + u64 transfer_memory_size, InCopyHandle t_mem) { - const auto parameters{rp.PopRaw()}; - const auto t_mem_handle{ctx.GetCopyHandle(0)}; - - auto t_mem = ctx.GetObjectFromHandle(t_mem_handle); - - if (t_mem.IsNull()) { - LOG_ERROR(Service_IRS, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultUnknown); - return; - } - - ASSERT_MSG(t_mem->GetSize() == parameters.transfer_memory_size, "t_mem has incorrect size"); + ASSERT_MSG(t_mem->GetSize() == transfer_memory_size, "t_mem has incorrect size"); LOG_INFO(Service_IRS, "called, npad_type={}, npad_id={}, transfer_memory_size={}, transfer_memory_size={}, " "applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.transfer_memory_size, t_mem->GetSize(), parameters.applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, transfer_memory_size, t_mem->GetSize(), + aruid.pid); - const auto result = IsIrCameraHandleValid(parameters.camera_handle); + R_TRY(IsIrCameraHandleValid(camera_handle)); - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); - MakeProcessorWithCoreContext(parameters.camera_handle, device); - auto& image_transfer_processor = - GetProcessor(parameters.camera_handle); - image_transfer_processor.SetConfig(parameters.processor_config); - image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessorWithCoreContext(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IRS::GetImageTransferProcessorState(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IRS::GetImageTransferProcessorState( + Out out_state, + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + OutBuffer out_buffer_data) { LOG_DEBUG(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - const auto result = IsIrCameraHandleValid(parameters.camera_handle); - if (result.IsError()) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - return; - } + R_TRY(IsIrCameraHandleValid(camera_handle)); - const auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); + const auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); - if (device.mode != Core::IrSensor::IrSensorMode::ImageTransferProcessor) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(InvalidProcessorState); - return; - } + R_TRY(IsIrCameraHandleValid(camera_handle)); + R_UNLESS(device.mode == Core::IrSensor::IrSensorMode::ImageTransferProcessor, + InvalidProcessorState); - std::vector data{}; - const auto& image_transfer_processor = - GetProcessor(parameters.camera_handle); - const auto& state = image_transfer_processor.GetState(data); + *out_state = GetProcessor(camera_handle).GetState(out_buffer_data); - ctx.WriteBuffer(data); - IPC::ResponseBuilder rb{ctx, 6}; - rb.Push(ResultSuccess); - rb.PushRaw(state); + R_SUCCEED(); } -void IRS::RunTeraPluginProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - Core::IrSensor::PackedTeraPluginProcessorConfig processor_config; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); +Result IRS::RunTeraPluginProcessor(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedTeraPluginProcessorConfig processor_config, + ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_IRS, + "(STUBBED) called, npad_type={}, npad_id={}, mode={}, mcu_version={}.{}, " + "applet_resource_user_id={}", + camera_handle.npad_type, camera_handle.npad_id, processor_config.mode, + processor_config.required_mcu_version.major, + processor_config.required_mcu_version.minor, aruid.pid); - const auto parameters{rp.PopRaw()}; + R_TRY(IsIrCameraHandleValid(camera_handle)); - LOG_WARNING( - Service_IRS, - "(STUBBED) called, npad_type={}, npad_id={}, mode={}, mcu_version={}.{}, " - "applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.processor_config.mode, parameters.processor_config.required_mcu_version.major, - parameters.processor_config.required_mcu_version.minor, parameters.applet_resource_user_id); + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessor(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - const auto result = IsIrCameraHandleValid(parameters.camera_handle); - - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); - MakeProcessor(parameters.camera_handle, device); - auto& image_transfer_processor = - GetProcessor(parameters.camera_handle); - image_transfer_processor.SetConfig(parameters.processor_config); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IRS::GetNpadIrCameraHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto npad_id{rp.PopEnum()}; +Result IRS::GetNpadIrCameraHandle(Out out_camera_handle, + Core::HID::NpadIdType npad_id) { + R_UNLESS(HID::IsNpadIdValid(npad_id), HID::ResultInvalidNpadId); - if (npad_id > Core::HID::NpadIdType::Player8 && npad_id != Core::HID::NpadIdType::Invalid && - npad_id != Core::HID::NpadIdType::Handheld) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(Service::HID::ResultInvalidNpadId); - return; - } - - Core::IrSensor::IrCameraHandle camera_handle{ + *out_camera_handle = { .npad_id = static_cast(HID::NpadIdTypeToIndex(npad_id)), .npad_type = Core::HID::NpadStyleIndex::None, }; LOG_INFO(Service_IRS, "called, npad_id={}, camera_npad_id={}, camera_npad_type={}", npad_id, - camera_handle.npad_id, camera_handle.npad_type); + out_camera_handle->npad_id, out_camera_handle->npad_type); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.PushRaw(camera_handle); + R_SUCCEED(); } -void IRS::RunPointingProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto camera_handle{rp.PopRaw()}; - const auto processor_config{rp.PopRaw()}; - const auto applet_resource_user_id{rp.Pop()}; - +Result IRS::RunPointingProcessor( + Core::IrSensor::IrCameraHandle camera_handle, + const Core::IrSensor::PackedPointingProcessorConfig& processor_config, + ClientAppletResourceUserId aruid) { LOG_WARNING( Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, mcu_version={}.{}, applet_resource_user_id={}", camera_handle.npad_type, camera_handle.npad_id, processor_config.required_mcu_version.major, - processor_config.required_mcu_version.minor, applet_resource_user_id); + processor_config.required_mcu_version.minor, aruid.pid); - auto result = IsIrCameraHandleValid(camera_handle); + R_TRY(IsIrCameraHandleValid(camera_handle)); - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); - MakeProcessor(camera_handle, device); - auto& image_transfer_processor = GetProcessor(camera_handle); - image_transfer_processor.SetConfig(processor_config); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessor(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IRS::SuspendImageProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IRS::SuspendImageProcessor(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - auto result = IsIrCameraHandleValid(parameters.camera_handle); - if (result.IsSuccess()) { - // TODO: Suspend image processor - result = ResultSuccess; - } + R_TRY(IsIrCameraHandleValid(camera_handle)); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + // TODO: Suspend image processor + + R_SUCCEED(); } -void IRS::CheckFirmwareVersion(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto camera_handle{rp.PopRaw()}; - const auto mcu_version{rp.PopRaw()}; - const auto applet_resource_user_id{rp.Pop()}; - +Result IRS::CheckFirmwareVersion(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedMcuVersion mcu_version, + ClientAppletResourceUserId aruid) { LOG_WARNING( Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}, mcu_version={}.{}", - camera_handle.npad_type, camera_handle.npad_id, applet_resource_user_id, mcu_version.major, + camera_handle.npad_type, camera_handle.npad_id, aruid.pid, mcu_version.major, mcu_version.minor); - auto result = IsIrCameraHandleValid(camera_handle); - if (result.IsSuccess()) { - // TODO: Check firmware version - result = ResultSuccess; - } + R_TRY(IsIrCameraHandleValid(camera_handle)); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + // TODO: Check firmware version + + R_SUCCEED(); } -void IRS::SetFunctionLevel(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto camera_handle{rp.PopRaw()}; - const auto function_level{rp.PopRaw()}; - const auto applet_resource_user_id{rp.Pop()}; - +Result IRS::SetFunctionLevel(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedFunctionLevel function_level, + ClientAppletResourceUserId aruid) { LOG_WARNING( Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, function_level={}, applet_resource_user_id={}", - camera_handle.npad_type, camera_handle.npad_id, function_level.function_level, - applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, function_level.function_level, aruid.pid); - auto result = IsIrCameraHandleValid(camera_handle); - if (result.IsSuccess()) { - // TODO: Set Function level - result = ResultSuccess; - } + R_TRY(IsIrCameraHandleValid(camera_handle)); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + // TODO: Set Function level + + R_SUCCEED(); } -void IRS::RunImageTransferExProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - Core::IrSensor::PackedImageTransferProcessorExConfig processor_config; - u64 transfer_memory_size; - }; - static_assert(sizeof(Parameters) == 0x38, "Parameters has incorrect size."); +Result IRS::RunImageTransferExProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedImageTransferProcessorExConfig& processor_config, + u64 transfer_memory_size, InCopyHandle t_mem) { - const auto parameters{rp.PopRaw()}; - const auto t_mem_handle{ctx.GetCopyHandle(0)}; - - auto t_mem = ctx.GetObjectFromHandle(t_mem_handle); + ASSERT_MSG(t_mem->GetSize() == transfer_memory_size, "t_mem has incorrect size"); LOG_INFO(Service_IRS, "called, npad_type={}, npad_id={}, transfer_memory_size={}, " "applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.transfer_memory_size, parameters.applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, transfer_memory_size, aruid.pid); - auto result = IsIrCameraHandleValid(parameters.camera_handle); + R_TRY(IsIrCameraHandleValid(camera_handle)); - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); - MakeProcessorWithCoreContext(parameters.camera_handle, device); - auto& image_transfer_processor = - GetProcessor(parameters.camera_handle); - image_transfer_processor.SetConfig(parameters.processor_config); - image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessorWithCoreContext(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IRS::RunIrLedProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto camera_handle{rp.PopRaw()}; - const auto processor_config{rp.PopRaw()}; - const auto applet_resource_user_id{rp.Pop()}; - +Result IRS::RunIrLedProcessor(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedIrLedProcessorConfig processor_config, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, light_target={}, mcu_version={}.{} " "applet_resource_user_id={}", camera_handle.npad_type, camera_handle.npad_id, processor_config.light_target, processor_config.required_mcu_version.major, - processor_config.required_mcu_version.minor, applet_resource_user_id); + processor_config.required_mcu_version.minor, aruid.pid); - auto result = IsIrCameraHandleValid(camera_handle); + R_TRY(IsIrCameraHandleValid(camera_handle)); - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); - MakeProcessor(camera_handle, device); - auto& image_transfer_processor = GetProcessor(camera_handle); - image_transfer_processor.SetConfig(processor_config); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessor(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IRS::StopImageProcessorAsync(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IRS::StopImageProcessorAsync(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - auto result = IsIrCameraHandleValid(parameters.camera_handle); - if (result.IsSuccess()) { - // TODO: Stop image processor async - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::Active); - result = ResultSuccess; - } + R_TRY(IsIrCameraHandleValid(camera_handle)); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + // TODO: Stop image processor async + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); + + R_SUCCEED(); } -void IRS::ActivateIrsensorWithFunctionLevel(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::PackedFunctionLevel function_level; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IRS::ActivateIrsensorWithFunctionLevel(Core::IrSensor::PackedFunctionLevel function_level, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_IRS, "(STUBBED) called, function_level={}, applet_resource_user_id={}", - parameters.function_level.function_level, parameters.applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + function_level.function_level, aruid.pid); + R_SUCCEED(); } Result IRS::IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const { diff --git a/src/core/hle/service/hid/irs.h b/src/core/hle/service/hid/irs.h index e7ac4f25f..11c5a72bd 100755 --- a/src/core/hle/service/hid/irs.h +++ b/src/core/hle/service/hid/irs.h @@ -4,6 +4,7 @@ #pragma once #include "core/core.h" +#include "core/hle/service/cmif_types.h" #include "core/hle/service/service.h" #include "hid_core/hid_types.h" #include "hid_core/irsensor/irs_types.h" @@ -35,26 +36,73 @@ private: }; static_assert(sizeof(StatusManager) == 0x8000, "StatusManager is an invalid size"); - void ActivateIrsensor(HLERequestContext& ctx); - void DeactivateIrsensor(HLERequestContext& ctx); - void GetIrsensorSharedMemoryHandle(HLERequestContext& ctx); - void StopImageProcessor(HLERequestContext& ctx); - void RunMomentProcessor(HLERequestContext& ctx); - void RunClusteringProcessor(HLERequestContext& ctx); - void RunImageTransferProcessor(HLERequestContext& ctx); - void GetImageTransferProcessorState(HLERequestContext& ctx); - void RunTeraPluginProcessor(HLERequestContext& ctx); - void GetNpadIrCameraHandle(HLERequestContext& ctx); - void RunPointingProcessor(HLERequestContext& ctx); - void SuspendImageProcessor(HLERequestContext& ctx); - void CheckFirmwareVersion(HLERequestContext& ctx); - void SetFunctionLevel(HLERequestContext& ctx); - void RunImageTransferExProcessor(HLERequestContext& ctx); - void RunIrLedProcessor(HLERequestContext& ctx); - void StopImageProcessorAsync(HLERequestContext& ctx); - void ActivateIrsensorWithFunctionLevel(HLERequestContext& ctx); + Result ActivateIrsensor(ClientAppletResourceUserId aruid); + + Result DeactivateIrsensor(ClientAppletResourceUserId aruid); + + Result GetIrsensorSharedMemoryHandle(OutCopyHandle out_shared_memory, + ClientAppletResourceUserId aruid); + Result StopImageProcessor(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid); + + Result RunMomentProcessor(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedMomentProcessorConfig& processor_config); + + Result RunClusteringProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedClusteringProcessorConfig& processor_config); + + Result RunImageTransferProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedImageTransferProcessorConfig& processor_config, + u64 transfer_memory_size, InCopyHandle t_mem); + + Result GetImageTransferProcessorState( + Out out_state, + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + OutBuffer out_buffer_data); + + Result RunTeraPluginProcessor(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedTeraPluginProcessorConfig processor_config, + ClientAppletResourceUserId aruid); + + Result GetNpadIrCameraHandle(Out out_camera_handle, + Core::HID::NpadIdType npad_id); + + Result RunPointingProcessor( + Core::IrSensor::IrCameraHandle camera_handle, + const Core::IrSensor::PackedPointingProcessorConfig& processor_config, + ClientAppletResourceUserId aruid); + + Result SuspendImageProcessor(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid); + + Result CheckFirmwareVersion(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedMcuVersion mcu_version, + ClientAppletResourceUserId aruid); + + Result SetFunctionLevel(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedFunctionLevel function_level, + ClientAppletResourceUserId aruid); + + Result RunImageTransferExProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedImageTransferProcessorExConfig& processor_config, + u64 transfer_memory_size, InCopyHandle t_mem); + + Result RunIrLedProcessor(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedIrLedProcessorConfig processor_config, + ClientAppletResourceUserId aruid); + + Result StopImageProcessorAsync(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid); + + Result ActivateIrsensorWithFunctionLevel(Core::IrSensor::PackedFunctionLevel function_level, + ClientAppletResourceUserId aruid); Result IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const; + Core::IrSensor::DeviceFormat& GetIrCameraSharedMemoryDeviceEntry( const Core::IrSensor::IrCameraHandle& camera_handle); diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index 18cf0ab4b..7ef8e87f0 100755 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp @@ -123,8 +123,6 @@ NvResult nvhost_as_gpu::AllocAsEx(IoctlAllocAsEx& params) { vm.va_range_end = params.va_range_end; } - const u64 max_big_page_bits = Common::Log2Ceil64(vm.va_range_end); - const auto start_pages{static_cast(vm.va_range_start >> VM::PAGE_SIZE_BITS)}; const auto end_pages{static_cast(vm.va_range_split >> VM::PAGE_SIZE_BITS)}; vm.small_page_allocator = std::make_shared(start_pages, end_pages); @@ -134,8 +132,8 @@ NvResult nvhost_as_gpu::AllocAsEx(IoctlAllocAsEx& params) { static_cast((vm.va_range_end - vm.va_range_split) >> vm.big_page_size_bits)}; vm.big_page_allocator = std::make_unique(start_big_pages, end_big_pages); - gmmu = std::make_shared(system, max_big_page_bits, vm.va_range_split, - vm.big_page_size_bits, VM::PAGE_SIZE_BITS); + gmmu = std::make_shared(system, 40, vm.big_page_size_bits, + VM::PAGE_SIZE_BITS); system.GPU().InitAddressSpace(*gmmu); vm.initialised = true; diff --git a/src/hid_core/irsensor/image_transfer_processor.cpp b/src/hid_core/irsensor/image_transfer_processor.cpp index d6573f8dc..2b5a50ef6 100755 --- a/src/hid_core/irsensor/image_transfer_processor.cpp +++ b/src/hid_core/irsensor/image_transfer_processor.cpp @@ -145,9 +145,8 @@ void ImageTransferProcessor::SetTransferMemoryAddress(Common::ProcessAddress t_m } Core::IrSensor::ImageTransferProcessorState ImageTransferProcessor::GetState( - std::vector& data) const { - const auto size = GetDataSize(current_config.trimming_format); - data.resize(size); + std::span data) const { + const auto size = std::min(GetDataSize(current_config.trimming_format), data.size()); system.ApplicationMemory().ReadBlock(transfer_memory, data.data(), size); return processor_state; } diff --git a/src/hid_core/irsensor/image_transfer_processor.h b/src/hid_core/irsensor/image_transfer_processor.h index 4e0117084..df1c9d920 100755 --- a/src/hid_core/irsensor/image_transfer_processor.h +++ b/src/hid_core/irsensor/image_transfer_processor.h @@ -3,6 +3,8 @@ #pragma once +#include + #include "common/typed_address.h" #include "hid_core/irsensor/irs_types.h" #include "hid_core/irsensor/processor_base.h" @@ -39,7 +41,7 @@ public: // Transfer memory where the image data will be stored void SetTransferMemoryAddress(Common::ProcessAddress t_mem); - Core::IrSensor::ImageTransferProcessorState GetState(std::vector& data) const; + Core::IrSensor::ImageTransferProcessorState GetState(std::span data) const; private: // This is nn::irsensor::ImageTransferProcessorConfig diff --git a/src/video_core/control/scheduler.cpp b/src/video_core/control/scheduler.cpp index 11f8bbe9d..31e3b1235 100755 --- a/src/video_core/control/scheduler.cpp +++ b/src/video_core/control/scheduler.cpp @@ -13,102 +13,20 @@ Scheduler::Scheduler(GPU& gpu_) : gpu{gpu_} {} Scheduler::~Scheduler() = default; -void Scheduler::Init() { - master_control = Common::Fiber::ThreadToFiber(); -} - -void Scheduler::Resume() { - bool nothing_pending; - do { - nothing_pending = true; - current_fifo = nullptr; - { - std::unique_lock lk(scheduling_guard); - size_t num_iters = gpfifos.size(); - for (size_t i = 0; i < num_iters; i++) { - size_t current_id = (current_fifo_rotation_id + i) % gpfifos.size(); - auto& fifo = gpfifos[current_id]; - if (!fifo.is_active) { - continue; - } - std::scoped_lock lk2(fifo.guard); - if (!fifo.pending_work.empty() || fifo.working.load(std::memory_order_acquire)) { - current_fifo = &fifo; - current_fifo_rotation_id = current_id; - nothing_pending = false; - break; - } - } - } - if (current_fifo) { - Common::Fiber::YieldTo(master_control, *current_fifo->context); - current_fifo = nullptr; - } - } while (!nothing_pending); -} - -void Scheduler::Yield() { - ASSERT(current_fifo != nullptr); - Common::Fiber::YieldTo(current_fifo->context, *master_control); - gpu.BindChannel(current_fifo->bind_id); -} - void Scheduler::Push(s32 channel, CommandList&& entries) { std::unique_lock lk(scheduling_guard); - auto it = channel_gpfifo_ids.find(channel); - ASSERT(it != channel_gpfifo_ids.end()); - auto gpfifo_id = it->second; - auto& fifo = gpfifos[gpfifo_id]; - { - std::scoped_lock lk2(fifo.guard); - fifo.pending_work.emplace_back(std::move(entries)); - } -} - -void Scheduler::ChannelLoop(size_t gpfifo_id, s32 channel_id) { - gpu.BindChannel(channel_id); - auto& fifo = gpfifos[gpfifo_id]; - while (true) { - auto* channel_state = channels[channel_id].get(); - fifo.guard.lock(); - while (!fifo.pending_work.empty()) { - { - - fifo.working.store(true, std::memory_order_release); - CommandList&& entries = std::move(fifo.pending_work.front()); - channel_state->dma_pusher->Push(std::move(entries)); - fifo.pending_work.pop_front(); - } - fifo.guard.unlock(); - channel_state->dma_pusher->DispatchCalls(); - fifo.guard.lock(); - } - fifo.working.store(false, std::memory_order_relaxed); - fifo.guard.unlock(); - Common::Fiber::YieldTo(fifo.context, *master_control); - gpu.BindChannel(channel_id); - } + auto it = channels.find(channel); + ASSERT(it != channels.end()); + auto channel_state = it->second; + gpu.BindChannel(channel_state->bind_id); + channel_state->dma_pusher->Push(std::move(entries)); + channel_state->dma_pusher->DispatchCalls(); } void Scheduler::DeclareChannel(std::shared_ptr new_channel) { s32 channel = new_channel->bind_id; std::unique_lock lk(scheduling_guard); channels.emplace(channel, new_channel); - size_t new_fifo_id; - if (!free_fifos.empty()) { - new_fifo_id = free_fifos.front(); - free_fifos.pop_front(); - } else { - new_fifo_id = gpfifos.size(); - gpfifos.emplace_back(); - } - auto& new_fifo = gpfifos[new_fifo_id]; - channel_gpfifo_ids[channel] = new_fifo_id; - new_fifo.is_active = true; - new_fifo.bind_id = channel; - new_fifo.pending_work.clear(); - std::function callback = std::bind(&Scheduler::ChannelLoop, this, new_fifo_id, channel); - new_fifo.context = std::make_shared(std::move(callback)); } } // namespace Tegra::Control diff --git a/src/video_core/control/scheduler.h b/src/video_core/control/scheduler.h index cc6a30ac0..eab52e536 100755 --- a/src/video_core/control/scheduler.h +++ b/src/video_core/control/scheduler.h @@ -3,13 +3,10 @@ #pragma once -#include -#include #include #include #include -#include "common/fiber.h" #include "video_core/dma_pusher.h" namespace Tegra { @@ -25,36 +22,14 @@ public: explicit Scheduler(GPU& gpu_); ~Scheduler(); - void Init(); - - void Resume(); - - void Yield(); - void Push(s32 channel, CommandList&& entries); void DeclareChannel(std::shared_ptr new_channel); private: - void ChannelLoop(size_t gpfifo_id, s32 channel_id); - std::unordered_map> channels; - std::unordered_map channel_gpfifo_ids; std::mutex scheduling_guard; - std::shared_ptr master_control; - struct GPFifoContext { - bool is_active; - std::shared_ptr context; - std::deque pending_work; - std::atomic working{}; - std::mutex guard; - s32 bind_id; - }; - std::deque gpfifos; - std::deque free_fifos; GPU& gpu; - size_t current_fifo_rotation_id{}; - GPFifoContext* current_fifo{}; }; } // namespace Control diff --git a/src/video_core/engines/puller.cpp b/src/video_core/engines/puller.cpp index c39cada43..79d84d662 100755 --- a/src/video_core/engines/puller.cpp +++ b/src/video_core/engines/puller.cpp @@ -6,7 +6,6 @@ #include "common/settings.h" #include "core/core.h" #include "video_core/control/channel_state.h" -#include "video_core/control/scheduler.h" #include "video_core/dma_pusher.h" #include "video_core/engines/fermi_2d.h" #include "video_core/engines/kepler_compute.h" @@ -15,8 +14,6 @@ #include "video_core/engines/maxwell_dma.h" #include "video_core/engines/puller.h" #include "video_core/gpu.h" -#include "video_core/host1x/host1x.h" -#include "video_core/host1x/syncpoint_manager.h" #include "video_core/memory_manager.h" #include "video_core/rasterizer_interface.h" @@ -63,14 +60,11 @@ void Puller::ProcessBindMethod(const MethodCall& method_call) { } void Puller::ProcessFenceActionMethod() { - auto& syncpoint_manager = gpu.Host1x().GetSyncpointManager(); switch (regs.fence_action.op) { case Puller::FenceOperation::Acquire: - while (regs.fence_value > - syncpoint_manager.GetGuestSyncpointValue(regs.fence_action.syncpoint_id)) { - rasterizer->ReleaseFences(); - gpu.Scheduler().Yield(); - } + // UNIMPLEMENTED_MSG("Channel Scheduling pending."); + // WaitFence(regs.fence_action.syncpoint_id, regs.fence_value); + rasterizer->ReleaseFences(); break; case Puller::FenceOperation::Increment: rasterizer->SignalSyncPoint(regs.fence_action.syncpoint_id); diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index f45f797b3..59356015b 100755 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -387,14 +387,6 @@ std::shared_ptr GPU::AllocateChannel() { return impl->AllocateChannel(); } -Tegra::Control::Scheduler& GPU::Scheduler() { - return *impl->scheduler; -} - -const Tegra::Control::Scheduler& GPU::Scheduler() const { - return *impl->scheduler; -} - void GPU::InitChannel(Control::ChannelState& to_init) { impl->InitChannel(to_init); } diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h index 154466f23..25c75a109 100755 --- a/src/video_core/gpu.h +++ b/src/video_core/gpu.h @@ -124,8 +124,7 @@ class KeplerCompute; namespace Control { struct ChannelState; -class Scheduler; -} // namespace Control +} namespace Host1x { class Host1x; @@ -205,12 +204,6 @@ public: /// Returns a const reference to the shader notifier. [[nodiscard]] const VideoCore::ShaderNotify& ShaderNotify() const; - /// Returns GPU Channel Scheduler. - [[nodiscard]] Tegra::Control::Scheduler& Scheduler(); - - /// Returns GPU Channel Scheduler. - [[nodiscard]] const Tegra::Control::Scheduler& Scheduler() const; - [[nodiscard]] u64 GetTicks() const; [[nodiscard]] bool IsAsync() const; diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp index 3aa59d034..0832234af 100755 --- a/src/video_core/gpu_thread.cpp +++ b/src/video_core/gpu_thread.cpp @@ -34,15 +34,13 @@ static void RunThread(std::stop_token stop_token, Core::System& system, CommandDataContainer next; - scheduler.Init(); - while (!stop_token.stop_requested()) { state.queue.PopWait(next, stop_token); if (stop_token.stop_requested()) { break; } - if (std::holds_alternative(next.data)) { - scheduler.Resume(); + if (auto* submit_list = std::get_if(&next.data)) { + scheduler.Push(submit_list->channel, std::move(submit_list->entries)); } else if (std::holds_alternative(next.data)) { system.GPU().TickWork(); } else if (const auto* flush = std::get_if(&next.data)) { @@ -69,16 +67,14 @@ ThreadManager::~ThreadManager() = default; void ThreadManager::StartThread(VideoCore::RendererBase& renderer, Core::Frontend::GraphicsContext& context, - Tegra::Control::Scheduler& scheduler_) { + Tegra::Control::Scheduler& scheduler) { rasterizer = renderer.ReadRasterizer(); - scheduler = &scheduler_; thread = std::jthread(RunThread, std::ref(system), std::ref(renderer), std::ref(context), - std::ref(scheduler_), std::ref(state)); + std::ref(scheduler), std::ref(state)); } void ThreadManager::SubmitList(s32 channel, Tegra::CommandList&& entries) { - scheduler->Push(channel, std::move(entries)); - PushCommand(SubmitListCommand()); + PushCommand(SubmitListCommand(channel, std::move(entries))); } void ThreadManager::FlushRegion(DAddr addr, u64 size) { diff --git a/src/video_core/gpu_thread.h b/src/video_core/gpu_thread.h index a4b01c42a..1a0de86b5 100755 --- a/src/video_core/gpu_thread.h +++ b/src/video_core/gpu_thread.h @@ -36,7 +36,13 @@ class RendererBase; namespace VideoCommon::GPUThread { /// Command to signal to the GPU thread that a command list is ready for processing -struct SubmitListCommand final {}; +struct SubmitListCommand final { + explicit SubmitListCommand(s32 channel_, Tegra::CommandList&& entries_) + : channel{channel_}, entries{std::move(entries_)} {} + + s32 channel; + Tegra::CommandList entries; +}; /// Command to signal to the GPU thread to flush a region struct FlushRegionCommand final { @@ -118,7 +124,6 @@ public: private: /// Pushes a command to be executed by the GPU thread u64 PushCommand(CommandData&& command_data, bool block = false); - Tegra::Control::Scheduler* scheduler; Core::System& system; const bool is_async; diff --git a/src/video_core/host1x/host1x.cpp b/src/video_core/host1x/host1x.cpp index 25939b7a4..6bc85b9ed 100755 --- a/src/video_core/host1x/host1x.cpp +++ b/src/video_core/host1x/host1x.cpp @@ -10,7 +10,7 @@ namespace Tegra::Host1x { Host1x::Host1x(Core::System& system_) : system{system_}, syncpoint_manager{}, - memory_manager(system.DeviceMemory()), gmmu_manager{system, memory_manager, 32, 0, 12}, + memory_manager(system.DeviceMemory()), gmmu_manager{system, memory_manager, 32, 12}, allocator{std::make_unique>(1 << 12)} {} Host1x::~Host1x() = default; diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index a0e0b30d1..38bd727ec 100755 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp @@ -22,12 +22,11 @@ using Tegra::Memory::GuestMemoryFlags; std::atomic MemoryManager::unique_identifier_generator{}; MemoryManager::MemoryManager(Core::System& system_, MaxwellDeviceMemoryManager& memory_, - u64 address_space_bits_, GPUVAddr split_address_, u64 big_page_bits_, - u64 page_bits_) + u64 address_space_bits_, u64 big_page_bits_, u64 page_bits_) : system{system_}, memory{memory_}, address_space_bits{address_space_bits_}, - split_address{split_address_}, page_bits{page_bits_}, big_page_bits{big_page_bits_}, - entries{}, big_entries{}, page_table{address_space_bits, address_space_bits + page_bits - 38, - page_bits != big_page_bits ? page_bits : 0}, + page_bits{page_bits_}, big_page_bits{big_page_bits_}, entries{}, big_entries{}, + page_table{address_space_bits, address_space_bits + page_bits - 38, + page_bits != big_page_bits ? page_bits : 0}, kind_map{PTEKind::INVALID}, unique_identifier{unique_identifier_generator.fetch_add( 1, std::memory_order_acq_rel)}, accumulator{std::make_unique()} { @@ -49,10 +48,10 @@ MemoryManager::MemoryManager(Core::System& system_, MaxwellDeviceMemoryManager& entries.resize(page_table_size / 32, 0); } -MemoryManager::MemoryManager(Core::System& system_, u64 address_space_bits_, - GPUVAddr split_address_, u64 big_page_bits_, u64 page_bits_) - : MemoryManager(system_, system_.Host1x().MemoryManager(), address_space_bits_, split_address_, - big_page_bits_, page_bits_) {} +MemoryManager::MemoryManager(Core::System& system_, u64 address_space_bits_, u64 big_page_bits_, + u64 page_bits_) + : MemoryManager(system_, system_.Host1x().MemoryManager(), address_space_bits_, big_page_bits_, + page_bits_) {} MemoryManager::~MemoryManager() = default; diff --git a/src/video_core/memory_manager.h b/src/video_core/memory_manager.h index eb3eb23eb..9b312b112 100755 --- a/src/video_core/memory_manager.h +++ b/src/video_core/memory_manager.h @@ -36,11 +36,10 @@ namespace Tegra { class MemoryManager final { public: explicit MemoryManager(Core::System& system_, u64 address_space_bits_ = 40, - GPUVAddr split_address = 1ULL << 34, u64 big_page_bits_ = 16, - u64 page_bits_ = 12); - explicit MemoryManager(Core::System& system_, MaxwellDeviceMemoryManager& memory_, - u64 address_space_bits_ = 40, GPUVAddr split_address = 1ULL << 34, u64 big_page_bits_ = 16, u64 page_bits_ = 12); + explicit MemoryManager(Core::System& system_, MaxwellDeviceMemoryManager& memory_, + u64 address_space_bits_ = 40, u64 big_page_bits_ = 16, + u64 page_bits_ = 12); ~MemoryManager(); static constexpr bool HAS_FLUSH_INVALIDATION = true; @@ -195,7 +194,6 @@ private: MaxwellDeviceMemoryManager& memory; const u64 address_space_bits; - GPUVAddr split_address; const u64 page_bits; u64 address_space_size; u64 page_size; diff --git a/src/yuzu/configuration/configure_hotkeys.cpp b/src/yuzu/configuration/configure_hotkeys.cpp index 257257467..33c3ecd22 100755 --- a/src/yuzu/configuration/configure_hotkeys.cpp +++ b/src/yuzu/configuration/configure_hotkeys.cpp @@ -45,15 +45,23 @@ ConfigureHotkeys::ConfigureHotkeys(Core::HID::HIDCore& hid_core, QWidget* parent controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); - connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); }); + connect(timeout_timer.get(), &QTimer::timeout, [this] { + const bool is_button_pressed = pressed_buttons != Core::HID::NpadButton::None || + pressed_home_button || pressed_capture_button; + SetPollingResult(!is_button_pressed); + }); connect(poll_timer.get(), &QTimer::timeout, [this] { - const auto buttons = controller->GetNpadButtons(); - const auto home_pressed = controller->GetHomeButtons().home != 0; - const auto capture_pressed = controller->GetCaptureButtons().capture != 0; - if (home_pressed || capture_pressed) { - SetPollingResult(buttons.raw, false); - return; + pressed_buttons |= controller->GetNpadButtons().raw; + pressed_home_button |= this->controller->GetHomeButtons().home != 0; + pressed_capture_button |= this->controller->GetCaptureButtons().capture != 0; + if (pressed_buttons != Core::HID::NpadButton::None || pressed_home_button || + pressed_capture_button) { + const QString button_name = + GetButtonCombinationName(pressed_buttons, pressed_home_button, + pressed_capture_button) + + QStringLiteral("..."); + model->setData(button_model_index, button_name); } }); RetranslateUI(); @@ -154,16 +162,14 @@ void ConfigureHotkeys::ConfigureController(QModelIndex index) { const auto previous_key = model->data(index); - input_setter = [this, index, previous_key](const Core::HID::NpadButton button, - const bool cancel) { + input_setter = [this, index, previous_key](const bool cancel) { if (cancel) { model->setData(index, previous_key); return; } - const auto home_pressed = this->controller->GetHomeButtons().home != 0; - const auto capture_pressed = this->controller->GetCaptureButtons().capture != 0; + const QString button_string = - GetButtonCombinationName(button, home_pressed, capture_pressed); + GetButtonCombinationName(pressed_buttons, pressed_home_button, pressed_capture_button); const auto [key_sequence_used, used_action] = IsUsedControllerKey(button_string); @@ -177,17 +183,22 @@ void ConfigureHotkeys::ConfigureController(QModelIndex index) { } }; + button_model_index = index; + pressed_buttons = Core::HID::NpadButton::None; + pressed_home_button = false; + pressed_capture_button = false; + model->setData(index, tr("[waiting]")); timeout_timer->start(2500); // Cancel after 2.5 seconds - poll_timer->start(200); // Check for new inputs every 200ms + poll_timer->start(100); // Check for new inputs every 100ms // We need to disable configuration to be able to read npad buttons controller->DisableConfiguration(); } -void ConfigureHotkeys::SetPollingResult(Core::HID::NpadButton button, const bool cancel) { +void ConfigureHotkeys::SetPollingResult(const bool cancel) { timeout_timer->stop(); poll_timer->stop(); - (*input_setter)(button, cancel); + (*input_setter)(cancel); // Re-Enable configuration controller->EnableConfiguration(); diff --git a/src/yuzu/configuration/configure_hotkeys.h b/src/yuzu/configuration/configure_hotkeys.h index 5651bdb21..c47bd7e2d 100755 --- a/src/yuzu/configuration/configure_hotkeys.h +++ b/src/yuzu/configuration/configure_hotkeys.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include namespace Common { @@ -54,14 +55,20 @@ private: void RestoreControllerHotkey(QModelIndex index); void RestoreHotkey(QModelIndex index); + void SetPollingResult(bool cancel); + QString GetButtonCombinationName(Core::HID::NpadButton button, bool home, bool capture) const; + std::unique_ptr ui; QStandardItemModel* model; - void SetPollingResult(Core::HID::NpadButton button, bool cancel); - QString GetButtonCombinationName(Core::HID::NpadButton button, bool home, bool capture) const; + bool pressed_home_button; + bool pressed_capture_button; + QModelIndex button_model_index; + Core::HID::NpadButton pressed_buttons; + Core::HID::EmulatedController* controller; std::unique_ptr timeout_timer; std::unique_ptr poll_timer; - std::optional> input_setter; + std::optional> input_setter; };