summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/hle/kernel/svc.cpp38
-rw-r--r--src/core/hle/service/set/set.cpp53
-rw-r--r--src/core/hle/service/set/set.h1
-rw-r--r--src/video_core/engines/shader_bytecode.h14
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
ASSERT(thread->condvar_wait_address == condition_variable_addr);
- // If the mutex is not yet acquired, acquire it.
- u32 mutex_val = Memory::Read32(thread->mutex_wait_address);
+ size_t current_core = Core::System::GetInstance().CurrentCoreIndex();
+
+ auto& monitor = Core::System::GetInstance().Monitor();
+
+ // Atomically read the value of the mutex.
+ u32 mutex_val = 0;
+ do {
+ monitor.SetExclusive(current_core, thread->mutex_wait_address);
+
+ // If the mutex is not yet acquired, acquire it.
+ mutex_val = Memory::Read32(thread->mutex_wait_address);
+
+ if (mutex_val != 0) {
+ monitor.ClearExclusive();
+ break;
+ }
+ } while (!monitor.ExclusiveWrite32(current_core, thread->mutex_wait_address,
+ thread->wait_handle));
if (mutex_val == 0) {
// We were able to acquire the mutex, resume this thread.
- Memory::Write32(thread->mutex_wait_address, thread->wait_handle);
ASSERT(thread->status == ThreadStatus::WaitMutex);
thread->ResumeFromWait();
@@ -668,7 +683,19 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
thread->condvar_wait_address = 0;
thread->wait_handle = 0;
} else {
- // Couldn't acquire the mutex, block the thread.
+ // Atomically signal that the mutex now has a waiting thread.
+ do {
+ monitor.SetExclusive(current_core, thread->mutex_wait_address);
+
+ // Ensure that the mutex value is still what we expect.
+ u32 value = Memory::Read32(thread->mutex_wait_address);
+ // TODO(Subv): When this happens, the kernel just clears the exclusive state and
+ // retries the initial read for this thread.
+ ASSERT_MSG(mutex_val == value, "Unhandled synchronization primitive case");
+ } while (!monitor.ExclusiveWrite32(current_core, thread->mutex_wait_address,
+ mutex_val | Mutex::MutexHasWaitersFlag));
+
+ // The mutex is already owned by some other thread, make this thread wait on it.
Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask);
auto owner = g_handle_table.Get<Thread>(owner_handle);
ASSERT(owner);
@@ -676,9 +703,6 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
thread->status = ThreadStatus::WaitMutex;
thread->wakeup_callback = nullptr;
- // Signal that the mutex now has a waiting thread.
- Memory::Write32(thread->mutex_wait_address, mutex_val | Mutex::MutexHasWaitersFlag);
-
owner->AddMutexWaiter(thread);
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 @@
namespace Service::Set {
+constexpr std::array<LanguageCode, 17> available_language_codes = {{
+ LanguageCode::JA,
+ LanguageCode::EN_US,
+ LanguageCode::FR,
+ LanguageCode::DE,
+ LanguageCode::IT,
+ LanguageCode::ES,
+ LanguageCode::ZH_CN,
+ LanguageCode::KO,
+ LanguageCode::NL,
+ LanguageCode::PT,
+ LanguageCode::RU,
+ LanguageCode::ZH_TW,
+ LanguageCode::EN_GB,
+ LanguageCode::FR_CA,
+ LanguageCode::ES_419,
+ LanguageCode::ZH_HANS,
+ LanguageCode::ZH_HANT,
+}};
+
void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) {
- static constexpr std::array<LanguageCode, 17> available_language_codes = {{
- LanguageCode::JA,
- LanguageCode::EN_US,
- LanguageCode::FR,
- LanguageCode::DE,
- LanguageCode::IT,
- LanguageCode::ES,
- LanguageCode::ZH_CN,
- LanguageCode::KO,
- LanguageCode::NL,
- LanguageCode::PT,
- LanguageCode::RU,
- LanguageCode::ZH_TW,
- LanguageCode::EN_GB,
- LanguageCode::FR_CA,
- LanguageCode::ES_419,
- LanguageCode::ZH_HANS,
- LanguageCode::ZH_HANT,
- }};
ctx.WriteBuffer(available_language_codes);
- IPC::ResponseBuilder rb{ctx, 4};
+ IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
- rb.Push(static_cast<u64>(available_language_codes.size()));
+ rb.Push(static_cast<u32>(available_language_codes.size()));
LOG_DEBUG(Service_SET, "called");
}
+void SET::GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx) {
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(RESULT_SUCCESS);
+ rb.Push(static_cast<u32>(available_language_codes.size()));
+}
+
SET::SET() : ServiceFramework("set") {
static const FunctionInfo functions[] = {
{0, nullptr, "GetLanguageCode"},
{1, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes"},
{2, nullptr, "MakeLanguageCode"},
- {3, nullptr, "GetAvailableLanguageCodeCount"},
+ {3, &SET::GetAvailableLanguageCodeCount, "GetAvailableLanguageCodeCount"},
{4, nullptr, "GetRegionCode"},
{5, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes2"},
- {6, nullptr, "GetAvailableLanguageCodeCount2"},
+ {6, &SET::GetAvailableLanguageCodeCount, "GetAvailableLanguageCodeCount2"},
{7, nullptr, "GetKeyCodeMap"},
{8, nullptr, "GetQuestFlag"},
};
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:
private:
void GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx);
+ void GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx);
};
} // 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 {
union {
BitField<50, 3, u64> component_mask_selector;
+ BitField<0, 8, Register> gpr0;
BitField<28, 8, Register> gpr28;
bool HasTwoDestinations() const {
@@ -432,13 +433,16 @@ union Instruction {
}
bool IsComponentEnabled(size_t component) const {
- static constexpr std::array<size_t, 5> one_dest_mask{0x1, 0x2, 0x4, 0x8, 0x3};
- static constexpr std::array<size_t, 5> two_dest_mask{0x7, 0xb, 0xd, 0xe, 0xf};
- const auto& mask{HasTwoDestinations() ? two_dest_mask : one_dest_mask};
+ static constexpr std::array<std::array<u32, 8>, 4> mask_lut{
+ {{},
+ {0x1, 0x2, 0x4, 0x8, 0x3},
+ {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
+ {0x7, 0xb, 0xd, 0xe, 0xf}}};
- ASSERT(component_mask_selector < mask.size());
+ size_t index{gpr0.Value() != Register::ZeroIndex ? 1U : 0U};
+ index |= gpr28.Value() != Register::ZeroIndex ? 2 : 0;
- return ((1ull << component) & mask[component_mask_selector]) != 0;
+ return ((1ull << component) & mask_lut[index][component_mask_selector]) != 0;
}
} texs;