-
Notifications
You must be signed in to change notification settings - Fork 860
[Skip CI] Virtual Texturing cache settings #536
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
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
81d1f11
Changed use of VT.System namespace to VT.Streaming namespace where th…
GraphineNicolas 66057c0
Virtual Texturing HDRP cache size settings.
GraphineNicolas 9142cd3
Merge branch 'fix-shadergraph-vt-cache-recreation' into virtualtextur…
GraphineNicolas b803339
VT settings UI is now shown but disabled when VT is not enabled.
GraphineNicolas 7c09cd8
Added a tooltip to the header of the VT settings.
GraphineNicolas c2ff1aa
Merge branch 'master' into virtualtexturing-settings
NicoLeyman fa3786e
Merge branch 'master' into virtualtexturing-settings
GraphineNicolas 93c2e8b
Merge branch 'virtualtexturing-settings' of https://github.com/Unity-…
GraphineNicolas 19e674b
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
GraphineNicolas 9e2ae9a
Revert whitespace changes to HDRP changelog.
GraphineNicolas ca2f1b3
Merge branch 'master' into virtualtexturing-settings
sebastienlagarde 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
20 changes: 20 additions & 0 deletions
20
...ines.high-definition/Editor/RenderPipeline/Settings/SerializedVirtualTexturingSettings.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using UnityEditor.Rendering; | ||
| using UnityEngine.Rendering.HighDefinition; | ||
|
|
||
| namespace UnityEditor.Rendering.HighDefinition | ||
| { | ||
| public sealed class SerializedVirtualTexturingSettings | ||
| { | ||
| public SerializedProperty root; | ||
|
|
||
| public SerializedProperty streamingCpuCacheSizeInMegaBytes; | ||
| public SerializedProperty streamingGpuCacheSettings; | ||
| public SerializedVirtualTexturingSettings(SerializedProperty root) | ||
| { | ||
| this.root = root; | ||
|
|
||
| streamingCpuCacheSizeInMegaBytes = root.Find((VirtualTexturingSettingsSRP s) => s.streamingCpuCacheSizeInMegaBytes); | ||
| streamingGpuCacheSettings = root.Find((VirtualTexturingSettingsSRP s) => s.streamingGpuCacheSettings); | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...high-definition/Editor/RenderPipeline/Settings/SerializedVirtualTexturingSettings.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
267 changes: 267 additions & 0 deletions
267
...nity.render-pipelines.high-definition/Editor/RenderPipeline/VirtualTexturingSettingsUI.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,267 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using UnityEditorInternal; | ||
| using UnityEngine; | ||
| using UnityEngine.Experimental.Rendering; | ||
| using UnityEngine.Rendering.VirtualTexturing; | ||
|
|
||
| #if ENABLE_VIRTUALTEXTURES | ||
| namespace UnityEditor.Rendering.HighDefinition | ||
| { | ||
| class VirtualTexturingSettingsUI | ||
| { | ||
| private ReorderableList m_GPUCacheSizeOverrideListStreaming; | ||
| private SerializedProperty m_GPUCacheSizeOverridesPropertyStreaming; | ||
|
|
||
| public SerializedObject serializedObject; | ||
| private SerializedHDRenderPipelineAsset serializedRPAsset; | ||
|
|
||
| private const int CPUCacheSizeMinValue = 64; | ||
| private const int GPUCacheSizeMinValue = 32; | ||
|
|
||
| public void OnGUI(SerializedHDRenderPipelineAsset serialized, Editor owner) | ||
| { | ||
| CheckStyles(); | ||
|
|
||
| serializedObject = serialized.serializedObject; | ||
| serializedRPAsset = serialized; | ||
|
|
||
| EditorGUILayout.Space(); | ||
|
|
||
| using (var scope = new EditorGUI.ChangeCheckScope()) | ||
| { | ||
| serialized.virtualTexturingSettings.streamingCpuCacheSizeInMegaBytes.intValue = Mathf.Max(CPUCacheSizeMinValue, EditorGUILayout.DelayedIntField(s_Styles.cpuCacheSize, serialized.virtualTexturingSettings.streamingCpuCacheSizeInMegaBytes.intValue)); | ||
|
|
||
| // GPU Cache size settings | ||
| if (m_GPUCacheSizeOverrideListStreaming == null || | ||
| m_GPUCacheSizeOverridesPropertyStreaming != serialized.virtualTexturingSettings.streamingGpuCacheSettings) | ||
| { | ||
| m_GPUCacheSizeOverridesPropertyStreaming = serialized.virtualTexturingSettings.streamingGpuCacheSettings; | ||
| m_GPUCacheSizeOverrideListStreaming = CreateGPUCacheSizeOverrideList(m_GPUCacheSizeOverridesPropertyStreaming, DrawStreamingOverrideElement); | ||
| } | ||
|
|
||
| m_GPUCacheSizeOverrideListStreaming.DoLayoutList(); | ||
| } | ||
|
|
||
| serialized.serializedObject.ApplyModifiedProperties(); | ||
| } | ||
|
|
||
| GPUCacheSetting[] GetGPUCacheSizeOverrideArrayFromProperty(SerializedProperty property) | ||
| { | ||
| List<GPUCacheSetting> settings = new List<GPUCacheSetting>(); | ||
| for (int i = 0; i < property.arraySize; ++i) | ||
| { | ||
| SerializedProperty settingProperty = property.GetArrayElementAtIndex(i); | ||
| settings.Add(new GPUCacheSetting() | ||
| { format = (GraphicsFormat)settingProperty.FindPropertyRelative("format").intValue, sizeInMegaBytes = (uint)settingProperty.FindPropertyRelative("sizeInMegaBytes").intValue }); | ||
| } | ||
|
|
||
| return settings.ToArray(); | ||
| } | ||
|
|
||
| ReorderableList CreateGPUCacheSizeOverrideList(SerializedProperty property, ReorderableList.ElementCallbackDelegate drawCallback) | ||
| { | ||
| ReorderableList list = new ReorderableList(property.serializedObject, property); | ||
|
|
||
| list.drawHeaderCallback = | ||
| (Rect rect) => | ||
| { | ||
| GUI.Label(rect, s_Styles.gpuCacheSize); | ||
| }; | ||
|
|
||
| list.drawElementCallback = drawCallback; | ||
|
|
||
| list.onAddCallback = (l) => | ||
| { | ||
| List<GraphicsFormat> availableFormats = new List<GraphicsFormat>(EditorHelpers.QuerySupportedFormats()); | ||
|
|
||
| // We can't just pass in existing settings as a parameter to CreateGPUCacheSizeOverrideList() because lambdas can't capture ref params. | ||
| GPUCacheSetting[] existingSettings = GetGPUCacheSizeOverrideArrayFromProperty(serializedRPAsset.virtualTexturingSettings.streamingGpuCacheSettings); | ||
| RemoveOverriddenFormats(availableFormats, existingSettings); | ||
|
|
||
| int index = property.arraySize; | ||
| property.InsertArrayElementAtIndex(index); | ||
| var newItemProperty = property.GetArrayElementAtIndex(index); | ||
| newItemProperty.FindPropertyRelative("format").intValue = availableFormats.Count > 0 ? (int)availableFormats[0] : 0; | ||
| newItemProperty.FindPropertyRelative("sizeInMegaBytes").intValue = 64; | ||
| }; | ||
|
|
||
| return list; | ||
| } | ||
|
|
||
| void GraphicsFormatToFormatAndChannelTransformString(GraphicsFormat graphicsFormat, out string format, out string channelTransform) | ||
| { | ||
| string formatString = graphicsFormat.ToString(); | ||
| int lastUnderscore = formatString.LastIndexOf('_'); | ||
| if (lastUnderscore < 0) | ||
| { | ||
| format = "None"; | ||
| channelTransform = "None"; | ||
| return; | ||
| } | ||
| format = formatString.Substring(0, lastUnderscore); | ||
| channelTransform = formatString.Substring(lastUnderscore + 1); | ||
| } | ||
| GraphicsFormat FormatAndChannelTransformStringToGraphicsFormat(string format, string channelTransform) | ||
| { | ||
| if (format == "None") return GraphicsFormat.None; | ||
|
|
||
| return (GraphicsFormat)Enum.Parse(typeof(GraphicsFormat), $"{format}_{channelTransform}"); | ||
| } | ||
|
|
||
| void RemoveOverriddenFormats(List<GraphicsFormat> formats, GPUCacheSetting[] settings) | ||
| { | ||
| foreach (var existingCacheSizeOverride in settings) | ||
| { | ||
| formats.Remove(existingCacheSizeOverride.format); | ||
| } | ||
| } | ||
|
|
||
| void GPUCacheSizeOverridesGUI(Rect rect, int settingIdx, SerializedProperty settingListProperty, GPUCacheSetting[] settingList) | ||
| { | ||
| var cacheSizeOverrideProperty = settingListProperty.GetArrayElementAtIndex(settingIdx); | ||
| var cacheSizeOverride = settingList[settingIdx]; | ||
|
|
||
| List<GraphicsFormat> availableFormats = new List<GraphicsFormat>(EditorHelpers.QuerySupportedFormats()); | ||
| // None is used for a default cache size. | ||
| availableFormats.Add(GraphicsFormat.None); | ||
|
|
||
| RemoveOverriddenFormats(availableFormats, settingList); | ||
|
|
||
| // Group formats | ||
| Dictionary<string, List<string>> formatGroups = new Dictionary<string, List<string>>(); | ||
| foreach (GraphicsFormat graphicsFormat in availableFormats) | ||
| { | ||
| GraphicsFormatToFormatAndChannelTransformString(graphicsFormat, out var format, out var channelTransform); | ||
| if (!formatGroups.ContainsKey(format)) | ||
| { | ||
| formatGroups.Add(format, new List<string>()); | ||
| } | ||
| formatGroups[format].Add(channelTransform); | ||
| } | ||
|
|
||
| GraphicsFormat serializedFormat = (GraphicsFormat) cacheSizeOverrideProperty.FindPropertyRelative("format").intValue; | ||
| GraphicsFormatToFormatAndChannelTransformString(serializedFormat, out string formatString, out string channelTransformString); | ||
|
|
||
| // GUI Drawing | ||
|
|
||
| float settingWidth = rect.width; | ||
|
|
||
| float spacing = Math.Min(5, settingWidth * 0.02f); | ||
|
|
||
| settingWidth -= 2 * spacing; | ||
|
|
||
| float formatLabelWidth = Math.Min(60, settingWidth * 0.25f); | ||
| float formatWidth = settingWidth * 0.3f; | ||
| float channelTransformWidth = settingWidth * 0.25f; | ||
| float sizeLabelWidth = Math.Min(45, settingWidth * 0.2f); | ||
| float sizeWidth = settingWidth * 0.15f; | ||
|
|
||
| // Format | ||
| rect.width = formatLabelWidth; | ||
| rect.position += new Vector2(-15, 0); | ||
| EditorGUI.LabelField(rect, s_Styles.gpuCacheSizeOverrideFormat); | ||
|
|
||
| rect.position += new Vector2(formatLabelWidth, 0); | ||
| rect.width = formatWidth; | ||
| if (EditorGUI.DropdownButton(rect, new GUIContent(formatString), FocusType.Keyboard)) | ||
| { | ||
| GenericMenu menu = new GenericMenu(); | ||
| foreach (string possibleFormat in formatGroups.Keys) | ||
| { | ||
| string localFormat = possibleFormat; | ||
| menu.AddItem(new GUIContent(localFormat), formatString == localFormat, () => | ||
| { | ||
| // Make sure the channelTransform is valid for the format. | ||
| List<string> formatGroup = formatGroups[localFormat]; | ||
| if (formatGroup.FindIndex((string possibleChannelTransform) => { return possibleChannelTransform == channelTransformString; }) == -1) | ||
| { | ||
| channelTransformString = formatGroup[0]; | ||
| } | ||
|
|
||
| cacheSizeOverrideProperty.FindPropertyRelative("format").intValue = (int)FormatAndChannelTransformStringToGraphicsFormat(localFormat, channelTransformString); | ||
|
|
||
| serializedObject.ApplyModifiedProperties(); | ||
| }); | ||
| } | ||
|
|
||
| menu.ShowAsContext(); | ||
| } | ||
|
|
||
| // Channel transform | ||
| rect.position += new Vector2(formatWidth, 0); | ||
| rect.width = channelTransformWidth; | ||
|
|
||
| List<string> possibleChannelTransforms = new List<string>(); | ||
|
|
||
| if (formatGroups.ContainsKey(formatString)) | ||
| { | ||
| possibleChannelTransforms = formatGroups[formatString]; | ||
| } | ||
|
|
||
| EditorGUI.BeginDisabledGroup(possibleChannelTransforms.Count == 0); | ||
| { | ||
| if (serializedFormat != GraphicsFormat.None && EditorGUI.DropdownButton(rect, new GUIContent(channelTransformString), FocusType.Keyboard)) | ||
| { | ||
| GenericMenu menu = new GenericMenu(); | ||
| possibleChannelTransforms.Add(channelTransformString); | ||
| possibleChannelTransforms.Sort(); | ||
|
|
||
| foreach (string possibleChannelTransform in possibleChannelTransforms) | ||
| { | ||
| string localChannelTransform = possibleChannelTransform; | ||
| menu.AddItem(new GUIContent(localChannelTransform), localChannelTransform == channelTransformString, () => | ||
| { | ||
| GraphicsFormat format = FormatAndChannelTransformStringToGraphicsFormat(formatString, localChannelTransform); | ||
| cacheSizeOverrideProperty.FindPropertyRelative("format").intValue = (int)format; | ||
| serializedObject.ApplyModifiedProperties(); | ||
| }); | ||
| } | ||
|
|
||
| menu.ShowAsContext(); | ||
| } | ||
| } | ||
| EditorGUI.EndDisabledGroup(); | ||
|
|
||
| // Size | ||
| rect.position += new Vector2(channelTransformWidth + spacing, 0); | ||
| rect.width = sizeLabelWidth; | ||
|
|
||
| EditorGUI.LabelField(rect, s_Styles.gpuCacheSizeOverrideSize); | ||
|
|
||
| rect.position += new Vector2(sizeLabelWidth, 0); | ||
| rect.width = sizeWidth; | ||
|
|
||
| cacheSizeOverride.sizeInMegaBytes = (uint) Mathf.Max(GPUCacheSizeMinValue, | ||
| EditorGUI.DelayedIntField(rect, (int) cacheSizeOverride.sizeInMegaBytes)); | ||
| cacheSizeOverrideProperty.FindPropertyRelative("sizeInMegaBytes").intValue = | ||
| (int) cacheSizeOverride.sizeInMegaBytes; | ||
| } | ||
|
|
||
| void DrawStreamingOverrideElement(Rect rect, int settingIdx, bool active, bool focused) | ||
| { | ||
| GPUCacheSizeOverridesGUI(rect, settingIdx, m_GPUCacheSizeOverridesPropertyStreaming, GetGPUCacheSizeOverrideArrayFromProperty(serializedRPAsset.virtualTexturingSettings.streamingGpuCacheSettings)); | ||
| } | ||
|
|
||
| sealed class Styles | ||
| { | ||
| public readonly GUIContent cpuCacheSize = new GUIContent("CPU Cache Size", "Amount of CPU memory (in MB) that can be allocated by the Streaming Virtual Texturing system to use to cache texture data."); | ||
| public readonly GUIContent gpuCacheSize = new GUIContent("GPU Cache Size per Format", "Amount of GPU memory (in MB) that can be allocated per format by the Streaming Virtual Texturing system to cache texture data. The value assigned to None is used for all unspecified formats."); | ||
|
|
||
| public readonly GUIContent gpuCacheSizeOverrideFormat = new GUIContent("Format", "Format and channel transform that will be overridden."); | ||
| public readonly GUIContent gpuCacheSizeOverrideSize = new GUIContent("Size", "Size (in MB) of the setting."); | ||
| } | ||
|
|
||
| static Styles s_Styles; | ||
|
|
||
| // Can't use a static initializer in case we need to create GUIStyle in the Styles class as | ||
| // these can only be created with an active GUI rendering context | ||
| void CheckStyles() | ||
| { | ||
| if (s_Styles == null) | ||
| s_Styles = new Styles(); | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
11 changes: 11 additions & 0 deletions
11
...render-pipelines.high-definition/Editor/RenderPipeline/VirtualTexturingSettingsUI.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.