From 97c954dd84d50ec7b739d2dd3adb7365589f3034 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 6 Jul 2021 21:26:15 +0300 Subject: SL-15522 Initial addition of meshoptimizer --- indra/llmeshoptimizer/llmeshoptimizer.cpp | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 indra/llmeshoptimizer/llmeshoptimizer.cpp (limited to 'indra/llmeshoptimizer/llmeshoptimizer.cpp') diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp new file mode 100644 index 0000000000..770cd5aa3c --- /dev/null +++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp @@ -0,0 +1,43 @@ + /** +* @file llmeshoptimizer.cpp +* @brief Wrapper around meshoptimizer +* +* $LicenseInfo:firstyear=2021&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2021, Linden Research, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA +* $/LicenseInfo$ +*/ + +#include "llmeshoptimizer.h" + +#include "linden_common.h" + +#include "meshoptimizer.h" +#include "llmath.h" + + +LLMeshOptimizer::LLMeshOptimizer() +{ + +} + +LLMeshOptimizer::~LLMeshOptimizer() +{ + +} -- cgit v1.2.3 From 7b7b8a8da8f3a7e726b7de2b152cd00c67df0f18 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 7 Jul 2021 22:34:26 +0300 Subject: DRTVWR-542 WIP --- indra/llmeshoptimizer/llmeshoptimizer.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'indra/llmeshoptimizer/llmeshoptimizer.cpp') diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp index 770cd5aa3c..c46fa8dcf3 100644 --- a/indra/llmeshoptimizer/llmeshoptimizer.cpp +++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp @@ -26,18 +26,24 @@ #include "llmeshoptimizer.h" -#include "linden_common.h" - #include "meshoptimizer.h" -#include "llmath.h" LLMeshOptimizer::LLMeshOptimizer() { - + // Todo: Looks like for memory management, we can add allocator and deallocator callbacks + // Should be one time + // meshopt_setAllocator(allocate, deallocate); } LLMeshOptimizer::~LLMeshOptimizer() { } + +//static +U32 LLMeshOptimizer::simplifyModel() +{ + LL_WARNS() << "NOT IMPLEMENTED" << LL_ENDL; + return 0; +} -- cgit v1.2.3 From 1a17e19a610b598650624fb0ae3e67352f00e499 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 8 Jul 2021 20:29:28 +0300 Subject: DRTVWR-542 WIP #2 --- indra/llmeshoptimizer/llmeshoptimizer.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'indra/llmeshoptimizer/llmeshoptimizer.cpp') diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp index c46fa8dcf3..02e97ef984 100644 --- a/indra/llmeshoptimizer/llmeshoptimizer.cpp +++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp @@ -28,7 +28,6 @@ #include "meshoptimizer.h" - LLMeshOptimizer::LLMeshOptimizer() { // Todo: Looks like for memory management, we can add allocator and deallocator callbacks @@ -38,12 +37,27 @@ LLMeshOptimizer::LLMeshOptimizer() LLMeshOptimizer::~LLMeshOptimizer() { - } //static -U32 LLMeshOptimizer::simplifyModel() +U64 LLMeshOptimizer::simplify(U16 *destination, + const U16 *indices, + U64 index_count, + const LLVector4a *vertex_positions, + U64 vertex_count, + U64 target_index_count, + F32 target_error, + F32* result_error + ) { - LL_WARNS() << "NOT IMPLEMENTED" << LL_ENDL; - return 0; + return meshopt_simplify(destination, + indices, + index_count, + (const float*)vertex_positions, // verify that it is correct to convert to float + vertex_count, + sizeof(LLVector4a), // should be either 0 or 4 + target_index_count, + target_error, + result_error + ); } -- cgit v1.2.3 From eb13133e3e0020c73399414cea4d9b39ef526cd3 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Mon, 12 Jul 2021 16:47:45 +0300 Subject: DRTVWR-542 WIP #5 --- indra/llmeshoptimizer/llmeshoptimizer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/llmeshoptimizer/llmeshoptimizer.cpp') diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp index 02e97ef984..dbf8e5b631 100644 --- a/indra/llmeshoptimizer/llmeshoptimizer.cpp +++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp @@ -50,12 +50,17 @@ U64 LLMeshOptimizer::simplify(U16 *destination, F32* result_error ) { + const size_t vertex_stride = 4; // should be either 0 or 4 + + // Consider running meshopt_generateShadowIndexBuffer first. + // meshopt_generateShadowIndexBuffer is only needed if models don't use some of the vertices, + // but since we call optimize() in a lot of cases, it likely isn't needed return meshopt_simplify(destination, indices, index_count, (const float*)vertex_positions, // verify that it is correct to convert to float vertex_count, - sizeof(LLVector4a), // should be either 0 or 4 + vertex_stride, target_index_count, target_error, result_error -- cgit v1.2.3 From 938969c811732a3e2faf0229301de286bd12c1a5 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Mon, 12 Jul 2021 19:18:25 +0300 Subject: DRTVWR-542 WIP #6 Trying out 'sloppy' variant --- indra/llmeshoptimizer/llmeshoptimizer.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'indra/llmeshoptimizer/llmeshoptimizer.cpp') diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp index dbf8e5b631..2f3d2491c2 100644 --- a/indra/llmeshoptimizer/llmeshoptimizer.cpp +++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp @@ -66,3 +66,27 @@ U64 LLMeshOptimizer::simplify(U16 *destination, result_error ); } + +//static +U64 LLMeshOptimizer::simplifySloppy(U16 *destination, + const U16 *indices, + U64 index_count, + const LLVector4a *vertex_positions, + U64 vertex_count, + U64 target_index_count, + F32 target_error, + F32* result_error + ) +{ + const size_t vertex_stride = 4; // should be either 0 or 4 + return meshopt_simplifySloppy(destination, + indices, + index_count, + (const float*)vertex_positions, // verify that it is correct to convert to float + vertex_count, + vertex_stride, + target_index_count, + target_error, + result_error + ); +} -- cgit v1.2.3 From 833a82f8593c513b12b59c489760f77d5a806668 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Mon, 12 Jul 2021 23:23:08 +0300 Subject: DRTVWR-542 WIP #7 --- indra/llmeshoptimizer/llmeshoptimizer.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'indra/llmeshoptimizer/llmeshoptimizer.cpp') diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp index 2f3d2491c2..0ddaa82c3d 100644 --- a/indra/llmeshoptimizer/llmeshoptimizer.cpp +++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp @@ -39,6 +39,26 @@ LLMeshOptimizer::~LLMeshOptimizer() { } +//static +void LLMeshOptimizer::generateShadowIndexBuffer(U16 *destination, + const U16 *indices, + U64 index_count, + const LLVector4a *vertex_positions, + U64 vertex_count +) +{ + const size_t vertex_stride = 4; // should be either 0 or 4 + + meshopt_generateShadowIndexBuffer(destination, + indices, + index_count, + (const float*)vertex_positions, // verify that it is correct to convert to float + vertex_count, + sizeof(LLVector4a), + vertex_stride + ); +} + //static U64 LLMeshOptimizer::simplify(U16 *destination, const U16 *indices, @@ -52,9 +72,6 @@ U64 LLMeshOptimizer::simplify(U16 *destination, { const size_t vertex_stride = 4; // should be either 0 or 4 - // Consider running meshopt_generateShadowIndexBuffer first. - // meshopt_generateShadowIndexBuffer is only needed if models don't use some of the vertices, - // but since we call optimize() in a lot of cases, it likely isn't needed return meshopt_simplify(destination, indices, index_count, -- cgit v1.2.3 From 66ba1c4c8e840bb5e9da23e2b5772cd24b23714f Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 13 Jul 2021 02:14:16 +0300 Subject: DRTVWR-542 WIP Fixed Stride --- indra/llmeshoptimizer/llmeshoptimizer.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'indra/llmeshoptimizer/llmeshoptimizer.cpp') diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp index 0ddaa82c3d..09fa7cb235 100644 --- a/indra/llmeshoptimizer/llmeshoptimizer.cpp +++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp @@ -44,18 +44,17 @@ void LLMeshOptimizer::generateShadowIndexBuffer(U16 *destination, const U16 *indices, U64 index_count, const LLVector4a *vertex_positions, - U64 vertex_count + U64 vertex_count, + U64 vertex_positions_stride ) { - const size_t vertex_stride = 4; // should be either 0 or 4 - meshopt_generateShadowIndexBuffer(destination, indices, index_count, (const float*)vertex_positions, // verify that it is correct to convert to float vertex_count, sizeof(LLVector4a), - vertex_stride + vertex_positions_stride ); } @@ -65,19 +64,19 @@ U64 LLMeshOptimizer::simplify(U16 *destination, U64 index_count, const LLVector4a *vertex_positions, U64 vertex_count, + U64 vertex_positions_stride, U64 target_index_count, F32 target_error, F32* result_error ) { - const size_t vertex_stride = 4; // should be either 0 or 4 return meshopt_simplify(destination, indices, index_count, - (const float*)vertex_positions, // verify that it is correct to convert to float + (const float*)vertex_positions, vertex_count, - vertex_stride, + vertex_positions_stride, target_index_count, target_error, result_error @@ -90,18 +89,18 @@ U64 LLMeshOptimizer::simplifySloppy(U16 *destination, U64 index_count, const LLVector4a *vertex_positions, U64 vertex_count, + U64 vertex_positions_stride, U64 target_index_count, F32 target_error, F32* result_error ) { - const size_t vertex_stride = 4; // should be either 0 or 4 return meshopt_simplifySloppy(destination, indices, index_count, - (const float*)vertex_positions, // verify that it is correct to convert to float + (const float*)vertex_positions, vertex_count, - vertex_stride, + vertex_positions_stride, target_index_count, target_error, result_error -- cgit v1.2.3 From 9aaac1bb985f5bd65f9b0fe985c47cd30dcfd166 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 23 Jul 2021 21:30:13 +0300 Subject: DRTVWR-542 Attempt to simplify all faces of an object as a whole and split back into faces --- indra/llmeshoptimizer/llmeshoptimizer.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'indra/llmeshoptimizer/llmeshoptimizer.cpp') diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp index 09fa7cb235..8097a05511 100644 --- a/indra/llmeshoptimizer/llmeshoptimizer.cpp +++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp @@ -58,6 +58,30 @@ void LLMeshOptimizer::generateShadowIndexBuffer(U16 *destination, ); } +//static +U64 LLMeshOptimizer::simplifyU32(U32 *destination, + const U32 *indices, + U64 index_count, + const LLVector4a *vertex_positions, + U64 vertex_count, + U64 vertex_positions_stride, + U64 target_index_count, + F32 target_error, + F32* result_error +) +{ + return meshopt_simplify(destination, + indices, + index_count, + (const float*)vertex_positions, + vertex_count, + vertex_positions_stride, + target_index_count, + target_error, + result_error + ); +} + //static U64 LLMeshOptimizer::simplify(U16 *destination, const U16 *indices, @@ -70,7 +94,6 @@ U64 LLMeshOptimizer::simplify(U16 *destination, F32* result_error ) { - return meshopt_simplify(destination, indices, index_count, -- cgit v1.2.3 From 1a1793244002effe46cedf63180de60f4bc69a9a Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 4 Aug 2021 21:14:00 +0300 Subject: DRTVWR-542 Automated method selection Normally simplification methods apply for whole upload, but this one selects methods per model or per face. --- indra/llmeshoptimizer/llmeshoptimizer.cpp | 97 +++++++++++++++++-------------- 1 file changed, 54 insertions(+), 43 deletions(-) (limited to 'indra/llmeshoptimizer/llmeshoptimizer.cpp') diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp index 8097a05511..a879389c5a 100644 --- a/indra/llmeshoptimizer/llmeshoptimizer.cpp +++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp @@ -67,19 +67,36 @@ U64 LLMeshOptimizer::simplifyU32(U32 *destination, U64 vertex_positions_stride, U64 target_index_count, F32 target_error, + bool sloppy, F32* result_error ) { - return meshopt_simplify(destination, - indices, - index_count, - (const float*)vertex_positions, - vertex_count, - vertex_positions_stride, - target_index_count, - target_error, - result_error - ); + if (sloppy) + { + return meshopt_simplifySloppy(destination, + indices, + index_count, + (const float*)vertex_positions, + vertex_count, + vertex_positions_stride, + target_index_count, + target_error, + result_error + ); + } + else + { + return meshopt_simplify(destination, + indices, + index_count, + (const float*)vertex_positions, + vertex_count, + vertex_positions_stride, + target_index_count, + target_error, + result_error + ); + } } //static @@ -91,41 +108,35 @@ U64 LLMeshOptimizer::simplify(U16 *destination, U64 vertex_positions_stride, U64 target_index_count, F32 target_error, + bool sloppy, F32* result_error ) { - return meshopt_simplify(destination, - indices, - index_count, - (const float*)vertex_positions, - vertex_count, - vertex_positions_stride, - target_index_count, - target_error, - result_error - ); + if (sloppy) + { + return meshopt_simplifySloppy(destination, + indices, + index_count, + (const float*)vertex_positions, + vertex_count, + vertex_positions_stride, + target_index_count, + target_error, + result_error + ); + } + else + { + return meshopt_simplify(destination, + indices, + index_count, + (const float*)vertex_positions, + vertex_count, + vertex_positions_stride, + target_index_count, + target_error, + result_error + ); + } } -//static -U64 LLMeshOptimizer::simplifySloppy(U16 *destination, - const U16 *indices, - U64 index_count, - const LLVector4a *vertex_positions, - U64 vertex_count, - U64 vertex_positions_stride, - U64 target_index_count, - F32 target_error, - F32* result_error - ) -{ - return meshopt_simplifySloppy(destination, - indices, - index_count, - (const float*)vertex_positions, - vertex_count, - vertex_positions_stride, - target_index_count, - target_error, - result_error - ); -} -- cgit v1.2.3