2022-04-23 08:59:50 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-02-12 02:34:20 +00:00
|
|
|
|
2019-03-06 01:25:01 +00:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/logging/log.h"
|
2022-11-05 21:26:38 +00:00
|
|
|
#include "common/microprofile.h"
|
2018-02-12 02:34:20 +00:00
|
|
|
#include "video_core/engines/fermi_2d.h"
|
2022-11-05 21:26:38 +00:00
|
|
|
#include "video_core/engines/sw_blitter/blitter.h"
|
2023-01-05 11:43:28 +00:00
|
|
|
#include "video_core/memory_manager.h"
|
2018-10-06 03:46:40 +00:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2021-07-08 18:06:09 +00:00
|
|
|
#include "video_core/surface.h"
|
2022-11-05 21:26:38 +00:00
|
|
|
#include "video_core/textures/decoders.h"
|
|
|
|
|
|
|
|
MICROPROFILE_DECLARE(GPU_BlitEngine);
|
|
|
|
MICROPROFILE_DEFINE(GPU_BlitEngine, "GPU", "Blit Engine", MP_RGB(224, 224, 128));
|
2021-07-08 18:06:09 +00:00
|
|
|
|
|
|
|
using VideoCore::Surface::BytesPerBlock;
|
|
|
|
using VideoCore::Surface::PixelFormatFromRenderTargetFormat;
|
2018-02-12 02:34:20 +00:00
|
|
|
|
2018-07-20 22:14:17 +00:00
|
|
|
namespace Tegra::Engines {
|
2018-02-12 02:34:20 +00:00
|
|
|
|
2022-11-05 21:26:38 +00:00
|
|
|
using namespace Texture;
|
|
|
|
|
2023-01-05 11:43:28 +00:00
|
|
|
Fermi2D::Fermi2D(MemoryManager& memory_manager_) : memory_manager{memory_manager_} {
|
|
|
|
sw_blitter = std::make_unique<Blitter::SoftwareBlitEngine>(memory_manager);
|
2020-12-30 05:25:23 +00:00
|
|
|
// Nvidia's OpenGL driver seems to assume these values
|
|
|
|
regs.src.depth = 1;
|
|
|
|
regs.dst.depth = 1;
|
2022-11-26 23:58:06 +00:00
|
|
|
|
|
|
|
execution_mask.reset();
|
|
|
|
execution_mask[FERMI2D_REG_INDEX(pixels_from_memory.src_y0) + 1] = true;
|
2020-12-30 05:25:23 +00:00
|
|
|
}
|
2020-06-11 03:58:57 +00:00
|
|
|
|
|
|
|
Fermi2D::~Fermi2D() = default;
|
|
|
|
|
2021-01-05 07:09:39 +00:00
|
|
|
void Fermi2D::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) {
|
|
|
|
rasterizer = rasterizer_;
|
2020-06-11 03:58:57 +00:00
|
|
|
}
|
2018-04-24 01:12:40 +00:00
|
|
|
|
2020-04-28 01:47:58 +00:00
|
|
|
void Fermi2D::CallMethod(u32 method, u32 method_argument, bool is_last_call) {
|
|
|
|
ASSERT_MSG(method < Regs::NUM_REGS,
|
2018-04-24 01:12:40 +00:00
|
|
|
"Invalid Fermi2D register, increase the size of the Regs structure");
|
2020-04-28 01:47:58 +00:00
|
|
|
regs.reg_array[method] = method_argument;
|
2018-04-25 03:00:40 +00:00
|
|
|
|
2020-12-30 05:25:23 +00:00
|
|
|
if (method == FERMI2D_REG_INDEX(pixels_from_memory.src_y0) + 1) {
|
|
|
|
Blit();
|
2018-04-25 03:00:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-20 06:16:56 +00:00
|
|
|
void Fermi2D::CallMultiMethod(u32 method, const u32* base_start, u32 amount, u32 methods_pending) {
|
2020-12-30 05:25:23 +00:00
|
|
|
for (u32 i = 0; i < amount; ++i) {
|
|
|
|
CallMethod(method, base_start[i], methods_pending - i <= 1);
|
2020-04-20 06:16:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 23:58:06 +00:00
|
|
|
void Fermi2D::ConsumeSinkImpl() {
|
|
|
|
for (auto [method, value] : method_sink) {
|
|
|
|
regs.reg_array[method] = value;
|
|
|
|
}
|
|
|
|
method_sink.clear();
|
|
|
|
}
|
|
|
|
|
2020-12-30 05:25:23 +00:00
|
|
|
void Fermi2D::Blit() {
|
2022-11-05 21:26:38 +00:00
|
|
|
MICROPROFILE_SCOPE(GPU_BlitEngine);
|
2020-12-30 05:25:23 +00:00
|
|
|
LOG_DEBUG(HW_GPU, "called. source address=0x{:x}, destination address=0x{:x}",
|
|
|
|
regs.src.Address(), regs.dst.Address());
|
2018-04-25 03:00:40 +00:00
|
|
|
|
2020-12-30 05:25:23 +00:00
|
|
|
UNIMPLEMENTED_IF_MSG(regs.operation != Operation::SrcCopy, "Operation is not copy");
|
|
|
|
UNIMPLEMENTED_IF_MSG(regs.src.layer != 0, "Source layer is not zero");
|
|
|
|
UNIMPLEMENTED_IF_MSG(regs.dst.layer != 0, "Destination layer is not zero");
|
|
|
|
UNIMPLEMENTED_IF_MSG(regs.src.depth != 1, "Source depth is not one");
|
|
|
|
UNIMPLEMENTED_IF_MSG(regs.clip_enable != 0, "Clipped blit enabled");
|
2018-04-25 03:00:40 +00:00
|
|
|
|
2020-12-30 05:25:23 +00:00
|
|
|
const auto& args = regs.pixels_from_memory;
|
2022-11-05 21:26:38 +00:00
|
|
|
constexpr s64 null_derivate = 1ULL << 32;
|
2022-11-06 10:08:22 +00:00
|
|
|
Surface src = regs.src;
|
|
|
|
const auto bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(src.format));
|
|
|
|
const bool delegate_to_gpu = src.width > 512 && src.height > 512 && bytes_per_pixel <= 8 &&
|
|
|
|
src.format != regs.dst.format;
|
2021-07-08 18:06:09 +00:00
|
|
|
Config config{
|
2020-09-18 17:55:18 +00:00
|
|
|
.operation = regs.operation,
|
2020-12-30 05:25:23 +00:00
|
|
|
.filter = args.sample_mode.filter,
|
2022-11-06 10:08:22 +00:00
|
|
|
.must_accelerate =
|
|
|
|
args.du_dx != null_derivate || args.dv_dy != null_derivate || delegate_to_gpu,
|
2020-12-30 05:25:23 +00:00
|
|
|
.dst_x0 = args.dst_x0,
|
|
|
|
.dst_y0 = args.dst_y0,
|
|
|
|
.dst_x1 = args.dst_x0 + args.dst_width,
|
|
|
|
.dst_y1 = args.dst_y0 + args.dst_height,
|
|
|
|
.src_x0 = static_cast<s32>(args.src_x0 >> 32),
|
|
|
|
.src_y0 = static_cast<s32>(args.src_y0 >> 32),
|
|
|
|
.src_x1 = static_cast<s32>((args.du_dx * args.dst_width + args.src_x0) >> 32),
|
|
|
|
.src_y1 = static_cast<s32>((args.dv_dy * args.dst_height + args.src_y0) >> 32),
|
2020-09-18 17:55:18 +00:00
|
|
|
};
|
2022-11-06 10:08:22 +00:00
|
|
|
|
2021-07-08 18:06:09 +00:00
|
|
|
const auto need_align_to_pitch =
|
|
|
|
src.linear == Tegra::Engines::Fermi2D::MemoryLayout::Pitch &&
|
|
|
|
static_cast<s32>(src.width) == config.src_x1 &&
|
|
|
|
config.src_x1 > static_cast<s32>(src.pitch / bytes_per_pixel) && config.src_x0 > 0;
|
|
|
|
if (need_align_to_pitch) {
|
|
|
|
auto address = src.Address() + config.src_x0 * bytes_per_pixel;
|
|
|
|
src.addr_upper = static_cast<u32>(address >> 32);
|
|
|
|
src.addr_lower = static_cast<u32>(address);
|
|
|
|
src.width -= config.src_x0;
|
|
|
|
config.src_x1 -= config.src_x0;
|
|
|
|
config.src_x0 = 0;
|
|
|
|
}
|
2022-11-05 21:26:38 +00:00
|
|
|
|
2023-01-05 11:43:28 +00:00
|
|
|
memory_manager.FlushCaching();
|
2021-07-08 18:06:09 +00:00
|
|
|
if (!rasterizer->AccelerateSurfaceCopy(src, regs.dst, config)) {
|
2022-11-05 21:26:38 +00:00
|
|
|
sw_blitter->Blit(src, regs.dst, config);
|
2018-04-25 03:00:40 +00:00
|
|
|
}
|
2018-04-24 01:12:40 +00:00
|
|
|
}
|
2018-02-12 02:34:20 +00:00
|
|
|
|
2018-07-20 22:14:17 +00:00
|
|
|
} // namespace Tegra::Engines
|