Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -126,6 +126,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Implemented ray traced reflections for transparent objects.
- Add a new parameter to control reflections in recursive rendering.
- Added an initial version of SSGI.
- Added Virtual Texturing cache settings to control the size of the Streaming Virtual Texturing caches.

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,10 @@ Use these settings to enable or disable settings relating to lighting in HDRP.
| **Grading LUT Size** | The size of the internal and external color grading lookup textures (LUTs). This size is fixed for the Project. You can not mix and match LUT sizes, so decide on a size before you start the color grading process. The default value, **32**, provides a good balance of speed and quality. |
| **Grading LUT Format** | Use the drop-down to select the format to encode the color grading LUTs with. Lower precision formats are faster and use less memory at the expense of color precision. These formats directly map to their equivalent in the built-in [GraphicsFormat](https://docs.unity3d.com/ScriptReference/Experimental.Rendering.GraphicsFormat.html) enum value. |
| **Buffer Format** | Use the drop-down to select the format of the color buffers that are used in the post-processing passes. Lower precision formats are faster and use less memory at the expense of color precision. These formats directly map to their equivalent in the built-in [GraphicsFormat](https://docs.unity3d.com/ScriptReference/Experimental.Rendering.GraphicsFormat.html) enum value.

## Virtual Texturing

| **Property** | **Description** |
| ----------------------- | --------------------------------------------------------------- |
| **CPU Cache Size** | Amount of CPU memory (in MB) that can be allocated by the Streaming Virtual Texturing system to cache texture data. |
| **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. |
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ internal enum SelectedFrameSettings

internal static SelectedFrameSettings selectedFrameSettings;

#if ENABLE_VIRTUALTEXTURES
internal static VirtualTexturingSettingsUI virtualTexturingSettingsUI = new VirtualTexturingSettingsUI();
#endif

static HDRenderPipelineUI()
{
Inspector = CED.Group(
Expand Down Expand Up @@ -100,6 +104,9 @@ static HDRenderPipelineUI()
CED.FoldoutGroup(Styles.chromaticAberrationQualitySettings, Expandable.ChromaticAberrationQuality, k_ExpandedState, FoldoutOption.Indent | FoldoutOption.SubFoldout | FoldoutOption.NoSpaceAtEnd, Drawer_SectionChromaticAberrationQualitySettings)
),
CED.FoldoutGroup(Styles.xrTitle, Expandable.XR, k_ExpandedState, Drawer_SectionXRSettings)
#if ENABLE_VIRTUALTEXTURES
,CED.FoldoutGroup(Styles.virtualTexturingTitle, Expandable.VirtualTexturing, k_ExpandedState, Drawer_SectionVTSettings)
#endif
);

// fix init of selection along what is serialized
Expand Down Expand Up @@ -551,6 +558,13 @@ static void Drawer_SectionXRSettings(SerializedHDRenderPipelineAsset serialized,
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.xrSettings.cameraJitter, Styles.XRCameraJitter);
}

#if ENABLE_VIRTUALTEXTURES
static void Drawer_SectionVTSettings(SerializedHDRenderPipelineAsset serialized, Editor owner)
{
virtualTexturingSettingsUI.OnGUI(serialized, owner);
}
#endif

static private bool m_ShowDoFLowQualitySection = false;
static private bool m_ShowDoFMediumQualitySection = false;
static private bool m_ShowDoFHighQualitySection = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SerializedHDRenderPipelineAsset
public SerializedFrameSettings defaultFrameSettings;
public SerializedFrameSettings defaultBakedOrCustomReflectionFrameSettings;
public SerializedFrameSettings defaultRealtimeReflectionFrameSettings;
public SerializedVirtualTexturingSettings virtualTexturingSettings;

//RenderPipelineResources not always exist and thus cannot be serialized normally.
public bool editorResourceHasMultipleDifferentValues
Expand Down Expand Up @@ -63,6 +64,8 @@ public SerializedHDRenderPipelineAsset(SerializedObject serializedObject)
defaultFrameSettings = new SerializedFrameSettings(serializedObject.FindProperty("m_RenderingPathDefaultCameraFrameSettings"), null); //no overrides in HDRPAsset
defaultBakedOrCustomReflectionFrameSettings = new SerializedFrameSettings(serializedObject.FindProperty("m_RenderingPathDefaultBakedOrCustomReflectionFrameSettings"), null); //no overrides in HDRPAsset
defaultRealtimeReflectionFrameSettings = new SerializedFrameSettings(serializedObject.FindProperty("m_RenderingPathDefaultRealtimeReflectionFrameSettings"), null); //no overrides in HDRPAsset

virtualTexturingSettings = new SerializedVirtualTexturingSettings(serializedObject.FindProperty("virtualTexturingSettings"));
}

public void Update()
Expand Down
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);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading