diff options
| author | JMC47 <JMC4789@gmail.com> | 2021-03-07 00:21:11 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-07 00:21:11 -0500 |
| commit | 089250fde65c2e225681c0ef6917d28fa187e8de (patch) | |
| tree | bcbb6db025c6003bd681e0028f0bc3b7b223bd07 /Source/Core/VideoCommon/VertexLoader.cpp | |
| parent | 5f7d935b0a40f5cece7341927bd92b6a8d5debbe (diff) | |
| parent | df81210e96c6603d3aeb6c76f51b030d06cd06ac (diff) | |
Merge pull request #9497 from Pokechu22/better-fifo-analyzer
Graphics refactoring + add names and descriptions in FIFO analyzer
Diffstat (limited to 'Source/Core/VideoCommon/VertexLoader.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/VertexLoader.cpp | 148 |
1 files changed, 73 insertions, 75 deletions
diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index d3584ddbeb..f06b60a430 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -2,11 +2,12 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "VideoCommon/VertexLoader.h" + #include "Common/Assert.h" #include "Common/CommonTypes.h" #include "VideoCommon/DataReader.h" -#include "VideoCommon/VertexLoader.h" #include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexLoaderUtils.h" #include "VideoCommon/VertexLoader_Color.h" @@ -84,20 +85,13 @@ void VertexLoader::CompileVertexTranslator() // Reset pipeline m_numPipelineStages = 0; - // Colors - const u64 col[2] = {m_VtxDesc.Color0, m_VtxDesc.Color1}; - // TextureCoord - const u64 tc[8] = {m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord, - m_VtxDesc.Tex3Coord, m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord, - m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord}; - u32 components = 0; // Position in pc vertex format. int nat_offset = 0; // Position Matrix Index - if (m_VtxDesc.PosMatIdx) + if (m_VtxDesc.low.PosMatIdx) { WriteCall(PosMtx_ReadDirect_UByte); components |= VB_HAS_POSMTXIDX; @@ -110,49 +104,49 @@ void VertexLoader::CompileVertexTranslator() m_VertexSize += 1; } - if (m_VtxDesc.Tex0MatIdx) + if (m_VtxDesc.low.Tex0MatIdx) { m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX0; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex1MatIdx) + if (m_VtxDesc.low.Tex1MatIdx) { m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX1; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex2MatIdx) + if (m_VtxDesc.low.Tex2MatIdx) { m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX2; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex3MatIdx) + if (m_VtxDesc.low.Tex3MatIdx) { m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX3; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex4MatIdx) + if (m_VtxDesc.low.Tex4MatIdx) { m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX4; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex5MatIdx) + if (m_VtxDesc.low.Tex5MatIdx) { m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX5; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex6MatIdx) + if (m_VtxDesc.low.Tex6MatIdx) { m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte); } - if (m_VtxDesc.Tex7MatIdx) + if (m_VtxDesc.low.Tex7MatIdx) { m_VertexSize += 1; components |= VB_HAS_TEXMTXIDX7; @@ -160,12 +154,12 @@ void VertexLoader::CompileVertexTranslator() } // Write vertex position loader - WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.Position, m_VtxAttr.PosFormat, + WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.low.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements)); - m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.Position, m_VtxAttr.PosFormat, + m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.low.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements); - int pos_elements = m_VtxAttr.PosElements + 2; + int pos_elements = m_VtxAttr.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; @@ -174,23 +168,24 @@ void VertexLoader::CompileVertexTranslator() nat_offset += pos_elements * sizeof(float); // Normals - if (m_VtxDesc.Normal != NOT_PRESENT) + if (m_VtxDesc.low.Normal != VertexComponentFormat::NotPresent) { - m_VertexSize += VertexLoader_Normal::GetSize(m_VtxDesc.Normal, m_VtxAttr.NormalFormat, + m_VertexSize += VertexLoader_Normal::GetSize(m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3); - TPipelineFunction pFunc = VertexLoader_Normal::GetFunction( - m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3); + TPipelineFunction pFunc = + VertexLoader_Normal::GetFunction(m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat, + m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3); if (pFunc == nullptr) { PanicAlertFmt("VertexLoader_Normal::GetFunction({} {} {} {}) returned zero!", - m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements, + m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3); } WriteCall(pFunc); - for (int i = 0; i < (vtx_attr.NormalElements ? 3 : 1); i++) + for (int i = 0; i < (vtx_attr.NormalElements == NormalComponentCount::NBT ? 3 : 1); i++) { m_native_vtx_decl.normals[i].components = 3; m_native_vtx_decl.normals[i].enable = true; @@ -201,43 +196,43 @@ void VertexLoader::CompileVertexTranslator() } components |= VB_HAS_NRM0; - if (m_VtxAttr.NormalElements == 1) + if (m_VtxAttr.NormalElements == NormalComponentCount::NBT) components |= VB_HAS_NRM1 | VB_HAS_NRM2; } - for (int i = 0; i < 2; i++) + for (size_t i = 0; i < m_VtxDesc.low.Color.Size(); i++) { 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 (col[i]) + switch (m_VtxDesc.low.Color[i]) { - case NOT_PRESENT: + case VertexComponentFormat::NotPresent: break; - case DIRECT: + case VertexComponentFormat::Direct: switch (m_VtxAttr.color[i].Comp) { - case FORMAT_16B_565: + case ColorFormat::RGB565: m_VertexSize += 2; WriteCall(Color_ReadDirect_16b_565); break; - case FORMAT_24B_888: + case ColorFormat::RGB888: m_VertexSize += 3; WriteCall(Color_ReadDirect_24b_888); break; - case FORMAT_32B_888x: + case ColorFormat::RGB888x: m_VertexSize += 4; WriteCall(Color_ReadDirect_32b_888x); break; - case FORMAT_16B_4444: + case ColorFormat::RGBA4444: m_VertexSize += 2; WriteCall(Color_ReadDirect_16b_4444); break; - case FORMAT_24B_6666: + case ColorFormat::RGBA6666: m_VertexSize += 3; WriteCall(Color_ReadDirect_24b_6666); break; - case FORMAT_32B_8888: + case ColorFormat::RGBA8888: m_VertexSize += 4; WriteCall(Color_ReadDirect_32b_8888); break; @@ -246,26 +241,26 @@ void VertexLoader::CompileVertexTranslator() break; } break; - case INDEX8: + case VertexComponentFormat::Index8: m_VertexSize += 1; switch (m_VtxAttr.color[i].Comp) { - case FORMAT_16B_565: + case ColorFormat::RGB565: WriteCall(Color_ReadIndex8_16b_565); break; - case FORMAT_24B_888: + case ColorFormat::RGB888: WriteCall(Color_ReadIndex8_24b_888); break; - case FORMAT_32B_888x: + case ColorFormat::RGB888x: WriteCall(Color_ReadIndex8_32b_888x); break; - case FORMAT_16B_4444: + case ColorFormat::RGBA4444: WriteCall(Color_ReadIndex8_16b_4444); break; - case FORMAT_24B_6666: + case ColorFormat::RGBA6666: WriteCall(Color_ReadIndex8_24b_6666); break; - case FORMAT_32B_8888: + case ColorFormat::RGBA8888: WriteCall(Color_ReadIndex8_32b_8888); break; default: @@ -273,26 +268,26 @@ void VertexLoader::CompileVertexTranslator() break; } break; - case INDEX16: + case VertexComponentFormat::Index16: m_VertexSize += 2; switch (m_VtxAttr.color[i].Comp) { - case FORMAT_16B_565: + case ColorFormat::RGB565: WriteCall(Color_ReadIndex16_16b_565); break; - case FORMAT_24B_888: + case ColorFormat::RGB888: WriteCall(Color_ReadIndex16_24b_888); break; - case FORMAT_32B_888x: + case ColorFormat::RGB888x: WriteCall(Color_ReadIndex16_32b_888x); break; - case FORMAT_16B_4444: + case ColorFormat::RGBA4444: WriteCall(Color_ReadIndex16_16b_4444); break; - case FORMAT_24B_6666: + case ColorFormat::RGBA6666: WriteCall(Color_ReadIndex16_24b_6666); break; - case FORMAT_32B_8888: + case ColorFormat::RGBA8888: WriteCall(Color_ReadIndex16_32b_8888); break; default: @@ -302,7 +297,7 @@ void VertexLoader::CompileVertexTranslator() break; } // Common for the three bottom cases - if (col[i] != NOT_PRESENT) + if (m_VtxDesc.low.Color[i] != VertexComponentFormat::NotPresent) { components |= VB_HAS_COL0 << i; m_native_vtx_decl.colors[i].offset = nat_offset; @@ -312,38 +307,40 @@ void VertexLoader::CompileVertexTranslator() } // Texture matrix indices (remove if corresponding texture coordinate isn't enabled) - for (int i = 0; i < 8; i++) + for (size_t i = 0; i < m_VtxDesc.high.TexCoord.Size(); i++) { m_native_vtx_decl.texcoords[i].offset = nat_offset; m_native_vtx_decl.texcoords[i].type = VAR_FLOAT; m_native_vtx_decl.texcoords[i].integer = false; - const int format = m_VtxAttr.texCoord[i].Format; - const int elements = m_VtxAttr.texCoord[i].Elements; + 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; - if (tc[i] != NOT_PRESENT) + if (tc != VertexComponentFormat::NotPresent) { - ASSERT_MSG(VIDEO, DIRECT <= tc[i] && tc[i] <= INDEX16, - "Invalid texture coordinates!\n(tc[i] = %d)", (u32)tc[i]); - ASSERT_MSG(VIDEO, FORMAT_UBYTE <= format && format <= FORMAT_FLOAT, - "Invalid texture coordinates format!\n(format = %d)", format); - ASSERT_MSG(VIDEO, 0 <= elements && elements <= 1, - "Invalid number of texture coordinates elements!\n(elements = %d)", elements); + ASSERT_MSG(VIDEO, VertexComponentFormat::Direct <= tc && tc <= VertexComponentFormat::Index16, + "Invalid texture coordinates!\n(tc = %d)", (u32)tc); + ASSERT_MSG(VIDEO, ComponentFormat::UByte <= format && format <= ComponentFormat::Float, + "Invalid texture coordinates format!\n(format = %d)", (u32)format); + 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[i], format, elements)); - m_VertexSize += VertexLoader_TextCoord::GetSize(tc[i], format, elements); + WriteCall(VertexLoader_TextCoord::GetFunction(tc, format, elements)); + m_VertexSize += VertexLoader_TextCoord::GetSize(tc, format, elements); } if (components & (VB_HAS_TEXMTXIDX0 << i)) { m_native_vtx_decl.texcoords[i].enable = true; - if (tc[i] != NOT_PRESENT) + 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(m_VtxAttr.texCoord[i].Elements ? TexMtx_Write_Float : TexMtx_Write_Float2); + WriteCall(m_VtxAttr.texCoord[i].Elements == TexComponentCount::ST ? TexMtx_Write_Float : + TexMtx_Write_Float2); } else { @@ -354,21 +351,22 @@ void VertexLoader::CompileVertexTranslator() } else { - if (tc[i] != NOT_PRESENT) + if (tc != VertexComponentFormat::NotPresent) { m_native_vtx_decl.texcoords[i].enable = true; - m_native_vtx_decl.texcoords[i].components = vtx_attr.texCoord[i].Elements ? 2 : 1; - nat_offset += 4 * (vtx_attr.texCoord[i].Elements ? 2 : 1); + 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); } } - if (tc[i] == NOT_PRESENT) + if (tc == VertexComponentFormat::NotPresent) { // if there's more tex coords later, have to write a dummy call - int j = i + 1; - for (; j < 8; ++j) + size_t j = i + 1; + for (; j < m_VtxDesc.high.TexCoord.Size(); ++j) { - if (tc[j] != NOT_PRESENT) + if (m_VtxDesc.high.TexCoord[j] != VertexComponentFormat::NotPresent) { WriteCall(VertexLoader_TextCoord::GetDummyFunction()); // important to get indices right! break; @@ -383,8 +381,8 @@ void VertexLoader::CompileVertexTranslator() } } - // indexed position formats may skip a the vertex - if (m_VtxDesc.Position & 2) + // indexed position formats may skip the vertex + if (IsIndexed(m_VtxDesc.low.Position)) { WriteCall(SkipVertex); } |
