From 5ee07448936914b1debdb0c608fd27c81d4bc69e Mon Sep 17 00:00:00 2001 From: Jarrod Norwell Date: Fri, 31 May 2024 13:52:45 +0800 Subject: [PATCH] Fixed an issue with reserved memory, updated strings and reworked LogicOp fix --- src/common/uuid.h | 2 +- src/core/hle/kernel/k_page_table_base.cpp | 6 ++-- src/core/hle/kernel/k_thread.h | 2 +- .../hle/service/am/applets/applet_cabinet.cpp | 7 ++-- .../service/am/applets/applet_mii_edit.cpp | 2 +- .../hle/service/am/common_state_getter.cpp | 13 +++++-- src/core/hle/service/am/common_state_getter.h | 2 ++ .../service/am/frontend/applet_cabinet.cpp | 7 ++-- .../service/am/frontend/applet_mii_edit.cpp | 2 +- src/core/hle/service/am/lifecycle_manager.cpp | 6 +++- src/core/hle/service/am/lifecycle_manager.h | 3 ++ .../am/service/common_state_getter.cpp | 17 ++++++++-- .../service/am/service/common_state_getter.h | 2 ++ src/core/hle/service/nfc/common/device.cpp | 4 +-- src/core/hle/service/set/set_sys.cpp | 2 +- .../renderer_opengl/gl_rasterizer.cpp | 23 ++++++++----- .../renderer_vulkan/vk_pipeline_cache.cpp | 2 +- .../renderer_vulkan/vk_rasterizer.cpp | 34 +++++++++++++------ 18 files changed, 93 insertions(+), 43 deletions(-) diff --git a/src/common/uuid.h b/src/common/uuid.h index bee4031..9ef6017 100644 --- a/src/common/uuid.h +++ b/src/common/uuid.h @@ -82,7 +82,7 @@ struct UUID { */ static constexpr UUID MakeDefault() { return UUID{ - {'y', 'u', 'z', 'u', ' ', 'D', 'e', 'f', 'a', 'u', 'l', 't', ' ', 'U', 'I', 'D'}, + {'s', 'u', 'd', 'a', ' ', 'D', 'e', 'f', 'a', 'u', 'l', 't', ' ', 'U', 'I', 'D'}, }; } diff --git a/src/core/hle/kernel/k_page_table_base.cpp b/src/core/hle/kernel/k_page_table_base.cpp index 6e10d68..cc8e4d3 100644 --- a/src/core/hle/kernel/k_page_table_base.cpp +++ b/src/core/hle/kernel/k_page_table_base.cpp @@ -259,9 +259,9 @@ Result KPageTableBase::InitializeForProcess(Svc::CreateProcessFlag as_type, bool // [switchbrew.org][0] Address space type must be 39-bit // [switchbrew.org][1] System resource size must be > 0 // [switchbrew.org][2] KTargetSystem::IsDebugMode() must be true - if (as_type == Svc::CreateProcessFlag::EnableReservedRegionExtraSize) { - m_reserved_region_extra_size = GetAddressSpaceSize() / 8; - alias_region_size += alias_region_size; + if ((as_type & Svc::CreateProcessFlag::AddressSpaceMask) == + Svc::CreateProcessFlag::EnableReservedRegionExtraSize) { + m_reserved_region_extra_size += GetAddressSpaceSize() / 8; } } else { stack_region_size = 0; diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h index 3d4b395..c516e27 100644 --- a/src/core/hle/kernel/k_thread.h +++ b/src/core/hle/kernel/k_thread.h @@ -656,7 +656,7 @@ public: void* native_context{}; std::atomic lock{1}; bool is_running{}; - u32 magic{Common::MakeMagic('Y', 'U', 'Z', 'U')}; + u32 magic{Common::MakeMagic('S', 'U', 'D', 'A')}; }; NativeExecutionParameters& GetNativeExecutionParameters() { diff --git a/src/core/hle/service/am/applets/applet_cabinet.cpp b/src/core/hle/service/am/applets/applet_cabinet.cpp index 66d0fac..4b57257 100644 --- a/src/core/hle/service/am/applets/applet_cabinet.cpp +++ b/src/core/hle/service/am/applets/applet_cabinet.cpp @@ -17,9 +17,8 @@ namespace Service::AM::Applets { Cabinet::Cabinet(Core::System& system_, LibraryAppletMode applet_mode_, const Core::Frontend::CabinetApplet& frontend_) - : Applet{system_, applet_mode_}, frontend{frontend_}, system{system_}, service_context{ - system_, - "CabinetApplet"} { + : Applet{system_, applet_mode_}, frontend{frontend_}, system{system_}, + service_context{system_, "CabinetApplet"} { availability_change_event = service_context.CreateEvent("CabinetApplet:AvailabilityChangeEvent"); @@ -123,7 +122,7 @@ void Cabinet::DisplayCompleted(bool apply_changes, std::string_view amiibo_name) std::memcpy(register_info.amiibo_name.data(), amiibo_name.data(), std::min(amiibo_name.size(), register_info.amiibo_name.size() - 1)); register_info.mii_store_data.BuildRandom(Mii::Age::All, Mii::Gender::All, Mii::Race::All); - register_info.mii_store_data.SetNickname({u'y', u'u', u'z', u'u'}); + register_info.mii_store_data.SetNickname({u's', u'u', u'd', u'a'}); nfp_device->SetRegisterInfoPrivate(register_info); break; } diff --git a/src/core/hle/service/am/applets/applet_mii_edit.cpp b/src/core/hle/service/am/applets/applet_mii_edit.cpp index b8d1459..a7dd5ee 100644 --- a/src/core/hle/service/am/applets/applet_mii_edit.cpp +++ b/src/core/hle/service/am/applets/applet_mii_edit.cpp @@ -93,7 +93,7 @@ void MiiEdit::Execute() { case MiiEditAppletMode::AppendMii: { Mii::StoreData store_data{}; store_data.BuildRandom(Mii::Age::All, Mii::Gender::All, Mii::Race::All); - store_data.SetNickname({u'y', u'u', u'z', u'u'}); + store_data.SetNickname({u's', u'u', u'd', u'a'}); store_data.SetChecksum(); const auto result = manager->AddOrReplace(metadata, store_data); diff --git a/src/core/hle/service/am/common_state_getter.cpp b/src/core/hle/service/am/common_state_getter.cpp index edfe1c7..ba058bd 100644 --- a/src/core/hle/service/am/common_state_getter.cpp +++ b/src/core/hle/service/am/common_state_getter.cpp @@ -48,8 +48,8 @@ ICommonStateGetter::ICommonStateGetter(Core::System& system_, std::shared_ptr applet_, LibraryAppletMode applet_mode_, const Core::Frontend::CabinetApplet& frontend_) - : FrontendApplet{system_, applet_, applet_mode_}, frontend{frontend_}, service_context{ - system_, - "CabinetApplet"} { + : FrontendApplet{system_, applet_, applet_mode_}, frontend{frontend_}, + service_context{system_, "CabinetApplet"} { availability_change_event = service_context.CreateEvent("CabinetApplet:AvailabilityChangeEvent"); @@ -120,7 +119,7 @@ void Cabinet::DisplayCompleted(bool apply_changes, std::string_view amiibo_name) std::memcpy(register_info.amiibo_name.data(), amiibo_name.data(), std::min(amiibo_name.size(), register_info.amiibo_name.size() - 1)); register_info.mii_store_data.BuildRandom(Mii::Age::All, Mii::Gender::All, Mii::Race::All); - register_info.mii_store_data.SetNickname({u'y', u'u', u'z', u'u'}); + register_info.mii_store_data.SetNickname({u's', u'u', u'd', u'a'}); nfp_device->SetRegisterInfoPrivate(register_info); break; } diff --git a/src/core/hle/service/am/frontend/applet_mii_edit.cpp b/src/core/hle/service/am/frontend/applet_mii_edit.cpp index 1207cfc..6c7dcf1 100644 --- a/src/core/hle/service/am/frontend/applet_mii_edit.cpp +++ b/src/core/hle/service/am/frontend/applet_mii_edit.cpp @@ -90,7 +90,7 @@ void MiiEdit::Execute() { case MiiEditAppletMode::AppendMii: { Mii::StoreData store_data{}; store_data.BuildRandom(Mii::Age::All, Mii::Gender::All, Mii::Race::All); - store_data.SetNickname({u'y', u'u', u'z', u'u'}); + store_data.SetNickname({u's', u'u', u'd', u'a'}); store_data.SetChecksum(); const auto result = manager->AddOrReplace(metadata, store_data); diff --git a/src/core/hle/service/am/lifecycle_manager.cpp b/src/core/hle/service/am/lifecycle_manager.cpp index cd00397..9f48896 100644 --- a/src/core/hle/service/am/lifecycle_manager.cpp +++ b/src/core/hle/service/am/lifecycle_manager.cpp @@ -9,7 +9,7 @@ namespace Service::AM { LifecycleManager::LifecycleManager(Core::System& system, KernelHelpers::ServiceContext& context, bool is_application) : m_system_event(context), m_operation_mode_changed_system_event(context), - m_is_application(is_application) {} + m_hdcp_state_changed_event(context), m_is_application(is_application) {} LifecycleManager::~LifecycleManager() = default; @@ -21,6 +21,10 @@ Event& LifecycleManager::GetOperationModeChangedSystemEvent() { return m_operation_mode_changed_system_event; } +Event& LifecycleManager::GetHDCPStateChangedEvent() { + return m_hdcp_state_changed_event; +} + void LifecycleManager::PushUnorderedMessage(AppletMessage message) { m_unordered_messages.push_back(message); this->SignalSystemEventIfNeeded(); diff --git a/src/core/hle/service/am/lifecycle_manager.h b/src/core/hle/service/am/lifecycle_manager.h index b3ebe6d..bf03771 100644 --- a/src/core/hle/service/am/lifecycle_manager.h +++ b/src/core/hle/service/am/lifecycle_manager.h @@ -42,6 +42,7 @@ public: public: Event& GetSystemEvent(); Event& GetOperationModeChangedSystemEvent(); + Event& GetHDCPStateChangedEvent(); public: bool IsApplication() { @@ -145,12 +146,14 @@ private: private: Event m_system_event; Event m_operation_mode_changed_system_event; + Event m_hdcp_state_changed_event; std::list m_unordered_messages{}; bool m_is_application{}; bool m_focus_state_changed_notification_enabled{true}; bool m_operation_mode_changed_notification_enabled{true}; + bool m_hdcp_state_changed_notification_enabled{true}; bool m_performance_mode_changed_notification_enabled{true}; bool m_resume_notification_enabled{}; diff --git a/src/core/hle/service/am/service/common_state_getter.cpp b/src/core/hle/service/am/service/common_state_getter.cpp index c8563e9..fea3d53 100644 --- a/src/core/hle/service/am/service/common_state_getter.cpp +++ b/src/core/hle/service/am/service/common_state_getter.cpp @@ -48,8 +48,8 @@ ICommonStateGetter::ICommonStateGetter(Core::System& system_, std::shared_ptr, "GetDefaultDisplayResolution"}, {61, D<&ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent>, "GetDefaultDisplayResolutionChangeEvent"}, - {62, nullptr, "GetHdcpAuthenticationState"}, - {63, nullptr, "GetHdcpAuthenticationStateChangeEvent"}, + {62, D<&ICommonStateGetter::GetHdcpAuthenticationState>, "GetHdcpAuthenticationState"}, + {63, D<&ICommonStateGetter::GetHdcpAuthenticationStateChangeEvent>, "GetHdcpAuthenticationStateChangeEvent"}, {64, nullptr, "SetTvPowerStateMatchingMode"}, {65, nullptr, "GetApplicationIdByContentActionName"}, {66, &ICommonStateGetter::SetCpuBoostMode, "SetCpuBoostMode"}, @@ -142,6 +142,19 @@ Result ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent( R_SUCCEED(); } +Result ICommonStateGetter::GetHdcpAuthenticationState(Out out_state) { + LOG_DEBUG(Service_AM, "called"); + *out_state = 1; + R_SUCCEED(); +} + +Result ICommonStateGetter::GetHdcpAuthenticationStateChangeEvent( + OutCopyHandle out_event) { + LOG_DEBUG(Service_AM, "called"); + *out_event = m_applet->lifecycle_manager.GetHDCPStateChangedEvent().GetHandle(); + R_SUCCEED(); +} + Result ICommonStateGetter::GetOperationMode(Out out_operation_mode) { const bool use_docked_mode{Settings::IsDockedMode()}; LOG_DEBUG(Service_AM, "called, use_docked_mode={}", use_docked_mode); diff --git a/src/core/hle/service/am/service/common_state_getter.h b/src/core/hle/service/am/service/common_state_getter.h index 32b96ce..75713a2 100644 --- a/src/core/hle/service/am/service/common_state_getter.h +++ b/src/core/hle/service/am/service/common_state_getter.h @@ -35,6 +35,8 @@ private: Result GetWriterLockAccessorEx(Out> out_lock_accessor, u32 button_type); Result GetDefaultDisplayResolutionChangeEvent(OutCopyHandle out_event); + Result GetHdcpAuthenticationState(Out out_state); + Result GetHdcpAuthenticationStateChangeEvent(OutCopyHandle out_event); Result GetOperationMode(Out out_operation_mode); Result GetPerformanceMode(Out out_performance_mode); Result GetBootMode(Out out_boot_mode); diff --git a/src/core/hle/service/nfc/common/device.cpp b/src/core/hle/service/nfc/common/device.cpp index 0a96700..5bd356c 100644 --- a/src/core/hle/service/nfc/common/device.cpp +++ b/src/core/hle/service/nfc/common/device.cpp @@ -628,7 +628,7 @@ Result NfcDevice::Restore() { LOG_ERROR(Service_NFP, "Regenerating mii data"); Mii::StoreData new_mii{}; new_mii.BuildRandom(Mii::Age::All, Mii::Gender::All, Mii::Race::All); - new_mii.SetNickname({u'y', u'u', u'z', u'u', u'\0'}); + new_mii.SetNickname({u's', u'u', u'd', u'a', u'\0'}); tag_data.owner_mii.BuildFromStoreData(new_mii); tag_data.mii_extension.SetFromStoreData(new_mii); @@ -1494,7 +1494,7 @@ void NfcDevice::BuildAmiiboWithoutKeys(NFP::NTAG215File& stubbed_tag_data, settings.write_date = GetAmiiboDate(GetCurrentPosixTime()); // Register info - SetAmiiboName(settings, {'y', 'u', 'z', 'u', 'A', 'm', 'i', 'i', 'b', 'o'}); + SetAmiiboName(settings, {'s', 'u', 'd', 'a', 'A', 'm', 'i', 'i', 'b', 'o'}); settings.settings.font_region.Assign(0); settings.init_date = GetAmiiboDate(GetCurrentPosixTime()); store_data.BuildBase(Mii::Gender::Male); diff --git a/src/core/hle/service/set/set_sys.cpp b/src/core/hle/service/set/set_sys.cpp index 7b2dd05..aca5613 100644 --- a/src/core/hle/service/set/set_sys.cpp +++ b/src/core/hle/service/set/set_sys.cpp @@ -26,7 +26,7 @@ namespace Service::Set { namespace { constexpr u32 SETTINGS_VERSION{1u}; -constexpr auto SETTINGS_MAGIC = Common::MakeMagic('y', 'u', 'z', 'u', '_', 's', 'e', 't'); +constexpr auto SETTINGS_MAGIC = Common::MakeMagic('s', 'u', 'd', 'a', '_', 's', 'e', 't'); struct SettingsHeader { u64 magic; u32 version; diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index f1d96b1..2e3e822 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -1208,17 +1208,24 @@ void RasterizerOpenGL::SyncLogicOpState() { } flags[Dirty::LogicOp] = false; - const auto& regs = maxwell3d->regs; + auto& regs = maxwell3d->regs; - bool has_float = false; + if (device.IsAmd()) { + struct In { + const Tegra::Engines::Maxwell3D::Regs::VertexAttribute::Type d; + In(Tegra::Engines::Maxwell3D::Regs::VertexAttribute::Type n) : d(n) {} + bool operator()(Tegra::Engines::Maxwell3D::Regs::VertexAttribute n) const { + return n.type == d; + } + }; - if (std::any_of(regs.vertex_attrib_format.begin(), regs.vertex_attrib_format.end(), - [&](Tegra::Engines::Maxwell3D::Regs::VertexAttribute attribute) { - return IsAnyFloat(attribute); - })) - has_float = true; + bool has_float = + std::any_of(regs.vertex_attrib_format.begin(), regs.vertex_attrib_format.end(), + In(Tegra::Engines::Maxwell3D::Regs::VertexAttribute::Type::Float)); + regs.logic_op.enable = static_cast(!has_float); + } - if (regs.logic_op.enable && !has_float) { + if (regs.logic_op.enable) { glEnable(GL_COLOR_LOGIC_OP); glLogicOp(MaxwellToGL::LogicOp(regs.logic_op.op)); } else { diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 56fe0d9..97609cd 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -54,7 +54,7 @@ using VideoCommon::GenericEnvironment; using VideoCommon::GraphicsEnvironment; constexpr u32 CACHE_VERSION = 11; -constexpr std::array VULKAN_CACHE_MAGIC_NUMBER{'y', 'u', 'z', 'u', 'v', 'k', 'c', 'h'}; +constexpr std::array VULKAN_CACHE_MAGIC_NUMBER{'s', 'u', 'd', 'a', 'v', 'k', 'c', 'h'}; template auto MakeSpan(Container& container) { diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 5b91391..a30267f 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -952,7 +952,27 @@ void RasterizerVulkan::UpdateDynamicStates() { UpdateDepthBiasEnable(regs); } if (device.IsExtExtendedDynamicState3EnablesSupported()) { - UpdateLogicOpEnable(regs); + const auto old = regs.logic_op.enable; + + if (device.GetDriverID() == VkDriverIdKHR::VK_DRIVER_ID_AMD_OPEN_SOURCE || + device.GetDriverID() == VkDriverIdKHR::VK_DRIVER_ID_AMD_OPEN_SOURCE_KHR) { + struct In { + const Tegra::Engines::Maxwell3D::Regs::VertexAttribute::Type d; + In(Tegra::Engines::Maxwell3D::Regs::VertexAttribute::Type n) : d(n) {} + bool operator()(Tegra::Engines::Maxwell3D::Regs::VertexAttribute n) const { + return n.type == d; + } + }; + + auto has_float = std::any_of( + regs.vertex_attrib_format.begin(), regs.vertex_attrib_format.end(), + In(Tegra::Engines::Maxwell3D::Regs::VertexAttribute::Type::Float)); + + regs.logic_op.enable = static_cast(!has_float); + UpdateLogicOpEnable(regs); + regs.logic_op.enable = old; + } else + UpdateLogicOpEnable(regs); UpdateDepthClampEnable(regs); } } @@ -1319,16 +1339,8 @@ void RasterizerVulkan::UpdateLogicOpEnable(Tegra::Engines::Maxwell3D::Regs& regs return; } - scheduler.Record([&, regs](vk::CommandBuffer cmdbuf) { - bool has_float = false; - - if (std::any_of(regs.vertex_attrib_format.begin(), regs.vertex_attrib_format.end(), - [&](Tegra::Engines::Maxwell3D::Regs::VertexAttribute attribute) { - return IsAnyFloat(attribute); - })) - has_float = true; - - cmdbuf.SetLogicOpEnableEXT((regs.logic_op.enable != 0 && !has_float) ? true : false); + scheduler.Record([&, enable = regs.logic_op.enable](vk::CommandBuffer cmdbuf) { + cmdbuf.SetLogicOpEnableEXT(enable != 0); }); }