Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel #3009

Merged
merged 5 commits into from
Jan 17, 2024
Merged

Devel #3009

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Docs/14-Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ The MeshLodGenerator now also support line primitives and correctly handles the

The interactive mode has been removed. Edge lists are no longer generated by default. Pass `-el` to generate them.

Since 14.2 the flag `-optvtxcache` is available to optimize the vertex cache utilization of a mesh.

## GL3Plus

Transform feedback outputs are now consistently named `xfb_position`, `xfb_uv0` instead of `oPos`, `oUv0`.
Expand Down
11 changes: 9 additions & 2 deletions OgreMain/include/OgreVertexIndexData.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ namespace Ogre {
{
public:
VertexCacheProfiler(unsigned int cachesize = 16)
: size ( cachesize ), tail (0), buffersize (0), hit (0), miss (0)
: size ( cachesize ), tail (0), buffersize (0), hit (0), miss (0), triangles(0)
{
cache = OGRE_ALLOC_T(uint32, size, MEMCATEGORY_GEOMETRY);
}
Expand All @@ -288,18 +288,25 @@ namespace Ogre {
}

void profile(const HardwareIndexBufferSharedPtr& indexBuffer);
void reset() { hit = 0; miss = 0; tail = 0; buffersize = 0; }
void reset() { hit = 0; miss = 0; tail = 0; buffersize = 0; triangles = 0; }
void flush() { tail = 0; buffersize = 0; }

unsigned int getHits() { return hit; }
unsigned int getMisses() { return miss; }
unsigned int getSize() { return size; }

/** Get the average cache miss ratio

@return ratio of vertex cache misses to the triangle count (0.5 - 3.0)
*/
float getAvgCacheMissRatio() { return (float)miss / triangles; }
private:
unsigned int size;
uint32 *cache;

unsigned int tail, buffersize;
unsigned int hit, miss;
uint32 triangles;

bool inCache(unsigned int index);
};
Expand Down
2 changes: 2 additions & 0 deletions OgreMain/src/OgreVertexIndexData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,8 @@ namespace Ogre {
}

indexBuffer->unlock();

triangles += indexBuffer->getNumIndexes()/3;
}

//-----------------------------------------------------------------------
Expand Down
37 changes: 32 additions & 5 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 @@ -426,11 +429,6 @@ struct MeshResourceCreator : public MeshSerializerListener

int main(int numargs, char** args)
{
if (numargs < 2) {
help();
return -1;
}

int retCode = 0;

LogManager logMgr;
Expand All @@ -453,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 All @@ -463,6 +462,13 @@ int main(int numargs, char** args)
binOptList["-log"] = "OgreMeshUpgrader.log";

int startIdx = findCommandLineOpts(numargs, args, unOptList, binOptList);

if(numargs < 2 || numargs == startIdx)
{
help();
return -1;
}

auto opts = parseOpts(unOptList, binOptList);

logMgr.setDefaultLog(NULL); // swallow startup messages
Expand Down Expand Up @@ -557,6 +563,27 @@ 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);
vcp.flush();
vcpnew.flush();
}

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
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ install:
- cmd: pip install swig==4.1.1
- cmd: curl -sSf -o rustup-init.exe https://win.rustup.rs/
- cmd: rustup-init.exe -y
- cmd: curl -LO https://sdk.lunarg.com/sdk/download/1.2.189.2/windows/VulkanSDK-1.2.189.2-Installer.exe
- cmd: VulkanSDK-1.2.189.2-Installer.exe --accept-licenses --default-answer --confirm-command install
- cmd: curl -LO https://sdk.lunarg.com/sdk/download/1.3.224.1/windows/VulkanSDK-1.3.224.1-Installer.exe
- cmd: VulkanSDK-1.3.224.1-Installer.exe --accept-licenses --default-answer --confirm-command install
- cmd: cd %APPVEYOR_BUILD_FOLDER%
- cmd: git submodule update --init --recursive
build_script:
- set PATH=C:\Qt\6.2\msvc2019_64\bin;C:\Users\appveyor\.cargo\bin;%PATH%
- set VULKAN_SDK=C:\VulkanSDK\1.2.189.2
- set VULKAN_SDK=C:\VulkanSDK\1.3.224.1
- cmake -P ci-build.cmake
- cmake --build build --config RelWithDebInfo --target INSTALL
test_script:
Expand Down