Skip to content

Commit a7cc9a1

Browse files
alekseiunityEvergreen
authored andcommitted
Graphics/gpudriven prefab mode fix uum 62427
Fixes: Tier0 not working correctly in prefab mode and LODGroup selection visibility not working correctly. https://jira.unity3d.com/browse/UUM-62427
1 parent a2792de commit a7cc9a1

File tree

11 files changed

+439
-252
lines changed

11 files changed

+439
-252
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ namespace UnityEngine.Rendering
1212
{
1313
internal partial class GPUResidentBatcher : IDisposable
1414
{
15+
private ParallelBitArray m_ProcessedThisFrameTreeBits;
16+
1517
private void ProcessTrees()
1618
{
1719
int treeInstancesCount = m_BatchersContext.GetAliveInstancesOfType(InstanceType.SpeedTree);
1820

1921
if (treeInstancesCount == 0)
2022
return;
2123

24+
ParallelBitArray compactedVisibilityMasks = m_InstanceCullingBatcher.GetCompactedVisibilityMasks(syncCullingJobs: false);
25+
26+
if (!compactedVisibilityMasks.IsCreated)
27+
return;
28+
2229
Profiler.BeginSample("GPUResidentInstanceBatcher.ProcessTrees");
2330

2431
int maxInstancesCount = m_BatchersContext.aliveInstances.Length;
@@ -32,9 +39,6 @@ private void ProcessTrees()
3239
var visibleTreeRendererIDs = new NativeList<int>(Allocator.TempJob);
3340
var visibleTreeInstances = new NativeList<InstanceHandle>(Allocator.TempJob);
3441

35-
ParallelBitArray compactedVisibilityMasks = m_InstanceCullingBatcher.GetCompactedVisibilityMasks(syncCullingJobs: false);
36-
Assert.IsTrue(compactedVisibilityMasks.IsCreated);
37-
3842
m_BatchersContext.GetVisibleTreeInstances(compactedVisibilityMasks, m_ProcessedThisFrameTreeBits, visibleTreeRendererIDs, visibleTreeInstances,
3943
becomeVisibleOnly, out var becomeVisibleTreeInstancesCount);
4044

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ internal partial class GPUResidentBatcher : IDisposable
2121

2222
private InstanceCullingBatcher m_InstanceCullingBatcher = null;
2323

24-
private ParallelBitArray m_ProcessedThisFrameTreeBits;
25-
2624
public GPUResidentBatcher(
2725
RenderersBatchersContext batcherContext,
2826
InstanceCullingBatcherDesc instanceCullerBatcherDesc,
@@ -112,6 +110,16 @@ public void UpdateRenderers(NativeArray<int> renderersID)
112110
m_GPUDrivenProcessor.enablePartialRendering = false;
113111
}
114112

113+
#if UNITY_EDITOR
114+
public void UpdateSelectedRenderers(NativeArray<int> renderersID)
115+
{
116+
var instances = new NativeArray<InstanceHandle>(renderersID.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
117+
m_BatchersContext.ScheduleQueryRendererGroupInstancesJob(renderersID, instances).Complete();
118+
m_BatchersContext.UpdateSelectedInstances(instances);
119+
instances.Dispose();
120+
}
121+
#endif
122+
115123
public void PostCullBeginCameraRendering(RenderRequestBatcherContext context)
116124
{
117125
RenderSettings.ambientProbe = context.ambientProbe;
@@ -126,9 +134,6 @@ private void UpdateRendererData(in GPUDrivenRendererGroupData rendererData, ILis
126134

127135
Profiler.BeginSample("GPUResidentInstanceBatcher.UpdateRendererData");
128136
{
129-
var usedMaterialIDs = new NativeList<int>(Allocator.TempJob);
130-
usedMaterialIDs.AddRange(rendererData.materialID);
131-
132137
// --------------------------------------------------------------------------------------------------------------------------------------
133138
// Allocate and Update CPU instance data
134139
// --------------------------------------------------------------------------------------------------------------------------------------
@@ -166,15 +171,14 @@ private void UpdateRendererData(in GPUDrivenRendererGroupData rendererData, ILis
166171
{
167172
m_InstanceCullingBatcher.BuildBatch(
168173
instances,
169-
usedMaterialIDs.AsArray(),
174+
rendererData.materialID,
170175
rendererData.meshID,
171176
rendererData);
172177

173178
}
174179
Profiler.EndSample();
175180

176181
instances.Dispose();
177-
usedMaterialIDs.Dispose();
178182
}
179183
Profiler.EndSample();
180184
}

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ private static void Recreate(GPUResidentDrawerSettings settings)
383383
private NativeList<int> m_FrameCameraIDs;
384384
private bool m_FrameUpdateNeeded = false;
385385

386+
private bool m_SelectionChanged;
387+
386388
static GPUResidentDrawer()
387389
{
388390
Lightmapping.bakeCompleted += Reinitialize;
@@ -437,7 +439,6 @@ private GPUResidentDrawer(GPUResidentDrawerSettings settings, int maxInstanceCou
437439

438440
m_Dispatcher = new ObjectDispatcher();
439441
m_Dispatcher.EnableTypeTracking<LODGroup>(TypeTrackingFlags.SceneObjects);
440-
m_Dispatcher.EnableTypeTracking<LightmapSettings>();
441442
m_Dispatcher.EnableTypeTracking<Mesh>();
442443
m_Dispatcher.EnableTypeTracking<Material>();
443444
m_Dispatcher.EnableTransformTracking<LODGroup>(TransformTrackingType.GlobalTRS);
@@ -454,6 +455,9 @@ private GPUResidentDrawer(GPUResidentDrawerSettings settings, int maxInstanceCou
454455
RenderPipelineManager.endContextRendering += OnEndContextRendering;
455456
RenderPipelineManager.beginCameraRendering += OnBeginCameraRendering;
456457
RenderPipelineManager.endCameraRendering += OnEndCameraRendering;
458+
#if UNITY_EDITOR
459+
Selection.selectionChanged += OnSelectionChanged;
460+
#endif
457461

458462
// GPU Resident Drawer only supports legacy lightmap binding.
459463
// Accordingly, we set the keyword globally across all shaders.
@@ -478,6 +482,9 @@ private void Dispose()
478482
RenderPipelineManager.endContextRendering -= OnEndContextRendering;
479483
RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
480484
RenderPipelineManager.endCameraRendering -= OnEndCameraRendering;
485+
#if UNITY_EDITOR
486+
Selection.selectionChanged -= OnSelectionChanged;
487+
#endif
481488

482489
RemoveFromPlayerLoop();
483490

@@ -513,6 +520,7 @@ private void OnBeginContextRendering(ScriptableRenderContext context, List<Camer
513520
{
514521
if (s_Instance is null)
515522
return;
523+
516524
#if UNITY_EDITOR
517525
EditorFrameUpdate(cameras);
518526
#endif
@@ -545,8 +553,35 @@ private void EditorFrameUpdate(List<Camera> cameras)
545553
else
546554
m_FrameUpdateNeeded = true;
547555
}
556+
557+
ProcessSelection();
558+
}
559+
560+
private void OnSelectionChanged()
561+
{
562+
m_SelectionChanged = true;
563+
}
564+
565+
private void ProcessSelection()
566+
{
567+
if(!m_SelectionChanged)
568+
return;
569+
570+
m_SelectionChanged = false;
571+
572+
Object[] renderers = Selection.GetFiltered(typeof(MeshRenderer), SelectionMode.Deep);
573+
574+
var rendererIDs = new NativeArray<int>(renderers.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
575+
576+
for (int i = 0; i < renderers.Length; ++i)
577+
rendererIDs[i] = renderers[i] ? renderers[i].GetInstanceID() : 0;
578+
579+
m_Batcher.UpdateSelectedRenderers(rendererIDs);
580+
581+
rendererIDs.Dispose();
548582
}
549583
#endif
584+
550585
private void OnEndContextRendering(ScriptableRenderContext context, List<Camera> cameras)
551586
{
552587
if (s_Instance is null)

0 commit comments

Comments
 (0)