2018-02-12 02:34:20 +00:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-11-06 20:26:27 +00:00
|
|
|
#include "core/core.h"
|
2018-04-25 03:00:40 +00:00
|
|
|
#include "core/memory.h"
|
2018-02-12 02:34:20 +00:00
|
|
|
#include "video_core/engines/fermi_2d.h"
|
2018-11-06 20:26:27 +00:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2018-10-06 03:46:40 +00:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2018-04-25 03:00:40 +00:00
|
|
|
#include "video_core/textures/decoders.h"
|
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
|
|
|
|
2018-10-06 03:46:40 +00:00
|
|
|
Fermi2D::Fermi2D(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager)
|
|
|
|
: memory_manager(memory_manager), rasterizer{rasterizer} {}
|
2018-04-24 01:12:40 +00:00
|
|
|
|
2018-11-24 04:20:56 +00:00
|
|
|
void Fermi2D::CallMethod(const GPU::MethodCall& method_call) {
|
|
|
|
ASSERT_MSG(method_call.method < Regs::NUM_REGS,
|
2018-04-24 01:12:40 +00:00
|
|
|
"Invalid Fermi2D register, increase the size of the Regs structure");
|
2018-04-25 03:00:40 +00:00
|
|
|
|
2018-11-24 04:20:56 +00:00
|
|
|
regs.reg_array[method_call.method] = method_call.argument;
|
2018-04-25 03:00:40 +00:00
|
|
|
|
2018-11-24 04:20:56 +00:00
|
|
|
switch (method_call.method) {
|
2018-04-25 03:00:40 +00:00
|
|
|
case FERMI2D_REG_INDEX(trigger): {
|
|
|
|
HandleSurfaceCopy();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fermi2D::HandleSurfaceCopy() {
|
2018-07-02 16:13:26 +00:00
|
|
|
LOG_WARNING(HW_GPU, "Requested a surface copy with operation {}",
|
2018-07-02 16:20:50 +00:00
|
|
|
static_cast<u32>(regs.operation));
|
2018-04-25 03:00:40 +00:00
|
|
|
|
|
|
|
const GPUVAddr source = regs.src.Address();
|
|
|
|
const GPUVAddr dest = regs.dst.Address();
|
|
|
|
|
|
|
|
// TODO(Subv): Only same-format and same-size copies are allowed for now.
|
|
|
|
ASSERT(regs.src.format == regs.dst.format);
|
|
|
|
ASSERT(regs.src.width * regs.src.height == regs.dst.width * regs.dst.height);
|
|
|
|
|
|
|
|
// TODO(Subv): Only raw copies are implemented.
|
|
|
|
ASSERT(regs.operation == Regs::Operation::SrcCopy);
|
|
|
|
|
2019-01-22 06:47:56 +00:00
|
|
|
const auto source_cpu = memory_manager.GpuToCpuAddress(source);
|
|
|
|
const auto dest_cpu = memory_manager.GpuToCpuAddress(dest);
|
|
|
|
ASSERT_MSG(source_cpu, "Invalid source GPU address");
|
|
|
|
ASSERT_MSG(dest_cpu, "Invalid destination GPU address");
|
2018-04-25 03:00:40 +00:00
|
|
|
|
|
|
|
u32 src_bytes_per_pixel = RenderTargetBytesPerPixel(regs.src.format);
|
|
|
|
u32 dst_bytes_per_pixel = RenderTargetBytesPerPixel(regs.dst.format);
|
|
|
|
|
2018-10-06 03:46:40 +00:00
|
|
|
if (!rasterizer.AccelerateSurfaceCopy(regs.src, regs.dst)) {
|
2018-11-06 20:26:27 +00:00
|
|
|
// All copies here update the main memory, so mark all rasterizer states as invalid.
|
|
|
|
Core::System::GetInstance().GPU().Maxwell3D().dirty_flags.OnMemoryWrite();
|
|
|
|
|
2019-01-22 06:47:56 +00:00
|
|
|
rasterizer.FlushRegion(*source_cpu, src_bytes_per_pixel * regs.src.width * regs.src.height);
|
2018-10-18 00:32:29 +00:00
|
|
|
// We have to invalidate the destination region to evict any outdated surfaces from the
|
|
|
|
// cache. We do this before actually writing the new data because the destination address
|
|
|
|
// might contain a dirty surface that will have to be written back to memory.
|
2019-01-22 06:47:56 +00:00
|
|
|
rasterizer.InvalidateRegion(*dest_cpu,
|
2018-10-18 00:32:29 +00:00
|
|
|
dst_bytes_per_pixel * regs.dst.width * regs.dst.height);
|
2018-10-06 03:46:40 +00:00
|
|
|
|
|
|
|
if (regs.src.linear == regs.dst.linear) {
|
|
|
|
// If the input layout and the output layout are the same, just perform a raw copy.
|
|
|
|
ASSERT(regs.src.BlockHeight() == regs.dst.BlockHeight());
|
2019-01-22 06:47:56 +00:00
|
|
|
Memory::CopyBlock(*dest_cpu, *source_cpu,
|
2018-10-06 03:46:40 +00:00
|
|
|
src_bytes_per_pixel * regs.dst.width * regs.dst.height);
|
|
|
|
return;
|
|
|
|
}
|
2019-01-22 06:47:56 +00:00
|
|
|
u8* src_buffer = Memory::GetPointer(*source_cpu);
|
|
|
|
u8* dst_buffer = Memory::GetPointer(*dest_cpu);
|
2018-10-06 03:46:40 +00:00
|
|
|
if (!regs.src.linear && regs.dst.linear) {
|
|
|
|
// If the input is tiled and the output is linear, deswizzle the input and copy it over.
|
2018-10-11 23:11:47 +00:00
|
|
|
Texture::CopySwizzledData(regs.src.width, regs.src.height, regs.src.depth,
|
|
|
|
src_bytes_per_pixel, dst_bytes_per_pixel, src_buffer,
|
|
|
|
dst_buffer, true, regs.src.BlockHeight(),
|
2018-11-16 17:01:54 +00:00
|
|
|
regs.src.BlockDepth(), 0);
|
2018-10-06 03:46:40 +00:00
|
|
|
} else {
|
|
|
|
// If the input is linear and the output is tiled, swizzle the input and copy it over.
|
2018-10-11 23:11:47 +00:00
|
|
|
Texture::CopySwizzledData(regs.src.width, regs.src.height, regs.src.depth,
|
|
|
|
src_bytes_per_pixel, dst_bytes_per_pixel, dst_buffer,
|
|
|
|
src_buffer, false, regs.dst.BlockHeight(),
|
2018-11-16 17:01:54 +00:00
|
|
|
regs.dst.BlockDepth(), 0);
|
2018-10-06 03:46:40 +00:00
|
|
|
}
|
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
|