summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/ring_buffer.h2
-rw-r--r--src/common/scratch_buffer.h46
-rw-r--r--src/core/hle/service/audio/audin_u.cpp16
-rw-r--r--src/core/hle/service/audio/audout_u.cpp20
-rw-r--r--src/core/hle/service/audio/audren_u.cpp23
-rw-r--r--src/core/hle/service/audio/hwopus.cpp9
-rw-r--r--src/core/hle/service/nvdrv/nvdrv_interface.cpp25
-rw-r--r--src/core/hle/service/nvdrv/nvdrv_interface.h5
-rw-r--r--src/core/hle/service/nvnflinger/parcel.h24
-rw-r--r--src/video_core/engines/maxwell_dma.cpp7
-rw-r--r--src/video_core/host1x/codecs/codec.cpp2
-rw-r--r--src/video_core/host1x/codecs/h264.cpp14
-rw-r--r--src/video_core/host1x/codecs/h264.h12
-rw-r--r--src/video_core/host1x/codecs/vp8.cpp2
-rw-r--r--src/video_core/host1x/codecs/vp8.h7
-rw-r--r--src/video_core/host1x/codecs/vp9.cpp1
-rw-r--r--src/video_core/host1x/codecs/vp9.h8
-rw-r--r--src/video_core/host1x/codecs/vp9_types.h1
18 files changed, 124 insertions, 100 deletions
diff --git a/src/common/ring_buffer.h b/src/common/ring_buffer.h
index 416680d44..5c961b202 100644
--- a/src/common/ring_buffer.h
+++ b/src/common/ring_buffer.h
@@ -54,7 +54,7 @@ public:
54 return push_count; 54 return push_count;
55 } 55 }
56 56
57 std::size_t Push(const std::span<T> input) { 57 std::size_t Push(std::span<const T> input) {
58 return Push(input.data(), input.size()); 58 return Push(input.data(), input.size());
59 } 59 }
60 60
diff --git a/src/common/scratch_buffer.h b/src/common/scratch_buffer.h
index 6fe907953..d5961b020 100644
--- a/src/common/scratch_buffer.h
+++ b/src/common/scratch_buffer.h
@@ -5,7 +5,6 @@
5 5
6#include <iterator> 6#include <iterator>
7 7
8#include "common/concepts.h"
9#include "common/make_unique_for_overwrite.h" 8#include "common/make_unique_for_overwrite.h"
10 9
11namespace Common { 10namespace Common {
@@ -19,15 +18,22 @@ namespace Common {
19template <typename T> 18template <typename T>
20class ScratchBuffer { 19class ScratchBuffer {
21public: 20public:
22 using iterator = T*;
23 using const_iterator = const T*;
24 using value_type = T;
25 using element_type = T; 21 using element_type = T;
26 using iterator_category = std::contiguous_iterator_tag; 22 using value_type = T;
23 using size_type = size_t;
24 using difference_type = std::ptrdiff_t;
25 using pointer = T*;
26 using const_pointer = const T*;
27 using reference = T&;
28 using const_reference = const T&;
29 using iterator = pointer;
30 using const_iterator = const_pointer;
31 using iterator_category = std::random_access_iterator_tag;
32 using iterator_concept = std::contiguous_iterator_tag;
27 33
28 ScratchBuffer() = default; 34 ScratchBuffer() = default;
29 35
30 explicit ScratchBuffer(size_t initial_capacity) 36 explicit ScratchBuffer(size_type initial_capacity)
31 : last_requested_size{initial_capacity}, buffer_capacity{initial_capacity}, 37 : last_requested_size{initial_capacity}, buffer_capacity{initial_capacity},
32 buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {} 38 buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {}
33 39
@@ -39,7 +45,7 @@ public:
39 45
40 /// This will only grow the buffer's capacity if size is greater than the current capacity. 46 /// This will only grow the buffer's capacity if size is greater than the current capacity.
41 /// The previously held data will remain intact. 47 /// The previously held data will remain intact.
42 void resize(size_t size) { 48 void resize(size_type size) {
43 if (size > buffer_capacity) { 49 if (size > buffer_capacity) {
44 auto new_buffer = Common::make_unique_for_overwrite<T[]>(size); 50 auto new_buffer = Common::make_unique_for_overwrite<T[]>(size);
45 std::move(buffer.get(), buffer.get() + buffer_capacity, new_buffer.get()); 51 std::move(buffer.get(), buffer.get() + buffer_capacity, new_buffer.get());
@@ -51,7 +57,7 @@ public:
51 57
52 /// This will only grow the buffer's capacity if size is greater than the current capacity. 58 /// This will only grow the buffer's capacity if size is greater than the current capacity.
53 /// The previously held data will be destroyed if a reallocation occurs. 59 /// The previously held data will be destroyed if a reallocation occurs.
54 void resize_destructive(size_t size) { 60 void resize_destructive(size_type size) {
55 if (size > buffer_capacity) { 61 if (size > buffer_capacity) {
56 buffer_capacity = size; 62 buffer_capacity = size;
57 buffer = Common::make_unique_for_overwrite<T[]>(buffer_capacity); 63 buffer = Common::make_unique_for_overwrite<T[]>(buffer_capacity);
@@ -59,43 +65,43 @@ public:
59 last_requested_size = size; 65 last_requested_size = size;
60 } 66 }
61 67
62 [[nodiscard]] T* data() noexcept { 68 [[nodiscard]] pointer data() noexcept {
63 return buffer.get(); 69 return buffer.get();
64 } 70 }
65 71
66 [[nodiscard]] const T* data() const noexcept { 72 [[nodiscard]] const_pointer data() const noexcept {
67 return buffer.get(); 73 return buffer.get();
68 } 74 }
69 75
70 [[nodiscard]] T* begin() noexcept { 76 [[nodiscard]] iterator begin() noexcept {
71 return data(); 77 return data();
72 } 78 }
73 79
74 [[nodiscard]] const T* begin() const noexcept { 80 [[nodiscard]] const_iterator begin() const noexcept {
75 return data(); 81 return data();
76 } 82 }
77 83
78 [[nodiscard]] T* end() noexcept { 84 [[nodiscard]] iterator end() noexcept {
79 return data() + last_requested_size; 85 return data() + last_requested_size;
80 } 86 }
81 87
82 [[nodiscard]] const T* end() const noexcept { 88 [[nodiscard]] const_iterator end() const noexcept {
83 return data() + last_requested_size; 89 return data() + last_requested_size;
84 } 90 }
85 91
86 [[nodiscard]] T& operator[](size_t i) { 92 [[nodiscard]] reference operator[](size_type i) {
87 return buffer[i]; 93 return buffer[i];
88 } 94 }
89 95
90 [[nodiscard]] const T& operator[](size_t i) const { 96 [[nodiscard]] const_reference operator[](size_type i) const {
91 return buffer[i]; 97 return buffer[i];
92 } 98 }
93 99
94 [[nodiscard]] size_t size() const noexcept { 100 [[nodiscard]] size_type size() const noexcept {
95 return last_requested_size; 101 return last_requested_size;
96 } 102 }
97 103
98 [[nodiscard]] size_t capacity() const noexcept { 104 [[nodiscard]] size_type capacity() const noexcept {
99 return buffer_capacity; 105 return buffer_capacity;
100 } 106 }
101 107
@@ -106,8 +112,8 @@ public:
106 } 112 }
107 113
108private: 114private:
109 size_t last_requested_size{}; 115 size_type last_requested_size{};
110 size_t buffer_capacity{}; 116 size_type buffer_capacity{};
111 std::unique_ptr<T[]> buffer{}; 117 std::unique_ptr<T[]> buffer{};
112}; 118};
113 119
diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp
index c8d574993..526a39130 100644
--- a/src/core/hle/service/audio/audin_u.cpp
+++ b/src/core/hle/service/audio/audin_u.cpp
@@ -5,7 +5,7 @@
5#include "audio_core/renderer/audio_device.h" 5#include "audio_core/renderer/audio_device.h"
6#include "common/common_funcs.h" 6#include "common/common_funcs.h"
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "common/settings.h" 8#include "common/scratch_buffer.h"
9#include "common/string_util.h" 9#include "common/string_util.h"
10#include "core/core.h" 10#include "core/core.h"
11#include "core/hle/kernel/k_event.h" 11#include "core/hle/kernel/k_event.h"
@@ -124,12 +124,15 @@ private:
124 124
125 void GetReleasedAudioInBuffer(HLERequestContext& ctx) { 125 void GetReleasedAudioInBuffer(HLERequestContext& ctx) {
126 const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>(); 126 const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>();
127 tmp_buffer.resize_destructive(write_buffer_size); 127 released_buffer.resize_destructive(write_buffer_size);
128 tmp_buffer[0] = 0; 128 released_buffer[0] = 0;
129 129
130 const auto count = impl->GetReleasedBuffers(tmp_buffer); 130 const auto count = impl->GetReleasedBuffers(released_buffer);
131 131
132 ctx.WriteBuffer(tmp_buffer); 132 LOG_TRACE(Service_Audio, "called. Session {} released {} buffers",
133 impl->GetSystem().GetSessionId(), count);
134
135 ctx.WriteBuffer(released_buffer);
133 136
134 IPC::ResponseBuilder rb{ctx, 3}; 137 IPC::ResponseBuilder rb{ctx, 3};
135 rb.Push(ResultSuccess); 138 rb.Push(ResultSuccess);
@@ -155,7 +158,6 @@ private:
155 LOG_DEBUG(Service_Audio, "called. Buffer count={}", buffer_count); 158 LOG_DEBUG(Service_Audio, "called. Buffer count={}", buffer_count);
156 159
157 IPC::ResponseBuilder rb{ctx, 3}; 160 IPC::ResponseBuilder rb{ctx, 3};
158
159 rb.Push(ResultSuccess); 161 rb.Push(ResultSuccess);
160 rb.Push(buffer_count); 162 rb.Push(buffer_count);
161 } 163 }
@@ -195,7 +197,7 @@ private:
195 KernelHelpers::ServiceContext service_context; 197 KernelHelpers::ServiceContext service_context;
196 Kernel::KEvent* event; 198 Kernel::KEvent* event;
197 std::shared_ptr<AudioCore::AudioIn::In> impl; 199 std::shared_ptr<AudioCore::AudioIn::In> impl;
198 Common::ScratchBuffer<u64> tmp_buffer; 200 Common::ScratchBuffer<u64> released_buffer;
199}; 201};
200 202
201AudInU::AudInU(Core::System& system_) 203AudInU::AudInU(Core::System& system_)
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp
index 032c8c11f..23f84a29f 100644
--- a/src/core/hle/service/audio/audout_u.cpp
+++ b/src/core/hle/service/audio/audout_u.cpp
@@ -9,6 +9,7 @@
9#include "audio_core/renderer/audio_device.h" 9#include "audio_core/renderer/audio_device.h"
10#include "common/common_funcs.h" 10#include "common/common_funcs.h"
11#include "common/logging/log.h" 11#include "common/logging/log.h"
12#include "common/scratch_buffer.h"
12#include "common/string_util.h" 13#include "common/string_util.h"
13#include "common/swap.h" 14#include "common/swap.h"
14#include "core/core.h" 15#include "core/core.h"
@@ -102,8 +103,8 @@ private:
102 AudioOutBuffer buffer{}; 103 AudioOutBuffer buffer{};
103 std::memcpy(&buffer, in_buffer.data(), sizeof(AudioOutBuffer)); 104 std::memcpy(&buffer, in_buffer.data(), sizeof(AudioOutBuffer));
104 105
105 [[maybe_unused]] auto sessionid{impl->GetSystem().GetSessionId()}; 106 LOG_TRACE(Service_Audio, "called. Session {} Appending buffer {:08X}",
106 LOG_TRACE(Service_Audio, "called. Session {} Appending buffer {:08X}", sessionid, tag); 107 impl->GetSystem().GetSessionId(), tag);
107 108
108 auto result = impl->AppendBuffer(buffer, tag); 109 auto result = impl->AppendBuffer(buffer, tag);
109 110
@@ -123,12 +124,15 @@ private:
123 124
124 void GetReleasedAudioOutBuffers(HLERequestContext& ctx) { 125 void GetReleasedAudioOutBuffers(HLERequestContext& ctx) {
125 const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>(); 126 const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>();
126 tmp_buffer.resize_destructive(write_buffer_size); 127 released_buffer.resize_destructive(write_buffer_size);
127 tmp_buffer[0] = 0; 128 released_buffer[0] = 0;
128 129
129 const auto count = impl->GetReleasedBuffers(tmp_buffer); 130 const auto count = impl->GetReleasedBuffers(released_buffer);
130 131
131 ctx.WriteBuffer(tmp_buffer); 132 ctx.WriteBuffer(released_buffer);
133
134 LOG_TRACE(Service_Audio, "called. Session {} released {} buffers",
135 impl->GetSystem().GetSessionId(), count);
132 136
133 IPC::ResponseBuilder rb{ctx, 3}; 137 IPC::ResponseBuilder rb{ctx, 3};
134 rb.Push(ResultSuccess); 138 rb.Push(ResultSuccess);
@@ -154,7 +158,6 @@ private:
154 LOG_DEBUG(Service_Audio, "called. Buffer count={}", buffer_count); 158 LOG_DEBUG(Service_Audio, "called. Buffer count={}", buffer_count);
155 159
156 IPC::ResponseBuilder rb{ctx, 3}; 160 IPC::ResponseBuilder rb{ctx, 3};
157
158 rb.Push(ResultSuccess); 161 rb.Push(ResultSuccess);
159 rb.Push(buffer_count); 162 rb.Push(buffer_count);
160 } 163 }
@@ -165,7 +168,6 @@ private:
165 LOG_DEBUG(Service_Audio, "called. Played samples={}", samples_played); 168 LOG_DEBUG(Service_Audio, "called. Played samples={}", samples_played);
166 169
167 IPC::ResponseBuilder rb{ctx, 4}; 170 IPC::ResponseBuilder rb{ctx, 4};
168
169 rb.Push(ResultSuccess); 171 rb.Push(ResultSuccess);
170 rb.Push(samples_played); 172 rb.Push(samples_played);
171 } 173 }
@@ -205,7 +207,7 @@ private:
205 KernelHelpers::ServiceContext service_context; 207 KernelHelpers::ServiceContext service_context;
206 Kernel::KEvent* event; 208 Kernel::KEvent* event;
207 std::shared_ptr<AudioCore::AudioOut::Out> impl; 209 std::shared_ptr<AudioCore::AudioOut::Out> impl;
208 Common::ScratchBuffer<u64> tmp_buffer; 210 Common::ScratchBuffer<u64> released_buffer;
209}; 211};
210 212
211AudOutU::AudOutU(Core::System& system_) 213AudOutU::AudOutU(Core::System& system_)
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp
index 12845c23a..003870176 100644
--- a/src/core/hle/service/audio/audren_u.cpp
+++ b/src/core/hle/service/audio/audren_u.cpp
@@ -15,6 +15,7 @@
15#include "common/common_funcs.h" 15#include "common/common_funcs.h"
16#include "common/logging/log.h" 16#include "common/logging/log.h"
17#include "common/polyfill_ranges.h" 17#include "common/polyfill_ranges.h"
18#include "common/scratch_buffer.h"
18#include "common/string_util.h" 19#include "common/string_util.h"
19#include "core/core.h" 20#include "core/core.h"
20#include "core/hle/kernel/k_event.h" 21#include "core/hle/kernel/k_event.h"
@@ -119,23 +120,23 @@ private:
119 auto is_buffer_b{ctx.BufferDescriptorB()[0].Size() != 0}; 120 auto is_buffer_b{ctx.BufferDescriptorB()[0].Size() != 0};
120 if (is_buffer_b) { 121 if (is_buffer_b) {
121 const auto buffersB{ctx.BufferDescriptorB()}; 122 const auto buffersB{ctx.BufferDescriptorB()};
122 tmp_output.resize_destructive(buffersB[0].Size()); 123 output_buffer.resize_destructive(buffersB[0].Size());
123 tmp_performance.resize_destructive(buffersB[1].Size()); 124 performance_buffer.resize_destructive(buffersB[1].Size());
124 } else { 125 } else {
125 const auto buffersC{ctx.BufferDescriptorC()}; 126 const auto buffersC{ctx.BufferDescriptorC()};
126 tmp_output.resize_destructive(buffersC[0].Size()); 127 output_buffer.resize_destructive(buffersC[0].Size());
127 tmp_performance.resize_destructive(buffersC[1].Size()); 128 performance_buffer.resize_destructive(buffersC[1].Size());
128 } 129 }
129 130
130 auto result = impl->RequestUpdate(input, tmp_performance, tmp_output); 131 auto result = impl->RequestUpdate(input, performance_buffer, output_buffer);
131 132
132 if (result.IsSuccess()) { 133 if (result.IsSuccess()) {
133 if (is_buffer_b) { 134 if (is_buffer_b) {
134 ctx.WriteBufferB(tmp_output.data(), tmp_output.size(), 0); 135 ctx.WriteBufferB(output_buffer.data(), output_buffer.size(), 0);
135 ctx.WriteBufferB(tmp_performance.data(), tmp_performance.size(), 1); 136 ctx.WriteBufferB(performance_buffer.data(), performance_buffer.size(), 1);
136 } else { 137 } else {
137 ctx.WriteBufferC(tmp_output.data(), tmp_output.size(), 0); 138 ctx.WriteBufferC(output_buffer.data(), output_buffer.size(), 0);
138 ctx.WriteBufferC(tmp_performance.data(), tmp_performance.size(), 1); 139 ctx.WriteBufferC(performance_buffer.data(), performance_buffer.size(), 1);
139 } 140 }
140 } else { 141 } else {
141 LOG_ERROR(Service_Audio, "RequestUpdate failed error 0x{:02X}!", result.description); 142 LOG_ERROR(Service_Audio, "RequestUpdate failed error 0x{:02X}!", result.description);
@@ -233,8 +234,8 @@ private:
233 Kernel::KEvent* rendered_event; 234 Kernel::KEvent* rendered_event;
234 Manager& manager; 235 Manager& manager;
235 std::unique_ptr<Renderer> impl; 236 std::unique_ptr<Renderer> impl;
236 Common::ScratchBuffer<u8> tmp_output; 237 Common::ScratchBuffer<u8> output_buffer;
237 Common::ScratchBuffer<u8> tmp_performance; 238 Common::ScratchBuffer<u8> performance_buffer;
238}; 239};
239 240
240class IAudioDevice final : public ServiceFramework<IAudioDevice> { 241class IAudioDevice final : public ServiceFramework<IAudioDevice> {
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp
index c835f6cb7..fa77007f3 100644
--- a/src/core/hle/service/audio/hwopus.cpp
+++ b/src/core/hle/service/audio/hwopus.cpp
@@ -11,6 +11,7 @@
11 11
12#include "common/assert.h" 12#include "common/assert.h"
13#include "common/logging/log.h" 13#include "common/logging/log.h"
14#include "common/scratch_buffer.h"
14#include "core/hle/service/audio/hwopus.h" 15#include "core/hle/service/audio/hwopus.h"
15#include "core/hle/service/ipc_helpers.h" 16#include "core/hle/service/ipc_helpers.h"
16 17
@@ -68,13 +69,13 @@ private:
68 ExtraBehavior extra_behavior) { 69 ExtraBehavior extra_behavior) {
69 u32 consumed = 0; 70 u32 consumed = 0;
70 u32 sample_count = 0; 71 u32 sample_count = 0;
71 tmp_samples.resize_destructive(ctx.GetWriteBufferNumElements<opus_int16>()); 72 samples.resize_destructive(ctx.GetWriteBufferNumElements<opus_int16>());
72 73
73 if (extra_behavior == ExtraBehavior::ResetContext) { 74 if (extra_behavior == ExtraBehavior::ResetContext) {
74 ResetDecoderContext(); 75 ResetDecoderContext();
75 } 76 }
76 77
77 if (!DecodeOpusData(consumed, sample_count, ctx.ReadBuffer(), tmp_samples, performance)) { 78 if (!DecodeOpusData(consumed, sample_count, ctx.ReadBuffer(), samples, performance)) {
78 LOG_ERROR(Audio, "Failed to decode opus data"); 79 LOG_ERROR(Audio, "Failed to decode opus data");
79 IPC::ResponseBuilder rb{ctx, 2}; 80 IPC::ResponseBuilder rb{ctx, 2};
80 // TODO(ogniK): Use correct error code 81 // TODO(ogniK): Use correct error code
@@ -90,7 +91,7 @@ private:
90 if (performance) { 91 if (performance) {
91 rb.Push<u64>(*performance); 92 rb.Push<u64>(*performance);
92 } 93 }
93 ctx.WriteBuffer(tmp_samples); 94 ctx.WriteBuffer(samples);
94 } 95 }
95 96
96 bool DecodeOpusData(u32& consumed, u32& sample_count, std::span<const u8> input, 97 bool DecodeOpusData(u32& consumed, u32& sample_count, std::span<const u8> input,
@@ -154,7 +155,7 @@ private:
154 OpusDecoderPtr decoder; 155 OpusDecoderPtr decoder;
155 u32 sample_rate; 156 u32 sample_rate;
156 u32 channel_count; 157 u32 channel_count;
157 Common::ScratchBuffer<opus_int16> tmp_samples; 158 Common::ScratchBuffer<opus_int16> samples;
158}; 159};
159 160
160class IHardwareOpusDecoderManager final : public ServiceFramework<IHardwareOpusDecoderManager> { 161class IHardwareOpusDecoderManager final : public ServiceFramework<IHardwareOpusDecoderManager> {
diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.cpp b/src/core/hle/service/nvdrv/nvdrv_interface.cpp
index 348207e25..c8a880e84 100644
--- a/src/core/hle/service/nvdrv/nvdrv_interface.cpp
+++ b/src/core/hle/service/nvdrv/nvdrv_interface.cpp
@@ -2,7 +2,6 @@
2// SPDX-FileCopyrightText: 2021 Skyline Team and Contributors 2// SPDX-FileCopyrightText: 2021 Skyline Team and Contributors
3// SPDX-License-Identifier: GPL-3.0-or-later 3// SPDX-License-Identifier: GPL-3.0-or-later
4 4
5#include <cinttypes>
6#include "common/logging/log.h" 5#include "common/logging/log.h"
7#include "core/core.h" 6#include "core/core.h"
8#include "core/hle/kernel/k_event.h" 7#include "core/hle/kernel/k_event.h"
@@ -63,12 +62,12 @@ void NVDRV::Ioctl1(HLERequestContext& ctx) {
63 } 62 }
64 63
65 // Check device 64 // Check device
66 tmp_output.resize_destructive(ctx.GetWriteBufferSize(0)); 65 output_buffer.resize_destructive(ctx.GetWriteBufferSize(0));
67 const auto input_buffer = ctx.ReadBuffer(0); 66 const auto input_buffer = ctx.ReadBuffer(0);
68 67
69 const auto nv_result = nvdrv->Ioctl1(fd, command, input_buffer, tmp_output); 68 const auto nv_result = nvdrv->Ioctl1(fd, command, input_buffer, output_buffer);
70 if (command.is_out != 0) { 69 if (command.is_out != 0) {
71 ctx.WriteBuffer(tmp_output); 70 ctx.WriteBuffer(output_buffer);
72 } 71 }
73 72
74 IPC::ResponseBuilder rb{ctx, 3}; 73 IPC::ResponseBuilder rb{ctx, 3};
@@ -90,12 +89,12 @@ void NVDRV::Ioctl2(HLERequestContext& ctx) {
90 89
91 const auto input_buffer = ctx.ReadBuffer(0); 90 const auto input_buffer = ctx.ReadBuffer(0);
92 const auto input_inlined_buffer = ctx.ReadBuffer(1); 91 const auto input_inlined_buffer = ctx.ReadBuffer(1);
93 tmp_output.resize_destructive(ctx.GetWriteBufferSize(0)); 92 output_buffer.resize_destructive(ctx.GetWriteBufferSize(0));
94 93
95 const auto nv_result = 94 const auto nv_result =
96 nvdrv->Ioctl2(fd, command, input_buffer, input_inlined_buffer, tmp_output); 95 nvdrv->Ioctl2(fd, command, input_buffer, input_inlined_buffer, output_buffer);
97 if (command.is_out != 0) { 96 if (command.is_out != 0) {
98 ctx.WriteBuffer(tmp_output); 97 ctx.WriteBuffer(output_buffer);
99 } 98 }
100 99
101 IPC::ResponseBuilder rb{ctx, 3}; 100 IPC::ResponseBuilder rb{ctx, 3};
@@ -116,12 +115,14 @@ void NVDRV::Ioctl3(HLERequestContext& ctx) {
116 } 115 }
117 116
118 const auto input_buffer = ctx.ReadBuffer(0); 117 const auto input_buffer = ctx.ReadBuffer(0);
119 tmp_output.resize_destructive(ctx.GetWriteBufferSize(0)); 118 output_buffer.resize_destructive(ctx.GetWriteBufferSize(0));
120 tmp_output_inline.resize_destructive(ctx.GetWriteBufferSize(1)); 119 inline_output_buffer.resize_destructive(ctx.GetWriteBufferSize(1));
121 const auto nv_result = nvdrv->Ioctl3(fd, command, input_buffer, tmp_output, tmp_output_inline); 120
121 const auto nv_result =
122 nvdrv->Ioctl3(fd, command, input_buffer, output_buffer, inline_output_buffer);
122 if (command.is_out != 0) { 123 if (command.is_out != 0) {
123 ctx.WriteBuffer(tmp_output, 0); 124 ctx.WriteBuffer(output_buffer, 0);
124 ctx.WriteBuffer(tmp_output_inline, 1); 125 ctx.WriteBuffer(inline_output_buffer, 1);
125 } 126 }
126 127
127 IPC::ResponseBuilder rb{ctx, 3}; 128 IPC::ResponseBuilder rb{ctx, 3};
diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.h b/src/core/hle/service/nvdrv/nvdrv_interface.h
index 4b593ff90..6e98115dc 100644
--- a/src/core/hle/service/nvdrv/nvdrv_interface.h
+++ b/src/core/hle/service/nvdrv/nvdrv_interface.h
@@ -4,6 +4,7 @@
4#pragma once 4#pragma once
5 5
6#include <memory> 6#include <memory>
7
7#include "common/scratch_buffer.h" 8#include "common/scratch_buffer.h"
8#include "core/hle/service/nvdrv/nvdrv.h" 9#include "core/hle/service/nvdrv/nvdrv.h"
9#include "core/hle/service/service.h" 10#include "core/hle/service/service.h"
@@ -34,8 +35,8 @@ private:
34 35
35 u64 pid{}; 36 u64 pid{};
36 bool is_initialized{}; 37 bool is_initialized{};
37 Common::ScratchBuffer<u8> tmp_output; 38 Common::ScratchBuffer<u8> output_buffer;
38 Common::ScratchBuffer<u8> tmp_output_inline; 39 Common::ScratchBuffer<u8> inline_output_buffer;
39}; 40};
40 41
41} // namespace Service::Nvidia 42} // namespace Service::Nvidia
diff --git a/src/core/hle/service/nvnflinger/parcel.h b/src/core/hle/service/nvnflinger/parcel.h
index 23ba315a0..e2c9bbd50 100644
--- a/src/core/hle/service/nvnflinger/parcel.h
+++ b/src/core/hle/service/nvnflinger/parcel.h
@@ -6,6 +6,7 @@
6#include <memory> 6#include <memory>
7#include <span> 7#include <span>
8#include <vector> 8#include <vector>
9
9#include <boost/container/small_vector.hpp> 10#include <boost/container/small_vector.hpp>
10 11
11#include "common/alignment.h" 12#include "common/alignment.h"
@@ -148,9 +149,9 @@ public:
148 this->WriteImpl(0U, m_object_buffer); 149 this->WriteImpl(0U, m_object_buffer);
149 } 150 }
150 151
151 std::vector<u8> Serialize() const { 152 std::span<u8> Serialize() {
152 std::vector<u8> output_buffer(sizeof(ParcelHeader) + m_data_buffer.size() + 153 m_output_buffer.resize(sizeof(ParcelHeader) + m_data_buffer.size() +
153 m_object_buffer.size()); 154 m_object_buffer.size());
154 155
155 ParcelHeader header{}; 156 ParcelHeader header{};
156 header.data_size = static_cast<u32>(m_data_buffer.size()); 157 header.data_size = static_cast<u32>(m_data_buffer.size());
@@ -158,17 +159,17 @@ public:
158 header.objects_size = static_cast<u32>(m_object_buffer.size()); 159 header.objects_size = static_cast<u32>(m_object_buffer.size());
159 header.objects_offset = header.data_offset + header.data_size; 160 header.objects_offset = header.data_offset + header.data_size;
160 161
161 std::memcpy(output_buffer.data(), &header, sizeof(header)); 162 std::memcpy(m_output_buffer.data(), &header, sizeof(ParcelHeader));
162 std::ranges::copy(m_data_buffer, output_buffer.data() + header.data_offset); 163 std::ranges::copy(m_data_buffer, m_output_buffer.data() + header.data_offset);
163 std::ranges::copy(m_object_buffer, output_buffer.data() + header.objects_offset); 164 std::ranges::copy(m_object_buffer, m_output_buffer.data() + header.objects_offset);
164 165
165 return output_buffer; 166 return m_output_buffer;
166 } 167 }
167 168
168private: 169private:
169 template <typename T> 170 template <typename T, size_t BufferSize>
170 requires(std::is_trivially_copyable_v<T>) 171 requires(std::is_trivially_copyable_v<T>)
171 void WriteImpl(const T& val, boost::container::small_vector<u8, 0x200>& buffer) { 172 void WriteImpl(const T& val, boost::container::small_vector<u8, BufferSize>& buffer) {
172 const size_t aligned_size = Common::AlignUp(sizeof(T), 4); 173 const size_t aligned_size = Common::AlignUp(sizeof(T), 4);
173 const size_t old_size = buffer.size(); 174 const size_t old_size = buffer.size();
174 buffer.resize(old_size + aligned_size); 175 buffer.resize(old_size + aligned_size);
@@ -177,8 +178,9 @@ private:
177 } 178 }
178 179
179private: 180private:
180 boost::container::small_vector<u8, 0x200> m_data_buffer; 181 boost::container::small_vector<u8, 0x1B0> m_data_buffer;
181 boost::container::small_vector<u8, 0x200> m_object_buffer; 182 boost::container::small_vector<u8, 0x40> m_object_buffer;
183 boost::container::small_vector<u8, 0x200> m_output_buffer;
182}; 184};
183 185
184} // namespace Service::android 186} // namespace Service::android
diff --git a/src/video_core/engines/maxwell_dma.cpp b/src/video_core/engines/maxwell_dma.cpp
index a290d6ea7..f8598fd98 100644
--- a/src/video_core/engines/maxwell_dma.cpp
+++ b/src/video_core/engines/maxwell_dma.cpp
@@ -174,8 +174,7 @@ void MaxwellDMA::CopyBlockLinearToPitch() {
174 src_operand.address = regs.offset_in; 174 src_operand.address = regs.offset_in;
175 175
176 DMA::BufferOperand dst_operand; 176 DMA::BufferOperand dst_operand;
177 u32 abs_pitch_out = std::abs(static_cast<s32>(regs.pitch_out)); 177 dst_operand.pitch = static_cast<u32>(std::abs(regs.pitch_out));
178 dst_operand.pitch = abs_pitch_out;
179 dst_operand.width = regs.line_length_in; 178 dst_operand.width = regs.line_length_in;
180 dst_operand.height = regs.line_count; 179 dst_operand.height = regs.line_count;
181 dst_operand.address = regs.offset_out; 180 dst_operand.address = regs.offset_out;
@@ -222,7 +221,7 @@ void MaxwellDMA::CopyBlockLinearToPitch() {
222 const size_t src_size = 221 const size_t src_size =
223 CalculateSize(true, bytes_per_pixel, width, height, depth, block_height, block_depth); 222 CalculateSize(true, bytes_per_pixel, width, height, depth, block_height, block_depth);
224 223
225 const size_t dst_size = static_cast<size_t>(abs_pitch_out) * regs.line_count; 224 const size_t dst_size = dst_operand.pitch * regs.line_count;
226 read_buffer.resize_destructive(src_size); 225 read_buffer.resize_destructive(src_size);
227 write_buffer.resize_destructive(dst_size); 226 write_buffer.resize_destructive(dst_size);
228 227
@@ -231,7 +230,7 @@ void MaxwellDMA::CopyBlockLinearToPitch() {
231 230
232 UnswizzleSubrect(write_buffer, read_buffer, bytes_per_pixel, width, height, depth, x_offset, 231 UnswizzleSubrect(write_buffer, read_buffer, bytes_per_pixel, width, height, depth, x_offset,
233 src_params.origin.y, x_elements, regs.line_count, block_height, block_depth, 232 src_params.origin.y, x_elements, regs.line_count, block_height, block_depth,
234 abs_pitch_out); 233 dst_operand.pitch);
235 234
236 memory_manager.WriteBlockCached(regs.offset_out, write_buffer.data(), dst_size); 235 memory_manager.WriteBlockCached(regs.offset_out, write_buffer.data(), dst_size);
237} 236}
diff --git a/src/video_core/host1x/codecs/codec.cpp b/src/video_core/host1x/codecs/codec.cpp
index cd6a3a9b8..da07a556f 100644
--- a/src/video_core/host1x/codecs/codec.cpp
+++ b/src/video_core/host1x/codecs/codec.cpp
@@ -290,7 +290,7 @@ void Codec::Decode() {
290 return vp9_decoder->GetFrameBytes(); 290 return vp9_decoder->GetFrameBytes();
291 default: 291 default:
292 ASSERT(false); 292 ASSERT(false);
293 return std::vector<u8>{}; 293 return std::span<const u8>{};
294 } 294 }
295 }(); 295 }();
296 AVPacketPtr packet{av_packet_alloc(), AVPacketDeleter}; 296 AVPacketPtr packet{av_packet_alloc(), AVPacketDeleter};
diff --git a/src/video_core/host1x/codecs/h264.cpp b/src/video_core/host1x/codecs/h264.cpp
index ce827eb6c..862904e39 100644
--- a/src/video_core/host1x/codecs/h264.cpp
+++ b/src/video_core/host1x/codecs/h264.cpp
@@ -29,15 +29,15 @@ H264::H264(Host1x::Host1x& host1x_) : host1x{host1x_} {}
29 29
30H264::~H264() = default; 30H264::~H264() = default;
31 31
32const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state, 32std::span<const u8> H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state,
33 bool is_first_frame) { 33 bool is_first_frame) {
34 H264DecoderContext context; 34 H264DecoderContext context;
35 host1x.MemoryManager().ReadBlock(state.picture_info_offset, &context, 35 host1x.MemoryManager().ReadBlock(state.picture_info_offset, &context,
36 sizeof(H264DecoderContext)); 36 sizeof(H264DecoderContext));
37 37
38 const s64 frame_number = context.h264_parameter_set.frame_number.Value(); 38 const s64 frame_number = context.h264_parameter_set.frame_number.Value();
39 if (!is_first_frame && frame_number != 0) { 39 if (!is_first_frame && frame_number != 0) {
40 frame.resize(context.stream_len); 40 frame.resize_destructive(context.stream_len);
41 host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.data(), frame.size()); 41 host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.data(), frame.size());
42 return frame; 42 return frame;
43 } 43 }
@@ -135,14 +135,14 @@ const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegist
135 for (s32 index = 0; index < 6; index++) { 135 for (s32 index = 0; index < 6; index++) {
136 writer.WriteBit(true); 136 writer.WriteBit(true);
137 std::span<const u8> matrix{context.weight_scale}; 137 std::span<const u8> matrix{context.weight_scale};
138 writer.WriteScalingList(matrix, index * 16, 16); 138 writer.WriteScalingList(scan, matrix, index * 16, 16);
139 } 139 }
140 140
141 if (context.h264_parameter_set.transform_8x8_mode_flag) { 141 if (context.h264_parameter_set.transform_8x8_mode_flag) {
142 for (s32 index = 0; index < 2; index++) { 142 for (s32 index = 0; index < 2; index++) {
143 writer.WriteBit(true); 143 writer.WriteBit(true);
144 std::span<const u8> matrix{context.weight_scale_8x8}; 144 std::span<const u8> matrix{context.weight_scale_8x8};
145 writer.WriteScalingList(matrix, index * 64, 64); 145 writer.WriteScalingList(scan, matrix, index * 64, 64);
146 } 146 }
147 } 147 }
148 148
@@ -188,8 +188,8 @@ void H264BitWriter::WriteBit(bool state) {
188 WriteBits(state ? 1 : 0, 1); 188 WriteBits(state ? 1 : 0, 1);
189} 189}
190 190
191void H264BitWriter::WriteScalingList(std::span<const u8> list, s32 start, s32 count) { 191void H264BitWriter::WriteScalingList(Common::ScratchBuffer<u8>& scan, std::span<const u8> list,
192 static Common::ScratchBuffer<u8> scan{}; 192 s32 start, s32 count) {
193 scan.resize_destructive(count); 193 scan.resize_destructive(count);
194 if (count == 16) { 194 if (count == 16) {
195 std::memcpy(scan.data(), zig_zag_scan.data(), scan.size()); 195 std::memcpy(scan.data(), zig_zag_scan.data(), scan.size());
diff --git a/src/video_core/host1x/codecs/h264.h b/src/video_core/host1x/codecs/h264.h
index 5cc86454e..d6b556322 100644
--- a/src/video_core/host1x/codecs/h264.h
+++ b/src/video_core/host1x/codecs/h264.h
@@ -5,9 +5,11 @@
5 5
6#include <span> 6#include <span>
7#include <vector> 7#include <vector>
8
8#include "common/bit_field.h" 9#include "common/bit_field.h"
9#include "common/common_funcs.h" 10#include "common/common_funcs.h"
10#include "common/common_types.h" 11#include "common/common_types.h"
12#include "common/scratch_buffer.h"
11#include "video_core/host1x/nvdec_common.h" 13#include "video_core/host1x/nvdec_common.h"
12 14
13namespace Tegra { 15namespace Tegra {
@@ -37,7 +39,8 @@ public:
37 39
38 /// Based on section 7.3.2.1.1.1 and Table 7-4 in the H.264 specification 40 /// Based on section 7.3.2.1.1.1 and Table 7-4 in the H.264 specification
39 /// Writes the scaling matrices of the sream 41 /// Writes the scaling matrices of the sream
40 void WriteScalingList(std::span<const u8> list, s32 start, s32 count); 42 void WriteScalingList(Common::ScratchBuffer<u8>& scan, std::span<const u8> list, s32 start,
43 s32 count);
41 44
42 /// Return the bitstream as a vector. 45 /// Return the bitstream as a vector.
43 [[nodiscard]] std::vector<u8>& GetByteArray(); 46 [[nodiscard]] std::vector<u8>& GetByteArray();
@@ -63,11 +66,12 @@ public:
63 ~H264(); 66 ~H264();
64 67
65 /// Compose the H264 frame for FFmpeg decoding 68 /// Compose the H264 frame for FFmpeg decoding
66 [[nodiscard]] const std::vector<u8>& ComposeFrame( 69 [[nodiscard]] std::span<const u8> ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state,
67 const Host1x::NvdecCommon::NvdecRegisters& state, bool is_first_frame = false); 70 bool is_first_frame = false);
68 71
69private: 72private:
70 std::vector<u8> frame; 73 Common::ScratchBuffer<u8> frame;
74 Common::ScratchBuffer<u8> scan;
71 Host1x::Host1x& host1x; 75 Host1x::Host1x& host1x;
72 76
73 struct H264ParameterSet { 77 struct H264ParameterSet {
diff --git a/src/video_core/host1x/codecs/vp8.cpp b/src/video_core/host1x/codecs/vp8.cpp
index 28fb12cb8..ee6392ff9 100644
--- a/src/video_core/host1x/codecs/vp8.cpp
+++ b/src/video_core/host1x/codecs/vp8.cpp
@@ -12,7 +12,7 @@ VP8::VP8(Host1x::Host1x& host1x_) : host1x{host1x_} {}
12 12
13VP8::~VP8() = default; 13VP8::~VP8() = default;
14 14
15const std::vector<u8>& VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) { 15std::span<const u8> VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) {
16 VP8PictureInfo info; 16 VP8PictureInfo info;
17 host1x.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo)); 17 host1x.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo));
18 18
diff --git a/src/video_core/host1x/codecs/vp8.h b/src/video_core/host1x/codecs/vp8.h
index 5bf07ecab..7926b73f3 100644
--- a/src/video_core/host1x/codecs/vp8.h
+++ b/src/video_core/host1x/codecs/vp8.h
@@ -4,10 +4,11 @@
4#pragma once 4#pragma once
5 5
6#include <array> 6#include <array>
7#include <vector> 7#include <span>
8 8
9#include "common/common_funcs.h" 9#include "common/common_funcs.h"
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "common/scratch_buffer.h"
11#include "video_core/host1x/nvdec_common.h" 12#include "video_core/host1x/nvdec_common.h"
12 13
13namespace Tegra { 14namespace Tegra {
@@ -24,11 +25,11 @@ public:
24 ~VP8(); 25 ~VP8();
25 26
26 /// Compose the VP8 frame for FFmpeg decoding 27 /// Compose the VP8 frame for FFmpeg decoding
27 [[nodiscard]] const std::vector<u8>& ComposeFrame( 28 [[nodiscard]] std::span<const u8> ComposeFrame(
28 const Host1x::NvdecCommon::NvdecRegisters& state); 29 const Host1x::NvdecCommon::NvdecRegisters& state);
29 30
30private: 31private:
31 std::vector<u8> frame; 32 Common::ScratchBuffer<u8> frame;
32 Host1x::Host1x& host1x; 33 Host1x::Host1x& host1x;
33 34
34 struct VP8PictureInfo { 35 struct VP8PictureInfo {
diff --git a/src/video_core/host1x/codecs/vp9.cpp b/src/video_core/host1x/codecs/vp9.cpp
index cf40c9012..306c3d0e8 100644
--- a/src/video_core/host1x/codecs/vp9.cpp
+++ b/src/video_core/host1x/codecs/vp9.cpp
@@ -3,6 +3,7 @@
3 3
4#include <algorithm> // for std::copy 4#include <algorithm> // for std::copy
5#include <numeric> 5#include <numeric>
6
6#include "common/assert.h" 7#include "common/assert.h"
7#include "video_core/host1x/codecs/vp9.h" 8#include "video_core/host1x/codecs/vp9.h"
8#include "video_core/host1x/host1x.h" 9#include "video_core/host1x/host1x.h"
diff --git a/src/video_core/host1x/codecs/vp9.h b/src/video_core/host1x/codecs/vp9.h
index d4083e8d3..f1ed19508 100644
--- a/src/video_core/host1x/codecs/vp9.h
+++ b/src/video_core/host1x/codecs/vp9.h
@@ -4,9 +4,11 @@
4#pragma once 4#pragma once
5 5
6#include <array> 6#include <array>
7#include <span>
7#include <vector> 8#include <vector>
8 9
9#include "common/common_types.h" 10#include "common/common_types.h"
11#include "common/scratch_buffer.h"
10#include "common/stream.h" 12#include "common/stream.h"
11#include "video_core/host1x/codecs/vp9_types.h" 13#include "video_core/host1x/codecs/vp9_types.h"
12#include "video_core/host1x/nvdec_common.h" 14#include "video_core/host1x/nvdec_common.h"
@@ -128,8 +130,8 @@ public:
128 return !current_frame_info.show_frame; 130 return !current_frame_info.show_frame;
129 } 131 }
130 132
131 /// Returns a const reference to the composed frame data. 133 /// Returns a const span to the composed frame data.
132 [[nodiscard]] const std::vector<u8>& GetFrameBytes() const { 134 [[nodiscard]] std::span<const u8> GetFrameBytes() const {
133 return frame; 135 return frame;
134 } 136 }
135 137
@@ -181,7 +183,7 @@ private:
181 [[nodiscard]] VpxBitStreamWriter ComposeUncompressedHeader(); 183 [[nodiscard]] VpxBitStreamWriter ComposeUncompressedHeader();
182 184
183 Host1x::Host1x& host1x; 185 Host1x::Host1x& host1x;
184 std::vector<u8> frame; 186 Common::ScratchBuffer<u8> frame;
185 187
186 std::array<s8, 4> loop_filter_ref_deltas{}; 188 std::array<s8, 4> loop_filter_ref_deltas{};
187 std::array<s8, 2> loop_filter_mode_deltas{}; 189 std::array<s8, 2> loop_filter_mode_deltas{};
diff --git a/src/video_core/host1x/codecs/vp9_types.h b/src/video_core/host1x/codecs/vp9_types.h
index adad8ed7e..cc9b25690 100644
--- a/src/video_core/host1x/codecs/vp9_types.h
+++ b/src/video_core/host1x/codecs/vp9_types.h
@@ -5,6 +5,7 @@
5 5
6#include <array> 6#include <array>
7#include <vector> 7#include <vector>
8
8#include "common/common_funcs.h" 9#include "common/common_funcs.h"
9#include "common/common_types.h" 10#include "common/common_types.h"
10 11