diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/glsl.zig | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/glsl.zig b/src/glsl.zig index a1cd2d6..974f566 100644 --- a/src/glsl.zig +++ b/src/glsl.zig @@ -98,12 +98,19 @@ pub fn generate(comptime root: type, comptime paths: []const []const u8, io: std } } +/// The most bytes a uniform block holds: what SDL_GPU's Vulkan backend +/// binds of one (its descriptors' range, MAX_UBO_SECTION_SIZE); a larger +/// block was cut off without a word (examples/live's two tapes met it). +pub const max_uniform_block = 4096; + /// Fails to compile unless `U` lays out exactly as a std140 uniform block /// with the same members in GLSL: scalars at 4 bytes, `vec2` at 8, -/// `vec3`/`vec4` at 16, arrays and nested structs at 16 with 16-byte strides. +/// `vec3`/`vec4` at 16, arrays and nested structs at 16 with 16-byte strides; +/// and fits `max_uniform_block`. pub fn assertStd140(comptime U: type) void { comptime { if (@typeInfo(U).@"struct".layout != .@"extern") @compileError(@typeName(U) ++ " must be extern to be a uniform block"); + if (@sizeOf(U) > max_uniform_block) @compileError(std.fmt.comptimePrint("{s} is {d} bytes: a uniform block is {d} at most (SDL_GPU's Vulkan backend binds 4 KiB of one, MAX_UBO_SECTION_SIZE, and the rest reads as nothing); put the rest in a storage buffer", .{ @typeName(U), @sizeOf(U), max_uniform_block })); const s = @typeInfo(U).@"struct"; for (s.field_names, s.field_types) |name, F| { const want = std140Align(F); @@ -136,6 +143,10 @@ fn std140Align(comptime T: type) usize { }; } +test "a uniform block of 4096 bytes is one (4112 fails to compile, as a lone check showed)" { + comptime assertStd140(extern struct { a: [256][4]f32 }); +} + test "uniform blocks and vertex inputs from structs" { const Root = struct { pub const Paint = extern struct { |
