Skip to content

LocaliseAttributes / AttributeQuery / AttributeTweaks : Inherit global attributes #6502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 14, 2025

Conversation

murraystevenson
Copy link
Contributor

This adds support for inheriting/localising global attributes in LocaliseAttributes, AttributeQuery and AttributeTweaks. After a bit of dliberation, I've made this behaviour optional for LocaliseAttributes via a new includeGlobalAttributes plug that defaults off for backwards compatibility, but is userDefaulted on for newly created nodes. This additional complexity seems reasonable for LocaliseAttributes, as it's already quite a simple node, and with this plug, LocaliseAttributes could be used in concert with AttributeQuery/AttributeTweaks/SubTree/etc in more complex cases where you require a very specific flavour of localisation.

This PR does introduce two breaking changes of behaviour, an AttributeQuery with inherit enabled will now return a result when querying an attribute that doesn't exist in the scene hierarchy but does exist in the globals, and AttributeTweaks would now not create an attribute in CreateIfMissing mode if localise was enabled and there was a global attribute of the same name. These may be edge-case enough that we don't need to go to great lengths to provide a compatibility mode, or overly complicate the nodes. I've reached out to a few users to gauge their opinions...

Future work would be to include a useFallback plug on AttributeQuery to allow the query to return the registered default value as a fallback, and changing the exists plug to a source plug similar to what we've added to CameraQuery. ShaderQuery & ShaderTweaks would also benefit from this new behaviour if we plan to add a global plug to ShaderAssignment, though LocaliseAttributes would help with this in the meantime.

@murraystevenson murraystevenson self-assigned this Jul 11, 2025
Copy link
Member

@johnhaddon johnhaddon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Murray!

ShaderQuery & ShaderTweaks would also benefit from this new behaviour if we plan to add a global plug to ShaderAssignment

I think perhaps we should do ShaderQuery and ShaderTweaks now, since it's already possible to make a global shader attribute by other means? Doing it now also means less compatibility worries than if we were to do it after adding ShaderAssignment.global.

@@ -452,6 +461,21 @@ IECore::CompoundObjectPtr ScenePlug::fullAttributes( const ScenePath &scenePath
path.pop_back();
}

if( withGlobalAttributes )
{
for( const auto &g : globals()->members() )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may have a dangling pointer issue here. Until C++23, which fixes the issue, I believe this is equivalent to this :

auto &&r = globals()->members();
for( auto it = begin( r ); it != end( r ); ++it )
{

}

globals() returns an owning Ptr, and we need to keep that alive for as long as we access members().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 62e5fa1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we have crossed wires here. My code example wasn't the intended fix, rather it was demonstrating what the original code was equivalent to, and why that was a problem. To be more clear :

// This creates a dangling reference. `globals()` returns `ConstCompoundObjectPtr`,
// and we need to keep that around to maintain ownership of the result, for as long
// as we access it. But after this line has run, the Ptr is gone, and we're referencing
// something that may no longer be alive.
auto &&r = globals()->members();

// This is what we actually want to do.
ConstCompoundObjectPtr g = globals();
for( const auto &m : g->members() )

@@ -532,6 +556,18 @@ IECore::MurmurHash ScenePlug::fullAttributesHash( const ScenePath &scenePath ) c
path.pop_back();
}

if( withGlobalAttributes )
{
for( const auto &g : globals()->members() )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, I think we have a lifetime issue here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, fixed in 62e5fa1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above...

@johnhaddon
Copy link
Member

Oh, one other thing I forgot. All the Changes.md updates will need moving into a new section since we release 1.6.0.0a1 the other day.

@murraystevenson murraystevenson force-pushed the inheritGlobalAttributes branch from b0b4473 to 9f53f89 Compare August 13, 2025 00:04
@murraystevenson
Copy link
Contributor Author

Thanks John! Rebased to bring up to date and fix the Changes.md entries, feedback addressed inline.

I think perhaps we should do ShaderQuery and ShaderTweaks now...

Added those in cb0dea3 and 366c924. It turned out that as ShaderQuery uses an internal AttributeQuery it just needed a test and a tweak to the menu.

@johnhaddon
Copy link
Member

Thanks Murray - changes all look good except for the Ptr mixup I've commented inline. Could you squash everything down while fixing that so we're ready to merge please? Thanks!

@murraystevenson murraystevenson force-pushed the inheritGlobalAttributes branch from 9f53f89 to 4f129a9 Compare August 13, 2025 21:18
@murraystevenson
Copy link
Contributor Author

Apologies for the crossed wires! That should be properly addressed now and all is squashed down ready to merge.

@johnhaddon johnhaddon force-pushed the inheritGlobalAttributes branch from 4f129a9 to 2dc8851 Compare August 14, 2025 15:05
@johnhaddon johnhaddon merged commit fa06d16 into GafferHQ:main Aug 14, 2025
2 of 6 checks passed
@johnhaddon
Copy link
Member

Thanks for the update - rebased to fix the Changes.md conflict, and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants