summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/settings.h1
-rw-r--r--src/common/x64/xbyak_abi.h16
-rw-r--r--src/core/hle/kernel/k_affinity_mask.h2
-rw-r--r--src/core/hle/kernel/k_page_table.cpp204
-rw-r--r--src/core/hle/kernel/k_page_table.h11
-rw-r--r--src/core/hle/kernel/k_process.cpp26
-rw-r--r--src/core/hle/kernel/k_process.h8
-rw-r--r--src/core/hle/kernel/k_thread.cpp11
-rw-r--r--src/core/hle/kernel/svc.cpp4
-rw-r--r--src/input_common/drivers/udp_client.cpp8
-rw-r--r--src/input_common/drivers/udp_client.h4
-rw-r--r--src/input_common/input_engine.h4
-rw-r--r--src/input_common/input_mapping.cpp11
-rw-r--r--src/input_common/input_mapping.h8
-rw-r--r--src/input_common/main.cpp6
-rw-r--r--src/input_common/main.h2
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate_program.h3
-rw-r--r--src/video_core/engines/maxwell_3d.cpp2
-rw-r--r--src/video_core/gpu.h16
-rw-r--r--src/video_core/macro/macro.cpp13
-rw-r--r--src/video_core/macro/macro.h2
-rw-r--r--src/video_core/macro/macro_hle.cpp34
-rw-r--r--src/video_core/macro/macro_hle.h21
-rw-r--r--src/video_core/macro/macro_interpreter.cpp92
-rw-r--r--src/video_core/macro/macro_interpreter.h78
-rw-r--r--src/video_core/macro/macro_jit_x64.cpp104
-rw-r--r--src/video_core/macro/macro_jit_x64.h71
-rw-r--r--src/video_core/renderer_vulkan/vk_fsr.cpp2
-rw-r--r--src/yuzu/configuration/config.cpp3
-rw-r--r--src/yuzu/configuration/configure_graphics.ui2
-rw-r--r--src/yuzu/configuration/configure_input_advanced.cpp2
-rw-r--r--src/yuzu/configuration/configure_input_advanced.ui19
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp59
-rw-r--r--src/yuzu/hotkeys.cpp3
-rw-r--r--src/yuzu/util/controller_navigation.cpp3
35 files changed, 430 insertions, 425 deletions
diff --git a/src/common/settings.h b/src/common/settings.h
index d01c0448c..9bee6e10f 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -554,6 +554,7 @@ struct Values {
554 Setting<bool> use_docked_mode{true, "use_docked_mode"}; 554 Setting<bool> use_docked_mode{true, "use_docked_mode"};
555 555
556 BasicSetting<bool> enable_raw_input{false, "enable_raw_input"}; 556 BasicSetting<bool> enable_raw_input{false, "enable_raw_input"};
557 BasicSetting<bool> controller_navigation{true, "controller_navigation"};
557 558
558 Setting<bool> vibration_enabled{true, "vibration_enabled"}; 559 Setting<bool> vibration_enabled{true, "vibration_enabled"};
559 Setting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"}; 560 Setting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"};
diff --git a/src/common/x64/xbyak_abi.h b/src/common/x64/xbyak_abi.h
index 0ddf9b83e..87b3d63a4 100644
--- a/src/common/x64/xbyak_abi.h
+++ b/src/common/x64/xbyak_abi.h
@@ -37,12 +37,12 @@ constexpr Xbyak::Reg IndexToReg(size_t reg_index) {
37 } 37 }
38} 38}
39 39
40inline std::bitset<32> BuildRegSet(std::initializer_list<Xbyak::Reg> regs) { 40constexpr std::bitset<32> BuildRegSet(std::initializer_list<Xbyak::Reg> regs) {
41 std::bitset<32> bits; 41 size_t bits = 0;
42 for (const Xbyak::Reg& reg : regs) { 42 for (const Xbyak::Reg& reg : regs) {
43 bits[RegToIndex(reg)] = true; 43 bits |= size_t{1} << RegToIndex(reg);
44 } 44 }
45 return bits; 45 return {bits};
46} 46}
47 47
48constexpr inline std::bitset<32> ABI_ALL_GPRS(0x0000FFFF); 48constexpr inline std::bitset<32> ABI_ALL_GPRS(0x0000FFFF);
@@ -57,7 +57,7 @@ constexpr inline Xbyak::Reg ABI_PARAM2 = Xbyak::util::rdx;
57constexpr inline Xbyak::Reg ABI_PARAM3 = Xbyak::util::r8; 57constexpr inline Xbyak::Reg ABI_PARAM3 = Xbyak::util::r8;
58constexpr inline Xbyak::Reg ABI_PARAM4 = Xbyak::util::r9; 58constexpr inline Xbyak::Reg ABI_PARAM4 = Xbyak::util::r9;
59 59
60const std::bitset<32> ABI_ALL_CALLER_SAVED = BuildRegSet({ 60constexpr inline std::bitset<32> ABI_ALL_CALLER_SAVED = BuildRegSet({
61 // GPRs 61 // GPRs
62 Xbyak::util::rcx, 62 Xbyak::util::rcx,
63 Xbyak::util::rdx, 63 Xbyak::util::rdx,
@@ -74,7 +74,7 @@ const std::bitset<32> ABI_ALL_CALLER_SAVED = BuildRegSet({
74 Xbyak::util::xmm5, 74 Xbyak::util::xmm5,
75}); 75});
76 76
77const std::bitset<32> ABI_ALL_CALLEE_SAVED = BuildRegSet({ 77constexpr inline std::bitset<32> ABI_ALL_CALLEE_SAVED = BuildRegSet({
78 // GPRs 78 // GPRs
79 Xbyak::util::rbx, 79 Xbyak::util::rbx,
80 Xbyak::util::rsi, 80 Xbyak::util::rsi,
@@ -108,7 +108,7 @@ constexpr inline Xbyak::Reg ABI_PARAM2 = Xbyak::util::rsi;
108constexpr inline Xbyak::Reg ABI_PARAM3 = Xbyak::util::rdx; 108constexpr inline Xbyak::Reg ABI_PARAM3 = Xbyak::util::rdx;
109constexpr inline Xbyak::Reg ABI_PARAM4 = Xbyak::util::rcx; 109constexpr inline Xbyak::Reg ABI_PARAM4 = Xbyak::util::rcx;
110 110
111const std::bitset<32> ABI_ALL_CALLER_SAVED = BuildRegSet({ 111constexpr inline std::bitset<32> ABI_ALL_CALLER_SAVED = BuildRegSet({
112 // GPRs 112 // GPRs
113 Xbyak::util::rcx, 113 Xbyak::util::rcx,
114 Xbyak::util::rdx, 114 Xbyak::util::rdx,
@@ -137,7 +137,7 @@ const std::bitset<32> ABI_ALL_CALLER_SAVED = BuildRegSet({
137 Xbyak::util::xmm15, 137 Xbyak::util::xmm15,
138}); 138});
139 139
140const std::bitset<32> ABI_ALL_CALLEE_SAVED = BuildRegSet({ 140constexpr inline std::bitset<32> ABI_ALL_CALLEE_SAVED = BuildRegSet({
141 // GPRs 141 // GPRs
142 Xbyak::util::rbx, 142 Xbyak::util::rbx,
143 Xbyak::util::rbp, 143 Xbyak::util::rbp,
diff --git a/src/core/hle/kernel/k_affinity_mask.h b/src/core/hle/kernel/k_affinity_mask.h
index b906895fc..cf704ce87 100644
--- a/src/core/hle/kernel/k_affinity_mask.h
+++ b/src/core/hle/kernel/k_affinity_mask.h
@@ -31,8 +31,6 @@ public:
31 } 31 }
32 32
33 constexpr void SetAffinity(s32 core, bool set) { 33 constexpr void SetAffinity(s32 core, bool set) {
34 ASSERT(0 <= core && core < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
35
36 if (set) { 34 if (set) {
37 this->mask |= GetCoreBit(core); 35 this->mask |= GetCoreBit(core);
38 } else { 36 } else {
diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp
index b650ea31d..2ebbc0819 100644
--- a/src/core/hle/kernel/k_page_table.cpp
+++ b/src/core/hle/kernel/k_page_table.cpp
@@ -276,22 +276,23 @@ ResultCode KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_
276 276
277ResultCode KPageTable::MapProcessCode(VAddr addr, std::size_t num_pages, KMemoryState state, 277ResultCode KPageTable::MapProcessCode(VAddr addr, std::size_t num_pages, KMemoryState state,
278 KMemoryPermission perm) { 278 KMemoryPermission perm) {
279 std::lock_guard lock{page_table_lock};
280
281 const u64 size{num_pages * PageSize}; 279 const u64 size{num_pages * PageSize};
282 280
283 if (!CanContain(addr, size, state)) { 281 // Validate the mapping request.
284 return ResultInvalidCurrentMemory; 282 R_UNLESS(this->CanContain(addr, size, state), ResultInvalidCurrentMemory);
285 }
286 283
287 if (IsRegionMapped(addr, size)) { 284 // Lock the table.
288 return ResultInvalidCurrentMemory; 285 std::lock_guard lock{page_table_lock};
289 } 286
287 // Verify that the destination memory is unmapped.
288 R_TRY(this->CheckMemoryState(addr, size, KMemoryState::All, KMemoryState::Free,
289 KMemoryPermission::None, KMemoryPermission::None,
290 KMemoryAttribute::None, KMemoryAttribute::None));
290 291
291 KPageLinkedList page_linked_list; 292 KPageLinkedList page_linked_list;
292 CASCADE_CODE(system.Kernel().MemoryManager().Allocate(page_linked_list, num_pages, memory_pool, 293 R_TRY(system.Kernel().MemoryManager().Allocate(page_linked_list, num_pages, memory_pool,
293 allocation_option)); 294 allocation_option));
294 CASCADE_CODE(Operate(addr, num_pages, page_linked_list, OperationType::MapGroup)); 295 R_TRY(Operate(addr, num_pages, page_linked_list, OperationType::MapGroup));
295 296
296 block_manager->Update(addr, num_pages, state, perm); 297 block_manager->Update(addr, num_pages, state, perm);
297 298
@@ -395,39 +396,12 @@ ResultCode KPageTable::UnmapProcessMemory(VAddr dst_addr, std::size_t size,
395 396
396 return ResultSuccess; 397 return ResultSuccess;
397} 398}
398void KPageTable::MapPhysicalMemory(KPageLinkedList& page_linked_list, VAddr start, VAddr end) {
399 auto node{page_linked_list.Nodes().begin()};
400 PAddr map_addr{node->GetAddress()};
401 std::size_t src_num_pages{node->GetNumPages()};
402
403 block_manager->IterateForRange(start, end, [&](const KMemoryInfo& info) {
404 if (info.state != KMemoryState::Free) {
405 return;
406 }
407
408 std::size_t dst_num_pages{GetSizeInRange(info, start, end) / PageSize};
409 VAddr dst_addr{GetAddressInRange(info, start)};
410
411 while (dst_num_pages) {
412 if (!src_num_pages) {
413 node = std::next(node);
414 map_addr = node->GetAddress();
415 src_num_pages = node->GetNumPages();
416 }
417
418 const std::size_t num_pages{std::min(src_num_pages, dst_num_pages)};
419 Operate(dst_addr, num_pages, KMemoryPermission::UserReadWrite, OperationType::Map,
420 map_addr);
421
422 dst_addr += num_pages * PageSize;
423 map_addr += num_pages * PageSize;
424 src_num_pages -= num_pages;
425 dst_num_pages -= num_pages;
426 }
427 });
428}
429 399
430ResultCode KPageTable::MapPhysicalMemory(VAddr addr, std::size_t size) { 400ResultCode KPageTable::MapPhysicalMemory(VAddr addr, std::size_t size) {
401 // Lock the physical memory lock.
402 std::lock_guard phys_lk(map_physical_memory_lock);
403
404 // Lock the table.
431 std::lock_guard lock{page_table_lock}; 405 std::lock_guard lock{page_table_lock};
432 406
433 std::size_t mapped_size{}; 407 std::size_t mapped_size{};
@@ -463,7 +437,35 @@ ResultCode KPageTable::MapPhysicalMemory(VAddr addr, std::size_t size) {
463 // We succeeded, so commit the memory reservation. 437 // We succeeded, so commit the memory reservation.
464 memory_reservation.Commit(); 438 memory_reservation.Commit();
465 439
466 MapPhysicalMemory(page_linked_list, addr, end_addr); 440 // Map the memory.
441 auto node{page_linked_list.Nodes().begin()};
442 PAddr map_addr{node->GetAddress()};
443 std::size_t src_num_pages{node->GetNumPages()};
444 block_manager->IterateForRange(addr, end_addr, [&](const KMemoryInfo& info) {
445 if (info.state != KMemoryState::Free) {
446 return;
447 }
448
449 std::size_t dst_num_pages{GetSizeInRange(info, addr, end_addr) / PageSize};
450 VAddr dst_addr{GetAddressInRange(info, addr)};
451
452 while (dst_num_pages) {
453 if (!src_num_pages) {
454 node = std::next(node);
455 map_addr = node->GetAddress();
456 src_num_pages = node->GetNumPages();
457 }
458
459 const std::size_t num_pages{std::min(src_num_pages, dst_num_pages)};
460 Operate(dst_addr, num_pages, KMemoryPermission::UserReadWrite, OperationType::Map,
461 map_addr);
462
463 dst_addr += num_pages * PageSize;
464 map_addr += num_pages * PageSize;
465 src_num_pages -= num_pages;
466 dst_num_pages -= num_pages;
467 }
468 });
467 469
468 mapped_physical_memory_size += remaining_size; 470 mapped_physical_memory_size += remaining_size;
469 471
@@ -503,23 +505,8 @@ ResultCode KPageTable::UnmapPhysicalMemory(VAddr addr, std::size_t size) {
503 return ResultSuccess; 505 return ResultSuccess;
504 } 506 }
505 507
506 CASCADE_CODE(UnmapMemory(addr, size));
507
508 auto process{system.Kernel().CurrentProcess()};
509 process->GetResourceLimit()->Release(LimitableResource::PhysicalMemory, mapped_size);
510 mapped_physical_memory_size -= mapped_size;
511
512 return ResultSuccess;
513}
514
515ResultCode KPageTable::UnmapMemory(VAddr addr, std::size_t size) {
516 std::lock_guard lock{page_table_lock};
517
518 const VAddr end_addr{addr + size};
519 ResultCode result{ResultSuccess};
520 KPageLinkedList page_linked_list;
521
522 // Unmap each region within the range 508 // Unmap each region within the range
509 KPageLinkedList page_linked_list;
523 block_manager->IterateForRange(addr, end_addr, [&](const KMemoryInfo& info) { 510 block_manager->IterateForRange(addr, end_addr, [&](const KMemoryInfo& info) {
524 if (info.state == KMemoryState::Normal) { 511 if (info.state == KMemoryState::Normal) {
525 const std::size_t block_size{GetSizeInRange(info, addr, end_addr)}; 512 const std::size_t block_size{GetSizeInRange(info, addr, end_addr)};
@@ -535,7 +522,6 @@ ResultCode KPageTable::UnmapMemory(VAddr addr, std::size_t size) {
535 } 522 }
536 } 523 }
537 }); 524 });
538
539 if (result.IsError()) { 525 if (result.IsError()) {
540 return result; 526 return result;
541 } 527 }
@@ -546,10 +532,14 @@ ResultCode KPageTable::UnmapMemory(VAddr addr, std::size_t size) {
546 532
547 block_manager->Update(addr, num_pages, KMemoryState::Free); 533 block_manager->Update(addr, num_pages, KMemoryState::Free);
548 534
535 auto process{system.Kernel().CurrentProcess()};
536 process->GetResourceLimit()->Release(LimitableResource::PhysicalMemory, mapped_size);
537 mapped_physical_memory_size -= mapped_size;
538
549 return ResultSuccess; 539 return ResultSuccess;
550} 540}
551 541
552ResultCode KPageTable::Map(VAddr dst_addr, VAddr src_addr, std::size_t size) { 542ResultCode KPageTable::MapMemory(VAddr dst_addr, VAddr src_addr, std::size_t size) {
553 std::lock_guard lock{page_table_lock}; 543 std::lock_guard lock{page_table_lock};
554 544
555 KMemoryState src_state{}; 545 KMemoryState src_state{};
@@ -588,7 +578,7 @@ ResultCode KPageTable::Map(VAddr dst_addr, VAddr src_addr, std::size_t size) {
588 return ResultSuccess; 578 return ResultSuccess;
589} 579}
590 580
591ResultCode KPageTable::Unmap(VAddr dst_addr, VAddr src_addr, std::size_t size) { 581ResultCode KPageTable::UnmapMemory(VAddr dst_addr, VAddr src_addr, std::size_t size) {
592 std::lock_guard lock{page_table_lock}; 582 std::lock_guard lock{page_table_lock};
593 583
594 KMemoryState src_state{}; 584 KMemoryState src_state{};
@@ -652,24 +642,26 @@ ResultCode KPageTable::MapPages(VAddr addr, const KPageLinkedList& page_linked_l
652 return ResultSuccess; 642 return ResultSuccess;
653} 643}
654 644
655ResultCode KPageTable::MapPages(VAddr addr, KPageLinkedList& page_linked_list, KMemoryState state, 645ResultCode KPageTable::MapPages(VAddr address, KPageLinkedList& page_linked_list,
656 KMemoryPermission perm) { 646 KMemoryState state, KMemoryPermission perm) {
657 std::lock_guard lock{page_table_lock}; 647 // Check that the map is in range.
658
659 const std::size_t num_pages{page_linked_list.GetNumPages()}; 648 const std::size_t num_pages{page_linked_list.GetNumPages()};
660 const std::size_t size{num_pages * PageSize}; 649 const std::size_t size{num_pages * PageSize};
650 R_UNLESS(this->CanContain(address, size, state), ResultInvalidCurrentMemory);
661 651
662 if (!CanContain(addr, size, state)) { 652 // Lock the table.
663 return ResultInvalidCurrentMemory; 653 std::lock_guard lock{page_table_lock};
664 }
665 654
666 if (IsRegionMapped(addr, num_pages * PageSize)) { 655 // Check the memory state.
667 return ResultInvalidCurrentMemory; 656 R_TRY(this->CheckMemoryState(address, size, KMemoryState::All, KMemoryState::Free,
668 } 657 KMemoryPermission::None, KMemoryPermission::None,
658 KMemoryAttribute::None, KMemoryAttribute::None));
669 659
670 CASCADE_CODE(MapPages(addr, page_linked_list, perm)); 660 // Map the pages.
661 R_TRY(MapPages(address, page_linked_list, perm));
671 662
672 block_manager->Update(addr, num_pages, state, perm); 663 // Update the blocks.
664 block_manager->Update(address, num_pages, state, perm);
673 665
674 return ResultSuccess; 666 return ResultSuccess;
675} 667}
@@ -693,21 +685,23 @@ ResultCode KPageTable::UnmapPages(VAddr addr, const KPageLinkedList& page_linked
693 685
694ResultCode KPageTable::UnmapPages(VAddr addr, KPageLinkedList& page_linked_list, 686ResultCode KPageTable::UnmapPages(VAddr addr, KPageLinkedList& page_linked_list,
695 KMemoryState state) { 687 KMemoryState state) {
696 std::lock_guard lock{page_table_lock}; 688 // Check that the unmap is in range.
697
698 const std::size_t num_pages{page_linked_list.GetNumPages()}; 689 const std::size_t num_pages{page_linked_list.GetNumPages()};
699 const std::size_t size{num_pages * PageSize}; 690 const std::size_t size{num_pages * PageSize};
691 R_UNLESS(this->Contains(addr, size), ResultInvalidCurrentMemory);
700 692
701 if (!CanContain(addr, size, state)) { 693 // Lock the table.
702 return ResultInvalidCurrentMemory; 694 std::lock_guard lock{page_table_lock};
703 }
704 695
705 if (IsRegionMapped(addr, num_pages * PageSize)) { 696 // Check the memory state.
706 return ResultInvalidCurrentMemory; 697 R_TRY(this->CheckMemoryState(addr, size, KMemoryState::All, state, KMemoryPermission::None,
707 } 698 KMemoryPermission::None, KMemoryAttribute::All,
699 KMemoryAttribute::None));
708 700
709 CASCADE_CODE(UnmapPages(addr, page_linked_list)); 701 // Perform the unmap.
702 R_TRY(UnmapPages(addr, page_linked_list));
710 703
704 // Update the blocks.
711 block_manager->Update(addr, num_pages, state, KMemoryPermission::None); 705 block_manager->Update(addr, num_pages, state, KMemoryPermission::None);
712 706
713 return ResultSuccess; 707 return ResultSuccess;
@@ -765,7 +759,6 @@ ResultCode KPageTable::SetProcessMemoryPermission(VAddr addr, std::size_t size,
765 759
766 // Ensure cache coherency, if we're setting pages as executable. 760 // Ensure cache coherency, if we're setting pages as executable.
767 if (is_x) { 761 if (is_x) {
768 // Memory execution state is changing, invalidate CPU cache range
769 system.InvalidateCpuInstructionCacheRange(addr, size); 762 system.InvalidateCpuInstructionCacheRange(addr, size);
770 } 763 }
771 764
@@ -793,12 +786,12 @@ ResultCode KPageTable::ReserveTransferMemory(VAddr addr, std::size_t size, KMemo
793 KMemoryState state{}; 786 KMemoryState state{};
794 KMemoryAttribute attribute{}; 787 KMemoryAttribute attribute{};
795 788
796 CASCADE_CODE(CheckMemoryState( 789 R_TRY(CheckMemoryState(&state, nullptr, &attribute, nullptr, addr, size,
797 &state, nullptr, &attribute, nullptr, addr, size, 790 KMemoryState::FlagCanTransfer | KMemoryState::FlagReferenceCounted,
798 KMemoryState::FlagCanTransfer | KMemoryState::FlagReferenceCounted, 791 KMemoryState::FlagCanTransfer | KMemoryState::FlagReferenceCounted,
799 KMemoryState::FlagCanTransfer | KMemoryState::FlagReferenceCounted, KMemoryPermission::All, 792 KMemoryPermission::All, KMemoryPermission::UserReadWrite,
800 KMemoryPermission::UserReadWrite, KMemoryAttribute::Mask, KMemoryAttribute::None, 793 KMemoryAttribute::Mask, KMemoryAttribute::None,
801 KMemoryAttribute::IpcAndDeviceMapped)); 794 KMemoryAttribute::IpcAndDeviceMapped));
802 795
803 block_manager->Update(addr, size / PageSize, state, perm, attribute | KMemoryAttribute::Locked); 796 block_manager->Update(addr, size / PageSize, state, perm, attribute | KMemoryAttribute::Locked);
804 797
@@ -810,12 +803,11 @@ ResultCode KPageTable::ResetTransferMemory(VAddr addr, std::size_t size) {
810 803
811 KMemoryState state{}; 804 KMemoryState state{};
812 805
813 CASCADE_CODE( 806 R_TRY(CheckMemoryState(&state, nullptr, nullptr, nullptr, addr, size,
814 CheckMemoryState(&state, nullptr, nullptr, nullptr, addr, size, 807 KMemoryState::FlagCanTransfer | KMemoryState::FlagReferenceCounted,
815 KMemoryState::FlagCanTransfer | KMemoryState::FlagReferenceCounted, 808 KMemoryState::FlagCanTransfer | KMemoryState::FlagReferenceCounted,
816 KMemoryState::FlagCanTransfer | KMemoryState::FlagReferenceCounted, 809 KMemoryPermission::None, KMemoryPermission::None, KMemoryAttribute::Mask,
817 KMemoryPermission::None, KMemoryPermission::None, KMemoryAttribute::Mask, 810 KMemoryAttribute::Locked, KMemoryAttribute::IpcAndDeviceMapped));
818 KMemoryAttribute::Locked, KMemoryAttribute::IpcAndDeviceMapped));
819 811
820 block_manager->Update(addr, size / PageSize, state, KMemoryPermission::UserReadWrite); 812 block_manager->Update(addr, size / PageSize, state, KMemoryPermission::UserReadWrite);
821 return ResultSuccess; 813 return ResultSuccess;
@@ -871,8 +863,9 @@ ResultCode KPageTable::SetMemoryAttribute(VAddr addr, std::size_t size, u32 mask
871 AttributeTestMask, KMemoryAttribute::None, ~AttributeTestMask)); 863 AttributeTestMask, KMemoryAttribute::None, ~AttributeTestMask));
872 864
873 // Determine the new attribute. 865 // Determine the new attribute.
874 const auto new_attr = ((old_attr & static_cast<KMemoryAttribute>(~mask)) | 866 const KMemoryAttribute new_attr =
875 static_cast<KMemoryAttribute>(attr & mask)); 867 static_cast<KMemoryAttribute>(((old_attr & static_cast<KMemoryAttribute>(~mask)) |
868 static_cast<KMemoryAttribute>(attr & mask)));
876 869
877 // Perform operation. 870 // Perform operation.
878 this->Operate(addr, num_pages, old_perm, OperationType::ChangePermissionsAndRefresh); 871 this->Operate(addr, num_pages, old_perm, OperationType::ChangePermissionsAndRefresh);
@@ -896,6 +889,9 @@ ResultCode KPageTable::SetMaxHeapSize(std::size_t size) {
896} 889}
897 890
898ResultCode KPageTable::SetHeapSize(VAddr* out, std::size_t size) { 891ResultCode KPageTable::SetHeapSize(VAddr* out, std::size_t size) {
892 // Lock the physical memory lock.
893 std::lock_guard phys_lk(map_physical_memory_lock);
894
899 // Try to perform a reduction in heap, instead of an extension. 895 // Try to perform a reduction in heap, instead of an extension.
900 VAddr cur_address{}; 896 VAddr cur_address{};
901 std::size_t allocation_size{}; 897 std::size_t allocation_size{};
@@ -1025,12 +1021,12 @@ ResultVal<VAddr> KPageTable::AllocateAndMapMemory(std::size_t needed_num_pages,
1025 } 1021 }
1026 1022
1027 if (is_map_only) { 1023 if (is_map_only) {
1028 CASCADE_CODE(Operate(addr, needed_num_pages, perm, OperationType::Map, map_addr)); 1024 R_TRY(Operate(addr, needed_num_pages, perm, OperationType::Map, map_addr));
1029 } else { 1025 } else {
1030 KPageLinkedList page_group; 1026 KPageLinkedList page_group;
1031 CASCADE_CODE(system.Kernel().MemoryManager().Allocate(page_group, needed_num_pages, 1027 R_TRY(system.Kernel().MemoryManager().Allocate(page_group, needed_num_pages, memory_pool,
1032 memory_pool, allocation_option)); 1028 allocation_option));
1033 CASCADE_CODE(Operate(addr, needed_num_pages, page_group, OperationType::MapGroup)); 1029 R_TRY(Operate(addr, needed_num_pages, page_group, OperationType::MapGroup));
1034 } 1030 }
1035 1031
1036 block_manager->Update(addr, needed_num_pages, state, perm); 1032 block_manager->Update(addr, needed_num_pages, state, perm);
@@ -1186,7 +1182,7 @@ VAddr KPageTable::AllocateVirtualMemory(VAddr start, std::size_t region_num_page
1186 1182
1187ResultCode KPageTable::Operate(VAddr addr, std::size_t num_pages, const KPageLinkedList& page_group, 1183ResultCode KPageTable::Operate(VAddr addr, std::size_t num_pages, const KPageLinkedList& page_group,
1188 OperationType operation) { 1184 OperationType operation) {
1189 std::lock_guard lock{page_table_lock}; 1185 ASSERT(this->IsLockedByCurrentThread());
1190 1186
1191 ASSERT(Common::IsAligned(addr, PageSize)); 1187 ASSERT(Common::IsAligned(addr, PageSize));
1192 ASSERT(num_pages > 0); 1188 ASSERT(num_pages > 0);
@@ -1211,7 +1207,7 @@ ResultCode KPageTable::Operate(VAddr addr, std::size_t num_pages, const KPageLin
1211 1207
1212ResultCode KPageTable::Operate(VAddr addr, std::size_t num_pages, KMemoryPermission perm, 1208ResultCode KPageTable::Operate(VAddr addr, std::size_t num_pages, KMemoryPermission perm,
1213 OperationType operation, PAddr map_addr) { 1209 OperationType operation, PAddr map_addr) {
1214 std::lock_guard lock{page_table_lock}; 1210 ASSERT(this->IsLockedByCurrentThread());
1215 1211
1216 ASSERT(num_pages > 0); 1212 ASSERT(num_pages > 0);
1217 ASSERT(Common::IsAligned(addr, PageSize)); 1213 ASSERT(Common::IsAligned(addr, PageSize));
diff --git a/src/core/hle/kernel/k_page_table.h b/src/core/hle/kernel/k_page_table.h
index f67986e91..60ae9b9e8 100644
--- a/src/core/hle/kernel/k_page_table.h
+++ b/src/core/hle/kernel/k_page_table.h
@@ -37,9 +37,8 @@ public:
37 VAddr src_addr); 37 VAddr src_addr);
38 ResultCode MapPhysicalMemory(VAddr addr, std::size_t size); 38 ResultCode MapPhysicalMemory(VAddr addr, std::size_t size);
39 ResultCode UnmapPhysicalMemory(VAddr addr, std::size_t size); 39 ResultCode UnmapPhysicalMemory(VAddr addr, std::size_t size);
40 ResultCode UnmapMemory(VAddr addr, std::size_t size); 40 ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, std::size_t size);
41 ResultCode Map(VAddr dst_addr, VAddr src_addr, std::size_t size); 41 ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, std::size_t size);
42 ResultCode Unmap(VAddr dst_addr, VAddr src_addr, std::size_t size);
43 ResultCode MapPages(VAddr addr, KPageLinkedList& page_linked_list, KMemoryState state, 42 ResultCode MapPages(VAddr addr, KPageLinkedList& page_linked_list, KMemoryState state,
44 KMemoryPermission perm); 43 KMemoryPermission perm);
45 ResultCode UnmapPages(VAddr addr, KPageLinkedList& page_linked_list, KMemoryState state); 44 ResultCode UnmapPages(VAddr addr, KPageLinkedList& page_linked_list, KMemoryState state);
@@ -88,7 +87,6 @@ private:
88 ResultCode MapPages(VAddr addr, const KPageLinkedList& page_linked_list, 87 ResultCode MapPages(VAddr addr, const KPageLinkedList& page_linked_list,
89 KMemoryPermission perm); 88 KMemoryPermission perm);
90 ResultCode UnmapPages(VAddr addr, const KPageLinkedList& page_linked_list); 89 ResultCode UnmapPages(VAddr addr, const KPageLinkedList& page_linked_list);
91 void MapPhysicalMemory(KPageLinkedList& page_linked_list, VAddr start, VAddr end);
92 bool IsRegionMapped(VAddr address, u64 size); 90 bool IsRegionMapped(VAddr address, u64 size);
93 bool IsRegionContiguous(VAddr addr, u64 size) const; 91 bool IsRegionContiguous(VAddr addr, u64 size) const;
94 void AddRegionToPages(VAddr start, std::size_t num_pages, KPageLinkedList& page_linked_list); 92 void AddRegionToPages(VAddr start, std::size_t num_pages, KPageLinkedList& page_linked_list);
@@ -148,6 +146,7 @@ private:
148 } 146 }
149 147
150 std::recursive_mutex page_table_lock; 148 std::recursive_mutex page_table_lock;
149 std::mutex map_physical_memory_lock;
151 std::unique_ptr<KMemoryBlockManager> block_manager; 150 std::unique_ptr<KMemoryBlockManager> block_manager;
152 151
153public: 152public:
@@ -249,7 +248,9 @@ public:
249 return !IsOutsideASLRRegion(address, size); 248 return !IsOutsideASLRRegion(address, size);
250 } 249 }
251 constexpr PAddr GetPhysicalAddr(VAddr addr) { 250 constexpr PAddr GetPhysicalAddr(VAddr addr) {
252 return page_table_impl.backing_addr[addr >> PageBits] + addr; 251 const auto backing_addr = page_table_impl.backing_addr[addr >> PageBits];
252 ASSERT(backing_addr);
253 return backing_addr + addr;
253 } 254 }
254 constexpr bool Contains(VAddr addr) const { 255 constexpr bool Contains(VAddr addr) const {
255 return address_space_start <= addr && addr <= address_space_end - 1; 256 return address_space_start <= addr && addr <= address_space_end - 1;
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp
index 265ac6fa1..85c506979 100644
--- a/src/core/hle/kernel/k_process.cpp
+++ b/src/core/hle/kernel/k_process.cpp
@@ -146,6 +146,13 @@ ResultCode KProcess::Initialize(KProcess* process, Core::System& system, std::st
146 // Open a reference to the resource limit. 146 // Open a reference to the resource limit.
147 process->resource_limit->Open(); 147 process->resource_limit->Open();
148 148
149 // Clear remaining fields.
150 process->num_running_threads = 0;
151 process->is_signaled = false;
152 process->exception_thread = nullptr;
153 process->is_suspended = false;
154 process->schedule_count = 0;
155
149 return ResultSuccess; 156 return ResultSuccess;
150} 157}
151 158
@@ -157,20 +164,17 @@ KResourceLimit* KProcess::GetResourceLimit() const {
157 return resource_limit; 164 return resource_limit;
158} 165}
159 166
160void KProcess::IncrementThreadCount() { 167void KProcess::IncrementRunningThreadCount() {
161 ASSERT(num_threads >= 0); 168 ASSERT(num_running_threads.load() >= 0);
162 num_created_threads++; 169 ++num_running_threads;
163
164 if (const auto count = ++num_threads; count > peak_num_threads) {
165 peak_num_threads = count;
166 }
167} 170}
168 171
169void KProcess::DecrementThreadCount() { 172void KProcess::DecrementRunningThreadCount() {
170 ASSERT(num_threads > 0); 173 ASSERT(num_running_threads.load() > 0);
171 174
172 if (const auto count = --num_threads; count == 0) { 175 if (const auto prev = num_running_threads--; prev == 1) {
173 LOG_WARNING(Kernel, "Process termination is not fully implemented."); 176 // TODO(bunnei): Process termination to be implemented when multiprocess is supported.
177 UNIMPLEMENTED_MSG("KProcess termination is not implemennted!");
174 } 178 }
175} 179}
176 180
diff --git a/src/core/hle/kernel/k_process.h b/src/core/hle/kernel/k_process.h
index c2a672021..38b446350 100644
--- a/src/core/hle/kernel/k_process.h
+++ b/src/core/hle/kernel/k_process.h
@@ -235,8 +235,8 @@ public:
235 ++schedule_count; 235 ++schedule_count;
236 } 236 }
237 237
238 void IncrementThreadCount(); 238 void IncrementRunningThreadCount();
239 void DecrementThreadCount(); 239 void DecrementRunningThreadCount();
240 240
241 void SetRunningThread(s32 core, KThread* thread, u64 idle_count) { 241 void SetRunningThread(s32 core, KThread* thread, u64 idle_count) {
242 running_threads[core] = thread; 242 running_threads[core] = thread;
@@ -473,9 +473,7 @@ private:
473 bool is_suspended{}; 473 bool is_suspended{};
474 bool is_initialized{}; 474 bool is_initialized{};
475 475
476 std::atomic<s32> num_created_threads{}; 476 std::atomic<u16> num_running_threads{};
477 std::atomic<u16> num_threads{};
478 u16 peak_num_threads{};
479 477
480 std::array<KThread*, Core::Hardware::NUM_CPU_CORES> running_threads{}; 478 std::array<KThread*, Core::Hardware::NUM_CPU_CORES> running_threads{};
481 std::array<u64, Core::Hardware::NUM_CPU_CORES> running_thread_idle_counts{}; 479 std::array<u64, Core::Hardware::NUM_CPU_CORES> running_thread_idle_counts{};
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp
index f42abb8a1..de3ffe0c7 100644
--- a/src/core/hle/kernel/k_thread.cpp
+++ b/src/core/hle/kernel/k_thread.cpp
@@ -215,7 +215,6 @@ ResultCode KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_s
215 215
216 parent = owner; 216 parent = owner;
217 parent->Open(); 217 parent->Open();
218 parent->IncrementThreadCount();
219 } 218 }
220 219
221 // Initialize thread context. 220 // Initialize thread context.
@@ -327,11 +326,6 @@ void KThread::Finalize() {
327 } 326 }
328 } 327 }
329 328
330 // Decrement the parent process's thread count.
331 if (parent != nullptr) {
332 parent->DecrementThreadCount();
333 }
334
335 // Perform inherited finalization. 329 // Perform inherited finalization.
336 KSynchronizationObject::Finalize(); 330 KSynchronizationObject::Finalize();
337} 331}
@@ -1011,7 +1005,7 @@ ResultCode KThread::Run() {
1011 if (IsUserThread() && IsSuspended()) { 1005 if (IsUserThread() && IsSuspended()) {
1012 this->UpdateState(); 1006 this->UpdateState();
1013 } 1007 }
1014 owner->IncrementThreadCount(); 1008 owner->IncrementRunningThreadCount();
1015 } 1009 }
1016 1010
1017 // Set our state and finish. 1011 // Set our state and finish.
@@ -1026,10 +1020,11 @@ ResultCode KThread::Run() {
1026void KThread::Exit() { 1020void KThread::Exit() {
1027 ASSERT(this == GetCurrentThreadPointer(kernel)); 1021 ASSERT(this == GetCurrentThreadPointer(kernel));
1028 1022
1029 // Release the thread resource hint from parent. 1023 // Release the thread resource hint, running thread count from parent.
1030 if (parent != nullptr) { 1024 if (parent != nullptr) {
1031 parent->GetResourceLimit()->Release(Kernel::LimitableResource::Threads, 0, 1); 1025 parent->GetResourceLimit()->Release(Kernel::LimitableResource::Threads, 0, 1);
1032 resource_limit_release_hint = true; 1026 resource_limit_release_hint = true;
1027 parent->DecrementRunningThreadCount();
1033 } 1028 }
1034 1029
1035 // Perform termination. 1030 // Perform termination.
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index c7f5140f4..40bb893ac 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -230,7 +230,7 @@ static ResultCode MapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr
230 return result; 230 return result;
231 } 231 }
232 232
233 return page_table.Map(dst_addr, src_addr, size); 233 return page_table.MapMemory(dst_addr, src_addr, size);
234} 234}
235 235
236static ResultCode MapMemory32(Core::System& system, u32 dst_addr, u32 src_addr, u32 size) { 236static ResultCode MapMemory32(Core::System& system, u32 dst_addr, u32 src_addr, u32 size) {
@@ -249,7 +249,7 @@ static ResultCode UnmapMemory(Core::System& system, VAddr dst_addr, VAddr src_ad
249 return result; 249 return result;
250 } 250 }
251 251
252 return page_table.Unmap(dst_addr, src_addr, size); 252 return page_table.UnmapMemory(dst_addr, src_addr, size);
253} 253}
254 254
255static ResultCode UnmapMemory32(Core::System& system, u32 dst_addr, u32 src_addr, u32 size) { 255static ResultCode UnmapMemory32(Core::System& system, u32 dst_addr, u32 src_addr, u32 size) {
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp
index 9aaeb91be..d1cdb1ab2 100644
--- a/src/input_common/drivers/udp_client.cpp
+++ b/src/input_common/drivers/udp_client.cpp
@@ -339,7 +339,7 @@ void UDPClient::StartCommunication(std::size_t client, const std::string& host,
339 } 339 }
340} 340}
341 341
342const PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const { 342PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const {
343 const std::size_t client = pad_index / PADS_PER_CLIENT; 343 const std::size_t client = pad_index / PADS_PER_CLIENT;
344 return { 344 return {
345 .guid = clients[client].uuid, 345 .guid = clients[client].uuid,
@@ -348,9 +348,9 @@ const PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const {
348 }; 348 };
349} 349}
350 350
351const Common::UUID UDPClient::GetHostUUID(const std::string host) const { 351Common::UUID UDPClient::GetHostUUID(const std::string& host) const {
352 const auto ip = boost::asio::ip::address_v4::from_string(host); 352 const auto ip = boost::asio::ip::make_address_v4(host);
353 const auto hex_host = fmt::format("{:06x}", ip.to_ulong()); 353 const auto hex_host = fmt::format("{:06x}", ip.to_uint());
354 return Common::UUID{hex_host}; 354 return Common::UUID{hex_host};
355} 355}
356 356
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h
index 61a1fff37..30d7c2682 100644
--- a/src/input_common/drivers/udp_client.h
+++ b/src/input_common/drivers/udp_client.h
@@ -145,8 +145,8 @@ private:
145 void OnPortInfo(Response::PortInfo); 145 void OnPortInfo(Response::PortInfo);
146 void OnPadData(Response::PadData, std::size_t client); 146 void OnPadData(Response::PadData, std::size_t client);
147 void StartCommunication(std::size_t client, const std::string& host, u16 port); 147 void StartCommunication(std::size_t client, const std::string& host, u16 port);
148 const PadIdentifier GetPadIdentifier(std::size_t pad_index) const; 148 PadIdentifier GetPadIdentifier(std::size_t pad_index) const;
149 const Common::UUID GetHostUUID(const std::string host) const; 149 Common::UUID GetHostUUID(const std::string& host) const;
150 150
151 Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const; 151 Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const;
152 152
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h
index 390581c94..fe2faee5a 100644
--- a/src/input_common/input_engine.h
+++ b/src/input_common/input_engine.h
@@ -16,7 +16,7 @@
16 16
17// Pad Identifier of data source 17// Pad Identifier of data source
18struct PadIdentifier { 18struct PadIdentifier {
19 Common::UUID guid{}; 19 Common::UUID guid{Common::INVALID_UUID};
20 std::size_t port{}; 20 std::size_t port{};
21 std::size_t pad{}; 21 std::size_t pad{};
22 22
@@ -89,7 +89,7 @@ struct UpdateCallback {
89 89
90// Triggered if data changed on the controller and the engine is on configuring mode 90// Triggered if data changed on the controller and the engine is on configuring mode
91struct MappingCallback { 91struct MappingCallback {
92 std::function<void(MappingData)> on_data; 92 std::function<void(const MappingData&)> on_data;
93}; 93};
94 94
95// Input Identifier of data source 95// Input Identifier of data source
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp
index 475257f42..a7a6ad8c2 100644
--- a/src/input_common/input_mapping.cpp
+++ b/src/input_common/input_mapping.cpp
@@ -2,14 +2,13 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included 3// Refer to the license.txt file included
4 4
5#include "common/common_types.h"
6#include "common/settings.h" 5#include "common/settings.h"
7#include "input_common/input_engine.h" 6#include "input_common/input_engine.h"
8#include "input_common/input_mapping.h" 7#include "input_common/input_mapping.h"
9 8
10namespace InputCommon { 9namespace InputCommon {
11 10
12MappingFactory::MappingFactory() {} 11MappingFactory::MappingFactory() = default;
13 12
14void MappingFactory::BeginMapping(Polling::InputType type) { 13void MappingFactory::BeginMapping(Polling::InputType type) {
15 is_enabled = true; 14 is_enabled = true;
@@ -19,7 +18,7 @@ void MappingFactory::BeginMapping(Polling::InputType type) {
19 second_axis = -1; 18 second_axis = -1;
20} 19}
21 20
22[[nodiscard]] const Common::ParamPackage MappingFactory::GetNextInput() { 21Common::ParamPackage MappingFactory::GetNextInput() {
23 Common::ParamPackage input; 22 Common::ParamPackage input;
24 input_queue.Pop(input); 23 input_queue.Pop(input);
25 return input; 24 return input;
@@ -57,7 +56,7 @@ void MappingFactory::StopMapping() {
57void MappingFactory::RegisterButton(const MappingData& data) { 56void MappingFactory::RegisterButton(const MappingData& data) {
58 Common::ParamPackage new_input; 57 Common::ParamPackage new_input;
59 new_input.Set("engine", data.engine); 58 new_input.Set("engine", data.engine);
60 if (data.pad.guid != Common::UUID{}) { 59 if (data.pad.guid.IsValid()) {
61 new_input.Set("guid", data.pad.guid.Format()); 60 new_input.Set("guid", data.pad.guid.Format());
62 } 61 }
63 new_input.Set("port", static_cast<int>(data.pad.port)); 62 new_input.Set("port", static_cast<int>(data.pad.port));
@@ -93,7 +92,7 @@ void MappingFactory::RegisterButton(const MappingData& data) {
93void MappingFactory::RegisterStick(const MappingData& data) { 92void MappingFactory::RegisterStick(const MappingData& data) {
94 Common::ParamPackage new_input; 93 Common::ParamPackage new_input;
95 new_input.Set("engine", data.engine); 94 new_input.Set("engine", data.engine);
96 if (data.pad.guid != Common::UUID{}) { 95 if (data.pad.guid.IsValid()) {
97 new_input.Set("guid", data.pad.guid.Format()); 96 new_input.Set("guid", data.pad.guid.Format());
98 } 97 }
99 new_input.Set("port", static_cast<int>(data.pad.port)); 98 new_input.Set("port", static_cast<int>(data.pad.port));
@@ -138,7 +137,7 @@ void MappingFactory::RegisterStick(const MappingData& data) {
138void MappingFactory::RegisterMotion(const MappingData& data) { 137void MappingFactory::RegisterMotion(const MappingData& data) {
139 Common::ParamPackage new_input; 138 Common::ParamPackage new_input;
140 new_input.Set("engine", data.engine); 139 new_input.Set("engine", data.engine);
141 if (data.pad.guid != Common::UUID{}) { 140 if (data.pad.guid.IsValid()) {
142 new_input.Set("guid", data.pad.guid.Format()); 141 new_input.Set("guid", data.pad.guid.Format());
143 } 142 }
144 new_input.Set("port", static_cast<int>(data.pad.port)); 143 new_input.Set("port", static_cast<int>(data.pad.port));
diff --git a/src/input_common/input_mapping.h b/src/input_common/input_mapping.h
index 93564b5f8..e0dfbc7ad 100644
--- a/src/input_common/input_mapping.h
+++ b/src/input_common/input_mapping.h
@@ -3,8 +3,14 @@
3// Refer to the license.txt file included 3// Refer to the license.txt file included
4 4
5#pragma once 5#pragma once
6
7#include "common/param_package.h"
6#include "common/threadsafe_queue.h" 8#include "common/threadsafe_queue.h"
7 9
10namespace InputCommon::Polling {
11enum class InputType;
12}
13
8namespace InputCommon { 14namespace InputCommon {
9class InputEngine; 15class InputEngine;
10struct MappingData; 16struct MappingData;
@@ -20,7 +26,7 @@ public:
20 void BeginMapping(Polling::InputType type); 26 void BeginMapping(Polling::InputType type);
21 27
22 /// Returns an input event with mapping information from the input_queue 28 /// Returns an input event with mapping information from the input_queue
23 [[nodiscard]] const Common::ParamPackage GetNextInput(); 29 [[nodiscard]] Common::ParamPackage GetNextInput();
24 30
25 /** 31 /**
26 * Registers mapping input data from the driver 32 * Registers mapping input data from the driver
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 940744c5f..a4d7ed645 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -27,7 +27,7 @@ namespace InputCommon {
27struct InputSubsystem::Impl { 27struct InputSubsystem::Impl {
28 void Initialize() { 28 void Initialize() {
29 mapping_factory = std::make_shared<MappingFactory>(); 29 mapping_factory = std::make_shared<MappingFactory>();
30 MappingCallback mapping_callback{[this](MappingData data) { RegisterInput(data); }}; 30 MappingCallback mapping_callback{[this](const MappingData& data) { RegisterInput(data); }};
31 31
32 keyboard = std::make_shared<Keyboard>("keyboard"); 32 keyboard = std::make_shared<Keyboard>("keyboard");
33 keyboard->SetMappingCallback(mapping_callback); 33 keyboard->SetMappingCallback(mapping_callback);
@@ -284,7 +284,7 @@ struct InputSubsystem::Impl {
284#endif 284#endif
285 } 285 }
286 286
287 void RegisterInput(MappingData data) { 287 void RegisterInput(const MappingData& data) {
288 mapping_factory->RegisterInput(data); 288 mapping_factory->RegisterInput(data);
289 } 289 }
290 290
@@ -394,7 +394,7 @@ void InputSubsystem::BeginMapping(Polling::InputType type) {
394 impl->mapping_factory->BeginMapping(type); 394 impl->mapping_factory->BeginMapping(type);
395} 395}
396 396
397const Common::ParamPackage InputSubsystem::GetNextInput() const { 397Common::ParamPackage InputSubsystem::GetNextInput() const {
398 return impl->mapping_factory->GetNextInput(); 398 return impl->mapping_factory->GetNextInput();
399} 399}
400 400
diff --git a/src/input_common/main.h b/src/input_common/main.h
index c6f97f691..baf107e0f 100644
--- a/src/input_common/main.h
+++ b/src/input_common/main.h
@@ -126,7 +126,7 @@ public:
126 void BeginMapping(Polling::InputType type); 126 void BeginMapping(Polling::InputType type);
127 127
128 /// Returns an input event with mapping information. 128 /// Returns an input event with mapping information.
129 [[nodiscard]] const Common::ParamPackage GetNextInput() const; 129 [[nodiscard]] Common::ParamPackage GetNextInput() const;
130 130
131 /// Stop polling from all backends. 131 /// Stop polling from all backends.
132 void StopMapping() const; 132 void StopMapping() const;
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.h b/src/shader_recompiler/frontend/maxwell/translate_program.h
index cd535f20d..eac83da9d 100644
--- a/src/shader_recompiler/frontend/maxwell/translate_program.h
+++ b/src/shader_recompiler/frontend/maxwell/translate_program.h
@@ -21,7 +21,6 @@ namespace Shader::Maxwell {
21[[nodiscard]] IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b, 21[[nodiscard]] IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b,
22 Environment& env_vertex_b); 22 Environment& env_vertex_b);
23 23
24[[nodiscard]] void ConvertLegacyToGeneric(IR::Program& program, 24void ConvertLegacyToGeneric(IR::Program& program, const RuntimeInfo& runtime_info);
25 const Shader::RuntimeInfo& runtime_info);
26 25
27} // namespace Shader::Maxwell 26} // namespace Shader::Maxwell
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
index b18b8a02a..c38ebd670 100644
--- a/src/video_core/engines/maxwell_3d.cpp
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -240,7 +240,7 @@ void Maxwell3D::CallMacroMethod(u32 method, const std::vector<u32>& parameters)
240 ((method - MacroRegistersStart) >> 1) % static_cast<u32>(macro_positions.size()); 240 ((method - MacroRegistersStart) >> 1) % static_cast<u32>(macro_positions.size());
241 241
242 // Execute the current macro. 242 // Execute the current macro.
243 macro_engine->Execute(*this, macro_positions[entry], parameters); 243 macro_engine->Execute(macro_positions[entry], parameters);
244 if (mme_draw.current_mode != MMEDrawMode::Undefined) { 244 if (mme_draw.current_mode != MMEDrawMode::Undefined) {
245 FlushMMEInlineDraw(); 245 FlushMMEInlineDraw();
246 } 246 }
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h
index 3188b83ed..26b8ea233 100644
--- a/src/video_core/gpu.h
+++ b/src/video_core/gpu.h
@@ -12,9 +12,6 @@
12#include "video_core/framebuffer_config.h" 12#include "video_core/framebuffer_config.h"
13 13
14namespace Core { 14namespace Core {
15namespace Frontend {
16class EmuWindow;
17}
18class System; 15class System;
19} // namespace Core 16} // namespace Core
20 17
@@ -25,7 +22,6 @@ class ShaderNotify;
25 22
26namespace Tegra { 23namespace Tegra {
27class DmaPusher; 24class DmaPusher;
28class CDmaPusher;
29struct CommandList; 25struct CommandList;
30 26
31enum class RenderTargetFormat : u32 { 27enum class RenderTargetFormat : u32 {
@@ -88,15 +84,9 @@ enum class DepthFormat : u32 {
88 D32_FLOAT_S8X24_UINT = 0x19, 84 D32_FLOAT_S8X24_UINT = 0x19,
89}; 85};
90 86
91struct CommandListHeader;
92class DebugContext;
93
94namespace Engines { 87namespace Engines {
95class Fermi2D;
96class Maxwell3D; 88class Maxwell3D;
97class MaxwellDMA;
98class KeplerCompute; 89class KeplerCompute;
99class KeplerMemory;
100} // namespace Engines 90} // namespace Engines
101 91
102enum class EngineID { 92enum class EngineID {
@@ -190,12 +180,6 @@ public:
190 /// Returns a const reference to the GPU DMA pusher. 180 /// Returns a const reference to the GPU DMA pusher.
191 [[nodiscard]] const Tegra::DmaPusher& DmaPusher() const; 181 [[nodiscard]] const Tegra::DmaPusher& DmaPusher() const;
192 182
193 /// Returns a reference to the GPU CDMA pusher.
194 [[nodiscard]] Tegra::CDmaPusher& CDmaPusher();
195
196 /// Returns a const reference to the GPU CDMA pusher.
197 [[nodiscard]] const Tegra::CDmaPusher& CDmaPusher() const;
198
199 /// Returns a reference to the underlying renderer. 183 /// Returns a reference to the underlying renderer.
200 [[nodiscard]] VideoCore::RendererBase& Renderer(); 184 [[nodiscard]] VideoCore::RendererBase& Renderer();
201 185
diff --git a/src/video_core/macro/macro.cpp b/src/video_core/macro/macro.cpp
index d7fabe605..0aeda4ce8 100644
--- a/src/video_core/macro/macro.cpp
+++ b/src/video_core/macro/macro.cpp
@@ -2,12 +2,13 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cstring>
5#include <optional> 6#include <optional>
7
6#include <boost/container_hash/hash.hpp> 8#include <boost/container_hash/hash.hpp>
9
7#include "common/assert.h" 10#include "common/assert.h"
8#include "common/logging/log.h"
9#include "common/settings.h" 11#include "common/settings.h"
10#include "video_core/engines/maxwell_3d.h"
11#include "video_core/macro/macro.h" 12#include "video_core/macro/macro.h"
12#include "video_core/macro/macro_hle.h" 13#include "video_core/macro/macro_hle.h"
13#include "video_core/macro/macro_interpreter.h" 14#include "video_core/macro/macro_interpreter.h"
@@ -24,8 +25,7 @@ void MacroEngine::AddCode(u32 method, u32 data) {
24 uploaded_macro_code[method].push_back(data); 25 uploaded_macro_code[method].push_back(data);
25} 26}
26 27
27void MacroEngine::Execute(Engines::Maxwell3D& maxwell3d, u32 method, 28void MacroEngine::Execute(u32 method, const std::vector<u32>& parameters) {
28 const std::vector<u32>& parameters) {
29 auto compiled_macro = macro_cache.find(method); 29 auto compiled_macro = macro_cache.find(method);
30 if (compiled_macro != macro_cache.end()) { 30 if (compiled_macro != macro_cache.end()) {
31 const auto& cache_info = compiled_macro->second; 31 const auto& cache_info = compiled_macro->second;
@@ -66,10 +66,9 @@ void MacroEngine::Execute(Engines::Maxwell3D& maxwell3d, u32 method,
66 cache_info.lle_program = Compile(code); 66 cache_info.lle_program = Compile(code);
67 } 67 }
68 68
69 auto hle_program = hle_macros->GetHLEProgram(cache_info.hash); 69 if (auto hle_program = hle_macros->GetHLEProgram(cache_info.hash)) {
70 if (hle_program.has_value()) {
71 cache_info.has_hle_program = true; 70 cache_info.has_hle_program = true;
72 cache_info.hle_program = std::move(hle_program.value()); 71 cache_info.hle_program = std::move(hle_program);
73 cache_info.hle_program->Execute(parameters, method); 72 cache_info.hle_program->Execute(parameters, method);
74 } else { 73 } else {
75 cache_info.lle_program->Execute(parameters, method); 74 cache_info.lle_program->Execute(parameters, method);
diff --git a/src/video_core/macro/macro.h b/src/video_core/macro/macro.h
index 31ee3440a..7aaa49286 100644
--- a/src/video_core/macro/macro.h
+++ b/src/video_core/macro/macro.h
@@ -119,7 +119,7 @@ public:
119 void AddCode(u32 method, u32 data); 119 void AddCode(u32 method, u32 data);
120 120
121 // Compiles the macro if its not in the cache, and executes the compiled macro 121 // Compiles the macro if its not in the cache, and executes the compiled macro
122 void Execute(Engines::Maxwell3D& maxwell3d, u32 method, const std::vector<u32>& parameters); 122 void Execute(u32 method, const std::vector<u32>& parameters);
123 123
124protected: 124protected:
125 virtual std::unique_ptr<CachedMacro> Compile(const std::vector<u32>& code) = 0; 125 virtual std::unique_ptr<CachedMacro> Compile(const std::vector<u32>& code) = 0;
diff --git a/src/video_core/macro/macro_hle.cpp b/src/video_core/macro/macro_hle.cpp
index 70ac7c620..900ad23c9 100644
--- a/src/video_core/macro/macro_hle.cpp
+++ b/src/video_core/macro/macro_hle.cpp
@@ -5,12 +5,15 @@
5#include <array> 5#include <array>
6#include <vector> 6#include <vector>
7#include "video_core/engines/maxwell_3d.h" 7#include "video_core/engines/maxwell_3d.h"
8#include "video_core/macro/macro.h"
8#include "video_core/macro/macro_hle.h" 9#include "video_core/macro/macro_hle.h"
9#include "video_core/rasterizer_interface.h" 10#include "video_core/rasterizer_interface.h"
10 11
11namespace Tegra { 12namespace Tegra {
12
13namespace { 13namespace {
14
15using HLEFunction = void (*)(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& parameters);
16
14// HLE'd functions 17// HLE'd functions
15void HLE_771BB18C62444DA0(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& parameters) { 18void HLE_771BB18C62444DA0(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& parameters) {
16 const u32 instance_count = parameters[2] & maxwell3d.GetRegisterValue(0xD1B); 19 const u32 instance_count = parameters[2] & maxwell3d.GetRegisterValue(0xD1B);
@@ -77,7 +80,6 @@ void HLE_0217920100488FF7(Engines::Maxwell3D& maxwell3d, const std::vector<u32>&
77 maxwell3d.CallMethodFromMME(0x8e5, 0x0); 80 maxwell3d.CallMethodFromMME(0x8e5, 0x0);
78 maxwell3d.mme_draw.current_mode = Engines::Maxwell3D::MMEDrawMode::Undefined; 81 maxwell3d.mme_draw.current_mode = Engines::Maxwell3D::MMEDrawMode::Undefined;
79} 82}
80} // Anonymous namespace
81 83
82constexpr std::array<std::pair<u64, HLEFunction>, 3> hle_funcs{{ 84constexpr std::array<std::pair<u64, HLEFunction>, 3> hle_funcs{{
83 {0x771BB18C62444DA0, &HLE_771BB18C62444DA0}, 85 {0x771BB18C62444DA0, &HLE_771BB18C62444DA0},
@@ -85,25 +87,31 @@ constexpr std::array<std::pair<u64, HLEFunction>, 3> hle_funcs{{
85 {0x0217920100488FF7, &HLE_0217920100488FF7}, 87 {0x0217920100488FF7, &HLE_0217920100488FF7},
86}}; 88}};
87 89
90class HLEMacroImpl final : public CachedMacro {
91public:
92 explicit HLEMacroImpl(Engines::Maxwell3D& maxwell3d_, HLEFunction func_)
93 : maxwell3d{maxwell3d_}, func{func_} {}
94
95 void Execute(const std::vector<u32>& parameters, u32 method) override {
96 func(maxwell3d, parameters);
97 }
98
99private:
100 Engines::Maxwell3D& maxwell3d;
101 HLEFunction func;
102};
103} // Anonymous namespace
104
88HLEMacro::HLEMacro(Engines::Maxwell3D& maxwell3d_) : maxwell3d{maxwell3d_} {} 105HLEMacro::HLEMacro(Engines::Maxwell3D& maxwell3d_) : maxwell3d{maxwell3d_} {}
89HLEMacro::~HLEMacro() = default; 106HLEMacro::~HLEMacro() = default;
90 107
91std::optional<std::unique_ptr<CachedMacro>> HLEMacro::GetHLEProgram(u64 hash) const { 108std::unique_ptr<CachedMacro> HLEMacro::GetHLEProgram(u64 hash) const {
92 const auto it = std::find_if(hle_funcs.cbegin(), hle_funcs.cend(), 109 const auto it = std::find_if(hle_funcs.cbegin(), hle_funcs.cend(),
93 [hash](const auto& pair) { return pair.first == hash; }); 110 [hash](const auto& pair) { return pair.first == hash; });
94 if (it == hle_funcs.end()) { 111 if (it == hle_funcs.end()) {
95 return std::nullopt; 112 return nullptr;
96 } 113 }
97 return std::make_unique<HLEMacroImpl>(maxwell3d, it->second); 114 return std::make_unique<HLEMacroImpl>(maxwell3d, it->second);
98} 115}
99 116
100HLEMacroImpl::~HLEMacroImpl() = default;
101
102HLEMacroImpl::HLEMacroImpl(Engines::Maxwell3D& maxwell3d_, HLEFunction func_)
103 : maxwell3d{maxwell3d_}, func{func_} {}
104
105void HLEMacroImpl::Execute(const std::vector<u32>& parameters, u32 method) {
106 func(maxwell3d, parameters);
107}
108
109} // namespace Tegra 117} // namespace Tegra
diff --git a/src/video_core/macro/macro_hle.h b/src/video_core/macro/macro_hle.h
index cb3bd1600..b86ba84a1 100644
--- a/src/video_core/macro/macro_hle.h
+++ b/src/video_core/macro/macro_hle.h
@@ -5,10 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include <memory>
8#include <optional>
9#include <vector>
10#include "common/common_types.h" 8#include "common/common_types.h"
11#include "video_core/macro/macro.h"
12 9
13namespace Tegra { 10namespace Tegra {
14 11
@@ -16,29 +13,17 @@ namespace Engines {
16class Maxwell3D; 13class Maxwell3D;
17} 14}
18 15
19using HLEFunction = void (*)(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& parameters);
20
21class HLEMacro { 16class HLEMacro {
22public: 17public:
23 explicit HLEMacro(Engines::Maxwell3D& maxwell3d_); 18 explicit HLEMacro(Engines::Maxwell3D& maxwell3d_);
24 ~HLEMacro(); 19 ~HLEMacro();
25 20
26 std::optional<std::unique_ptr<CachedMacro>> GetHLEProgram(u64 hash) const; 21 // Allocates and returns a cached macro if the hash matches a known function.
27 22 // Returns nullptr otherwise.
28private: 23 [[nodiscard]] std::unique_ptr<CachedMacro> GetHLEProgram(u64 hash) const;
29 Engines::Maxwell3D& maxwell3d;
30};
31
32class HLEMacroImpl : public CachedMacro {
33public:
34 explicit HLEMacroImpl(Engines::Maxwell3D& maxwell3d, HLEFunction func);
35 ~HLEMacroImpl();
36
37 void Execute(const std::vector<u32>& parameters, u32 method) override;
38 24
39private: 25private:
40 Engines::Maxwell3D& maxwell3d; 26 Engines::Maxwell3D& maxwell3d;
41 HLEFunction func;
42}; 27};
43 28
44} // namespace Tegra 29} // namespace Tegra
diff --git a/src/video_core/macro/macro_interpreter.cpp b/src/video_core/macro/macro_interpreter.cpp
index 8da26fd59..fba755448 100644
--- a/src/video_core/macro/macro_interpreter.cpp
+++ b/src/video_core/macro/macro_interpreter.cpp
@@ -2,6 +2,9 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <array>
6#include <optional>
7
5#include "common/assert.h" 8#include "common/assert.h"
6#include "common/logging/log.h" 9#include "common/logging/log.h"
7#include "common/microprofile.h" 10#include "common/microprofile.h"
@@ -11,16 +14,81 @@
11MICROPROFILE_DEFINE(MacroInterp, "GPU", "Execute macro interpreter", MP_RGB(128, 128, 192)); 14MICROPROFILE_DEFINE(MacroInterp, "GPU", "Execute macro interpreter", MP_RGB(128, 128, 192));
12 15
13namespace Tegra { 16namespace Tegra {
14MacroInterpreter::MacroInterpreter(Engines::Maxwell3D& maxwell3d_) 17namespace {
15 : MacroEngine{maxwell3d_}, maxwell3d{maxwell3d_} {} 18class MacroInterpreterImpl final : public CachedMacro {
19public:
20 explicit MacroInterpreterImpl(Engines::Maxwell3D& maxwell3d_, const std::vector<u32>& code_)
21 : maxwell3d{maxwell3d_}, code{code_} {}
16 22
17std::unique_ptr<CachedMacro> MacroInterpreter::Compile(const std::vector<u32>& code) { 23 void Execute(const std::vector<u32>& params, u32 method) override;
18 return std::make_unique<MacroInterpreterImpl>(maxwell3d, code); 24
19} 25private:
26 /// Resets the execution engine state, zeroing registers, etc.
27 void Reset();
28
29 /**
30 * Executes a single macro instruction located at the current program counter. Returns whether
31 * the interpreter should keep running.
32 *
33 * @param is_delay_slot Whether the current step is being executed due to a delay slot in a
34 * previous instruction.
35 */
36 bool Step(bool is_delay_slot);
37
38 /// Calculates the result of an ALU operation. src_a OP src_b;
39 u32 GetALUResult(Macro::ALUOperation operation, u32 src_a, u32 src_b);
40
41 /// Performs the result operation on the input result and stores it in the specified register
42 /// (if necessary).
43 void ProcessResult(Macro::ResultOperation operation, u32 reg, u32 result);
44
45 /// Evaluates the branch condition and returns whether the branch should be taken or not.
46 bool EvaluateBranchCondition(Macro::BranchCondition cond, u32 value) const;
47
48 /// Reads an opcode at the current program counter location.
49 Macro::Opcode GetOpcode() const;
50
51 /// Returns the specified register's value. Register 0 is hardcoded to always return 0.
52 u32 GetRegister(u32 register_id) const;
53
54 /// Sets the register to the input value.
55 void SetRegister(u32 register_id, u32 value);
56
57 /// Sets the method address to use for the next Send instruction.
58 void SetMethodAddress(u32 address);
20 59
21MacroInterpreterImpl::MacroInterpreterImpl(Engines::Maxwell3D& maxwell3d_, 60 /// Calls a GPU Engine method with the input parameter.
22 const std::vector<u32>& code_) 61 void Send(u32 value);
23 : maxwell3d{maxwell3d_}, code{code_} {} 62
63 /// Reads a GPU register located at the method address.
64 u32 Read(u32 method) const;
65
66 /// Returns the next parameter in the parameter queue.
67 u32 FetchParameter();
68
69 Engines::Maxwell3D& maxwell3d;
70
71 /// Current program counter
72 u32 pc{};
73 /// Program counter to execute at after the delay slot is executed.
74 std::optional<u32> delayed_pc;
75
76 /// General purpose macro registers.
77 std::array<u32, Macro::NUM_MACRO_REGISTERS> registers = {};
78
79 /// Method address to use for the next Send instruction.
80 Macro::MethodAddress method_address = {};
81
82 /// Input parameters of the current macro.
83 std::unique_ptr<u32[]> parameters;
84 std::size_t num_parameters = 0;
85 std::size_t parameters_capacity = 0;
86 /// Index of the next parameter that will be fetched by the 'parm' instruction.
87 u32 next_parameter_index = 0;
88
89 bool carry_flag = false;
90 const std::vector<u32>& code;
91};
24 92
25void MacroInterpreterImpl::Execute(const std::vector<u32>& params, u32 method) { 93void MacroInterpreterImpl::Execute(const std::vector<u32>& params, u32 method) {
26 MICROPROFILE_SCOPE(MacroInterp); 94 MICROPROFILE_SCOPE(MacroInterp);
@@ -283,5 +351,13 @@ u32 MacroInterpreterImpl::FetchParameter() {
283 ASSERT(next_parameter_index < num_parameters); 351 ASSERT(next_parameter_index < num_parameters);
284 return parameters[next_parameter_index++]; 352 return parameters[next_parameter_index++];
285} 353}
354} // Anonymous namespace
355
356MacroInterpreter::MacroInterpreter(Engines::Maxwell3D& maxwell3d_)
357 : MacroEngine{maxwell3d_}, maxwell3d{maxwell3d_} {}
358
359std::unique_ptr<CachedMacro> MacroInterpreter::Compile(const std::vector<u32>& code) {
360 return std::make_unique<MacroInterpreterImpl>(maxwell3d, code);
361}
286 362
287} // namespace Tegra 363} // namespace Tegra
diff --git a/src/video_core/macro/macro_interpreter.h b/src/video_core/macro/macro_interpreter.h
index d50c619ce..8a9648e46 100644
--- a/src/video_core/macro/macro_interpreter.h
+++ b/src/video_core/macro/macro_interpreter.h
@@ -3,10 +3,9 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#pragma once 5#pragma once
6#include <array> 6
7#include <optional>
8#include <vector> 7#include <vector>
9#include "common/bit_field.h" 8
10#include "common/common_types.h" 9#include "common/common_types.h"
11#include "video_core/macro/macro.h" 10#include "video_core/macro/macro.h"
12 11
@@ -26,77 +25,4 @@ private:
26 Engines::Maxwell3D& maxwell3d; 25 Engines::Maxwell3D& maxwell3d;
27}; 26};
28 27
29class MacroInterpreterImpl : public CachedMacro {
30public:
31 explicit MacroInterpreterImpl(Engines::Maxwell3D& maxwell3d_, const std::vector<u32>& code_);
32 void Execute(const std::vector<u32>& params, u32 method) override;
33
34private:
35 /// Resets the execution engine state, zeroing registers, etc.
36 void Reset();
37
38 /**
39 * Executes a single macro instruction located at the current program counter. Returns whether
40 * the interpreter should keep running.
41 *
42 * @param is_delay_slot Whether the current step is being executed due to a delay slot in a
43 * previous instruction.
44 */
45 bool Step(bool is_delay_slot);
46
47 /// Calculates the result of an ALU operation. src_a OP src_b;
48 u32 GetALUResult(Macro::ALUOperation operation, u32 src_a, u32 src_b);
49
50 /// Performs the result operation on the input result and stores it in the specified register
51 /// (if necessary).
52 void ProcessResult(Macro::ResultOperation operation, u32 reg, u32 result);
53
54 /// Evaluates the branch condition and returns whether the branch should be taken or not.
55 bool EvaluateBranchCondition(Macro::BranchCondition cond, u32 value) const;
56
57 /// Reads an opcode at the current program counter location.
58 Macro::Opcode GetOpcode() const;
59
60 /// Returns the specified register's value. Register 0 is hardcoded to always return 0.
61 u32 GetRegister(u32 register_id) const;
62
63 /// Sets the register to the input value.
64 void SetRegister(u32 register_id, u32 value);
65
66 /// Sets the method address to use for the next Send instruction.
67 void SetMethodAddress(u32 address);
68
69 /// Calls a GPU Engine method with the input parameter.
70 void Send(u32 value);
71
72 /// Reads a GPU register located at the method address.
73 u32 Read(u32 method) const;
74
75 /// Returns the next parameter in the parameter queue.
76 u32 FetchParameter();
77
78 Engines::Maxwell3D& maxwell3d;
79
80 /// Current program counter
81 u32 pc;
82 /// Program counter to execute at after the delay slot is executed.
83 std::optional<u32> delayed_pc;
84
85 /// General purpose macro registers.
86 std::array<u32, Macro::NUM_MACRO_REGISTERS> registers = {};
87
88 /// Method address to use for the next Send instruction.
89 Macro::MethodAddress method_address = {};
90
91 /// Input parameters of the current macro.
92 std::unique_ptr<u32[]> parameters;
93 std::size_t num_parameters = 0;
94 std::size_t parameters_capacity = 0;
95 /// Index of the next parameter that will be fetched by the 'parm' instruction.
96 u32 next_parameter_index = 0;
97
98 bool carry_flag = false;
99 const std::vector<u32>& code;
100};
101
102} // namespace Tegra 28} // namespace Tegra
diff --git a/src/video_core/macro/macro_jit_x64.cpp b/src/video_core/macro/macro_jit_x64.cpp
index c6b2b2109..47b28ad16 100644
--- a/src/video_core/macro/macro_jit_x64.cpp
+++ b/src/video_core/macro/macro_jit_x64.cpp
@@ -2,9 +2,17 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <array>
6#include <bitset>
7#include <optional>
8
9#include <xbyak/xbyak.h>
10
5#include "common/assert.h" 11#include "common/assert.h"
12#include "common/bit_field.h"
6#include "common/logging/log.h" 13#include "common/logging/log.h"
7#include "common/microprofile.h" 14#include "common/microprofile.h"
15#include "common/x64/xbyak_abi.h"
8#include "common/x64/xbyak_util.h" 16#include "common/x64/xbyak_util.h"
9#include "video_core/engines/maxwell_3d.h" 17#include "video_core/engines/maxwell_3d.h"
10#include "video_core/macro/macro_interpreter.h" 18#include "video_core/macro/macro_interpreter.h"
@@ -14,13 +22,14 @@ MICROPROFILE_DEFINE(MacroJitCompile, "GPU", "Compile macro JIT", MP_RGB(173, 255
14MICROPROFILE_DEFINE(MacroJitExecute, "GPU", "Execute macro JIT", MP_RGB(255, 255, 0)); 22MICROPROFILE_DEFINE(MacroJitExecute, "GPU", "Execute macro JIT", MP_RGB(255, 255, 0));
15 23
16namespace Tegra { 24namespace Tegra {
25namespace {
17constexpr Xbyak::Reg64 STATE = Xbyak::util::rbx; 26constexpr Xbyak::Reg64 STATE = Xbyak::util::rbx;
18constexpr Xbyak::Reg32 RESULT = Xbyak::util::ebp; 27constexpr Xbyak::Reg32 RESULT = Xbyak::util::ebp;
19constexpr Xbyak::Reg64 PARAMETERS = Xbyak::util::r12; 28constexpr Xbyak::Reg64 PARAMETERS = Xbyak::util::r12;
20constexpr Xbyak::Reg32 METHOD_ADDRESS = Xbyak::util::r14d; 29constexpr Xbyak::Reg32 METHOD_ADDRESS = Xbyak::util::r14d;
21constexpr Xbyak::Reg64 BRANCH_HOLDER = Xbyak::util::r15; 30constexpr Xbyak::Reg64 BRANCH_HOLDER = Xbyak::util::r15;
22 31
23static const std::bitset<32> PERSISTENT_REGISTERS = Common::X64::BuildRegSet({ 32constexpr std::bitset<32> PERSISTENT_REGISTERS = Common::X64::BuildRegSet({
24 STATE, 33 STATE,
25 RESULT, 34 RESULT,
26 PARAMETERS, 35 PARAMETERS,
@@ -28,19 +37,75 @@ static const std::bitset<32> PERSISTENT_REGISTERS = Common::X64::BuildRegSet({
28 BRANCH_HOLDER, 37 BRANCH_HOLDER,
29}); 38});
30 39
31MacroJITx64::MacroJITx64(Engines::Maxwell3D& maxwell3d_) 40// Arbitrarily chosen based on current booting games.
32 : MacroEngine{maxwell3d_}, maxwell3d{maxwell3d_} {} 41constexpr size_t MAX_CODE_SIZE = 0x10000;
33 42
34std::unique_ptr<CachedMacro> MacroJITx64::Compile(const std::vector<u32>& code) { 43std::bitset<32> PersistentCallerSavedRegs() {
35 return std::make_unique<MacroJITx64Impl>(maxwell3d, code); 44 return PERSISTENT_REGISTERS & Common::X64::ABI_ALL_CALLER_SAVED;
36} 45}
37 46
38MacroJITx64Impl::MacroJITx64Impl(Engines::Maxwell3D& maxwell3d_, const std::vector<u32>& code_) 47class MacroJITx64Impl final : public Xbyak::CodeGenerator, public CachedMacro {
39 : CodeGenerator{MAX_CODE_SIZE}, code{code_}, maxwell3d{maxwell3d_} { 48public:
40 Compile(); 49 explicit MacroJITx64Impl(Engines::Maxwell3D& maxwell3d_, const std::vector<u32>& code_)
41} 50 : CodeGenerator{MAX_CODE_SIZE}, code{code_}, maxwell3d{maxwell3d_} {
51 Compile();
52 }
53
54 void Execute(const std::vector<u32>& parameters, u32 method) override;
55
56 void Compile_ALU(Macro::Opcode opcode);
57 void Compile_AddImmediate(Macro::Opcode opcode);
58 void Compile_ExtractInsert(Macro::Opcode opcode);
59 void Compile_ExtractShiftLeftImmediate(Macro::Opcode opcode);
60 void Compile_ExtractShiftLeftRegister(Macro::Opcode opcode);
61 void Compile_Read(Macro::Opcode opcode);
62 void Compile_Branch(Macro::Opcode opcode);
63
64private:
65 void Optimizer_ScanFlags();
66
67 void Compile();
68 bool Compile_NextInstruction();
69
70 Xbyak::Reg32 Compile_FetchParameter();
71 Xbyak::Reg32 Compile_GetRegister(u32 index, Xbyak::Reg32 dst);
72
73 void Compile_ProcessResult(Macro::ResultOperation operation, u32 reg);
74 void Compile_Send(Xbyak::Reg32 value);
42 75
43MacroJITx64Impl::~MacroJITx64Impl() = default; 76 Macro::Opcode GetOpCode() const;
77
78 struct JITState {
79 Engines::Maxwell3D* maxwell3d{};
80 std::array<u32, Macro::NUM_MACRO_REGISTERS> registers{};
81 u32 carry_flag{};
82 };
83 static_assert(offsetof(JITState, maxwell3d) == 0, "Maxwell3D is not at 0x0");
84 using ProgramType = void (*)(JITState*, const u32*);
85
86 struct OptimizerState {
87 bool can_skip_carry{};
88 bool has_delayed_pc{};
89 bool zero_reg_skip{};
90 bool skip_dummy_addimmediate{};
91 bool optimize_for_method_move{};
92 bool enable_asserts{};
93 };
94 OptimizerState optimizer{};
95
96 std::optional<Macro::Opcode> next_opcode{};
97 ProgramType program{nullptr};
98
99 std::array<Xbyak::Label, MAX_CODE_SIZE> labels;
100 std::array<Xbyak::Label, MAX_CODE_SIZE> delay_skip;
101 Xbyak::Label end_of_code{};
102
103 bool is_delay_slot{};
104 u32 pc{};
105
106 const std::vector<u32>& code;
107 Engines::Maxwell3D& maxwell3d;
108};
44 109
45void MacroJITx64Impl::Execute(const std::vector<u32>& parameters, u32 method) { 110void MacroJITx64Impl::Execute(const std::vector<u32>& parameters, u32 method) {
46 MICROPROFILE_SCOPE(MacroJitExecute); 111 MICROPROFILE_SCOPE(MacroJitExecute);
@@ -307,11 +372,11 @@ void MacroJITx64Impl::Compile_Read(Macro::Opcode opcode) {
307 Compile_ProcessResult(opcode.result_operation, opcode.dst); 372 Compile_ProcessResult(opcode.result_operation, opcode.dst);
308} 373}
309 374
310static void Send(Engines::Maxwell3D* maxwell3d, Macro::MethodAddress method_address, u32 value) { 375void Send(Engines::Maxwell3D* maxwell3d, Macro::MethodAddress method_address, u32 value) {
311 maxwell3d->CallMethodFromMME(method_address.address, value); 376 maxwell3d->CallMethodFromMME(method_address.address, value);
312} 377}
313 378
314void Tegra::MacroJITx64Impl::Compile_Send(Xbyak::Reg32 value) { 379void MacroJITx64Impl::Compile_Send(Xbyak::Reg32 value) {
315 Common::X64::ABI_PushRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0); 380 Common::X64::ABI_PushRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0);
316 mov(Common::X64::ABI_PARAM1, qword[STATE]); 381 mov(Common::X64::ABI_PARAM1, qword[STATE]);
317 mov(Common::X64::ABI_PARAM2, METHOD_ADDRESS); 382 mov(Common::X64::ABI_PARAM2, METHOD_ADDRESS);
@@ -338,7 +403,7 @@ void Tegra::MacroJITx64Impl::Compile_Send(Xbyak::Reg32 value) {
338 L(dont_process); 403 L(dont_process);
339} 404}
340 405
341void Tegra::MacroJITx64Impl::Compile_Branch(Macro::Opcode opcode) { 406void MacroJITx64Impl::Compile_Branch(Macro::Opcode opcode) {
342 ASSERT_MSG(!is_delay_slot, "Executing a branch in a delay slot is not valid"); 407 ASSERT_MSG(!is_delay_slot, "Executing a branch in a delay slot is not valid");
343 const s32 jump_address = 408 const s32 jump_address =
344 static_cast<s32>(pc) + static_cast<s32>(opcode.GetBranchTarget() / sizeof(s32)); 409 static_cast<s32>(pc) + static_cast<s32>(opcode.GetBranchTarget() / sizeof(s32));
@@ -392,7 +457,7 @@ void Tegra::MacroJITx64Impl::Compile_Branch(Macro::Opcode opcode) {
392 L(end); 457 L(end);
393} 458}
394 459
395void Tegra::MacroJITx64Impl::Optimizer_ScanFlags() { 460void MacroJITx64Impl::Optimizer_ScanFlags() {
396 optimizer.can_skip_carry = true; 461 optimizer.can_skip_carry = true;
397 optimizer.has_delayed_pc = false; 462 optimizer.has_delayed_pc = false;
398 for (auto raw_op : code) { 463 for (auto raw_op : code) {
@@ -534,7 +599,7 @@ bool MacroJITx64Impl::Compile_NextInstruction() {
534 return true; 599 return true;
535} 600}
536 601
537Xbyak::Reg32 Tegra::MacroJITx64Impl::Compile_FetchParameter() { 602Xbyak::Reg32 MacroJITx64Impl::Compile_FetchParameter() {
538 mov(eax, dword[PARAMETERS]); 603 mov(eax, dword[PARAMETERS]);
539 add(PARAMETERS, sizeof(u32)); 604 add(PARAMETERS, sizeof(u32));
540 return eax; 605 return eax;
@@ -611,9 +676,12 @@ Macro::Opcode MacroJITx64Impl::GetOpCode() const {
611 ASSERT(pc < code.size()); 676 ASSERT(pc < code.size());
612 return {code[pc]}; 677 return {code[pc]};
613} 678}
679} // Anonymous namespace
614 680
615std::bitset<32> MacroJITx64Impl::PersistentCallerSavedRegs() const { 681MacroJITx64::MacroJITx64(Engines::Maxwell3D& maxwell3d_)
616 return PERSISTENT_REGISTERS & Common::X64::ABI_ALL_CALLER_SAVED; 682 : MacroEngine{maxwell3d_}, maxwell3d{maxwell3d_} {}
617}
618 683
684std::unique_ptr<CachedMacro> MacroJITx64::Compile(const std::vector<u32>& code) {
685 return std::make_unique<MacroJITx64Impl>(maxwell3d, code);
686}
619} // namespace Tegra 687} // namespace Tegra
diff --git a/src/video_core/macro/macro_jit_x64.h b/src/video_core/macro/macro_jit_x64.h
index d03d480b4..773b037ae 100644
--- a/src/video_core/macro/macro_jit_x64.h
+++ b/src/video_core/macro/macro_jit_x64.h
@@ -4,12 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <array>
8#include <bitset>
9#include <xbyak/xbyak.h>
10#include "common/bit_field.h"
11#include "common/common_types.h" 7#include "common/common_types.h"
12#include "common/x64/xbyak_abi.h"
13#include "video_core/macro/macro.h" 8#include "video_core/macro/macro.h"
14 9
15namespace Tegra { 10namespace Tegra {
@@ -18,9 +13,6 @@ namespace Engines {
18class Maxwell3D; 13class Maxwell3D;
19} 14}
20 15
21/// MAX_CODE_SIZE is arbitrarily chosen based on current booting games
22constexpr size_t MAX_CODE_SIZE = 0x10000;
23
24class MacroJITx64 final : public MacroEngine { 16class MacroJITx64 final : public MacroEngine {
25public: 17public:
26 explicit MacroJITx64(Engines::Maxwell3D& maxwell3d_); 18 explicit MacroJITx64(Engines::Maxwell3D& maxwell3d_);
@@ -32,67 +24,4 @@ private:
32 Engines::Maxwell3D& maxwell3d; 24 Engines::Maxwell3D& maxwell3d;
33}; 25};
34 26
35class MacroJITx64Impl : public Xbyak::CodeGenerator, public CachedMacro {
36public:
37 explicit MacroJITx64Impl(Engines::Maxwell3D& maxwell3d_, const std::vector<u32>& code_);
38 ~MacroJITx64Impl();
39
40 void Execute(const std::vector<u32>& parameters, u32 method) override;
41
42 void Compile_ALU(Macro::Opcode opcode);
43 void Compile_AddImmediate(Macro::Opcode opcode);
44 void Compile_ExtractInsert(Macro::Opcode opcode);
45 void Compile_ExtractShiftLeftImmediate(Macro::Opcode opcode);
46 void Compile_ExtractShiftLeftRegister(Macro::Opcode opcode);
47 void Compile_Read(Macro::Opcode opcode);
48 void Compile_Branch(Macro::Opcode opcode);
49
50private:
51 void Optimizer_ScanFlags();
52
53 void Compile();
54 bool Compile_NextInstruction();
55
56 Xbyak::Reg32 Compile_FetchParameter();
57 Xbyak::Reg32 Compile_GetRegister(u32 index, Xbyak::Reg32 dst);
58
59 void Compile_ProcessResult(Macro::ResultOperation operation, u32 reg);
60 void Compile_Send(Xbyak::Reg32 value);
61
62 Macro::Opcode GetOpCode() const;
63 std::bitset<32> PersistentCallerSavedRegs() const;
64
65 struct JITState {
66 Engines::Maxwell3D* maxwell3d{};
67 std::array<u32, Macro::NUM_MACRO_REGISTERS> registers{};
68 u32 carry_flag{};
69 };
70 static_assert(offsetof(JITState, maxwell3d) == 0, "Maxwell3D is not at 0x0");
71 using ProgramType = void (*)(JITState*, const u32*);
72
73 struct OptimizerState {
74 bool can_skip_carry{};
75 bool has_delayed_pc{};
76 bool zero_reg_skip{};
77 bool skip_dummy_addimmediate{};
78 bool optimize_for_method_move{};
79 bool enable_asserts{};
80 };
81 OptimizerState optimizer{};
82
83 std::optional<Macro::Opcode> next_opcode{};
84 ProgramType program{nullptr};
85
86 std::array<Xbyak::Label, MAX_CODE_SIZE> labels;
87 std::array<Xbyak::Label, MAX_CODE_SIZE> delay_skip;
88 Xbyak::Label end_of_code{};
89
90 bool is_delay_slot{};
91 u32 pc{};
92 std::optional<u32> delayed_pc;
93
94 const std::vector<u32>& code;
95 Engines::Maxwell3D& maxwell3d;
96};
97
98} // namespace Tegra 27} // namespace Tegra
diff --git a/src/video_core/renderer_vulkan/vk_fsr.cpp b/src/video_core/renderer_vulkan/vk_fsr.cpp
index 73629d229..b630090e8 100644
--- a/src/video_core/renderer_vulkan/vk_fsr.cpp
+++ b/src/video_core/renderer_vulkan/vk_fsr.cpp
@@ -214,7 +214,7 @@ VkImageView FSR::Draw(VKScheduler& scheduler, size_t image_index, VkImageView im
214 214
215 { 215 {
216 VkImageMemoryBarrier fsr_write_barrier = base_barrier; 216 VkImageMemoryBarrier fsr_write_barrier = base_barrier;
217 fsr_write_barrier.image = *images[image_index], 217 fsr_write_barrier.image = *images[image_index];
218 fsr_write_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; 218 fsr_write_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
219 219
220 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 220 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp
index 7e8f92840..2c8c10c50 100644
--- a/src/yuzu/configuration/config.cpp
+++ b/src/yuzu/configuration/config.cpp
@@ -393,6 +393,8 @@ void Config::ReadControlValues() {
393 ReadGlobalSetting(Settings::values.enable_accurate_vibrations); 393 ReadGlobalSetting(Settings::values.enable_accurate_vibrations);
394 ReadGlobalSetting(Settings::values.motion_enabled); 394 ReadGlobalSetting(Settings::values.motion_enabled);
395 395
396 ReadBasicSetting(Settings::values.controller_navigation);
397
396 qt_config->endGroup(); 398 qt_config->endGroup();
397} 399}
398 400
@@ -1001,6 +1003,7 @@ void Config::SaveControlValues() {
1001 WriteBasicSetting(Settings::values.keyboard_enabled); 1003 WriteBasicSetting(Settings::values.keyboard_enabled);
1002 WriteBasicSetting(Settings::values.emulate_analog_keyboard); 1004 WriteBasicSetting(Settings::values.emulate_analog_keyboard);
1003 WriteBasicSetting(Settings::values.mouse_panning_sensitivity); 1005 WriteBasicSetting(Settings::values.mouse_panning_sensitivity);
1006 WriteBasicSetting(Settings::values.controller_navigation);
1004 1007
1005 WriteBasicSetting(Settings::values.tas_enable); 1008 WriteBasicSetting(Settings::values.tas_enable);
1006 WriteBasicSetting(Settings::values.tas_loop); 1009 WriteBasicSetting(Settings::values.tas_loop);
diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui
index 9241678e4..74f0e0b79 100644
--- a/src/yuzu/configuration/configure_graphics.ui
+++ b/src/yuzu/configuration/configure_graphics.ui
@@ -429,7 +429,7 @@
429 </item> 429 </item>
430 <item> 430 <item>
431 <property name="text"> 431 <property name="text">
432 <string>AMD FidelityFX™️ Super Resolution [Vulkan Only]</string> 432 <string>AMD FidelityFX™️ Super Resolution (Vulkan Only)</string>
433 </property> 433 </property>
434 </item> 434 </item>
435 </widget> 435 </widget>
diff --git a/src/yuzu/configuration/configure_input_advanced.cpp b/src/yuzu/configuration/configure_input_advanced.cpp
index 65c8e59ac..20fc2599d 100644
--- a/src/yuzu/configuration/configure_input_advanced.cpp
+++ b/src/yuzu/configuration/configure_input_advanced.cpp
@@ -131,6 +131,7 @@ void ConfigureInputAdvanced::ApplyConfiguration() {
131 Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked(); 131 Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked();
132 Settings::values.enable_raw_input = ui->enable_raw_input->isChecked(); 132 Settings::values.enable_raw_input = ui->enable_raw_input->isChecked();
133 Settings::values.enable_udp_controller = ui->enable_udp_controller->isChecked(); 133 Settings::values.enable_udp_controller = ui->enable_udp_controller->isChecked();
134 Settings::values.controller_navigation = ui->controller_navigation->isChecked();
134} 135}
135 136
136void ConfigureInputAdvanced::LoadConfiguration() { 137void ConfigureInputAdvanced::LoadConfiguration() {
@@ -162,6 +163,7 @@ void ConfigureInputAdvanced::LoadConfiguration() {
162 ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled); 163 ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled);
163 ui->enable_raw_input->setChecked(Settings::values.enable_raw_input.GetValue()); 164 ui->enable_raw_input->setChecked(Settings::values.enable_raw_input.GetValue());
164 ui->enable_udp_controller->setChecked(Settings::values.enable_udp_controller.GetValue()); 165 ui->enable_udp_controller->setChecked(Settings::values.enable_udp_controller.GetValue());
166 ui->controller_navigation->setChecked(Settings::values.controller_navigation.GetValue());
165 167
166 UpdateUIEnabled(); 168 UpdateUIEnabled();
167} 169}
diff --git a/src/yuzu/configuration/configure_input_advanced.ui b/src/yuzu/configuration/configure_input_advanced.ui
index df0e4d602..66f2075f2 100644
--- a/src/yuzu/configuration/configure_input_advanced.ui
+++ b/src/yuzu/configuration/configure_input_advanced.ui
@@ -2655,6 +2655,19 @@
2655 </widget> 2655 </widget>
2656 </item> 2656 </item>
2657 <item row="4" column="0"> 2657 <item row="4" column="0">
2658 <widget class="QCheckBox" name="controller_navigation">
2659 <property name="minimumSize">
2660 <size>
2661 <width>0</width>
2662 <height>23</height>
2663 </size>
2664 </property>
2665 <property name="text">
2666 <string>Controller navigation</string>
2667 </property>
2668 </widget>
2669 </item>
2670 <item row="5" column="0">
2658 <widget class="QCheckBox" name="mouse_panning"> 2671 <widget class="QCheckBox" name="mouse_panning">
2659 <property name="minimumSize"> 2672 <property name="minimumSize">
2660 <size> 2673 <size>
@@ -2667,7 +2680,7 @@
2667 </property> 2680 </property>
2668 </widget> 2681 </widget>
2669 </item> 2682 </item>
2670 <item row="4" column="2"> 2683 <item row="5" column="2">
2671 <widget class="QSpinBox" name="mouse_panning_sensitivity"> 2684 <widget class="QSpinBox" name="mouse_panning_sensitivity">
2672 <property name="toolTip"> 2685 <property name="toolTip">
2673 <string>Mouse sensitivity</string> 2686 <string>Mouse sensitivity</string>
@@ -2689,14 +2702,14 @@
2689 </property> 2702 </property>
2690 </widget> 2703 </widget>
2691 </item> 2704 </item>
2692 <item row="5" column="0"> 2705 <item row="6" column="0">
2693 <widget class="QLabel" name="motion_touch"> 2706 <widget class="QLabel" name="motion_touch">
2694 <property name="text"> 2707 <property name="text">
2695 <string>Motion / Touch</string> 2708 <string>Motion / Touch</string>
2696 </property> 2709 </property>
2697 </widget> 2710 </widget>
2698 </item> 2711 </item>
2699 <item row="5" column="2"> 2712 <item row="6" column="2">
2700 <widget class="QPushButton" name="buttonMotionTouch"> 2713 <widget class="QPushButton" name="buttonMotionTouch">
2701 <property name="text"> 2714 <property name="text">
2702 <string>Configure</string> 2715 <string>Configure</string>
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 365e97411..752504236 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -147,7 +147,7 @@ QString ConfigureInputPlayer::ButtonToText(const Common::ParamPackage& param) {
147 // Retrieve the names from Qt 147 // Retrieve the names from Qt
148 if (param.Get("engine", "") == "keyboard") { 148 if (param.Get("engine", "") == "keyboard") {
149 const QString button_str = GetKeyName(param.Get("code", 0)); 149 const QString button_str = GetKeyName(param.Get("code", 0));
150 return QObject::tr("%1%2").arg(toggle, button_str); 150 return QObject::tr("%1%2%3").arg(toggle, inverted, button_str);
151 } 151 }
152 152
153 if (common_button_name == Common::Input::ButtonNames::Invalid) { 153 if (common_button_name == Common::Input::ButtonNames::Invalid) {
@@ -341,7 +341,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
341 emulated_controller->SetButtonParam(button_id, {}); 341 emulated_controller->SetButtonParam(button_id, {});
342 button_map[button_id]->setText(tr("[not set]")); 342 button_map[button_id]->setText(tr("[not set]"));
343 }); 343 });
344 if (param.Has("button") || param.Has("hat")) { 344 if (param.Has("code") || param.Has("button") || param.Has("hat")) {
345 context_menu.addAction(tr("Toggle button"), [&] { 345 context_menu.addAction(tr("Toggle button"), [&] {
346 const bool toggle_value = !param.Get("toggle", false); 346 const bool toggle_value = !param.Get("toggle", false);
347 param.Set("toggle", toggle_value); 347 param.Set("toggle", toggle_value);
@@ -349,8 +349,8 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
349 emulated_controller->SetButtonParam(button_id, param); 349 emulated_controller->SetButtonParam(button_id, param);
350 }); 350 });
351 context_menu.addAction(tr("Invert button"), [&] { 351 context_menu.addAction(tr("Invert button"), [&] {
352 const bool toggle_value = !param.Get("inverted", false); 352 const bool invert_value = !param.Get("inverted", false);
353 param.Set("inverted", toggle_value); 353 param.Set("inverted", invert_value);
354 button_map[button_id]->setText(ButtonToText(param)); 354 button_map[button_id]->setText(ButtonToText(param));
355 emulated_controller->SetButtonParam(button_id, param); 355 emulated_controller->SetButtonParam(button_id, param);
356 }); 356 });
@@ -522,28 +522,37 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
522 522
523 analog_map_modifier_button[analog_id]->setContextMenuPolicy(Qt::CustomContextMenu); 523 analog_map_modifier_button[analog_id]->setContextMenuPolicy(Qt::CustomContextMenu);
524 524
525 connect(analog_map_modifier_button[analog_id], &QPushButton::customContextMenuRequested, 525 connect(
526 [=, this](const QPoint& menu_location) { 526 analog_map_modifier_button[analog_id], &QPushButton::customContextMenuRequested,
527 QMenu context_menu; 527 [=, this](const QPoint& menu_location) {
528 Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); 528 QMenu context_menu;
529 context_menu.addAction(tr("Clear"), [&] { 529 Common::ParamPackage param = emulated_controller->GetStickParam(analog_id);
530 param.Set("modifier", ""); 530 context_menu.addAction(tr("Clear"), [&] {
531 analog_map_modifier_button[analog_id]->setText(tr("[not set]")); 531 param.Set("modifier", "");
532 emulated_controller->SetStickParam(analog_id, param); 532 analog_map_modifier_button[analog_id]->setText(tr("[not set]"));
533 }); 533 emulated_controller->SetStickParam(analog_id, param);
534 context_menu.addAction(tr("Toggle button"), [&] { 534 });
535 Common::ParamPackage modifier_param = 535 context_menu.addAction(tr("Toggle button"), [&] {
536 Common::ParamPackage{param.Get("modifier", "")}; 536 Common::ParamPackage modifier_param =
537 const bool toggle_value = !modifier_param.Get("toggle", false); 537 Common::ParamPackage{param.Get("modifier", "")};
538 modifier_param.Set("toggle", toggle_value); 538 const bool toggle_value = !modifier_param.Get("toggle", false);
539 param.Set("modifier", modifier_param.Serialize()); 539 modifier_param.Set("toggle", toggle_value);
540 analog_map_modifier_button[analog_id]->setText( 540 param.Set("modifier", modifier_param.Serialize());
541 ButtonToText(modifier_param)); 541 analog_map_modifier_button[analog_id]->setText(ButtonToText(modifier_param));
542 emulated_controller->SetStickParam(analog_id, param); 542 emulated_controller->SetStickParam(analog_id, param);
543 });
544 context_menu.exec(
545 analog_map_modifier_button[analog_id]->mapToGlobal(menu_location));
546 }); 543 });
544 context_menu.addAction(tr("Invert button"), [&] {
545 Common::ParamPackage modifier_param =
546 Common::ParamPackage{param.Get("modifier", "")};
547 const bool invert_value = !modifier_param.Get("inverted", false);
548 modifier_param.Set("inverted", invert_value);
549 param.Set("modifier", modifier_param.Serialize());
550 analog_map_modifier_button[analog_id]->setText(ButtonToText(modifier_param));
551 emulated_controller->SetStickParam(analog_id, param);
552 });
553 context_menu.exec(
554 analog_map_modifier_button[analog_id]->mapToGlobal(menu_location));
555 });
547 556
548 connect(analog_map_range_spinbox[analog_id], qOverload<int>(&QSpinBox::valueChanged), 557 connect(analog_map_range_spinbox[analog_id], qOverload<int>(&QSpinBox::valueChanged),
549 [=, this] { 558 [=, this] {
diff --git a/src/yuzu/hotkeys.cpp b/src/yuzu/hotkeys.cpp
index d96497c4e..6ed9611c7 100644
--- a/src/yuzu/hotkeys.cpp
+++ b/src/yuzu/hotkeys.cpp
@@ -190,6 +190,9 @@ void ControllerShortcut::ControllerUpdateEvent(Core::HID::ControllerTriggerType
190 if (type != Core::HID::ControllerTriggerType::Button) { 190 if (type != Core::HID::ControllerTriggerType::Button) {
191 return; 191 return;
192 } 192 }
193 if (!Settings::values.controller_navigation) {
194 return;
195 }
193 if (button_sequence.npad.raw == Core::HID::NpadButton::None && 196 if (button_sequence.npad.raw == Core::HID::NpadButton::None &&
194 button_sequence.capture.raw == 0 && button_sequence.home.raw == 0) { 197 button_sequence.capture.raw == 0 && button_sequence.home.raw == 0) {
195 return; 198 return;
diff --git a/src/yuzu/util/controller_navigation.cpp b/src/yuzu/util/controller_navigation.cpp
index 86fb28b9f..c2b13123d 100644
--- a/src/yuzu/util/controller_navigation.cpp
+++ b/src/yuzu/util/controller_navigation.cpp
@@ -40,6 +40,9 @@ void ControllerNavigation::TriggerButton(Settings::NativeButton::Values native_b
40 40
41void ControllerNavigation::ControllerUpdateEvent(Core::HID::ControllerTriggerType type) { 41void ControllerNavigation::ControllerUpdateEvent(Core::HID::ControllerTriggerType type) {
42 std::lock_guard lock{mutex}; 42 std::lock_guard lock{mutex};
43 if (!Settings::values.controller_navigation) {
44 return;
45 }
43 if (type == Core::HID::ControllerTriggerType::Button) { 46 if (type == Core::HID::ControllerTriggerType::Button) {
44 ControllerUpdateButton(); 47 ControllerUpdateButton();
45 return; 48 return;