From d804a66aa22d2e695ac3df51c5d0a9e7ca05d2f8 Mon Sep 17 00:00:00 2001 From: psucien Date: Fri, 10 May 2024 23:51:24 +0200 Subject: [PATCH] review comments applied --- src/core/libraries/gnmdriver/gnmdriver.cpp | 4 ++-- src/core/libraries/kernel/event_queue.cpp | 4 ++-- src/core/platform.h | 26 ++++++++++------------ src/video_core/amdgpu/liverpool.cpp | 3 +-- src/video_core/amdgpu/pm4_cmds.h | 19 ++++++++++++---- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/core/libraries/gnmdriver/gnmdriver.cpp b/src/core/libraries/gnmdriver/gnmdriver.cpp index ba6142a0..141aff6f 100644 --- a/src/core/libraries/gnmdriver/gnmdriver.cpp +++ b/src/core/libraries/gnmdriver/gnmdriver.cpp @@ -1307,8 +1307,8 @@ static inline s32 PatchFlipRequest(u32* cmdbuf, u32 size, u32 vo_handle, u32 buf auto* write_lock = reinterpret_cast(cmdbuf); write_lock->header = PM4Type3Header{PM4ItOpcode::WriteData, 3}; write_lock->raw = 0x500u; - *reinterpret_cast(&write_lock->dst_addr_lo) = - (label_addr + buf_idx * sizeof(uintptr_t)) & ~0x3ull; + const auto addr = (label_addr + buf_idx * sizeof(label_addr)) & ~0x3ull; + write_lock->Address(addr); write_lock->data[0] = 1; auto* nop = reinterpret_cast(cmdbuf + 5); diff --git a/src/core/libraries/kernel/event_queue.cpp b/src/core/libraries/kernel/event_queue.cpp index d1004f61..023811da 100644 --- a/src/core/libraries/kernel/event_queue.cpp +++ b/src/core/libraries/kernel/event_queue.cpp @@ -21,8 +21,8 @@ int EqueueInternal::addEvent(const EqueueEvent& event) { } int EqueueInternal::removeEvent(u64 id) { - const auto& event_q = std::find_if(m_events.cbegin(), m_events.cend(), - [id](auto& ev) { return ev.event.ident == id; }); + const auto& event_q = + std::ranges::find_if(m_events, [id](auto& ev) { return ev.event.ident == id; }); ASSERT(event_q != m_events.cend()); m_events.erase(event_q); return 0; diff --git a/src/core/platform.h b/src/core/platform.h index 442a6d9e..4d3f4b96 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -38,10 +38,9 @@ struct IrqController { void Register(IrqHandler handler) { ASSERT_MSG(!persistent_handler.has_value(), "Too many persistent handlers"); // Add a slot map if so - { - std::unique_lock lock{m_lock}; - persistent_handler.emplace(handler); - } + + std::unique_lock lock{m_lock}; + persistent_handler.emplace(handler); } void Unregister() { @@ -50,20 +49,19 @@ struct IrqController { } void Signal(InterruptId irq) { + std::unique_lock lock{m_lock}; + LOG_TRACE(Core, "IRQ signaled: {}", magic_enum::enum_name(irq)); - { - std::unique_lock lock{m_lock}; - if (persistent_handler) { - persistent_handler.value()(irq); - } + if (persistent_handler) { + persistent_handler.value()(irq); + } - while (!one_time_subscribers.empty()) { - const auto& h = one_time_subscribers.front(); - h(irq); + while (!one_time_subscribers.empty()) { + const auto& h = one_time_subscribers.front(); + h(irq); - one_time_subscribers.pop(); - } + one_time_subscribers.pop(); } } diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index f41f4bb3..58e36017 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -90,8 +90,7 @@ void Liverpool::ProcessCmdList(u32* cmdbuf, u32 size_in_bytes) { ASSERT(write_data->dst_sel.Value() == 2 || write_data->dst_sel.Value() == 5); const u32 data_size = (header->type3.count.Value() - 2) * 4; if (!write_data->wr_one_addr.Value()) { - std::memcpy(reinterpret_cast(write_data->Address()), write_data->data, - data_size); + std::memcpy(write_data->Address(), write_data->data, data_size); } else { UNREACHABLE(); } diff --git a/src/video_core/amdgpu/pm4_cmds.h b/src/video_core/amdgpu/pm4_cmds.h index 241367b7..e26830cd 100644 --- a/src/video_core/amdgpu/pm4_cmds.h +++ b/src/video_core/amdgpu/pm4_cmds.h @@ -428,12 +428,23 @@ struct PM4CmdWriteData { BitField<30, 1, u32> engine_sel; u32 raw; }; - u32 dst_addr_lo; - u32 dst_addr_hi; + union { + struct { + u32 dst_addr_lo; + u32 dst_addr_hi; + }; + u64 addr64; + }; u32 data[0]; - uintptr_t Address() const { - return (uintptr_t(dst_addr_hi) << 32) | dst_addr_lo; + template + void Address(T addr) { + addr64 = reinterpret_cast(addr); + } + + template + T* Address() const { + return reinterpret_cast(addr64); } };