From afe5adb74d4db1815e0aa20017f980314ca9027d Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Thu, 14 Jul 2022 19:27:44 -0700 Subject: VertexLoaderARM64: Use EnumMap for normal scales --- Source/Core/VideoCommon/VertexLoaderARM64.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoaderARM64.cpp') diff --git a/Source/Core/VideoCommon/VertexLoaderARM64.cpp b/Source/Core/VideoCommon/VertexLoaderARM64.cpp index 9388c21a7b..f5cd7c27d5 100644 --- a/Source/Core/VideoCommon/VertexLoaderARM64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderARM64.cpp @@ -470,8 +470,9 @@ void VertexLoaderARM64::GenerateVertexLoader() if (m_VtxDesc.low.Normal != VertexComponentFormat::NotPresent) { - static const u8 map[8] = {7, 6, 15, 14}; - const u8 scaling_exponent = map[u32(m_VtxAttr.g0.NormalFormat.Value())]; + static constexpr Common::EnumMap(7)> SCALE_MAP = {7, 6, 15, 14, + 0, 0, 0, 0}; + const u8 scaling_exponent = SCALE_MAP[m_VtxAttr.g0.NormalFormat]; const int limit = m_VtxAttr.g0.NormalElements == NormalComponentCount::NTB ? 3 : 1; s32 offset = -1; -- cgit v1.2.3 From 9a290c3d501acaf3eb4c3dceafec821d5a644fad Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Thu, 14 Jul 2022 20:02:55 -0700 Subject: VertexLoaderARM64: Always use unscaled load/store instructions The source and destination offsets will always be less than 255, so we can get rid of a lot of the complexity by doing this. --- Source/Core/VideoCommon/VertexLoaderARM64.cpp | 94 +++++---------------------- 1 file changed, 17 insertions(+), 77 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoaderARM64.cpp') diff --git a/Source/Core/VideoCommon/VertexLoaderARM64.cpp b/Source/Core/VideoCommon/VertexLoaderARM64.cpp index f5cd7c27d5..59ca260fe2 100644 --- a/Source/Core/VideoCommon/VertexLoaderARM64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderARM64.cpp @@ -66,32 +66,12 @@ void VertexLoaderARM64::GetVertexAddr(CPArray array, VertexComponentFormat attri { if (attribute == VertexComponentFormat::Index8) { - if (m_src_ofs < 4096) - { - LDRB(IndexType::Unsigned, scratch1_reg, src_reg, m_src_ofs); - } - else - { - ADD(reg, src_reg, m_src_ofs); - LDRB(IndexType::Unsigned, scratch1_reg, reg, 0); - } + LDURB(scratch1_reg, src_reg, m_src_ofs); m_src_ofs += 1; } - else + else // Index16 { - if (m_src_ofs < 256) - { - LDURH(scratch1_reg, src_reg, m_src_ofs); - } - else if (m_src_ofs <= 8190 && !(m_src_ofs & 1)) - { - LDRH(IndexType::Unsigned, scratch1_reg, src_reg, m_src_ofs); - } - else - { - ADD(reg, src_reg, m_src_ofs); - LDRH(IndexType::Unsigned, scratch1_reg, reg, 0); - } + LDURH(scratch1_reg, src_reg, m_src_ofs); m_src_ofs += 2; REV16(scratch1_reg, scratch1_reg); } @@ -118,7 +98,7 @@ void VertexLoaderARM64::GetVertexAddr(CPArray array, VertexComponentFormat attri s32 VertexLoaderARM64::GetAddressImm(CPArray array, VertexComponentFormat attribute, Arm64Gen::ARM64Reg reg, u32 align) { - if (IsIndexed(attribute) || (m_src_ofs > 255 && (m_src_ofs & (align - 1)))) + if (IsIndexed(attribute)) GetVertexAddr(array, attribute, reg); else return m_src_ofs; @@ -145,13 +125,9 @@ int VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentForm else m_float_emit.LD1(elem_size, 1, coords, EncodeRegTo64(scratch1_reg)); } - else if (offset & (load_size - 1)) // Not aligned - unscaled - { - m_float_emit.LDUR(load_size, coords, src_reg, offset); - } else { - m_float_emit.LDR(load_size, IndexType::Unsigned, coords, src_reg, offset); + m_float_emit.LDUR(load_size, coords, src_reg, offset); } if (format != ComponentFormat::Float) @@ -191,20 +167,7 @@ int VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentForm } const u32 write_size = count_out == 3 ? 128 : count_out * 32; - const u32 mask = count_out == 3 ? 0xF : count_out == 2 ? 0x7 : 0x3; - if (m_dst_ofs < 256) - { - m_float_emit.STUR(write_size, coords, dst_reg, m_dst_ofs); - } - else if (!(m_dst_ofs & mask)) - { - m_float_emit.STR(write_size, IndexType::Unsigned, coords, dst_reg, m_dst_ofs); - } - else - { - ADD(EncodeRegTo64(scratch2_reg), dst_reg, m_dst_ofs); - m_float_emit.ST1(32, 1, coords, EncodeRegTo64(scratch2_reg)); - } + m_float_emit.STUR(write_size, coords, dst_reg, m_dst_ofs); // Z-Freeze if (native_format == &m_native_vtx_decl.position) @@ -253,10 +216,8 @@ void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat f case ColorFormat::RGBA8888: if (offset == -1) LDR(IndexType::Unsigned, scratch2_reg, EncodeRegTo64(scratch1_reg), 0); - else if (offset & 3) // Not aligned - unscaled - LDUR(scratch2_reg, src_reg, offset); else - LDR(IndexType::Unsigned, scratch2_reg, src_reg, offset); + LDUR(scratch2_reg, src_reg, offset); if (format != ColorFormat::RGBA8888) ORR(scratch2_reg, scratch2_reg, LogicalImm(0xFF000000, 32)); @@ -269,10 +230,8 @@ void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat f // AAAAAAAA BBBBBBBB GGGGGGGG RRRRRRRR if (offset == -1) LDRH(IndexType::Unsigned, scratch3_reg, EncodeRegTo64(scratch1_reg), 0); - else if (offset & 1) // Not aligned - unscaled - LDURH(scratch3_reg, src_reg, offset); else - LDRH(IndexType::Unsigned, scratch3_reg, src_reg, offset); + LDURH(scratch3_reg, src_reg, offset); REV16(scratch3_reg, scratch3_reg); @@ -306,10 +265,8 @@ void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat f // AAAAAAAA BBBBBBBB GGGGGGGG RRRRRRRR if (offset == -1) LDRH(IndexType::Unsigned, scratch3_reg, EncodeRegTo64(scratch1_reg), 0); - else if (offset & 1) // Not aligned - unscaled - LDURH(scratch3_reg, src_reg, offset); else - LDRH(IndexType::Unsigned, scratch3_reg, src_reg, offset); + LDURH(scratch3_reg, src_reg, offset); // R UBFM(scratch1_reg, scratch3_reg, 4, 7); @@ -337,17 +294,9 @@ void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat f // RRRRRRGG GGGGBBBB BBAAAAAA // AAAAAAAA BBBBBBBB GGGGGGGG RRRRRRRR if (offset == -1) - { LDUR(scratch3_reg, EncodeRegTo64(scratch1_reg), -1); - } else - { - offset -= 1; - if (offset & 3) // Not aligned - unscaled - LDUR(scratch3_reg, src_reg, offset); - else - LDR(IndexType::Unsigned, scratch3_reg, src_reg, offset); - } + LDUR(scratch3_reg, src_reg, offset - 1); REV32(scratch3_reg, scratch3_reg); @@ -385,6 +334,12 @@ void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat f void VertexLoaderARM64::GenerateVertexLoader() { + // 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); + // R0 - Source pointer // R1 - Destination pointer // R2 - Count @@ -568,22 +523,7 @@ void VertexLoaderARM64::GenerateVertexLoader() { m_native_vtx_decl.texcoords[i].offset = m_dst_ofs; - if (m_dst_ofs < 256) - { - STUR(ARM64Reg::SP, dst_reg, m_dst_ofs); - } - else if (!(m_dst_ofs & 7)) - { - // If m_dst_ofs isn't 8byte aligned we can't store an 8byte zero register - // So store two 4byte zero registers - // The destination is always 4byte aligned - STR(IndexType::Unsigned, ARM64Reg::WSP, dst_reg, m_dst_ofs); - STR(IndexType::Unsigned, ARM64Reg::WSP, dst_reg, m_dst_ofs + 4); - } - else - { - STR(IndexType::Unsigned, ARM64Reg::SP, dst_reg, m_dst_ofs); - } + STUR(ARM64Reg::SP, dst_reg, m_dst_ofs); m_float_emit.STR(32, IndexType::Unsigned, ARM64Reg::D31, dst_reg, m_dst_ofs + 8); m_dst_ofs += sizeof(float) * 3; -- cgit v1.2.3 From ad644d5e92a45aa2313f382374a5b6dcfe61abf8 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Fri, 15 Jul 2022 13:02:55 -0700 Subject: VertexLoaderARM64: Merge GetAddressImm into GetVertexAddr This way it more closely matches VertexLoaderX64, and is in general easier to understand. --- Source/Core/VideoCommon/VertexLoaderARM64.cpp | 55 ++++++++------------------- 1 file changed, 15 insertions(+), 40 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoaderARM64.cpp') diff --git a/Source/Core/VideoCommon/VertexLoaderARM64.cpp b/Source/Core/VideoCommon/VertexLoaderARM64.cpp index 59ca260fe2..de602e18df 100644 --- a/Source/Core/VideoCommon/VertexLoaderARM64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderARM64.cpp @@ -60,7 +60,7 @@ VertexLoaderARM64::VertexLoaderARM64(const TVtxDesc& vtx_desc, const VAT& vtx_at WriteProtect(); } -void VertexLoaderARM64::GetVertexAddr(CPArray array, VertexComponentFormat attribute, ARM64Reg reg) +s32 VertexLoaderARM64::GetVertexAddr(CPArray array, VertexComponentFormat attribute, ARM64Reg reg) { if (IsIndexed(attribute)) { @@ -90,19 +90,12 @@ void VertexLoaderARM64::GetVertexAddr(CPArray array, VertexComponentFormat attri LDR(IndexType::Unsigned, EncodeRegTo64(scratch2_reg), arraybase_reg, static_cast(array) * 8); ADD(EncodeRegTo64(reg), EncodeRegTo64(scratch1_reg), EncodeRegTo64(scratch2_reg)); + return -1; } else - ADD(reg, src_reg, m_src_ofs); -} - -s32 VertexLoaderARM64::GetAddressImm(CPArray array, VertexComponentFormat attribute, - Arm64Gen::ARM64Reg reg, u32 align) -{ - if (IsIndexed(attribute)) - GetVertexAddr(array, attribute, reg); - else + { return m_src_ofs; - return -1; + } } int VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentFormat format, @@ -411,14 +404,10 @@ void VertexLoaderARM64::GenerateVertexLoader() // Position { - int elem_size = GetElementSize(m_VtxAttr.g0.PosFormat); - int pos_elements = m_VtxAttr.g0.PosElements == CoordComponentCount::XY ? 2 : 3; - int load_bytes = elem_size * pos_elements; - int load_size = GetLoadSize(load_bytes); - load_size <<= 3; - - s32 offset = GetAddressImm(CPArray::Position, m_VtxDesc.low.Position, - EncodeRegTo64(scratch1_reg), load_size); + const int pos_elements = m_VtxAttr.g0.PosElements == CoordComponentCount::XY ? 2 : 3; + + const s32 offset = + GetVertexAddr(CPArray::Position, m_VtxDesc.low.Position, EncodeRegTo64(scratch1_reg)); ReadVertex(m_VtxDesc.low.Position, m_VtxAttr.g0.PosFormat, pos_elements, pos_elements, m_VtxAttr.g0.ByteDequant, m_VtxAttr.g0.PosFrac, &m_native_vtx_decl.position, offset); } @@ -435,13 +424,9 @@ void VertexLoaderARM64::GenerateVertexLoader() { if (!i || m_VtxAttr.g0.NormalIndex3) { - int elem_size = GetElementSize(m_VtxAttr.g0.NormalFormat); - - int load_bytes = elem_size * 3; - int load_size = GetLoadSize(load_bytes); + const int elem_size = GetElementSize(m_VtxAttr.g0.NormalFormat); - offset = GetAddressImm(CPArray::Normal, m_VtxDesc.low.Normal, EncodeRegTo64(scratch1_reg), - load_size << 3); + offset = GetVertexAddr(CPArray::Normal, m_VtxDesc.low.Normal, EncodeRegTo64(scratch1_reg)); if (offset == -1) ADD(EncodeRegTo64(scratch1_reg), EncodeRegTo64(scratch1_reg), i * elem_size * 3); @@ -466,13 +451,8 @@ void VertexLoaderARM64::GenerateVertexLoader() if (m_VtxDesc.low.Color[i] != VertexComponentFormat::NotPresent) { - u32 align = 4; - if (m_VtxAttr.GetColorFormat(i) == ColorFormat::RGB565 || - m_VtxAttr.GetColorFormat(i) == ColorFormat::RGBA4444) - align = 2; - - s32 offset = GetAddressImm(CPArray::Color0 + i, m_VtxDesc.low.Color[i], - EncodeRegTo64(scratch1_reg), align); + const s32 offset = + GetVertexAddr(CPArray::Color0 + i, m_VtxDesc.low.Color[i], EncodeRegTo64(scratch1_reg)); ReadColor(m_VtxDesc.low.Color[i], m_VtxAttr.GetColorFormat(i), offset); m_native_vtx_decl.colors[i].components = 4; m_native_vtx_decl.colors[i].enable = true; @@ -489,16 +469,11 @@ void VertexLoaderARM64::GenerateVertexLoader() m_native_vtx_decl.texcoords[i].type = ComponentFormat::Float; m_native_vtx_decl.texcoords[i].integer = false; - int elements = m_VtxAttr.GetTexElements(i) == TexComponentCount::S ? 1 : 2; + const int elements = m_VtxAttr.GetTexElements(i) == TexComponentCount::S ? 1 : 2; if (m_VtxDesc.high.TexCoord[i] != VertexComponentFormat::NotPresent) { - int elem_size = GetElementSize(m_VtxAttr.GetTexFormat(i)); - int load_bytes = elem_size * (elements + 2); - int load_size = GetLoadSize(load_bytes); - load_size <<= 3; - - s32 offset = GetAddressImm(CPArray::TexCoord0 + i, m_VtxDesc.high.TexCoord[i], - EncodeRegTo64(scratch1_reg), load_size); + s32 offset = GetVertexAddr(CPArray::TexCoord0 + i, m_VtxDesc.high.TexCoord[i], + EncodeRegTo64(scratch1_reg)); 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, -- cgit v1.2.3 From f148de161f3126d2b328d5c022acb04379f1da1f Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Fri, 15 Jul 2022 13:22:58 -0700 Subject: VertexLoaderARM64: Specify the register to use as a parameter to ReadVertex This also means that both a register and a vertex are always specified, though right now if the register is scratch1_reg the offset is always 0. --- Source/Core/VideoCommon/VertexLoaderARM64.cpp | 83 ++++++++++----------------- 1 file changed, 29 insertions(+), 54 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoaderARM64.cpp') diff --git a/Source/Core/VideoCommon/VertexLoaderARM64.cpp b/Source/Core/VideoCommon/VertexLoaderARM64.cpp index de602e18df..3d64e85cb7 100644 --- a/Source/Core/VideoCommon/VertexLoaderARM64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderARM64.cpp @@ -60,7 +60,11 @@ VertexLoaderARM64::VertexLoaderARM64(const TVtxDesc& vtx_desc, const VAT& vtx_at WriteProtect(); } -s32 VertexLoaderARM64::GetVertexAddr(CPArray array, VertexComponentFormat attribute, ARM64Reg reg) +// 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 VertexLoaderARM64::GetVertexAddr(CPArray array, + VertexComponentFormat attribute) { if (IsIndexed(attribute)) { @@ -89,18 +93,18 @@ s32 VertexLoaderARM64::GetVertexAddr(CPArray array, VertexComponentFormat attrib LDR(IndexType::Unsigned, EncodeRegTo64(scratch2_reg), arraybase_reg, static_cast(array) * 8); - ADD(EncodeRegTo64(reg), EncodeRegTo64(scratch1_reg), EncodeRegTo64(scratch2_reg)); - return -1; + ADD(EncodeRegTo64(scratch1_reg), EncodeRegTo64(scratch1_reg), EncodeRegTo64(scratch2_reg)); + return {EncodeRegTo64(scratch1_reg), 0}; } else { - return m_src_ofs; + return {src_reg, m_src_ofs}; } } int VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentFormat format, int count_in, int count_out, bool dequantize, u8 scaling_exponent, - AttributeFormat* native_format, s32 offset) + AttributeFormat* native_format, ARM64Reg reg, u32 offset) { ARM64Reg coords = count_in == 3 ? ARM64Reg::Q31 : ARM64Reg::D31; ARM64Reg scale = count_in == 3 ? ARM64Reg::Q30 : ARM64Reg::D30; @@ -111,17 +115,7 @@ int VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentForm load_size <<= 3; elem_size <<= 3; - if (offset == -1) - { - if (count_in == 1) - m_float_emit.LDR(elem_size, IndexType::Unsigned, coords, EncodeRegTo64(scratch1_reg), 0); - else - m_float_emit.LD1(elem_size, 1, coords, EncodeRegTo64(scratch1_reg)); - } - else - { - m_float_emit.LDUR(load_size, coords, src_reg, offset); - } + m_float_emit.LDUR(load_size, coords, reg, offset); if (format != ComponentFormat::Float) { @@ -199,7 +193,8 @@ int VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentForm return load_bytes; } -void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat format, s32 offset) +void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat format, ARM64Reg reg, + u32 offset) { int load_bytes = 0; switch (format) @@ -207,10 +202,7 @@ void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat f case ColorFormat::RGB888: case ColorFormat::RGB888x: case ColorFormat::RGBA8888: - if (offset == -1) - LDR(IndexType::Unsigned, scratch2_reg, EncodeRegTo64(scratch1_reg), 0); - else - LDUR(scratch2_reg, src_reg, offset); + LDUR(scratch2_reg, reg, offset); if (format != ColorFormat::RGBA8888) ORR(scratch2_reg, scratch2_reg, LogicalImm(0xFF000000, 32)); @@ -221,10 +213,7 @@ void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat f case ColorFormat::RGB565: // RRRRRGGG GGGBBBBB // AAAAAAAA BBBBBBBB GGGGGGGG RRRRRRRR - if (offset == -1) - LDRH(IndexType::Unsigned, scratch3_reg, EncodeRegTo64(scratch1_reg), 0); - else - LDURH(scratch3_reg, src_reg, offset); + LDURH(scratch3_reg, reg, offset); REV16(scratch3_reg, scratch3_reg); @@ -256,10 +245,7 @@ void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat f // BBBBAAAA RRRRGGGG // REV16 - RRRRGGGG BBBBAAAA // AAAAAAAA BBBBBBBB GGGGGGGG RRRRRRRR - if (offset == -1) - LDRH(IndexType::Unsigned, scratch3_reg, EncodeRegTo64(scratch1_reg), 0); - else - LDURH(scratch3_reg, src_reg, offset); + LDURH(scratch3_reg, reg, offset); // R UBFM(scratch1_reg, scratch3_reg, 4, 7); @@ -286,10 +272,7 @@ void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat f case ColorFormat::RGBA6666: // RRRRRRGG GGGGBBBB BBAAAAAA // AAAAAAAA BBBBBBBB GGGGGGGG RRRRRRRR - if (offset == -1) - LDUR(scratch3_reg, EncodeRegTo64(scratch1_reg), -1); - else - LDUR(scratch3_reg, src_reg, offset - 1); + LDUR(scratch3_reg, reg, offset - 1); REV32(scratch3_reg, scratch3_reg); @@ -406,10 +389,10 @@ void VertexLoaderARM64::GenerateVertexLoader() { const int pos_elements = m_VtxAttr.g0.PosElements == CoordComponentCount::XY ? 2 : 3; - const s32 offset = - GetVertexAddr(CPArray::Position, m_VtxDesc.low.Position, EncodeRegTo64(scratch1_reg)); + const auto [reg, offset] = GetVertexAddr(CPArray::Position, m_VtxDesc.low.Position); ReadVertex(m_VtxDesc.low.Position, m_VtxAttr.g0.PosFormat, pos_elements, pos_elements, - m_VtxAttr.g0.ByteDequant, m_VtxAttr.g0.PosFrac, &m_native_vtx_decl.position, offset); + m_VtxAttr.g0.ByteDequant, m_VtxAttr.g0.PosFrac, &m_native_vtx_decl.position, reg, + offset); } if (m_VtxDesc.low.Normal != VertexComponentFormat::NotPresent) @@ -419,27 +402,21 @@ void VertexLoaderARM64::GenerateVertexLoader() const u8 scaling_exponent = SCALE_MAP[m_VtxAttr.g0.NormalFormat]; const int limit = m_VtxAttr.g0.NormalElements == NormalComponentCount::NTB ? 3 : 1; - s32 offset = -1; + ARM64Reg reg{}; + u32 offset{}; for (int i = 0; i < limit; i++) { if (!i || m_VtxAttr.g0.NormalIndex3) { const int elem_size = GetElementSize(m_VtxAttr.g0.NormalFormat); - offset = GetVertexAddr(CPArray::Normal, m_VtxDesc.low.Normal, EncodeRegTo64(scratch1_reg)); - - if (offset == -1) - ADD(EncodeRegTo64(scratch1_reg), EncodeRegTo64(scratch1_reg), i * elem_size * 3); - else - offset += i * elem_size * 3; + std::tie(reg, offset) = GetVertexAddr(CPArray::Normal, m_VtxDesc.low.Normal); + offset += i * elem_size * 3; } int bytes_read = ReadVertex(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, 3, 3, true, - scaling_exponent, &m_native_vtx_decl.normals[i], offset); + scaling_exponent, &m_native_vtx_decl.normals[i], reg, offset); - if (offset == -1) - ADD(EncodeRegTo64(scratch1_reg), EncodeRegTo64(scratch1_reg), bytes_read); - else - offset += bytes_read; + offset += bytes_read; } } @@ -451,9 +428,8 @@ void VertexLoaderARM64::GenerateVertexLoader() if (m_VtxDesc.low.Color[i] != VertexComponentFormat::NotPresent) { - const s32 offset = - GetVertexAddr(CPArray::Color0 + i, m_VtxDesc.low.Color[i], EncodeRegTo64(scratch1_reg)); - ReadColor(m_VtxDesc.low.Color[i], m_VtxAttr.GetColorFormat(i), offset); + 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); 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; @@ -472,12 +448,11 @@ void VertexLoaderARM64::GenerateVertexLoader() const int elements = m_VtxAttr.GetTexElements(i) == TexComponentCount::S ? 1 : 2; if (m_VtxDesc.high.TexCoord[i] != VertexComponentFormat::NotPresent) { - s32 offset = GetVertexAddr(CPArray::TexCoord0 + i, m_VtxDesc.high.TexCoord[i], - EncodeRegTo64(scratch1_reg)); + const auto [reg, offset] = GetVertexAddr(CPArray::TexCoord0 + i, m_VtxDesc.high.TexCoord[i]); 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, - scaling_exponent, &m_native_vtx_decl.texcoords[i], offset); + scaling_exponent, &m_native_vtx_decl.texcoords[i], reg, offset); } if (m_VtxDesc.low.TexMatIdx[i]) { -- cgit v1.2.3 From d80201a57f6433bf660be2a1aecd60b97ddb6599 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 4 Jul 2022 19:20:15 -0700 Subject: VertexLoaderARM64: Fix direct normal+tangent+binormal with index3 set Fixes https://bugs.dolphin-emu.org/issues/12952 --- Source/Core/VideoCommon/VertexLoaderARM64.cpp | 45 ++++++++++++++++----------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoaderARM64.cpp') diff --git a/Source/Core/VideoCommon/VertexLoaderARM64.cpp b/Source/Core/VideoCommon/VertexLoaderARM64.cpp index 3d64e85cb7..99ba5b3357 100644 --- a/Source/Core/VideoCommon/VertexLoaderARM64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderARM64.cpp @@ -102,9 +102,10 @@ std::pair VertexLoaderARM64::GetVertexAddr(CPArray arra } } -int VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentFormat format, - int count_in, int count_out, bool dequantize, u8 scaling_exponent, - AttributeFormat* native_format, ARM64Reg reg, u32 offset) +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) { ARM64Reg coords = count_in == 3 ? ARM64Reg::Q31 : ARM64Reg::D31; ARM64Reg scale = count_in == 3 ? ARM64Reg::Q30 : ARM64Reg::D30; @@ -113,7 +114,6 @@ int VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentForm int load_bytes = elem_size * count_in; int load_size = GetLoadSize(load_bytes); load_size <<= 3; - elem_size <<= 3; m_float_emit.LDUR(load_size, coords, reg, offset); @@ -189,8 +189,6 @@ int VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentForm if (attribute == VertexComponentFormat::Direct) m_src_ofs += load_bytes; - - return load_bytes; } void VertexLoaderARM64::ReadColor(VertexComponentFormat attribute, ColorFormat format, ARM64Reg reg, @@ -400,23 +398,32 @@ void VertexLoaderARM64::GenerateVertexLoader() static constexpr Common::EnumMap(7)> SCALE_MAP = {7, 6, 15, 14, 0, 0, 0, 0}; const u8 scaling_exponent = SCALE_MAP[m_VtxAttr.g0.NormalFormat]; - const int limit = m_VtxAttr.g0.NormalElements == NormalComponentCount::NTB ? 3 : 1; - ARM64Reg reg{}; - u32 offset{}; - for (int i = 0; i < limit; i++) + // 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) { - if (!i || m_VtxAttr.g0.NormalIndex3) - { - const int elem_size = GetElementSize(m_VtxAttr.g0.NormalFormat); + 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; + // Tangent + // If in Index3 mode, and indexed components are used, replace the index with a new index. + if (index3) std::tie(reg, offset) = GetVertexAddr(CPArray::Normal, m_VtxDesc.low.Normal); - offset += i * elem_size * 3; - } - int bytes_read = ReadVertex(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, 3, 3, true, - scaling_exponent, &m_native_vtx_decl.normals[i], reg, offset); - - offset += bytes_read; + // 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); } } -- cgit v1.2.3