Skip to content

Commit

Permalink
Tools: MeshUpgrader - add optvtxcache flag to optimize vertex cache
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Jan 16, 2024
1 parent 3b430d0 commit ac7a0d8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Tools/MeshUpgrader/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ R"HELP(Usage: OgreMeshUpgrader [opts] sourcefile [destfile]
Upgrades or downgrades .mesh file versions.
-pack = Pack normals and tangents as int_10_10_10_2
-optvtxcache = Reorder the indexes to optimise vertex cache utilisation
-autogen = Generate autoconfigured LOD. No LOD options needed
-l lodlevels = number of LOD levels
-d loddist = distance increment to reduce LOD
Expand Down Expand Up @@ -81,6 +82,7 @@ struct UpgradeOptions {
bool dontReorganise;
bool lodAutoconfigure;
bool packNormalsTangents;
bool optimiseVertexCache;
unsigned short numLods;
Real lodDist;
Real lodPercent;
Expand Down Expand Up @@ -123,6 +125,7 @@ UpgradeOptions parseOpts(UnaryOptionList& unOpts, BinaryOptionList& binOpts)
opts.lodAutoconfigure = unOpts["-autogen"];
opts.dontReorganise = unOpts["-r"];
opts.packNormalsTangents = unOpts["-pack"];
opts.optimiseVertexCache = unOpts["-optvtxcache"];

// Unary options (true/false options that don't take a parameter)
if (unOpts["-b"]) {
Expand Down Expand Up @@ -448,6 +451,7 @@ int main(int numargs, char** args)
unOptList["-autogen"] = false;
unOptList["-pack"] = false;
unOptList["-b"] = false;
unOptList["-optvtxcache"] = false;
binOptList["-l"] = "";
binOptList["-d"] = "";
binOptList["-p"] = "";
Expand Down Expand Up @@ -559,6 +563,25 @@ int main(int numargs, char** args)
recalcBounds(mesh);
}

if(opts.optimiseVertexCache)
{
logMgr.logMessage("Vertex cache optimization...");
VertexCacheProfiler vcp;
VertexCacheProfiler vcpnew;

for (auto s : mesh->getSubMeshes())
{
if(!s->indexData->indexBuffer)
continue;
vcp.profile(s->indexData->indexBuffer);
s->indexData->optimiseVertexCacheTriList();
vcpnew.profile(s->indexData->indexBuffer);
}

logMgr.logMessage(StringUtil::format("Vertex cache optimization: ACMR change %.2f -> %.2f",
vcp.getAvgCacheMissRatio(), vcpnew.getAvgCacheMissRatio()));
}

meshSerializer.exportMesh(mesh, dest, opts.targetVersion, opts.endian);

logMgr.setDefaultLog(NULL); // swallow shutdown messages
Expand Down

0 comments on commit ac7a0d8

Please sign in to comment.