diff options
| author | 2023-01-30 12:17:09 -0800 | |
|---|---|---|
| committer | 2023-01-30 12:17:09 -0800 | |
| commit | ed4a88bd93c93ac1aaf5b6bae7d8ede10ff0338a (patch) | |
| tree | 54b6ce04e859b1dee33f4331f392c0d645f4db43 /src/core/hle/kernel | |
| parent | Merge pull request #9701 from german77/common_protocol (diff) | |
| parent | hle_ipc: Use thread_local ReadBuffer (diff) | |
| download | yuzu-ed4a88bd93c93ac1aaf5b6bae7d8ede10ff0338a.tar.gz yuzu-ed4a88bd93c93ac1aaf5b6bae7d8ede10ff0338a.tar.xz yuzu-ed4a88bd93c93ac1aaf5b6bae7d8ede10ff0338a.zip | |
Merge pull request #9508 from ameerj/hle-ipc-buffer-span
hle_ipc: Use std::span to avoid heap allocations/copies when calling ReadBuffer
Diffstat (limited to 'src/core/hle/kernel')
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.cpp | 30 | ||||
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.h | 8 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 738b6d0f1..494151eef 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include "common/common_funcs.h" | 11 | #include "common/common_funcs.h" |
| 12 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 13 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 14 | #include "common/scratch_buffer.h" | ||
| 14 | #include "core/hle/ipc_helpers.h" | 15 | #include "core/hle/ipc_helpers.h" |
| 15 | #include "core/hle/kernel/hle_ipc.h" | 16 | #include "core/hle/kernel/hle_ipc.h" |
| 16 | #include "core/hle/kernel/k_auto_object.h" | 17 | #include "core/hle/kernel/k_auto_object.h" |
| @@ -325,7 +326,7 @@ Result HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_threa | |||
| 325 | return ResultSuccess; | 326 | return ResultSuccess; |
| 326 | } | 327 | } |
| 327 | 328 | ||
| 328 | std::vector<u8> HLERequestContext::ReadBuffer(std::size_t buffer_index) const { | 329 | std::vector<u8> HLERequestContext::ReadBufferCopy(std::size_t buffer_index) const { |
| 329 | const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && | 330 | const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && |
| 330 | BufferDescriptorA()[buffer_index].Size()}; | 331 | BufferDescriptorA()[buffer_index].Size()}; |
| 331 | if (is_buffer_a) { | 332 | if (is_buffer_a) { |
| @@ -345,6 +346,33 @@ std::vector<u8> HLERequestContext::ReadBuffer(std::size_t buffer_index) const { | |||
| 345 | } | 346 | } |
| 346 | } | 347 | } |
| 347 | 348 | ||
| 349 | std::span<const u8> HLERequestContext::ReadBuffer(std::size_t buffer_index) const { | ||
| 350 | static thread_local std::array<Common::ScratchBuffer<u8>, 2> read_buffer_a; | ||
| 351 | static thread_local std::array<Common::ScratchBuffer<u8>, 2> read_buffer_x; | ||
| 352 | |||
| 353 | const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && | ||
| 354 | BufferDescriptorA()[buffer_index].Size()}; | ||
| 355 | if (is_buffer_a) { | ||
| 356 | ASSERT_OR_EXECUTE_MSG( | ||
| 357 | BufferDescriptorA().size() > buffer_index, { return {}; }, | ||
| 358 | "BufferDescriptorA invalid buffer_index {}", buffer_index); | ||
| 359 | auto& read_buffer = read_buffer_a[buffer_index]; | ||
| 360 | read_buffer.resize_destructive(BufferDescriptorA()[buffer_index].Size()); | ||
| 361 | memory.ReadBlock(BufferDescriptorA()[buffer_index].Address(), read_buffer.data(), | ||
| 362 | read_buffer.size()); | ||
| 363 | return read_buffer; | ||
| 364 | } else { | ||
| 365 | ASSERT_OR_EXECUTE_MSG( | ||
| 366 | BufferDescriptorX().size() > buffer_index, { return {}; }, | ||
| 367 | "BufferDescriptorX invalid buffer_index {}", buffer_index); | ||
| 368 | auto& read_buffer = read_buffer_x[buffer_index]; | ||
| 369 | read_buffer.resize_destructive(BufferDescriptorX()[buffer_index].Size()); | ||
| 370 | memory.ReadBlock(BufferDescriptorX()[buffer_index].Address(), read_buffer.data(), | ||
| 371 | read_buffer.size()); | ||
| 372 | return read_buffer; | ||
| 373 | } | ||
| 374 | } | ||
| 375 | |||
| 348 | std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size, | 376 | std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size, |
| 349 | std::size_t buffer_index) const { | 377 | std::size_t buffer_index) const { |
| 350 | if (size == 0) { | 378 | if (size == 0) { |
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index e252b5f4b..5bf4f171b 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <functional> | 7 | #include <functional> |
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | #include <optional> | 9 | #include <optional> |
| 10 | #include <span> | ||
| 10 | #include <string> | 11 | #include <string> |
| 11 | #include <type_traits> | 12 | #include <type_traits> |
| 12 | #include <vector> | 13 | #include <vector> |
| @@ -270,8 +271,11 @@ public: | |||
| 270 | return domain_message_header.has_value(); | 271 | return domain_message_header.has_value(); |
| 271 | } | 272 | } |
| 272 | 273 | ||
| 273 | /// Helper function to read a buffer using the appropriate buffer descriptor | 274 | /// Helper function to get a span of a buffer using the appropriate buffer descriptor |
| 274 | [[nodiscard]] std::vector<u8> ReadBuffer(std::size_t buffer_index = 0) const; | 275 | [[nodiscard]] std::span<const u8> ReadBuffer(std::size_t buffer_index = 0) const; |
| 276 | |||
| 277 | /// Helper function to read a copy of a buffer using the appropriate buffer descriptor | ||
| 278 | [[nodiscard]] std::vector<u8> ReadBufferCopy(std::size_t buffer_index = 0) const; | ||
| 275 | 279 | ||
| 276 | /// Helper function to write a buffer using the appropriate buffer descriptor | 280 | /// Helper function to write a buffer using the appropriate buffer descriptor |
| 277 | std::size_t WriteBuffer(const void* buffer, std::size_t size, | 281 | std::size_t WriteBuffer(const void* buffer, std::size_t size, |