Commit Graph

29 Commits

Author SHA1 Message Date
wangshilin c101fc65e3 增加相关文档,测试用例。Signed-off-by: wangshilin <wangshilin20@h-partners.com> 2025-09-18 20:24:47 +08:00
Arseny Kapoulkine fcc3c307f9 Replace meshopt_Buffer with meshopt_Allocator
meshopt_Allocator can be used to allocate typed buffers and automatically
deallocate them later. Unlike meshopt_Buffer, the result is a pointer
that can be dereferenced at no additional cost in Debug.

This change migrates from meshopt_Buffer to meshopt_Allocator to
improve performance in Debug. Note that we forgo bounds checking in
Debug by using this type, but we were already inconsistent about using
pointers vs buffers - address sanitizer will help ensure memory safety
and we won't need to compromise Debug performance in regular builds for
that.

The following times are taken in MSVC 2017 x64 Debug using buddha.obj:

meshopt_analyzeOverdraw: 10.1s -> 7.7s
meshopt_analyzeVertexCache: 5.4s -> 0.9s
meshopt_analyzeVertexFetch: 1.2s -> 0.7s
meshopt_optimizeOverdraw: 1.0s -> 0.7s
meshopt_optimizeVertexCache: 26.1s -> 5.6s
meshopt_simplify: 3.7s -> 2.8s
2018-11-12 23:16:21 -08:00
Arseny Kapoulkine 9d1bf03b94 Convert CRLF to LF everywhere
We had a mixture of files that were using LF and files that were using
CRLF. For consistency convert *everything* to LF.

This unfortunately means that for most code blame will become less
useful since you'd need to go past this commit but such is life.
2018-10-17 19:16:18 -07:00
Arseny Kapoulkine 5ecbe2de3f vcache: Fix ATVR computation for meshes with sparse vertex buffers
In cases where the vertex buffer is shared between several meshes, such
as simplification, the ATVR metric wasn't taking this into account and
reported unrealistically low values.

Fix this by computing unique vertex count - all vertices that ever
entered the cache contribute to this - and using it instead.
2018-04-24 20:15:59 -07:00
Arseny Kapoulkine 2f2eee1c2f vcache: Convert to meshopt_Buffer<T>
Note that since meshopt_Buffer<T> currently can't be reallocated we
modify the .data member directly.
2017-12-23 18:15:45 -08:00
Arseny Kapoulkine 144bd8117f vcacheanalyzer: Rename buffer_size to primgroup_size
Apparently this is what AMD calls this, based on radv sources:

https://github.com/mesa3d/mesa/commit/d2490eb2d1c73054c0022f02d425d5f9c6d56c56#diff-b32b1015537a4edeb9e0b0e7d0a05239
2017-11-04 00:21:45 -07:00
Arseny Kapoulkine 09e7f16216 vcacheanalyzer: Minor refactoring
Remove redundant empty namespace
2017-10-29 20:11:11 -07:00
Arseny Kapoulkine 34e03ebc10 vcacheanalyzer: Fix off-by-one error for warp count
The previous change forgot to take last warp into account.
2017-10-28 22:54:15 -07:00
Arseny Kapoulkine 0a32fd1f5c vcacheanalyzer: Make analysis results closer to GPU behavior
While details of the hardware behavior are not known and vary between
vendors and GPU generations, based on the results of vcachetester it
seems that both AMD and NVidia follow a similar algorithm:

- Triangles are buffered up to a certain number, after which the cache
is flushed
- Within the buffer, a FIFO cache is used to gather vertices to fill a
warp/wavefront
- When a warp is full, it's dispatched for execution; cache is flushed
at this point - new warps don't share data with old warps

There are some pecularities, for example in case of NVidia the 9xx
series has a cache that has 16 vertices but the cache behavior is
somewhat odd - even if a vertex is still in FIFO cache it will not be
reused in some conditions - whereas the 10xx series seems to be able to
reuse any vertex from the current warp, making the effective cache size
32.

AMD seems to consistently follow the outlined procedure with cache size
14, wavefront size 64 and triangle buffer size 128 for multiple GPUs
from GCN era; pre-GCN cards (e.g. AMD Radeon HD 6xxx) seem to follow
a different - possibly more traditional? - algorithm.

Intel more or less has a simple 128-entry FIFO with no obvious warp
boundaries; there is some sort of limitation on reuse but I can't yet
figure out what the pattern is, so for now we'll assume Intel has a
vanilla 128 entry FIFO cache.

This change also removes LRU simulation because GPUs don't seem to
actually use LRU, so it's not very useful.
2017-10-28 22:42:55 -07:00
Arseny Kapoulkine c9ad516d71 Cleanup includes
Separate CRT includes from STL includes to make it clear which files use
STL and which don't; also remove some redundant includes.
2017-09-29 19:51:28 -07:00
Arseny Kapoulkine 3e426f5ff6 Add meshopt_ prefix for public structs
This fixes possible naming conflicts; these structs can't be namespaced
because they are part of the C interface.
2017-09-21 08:29:43 -07:00
Arseny Kapoulkine 137d2974bd Move function implementations back into namespace meshopt
This mostly makes profiler output nicer but also works around build
non-determinism for some compilers (that generate unique symbol names
for anonymous namespaces in each compilation attempt).
2017-08-20 18:07:12 +01:00
Arseny Kapoulkine c3521ab1f1 Implement C-style interface
Now all main entrypoints to the library are C-style - they use
non-mangled symbols without any default arguments or other C++ features.
We still have templated wrappers in namespace meshopt.

The implementation currently uses anonymous namespaces to reduce the
amount of differences, which may need some cleanup.
2017-08-20 13:52:37 +01:00
Arseny Kapoulkine 1f253b913c Rename meshoptimizer.hpp to meshoptimizer.h
This is a first step towards making a C-compatible interface.
2017-08-20 13:51:57 +01:00
Arseny Kapoulkine e8856f4113 vcache: Optimize LRU analyzer
Instead of doing many redundant data movements in std::vector, do a
single-pass copy with a branchless loop body to a new cache, similar to
what we do in the optimization algorithm.

This makes LRU analyzer ~30% faster.
2017-08-06 14:13:52 +01:00
Arseny Kapoulkine a01589e72f Reformat code 2017-08-02 20:59:37 -07:00
Arseny Kapoulkine ab8ffe2271 vcache: Add LRU cache analyzer
Since hardware cache resembles LRU more than it does FIFO, LRU analysis
is useful for developing the linear cache optimization.

To match behavior of optimizeVertexCache, we switch to LRU analysis mode
for cache_size=0.
2017-08-02 08:51:48 -07:00
Arseny Kapoulkine fbd6881d93 Remove extra code supporting 16-bit indices
Since index conversion is now performed by C++ inline adapters we don't
need extra complexity inside the implementation.
2017-07-18 09:00:24 -07:00
Arseny Kapoulkine 353e3d1e86 Rename time_stamp to timestamp 2017-07-11 08:49:39 -07:00
Arseny Kapoulkine 35494f614f Add more assertions
Also remove calculateACMR which isn't used any more and slightly
optimize buildAdjacency.
2017-07-10 21:15:03 -07:00
Arseny Kapoulkine bec59756d4 Refactor vertex fetch optimizer and add more assertions
We now range check indices in most algorithms and do some other sanity
checks. Also analyzers now correctly handle empty meshes.
2017-07-09 20:15:03 -07:00
Arseny Kapoulkine 9cbef2c1da Change the terminology once more, hopefully this time it's final.
We now refer to pre-transform cache optimization as "vertex fetch
optimization".
We now refer to post-transform cache optimization as "vertex cache
optimization".

This seems to be a bit more modern and easier to explain.
2017-07-09 18:50:33 -07:00
Arseny Kapoulkine 55cec24131 Rename vcacheanalyzer to posttransformanalyzer 2017-05-17 08:25:42 -07:00
Arseny Kapoulkine 1ab49a3bb0 Fix code formatting 2017-05-15 20:48:17 -07:00
Arseny Kapoulkine a12e61baf0 Add ATVR to vcache analyzer
ACMR is a good metric in general but the optimal ACMR number for a given
mesh depends on the triangle/vertex ratio - ACMR of 0.5 is impossible to
reach for certain meshes. In contrast, if we assume all vertices are
required by a given mesh, ATVR (average transform to vertex ratio) has
to be at least 1.0 (each vertex is transformed once), and represents the
amount of over-transformation due to vertex cache misses.
2017-05-15 20:44:24 -07:00
Arseny Kapoulkine cc26c74f15 Rename PostTL to PostTransform
Use modern names everywhere consistently (except for file names...)
2016-09-09 10:21:06 -07:00
Arseny Kapoulkine b26edd2c44 src: Merge all headers into one
They are small enough and almost all of them need std::vector
2016-09-09 00:53:28 -07:00
Arseny Kapoulkine 5c75b009a5 Fix compilation issues
Also introduce src/math.hpp with a simple vec3 class.
2016-09-08 22:46:39 -07:00
Arseny Kapoulkine 3f2ec7a0e2 Initial commit
This code does not compile yet.
2016-09-08 22:30:17 -07:00