VertexLoader: Optimize GetVertexSize
GetComponentSizes was unused, so we simplify this and get rid of the branches.
This commit is contained in:
parent
3420823002
commit
8aa214453a
|
@ -12,6 +12,7 @@
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "Common/Assert.h"
|
#include "Common/Assert.h"
|
||||||
|
#include "Common/BitSet.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
|
@ -96,45 +97,33 @@ private:
|
||||||
std::vector<u8> buffer_b;
|
std::vector<u8> buffer_b;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Function>
|
u32 VertexLoaderBase::GetVertexSize(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
|
||||||
static void GetComponentSizes(const TVtxDesc& vtx_desc, const VAT& vtx_attr, Function f)
|
|
||||||
{
|
{
|
||||||
if (vtx_desc.low.PosMatIdx)
|
u32 size = 0;
|
||||||
f(1);
|
|
||||||
for (auto texmtxidx : vtx_desc.low.TexMatIdx)
|
// Each enabled TexMatIdx adds one byte, as does PosMatIdx
|
||||||
{
|
size += Common::CountSetBits(vtx_desc.low.Hex & 0x1FF);
|
||||||
if (texmtxidx)
|
|
||||||
f(1);
|
|
||||||
}
|
|
||||||
const u32 pos_size = VertexLoader_Position::GetSize(vtx_desc.low.Position, vtx_attr.g0.PosFormat,
|
const u32 pos_size = VertexLoader_Position::GetSize(vtx_desc.low.Position, vtx_attr.g0.PosFormat,
|
||||||
vtx_attr.g0.PosElements);
|
vtx_attr.g0.PosElements);
|
||||||
if (pos_size != 0)
|
size += pos_size;
|
||||||
f(pos_size);
|
|
||||||
const u32 norm_size =
|
const u32 norm_size =
|
||||||
VertexLoader_Normal::GetSize(vtx_desc.low.Normal, vtx_attr.g0.NormalFormat,
|
VertexLoader_Normal::GetSize(vtx_desc.low.Normal, vtx_attr.g0.NormalFormat,
|
||||||
vtx_attr.g0.NormalElements, vtx_attr.g0.NormalIndex3);
|
vtx_attr.g0.NormalElements, vtx_attr.g0.NormalIndex3);
|
||||||
if (norm_size != 0)
|
size += norm_size;
|
||||||
f(norm_size);
|
|
||||||
for (u32 i = 0; i < vtx_desc.low.Color.Size(); i++)
|
for (u32 i = 0; i < vtx_desc.low.Color.Size(); i++)
|
||||||
{
|
{
|
||||||
const u32 color_size =
|
const u32 color_size =
|
||||||
VertexLoader_Color::GetSize(vtx_desc.low.Color[i], vtx_attr.GetColorFormat(i));
|
VertexLoader_Color::GetSize(vtx_desc.low.Color[i], vtx_attr.GetColorFormat(i));
|
||||||
if (color_size != 0)
|
size += color_size;
|
||||||
f(color_size);
|
|
||||||
}
|
}
|
||||||
for (u32 i = 0; i < vtx_desc.high.TexCoord.Size(); i++)
|
for (u32 i = 0; i < vtx_desc.high.TexCoord.Size(); i++)
|
||||||
{
|
{
|
||||||
const u32 tc_size = VertexLoader_TextCoord::GetSize(
|
const u32 tc_size = VertexLoader_TextCoord::GetSize(
|
||||||
vtx_desc.high.TexCoord[i], vtx_attr.GetTexFormat(i), vtx_attr.GetTexElements(i));
|
vtx_desc.high.TexCoord[i], vtx_attr.GetTexFormat(i), vtx_attr.GetTexElements(i));
|
||||||
if (tc_size != 0)
|
size += tc_size;
|
||||||
f(tc_size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 VertexLoaderBase::GetVertexSize(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
|
|
||||||
{
|
|
||||||
u32 size = 0;
|
|
||||||
GetComponentSizes(vtx_desc, vtx_attr, [&size](u32 s) { size += s; });
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,14 +157,6 @@ u32 VertexLoaderBase::GetVertexComponents(const TVtxDesc& vtx_desc, const VAT& v
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<u32> VertexLoaderBase::GetVertexComponentSizes(const TVtxDesc& vtx_desc,
|
|
||||||
const VAT& vtx_attr)
|
|
||||||
{
|
|
||||||
std::vector<u32> sizes;
|
|
||||||
GetComponentSizes(vtx_desc, vtx_attr, [&sizes](u32 s) { sizes.push_back(s); });
|
|
||||||
return sizes;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<VertexLoaderBase> VertexLoaderBase::CreateVertexLoader(const TVtxDesc& vtx_desc,
|
std::unique_ptr<VertexLoaderBase> VertexLoaderBase::CreateVertexLoader(const TVtxDesc& vtx_desc,
|
||||||
const VAT& vtx_attr)
|
const VAT& vtx_attr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,7 +62,6 @@ class VertexLoaderBase
|
||||||
public:
|
public:
|
||||||
static u32 GetVertexSize(const TVtxDesc& vtx_desc, const VAT& vtx_attr);
|
static u32 GetVertexSize(const TVtxDesc& vtx_desc, const VAT& vtx_attr);
|
||||||
static u32 GetVertexComponents(const TVtxDesc& vtx_desc, const VAT& vtx_attr);
|
static u32 GetVertexComponents(const TVtxDesc& vtx_desc, const VAT& vtx_attr);
|
||||||
static std::vector<u32> GetVertexComponentSizes(const TVtxDesc& vtx_desc, const VAT& vtx_attr);
|
|
||||||
static std::unique_ptr<VertexLoaderBase> CreateVertexLoader(const TVtxDesc& vtx_desc,
|
static std::unique_ptr<VertexLoaderBase> CreateVertexLoader(const TVtxDesc& vtx_desc,
|
||||||
const VAT& vtx_attr);
|
const VAT& vtx_attr);
|
||||||
virtual ~VertexLoaderBase() {}
|
virtual ~VertexLoaderBase() {}
|
||||||
|
|
Loading…
Reference in New Issue