renderer/metal: fix color bug on macOS 13 Intel.

See the associated test.
This commit is contained in:
Mitchell Hashimoto
2023-03-22 13:51:08 -07:00
parent 5f5700259f
commit 7ae200a1dc

View File

@ -83,13 +83,28 @@ texture_color: objc.Object, // MTLTexture
const GPUCell = extern struct { const GPUCell = extern struct {
mode: GPUCellMode, mode: GPUCellMode,
grid_pos: [2]f32, grid_pos: [2]f32,
cell_width: u8,
color: [4]u8,
glyph_pos: [2]u32 = .{ 0, 0 }, glyph_pos: [2]u32 = .{ 0, 0 },
glyph_size: [2]u32 = .{ 0, 0 }, glyph_size: [2]u32 = .{ 0, 0 },
glyph_offset: [2]i32 = .{ 0, 0 }, glyph_offset: [2]i32 = .{ 0, 0 },
color: [4]u8,
cell_width: u8,
}; };
// Intel macOS 13 doesn't like it when any field in a vertex buffer is not
// aligned on the alignment of the struct. I don't understand it, I think
// this must be some macOS 13 Metal GPU driver bug because it doesn't matter
// on macOS 12 or Apple Silicon macOS 13.
//
// To be safe, we put this test in here.
test "GPUCell offsets" {
const testing = std.testing;
const alignment = @alignOf(GPUCell);
inline for (@typeInfo(GPUCell).Struct.fields) |field| {
const offset = @offsetOf(GPUCell, field.name);
try testing.expectEqual(0, @mod(offset, alignment));
}
}
const GPUUniforms = extern struct { const GPUUniforms = extern struct {
/// The projection matrix for turning world coordinates to normalized. /// The projection matrix for turning world coordinates to normalized.
/// This is calculated based on the size of the screen. /// This is calculated based on the size of the screen.