2018-09-08 22:58:20 +02:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-02-16 04:05:17 +01:00
|
|
|
#include "common/assert.h"
|
2018-09-08 22:58:20 +02:00
|
|
|
#include "common/logging/log.h"
|
2018-11-06 21:26:27 +01:00
|
|
|
#include "core/core.h"
|
2018-09-08 22:58:20 +02:00
|
|
|
#include "video_core/engines/kepler_memory.h"
|
2018-11-06 21:26:27 +01:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2019-04-06 00:21:15 +02:00
|
|
|
#include "video_core/memory_manager.h"
|
2018-10-18 02:44:07 +02:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2019-02-19 02:58:32 +01:00
|
|
|
#include "video_core/renderer_base.h"
|
2019-04-15 18:43:37 +02:00
|
|
|
#include "video_core/textures/convert.h"
|
|
|
|
#include "video_core/textures/decoders.h"
|
2018-09-08 22:58:20 +02:00
|
|
|
|
|
|
|
namespace Tegra::Engines {
|
|
|
|
|
2019-02-16 04:05:17 +01:00
|
|
|
KeplerMemory::KeplerMemory(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
|
2018-10-18 02:44:07 +02:00
|
|
|
MemoryManager& memory_manager)
|
2019-04-06 00:25:20 +02:00
|
|
|
: system{system}, rasterizer{rasterizer}, memory_manager{memory_manager} {}
|
2018-10-18 02:44:07 +02:00
|
|
|
|
2018-09-08 22:58:20 +02:00
|
|
|
KeplerMemory::~KeplerMemory() = default;
|
|
|
|
|
2018-11-24 05:20:56 +01:00
|
|
|
void KeplerMemory::CallMethod(const GPU::MethodCall& method_call) {
|
|
|
|
ASSERT_MSG(method_call.method < Regs::NUM_REGS,
|
2018-09-08 22:58:20 +02:00
|
|
|
"Invalid KeplerMemory register, increase the size of the Regs structure");
|
|
|
|
|
2018-11-24 05:20:56 +01:00
|
|
|
regs.reg_array[method_call.method] = method_call.argument;
|
2018-09-08 22:58:20 +02:00
|
|
|
|
2018-11-24 05:20:56 +01:00
|
|
|
switch (method_call.method) {
|
2018-09-08 22:58:20 +02:00
|
|
|
case KEPLERMEMORY_REG_INDEX(exec): {
|
2019-04-15 18:43:37 +02:00
|
|
|
ProcessExec();
|
2018-09-08 22:58:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEPLERMEMORY_REG_INDEX(data): {
|
2019-04-15 18:43:37 +02:00
|
|
|
ProcessData(method_call.argument, method_call.IsLastCall());
|
2018-09-08 22:58:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 18:43:37 +02:00
|
|
|
void KeplerMemory::ProcessExec() {
|
|
|
|
state.write_offset = 0;
|
|
|
|
state.copy_size = regs.line_length_in * regs.line_count;
|
|
|
|
state.inner_buffer.resize(state.copy_size);
|
|
|
|
}
|
2018-10-18 02:44:07 +02:00
|
|
|
|
2019-04-15 18:43:37 +02:00
|
|
|
void KeplerMemory::ProcessData(u32 data, bool is_last_call) {
|
|
|
|
const u32 sub_copy_size = std::min(4U, state.copy_size - state.write_offset);
|
|
|
|
std::memcpy(&state.inner_buffer[state.write_offset], &data, sub_copy_size);
|
|
|
|
state.write_offset += sub_copy_size;
|
|
|
|
if (is_last_call) {
|
|
|
|
UNIMPLEMENTED_IF_MSG(regs.exec.linear == 0, "Block Linear Copy is not implemented");
|
|
|
|
if (regs.exec.linear != 0) {
|
|
|
|
const GPUVAddr address{regs.dest.Address()};
|
|
|
|
const auto host_ptr = memory_manager.GetPointer(address);
|
|
|
|
// 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.
|
2018-09-08 22:58:20 +02:00
|
|
|
|
2019-04-15 18:43:37 +02:00
|
|
|
rasterizer.InvalidateRegion(ToCacheAddr(host_ptr), state.copy_size);
|
|
|
|
std::memcpy(host_ptr, state.inner_buffer.data(), state.copy_size);
|
|
|
|
system.GPU().Maxwell3D().dirty_flags.OnMemoryWrite();
|
|
|
|
}
|
|
|
|
}
|
2018-09-08 22:58:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Tegra::Engines
|