Skip to content

Commit 3e8732d

Browse files
Internal/6000.2/staging
Internal/6000.2/staging
2 parents 64b601d + 725f664 commit 3e8732d

File tree

75 files changed

+6661
-1124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+6661
-1124
lines changed

Packages/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,35 @@ public sealed class DebugStateInt : DebugState<int> { }
182182
[Serializable, DebugState(typeof(DebugUI.ObjectPopupField), typeof(DebugUI.CameraSelector), typeof(DebugUI.ObjectField))]
183183
public sealed class DebugStateObject : DebugState<UnityEngine.Object>
184184
{
185+
[SerializeField] string m_UserData;
186+
187+
/// <inheritdoc/>
188+
public override void SetValue(object value, DebugUI.IValueField field)
189+
{
190+
// DebugStateObject is used to serialize the selected camera reference in DebugUI.CameraSelector. For SceneView Camera this doesn't work because
191+
// the camera is never saved and always recreated. So we use a special string to identify this case and restore the reference later.
192+
if (field is DebugUI.CameraSelector && SceneView.lastActiveSceneView != null && (Camera)value == SceneView.lastActiveSceneView.camera)
193+
{
194+
m_UserData = "SceneViewCamera";
195+
}
196+
else
197+
{
198+
m_UserData = null;
199+
}
200+
base.SetValue(value, field);
201+
}
202+
203+
/// <inheritdoc/>
204+
public override object GetValue()
205+
{
206+
if (value == null && m_UserData != null && m_UserData == "SceneViewCamera" && SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera != null)
207+
{
208+
value = SceneView.lastActiveSceneView.camera;
209+
}
210+
211+
return base.GetValue();
212+
}
213+
185214
/// <summary>
186215
/// Returns the hash code of the Debug Item.
187216
/// </summary>

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.VirtualOffset.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public override void Initialize(ProbeVolumeBakingSet bakingSet, NativeArray<Vect
109109
batchResult = new Vector3[k_MaxProbeCountPerBatch];
110110

111111
var computeBufferTarget = GraphicsBuffer.Target.CopyDestination | GraphicsBuffer.Target.CopySource
112-
| GraphicsBuffer.Target.Structured | GraphicsBuffer.Target.Raw;
112+
| GraphicsBuffer.Target.Structured;
113113

114114
// Create acceletation structure
115115
m_AccelerationStructure = BuildAccelerationStructure(voSettings.collisionMask);

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeVolumeLightingTab.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ void ShowWarnings()
428428
{
429429
for (int i = 0; i < SceneManager.sceneCount; i++)
430430
{
431-
var scene = SceneManager.GetSceneAt(i);
431+
Scene scene = SceneManager.GetSceneAt(i);
432432
if (scene.isLoaded && ProbeVolumeBakingSet.GetBakingSetForScene(scene) != activeSet)
433433
scenesToUnload.Add(scene);
434434
}
@@ -467,7 +467,7 @@ void ShowWarnings()
467467
if (scenesToUnload.All(s => !s.isDirty) || EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
468468
{
469469
foreach (var scene in scenesToUnload)
470-
EditorSceneManager.CloseScene(scene, false);
470+
EditorSceneManager.CloseScene(scene, string.IsNullOrEmpty(scene.path)); // Remove the scene from the hierarchy iff it has never been saved.
471471
}
472472
break;
473473
}

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/VirtualOffset/TraceVirtualOffset.urtshader

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,22 @@ void RayGenExecute(UnifiedRT::DispatchInfo dispatchInfo)
8787
if (!hit.IsValid() || hit.isFrontFace)
8888
{
8989
validHits++;
90-
continue;
9190
}
92-
93-
float distanceDiff = hit.hitDistance - minDist;
94-
if (distanceDiff < DISTANCE_THRESHOLD)
91+
else if (hit.IsValid())
9592
{
96-
UnifiedRT::HitGeomAttributes attributes = UnifiedRT::FetchHitGeomAttributes(hit, UnifiedRT::kGeomAttribFaceNormal);
97-
float dotSurface = dot(ray.direction, attributes.faceNormal);
98-
99-
// If new distance is smaller by at least kDistanceThreshold, or if ray is at least DOT_THRESHOLD more colinear with normal
100-
if (distanceDiff < -DISTANCE_THRESHOLD || dotSurface - maxDotSurface > DOT_THRESHOLD)
93+
float distanceDiff = hit.hitDistance - minDist;
94+
if (distanceDiff < DISTANCE_THRESHOLD)
10195
{
102-
outDirection = ray.direction;
103-
maxDotSurface = dotSurface;
104-
minDist = hit.hitDistance;
96+
UnifiedRT::HitGeomAttributes attributes = UnifiedRT::FetchHitGeomAttributes(hit, UnifiedRT::kGeomAttribFaceNormal);
97+
float dotSurface = dot(ray.direction, attributes.faceNormal);
98+
99+
// If new distance is smaller by at least kDistanceThreshold, or if ray is at least DOT_THRESHOLD more colinear with normal
100+
if (distanceDiff < -DISTANCE_THRESHOLD || dotSurface - maxDotSurface > DOT_THRESHOLD)
101+
{
102+
outDirection = ray.direction;
103+
maxDotSurface = dotSurface;
104+
minDist = hit.hitDistance;
105+
}
105106
}
106107
}
107108
}

Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugDisplaySettingsVolumes.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,10 @@ public Type selectedComponentType
5959
/// <summary>Current camera to debug.</summary>
6060
public Camera selectedCamera
6161
{
62-
get
63-
{
64-
#if UNITY_EDITOR
65-
// By default pick the one scene camera
66-
if (m_SelectedCamera == null && SceneView.lastActiveSceneView != null)
67-
{
68-
var sceneCamera = SceneView.lastActiveSceneView.camera;
69-
if (sceneCamera != null)
70-
m_SelectedCamera = sceneCamera;
71-
}
72-
#endif
73-
74-
return m_SelectedCamera;
75-
}
62+
get => m_SelectedCamera;
7663
set
7764
{
78-
if (value != null && value != m_SelectedCamera)
65+
if (value != m_SelectedCamera)
7966
{
8067
m_SelectedCamera = value;
8168
OnSelectionChanged();
@@ -333,7 +320,7 @@ public static DebugUI.EnumField CreateComponentSelector(SettingsPanel panel, Act
333320
};
334321
}
335322

336-
public static DebugUI.ObjectPopupField CreateCameraSelector(SettingsPanel panel, Action<DebugUI.Field<Object>, Object> refresh)
323+
public static DebugUI.CameraSelector CreateCameraSelector(SettingsPanel panel, Action<DebugUI.Field<Object>, Object> refresh)
337324
{
338325
return new DebugUI.CameraSelector()
339326
{
@@ -708,7 +695,14 @@ public override void Dispose()
708695
public SettingsPanel(DebugDisplaySettingsVolume data)
709696
: base(data)
710697
{
711-
AddWidget(WidgetFactory.CreateCameraSelector(this, (_, __) => Refresh()));
698+
var cameraSelector = WidgetFactory.CreateCameraSelector(this, (_, __) => Refresh());
699+
700+
// Select first camera if none is selected
701+
var availableCameras = cameraSelector.getObjects() as List<Camera>;
702+
if (data.selectedCamera == null && availableCameras is { Count: > 0 })
703+
data.selectedCamera = availableCameras[0];
704+
705+
AddWidget(cameraSelector);
712706
AddWidget(WidgetFactory.CreateComponentSelector(this, (_, __) => Refresh()));
713707

714708
Func<bool> hiddenCallback = () => data.selectedCamera == null || data.selectedComponent <= 0;

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/Compiler/ResourcesData.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void SetWritingPass(CompilerContextData ctx, ResourceHandle h, int passId
146146
public void RegisterReadingPass(CompilerContextData ctx, ResourceHandle h, int passId, int index)
147147
{
148148
#if DEVELOPMENT_BUILD || UNITY_EDITOR
149-
if (numReaders >= ctx.resources.MaxReaders)
149+
if (numReaders >= ctx.resources.MaxReaders[h.iType])
150150
{
151151
string passName = ctx.GetPassName(passId);
152152
string resourceName = ctx.GetResourceName(h);
@@ -194,8 +194,8 @@ internal class ResourcesData
194194
public NativeList<ResourceVersionedData>[] versionedData; // Flattened fixed size array storing up to MaxVersions versions per resource id.
195195
public NativeList<ResourceReaderData>[] readerData; // Flattened fixed size array storing up to MaxReaders per resource id per version.
196196

197-
public int MaxVersions;
198-
public int MaxReaders;
197+
public int[] MaxVersions;
198+
public int[] MaxReaders;
199199

200200
public DynamicArray<Name>[] resourceNames;
201201

@@ -205,6 +205,8 @@ public ResourcesData()
205205
versionedData = new NativeList<ResourceVersionedData>[(int)RenderGraphResourceType.Count];
206206
readerData = new NativeList<ResourceReaderData>[(int)RenderGraphResourceType.Count];
207207
resourceNames = new DynamicArray<Name>[(int)RenderGraphResourceType.Count];
208+
MaxVersions = new int[(int)RenderGraphResourceType.Count];
209+
MaxReaders = new int[(int)RenderGraphResourceType.Count];
208210

209211
for (int t = 0; t < (int)RenderGraphResourceType.Count; t++)
210212
resourceNames[t] = new DynamicArray<Name>(0); // T in NativeList<T> cannot contain managed types, so the names are stored separately
@@ -241,14 +243,14 @@ void AllocateAndResizeNativeListIfNeeded<T>(ref NativeList<T> nativeList, int si
241243

242244
public void Initialize(RenderGraphResourceRegistry resources)
243245
{
244-
uint maxReaders = 0;
245-
uint maxWriters = 0;
246-
247246
for (int t = 0; t < (int)RenderGraphResourceType.Count; t++)
248247
{
249248
RenderGraphResourceType resourceType = (RenderGraphResourceType) t;
250249
var numResources = resources.GetResourceCount(resourceType);
251250

251+
uint maxReaders = 0;
252+
uint maxWriters = 0;
253+
252254
// We don't clear the list as we reinitialize it right after
253255
AllocateAndResizeNativeListIfNeeded(ref unversionedData[t], numResources, NativeArrayOptions.UninitializedMemory);
254256

@@ -308,12 +310,12 @@ public void Initialize(RenderGraphResourceRegistry resources)
308310
}
309311

310312
// The first resource is a null resource, so we need to add 1 to the count.
311-
MaxReaders = (int)maxReaders + 1;
312-
MaxVersions = (int)maxWriters + 1;
313+
MaxReaders[t] = (int)maxReaders + 1;
314+
MaxVersions[t] = (int)maxWriters + 1;
313315

314316
// Clear the other caching structures, they will be filled later
315-
AllocateAndResizeNativeListIfNeeded(ref versionedData[t], MaxVersions * numResources, NativeArrayOptions.ClearMemory);
316-
AllocateAndResizeNativeListIfNeeded(ref readerData[t], MaxVersions * MaxReaders * numResources, NativeArrayOptions.ClearMemory);
317+
AllocateAndResizeNativeListIfNeeded(ref versionedData[t], MaxVersions[t] * numResources, NativeArrayOptions.ClearMemory);
318+
AllocateAndResizeNativeListIfNeeded(ref readerData[t], MaxVersions[t] * MaxReaders[t] * numResources, NativeArrayOptions.ClearMemory);
317319
}
318320
}
319321

@@ -322,23 +324,23 @@ public void Initialize(RenderGraphResourceRegistry resources)
322324
public int Index(ResourceHandle h)
323325
{
324326
#if UNITY_EDITOR // Hot path
325-
if (h.version < 0 || h.version >= MaxVersions)
327+
if (h.version < 0 || h.version >= MaxVersions[h.iType])
326328
throw new Exception("Invalid version: " + h.version);
327329
#endif
328-
return h.index * MaxVersions + h.version;
330+
return h.index * MaxVersions[h.iType] + h.version;
329331
}
330332

331333
// Flatten array index
332334
[MethodImpl(MethodImplOptions.AggressiveInlining)]
333335
public int IndexReader(ResourceHandle h, int readerID)
334336
{
335337
#if UNITY_EDITOR // Hot path
336-
if (h.version < 0 || h.version >= MaxVersions)
338+
if (h.version < 0 || h.version >= MaxVersions[h.iType])
337339
throw new Exception("Invalid version");
338-
if (readerID < 0 || readerID >= MaxReaders)
340+
if (readerID < 0 || readerID >= MaxReaders[h.iType])
339341
throw new Exception("Invalid reader");
340342
#endif
341-
return (h.index * MaxVersions + h.version) * MaxReaders + readerID;
343+
return (h.index * MaxVersions[h.iType] + h.version) * MaxReaders[h.iType] + readerID;
342344
}
343345

344346
// Lookup data for a given handle

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ internal void ForceCleanup()
591591

592592
nativeCompiler?.Cleanup();
593593

594-
m_CompilationCache?.Clear();
594+
m_CompilationCache?.Cleanup();
595595

596596
DelegateHashCodeUtils.ClearCache();
597597
}

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphCompilationCache.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,41 @@ public bool GetCompilationCache(int hash, int frameIndex, out CompilerContextDat
9696
return GetCompilationCache(hash, frameIndex, out outGraph, m_NativeHashEntries, m_NativeCompiledGraphPool, s_NativeEntryComparer);
9797
}
9898

99-
public void Clear()
99+
public void Cleanup()
100100
{
101+
// We clear the contents of the pools but not the pool themselves, because they are only
102+
// filled at the beginning of the renderer pipeline and never after. This means when we call
103+
// Cleanup() after an error, if we were clearing the pools, the render graph could not gracefully start
104+
// back up because the cache would have a size of 0 (so no room to cache anything).
105+
106+
// Cleanup compiled graphs currently in the cache
101107
for (int i = 0; i < m_HashEntries.size; ++i)
102-
m_CompiledGraphPool.Push(m_HashEntries[i].compiledGraph);
108+
{
109+
var compiledGraph = m_HashEntries[i].compiledGraph;
110+
compiledGraph.Clear();
111+
}
103112
m_HashEntries.Clear();
104113

114+
// Cleanup compiled graphs that might be left in the pool
115+
var compiledGraphs = m_CompiledGraphPool.ToArray();
116+
for (int i = 0; i < compiledGraphs.Length; ++i)
117+
{
118+
compiledGraphs[i].Clear();
119+
}
120+
121+
// Dispose of CompilerContextData currently in the cache
105122
for (int i = 0; i < m_NativeHashEntries.size; ++i)
106-
m_NativeCompiledGraphPool.Push(m_NativeHashEntries[i].compiledGraph);
123+
{
124+
var compiledGraph = m_NativeHashEntries[i].compiledGraph;
125+
compiledGraph.Dispose();
126+
}
107127
m_NativeHashEntries.Clear();
128+
129+
// Dispose of CompilerContextData that might be left in the pool
130+
var nativeCompiledGraphs = m_NativeCompiledGraphPool.ToArray();
131+
for (int i = 0; i < nativeCompiledGraphs.Length; ++i)
132+
{
133+
nativeCompiledGraphs[i].Dispose();
134+
}
108135
}
109136
}

0 commit comments

Comments
 (0)