The root dir of our repository has grown quite a lot the past few months.
I'd like to make it more clear where the bulk of the engine lives (`src/`) and
also make it more clear which Mach libraries are consumable as standalone projects.
As for the name of this directory, `libs` was my first choice but there's a bit of
a convention of that being external libraries in Zig projects _today_, while these
are libraries maintained as part of Mach in this repository - not external ones.
We will name this directory `libs`, and if we have a need for external libraries
we will use `external` or `deps` for that directory name. I considered other names
such as `components`, `systems`, `modules` (which are bad as they overlap with
major ECS / engine concepts), and it seems likely the official Zig package manager
will break the convention of using a `libs` dir anyway.
Performed via:
```sh
mkdir libs/
git mv freetype libs/
git mv basisu libs/
git mv gamemode libs/
git mv glfw libs/
git mv gpu libs/
git mv gpu-dawn libs/
git mv sysaudio libs/
git mv sysjs libs/
git mv ecs libs/
```
git-subtree-dir: glfw
git-subtree-mainline: 0d5b853443
git-subtree-split: 572d1144f11b353abdb64fff828b25a4f0fbb7ca
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
git mv ecs libs/
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
149 lines
4.6 KiB
Zig
149 lines
4.6 KiB
Zig
const std = @import("std");
|
|
const ChainedStruct = @import("types.zig").ChainedStruct;
|
|
const MapModeFlags = @import("types.zig").MapModeFlags;
|
|
const Impl = @import("interface.zig").Impl;
|
|
|
|
pub const Buffer = opaque {
|
|
pub const MapCallback = if (@import("builtin").zig_backend == .stage1)
|
|
fn (status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void
|
|
else
|
|
*const 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,
|
|
};
|
|
|
|
pub const UsageFlags = 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 = UsageFlags{};
|
|
|
|
pub fn equal(a: UsageFlags, b: UsageFlags) 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: UsageFlags,
|
|
size: u64,
|
|
mapped_at_creation: bool = false,
|
|
};
|
|
|
|
pub inline fn destroy(buffer: *Buffer) void {
|
|
Impl.bufferDestroy(buffer);
|
|
}
|
|
|
|
/// Default `offset_bytes`: 0
|
|
/// Default `len`: `gpu.whole_map_size` / `std.math.maxint(usize)` (whole range)
|
|
pub inline fn getConstMappedRange(
|
|
buffer: *Buffer,
|
|
comptime T: type,
|
|
offset_bytes: usize,
|
|
len: usize,
|
|
) ?[]const T {
|
|
const size = @sizeOf(T) * len;
|
|
const data = Impl.bufferGetConstMappedRange(
|
|
buffer,
|
|
offset_bytes,
|
|
size + size % 4,
|
|
);
|
|
return if (data) |d| @ptrCast([*]const T, @alignCast(@alignOf(T), d))[0..len] else null;
|
|
}
|
|
|
|
/// Default `offset_bytes`: 0
|
|
/// Default `len`: `gpu.whole_map_size` / `std.math.maxint(usize)` (whole range)
|
|
pub inline fn getMappedRange(
|
|
buffer: *Buffer,
|
|
comptime T: type,
|
|
offset_bytes: usize,
|
|
len: usize,
|
|
) ?[]T {
|
|
const size = @sizeOf(T) * len;
|
|
const data = Impl.bufferGetMappedRange(
|
|
buffer,
|
|
offset_bytes,
|
|
size + size % 4,
|
|
);
|
|
return if (data) |d| @ptrCast([*]T, @alignCast(@alignOf(T), d))[0..len] else null;
|
|
}
|
|
|
|
pub inline fn getSize(buffer: *Buffer) u64 {
|
|
return Impl.bufferGetSize(buffer);
|
|
}
|
|
|
|
pub inline fn getUsage(buffer: *Buffer) Buffer.UsageFlags {
|
|
return Impl.bufferGetUsage(buffer);
|
|
}
|
|
|
|
pub inline fn mapAsync(
|
|
buffer: *Buffer,
|
|
mode: MapModeFlags,
|
|
offset: usize,
|
|
size: usize,
|
|
context: anytype,
|
|
comptime callback: fn (ctx: @TypeOf(context), status: MapAsyncStatus) callconv(.Inline) void,
|
|
) void {
|
|
const Context = @TypeOf(context);
|
|
const Helper = struct {
|
|
pub fn cCallback(status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void {
|
|
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), status);
|
|
}
|
|
};
|
|
Impl.bufferMapAsync(buffer, mode, offset, size, Helper.cCallback, if (Context == void) null else context);
|
|
}
|
|
|
|
pub inline fn setLabel(buffer: *Buffer, label: [*:0]const u8) void {
|
|
Impl.bufferSetLabel(buffer, label);
|
|
}
|
|
|
|
pub inline fn unmap(buffer: *Buffer) void {
|
|
Impl.bufferUnmap(buffer);
|
|
}
|
|
|
|
pub inline fn reference(buffer: *Buffer) void {
|
|
Impl.bufferReference(buffer);
|
|
}
|
|
|
|
pub inline fn release(buffer: *Buffer) void {
|
|
Impl.bufferRelease(buffer);
|
|
}
|
|
};
|