Arseny Kapoulkine 6cbf8afcd7 pretransformanalyzer: Add pre-transform cache analyzer
Generally vertex fetch goes through a more or less traditional cache.
This cache can have different size, number of ways, replacement policy
and also may or may not be shared with other units, like texture fetch.

Modeling the real cache is subtle and complicated; this provides a
simple approximation that uses a moderately sized direct-mapped cache.
The performance is close to that of a 4-way cache on typical mesh data
and direct mapping is slightly simpler to implement.

The primary metric for the fetch cache is currently 'overfetch' factor -
that is, the ratio between the number of bytes we need to fetch to
transform all the vertices to the optimal number of bytes aka the size
of the vertex buffer. This will depend on the vertex size, cache
alignment and, most importantly, vertex index order.
2017-05-24 20:06:40 -07:00
2017-05-15 20:48:53 -07:00
2016-09-08 22:48:31 -07:00
2017-05-17 23:45:45 -07:00
2017-05-22 20:32:13 -07:00
2017-05-19 08:43:25 -07:00

meshoptimizer Build Status Build status

Purpose

To make sure GPU can render indexed meshes efficiently, you should optimize them for pre-transform cache (to improve vertex fetch locality) and for post-transform cache (to reduce the number of vertex shader invocations). This library provides algorithms for both.

Post-transform cache optimization involves reordering triangle indices to make sure that the vertices referenced by the triangles are hitting the built-in fixed size GPU cache (which is usually small, 16-32 vertices, and can have different replacement policies) as much as possible. All algorithms take index data as an input and produce a new index buffer.

Pre-transform cache optimization involves reordering vertices (and remapping triangle indices) to make sure that the memory cache that GPU uses to fetch vertex data is utilized efficiently.

You should first optimize your mesh for post-transform cache (to get the optimal triangle order), and then optimize the result for pre-transform cache (which keeps the triangle order but changes the vertex data) for maximum efficiency.

The post-transform optimization algorithm is capable of optimizing for overdraw by splitting the mesh into clusters and reordering them using a heuristic that tries to reduce overdraw. The heuristic needs access to vertex positions.

Post-transform optimizer

The library implements an algorithm Tipsify for post-transform cache and overdraw optimization.

To use Tipsify for post-transform optimization, invoke this function:

optimizePostTransform(new_index_data, index_data, index_count, vertex_count)

You have to pass a pointer to the resulting index array as new_index_data, which will be filled with an optimized index sequence.

To use Tipsify for post-transform and overdraw optimization, you have to invoke the function with an additional output argument, which you then have to pass to another function:

float threshold = 1.05f;

std::vector<unsigned int> clusters;
optimizePostTransform(temp_index_data, index_data, index_count, vertex_count, 16, &clusters);
optimizeOverdraw(new_index_data, temp_index_data, index_count, vertex_positions, vertex_stride, vertex_count, clusters, 16, threshold);

The first call generates a cache-optimized index sequence to the temp location as well as a set of clusters that the second call then reorders to get better overdraw results. The overdraw optimizer also needs to read vertex positions, which you have to provide as a pointer to a float3 vector and a stride, similar to glVertexPointer.

You can also provide a threshold that will determine how much the algorithm can compromise the vertex cache hit ratio in favor of overdraw; 1.05 means that the resulting vertex cache hit ratio should be at most 5% worse than a non-overdraw optimized order.

Pre-transform optimizer

This algorithm is pretty straightforward - it does not try to model cache replacement and instead just orders vertices in the order of their use, which generally produces results that are close to optimal on real meshes. To invoke it, call:

optimizePreTransform(new_vertices, vertices, indices, index_count, vertex_count, vertex_size)

In a similar fashion to other functions, you have to provide a pointer to the resulting vertex buffer which will be filled with vertices from the source vertex buffer.

Vertex cache analyzer

You can use the provided analyzer to compute approximate statistics for the given vertex data by calling analyzePostTransform function.

The common metric to use is ACMR - average cache miss ratio, which is the ratio of the total number of vertex invocations to the triangle count. The worst-case ACMR is 3 (GPU has to process 3 vertices for each triangle); on regular grids the optimal ACMR approaches 0.5. On real meshes it usually is in [0.5..1.5] ratio depending on the amount of vertex splits.

License

This library is available to anybody free of charge, under the terms of MIT License (see LICENSE.md)

S
Description
meshoptimizer 是一个高效的网格优化库,旨在通过多种技术减少 3D 网格数据的存储大小和提升渲染性能。它主要用于图形学和游戏开发领域,尤其是处理大量多边形的 3D 模型时,能够显著降低渲染负担,提高运行效率。
Readme 13 MiB
Languages
C++ 78.7%
JavaScript 11%
C 8%
Makefile 1.1%
CMake 0.7%
Other 0.5%