diff --git a/src/audio_core/common/workbuffer_allocator.h b/src/audio_core/common/workbuffer_allocator.h index fb89f97fea..1f4e05d0d9 100644 --- a/src/audio_core/common/workbuffer_allocator.h +++ b/src/audio_core/common/workbuffer_allocator.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -16,8 +19,9 @@ namespace AudioCore { */ class WorkbufferAllocator { public: - explicit WorkbufferAllocator(std::span buffer_, u64 size_) - : buffer{reinterpret_cast(buffer_.data())}, size{size_} {} + explicit WorkbufferAllocator(std::span buffer_) + : buffer{buffer_} + {} /** * Allocate the given count of T elements, aligned to alignment. @@ -29,36 +33,31 @@ public: template std::span Allocate(u64 count, u64 alignment) { u64 out{0}; - u64 byte_size{count * sizeof(T)}; - + u64 byte_size = count * sizeof(T); if (byte_size > 0) { - auto current{buffer + offset}; + auto current{uintptr_t(buffer.data()) + offset}; auto aligned_buffer{Common::AlignUp(current, alignment)}; - if (aligned_buffer + byte_size <= buffer + size) { + if (aligned_buffer + byte_size <= uintptr_t(buffer.data()) + buffer.size()) { out = aligned_buffer; - offset = byte_size - buffer + aligned_buffer; + offset = byte_size - uintptr_t(buffer.data()) + aligned_buffer; } else { LOG_ERROR( Service_Audio, "Allocated buffer was too small to hold new alloc.\nAllocator size={:08X}, " "offset={:08X}.\nAttempting to allocate {:08X} with alignment={:02X}", - size, offset, byte_size, alignment); + buffer.size(), offset, byte_size, alignment); count = 0; } } - return std::span(reinterpret_cast(out), count); } - /** - * Align the current offset to the given alignment. - * - * @param alignment - The required starting alignment. - */ + /// @brief Align the current offset to the given alignment. + /// @param alignment - The required starting alignment. void Align(u64 alignment) { - auto current{buffer + offset}; + auto current{uintptr_t(buffer.data()) + offset}; auto aligned_buffer{Common::AlignUp(current, alignment)}; - offset = 0 - buffer + aligned_buffer; + offset = 0 - uintptr_t(buffer.data()) + aligned_buffer; } /** @@ -76,7 +75,7 @@ public: * @return The size of the current buffer. */ u64 GetSize() const { - return size; + return buffer.size(); } /** @@ -85,14 +84,11 @@ public: * @return The remaining size left in the buffer. */ u64 GetRemainingSize() const { - return size - offset; + return buffer.size() - offset; } private: - /// The buffer into which we are allocating. - u64 buffer; - /// Size of the buffer we're allocating to. - u64 size; + const std::span buffer; /// Current offset into the buffer, an error will be thrown if it exceeds size. u64 offset{}; };