Skip to content

Commit 5e19a23

Browse files
Cache base types of Volume Manager to improve perf/memory #3804
1 parent eaa5243 commit 5e19a23

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

com.unity.render-pipelines.core/Editor/Volume/VolumeComponentProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void CreateComponentTree(List<Element> tree)
5151
{
5252
tree.Add(new GroupElement(0, "Volume Overrides"));
5353

54-
var types = VolumeManager.instance.baseComponentTypes;
54+
var types = VolumeManager.instance.baseComponentTypeArray;
5555
var rootNode = new PathNode();
5656

5757
foreach (var t in types)

com.unity.render-pipelines.core/Runtime/Volume/VolumeManager.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,20 @@ public sealed class VolumeManager
3030
/// <summary>
3131
/// The current list of all available types that derive from <see cref="VolumeComponent"/>.
3232
/// </summary>
33-
public IEnumerable<Type> baseComponentTypes { get; private set; }
33+
[Obsolete("Please use baseComponentTypeArray instead.")]
34+
public IEnumerable<Type> baseComponentTypes
35+
{
36+
get
37+
{
38+
return baseComponentTypeArray;
39+
}
40+
private set
41+
{
42+
baseComponentTypeArray = value.ToArray();
43+
}
44+
}
45+
46+
public Type[] baseComponentTypeArray { get; private set; }
3447

3548
// Max amount of layers available in Unity
3649
const int k_MaxLayerCount = 32;
@@ -75,7 +88,7 @@ public sealed class VolumeManager
7588
public VolumeStack CreateStack()
7689
{
7790
var stack = new VolumeStack();
78-
stack.Reload(baseComponentTypes);
91+
stack.Reload(baseComponentTypeArray);
7992
return stack;
8093
}
8194

@@ -95,12 +108,12 @@ void ReloadBaseTypes()
95108
m_ComponentsDefaultState.Clear();
96109

97110
// Grab all the component types we can find
98-
baseComponentTypes = CoreUtils.GetAllTypesDerivedFrom<VolumeComponent>()
99-
.Where(t => !t.IsAbstract);
111+
baseComponentTypeArray = CoreUtils.GetAllTypesDerivedFrom<VolumeComponent>()
112+
.Where(t => !t.IsAbstract).ToArray();
100113

101114
// Keep an instance of each type to be used in a virtual lowest priority global volume
102115
// so that we have a default state to fallback to when exiting volumes
103-
foreach (var type in baseComponentTypes)
116+
foreach (var type in baseComponentTypeArray)
104117
{
105118
var inst = (VolumeComponent)ScriptableObject.CreateInstance(type);
106119
m_ComponentsDefaultState.Add(inst);
@@ -260,15 +273,15 @@ public void CheckStack(VolumeStack stack)
260273

261274
if (components == null)
262275
{
263-
stack.Reload(baseComponentTypes);
276+
stack.Reload(baseComponentTypeArray);
264277
return;
265278
}
266279

267280
foreach (var kvp in components)
268281
{
269282
if (kvp.Key == null || kvp.Value == null)
270283
{
271-
stack.Reload(baseComponentTypes);
284+
stack.Reload(baseComponentTypeArray);
272285
return;
273286
}
274287
}

com.unity.render-pipelines.core/Runtime/Volume/VolumeStack.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal VolumeStack()
1818
{
1919
}
2020

21-
internal void Reload(IEnumerable<Type> baseTypes)
21+
internal void Reload(Type[] baseTypes)
2222
{
2323
if (components == null)
2424
components = new Dictionary<Type, VolumeComponent>();

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ The version number for this package has increased due to a version update of a r
166166
- Transparent materials created by the Model Importer are set to not cast shadows. ( case 1295747)
167167
- Change some light unit slider value ranges to better reflect the lighting scenario.
168168
- Change the tooltip for color shadows and semi-transparent shadows (case 1307704).
169+
- Cached the base types of Volume Manager to improve memory and cpu usage.
169170

170171
## [10.2.1] - 2020-11-30
171172

com.unity.render-pipelines.high-definition/Runtime/Debug/VolumeDebug.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static public List<Type> componentTypes
132132
{
133133
if (s_ComponentTypes == null)
134134
{
135-
s_ComponentTypes = VolumeManager.instance.baseComponentTypes
135+
s_ComponentTypes = VolumeManager.instance.baseComponentTypeArray
136136
.Where(t => !t.IsDefined(typeof(VolumeComponentDeprecated), false))
137137
.OrderBy(t => ComponentDisplayName(t))
138138
.ToList();

0 commit comments

Comments
 (0)