From b0722591c9b8c1aed5b8bfc5e67e7e957b08f209 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Wed, 28 Dec 2022 18:24:57 -0500 Subject: [PATCH] hle_ipc: Use thread_local ReadBuffer --- src/core/hle/kernel/hle_ipc.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index f6654f56c..494151eef 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -11,6 +11,7 @@ #include "common/common_funcs.h" #include "common/common_types.h" #include "common/logging/log.h" +#include "common/scratch_buffer.h" #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_auto_object.h" @@ -346,20 +347,29 @@ std::vector HLERequestContext::ReadBufferCopy(std::size_t buffer_index) cons } std::span HLERequestContext::ReadBuffer(std::size_t buffer_index) const { + static thread_local std::array, 2> read_buffer_a; + static thread_local std::array, 2> read_buffer_x; + const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && BufferDescriptorA()[buffer_index].Size()}; if (is_buffer_a) { ASSERT_OR_EXECUTE_MSG( BufferDescriptorA().size() > buffer_index, { return {}; }, "BufferDescriptorA invalid buffer_index {}", buffer_index); - const u8* const mem_ptr = memory.GetPointer(BufferDescriptorA()[buffer_index].Address()); - return std::span(mem_ptr, BufferDescriptorA()[buffer_index].Size()); + auto& read_buffer = read_buffer_a[buffer_index]; + read_buffer.resize_destructive(BufferDescriptorA()[buffer_index].Size()); + memory.ReadBlock(BufferDescriptorA()[buffer_index].Address(), read_buffer.data(), + read_buffer.size()); + return read_buffer; } else { ASSERT_OR_EXECUTE_MSG( BufferDescriptorX().size() > buffer_index, { return {}; }, "BufferDescriptorX invalid buffer_index {}", buffer_index); - const u8* const mem_ptr = memory.GetPointer(BufferDescriptorX()[buffer_index].Address()); - return std::span(mem_ptr, BufferDescriptorX()[buffer_index].Size()); + auto& read_buffer = read_buffer_x[buffer_index]; + read_buffer.resize_destructive(BufferDescriptorX()[buffer_index].Size()); + memory.ReadBlock(BufferDescriptorX()[buffer_index].Address(), read_buffer.data(), + read_buffer.size()); + return read_buffer; } }