diff options
author | Dave Parks <davep@lindenlab.com> | 2022-09-12 11:48:16 -0500 |
---|---|---|
committer | Dave Parks <davep@lindenlab.com> | 2022-09-12 11:48:16 -0500 |
commit | d7c77e5c64ddfef44b3e47f4c7ae6943ff0e860a (patch) | |
tree | d04ed79aea3f90bda1797d1a06ec7000b704ad8c | |
parent | c822da9fe644e4a420caabb30a25b487ce75c099 (diff) |
SL-18095 WIP -- Use meshoptimizer to re-weld and cache optimize after generating tangents
-rw-r--r-- | indra/cmake/LLMath.cmake | 1 | ||||
-rw-r--r-- | indra/llmath/llvolume.cpp | 56 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl | 1 | ||||
-rw-r--r-- | indra/newview/llface.cpp | 1 |
4 files changed, 46 insertions, 13 deletions
diff --git a/indra/cmake/LLMath.cmake b/indra/cmake/LLMath.cmake index 3cbb7ad561..513ff9f81d 100644 --- a/indra/cmake/LLMath.cmake +++ b/indra/cmake/LLMath.cmake @@ -2,6 +2,7 @@ include(Variables) include(Mikktspace) +include(MESHOPTIMIZER) set(LLMATH_INCLUDE_DIRS ${LIBS_OPEN_DIR}/llmath diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 0ce1577d00..fca9471f14 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -56,6 +56,8 @@ #include "mikktspace/mikktspace.h" #include "mikktspace/mikktspace.c" // insert mikktspace implementation into llvolume object file +#include "meshoptimizer/meshoptimizer.h" + #define DEBUG_SILHOUETTE_BINORMALS 0 #define DEBUG_SILHOUETTE_NORMALS 0 // TomY: Use this to display normals using the silhouette #define DEBUG_SILHOUETTE_EDGE_MAP 0 // DaveP: Use this to display edge map using the silhouette @@ -5499,34 +5501,66 @@ bool LLVolumeFace::cacheOptimize() SMikkTSpaceContext ctx = { &ms, &data }; genTangSpaceDefault(&ctx); - - resizeVertices(data.p.size()); - resizeIndices(data.p.size()); - + + //re-weld + meshopt_Stream mos[] = + { + { &data.p[0], sizeof(LLVector3), sizeof(LLVector3) }, + { &data.n[0], sizeof(LLVector3), sizeof(LLVector3) }, + { &data.t[0], sizeof(LLVector4), sizeof(LLVector4) }, + { &data.tc[0], sizeof(LLVector2), sizeof(LLVector2) }, + { data.w.empty() ? nullptr : &data.w[0], sizeof(LLVector4), sizeof(LLVector4) } + }; + + std::vector<U32> remap; + remap.resize(data.p.size()); + + U32 stream_count = data.w.empty() ? 4 : 5; + + U32 vert_count = meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count); + + std::vector<U32> indices; + indices.resize(mNumIndices); + + //copy results back into volume + resizeVertices(vert_count); + if (!data.w.empty()) { - allocateWeights(data.w.size()); + allocateWeights(vert_count); } allocateTangents(mNumVertices, true); for (int i = 0; i < mNumIndices; ++i) { - mIndices[i] = i; + U32 src_idx = i; + U32 dst_idx = remap[i]; + mIndices[i] = dst_idx; - mPositions[i].load3(data.p[i].mV); - mNormals[i].load3(data.n[i].mV); - mTexCoords[i] = data.tc[i]; + mPositions[dst_idx].load3(data.p[src_idx].mV); + mNormals[dst_idx].load3(data.n[src_idx].mV); + mTexCoords[dst_idx] = data.tc[src_idx]; - mMikktSpaceTangents[i].loadua(data.t[i].mV); + mMikktSpaceTangents[dst_idx].loadua(data.t[src_idx].mV); if (mWeights) { - mWeights[i].loadua(data.w[i].mV); + mWeights[dst_idx].loadua(data.w[src_idx].mV); } } + // cache optimize index buffer + + // meshopt needs scratch space, do some pointer shuffling to avoid an extra index buffer copy + U16* src_indices = mIndices; + mIndices = nullptr; + resizeIndices(mNumIndices); + + meshopt_optimizeVertexCache<U16>(mIndices, src_indices, mNumIndices, mNumVertices); + ll_aligned_free_16(src_indices); + return true; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl index c90a17993f..5573c02a60 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -76,7 +76,6 @@ void main() vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; - #ifdef HAS_SKIN vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index 83d35b7f3c..2827329739 100644 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -2189,7 +2189,6 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, { LLVector4a tangent_out; mat_normal.rotate(*src, tangent_out); - tangent_out.normalize3(); tangent_out.setSelectWithMask(mask, *src, tangent_out); tangent_out.store4a(tangents); |