Split imported and generated mesh layouts

This commit is contained in:
Meta Vens 2026-05-26 22:25:08 +01:00
commit 44e22d127d
7 changed files with 65 additions and 8 deletions

View file

@ -113,6 +113,13 @@ public enum AquariumFieldMeshIndexFormat
UInt32 = 2,
}
public enum AquariumFieldMeshLayout
{
Unknown = 0,
PositionNormalUvColor = 1,
PipelinePrivate = 2,
}
public enum AquariumFieldInvalidationCode
{
None = 0,
@ -270,19 +277,29 @@ public readonly record struct AquariumFieldMeshResource(
AquariumFieldMeshBuffer Indices,
AquariumFieldMeshTopology Topology,
AquariumFieldMeshIndexFormat IndexFormat,
AquariumFieldMeshLayout Layout,
Vector3 BoundsMin,
Vector3 BoundsMax,
int SubmeshCount)
{
public const int PositionNormalUvColorStrideBytes = 48;
public bool IsValid =>
Vertices.HasShape &&
Indices.HasShape &&
Topology != AquariumFieldMeshTopology.Unknown &&
IndexFormat != AquariumFieldMeshIndexFormat.Unknown &&
Layout != AquariumFieldMeshLayout.Unknown &&
SubmeshCount > 0 &&
BoundsMax.X >= BoundsMin.X &&
BoundsMax.Y >= BoundsMin.Y &&
BoundsMax.Z >= BoundsMin.Z;
public bool IsStandardImportedLayout =>
Layout == AquariumFieldMeshLayout.PositionNormalUvColor &&
Vertices.StrideBytes == PositionNormalUvColorStrideBytes;
public bool IsPipelinePrivate => Layout == AquariumFieldMeshLayout.PipelinePrivate;
}
public readonly record struct AquariumFieldTubeSplineLowering(

View file

@ -170,7 +170,11 @@ public static class AquariumFieldScriptCompiler
var id = Required(args, "id", lineIndex);
var key = StringValue(args, "key", $"aquarium:resource:mesh:{id}");
var vertexCount = Int(args, "vertices", 1, lineIndex);
var vertexStride = Int(args, "vertexStride", 32, lineIndex);
var layout = Enum.Parse<AquariumFieldMeshLayout>(StringValue(args, "layout", nameof(AquariumFieldMeshLayout.PositionNormalUvColor)), ignoreCase: true);
var defaultVertexStride = layout == AquariumFieldMeshLayout.PositionNormalUvColor
? AquariumFieldMeshResource.PositionNormalUvColorStrideBytes
: 32;
var vertexStride = Int(args, "vertexStride", defaultVertexStride, lineIndex);
var indexCount = Int(args, "indices", 3, lineIndex);
var indexFormat = Enum.Parse<AquariumFieldMeshIndexFormat>(StringValue(args, "indexFormat", nameof(AquariumFieldMeshIndexFormat.UInt32)), ignoreCase: true);
var indexStride = indexFormat == AquariumFieldMeshIndexFormat.UInt16 ? 2 : 4;
@ -179,6 +183,7 @@ public static class AquariumFieldScriptCompiler
Indices: new AquariumFieldMeshBuffer($"{key}:indices", indexCount, indexStride, IntPtr.Zero, "fensalir-mesh-indices"),
Topology: Enum.Parse<AquariumFieldMeshTopology>(StringValue(args, "topology", nameof(AquariumFieldMeshTopology.TriangleList)), ignoreCase: true),
IndexFormat: indexFormat,
Layout: layout,
BoundsMin: Vec3(args, "min", -Vector3.One, lineIndex),
BoundsMax: Vec3(args, "max", Vector3.One, lineIndex),
SubmeshCount: Int(args, "submeshes", 1, lineIndex));

View file

@ -11,6 +11,7 @@ internal sealed class D3D12FieldMesh : IDisposable
D3D12StructuredBuffer indices,
AquariumFieldMeshTopology topology,
AquariumFieldMeshIndexFormat indexFormat,
AquariumFieldMeshLayout layout,
int submeshCount,
ulong version)
{
@ -18,6 +19,7 @@ internal sealed class D3D12FieldMesh : IDisposable
Indices = indices;
Topology = topology;
IndexFormat = indexFormat;
Layout = layout;
SubmeshCount = submeshCount;
Version = version;
}
@ -30,6 +32,14 @@ internal sealed class D3D12FieldMesh : IDisposable
public AquariumFieldMeshIndexFormat IndexFormat { get; }
public AquariumFieldMeshLayout Layout { get; }
public bool HasStandardImportedLayout =>
Layout == AquariumFieldMeshLayout.PositionNormalUvColor &&
Vertices.StrideBytes == AquariumFieldMeshResource.PositionNormalUvColorStrideBytes;
public bool IsPipelinePrivate => Layout == AquariumFieldMeshLayout.PipelinePrivate;
public int SubmeshCount { get; }
public ulong Version { get; }

View file

@ -517,7 +517,8 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
existing.Indices.ElementCount == mesh.Indices.Count &&
existing.Indices.StrideBytes == mesh.Indices.StrideBytes &&
existing.Topology == mesh.Topology &&
existing.IndexFormat == mesh.IndexFormat)
existing.IndexFormat == mesh.IndexFormat &&
existing.Layout == mesh.Layout)
{
return true;
}
@ -543,6 +544,7 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
indices,
mesh.Topology,
mesh.IndexFormat,
mesh.Layout,
mesh.SubmeshCount,
declaration.Version);
return true;

View file

@ -243,3 +243,4 @@
{"lesson":"VolumeTexture is now a resolvable field resource kind. AquariumFieldResourceDeclaration has a VolumeTexture factory, the field evidence DSL accepts `volumetexture id=... key=... width=... height=... depth=... format=...`, and D3D12FieldResourceRegistry allocates empty GPU-resident shader-readable Texture3D resources with format/dimension/version tracking. This creates resource authority for future density/extinction/SDF3D lowerings without pretending those render paths exist yet. Fensalir build/tests/headless reload and Mimir build/field smokes passed.","timestamp":"2026-05-26T21:11:00+01:00","files":["src/Aquarium.Engine.Contracts/Render/AquariumFieldEvidence.cs","src/Aquarium.Engine.Contracts/Render/AquariumFieldScriptCompiler.cs","src/Aquarium.Engine/Render/D3D12FieldTexture3D.cs","src/Aquarium.Engine/Render/D3D12FieldTextureFormat.cs","src/Aquarium.Engine/Render/D3D12FieldResourceRegistry.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","tests/Aquarium.Engine.Tests/FieldScriptCompilerTests.cs","state/map.yaml"],"source":"continued field resource resolver migration","topic":"field-volume-texture-resource-resolver"}
{"lesson":"Mesh is now a resolvable field resource package rather than loose scalar handles. AquariumFieldMeshResource owns Mesh.Vertices, Mesh.Indices, topology, index format, bounds, submesh count, and version; the field evidence DSL accepts `mesh id=... key=... vertices=... vertexStride=... indices=... indexFormat=... topology=...`; and D3D12FieldResourceRegistry allocates/reuses GPU-resident vertex and index buffers under the mesh resource key. This creates resource authority for future mesh draw/compute lowerings without pretending a material or vertex-layout render path exists yet. Fensalir build/tests/headless reload passed.","timestamp":"2026-05-26T21:24:00+01:00","files":["src/Aquarium.Engine.Contracts/Render/AquariumFieldEvidence.cs","src/Aquarium.Engine.Contracts/Render/AquariumFieldScriptCompiler.cs","src/Aquarium.Engine/Render/D3D12FieldMesh.cs","src/Aquarium.Engine/Render/D3D12FieldResourceRegistry.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","tests/Aquarium.Engine.Tests/FieldScriptCompilerTests.cs","state/map.yaml"],"source":"user clarified Mesh package API boundary","topic":"field-mesh-resource-resolver"}
{"lesson":"The field evidence DSL can now plan generic resource-backed claims, not only Tube claims. `claim id=... resource=... encoding=... layer=...` creates a selected claim/candidate over the declared resource, so Mesh packages, SurfacePage height/SDF/material pages, and VolumeTexture density/extinction resources can reach AquariumFieldLoweringPlanner and produce backend packets. This closes the planner/resource contract cut. Actual Mesh rendering remains blocked on a vertex attribute/material layout contract; the mesh package owns buffer shape, not byte semantics. Fensalir build and Aquarium.Engine.Tests passed.","timestamp":"2026-05-26T21:42:00+01:00","files":["src/Aquarium.Engine.Contracts/Render/AquariumFieldScriptCompiler.cs","tests/Aquarium.Engine.Tests/FieldScriptCompilerTests.cs","state/map.yaml"],"source":"continued field packet/resource migration after mesh resolver","topic":"generic-field-resource-claims"}
{"lesson":"Mesh layout authority is now split by source. Imported/user-facing mesh packages default to the engine standard `PositionNormalUvColor` vertex layout (48-byte position, normal, uv, color contract), which is the lane for FBX/OBJ-style assets. Generated meshes can declare `layout=PipelinePrivate`; those bytes belong to the selected lowering that emits and consumes them, so Fensalir does not force TubeField or future procedural surfaces through a bloated public vertex ABI. Fensalir build and Aquarium.Engine.Tests passed with 23 tests.","timestamp":"2026-05-26T21:58:00+01:00","files":["src/Aquarium.Engine.Contracts/Render/AquariumFieldEvidence.cs","src/Aquarium.Engine.Contracts/Render/AquariumFieldScriptCompiler.cs","src/Aquarium.Engine/Render/D3D12FieldMesh.cs","src/Aquarium.Engine/Render/D3D12FieldResourceRegistry.cs","tests/Aquarium.Engine.Tests/FieldScriptCompilerTests.cs","state/map.yaml"],"source":"user clarified imported mesh versus generated mesh layout authority","topic":"field-mesh-layout-authority"}

View file

@ -111,9 +111,12 @@ next_actions:
evidence DSL also has a generic resource-backed `claim` command, so Mesh,
Height/SurfacePage, and Density/VolumeTexture resources can be planned into
backend packets without pretending a render path exists. Remaining cuts are
render lowerings that consume those packets. Mesh rendering is blocked on a
vertex attribute/material contract; stride/count/index format is resource
shape, not enough authority to decide position/normal/uv/color semantics.
render lowerings that consume those packets. Mesh layout authority is now
split intentionally: imported/user-facing meshes use the standard
`PositionNormalUvColor` layout, while generated meshes may declare
`PipelinePrivate` so the selected lowering owns the minimal bytes it emits
and consumes. Mesh rendering is now blocked on choosing the first selected
render lowering/material path, not on a generic imported-mesh ABI.
- Move any remaining client-only Epiphany state found here back to `E:\Projects\Aquarium-Engine`.
- Keep Mimir app/adapters out of this repo; Fensalir may expose generic sensor-fusion contracts only.
- Package contracts/host deliberately before replacing sibling source references in client repos.

View file

@ -174,7 +174,7 @@ public sealed class FieldScriptCompilerTests
{
var frame = AquariumFieldScriptCompiler.CompileEvidence(
"""
mesh id=quad key=aquarium:resource:mesh:quad vertices=4 vertexStride=32 indices=6 indexFormat=UInt32 topology=TriangleList min=-1,-1,0 max=1,1,0 submeshes=1 version=9
mesh id=quad key=aquarium:resource:mesh:quad vertices=4 indices=6 indexFormat=UInt32 topology=TriangleList min=-1,-1,0 max=1,1,0 submeshes=1 version=9
""",
new Dictionary<string, AquariumFieldResourceDeclaration>(StringComparer.Ordinal));
@ -185,12 +185,31 @@ public sealed class FieldScriptCompilerTests
Assert.Equal(AquariumFieldShaderAccess.ShaderResource, resource.Access);
Assert.Equal("fensalir-mesh-package", resource.NativeHandleKind);
Assert.True(resource.Mesh.IsValid);
Assert.True(resource.Mesh.IsStandardImportedLayout);
Assert.Equal(4, resource.Mesh.Vertices.Count);
Assert.Equal(32, resource.Mesh.Vertices.StrideBytes);
Assert.Equal(AquariumFieldMeshResource.PositionNormalUvColorStrideBytes, resource.Mesh.Vertices.StrideBytes);
Assert.Equal(6, resource.Mesh.Indices.Count);
Assert.Equal(4, resource.Mesh.Indices.StrideBytes);
Assert.Equal(AquariumFieldMeshTopology.TriangleList, resource.Mesh.Topology);
Assert.Equal(AquariumFieldMeshIndexFormat.UInt32, resource.Mesh.IndexFormat);
Assert.Equal(AquariumFieldMeshLayout.PositionNormalUvColor, resource.Mesh.Layout);
}
[Fact]
public void CompileEvidenceCanDeclarePipelinePrivateMeshes()
{
var frame = AquariumFieldScriptCompiler.CompileEvidence(
"""
mesh id=generated key=aquarium:resource:mesh:generated layout=PipelinePrivate vertices=8 vertexStride=20 indices=12 indexFormat=UInt16 topology=TriangleList min=-1,-1,0 max=1,1,0 submeshes=1
""",
new Dictionary<string, AquariumFieldResourceDeclaration>(StringComparer.Ordinal));
var resource = Assert.Single(frame.Resources);
Assert.True(resource.Mesh.IsValid);
Assert.True(resource.Mesh.IsPipelinePrivate);
Assert.False(resource.Mesh.IsStandardImportedLayout);
Assert.Equal(20, resource.Mesh.Vertices.StrideBytes);
Assert.Equal(2, resource.Mesh.Indices.StrideBytes);
}
[Fact]
@ -198,7 +217,7 @@ public sealed class FieldScriptCompilerTests
{
var frame = AquariumFieldScriptCompiler.CompileEvidence(
"""
mesh id=quad key=aquarium:resource:mesh:quad vertices=4 vertexStride=32 indices=6 indexFormat=UInt32 topology=TriangleList min=-1,-1,0 max=1,1,0 submeshes=1 version=9
mesh id=quad key=aquarium:resource:mesh:quad vertices=4 indices=6 indexFormat=UInt32 topology=TriangleList min=-1,-1,0 max=1,1,0 submeshes=1 version=9
surfacepage id=height key=aquarium:resource:surface-page:height width=64 height=64 format=R16Float
volumetexture id=fog key=aquarium:resource:volume-texture:fog width=16 height=16 depth=16 format=R16Float
claim id=quad resource=quad encoding=Mesh layer=Form radius=1