2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-02-13 00:52:07 +00:00
|
|
|
|
|
|
|
#include "VideoCommon/VertexLoaderARM64.h"
|
2021-02-08 23:22:10 +00:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2021-06-20 20:47:57 +00:00
|
|
|
#include "VideoCommon/CPMemory.h"
|
2015-05-29 12:42:45 +00:00
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
2015-02-13 00:52:07 +00:00
|
|
|
|
|
|
|
using namespace Arm64Gen;
|
|
|
|
|
2021-02-06 18:50:33 +00:00
|
|
|
constexpr ARM64Reg src_reg = ARM64Reg::X0;
|
|
|
|
constexpr ARM64Reg dst_reg = ARM64Reg::X1;
|
2022-04-14 19:01:57 +00:00
|
|
|
constexpr ARM64Reg remaining_reg = ARM64Reg::W2;
|
2021-02-06 18:50:33 +00:00
|
|
|
constexpr ARM64Reg skipped_reg = ARM64Reg::W17;
|
|
|
|
constexpr ARM64Reg scratch1_reg = ARM64Reg::W16;
|
|
|
|
constexpr ARM64Reg scratch2_reg = ARM64Reg::W15;
|
|
|
|
constexpr ARM64Reg scratch3_reg = ARM64Reg::W14;
|
|
|
|
constexpr ARM64Reg saved_count = ARM64Reg::W12;
|
|
|
|
|
|
|
|
constexpr ARM64Reg stride_reg = ARM64Reg::X11;
|
|
|
|
constexpr ARM64Reg arraybase_reg = ARM64Reg::X10;
|
|
|
|
constexpr ARM64Reg scale_reg = ARM64Reg::X9;
|
2015-02-13 00:52:07 +00:00
|
|
|
|
2021-03-11 23:57:54 +00:00
|
|
|
static constexpr int GetLoadSize(int load_bytes)
|
|
|
|
{
|
|
|
|
if (load_bytes == 1)
|
|
|
|
return 1;
|
|
|
|
else if (load_bytes <= 2)
|
|
|
|
return 2;
|
|
|
|
else if (load_bytes <= 4)
|
|
|
|
return 4;
|
|
|
|
else if (load_bytes <= 8)
|
|
|
|
return 8;
|
|
|
|
else
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
|
2015-09-05 15:44:21 +00:00
|
|
|
alignas(16) static const float scale_factors[] = {
|
2015-02-13 00:52:07 +00:00
|
|
|
1.0 / (1ULL << 0), 1.0 / (1ULL << 1), 1.0 / (1ULL << 2), 1.0 / (1ULL << 3),
|
|
|
|
1.0 / (1ULL << 4), 1.0 / (1ULL << 5), 1.0 / (1ULL << 6), 1.0 / (1ULL << 7),
|
|
|
|
1.0 / (1ULL << 8), 1.0 / (1ULL << 9), 1.0 / (1ULL << 10), 1.0 / (1ULL << 11),
|
|
|
|
1.0 / (1ULL << 12), 1.0 / (1ULL << 13), 1.0 / (1ULL << 14), 1.0 / (1ULL << 15),
|
|
|
|
1.0 / (1ULL << 16), 1.0 / (1ULL << 17), 1.0 / (1ULL << 18), 1.0 / (1ULL << 19),
|
|
|
|
1.0 / (1ULL << 20), 1.0 / (1ULL << 21), 1.0 / (1ULL << 22), 1.0 / (1ULL << 23),
|
|
|
|
1.0 / (1ULL << 24), 1.0 / (1ULL << 25), 1.0 / (1ULL << 26), 1.0 / (1ULL << 27),
|
|
|
|
1.0 / (1ULL << 28), 1.0 / (1ULL << 29), 1.0 / (1ULL << 30), 1.0 / (1ULL << 31),
|
|
|
|
};
|
|
|
|
|
|
|
|
VertexLoaderARM64::VertexLoaderARM64(const TVtxDesc& vtx_desc, const VAT& vtx_att)
|
|
|
|
: VertexLoaderBase(vtx_desc, vtx_att), m_float_emit(this)
|
|
|
|
{
|
|
|
|
AllocCodeSpace(4096);
|
2021-05-15 14:10:10 +00:00
|
|
|
const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes;
|
2015-02-13 00:52:07 +00:00
|
|
|
ClearCodeSpace();
|
|
|
|
GenerateVertexLoader();
|
2023-09-30 15:32:51 +00:00
|
|
|
WriteProtect(true);
|
2015-02-13 00:52:07 +00:00
|
|
|
}
|
|
|
|
|
2022-07-15 20:22:58 +00:00
|
|
|
// Returns the register to use as the base and an offset from that register.
|
|
|
|
// For indexed attributes, the index is read into scratch1_reg, and then scratch1_reg with no offset
|
|
|
|
// is returned. For direct attributes, an offset from src_reg is returned.
|
|
|
|
std::pair<Arm64Gen::ARM64Reg, u32> VertexLoaderARM64::GetVertexAddr(CPArray array,
|
|
|
|
VertexComponentFormat attribute)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
if (IsIndexed(attribute))
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
if (attribute == VertexComponentFormat::Index8)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2022-07-15 03:02:55 +00:00
|
|
|
LDURB(scratch1_reg, src_reg, m_src_ofs);
|
2015-02-13 00:52:07 +00:00
|
|
|
m_src_ofs += 1;
|
|
|
|
}
|
2022-07-15 03:02:55 +00:00
|
|
|
else // Index16
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2022-07-15 03:02:55 +00:00
|
|
|
LDURH(scratch1_reg, src_reg, m_src_ofs);
|
2015-02-13 00:52:07 +00:00
|
|
|
m_src_ofs += 2;
|
|
|
|
REV16(scratch1_reg, scratch1_reg);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-06-20 20:47:57 +00:00
|
|
|
if (array == CPArray::Position)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2021-07-12 10:05:34 +00:00
|
|
|
EOR(scratch2_reg, scratch1_reg,
|
2023-12-16 12:27:13 +00:00
|
|
|
attribute == VertexComponentFormat::Index8 ? LogicalImm(0xFF, GPRSize::B32) :
|
|
|
|
LogicalImm(0xFFFF, GPRSize::B32));
|
2015-02-13 00:52:07 +00:00
|
|
|
m_skip_vertex = CBZ(scratch2_reg);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-06-20 20:47:57 +00:00
|
|
|
LDR(IndexType::Unsigned, scratch2_reg, stride_reg, static_cast<u8>(array) * 4);
|
2015-02-13 00:52:07 +00:00
|
|
|
MUL(scratch1_reg, scratch1_reg, scratch2_reg);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-06-20 20:47:57 +00:00
|
|
|
LDR(IndexType::Unsigned, EncodeRegTo64(scratch2_reg), arraybase_reg,
|
|
|
|
static_cast<u8>(array) * 8);
|
2022-07-15 20:22:58 +00:00
|
|
|
ADD(EncodeRegTo64(scratch1_reg), EncodeRegTo64(scratch1_reg), EncodeRegTo64(scratch2_reg));
|
|
|
|
return {EncodeRegTo64(scratch1_reg), 0};
|
2015-02-13 00:52:07 +00:00
|
|
|
}
|
2015-09-05 00:57:08 +00:00
|
|
|
else
|
2022-07-15 20:02:55 +00:00
|
|
|
{
|
2022-07-15 20:22:58 +00:00
|
|
|
return {src_reg, m_src_ofs};
|
2022-07-15 20:02:55 +00:00
|
|
|
}
|
2015-02-13 00:52:07 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 02:20:15 +00:00
|
|
|
void VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentFormat format,
|
|
|
|
int count_in, int count_out, bool dequantize,
|
|
|
|
u8 scaling_exponent, AttributeFormat* native_format,
|
|
|
|
ARM64Reg reg, u32 offset)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2021-02-06 18:50:33 +00:00
|
|
|
ARM64Reg coords = count_in == 3 ? ARM64Reg::Q31 : ARM64Reg::D31;
|
|
|
|
ARM64Reg scale = count_in == 3 ? ARM64Reg::Q30 : ARM64Reg::D30;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
int elem_size = GetElementSize(format);
|
2015-02-13 00:52:07 +00:00
|
|
|
int load_bytes = elem_size * count_in;
|
2021-03-11 23:57:54 +00:00
|
|
|
int load_size = GetLoadSize(load_bytes);
|
2015-02-17 04:01:07 +00:00
|
|
|
load_size <<= 3;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-07-15 20:22:58 +00:00
|
|
|
m_float_emit.LDUR(load_size, coords, reg, offset);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2024-04-02 04:37:11 +00:00
|
|
|
if (format < ComponentFormat::Float)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
|
|
|
// Extend and convert to float
|
|
|
|
switch (format)
|
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
case ComponentFormat::UByte:
|
2015-02-13 00:52:07 +00:00
|
|
|
m_float_emit.UXTL(8, EncodeRegToDouble(coords), EncodeRegToDouble(coords));
|
|
|
|
m_float_emit.UXTL(16, EncodeRegToDouble(coords), EncodeRegToDouble(coords));
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ComponentFormat::Byte:
|
2015-02-13 00:52:07 +00:00
|
|
|
m_float_emit.SXTL(8, EncodeRegToDouble(coords), EncodeRegToDouble(coords));
|
|
|
|
m_float_emit.SXTL(16, EncodeRegToDouble(coords), EncodeRegToDouble(coords));
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ComponentFormat::UShort:
|
2015-02-13 00:52:07 +00:00
|
|
|
m_float_emit.REV16(8, EncodeRegToDouble(coords), EncodeRegToDouble(coords));
|
|
|
|
m_float_emit.UXTL(16, EncodeRegToDouble(coords), EncodeRegToDouble(coords));
|
|
|
|
break;
|
2021-02-08 23:22:10 +00:00
|
|
|
case ComponentFormat::Short:
|
2015-02-13 00:52:07 +00:00
|
|
|
m_float_emit.REV16(8, EncodeRegToDouble(coords), EncodeRegToDouble(coords));
|
|
|
|
m_float_emit.SXTL(16, EncodeRegToDouble(coords), EncodeRegToDouble(coords));
|
|
|
|
break;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
m_float_emit.SCVTF(32, coords, coords);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
if (dequantize && scaling_exponent)
|
|
|
|
{
|
2021-01-16 07:27:11 +00:00
|
|
|
m_float_emit.LDR(32, IndexType::Unsigned, scale, scale_reg, scaling_exponent * 4);
|
2015-02-13 00:52:07 +00:00
|
|
|
m_float_emit.FMUL(32, coords, coords, scale, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_float_emit.REV32(8, coords, coords);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
const u32 write_size = count_out == 3 ? 128 : count_out * 32;
|
2022-07-15 03:02:55 +00:00
|
|
|
m_float_emit.STUR(write_size, coords, dst_reg, m_dst_ofs);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-06-07 04:50:50 +00:00
|
|
|
// Z-Freeze
|
|
|
|
if (native_format == &m_native_vtx_decl.position)
|
|
|
|
{
|
2022-04-14 19:01:57 +00:00
|
|
|
CMP(remaining_reg, 3);
|
|
|
|
FixupBranch dont_store = B(CC_GE);
|
2022-04-13 23:12:53 +00:00
|
|
|
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::position_cache.data());
|
2022-04-14 19:01:57 +00:00
|
|
|
m_float_emit.STR(128, coords, EncodeRegTo64(scratch2_reg), ArithOption(remaining_reg, true));
|
2015-06-07 04:50:50 +00:00
|
|
|
SetJumpTarget(dont_store);
|
|
|
|
}
|
Cache normals in addition to binormals and tangents
Fixes LIT (https://bugs.dolphin-emu.org/issues/13635). The text does not include normals, but has lighting enabled. With the previous default of (0, 0, 0), lighting was always black (as dot(X, (0, 0, 0)) is always 0). It seems like the normal from the map in the background (0, 0, 1) is re-used.
LIT also has the vertex color enabled while vertex color is not specified, the same as SMS's debug cubes; the default MissingColorValue GameINI value of solid white seems to work correctly in this case.
2024-09-25 06:46:45 +00:00
|
|
|
else if (native_format == &m_native_vtx_decl.normals[0])
|
|
|
|
{
|
|
|
|
FixupBranch dont_store = CBNZ(remaining_reg);
|
|
|
|
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::normal_cache.data());
|
|
|
|
m_float_emit.STR(128, IndexType::Unsigned, coords, EncodeRegTo64(scratch2_reg), 0);
|
|
|
|
SetJumpTarget(dont_store);
|
|
|
|
}
|
2022-04-14 05:03:34 +00:00
|
|
|
else if (native_format == &m_native_vtx_decl.normals[1])
|
|
|
|
{
|
|
|
|
FixupBranch dont_store = CBNZ(remaining_reg);
|
|
|
|
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::tangent_cache.data());
|
|
|
|
m_float_emit.STR(128, IndexType::Unsigned, coords, EncodeRegTo64(scratch2_reg), 0);
|
|
|
|
SetJumpTarget(dont_store);
|
|
|
|
}
|
|
|
|
else if (native_format == &m_native_vtx_decl.normals[2])
|
|
|
|
{
|
|
|
|
FixupBranch dont_store = CBNZ(remaining_reg);
|
|
|
|
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::binormal_cache.data());
|
|
|
|
m_float_emit.STR(128, IndexType::Unsigned, coords, EncodeRegTo64(scratch2_reg), 0);
|
|
|
|
SetJumpTarget(dont_store);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
native_format->components = count_out;
|
|
|
|
native_format->enable = true;
|
|
|
|
native_format->offset = m_dst_ofs;
|
2021-06-26 19:48:28 +00:00
|
|
|
native_format->type = ComponentFormat::Float;
|
2015-02-13 00:52:07 +00:00
|
|
|
native_format->integer = false;
|
|
|
|
m_dst_ofs += sizeof(float) * count_out;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
if (attribute == VertexComponentFormat::Direct)
|
2015-02-13 00:52:07 +00:00
|
|
|
m_src_ofs += load_bytes;
|
|
|
|
}
|
|
|
|
|
2022-07-15 20:22:58 +00:00
|
|
|
void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat format, ARM64Reg reg,
|
|
|
|
u32 offset)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
|
|
|
int load_bytes = 0;
|
|
|
|
switch (format)
|
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB888:
|
|
|
|
case ColorFormat::RGB888x:
|
|
|
|
case ColorFormat::RGBA8888:
|
2022-07-15 20:22:58 +00:00
|
|
|
LDUR(scratch2_reg, reg, offset);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
if (format != ColorFormat::RGBA8888)
|
2023-12-16 12:27:13 +00:00
|
|
|
ORR(scratch2_reg, scratch2_reg, LogicalImm(0xFF000000, GPRSize::B32));
|
2021-01-16 07:27:11 +00:00
|
|
|
STR(IndexType::Unsigned, scratch2_reg, dst_reg, m_dst_ofs);
|
2021-02-08 23:22:10 +00:00
|
|
|
load_bytes = format == ColorFormat::RGB888 ? 3 : 4;
|
2015-02-13 00:52:07 +00:00
|
|
|
break;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGB565:
|
2015-02-13 00:52:07 +00:00
|
|
|
// RRRRRGGG GGGBBBBB
|
|
|
|
// AAAAAAAA BBBBBBBB GGGGGGGG RRRRRRRR
|
2022-07-15 20:22:58 +00:00
|
|
|
LDURH(scratch3_reg, reg, offset);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
REV16(scratch3_reg, scratch3_reg);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// B
|
2023-12-16 12:27:13 +00:00
|
|
|
AND(scratch2_reg, scratch3_reg, LogicalImm(0x1F, GPRSize::B32));
|
2021-02-06 18:50:33 +00:00
|
|
|
ORR(scratch2_reg, ARM64Reg::WSP, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 3));
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch2_reg, scratch2_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSR, 5));
|
2021-02-06 18:50:33 +00:00
|
|
|
ORR(scratch1_reg, ARM64Reg::WSP, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 16));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// G
|
|
|
|
UBFM(scratch2_reg, scratch3_reg, 5, 10);
|
2021-02-06 18:50:33 +00:00
|
|
|
ORR(scratch2_reg, ARM64Reg::WSP, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 2));
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch2_reg, scratch2_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSR, 6));
|
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 8));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// R
|
|
|
|
UBFM(scratch2_reg, scratch3_reg, 11, 15);
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 3));
|
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSR, 2));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// A
|
2023-12-16 12:27:13 +00:00
|
|
|
ORR(scratch1_reg, scratch1_reg, LogicalImm(0xFF000000, GPRSize::B32));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-01-16 07:27:11 +00:00
|
|
|
STR(IndexType::Unsigned, scratch1_reg, dst_reg, m_dst_ofs);
|
2015-02-13 00:52:07 +00:00
|
|
|
load_bytes = 2;
|
|
|
|
break;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA4444:
|
2015-02-13 00:52:07 +00:00
|
|
|
// BBBBAAAA RRRRGGGG
|
|
|
|
// REV16 - RRRRGGGG BBBBAAAA
|
|
|
|
// AAAAAAAA BBBBBBBB GGGGGGGG RRRRRRRR
|
2022-07-15 20:22:58 +00:00
|
|
|
LDURH(scratch3_reg, reg, offset);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// R
|
|
|
|
UBFM(scratch1_reg, scratch3_reg, 4, 7);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// G
|
2023-12-16 12:27:13 +00:00
|
|
|
AND(scratch2_reg, scratch3_reg, LogicalImm(0xF, GPRSize::B32));
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 8));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// B
|
|
|
|
UBFM(scratch2_reg, scratch3_reg, 12, 15);
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 16));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// A
|
|
|
|
UBFM(scratch2_reg, scratch3_reg, 8, 11);
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 24));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// Final duplication
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch1_reg, ArithOption(scratch1_reg, ShiftType::LSL, 4));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-01-16 07:27:11 +00:00
|
|
|
STR(IndexType::Unsigned, scratch1_reg, dst_reg, m_dst_ofs);
|
2015-02-13 00:52:07 +00:00
|
|
|
load_bytes = 2;
|
|
|
|
break;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
case ColorFormat::RGBA6666:
|
2015-02-13 00:52:07 +00:00
|
|
|
// RRRRRRGG GGGGBBBB BBAAAAAA
|
|
|
|
// AAAAAAAA BBBBBBBB GGGGGGGG RRRRRRRR
|
2022-07-15 20:22:58 +00:00
|
|
|
LDUR(scratch3_reg, reg, offset - 1);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
REV32(scratch3_reg, scratch3_reg);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// A
|
2015-06-21 02:12:31 +00:00
|
|
|
UBFM(scratch2_reg, scratch3_reg, 0, 5);
|
2021-02-06 18:50:33 +00:00
|
|
|
ORR(scratch2_reg, ARM64Reg::WSP, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 2));
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch2_reg, scratch2_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSR, 6));
|
2021-02-06 18:50:33 +00:00
|
|
|
ORR(scratch1_reg, ARM64Reg::WSP, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 24));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// B
|
|
|
|
UBFM(scratch2_reg, scratch3_reg, 6, 11);
|
2021-02-06 18:50:33 +00:00
|
|
|
ORR(scratch2_reg, ARM64Reg::WSP, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 2));
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch2_reg, scratch2_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSR, 6));
|
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 16));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// G
|
|
|
|
UBFM(scratch2_reg, scratch3_reg, 12, 17);
|
2021-02-06 18:50:33 +00:00
|
|
|
ORR(scratch2_reg, ARM64Reg::WSP, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 2));
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch2_reg, scratch2_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSR, 6));
|
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 8));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// R
|
|
|
|
UBFM(scratch2_reg, scratch3_reg, 18, 23);
|
2021-01-16 09:26:23 +00:00
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSL, 2));
|
|
|
|
ORR(scratch1_reg, scratch1_reg, scratch2_reg, ArithOption(scratch2_reg, ShiftType::LSR, 4));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-01-16 07:27:11 +00:00
|
|
|
STR(IndexType::Unsigned, scratch1_reg, dst_reg, m_dst_ofs);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
load_bytes = 3;
|
|
|
|
break;
|
|
|
|
}
|
2021-02-08 23:22:10 +00:00
|
|
|
if (attribute == VertexComponentFormat::Direct)
|
2015-02-13 00:52:07 +00:00
|
|
|
m_src_ofs += load_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VertexLoaderARM64::GenerateVertexLoader()
|
|
|
|
{
|
2022-07-15 03:02:55 +00:00
|
|
|
// The largest input vertex (with the position matrix index and all texture matrix indices
|
|
|
|
// enabled, and all components set as direct) is 129 bytes (corresponding to a 156-byte
|
|
|
|
// output). This is small enough that we can always use the unscaled load/store instructions
|
|
|
|
// (which allow an offset from -256 to +255).
|
|
|
|
ASSERT(m_vertex_size <= 255);
|
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// R0 - Source pointer
|
|
|
|
// R1 - Destination pointer
|
|
|
|
// R2 - Count
|
|
|
|
// R30 - LR
|
|
|
|
//
|
|
|
|
// R0 return how many
|
|
|
|
//
|
|
|
|
// Registers we don't have to worry about saving
|
|
|
|
// R9-R17 are caller saved temporaries
|
|
|
|
// R18 is a temporary or platform specific register(iOS)
|
|
|
|
//
|
|
|
|
// VFP registers
|
|
|
|
// We can touch all except v8-v15
|
|
|
|
// If we need to use those, we need to retain the lower 64bits(!) of the register
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-09-05 00:57:08 +00:00
|
|
|
bool has_tc = false;
|
|
|
|
bool has_tc_scale = false;
|
2021-02-08 23:22:10 +00:00
|
|
|
for (size_t i = 0; i < m_VtxDesc.high.TexCoord.Size(); i++)
|
2015-09-05 00:57:08 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
has_tc |= m_VtxDesc.high.TexCoord[i] != VertexComponentFormat::NotPresent;
|
2021-03-11 06:15:43 +00:00
|
|
|
has_tc_scale |= (m_VtxAttr.GetTexFrac(i) != 0);
|
2015-09-05 00:57:08 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-03-11 06:15:43 +00:00
|
|
|
bool need_scale = (m_VtxAttr.g0.ByteDequant && m_VtxAttr.g0.PosFrac) ||
|
|
|
|
(has_tc && has_tc_scale) ||
|
2021-02-08 23:22:10 +00:00
|
|
|
(m_VtxDesc.low.Normal != VertexComponentFormat::NotPresent);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-09-05 00:57:08 +00:00
|
|
|
AlignCode16();
|
2021-02-08 23:22:10 +00:00
|
|
|
if (IsIndexed(m_VtxDesc.low.Position))
|
2021-02-06 18:50:33 +00:00
|
|
|
MOV(skipped_reg, ARM64Reg::WZR);
|
2022-04-14 19:01:57 +00:00
|
|
|
ADD(saved_count, remaining_reg, 1);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-04-23 03:57:56 +00:00
|
|
|
MOVP2R(stride_reg, g_main_cp_state.array_strides.data());
|
2021-05-13 23:05:31 +00:00
|
|
|
MOVP2R(arraybase_reg, VertexLoaderManager::cached_arraybases.data());
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-09-05 00:57:08 +00:00
|
|
|
if (need_scale)
|
2016-05-07 07:35:40 +00:00
|
|
|
MOVP2R(scale_reg, scale_factors);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
const u8* loop_start = GetCodePtr();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.PosMatIdx)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2021-01-16 07:27:11 +00:00
|
|
|
LDRB(IndexType::Unsigned, scratch1_reg, src_reg, m_src_ofs);
|
2023-12-16 12:27:13 +00:00
|
|
|
AND(scratch1_reg, scratch1_reg, LogicalImm(0x3F, GPRSize::B32));
|
2021-01-16 07:27:11 +00:00
|
|
|
STR(IndexType::Unsigned, scratch1_reg, dst_reg, m_dst_ofs);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-06-07 04:50:50 +00:00
|
|
|
// Z-Freeze
|
2022-04-14 19:01:57 +00:00
|
|
|
CMP(remaining_reg, 3);
|
|
|
|
FixupBranch dont_store = B(CC_GE);
|
2022-04-13 23:12:53 +00:00
|
|
|
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::position_matrix_index_cache.data());
|
2022-04-14 19:01:57 +00:00
|
|
|
STR(scratch1_reg, EncodeRegTo64(scratch2_reg), ArithOption(remaining_reg, true));
|
2015-06-07 04:50:50 +00:00
|
|
|
SetJumpTarget(dont_store);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
m_native_vtx_decl.posmtx.components = 4;
|
|
|
|
m_native_vtx_decl.posmtx.enable = true;
|
|
|
|
m_native_vtx_decl.posmtx.offset = m_dst_ofs;
|
2021-06-26 19:48:28 +00:00
|
|
|
m_native_vtx_decl.posmtx.type = ComponentFormat::UByte;
|
2015-02-13 00:52:07 +00:00
|
|
|
m_native_vtx_decl.posmtx.integer = true;
|
|
|
|
m_src_ofs += sizeof(u8);
|
|
|
|
m_dst_ofs += sizeof(u32);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
std::array<u32, 8> texmatidx_ofs;
|
|
|
|
for (size_t i = 0; i < m_VtxDesc.low.TexMatIdx.Size(); i++)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.TexMatIdx[i])
|
2015-02-13 00:52:07 +00:00
|
|
|
texmatidx_ofs[i] = m_src_ofs++;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-17 04:01:07 +00:00
|
|
|
// Position
|
|
|
|
{
|
2022-07-15 20:02:55 +00:00
|
|
|
const int pos_elements = m_VtxAttr.g0.PosElements == CoordComponentCount::XY ? 2 : 3;
|
|
|
|
|
2022-07-15 20:22:58 +00:00
|
|
|
const auto [reg, offset] = GetVertexAddr(CPArray::Position, m_VtxDesc.low.Position);
|
2021-03-11 06:15:43 +00:00
|
|
|
ReadVertex(m_VtxDesc.low.Position, m_VtxAttr.g0.PosFormat, pos_elements, pos_elements,
|
2022-07-15 20:22:58 +00:00
|
|
|
m_VtxAttr.g0.ByteDequant, m_VtxAttr.g0.PosFrac, &m_native_vtx_decl.position, reg,
|
|
|
|
offset);
|
2015-02-17 04:01:07 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Normal != VertexComponentFormat::NotPresent)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2024-04-02 04:37:11 +00:00
|
|
|
static constexpr Common::EnumMap<u8, ComponentFormat::InvalidFloat7> SCALE_MAP = {7, 6, 15, 14,
|
|
|
|
0, 0, 0, 0};
|
2022-07-15 02:27:44 +00:00
|
|
|
const u8 scaling_exponent = SCALE_MAP[m_VtxAttr.g0.NormalFormat];
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-07-05 02:20:15 +00:00
|
|
|
// Normal
|
|
|
|
auto [reg, offset] = GetVertexAddr(CPArray::Normal, m_VtxDesc.low.Normal);
|
|
|
|
ReadVertex(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, 3, 3, true, scaling_exponent,
|
|
|
|
&m_native_vtx_decl.normals[0], reg, offset);
|
|
|
|
|
|
|
|
if (m_VtxAttr.g0.NormalElements == NormalComponentCount::NTB)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2022-07-05 02:20:15 +00:00
|
|
|
const bool index3 = IsIndexed(m_VtxDesc.low.Normal) && m_VtxAttr.g0.NormalIndex3;
|
|
|
|
const int elem_size = GetElementSize(m_VtxAttr.g0.NormalFormat);
|
|
|
|
const int load_bytes = elem_size * 3;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-07-05 02:20:15 +00:00
|
|
|
// Tangent
|
|
|
|
// If in Index3 mode, and indexed components are used, replace the index with a new index.
|
|
|
|
if (index3)
|
2022-07-15 20:22:58 +00:00
|
|
|
std::tie(reg, offset) = GetVertexAddr(CPArray::Normal, m_VtxDesc.low.Normal);
|
2022-07-05 02:20:15 +00:00
|
|
|
// The tangent comes after the normal; even in index3 mode, an extra offset of load_bytes is
|
|
|
|
// applied. Note that this is different from adding 1 to the index, as the stride for indices
|
|
|
|
// may be different from the size of the tangent itself.
|
|
|
|
ReadVertex(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, 3, 3, true, scaling_exponent,
|
|
|
|
&m_native_vtx_decl.normals[1], reg, offset + load_bytes);
|
|
|
|
// Binormal
|
|
|
|
if (index3)
|
|
|
|
std::tie(reg, offset) = GetVertexAddr(CPArray::Normal, m_VtxDesc.low.Normal);
|
|
|
|
ReadVertex(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, 3, 3, true, scaling_exponent,
|
|
|
|
&m_native_vtx_decl.normals[2], reg, offset + load_bytes * 2);
|
2015-02-13 00:52:07 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-06-20 20:47:57 +00:00
|
|
|
for (u8 i = 0; i < m_VtxDesc.low.Color.Size(); i++)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
|
|
|
m_native_vtx_decl.colors[i].components = 4;
|
2021-06-26 19:48:28 +00:00
|
|
|
m_native_vtx_decl.colors[i].type = ComponentFormat::UByte;
|
2015-02-13 00:52:07 +00:00
|
|
|
m_native_vtx_decl.colors[i].integer = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.Color[i] != VertexComponentFormat::NotPresent)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2022-07-15 20:22:58 +00:00
|
|
|
const auto [reg, offset] = GetVertexAddr(CPArray::Color0 + i, m_VtxDesc.low.Color[i]);
|
|
|
|
ReadColor(m_VtxDesc.low.Color[i], m_VtxAttr.GetColorFormat(i), reg, offset);
|
2015-02-13 00:52:07 +00:00
|
|
|
m_native_vtx_decl.colors[i].components = 4;
|
|
|
|
m_native_vtx_decl.colors[i].enable = true;
|
|
|
|
m_native_vtx_decl.colors[i].offset = m_dst_ofs;
|
2021-06-26 19:48:28 +00:00
|
|
|
m_native_vtx_decl.colors[i].type = ComponentFormat::UByte;
|
2015-02-13 00:52:07 +00:00
|
|
|
m_native_vtx_decl.colors[i].integer = false;
|
|
|
|
m_dst_ofs += 4;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 20:47:57 +00:00
|
|
|
for (u8 i = 0; i < m_VtxDesc.high.TexCoord.Size(); i++)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
|
|
|
m_native_vtx_decl.texcoords[i].offset = m_dst_ofs;
|
2021-06-26 19:48:28 +00:00
|
|
|
m_native_vtx_decl.texcoords[i].type = ComponentFormat::Float;
|
2015-02-13 00:52:07 +00:00
|
|
|
m_native_vtx_decl.texcoords[i].integer = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-07-15 20:02:55 +00:00
|
|
|
const int elements = m_VtxAttr.GetTexElements(i) == TexComponentCount::S ? 1 : 2;
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.high.TexCoord[i] != VertexComponentFormat::NotPresent)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2022-07-15 20:22:58 +00:00
|
|
|
const auto [reg, offset] = GetVertexAddr(CPArray::TexCoord0 + i, m_VtxDesc.high.TexCoord[i]);
|
2021-03-11 06:15:43 +00:00
|
|
|
u8 scaling_exponent = m_VtxAttr.GetTexFrac(i);
|
|
|
|
ReadVertex(m_VtxDesc.high.TexCoord[i], m_VtxAttr.GetTexFormat(i), elements,
|
|
|
|
m_VtxDesc.low.TexMatIdx[i] ? 2 : elements, m_VtxAttr.g0.ByteDequant,
|
2022-07-15 20:22:58 +00:00
|
|
|
scaling_exponent, &m_native_vtx_decl.texcoords[i], reg, offset);
|
2015-02-13 00:52:07 +00:00
|
|
|
}
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.low.TexMatIdx[i])
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
|
|
|
m_native_vtx_decl.texcoords[i].components = 3;
|
|
|
|
m_native_vtx_decl.texcoords[i].enable = true;
|
2021-06-26 19:48:28 +00:00
|
|
|
m_native_vtx_decl.texcoords[i].type = ComponentFormat::Float;
|
2015-02-13 00:52:07 +00:00
|
|
|
m_native_vtx_decl.texcoords[i].integer = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-01-16 07:27:11 +00:00
|
|
|
LDRB(IndexType::Unsigned, scratch2_reg, src_reg, texmatidx_ofs[i]);
|
2021-02-06 18:50:33 +00:00
|
|
|
m_float_emit.UCVTF(ARM64Reg::S31, scratch2_reg);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
if (m_VtxDesc.high.TexCoord[i] != VertexComponentFormat::NotPresent)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2021-02-06 18:50:33 +00:00
|
|
|
m_float_emit.STR(32, IndexType::Unsigned, ARM64Reg::D31, dst_reg, m_dst_ofs);
|
2015-02-13 00:52:07 +00:00
|
|
|
m_dst_ofs += sizeof(float);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_native_vtx_decl.texcoords[i].offset = m_dst_ofs;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-07-15 03:02:55 +00:00
|
|
|
STUR(ARM64Reg::SP, dst_reg, m_dst_ofs);
|
2021-02-06 18:50:33 +00:00
|
|
|
m_float_emit.STR(32, IndexType::Unsigned, ARM64Reg::D31, dst_reg, m_dst_ofs + 8);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
m_dst_ofs += sizeof(float) * 3;
|
|
|
|
}
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
// Prepare for the next vertex.
|
|
|
|
ADD(dst_reg, dst_reg, m_dst_ofs);
|
|
|
|
const u8* cont = GetCodePtr();
|
|
|
|
ADD(src_reg, src_reg, m_src_ofs);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-04-14 19:01:57 +00:00
|
|
|
SUBS(remaining_reg, remaining_reg, 1);
|
|
|
|
B(CCFlags::CC_GE, loop_start);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
if (IsIndexed(m_VtxDesc.low.Position))
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
2021-02-06 18:50:33 +00:00
|
|
|
SUB(ARM64Reg::W0, saved_count, skipped_reg);
|
|
|
|
RET(ARM64Reg::X30);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
SetJumpTarget(m_skip_vertex);
|
|
|
|
ADD(skipped_reg, skipped_reg, 1);
|
|
|
|
B(cont);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-06 18:50:33 +00:00
|
|
|
MOV(ARM64Reg::W0, saved_count);
|
|
|
|
RET(ARM64Reg::X30);
|
2015-02-13 00:52:07 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-13 00:52:07 +00:00
|
|
|
FlushIcache();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2023-02-13 03:47:51 +00:00
|
|
|
ASSERT_MSG(VIDEO, m_vertex_size == m_src_ofs,
|
|
|
|
"Vertex size from vertex loader ({}) does not match expected vertex size ({})!\nVtx "
|
|
|
|
"desc: {:08x} {:08x}\nVtx attr: {:08x} {:08x} {:08x}",
|
|
|
|
m_src_ofs, m_vertex_size, m_VtxDesc.low.Hex, m_VtxDesc.high.Hex, m_VtxAttr.g0.Hex,
|
|
|
|
m_VtxAttr.g1.Hex, m_VtxAttr.g2.Hex);
|
2015-02-13 00:52:07 +00:00
|
|
|
m_native_vtx_decl.stride = m_dst_ofs;
|
|
|
|
}
|
|
|
|
|
2022-11-23 00:54:05 +00:00
|
|
|
int VertexLoaderARM64::RunVertices(const u8* src, u8* dst, int count)
|
2015-02-13 00:52:07 +00:00
|
|
|
{
|
|
|
|
m_numLoadedVertices += count;
|
2022-11-23 00:54:05 +00:00
|
|
|
return ((int (*)(const u8* src, u8* dst, int count))region)(src, dst, count - 1);
|
2015-02-13 00:52:07 +00:00
|
|
|
}
|