From 97e98cd0c55db1294f948611fff4686e32122af5 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Tue, 15 Aug 2023 17:34:45 -0400 Subject: [PATCH 1/4] hd: use std::shared_ptr's use_count() instead of unique() in HdInstanceRegistry unique() was deprecated in C++17 and removed in C++20. Testing use_count() == 1 should be equivalent, though both may create thread safety concerns when used in a multithreaded environment. See the notes here for more detail: https://en.cppreference.com/w/cpp/memory/shared_ptr/use_count --- pxr/imaging/hd/instanceRegistry.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxr/imaging/hd/instanceRegistry.h b/pxr/imaging/hd/instanceRegistry.h index 871564b186..b4e36eae72 100644 --- a/pxr/imaging/hd/instanceRegistry.h +++ b/pxr/imaging/hd/instanceRegistry.h @@ -177,7 +177,7 @@ class HdInstanceRegistry { private: template static bool _IsUnique(std::shared_ptr const &value) { - return value.unique(); + return value.use_count() == 1; } typename InstanceType::Dictionary _dictionary; From 127d667995d56f32a51bf55187616efc52b3016e Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Tue, 15 Aug 2023 17:51:37 -0400 Subject: [PATCH 2/4] hdSt: use std::shared_ptr's use_count() instead of unique() in HdStResourceRegistry and HdSt_SamplerObjectRegistry unique() was deprecated in C++17 and removed in C++20. Testing use_count() == 1 should be equivalent, though both may create thread safety concerns when used in a multithreaded environment. See the notes here for more detail: https://en.cppreference.com/w/cpp/memory/shared_ptr/use_count --- pxr/imaging/hdSt/resourceRegistry.cpp | 10 ++++++---- pxr/imaging/hdSt/samplerObjectRegistry.cpp | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pxr/imaging/hdSt/resourceRegistry.cpp b/pxr/imaging/hdSt/resourceRegistry.cpp index cc62846c3c..f878e872a1 100644 --- a/pxr/imaging/hdSt/resourceRegistry.cpp +++ b/pxr/imaging/hdSt/resourceRegistry.cpp @@ -551,8 +551,9 @@ HdStResourceRegistry::GarbageCollectDispatchBuffers() _dispatchBufferRegistry.erase( std::remove_if( _dispatchBufferRegistry.begin(), _dispatchBufferRegistry.end(), - std::bind(&HdStDispatchBufferSharedPtr::unique, - std::placeholders::_1)), + [](const HdStDispatchBufferSharedPtr& ptr) { + return ptr.use_count() == 1; + }), _dispatchBufferRegistry.end()); } @@ -564,8 +565,9 @@ HdStResourceRegistry::GarbageCollectBufferResources() _bufferResourceRegistry.erase( std::remove_if( _bufferResourceRegistry.begin(), _bufferResourceRegistry.end(), - std::bind(&HdStBufferResourceSharedPtr::unique, - std::placeholders::_1)), + [](const HdStBufferResourceSharedPtr& ptr) { + return ptr.use_count() == 1; + }), _bufferResourceRegistry.end()); } diff --git a/pxr/imaging/hdSt/samplerObjectRegistry.cpp b/pxr/imaging/hdSt/samplerObjectRegistry.cpp index 894c4ac8d4..c57fc99a5f 100644 --- a/pxr/imaging/hdSt/samplerObjectRegistry.cpp +++ b/pxr/imaging/hdSt/samplerObjectRegistry.cpp @@ -129,13 +129,13 @@ HdSt_SamplerObjectRegistry::GarbageCollect() size_t last = _samplerObjects.size(); for (size_t i = 0; i < last; i++) { - if (_samplerObjects[i].unique()) { + if (_samplerObjects[i].use_count() == 1) { while(true) { last--; if (i == last) { break; } - if (!_samplerObjects[last].unique()) { + if (_samplerObjects[last].use_count() != 1) { _samplerObjects[i] = _samplerObjects[last]; break; } From 49e88cb5cebac326e68521ad6029896b1c954e53 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Tue, 15 Aug 2023 17:53:17 -0400 Subject: [PATCH 3/4] pcp: use std::shared_ptr's use_count() instead of unique() in PcpPrimIndex_Graph unique() was deprecated in C++17 and removed in C++20. Testing use_count() == 1 should be equivalent, though both may create thread safety concerns when used in a multithreaded environment. See the notes here for more detail: https://en.cppreference.com/w/cpp/memory/shared_ptr/use_count --- pxr/usd/pcp/primIndex_Graph.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxr/usd/pcp/primIndex_Graph.cpp b/pxr/usd/pcp/primIndex_Graph.cpp index 4ae967d559..776a0d6411 100644 --- a/pxr/usd/pcp/primIndex_Graph.cpp +++ b/pxr/usd/pcp/primIndex_Graph.cpp @@ -613,7 +613,7 @@ PcpPrimIndex_Graph::_InsertChildInStrengthOrder( void PcpPrimIndex_Graph::_DetachSharedNodePool() { - if (!_nodes.unique()) { + if (_nodes.use_count() != 1) { TRACE_FUNCTION(); TfAutoMallocTag tag("_DetachSharedNodePool"); _nodes = std::make_shared<_NodePool>(*_nodes); @@ -623,7 +623,7 @@ PcpPrimIndex_Graph::_DetachSharedNodePool() void PcpPrimIndex_Graph::_DetachSharedNodePoolForNewNodes(size_t numAddedNodes) { - if (!_nodes.unique()) { + if (_nodes.use_count() != 1) { TRACE_FUNCTION(); TfAutoMallocTag tag("_DetachSharedNodePoolForNewNodes"); // Create a new copy, but with some extra capacity since we are adding From 7f1de7154235a5d6476c556ea567927044b7e471 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Tue, 15 Aug 2023 18:28:35 -0400 Subject: [PATCH 4/4] hio: use a named struct for stbi__png typedef in stb_image.h and update patch The local patch to stb_image.h adds a "gamma" member to the previously unnamed struct used in the typedef of stbi__png. It also includes a default initializer to set the member to 0. When using C++17 or later, some compilers will emit an error that an unnamed class cannot be used within a typedef if it has a non-static data member with a default member initializer. In particular, this is the case with msvc: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5208 In this case, the error can be avoided simply by giving the problematic struct a name. stb_image.h in hio was updated to make this change, and the patch file used to create it from the original source version was regenerated to ensure that the same change is applied if/when stb is upgraded in the future. --- pxr/imaging/hio/stb/stb_image.h | 2 +- pxr/imaging/hio/stb/stb_image.patch | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pxr/imaging/hio/stb/stb_image.h b/pxr/imaging/hio/stb/stb_image.h index ff3b47c7a5..45a790edf9 100644 --- a/pxr/imaging/hio/stb/stb_image.h +++ b/pxr/imaging/hio/stb/stb_image.h @@ -4626,7 +4626,7 @@ static int stbi__check_png_header(stbi__context *s) return 1; } -typedef struct +typedef struct stbi__png_type { stbi__context *s; stbi_uc *idata, *expanded, *out; diff --git a/pxr/imaging/hio/stb/stb_image.patch b/pxr/imaging/hio/stb/stb_image.patch index 6bf059d6ae..fa9d8a35f1 100644 --- a/pxr/imaging/hio/stb/stb_image.patch +++ b/pxr/imaging/hio/stb/stb_image.patch @@ -1,5 +1,5 @@ ---- original/stb_image.h 2024-05-21 15:30:18.887733957 -0700 -+++ stb_image.h 2024-05-21 15:17:49.371401403 -0700 +--- original/stb_image.h 2024-12-09 08:40:54 ++++ stb_image.h 2024-12-09 08:41:15 @@ -490,14 +490,14 @@ STBIDEF void stbi_image_free (void *retval_from_stbi_load); @@ -28,7 +28,13 @@ static int stbi__png_is16(stbi__context *s); #endif -@@ -4631,6 +4631,7 @@ +@@ -4626,11 +4626,12 @@ + return 1; + } + +-typedef struct ++typedef struct stbi__png_type + { stbi__context *s; stbi_uc *idata, *expanded, *out; int depth;