Skip to content

[HDRP] Fix infitnite material import loop materials #6185

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 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed sky override layer mask having no effect.
- Fixed a memory leak in the template tutorial (1374640).
- Fixed a build-time warning regarding light loop variants (case 1372256).
- Fixed an infinite import loop of materials when there is no HDMetaData generated by the ShaderGraph.

### Changed
- Use RayTracingAccelerationStructure.CullInstances to filter Renderers and populate the acceleration structure with ray tracing instances for improved CPU performance on the main thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class MaterialPostprocessor : AssetPostprocessor
{
internal static List<string> s_CreatedAssets = new List<string>();
internal static List<string> s_ImportedAssetThatNeedSaving = new List<string>();
internal static Dictionary<string, int> s_ImportedMaterialCounter = new Dictionary<string, int>();
internal static bool s_NeedsSavingAssets = false;

// Important: This should only be called by the RegisterUpgraderReimport(), ie the shadegraph/material version
Expand Down Expand Up @@ -371,6 +372,14 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
// we would miss re-importing that dependency.
if (MaterialReimporter.CheckHDShaderGraphVersionsForUpgrade("", material.shader, ignoreNonHDRPShaderGraphs: false))
{
s_ImportedMaterialCounter.TryGetValue(asset, out var importCounter);
s_ImportedMaterialCounter[asset] = ++importCounter;

// CheckHDShaderGraphVersionsForUpgrade always return true if a ShaderGraph don't have an HDMetaData attached
Copy link
Contributor

Choose a reason for hiding this comment

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

question, can't we check that the shadergraph currently have or not the HDMetaData data instead of relying on importCounter info?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's complicated because an HD ShaderGraph could not have an HDMetaData if it's old, in this case, the ShaderGraph needs to be reimported along with the material. It's only after this reimport that we can know if the material has or not an HDMetaData (i.e. the second time the material is imported).

// we need a check to avoid importing the same assets over and over again.
if (importCounter > 2)
continue;

var shaderPath = AssetDatabase.GetAssetPath(material.shader.GetInstanceID());
AssetDatabase.ImportAsset(shaderPath);

Expand Down