Merge branch 'main' into audio3

This commit is contained in:
georgemoralis 2026-02-09 23:28:52 +02:00 committed by GitHub
commit c59c5b0781
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 12 deletions

View File

@ -4,6 +4,7 @@
#include <chrono> #include <chrono>
#include <filesystem> #include <filesystem>
#include <mutex>
#include <thread> #include <thread>
#include <fmt/format.h> #include <fmt/format.h>
@ -208,26 +209,41 @@ public:
} }
} }
std::unique_lock entry_loc(_mutex);
if (_last_entry.message == message) {
++_last_entry.counter;
return;
}
if (_last_entry.counter >= 2) {
_last_entry.message += " x" + std::to_string(_last_entry.counter);
}
if (_last_entry.counter >= 1) {
if (Config::getLogType() == "async") {
message_queue.EmplaceWait(_last_entry);
} else {
ForEachBackend([this](auto& backend) { backend.Write(this->_last_entry); });
std::fflush(stdout);
}
}
using std::chrono::duration_cast; using std::chrono::duration_cast;
using std::chrono::microseconds; using std::chrono::microseconds;
using std::chrono::steady_clock; using std::chrono::steady_clock;
const Entry entry = { this->_last_entry = {
.timestamp = duration_cast<microseconds>(steady_clock::now() - time_origin), .timestamp = duration_cast<microseconds>(steady_clock::now() - time_origin),
.log_class = log_class, .log_class = log_class,
.log_level = log_level, .log_level = log_level,
.filename = filename, .filename = filename,
.line_num = line_num, .line_num = line_num,
.function = function, .function = function,
.message = std::move(message), .message = message,
.thread = Common::GetCurrentThreadName(), .thread = Common::GetCurrentThreadName(),
.counter = 1,
}; };
if (Config::getLogType() == "async") {
message_queue.EmplaceWait(entry);
} else {
ForEachBackend([&entry](auto& backend) { backend.Write(entry); });
std::fflush(stdout);
}
} }
private: private:
@ -259,6 +275,22 @@ private:
} }
void StopBackendThread() { void StopBackendThread() {
// log last message
if (_last_entry.counter >= 2) {
_last_entry.message += " x" + std::to_string(_last_entry.counter);
}
if (_last_entry.counter >= 1) {
if (Config::getLogType() == "async") {
message_queue.EmplaceWait(_last_entry);
} else {
ForEachBackend([this](auto& backend) { backend.Write(this->_last_entry); });
std::fflush(stdout);
}
}
this->_last_entry = {};
backend_thread.request_stop(); backend_thread.request_stop();
if (backend_thread.joinable()) { if (backend_thread.joinable()) {
backend_thread.join(); backend_thread.join();
@ -292,6 +324,8 @@ private:
MPSCQueue<Entry> message_queue{}; MPSCQueue<Entry> message_queue{};
std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};
std::jthread backend_thread; std::jthread backend_thread;
Entry _last_entry;
std::mutex _mutex;
}; };
} // namespace } // namespace

View File

@ -22,6 +22,7 @@ struct Entry {
std::string function; std::string function;
std::string message; std::string message;
std::string thread; std::string thread;
u32 counter = 0;
}; };
} // namespace Common::Log } // namespace Common::Log

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project // SPDX-FileCopyrightText: Copyright 2025-2026 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "common/alignment.h" #include "common/alignment.h"
@ -73,7 +73,7 @@ void MemoryManager::SetupMemoryRegions(u64 flexible_size, bool use_extended_mem1
} }
u64 MemoryManager::ClampRangeSize(VAddr virtual_addr, u64 size) { u64 MemoryManager::ClampRangeSize(VAddr virtual_addr, u64 size) {
static constexpr u64 MinSizeToClamp = 3_GB; static constexpr u64 MinSizeToClamp = 1_GB;
// Dont bother with clamping if the size is small so we dont pay a map lookup on every buffer. // Dont bother with clamping if the size is small so we dont pay a map lookup on every buffer.
if (size < MinSizeToClamp) { if (size < MinSizeToClamp) {
return size; return size;
@ -349,7 +349,8 @@ s32 MemoryManager::Free(PAddr phys_addr, u64 size, bool is_checked) {
} }
s32 MemoryManager::PoolCommit(VAddr virtual_addr, u64 size, MemoryProt prot, s32 mtype) { s32 MemoryManager::PoolCommit(VAddr virtual_addr, u64 size, MemoryProt prot, s32 mtype) {
std::scoped_lock lk{mutex, unmap_mutex}; std::scoped_lock lk{unmap_mutex};
std::unique_lock lk2{mutex};
ASSERT_MSG(IsValidMapping(virtual_addr, size), "Attempted to access invalid address {:#x}", ASSERT_MSG(IsValidMapping(virtual_addr, size), "Attempted to access invalid address {:#x}",
virtual_addr); virtual_addr);
@ -434,6 +435,7 @@ s32 MemoryManager::PoolCommit(VAddr virtual_addr, u64 size, MemoryProt prot, s32
// Merge this VMA with similar nearby areas // Merge this VMA with similar nearby areas
MergeAdjacent(vma_map, new_vma_handle); MergeAdjacent(vma_map, new_vma_handle);
lk2.unlock();
if (IsValidGpuMapping(mapped_addr, size)) { if (IsValidGpuMapping(mapped_addr, size)) {
rasterizer->MapMemory(mapped_addr, size); rasterizer->MapMemory(mapped_addr, size);
} }
@ -554,7 +556,7 @@ s32 MemoryManager::MapMemory(void** out_addr, VAddr virtual_addr, u64 size, Memo
} }
// Acquire writer lock. // Acquire writer lock.
std::scoped_lock lk2{mutex}; std::unique_lock lk2{mutex};
// Create VMA representing this mapping. // Create VMA representing this mapping.
auto new_vma_handle = CreateArea(virtual_addr, size, prot, flags, type, name, alignment); auto new_vma_handle = CreateArea(virtual_addr, size, prot, flags, type, name, alignment);
@ -650,6 +652,8 @@ s32 MemoryManager::MapMemory(void** out_addr, VAddr virtual_addr, u64 size, Memo
// TRACK_ALLOC(mapped_addr, size, "VMEM"); // TRACK_ALLOC(mapped_addr, size, "VMEM");
} }
lk2.unlock();
// If this is not a reservation, then map to GPU and address space // If this is not a reservation, then map to GPU and address space
if (IsValidGpuMapping(mapped_addr, size)) { if (IsValidGpuMapping(mapped_addr, size)) {
rasterizer->MapMemory(mapped_addr, size); rasterizer->MapMemory(mapped_addr, size);