2019-04-22 22:50:56 +00:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-05-14 17:38:01 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
2019-04-22 22:50:56 +00:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "video_core/engines/engine_upload.h"
|
|
|
|
#include "video_core/memory_manager.h"
|
2022-01-29 21:00:49 +00:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2019-04-22 22:50:56 +00:00
|
|
|
#include "video_core/textures/decoders.h"
|
|
|
|
|
|
|
|
namespace Tegra::Engines::Upload {
|
|
|
|
|
2020-12-04 19:39:12 +00:00
|
|
|
State::State(MemoryManager& memory_manager_, Registers& regs_)
|
|
|
|
: regs{regs_}, memory_manager{memory_manager_} {}
|
2019-04-23 12:02:24 +00:00
|
|
|
|
2019-05-14 17:41:34 +00:00
|
|
|
State::~State() = default;
|
|
|
|
|
2022-01-29 21:00:49 +00:00
|
|
|
void State::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) {
|
|
|
|
rasterizer = rasterizer_;
|
|
|
|
}
|
|
|
|
|
2020-12-04 19:39:12 +00:00
|
|
|
void State::ProcessExec(const bool is_linear_) {
|
2019-04-22 22:50:56 +00:00
|
|
|
write_offset = 0;
|
|
|
|
copy_size = regs.line_length_in * regs.line_count;
|
|
|
|
inner_buffer.resize(copy_size);
|
2020-12-04 19:39:12 +00:00
|
|
|
is_linear = is_linear_;
|
2019-04-22 22:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void State::ProcessData(const u32 data, const bool is_last_call) {
|
|
|
|
const u32 sub_copy_size = std::min(4U, copy_size - write_offset);
|
|
|
|
std::memcpy(&inner_buffer[write_offset], &data, sub_copy_size);
|
|
|
|
write_offset += sub_copy_size;
|
2019-04-25 16:57:10 +00:00
|
|
|
if (!is_last_call) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const GPUVAddr address{regs.dest.Address()};
|
|
|
|
if (is_linear) {
|
2022-01-31 22:41:29 +00:00
|
|
|
rasterizer->AccelerateInlineToMemory(address, copy_size, inner_buffer);
|
2019-04-25 16:57:10 +00:00
|
|
|
} else {
|
|
|
|
UNIMPLEMENTED_IF(regs.dest.z != 0);
|
|
|
|
UNIMPLEMENTED_IF(regs.dest.depth != 1);
|
2019-05-11 04:38:35 +00:00
|
|
|
UNIMPLEMENTED_IF(regs.dest.BlockWidth() != 0);
|
|
|
|
UNIMPLEMENTED_IF(regs.dest.BlockDepth() != 0);
|
2019-04-25 16:57:10 +00:00
|
|
|
const std::size_t dst_size = Tegra::Texture::CalculateSize(
|
2019-06-13 20:41:16 +00:00
|
|
|
true, 1, regs.dest.width, regs.dest.height, 1, regs.dest.BlockHeight(), 0);
|
2019-04-25 16:57:10 +00:00
|
|
|
tmp_buffer.resize(dst_size);
|
|
|
|
memory_manager.ReadBlock(address, tmp_buffer.data(), dst_size);
|
|
|
|
Tegra::Texture::SwizzleKepler(regs.dest.width, regs.dest.height, regs.dest.x, regs.dest.y,
|
|
|
|
regs.dest.BlockHeight(), copy_size, inner_buffer.data(),
|
|
|
|
tmp_buffer.data());
|
|
|
|
memory_manager.WriteBlock(address, tmp_buffer.data(), dst_size);
|
2019-04-22 22:50:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Tegra::Engines::Upload
|