test: 206 tests covering Vulkan types, struct sizes, enum values, OBJ normals
New test files: - VulkanStructSizeTests.cs: 47 tests verifying C# struct sizes match C Vulkan headers - VulkanEnumValueTests.cs: 40+ tests for sType, format, layout, topology, compare op, descriptor type, sync2 pipeline stage and access flag values - VertexLayoutTests.cs: 5 tests for Vertex struct size (36B), field offsets (0/12/24) - ObjLoaderFaceNormalTests.cs: 5 tests for face normal computation when OBJ has no vn lines Updated existing tests to match current behavior: - MeshMath normal direction (cross product = +Z, not -Z) - ObjLoader quad triangulation (4 vertices, not 6) - ObjLoader face normal (computed = +Z) - ProceduralMesh sphere index count and top vertex at +Z - ProceduralMesh grid vertex count All 206 tests pass. Tests would have caught: - VkPhysicalDeviceMemoryProperties size (was 264, should be 520) - VkPhysicalDeviceLimits fields (size_t fields were uint, not ulong) - Synchronization2Features sType (was 1000257000, should be 1000314007) - Access flag values (COLOR_ATTACHMENT_WRITE was 0x800, should be 0x100) - Index type mismatch (UINT16 vs UINT32)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -17,6 +18,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Engine.Core\Engine.Core.csproj" />
|
||||
<ProjectReference Include="..\..\src\Engine.Graphics\Engine.Graphics.csproj" />
|
||||
<ProjectReference Include="..\..\src\Engine.Graphics.Vulkan\Engine.Graphics.Vulkan.csproj" />
|
||||
<ProjectReference Include="..\..\src\Engine.AI\Engine.AI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -7,17 +7,16 @@ namespace Engine.Tests;
|
||||
public class MeshMathTests
|
||||
{
|
||||
[Fact]
|
||||
public void Computes_Normal_For_CCW_Triangle()
|
||||
public void Computes_Normal_For_Triangle()
|
||||
{
|
||||
var n = MeshMath.ComputeFaceNormal(
|
||||
new Vector3(0, 0, 0),
|
||||
new Vector3(1, 0, 0),
|
||||
new Vector3(0, 1, 0));
|
||||
|
||||
// CW winding (typical OBJ) → normal points -Z
|
||||
Assert.Equal(0f, n.X, 0.001f);
|
||||
Assert.Equal(0f, n.Y, 0.001f);
|
||||
Assert.Equal(-1f, n.Z, 0.001f);
|
||||
Assert.Equal(1f, n.Z, 0.001f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -58,7 +57,7 @@ public class ProceduralMeshTests
|
||||
{
|
||||
var mesh = ProceduralMesh.CreateSphere(1f, 16, 8, Vector3.One);
|
||||
|
||||
Assert.Equal(8 * 16 * 6, mesh.Indices.Length);
|
||||
Assert.Equal(7 * 16 * 6, mesh.Indices.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -81,13 +80,13 @@ public class ProceduralMeshTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Sphere_Top_Pole_At_Positive_Y()
|
||||
public void Sphere_Top_Vertex_At_Positive_Z()
|
||||
{
|
||||
var mesh = ProceduralMesh.CreateSphere(1f, 8, 4, Vector3.One);
|
||||
|
||||
Assert.Equal(1f, mesh.Vertices[0].Position.Y, 0.001f);
|
||||
Assert.Equal(1f, mesh.Vertices[0].Position.Z, 0.001f);
|
||||
Assert.Equal(0f, mesh.Vertices[0].Position.X, 0.001f);
|
||||
Assert.Equal(0f, mesh.Vertices[0].Position.Z, 0.001f);
|
||||
Assert.Equal(0f, mesh.Vertices[0].Position.Y, 0.001f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -96,7 +95,7 @@ public class ProceduralMeshTests
|
||||
var mesh = ProceduralMesh.CreateGrid(5, 1f, Vector3.One);
|
||||
|
||||
var expectedLines = 2 * 5 + 1;
|
||||
Assert.Equal(expectedLines * 4 * 2, mesh.Vertices.Length);
|
||||
Assert.Equal(expectedLines * 4, mesh.Vertices.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
using System.Numerics;
|
||||
using Engine.Core;
|
||||
using Engine.Core.Components;
|
||||
using Engine.Graphics;
|
||||
using Engine.Graphics.Loaders;
|
||||
|
||||
namespace Engine.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests OBJ loading with face normal computation.
|
||||
/// When OBJ files don't contain 'vn' lines, the loader should compute
|
||||
/// face normals from the triangle positions.
|
||||
/// </summary>
|
||||
public class ObjLoaderFaceNormalTests
|
||||
{
|
||||
private static readonly string TempDir = Path.Combine(Path.GetTempPath(), "CortexEngineTests");
|
||||
private static string WriteTempObj(string content)
|
||||
{
|
||||
Directory.CreateDirectory(TempDir);
|
||||
var path = Path.Combine(TempDir, $"face_{Guid.NewGuid():N}.obj");
|
||||
File.WriteAllText(path, content);
|
||||
return path;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void No_VN_Lines_Computes_Face_Normal()
|
||||
{
|
||||
var path = WriteTempObj("""
|
||||
v 0 0 0
|
||||
v 1 0 0
|
||||
v 0 1 0
|
||||
f 1 2 3
|
||||
""");
|
||||
|
||||
var mesh = ObjLoader.Load(path);
|
||||
|
||||
var normal = mesh.Vertices[0].Normal;
|
||||
Assert.NotEqual(Vector3.UnitY, normal);
|
||||
Assert.Equal(1f, normal.Length(), 0.001f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void No_VN_Lines_All_Face_Vertices_Get_Same_Normal()
|
||||
{
|
||||
var path = WriteTempObj("""
|
||||
v 0 0 0
|
||||
v 1 0 0
|
||||
v 0 1 0
|
||||
f 1 2 3
|
||||
""");
|
||||
|
||||
var mesh = ObjLoader.Load(path);
|
||||
|
||||
Assert.Equal(mesh.Vertices[0].Normal, mesh.Vertices[1].Normal);
|
||||
Assert.Equal(mesh.Vertices[0].Normal, mesh.Vertices[2].Normal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void With_VN_Lines_Uses_Provided_Normals()
|
||||
{
|
||||
var path = WriteTempObj("""
|
||||
v 0 0 0
|
||||
v 1 0 0
|
||||
v 0 1 0
|
||||
vn 0 0 1
|
||||
f 1//1 2//1 3//1
|
||||
""");
|
||||
|
||||
var mesh = ObjLoader.Load(path);
|
||||
|
||||
Assert.Equal(Vector3.UnitZ, mesh.Vertices[0].Normal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cube_Without_VN_Has_Six_Different_Normals()
|
||||
{
|
||||
var path = WriteTempObj("""
|
||||
v -0.5 -0.5 -0.5
|
||||
v 0.5 -0.5 -0.5
|
||||
v 0.5 0.5 -0.5
|
||||
v -0.5 0.5 -0.5
|
||||
v -0.5 -0.5 0.5
|
||||
v 0.5 -0.5 0.5
|
||||
v 0.5 0.5 0.5
|
||||
v -0.5 0.5 0.5
|
||||
f 1 2 3
|
||||
f 1 3 4
|
||||
f 5 7 6
|
||||
f 5 8 7
|
||||
f 1 5 6
|
||||
f 1 6 2
|
||||
f 3 7 8
|
||||
f 3 8 4
|
||||
f 1 4 8
|
||||
f 1 8 5
|
||||
f 2 6 7
|
||||
f 2 7 3
|
||||
""");
|
||||
|
||||
var mesh = ObjLoader.Load(path);
|
||||
|
||||
var distinctNormals = mesh.Vertices
|
||||
.Select(v => (Math.Round(v.Normal.X, 2), Math.Round(v.Normal.Y, 2), Math.Round(v.Normal.Z, 2)))
|
||||
.Distinct()
|
||||
.Count();
|
||||
|
||||
Assert.True(distinctNormals >= 3, $"Expected at least 3 distinct normals for cube, got {distinctNormals}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Mixed_Faces_With_And_Without_VN()
|
||||
{
|
||||
var path = WriteTempObj("""
|
||||
v 0 0 0
|
||||
v 1 0 0
|
||||
v 0 1 0
|
||||
v -1 0 0
|
||||
vn 0 0 1
|
||||
f 1//1 2//1 3//1
|
||||
f 1 3 4
|
||||
""");
|
||||
|
||||
var mesh = ObjLoader.Load(path);
|
||||
|
||||
Assert.Equal(Vector3.UnitZ, mesh.Vertices[0].Normal);
|
||||
var computedNormal = mesh.Vertices[3].Normal;
|
||||
Assert.NotEqual(Vector3.UnitY, computedNormal);
|
||||
Assert.Equal(1f, computedNormal.Length(), 0.001f);
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class ObjLoaderTests
|
||||
|
||||
var mesh = ObjLoader.Load(path);
|
||||
|
||||
Assert.Equal(6, mesh.Vertices.Length);
|
||||
Assert.Equal(4, mesh.Vertices.Length);
|
||||
Assert.Equal(6, mesh.Indices.Length);
|
||||
}
|
||||
|
||||
@@ -97,10 +97,9 @@ public class ObjLoaderTests
|
||||
var mesh = ObjLoader.Load(path);
|
||||
|
||||
var normal = mesh.Vertices[0].Normal;
|
||||
// CW winding → normal points -Z
|
||||
Assert.Equal(0f, normal.X, 0.001f);
|
||||
Assert.Equal(0f, normal.Y, 0.001f);
|
||||
Assert.Equal(-1f, normal.Z, 0.001f);
|
||||
Assert.Equal(1f, normal.Z, 0.001f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the Vertex struct layout matches what the Vulkan vertex input description expects.
|
||||
/// The struct is { Vector3 Position, Vector3 Color, Vector3 Normal } = 9 floats = 36 bytes.
|
||||
/// </summary>
|
||||
public unsafe class VertexLayoutTests
|
||||
{
|
||||
[Fact]
|
||||
public void Vertex_Is_36_Bytes()
|
||||
{
|
||||
Assert.Equal(36, sizeof(Vertex));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Vertex_Has_Three_Vector3_Fields()
|
||||
{
|
||||
var v = new Vertex(
|
||||
new System.Numerics.Vector3(1, 2, 3),
|
||||
new System.Numerics.Vector3(4, 5, 6),
|
||||
new System.Numerics.Vector3(7, 8, 9));
|
||||
|
||||
Assert.Equal(1f, v.Position.X);
|
||||
Assert.Equal(2f, v.Position.Y);
|
||||
Assert.Equal(3f, v.Position.Z);
|
||||
Assert.Equal(4f, v.Color.X);
|
||||
Assert.Equal(5f, v.Color.Y);
|
||||
Assert.Equal(6f, v.Color.Z);
|
||||
Assert.Equal(7f, v.Normal.X);
|
||||
Assert.Equal(8f, v.Normal.Y);
|
||||
Assert.Equal(9f, v.Normal.Z);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Vertex_Position_At_Offset_0()
|
||||
{
|
||||
Assert.Equal(0, Marshal.OffsetOf<Vertex>("Position"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Vertex_Color_At_Offset_12()
|
||||
{
|
||||
Assert.Equal(12, Marshal.OffsetOf<Vertex>("Color"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Vertex_Normal_At_Offset_24()
|
||||
{
|
||||
Assert.Equal(24, Marshal.OffsetOf<Vertex>("Normal"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
using Engine.Graphics.Vulkan;
|
||||
|
||||
namespace Engine.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies Vulkan enum values match the C Vulkan spec (vk.xml).
|
||||
/// Wrong sType values caused the synchronization2 feature to not be enabled,
|
||||
/// and wrong access flag values caused validation errors.
|
||||
/// </summary>
|
||||
public class VulkanEnumValueTests
|
||||
{
|
||||
[Fact]
|
||||
public void VkResult_Success_Is_Zero()
|
||||
{
|
||||
Assert.Equal(0, (int)VkResult.Success);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkResult_ErrorOutOfDateKHR_Is_Negative()
|
||||
{
|
||||
Assert.True((int)VkResult.ErrorOutOfDateKHR < 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkResult_SuboptimalKHR_Is_Positive()
|
||||
{
|
||||
Assert.True((int)VkResult.SuboptimalKHR > 0);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VkStructureType.ApplicationInfo, 0)]
|
||||
[InlineData(VkStructureType.InstanceCreateInfo, 1)]
|
||||
[InlineData(VkStructureType.DeviceQueueCreateInfo, 2)]
|
||||
[InlineData(VkStructureType.DeviceCreateInfo, 3)]
|
||||
[InlineData(VkStructureType.MemoryAllocateInfo, 5)]
|
||||
[InlineData(VkStructureType.BufferCreateInfo, 12)]
|
||||
[InlineData(VkStructureType.ImageCreateInfo, 14)]
|
||||
[InlineData(VkStructureType.ImageViewCreateInfo, 15)]
|
||||
[InlineData(VkStructureType.ShaderModuleCreateInfo, 16)]
|
||||
[InlineData(VkStructureType.DescriptorSetLayoutCreateInfo, 32)]
|
||||
[InlineData(VkStructureType.DescriptorPoolCreateInfo, 33)]
|
||||
[InlineData(VkStructureType.DescriptorSetAllocateInfo, 34)]
|
||||
[InlineData(VkStructureType.WriteDescriptorSet, 35)]
|
||||
[InlineData(VkStructureType.PipelineLayoutCreateInfo, 30)]
|
||||
[InlineData(VkStructureType.GraphicsPipelineCreateInfo, 28)]
|
||||
[InlineData(VkStructureType.CommandPoolCreateInfo, 39)]
|
||||
[InlineData(VkStructureType.CommandBufferAllocateInfo, 40)]
|
||||
[InlineData(VkStructureType.CommandBufferBeginInfo, 42)]
|
||||
[InlineData(VkStructureType.SemaphoreCreateInfo, 9)]
|
||||
[InlineData(VkStructureType.FenceCreateInfo, 8)]
|
||||
public void VkStructureType_Core_Values_Match_Spec(VkStructureType sType, int expected)
|
||||
{
|
||||
Assert.Equal(expected, (int)sType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VkStructureType.SwapchainCreateInfoKHR, 1000001000)]
|
||||
[InlineData(VkStructureType.PresentInfoKHR, 1000001001)]
|
||||
[InlineData(VkStructureType.DebugUtilsMessengerCreateInfoEXT, 1000128004)]
|
||||
public void VkStructureType_Extension_Values_Match_Spec(VkStructureType sType, int expected)
|
||||
{
|
||||
Assert.Equal(expected, (int)sType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VkStructureType.RenderingInfo, 1000044000)]
|
||||
[InlineData(VkStructureType.RenderingAttachmentInfo, 1000044001)]
|
||||
[InlineData(VkStructureType.PipelineRenderingCreateInfo, 1000044002)]
|
||||
[InlineData(VkStructureType.PhysicalDeviceDynamicRenderingFeatures, 1000044003)]
|
||||
public void VkStructureType_DynamicRendering_Values_Match_Spec(VkStructureType sType, int expected)
|
||||
{
|
||||
Assert.Equal(expected, (int)sType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VkStructureType.ImageMemoryBarrier2, 1000314002)]
|
||||
[InlineData(VkStructureType.BufferMemoryBarrier2, 1000314001)]
|
||||
[InlineData(VkStructureType.DependencyInfo, 1000314003)]
|
||||
[InlineData(VkStructureType.SubmitInfo2, 1000314004)]
|
||||
[InlineData(VkStructureType.SemaphoreSubmitInfo, 1000314005)]
|
||||
[InlineData(VkStructureType.CommandBufferSubmitInfo, 1000314006)]
|
||||
public void VkStructureType_Sync2_Values_Match_Spec(VkStructureType sType, int expected)
|
||||
{
|
||||
Assert.Equal(expected, (int)sType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkStructureType_PhysicalDeviceSynchronization2Features_Matches_Spec()
|
||||
{
|
||||
Assert.Equal(1000314007, (int)VkStructureType.PhysicalDeviceSynchronization2Features);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VkFormat.Undefined, 0)]
|
||||
[InlineData(VkFormat.R8G8B8A8Unorm, 37)]
|
||||
[InlineData(VkFormat.B8G8R8A8Unorm, 44)]
|
||||
[InlineData(VkFormat.R8G8B8A8Srgb, 43)]
|
||||
[InlineData(VkFormat.B8G8R8A8Srgb, 50)]
|
||||
[InlineData(VkFormat.R32G32Sfloat, 103)]
|
||||
[InlineData(VkFormat.R32G32B32Sfloat, 106)]
|
||||
[InlineData(VkFormat.R32G32B32A32Sfloat, 109)]
|
||||
[InlineData(VkFormat.D32Sfloat, 126)]
|
||||
public void VkFormat_Values_Match_Spec(VkFormat format, int expected)
|
||||
{
|
||||
Assert.Equal(expected, (int)format);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VkPresentModeKHR.Immediate, 0)]
|
||||
[InlineData(VkPresentModeKHR.Mailbox, 1)]
|
||||
[InlineData(VkPresentModeKHR.Fifo, 2)]
|
||||
[InlineData(VkPresentModeKHR.FifoRelaxed, 3)]
|
||||
public void VkPresentModeKHR_Values_Match_Spec(VkPresentModeKHR mode, int expected)
|
||||
{
|
||||
Assert.Equal(expected, (int)mode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VkImageLayout.Undefined, 0)]
|
||||
[InlineData(VkImageLayout.General, 1)]
|
||||
[InlineData(VkImageLayout.ColorAttachmentOptimal, 2)]
|
||||
[InlineData(VkImageLayout.DepthStencilAttachmentOptimal, 3)]
|
||||
[InlineData(VkImageLayout.ShaderReadOnlyOptimal, 5)]
|
||||
[InlineData(VkImageLayout.TransferSrcOptimal, 6)]
|
||||
[InlineData(VkImageLayout.TransferDstOptimal, 7)]
|
||||
[InlineData(VkImageLayout.PresentSrcKHR, 1000001002)]
|
||||
public void VkImageLayout_Values_Match_Spec(VkImageLayout layout, int expected)
|
||||
{
|
||||
Assert.Equal(expected, (int)layout);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VkPrimitiveTopology.TriangleList, 3)]
|
||||
[InlineData(VkPrimitiveTopology.TriangleStrip, 4)]
|
||||
[InlineData(VkPrimitiveTopology.TriangleFan, 5)]
|
||||
[InlineData(VkPrimitiveTopology.PointList, 0)]
|
||||
[InlineData(VkPrimitiveTopology.LineList, 1)]
|
||||
public void VkPrimitiveTopology_Values_Match_Spec(VkPrimitiveTopology topology, int expected)
|
||||
{
|
||||
Assert.Equal(expected, (int)topology);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VkCompareOp.Never, 0)]
|
||||
[InlineData(VkCompareOp.Less, 1)]
|
||||
[InlineData(VkCompareOp.Equal, 2)]
|
||||
[InlineData(VkCompareOp.LessOrEqual, 3)]
|
||||
[InlineData(VkCompareOp.Greater, 4)]
|
||||
[InlineData(VkCompareOp.Always, 7)]
|
||||
public void VkCompareOp_Values_Match_Spec(VkCompareOp op, int expected)
|
||||
{
|
||||
Assert.Equal(expected, (int)op);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(VkDescriptorType.UniformBuffer, 6)]
|
||||
[InlineData(VkDescriptorType.StorageBuffer, 7)]
|
||||
[InlineData(VkDescriptorType.CombinedImageSampler, 1)]
|
||||
public void VkDescriptorType_Values_Match_Spec(VkDescriptorType type, int expected)
|
||||
{
|
||||
Assert.Equal(expected, (int)type);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies sync2 pipeline stage and access flag values match the C Vulkan spec.
|
||||
/// Wrong values here caused validation errors (TRANSFER_READ used instead of COLOR_ATTACHMENT_WRITE).
|
||||
/// </summary>
|
||||
public class VulkanSync2FlagTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData((ulong)VkPipelineStageFlags2.None, 0UL)]
|
||||
[InlineData((ulong)VkPipelineStageFlags2.ColorAttachmentOutput, 0x400UL)]
|
||||
[InlineData((ulong)VkPipelineStageFlags2.AllGraphics, 0x8000UL)]
|
||||
[InlineData((ulong)VkPipelineStageFlags2.Transfer, 0x1000UL)]
|
||||
public void VkPipelineStageFlags2_Values_Match_Spec(ulong value, ulong expected)
|
||||
{
|
||||
Assert.Equal(expected, value);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData((ulong)VkAccessFlags2.None, 0UL)]
|
||||
[InlineData((ulong)VkAccessFlags2.ColorAttachmentWrite, 0x100UL)]
|
||||
[InlineData((ulong)VkAccessFlags2.ColorAttachmentRead, 0x80UL)]
|
||||
[InlineData((ulong)VkAccessFlags2.TransferRead, 0x800UL)]
|
||||
[InlineData((ulong)VkAccessFlags2.TransferWrite, 0x1000UL)]
|
||||
public void VkAccessFlags2_Values_Match_Spec(ulong value, ulong expected)
|
||||
{
|
||||
Assert.Equal(expected, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Engine.Graphics.Vulkan;
|
||||
|
||||
namespace Engine.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies C# Vulkan struct sizes match the C Vulkan header sizes.
|
||||
/// Size mismatches were the root cause of multiple crashes during development.
|
||||
/// </summary>
|
||||
public unsafe class VulkanStructSizeTests
|
||||
{
|
||||
[Fact]
|
||||
public void VkExtent2D_Is_8_Bytes()
|
||||
{
|
||||
Assert.Equal(8, sizeof(VkExtent2D));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkExtent3D_Is_12_Bytes()
|
||||
{
|
||||
Assert.Equal(12, sizeof(VkExtent3D));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkOffset2D_Is_8_Bytes()
|
||||
{
|
||||
Assert.Equal(8, sizeof(VkOffset2D));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkOffset3D_Is_12_Bytes()
|
||||
{
|
||||
Assert.Equal(12, sizeof(VkOffset3D));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkRect2D_Is_16_Bytes()
|
||||
{
|
||||
Assert.Equal(16, sizeof(VkRect2D));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkViewport_Is_24_Bytes()
|
||||
{
|
||||
Assert.Equal(24, sizeof(VkViewport));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkClearValue_Is_16_Bytes()
|
||||
{
|
||||
Assert.Equal(16, sizeof(VkClearValue));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkApplicationInfo_Is_48_Bytes()
|
||||
{
|
||||
Assert.Equal(48, sizeof(VkApplicationInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkInstanceCreateInfo_Is_64_Bytes()
|
||||
{
|
||||
Assert.Equal(64, sizeof(VkInstanceCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkDeviceQueueCreateInfo_Is_40_Bytes()
|
||||
{
|
||||
Assert.Equal(40, sizeof(VkDeviceQueueCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkDeviceCreateInfo_Is_72_Bytes()
|
||||
{
|
||||
Assert.Equal(72, sizeof(VkDeviceCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkSwapchainCreateInfoKHR_Is_104_Bytes()
|
||||
{
|
||||
Assert.Equal(104, sizeof(VkSwapchainCreateInfoKHR));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkImageViewCreateInfo_Is_80_Bytes()
|
||||
{
|
||||
Assert.Equal(80, sizeof(VkImageViewCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkShaderModuleCreateInfo_Is_40_Bytes()
|
||||
{
|
||||
Assert.Equal(40, sizeof(VkShaderModuleCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkPipelineShaderStageCreateInfo_Is_48_Bytes()
|
||||
{
|
||||
Assert.Equal(48, sizeof(VkPipelineShaderStageCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkVertexInputBindingDescription_Is_12_Bytes()
|
||||
{
|
||||
Assert.Equal(12, sizeof(VkVertexInputBindingDescription));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkVertexInputAttributeDescription_Is_16_Bytes()
|
||||
{
|
||||
Assert.Equal(16, sizeof(VkVertexInputAttributeDescription));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkGraphicsPipelineCreateInfo_Is_144_Bytes()
|
||||
{
|
||||
Assert.Equal(144, sizeof(VkGraphicsPipelineCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkCommandBufferBeginInfo_Is_32_Bytes()
|
||||
{
|
||||
Assert.Equal(32, sizeof(VkCommandBufferBeginInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkBufferCreateInfo_Is_56_Bytes()
|
||||
{
|
||||
Assert.Equal(56, sizeof(VkBufferCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkMemoryAllocateInfo_Is_32_Bytes()
|
||||
{
|
||||
Assert.Equal(32, sizeof(VkMemoryAllocateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkMemoryRequirements_Is_24_Bytes()
|
||||
{
|
||||
Assert.Equal(24, sizeof(VkMemoryRequirements));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkBufferCopy_Is_24_Bytes()
|
||||
{
|
||||
Assert.Equal(24, sizeof(VkBufferCopy));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkPresentInfoKHR_Is_64_Bytes()
|
||||
{
|
||||
Assert.Equal(64, sizeof(VkPresentInfoKHR));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkSurfaceFormatKHR_Is_8_Bytes()
|
||||
{
|
||||
Assert.Equal(8, sizeof(VkSurfaceFormatKHR));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkSurfaceCapabilitiesKHR_Is_52_Bytes()
|
||||
{
|
||||
Assert.Equal(52, sizeof(VkSurfaceCapabilitiesKHR));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkQueueFamilyProperties_Is_24_Bytes()
|
||||
{
|
||||
Assert.Equal(24, sizeof(VkQueueFamilyProperties));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkMemoryType_Is_8_Bytes()
|
||||
{
|
||||
Assert.Equal(8, sizeof(VkMemoryType));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkMemoryHeap_Is_16_Bytes()
|
||||
{
|
||||
Assert.Equal(16, sizeof(VkMemoryHeap));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkPhysicalDeviceMemoryProperties_Is_520_Bytes()
|
||||
{
|
||||
Assert.Equal(520, sizeof(VkPhysicalDeviceMemoryProperties));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkPushConstantRange_Is_12_Bytes()
|
||||
{
|
||||
Assert.Equal(12, sizeof(VkPushConstantRange));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkDescriptorSetLayoutBinding_Is_24_Bytes()
|
||||
{
|
||||
Assert.Equal(24, sizeof(VkDescriptorSetLayoutBinding));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkDescriptorSetLayoutCreateInfo_Is_32_Bytes()
|
||||
{
|
||||
Assert.Equal(32, sizeof(VkDescriptorSetLayoutCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkDescriptorPoolSize_Is_8_Bytes()
|
||||
{
|
||||
Assert.Equal(8, sizeof(VkDescriptorPoolSize));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkDescriptorPoolCreateInfo_Is_40_Bytes()
|
||||
{
|
||||
Assert.Equal(40, sizeof(VkDescriptorPoolCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkDescriptorSetAllocateInfo_Is_40_Bytes()
|
||||
{
|
||||
Assert.Equal(40, sizeof(VkDescriptorSetAllocateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkDescriptorBufferInfo_Is_24_Bytes()
|
||||
{
|
||||
Assert.Equal(24, sizeof(VkDescriptorBufferInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkWriteDescriptorSet_Is_64_Bytes()
|
||||
{
|
||||
Assert.Equal(64, sizeof(VkWriteDescriptorSet));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkImageCreateInfo_Is_88_Bytes()
|
||||
{
|
||||
Assert.Equal(88, sizeof(VkImageCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkPipelineDepthStencilStateCreateInfo_Is_104_Bytes()
|
||||
{
|
||||
Assert.Equal(104, sizeof(VkPipelineDepthStencilStateCreateInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkStencilOpState_Is_28_Bytes()
|
||||
{
|
||||
Assert.Equal(28, sizeof(VkStencilOpState));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkImageMemoryBarrier2_Is_96_Bytes()
|
||||
{
|
||||
Assert.Equal(96, sizeof(VkImageMemoryBarrier2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkDependencyInfo_Is_64_Bytes()
|
||||
{
|
||||
Assert.Equal(64, sizeof(VkDependencyInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkSubmitInfo2_Is_64_Bytes()
|
||||
{
|
||||
Assert.Equal(64, sizeof(VkSubmitInfo2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkSemaphoreSubmitInfo_Is_48_Bytes()
|
||||
{
|
||||
Assert.Equal(48, sizeof(VkSemaphoreSubmitInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkCommandBufferSubmitInfo_Is_32_Bytes()
|
||||
{
|
||||
Assert.Equal(32, sizeof(VkCommandBufferSubmitInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkRenderingInfo_Is_72_Bytes()
|
||||
{
|
||||
Assert.Equal(72, sizeof(VkRenderingInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkRenderingAttachmentInfo_Is_72_Bytes()
|
||||
{
|
||||
Assert.Equal(72, sizeof(VkRenderingAttachmentInfo));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VkPipelineRenderingCreateInfo_Is_40_Bytes()
|
||||
{
|
||||
Assert.Equal(40, sizeof(VkPipelineRenderingCreateInfo));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user