Reduce planetary page bounds on GPU

This commit is contained in:
Meta Vens 2026-07-12 20:13:35 +01:00
commit c1c32a0f14
4 changed files with 29 additions and 1 deletions

View file

@ -11,6 +11,7 @@ float zyPageErosion(float3 direction, float radius, float spacing)
float3 dir=normalize(direction); return zyAdvancedErosion(dir,zySphericalField(dir),radius,spacing).x;
}
[numthreads(64,1,1)]
void D3D12ZyphosTerrainPageCS(uint3 id : SV_DispatchThreadID)
{

View file

@ -0,0 +1,20 @@
struct PageOutput { float4 height_gradient; float4 masks; };
struct PageSummary { float4 bounds; float4 metadata; };
StructuredBuffer<PageOutput> summary_inputs : register(t0);
RWStructuredBuffer<PageSummary> summary_outputs : register(u0);
cbuffer PageConstants : register(b0) { uint page_sample_count; }
[numthreads(1,1,1)]
void D3D12ZyphosTerrainPageSummaryCS(uint3 id : SV_DispatchThreadID)
{
if(id.x!=0 || page_sample_count==0) return;
float minimum_height=3.402823466e+38, maximum_height=-3.402823466e+38, maximum_slope=0.0, maximum_unresolved=0.0;
[loop] for(uint index=0;index<page_sample_count;index++)
{
float4 sample=summary_inputs[index].height_gradient;
minimum_height=min(minimum_height,sample.x); maximum_height=max(maximum_height,sample.x);
maximum_slope=max(maximum_slope,length(sample.yz)); maximum_unresolved=max(maximum_unresolved,sample.w);
}
summary_outputs[0].bounds=float4(minimum_height,maximum_height,maximum_slope,maximum_unresolved);
summary_outputs[0].metadata=float4(page_sample_count,0,0,1);
}

View file

@ -336,3 +336,4 @@
{"timestamp":"2026-07-12T20:30:00+01:00","topic":"advanced-erosion-gpu-parity","lesson":"Float-based cell hashes diverged enough between C# and HLSL to select different erosion pivots across a 2052-sample corpus. CultMath now uses the same integer avalanche hash in both paths, and Fensalir verifies the actual HLSL kernel with a standalone D3D12 compute/readback probe instead of inferring parity from similar source text or booting the renderer.","files":["E:\\Projects\\CultMath\\src\\CultMath\\AdvancedErosionFilter.cs","E:\\Projects\\CultMath\\shaders\\AdvancedErosionFilter.hlsl","src/Aquarium.Engine/Render/D3D12ComputeProbe.cs","src/Aquarium.Engine/Render/D3D12ShaderCompiler.cs","tests/Aquarium.Engine.Tests/D3D12AdvancedErosionParityTests.cs"],"source":"measured CPU/GPU parity implementation"}
{"timestamp":"2026-07-12T21:00:00+01:00","topic":"erosion-physical-frequency-bands","lesson":"Planetary erosion LOD is now a filter over one world-space spectrum: CultMath selects active octaves from physical wavelength and sample spacing, fractionally weights the last resolvable octave, and reports omitted height. Zyphos uses that contract through smooth planet-space triplanar charts, so changing view footprint changes represented bands rather than switching terrain authorities.","files":["E:\\Projects\\CultMath\\src\\CultMath\\ErosionFrequencyBands.cs","E:\\Projects\\CultMath\\src\\CultMath\\AdvancedErosionFilter.cs","E:\\Projects\\CultMath\\shaders\\AdvancedErosionFilter.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl"],"source":"phase 3 of stateless planetary erosion rendering plan"}
{"timestamp":"2026-07-12T21:35:00+01:00","topic":"planetary-page-boundary-authority","lesson":"Using each tile's locally measured angular texel size caused independently generated sibling pages to choose different erosion weights at the same shared boundary. Band selection now uses a level-global nominal angular footprint; local projection distortion remains summary evidence. GPU-generated sibling boundaries are identical and borders sample the spherical field without neighbor residency.","files":["src/Aquarium.Engine.Fractal/Lod/PlanetarySurfacePage.cs","src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrain.hlsli","src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrainPage.hlsl","tests/Aquarium.Engine.Tests/D3D12PlanetarySurfacePageTests.cs"],"source":"phase 4 cross-page GPU verification"}
{"timestamp":"2026-07-12T22:00:00+01:00","topic":"planetary-page-summary-reduction","lesson":"Planetary erosion pages now reduce minimum/maximum displacement, maximum tangent slope, and maximum unresolved height through the GPU kernel and verify those results against CPU reduction. These summaries are the conservative evidence needed by later intersection and residency; they are not inferred from parameters.","files":["src/Aquarium.Zyphos/Shaders/D3D12ZyphosTerrainPageSummary.hlsl","tests/Aquarium.Engine.Tests/D3D12PlanetarySurfacePageTests.cs"],"source":"phase 4 GPU summary gate"}

View file

@ -30,6 +30,9 @@ public sealed class D3D12PlanetarySurfacePageTests
Assert.All(output,s=>{Assert.True(float.IsFinite(s.HeightGradient.X));Assert.True(float.IsFinite(s.HeightGradient.Y));Assert.InRange(s.Masks.X,0,1);Assert.InRange(s.Masks.Y,0,1);});
var min=output.Min(s=>s.HeightGradient.X); var max=output.Max(s=>s.HeightGradient.X); var slope=output.Max(s=>MathF.Sqrt(s.HeightGradient.Y*s.HeightGradient.Y+s.HeightGradient.Z*s.HeightGradient.Z));
Assert.True(min<=max); Assert.True(slope>=0); Assert.True(output.Max(s=>s.HeightGradient.W)>=0);
var shader=Path.Combine(RepositoryRoot(),"src","Aquarium.Zyphos","Shaders","D3D12ZyphosTerrainPageSummary.hlsl");
var summary=D3D12ComputeProbe.Run<PageOutput,PageSummary>(shader,"D3D12ZyphosTerrainPageSummaryCS",output)[0];
Assert.Equal(min,summary.Bounds.X); Assert.Equal(max,summary.Bounds.Y); Assert.Equal(slope,summary.Bounds.Z); Assert.Equal(output.Max(s=>s.HeightGradient.W),summary.Bounds.W);
}
private static PageOutput[] Generate(PlanetarySurfacePageRequest request)
@ -38,11 +41,14 @@ public sealed class D3D12PlanetarySurfacePageTests
var input=new PageInput[request.StorageSize*request.StorageSize];
for(int y=0;y<request.StorageSize;y++) for(int x=0;x<request.StorageSize;x++)
{ var d=PlanetarySurfacePageSampling.Direction(request,x,y); input[y*request.StorageSize+x]=new PageInput(new Vector4(d,radius),new Vector4(spacing,0,0,0)); }
var shader=Path.Combine(RepositoryRoot(),"src","Aquarium.Zyphos","Shaders","D3D12ZyphosTerrainPage.hlsl");
var shader=ShaderPath();
return D3D12ComputeProbe.Run<PageInput,PageOutput>(shader,"D3D12ZyphosTerrainPageCS",input);
}
private static string ShaderPath()=>Path.Combine(RepositoryRoot(),"src","Aquarium.Zyphos","Shaders","D3D12ZyphosTerrainPage.hlsl");
private static string RepositoryRoot(){var d=new DirectoryInfo(AppContext.BaseDirectory);while(d is not null&&!File.Exists(Path.Combine(d.FullName,"Fensalir.sln")))d=d.Parent;return d?.FullName??throw new InvalidOperationException();}
[StructLayout(LayoutKind.Sequential)] private readonly record struct PageInput(Vector4 DirectionRadius,Vector4 Sampling);
[StructLayout(LayoutKind.Sequential)] private readonly record struct PageOutput(Vector4 HeightGradient,Vector4 Masks);
[StructLayout(LayoutKind.Sequential)] private readonly record struct PageSummary(Vector4 Bounds,Vector4 Metadata);
}