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 "core/memory.h"
|
|
|
|
#include "video_core/engines/kepler_memory.h"
|
2018-11-06 21:26:27 +01:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2018-10-18 02:44:07 +02:00
|
|
|
#include "video_core/rasterizer_interface.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-02-16 04:05:17 +01:00
|
|
|
: system{system}, memory_manager(memory_manager), rasterizer{rasterizer} {}
|
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): {
|
|
|
|
state.write_offset = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEPLERMEMORY_REG_INDEX(data): {
|
2018-11-24 05:20:56 +01:00
|
|
|
ProcessData(method_call.argument);
|
2018-09-08 22:58:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeplerMemory::ProcessData(u32 data) {
|
|
|
|
ASSERT_MSG(regs.exec.linear, "Non-linear uploads are not supported");
|
|
|
|
ASSERT(regs.dest.x == 0 && regs.dest.y == 0 && regs.dest.z == 0);
|
|
|
|
|
2019-01-22 07:47:56 +01:00
|
|
|
const GPUVAddr address = regs.dest.Address();
|
|
|
|
const auto dest_address =
|
|
|
|
memory_manager.GpuToCpuAddress(address + state.write_offset * sizeof(u32));
|
|
|
|
ASSERT_MSG(dest_address, "Invalid GPU address");
|
2018-09-08 22:58:20 +02:00
|
|
|
|
2018-10-18 02:44:07 +02: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 07:47:56 +01:00
|
|
|
rasterizer.InvalidateRegion(*dest_address, sizeof(u32));
|
2018-10-18 02:44:07 +02:00
|
|
|
|
2019-01-22 07:47:56 +01:00
|
|
|
Memory::Write32(*dest_address, data);
|
2019-02-16 04:05:17 +01:00
|
|
|
system.GPU().Maxwell3D().dirty_flags.OnMemoryWrite();
|
2018-09-08 22:58:20 +02:00
|
|
|
|
|
|
|
state.write_offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Tegra::Engines
|