Skip to content

Commit 385e672

Browse files
Internal/6000.2/staging
Internal/6000.2/staging
2 parents 3e8732d + 88f67ec commit 385e672

File tree

160 files changed

+15977
-2217
lines changed

Some content is hidden

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

160 files changed

+15977
-2217
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static ProbeSubdivisionResult GetWorldSubdivision(ref bool canceledByUser)
164164
return GetBricksFromLoaded();
165165

166166
var ctx = PrepareProbeSubdivisionContext();
167-
return BakeBricks(ctx, m_BakingBatch.contributors, ref canceledByUser);
167+
return BakeBricks(ctx, m_BakingBatch.contributors, showProgress: true, ref canceledByUser);
168168
}
169169

170170
static NativeList<Vector3> ApplySubdivisionResults(ProbeSubdivisionResult results, ref bool canceledByUser)
@@ -319,7 +319,7 @@ static internal ProbeSubdivisionContext PrepareProbeSubdivisionContext(bool live
319319
return ctx;
320320
}
321321

322-
static internal ProbeSubdivisionResult BakeBricks(ProbeSubdivisionContext ctx, in GIContributors contributors, ref bool canceledByUser)
322+
static internal ProbeSubdivisionResult BakeBricks(ProbeSubdivisionContext ctx, in GIContributors contributors, bool showProgress, ref bool canceledByUser)
323323
{
324324
var result = new ProbeSubdivisionResult();
325325

@@ -334,7 +334,7 @@ static internal ProbeSubdivisionResult BakeBricks(ProbeSubdivisionContext ctx, i
334334
// subdivide all the cells and generate brick positions
335335
foreach (var cell in ctx.cells)
336336
{
337-
if (cellIdx++ % freq == 0) // Don't refresh progress bar at every iteration because it's slow
337+
if (showProgress && cellIdx++ % freq == 0) // Don't refresh progress bar at every iteration because it's slow
338338
{
339339
if (EditorUtility.DisplayCancelableProgressBar("Generating Probe Volume Bricks", $"Processing cell {cellIdx} out of {ctx.cells.Count}", Mathf.Lerp(progress0, progress1, cellIdx / (float)ctx.cells.Count)))
340340
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void UpdateRealtimeSubdivisionDebug()
5353
if (s_CurrentSubdivision == null)
5454
{
5555
// Start a new Subdivision
56-
s_CurrentSubdivision = Subdivide();
56+
s_CurrentSubdivision = Subdivide(showProgress: false);
5757
}
5858

5959
// Step the subdivision with the amount of cell per frame in debug menu
@@ -71,7 +71,7 @@ static void UpdateRealtimeSubdivisionDebug()
7171
}
7272
}
7373

74-
IEnumerator Subdivide()
74+
IEnumerator Subdivide(bool showProgress)
7575
{
7676
var ctx = AdaptiveProbeVolumes.PrepareProbeSubdivisionContext(true);
7777
var contributors = GIContributors.Find(GIContributors.ContributorFilter.All);
@@ -115,7 +115,7 @@ IEnumerator Subdivide()
115115
ctx.cells.Add(cell);
116116

117117
bool canceledByUser = false;
118-
var result = AdaptiveProbeVolumes.BakeBricks(ctx, contributors, ref canceledByUser);
118+
var result = AdaptiveProbeVolumes.BakeBricks(ctx, contributors, showProgress, ref canceledByUser);
119119

120120
if (result.cells.Count != 0)
121121
ProbeReferenceVolume.instance.realtimeSubdivisionInfo[cell.bounds] = result.cells[0].bricks;

Packages/com.unity.render-pipelines.core/Editor/PostProcessing/LensFlareDataSRPEditor.cs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ void DrawSummary(Rect summaryRect, SerializedProperty element, int index)
760760
{
761761
SerializedProperty lensFlareDataSRP = element.FindPropertyRelative("lensFlareDataSRP");
762762
fieldRect.MoveNext();
763-
EditorGUI.PropertyField(fieldRect.Current, lensFlareDataSRP, Styles.lensFlareDataSRP);
763+
DrawLensFlareDataSRPFieldWithCycleDetection(fieldRect.Current, lensFlareDataSRP, Styles.lensFlareDataSRP);
764764
EditorGUIUtility.labelWidth = oldLabelWidth;
765765
return;
766766
}
@@ -918,7 +918,7 @@ void DrawTypeCathegory(ref Rect remainingRect, SerializedProperty element)
918918
{
919919
SerializedProperty lensFlareDataSRP = element.FindPropertyRelative("lensFlareDataSRP");
920920
fieldRect.MoveNext();
921-
EditorGUI.PropertyField(fieldRect.Current, lensFlareDataSRP, Styles.lensFlareDataSRP);
921+
DrawLensFlareDataSRPFieldWithCycleDetection(fieldRect.Current, lensFlareDataSRP, Styles.lensFlareDataSRP);
922922
}
923923
break;
924924
}
@@ -1247,6 +1247,67 @@ T GetEnum<T>(SerializedProperty property)
12471247

12481248
void SetEnum<T>(SerializedProperty property, T value)
12491249
=> property.intValue = (int)(object)value;
1250+
1251+
void DrawLensFlareDataSRPFieldWithCycleDetection(Rect rect, SerializedProperty lensFlareDataSRPProperty, GUIContent label)
1252+
{
1253+
LensFlareDataSRP currentAsset = target as LensFlareDataSRP;
1254+
1255+
EditorGUI.BeginChangeCheck();
1256+
LensFlareDataSRP newValue = EditorGUI.ObjectField(rect, label, lensFlareDataSRPProperty.objectReferenceValue, typeof(LensFlareDataSRP), false) as LensFlareDataSRP;
1257+
1258+
if (EditorGUI.EndChangeCheck())
1259+
{
1260+
// Check for cycles before setting the value
1261+
bool wouldCreateCycle = false;
1262+
1263+
if (newValue != null && currentAsset != null)
1264+
{
1265+
// Direct self-reference check
1266+
if (currentAsset == newValue)
1267+
{
1268+
wouldCreateCycle = true;
1269+
}
1270+
else
1271+
{
1272+
// Multi-level cycle check - see if newValue already references currentAsset
1273+
HashSet<LensFlareDataSRP> visited = new HashSet<LensFlareDataSRP>();
1274+
1275+
// Recursive function to check if targetAsset is found in asset's dependency chain
1276+
bool CheckCycle(LensFlareDataSRP asset, LensFlareDataSRP targetAsset)
1277+
{
1278+
if (asset == null || visited.Contains(asset))
1279+
return false;
1280+
1281+
visited.Add(asset);
1282+
1283+
foreach (var element in asset.elements)
1284+
{
1285+
if (element.flareType == SRPLensFlareType.LensFlareDataSRP && element.lensFlareDataSRP != null)
1286+
{
1287+
if (element.lensFlareDataSRP == targetAsset || CheckCycle(element.lensFlareDataSRP, targetAsset))
1288+
return true;
1289+
}
1290+
}
1291+
return false;
1292+
}
1293+
1294+
wouldCreateCycle = CheckCycle(newValue, currentAsset);
1295+
}
1296+
}
1297+
1298+
if (wouldCreateCycle)
1299+
{
1300+
// Cycle detected - set to null and show a warning
1301+
lensFlareDataSRPProperty.objectReferenceValue = null;
1302+
Debug.LogWarning($"Cannot assign lens flare asset '{newValue.name}' because it would create a cyclic dependency. Setting to null to prevent infinite loop.");
1303+
}
1304+
else
1305+
{
1306+
lensFlareDataSRPProperty.objectReferenceValue = newValue;
1307+
}
1308+
}
1309+
}
1310+
12501311
#endregion
12511312
}
12521313
}

Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceCuller.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ unsafe public void Execute()
848848
allocInfo.drawCount = outIndirectCommandIndex;
849849
allocInfo.instanceCount = outIndirectVisibleInstanceIndex;
850850

851-
int drawAllocCount = allocInfo.drawCount + IndirectBufferContextStorage.kExtraDrawAllocationCount;
851+
int drawAllocCount = allocInfo.drawCount;
852852
int drawAllocEnd = Interlocked.Add(ref UnsafeUtility.AsRef<int>(allocCounters + (int)IndirectAllocator.NextDrawIndex), drawAllocCount);
853853
allocInfo.drawAllocIndex = drawAllocEnd - drawAllocCount;
854854

@@ -1758,6 +1758,7 @@ private static class ShaderIDs
17581758
public static readonly int InstanceOcclusionCullerShaderVariables = Shader.PropertyToID("InstanceOcclusionCullerShaderVariables");
17591759
public static readonly int _DrawInfo = Shader.PropertyToID("_DrawInfo");
17601760
public static readonly int _InstanceInfo = Shader.PropertyToID("_InstanceInfo");
1761+
public static readonly int _DispatchArgs = Shader.PropertyToID("_DispatchArgs");
17611762
public static readonly int _DrawArgs = Shader.PropertyToID("_DrawArgs");
17621763
public static readonly int _InstanceIndices = Shader.PropertyToID("_InstanceIndices");
17631764
public static readonly int _InstanceDataBuffer = Shader.PropertyToID("_InstanceDataBuffer");
@@ -2091,7 +2092,7 @@ public unsafe JobHandle CreateCullJobTree(
20912092
cullingOutput = cullingOutput.drawCommands,
20922093
indirectBufferLimits = indirectBufferLimits,
20932094
visibleInstancesBufferHandle = m_IndirectStorage.visibleInstanceBufferHandle,
2094-
indirectArgsBufferHandle = m_IndirectStorage.indirectArgsBufferHandle,
2095+
indirectArgsBufferHandle = m_IndirectStorage.indirectDrawArgsBufferHandle,
20952096
indirectBufferAllocInfo = indirectBufferAllocInfo,
20962097
indirectInstanceInfoGlobalArray = m_IndirectStorage.instanceInfoGlobalArray,
20972098
indirectDrawInfoGlobalArray = m_IndirectStorage.drawInfoGlobalArray,
@@ -2386,7 +2387,7 @@ internal void EnsureValidOcclusionTestResults(int viewInstanceID)
23862387
int kernel = m_CopyInstancesKernel;
23872388
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawInfo, m_IndirectStorage.drawInfoBuffer);
23882389
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._InstanceInfo, m_IndirectStorage.instanceInfoBuffer);
2389-
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawArgs, m_IndirectStorage.argsBuffer);
2390+
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawArgs, m_IndirectStorage.drawArgsBuffer);
23902391
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._InstanceIndices, m_IndirectStorage.instanceBuffer);
23912392

23922393
cmd.DispatchCompute(cs, kernel, (allocInfo.instanceCount + 63) / 64, 1, 1);
@@ -2539,10 +2540,10 @@ private void AddOcclusionCullingDispatch(
25392540
if (doCopyInstances)
25402541
{
25412542
int kernel = m_CopyInstancesKernel;
2542-
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawInfo, m_IndirectStorage.drawInfoBuffer);
2543-
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._InstanceInfo, m_IndirectStorage.instanceInfoBuffer);
2544-
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawArgs, m_IndirectStorage.argsBuffer);
2545-
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._InstanceIndices, m_IndirectStorage.instanceBuffer);
2543+
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawInfo, bufferHandles.drawInfoBuffer);
2544+
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._InstanceInfo, bufferHandles.instanceInfoBuffer);
2545+
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawArgs, bufferHandles.drawArgsBuffer);
2546+
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._InstanceIndices, bufferHandles.instanceBuffer);
25462547

25472548
cmd.DispatchCompute(cs, kernel, (allocInfo.instanceCount + 63) / 64, 1, 1);
25482549
}
@@ -2551,7 +2552,10 @@ private void AddOcclusionCullingDispatch(
25512552
{
25522553
int kernel = m_ResetDrawArgsKernel;
25532554
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawInfo, bufferHandles.drawInfoBuffer);
2554-
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawArgs, bufferHandles.argsBuffer);
2555+
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawArgs, bufferHandles.drawArgsBuffer);
2556+
if (isSecondPass)
2557+
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DispatchArgs, bufferHandles.dispatchArgsBuffer);
2558+
25552559
cmd.DispatchCompute(cs, kernel, (allocInfo.drawCount + 63) / 64, 1, 1);
25562560
}
25572561

@@ -2560,7 +2564,7 @@ private void AddOcclusionCullingDispatch(
25602564
int kernel = m_CullInstancesKernel;
25612565
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawInfo, bufferHandles.drawInfoBuffer);
25622566
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._InstanceInfo, bufferHandles.instanceInfoBuffer);
2563-
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawArgs, bufferHandles.argsBuffer);
2567+
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._DrawArgs, bufferHandles.drawArgsBuffer);
25642568
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._InstanceIndices, bufferHandles.instanceBuffer);
25652569
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._InstanceDataBuffer, batchersContext.gpuInstanceDataBuffer);
25662570
cmd.SetComputeBufferParam(cs, kernel, ShaderIDs._OcclusionDebugCounters, m_OcclusionEventDebugArray.CounterBuffer);
@@ -2572,7 +2576,7 @@ private void AddOcclusionCullingDispatch(
25722576
OcclusionCullingCommon.SetDebugPyramid(cmd, m_OcclusionTestShader, kernel, occluderHandles);
25732577

25742578
if (isSecondPass)
2575-
cmd.DispatchCompute(cs, kernel, bufferHandles.argsBuffer, (uint)(GraphicsBuffer.IndirectDrawIndexedArgs.size * allocInfo.GetExtraDrawInfoSlotIndex()));
2579+
cmd.DispatchCompute(cs, kernel, bufferHandles.dispatchArgsBuffer, 0);
25762580
else
25772581
cmd.DispatchCompute(cs, kernel, (allocInfo.instanceCount + 63) / 64, 1, 1);
25782582
}
@@ -2610,6 +2614,7 @@ private void OnEndSceneViewCameraRendering()
26102614

26112615
public void UpdateFrame(int cameraCount)
26122616
{
2617+
DisposeSceneViewHiddenBits();
26132618
DisposeCompactVisibilityMasks();
26142619
if (cameraCount > m_LODParamsToCameraID.Capacity)
26152620
m_LODParamsToCameraID.Capacity = cameraCount;

Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/InstanceOcclusionCuller.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -560,22 +560,23 @@ internal struct IndirectBufferContextHandles
560560
{
561561
public BufferHandle instanceBuffer;
562562
public BufferHandle instanceInfoBuffer;
563-
public BufferHandle argsBuffer;
563+
public BufferHandle dispatchArgsBuffer;
564+
public BufferHandle drawArgsBuffer;
564565
public BufferHandle drawInfoBuffer;
565566

566567
public void UseForOcclusionTest(IBaseRenderGraphBuilder builder)
567568
{
568569
instanceBuffer = builder.UseBuffer(instanceBuffer, AccessFlags.ReadWrite);
569570
instanceInfoBuffer = builder.UseBuffer(instanceInfoBuffer, AccessFlags.Read);
570-
argsBuffer = builder.UseBuffer(argsBuffer, AccessFlags.ReadWrite);
571+
dispatchArgsBuffer = builder.UseBuffer(dispatchArgsBuffer, AccessFlags.ReadWrite);
572+
drawArgsBuffer = builder.UseBuffer(drawArgsBuffer, AccessFlags.ReadWrite);
571573
drawInfoBuffer = builder.UseBuffer(drawInfoBuffer, AccessFlags.Read);
572574
}
573575
}
574576

575577
internal struct IndirectBufferContextStorage : IDisposable
576578
{
577579
private const int kAllocatorCount = (int)IndirectAllocator.Count;
578-
internal const int kExtraDrawAllocationCount = 1; // over-allocate by one for indirect args scratch space GPU-side
579580
internal const int kInstanceInfoGpuOffsetMultiplier = 2; // GPU side allocates storage for extra copy of instance list
580581

581582
private IndirectBufferLimits m_BufferLimits;
@@ -584,7 +585,8 @@ internal struct IndirectBufferContextStorage : IDisposable
584585
private GraphicsBuffer m_InstanceInfoBuffer;
585586
private NativeArray<IndirectInstanceInfo> m_InstanceInfoStaging;
586587

587-
private GraphicsBuffer m_ArgsBuffer;
588+
private GraphicsBuffer m_DispatchArgsBuffer;
589+
private GraphicsBuffer m_DrawArgsBuffer;
588590
private GraphicsBuffer m_DrawInfoBuffer;
589591
private NativeArray<IndirectDrawInfo> m_DrawInfoStaging;
590592

@@ -596,19 +598,21 @@ internal struct IndirectBufferContextStorage : IDisposable
596598

597599
public GraphicsBuffer instanceBuffer { get { return m_InstanceBuffer; } }
598600
public GraphicsBuffer instanceInfoBuffer { get { return m_InstanceInfoBuffer; } }
599-
public GraphicsBuffer argsBuffer { get { return m_ArgsBuffer; } }
601+
public GraphicsBuffer dispatchArgsBuffer { get { return m_DispatchArgsBuffer; } }
602+
public GraphicsBuffer drawArgsBuffer { get { return m_DrawArgsBuffer; } }
600603
public GraphicsBuffer drawInfoBuffer { get { return m_DrawInfoBuffer; } }
601604

602605
public GraphicsBufferHandle visibleInstanceBufferHandle { get { return m_InstanceBuffer.bufferHandle; } }
603-
public GraphicsBufferHandle indirectArgsBufferHandle { get { return m_ArgsBuffer.bufferHandle; } }
606+
public GraphicsBufferHandle indirectDrawArgsBufferHandle { get { return m_DrawArgsBuffer.bufferHandle; } }
604607

605608
public IndirectBufferContextHandles ImportBuffers(RenderGraph renderGraph)
606609
{
607610
return new IndirectBufferContextHandles()
608611
{
609612
instanceBuffer = renderGraph.ImportBuffer(m_InstanceBuffer),
610613
instanceInfoBuffer = renderGraph.ImportBuffer(m_InstanceInfoBuffer),
611-
argsBuffer = renderGraph.ImportBuffer(m_ArgsBuffer),
614+
dispatchArgsBuffer = renderGraph.ImportBuffer(m_DispatchArgsBuffer),
615+
drawArgsBuffer = renderGraph.ImportBuffer(m_DrawArgsBuffer),
612616
drawInfoBuffer = renderGraph.ImportBuffer(m_DrawInfoBuffer),
613617
};
614618
}
@@ -653,15 +657,18 @@ void FreeInstanceBuffers()
653657

654658
void AllocateDrawBuffers(int maxDrawCount)
655659
{
656-
m_ArgsBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured | GraphicsBuffer.Target.IndirectArguments, (maxDrawCount + kExtraDrawAllocationCount) * (GraphicsBuffer.IndirectDrawIndexedArgs.size / sizeof(int)), sizeof(int));
660+
// Compute dispatch arguments are number of thread groups in X,Y and Z dimensions, hence 3 integers for the size.
661+
m_DispatchArgsBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured | GraphicsBuffer.Target.IndirectArguments, 3, sizeof(int));
662+
m_DrawArgsBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured | GraphicsBuffer.Target.IndirectArguments, maxDrawCount * (GraphicsBuffer.IndirectDrawIndexedArgs.size / sizeof(int)), sizeof(int));
657663
m_DrawInfoBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, maxDrawCount, System.Runtime.InteropServices.Marshal.SizeOf<IndirectDrawInfo>());
658664
m_DrawInfoStaging = new NativeArray<IndirectDrawInfo>(maxDrawCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
659665
m_BufferLimits.maxDrawCount = maxDrawCount;
660666
}
661667

662668
void FreeDrawBuffers()
663669
{
664-
m_ArgsBuffer.Release();
670+
m_DispatchArgsBuffer.Release();
671+
m_DrawArgsBuffer.Release();
665672
m_DrawInfoBuffer.Release();
666673
m_DrawInfoStaging.Dispose();
667674
m_BufferLimits.maxDrawCount = 0;

0 commit comments

Comments
 (0)