From 1b6995d2dfcda799668834e9f645b4325f556a9e Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 8 May 2026 20:29:58 +0200 Subject: [PATCH] phase(N.5) Task 7 fixup: BatchData Pack=8 for ulong alignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code quality review caught that BatchData uses Pack=4 but contains a ulong field. With the current field order (TextureHandle first), offset 0 is always 8-byte aligned so std430 works. But adding a 4-byte field before TextureHandle without bumping Pack would silently misalign the GPU struct. Pack=8 makes the alignment requirement explicit and adds a comment documenting expected std430 offsets. No runtime change — current offsets (0/8/12) are identical under both Pack values for this field order. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/AcDream.App/Rendering/Wb/WbDrawDispatcher.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/AcDream.App/Rendering/Wb/WbDrawDispatcher.cs b/src/AcDream.App/Rendering/Wb/WbDrawDispatcher.cs index 07d33d1..d81360f 100644 --- a/src/AcDream.App/Rendering/Wb/WbDrawDispatcher.cs +++ b/src/AcDream.App/Rendering/Wb/WbDrawDispatcher.cs @@ -80,7 +80,13 @@ public sealed unsafe class WbDrawDispatcher : IDisposable private int _transparentByteOffset; #pragma warning restore CS0169 - [StructLayout(LayoutKind.Sequential, Pack = 4)] + // std430 layout: ulong TextureHandle (uvec2) at offset 0, uint TextureLayer + // at offset 8, uint Flags at offset 12. Total 16 bytes. + // Pack=8 (not 4) because std430's uvec2 requires 8-byte alignment — Pack=4 + // works today by accident (TextureHandle is the first field, so offset 0 is + // always 8-byte aligned), but adding a 4-byte field before TextureHandle + // without bumping Pack would silently misalign the GPU struct. + [StructLayout(LayoutKind.Sequential, Pack = 8)] private struct BatchData { public ulong TextureHandle; // bindless handle (uvec2 in GLSL)