mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-14 05:55:13 +01:00
Merge pull request #2809 from wwylele/texture-copy-fix
gpu: fix edge cases for TextureCopy
This commit is contained in:
commit
686fde7e52
@ -5,6 +5,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include "common/alignment.h"
|
||||||
#include "common/color.h"
|
#include "common/color.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
@ -313,7 +314,7 @@ static void TextureCopy(const Regs::DisplayTransferConfig& config) {
|
|||||||
const PAddr src_addr = config.GetPhysicalInputAddress();
|
const PAddr src_addr = config.GetPhysicalInputAddress();
|
||||||
const PAddr dst_addr = config.GetPhysicalOutputAddress();
|
const PAddr dst_addr = config.GetPhysicalOutputAddress();
|
||||||
|
|
||||||
// TODO: do hwtest with these cases
|
// TODO: do hwtest with invalid addresses
|
||||||
if (!Memory::IsValidPhysicalAddress(src_addr)) {
|
if (!Memory::IsValidPhysicalAddress(src_addr)) {
|
||||||
LOG_CRITICAL(HW_GPU, "invalid input address 0x%08X", src_addr);
|
LOG_CRITICAL(HW_GPU, "invalid input address 0x%08X", src_addr);
|
||||||
return;
|
return;
|
||||||
@ -324,32 +325,37 @@ static void TextureCopy(const Regs::DisplayTransferConfig& config) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.texture_copy.input_width == 0) {
|
|
||||||
LOG_CRITICAL(HW_GPU, "zero input width");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.texture_copy.output_width == 0) {
|
|
||||||
LOG_CRITICAL(HW_GPU, "zero output width");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.texture_copy.size == 0) {
|
|
||||||
LOG_CRITICAL(HW_GPU, "zero size");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VideoCore::g_renderer->Rasterizer()->AccelerateTextureCopy(config))
|
if (VideoCore::g_renderer->Rasterizer()->AccelerateTextureCopy(config))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
u8* src_pointer = Memory::GetPhysicalPointer(src_addr);
|
u8* src_pointer = Memory::GetPhysicalPointer(src_addr);
|
||||||
u8* dst_pointer = Memory::GetPhysicalPointer(dst_addr);
|
u8* dst_pointer = Memory::GetPhysicalPointer(dst_addr);
|
||||||
|
|
||||||
u32 input_width = config.texture_copy.input_width * 16;
|
u32 remaining_size = Common::AlignDown(config.texture_copy.size, 16);
|
||||||
|
|
||||||
|
if (remaining_size == 0) {
|
||||||
|
LOG_CRITICAL(HW_GPU, "zero size. Real hardware freezes on this.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
u32 input_gap = config.texture_copy.input_gap * 16;
|
u32 input_gap = config.texture_copy.input_gap * 16;
|
||||||
u32 output_width = config.texture_copy.output_width * 16;
|
|
||||||
u32 output_gap = config.texture_copy.output_gap * 16;
|
u32 output_gap = config.texture_copy.output_gap * 16;
|
||||||
|
|
||||||
|
// Zero gap means contiguous input/output even if width = 0. To avoid infinite loop below, width
|
||||||
|
// is assigned with the total size if gap = 0.
|
||||||
|
u32 input_width = input_gap == 0 ? remaining_size : config.texture_copy.input_width * 16;
|
||||||
|
u32 output_width = output_gap == 0 ? remaining_size : config.texture_copy.output_width * 16;
|
||||||
|
|
||||||
|
if (input_width == 0) {
|
||||||
|
LOG_CRITICAL(HW_GPU, "zero input width. Real hardware freezes on this.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (output_width == 0) {
|
||||||
|
LOG_CRITICAL(HW_GPU, "zero output width. Real hardware freezes on this.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
size_t contiguous_input_size =
|
size_t contiguous_input_size =
|
||||||
config.texture_copy.size / input_width * (input_width + input_gap);
|
config.texture_copy.size / input_width * (input_width + input_gap);
|
||||||
Memory::RasterizerFlushRegion(config.GetPhysicalInputAddress(),
|
Memory::RasterizerFlushRegion(config.GetPhysicalInputAddress(),
|
||||||
@ -360,7 +366,6 @@ static void TextureCopy(const Regs::DisplayTransferConfig& config) {
|
|||||||
Memory::RasterizerFlushAndInvalidateRegion(config.GetPhysicalOutputAddress(),
|
Memory::RasterizerFlushAndInvalidateRegion(config.GetPhysicalOutputAddress(),
|
||||||
static_cast<u32>(contiguous_output_size));
|
static_cast<u32>(contiguous_output_size));
|
||||||
|
|
||||||
u32 remaining_size = config.texture_copy.size;
|
|
||||||
u32 remaining_input = input_width;
|
u32 remaining_input = input_width;
|
||||||
u32 remaining_output = output_width;
|
u32 remaining_output = output_width;
|
||||||
while (remaining_size > 0) {
|
while (remaining_size > 0) {
|
||||||
|
@ -225,7 +225,7 @@ struct Regs {
|
|||||||
INSERT_PADDING_WORDS(0x1);
|
INSERT_PADDING_WORDS(0x1);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
u32 size;
|
u32 size; // The lower 4 bits are ignored
|
||||||
|
|
||||||
union {
|
union {
|
||||||
u32 input_size;
|
u32 input_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user