summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/scratch_buffer.h9
-rw-r--r--src/video_core/engines/sw_blitter/blitter.cpp25
-rw-r--r--src/video_core/texture_cache/texture_cache.h2
3 files changed, 24 insertions, 12 deletions
diff --git a/src/common/scratch_buffer.h b/src/common/scratch_buffer.h
index 26d4e76dc..a69a5a7af 100644
--- a/src/common/scratch_buffer.h
+++ b/src/common/scratch_buffer.h
@@ -23,7 +23,10 @@ public:
23 buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {} 23 buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {}
24 24
25 ~ScratchBuffer() = default; 25 ~ScratchBuffer() = default;
26 ScratchBuffer(const ScratchBuffer&) = delete;
27 ScratchBuffer& operator=(const ScratchBuffer&) = delete;
26 ScratchBuffer(ScratchBuffer&&) = default; 28 ScratchBuffer(ScratchBuffer&&) = default;
29 ScratchBuffer& operator=(ScratchBuffer&&) = default;
27 30
28 /// This will only grow the buffer's capacity if size is greater than the current capacity. 31 /// This will only grow the buffer's capacity if size is greater than the current capacity.
29 /// The previously held data will remain intact. 32 /// The previously held data will remain intact.
@@ -87,6 +90,12 @@ public:
87 return buffer_capacity; 90 return buffer_capacity;
88 } 91 }
89 92
93 void swap(ScratchBuffer& other) noexcept {
94 std::swap(last_requested_size, other.last_requested_size);
95 std::swap(buffer_capacity, other.buffer_capacity);
96 std::swap(buffer, other.buffer);
97 }
98
90private: 99private:
91 size_t last_requested_size{}; 100 size_t last_requested_size{};
92 size_t buffer_capacity{}; 101 size_t buffer_capacity{};
diff --git a/src/video_core/engines/sw_blitter/blitter.cpp b/src/video_core/engines/sw_blitter/blitter.cpp
index 3c9f38559..ff88cd03d 100644
--- a/src/video_core/engines/sw_blitter/blitter.cpp
+++ b/src/video_core/engines/sw_blitter/blitter.cpp
@@ -5,6 +5,7 @@
5#include <cmath> 5#include <cmath>
6#include <vector> 6#include <vector>
7 7
8#include "common/scratch_buffer.h"
8#include "video_core/engines/sw_blitter/blitter.h" 9#include "video_core/engines/sw_blitter/blitter.h"
9#include "video_core/engines/sw_blitter/converter.h" 10#include "video_core/engines/sw_blitter/converter.h"
10#include "video_core/memory_manager.h" 11#include "video_core/memory_manager.h"
@@ -112,11 +113,11 @@ void Bilinear(std::span<const f32> input, std::span<f32> output, size_t src_widt
112} // namespace 113} // namespace
113 114
114struct SoftwareBlitEngine::BlitEngineImpl { 115struct SoftwareBlitEngine::BlitEngineImpl {
115 std::vector<u8> tmp_buffer; 116 Common::ScratchBuffer<u8> tmp_buffer;
116 std::vector<u8> src_buffer; 117 Common::ScratchBuffer<u8> src_buffer;
117 std::vector<u8> dst_buffer; 118 Common::ScratchBuffer<u8> dst_buffer;
118 std::vector<f32> intermediate_src; 119 Common::ScratchBuffer<f32> intermediate_src;
119 std::vector<f32> intermediate_dst; 120 Common::ScratchBuffer<f32> intermediate_dst;
120 ConverterFactory converter_factory; 121 ConverterFactory converter_factory;
121}; 122};
122 123
@@ -158,14 +159,14 @@ bool SoftwareBlitEngine::Blit(Fermi2D::Surface& src, Fermi2D::Surface& dst,
158 const auto src_bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(src.format)); 159 const auto src_bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(src.format));
159 const auto dst_bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(dst.format)); 160 const auto dst_bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(dst.format));
160 const size_t src_size = get_surface_size(src, src_bytes_per_pixel); 161 const size_t src_size = get_surface_size(src, src_bytes_per_pixel);
161 impl->tmp_buffer.resize(src_size); 162 impl->tmp_buffer.resize_destructive(src_size);
162 memory_manager.ReadBlock(src.Address(), impl->tmp_buffer.data(), src_size); 163 memory_manager.ReadBlock(src.Address(), impl->tmp_buffer.data(), src_size);
163 164
164 const size_t src_copy_size = src_extent_x * src_extent_y * src_bytes_per_pixel; 165 const size_t src_copy_size = src_extent_x * src_extent_y * src_bytes_per_pixel;
165 166
166 const size_t dst_copy_size = dst_extent_x * dst_extent_y * dst_bytes_per_pixel; 167 const size_t dst_copy_size = dst_extent_x * dst_extent_y * dst_bytes_per_pixel;
167 168
168 impl->src_buffer.resize(src_copy_size); 169 impl->src_buffer.resize_destructive(src_copy_size);
169 170
170 const bool no_passthrough = 171 const bool no_passthrough =
171 src.format != dst.format || src_extent_x != dst_extent_x || src_extent_y != dst_extent_y; 172 src.format != dst.format || src_extent_x != dst_extent_x || src_extent_y != dst_extent_y;
@@ -177,8 +178,10 @@ bool SoftwareBlitEngine::Blit(Fermi2D::Surface& src, Fermi2D::Surface& dst,
177 178
178 const auto convertion_phase_ir = [&]() { 179 const auto convertion_phase_ir = [&]() {
179 auto* input_converter = impl->converter_factory.GetFormatConverter(src.format); 180 auto* input_converter = impl->converter_factory.GetFormatConverter(src.format);
180 impl->intermediate_src.resize((src_copy_size / src_bytes_per_pixel) * ir_components); 181 impl->intermediate_src.resize_destructive((src_copy_size / src_bytes_per_pixel) *
181 impl->intermediate_dst.resize((dst_copy_size / dst_bytes_per_pixel) * ir_components); 182 ir_components);
183 impl->intermediate_dst.resize_destructive((dst_copy_size / dst_bytes_per_pixel) *
184 ir_components);
182 input_converter->ConvertTo(impl->src_buffer, impl->intermediate_src); 185 input_converter->ConvertTo(impl->src_buffer, impl->intermediate_src);
183 186
184 if (config.filter != Fermi2D::Filter::Bilinear) { 187 if (config.filter != Fermi2D::Filter::Bilinear) {
@@ -195,7 +198,7 @@ bool SoftwareBlitEngine::Blit(Fermi2D::Surface& src, Fermi2D::Surface& dst,
195 198
196 // Do actual Blit 199 // Do actual Blit
197 200
198 impl->dst_buffer.resize(dst_copy_size); 201 impl->dst_buffer.resize_destructive(dst_copy_size);
199 if (src.linear == Fermi2D::MemoryLayout::BlockLinear) { 202 if (src.linear == Fermi2D::MemoryLayout::BlockLinear) {
200 UnswizzleSubrect(impl->src_buffer, impl->tmp_buffer, src_bytes_per_pixel, src.width, 203 UnswizzleSubrect(impl->src_buffer, impl->tmp_buffer, src_bytes_per_pixel, src.width,
201 src.height, src.depth, config.src_x0, config.src_y0, src_extent_x, 204 src.height, src.depth, config.src_x0, config.src_y0, src_extent_x,
@@ -218,7 +221,7 @@ bool SoftwareBlitEngine::Blit(Fermi2D::Surface& src, Fermi2D::Surface& dst,
218 } 221 }
219 222
220 const size_t dst_size = get_surface_size(dst, dst_bytes_per_pixel); 223 const size_t dst_size = get_surface_size(dst, dst_bytes_per_pixel);
221 impl->tmp_buffer.resize(dst_size); 224 impl->tmp_buffer.resize_destructive(dst_size);
222 memory_manager.ReadBlock(dst.Address(), impl->tmp_buffer.data(), dst_size); 225 memory_manager.ReadBlock(dst.Address(), impl->tmp_buffer.data(), dst_size);
223 226
224 if (dst.linear == Fermi2D::MemoryLayout::BlockLinear) { 227 if (dst.linear == Fermi2D::MemoryLayout::BlockLinear) {
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index e1198dcf8..b24086fce 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -1469,7 +1469,7 @@ std::optional<typename TextureCache<P>::BlitImages> TextureCache<P>::GetBlitImag
1469 if (!copy.must_accelerate) { 1469 if (!copy.must_accelerate) {
1470 do { 1470 do {
1471 if (!src_id && !dst_id) { 1471 if (!src_id && !dst_id) {
1472 return std::nullopt; 1472 break;
1473 } 1473 }
1474 if (src_id && True(slot_images[src_id].flags & ImageFlagBits::GpuModified)) { 1474 if (src_id && True(slot_images[src_id].flags & ImageFlagBits::GpuModified)) {
1475 break; 1475 break;