Close planetary patch performance and arrival gates

This commit is contained in:
Meta Vens 2026-07-12 23:58:04 +01:00
commit c3a78af2f3
9 changed files with 92 additions and 16 deletions

View file

@ -564,6 +564,7 @@ public sealed class AquariumPlanetarySurfacePageSet
public long PresentationVersion { get; init; }
public IReadOnlyList<AquariumPlanetarySurfacePage> Pages { get; init; } = [];
public bool RenderCoarsePatches { get; init; }
public int PatchCells { get; init; } = 16;
public int SampleCount => Pages.Sum(page => page.Samples.Count);
public bool HasInput => ContentVersion != 0 && Pages.Count > 0 && Pages.All(page => page.HasInput);
}

View file

@ -327,6 +327,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
private AquariumPlanetarySurfacePageSet activePlanetarySurfacePages = AquariumPlanetarySurfacePageSet.Empty;
private long residentPlanetarySurfacePageContentVersion;
private long residentPlanetarySurfacePagePresentationVersion;
private int residentPlanetarySurfacePatchCells;
private D3D12StructuredBuffer fieldReservoirCandidateBuffer = null!;
private D3D12StructuredBuffer fieldReservoirLockBuffer = null!;
private readonly List<D3D12TubeFieldDrawBatch> tubeFieldDrawBatches = [];
@ -433,6 +434,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
private readonly D3D12ShaderPaths shaderPaths;
private readonly CompiledRenderGraph renderGraph;
private readonly bool hasSceneRenderingPass;
private readonly bool profilePlanetarySurfacePages;
private readonly Stopwatch shaderReloadClock = Stopwatch.StartNew();
private readonly Dictionary<string, DateTime> shaderWriteTimesUtc = new(StringComparer.OrdinalIgnoreCase);
private readonly double[] accumulatedGpuTimingMilliseconds = new double[(int)D3D12GpuTimingPass.Count];
@ -476,6 +478,10 @@ public sealed class D3D12Renderer : IAquariumRenderer
renderGraph = D3D12RenderGraphCompiler.Compile(activeRenderPlan);
hasSceneRenderingPass = renderGraph.Passes.Any(static pass =>
pass.Kind is AquariumPassKind.Fullscreen or AquariumPassKind.Proxy or AquariumPassKind.Instanced or AquariumPassKind.Compute);
profilePlanetarySurfacePages = string.Equals(
Environment.GetEnvironmentVariable("AQUARIUM_PROFILE_PLANETARY_PAGES"),
"1",
StringComparison.Ordinal);
shaderSourceRoot = ResolveShaderSourceRoot(shaderPath, activeRenderPlan.Shaders);
shaderPaths = D3D12ShaderPaths.FromManifest(shaderSourceRoot, activeRenderPlan.Shaders);
sdfProxyPipelineStates = new ID3D12PipelineState?[shaderPaths.SdfShaders.Count];
@ -3175,7 +3181,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
context.CommandList.SetGraphicsRootShaderResourceView(RootPlanetarySurfacePageSummary, planetarySurfacePageSummaryBuffer.Resource.GPUVirtualAddress);
context.CommandList.SetGraphicsRootShaderResourceView(RootPlanetarySurfacePageSet, planetarySurfacePageSetBuffer.Resource.GPUVirtualAddress);
context.CommandList.SetPipelineState(planetarySurfacePatchPipelineState!);
context.CommandList.DrawInstanced(16u * 16u * 6u, 6, 0, 0);
var patchCells = (uint)Math.Clamp(activePlanetarySurfacePages.PatchCells, 1, 256);
context.CommandList.DrawInstanced(patchCells * patchCells * 6u, 6, 0, 0);
EndGpuTiming(context.CommandList, frameResources, D3D12GpuTimingPass.PlanetarySurfacePatches);
}
@ -3938,6 +3945,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
planetarySurfacePageSetBuffer = new D3D12StructuredBuffer(device, 1, 16, "Aquarium Planetary Page Set");
residentPlanetarySurfacePageContentVersion = 0;
residentPlanetarySurfacePagePresentationVersion = 0;
residentPlanetarySurfacePatchCells = 0;
}
private void DispatchPlanetarySurfacePage(ID3D12GraphicsCommandList activeCommandList, FrameResources frameResources)
@ -3951,6 +3959,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
planetarySurfacePageSetBuffer.Upload(activeCommandList, frameResources.UploadRing, new[] { Vector4.Zero });
residentPlanetarySurfacePageContentVersion = 0;
residentPlanetarySurfacePagePresentationVersion = 0;
residentPlanetarySurfacePatchCells = 0;
}
return;
}
@ -3965,13 +3974,15 @@ public sealed class D3D12Renderer : IAquariumRenderer
metadata[pageIndex] = page.Metadata with { Layout = new Vector4(sampleOffset, page.Metadata.Layout.Y, page.Metadata.Layout.Z, page.Metadata.Layout.W) };
sampleOffset += page.Samples.Count;
}
if (residentPlanetarySurfacePagePresentationVersion != activePlanetarySurfacePages.PresentationVersion)
var patchCells = Math.Clamp(activePlanetarySurfacePages.PatchCells, 1, 256);
if (residentPlanetarySurfacePagePresentationVersion != activePlanetarySurfacePages.PresentationVersion || residentPlanetarySurfacePatchCells != patchCells)
{
planetarySurfacePageMetadataBuffer.Upload(activeCommandList, frameResources.UploadRing, metadata);
planetarySurfacePageSetBuffer.Upload(activeCommandList, frameResources.UploadRing, new[] { new Vector4(pages.Count, 0, 0, 1) });
planetarySurfacePageSetBuffer.Upload(activeCommandList, frameResources.UploadRing, new[] { new Vector4(pages.Count, patchCells, 0, 1) });
residentPlanetarySurfacePagePresentationVersion = activePlanetarySurfacePages.PresentationVersion;
residentPlanetarySurfacePatchCells = patchCells;
}
if (residentPlanetarySurfacePageContentVersion == activePlanetarySurfacePages.ContentVersion) return;
if (residentPlanetarySurfacePageContentVersion == activePlanetarySurfacePages.ContentVersion && !profilePlanetarySurfacePages) return;
BeginGpuTiming(activeCommandList, frameResources, D3D12GpuTimingPass.PlanetarySurfacePages);
planetarySurfacePageInputBuffer.Upload(activeCommandList, frameResources.UploadRing, samples);
planetarySurfacePageOutputBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess);

View file

@ -1,8 +1,5 @@
#include "D3D12ZyphosPlanet.hlsl"
static const uint ZY_PATCH_CELLS = 16u;
static const uint ZY_PATCH_VERTICES = ZY_PATCH_CELLS * ZY_PATCH_CELLS * 6u;
struct ZyPatchVertexOut
{
float4 position : SV_Position;
@ -26,9 +23,10 @@ float3 zyPatchDirection(uint face,float2 local)
ZyPatchVertexOut D3D12ZyphosTerrainPatchVS(uint vertexId:SV_VertexID,uint instanceId:SV_InstanceID)
{
uint cell=vertexId/6u,corner=vertexId%6u; uint x=cell%ZY_PATCH_CELLS,y=cell/ZY_PATCH_CELLS;
uint patchCells=(uint)max(zy_planet_page_set[0].state.y,1.0);
uint cell=vertexId/6u,corner=vertexId%6u; uint x=cell%patchCells,y=cell/patchCells;
uint2 offsets[6]={uint2(0,0),uint2(1,0),uint2(1,1),uint2(0,0),uint2(1,1),uint2(0,1)};
float2 local=(float2(x,y)+offsets[corner])/(float)ZY_PATCH_CELLS;
float2 local=(float2(x,y)+offsets[corner])/(float)patchCells;
ZyPlanetPageMetadata root=zy_planet_page_metadata[instanceId]; float3 dir=zyPatchDirection((uint)root.address.x,local);
SdfObject planet=sdfObjects[0]; float height=zyTerrainOffset(dir,planet); if(!isfinite(height))height=0.0;
float captureMargin=zyTerrainPatchCaptureMargin(dir);
@ -52,7 +50,10 @@ ZyPatchSceneOut D3D12ZyphosTerrainPatchPS(ZyPatchVertexOut input)
}
if(!all(isfinite(p)))p=coarsePosition;
float travel=length(p-cameraPosition); if(!isfinite(travel)||travel<=0.0||travel>farDistance)discard;
float3 radial=normalize(p-planet.centerRadius.xyz); float3 normal=zyPlanetSurfaceNormal(p,0); if(!all(isfinite(normal))||dot(normal,normal)<0.25)normal=radial;
float3 radial=normalize(p-planet.centerRadius.xyz);
float3 normal=cross(ddy(p),ddx(p));
if(!all(isfinite(normal))||dot(normal,normal)<1.0e-10)normal=radial; else normal=normalize(normal);
if(dot(normal,cameraPosition-p)<0.0)normal=-normal;
SdfSurface surface=sdfSurface(p,0);
ZyPatchSceneOut output; output.colorTravel=float4(shadeSdf(0.0,travel,p,normal,0,surface),min(travel,farDistance+1.0));
output.metadata=float4(FIELD_ID_SDF_OBJECT_BASE,normal); output.control=float4(1,4.0/384.0,saturate(surface.temporalDetail),saturate(surface.reservoirConfidence));

View file

@ -24,6 +24,12 @@ internal static class ZyphosPlanetarySurfacePages
lastTimeSeconds=float.NegativeInfinity;
}
internal static void PrimeForCapture(Vector3 cameraPosition, float pageAgeSeconds)
{
Reset();
_ = ForCamera(cameraPosition, -Math.Max(pageAgeSeconds, 0.0f));
}
public static AquariumPlanetarySurfacePageSet ForCamera(Vector3 cameraPosition, float timeSeconds)
{
if (timeSeconds < lastTimeSeconds)
@ -69,6 +75,7 @@ internal static class ZyphosPlanetarySurfacePages
PresentationVersion = presentationVersion,
Pages = pages,
RenderCoarsePatches = true,
PatchCells = 64,
};
}

View file

@ -77,6 +77,17 @@ public sealed class ZyphosRuntime : IAquariumRuntime
public ZyphosRuntime()
{
var captureDomain = Environment.GetEnvironmentVariable("AQUARIUM_ZYPHOS_DOMAIN");
if (!string.IsNullOrWhiteSpace(captureDomain))
{
var domain = ZyphosSpatialDomainCatalog.Domains.FirstOrDefault(candidate =>
string.Equals(candidate.Key.Value, captureDomain, StringComparison.OrdinalIgnoreCase));
if (domain is not null)
{
selectedDomainKey = domain.Key;
autoOrbit = false;
}
}
if (float.TryParse(
Environment.GetEnvironmentVariable("AQUARIUM_ZYPHOS_ORBIT_DISTANCE"),
NumberStyles.Float,
@ -86,6 +97,16 @@ public sealed class ZyphosRuntime : IAquariumRuntime
orbitDistance = ClampOrbitDistance(captureDistance);
autoOrbit = false;
}
if (float.TryParse(
Environment.GetEnvironmentVariable("AQUARIUM_ZYPHOS_PAGE_AGE_SECONDS"),
NumberStyles.Float,
CultureInfo.InvariantCulture,
out var pageAgeSeconds))
{
timeScale = 0.0f;
autoOrbit = false;
ZyphosPlanetarySurfacePages.PrimeForCapture(CurrentShot().CameraPosition, pageAgeSeconds);
}
var ui = new AquariumUiDocument()
.Panel("Zyphos", 18.0f, 82.0f, 340.0f, panel =>
{