diff options
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 38 | ||||
| -rw-r--r-- | src/core/hle/service/set/set.cpp | 53 | ||||
| -rw-r--r-- | src/core/hle/service/set/set.h | 1 | ||||
| -rw-r--r-- | src/video_core/engines/shader_bytecode.h | 14 |
4 files changed, 71 insertions, 35 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 6b2995fe2..7b41c9cfd 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -650,12 +650,27 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target | |||
| 650 | 650 | ||
| 651 | ASSERT(thread->condvar_wait_address == condition_variable_addr); | 651 | ASSERT(thread->condvar_wait_address == condition_variable_addr); |
| 652 | 652 | ||
| 653 | // If the mutex is not yet acquired, acquire it. | 653 | size_t current_core = Core::System::GetInstance().CurrentCoreIndex(); |
| 654 | u32 mutex_val = Memory::Read32(thread->mutex_wait_address); | 654 | |
| 655 | auto& monitor = Core::System::GetInstance().Monitor(); | ||
| 656 | |||
| 657 | // Atomically read the value of the mutex. | ||
| 658 | u32 mutex_val = 0; | ||
| 659 | do { | ||
| 660 | monitor.SetExclusive(current_core, thread->mutex_wait_address); | ||
| 661 | |||
| 662 | // If the mutex is not yet acquired, acquire it. | ||
| 663 | mutex_val = Memory::Read32(thread->mutex_wait_address); | ||
| 664 | |||
| 665 | if (mutex_val != 0) { | ||
| 666 | monitor.ClearExclusive(); | ||
| 667 | break; | ||
| 668 | } | ||
| 669 | } while (!monitor.ExclusiveWrite32(current_core, thread->mutex_wait_address, | ||
| 670 | thread->wait_handle)); | ||
| 655 | 671 | ||
| 656 | if (mutex_val == 0) { | 672 | if (mutex_val == 0) { |
| 657 | // We were able to acquire the mutex, resume this thread. | 673 | // We were able to acquire the mutex, resume this thread. |
| 658 | Memory::Write32(thread->mutex_wait_address, thread->wait_handle); | ||
| 659 | ASSERT(thread->status == ThreadStatus::WaitMutex); | 674 | ASSERT(thread->status == ThreadStatus::WaitMutex); |
| 660 | thread->ResumeFromWait(); | 675 | thread->ResumeFromWait(); |
| 661 | 676 | ||
| @@ -668,7 +683,19 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target | |||
| 668 | thread->condvar_wait_address = 0; | 683 | thread->condvar_wait_address = 0; |
| 669 | thread->wait_handle = 0; | 684 | thread->wait_handle = 0; |
| 670 | } else { | 685 | } else { |
| 671 | // Couldn't acquire the mutex, block the thread. | 686 | // Atomically signal that the mutex now has a waiting thread. |
| 687 | do { | ||
| 688 | monitor.SetExclusive(current_core, thread->mutex_wait_address); | ||
| 689 | |||
| 690 | // Ensure that the mutex value is still what we expect. | ||
| 691 | u32 value = Memory::Read32(thread->mutex_wait_address); | ||
| 692 | // TODO(Subv): When this happens, the kernel just clears the exclusive state and | ||
| 693 | // retries the initial read for this thread. | ||
| 694 | ASSERT_MSG(mutex_val == value, "Unhandled synchronization primitive case"); | ||
| 695 | } while (!monitor.ExclusiveWrite32(current_core, thread->mutex_wait_address, | ||
| 696 | mutex_val | Mutex::MutexHasWaitersFlag)); | ||
| 697 | |||
| 698 | // The mutex is already owned by some other thread, make this thread wait on it. | ||
| 672 | Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask); | 699 | Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask); |
| 673 | auto owner = g_handle_table.Get<Thread>(owner_handle); | 700 | auto owner = g_handle_table.Get<Thread>(owner_handle); |
| 674 | ASSERT(owner); | 701 | ASSERT(owner); |
| @@ -676,9 +703,6 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target | |||
| 676 | thread->status = ThreadStatus::WaitMutex; | 703 | thread->status = ThreadStatus::WaitMutex; |
| 677 | thread->wakeup_callback = nullptr; | 704 | thread->wakeup_callback = nullptr; |
| 678 | 705 | ||
| 679 | // Signal that the mutex now has a waiting thread. | ||
| 680 | Memory::Write32(thread->mutex_wait_address, mutex_val | Mutex::MutexHasWaitersFlag); | ||
| 681 | |||
| 682 | owner->AddMutexWaiter(thread); | 706 | owner->AddMutexWaiter(thread); |
| 683 | 707 | ||
| 684 | Core::System::GetInstance().CpuCore(thread->processor_id).PrepareReschedule(); | 708 | Core::System::GetInstance().CpuCore(thread->processor_id).PrepareReschedule(); |
diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index 886133b74..4195c9067 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp | |||
| @@ -11,44 +11,51 @@ | |||
| 11 | 11 | ||
| 12 | namespace Service::Set { | 12 | namespace Service::Set { |
| 13 | 13 | ||
| 14 | constexpr std::array<LanguageCode, 17> available_language_codes = {{ | ||
| 15 | LanguageCode::JA, | ||
| 16 | LanguageCode::EN_US, | ||
| 17 | LanguageCode::FR, | ||
| 18 | LanguageCode::DE, | ||
| 19 | LanguageCode::IT, | ||
| 20 | LanguageCode::ES, | ||
| 21 | LanguageCode::ZH_CN, | ||
| 22 | LanguageCode::KO, | ||
| 23 | LanguageCode::NL, | ||
| 24 | LanguageCode::PT, | ||
| 25 | LanguageCode::RU, | ||
| 26 | LanguageCode::ZH_TW, | ||
| 27 | LanguageCode::EN_GB, | ||
| 28 | LanguageCode::FR_CA, | ||
| 29 | LanguageCode::ES_419, | ||
| 30 | LanguageCode::ZH_HANS, | ||
| 31 | LanguageCode::ZH_HANT, | ||
| 32 | }}; | ||
| 33 | |||
| 14 | void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) { | 34 | void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) { |
| 15 | static constexpr std::array<LanguageCode, 17> available_language_codes = {{ | ||
| 16 | LanguageCode::JA, | ||
| 17 | LanguageCode::EN_US, | ||
| 18 | LanguageCode::FR, | ||
| 19 | LanguageCode::DE, | ||
| 20 | LanguageCode::IT, | ||
| 21 | LanguageCode::ES, | ||
| 22 | LanguageCode::ZH_CN, | ||
| 23 | LanguageCode::KO, | ||
| 24 | LanguageCode::NL, | ||
| 25 | LanguageCode::PT, | ||
| 26 | LanguageCode::RU, | ||
| 27 | LanguageCode::ZH_TW, | ||
| 28 | LanguageCode::EN_GB, | ||
| 29 | LanguageCode::FR_CA, | ||
| 30 | LanguageCode::ES_419, | ||
| 31 | LanguageCode::ZH_HANS, | ||
| 32 | LanguageCode::ZH_HANT, | ||
| 33 | }}; | ||
| 34 | ctx.WriteBuffer(available_language_codes); | 35 | ctx.WriteBuffer(available_language_codes); |
| 35 | 36 | ||
| 36 | IPC::ResponseBuilder rb{ctx, 4}; | 37 | IPC::ResponseBuilder rb{ctx, 3}; |
| 37 | rb.Push(RESULT_SUCCESS); | 38 | rb.Push(RESULT_SUCCESS); |
| 38 | rb.Push(static_cast<u64>(available_language_codes.size())); | 39 | rb.Push(static_cast<u32>(available_language_codes.size())); |
| 39 | 40 | ||
| 40 | LOG_DEBUG(Service_SET, "called"); | 41 | LOG_DEBUG(Service_SET, "called"); |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 44 | void SET::GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx) { | ||
| 45 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 46 | rb.Push(RESULT_SUCCESS); | ||
| 47 | rb.Push(static_cast<u32>(available_language_codes.size())); | ||
| 48 | } | ||
| 49 | |||
| 43 | SET::SET() : ServiceFramework("set") { | 50 | SET::SET() : ServiceFramework("set") { |
| 44 | static const FunctionInfo functions[] = { | 51 | static const FunctionInfo functions[] = { |
| 45 | {0, nullptr, "GetLanguageCode"}, | 52 | {0, nullptr, "GetLanguageCode"}, |
| 46 | {1, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes"}, | 53 | {1, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes"}, |
| 47 | {2, nullptr, "MakeLanguageCode"}, | 54 | {2, nullptr, "MakeLanguageCode"}, |
| 48 | {3, nullptr, "GetAvailableLanguageCodeCount"}, | 55 | {3, &SET::GetAvailableLanguageCodeCount, "GetAvailableLanguageCodeCount"}, |
| 49 | {4, nullptr, "GetRegionCode"}, | 56 | {4, nullptr, "GetRegionCode"}, |
| 50 | {5, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes2"}, | 57 | {5, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes2"}, |
| 51 | {6, nullptr, "GetAvailableLanguageCodeCount2"}, | 58 | {6, &SET::GetAvailableLanguageCodeCount, "GetAvailableLanguageCodeCount2"}, |
| 52 | {7, nullptr, "GetKeyCodeMap"}, | 59 | {7, nullptr, "GetKeyCodeMap"}, |
| 53 | {8, nullptr, "GetQuestFlag"}, | 60 | {8, nullptr, "GetQuestFlag"}, |
| 54 | }; | 61 | }; |
diff --git a/src/core/hle/service/set/set.h b/src/core/hle/service/set/set.h index ec0df0152..a2472ec4c 100644 --- a/src/core/hle/service/set/set.h +++ b/src/core/hle/service/set/set.h | |||
| @@ -36,6 +36,7 @@ public: | |||
| 36 | 36 | ||
| 37 | private: | 37 | private: |
| 38 | void GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx); | 38 | void GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx); |
| 39 | void GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx); | ||
| 39 | }; | 40 | }; |
| 40 | 41 | ||
| 41 | } // namespace Service::Set | 42 | } // namespace Service::Set |
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h index f495b623b..c7e3fb4b1 100644 --- a/src/video_core/engines/shader_bytecode.h +++ b/src/video_core/engines/shader_bytecode.h | |||
| @@ -425,6 +425,7 @@ union Instruction { | |||
| 425 | 425 | ||
| 426 | union { | 426 | union { |
| 427 | BitField<50, 3, u64> component_mask_selector; | 427 | BitField<50, 3, u64> component_mask_selector; |
| 428 | BitField<0, 8, Register> gpr0; | ||
| 428 | BitField<28, 8, Register> gpr28; | 429 | BitField<28, 8, Register> gpr28; |
| 429 | 430 | ||
| 430 | bool HasTwoDestinations() const { | 431 | bool HasTwoDestinations() const { |
| @@ -432,13 +433,16 @@ union Instruction { | |||
| 432 | } | 433 | } |
| 433 | 434 | ||
| 434 | bool IsComponentEnabled(size_t component) const { | 435 | bool IsComponentEnabled(size_t component) const { |
| 435 | static constexpr std::array<size_t, 5> one_dest_mask{0x1, 0x2, 0x4, 0x8, 0x3}; | 436 | static constexpr std::array<std::array<u32, 8>, 4> mask_lut{ |
| 436 | static constexpr std::array<size_t, 5> two_dest_mask{0x7, 0xb, 0xd, 0xe, 0xf}; | 437 | {{}, |
| 437 | const auto& mask{HasTwoDestinations() ? two_dest_mask : one_dest_mask}; | 438 | {0x1, 0x2, 0x4, 0x8, 0x3}, |
| 439 | {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc}, | ||
| 440 | {0x7, 0xb, 0xd, 0xe, 0xf}}}; | ||
| 438 | 441 | ||
| 439 | ASSERT(component_mask_selector < mask.size()); | 442 | size_t index{gpr0.Value() != Register::ZeroIndex ? 1U : 0U}; |
| 443 | index |= gpr28.Value() != Register::ZeroIndex ? 2 : 0; | ||
| 440 | 444 | ||
| 441 | return ((1ull << component) & mask[component_mask_selector]) != 0; | 445 | return ((1ull << component) & mask_lut[index][component_mask_selector]) != 0; |
| 442 | } | 446 | } |
| 443 | } texs; | 447 | } texs; |
| 444 | 448 | ||