gpu: convert Buffer from enum(usize) to *opaque

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-07-24 14:48:12 -07:00 committed by Stephen Gutekanst
parent 9b28403d9d
commit ca21c4fa80
3 changed files with 61 additions and 64 deletions

View file

@ -9,7 +9,7 @@ pub const BindGroup = *opaque {};
pub const BindGroupEntry = extern struct { pub const BindGroupEntry = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
binding: u32, binding: u32,
buffer: Buffer = Buffer.none, // nullable buffer: ?Buffer,
offset: u64, offset: u64,
size: u64, size: u64,
sampler: Sampler = Sampler.none, // nullable sampler: Sampler = Sampler.none, // nullable

View file

@ -1,6 +1,7 @@
const ChainedStruct = @import("types.zig").ChainedStruct; const ChainedStruct = @import("types.zig").ChainedStruct;
const ShaderStageFlags = @import("types.zig").ShaderStageFlags; const ShaderStageFlags = @import("types.zig").ShaderStageFlags;
const Buffer = @import("buffer.zig").Buffer; const Buffer = @import("buffer.zig").Buffer;
const BufferBindingLayout = @import("buffer.zig").BufferBindingLayout;
const Sampler = @import("sampler.zig").Sampler; const Sampler = @import("sampler.zig").Sampler;
const Texture = @import("texture.zig").Texture; const Texture = @import("texture.zig").Texture;
const StorageTextureBindingLayout = @import("types.zig").StorageTextureBindingLayout; const StorageTextureBindingLayout = @import("types.zig").StorageTextureBindingLayout;
@ -11,7 +12,7 @@ pub const BindGroupLayoutEntry = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
binding: u32, binding: u32,
visibility: ShaderStageFlags, visibility: ShaderStageFlags,
buffer: Buffer.BindingLayout, buffer: BufferBindingLayout,
sampler: Sampler.BindingLayout, sampler: Sampler.BindingLayout,
texture: Texture.BindingLayout, texture: Texture.BindingLayout,
storage_texture: StorageTextureBindingLayout, storage_texture: StorageTextureBindingLayout,

View file

@ -1,67 +1,63 @@
const std = @import("std"); const std = @import("std");
const ChainedStruct = @import("types.zig").ChainedStruct; const ChainedStruct = @import("types.zig").ChainedStruct;
pub const Buffer = enum(usize) { pub const Buffer = *opaque {};
_,
pub const none: Buffer = @intToEnum(Buffer, 0); pub const BufferBindingType = enum(u32) {
undef = 0x00000000,
pub const BindingType = enum(u32) { uniform = 0x00000001,
undef = 0x00000000, storage = 0x00000002,
uniform = 0x00000001, read_only_storage = 0x00000003,
storage = 0x00000002, };
read_only_storage = 0x00000003,
}; pub const BufferMapAsyncStatus = enum(u32) {
success = 0x00000000,
pub const MapAsyncStatus = enum(u32) { err = 0x00000001,
success = 0x00000000, unknown = 0x00000002,
err = 0x00000001, device_lost = 0x00000003,
unknown = 0x00000002, destroyed_before_callback = 0x00000004,
device_lost = 0x00000003, unmapped_before_callback = 0x00000005,
destroyed_before_callback = 0x00000004, };
unmapped_before_callback = 0x00000005,
}; pub const BufferUsage = packed struct {
map_read: bool = false,
pub const Usage = packed struct { map_write: bool = false,
map_read: bool = false, copy_src: bool = false,
map_write: bool = false, copy_dst: bool = false,
copy_src: bool = false, index: bool = false,
copy_dst: bool = false, vertex: bool = false,
index: bool = false, uniform: bool = false,
vertex: bool = false, storage: bool = false,
uniform: bool = false, indirect: bool = false,
storage: bool = false, query_resolve: bool = false,
indirect: bool = false,
query_resolve: bool = false, _padding: u22 = 0,
_padding: u22 = 0, comptime {
std.debug.assert(
comptime { @sizeOf(@This()) == @sizeOf(u32) and
std.debug.assert( @bitSizeOf(@This()) == @bitSizeOf(u32),
@sizeOf(@This()) == @sizeOf(u32) and );
@bitSizeOf(@This()) == @bitSizeOf(u32), }
);
} pub const none = BufferUsage{};
pub const none = Usage{}; pub fn equal(a: BufferUsage, b: BufferUsage) bool {
return @truncate(u10, @bitCast(u32, a)) == @truncate(u10, @bitCast(u32, b));
pub fn equal(a: Usage, b: Usage) bool { }
return @truncate(u10, @bitCast(u32, a)) == @truncate(u10, @bitCast(u32, b)); };
}
}; pub const BufferBindingLayout = extern struct {
next_in_chain: *const ChainedStruct,
pub const BindingLayout = extern struct { type: BufferBindingType,
next_in_chain: *const ChainedStruct, has_dynamic_offset: bool = false,
type: BindingType, min_binding_size: u64 = 0,
has_dynamic_offset: bool = false, };
min_binding_size: u64 = 0,
}; pub const BufferDescriptor = extern struct {
next_in_chain: *const ChainedStruct,
pub const Descriptor = extern struct { label: ?[*:0]const u8 = null,
next_in_chain: *const ChainedStruct, usage: BufferUsage,
label: ?[*:0]const u8 = null, size: u64,
usage: Usage, mapped_at_creation: bool,
size: u64,
mapped_at_creation: bool,
};
}; };