2018-06-10 18:02:33 -04:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-02-15 22:05:17 -05:00
|
|
|
#include "common/assert.h"
|
2019-03-05 20:25:01 -05:00
|
|
|
#include "common/logging/log.h"
|
2018-11-06 15:26:27 -05:00
|
|
|
#include "core/core.h"
|
2019-07-24 19:18:17 -04:00
|
|
|
#include "core/settings.h"
|
2018-11-06 15:26:27 -05:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2018-06-10 18:02:33 -04:00
|
|
|
#include "video_core/engines/maxwell_dma.h"
|
2019-04-05 18:21:15 -04:00
|
|
|
#include "video_core/memory_manager.h"
|
2019-02-18 20:58:32 -05:00
|
|
|
#include "video_core/renderer_base.h"
|
2018-06-10 18:02:33 -04:00
|
|
|
#include "video_core/textures/decoders.h"
|
|
|
|
|
2018-10-20 15:58:06 -04:00
|
|
|
namespace Tegra::Engines {
|
2018-06-10 18:02:33 -04:00
|
|
|
|
2019-08-30 14:08:00 -04:00
|
|
|
MaxwellDMA::MaxwellDMA(Core::System& system, MemoryManager& memory_manager)
|
|
|
|
: system{system}, memory_manager{memory_manager} {}
|
2018-06-10 18:02:33 -04:00
|
|
|
|
2020-04-27 21:47:58 -04:00
|
|
|
void MaxwellDMA::CallMethod(u32 method, u32 method_argument, bool is_last_call) {
|
|
|
|
ASSERT_MSG(method < Regs::NUM_REGS,
|
2018-06-10 18:02:33 -04:00
|
|
|
"Invalid MaxwellDMA register, increase the size of the Regs structure");
|
|
|
|
|
2020-04-27 21:47:58 -04:00
|
|
|
regs.reg_array[method] = method_argument;
|
2018-06-10 18:02:33 -04:00
|
|
|
|
|
|
|
#define MAXWELLDMA_REG_INDEX(field_name) \
|
|
|
|
(offsetof(Tegra::Engines::MaxwellDMA::Regs, field_name) / sizeof(u32))
|
|
|
|
|
2020-04-27 21:47:58 -04:00
|
|
|
switch (method) {
|
2018-06-10 18:02:33 -04:00
|
|
|
case MAXWELLDMA_REG_INDEX(exec): {
|
|
|
|
HandleCopy();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef MAXWELLDMA_REG_INDEX
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:42:14 -04:00
|
|
|
void MaxwellDMA::CallMultiMethod(u32 method, const u32* base_start, u32 amount,
|
|
|
|
u32 methods_pending) {
|
2020-04-20 02:16:56 -04:00
|
|
|
for (std::size_t i = 0; i < amount; i++) {
|
2020-04-27 21:47:58 -04:00
|
|
|
CallMethod(method, base_start[i], methods_pending - static_cast<u32>(i) <= 1);
|
2020-04-20 02:16:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-10 18:02:33 -04:00
|
|
|
void MaxwellDMA::HandleCopy() {
|
2019-07-18 08:31:38 -04:00
|
|
|
LOG_TRACE(HW_GPU, "Requested a DMA copy");
|
2018-06-10 18:02:33 -04:00
|
|
|
|
|
|
|
const GPUVAddr source = regs.src_address.Address();
|
|
|
|
const GPUVAddr dest = regs.dst_address.Address();
|
|
|
|
|
|
|
|
// TODO(Subv): Perform more research and implement all features of this engine.
|
|
|
|
ASSERT(regs.exec.enable_swizzle == 0);
|
|
|
|
ASSERT(regs.exec.query_mode == Regs::QueryMode::None);
|
|
|
|
ASSERT(regs.exec.query_intr == Regs::QueryIntr::None);
|
|
|
|
ASSERT(regs.exec.copy_mode == Regs::CopyMode::Unk2);
|
|
|
|
ASSERT(regs.dst_params.pos_x == 0);
|
|
|
|
ASSERT(regs.dst_params.pos_y == 0);
|
2018-07-02 10:46:33 -04:00
|
|
|
|
2018-10-17 21:29:10 -04:00
|
|
|
if (!regs.exec.is_dst_linear && !regs.exec.is_src_linear) {
|
|
|
|
// If both the source and the destination are in block layout, assert.
|
|
|
|
UNREACHABLE_MSG("Tiled->Tiled DMA transfers are not yet implemented");
|
|
|
|
return;
|
|
|
|
}
|
2018-09-08 17:02:16 -04:00
|
|
|
|
2019-12-26 20:14:10 -05:00
|
|
|
// All copies here update the main memory, so mark all rasterizer states as invalid.
|
|
|
|
system.GPU().Maxwell3D().OnMemoryWrite();
|
|
|
|
|
2018-10-17 21:29:10 -04:00
|
|
|
if (regs.exec.is_dst_linear && regs.exec.is_src_linear) {
|
2018-09-08 17:02:16 -04:00
|
|
|
// When the enable_2d bit is disabled, the copy is performed as if we were copying a 1D
|
2018-10-17 21:29:10 -04:00
|
|
|
// buffer of length `x_count`, otherwise we copy a 2D image of dimensions (x_count,
|
|
|
|
// y_count).
|
|
|
|
if (!regs.exec.enable_2d) {
|
2019-02-24 00:15:35 -05:00
|
|
|
memory_manager.CopyBlock(dest, source, regs.x_count);
|
2018-10-17 21:29:10 -04:00
|
|
|
return;
|
2018-09-08 17:02:16 -04:00
|
|
|
}
|
|
|
|
|
2018-10-17 21:29:10 -04:00
|
|
|
// If both the source and the destination are in linear layout, perform a line-by-line
|
|
|
|
// copy. We're going to take a subrect of size (x_count, y_count) from the source
|
|
|
|
// rectangle. There is no need to manually flush/invalidate the regions because
|
|
|
|
// CopyBlock does that for us.
|
|
|
|
for (u32 line = 0; line < regs.y_count; ++line) {
|
2019-02-24 00:15:35 -05:00
|
|
|
const GPUVAddr source_line = source + line * regs.src_pitch;
|
|
|
|
const GPUVAddr dest_line = dest + line * regs.dst_pitch;
|
|
|
|
memory_manager.CopyBlock(dest_line, source_line, regs.x_count);
|
2018-10-17 21:29:10 -04:00
|
|
|
}
|
2018-07-02 10:46:33 -04:00
|
|
|
return;
|
|
|
|
}
|
2018-06-10 18:02:33 -04:00
|
|
|
|
2018-09-08 17:02:16 -04:00
|
|
|
ASSERT(regs.exec.enable_2d == 1);
|
2018-10-17 21:29:10 -04:00
|
|
|
|
2019-04-23 12:41:55 -04:00
|
|
|
if (regs.exec.is_dst_linear && !regs.exec.is_src_linear) {
|
2020-04-27 23:57:24 -04:00
|
|
|
|
2019-07-24 19:18:17 -04:00
|
|
|
ASSERT(regs.src_params.BlockDepth() == 0);
|
2020-04-27 23:57:24 -04:00
|
|
|
// Optimized path for micro copies.
|
|
|
|
if (regs.dst_pitch * regs.y_count < Texture::GetGOBSize() && regs.dst_pitch <= 64) {
|
|
|
|
const u32 bytes_per_pixel = regs.dst_pitch / regs.x_count;
|
|
|
|
const std::size_t src_size = Texture::GetGOBSize();
|
|
|
|
const std::size_t dst_size = regs.dst_pitch * regs.y_count;
|
|
|
|
u32 pos_x = regs.src_params.pos_x;
|
|
|
|
u32 pos_y = regs.src_params.pos_y;
|
|
|
|
const u64 offset =
|
|
|
|
Texture::GetGOBOffset(regs.src_params.size_x, regs.src_params.size_y, pos_x, pos_y,
|
|
|
|
regs.src_params.BlockDepth(), bytes_per_pixel);
|
|
|
|
const u32 x_in_gob = 64 / bytes_per_pixel;
|
|
|
|
pos_x = pos_x % x_in_gob;
|
|
|
|
pos_y = pos_y % 8;
|
|
|
|
|
|
|
|
if (read_buffer.size() < src_size) {
|
|
|
|
read_buffer.resize(src_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write_buffer.size() < dst_size) {
|
|
|
|
write_buffer.resize(dst_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Settings::IsGPULevelExtreme()) {
|
|
|
|
memory_manager.ReadBlock(source + offset, read_buffer.data(), src_size);
|
|
|
|
memory_manager.ReadBlock(dest, write_buffer.data(), dst_size);
|
|
|
|
} else {
|
|
|
|
memory_manager.ReadBlockUnsafe(source + offset, read_buffer.data(), src_size);
|
|
|
|
memory_manager.ReadBlockUnsafe(dest, write_buffer.data(), dst_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
Texture::UnswizzleSubrect(regs.x_count, regs.y_count, regs.dst_pitch,
|
|
|
|
regs.src_params.size_x, bytes_per_pixel, read_buffer.data(),
|
|
|
|
write_buffer.data(), regs.src_params.BlockHeight(), pos_x,
|
|
|
|
pos_y);
|
|
|
|
|
|
|
|
memory_manager.WriteBlock(dest, write_buffer.data(), dst_size);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2019-04-23 12:41:55 -04:00
|
|
|
// If the input is tiled and the output is linear, deswizzle the input and copy it over.
|
2019-07-24 19:18:17 -04:00
|
|
|
const u32 bytes_per_pixel = regs.dst_pitch / regs.x_count;
|
2019-04-23 12:41:55 -04:00
|
|
|
const std::size_t src_size = Texture::CalculateSize(
|
2019-07-24 19:18:17 -04:00
|
|
|
true, bytes_per_pixel, regs.src_params.size_x, regs.src_params.size_y,
|
2019-04-23 12:41:55 -04:00
|
|
|
regs.src_params.size_z, regs.src_params.BlockHeight(), regs.src_params.BlockDepth());
|
2018-10-17 21:29:10 -04:00
|
|
|
|
2019-07-24 19:18:17 -04:00
|
|
|
const std::size_t src_layer_size = Texture::CalculateSize(
|
|
|
|
true, bytes_per_pixel, regs.src_params.size_x, regs.src_params.size_y, 1,
|
|
|
|
regs.src_params.BlockHeight(), regs.src_params.BlockDepth());
|
|
|
|
|
2019-04-23 12:41:55 -04:00
|
|
|
const std::size_t dst_size = regs.dst_pitch * regs.y_count;
|
2019-02-24 00:15:35 -05:00
|
|
|
|
2019-04-23 12:41:55 -04:00
|
|
|
if (read_buffer.size() < src_size) {
|
|
|
|
read_buffer.resize(src_size);
|
|
|
|
}
|
2019-03-09 14:36:52 -05:00
|
|
|
|
2019-04-23 12:41:55 -04:00
|
|
|
if (write_buffer.size() < dst_size) {
|
|
|
|
write_buffer.resize(dst_size);
|
|
|
|
}
|
2019-03-09 14:36:52 -05:00
|
|
|
|
2020-04-19 13:27:56 -04:00
|
|
|
if (Settings::IsGPULevelExtreme()) {
|
|
|
|
memory_manager.ReadBlock(source, read_buffer.data(), src_size);
|
|
|
|
memory_manager.ReadBlock(dest, write_buffer.data(), dst_size);
|
|
|
|
} else {
|
|
|
|
memory_manager.ReadBlockUnsafe(source, read_buffer.data(), src_size);
|
|
|
|
memory_manager.ReadBlockUnsafe(dest, write_buffer.data(), dst_size);
|
|
|
|
}
|
2018-10-17 21:29:10 -04:00
|
|
|
|
2019-07-24 19:18:17 -04:00
|
|
|
Texture::UnswizzleSubrect(
|
|
|
|
regs.x_count, regs.y_count, regs.dst_pitch, regs.src_params.size_x, bytes_per_pixel,
|
|
|
|
read_buffer.data() + src_layer_size * regs.src_params.pos_z, write_buffer.data(),
|
|
|
|
regs.src_params.BlockHeight(), regs.src_params.pos_x, regs.src_params.pos_y);
|
2018-10-17 21:29:10 -04:00
|
|
|
|
2019-04-23 12:41:55 -04:00
|
|
|
memory_manager.WriteBlock(dest, write_buffer.data(), dst_size);
|
|
|
|
} else {
|
2019-06-14 16:40:04 -04:00
|
|
|
ASSERT(regs.dst_params.BlockDepth() == 0);
|
2018-10-17 21:29:10 -04:00
|
|
|
|
2019-07-24 19:18:17 -04:00
|
|
|
const u32 bytes_per_pixel = regs.src_pitch / regs.x_count;
|
2018-10-17 21:29:10 -04:00
|
|
|
|
2019-04-23 12:41:55 -04:00
|
|
|
const std::size_t dst_size = Texture::CalculateSize(
|
2019-07-24 19:18:17 -04:00
|
|
|
true, bytes_per_pixel, regs.dst_params.size_x, regs.dst_params.size_y,
|
2019-04-23 12:41:55 -04:00
|
|
|
regs.dst_params.size_z, regs.dst_params.BlockHeight(), regs.dst_params.BlockDepth());
|
2018-10-17 21:29:10 -04:00
|
|
|
|
2019-04-23 12:41:55 -04:00
|
|
|
const std::size_t dst_layer_size = Texture::CalculateSize(
|
2019-07-24 19:18:17 -04:00
|
|
|
true, bytes_per_pixel, regs.dst_params.size_x, regs.dst_params.size_y, 1,
|
2019-04-23 12:41:55 -04:00
|
|
|
regs.dst_params.BlockHeight(), regs.dst_params.BlockDepth());
|
2018-10-17 21:29:10 -04:00
|
|
|
|
2019-04-23 12:41:55 -04:00
|
|
|
const std::size_t src_size = regs.src_pitch * regs.y_count;
|
2018-10-17 21:29:10 -04:00
|
|
|
|
2019-04-23 12:41:55 -04:00
|
|
|
if (read_buffer.size() < src_size) {
|
|
|
|
read_buffer.resize(src_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write_buffer.size() < dst_size) {
|
|
|
|
write_buffer.resize(dst_size);
|
|
|
|
}
|
|
|
|
|
2020-02-18 15:51:42 -05:00
|
|
|
if (Settings::IsGPULevelExtreme()) {
|
2019-07-24 19:18:17 -04:00
|
|
|
memory_manager.ReadBlock(source, read_buffer.data(), src_size);
|
|
|
|
memory_manager.ReadBlock(dest, write_buffer.data(), dst_size);
|
|
|
|
} else {
|
|
|
|
memory_manager.ReadBlockUnsafe(source, read_buffer.data(), src_size);
|
|
|
|
memory_manager.ReadBlockUnsafe(dest, write_buffer.data(), dst_size);
|
|
|
|
}
|
2018-10-17 21:29:10 -04:00
|
|
|
|
2018-06-10 18:02:33 -04:00
|
|
|
// If the input is linear and the output is tiled, swizzle the input and copy it over.
|
2019-07-24 19:18:17 -04:00
|
|
|
Texture::SwizzleSubrect(
|
|
|
|
regs.x_count, regs.y_count, regs.src_pitch, regs.dst_params.size_x, bytes_per_pixel,
|
|
|
|
write_buffer.data() + dst_layer_size * regs.dst_params.pos_z, read_buffer.data(),
|
|
|
|
regs.dst_params.BlockHeight(), regs.dst_params.pos_x, regs.dst_params.pos_y);
|
2019-04-23 12:41:55 -04:00
|
|
|
|
|
|
|
memory_manager.WriteBlock(dest, write_buffer.data(), dst_size);
|
2018-06-10 18:02:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-20 15:58:06 -04:00
|
|
|
} // namespace Tegra::Engines
|