This commit is contained in:
Rian Drake 2026-10-15 14:09:11 +13:00
commit b578433e37
9 changed files with 784842 additions and 0 deletions

View file

@ -0,0 +1,43 @@
namespace Brutal.MeshOptimizer
{
/// <summary>
/// Vertex buffer filter encoders
/// These functions can be used to encode data in a format that meshopt_decodeFilter can decode
/// </summary>
/// <remarks>
/// <para>
/// meshopt_encodeFilterOct encodes unit vectors with K-bit (2 &lt;= K &lt;= 16) signed X/Y as an output.
/// Each component is stored as an 8-bit or 16-bit normalized integer; stride must be equal to 4 or 8. Z will store 1.0f, W is preserved as is.
/// Input data must contain 4 floats for every vector (count*4 total).
/// </para>
/// <para>
/// meshopt_encodeFilterQuat encodes unit quaternions with K-bit (4 &lt;= K &lt;= 16) component encoding.
/// Each component is stored as an 16-bit integer; stride must be equal to 8.
/// Input data must contain 4 floats for every quaternion (count*4 total).
/// </para>
/// <para>
/// meshopt_encodeFilterExp encodes arbitrary (finite) floating-point data with 8-bit exponent and K-bit integer mantissa (1 &lt;= K &lt;= 24).
/// Exponent can be shared between all components of a given vector as defined by stride or all values of a given component; stride must be divisible by 4.
/// Input data must contain stride/4 floats for every vector (count*stride/4 total).
/// </para>
/// <para>
/// meshopt_encodeFilterColor encodes RGBA color data by converting RGB to YCoCg color space with K-bit (2 &lt;= K &lt;= 16) component encoding; A is stored using K-1 bits.
/// Each component is stored as an 8-bit or 16-bit integer; stride must be equal to 4 or 8.
/// Input data must contain 4 floats for every color (count*4 total).
/// </para>
/// </remarks>
public enum MeshOptEncodeExpMode
{
/// When encoding exponents, use separate values for each component (maximum quality)
EncodeExpSeparate,
/// When encoding exponents, use shared value for all components of each vector (better compression)
EncodeExpSharedVector,
/// When encoding exponents, use shared value for each component of all vectors (best compression)
EncodeExpSharedComponent,
/// When encoding exponents, use separate values for each component, but clamp to 0 (good quality if very small values are not important)
EncodeExpClamped,
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,35 @@
using Brutal.Interop;
using Brutal.Numerics;
using Brutal.Pointers;
namespace Brutal.MeshOptimizer
{
[StructLayout(LayoutKind.Explicit, Size = 48)]
public unsafe partial struct MeshOptBounds
{
/// bounding sphere, useful for frustum and occlusion culling
[FieldOffset(0)]
public float3 Center;
[FieldOffset(12)]
public float Radius;
/// normal cone, useful for backface culling
[FieldOffset(16)]
public float3 ConeApex;
[FieldOffset(28)]
public float3 ConeAxis;
/// = cos(angle/2)
[FieldOffset(40)]
public float ConeCutoff;
/// normal cone axis and cutoff, stored in 8-bit SNORM format; decode using x/127.0
[FieldOffset(44)]
public byte3 ConeAxisS8;
[FieldOffset(47)]
public byte ConeCutoffS8;
}
}

View file

@ -0,0 +1,17 @@
using Brutal.Interop;
using Brutal.Numerics;
using Brutal.Pointers;
namespace Brutal.MeshOptimizer
{
[StructLayout(LayoutKind.Explicit, Size = 16)]
public unsafe partial struct MeshOptCoverageStatistics
{
[FieldOffset(0)]
public float3 Coverage;
/// viewport size in mesh coordinates
[FieldOffset(12)]
public float Extent;
}
}

View file

@ -0,0 +1,24 @@
using Brutal.Interop;
using Brutal.Numerics;
using Brutal.Pointers;
namespace Brutal.MeshOptimizer
{
[StructLayout(LayoutKind.Explicit, Size = 16)]
public unsafe partial struct MeshOptMeshlet
{
/// offsets within meshlet_vertices and meshlet_triangles arrays with meshlet data
[FieldOffset(0)]
public int VertexOffset;
[FieldOffset(4)]
public int TriangleOffset;
/// number of vertices and triangles used in the meshlet; data is stored in consecutive range [offset..offset+count) for vertices and [offset..offset+count*3) for triangles
[FieldOffset(8)]
public int VertexCount;
[FieldOffset(12)]
public int TriangleCount;
}
}

View file

@ -0,0 +1,20 @@
using Brutal.Interop;
using Brutal.Numerics;
using Brutal.Pointers;
namespace Brutal.MeshOptimizer
{
[StructLayout(LayoutKind.Explicit, Size = 12)]
public unsafe partial struct MeshOptOverdrawStatistics
{
[FieldOffset(0)]
public int PixelsCovered;
[FieldOffset(4)]
public int PixelsShaded;
/// shaded pixels / covered pixels; best case 1.0
[FieldOffset(8)]
public float Overdraw;
}
}

View file

@ -0,0 +1,19 @@
using Brutal.Interop;
using Brutal.Numerics;
using Brutal.Pointers;
namespace Brutal.MeshOptimizer
{
[StructLayout(LayoutKind.Explicit, Size = 24)]
public unsafe partial struct MeshOptStream
{
[FieldOffset(0)]
public Ptr Data;
[FieldOffset(8)]
public ByteSize64 Size;
[FieldOffset(16)]
public ByteSize64 Stride;
}
}

View file

@ -0,0 +1,24 @@
using Brutal.Interop;
using Brutal.Numerics;
using Brutal.Pointers;
namespace Brutal.MeshOptimizer
{
[StructLayout(LayoutKind.Explicit, Size = 16)]
public unsafe partial struct MeshOptVertexCacheStatistics
{
[FieldOffset(0)]
public int VerticesTransformed;
[FieldOffset(4)]
public int WarpsExecuted;
/// transformed vertices / triangle count; best case 0.5, worst case 3.0, optimum depends on topology
[FieldOffset(8)]
public float Acmr;
/// transformed vertices / vertex count; best case 1.0, worst case 6.0, optimum is 1.0 (each vertex is transformed once)
[FieldOffset(12)]
public float Atvr;
}
}

View file

@ -0,0 +1,17 @@
using Brutal.Interop;
using Brutal.Numerics;
using Brutal.Pointers;
namespace Brutal.MeshOptimizer
{
[StructLayout(LayoutKind.Explicit, Size = 8)]
public unsafe partial struct MeshOptVertexFetchStatistics
{
[FieldOffset(0)]
public int BytesFetched;
/// fetched bytes / vertex buffer size; best case 1.0 (each byte is fetched once)
[FieldOffset(4)]
public float Overfetch;
}
}