gpu: internalize Buffer types
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
e10432834b
commit
9ba109f659
4 changed files with 76 additions and 77 deletions
|
|
@ -4,6 +4,68 @@ const MapModeFlags = @import("types.zig").MapModeFlags;
|
|||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const Buffer = opaque {
|
||||
pub const MapCallback = fn (status: MapAsyncStatus, userdata: *anyopaque) callconv(.C) void;
|
||||
|
||||
pub const BindingType = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
uniform = 0x00000001,
|
||||
storage = 0x00000002,
|
||||
read_only_storage = 0x00000003,
|
||||
};
|
||||
|
||||
pub const MapAsyncStatus = enum(u32) {
|
||||
success = 0x00000000,
|
||||
err = 0x00000001,
|
||||
unknown = 0x00000002,
|
||||
device_lost = 0x00000003,
|
||||
destroyed_before_callback = 0x00000004,
|
||||
unmapped_before_callback = 0x00000005,
|
||||
};
|
||||
|
||||
// TODO: should be UsageFlags
|
||||
pub const Usage = packed struct {
|
||||
map_read: bool = false,
|
||||
map_write: bool = false,
|
||||
copy_src: bool = false,
|
||||
copy_dst: bool = false,
|
||||
index: bool = false,
|
||||
vertex: bool = false,
|
||||
uniform: bool = false,
|
||||
storage: bool = false,
|
||||
indirect: bool = false,
|
||||
query_resolve: bool = false,
|
||||
|
||||
_padding: u22 = 0,
|
||||
|
||||
comptime {
|
||||
std.debug.assert(
|
||||
@sizeOf(@This()) == @sizeOf(u32) and
|
||||
@bitSizeOf(@This()) == @bitSizeOf(u32),
|
||||
);
|
||||
}
|
||||
|
||||
pub const none = Usage{};
|
||||
|
||||
pub fn equal(a: Usage, b: Usage) bool {
|
||||
return @truncate(u10, @bitCast(u32, a)) == @truncate(u10, @bitCast(u32, b));
|
||||
}
|
||||
};
|
||||
|
||||
pub const BindingLayout = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
type: BindingType = .undef,
|
||||
has_dynamic_offset: bool = false,
|
||||
min_binding_size: u64 = 0,
|
||||
};
|
||||
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
usage: Usage,
|
||||
size: u64,
|
||||
mapped_at_creation: bool = true,
|
||||
};
|
||||
|
||||
pub inline fn destroy(buffer: *Buffer) void {
|
||||
Impl.bufferDestroy(buffer);
|
||||
}
|
||||
|
|
@ -24,11 +86,11 @@ pub const Buffer = opaque {
|
|||
return Impl.bufferGetSize(buffer);
|
||||
}
|
||||
|
||||
pub inline fn bufferGetUsage(buffer: *Buffer) BufferUsage {
|
||||
pub inline fn bufferGetUsage(buffer: *Buffer) Buffer.Usage {
|
||||
return Impl.bufferGetUsage(buffer);
|
||||
}
|
||||
|
||||
pub inline fn bufferMapAsync(buffer: *Buffer, mode: MapModeFlags, offset: usize, size: usize, callback: BufferMapCallback, userdata: *anyopaque) void {
|
||||
pub inline fn bufferMapAsync(buffer: *Buffer, mode: MapModeFlags, offset: usize, size: usize, callback: MapCallback, userdata: *anyopaque) void {
|
||||
Impl.bufferMapAsync(buffer, mode, offset, size, callback, userdata);
|
||||
}
|
||||
|
||||
|
|
@ -48,64 +110,3 @@ pub const Buffer = opaque {
|
|||
Impl.bufferRelease(buffer);
|
||||
}
|
||||
};
|
||||
|
||||
pub const BufferMapCallback = fn (status: BufferMapAsyncStatus, userdata: *anyopaque) callconv(.C) void;
|
||||
|
||||
pub const BufferBindingType = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
uniform = 0x00000001,
|
||||
storage = 0x00000002,
|
||||
read_only_storage = 0x00000003,
|
||||
};
|
||||
|
||||
pub const BufferMapAsyncStatus = enum(u32) {
|
||||
success = 0x00000000,
|
||||
err = 0x00000001,
|
||||
unknown = 0x00000002,
|
||||
device_lost = 0x00000003,
|
||||
destroyed_before_callback = 0x00000004,
|
||||
unmapped_before_callback = 0x00000005,
|
||||
};
|
||||
|
||||
pub const BufferUsage = packed struct {
|
||||
map_read: bool = false,
|
||||
map_write: bool = false,
|
||||
copy_src: bool = false,
|
||||
copy_dst: bool = false,
|
||||
index: bool = false,
|
||||
vertex: bool = false,
|
||||
uniform: bool = false,
|
||||
storage: bool = false,
|
||||
indirect: bool = false,
|
||||
query_resolve: bool = false,
|
||||
|
||||
_padding: u22 = 0,
|
||||
|
||||
comptime {
|
||||
std.debug.assert(
|
||||
@sizeOf(@This()) == @sizeOf(u32) and
|
||||
@bitSizeOf(@This()) == @bitSizeOf(u32),
|
||||
);
|
||||
}
|
||||
|
||||
pub const none = BufferUsage{};
|
||||
|
||||
pub fn equal(a: BufferUsage, b: BufferUsage) bool {
|
||||
return @truncate(u10, @bitCast(u32, a)) == @truncate(u10, @bitCast(u32, b));
|
||||
}
|
||||
};
|
||||
|
||||
pub const BufferBindingLayout = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
type: BufferBindingType = .undef,
|
||||
has_dynamic_offset: bool = false,
|
||||
min_binding_size: u64 = 0,
|
||||
};
|
||||
|
||||
pub const BufferDescriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
usage: BufferUsage,
|
||||
size: u64,
|
||||
mapped_at_creation: bool = true,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue