From 8eb2d17c7715dbe72d4719d7ed3dd05f8cb4b65e Mon Sep 17 00:00:00 2001 From: Henri Beauchamp Date: Thu, 30 Nov 2023 13:23:57 +0100 Subject: Fix LLGLTFMaterial hashing This PR fixes the non-working material hashing for LLGLTFMaterial instances. There are several issues in the current code, stemming to the fact that the hashing is performed on the block of the member variables: 1.- There are padding bytes between member variables, even after rearranging them to avoid most of the padding; in particular, the std::array's size is not a multiple of 4 bytes (64 bits), and most compilers will pad them to the next 4-byte aligment as a result. Note that C++ standards do not impose the zeroing of padding bytes on construction of a class instance, with only a couple exceptions (such as explicit zero-initialization). Those bytes MUST therefore be zeroed by us on construction. 2.- The TextureTransform strutcure getPacked() method did not touch some of the packed bytes, and as a result could *potentially* cause an issue for hashing when applied to a transform of another material instance. 3.- With the recent addition of the local textures tracking map, the said map cannot be hashed as a block of memory (map pairs will typically be allocated on the heap or on the stack, not in the memory block used by member variables). This PR solves all these issues and offers proper hashing of LLGLTFMaterial instances. --- indra/llprimitive/llgltfmaterial.h | 62 +++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 24 deletions(-) (limited to 'indra/llprimitive/llgltfmaterial.h') diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index 02f62fb08c..9f817d6a19 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -81,7 +81,7 @@ public: ALPHA_MODE_MASK }; - LLGLTFMaterial() {} + LLGLTFMaterial(); LLGLTFMaterial(const LLGLTFMaterial& rhs); LLGLTFMaterial& operator=(const LLGLTFMaterial& rhs); @@ -110,25 +110,6 @@ public: static const char* const GLTF_FILE_EXTENSION_TRANSFORM_ROTATION; static const LLUUID GLTF_OVERRIDE_NULL_UUID; - std::array mTextureId; - std::array mTextureTransform; - - // NOTE: initialize values to defaults according to the GLTF spec - // NOTE: these values should be in linear color space - LLColor4 mBaseColor = LLColor4(1, 1, 1, 1); - LLColor3 mEmissiveColor = LLColor3(0, 0, 0); - - F32 mMetallicFactor = 1.f; - F32 mRoughnessFactor = 1.f; - F32 mAlphaCutoff = 0.5f; - - bool mDoubleSided = false; - AlphaMode mAlphaMode = ALPHA_MODE_OPAQUE; - - // override specific flags for state that can't use off-by-epsilon or UUID hack - bool mOverrideDoubleSided = false; - bool mOverrideAlphaMode = false; - // get a UUID based on a hash of this LLGLTFMaterial LLUUID getHash() const; @@ -229,10 +210,6 @@ public: virtual bool replaceLocalTexture(const LLUUID& tracking_id, const LLUUID &old_id, const LLUUID& new_id); virtual void updateTextureTracking(); - // These fields are local to viewer and are a part of local bitmap support - typedef std::map local_tex_map_t; - local_tex_map_t mTrackingIdToLocalTexture; - protected: static LLVector2 vec2FromJson(const std::map& object, const char* key, const LLVector2& default_value); static F32 floatFromJson(const std::map& object, const char* key, const F32 default_value); @@ -249,4 +226,41 @@ protected: void writeToTexture(tinygltf::Model& model, T& texture_info, TextureInfo texture_info_id, bool force_write = false) const; template static void writeToTexture(tinygltf::Model& model, T& texture_info, const LLUUID& texture_id, const TextureTransform& transform, bool force_write = false); + + // Used to update the digest of the mTrackingIdToLocalTexture map each time + // it is changed; this way, that digest can be used by the fast getHash() + // method intsead of having to hash all individual keys and values. HB + void updateLocalTexDataDigest(); + +public: + // These fields are local to viewer and are a part of local bitmap support + // IMPORTANT: do not move this member down (and do not move + // mLocalTexDataDigest either): the getHash() method does rely on the + // current ordering. HB + typedef std::map local_tex_map_t; + local_tex_map_t mTrackingIdToLocalTexture; + + // Used to store a digest of mTrackingIdToLocalTexture when the latter is + // not empty, or zero otherwise. HB + U64 mLocalTexDataDigest; + + std::array mTextureId; + std::array mTextureTransform; + + // NOTE: initialize values to defaults according to the GLTF spec + // NOTE: these values should be in linear color space + LLColor4 mBaseColor; + LLColor3 mEmissiveColor; + + F32 mMetallicFactor; + F32 mRoughnessFactor; + F32 mAlphaCutoff; + + AlphaMode mAlphaMode; + bool mDoubleSided; + + // Override specific flags for state that can't use off-by-epsilon or UUID + // hack + bool mOverrideDoubleSided; + bool mOverrideAlphaMode; }; -- cgit v1.2.3 From 9441608623a2692263191c254db23765eefa2cef Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Mon, 6 May 2024 10:07:02 -0700 Subject: secondlife/viewer#907: Local PBR terrain texture transforms --- indra/llprimitive/llgltfmaterial.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/llprimitive/llgltfmaterial.h') diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index 90f1ecfa8f..7888ba3b05 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -68,7 +68,12 @@ public: LLVector2 mScale = { 1.f, 1.f }; F32 mRotation = 0.f; - void getPacked(F32 (&packed)[8]) const; + static const size_t PACK_SIZE = 8; + static const size_t PACK_TIGHT_SIZE = 5; + using Pack = F32[PACK_SIZE]; + using PackTight = F32[PACK_TIGHT_SIZE]; + void getPacked(Pack& packed) const; + void getPackedTight(PackTight& packed) const; bool operator==(const TextureTransform& other) const; bool operator!=(const TextureTransform& other) const { return !(*this == other); } -- cgit v1.2.3 From cdcfbab5c4a24c4d9bf7af6bbbb8a8760bcc5189 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Mon, 13 May 2024 15:23:33 -0700 Subject: secondlife/viewer#907: Fix bad merge in LLGLTFMaterial Caused by a conflict between the LLGLTFMaterial::getHash fix, and an improvement in LLGLTFMaterial field ordering for platform-dependent memory reduction. --- indra/llprimitive/llgltfmaterial.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'indra/llprimitive/llgltfmaterial.h') diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index 7888ba3b05..1b0ab19f71 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -125,12 +125,6 @@ public: // heightmaps cannot currently be described as finite enclosed // volumes. // See also LLPanelRegionTerrainInfo::validateMaterials - bool mDoubleSided = false; - - - // These fields are local to viewer and are a part of local bitmap support - typedef std::map local_tex_map_t; - local_tex_map_t mTrackingIdToLocalTexture; public: -- cgit v1.2.3 From 03c4458bdcc6821a3047f93b729d412e274ab9af Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 20 May 2024 13:22:55 -0500 Subject: #1392 GLTF Upload (#1394) * #1392 WIP -- Functional texture upload, stubbed out .bin upload. * #1392 GLTF Upload WIP -- Emulates successful upload Successfully uploads texture Emulates successful .gltf and .bin upload by injecting into local asset cache. Emulates rez from inventory by setting sculpt ID of selected object Currently fails in tinygltf parsing due to missing .bin * Add missing notification * Build fix * #1392 Add boost::json .gltf reading support. * #1392 boost::json GLTF writing prototype * Create gltf/README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * #1392 Add ability to render directly from LL::GLTF::Material * Fix for mac build * Mac build fix * #1392 AssetType and Inventory Type plumbing * #1392 More sane error handling and scheduling of uploads. * #1392 Actually attempt to upload glbin * Mac build fix, upload nudge * Mac build fix * Fix glTF asset uploads to server * Mac build fix (inline not static) * More consistent inline * Add glm, mac nudge. * #1392 For consistency with spec, start using glm over glh:: and LLFoo * Another attempt at placating Mac builds * Another Mac nudge * Mac build take 23 * #1392 Prune LLMatrix4a from GLTF namespace. * #1392 Fix for orientation being off (glm::quat is wxyz, not xyzw) * #1392 WIP -- Actually send the sculpt type and id, nudge readme and alpha rendering * #1392 Working download! * #1394 Add support for GLTFEnabled SimulatorFeature * #1392 Review feedback --------- Co-authored-by: Pepper Linden <3782201+rohvani@users.noreply.github.com> --- indra/llprimitive/llgltfmaterial.h | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llprimitive/llgltfmaterial.h') diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index 23a39593cf..67b22f56e2 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -273,6 +273,7 @@ public: F32 mAlphaCutoff; AlphaMode mAlphaMode; + bool mDoubleSided = false; // Override specific flags for state that can't use off-by-epsilon or UUID -- cgit v1.2.3 From 6de0086ae9c678dafa8a26eb117279a487860f2f Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Wed, 15 May 2024 19:27:37 -0700 Subject: secondlife/viewer#1475: Add PBR terrain repeats editing --- indra/llprimitive/llgltfmaterial.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llprimitive/llgltfmaterial.h') diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index 67b22f56e2..e04b6d5eee 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -202,7 +202,7 @@ public: // Get the given override on this LLGLTFMaterial as LLSD // override_mat -- the override source data // data -- output LLSD object (should be passed in empty) - void getOverrideLLSD(const LLGLTFMaterial& override_mat, LLSD& data); + void getOverrideLLSD(const LLGLTFMaterial& override_mat, LLSD& data) const; // For base materials only (i.e. assets). Clears transforms to // default since they're not supported in assets yet. -- cgit v1.2.3 From 1ebf62e102cb3f328aa90809f7f5060b8f065db1 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Tue, 11 Jun 2024 15:40:09 +0200 Subject: Clean up line endings that got mangled up during last merge --- indra/llprimitive/llgltfmaterial.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/llprimitive/llgltfmaterial.h') diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index e9b48a60dd..f501a03854 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -5,21 +5,21 @@ * $LicenseInfo:firstyear=2022&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2022, 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$ */ @@ -178,7 +178,7 @@ public: void writeToModel(tinygltf::Model& model, S32 mat_index) const; virtual void applyOverride(const LLGLTFMaterial& override_mat); - + // apply the given LLSD override data void applyOverrideLLSD(const LLSD& data); -- cgit v1.2.3