From bc7da726a5b8cc8e9c229a62796993a9e1119362 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Wed, 10 Mar 2021 17:11:45 -0800 Subject: Convert VertexLoader_Color to a table --- Source/Core/VideoCommon/VertexLoader.cpp | 102 +++---------------------------- 1 file changed, 10 insertions(+), 92 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoader.cpp') diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index f06b60a430..f51b27518f 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -205,98 +205,16 @@ void VertexLoader::CompileVertexTranslator() m_native_vtx_decl.colors[i].components = 4; m_native_vtx_decl.colors[i].type = VAR_UNSIGNED_BYTE; m_native_vtx_decl.colors[i].integer = false; - switch (m_VtxDesc.low.Color[i]) - { - case VertexComponentFormat::NotPresent: - break; - case VertexComponentFormat::Direct: - switch (m_VtxAttr.color[i].Comp) - { - case ColorFormat::RGB565: - m_VertexSize += 2; - WriteCall(Color_ReadDirect_16b_565); - break; - case ColorFormat::RGB888: - m_VertexSize += 3; - WriteCall(Color_ReadDirect_24b_888); - break; - case ColorFormat::RGB888x: - m_VertexSize += 4; - WriteCall(Color_ReadDirect_32b_888x); - break; - case ColorFormat::RGBA4444: - m_VertexSize += 2; - WriteCall(Color_ReadDirect_16b_4444); - break; - case ColorFormat::RGBA6666: - m_VertexSize += 3; - WriteCall(Color_ReadDirect_24b_6666); - break; - case ColorFormat::RGBA8888: - m_VertexSize += 4; - WriteCall(Color_ReadDirect_32b_8888); - break; - default: - ASSERT(0); - break; - } - break; - case VertexComponentFormat::Index8: - m_VertexSize += 1; - switch (m_VtxAttr.color[i].Comp) - { - case ColorFormat::RGB565: - WriteCall(Color_ReadIndex8_16b_565); - break; - case ColorFormat::RGB888: - WriteCall(Color_ReadIndex8_24b_888); - break; - case ColorFormat::RGB888x: - WriteCall(Color_ReadIndex8_32b_888x); - break; - case ColorFormat::RGBA4444: - WriteCall(Color_ReadIndex8_16b_4444); - break; - case ColorFormat::RGBA6666: - WriteCall(Color_ReadIndex8_24b_6666); - break; - case ColorFormat::RGBA8888: - WriteCall(Color_ReadIndex8_32b_8888); - break; - default: - ASSERT(0); - break; - } - break; - case VertexComponentFormat::Index16: - m_VertexSize += 2; - switch (m_VtxAttr.color[i].Comp) - { - case ColorFormat::RGB565: - WriteCall(Color_ReadIndex16_16b_565); - break; - case ColorFormat::RGB888: - WriteCall(Color_ReadIndex16_24b_888); - break; - case ColorFormat::RGB888x: - WriteCall(Color_ReadIndex16_32b_888x); - break; - case ColorFormat::RGBA4444: - WriteCall(Color_ReadIndex16_16b_4444); - break; - case ColorFormat::RGBA6666: - WriteCall(Color_ReadIndex16_24b_6666); - break; - case ColorFormat::RGBA8888: - WriteCall(Color_ReadIndex16_32b_8888); - break; - default: - ASSERT(0); - break; - } - break; - } - // Common for the three bottom cases + + m_VertexSize += VertexLoader_Color::GetSize(m_VtxDesc.low.Color[i], m_VtxAttr.color[i].Comp); + TPipelineFunction pFunc = + VertexLoader_Color::GetFunction(m_VtxDesc.low.Color[i], m_VtxAttr.color[i].Comp); + + if (pFunc != nullptr) + WriteCall(pFunc); + else + ASSERT(m_VtxDesc.low.Color[i] == VertexComponentFormat::NotPresent); + if (m_VtxDesc.low.Color[i] != VertexComponentFormat::NotPresent) { components |= VB_HAS_COL0 << i; -- cgit v1.2.3 From cafffff75ea4fc42c401b87370e94efe17309cad Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Wed, 10 Mar 2021 22:15:43 -0800 Subject: Eliminate TVtxAttr --- Source/Core/VideoCommon/VertexLoader.cpp | 51 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoader.cpp') diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index f51b27518f..da8e0d2e05 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -72,15 +72,14 @@ VertexLoader::VertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr) CompileVertexTranslator(); // generate frac factors - m_posScale = 1.0f / (1U << m_VtxAttr.PosFrac); - for (int i = 0; i < 8; i++) - m_tcScale[i] = 1.0f / (1U << m_VtxAttr.texCoord[i].Frac); + m_posScale = 1.0f / (1U << m_VtxAttr.g0.PosFrac); + for (u32 i = 0; i < 8; i++) + m_tcScale[i] = 1.0f / (1U << m_VtxAttr.GetTexFrac(i)); } void VertexLoader::CompileVertexTranslator() { m_VertexSize = 0; - const TVtxAttr& vtx_attr = m_VtxAttr; // Reset pipeline m_numPipelineStages = 0; @@ -154,12 +153,12 @@ void VertexLoader::CompileVertexTranslator() } // Write vertex position loader - WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.low.Position, m_VtxAttr.PosFormat, - m_VtxAttr.PosElements)); + WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.low.Position, m_VtxAttr.g0.PosFormat, + m_VtxAttr.g0.PosElements)); - m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.low.Position, m_VtxAttr.PosFormat, - m_VtxAttr.PosElements); - int pos_elements = m_VtxAttr.PosElements == CoordComponentCount::XY ? 2 : 3; + m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.low.Position, m_VtxAttr.g0.PosFormat, + m_VtxAttr.g0.PosElements); + int pos_elements = m_VtxAttr.g0.PosElements == CoordComponentCount::XY ? 2 : 3; m_native_vtx_decl.position.components = pos_elements; m_native_vtx_decl.position.enable = true; m_native_vtx_decl.position.offset = nat_offset; @@ -170,22 +169,23 @@ void VertexLoader::CompileVertexTranslator() // Normals if (m_VtxDesc.low.Normal != VertexComponentFormat::NotPresent) { - m_VertexSize += VertexLoader_Normal::GetSize(m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat, - m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3); + m_VertexSize += + VertexLoader_Normal::GetSize(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, + m_VtxAttr.g0.NormalElements, m_VtxAttr.g0.NormalIndex3); TPipelineFunction pFunc = - VertexLoader_Normal::GetFunction(m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat, - m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3); + VertexLoader_Normal::GetFunction(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, + m_VtxAttr.g0.NormalElements, m_VtxAttr.g0.NormalIndex3); if (pFunc == nullptr) { PanicAlertFmt("VertexLoader_Normal::GetFunction({} {} {} {}) returned zero!", - m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements, - m_VtxAttr.NormalIndex3); + m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, m_VtxAttr.g0.NormalElements, + m_VtxAttr.g0.NormalIndex3); } WriteCall(pFunc); - for (int i = 0; i < (vtx_attr.NormalElements == NormalComponentCount::NBT ? 3 : 1); i++) + for (int i = 0; i < (m_VtxAttr.g0.NormalElements == NormalComponentCount::NBT ? 3 : 1); i++) { m_native_vtx_decl.normals[i].components = 3; m_native_vtx_decl.normals[i].enable = true; @@ -196,7 +196,7 @@ void VertexLoader::CompileVertexTranslator() } components |= VB_HAS_NRM0; - if (m_VtxAttr.NormalElements == NormalComponentCount::NBT) + if (m_VtxAttr.g0.NormalElements == NormalComponentCount::NBT) components |= VB_HAS_NRM1 | VB_HAS_NRM2; } @@ -206,9 +206,10 @@ void VertexLoader::CompileVertexTranslator() m_native_vtx_decl.colors[i].type = VAR_UNSIGNED_BYTE; m_native_vtx_decl.colors[i].integer = false; - m_VertexSize += VertexLoader_Color::GetSize(m_VtxDesc.low.Color[i], m_VtxAttr.color[i].Comp); + m_VertexSize += + VertexLoader_Color::GetSize(m_VtxDesc.low.Color[i], m_VtxAttr.GetColorFormat(i)); TPipelineFunction pFunc = - VertexLoader_Color::GetFunction(m_VtxDesc.low.Color[i], m_VtxAttr.color[i].Comp); + VertexLoader_Color::GetFunction(m_VtxDesc.low.Color[i], m_VtxAttr.GetColorFormat(i)); if (pFunc != nullptr) WriteCall(pFunc); @@ -232,8 +233,8 @@ void VertexLoader::CompileVertexTranslator() m_native_vtx_decl.texcoords[i].integer = false; const auto tc = m_VtxDesc.high.TexCoord[i].Value(); - const auto format = m_VtxAttr.texCoord[i].Format; - const auto elements = m_VtxAttr.texCoord[i].Elements; + const auto format = m_VtxAttr.GetTexFormat(i); + const auto elements = m_VtxAttr.GetTexElements(i); if (tc != VertexComponentFormat::NotPresent) { @@ -257,8 +258,7 @@ void VertexLoader::CompileVertexTranslator() // if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index m_native_vtx_decl.texcoords[i].components = 3; nat_offset += 12; - WriteCall(m_VtxAttr.texCoord[i].Elements == TexComponentCount::ST ? TexMtx_Write_Float : - TexMtx_Write_Float2); + WriteCall(elements == TexComponentCount::ST ? TexMtx_Write_Float : TexMtx_Write_Float2); } else { @@ -272,9 +272,8 @@ void VertexLoader::CompileVertexTranslator() if (tc != VertexComponentFormat::NotPresent) { m_native_vtx_decl.texcoords[i].enable = true; - m_native_vtx_decl.texcoords[i].components = - vtx_attr.texCoord[i].Elements == TexComponentCount::ST ? 2 : 1; - nat_offset += 4 * (vtx_attr.texCoord[i].Elements == TexComponentCount::ST ? 2 : 1); + m_native_vtx_decl.texcoords[i].components = elements == TexComponentCount::ST ? 2 : 1; + nat_offset += 4 * (elements == TexComponentCount::ST ? 2 : 1); } } -- cgit v1.2.3 From 0a906f553fe7699d1c863a464211f74b6c306a0f Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Thu, 11 Mar 2021 12:55:25 -0800 Subject: Move vertex size and component calculation to VertexLoaderBase --- Source/Core/VideoCommon/VertexLoader.cpp | 91 +++++--------------------------- 1 file changed, 14 insertions(+), 77 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoader.cpp') diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index da8e0d2e05..0d49ef1a4b 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -79,13 +79,9 @@ VertexLoader::VertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr) void VertexLoader::CompileVertexTranslator() { - m_VertexSize = 0; - // Reset pipeline m_numPipelineStages = 0; - u32 components = 0; - // Position in pc vertex format. int nat_offset = 0; @@ -93,71 +89,24 @@ void VertexLoader::CompileVertexTranslator() if (m_VtxDesc.low.PosMatIdx) { WriteCall(PosMtx_ReadDirect_UByte); - components |= VB_HAS_POSMTXIDX; m_native_vtx_decl.posmtx.components = 4; m_native_vtx_decl.posmtx.enable = true; m_native_vtx_decl.posmtx.offset = nat_offset; m_native_vtx_decl.posmtx.type = VAR_UNSIGNED_BYTE; m_native_vtx_decl.posmtx.integer = true; nat_offset += 4; - m_VertexSize += 1; } - if (m_VtxDesc.low.Tex0MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX0; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex1MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX1; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex2MatIdx) + for (auto texmtxidx : m_VtxDesc.low.TexMatIdx) { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX2; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex3MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX3; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex4MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX4; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex5MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX5; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex6MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX6; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex7MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX7; - WriteCall(TexMtx_ReadDirect_UByte); + if (texmtxidx) + WriteCall(TexMtx_ReadDirect_UByte); } // Write vertex position loader WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.low.Position, m_VtxAttr.g0.PosFormat, m_VtxAttr.g0.PosElements)); - m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.low.Position, m_VtxAttr.g0.PosFormat, - m_VtxAttr.g0.PosElements); int pos_elements = m_VtxAttr.g0.PosElements == CoordComponentCount::XY ? 2 : 3; m_native_vtx_decl.position.components = pos_elements; m_native_vtx_decl.position.enable = true; @@ -169,10 +118,6 @@ void VertexLoader::CompileVertexTranslator() // Normals if (m_VtxDesc.low.Normal != VertexComponentFormat::NotPresent) { - m_VertexSize += - VertexLoader_Normal::GetSize(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, - m_VtxAttr.g0.NormalElements, m_VtxAttr.g0.NormalIndex3); - TPipelineFunction pFunc = VertexLoader_Normal::GetFunction(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, m_VtxAttr.g0.NormalElements, m_VtxAttr.g0.NormalIndex3); @@ -194,10 +139,6 @@ void VertexLoader::CompileVertexTranslator() m_native_vtx_decl.normals[i].integer = false; nat_offset += 12; } - - components |= VB_HAS_NRM0; - if (m_VtxAttr.g0.NormalElements == NormalComponentCount::NBT) - components |= VB_HAS_NRM1 | VB_HAS_NRM2; } for (size_t i = 0; i < m_VtxDesc.low.Color.Size(); i++) @@ -206,8 +147,6 @@ void VertexLoader::CompileVertexTranslator() m_native_vtx_decl.colors[i].type = VAR_UNSIGNED_BYTE; m_native_vtx_decl.colors[i].integer = false; - m_VertexSize += - VertexLoader_Color::GetSize(m_VtxDesc.low.Color[i], m_VtxAttr.GetColorFormat(i)); TPipelineFunction pFunc = VertexLoader_Color::GetFunction(m_VtxDesc.low.Color[i], m_VtxAttr.GetColorFormat(i)); @@ -218,7 +157,6 @@ void VertexLoader::CompileVertexTranslator() if (m_VtxDesc.low.Color[i] != VertexComponentFormat::NotPresent) { - components |= VB_HAS_COL0 << i; m_native_vtx_decl.colors[i].offset = nat_offset; m_native_vtx_decl.colors[i].enable = true; nat_offset += 4; @@ -245,25 +183,21 @@ void VertexLoader::CompileVertexTranslator() ASSERT_MSG(VIDEO, elements == TexComponentCount::S || elements == TexComponentCount::ST, "Invalid number of texture coordinates elements!\n(elements = %d)", (u32)elements); - components |= VB_HAS_UV0 << i; WriteCall(VertexLoader_TextCoord::GetFunction(tc, format, elements)); - m_VertexSize += VertexLoader_TextCoord::GetSize(tc, format, elements); } - if (components & (VB_HAS_TEXMTXIDX0 << i)) + if (m_VtxDesc.low.TexMatIdx[i]) { m_native_vtx_decl.texcoords[i].enable = true; + m_native_vtx_decl.texcoords[i].components = 3; + nat_offset += 12; if (tc != VertexComponentFormat::NotPresent) { // if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index - m_native_vtx_decl.texcoords[i].components = 3; - nat_offset += 12; WriteCall(elements == TexComponentCount::ST ? TexMtx_Write_Float : TexMtx_Write_Float2); } else { - m_native_vtx_decl.texcoords[i].components = 3; - nat_offset += 12; WriteCall(TexMtx_Write_Float3); } } @@ -280,17 +214,21 @@ void VertexLoader::CompileVertexTranslator() if (tc == VertexComponentFormat::NotPresent) { // if there's more tex coords later, have to write a dummy call - size_t j = i + 1; - for (; j < m_VtxDesc.high.TexCoord.Size(); ++j) + bool has_more = false; + for (size_t j = 0; j < m_VtxDesc.high.TexCoord.Size(); ++j) { if (m_VtxDesc.high.TexCoord[j] != VertexComponentFormat::NotPresent) { + has_more = true; WriteCall(VertexLoader_TextCoord::GetDummyFunction()); // important to get indices right! break; } + else if (m_VtxDesc.low.TexMatIdx[i]) + { + has_more = true; + } } - // tricky! - if (j == 8 && !((components & VB_HAS_TEXMTXIDXALL) & (VB_HAS_TEXMTXIDXALL << (i + 1)))) + if (!has_more) { // no more tex coords and tex matrices, so exit loop break; @@ -304,7 +242,6 @@ void VertexLoader::CompileVertexTranslator() WriteCall(SkipVertex); } - m_native_components = components; m_native_vtx_decl.stride = nat_offset; } -- cgit v1.2.3