From e81d7c0d8aab8bf7e96b881a343968bb30f573a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Fri, 3 Jul 2020 11:33:02 +0200 Subject: [PATCH] Implemented shadergraph upgrade system using system data --- .../Material/ShaderGraph/HDSubTarget.cs | 26 ++++++++++++++++++- .../ShaderGraph/ShaderGraphVersion.cs | 13 ++++++++++ .../ShaderGraph/ShaderGraphVersion.cs.meta | 11 ++++++++ .../ShaderGraph/TargetData/SystemData.cs | 8 ++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs.meta diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs index bb801f40233..44e609a1d88 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs @@ -14,7 +14,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { abstract class HDSubTarget : SubTarget, IHasMetadata, - IRequiresData + IRequiresData, IVersionable { SystemData m_SystemData; protected bool m_MigrateFromOldCrossPipelineSG; // Use only for the migration to shader stack architecture @@ -60,12 +60,36 @@ public virtual ScriptableObject GetMetadataObject() return hdMetadata; } + ShaderGraphVersion IVersionable.version + { + get => systemData.version; + set => systemData.version = value; + } + + // Generate migration description steps to migrate HD shader targets + internal static MigrationDescription migrationSteps => MigrationDescription.New( + Enum.GetValues(typeof(ShaderGraphVersion)).Cast().Select( + version => MigrationStep.New(version, (HDSubTarget t) => t.MigrateTo(version)) + ).ToArray() + ); + + /// + /// Override this method to handle migration in inherited subtargets + /// + /// The current version of the migration + internal virtual void MigrateTo(ShaderGraphVersion version) + { + } + public override void Setup(ref TargetSetupContext context) { context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath("c09e6e9062cbd5a48900c48a0c2ed1c2")); // HDSubTarget.cs context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(subTargetAssetGuid)); context.SetDefaultShaderGUI(customInspector); + if (migrationSteps.Migrate(this)) + OnBeforeSerialize(); + foreach (var subShader in EnumerateSubShaders()) { // patch render type and render queue from pass declaration: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs new file mode 100644 index 00000000000..1864ea0f241 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs @@ -0,0 +1,13 @@ +using System; +using UnityEngine; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEngine.Serialization; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + public enum ShaderGraphVersion + { + Initial = 0, + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs.meta new file mode 100644 index 00000000000..fe5da8616f6 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 76d507e672f03ab44ae82ba1c6fdb67b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs index 2de372cc6cd..12e334d6d05 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs @@ -133,6 +133,14 @@ public bool dotsInstancing set => m_DOTSInstancing = value; } + [SerializeField] + ShaderGraphVersion m_Version = MigrationDescription.LastVersion(); + public ShaderGraphVersion version + { + get => m_Version; + set => m_Version = value; + } + internal int inspectorFoldoutMask; }