all: move standalone libraries to libs/ subdirectory
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>
This commit is contained in:
parent
79ec61396f
commit
0645429df9
240 changed files with 6 additions and 6 deletions
109
libs/gpu/src/adapter.zig
Normal file
109
libs/gpu/src/adapter.zig
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const ChainedStructOut = @import("types.zig").ChainedStructOut;
|
||||
const Device = @import("device.zig").Device;
|
||||
const FeatureName = @import("types.zig").FeatureName;
|
||||
const SupportedLimits = @import("types.zig").SupportedLimits;
|
||||
const RequestDeviceStatus = @import("types.zig").RequestDeviceStatus;
|
||||
const BackendType = @import("types.zig").BackendType;
|
||||
const RequestDeviceCallback = @import("callbacks.zig").RequestDeviceCallback;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const Adapter = opaque {
|
||||
pub const Type = enum(u32) {
|
||||
discrete_gpu,
|
||||
integrated_gpu,
|
||||
cpu,
|
||||
unknown,
|
||||
|
||||
pub fn name(t: Type) []const u8 {
|
||||
return switch (t) {
|
||||
.discrete_gpu => "Discrete GPU",
|
||||
.integrated_gpu => "Integrated GPU",
|
||||
.cpu => "CPU",
|
||||
.unknown => "Unknown",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const Properties = extern struct {
|
||||
next_in_chain: ?*ChainedStructOut = null,
|
||||
vendor_id: u32,
|
||||
vendor_name: [*:0]const u8,
|
||||
architecture: [*:0]const u8,
|
||||
device_id: u32,
|
||||
name: [*:0]const u8,
|
||||
driver_description: [*:0]const u8,
|
||||
adapter_type: Type,
|
||||
backend_type: BackendType,
|
||||
};
|
||||
|
||||
pub inline fn createDevice(adapter: *Adapter, descriptor: ?*const Device.Descriptor) ?*Device {
|
||||
return Impl.adapterCreateDevice(adapter, descriptor);
|
||||
}
|
||||
|
||||
/// Call once with null to determine the array length, and again to fetch the feature list.
|
||||
///
|
||||
/// Consider using the enumerateFeaturesOwned helper.
|
||||
pub inline fn enumerateFeatures(adapter: *Adapter, features: ?[*]FeatureName) usize {
|
||||
return Impl.adapterEnumerateFeatures(adapter, features);
|
||||
}
|
||||
|
||||
/// Enumerates the adapter features, storing the result in an allocated slice which is owned by
|
||||
/// the caller.
|
||||
pub inline fn enumerateFeaturesOwned(adapter: *Adapter, allocator: std.mem.Allocator) ![]FeatureName {
|
||||
const count = adapter.enumerateFeatures(null);
|
||||
var data = try allocator.alloc(FeatureName, count);
|
||||
_ = adapter.enumerateFeatures(data.ptr);
|
||||
return data;
|
||||
}
|
||||
|
||||
pub inline fn getLimits(adapter: *Adapter, limits: *SupportedLimits) bool {
|
||||
return Impl.adapterGetLimits(adapter, limits);
|
||||
}
|
||||
|
||||
pub inline fn getProperties(adapter: *Adapter, properties: *Adapter.Properties) void {
|
||||
Impl.adapterGetProperties(adapter, properties);
|
||||
}
|
||||
|
||||
pub inline fn hasFeature(adapter: *Adapter, feature: FeatureName) bool {
|
||||
return Impl.adapterHasFeature(adapter, feature);
|
||||
}
|
||||
|
||||
pub inline fn requestDevice(
|
||||
adapter: *Adapter,
|
||||
descriptor: ?*const Device.Descriptor,
|
||||
context: anytype,
|
||||
comptime callback: fn (
|
||||
ctx: @TypeOf(context),
|
||||
status: RequestDeviceStatus,
|
||||
device: *Device,
|
||||
message: ?[*:0]const u8,
|
||||
) callconv(.Inline) void,
|
||||
) void {
|
||||
const Context = @TypeOf(context);
|
||||
const Helper = struct {
|
||||
pub fn cCallback(status: RequestDeviceStatus, device: *Device, message: ?[*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
||||
callback(
|
||||
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
||||
status,
|
||||
device,
|
||||
message,
|
||||
);
|
||||
}
|
||||
};
|
||||
Impl.adapterRequestDevice(adapter, descriptor, Helper.cCallback, if (Context == void) null else context);
|
||||
}
|
||||
|
||||
pub inline fn reference(adapter: *Adapter) void {
|
||||
Impl.adapterReference(adapter);
|
||||
}
|
||||
|
||||
pub inline fn release(adapter: *Adapter) void {
|
||||
Impl.adapterRelease(adapter);
|
||||
}
|
||||
};
|
||||
|
||||
test "Adapter.Type name" {
|
||||
try testing.expectEqualStrings("Discrete GPU", Adapter.Type.discrete_gpu.name());
|
||||
}
|
||||
88
libs/gpu/src/bind_group.zig
Normal file
88
libs/gpu/src/bind_group.zig
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
const Buffer = @import("buffer.zig").Buffer;
|
||||
const Sampler = @import("sampler.zig").Sampler;
|
||||
const TextureView = @import("texture_view.zig").TextureView;
|
||||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const BindGroupLayout = @import("bind_group_layout.zig").BindGroupLayout;
|
||||
const ExternalTexture = @import("external_texture.zig").ExternalTexture;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const BindGroup = opaque {
|
||||
pub const Entry = extern struct {
|
||||
pub const NextInChain = extern union {
|
||||
generic: ?*const ChainedStruct,
|
||||
external_texture_binding_entry: *const ExternalTexture.BindingEntry,
|
||||
};
|
||||
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
binding: u32,
|
||||
buffer: ?*Buffer = null,
|
||||
offset: u64 = 0,
|
||||
size: u64,
|
||||
sampler: ?*Sampler = null,
|
||||
texture_view: ?*TextureView = null,
|
||||
|
||||
/// Helper to create a buffer BindGroup.Entry.
|
||||
pub fn buffer(binding: u32, buf: *Buffer, offset: u64, size: u64) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.buffer = buf,
|
||||
.offset = offset,
|
||||
.size = size,
|
||||
};
|
||||
}
|
||||
|
||||
/// Helper to create a sampler BindGroup.Entry.
|
||||
pub fn sampler(binding: u32, _sampler: *Sampler) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.sampler = _sampler,
|
||||
.size = 0,
|
||||
};
|
||||
}
|
||||
|
||||
/// Helper to create a texture view BindGroup.Entry.
|
||||
pub fn textureView(binding: u32, texture_view: *TextureView) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.texture_view = texture_view,
|
||||
.size = 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
layout: *BindGroupLayout,
|
||||
entry_count: u32 = 0,
|
||||
entries: ?[*]const Entry = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
layout: *BindGroupLayout,
|
||||
entries: ?[]const Entry = null,
|
||||
}) Descriptor {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.label = v.label,
|
||||
.layout = v.layout,
|
||||
.entry_count = if (v.entries) |e| @intCast(u32, e.len) else 0,
|
||||
.entries = if (v.entries) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub inline fn setLabel(bind_group: *BindGroup, label: [*:0]const u8) void {
|
||||
Impl.bindGroupSetLabel(bind_group, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(bind_group: *BindGroup) void {
|
||||
Impl.bindGroupReference(bind_group);
|
||||
}
|
||||
|
||||
pub inline fn release(bind_group: *BindGroup) void {
|
||||
Impl.bindGroupRelease(bind_group);
|
||||
}
|
||||
};
|
||||
130
libs/gpu/src/bind_group_layout.zig
Normal file
130
libs/gpu/src/bind_group_layout.zig
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const ShaderStageFlags = @import("types.zig").ShaderStageFlags;
|
||||
const Buffer = @import("buffer.zig").Buffer;
|
||||
const Sampler = @import("sampler.zig").Sampler;
|
||||
const Texture = @import("texture.zig").Texture;
|
||||
const TextureView = @import("texture_view.zig").TextureView;
|
||||
const StorageTextureBindingLayout = @import("types.zig").StorageTextureBindingLayout;
|
||||
const StorageTextureAccess = @import("types.zig").StorageTextureAccess;
|
||||
const ExternalTexture = @import("external_texture.zig").ExternalTexture;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const BindGroupLayout = opaque {
|
||||
pub const Entry = extern struct {
|
||||
pub const NextInChain = extern union {
|
||||
generic: ?*const ChainedStruct,
|
||||
external_texture_binding_layout: *const ExternalTexture.BindingLayout,
|
||||
};
|
||||
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
buffer: Buffer.BindingLayout = .{},
|
||||
sampler: Sampler.BindingLayout = .{},
|
||||
texture: Texture.BindingLayout = .{},
|
||||
storage_texture: StorageTextureBindingLayout = .{},
|
||||
|
||||
/// Helper to create a buffer BindGroupLayout.Entry.
|
||||
pub fn buffer(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
binding_type: Buffer.BindingType,
|
||||
has_dynamic_offset: bool,
|
||||
min_binding_size: u64,
|
||||
) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.visibility = visibility,
|
||||
.buffer = .{
|
||||
.type = binding_type,
|
||||
.has_dynamic_offset = has_dynamic_offset,
|
||||
.min_binding_size = min_binding_size,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/// Helper to create a sampler BindGroupLayout.Entry.
|
||||
pub fn sampler(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
binding_type: Sampler.BindingType,
|
||||
) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.visibility = visibility,
|
||||
.sampler = .{ .type = binding_type },
|
||||
};
|
||||
}
|
||||
|
||||
/// Helper to create a texture BindGroupLayout.Entry.
|
||||
pub fn texture(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
sample_type: Texture.SampleType,
|
||||
view_dimension: TextureView.Dimension,
|
||||
multisampled: bool,
|
||||
) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.visibility = visibility,
|
||||
.texture = .{
|
||||
.sample_type = sample_type,
|
||||
.view_dimension = view_dimension,
|
||||
.multisampled = multisampled,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/// Helper to create a storage texture BindGroupLayout.Entry.
|
||||
pub fn storageTexture(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
access: StorageTextureAccess,
|
||||
format: Texture.Format,
|
||||
view_dimension: TextureView.Dimension,
|
||||
) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.visibility = visibility,
|
||||
.storage_texture = .{
|
||||
.access = access,
|
||||
.format = format,
|
||||
.view_dimension = view_dimension,
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
entry_count: u32 = 0,
|
||||
entries: ?[*]const Entry = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
entries: ?[]const Entry = null,
|
||||
}) Descriptor {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.label = v.label,
|
||||
.entry_count = if (v.entries) |e| @intCast(u32, e.len) else 0,
|
||||
.entries = if (v.entries) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub inline fn setLabel(bind_group_layout: *BindGroupLayout, label: [*:0]const u8) void {
|
||||
Impl.bindGroupLayoutSetLabel(bind_group_layout, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(bind_group_layout: *BindGroupLayout) void {
|
||||
Impl.bindGroupLayoutReference(bind_group_layout);
|
||||
}
|
||||
|
||||
pub inline fn release(bind_group_layout: *BindGroupLayout) void {
|
||||
Impl.bindGroupLayoutRelease(bind_group_layout);
|
||||
}
|
||||
};
|
||||
149
libs/gpu/src/buffer.zig
Normal file
149
libs/gpu/src/buffer.zig
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
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);
|
||||
}
|
||||
};
|
||||
110
libs/gpu/src/callbacks.zig
Normal file
110
libs/gpu/src/callbacks.zig
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
const CompilationInfoRequestStatus = @import("types.zig").CompilationInfoRequestStatus;
|
||||
const CompilationInfo = @import("types.zig").CompilationInfo;
|
||||
const ErrorType = @import("types.zig").ErrorType;
|
||||
const LoggingType = @import("types.zig").LoggingType;
|
||||
const RequestDeviceStatus = @import("types.zig").RequestDeviceStatus;
|
||||
const RequestAdapterStatus = @import("types.zig").RequestAdapterStatus;
|
||||
const CreatePipelineAsyncStatus = @import("types.zig").CreatePipelineAsyncStatus;
|
||||
const Device = @import("device.zig").Device;
|
||||
const Adapter = @import("adapter.zig").Adapter;
|
||||
const ComputePipeline = @import("compute_pipeline.zig").ComputePipeline;
|
||||
const RenderPipeline = @import("render_pipeline.zig").RenderPipeline;
|
||||
|
||||
pub const CompilationInfoCallback = if (@import("builtin").zig_backend == .stage1)
|
||||
fn (
|
||||
status: CompilationInfoRequestStatus,
|
||||
compilation_info: *const CompilationInfo,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void
|
||||
else
|
||||
*const fn (
|
||||
status: CompilationInfoRequestStatus,
|
||||
compilation_info: *const CompilationInfo,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void;
|
||||
|
||||
pub const ErrorCallback = if (@import("builtin").zig_backend == .stage1)
|
||||
fn (
|
||||
typ: ErrorType,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void
|
||||
else
|
||||
*const fn (
|
||||
typ: ErrorType,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void;
|
||||
|
||||
pub const LoggingCallback = if (@import("builtin").zig_backend == .stage1)
|
||||
fn (
|
||||
typ: LoggingType,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void
|
||||
else
|
||||
*const fn (
|
||||
typ: LoggingType,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void;
|
||||
|
||||
pub const RequestDeviceCallback = if (@import("builtin").zig_backend == .stage1)
|
||||
fn (
|
||||
status: RequestDeviceStatus,
|
||||
device: *Device,
|
||||
message: ?[*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void
|
||||
else
|
||||
*const fn (
|
||||
status: RequestDeviceStatus,
|
||||
device: *Device,
|
||||
message: ?[*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void;
|
||||
|
||||
pub const RequestAdapterCallback = if (@import("builtin").zig_backend == .stage1)
|
||||
fn (
|
||||
status: RequestAdapterStatus,
|
||||
adapter: *Adapter,
|
||||
message: ?[*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void
|
||||
else
|
||||
*const fn (
|
||||
status: RequestAdapterStatus,
|
||||
adapter: *Adapter,
|
||||
message: ?[*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void;
|
||||
|
||||
pub const CreateComputePipelineAsyncCallback = if (@import("builtin").zig_backend == .stage1)
|
||||
fn (
|
||||
status: CreatePipelineAsyncStatus,
|
||||
compute_pipeline: *ComputePipeline,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void
|
||||
else
|
||||
*const fn (
|
||||
status: CreatePipelineAsyncStatus,
|
||||
compute_pipeline: *ComputePipeline,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void;
|
||||
|
||||
pub const CreateRenderPipelineAsyncCallback = if (@import("builtin").zig_backend == .stage1)
|
||||
fn (
|
||||
status: CreatePipelineAsyncStatus,
|
||||
pipeline: *RenderPipeline,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void
|
||||
else
|
||||
*const fn (
|
||||
status: CreatePipelineAsyncStatus,
|
||||
pipeline: *RenderPipeline,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void;
|
||||
21
libs/gpu/src/command_buffer.zig
Normal file
21
libs/gpu/src/command_buffer.zig
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const CommandBuffer = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
};
|
||||
|
||||
pub inline fn setLabel(command_buffer: *CommandBuffer, label: [*:0]const u8) void {
|
||||
Impl.commandBufferSetLabel(command_buffer, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(command_buffer: *CommandBuffer) void {
|
||||
Impl.commandBufferReference(command_buffer);
|
||||
}
|
||||
|
||||
pub inline fn release(command_buffer: *CommandBuffer) void {
|
||||
Impl.commandBufferRelease(command_buffer);
|
||||
}
|
||||
};
|
||||
118
libs/gpu/src/command_encoder.zig
Normal file
118
libs/gpu/src/command_encoder.zig
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
const std = @import("std");
|
||||
const ComputePassEncoder = @import("compute_pass_encoder.zig").ComputePassEncoder;
|
||||
const RenderPassEncoder = @import("render_pass_encoder.zig").RenderPassEncoder;
|
||||
const CommandBuffer = @import("command_buffer.zig").CommandBuffer;
|
||||
const Buffer = @import("buffer.zig").Buffer;
|
||||
const QuerySet = @import("query_set.zig").QuerySet;
|
||||
const RenderPassDescriptor = @import("types.zig").RenderPassDescriptor;
|
||||
const ComputePassDescriptor = @import("types.zig").ComputePassDescriptor;
|
||||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const ImageCopyBuffer = @import("types.zig").ImageCopyBuffer;
|
||||
const ImageCopyTexture = @import("types.zig").ImageCopyTexture;
|
||||
const Extent3D = @import("types.zig").Extent3D;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
const dawn = @import("dawn.zig");
|
||||
|
||||
pub const CommandEncoder = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
pub const NextInChain = extern union {
|
||||
generic: ?*const ChainedStruct,
|
||||
dawn_encoder_internal_usage_descriptor: *const dawn.EncoderInternalUsageDescriptor,
|
||||
};
|
||||
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
label: ?[*:0]const u8 = null,
|
||||
};
|
||||
|
||||
pub inline fn beginComputePass(command_encoder: *CommandEncoder, descriptor: ?*const ComputePassDescriptor) *ComputePassEncoder {
|
||||
return Impl.commandEncoderBeginComputePass(command_encoder, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn beginRenderPass(command_encoder: *CommandEncoder, descriptor: *const RenderPassDescriptor) *RenderPassEncoder {
|
||||
return Impl.commandEncoderBeginRenderPass(command_encoder, descriptor);
|
||||
}
|
||||
|
||||
/// Default `offset`: 0
|
||||
/// Default `size`: `gpu.whole_size`
|
||||
pub inline fn clearBuffer(command_encoder: *CommandEncoder, buffer: *Buffer, offset: u64, size: u64) void {
|
||||
Impl.commandEncoderClearBuffer(command_encoder, buffer, offset, size);
|
||||
}
|
||||
|
||||
pub inline fn copyBufferToBuffer(command_encoder: *CommandEncoder, source: *Buffer, source_offset: u64, destination: *Buffer, destination_offset: u64, size: u64) void {
|
||||
Impl.commandEncoderCopyBufferToBuffer(command_encoder, source, source_offset, destination, destination_offset, size);
|
||||
}
|
||||
|
||||
pub inline fn copyBufferToTexture(command_encoder: *CommandEncoder, source: *const ImageCopyBuffer, destination: *const ImageCopyTexture, copy_size: *const Extent3D) void {
|
||||
Impl.commandEncoderCopyBufferToTexture(command_encoder, source, destination, copy_size);
|
||||
}
|
||||
|
||||
pub inline fn copyTextureToBuffer(command_encoder: *CommandEncoder, source: *const ImageCopyTexture, destination: *const ImageCopyBuffer, copy_size: *const Extent3D) void {
|
||||
Impl.commandEncoderCopyTextureToBuffer(command_encoder, source, destination, copy_size);
|
||||
}
|
||||
|
||||
pub inline fn copyTextureToTexture(command_encoder: *CommandEncoder, source: *const ImageCopyTexture, destination: *const ImageCopyTexture, copy_size: *const Extent3D) void {
|
||||
Impl.commandEncoderCopyTextureToTexture(command_encoder, source, destination, copy_size);
|
||||
}
|
||||
|
||||
// Note: the only difference between this and the non-internal variant is that this one checks
|
||||
// internal usage.
|
||||
pub inline fn copyTextureToTextureInternal(command_encoder: *CommandEncoder, source: *const ImageCopyTexture, destination: *const ImageCopyTexture, copy_size: *const Extent3D) void {
|
||||
Impl.commandEncoderCopyTextureToTextureInternal(command_encoder, source, destination, copy_size);
|
||||
}
|
||||
|
||||
pub inline fn finish(command_encoder: *CommandEncoder, descriptor: ?*const CommandBuffer.Descriptor) *CommandBuffer {
|
||||
return Impl.commandEncoderFinish(command_encoder, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn injectValidationError(command_encoder: *CommandEncoder, message: [*:0]const u8) void {
|
||||
Impl.commandEncoderInjectValidationError(command_encoder, message);
|
||||
}
|
||||
|
||||
pub inline fn insertDebugMarker(command_encoder: *CommandEncoder, marker_label: [*:0]const u8) void {
|
||||
Impl.commandEncoderInsertDebugMarker(command_encoder, marker_label);
|
||||
}
|
||||
|
||||
pub inline fn popDebugGroup(command_encoder: *CommandEncoder) void {
|
||||
Impl.commandEncoderPopDebugGroup(command_encoder);
|
||||
}
|
||||
|
||||
pub inline fn pushDebugGroup(command_encoder: *CommandEncoder, group_label: [*:0]const u8) void {
|
||||
Impl.commandEncoderPushDebugGroup(command_encoder, group_label);
|
||||
}
|
||||
|
||||
pub inline fn resolveQuerySet(command_encoder: *CommandEncoder, query_set: *QuerySet, first_query: u32, query_count: u32, destination: *Buffer, destination_offset: u64) void {
|
||||
Impl.commandEncoderResolveQuerySet(command_encoder, query_set, first_query, query_count, destination, destination_offset);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(command_encoder: *CommandEncoder, label: [*:0]const u8) void {
|
||||
Impl.commandEncoderSetLabel(command_encoder, label);
|
||||
}
|
||||
|
||||
pub inline fn writeBuffer(
|
||||
command_encoder: *CommandEncoder,
|
||||
buffer: *Buffer,
|
||||
buffer_offset_bytes: u64,
|
||||
data_span: anytype,
|
||||
) void {
|
||||
const data_slice = std.mem.span(data_span);
|
||||
Impl.commandEncoderWriteBuffer(
|
||||
command_encoder,
|
||||
buffer,
|
||||
buffer_offset_bytes,
|
||||
@ptrCast([*]const u8, data_slice.ptr),
|
||||
@intCast(u64, data_slice.len) * @sizeOf(std.meta.Elem(@TypeOf(data_slice))),
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn writeTimestamp(command_encoder: *CommandEncoder, query_set: *QuerySet, query_index: u32) void {
|
||||
Impl.commandEncoderWriteTimestamp(command_encoder, query_set, query_index);
|
||||
}
|
||||
|
||||
pub inline fn reference(command_encoder: *CommandEncoder) void {
|
||||
Impl.commandEncoderReference(command_encoder);
|
||||
}
|
||||
|
||||
pub inline fn release(command_encoder: *CommandEncoder) void {
|
||||
Impl.commandEncoderRelease(command_encoder);
|
||||
}
|
||||
};
|
||||
64
libs/gpu/src/compute_pass_encoder.zig
Normal file
64
libs/gpu/src/compute_pass_encoder.zig
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
const Buffer = @import("buffer.zig").Buffer;
|
||||
const BindGroup = @import("bind_group.zig").BindGroup;
|
||||
const ComputePipeline = @import("compute_pipeline.zig").ComputePipeline;
|
||||
const QuerySet = @import("query_set.zig").QuerySet;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const ComputePassEncoder = opaque {
|
||||
/// Default `workgroup_count_y`: 1
|
||||
/// Default `workgroup_count_z`: 1
|
||||
pub inline fn dispatchWorkgroups(compute_pass_encoder: *ComputePassEncoder, workgroup_count_x: u32, workgroup_count_y: u32, workgroup_count_z: u32) void {
|
||||
Impl.computePassEncoderDispatchWorkgroups(compute_pass_encoder, workgroup_count_x, workgroup_count_y, workgroup_count_z);
|
||||
}
|
||||
|
||||
pub inline fn dispatchWorkgroupsIndirect(compute_pass_encoder: *ComputePassEncoder, indirect_buffer: *Buffer, indirect_offset: u64) void {
|
||||
Impl.computePassEncoderDispatchWorkgroupsIndirect(compute_pass_encoder, indirect_buffer, indirect_offset);
|
||||
}
|
||||
|
||||
pub inline fn end(compute_pass_encoder: *ComputePassEncoder) void {
|
||||
Impl.computePassEncoderEnd(compute_pass_encoder);
|
||||
}
|
||||
|
||||
pub inline fn insertDebugMarker(compute_pass_encoder: *ComputePassEncoder, marker_label: [*:0]const u8) void {
|
||||
Impl.computePassEncoderInsertDebugMarker(compute_pass_encoder, marker_label);
|
||||
}
|
||||
|
||||
pub inline fn popDebugGroup(compute_pass_encoder: *ComputePassEncoder) void {
|
||||
Impl.computePassEncoderPopDebugGroup(compute_pass_encoder);
|
||||
}
|
||||
|
||||
pub inline fn pushDebugGroup(compute_pass_encoder: *ComputePassEncoder, group_label: [*:0]const u8) void {
|
||||
Impl.computePassEncoderPushDebugGroup(compute_pass_encoder, group_label);
|
||||
}
|
||||
|
||||
/// Default `dynamic_offsets`: null
|
||||
pub inline fn setBindGroup(compute_pass_encoder: *ComputePassEncoder, group_index: u32, group: *BindGroup, dynamic_offsets: ?[]const u32) void {
|
||||
Impl.computePassEncoderSetBindGroup(
|
||||
compute_pass_encoder,
|
||||
group_index,
|
||||
group,
|
||||
if (dynamic_offsets) |v| @intCast(u32, v.len) else 0,
|
||||
if (dynamic_offsets) |v| v.ptr else null,
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(compute_pass_encoder: *ComputePassEncoder, label: [*:0]const u8) void {
|
||||
Impl.computePassEncoderSetLabel(compute_pass_encoder, label);
|
||||
}
|
||||
|
||||
pub inline fn setPipeline(compute_pass_encoder: *ComputePassEncoder, pipeline: *ComputePipeline) void {
|
||||
Impl.computePassEncoderSetPipeline(compute_pass_encoder, pipeline);
|
||||
}
|
||||
|
||||
pub inline fn writeTimestamp(compute_pass_encoder: *ComputePassEncoder, query_set: *QuerySet, query_index: u32) void {
|
||||
Impl.computePassEncoderWriteTimestamp(compute_pass_encoder, query_set, query_index);
|
||||
}
|
||||
|
||||
pub inline fn reference(compute_pass_encoder: *ComputePassEncoder) void {
|
||||
Impl.computePassEncoderReference(compute_pass_encoder);
|
||||
}
|
||||
|
||||
pub inline fn release(compute_pass_encoder: *ComputePassEncoder) void {
|
||||
Impl.computePassEncoderRelease(compute_pass_encoder);
|
||||
}
|
||||
};
|
||||
30
libs/gpu/src/compute_pipeline.zig
Normal file
30
libs/gpu/src/compute_pipeline.zig
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const ProgrammableStageDescriptor = @import("types.zig").ProgrammableStageDescriptor;
|
||||
const PipelineLayout = @import("pipeline_layout.zig").PipelineLayout;
|
||||
const BindGroupLayout = @import("bind_group_layout.zig").BindGroupLayout;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const ComputePipeline = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
layout: ?*PipelineLayout = null,
|
||||
compute: ProgrammableStageDescriptor,
|
||||
};
|
||||
|
||||
pub inline fn getBindGroupLayout(compute_pipeline: *ComputePipeline, group_index: u32) *BindGroupLayout {
|
||||
return Impl.computePipelineGetBindGroupLayout(compute_pipeline, group_index);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(compute_pipeline: *ComputePipeline, label: [*:0]const u8) void {
|
||||
Impl.computePipelineSetLabel(compute_pipeline, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(compute_pipeline: *ComputePipeline) void {
|
||||
Impl.computePipelineReference(compute_pipeline);
|
||||
}
|
||||
|
||||
pub inline fn release(compute_pipeline: *ComputePipeline) void {
|
||||
Impl.computePipelineRelease(compute_pipeline);
|
||||
}
|
||||
};
|
||||
59
libs/gpu/src/dawn.zig
Normal file
59
libs/gpu/src/dawn.zig
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const Texture = @import("texture.zig").Texture;
|
||||
pub const Interface = @import("dawn_impl.zig").Interface;
|
||||
|
||||
pub const CacheDeviceDescriptor = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .dawn_cache_device_descriptor },
|
||||
isolation_key: [*:0]const u8 = "",
|
||||
};
|
||||
|
||||
pub const EncoderInternalUsageDescriptor = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .dawn_encoder_internal_usage_descriptor },
|
||||
use_internal_usages: bool = false,
|
||||
};
|
||||
|
||||
pub const InstanceDescriptor = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .dawn_instance_descriptor },
|
||||
additional_runtime_search_paths_count: u32 = 0,
|
||||
additional_runtime_search_paths: ?[*]const u8 = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .dawn_instance_descriptor },
|
||||
additional_runtime_search_paths: ?[]const u8 = null,
|
||||
}) InstanceDescriptor {
|
||||
return .{
|
||||
.chain = v.chain,
|
||||
.additional_runtime_search_paths_count = if (v.additional_runtime_search_paths) |e| @intCast(u32, e.len) else 0,
|
||||
.additional_runtime_search_paths = if (v.additional_runtime_search_paths) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const TextureInternalUsageDescriptor = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .dawn_texture_internal_usage_descriptor },
|
||||
internal_usage: Texture.UsageFlags = Texture.UsageFlags.none,
|
||||
};
|
||||
|
||||
pub const TogglesDeviceDescriptor = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .dawn_toggles_device_descriptor },
|
||||
force_enabled_toggles_count: u32 = 0,
|
||||
force_enabled_toggles: ?[*]const u8 = null,
|
||||
force_disabled_toggles_count: u32 = 0,
|
||||
force_disabled_toggles: ?[*]const u8 = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .dawn_toggles_device_descriptor },
|
||||
force_enabled_toggles: ?[]const u8 = null,
|
||||
force_disabled_toggles: ?[]const u8 = null,
|
||||
}) TogglesDeviceDescriptor {
|
||||
return .{
|
||||
.chain = v.chain,
|
||||
.force_enabled_toggles_count = if (v.force_enabled_toggles) |e| @intCast(u32, e.len) else 0,
|
||||
.force_enabled_toggles = if (v.force_enabled_toggles) |e| e.ptr else null,
|
||||
.force_disabled_toggles_count = if (v.force_disabled_toggles) |e| @intCast(u32, e.len) else 0,
|
||||
.force_disabled_toggles = if (v.force_disabled_toggles) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
1224
libs/gpu/src/dawn_impl.zig
Normal file
1224
libs/gpu/src/dawn_impl.zig
Normal file
File diff suppressed because it is too large
Load diff
2874
libs/gpu/src/dawn_webgpu_h.zig
Normal file
2874
libs/gpu/src/dawn_webgpu_h.zig
Normal file
File diff suppressed because it is too large
Load diff
353
libs/gpu/src/device.zig
Normal file
353
libs/gpu/src/device.zig
Normal file
|
|
@ -0,0 +1,353 @@
|
|||
const std = @import("std");
|
||||
const Queue = @import("queue.zig").Queue;
|
||||
const BindGroup = @import("bind_group.zig").BindGroup;
|
||||
const BindGroupLayout = @import("bind_group_layout.zig").BindGroupLayout;
|
||||
const Buffer = @import("buffer.zig").Buffer;
|
||||
const CommandEncoder = @import("command_encoder.zig").CommandEncoder;
|
||||
const ComputePipeline = @import("compute_pipeline.zig").ComputePipeline;
|
||||
const ExternalTexture = @import("external_texture.zig").ExternalTexture;
|
||||
const PipelineLayout = @import("pipeline_layout.zig").PipelineLayout;
|
||||
const QuerySet = @import("query_set.zig").QuerySet;
|
||||
const RenderBundleEncoder = @import("render_bundle_encoder.zig").RenderBundleEncoder;
|
||||
const RenderPipeline = @import("render_pipeline.zig").RenderPipeline;
|
||||
const Sampler = @import("sampler.zig").Sampler;
|
||||
const ShaderModule = @import("shader_module.zig").ShaderModule;
|
||||
const Surface = @import("surface.zig").Surface;
|
||||
const SwapChain = @import("swap_chain.zig").SwapChain;
|
||||
const Texture = @import("texture.zig").Texture;
|
||||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const FeatureName = @import("types.zig").FeatureName;
|
||||
const RequiredLimits = @import("types.zig").RequiredLimits;
|
||||
const SupportedLimits = @import("types.zig").SupportedLimits;
|
||||
const ErrorType = @import("types.zig").ErrorType;
|
||||
const ErrorFilter = @import("types.zig").ErrorFilter;
|
||||
const LoggingType = @import("types.zig").LoggingType;
|
||||
const CreatePipelineAsyncStatus = @import("types.zig").CreatePipelineAsyncStatus;
|
||||
const LoggingCallback = @import("callbacks.zig").LoggingCallback;
|
||||
const ErrorCallback = @import("callbacks.zig").ErrorCallback;
|
||||
const CreateComputePipelineAsyncCallback = @import("callbacks.zig").CreateComputePipelineAsyncCallback;
|
||||
const CreateRenderPipelineAsyncCallback = @import("callbacks.zig").CreateRenderPipelineAsyncCallback;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
const dawn = @import("dawn.zig");
|
||||
|
||||
pub const Device = opaque {
|
||||
pub const LostCallback = if (@import("builtin").zig_backend == .stage1)
|
||||
fn (
|
||||
reason: LostReason,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void
|
||||
else
|
||||
*const fn (
|
||||
reason: LostReason,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void;
|
||||
|
||||
pub const LostReason = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
destroyed = 0x00000001,
|
||||
};
|
||||
|
||||
pub const Descriptor = extern struct {
|
||||
pub const NextInChain = extern union {
|
||||
generic: ?*const ChainedStruct,
|
||||
dawn_toggles_device_descriptor: *const dawn.TogglesDeviceDescriptor,
|
||||
dawn_cache_device_descriptor: *const dawn.CacheDeviceDescriptor,
|
||||
};
|
||||
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
label: ?[*:0]const u8 = null,
|
||||
required_features_count: u32 = 0,
|
||||
required_features: ?[*]const FeatureName = null,
|
||||
required_limits: ?*const RequiredLimits = null,
|
||||
default_queue: Queue.Descriptor = Queue.Descriptor{},
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
label: ?[*:0]const u8 = null,
|
||||
required_features: ?[]const FeatureName = null,
|
||||
required_limits: ?*const RequiredLimits = null,
|
||||
default_queue: Queue.Descriptor = Queue.Descriptor{},
|
||||
}) Descriptor {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.label = v.label,
|
||||
.required_features_count = if (v.required_features) |e| @intCast(u32, e.len) else 0,
|
||||
.required_features = if (v.required_features) |e| e.ptr else null,
|
||||
.default_queue = v.default_queue,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub inline fn createBindGroup(device: *Device, descriptor: *const BindGroup.Descriptor) *BindGroup {
|
||||
return Impl.deviceCreateBindGroup(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createBindGroupLayout(device: *Device, descriptor: *const BindGroupLayout.Descriptor) *BindGroupLayout {
|
||||
return Impl.deviceCreateBindGroupLayout(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createBuffer(device: *Device, descriptor: *const Buffer.Descriptor) *Buffer {
|
||||
return Impl.deviceCreateBuffer(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createCommandEncoder(device: *Device, descriptor: ?*const CommandEncoder.Descriptor) *CommandEncoder {
|
||||
return Impl.deviceCreateCommandEncoder(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createComputePipeline(device: *Device, descriptor: *const ComputePipeline.Descriptor) *ComputePipeline {
|
||||
return Impl.deviceCreateComputePipeline(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createComputePipelineAsync(
|
||||
device: *Device,
|
||||
descriptor: *const ComputePipeline.Descriptor,
|
||||
context: anytype,
|
||||
comptime callback: fn (
|
||||
status: CreatePipelineAsyncStatus,
|
||||
compute_pipeline: *ComputePipeline,
|
||||
message: [*:0]const u8,
|
||||
ctx: @TypeOf(context),
|
||||
) callconv(.Inline) void,
|
||||
) void {
|
||||
const Context = @TypeOf(context);
|
||||
const Helper = struct {
|
||||
pub fn cCallback(
|
||||
status: CreatePipelineAsyncStatus,
|
||||
compute_pipeline: *ComputePipeline,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
callback(
|
||||
status,
|
||||
compute_pipeline,
|
||||
message,
|
||||
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
||||
);
|
||||
}
|
||||
};
|
||||
Impl.deviceCreateComputePipelineAsync(device, descriptor, Helper.cCallback, if (Context == void) null else context);
|
||||
}
|
||||
|
||||
pub inline fn createErrorBuffer(device: *Device) *Buffer {
|
||||
return Impl.deviceCreateErrorBuffer(device);
|
||||
}
|
||||
|
||||
pub inline fn createErrorExternalTexture(device: *Device) *ExternalTexture {
|
||||
return Impl.deviceCreateErrorExternalTexture(device);
|
||||
}
|
||||
|
||||
pub inline fn createErrorTexture(device: *Device, descriptor: *const Texture.Descriptor) *Texture {
|
||||
return Impl.deviceCreateErrorTexture(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createExternalTexture(device: *Device, external_texture_descriptor: *const ExternalTexture.Descriptor) *ExternalTexture {
|
||||
return Impl.deviceCreateExternalTexture(device, external_texture_descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createPipelineLayout(device: *Device, pipeline_layout_descriptor: *const PipelineLayout.Descriptor) *PipelineLayout {
|
||||
return Impl.deviceCreatePipelineLayout(device, pipeline_layout_descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createQuerySet(device: *Device, descriptor: *const QuerySet.Descriptor) *QuerySet {
|
||||
return Impl.deviceCreateQuerySet(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createRenderBundleEncoder(device: *Device, descriptor: *const RenderBundleEncoder.Descriptor) *RenderBundleEncoder {
|
||||
return Impl.deviceCreateRenderBundleEncoder(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createRenderPipeline(device: *Device, descriptor: *const RenderPipeline.Descriptor) *RenderPipeline {
|
||||
return Impl.deviceCreateRenderPipeline(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createRenderPipelineAsync(
|
||||
device: *Device,
|
||||
descriptor: *const RenderPipeline.Descriptor,
|
||||
context: anytype,
|
||||
comptime callback: fn (
|
||||
ctx: @TypeOf(context),
|
||||
status: CreatePipelineAsyncStatus,
|
||||
pipeline: *RenderPipeline,
|
||||
message: [*:0]const u8,
|
||||
) callconv(.Inline) void,
|
||||
) void {
|
||||
const Context = @TypeOf(context);
|
||||
const Helper = struct {
|
||||
pub fn cCallback(
|
||||
status: CreatePipelineAsyncStatus,
|
||||
pipeline: *RenderPipeline,
|
||||
message: [*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
callback(
|
||||
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
||||
status,
|
||||
pipeline,
|
||||
message,
|
||||
);
|
||||
}
|
||||
};
|
||||
Impl.deviceCreateRenderPipelineAsync(device, descriptor, Helper.cCallback, if (Context == void) null else context);
|
||||
}
|
||||
|
||||
pub inline fn createSampler(device: *Device, descriptor: ?*const Sampler.Descriptor) *Sampler {
|
||||
return Impl.deviceCreateSampler(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createShaderModule(device: *Device, descriptor: *const ShaderModule.Descriptor) *ShaderModule {
|
||||
return Impl.deviceCreateShaderModule(device, descriptor);
|
||||
}
|
||||
|
||||
/// Helper to make createShaderModule invocations slightly nicer.
|
||||
pub inline fn createShaderModuleWGSL(
|
||||
device: *Device,
|
||||
label: ?[*:0]const u8,
|
||||
wgsl_source: [*:0]const u8,
|
||||
) *ShaderModule {
|
||||
return device.createShaderModule(&ShaderModule.Descriptor{
|
||||
.next_in_chain = .{ .wgsl_descriptor = &.{
|
||||
.source = wgsl_source,
|
||||
} },
|
||||
.label = label,
|
||||
});
|
||||
}
|
||||
|
||||
pub inline fn createSwapChain(device: *Device, surface: ?*Surface, descriptor: *const SwapChain.Descriptor) *SwapChain {
|
||||
return Impl.deviceCreateSwapChain(device, surface, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createTexture(device: *Device, descriptor: *const Texture.Descriptor) *Texture {
|
||||
return Impl.deviceCreateTexture(device, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn destroy(device: *Device) void {
|
||||
Impl.deviceDestroy(device);
|
||||
}
|
||||
|
||||
/// Call once with null to determine the array length, and again to fetch the feature list.
|
||||
///
|
||||
/// Consider using the enumerateFeaturesOwned helper.
|
||||
pub inline fn enumerateFeatures(device: *Device, features: ?[*]FeatureName) usize {
|
||||
return Impl.deviceEnumerateFeatures(device, features);
|
||||
}
|
||||
|
||||
/// Enumerates the adapter features, storing the result in an allocated slice which is owned by
|
||||
/// the caller.
|
||||
pub inline fn enumerateFeaturesOwned(device: *Device, allocator: std.mem.Allocator) ![]FeatureName {
|
||||
const count = device.enumerateFeatures(null);
|
||||
var data = try allocator.alloc(FeatureName, count);
|
||||
_ = device.enumerateFeatures(data.ptr);
|
||||
return data;
|
||||
}
|
||||
|
||||
pub inline fn getLimits(device: *Device, limits: *SupportedLimits) bool {
|
||||
return Impl.deviceGetLimits(device, limits);
|
||||
}
|
||||
|
||||
pub inline fn getQueue(device: *Device) *Queue {
|
||||
return Impl.deviceGetQueue(device);
|
||||
}
|
||||
|
||||
pub inline fn hasFeature(device: *Device, feature: FeatureName) bool {
|
||||
return Impl.deviceHasFeature(device, feature);
|
||||
}
|
||||
|
||||
pub inline fn injectError(device: *Device, typ: ErrorType, message: [*:0]const u8) void {
|
||||
Impl.deviceInjectError(device, typ, message);
|
||||
}
|
||||
|
||||
pub inline fn loseForTesting(device: *Device) void {
|
||||
Impl.deviceLoseForTesting(device);
|
||||
}
|
||||
|
||||
pub inline fn popErrorScope(
|
||||
device: *Device,
|
||||
context: anytype,
|
||||
comptime callback: fn (ctx: @TypeOf(context), typ: ErrorType, message: [*:0]const u8) callconv(.Inline) void,
|
||||
) bool {
|
||||
const Context = @TypeOf(context);
|
||||
const Helper = struct {
|
||||
pub fn cCallback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
||||
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message);
|
||||
}
|
||||
};
|
||||
return Impl.devicePopErrorScope(device, Helper.cCallback, if (Context == void) null else context);
|
||||
}
|
||||
|
||||
pub inline fn pushErrorScope(device: *Device, filter: ErrorFilter) void {
|
||||
Impl.devicePushErrorScope(device, filter);
|
||||
}
|
||||
|
||||
pub inline fn setDeviceLostCallback(
|
||||
device: *Device,
|
||||
context: anytype,
|
||||
comptime callback: ?fn (ctx: @TypeOf(context), reason: LostReason, message: [*:0]const u8) callconv(.Inline) void,
|
||||
) void {
|
||||
if (callback) |cb| {
|
||||
const Context = @TypeOf(context);
|
||||
const Helper = struct {
|
||||
pub fn cCallback(reason: LostReason, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
||||
cb(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), reason, message);
|
||||
}
|
||||
};
|
||||
Impl.deviceSetDeviceLostCallback(device, Helper.cCallback, if (Context == void) null else context);
|
||||
} else {
|
||||
Impl.deviceSetDeviceLostCallback(device, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
pub inline fn setLabel(device: *Device, label: [*:0]const u8) void {
|
||||
Impl.deviceSetLabel(device, label);
|
||||
}
|
||||
|
||||
pub inline fn setLoggingCallback(
|
||||
device: *Device,
|
||||
context: anytype,
|
||||
comptime callback: ?fn (ctx: @TypeOf(context), typ: LoggingType, message: [*:0]const u8) callconv(.Inline) void,
|
||||
) void {
|
||||
if (callback) |cb| {
|
||||
const Context = @TypeOf(context);
|
||||
const Helper = struct {
|
||||
pub fn cCallback(typ: LoggingType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
||||
cb(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message);
|
||||
}
|
||||
};
|
||||
Impl.deviceSetLoggingCallback(device, Helper.cCallback, if (Context == void) null else context);
|
||||
} else {
|
||||
Impl.deviceSetLoggingCallback(device, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
pub inline fn setUncapturedErrorCallback(
|
||||
device: *Device,
|
||||
context: anytype,
|
||||
comptime callback: ?fn (ctx: @TypeOf(context), typ: ErrorType, message: [*:0]const u8) callconv(.Inline) void,
|
||||
) void {
|
||||
if (callback) |cb| {
|
||||
const Context = @TypeOf(context);
|
||||
const Helper = struct {
|
||||
pub fn cCallback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
|
||||
cb(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message);
|
||||
}
|
||||
};
|
||||
Impl.deviceSetUncapturedErrorCallback(device, Helper.cCallback, if (Context == void) null else context);
|
||||
} else {
|
||||
Impl.deviceSetUncapturedErrorCallback(device, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
pub inline fn tick(device: *Device) void {
|
||||
Impl.deviceTick(device);
|
||||
}
|
||||
|
||||
pub inline fn reference(device: *Device) void {
|
||||
Impl.deviceReference(device);
|
||||
}
|
||||
|
||||
pub inline fn release(device: *Device) void {
|
||||
Impl.deviceRelease(device);
|
||||
}
|
||||
};
|
||||
42
libs/gpu/src/external_texture.zig
Normal file
42
libs/gpu/src/external_texture.zig
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const TextureView = @import("texture_view.zig").TextureView;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const ExternalTexture = opaque {
|
||||
pub const BindingEntry = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .external_texture_binding_entry },
|
||||
external_texture: *ExternalTexture,
|
||||
};
|
||||
|
||||
pub const BindingLayout = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .external_texture_binding_layout },
|
||||
};
|
||||
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
plane0: *TextureView,
|
||||
plane1: ?*TextureView = null,
|
||||
do_yuv_to_rgb_conversion_only: bool = false,
|
||||
yuv_to_rgb_conversion_matrix: ?*const [12]f32 = null,
|
||||
src_transform_function_parameters: *const [7]f32,
|
||||
dst_transform_function_parameters: *const [7]f32,
|
||||
gamut_conversion_matrix: *const [9]f32,
|
||||
};
|
||||
|
||||
pub inline fn destroy(external_texture: *ExternalTexture) void {
|
||||
Impl.externalTextureDestroy(external_texture);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(external_texture: *ExternalTexture, label: [*:0]const u8) void {
|
||||
Impl.externalTextureSetLabel(external_texture, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(external_texture: *ExternalTexture) void {
|
||||
Impl.externalTextureReference(external_texture);
|
||||
}
|
||||
|
||||
pub inline fn release(external_texture: *ExternalTexture) void {
|
||||
Impl.externalTextureRelease(external_texture);
|
||||
}
|
||||
};
|
||||
61
libs/gpu/src/instance.zig
Normal file
61
libs/gpu/src/instance.zig
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const RequestAdapterStatus = @import("types.zig").RequestAdapterStatus;
|
||||
const Surface = @import("surface.zig").Surface;
|
||||
const Adapter = @import("adapter.zig").Adapter;
|
||||
const RequestAdapterOptions = @import("types.zig").RequestAdapterOptions;
|
||||
const RequestAdapterCallback = @import("callbacks.zig").RequestAdapterCallback;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
const dawn = @import("dawn.zig");
|
||||
|
||||
pub const Instance = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
pub const NextInChain = extern union {
|
||||
generic: ?*const ChainedStruct,
|
||||
dawn_instance_descriptor: *const dawn.InstanceDescriptor,
|
||||
};
|
||||
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
};
|
||||
|
||||
pub inline fn createSurface(instance: *Instance, descriptor: *const Surface.Descriptor) *Surface {
|
||||
return Impl.instanceCreateSurface(instance, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn requestAdapter(
|
||||
instance: *Instance,
|
||||
options: ?*const RequestAdapterOptions,
|
||||
context: anytype,
|
||||
comptime callback: fn (
|
||||
ctx: @TypeOf(context),
|
||||
status: RequestAdapterStatus,
|
||||
adapter: *Adapter,
|
||||
message: ?[*:0]const u8,
|
||||
) callconv(.Inline) void,
|
||||
) void {
|
||||
const Context = @TypeOf(context);
|
||||
const Helper = struct {
|
||||
pub fn cCallback(
|
||||
status: RequestAdapterStatus,
|
||||
adapter: *Adapter,
|
||||
message: ?[*:0]const u8,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
callback(
|
||||
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
||||
status,
|
||||
adapter,
|
||||
message,
|
||||
);
|
||||
}
|
||||
};
|
||||
Impl.instanceRequestAdapter(instance, options, Helper.cCallback, if (Context == void) null else context);
|
||||
}
|
||||
|
||||
pub inline fn reference(instance: *Instance) void {
|
||||
Impl.instanceReference(instance);
|
||||
}
|
||||
|
||||
pub inline fn release(instance: *Instance) void {
|
||||
Impl.instanceRelease(instance);
|
||||
}
|
||||
};
|
||||
2456
libs/gpu/src/interface.zig
Normal file
2456
libs/gpu/src/interface.zig
Normal file
File diff suppressed because it is too large
Load diff
14
libs/gpu/src/mach_dawn.cpp
Normal file
14
libs/gpu/src/mach_dawn.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include <dawn/native/DawnNative.h>
|
||||
#include "mach_dawn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MACH_EXPORT const DawnProcTable machDawnGetProcTable() {
|
||||
return dawn_native::GetProcs();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
35
libs/gpu/src/mach_dawn.h
Normal file
35
libs/gpu/src/mach_dawn.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef MACH_DAWN_C_H_
|
||||
#define MACH_DAWN_C_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(MACH_DAWN_C_SHARED_LIBRARY)
|
||||
# if defined(_WIN32)
|
||||
# if defined(MACH_DAWN_C_IMPLEMENTATION)
|
||||
# define MACH_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define MACH_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
# else // defined(_WIN32)
|
||||
# if defined(MACH_DAWN_C_IMPLEMENTATION)
|
||||
# define MACH_EXPORT __attribute__((visibility("default")))
|
||||
# else
|
||||
# define MACH_EXPORT
|
||||
# endif
|
||||
# endif // defined(_WIN32)
|
||||
#else // defined(MACH_DAWN_C_SHARED_LIBRARY)
|
||||
# define MACH_EXPORT
|
||||
#endif // defined(MACH_DAWN_C_SHARED_LIBRARY)
|
||||
|
||||
#include <dawn/webgpu.h>
|
||||
#include <dawn/dawn_proc_table.h>
|
||||
|
||||
MACH_EXPORT const DawnProcTable machDawnGetProcTable();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // MACH_DAWN_C_H_
|
||||
77
libs/gpu/src/main.zig
Normal file
77
libs/gpu/src/main.zig
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub usingnamespace @import("adapter.zig");
|
||||
pub usingnamespace @import("bind_group.zig");
|
||||
pub usingnamespace @import("bind_group_layout.zig");
|
||||
pub usingnamespace @import("buffer.zig");
|
||||
pub usingnamespace @import("callbacks.zig");
|
||||
pub usingnamespace @import("command_buffer.zig");
|
||||
pub usingnamespace @import("command_encoder.zig");
|
||||
pub usingnamespace @import("compute_pass_encoder.zig");
|
||||
pub usingnamespace @import("compute_pipeline.zig");
|
||||
pub usingnamespace @import("device.zig");
|
||||
pub usingnamespace @import("external_texture.zig");
|
||||
pub usingnamespace @import("instance.zig");
|
||||
pub usingnamespace @import("pipeline_layout.zig");
|
||||
pub usingnamespace @import("query_set.zig");
|
||||
pub usingnamespace @import("queue.zig");
|
||||
pub usingnamespace @import("render_bundle.zig");
|
||||
pub usingnamespace @import("render_bundle_encoder.zig");
|
||||
pub usingnamespace @import("render_pass_encoder.zig");
|
||||
pub usingnamespace @import("render_pipeline.zig");
|
||||
pub usingnamespace @import("sampler.zig");
|
||||
pub usingnamespace @import("shader_module.zig");
|
||||
pub usingnamespace @import("surface.zig");
|
||||
pub usingnamespace @import("swap_chain.zig");
|
||||
pub usingnamespace @import("texture.zig");
|
||||
pub usingnamespace @import("texture_view.zig");
|
||||
|
||||
pub const dawn = @import("dawn.zig");
|
||||
|
||||
pub usingnamespace @import("types.zig");
|
||||
pub usingnamespace @import("interface.zig");
|
||||
|
||||
const instance = @import("instance.zig");
|
||||
const device = @import("device.zig");
|
||||
const interface = @import("interface.zig");
|
||||
const types = @import("types.zig");
|
||||
|
||||
pub inline fn createInstance(descriptor: ?*const instance.Instance.Descriptor) ?*instance.Instance {
|
||||
return interface.Impl.createInstance(descriptor);
|
||||
}
|
||||
|
||||
pub inline fn getProcAddress(_device: *device.Device, proc_name: [*:0]const u8) ?types.Proc {
|
||||
return interface.Impl.getProcAddress(_device, proc_name);
|
||||
}
|
||||
|
||||
test {
|
||||
std.testing.refAllDeclsRecursive(@This());
|
||||
|
||||
// Due to usingnamespace imports, these are not referenceable via @This()
|
||||
std.testing.refAllDeclsRecursive(@import("adapter.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("bind_group.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("bind_group_layout.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("buffer.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("command_buffer.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("command_encoder.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("compute_pass_encoder.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("compute_pipeline.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("device.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("external_texture.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("instance.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("pipeline_layout.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("query_set.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("queue.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("render_bundle.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("render_bundle_encoder.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("render_pass_encoder.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("render_pipeline.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("sampler.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("shader_module.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("surface.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("swap_chain.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("texture.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("texture_view.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("types.zig"));
|
||||
std.testing.refAllDeclsRecursive(@import("interface.zig"));
|
||||
}
|
||||
38
libs/gpu/src/pipeline_layout.zig
Normal file
38
libs/gpu/src/pipeline_layout.zig
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const BindGroupLayout = @import("bind_group_layout.zig").BindGroupLayout;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const PipelineLayout = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
bind_group_layout_count: u32 = 0,
|
||||
bind_group_layouts: ?[*]const *BindGroupLayout = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
bind_group_layouts: ?[]const *BindGroupLayout = null,
|
||||
}) Descriptor {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.label = v.label,
|
||||
.bind_group_layout_count = if (v.bind_group_layouts) |e| @intCast(u32, e.len) else 0,
|
||||
.bind_group_layouts = if (v.bind_group_layouts) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub inline fn setLabel(pipeline_layout: *PipelineLayout, label: [*:0]const u8) void {
|
||||
Impl.pipelineLayoutSetLabel(pipeline_layout, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(pipeline_layout: *PipelineLayout) void {
|
||||
Impl.pipelineLayoutReference(pipeline_layout);
|
||||
}
|
||||
|
||||
pub inline fn release(pipeline_layout: *PipelineLayout) void {
|
||||
Impl.pipelineLayoutRelease(pipeline_layout);
|
||||
}
|
||||
};
|
||||
57
libs/gpu/src/query_set.zig
Normal file
57
libs/gpu/src/query_set.zig
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const PipelineStatisticName = @import("types.zig").PipelineStatisticName;
|
||||
const QueryType = @import("types.zig").QueryType;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const QuerySet = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
type: QueryType,
|
||||
count: u32,
|
||||
pipeline_statistics: ?[*]const PipelineStatisticName = null,
|
||||
pipeline_statistics_count: u32 = 0,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
type: QueryType,
|
||||
count: u32,
|
||||
pipeline_statistics: ?[]const PipelineStatisticName = null,
|
||||
}) Descriptor {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.label = v.label,
|
||||
.type = v.type,
|
||||
.count = v.count,
|
||||
.pipeline_statistics_count = if (v.pipeline_statistics) |e| @intCast(u32, e.len) else 0,
|
||||
.pipeline_statistics = if (v.pipeline_statistics) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub inline fn destroy(query_set: *QuerySet) void {
|
||||
Impl.querySetDestroy(query_set);
|
||||
}
|
||||
|
||||
pub inline fn getCount(query_set: *QuerySet) u32 {
|
||||
return Impl.querySetGetCount(query_set);
|
||||
}
|
||||
|
||||
pub inline fn getType(query_set: *QuerySet) QueryType {
|
||||
return Impl.querySetGetType(query_set);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(query_set: *QuerySet, label: [*:0]const u8) void {
|
||||
Impl.querySetSetLabel(query_set, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(query_set: *QuerySet) void {
|
||||
Impl.querySetReference(query_set);
|
||||
}
|
||||
|
||||
pub inline fn release(query_set: *QuerySet) void {
|
||||
Impl.querySetRelease(query_set);
|
||||
}
|
||||
};
|
||||
104
libs/gpu/src/queue.zig
Normal file
104
libs/gpu/src/queue.zig
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
const std = @import("std");
|
||||
const CommandBuffer = @import("command_buffer.zig").CommandBuffer;
|
||||
const Buffer = @import("buffer.zig").Buffer;
|
||||
const Texture = @import("texture.zig").Texture;
|
||||
const ImageCopyTexture = @import("types.zig").ImageCopyTexture;
|
||||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const Extent3D = @import("types.zig").Extent3D;
|
||||
const CopyTextureForBrowserOptions = @import("types.zig").CopyTextureForBrowserOptions;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const Queue = opaque {
|
||||
pub const WorkDoneCallback = if (@import("builtin").zig_backend == .stage1)
|
||||
fn (
|
||||
status: WorkDoneStatus,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void
|
||||
else
|
||||
*const fn (
|
||||
status: WorkDoneStatus,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void;
|
||||
|
||||
pub const WorkDoneStatus = enum(u32) {
|
||||
success = 0x00000000,
|
||||
err = 0x00000001,
|
||||
unknown = 0x00000002,
|
||||
device_lost = 0x00000003,
|
||||
};
|
||||
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
};
|
||||
|
||||
pub inline fn copyTextureForBrowser(queue: *Queue, source: *const ImageCopyTexture, destination: *const ImageCopyTexture, copy_size: *const Extent3D, options: *const CopyTextureForBrowserOptions) void {
|
||||
Impl.queueCopyTextureForBrowser(queue, source, destination, copy_size, options);
|
||||
}
|
||||
|
||||
// TODO: dawn: does not allow unsetting this callback to null
|
||||
pub inline fn onSubmittedWorkDone(
|
||||
queue: *Queue,
|
||||
signal_value: u64,
|
||||
context: anytype,
|
||||
comptime callback: fn (ctx: @TypeOf(context), status: WorkDoneStatus) callconv(.Inline) void,
|
||||
) void {
|
||||
const Context = @TypeOf(context);
|
||||
const Helper = struct {
|
||||
pub fn cCallback(status: WorkDoneStatus, userdata: ?*anyopaque) callconv(.C) void {
|
||||
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), status);
|
||||
}
|
||||
};
|
||||
Impl.queueOnSubmittedWorkDone(queue, signal_value, Helper.cCallback, if (Context == void) null else context);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(queue: *Queue, label: [*:0]const u8) void {
|
||||
Impl.queueSetLabel(queue, label);
|
||||
}
|
||||
|
||||
pub inline fn submit(queue: *Queue, commands: []*const CommandBuffer) void {
|
||||
Impl.queueSubmit(queue, @intCast(u32, commands.len), commands.ptr);
|
||||
}
|
||||
|
||||
pub inline fn writeBuffer(
|
||||
queue: *Queue,
|
||||
buffer: *Buffer,
|
||||
buffer_offset_bytes: u64,
|
||||
data_span: anytype,
|
||||
) void {
|
||||
const data_slice = std.mem.span(data_span);
|
||||
Impl.queueWriteBuffer(
|
||||
queue,
|
||||
buffer,
|
||||
buffer_offset_bytes,
|
||||
@ptrCast(*const anyopaque, data_slice.ptr),
|
||||
@intCast(u64, data_slice.len) * @sizeOf(std.meta.Elem(@TypeOf(data_slice))),
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn writeTexture(
|
||||
queue: *Queue,
|
||||
destination: *const ImageCopyTexture,
|
||||
data_layout: *const Texture.DataLayout,
|
||||
write_size: *const Extent3D,
|
||||
data_span: anytype,
|
||||
) void {
|
||||
const data_slice = std.mem.span(data_span);
|
||||
Impl.queueWriteTexture(
|
||||
queue,
|
||||
destination,
|
||||
@ptrCast(*const anyopaque, data_slice.ptr),
|
||||
@intCast(usize, data_slice.len) * @sizeOf(std.meta.Elem(@TypeOf(data_slice))),
|
||||
data_layout,
|
||||
write_size,
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn reference(queue: *Queue) void {
|
||||
Impl.queueReference(queue);
|
||||
}
|
||||
|
||||
pub inline fn release(queue: *Queue) void {
|
||||
Impl.queueRelease(queue);
|
||||
}
|
||||
};
|
||||
17
libs/gpu/src/render_bundle.zig
Normal file
17
libs/gpu/src/render_bundle.zig
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const RenderBundle = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
};
|
||||
|
||||
pub inline fn reference(render_bundle: *RenderBundle) void {
|
||||
Impl.renderBundleReference(render_bundle);
|
||||
}
|
||||
|
||||
pub inline fn release(render_bundle: *RenderBundle) void {
|
||||
Impl.renderBundleRelease(render_bundle);
|
||||
}
|
||||
};
|
||||
121
libs/gpu/src/render_bundle_encoder.zig
Normal file
121
libs/gpu/src/render_bundle_encoder.zig
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
const Texture = @import("texture.zig").Texture;
|
||||
const Buffer = @import("buffer.zig").Buffer;
|
||||
const BindGroup = @import("bind_group.zig").BindGroup;
|
||||
const RenderPipeline = @import("render_pipeline.zig").RenderPipeline;
|
||||
const RenderBundle = @import("render_bundle.zig").RenderBundle;
|
||||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const IndexFormat = @import("types.zig").IndexFormat;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const RenderBundleEncoder = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
color_formats_count: u32 = 0,
|
||||
color_formats: ?[*]const Texture.Format = null,
|
||||
depth_stencil_format: Texture.Format = .undef,
|
||||
sample_count: u32 = 1,
|
||||
depth_read_only: bool = false,
|
||||
stencil_read_only: bool = false,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
color_formats: ?[]const Texture.Format = null,
|
||||
depth_stencil_format: Texture.Format = .undef,
|
||||
sample_count: u32 = 1,
|
||||
depth_read_only: bool = false,
|
||||
stencil_read_only: bool = false,
|
||||
}) Descriptor {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.label = v.label,
|
||||
.color_formats_count = if (v.color_formats) |e| @intCast(u32, e.len) else 0,
|
||||
.color_formats = if (v.color_formats) |e| e.ptr else null,
|
||||
.depth_stencil_format = v.depth_stencil_format,
|
||||
.sample_count = v.sample_count,
|
||||
.depth_read_only = v.depth_read_only,
|
||||
.stencil_read_only = v.stencil_read_only,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/// Default `instance_count`: 1
|
||||
/// Default `first_vertex`: 0
|
||||
/// Default `first_instance`: 0
|
||||
pub inline fn draw(render_bundle_encoder: *RenderBundleEncoder, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32) void {
|
||||
Impl.renderBundleEncoderDraw(render_bundle_encoder, vertex_count, instance_count, first_vertex, first_instance);
|
||||
}
|
||||
|
||||
/// Default `instance_count`: 1
|
||||
/// Default `first_index`: 0
|
||||
/// Default `base_vertex`: 0
|
||||
/// Default `first_instance`: 0
|
||||
pub inline fn drawIndexed(render_bundle_encoder: *RenderBundleEncoder, index_count: u32, instance_count: u32, first_index: u32, base_vertex: i32, first_instance: u32) void {
|
||||
Impl.renderBundleEncoderDrawIndexed(render_bundle_encoder, index_count, instance_count, first_index, base_vertex, first_instance);
|
||||
}
|
||||
|
||||
pub inline fn drawIndexedIndirect(render_bundle_encoder: *RenderBundleEncoder, indirect_buffer: *Buffer, indirect_offset: u64) void {
|
||||
Impl.renderBundleEncoderDrawIndexedIndirect(render_bundle_encoder, indirect_buffer, indirect_offset);
|
||||
}
|
||||
|
||||
pub inline fn drawIndirect(render_bundle_encoder: *RenderBundleEncoder, indirect_buffer: *Buffer, indirect_offset: u64) void {
|
||||
Impl.renderBundleEncoderDrawIndirect(render_bundle_encoder, indirect_buffer, indirect_offset);
|
||||
}
|
||||
|
||||
pub inline fn finish(render_bundle_encoder: *RenderBundleEncoder, descriptor: ?*const RenderBundle.Descriptor) *RenderBundle {
|
||||
return Impl.renderBundleEncoderFinish(render_bundle_encoder, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn insertDebugMarker(render_bundle_encoder: *RenderBundleEncoder, marker_label: [*:0]const u8) void {
|
||||
Impl.renderBundleEncoderInsertDebugMarker(render_bundle_encoder, marker_label);
|
||||
}
|
||||
|
||||
pub inline fn popDebugGroup(render_bundle_encoder: *RenderBundleEncoder) void {
|
||||
Impl.renderBundleEncoderPopDebugGroup(render_bundle_encoder);
|
||||
}
|
||||
|
||||
pub inline fn pushDebugGroup(render_bundle_encoder: *RenderBundleEncoder, group_label: [*:0]const u8) void {
|
||||
Impl.renderBundleEncoderPushDebugGroup(render_bundle_encoder, group_label);
|
||||
}
|
||||
|
||||
/// Default `dynamic_offsets`: `null`
|
||||
pub inline fn setBindGroup(render_bundle_encoder: *RenderBundleEncoder, group_index: u32, group: *BindGroup, dynamic_offsets: ?[]const u32) void {
|
||||
Impl.renderBundleEncoderSetBindGroup(
|
||||
render_bundle_encoder,
|
||||
group_index,
|
||||
group,
|
||||
if (dynamic_offsets) |v| @intCast(u32, v.len) else 0,
|
||||
if (dynamic_offsets) |v| v.ptr else null,
|
||||
);
|
||||
}
|
||||
|
||||
/// Default `offset`: 0
|
||||
/// Default `size`: `gpu.whole_size`
|
||||
pub inline fn setIndexBuffer(render_bundle_encoder: *RenderBundleEncoder, buffer: *Buffer, format: IndexFormat, offset: u64, size: u64) void {
|
||||
Impl.renderBundleEncoderSetIndexBuffer(render_bundle_encoder, buffer, format, offset, size);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(render_bundle_encoder: *RenderBundleEncoder, label: [*:0]const u8) void {
|
||||
Impl.renderBundleEncoderSetLabel(render_bundle_encoder, label);
|
||||
}
|
||||
|
||||
pub inline fn setPipeline(render_bundle_encoder: *RenderBundleEncoder, pipeline: *RenderPipeline) void {
|
||||
Impl.renderBundleEncoderSetPipeline(render_bundle_encoder, pipeline);
|
||||
}
|
||||
|
||||
/// Default `offset`: 0
|
||||
/// Default `size`: `gpu.whole_size`
|
||||
pub inline fn setVertexBuffer(render_bundle_encoder: *RenderBundleEncoder, slot: u32, buffer: *Buffer, offset: u64, size: u64) void {
|
||||
Impl.renderBundleEncoderSetVertexBuffer(render_bundle_encoder, slot, buffer, offset, size);
|
||||
}
|
||||
|
||||
pub inline fn reference(render_bundle_encoder: *RenderBundleEncoder) void {
|
||||
Impl.renderBundleEncoderReference(render_bundle_encoder);
|
||||
}
|
||||
|
||||
pub inline fn release(render_bundle_encoder: *RenderBundleEncoder) void {
|
||||
Impl.renderBundleEncoderRelease(render_bundle_encoder);
|
||||
}
|
||||
};
|
||||
128
libs/gpu/src/render_pass_encoder.zig
Normal file
128
libs/gpu/src/render_pass_encoder.zig
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
const Buffer = @import("buffer.zig").Buffer;
|
||||
const RenderBundle = @import("render_bundle.zig").RenderBundle;
|
||||
const BindGroup = @import("bind_group.zig").BindGroup;
|
||||
const RenderPipeline = @import("render_pipeline.zig").RenderPipeline;
|
||||
const QuerySet = @import("query_set.zig").QuerySet;
|
||||
const Color = @import("types.zig").Color;
|
||||
const IndexFormat = @import("types.zig").IndexFormat;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const RenderPassEncoder = opaque {
|
||||
pub inline fn beginOcclusionQuery(render_pass_encoder: *RenderPassEncoder, query_index: u32) void {
|
||||
Impl.renderPassEncoderBeginOcclusionQuery(render_pass_encoder, query_index);
|
||||
}
|
||||
|
||||
/// Default `instance_count`: 1
|
||||
/// Default `first_vertex`: 0
|
||||
/// Default `first_instance`: 0
|
||||
pub inline fn draw(render_pass_encoder: *RenderPassEncoder, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32) void {
|
||||
Impl.renderPassEncoderDraw(render_pass_encoder, vertex_count, instance_count, first_vertex, first_instance);
|
||||
}
|
||||
|
||||
/// Default `instance_count`: 1
|
||||
/// Default `first_index`: 0
|
||||
/// Default `base_vertex`: 0
|
||||
/// Default `first_instance`: 0
|
||||
pub inline fn drawIndexed(render_pass_encoder: *RenderPassEncoder, index_count: u32, instance_count: u32, first_index: u32, base_vertex: i32, first_instance: u32) void {
|
||||
Impl.renderPassEncoderDrawIndexed(render_pass_encoder, index_count, instance_count, first_index, base_vertex, first_instance);
|
||||
}
|
||||
|
||||
pub inline fn drawIndexedIndirect(render_pass_encoder: *RenderPassEncoder, indirect_buffer: *Buffer, indirect_offset: u64) void {
|
||||
Impl.renderPassEncoderDrawIndexedIndirect(render_pass_encoder, indirect_buffer, indirect_offset);
|
||||
}
|
||||
|
||||
pub inline fn drawIndirect(render_pass_encoder: *RenderPassEncoder, indirect_buffer: *Buffer, indirect_offset: u64) void {
|
||||
Impl.renderPassEncoderDrawIndirect(render_pass_encoder, indirect_buffer, indirect_offset);
|
||||
}
|
||||
|
||||
pub inline fn end(render_pass_encoder: *RenderPassEncoder) void {
|
||||
Impl.renderPassEncoderEnd(render_pass_encoder);
|
||||
}
|
||||
|
||||
pub inline fn endOcclusionQuery(render_pass_encoder: *RenderPassEncoder) void {
|
||||
Impl.renderPassEncoderEndOcclusionQuery(render_pass_encoder);
|
||||
}
|
||||
|
||||
pub inline fn executeBundles(
|
||||
render_pass_encoder: *RenderPassEncoder,
|
||||
bundles: []*const RenderBundle,
|
||||
) void {
|
||||
Impl.renderPassEncoderExecuteBundles(
|
||||
render_pass_encoder,
|
||||
@intCast(u32, bundles.len),
|
||||
bundles.ptr,
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn insertDebugMarker(render_pass_encoder: *RenderPassEncoder, marker_label: [*:0]const u8) void {
|
||||
Impl.renderPassEncoderInsertDebugMarker(render_pass_encoder, marker_label);
|
||||
}
|
||||
|
||||
pub inline fn popDebugGroup(render_pass_encoder: *RenderPassEncoder) void {
|
||||
Impl.renderPassEncoderPopDebugGroup(render_pass_encoder);
|
||||
}
|
||||
|
||||
pub inline fn pushDebugGroup(render_pass_encoder: *RenderPassEncoder, group_label: [*:0]const u8) void {
|
||||
Impl.renderPassEncoderPushDebugGroup(render_pass_encoder, group_label);
|
||||
}
|
||||
|
||||
/// Default `dynamic_offsets_count`: 0
|
||||
/// Default `dynamic_offsets`: `null`
|
||||
pub inline fn setBindGroup(render_pass_encoder: *RenderPassEncoder, group_index: u32, group: *BindGroup, dynamic_offsets: ?[]const u32) void {
|
||||
Impl.renderPassEncoderSetBindGroup(
|
||||
render_pass_encoder,
|
||||
group_index,
|
||||
group,
|
||||
if (dynamic_offsets) |v| @intCast(u32, v.len) else 0,
|
||||
if (dynamic_offsets) |v| v.ptr else null,
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn setBlendConstant(render_pass_encoder: *RenderPassEncoder, color: *const Color) void {
|
||||
Impl.renderPassEncoderSetBlendConstant(render_pass_encoder, color);
|
||||
}
|
||||
|
||||
/// Default `offset`: 0
|
||||
/// Default `size`: `gpu.whole_size`
|
||||
pub inline fn setIndexBuffer(render_pass_encoder: *RenderPassEncoder, buffer: *Buffer, format: IndexFormat, offset: u64, size: u64) void {
|
||||
Impl.renderPassEncoderSetIndexBuffer(render_pass_encoder, buffer, format, offset, size);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(render_pass_encoder: *RenderPassEncoder, label: [*:0]const u8) void {
|
||||
Impl.renderPassEncoderSetLabel(render_pass_encoder, label);
|
||||
}
|
||||
|
||||
pub inline fn setPipeline(render_pass_encoder: *RenderPassEncoder, pipeline: *RenderPipeline) void {
|
||||
Impl.renderPassEncoderSetPipeline(render_pass_encoder, pipeline);
|
||||
}
|
||||
|
||||
pub inline fn setScissorRect(render_pass_encoder: *RenderPassEncoder, x: u32, y: u32, width: u32, height: u32) void {
|
||||
Impl.renderPassEncoderSetScissorRect(render_pass_encoder, x, y, width, height);
|
||||
}
|
||||
|
||||
pub inline fn setStencilReference(render_pass_encoder: *RenderPassEncoder, _reference: u32) void {
|
||||
Impl.renderPassEncoderSetStencilReference(render_pass_encoder, _reference);
|
||||
}
|
||||
|
||||
/// Default `offset`: 0
|
||||
/// Default `size`: `gpu.whole_size`
|
||||
pub inline fn setVertexBuffer(render_pass_encoder: *RenderPassEncoder, slot: u32, buffer: *Buffer, offset: u64, size: u64) void {
|
||||
Impl.renderPassEncoderSetVertexBuffer(render_pass_encoder, slot, buffer, offset, size);
|
||||
}
|
||||
|
||||
pub inline fn setViewport(render_pass_encoder: *RenderPassEncoder, x: f32, y: f32, width: f32, height: f32, min_depth: f32, max_depth: f32) void {
|
||||
Impl.renderPassEncoderSetViewport(render_pass_encoder, x, y, width, height, min_depth, max_depth);
|
||||
}
|
||||
|
||||
pub inline fn writeTimestamp(render_pass_encoder: *RenderPassEncoder, query_set: *QuerySet, query_index: u32) void {
|
||||
Impl.renderPassEncoderWriteTimestamp(render_pass_encoder, query_set, query_index);
|
||||
}
|
||||
|
||||
pub inline fn reference(render_pass_encoder: *RenderPassEncoder) void {
|
||||
Impl.renderPassEncoderReference(render_pass_encoder);
|
||||
}
|
||||
|
||||
pub inline fn release(render_pass_encoder: *RenderPassEncoder) void {
|
||||
Impl.renderPassEncoderRelease(render_pass_encoder);
|
||||
}
|
||||
};
|
||||
38
libs/gpu/src/render_pipeline.zig
Normal file
38
libs/gpu/src/render_pipeline.zig
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const DepthStencilState = @import("types.zig").DepthStencilState;
|
||||
const MultisampleState = @import("types.zig").MultisampleState;
|
||||
const VertexState = @import("types.zig").VertexState;
|
||||
const PrimitiveState = @import("types.zig").PrimitiveState;
|
||||
const FragmentState = @import("types.zig").FragmentState;
|
||||
const PipelineLayout = @import("pipeline_layout.zig").PipelineLayout;
|
||||
const BindGroupLayout = @import("bind_group_layout.zig").BindGroupLayout;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const RenderPipeline = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
layout: ?*PipelineLayout = null,
|
||||
vertex: VertexState,
|
||||
primitive: PrimitiveState = .{},
|
||||
depth_stencil: ?*const DepthStencilState = null,
|
||||
multisample: MultisampleState = .{},
|
||||
fragment: ?*const FragmentState = null,
|
||||
};
|
||||
|
||||
pub inline fn getBindGroupLayout(render_pipeline: *RenderPipeline, group_index: u32) *BindGroupLayout {
|
||||
return Impl.renderPipelineGetBindGroupLayout(render_pipeline, group_index);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(render_pipeline: *RenderPipeline, label: [*:0]const u8) void {
|
||||
Impl.renderPipelineSetLabel(render_pipeline, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(render_pipeline: *RenderPipeline) void {
|
||||
Impl.renderPipelineReference(render_pipeline);
|
||||
}
|
||||
|
||||
pub inline fn release(render_pipeline: *RenderPipeline) void {
|
||||
Impl.renderPipelineRelease(render_pipeline);
|
||||
}
|
||||
};
|
||||
51
libs/gpu/src/sampler.zig
Normal file
51
libs/gpu/src/sampler.zig
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const FilterMode = @import("types.zig").FilterMode;
|
||||
const CompareFunction = @import("types.zig").CompareFunction;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const Sampler = opaque {
|
||||
pub const AddressMode = enum(u32) {
|
||||
repeat = 0x00000000,
|
||||
mirror_repeat = 0x00000001,
|
||||
clamp_to_edge = 0x00000002,
|
||||
};
|
||||
|
||||
pub const BindingType = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
filtering = 0x00000001,
|
||||
non_filtering = 0x00000002,
|
||||
comparison = 0x00000003,
|
||||
};
|
||||
|
||||
pub const BindingLayout = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
type: BindingType = .undef,
|
||||
};
|
||||
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
address_mode_u: AddressMode = .clamp_to_edge,
|
||||
address_mode_v: AddressMode = .clamp_to_edge,
|
||||
address_mode_w: AddressMode = .clamp_to_edge,
|
||||
mag_filter: FilterMode = .nearest,
|
||||
min_filter: FilterMode = .nearest,
|
||||
mipmap_filter: FilterMode = .nearest,
|
||||
lod_min_clamp: f32 = 0.0,
|
||||
lod_max_clamp: f32 = 1000.0,
|
||||
compare: CompareFunction = .undef,
|
||||
max_anisotropy: u16 = 1,
|
||||
};
|
||||
|
||||
pub inline fn setLabel(sampler: *Sampler, label: [*:0]const u8) void {
|
||||
Impl.samplerSetLabel(sampler, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(sampler: *Sampler) void {
|
||||
Impl.samplerReference(sampler);
|
||||
}
|
||||
|
||||
pub inline fn release(sampler: *Sampler) void {
|
||||
Impl.samplerRelease(sampler);
|
||||
}
|
||||
};
|
||||
67
libs/gpu/src/shader_module.zig
Normal file
67
libs/gpu/src/shader_module.zig
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const CompilationInfoCallback = @import("callbacks.zig").CompilationInfoCallback;
|
||||
const CompilationInfoRequestStatus = @import("types.zig").CompilationInfoRequestStatus;
|
||||
const CompilationInfo = @import("types.zig").CompilationInfo;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const ShaderModule = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
pub const NextInChain = extern union {
|
||||
generic: ?*const ChainedStruct,
|
||||
spirv_descriptor: ?*const SPIRVDescriptor,
|
||||
wgsl_descriptor: ?*const WGSLDescriptor,
|
||||
};
|
||||
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
label: ?[*:0]const u8 = null,
|
||||
};
|
||||
|
||||
pub const SPIRVDescriptor = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .shader_module_spirv_descriptor },
|
||||
code_size: u32,
|
||||
code: [*]const u32,
|
||||
};
|
||||
|
||||
pub const WGSLDescriptor = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .shader_module_wgsl_descriptor },
|
||||
source: [*:0]const u8,
|
||||
};
|
||||
|
||||
pub inline fn getCompilationInfo(
|
||||
shader_module: *ShaderModule,
|
||||
context: anytype,
|
||||
comptime callback: fn (
|
||||
ctx: @TypeOf(context),
|
||||
status: CompilationInfoRequestStatus,
|
||||
compilation_info: *const CompilationInfo,
|
||||
) callconv(.Inline) void,
|
||||
) void {
|
||||
const Context = @TypeOf(context);
|
||||
const Helper = struct {
|
||||
pub fn cCallback(
|
||||
status: CompilationInfoRequestStatus,
|
||||
compilation_info: *const CompilationInfo,
|
||||
userdata: ?*anyopaque,
|
||||
) callconv(.C) void {
|
||||
callback(
|
||||
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)),
|
||||
status,
|
||||
compilation_info,
|
||||
);
|
||||
}
|
||||
};
|
||||
Impl.shaderModuleGetCompilationInfo(shader_module, Helper.cCallback, if (Context == void) null else context);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(shader_module: *ShaderModule, label: [*:0]const u8) void {
|
||||
Impl.shaderModuleSetLabel(shader_module, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(shader_module: *ShaderModule) void {
|
||||
Impl.shaderModuleReference(shader_module);
|
||||
}
|
||||
|
||||
pub inline fn release(shader_module: *ShaderModule) void {
|
||||
Impl.shaderModuleRelease(shader_module);
|
||||
}
|
||||
};
|
||||
72
libs/gpu/src/surface.zig
Normal file
72
libs/gpu/src/surface.zig
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const Surface = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
pub const NextInChain = extern union {
|
||||
generic: ?*const ChainedStruct,
|
||||
from_android_native_window: *const DescriptorFromAndroidNativeWindow,
|
||||
from_canvas_html_selector: *const DescriptorFromCanvasHTMLSelector,
|
||||
from_metal_layer: *const DescriptorFromMetalLayer,
|
||||
from_wayland_surface: *const DescriptorFromWaylandSurface,
|
||||
from_windows_core_window: *const DescriptorFromWindowsCoreWindow,
|
||||
from_windows_hwnd: *const DescriptorFromWindowsHWND,
|
||||
from_windows_swap_chain_panel: *const DescriptorFromWindowsSwapChainPanel,
|
||||
from_xlib_window: *const DescriptorFromXlibWindow,
|
||||
};
|
||||
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
label: ?[*:0]const u8 = null,
|
||||
};
|
||||
|
||||
pub const DescriptorFromAndroidNativeWindow = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .surface_descriptor_from_android_native_window },
|
||||
window: *anyopaque,
|
||||
};
|
||||
|
||||
pub const DescriptorFromCanvasHTMLSelector = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .surface_descriptor_from_canvas_html_selector },
|
||||
selector: [*:0]const u8,
|
||||
};
|
||||
|
||||
pub const DescriptorFromMetalLayer = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .surface_descriptor_from_metal_layer },
|
||||
layer: *anyopaque,
|
||||
};
|
||||
|
||||
pub const DescriptorFromWaylandSurface = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .surface_descriptor_from_wayland_surface },
|
||||
display: *anyopaque,
|
||||
surface: *anyopaque,
|
||||
};
|
||||
|
||||
pub const DescriptorFromWindowsCoreWindow = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .surface_descriptor_from_windows_core_window },
|
||||
core_window: *anyopaque,
|
||||
};
|
||||
|
||||
pub const DescriptorFromWindowsHWND = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .surface_descriptor_from_windows_hwnd },
|
||||
hinstance: *anyopaque,
|
||||
hwnd: *anyopaque,
|
||||
};
|
||||
|
||||
pub const DescriptorFromWindowsSwapChainPanel = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .surface_descriptor_from_windows_swap_chain_panel },
|
||||
swap_chain_panel: *anyopaque,
|
||||
};
|
||||
|
||||
pub const DescriptorFromXlibWindow = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .surface_descriptor_from_xlib_window },
|
||||
display: *anyopaque,
|
||||
window: u32,
|
||||
};
|
||||
|
||||
pub inline fn reference(surface: *Surface) void {
|
||||
Impl.surfaceReference(surface);
|
||||
}
|
||||
|
||||
pub inline fn release(surface: *Surface) void {
|
||||
Impl.surfaceRelease(surface);
|
||||
}
|
||||
};
|
||||
39
libs/gpu/src/swap_chain.zig
Normal file
39
libs/gpu/src/swap_chain.zig
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const PresentMode = @import("types.zig").PresentMode;
|
||||
const Texture = @import("texture.zig").Texture;
|
||||
const TextureView = @import("texture_view.zig").TextureView;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const SwapChain = opaque {
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
usage: Texture.UsageFlags,
|
||||
format: Texture.Format,
|
||||
width: u32,
|
||||
height: u32,
|
||||
present_mode: PresentMode,
|
||||
/// deprecated
|
||||
implementation: u64 = 0,
|
||||
};
|
||||
|
||||
pub inline fn configure(swap_chain: *SwapChain, format: Texture.Format, allowed_usage: Texture.UsageFlags, width: u32, height: u32) void {
|
||||
Impl.swapChainConfigure(swap_chain, format, allowed_usage, width, height);
|
||||
}
|
||||
|
||||
pub inline fn getCurrentTextureView(swap_chain: *SwapChain) *TextureView {
|
||||
return Impl.swapChainGetCurrentTextureView(swap_chain);
|
||||
}
|
||||
|
||||
pub inline fn present(swap_chain: *SwapChain) void {
|
||||
Impl.swapChainPresent(swap_chain);
|
||||
}
|
||||
|
||||
pub inline fn reference(swap_chain: *SwapChain) void {
|
||||
Impl.swapChainReference(swap_chain);
|
||||
}
|
||||
|
||||
pub inline fn release(swap_chain: *SwapChain) void {
|
||||
Impl.swapChainRelease(swap_chain);
|
||||
}
|
||||
};
|
||||
272
libs/gpu/src/texture.zig
Normal file
272
libs/gpu/src/texture.zig
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
const std = @import("std");
|
||||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const TextureView = @import("texture_view.zig").TextureView;
|
||||
const Extent3D = @import("types.zig").Extent3D;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
const types = @import("types.zig");
|
||||
const dawn = @import("dawn.zig");
|
||||
|
||||
pub const Texture = opaque {
|
||||
pub const Aspect = enum(u32) {
|
||||
all = 0x00000000,
|
||||
stencil_only = 0x00000001,
|
||||
depth_only = 0x00000002,
|
||||
plane0_only = 0x00000003,
|
||||
plane1_only = 0x00000004,
|
||||
};
|
||||
|
||||
pub const ComponentType = enum(u32) {
|
||||
float = 0x00000000,
|
||||
sint = 0x00000001,
|
||||
uint = 0x00000002,
|
||||
depth_comparison = 0x00000003,
|
||||
};
|
||||
|
||||
pub const Dimension = enum(u32) {
|
||||
dimension_1d = 0x00000000,
|
||||
dimension_2d = 0x00000001,
|
||||
dimension_3d = 0x00000002,
|
||||
};
|
||||
|
||||
pub const Format = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
r8_unorm = 0x00000001,
|
||||
r8_snorm = 0x00000002,
|
||||
r8_uint = 0x00000003,
|
||||
r8_sint = 0x00000004,
|
||||
r16_uint = 0x00000005,
|
||||
r16_sint = 0x00000006,
|
||||
r16_float = 0x00000007,
|
||||
rg8_unorm = 0x00000008,
|
||||
rg8_snorm = 0x00000009,
|
||||
rg8_uint = 0x0000000a,
|
||||
rg8_sint = 0x0000000b,
|
||||
r32_float = 0x0000000c,
|
||||
r32_uint = 0x0000000d,
|
||||
r32_sint = 0x0000000e,
|
||||
rg16_uint = 0x0000000f,
|
||||
rg16_sint = 0x00000010,
|
||||
rg16_float = 0x00000011,
|
||||
rgba8_unorm = 0x00000012,
|
||||
rgba8_unorm_srgb = 0x00000013,
|
||||
rgba8_snorm = 0x00000014,
|
||||
rgba8_uint = 0x00000015,
|
||||
rgba8_sint = 0x00000016,
|
||||
bgra8_unorm = 0x00000017,
|
||||
bgra8_unorm_srgb = 0x00000018,
|
||||
rgb10_a2_unorm = 0x00000019,
|
||||
rg11_b10_ufloat = 0x0000001a,
|
||||
rgb9_e5_ufloat = 0x0000001b,
|
||||
rg32_float = 0x0000001c,
|
||||
rg32_uint = 0x0000001d,
|
||||
rg32_sint = 0x0000001e,
|
||||
rgba16_uint = 0x0000001f,
|
||||
rgba16_sint = 0x00000020,
|
||||
rgba16_float = 0x00000021,
|
||||
rgba32_float = 0x00000022,
|
||||
rgba32_uint = 0x00000023,
|
||||
rgba32_sint = 0x00000024,
|
||||
stencil8 = 0x00000025,
|
||||
depth16_unorm = 0x00000026,
|
||||
depth24_plus = 0x00000027,
|
||||
depth24_plus_stencil8 = 0x00000028,
|
||||
depth32_float = 0x00000029,
|
||||
depth32_float_stencil8 = 0x0000002a,
|
||||
bc1_rgba_unorm = 0x0000002b,
|
||||
bc1_rgba_unorm_srgb = 0x0000002c,
|
||||
bc2_rgba_unorm = 0x0000002d,
|
||||
bc2_rgba_unorm_srgb = 0x0000002e,
|
||||
bc3_rgba_unorm = 0x0000002f,
|
||||
bc3_rgba_unorm_srgb = 0x00000030,
|
||||
bc4_runorm = 0x00000031,
|
||||
bc4_rsnorm = 0x00000032,
|
||||
bc5_rg_unorm = 0x00000033,
|
||||
bc5_rg_snorm = 0x00000034,
|
||||
bc6_hrgb_ufloat = 0x00000035,
|
||||
bc6_hrgb_float = 0x00000036,
|
||||
bc7_rgba_unorm = 0x00000037,
|
||||
bc7_rgba_unorm_srgb = 0x00000038,
|
||||
etc2_rgb8_unorm = 0x00000039,
|
||||
etc2_rgb8_unorm_srgb = 0x0000003a,
|
||||
etc2_rgb8_a1_unorm = 0x0000003b,
|
||||
etc2_rgb8_a1_unorm_srgb = 0x0000003c,
|
||||
etc2_rgba8_unorm = 0x0000003d,
|
||||
etc2_rgba8_unorm_srgb = 0x0000003e,
|
||||
eacr11_unorm = 0x0000003f,
|
||||
eacr11_snorm = 0x00000040,
|
||||
eacrg11_unorm = 0x00000041,
|
||||
eacrg11_snorm = 0x00000042,
|
||||
astc4x4_unorm = 0x00000043,
|
||||
astc4x4_unorm_srgb = 0x00000044,
|
||||
astc5x4_unorm = 0x00000045,
|
||||
astc5x4_unorm_srgb = 0x00000046,
|
||||
astc5x5_unorm = 0x00000047,
|
||||
astc5x5_unorm_srgb = 0x00000048,
|
||||
astc6x5_unorm = 0x00000049,
|
||||
astc6x5_unorm_srgb = 0x0000004a,
|
||||
astc6x6_unorm = 0x0000004b,
|
||||
astc6x6_unorm_srgb = 0x0000004c,
|
||||
astc8x5_unorm = 0x0000004d,
|
||||
astc8x5_unorm_srgb = 0x0000004e,
|
||||
astc8x6_unorm = 0x0000004f,
|
||||
astc8x6_unorm_srgb = 0x00000050,
|
||||
astc8x8_unorm = 0x00000051,
|
||||
astc8x8_unorm_srgb = 0x00000052,
|
||||
astc10x5_unorm = 0x00000053,
|
||||
astc10x5_unorm_srgb = 0x00000054,
|
||||
astc10x6_unorm = 0x00000055,
|
||||
astc10x6_unorm_srgb = 0x00000056,
|
||||
astc10x8_unorm = 0x00000057,
|
||||
astc10x8_unorm_srgb = 0x00000058,
|
||||
astc10x10_unorm = 0x00000059,
|
||||
astc10x10_unorm_srgb = 0x0000005a,
|
||||
astc12x10_unorm = 0x0000005b,
|
||||
astc12x10_unorm_srgb = 0x0000005c,
|
||||
astc12x12_unorm = 0x0000005d,
|
||||
astc12x12_unorm_srgb = 0x0000005e,
|
||||
r8_bg8_biplanar420_unorm = 0x0000005f,
|
||||
};
|
||||
|
||||
pub const SampleType = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
float = 0x00000001,
|
||||
unfilterable_float = 0x00000002,
|
||||
depth = 0x00000003,
|
||||
sint = 0x00000004,
|
||||
uint = 0x00000005,
|
||||
};
|
||||
|
||||
pub const UsageFlags = packed struct {
|
||||
copy_src: bool = false,
|
||||
copy_dst: bool = false,
|
||||
texture_binding: bool = false,
|
||||
storage_binding: bool = false,
|
||||
render_attachment: bool = false,
|
||||
present: bool = false,
|
||||
|
||||
_padding: u26 = 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(u6, @bitCast(u32, a)) == @truncate(u6, @bitCast(u32, b));
|
||||
}
|
||||
};
|
||||
|
||||
pub const BindingLayout = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
sample_type: SampleType = .undef,
|
||||
view_dimension: TextureView.Dimension = .dimension_undef,
|
||||
multisampled: bool = false,
|
||||
};
|
||||
|
||||
pub const DataLayout = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
offset: u64 = 0,
|
||||
bytes_per_row: u32 = types.copy_stride_undef,
|
||||
rows_per_image: u32 = types.copy_stride_undef,
|
||||
};
|
||||
|
||||
pub const Descriptor = extern struct {
|
||||
pub const NextInChain = extern union {
|
||||
generic: ?*const ChainedStruct,
|
||||
dawn_texture_internal_usage_descriptor: *const dawn.TextureInternalUsageDescriptor,
|
||||
};
|
||||
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
label: ?[*:0]const u8 = null,
|
||||
usage: UsageFlags,
|
||||
dimension: Dimension = .dimension_2d,
|
||||
size: Extent3D,
|
||||
format: Format,
|
||||
mip_level_count: u32 = 1,
|
||||
sample_count: u32 = 1,
|
||||
view_format_count: u32 = 0,
|
||||
view_formats: ?[*]const Format = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
label: ?[*:0]const u8 = null,
|
||||
usage: UsageFlags,
|
||||
dimension: Dimension = .dimension_2d,
|
||||
size: Extent3D,
|
||||
format: Format,
|
||||
mip_level_count: u32 = 1,
|
||||
sample_count: u32 = 1,
|
||||
view_formats: ?[]const Format = null,
|
||||
}) Descriptor {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.label = v.label,
|
||||
.usage = v.usage,
|
||||
.dimension = v.dimension,
|
||||
.size = v.size,
|
||||
.format = v.format,
|
||||
.mip_level_count = v.mip_level_count,
|
||||
.sample_count = v.sample_count,
|
||||
.view_format_count = if (v.view_formats) |e| @intCast(u32, e.len) else 0,
|
||||
.view_formats = if (v.view_formats) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub inline fn createView(texture: *Texture, descriptor: ?*const TextureView.Descriptor) *TextureView {
|
||||
return Impl.textureCreateView(texture, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn destroy(texture: *Texture) void {
|
||||
Impl.textureDestroy(texture);
|
||||
}
|
||||
|
||||
pub inline fn getDepthOrArrayLayers(texture: *Texture) u32 {
|
||||
return Impl.textureGetDepthOrArrayLayers(texture);
|
||||
}
|
||||
|
||||
pub inline fn getDimension(texture: *Texture) Dimension {
|
||||
return Impl.textureGetDimension(texture);
|
||||
}
|
||||
|
||||
pub inline fn getFormat(texture: *Texture) Format {
|
||||
return Impl.textureGetFormat(texture);
|
||||
}
|
||||
|
||||
pub inline fn getHeight(texture: *Texture) u32 {
|
||||
return Impl.textureGetHeight(texture);
|
||||
}
|
||||
|
||||
pub inline fn getMipLevelCount(texture: *Texture) u32 {
|
||||
return Impl.textureGetMipLevelCount(texture);
|
||||
}
|
||||
|
||||
pub inline fn getSampleCount(texture: *Texture) u32 {
|
||||
return Impl.textureGetSampleCount(texture);
|
||||
}
|
||||
|
||||
pub inline fn getUsage(texture: *Texture) UsageFlags {
|
||||
return Impl.textureGetUsage(texture);
|
||||
}
|
||||
|
||||
pub inline fn getWidth(texture: *Texture) u32 {
|
||||
return Impl.textureGetWidth(texture);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(texture: *Texture, label: [*:0]const u8) void {
|
||||
Impl.textureSetLabel(texture, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(texture: *Texture) void {
|
||||
Impl.textureReference(texture);
|
||||
}
|
||||
|
||||
pub inline fn release(texture: *Texture) void {
|
||||
Impl.textureRelease(texture);
|
||||
}
|
||||
};
|
||||
40
libs/gpu/src/texture_view.zig
Normal file
40
libs/gpu/src/texture_view.zig
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
const ChainedStruct = @import("types.zig").ChainedStruct;
|
||||
const Texture = @import("texture.zig").Texture;
|
||||
const Impl = @import("interface.zig").Impl;
|
||||
const types = @import("types.zig");
|
||||
|
||||
pub const TextureView = opaque {
|
||||
pub const Dimension = enum(u32) {
|
||||
dimension_undef = 0x00000000,
|
||||
dimension_1d = 0x00000001,
|
||||
dimension_2d = 0x00000002,
|
||||
dimension_2d_array = 0x00000003,
|
||||
dimension_cube = 0x00000004,
|
||||
dimension_cube_array = 0x00000005,
|
||||
dimension_3d = 0x00000006,
|
||||
};
|
||||
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
format: Texture.Format = .undef,
|
||||
dimension: Dimension = .dimension_undef,
|
||||
base_mip_level: u32 = 0,
|
||||
mip_level_count: u32 = types.mip_level_count_undef,
|
||||
base_array_layer: u32 = 0,
|
||||
array_layer_count: u32 = types.array_layer_count_undef,
|
||||
aspect: Texture.Aspect = .all,
|
||||
};
|
||||
|
||||
pub inline fn setLabel(texture_view: *TextureView, label: [*:0]const u8) void {
|
||||
Impl.textureViewSetLabel(texture_view, label);
|
||||
}
|
||||
|
||||
pub inline fn reference(texture_view: *TextureView) void {
|
||||
Impl.textureViewReference(texture_view);
|
||||
}
|
||||
|
||||
pub inline fn release(texture_view: *TextureView) void {
|
||||
Impl.textureViewRelease(texture_view);
|
||||
}
|
||||
};
|
||||
810
libs/gpu/src/types.zig
Normal file
810
libs/gpu/src/types.zig
Normal file
|
|
@ -0,0 +1,810 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const Texture = @import("texture.zig").Texture;
|
||||
const TextureView = @import("texture_view.zig").TextureView;
|
||||
const Buffer = @import("buffer.zig").Buffer;
|
||||
const ShaderModule = @import("shader_module.zig").ShaderModule;
|
||||
const QuerySet = @import("query_set.zig").QuerySet;
|
||||
const Surface = @import("surface.zig").Surface;
|
||||
|
||||
pub const array_layer_count_undef = 0xffffffff;
|
||||
pub const copy_stride_undef = 0xffffffff;
|
||||
pub const limit_u32_undef = 0xffffffff;
|
||||
pub const limit_u64_undef = 0xffffffffffffffff;
|
||||
pub const mip_level_count_undef = 0xffffffff;
|
||||
pub const whole_map_size = std.math.maxInt(usize);
|
||||
pub const whole_size = 0xffffffffffffffff;
|
||||
|
||||
/// Generic function pointer type, used for returning API function pointers. Must be
|
||||
/// cast to the right `fn (...) callconv(.C) T` type before use.
|
||||
pub const Proc = if (@import("builtin").zig_backend == .stage1)
|
||||
fn () callconv(.C) void
|
||||
else
|
||||
*const fn () callconv(.C) void;
|
||||
|
||||
pub const ComputePassTimestampWrite = extern struct {
|
||||
query_set: *QuerySet,
|
||||
query_index: u32,
|
||||
location: ComputePassTimestampLocation,
|
||||
};
|
||||
|
||||
pub const RenderPassDepthStencilAttachment = extern struct {
|
||||
view: *TextureView,
|
||||
depth_load_op: LoadOp = .undef,
|
||||
depth_store_op: StoreOp = .undef,
|
||||
/// deprecated
|
||||
clear_depth: f32 = std.math.nan(f32),
|
||||
depth_clear_value: f32 = 0,
|
||||
depth_read_only: bool = false,
|
||||
stencil_load_op: LoadOp = .undef,
|
||||
stencil_store_op: StoreOp = .undef,
|
||||
/// deprecated
|
||||
clear_stencil: u32 = 0,
|
||||
stencil_clear_value: u32 = 0,
|
||||
stencil_read_only: bool = false,
|
||||
};
|
||||
|
||||
pub const RenderPassTimestampWrite = extern struct {
|
||||
query_set: *QuerySet,
|
||||
query_index: u32,
|
||||
location: RenderPassTimestampLocation,
|
||||
};
|
||||
|
||||
pub const RequestAdapterOptions = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
compatible_surface: ?*Surface = null,
|
||||
power_preference: PowerPreference = .undef,
|
||||
force_fallback_adapter: bool = false,
|
||||
};
|
||||
|
||||
pub const ComputePassDescriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
timestamp_write_count: u32 = 0,
|
||||
timestamp_writes: ?[*]const ComputePassTimestampWrite = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
timestamp_writes: ?[]const ComputePassTimestampWrite = null,
|
||||
}) ComputePassDescriptor {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.label = v.label,
|
||||
.timestamp_write_count = if (v.timestamp_writes) |e| @intCast(u32, e.len) else 0,
|
||||
.timestamp_writes = if (v.timestamp_writes) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const RenderPassDescriptor = extern struct {
|
||||
pub const NextInChain = extern union {
|
||||
generic: ?*const ChainedStruct,
|
||||
max_draw_count: *const RenderPassDescriptorMaxDrawCount,
|
||||
};
|
||||
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
label: ?[*:0]const u8 = null,
|
||||
color_attachment_count: u32 = 0,
|
||||
color_attachments: ?[*]const RenderPassColorAttachment = null,
|
||||
depth_stencil_attachment: ?*const RenderPassDepthStencilAttachment = null,
|
||||
occlusion_query_set: ?*QuerySet = null,
|
||||
timestamp_write_count: u32 = 0,
|
||||
timestamp_writes: ?[*]const RenderPassTimestampWrite = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
label: ?[*:0]const u8 = null,
|
||||
color_attachments: ?[]const RenderPassColorAttachment = null,
|
||||
depth_stencil_attachment: ?*const RenderPassDepthStencilAttachment = null,
|
||||
occlusion_query_set: ?*QuerySet = null,
|
||||
timestamp_writes: ?[]const RenderPassTimestampWrite = null,
|
||||
}) RenderPassDescriptor {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.label = v.label,
|
||||
.color_attachment_count = if (v.color_attachments) |e| @intCast(u32, e.len) else 0,
|
||||
.color_attachments = if (v.color_attachments) |e| e.ptr else null,
|
||||
.depth_stencil_attachment = v.depth_stencil_attachment,
|
||||
.occlusion_query_set = v.occlusion_query_set,
|
||||
.timestamp_write_count = if (v.timestamp_writes) |e| @intCast(u32, e.len) else 0,
|
||||
.timestamp_writes = if (v.timestamp_writes) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const AlphaMode = enum(u32) { premultiplied = 0x00000000, unpremultiplied = 0x00000001, opaq = 0x00000002 };
|
||||
|
||||
pub const BackendType = enum(u32) {
|
||||
nul,
|
||||
webgpu,
|
||||
d3d11,
|
||||
d3d12,
|
||||
metal,
|
||||
vulkan,
|
||||
opengl,
|
||||
opengles,
|
||||
|
||||
pub fn name(t: BackendType) []const u8 {
|
||||
return switch (t) {
|
||||
.nul => "Null",
|
||||
.webgpu => "WebGPU",
|
||||
.d3d11 => "D3D11",
|
||||
.d3d12 => "D3D12",
|
||||
.metal => "Metal",
|
||||
.vulkan => "Vulkan",
|
||||
.opengl => "OpenGL",
|
||||
.opengles => "OpenGLES",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const BlendFactor = enum(u32) {
|
||||
zero = 0x00000000,
|
||||
one = 0x00000001,
|
||||
src = 0x00000002,
|
||||
one_minus_src = 0x00000003,
|
||||
src_alpha = 0x00000004,
|
||||
one_minus_src_alpha = 0x00000005,
|
||||
dst = 0x00000006,
|
||||
one_minus_dst = 0x00000007,
|
||||
dst_alpha = 0x00000008,
|
||||
one_minus_dst_alpha = 0x00000009,
|
||||
src_alpha_saturated = 0x0000000A,
|
||||
constant = 0x0000000B,
|
||||
one_minus_constant = 0x0000000C,
|
||||
};
|
||||
|
||||
pub const BlendOperation = enum(u32) {
|
||||
add = 0x00000000,
|
||||
subtract = 0x00000001,
|
||||
reverse_subtract = 0x00000002,
|
||||
min = 0x00000003,
|
||||
max = 0x00000004,
|
||||
};
|
||||
|
||||
pub const CompareFunction = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
never = 0x00000001,
|
||||
less = 0x00000002,
|
||||
less_equal = 0x00000003,
|
||||
greater = 0x00000004,
|
||||
greater_equal = 0x00000005,
|
||||
equal = 0x00000006,
|
||||
not_equal = 0x00000007,
|
||||
always = 0x00000008,
|
||||
};
|
||||
|
||||
pub const CompilationInfoRequestStatus = enum(u32) {
|
||||
success = 0x00000000,
|
||||
err = 0x00000001,
|
||||
device_lost = 0x00000002,
|
||||
unknown = 0x00000003,
|
||||
};
|
||||
|
||||
pub const CompilationMessageType = enum(u32) {
|
||||
err = 0x00000000,
|
||||
warning = 0x00000001,
|
||||
info = 0x00000002,
|
||||
};
|
||||
|
||||
pub const ComputePassTimestampLocation = enum(u32) {
|
||||
beginning = 0x00000000,
|
||||
end = 0x00000001,
|
||||
};
|
||||
|
||||
pub const CreatePipelineAsyncStatus = enum(u32) {
|
||||
success = 0x00000000,
|
||||
err = 0x00000001,
|
||||
device_lost = 0x00000002,
|
||||
device_destroyed = 0x00000003,
|
||||
unknown = 0x00000004,
|
||||
};
|
||||
|
||||
pub const CullMode = enum(u32) {
|
||||
none = 0x00000000,
|
||||
front = 0x00000001,
|
||||
back = 0x00000002,
|
||||
};
|
||||
|
||||
pub const ErrorFilter = enum(u32) {
|
||||
validation = 0x00000000,
|
||||
out_of_memory = 0x00000001,
|
||||
};
|
||||
|
||||
pub const ErrorType = enum(u32) {
|
||||
no_error = 0x00000000,
|
||||
validation = 0x00000001,
|
||||
out_of_memory = 0x00000002,
|
||||
unknown = 0x00000003,
|
||||
device_lost = 0x00000004,
|
||||
};
|
||||
|
||||
pub const FeatureName = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
depth_clip_control = 0x00000001,
|
||||
depth32_float_stencil8 = 0x00000002,
|
||||
timestamp_query = 0x00000003,
|
||||
pipeline_statistics_query = 0x00000004,
|
||||
texture_compression_bc = 0x00000005,
|
||||
texture_compression_etc2 = 0x00000006,
|
||||
texture_compression_astc = 0x00000007,
|
||||
indirect_first_instance = 0x00000008,
|
||||
dawn_shader_float16 = 0x000003e9,
|
||||
dawn_internal_usages = 0x000003ea,
|
||||
dawn_multi_planar_formats = 0x000003eb,
|
||||
dawn_native = 0x000003ec,
|
||||
chromium_experimental_dp4a = 0x000003ed,
|
||||
};
|
||||
|
||||
pub const FilterMode = enum(u32) {
|
||||
nearest = 0x00000000,
|
||||
linear = 0x00000001,
|
||||
};
|
||||
|
||||
pub const FrontFace = enum(u32) {
|
||||
ccw = 0x00000000,
|
||||
cw = 0x00000001,
|
||||
};
|
||||
|
||||
pub const IndexFormat = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
uint16 = 0x00000001,
|
||||
uint32 = 0x00000002,
|
||||
};
|
||||
|
||||
pub const LoadOp = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
clear = 0x00000001,
|
||||
load = 0x00000002,
|
||||
};
|
||||
|
||||
pub const LoggingType = enum(u32) {
|
||||
verbose = 0x00000000,
|
||||
info = 0x00000001,
|
||||
warning = 0x00000002,
|
||||
err = 0x00000003,
|
||||
};
|
||||
|
||||
pub const PipelineStatisticName = enum(u32) {
|
||||
vertex_shader_invocations = 0x00000000,
|
||||
clipper_invocations = 0x00000001,
|
||||
clipper_primitives_out = 0x00000002,
|
||||
fragment_shader_invocations = 0x00000003,
|
||||
compute_shader_invocations = 0x00000004,
|
||||
};
|
||||
|
||||
pub const PowerPreference = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
low_power = 0x00000001,
|
||||
high_performance = 0x00000002,
|
||||
};
|
||||
|
||||
pub const PresentMode = enum(u32) {
|
||||
immediate = 0x00000000,
|
||||
mailbox = 0x00000001,
|
||||
fifo = 0x00000002,
|
||||
};
|
||||
|
||||
pub const PrimitiveTopology = enum(u32) {
|
||||
point_list = 0x00000000,
|
||||
line_list = 0x00000001,
|
||||
line_strip = 0x00000002,
|
||||
triangle_list = 0x00000003,
|
||||
triangle_strip = 0x00000004,
|
||||
};
|
||||
|
||||
pub const QueryType = enum(u32) {
|
||||
occlusion = 0x00000000,
|
||||
pipeline_statistics = 0x00000001,
|
||||
timestamp = 0x00000002,
|
||||
};
|
||||
|
||||
pub const RenderPassTimestampLocation = enum(u32) {
|
||||
beginning = 0x00000000,
|
||||
end = 0x00000001,
|
||||
};
|
||||
|
||||
pub const RequestAdapterStatus = enum(u32) {
|
||||
success = 0x00000000,
|
||||
unavailable = 0x00000001,
|
||||
err = 0x00000002,
|
||||
unknown = 0x00000003,
|
||||
};
|
||||
|
||||
pub const RequestDeviceStatus = enum(u32) {
|
||||
success = 0x00000000,
|
||||
err = 0x00000001,
|
||||
unknown = 0x00000002,
|
||||
};
|
||||
|
||||
pub const SType = enum(u32) {
|
||||
invalid = 0x00000000,
|
||||
surface_descriptor_from_metal_layer = 0x00000001,
|
||||
surface_descriptor_from_windows_hwnd = 0x00000002,
|
||||
surface_descriptor_from_xlib_window = 0x00000003,
|
||||
surface_descriptor_from_canvas_html_selector = 0x00000004,
|
||||
shader_module_spirv_descriptor = 0x00000005,
|
||||
shader_module_wgsl_descriptor = 0x00000006,
|
||||
primitive_depth_clip_control = 0x00000007,
|
||||
surface_descriptor_from_wayland_surface = 0x00000008,
|
||||
surface_descriptor_from_android_native_window = 0x00000009,
|
||||
surface_descriptor_from_windows_core_window = 0x0000000B,
|
||||
external_texture_binding_entry = 0x0000000C,
|
||||
external_texture_binding_layout = 0x0000000D,
|
||||
surface_descriptor_from_windows_swap_chain_panel = 0x0000000E,
|
||||
render_pass_descriptor_max_draw_count = 0x0000000F,
|
||||
dawn_texture_internal_usage_descriptor = 0x000003E8,
|
||||
dawn_toggles_device_descriptor = 0x000003EA,
|
||||
dawn_encoder_internal_usage_descriptor = 0x000003EB,
|
||||
dawn_instance_descriptor = 0x000003EC,
|
||||
dawn_cache_device_descriptor = 0x000003ED,
|
||||
};
|
||||
|
||||
pub const StencilOperation = enum(u32) {
|
||||
keep = 0x00000000,
|
||||
zero = 0x00000001,
|
||||
replace = 0x00000002,
|
||||
invert = 0x00000003,
|
||||
increment_clamp = 0x00000004,
|
||||
decrement_clamp = 0x00000005,
|
||||
increment_wrap = 0x00000006,
|
||||
decrement_wrap = 0x00000007,
|
||||
};
|
||||
|
||||
pub const StorageTextureAccess = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
write_only = 0x00000001,
|
||||
};
|
||||
|
||||
pub const StoreOp = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
store = 0x00000001,
|
||||
discard = 0x00000002,
|
||||
};
|
||||
|
||||
pub const VertexFormat = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
uint8x2 = 0x00000001,
|
||||
uint8x4 = 0x00000002,
|
||||
sint8x2 = 0x00000003,
|
||||
sint8x4 = 0x00000004,
|
||||
unorm8x2 = 0x00000005,
|
||||
unorm8x4 = 0x00000006,
|
||||
snorm8x2 = 0x00000007,
|
||||
snorm8x4 = 0x00000008,
|
||||
uint16x2 = 0x00000009,
|
||||
uint16x4 = 0x0000000a,
|
||||
sint16x2 = 0x0000000b,
|
||||
sint16x4 = 0x0000000c,
|
||||
unorm16x2 = 0x0000000d,
|
||||
unorm16x4 = 0x0000000e,
|
||||
snorm16x2 = 0x0000000f,
|
||||
snorm16x4 = 0x00000010,
|
||||
float16x2 = 0x00000011,
|
||||
float16x4 = 0x00000012,
|
||||
float32 = 0x00000013,
|
||||
float32x2 = 0x00000014,
|
||||
float32x3 = 0x00000015,
|
||||
float32x4 = 0x00000016,
|
||||
uint32 = 0x00000017,
|
||||
uint32x2 = 0x00000018,
|
||||
uint32x3 = 0x00000019,
|
||||
uint32x4 = 0x0000001a,
|
||||
sint32 = 0x0000001b,
|
||||
sint32x2 = 0x0000001c,
|
||||
sint32x3 = 0x0000001d,
|
||||
sint32x4 = 0x0000001e,
|
||||
};
|
||||
|
||||
pub const VertexStepMode = enum(u32) {
|
||||
vertex = 0x00000000,
|
||||
instance = 0x00000001,
|
||||
vertex_buffer_not_used = 0x00000002,
|
||||
};
|
||||
|
||||
pub const ColorWriteMaskFlags = packed struct {
|
||||
red: bool = false,
|
||||
green: bool = false,
|
||||
blue: bool = false,
|
||||
alpha: bool = false,
|
||||
|
||||
_padding: u28 = 0,
|
||||
|
||||
comptime {
|
||||
std.debug.assert(
|
||||
@sizeOf(@This()) == @sizeOf(u32) and
|
||||
@bitSizeOf(@This()) == @bitSizeOf(u32),
|
||||
);
|
||||
}
|
||||
|
||||
pub const all = ColorWriteMaskFlags{
|
||||
.red = true,
|
||||
.green = true,
|
||||
.blue = true,
|
||||
.alpha = true,
|
||||
};
|
||||
|
||||
pub fn equal(a: ColorWriteMaskFlags, b: ColorWriteMaskFlags) bool {
|
||||
return @truncate(u4, @bitCast(u32, a)) == @truncate(u4, @bitCast(u32, b));
|
||||
}
|
||||
};
|
||||
|
||||
pub const MapModeFlags = packed struct {
|
||||
read: bool = false,
|
||||
write: bool = false,
|
||||
|
||||
_padding: u30 = 0,
|
||||
|
||||
comptime {
|
||||
std.debug.assert(
|
||||
@sizeOf(@This()) == @sizeOf(u32) and
|
||||
@bitSizeOf(@This()) == @bitSizeOf(u32),
|
||||
);
|
||||
}
|
||||
|
||||
pub const undef = MapModeFlags{};
|
||||
|
||||
pub fn equal(a: MapModeFlags, b: MapModeFlags) bool {
|
||||
return @truncate(u2, @bitCast(u32, a)) == @truncate(u2, @bitCast(u32, b));
|
||||
}
|
||||
};
|
||||
|
||||
pub const ShaderStageFlags = packed struct {
|
||||
vertex: bool = false,
|
||||
fragment: bool = false,
|
||||
compute: bool = false,
|
||||
|
||||
_padding: u29 = 0,
|
||||
|
||||
comptime {
|
||||
std.debug.assert(
|
||||
@sizeOf(@This()) == @sizeOf(u32) and
|
||||
@bitSizeOf(@This()) == @bitSizeOf(u32),
|
||||
);
|
||||
}
|
||||
|
||||
pub const none = ShaderStageFlags{};
|
||||
|
||||
pub fn equal(a: ShaderStageFlags, b: ShaderStageFlags) bool {
|
||||
return @truncate(u3, @bitCast(u32, a)) == @truncate(u3, @bitCast(u32, b));
|
||||
}
|
||||
};
|
||||
|
||||
pub const ChainedStruct = extern struct {
|
||||
// TODO: dawn: not marked as nullable in dawn.json but in fact is.
|
||||
next: ?*const ChainedStruct = null,
|
||||
s_type: SType,
|
||||
};
|
||||
|
||||
pub const ChainedStructOut = extern struct {
|
||||
// TODO: dawn: not marked as nullable in dawn.json but in fact is.
|
||||
next: ?*ChainedStructOut = null,
|
||||
s_type: SType,
|
||||
};
|
||||
|
||||
pub const BlendComponent = extern struct {
|
||||
operation: BlendOperation = .add,
|
||||
src_factor: BlendFactor = .one,
|
||||
dst_factor: BlendFactor = .zero,
|
||||
};
|
||||
|
||||
pub const Color = extern struct {
|
||||
r: f64,
|
||||
g: f64,
|
||||
b: f64,
|
||||
a: f64,
|
||||
};
|
||||
|
||||
pub const Extent3D = extern struct {
|
||||
width: u32,
|
||||
height: u32 = 1,
|
||||
depth_or_array_layers: u32 = 1,
|
||||
};
|
||||
|
||||
pub const Limits = extern struct {
|
||||
max_texture_dimension_1d: u32 = limit_u32_undef,
|
||||
max_texture_dimension_2d: u32 = limit_u32_undef,
|
||||
max_texture_dimension_3d: u32 = limit_u32_undef,
|
||||
max_texture_array_layers: u32 = limit_u32_undef,
|
||||
max_bind_groups: u32 = limit_u32_undef,
|
||||
max_dynamic_uniform_buffers_per_pipeline_layout: u32 = limit_u32_undef,
|
||||
max_dynamic_storage_buffers_per_pipeline_layout: u32 = limit_u32_undef,
|
||||
max_sampled_textures_per_shader_stage: u32 = limit_u32_undef,
|
||||
max_samplers_per_shader_stage: u32 = limit_u32_undef,
|
||||
max_storage_buffers_per_shader_stage: u32 = limit_u32_undef,
|
||||
max_storage_textures_per_shader_stage: u32 = limit_u32_undef,
|
||||
max_uniform_buffers_per_shader_stage: u32 = limit_u32_undef,
|
||||
max_uniform_buffer_binding_size: u64 = limit_u64_undef,
|
||||
max_storage_buffer_binding_size: u64 = limit_u64_undef,
|
||||
min_uniform_buffer_offset_alignment: u32 = limit_u32_undef,
|
||||
min_storage_buffer_offset_alignment: u32 = limit_u32_undef,
|
||||
max_vertex_buffers: u32 = limit_u32_undef,
|
||||
max_vertex_attributes: u32 = limit_u32_undef,
|
||||
max_vertex_buffer_array_stride: u32 = limit_u32_undef,
|
||||
max_inter_stage_shader_components: u32 = limit_u32_undef,
|
||||
max_inter_stage_shader_variables: u32 = limit_u32_undef,
|
||||
max_color_attachments: u32 = limit_u32_undef,
|
||||
max_compute_workgroup_storage_size: u32 = limit_u32_undef,
|
||||
max_compute_invocations_per_workgroup: u32 = limit_u32_undef,
|
||||
max_compute_workgroup_size_x: u32 = limit_u32_undef,
|
||||
max_compute_workgroup_size_y: u32 = limit_u32_undef,
|
||||
max_compute_workgroup_size_z: u32 = limit_u32_undef,
|
||||
max_compute_workgroups_per_dimension: u32 = limit_u32_undef,
|
||||
};
|
||||
|
||||
pub const Origin3D = extern struct {
|
||||
x: u32 = 0,
|
||||
y: u32 = 0,
|
||||
z: u32 = 0,
|
||||
};
|
||||
|
||||
pub const CompilationMessage = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
message: ?[*:0]const u8 = null,
|
||||
type: CompilationMessageType,
|
||||
line_num: u64,
|
||||
line_pos: u64,
|
||||
offset: u64,
|
||||
length: u64,
|
||||
};
|
||||
|
||||
pub const ConstantEntry = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
key: [*:0]const u8,
|
||||
value: f64,
|
||||
};
|
||||
|
||||
pub const CopyTextureForBrowserOptions = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
flip_y: bool = false,
|
||||
needs_color_space_conversion: bool = false,
|
||||
src_alpha_mode: AlphaMode = .unpremultiplied,
|
||||
src_transfer_function_parameters: ?*const [7]f32 = null,
|
||||
conversion_matrix: ?*const [9]f32 = null,
|
||||
dst_transfer_function_parameters: ?*const [7]f32 = null,
|
||||
dst_alpha_mode: AlphaMode = .unpremultiplied,
|
||||
internal_usage: bool = false,
|
||||
};
|
||||
|
||||
pub const MultisampleState = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
count: u32 = 1,
|
||||
mask: u32 = 0xFFFFFFFF,
|
||||
alpha_to_coverage_enabled: bool = false,
|
||||
};
|
||||
|
||||
pub const PrimitiveDepthClipControl = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .primitive_depth_clip_control },
|
||||
unclipped_depth: bool = false,
|
||||
};
|
||||
|
||||
pub const PrimitiveState = extern struct {
|
||||
pub const NextInChain = extern union {
|
||||
generic: ?*const ChainedStruct,
|
||||
primitive_depth_clip_control: *const PrimitiveDepthClipControl,
|
||||
};
|
||||
|
||||
next_in_chain: NextInChain = .{ .generic = null },
|
||||
topology: PrimitiveTopology = .triangle_list,
|
||||
strip_index_format: IndexFormat = .undef,
|
||||
front_face: FrontFace = .ccw,
|
||||
cull_mode: CullMode = .none,
|
||||
};
|
||||
|
||||
pub const RenderPassDescriptorMaxDrawCount = extern struct {
|
||||
chain: ChainedStruct = .{ .next = null, .s_type = .render_pass_descriptor_max_draw_count },
|
||||
max_draw_count: u64 = 50000000,
|
||||
};
|
||||
|
||||
pub const StencilFaceState = extern struct {
|
||||
compare: CompareFunction = .always,
|
||||
fail_op: StencilOperation = .keep,
|
||||
depth_fail_op: StencilOperation = .keep,
|
||||
pass_op: StencilOperation = .keep,
|
||||
};
|
||||
|
||||
pub const StorageTextureBindingLayout = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
access: StorageTextureAccess = .undef,
|
||||
format: Texture.Format = .undef,
|
||||
view_dimension: TextureView.Dimension = .dimension_undef,
|
||||
};
|
||||
|
||||
pub const VertexAttribute = extern struct {
|
||||
format: VertexFormat,
|
||||
offset: u64,
|
||||
shader_location: u32,
|
||||
};
|
||||
|
||||
pub const BlendState = extern struct {
|
||||
color: BlendComponent = .{},
|
||||
alpha: BlendComponent = .{},
|
||||
};
|
||||
|
||||
pub const CompilationInfo = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
message_count: u32,
|
||||
messages: ?[*]const CompilationMessage = null,
|
||||
|
||||
/// Helper to get messages as a slice.
|
||||
pub fn getMessages(info: CompilationInfo) ?[]const CompilationMessage {
|
||||
if (info.messages) |messages| {
|
||||
return messages[0..info.message_count];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
pub const DepthStencilState = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
format: Texture.Format,
|
||||
depth_write_enabled: bool = false,
|
||||
depth_compare: CompareFunction = .always,
|
||||
stencil_front: StencilFaceState = .{},
|
||||
stencil_back: StencilFaceState = .{},
|
||||
stencil_read_mask: u32 = 0xFFFFFFFF,
|
||||
stencil_write_mask: u32 = 0xFFFFFFFF,
|
||||
depth_bias: i32 = 0,
|
||||
depth_bias_slope_scale: f32 = 0.0,
|
||||
depth_bias_clamp: f32 = 0.0,
|
||||
};
|
||||
|
||||
pub const ImageCopyBuffer = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
layout: Texture.DataLayout,
|
||||
buffer: *Buffer,
|
||||
};
|
||||
|
||||
pub const ImageCopyTexture = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
texture: *Texture,
|
||||
mip_level: u32 = 0,
|
||||
origin: Origin3D = .{},
|
||||
aspect: Texture.Aspect = .all,
|
||||
};
|
||||
|
||||
pub const ProgrammableStageDescriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
module: *ShaderModule,
|
||||
entry_point: [*:0]const u8,
|
||||
constant_count: u32 = 0,
|
||||
constants: ?[*]const ConstantEntry = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
module: *ShaderModule,
|
||||
entry_point: [*:0]const u8,
|
||||
constants: ?[]const ConstantEntry = null,
|
||||
}) ProgrammableStageDescriptor {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.module = v.module,
|
||||
.entry_point = v.entry_point,
|
||||
.constant_count = if (v.constants) |e| @intCast(u32, e.len) else 0,
|
||||
.constants = if (v.constants) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const RenderPassColorAttachment = extern struct {
|
||||
view: ?*TextureView = null,
|
||||
resolve_target: ?*TextureView = null,
|
||||
load_op: LoadOp,
|
||||
store_op: StoreOp,
|
||||
/// deprecated
|
||||
clear_color: Color = .{
|
||||
.r = std.math.nan(f64),
|
||||
.g = std.math.nan(f64),
|
||||
.b = std.math.nan(f64),
|
||||
.a = std.math.nan(f64),
|
||||
},
|
||||
clear_value: Color,
|
||||
};
|
||||
|
||||
pub const RequiredLimits = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
limits: Limits,
|
||||
};
|
||||
|
||||
pub const SupportedLimits = extern struct {
|
||||
next_in_chain: ?*ChainedStructOut = null,
|
||||
limits: Limits,
|
||||
};
|
||||
|
||||
pub const VertexBufferLayout = extern struct {
|
||||
array_stride: u64,
|
||||
step_mode: VertexStepMode = .vertex,
|
||||
attribute_count: u32,
|
||||
attributes: ?[*]const VertexAttribute = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
array_stride: u64,
|
||||
step_mode: VertexStepMode = .vertex,
|
||||
attributes: ?[]const VertexAttribute = null,
|
||||
}) VertexBufferLayout {
|
||||
return .{
|
||||
.array_stride = v.array_stride,
|
||||
.step_mode = v.step_mode,
|
||||
.attribute_count = if (v.attributes) |e| @intCast(u32, e.len) else 0,
|
||||
.attributes = if (v.attributes) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const ColorTargetState = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
format: Texture.Format,
|
||||
blend: ?*const BlendState = null,
|
||||
write_mask: ColorWriteMaskFlags = ColorWriteMaskFlags.all,
|
||||
};
|
||||
|
||||
pub const VertexState = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
module: *ShaderModule,
|
||||
entry_point: [*:0]const u8,
|
||||
constant_count: u32 = 0,
|
||||
constants: ?[*]const ConstantEntry = null,
|
||||
buffer_count: u32 = 0,
|
||||
buffers: ?[*]const VertexBufferLayout = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
module: *ShaderModule,
|
||||
entry_point: [*:0]const u8,
|
||||
constants: ?[]const ConstantEntry = null,
|
||||
buffers: ?[]const VertexBufferLayout = null,
|
||||
}) VertexState {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.module = v.module,
|
||||
.entry_point = v.entry_point,
|
||||
.constant_count = if (v.constants) |e| @intCast(u32, e.len) else 0,
|
||||
.constants = if (v.constants) |e| e.ptr else null,
|
||||
.buffer_count = if (v.buffers) |e| @intCast(u32, e.len) else 0,
|
||||
.buffers = if (v.buffers) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const FragmentState = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
module: *ShaderModule,
|
||||
entry_point: [*:0]const u8,
|
||||
constant_count: u32 = 0,
|
||||
constants: ?[*]const ConstantEntry = null,
|
||||
target_count: u32,
|
||||
targets: ?[*]const ColorTargetState = null,
|
||||
|
||||
/// Provides a slightly friendlier Zig API to initialize this structure.
|
||||
pub inline fn init(v: struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
module: *ShaderModule,
|
||||
entry_point: [*:0]const u8,
|
||||
constants: ?[]const ConstantEntry = null,
|
||||
targets: ?[]const ColorTargetState = null,
|
||||
}) FragmentState {
|
||||
return .{
|
||||
.next_in_chain = v.next_in_chain,
|
||||
.module = v.module,
|
||||
.entry_point = v.entry_point,
|
||||
.constant_count = if (v.constants) |e| @intCast(u32, e.len) else 0,
|
||||
.constants = if (v.constants) |e| e.ptr else null,
|
||||
.target_count = if (v.targets) |e| @intCast(u32, e.len) else 0,
|
||||
.targets = if (v.targets) |e| e.ptr else null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
test "BackendType name" {
|
||||
try testing.expectEqualStrings("Vulkan", BackendType.vulkan.name());
|
||||
}
|
||||
|
||||
test "enum name" {
|
||||
try testing.expectEqualStrings("front", @tagName(CullMode.front));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue