summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Ameer J2021-07-12 12:49:11 -0400
committerGravatar GitHub2021-07-12 12:49:11 -0400
commit776f391ff6cb37e63241d3513a140662c5a69f08 (patch)
tree9cf19af1b1826261a27a75a744c6415271dadd2d /src
parentMerge pull request #6577 from ReinUsesLisp/precommit (diff)
parentaccelerateDMA: Fixes and feedback. (diff)
downloadyuzu-776f391ff6cb37e63241d3513a140662c5a69f08.tar.gz
yuzu-776f391ff6cb37e63241d3513a140662c5a69f08.tar.xz
yuzu-776f391ff6cb37e63241d3513a140662c5a69f08.zip
Merge pull request #6597 from FernandoS27/accelerate-dma
DMAEngine: Introduce Accelerate DMA.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/buffer_cache/buffer_cache.h150
-rw-r--r--src/video_core/engines/maxwell_dma.cpp36
-rw-r--r--src/video_core/engines/maxwell_dma.h17
-rw-r--r--src/video_core/gpu.cpp1
-rw-r--r--src/video_core/rasterizer_interface.h5
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp13
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h13
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.cpp13
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.h13
9 files changed, 199 insertions, 62 deletions
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h
index 502feddba..2871682f6 100644
--- a/src/video_core/buffer_cache/buffer_cache.h
+++ b/src/video_core/buffer_cache/buffer_cache.h
@@ -164,6 +164,8 @@ public:
164 /// Pop asynchronous downloads 164 /// Pop asynchronous downloads
165 void PopAsyncFlushes(); 165 void PopAsyncFlushes();
166 166
167 [[nodiscard]] bool DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount);
168
167 /// Return true when a CPU region is modified from the GPU 169 /// Return true when a CPU region is modified from the GPU
168 [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size); 170 [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size);
169 171
@@ -200,6 +202,36 @@ private:
200 } 202 }
201 } 203 }
202 204
205 template <typename Func>
206 void ForEachWrittenRange(VAddr cpu_addr, u64 size, Func&& func) {
207 const VAddr start_address = cpu_addr;
208 const VAddr end_address = start_address + size;
209 const VAddr search_base =
210 static_cast<VAddr>(std::min<s64>(0LL, static_cast<s64>(start_address - size)));
211 const IntervalType search_interval{search_base, search_base + 1};
212 auto it = common_ranges.lower_bound(search_interval);
213 if (it == common_ranges.end()) {
214 it = common_ranges.begin();
215 }
216 for (; it != common_ranges.end(); it++) {
217 VAddr inter_addr_end = it->upper();
218 VAddr inter_addr = it->lower();
219 if (inter_addr >= end_address) {
220 break;
221 }
222 if (inter_addr_end <= start_address) {
223 continue;
224 }
225 if (inter_addr_end > end_address) {
226 inter_addr_end = end_address;
227 }
228 if (inter_addr < start_address) {
229 inter_addr = start_address;
230 }
231 func(inter_addr, inter_addr_end);
232 }
233 }
234
203 static bool IsRangeGranular(VAddr cpu_addr, size_t size) { 235 static bool IsRangeGranular(VAddr cpu_addr, size_t size) {
204 return (cpu_addr & ~Core::Memory::PAGE_MASK) == 236 return (cpu_addr & ~Core::Memory::PAGE_MASK) ==
205 ((cpu_addr + size) & ~Core::Memory::PAGE_MASK); 237 ((cpu_addr + size) & ~Core::Memory::PAGE_MASK);
@@ -431,6 +463,68 @@ void BufferCache<P>::DownloadMemory(VAddr cpu_addr, u64 size) {
431} 463}
432 464
433template <class P> 465template <class P>
466bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) {
467 const std::optional<VAddr> cpu_src_address = gpu_memory.GpuToCpuAddress(src_address);
468 const std::optional<VAddr> cpu_dest_address = gpu_memory.GpuToCpuAddress(dest_address);
469 if (!cpu_src_address || !cpu_dest_address) {
470 return false;
471 }
472 const bool source_dirty = IsRegionGpuModified(*cpu_src_address, amount);
473 const bool dest_dirty = IsRegionGpuModified(*cpu_dest_address, amount);
474 if (!source_dirty && !dest_dirty) {
475 return false;
476 }
477
478 const IntervalType subtract_interval{*cpu_dest_address, *cpu_dest_address + amount};
479 uncommitted_ranges.subtract(subtract_interval);
480 for (auto& interval_set : committed_ranges) {
481 interval_set.subtract(subtract_interval);
482 }
483
484 BufferId buffer_a;
485 BufferId buffer_b;
486 do {
487 has_deleted_buffers = false;
488 buffer_a = FindBuffer(*cpu_src_address, static_cast<u32>(amount));
489 buffer_b = FindBuffer(*cpu_dest_address, static_cast<u32>(amount));
490 } while (has_deleted_buffers);
491 auto& src_buffer = slot_buffers[buffer_a];
492 auto& dest_buffer = slot_buffers[buffer_b];
493 SynchronizeBuffer(src_buffer, *cpu_src_address, static_cast<u32>(amount));
494 SynchronizeBuffer(dest_buffer, *cpu_dest_address, static_cast<u32>(amount));
495 std::array copies{BufferCopy{
496 .src_offset = src_buffer.Offset(*cpu_src_address),
497 .dst_offset = dest_buffer.Offset(*cpu_dest_address),
498 .size = amount,
499 }};
500
501 boost::container::small_vector<IntervalType, 4> tmp_intervals;
502 auto mirror = [&](VAddr base_address, VAddr base_address_end) {
503 const u64 size = base_address_end - base_address;
504 const VAddr diff = base_address - *cpu_src_address;
505 const VAddr new_base_address = *cpu_dest_address + diff;
506 const IntervalType add_interval{new_base_address, new_base_address + size};
507 uncommitted_ranges.add(add_interval);
508 tmp_intervals.push_back(add_interval);
509 };
510 ForEachWrittenRange(*cpu_src_address, amount, mirror);
511 // This subtraction in this order is important for overlapping copies.
512 common_ranges.subtract(subtract_interval);
513 for (const IntervalType add_interval : tmp_intervals) {
514 common_ranges.add(add_interval);
515 }
516
517 runtime.CopyBuffer(dest_buffer, src_buffer, copies);
518 if (source_dirty) {
519 dest_buffer.MarkRegionAsGpuModified(*cpu_dest_address, amount);
520 }
521 std::vector<u8> tmp_buffer(amount);
522 cpu_memory.ReadBlockUnsafe(*cpu_src_address, tmp_buffer.data(), amount);
523 cpu_memory.WriteBlockUnsafe(*cpu_dest_address, tmp_buffer.data(), amount);
524 return true;
525}
526
527template <class P>
434void BufferCache<P>::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, 528void BufferCache<P>::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr,
435 u32 size) { 529 u32 size) {
436 const std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr); 530 const std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr);
@@ -616,30 +710,7 @@ void BufferCache<P>::CommitAsyncFlushesHigh() {
616 710
617 const VAddr start_address = buffer_addr + range_offset; 711 const VAddr start_address = buffer_addr + range_offset;
618 const VAddr end_address = start_address + range_size; 712 const VAddr end_address = start_address + range_size;
619 const IntervalType search_interval{cpu_addr, 1}; 713 ForEachWrittenRange(start_address, range_size, add_download);
620 auto it = common_ranges.lower_bound(search_interval);
621 if (it == common_ranges.end()) {
622 it = common_ranges.begin();
623 }
624 while (it != common_ranges.end()) {
625 VAddr inter_addr_end = it->upper();
626 VAddr inter_addr = it->lower();
627 if (inter_addr >= end_address) {
628 break;
629 }
630 if (inter_addr_end <= start_address) {
631 it++;
632 continue;
633 }
634 if (inter_addr_end > end_address) {
635 inter_addr_end = end_address;
636 }
637 if (inter_addr < start_address) {
638 inter_addr = start_address;
639 }
640 add_download(inter_addr, inter_addr_end);
641 it++;
642 }
643 const IntervalType subtract_interval{start_address, end_address}; 714 const IntervalType subtract_interval{start_address, end_address};
644 common_ranges.subtract(subtract_interval); 715 common_ranges.subtract(subtract_interval);
645 }); 716 });
@@ -737,7 +808,9 @@ void BufferCache<P>::BindHostIndexBuffer() {
737 const u32 size = index_buffer.size; 808 const u32 size = index_buffer.size;
738 SynchronizeBuffer(buffer, index_buffer.cpu_addr, size); 809 SynchronizeBuffer(buffer, index_buffer.cpu_addr, size);
739 if constexpr (HAS_FULL_INDEX_AND_PRIMITIVE_SUPPORT) { 810 if constexpr (HAS_FULL_INDEX_AND_PRIMITIVE_SUPPORT) {
740 runtime.BindIndexBuffer(buffer, offset, size); 811 const u32 new_offset = offset + maxwell3d.regs.index_array.first *
812 maxwell3d.regs.index_array.FormatSizeInBytes();
813 runtime.BindIndexBuffer(buffer, new_offset, size);
741 } else { 814 } else {
742 runtime.BindIndexBuffer(maxwell3d.regs.draw.topology, maxwell3d.regs.index_array.format, 815 runtime.BindIndexBuffer(maxwell3d.regs.draw.topology, maxwell3d.regs.index_array.format,
743 maxwell3d.regs.index_array.first, maxwell3d.regs.index_array.count, 816 maxwell3d.regs.index_array.first, maxwell3d.regs.index_array.count,
@@ -951,7 +1024,7 @@ void BufferCache<P>::UpdateIndexBuffer() {
951 const GPUVAddr gpu_addr_end = index_array.EndAddress(); 1024 const GPUVAddr gpu_addr_end = index_array.EndAddress();
952 const std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr_begin); 1025 const std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr_begin);
953 const u32 address_size = static_cast<u32>(gpu_addr_end - gpu_addr_begin); 1026 const u32 address_size = static_cast<u32>(gpu_addr_end - gpu_addr_begin);
954 const u32 draw_size = index_array.count * index_array.FormatSizeInBytes(); 1027 const u32 draw_size = (index_array.count + index_array.first) * index_array.FormatSizeInBytes();
955 const u32 size = std::min(address_size, draw_size); 1028 const u32 size = std::min(address_size, draw_size);
956 if (size == 0 || !cpu_addr) { 1029 if (size == 0 || !cpu_addr) {
957 index_buffer = NULL_BINDING; 1030 index_buffer = NULL_BINDING;
@@ -1350,30 +1423,7 @@ void BufferCache<P>::DownloadBufferMemory(Buffer& buffer, VAddr cpu_addr, u64 si
1350 1423
1351 const VAddr start_address = buffer_addr + range_offset; 1424 const VAddr start_address = buffer_addr + range_offset;
1352 const VAddr end_address = start_address + range_size; 1425 const VAddr end_address = start_address + range_size;
1353 const IntervalType search_interval{start_address - range_size, 1}; 1426 ForEachWrittenRange(start_address, range_size, add_download);
1354 auto it = common_ranges.lower_bound(search_interval);
1355 if (it == common_ranges.end()) {
1356 it = common_ranges.begin();
1357 }
1358 while (it != common_ranges.end()) {
1359 VAddr inter_addr_end = it->upper();
1360 VAddr inter_addr = it->lower();
1361 if (inter_addr >= end_address) {
1362 break;
1363 }
1364 if (inter_addr_end <= start_address) {
1365 it++;
1366 continue;
1367 }
1368 if (inter_addr_end > end_address) {
1369 inter_addr_end = end_address;
1370 }
1371 if (inter_addr < start_address) {
1372 inter_addr = start_address;
1373 }
1374 add_download(inter_addr, inter_addr_end);
1375 it++;
1376 }
1377 const IntervalType subtract_interval{start_address, end_address}; 1427 const IntervalType subtract_interval{start_address, end_address};
1378 common_ranges.subtract(subtract_interval); 1428 common_ranges.subtract(subtract_interval);
1379 }); 1429 });
diff --git a/src/video_core/engines/maxwell_dma.cpp b/src/video_core/engines/maxwell_dma.cpp
index 2ee980bab..24481952b 100644
--- a/src/video_core/engines/maxwell_dma.cpp
+++ b/src/video_core/engines/maxwell_dma.cpp
@@ -21,6 +21,10 @@ MaxwellDMA::MaxwellDMA(Core::System& system_, MemoryManager& memory_manager_)
21 21
22MaxwellDMA::~MaxwellDMA() = default; 22MaxwellDMA::~MaxwellDMA() = default;
23 23
24void MaxwellDMA::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) {
25 rasterizer = rasterizer_;
26}
27
24void MaxwellDMA::CallMethod(u32 method, u32 method_argument, bool is_last_call) { 28void MaxwellDMA::CallMethod(u32 method, u32 method_argument, bool is_last_call) {
25 ASSERT_MSG(method < NUM_REGS, "Invalid MaxwellDMA register"); 29 ASSERT_MSG(method < NUM_REGS, "Invalid MaxwellDMA register");
26 30
@@ -44,7 +48,6 @@ void MaxwellDMA::Launch() {
44 48
45 // TODO(Subv): Perform more research and implement all features of this engine. 49 // TODO(Subv): Perform more research and implement all features of this engine.
46 const LaunchDMA& launch = regs.launch_dma; 50 const LaunchDMA& launch = regs.launch_dma;
47 ASSERT(launch.remap_enable == 0);
48 ASSERT(launch.semaphore_type == LaunchDMA::SemaphoreType::NONE); 51 ASSERT(launch.semaphore_type == LaunchDMA::SemaphoreType::NONE);
49 ASSERT(launch.interrupt_type == LaunchDMA::InterruptType::NONE); 52 ASSERT(launch.interrupt_type == LaunchDMA::InterruptType::NONE);
50 ASSERT(launch.data_transfer_type == LaunchDMA::DataTransferType::NON_PIPELINED); 53 ASSERT(launch.data_transfer_type == LaunchDMA::DataTransferType::NON_PIPELINED);
@@ -77,11 +80,29 @@ void MaxwellDMA::CopyPitchToPitch() {
77 // When `multi_line_enable` bit is disabled the copy is performed as if we were copying a 1D 80 // When `multi_line_enable` bit is disabled the copy is performed as if we were copying a 1D
78 // buffer of length `line_length_in`. 81 // buffer of length `line_length_in`.
79 // Otherwise we copy a 2D image of dimensions (line_length_in, line_count). 82 // Otherwise we copy a 2D image of dimensions (line_length_in, line_count).
83 auto& accelerate = rasterizer->AccessAccelerateDMA();
80 if (!regs.launch_dma.multi_line_enable) { 84 if (!regs.launch_dma.multi_line_enable) {
81 memory_manager.CopyBlock(regs.offset_out, regs.offset_in, regs.line_length_in); 85 const bool is_buffer_clear = regs.launch_dma.remap_enable != 0 &&
86 regs.remap_const.dst_x == RemapConst::Swizzle::CONST_A;
87 // TODO: allow multisized components.
88 if (is_buffer_clear) {
89 ASSERT(regs.remap_const.component_size_minus_one == 3);
90 std::vector<u32> tmp_buffer(regs.line_length_in, regs.remap_consta_value);
91 memory_manager.WriteBlock(regs.offset_out, reinterpret_cast<u8*>(tmp_buffer.data()),
92 regs.line_length_in * sizeof(u32));
93 return;
94 }
95 UNIMPLEMENTED_IF(regs.launch_dma.remap_enable != 0);
96 if (!accelerate.BufferCopy(regs.offset_in, regs.offset_out, regs.line_length_in)) {
97 std::vector<u8> tmp_buffer(regs.line_length_in);
98 memory_manager.ReadBlockUnsafe(regs.offset_in, tmp_buffer.data(), regs.line_length_in);
99 memory_manager.WriteBlock(regs.offset_out, tmp_buffer.data(), regs.line_length_in);
100 }
82 return; 101 return;
83 } 102 }
84 103
104 UNIMPLEMENTED_IF(regs.launch_dma.remap_enable != 0);
105
85 // Perform a line-by-line copy. 106 // Perform a line-by-line copy.
86 // We're going to take a subrect of size (line_length_in, line_count) from the source rectangle. 107 // We're going to take a subrect of size (line_length_in, line_count) from the source rectangle.
87 // There is no need to manually flush/invalidate the regions because CopyBlock does that for us. 108 // There is no need to manually flush/invalidate the regions because CopyBlock does that for us.
@@ -105,6 +126,7 @@ void MaxwellDMA::CopyBlockLinearToPitch() {
105 } 126 }
106 127
107 // Deswizzle the input and copy it over. 128 // Deswizzle the input and copy it over.
129 UNIMPLEMENTED_IF(regs.launch_dma.remap_enable != 0);
108 const u32 bytes_per_pixel = regs.pitch_out / regs.line_length_in; 130 const u32 bytes_per_pixel = regs.pitch_out / regs.line_length_in;
109 const Parameters& src_params = regs.src_params; 131 const Parameters& src_params = regs.src_params;
110 const u32 width = src_params.width; 132 const u32 width = src_params.width;
@@ -134,6 +156,7 @@ void MaxwellDMA::CopyBlockLinearToPitch() {
134 156
135void MaxwellDMA::CopyPitchToBlockLinear() { 157void MaxwellDMA::CopyPitchToBlockLinear() {
136 UNIMPLEMENTED_IF_MSG(regs.dst_params.block_size.width != 0, "Block width is not one"); 158 UNIMPLEMENTED_IF_MSG(regs.dst_params.block_size.width != 0, "Block width is not one");
159 UNIMPLEMENTED_IF(regs.launch_dma.remap_enable != 0);
137 160
138 const auto& dst_params = regs.dst_params; 161 const auto& dst_params = regs.dst_params;
139 const u32 bytes_per_pixel = regs.pitch_in / regs.line_length_in; 162 const u32 bytes_per_pixel = regs.pitch_in / regs.line_length_in;
@@ -156,13 +179,8 @@ void MaxwellDMA::CopyPitchToBlockLinear() {
156 write_buffer.resize(dst_size); 179 write_buffer.resize(dst_size);
157 } 180 }
158 181
159 if (Settings::IsGPULevelExtreme()) { 182 memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size);
160 memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); 183 memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size);
161 memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size);
162 } else {
163 memory_manager.ReadBlockUnsafe(regs.offset_in, read_buffer.data(), src_size);
164 memory_manager.ReadBlockUnsafe(regs.offset_out, write_buffer.data(), dst_size);
165 }
166 184
167 // If the input is linear and the output is tiled, swizzle the input and copy it over. 185 // If the input is linear and the output is tiled, swizzle the input and copy it over.
168 if (regs.dst_params.block_size.depth > 0) { 186 if (regs.dst_params.block_size.depth > 0) {
diff --git a/src/video_core/engines/maxwell_dma.h b/src/video_core/engines/maxwell_dma.h
index c77f02a22..4ed0d0996 100644
--- a/src/video_core/engines/maxwell_dma.h
+++ b/src/video_core/engines/maxwell_dma.h
@@ -21,8 +21,18 @@ namespace Tegra {
21class MemoryManager; 21class MemoryManager;
22} 22}
23 23
24namespace VideoCore {
25class RasterizerInterface;
26}
27
24namespace Tegra::Engines { 28namespace Tegra::Engines {
25 29
30class AccelerateDMAInterface {
31public:
32 /// Write the value to the register identified by method.
33 virtual bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) = 0;
34};
35
26/** 36/**
27 * This engine is known as gk104_copy. Documentation can be found in: 37 * This engine is known as gk104_copy. Documentation can be found in:
28 * https://github.com/NVIDIA/open-gpu-doc/blob/master/classes/dma-copy/clb0b5.h 38 * https://github.com/NVIDIA/open-gpu-doc/blob/master/classes/dma-copy/clb0b5.h
@@ -187,6 +197,8 @@ public:
187 }; 197 };
188 static_assert(sizeof(RemapConst) == 12); 198 static_assert(sizeof(RemapConst) == 12);
189 199
200 void BindRasterizer(VideoCore::RasterizerInterface* rasterizer);
201
190 explicit MaxwellDMA(Core::System& system_, MemoryManager& memory_manager_); 202 explicit MaxwellDMA(Core::System& system_, MemoryManager& memory_manager_);
191 ~MaxwellDMA() override; 203 ~MaxwellDMA() override;
192 204
@@ -213,6 +225,7 @@ private:
213 Core::System& system; 225 Core::System& system;
214 226
215 MemoryManager& memory_manager; 227 MemoryManager& memory_manager;
228 VideoCore::RasterizerInterface* rasterizer;
216 229
217 std::vector<u8> read_buffer; 230 std::vector<u8> read_buffer;
218 std::vector<u8> write_buffer; 231 std::vector<u8> write_buffer;
@@ -240,7 +253,9 @@ private:
240 u32 pitch_out; 253 u32 pitch_out;
241 u32 line_length_in; 254 u32 line_length_in;
242 u32 line_count; 255 u32 line_count;
243 u32 reserved06[0xb8]; 256 u32 reserved06[0xb6];
257 u32 remap_consta_value;
258 u32 remap_constb_value;
244 RemapConst remap_const; 259 RemapConst remap_const;
245 Parameters dst_params; 260 Parameters dst_params;
246 u32 reserved07[0x1]; 261 u32 reserved07[0x1];
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp
index f317ddc2b..ff024f530 100644
--- a/src/video_core/gpu.cpp
+++ b/src/video_core/gpu.cpp
@@ -50,6 +50,7 @@ void GPU::BindRenderer(std::unique_ptr<VideoCore::RendererBase> renderer_) {
50 maxwell_3d->BindRasterizer(rasterizer); 50 maxwell_3d->BindRasterizer(rasterizer);
51 fermi_2d->BindRasterizer(rasterizer); 51 fermi_2d->BindRasterizer(rasterizer);
52 kepler_compute->BindRasterizer(rasterizer); 52 kepler_compute->BindRasterizer(rasterizer);
53 maxwell_dma->BindRasterizer(rasterizer);
53} 54}
54 55
55Engines::Maxwell3D& GPU::Maxwell3D() { 56Engines::Maxwell3D& GPU::Maxwell3D() {
diff --git a/src/video_core/rasterizer_interface.h b/src/video_core/rasterizer_interface.h
index 67aef6000..58014c1c3 100644
--- a/src/video_core/rasterizer_interface.h
+++ b/src/video_core/rasterizer_interface.h
@@ -15,7 +15,10 @@
15 15
16namespace Tegra { 16namespace Tegra {
17class MemoryManager; 17class MemoryManager;
18namespace Engines {
19class AccelerateDMAInterface;
18} 20}
21} // namespace Tegra
19 22
20namespace VideoCore { 23namespace VideoCore {
21 24
@@ -119,6 +122,8 @@ public:
119 return false; 122 return false;
120 } 123 }
121 124
125 [[nodiscard]] virtual Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() = 0;
126
122 /// Attempt to use a faster method to display the framebuffer to screen 127 /// Attempt to use a faster method to display the framebuffer to screen
123 [[nodiscard]] virtual bool AccelerateDisplay(const Tegra::FramebufferConfig& config, 128 [[nodiscard]] virtual bool AccelerateDisplay(const Tegra::FramebufferConfig& config,
124 VAddr framebuffer_addr, u32 pixel_stride) { 129 VAddr framebuffer_addr, u32 pixel_stride) {
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index a4ed8f68f..82c84127a 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -171,7 +171,7 @@ RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegra
171 buffer_cache_runtime(device), 171 buffer_cache_runtime(device),
172 buffer_cache(*this, maxwell3d, kepler_compute, gpu_memory, cpu_memory_, buffer_cache_runtime), 172 buffer_cache(*this, maxwell3d, kepler_compute, gpu_memory, cpu_memory_, buffer_cache_runtime),
173 shader_cache(*this, emu_window_, gpu, maxwell3d, kepler_compute, gpu_memory, device), 173 shader_cache(*this, emu_window_, gpu, maxwell3d, kepler_compute, gpu_memory, device),
174 query_cache(*this, maxwell3d, gpu_memory), 174 query_cache(*this, maxwell3d, gpu_memory), accelerate_dma(buffer_cache),
175 fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache), 175 fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache),
176 async_shaders(emu_window_) { 176 async_shaders(emu_window_) {
177 if (device.UseAsynchronousShaders()) { 177 if (device.UseAsynchronousShaders()) {
@@ -701,6 +701,10 @@ bool RasterizerOpenGL::AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surf
701 return true; 701 return true;
702} 702}
703 703
704Tegra::Engines::AccelerateDMAInterface& RasterizerOpenGL::AccessAccelerateDMA() {
705 return accelerate_dma;
706}
707
704bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config, 708bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config,
705 VAddr framebuffer_addr, u32 pixel_stride) { 709 VAddr framebuffer_addr, u32 pixel_stride) {
706 if (framebuffer_addr == 0) { 710 if (framebuffer_addr == 0) {
@@ -1396,4 +1400,11 @@ void RasterizerOpenGL::EndTransformFeedback() {
1396 glEndTransformFeedback(); 1400 glEndTransformFeedback();
1397} 1401}
1398 1402
1403AccelerateDMA::AccelerateDMA(BufferCache& buffer_cache_) : buffer_cache{buffer_cache_} {}
1404
1405bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) {
1406 std::scoped_lock lock{buffer_cache.mutex};
1407 return buffer_cache.DMACopy(src_address, dest_address, amount);
1408}
1409
1399} // namespace OpenGL 1410} // namespace OpenGL
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index d8df71962..ccee9ba33 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -19,6 +19,7 @@
19#include "common/common_types.h" 19#include "common/common_types.h"
20#include "video_core/engines/const_buffer_info.h" 20#include "video_core/engines/const_buffer_info.h"
21#include "video_core/engines/maxwell_3d.h" 21#include "video_core/engines/maxwell_3d.h"
22#include "video_core/engines/maxwell_dma.h"
22#include "video_core/rasterizer_accelerated.h" 23#include "video_core/rasterizer_accelerated.h"
23#include "video_core/rasterizer_interface.h" 24#include "video_core/rasterizer_interface.h"
24#include "video_core/renderer_opengl/gl_buffer_cache.h" 25#include "video_core/renderer_opengl/gl_buffer_cache.h"
@@ -58,6 +59,16 @@ struct BindlessSSBO {
58}; 59};
59static_assert(sizeof(BindlessSSBO) * CHAR_BIT == 128); 60static_assert(sizeof(BindlessSSBO) * CHAR_BIT == 128);
60 61
62class AccelerateDMA : public Tegra::Engines::AccelerateDMAInterface {
63public:
64 explicit AccelerateDMA(BufferCache& buffer_cache);
65
66 bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) override;
67
68private:
69 BufferCache& buffer_cache;
70};
71
61class RasterizerOpenGL : public VideoCore::RasterizerAccelerated { 72class RasterizerOpenGL : public VideoCore::RasterizerAccelerated {
62public: 73public:
63 explicit RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu_, 74 explicit RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu_,
@@ -94,6 +105,7 @@ public:
94 bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src, 105 bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src,
95 const Tegra::Engines::Fermi2D::Surface& dst, 106 const Tegra::Engines::Fermi2D::Surface& dst,
96 const Tegra::Engines::Fermi2D::Config& copy_config) override; 107 const Tegra::Engines::Fermi2D::Config& copy_config) override;
108 Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() override;
97 bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr, 109 bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
98 u32 pixel_stride) override; 110 u32 pixel_stride) override;
99 void LoadDiskResources(u64 title_id, std::stop_token stop_loading, 111 void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
@@ -234,6 +246,7 @@ private:
234 BufferCache buffer_cache; 246 BufferCache buffer_cache;
235 ShaderCacheOpenGL shader_cache; 247 ShaderCacheOpenGL shader_cache;
236 QueryCache query_cache; 248 QueryCache query_cache;
249 AccelerateDMA accelerate_dma;
237 FenceManagerOpenGL fence_manager; 250 FenceManagerOpenGL fence_manager;
238 251
239 VideoCommon::Shader::AsyncShaders async_shaders; 252 VideoCommon::Shader::AsyncShaders async_shaders;
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
index 9ea4b6653..e378a5679 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
@@ -251,7 +251,7 @@ RasterizerVulkan::RasterizerVulkan(Core::Frontend::EmuWindow& emu_window_, Tegra
251 buffer_cache(*this, maxwell3d, kepler_compute, gpu_memory, cpu_memory_, buffer_cache_runtime), 251 buffer_cache(*this, maxwell3d, kepler_compute, gpu_memory, cpu_memory_, buffer_cache_runtime),
252 pipeline_cache(*this, gpu, maxwell3d, kepler_compute, gpu_memory, device, scheduler, 252 pipeline_cache(*this, gpu, maxwell3d, kepler_compute, gpu_memory, device, scheduler,
253 descriptor_pool, update_descriptor_queue), 253 descriptor_pool, update_descriptor_queue),
254 query_cache{*this, maxwell3d, gpu_memory, device, scheduler}, 254 query_cache{*this, maxwell3d, gpu_memory, device, scheduler}, accelerate_dma{buffer_cache},
255 fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache, device, scheduler), 255 fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache, device, scheduler),
256 wfi_event(device.GetLogical().CreateEvent()), async_shaders(emu_window_) { 256 wfi_event(device.GetLogical().CreateEvent()), async_shaders(emu_window_) {
257 scheduler.SetQueryCache(query_cache); 257 scheduler.SetQueryCache(query_cache);
@@ -660,6 +660,10 @@ bool RasterizerVulkan::AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surf
660 return true; 660 return true;
661} 661}
662 662
663Tegra::Engines::AccelerateDMAInterface& RasterizerVulkan::AccessAccelerateDMA() {
664 return accelerate_dma;
665}
666
663bool RasterizerVulkan::AccelerateDisplay(const Tegra::FramebufferConfig& config, 667bool RasterizerVulkan::AccelerateDisplay(const Tegra::FramebufferConfig& config,
664 VAddr framebuffer_addr, u32 pixel_stride) { 668 VAddr framebuffer_addr, u32 pixel_stride) {
665 if (!framebuffer_addr) { 669 if (!framebuffer_addr) {
@@ -698,6 +702,13 @@ void RasterizerVulkan::FlushWork() {
698 draw_counter = 0; 702 draw_counter = 0;
699} 703}
700 704
705AccelerateDMA::AccelerateDMA(BufferCache& buffer_cache_) : buffer_cache{buffer_cache_} {}
706
707bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) {
708 std::scoped_lock lock{buffer_cache.mutex};
709 return buffer_cache.DMACopy(src_address, dest_address, amount);
710}
711
701void RasterizerVulkan::SetupShaderDescriptors( 712void RasterizerVulkan::SetupShaderDescriptors(
702 const std::array<Shader*, Maxwell::MaxShaderProgram>& shaders, bool is_indexed) { 713 const std::array<Shader*, Maxwell::MaxShaderProgram>& shaders, bool is_indexed) {
703 image_view_indices.clear(); 714 image_view_indices.clear();
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h
index 5450ccfb5..3a78de258 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.h
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.h
@@ -13,6 +13,7 @@
13#include <boost/container/static_vector.hpp> 13#include <boost/container/static_vector.hpp>
14 14
15#include "common/common_types.h" 15#include "common/common_types.h"
16#include "video_core/engines/maxwell_dma.h"
16#include "video_core/rasterizer_accelerated.h" 17#include "video_core/rasterizer_accelerated.h"
17#include "video_core/rasterizer_interface.h" 18#include "video_core/rasterizer_interface.h"
18#include "video_core/renderer_vulkan/blit_image.h" 19#include "video_core/renderer_vulkan/blit_image.h"
@@ -49,6 +50,16 @@ struct VKScreenInfo;
49 50
50class StateTracker; 51class StateTracker;
51 52
53class AccelerateDMA : public Tegra::Engines::AccelerateDMAInterface {
54public:
55 explicit AccelerateDMA(BufferCache& buffer_cache);
56
57 bool BufferCopy(GPUVAddr start_address, GPUVAddr end_address, u64 amount) override;
58
59private:
60 BufferCache& buffer_cache;
61};
62
52class RasterizerVulkan final : public VideoCore::RasterizerAccelerated { 63class RasterizerVulkan final : public VideoCore::RasterizerAccelerated {
53public: 64public:
54 explicit RasterizerVulkan(Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu_, 65 explicit RasterizerVulkan(Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu_,
@@ -86,6 +97,7 @@ public:
86 bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src, 97 bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src,
87 const Tegra::Engines::Fermi2D::Surface& dst, 98 const Tegra::Engines::Fermi2D::Surface& dst,
88 const Tegra::Engines::Fermi2D::Config& copy_config) override; 99 const Tegra::Engines::Fermi2D::Config& copy_config) override;
100 Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() override;
89 bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr, 101 bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
90 u32 pixel_stride) override; 102 u32 pixel_stride) override;
91 103
@@ -186,6 +198,7 @@ private:
186 BufferCache buffer_cache; 198 BufferCache buffer_cache;
187 VKPipelineCache pipeline_cache; 199 VKPipelineCache pipeline_cache;
188 VKQueryCache query_cache; 200 VKQueryCache query_cache;
201 AccelerateDMA accelerate_dma;
189 VKFenceManager fence_manager; 202 VKFenceManager fence_manager;
190 203
191 vk::Event wfi_event; 204 vk::Event wfi_event;