Cull daemon render groups through shared queries
This commit is contained in:
parent
7643f64278
commit
dd21162ece
3 changed files with 212 additions and 1 deletions
|
|
@ -1783,6 +1783,11 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
? File.ReadAllText(packageSnapshotPath)
|
||||
: throw new InvalidOperationException("Cannot verify daemon render query authority; package snapshot documents are missing.");
|
||||
|
||||
var indirectRendererPath = Path.Combine(root, "Assets", "Scripts", "Gameplay", "AetheriaDaemonIndirectRenderer.cs");
|
||||
var indirectRenderer = File.Exists(indirectRendererPath)
|
||||
? File.ReadAllText(indirectRendererPath)
|
||||
: throw new InvalidOperationException("Cannot verify daemon render query authority; AetheriaDaemonIndirectRenderer.cs is missing.");
|
||||
|
||||
var canonicalSnapshotPath = Path.Combine(root, "Aetheria.State", "Documents", "AetheriaRuntimeStateDocuments.cs");
|
||||
var canonicalSnapshot = File.Exists(canonicalSnapshotPath)
|
||||
? File.ReadAllText(canonicalSnapshotPath)
|
||||
|
|
@ -1836,6 +1841,23 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"Daemon body snapshots must publish resolved gravity influence fields so render clients do not reconstruct Unity gravity state: " +
|
||||
string.Join("; ", missingSnapshotSymbols));
|
||||
}
|
||||
|
||||
var requiredRendererSymbols = new[]
|
||||
{
|
||||
"private readonly List<AetheriaRuntimeDaemonRenderGroupDocument> _visibleRenderGroups",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryRenderGroups(",
|
||||
"TryGetCameraQueryBounds(out var min, out var max)",
|
||||
"return index.RenderGroups;"
|
||||
};
|
||||
var missingRendererSymbols = requiredRendererSymbols
|
||||
.Where(symbol => !indirectRenderer.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (missingRendererSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Unity's daemon indirect renderer must query daemon SoA render groups by camera bounds before lowering draw calls: " +
|
||||
string.Join(", ", missingRendererSymbols));
|
||||
}
|
||||
}
|
||||
|
||||
static void RequireTypedZoneConstructionKeys(string root)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ public sealed class AetheriaDaemonIndirectRenderer : MonoBehaviour
|
|||
new Dictionary<int, AetheriaDaemonRenderGroupBatch>();
|
||||
private readonly HashSet<int> _seenGroupIds = new HashSet<int>();
|
||||
private readonly List<int> _staleGroupIds = new List<int>();
|
||||
private readonly List<AetheriaRuntimeDaemonRenderGroupDocument> _visibleRenderGroups =
|
||||
new List<AetheriaRuntimeDaemonRenderGroupDocument>();
|
||||
private readonly Vector3[] _frustumCorners = new Vector3[8];
|
||||
private static readonly int MatrixBufferPropertyId =
|
||||
Shader.PropertyToID(AetheriaDaemonRenderBuffer.MatrixBufferPropertyName);
|
||||
private static readonly int InstanceCountPropertyId =
|
||||
|
|
@ -60,7 +63,8 @@ public sealed class AetheriaDaemonIndirectRenderer : MonoBehaviour
|
|||
var index = observer.LastSoaIndex;
|
||||
var view = observer.LastRenderNativeView;
|
||||
_seenGroupIds.Clear();
|
||||
foreach (var renderGroup in index.RenderGroups)
|
||||
var renderGroups = QueryRenderGroups(index);
|
||||
foreach (var renderGroup in renderGroups)
|
||||
{
|
||||
_seenGroupIds.Add(renderGroup.GroupId);
|
||||
if (!assetCatalog.TryResolveMesh(renderGroup.MeshKey, out var mesh) ||
|
||||
|
|
@ -117,6 +121,58 @@ public sealed class AetheriaDaemonIndirectRenderer : MonoBehaviour
|
|||
return drewAny;
|
||||
}
|
||||
|
||||
private IReadOnlyList<AetheriaRuntimeDaemonRenderGroupDocument> QueryRenderGroups(
|
||||
AetheriaRuntimeDaemonSoaViewIndex index)
|
||||
{
|
||||
if (!TryGetCameraQueryBounds(out var min, out var max))
|
||||
{
|
||||
return index.RenderGroups;
|
||||
}
|
||||
|
||||
AetheriaRuntimeDaemonRenderQueries.QueryRenderGroups(
|
||||
index,
|
||||
min.x,
|
||||
min.y,
|
||||
min.z,
|
||||
max.x,
|
||||
max.y,
|
||||
max.z,
|
||||
_visibleRenderGroups);
|
||||
return _visibleRenderGroups;
|
||||
}
|
||||
|
||||
private bool TryGetCameraQueryBounds(out Vector3 min, out Vector3 max)
|
||||
{
|
||||
var camera = targetCamera != null ? targetCamera : Camera.main;
|
||||
if (camera == null || !camera.enabled)
|
||||
{
|
||||
min = default;
|
||||
max = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var near = Mathf.Max(0.0f, camera.nearClipPlane);
|
||||
var far = Mathf.Max(near, camera.farClipPlane);
|
||||
_frustumCorners[0] = camera.ViewportToWorldPoint(new Vector3(0, 0, near));
|
||||
_frustumCorners[1] = camera.ViewportToWorldPoint(new Vector3(1, 0, near));
|
||||
_frustumCorners[2] = camera.ViewportToWorldPoint(new Vector3(0, 1, near));
|
||||
_frustumCorners[3] = camera.ViewportToWorldPoint(new Vector3(1, 1, near));
|
||||
_frustumCorners[4] = camera.ViewportToWorldPoint(new Vector3(0, 0, far));
|
||||
_frustumCorners[5] = camera.ViewportToWorldPoint(new Vector3(1, 0, far));
|
||||
_frustumCorners[6] = camera.ViewportToWorldPoint(new Vector3(0, 1, far));
|
||||
_frustumCorners[7] = camera.ViewportToWorldPoint(new Vector3(1, 1, far));
|
||||
|
||||
min = _frustumCorners[0];
|
||||
max = _frustumCorners[0];
|
||||
for (var i = 1; i < _frustumCorners.Length; i++)
|
||||
{
|
||||
min = Vector3.Min(min, _frustumCorners[i]);
|
||||
max = Vector3.Max(max, _frustumCorners[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Bounds GetDrawBounds(AetheriaRuntimeDaemonRenderGroupDocument renderGroup)
|
||||
{
|
||||
return new Bounds(
|
||||
|
|
|
|||
|
|
@ -590,6 +590,139 @@ public class DaemonRuntimeDocumentTests
|
|||
Assert.AreEqual(2, renderGroup.Lod);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonRenderQueriesFilterRenderGroupsByBounds()
|
||||
{
|
||||
var view = AetheriaRuntimeDaemonSoaViewDocument.Create(
|
||||
"aetheria-daemon",
|
||||
"session-render-query",
|
||||
130,
|
||||
131,
|
||||
new[]
|
||||
{
|
||||
new AetheriaRuntimeDaemonSoaBufferDocument
|
||||
{
|
||||
BufferId = "render-hot",
|
||||
ByteLength = 128
|
||||
}
|
||||
},
|
||||
new[]
|
||||
{
|
||||
new AetheriaRuntimeDaemonSoaColumnDocument
|
||||
{
|
||||
ColumnId = "render-group-id",
|
||||
Kind = AetheriaRuntimeDaemonSoaColumnKinds.RenderGroupId,
|
||||
BufferId = "render-hot",
|
||||
ScalarType = "uint32",
|
||||
ElementStride = 4,
|
||||
ElementCount = 16
|
||||
}
|
||||
},
|
||||
renderGroups: new[]
|
||||
{
|
||||
new AetheriaRuntimeDaemonRenderGroupDocument
|
||||
{
|
||||
GroupId = 1,
|
||||
MeshKey = "ships/djinni",
|
||||
MaterialKey = "materials/ships/hull",
|
||||
BoundsCenterX = 0,
|
||||
BoundsCenterY = 0,
|
||||
BoundsCenterZ = 0,
|
||||
BoundsSizeX = 8,
|
||||
BoundsSizeY = 8,
|
||||
BoundsSizeZ = 8
|
||||
},
|
||||
new AetheriaRuntimeDaemonRenderGroupDocument
|
||||
{
|
||||
GroupId = 2,
|
||||
MeshKey = "ships/far",
|
||||
MaterialKey = "materials/ships/hull",
|
||||
BoundsCenterX = 100,
|
||||
BoundsCenterY = 0,
|
||||
BoundsCenterZ = 0,
|
||||
BoundsSizeX = 8,
|
||||
BoundsSizeY = 8,
|
||||
BoundsSizeZ = 8
|
||||
}
|
||||
});
|
||||
|
||||
var index = AetheriaRuntimeDaemonSoaViewIndex.Build(view);
|
||||
var groups = new List<AetheriaRuntimeDaemonRenderGroupDocument>();
|
||||
var count = AetheriaRuntimeDaemonRenderQueries.QueryRenderGroups(
|
||||
index,
|
||||
-10,
|
||||
-10,
|
||||
-10,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
groups);
|
||||
|
||||
Assert.AreEqual(1, count);
|
||||
Assert.AreEqual(1, groups.Count);
|
||||
Assert.AreEqual(1, groups[0].GroupId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonRenderQueriesFilterGravityInfluencesByXzViewport()
|
||||
{
|
||||
var zone = new AetheriaRuntimeZoneSnapshotCommit
|
||||
{
|
||||
ZoneIndex = 0,
|
||||
Bodies = new[]
|
||||
{
|
||||
new AetheriaRuntimeBodySnapshotCommit
|
||||
{
|
||||
BodyKey = "body:near",
|
||||
OrbitKey = "orbit:near",
|
||||
Kind = "gas_giant",
|
||||
GravityInfluenceCenterX = 4,
|
||||
GravityInfluenceCenterZ = 0,
|
||||
GravityInfluenceRadius = 6,
|
||||
GravityWellDepth = 20,
|
||||
GravityDepthExponent = 12,
|
||||
GravityWaveRadius = 9,
|
||||
GravityWaveDepth = 3,
|
||||
GravityWaveSpeed = 2
|
||||
},
|
||||
new AetheriaRuntimeBodySnapshotCommit
|
||||
{
|
||||
BodyKey = "body:far",
|
||||
OrbitKey = "orbit:far",
|
||||
Kind = "planet",
|
||||
GravityInfluenceCenterX = 100,
|
||||
GravityInfluenceCenterZ = 0,
|
||||
GravityInfluenceRadius = 4,
|
||||
GravityWellDepth = 10
|
||||
},
|
||||
new AetheriaRuntimeBodySnapshotCommit
|
||||
{
|
||||
BodyKey = "body:legacy-missing-radius",
|
||||
OrbitKey = "orbit:legacy",
|
||||
Kind = "planet",
|
||||
GravityInfluenceCenterX = 0,
|
||||
GravityInfluenceCenterZ = 0
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var brushes = new List<AetheriaRuntimeGravityInfluenceBrush>();
|
||||
var count = AetheriaRuntimeDaemonRenderQueries.QueryGravityInfluences(
|
||||
zone,
|
||||
new AetheriaRuntimeXzRect(-10, -10, 10, 10),
|
||||
brushes);
|
||||
|
||||
Assert.AreEqual(1, count);
|
||||
Assert.AreEqual("body:near", brushes[0].BodyKey);
|
||||
Assert.AreEqual(AetheriaRuntimeGravityInfluenceKind.GasGiant, brushes[0].Kind);
|
||||
Assert.AreEqual(9, brushes[0].Radius);
|
||||
Assert.AreEqual(20, brushes[0].GravityDepth);
|
||||
Assert.AreEqual(12, brushes[0].GravityDepthExponent);
|
||||
Assert.AreEqual(9, brushes[0].WaveRadius);
|
||||
Assert.AreEqual(3, brushes[0].WaveDepth);
|
||||
Assert.AreEqual(2, brushes[0].WaveSpeed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SoaViewIndexRejectsInvalidRenderGroups()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue