-
Notifications
You must be signed in to change notification settings - Fork 202
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
MAYA-121882 Share the cached HdVP2TextureInfo between all materials so that isSRGB #2145
Merged
+62
−28
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f84fc1a
Share the cached HdVP2TextureInfo between all materials so that isSRG…
7e550af
Clang format, remove debugging fprintf
36685b9
Use reference counting to manage the lifetime of HdVP2TextureInfo. Th…
7ed337d
Build fix for OSX and Linux, where we don't have full C++17 support.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,9 +62,21 @@ struct HdVP2TextureInfo | |
bool _isColorSpaceSRGB { false }; //!< Whether sRGB linearization is needed | ||
}; | ||
|
||
using HdVP2TextureInfoSharedPtr = std::shared_ptr<HdVP2TextureInfo>; | ||
using HdVP2TextureInfoWeakPtr = std::weak_ptr<HdVP2TextureInfo>; | ||
|
||
/*! \brief An unordered string-indexed map to cache texture information. | ||
|
||
Maya has a global internal texture map but we can't rely on it here, because we miss out | ||
on the extra information we store, such as _isColorSpaceSRGB. In HdVP2GlobalTextureMap we | ||
have that additional information. | ||
|
||
In order to correctly delete textures when they are no longer in use the global texture map | ||
holds only a weak_ptr to the HdVP2TextureInfo. The individual materials hold shared_ptrs to | ||
the textures they are using, so that when no materials are using a texture it'll be deleted. | ||
*/ | ||
using HdVP2TextureMap = std::unordered_map<std::string, HdVP2TextureInfo>; | ||
using HdVP2LocalTextureMap = std::unordered_map<std::string, HdVP2TextureInfoSharedPtr>; | ||
using HdVP2GlobalTextureMap = std::unordered_map<std::string, HdVP2TextureInfoWeakPtr>; | ||
|
||
/*! \brief A VP2-specific implementation for a Hydra material prim. | ||
\class HdVP2Material | ||
|
@@ -147,10 +159,11 @@ class HdVP2Material final : public HdMaterial | |
|
||
TfToken _surfaceNetworkToken; //!< Generated token to uniquely identify a material network | ||
|
||
HdVP2ShaderUniquePtr _surfaceShader; //!< VP2 surface shader instance | ||
SdfPath _surfaceShaderId; //!< Path of the surface shader | ||
HdVP2TextureMap _textureMap; //!< Textures used by this material | ||
TfTokenVector _requiredPrimvars; //!< primvars required by this material | ||
HdVP2ShaderUniquePtr _surfaceShader; //!< VP2 surface shader instance | ||
SdfPath _surfaceShaderId; //!< Path of the surface shader | ||
static HdVP2GlobalTextureMap _globalTextureMap; //!< Texture in use by all materials in MayaUSD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With a single global static structure we'd never delete the textures until the plugin unloads or Maya exits. At that time it is often not safe to try to destroy the texture, and textures were held in the cache beyond This way we get the deletion at the right time. |
||
HdVP2LocalTextureMap _localTextureMap; //!< Textures used by this material | ||
TfTokenVector _requiredPrimvars; //!< primvars required by this material | ||
|
||
std::unordered_map<std::string, TextureLoadingTask*> _textureLoadingTasks; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The early exit here is wrong. It also stops marking the sprim dirty and triggering a refresh.