Skip to content

Commit 092df02

Browse files
amsXYZEvergreen
authored andcommitted
GPUDrivenProcessor: Main-thread material indirect-support collection.
This PR fixes indirect-support collection for Materials, which was happening over multiple-threads instead of in the main-thread (spamming failed assertions in Debug editors), and introduces `GPUDrivenPackedMaterialData` to simplify material-data being passed by `GPUDrivenProcessor` between the engine/scripting sides.
1 parent 28934f1 commit 092df02

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,21 @@ public void ProcessRenderer(int i)
424424
overridenComponents |= InstanceComponentGroup.Lightmap;
425425
}
426426

427+
// Scan all materials once to retrieve whether this renderer is indirect-compatible or not (and store it in the RangeKey).
428+
var supportsIndirect = true;
429+
for (int matIndex = 0; matIndex < materialsCount; ++matIndex)
430+
{
431+
if (matIndex >= submeshCount)
432+
{
433+
Debug.LogWarning("Material count in the shared material list is higher than sub mesh count for the mesh. Object may be corrupted.");
434+
continue;
435+
}
436+
437+
var materialIndex = rendererData.materialIndex[materialsOffset + matIndex];
438+
var packedMaterialData = rendererData.packedMaterialData[materialIndex];
439+
supportsIndirect &= packedMaterialData.isIndirectSupported;
440+
}
441+
427442
var rangeKey = new RangeKey
428443
{
429444
layer = (byte)gameObjectLayer,
@@ -432,7 +447,7 @@ public void ProcessRenderer(int i)
432447
shadowCastingMode = packedRendererData.shadowCastingMode,
433448
staticShadowCaster = packedRendererData.staticShadowCaster,
434449
rendererPriority = rendererPriority,
435-
supportsIndirect = packedRendererData.supportsIndirect,
450+
supportsIndirect = supportsIndirect
436451
};
437452

438453
ref DrawRange drawRange = ref EditDrawRange(rangeKey);
@@ -447,8 +462,7 @@ public void ProcessRenderer(int i)
447462

448463
var materialIndex = rendererData.materialIndex[materialsOffset + matIndex];
449464
var materialID = rendererData.materialID[materialIndex];
450-
var isTransparent = rendererData.isTransparent[materialIndex];
451-
var isMotionVectorsPassEnabled = rendererData.isMotionVectorsPassEnabled[materialIndex];
465+
var packedMaterialData = rendererData.packedMaterialData[materialIndex];
452466

453467
if (rendererToMaterialMap.TryGetValue(new LightmapManager.RendererSubmeshPair(rendererGroupID, matIndex), out var cachedMaterialID))
454468
materialID = cachedMaterialID;
@@ -467,10 +481,10 @@ public void ProcessRenderer(int i)
467481

468482
// assume that a custom motion vectors pass contains deformation motion, so should always output motion vectors
469483
// (otherwise this flag is set dynamically during culling only when the transform is changing)
470-
if (isMotionVectorsPassEnabled)
484+
if (packedMaterialData.isMotionVectorsPassEnabled)
471485
flags |= BatchDrawCommandFlags.HasMotion;
472486

473-
if (isTransparent)
487+
if (packedMaterialData.isTransparent)
474488
flags |= BatchDrawCommandFlags.HasSortingPosition;
475489

476490
// Let the engine know if we've opted out of lightmap texture arrays
@@ -487,7 +501,7 @@ public void ProcessRenderer(int i)
487501
meshID = batchMeshID,
488502
submeshIndex = submeshIndex,
489503
flags = flags,
490-
transparentInstanceId = isTransparent ? rendererGroupID : 0,
504+
transparentInstanceId = packedMaterialData.isTransparent ? rendererGroupID : 0,
491505
range = rangeKey,
492506
overridenComponents = (uint)overridenComponents,
493507
// When we've opted out of lightmap texture arrays, we

0 commit comments

Comments
 (0)