2018-02-12 03:34:20 +01:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-03-06 02:25:01 +01:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/logging/log.h"
|
2018-02-12 03:34:20 +01:00
|
|
|
#include "video_core/engines/fermi_2d.h"
|
2019-04-06 00:21:15 +02:00
|
|
|
#include "video_core/memory_manager.h"
|
2018-10-06 05:46:40 +02:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2018-07-21 00:14:17 +02:00
|
|
|
namespace Tegra::Engines {
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2020-06-11 05:58:57 +02:00
|
|
|
Fermi2D::Fermi2D() = default;
|
|
|
|
|
|
|
|
Fermi2D::~Fermi2D() = default;
|
|
|
|
|
|
|
|
void Fermi2D::BindRasterizer(VideoCore::RasterizerInterface& rasterizer_) {
|
|
|
|
rasterizer = &rasterizer_;
|
|
|
|
}
|
2018-04-24 03:12:40 +02:00
|
|
|
|
2020-04-28 03:47:58 +02:00
|
|
|
void Fermi2D::CallMethod(u32 method, u32 method_argument, bool is_last_call) {
|
|
|
|
ASSERT_MSG(method < Regs::NUM_REGS,
|
2018-04-24 03:12:40 +02:00
|
|
|
"Invalid Fermi2D register, increase the size of the Regs structure");
|
2018-04-25 05:00:40 +02:00
|
|
|
|
2020-04-28 03:47:58 +02:00
|
|
|
regs.reg_array[method] = method_argument;
|
2018-04-25 05:00:40 +02:00
|
|
|
|
2020-04-28 03:47:58 +02:00
|
|
|
switch (method) {
|
2018-12-15 06:20:00 +01:00
|
|
|
// Trigger the surface copy on the last register write. This is blit_src_y, but this is 64-bit,
|
|
|
|
// so trigger on the second 32-bit write.
|
|
|
|
case FERMI2D_REG_INDEX(blit_src_y) + 1: {
|
2018-04-25 05:00:40 +02:00
|
|
|
HandleSurfaceCopy();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-20 08:16:56 +02:00
|
|
|
void Fermi2D::CallMultiMethod(u32 method, const u32* base_start, u32 amount, u32 methods_pending) {
|
|
|
|
for (std::size_t i = 0; i < amount; i++) {
|
2020-04-28 03:47:58 +02:00
|
|
|
CallMethod(method, base_start[i], methods_pending - static_cast<u32>(i) <= 1);
|
2020-04-20 08:16:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-17 04:43:33 +02:00
|
|
|
static std::pair<u32, u32> DelimitLine(u32 src_1, u32 src_2, u32 dst_1, u32 dst_2, u32 src_line) {
|
2019-10-18 00:21:01 +02:00
|
|
|
const u32 line_a = src_2 - src_1;
|
|
|
|
const u32 line_b = dst_2 - dst_1;
|
|
|
|
const u32 excess = std::max<s32>(0, line_a - src_line + src_1);
|
|
|
|
return {line_b - (excess * line_b) / line_a, excess};
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:00:40 +02:00
|
|
|
void Fermi2D::HandleSurfaceCopy() {
|
2020-12-07 06:41:47 +01:00
|
|
|
LOG_DEBUG(HW_GPU, "Requested a surface copy with operation {}", regs.operation);
|
2018-04-25 05:00:40 +02:00
|
|
|
|
|
|
|
// TODO(Subv): Only raw copies are implemented.
|
2019-05-18 10:57:49 +02:00
|
|
|
ASSERT(regs.operation == Operation::SrcCopy);
|
2018-04-25 05:00:40 +02:00
|
|
|
|
2018-12-15 06:20:00 +01:00
|
|
|
const u32 src_blit_x1{static_cast<u32>(regs.blit_src_x >> 32)};
|
|
|
|
const u32 src_blit_y1{static_cast<u32>(regs.blit_src_y >> 32)};
|
2019-06-12 22:20:20 +02:00
|
|
|
u32 src_blit_x2, src_blit_y2;
|
|
|
|
if (regs.blit_control.origin == Origin::Corner) {
|
|
|
|
src_blit_x2 =
|
|
|
|
static_cast<u32>((regs.blit_src_x + (regs.blit_du_dx * regs.blit_dst_width)) >> 32);
|
|
|
|
src_blit_y2 =
|
|
|
|
static_cast<u32>((regs.blit_src_y + (regs.blit_dv_dy * regs.blit_dst_height)) >> 32);
|
|
|
|
} else {
|
|
|
|
src_blit_x2 = static_cast<u32>((regs.blit_src_x >> 32) + regs.blit_dst_width);
|
|
|
|
src_blit_y2 = static_cast<u32>((regs.blit_src_y >> 32) + regs.blit_dst_height);
|
|
|
|
}
|
2019-10-18 00:21:01 +02:00
|
|
|
u32 dst_blit_x2 = regs.blit_dst_x + regs.blit_dst_width;
|
|
|
|
u32 dst_blit_y2 = regs.blit_dst_y + regs.blit_dst_height;
|
|
|
|
const auto [new_dst_w, src_excess_x] =
|
|
|
|
DelimitLine(src_blit_x1, src_blit_x2, regs.blit_dst_x, dst_blit_x2, regs.src.width);
|
|
|
|
const auto [new_dst_h, src_excess_y] =
|
|
|
|
DelimitLine(src_blit_y1, src_blit_y2, regs.blit_dst_y, dst_blit_y2, regs.src.height);
|
|
|
|
dst_blit_x2 = new_dst_w + regs.blit_dst_x;
|
|
|
|
src_blit_x2 = src_blit_x2 - src_excess_x;
|
|
|
|
dst_blit_y2 = new_dst_h + regs.blit_dst_y;
|
|
|
|
src_blit_y2 = src_blit_y2 - src_excess_y;
|
|
|
|
const auto [new_src_w, dst_excess_x] =
|
|
|
|
DelimitLine(regs.blit_dst_x, dst_blit_x2, src_blit_x1, src_blit_x2, regs.dst.width);
|
|
|
|
const auto [new_src_h, dst_excess_y] =
|
|
|
|
DelimitLine(regs.blit_dst_y, dst_blit_y2, src_blit_y1, src_blit_y2, regs.dst.height);
|
|
|
|
src_blit_x2 = new_src_w + src_blit_x1;
|
|
|
|
dst_blit_x2 = dst_blit_x2 - dst_excess_x;
|
|
|
|
src_blit_y2 = new_src_h + src_blit_y1;
|
|
|
|
dst_blit_y2 = dst_blit_y2 - dst_excess_y;
|
|
|
|
const Common::Rectangle<u32> src_rect{src_blit_x1, src_blit_y1, src_blit_x2, src_blit_y2};
|
|
|
|
const Common::Rectangle<u32> dst_rect{regs.blit_dst_x, regs.blit_dst_y, dst_blit_x2,
|
|
|
|
dst_blit_y2};
|
2020-09-18 19:55:18 +02:00
|
|
|
const Config copy_config{
|
|
|
|
.operation = regs.operation,
|
|
|
|
.filter = regs.blit_control.filter,
|
|
|
|
.src_rect = src_rect,
|
|
|
|
.dst_rect = dst_rect,
|
|
|
|
};
|
2020-06-11 05:58:57 +02:00
|
|
|
if (!rasterizer->AccelerateSurfaceCopy(regs.src, regs.dst, copy_config)) {
|
2018-12-15 06:20:00 +01:00
|
|
|
UNIMPLEMENTED();
|
2018-04-25 05:00:40 +02:00
|
|
|
}
|
2018-04-24 03:12:40 +02:00
|
|
|
}
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2018-07-21 00:14:17 +02:00
|
|
|
} // namespace Tegra::Engines
|