Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/triangle/triangle.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn main() !void {
.label = wgpu.StringView.fromSlice("Render texture"),
.size = output_extent,
.format = swap_chain_format,
.usage = wgpu.TextureUsages.render_attachment | wgpu.TextureUsages.copy_src,
.usage = wgpu.TextureUsage{ .render_attachment = true, .copy_src = true },
});
defer target_texture.release();

Expand All @@ -56,7 +56,7 @@ pub fn main() !void {

const staging_buffer = try device.createBuffer(&wgpu.BufferDescriptor {
.label = wgpu.StringView.fromSlice("staging_buffer"),
.usage = wgpu.BufferUsages.map_read | wgpu.BufferUsages.copy_dst,
.usage = wgpu.BufferUsage{ .map_read = true, .copy_dst = true },
.size = output_size,
.mapped_at_creation = @as(u32, @intFromBool(false)),
});
Expand Down Expand Up @@ -147,7 +147,7 @@ pub fn main() !void {
queue.submit(&[_]*const wgpu.CommandBuffer{command_buffer});

var buffer_map_complete = false;
_ = staging_buffer.mapAsync(wgpu.MapModes.read, 0, output_size, wgpu.BufferMapCallbackInfo {
_ = staging_buffer.mapAsync(wgpu.MapMode{ .read = true }, 0, output_size, wgpu.BufferMapCallbackInfo {
.callback = handleBufferMap,
.userdata1 = @ptrCast(&buffer_map_complete),
});
Expand Down
38 changes: 20 additions & 18 deletions src/buffer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ pub const BufferBindingLayout = extern struct {
min_binding_size: u64 = 0,
};

pub const BufferUsage = WGPUFlags;
pub const BufferUsages = struct {
pub const none = @as(BufferUsage, 0x0000000000000000);
pub const map_read = @as(BufferUsage, 0x0000000000000001);
pub const map_write = @as(BufferUsage, 0x0000000000000002);
pub const copy_src = @as(BufferUsage, 0x0000000000000004);
pub const copy_dst = @as(BufferUsage, 0x0000000000000008);
pub const index = @as(BufferUsage, 0x0000000000000010);
pub const vertex = @as(BufferUsage, 0x0000000000000020);
pub const uniform = @as(BufferUsage, 0x0000000000000040);
pub const storage = @as(BufferUsage, 0x0000000000000080);
pub const indirect = @as(BufferUsage, 0x0000000000000100);
pub const query_resolve = @as(BufferUsage, 0x0000000000000200);
pub const BufferUsage = packed struct(WGPUFlags) {
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,
_: u54 = 0,

pub const none = BufferUsage{};
};

pub const BufferMapState = enum(u32) {
Expand All @@ -49,11 +50,12 @@ pub const BufferMapState = enum(u32) {
mapped = 0x00000003,
};

pub const MapMode = WGPUFlags;
pub const MapModes = struct {
pub const none = @as(MapMode, 0x0000000000000000);
pub const read = @as(MapMode, 0x0000000000000001);
pub const write = @as(MapMode, 0x0000000000000002);
pub const MapMode = packed struct(WGPUFlags) {
read: bool = false,
write: bool = false,
_: u62 = 0,

pub const none = MapMode{};
};

pub const MapAsyncStatus = enum(u32) {
Expand Down
36 changes: 19 additions & 17 deletions src/instance.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,27 @@ const WaitStatus = _async.WaitStatus;
const FutureWaitInfo = _async.FutureWaitInfo;
const CallbackMode = _async.CallbackMode;

pub const InstanceBackend = WGPUFlags;
pub const InstanceBackends = struct {
pub const all = @as(InstanceBackend, 0x00000000);
pub const vulkan = @as(InstanceBackend, 0x00000001);
pub const gl = @as(InstanceBackend, 0x00000002);
pub const metal = @as(InstanceBackend, 0x00000004);
pub const dx12 = @as(InstanceBackend, 0x00000008);
pub const dx11 = @as(InstanceBackend, 0x00000010);
pub const browser_webgpu = @as(InstanceBackend, 0x00000020);
pub const primary = vulkan | metal | dx12 | browser_webgpu;
pub const secondary = gl | dx11;
pub const InstanceBackend = packed struct(WGPUFlags) {
vulkan: bool = false,
gl: bool = false,
metal: bool = false,
dx12: bool = false,
dx11: bool = false,
browser_webgpu: bool = false,
_: u58 = 0,

pub const all = Instance{};
pub const primary = InstanceBackend{ .vulkan = true , .metal = true, .dx12 = true, .browser_webgpu = true };
pub const secondary = InstanceBackend{ .gl = true, .dx11 = true };
};

pub const InstanceFlag = WGPUFlags;
pub const InstanceFlags = struct {
pub const default = @as(InstanceFlag, 0x00000000);
pub const debug = @as(InstanceFlag, 0x00000001);
pub const validation = @as(InstanceFlag, 0x00000002);
pub const discard_hal_labels = @as(InstanceFlag, 0x00000004);
pub const InstanceFlag = packed struct(WGPUFlags) {
debug: bool = false,
validation: bool = false,
discard_hal_labels: bool = false,
_: u61 = 0,

pub const default = InstanceFlag{};
};

pub const Dx12Compiler = enum(u32) {
Expand Down
19 changes: 10 additions & 9 deletions src/pipeline.zig
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,15 @@ pub const BlendState = extern struct {
};
};

pub const ColorWriteMask = WGPUFlags;
pub const ColorWriteMasks = struct {
pub const none = @as(ColorWriteMask, 0x0000000000000000);
pub const red = @as(ColorWriteMask, 0x0000000000000001);
pub const green = @as(ColorWriteMask, 0x0000000000000002);
pub const blue = @as(ColorWriteMask, 0x0000000000000004);
pub const alpha = @as(ColorWriteMask, 0x0000000000000008);
pub const all = none | red | green | blue | alpha;
pub const ColorWriteMask = packed struct(WGPUFlags) {
red: bool = false,
green: bool = false,
blue: bool = false,
alpha: bool = false,
_: u60 = 0,

pub const none = ColorWriteMask{};
pub const all = ColorWriteMask{ .red = true, .green = true, .blue = true, .alpha = true };
};

pub const ColorTargetState = extern struct {
Expand All @@ -400,7 +401,7 @@ pub const ColorTargetState = extern struct {
format: TextureFormat,

blend: ?*const BlendState = null,
write_mask: ColorWriteMask = ColorWriteMasks.all,
write_mask: ColorWriteMask = ColorWriteMask.all,
};

pub const FragmentState = extern struct {
Expand Down
7 changes: 0 additions & 7 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ pub const WGPU_WHOLE_MAP_SIZE = _buffer.WGPU_WHOLE_MAP_SIZE;
pub const BufferBindingType = _buffer.BufferBindingType;
pub const BufferBindingLayout = _buffer.BufferBindingLayout;
pub const BufferUsage = _buffer.BufferUsage;
pub const BufferUsages = _buffer.BufferUsages;
pub const BufferMapState = _buffer.BufferMapState;
pub const MapMode = _buffer.MapMode;
pub const MapModes = _buffer.MapModes;
pub const MapAsyncStatus = _buffer.MapAsyncStatus;
pub const BufferMapCallbackInfo = _buffer.BufferMapCallbackInfo;
pub const BufferMapCallback = _buffer.BufferMapCallback;
Expand Down Expand Up @@ -104,9 +102,7 @@ pub const Device = _device.Device;

const _instance = @import("instance.zig");
pub const InstanceBackend = _instance.InstanceBackend;
pub const InstanceBackends = _instance.InstanceBackends;
pub const InstanceFlag = _instance.InstanceFlag;
pub const InstanceFlags = _instance.InstanceFlags;
pub const Dx12Compiler = _instance.Dx12Compiler;
pub const Gles3MinorVersion = _instance.Gles3MinorVersion;
pub const DxcMaxShaderModel = _instance.DxcMaxShaderModel;
Expand Down Expand Up @@ -166,7 +162,6 @@ pub const BlendFactor = _pipeline.BlendFactor;
pub const BlendComponent = _pipeline.BlendComponent;
pub const BlendState = _pipeline.BlendState;
pub const ColorWriteMask = _pipeline.ColorWriteMask;
pub const ColorWriteMasks = _pipeline.ColorWriteMasks;
pub const ColorTargetState = _pipeline.ColorTargetState;
pub const FragmentState = _pipeline.FragmentState;
pub const RenderPipelineDescriptor = _pipeline.RenderPipelineDescriptor;
Expand Down Expand Up @@ -212,7 +207,6 @@ pub const Sampler = _sampler.Sampler;

const _shader = @import("shader.zig");
pub const ShaderStage = _shader.ShaderStage;
pub const ShaderStages = _shader.ShaderStages;
pub const ShaderModuleDescriptor = _shader.ShaderModuleDescriptor;
pub const ShaderModuleDescriptorSpirV = _shader.ShaderModuleDescriptorSpirV;
pub const ShaderSourceSPIRV = _shader.ShaderSourceSPIRV;
Expand Down Expand Up @@ -271,7 +265,6 @@ pub const WGPU_MIP_LEVEL_COUNT_UNDEFINED = _texture.WGPU_MIP_LEVEL_COUNT_UNDEFIN
pub const WGPU_COPY_STRIDE_UNDEFINED = _texture.WGPU_COPY_STRIDE_UNDEFINED;
pub const TextureFormat = _texture.TextureFormat;
pub const TextureUsage = _texture.TextureUsage;
pub const TextureUsages = _texture.TextureUsages;
pub const TextureAspect = _texture.TextureAspect;
pub const TextureViewDescriptor = _texture.TextureViewDescriptor;
pub const TextureViewProcs = _texture.TextureViewProcs;
Expand Down
13 changes: 7 additions & 6 deletions src/shader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ const _async = @import("async.zig");
const CallbackMode = _async.CallbackMode;
const Future = _async.Future;

pub const ShaderStage = WGPUFlags;
pub const ShaderStages = struct {
pub const none = @as(ShaderStage, 0x0000000000000000);
pub const vertex = @as(ShaderStage, 0x0000000000000001);
pub const fragment = @as(ShaderStage, 0x0000000000000002);
pub const compute = @as(ShaderStage, 0x0000000000000004);
pub const ShaderStage = packed struct(WGPUFlags) {
vertex: bool = false,
fragment: bool = false,
compute: bool = false,
_: u61 = 0,

pub const none = ShaderStage{};
};

pub const ShaderModuleDescriptor = extern struct {
Expand Down
3 changes: 1 addition & 2 deletions src/surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const _texture = @import("texture.zig");
const Texture = _texture.Texture;
const TextureFormat = _texture.TextureFormat;
const TextureUsage = _texture.TextureUsage;
const TextureUsages = _texture.TextureUsages;

const _device = @import("device.zig");
const Device = _device.Device;
Expand Down Expand Up @@ -246,7 +245,7 @@ pub const SurfaceConfiguration = extern struct {
format: TextureFormat,

// The TextureUsage of the surface's textures.
usage: TextureUsage = TextureUsages.render_attachment,
usage: TextureUsage = TextureUsage{ .render_attachment = true },

// The width of the surface's textures
width: u32,
Expand Down
19 changes: 10 additions & 9 deletions src/texture.zig
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ pub const TextureFormat = enum(u32) {
nv12 = 0x00030007,
};

pub const TextureUsage = WGPUFlags;
pub const TextureUsages = struct {
pub const none = @as(TextureUsage, 0x0000000000000000);
pub const copy_src = @as(TextureUsage, 0x0000000000000001);
pub const copy_dst = @as(TextureUsage, 0x0000000000000002);
pub const texture_binding = @as(TextureUsage, 0x0000000000000004);
pub const storage_binding = @as(TextureUsage, 0x0000000000000008);
pub const render_attachment = @as(TextureUsage, 0x0000000000000010);
pub const TextureUsage = packed struct(WGPUFlags) {
copy_src: bool = false,
copy_dst: bool = false,
texture_binding: bool = false,
storage_binding: bool = false,
render_attachment: bool = false,
_: u59 = 0,

pub const none = TextureUsage{};
};

// TODO: Like a lot of things in this file, this breaks from the wrapper code convention by having an unneeded prefix ("Texture")
Expand All @@ -150,7 +151,7 @@ pub const TextureViewDescriptor = extern struct {
base_array_layer: u32 = 0,
array_layer_count: u32 = WGPU_ARRAY_LAYER_COUNT_UNDEFINED,
aspect: TextureAspect = TextureAspect.all,
usage: TextureUsage = TextureUsages.none,
usage: TextureUsage = TextureUsage.none,
};

pub const TextureViewProcs = struct {
Expand Down
6 changes: 3 additions & 3 deletions tests/compute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ fn compute_collatz() ![4]u32 {

const staging_buffer = try device.createBuffer(&wgpu.BufferDescriptor {
.label = wgpu.StringView.fromSlice("staging_buffer"),
.usage = wgpu.BufferUsages.map_read | wgpu.BufferUsages.copy_dst,
.usage = wgpu.BufferUsage{ .map_read = true, .copy_dst = true },
.size = numbers_size,
.mapped_at_creation = @as(u32, @intFromBool(false)),
});
defer staging_buffer.release();

const storage_buffer = try device.createBuffer(&wgpu.BufferDescriptor {
.label = wgpu.StringView.fromSlice("storage_buffer"),
.usage = wgpu.BufferUsages.storage | wgpu.BufferUsages.copy_dst | wgpu.BufferUsages.copy_src,
.usage = wgpu.BufferUsage{ .storage = true, .copy_dst = true, .copy_src = true },
.size = numbers_size,
.mapped_at_creation = @as(u32, @intFromBool(false)),
});
Expand Down Expand Up @@ -103,7 +103,7 @@ fn compute_collatz() ![4]u32 {
queue.submit(&[_]*const wgpu.CommandBuffer{command_buffer});

var buffer_map_complete = false;
_ = staging_buffer.mapAsync(wgpu.MapModes.read, 0, numbers_size, wgpu.BufferMapCallbackInfo {
_ = staging_buffer.mapAsync(wgpu.MapMode{ .read = true }, 0, numbers_size, wgpu.BufferMapCallbackInfo {
.callback = handleBufferMap,
.userdata1 = @ptrCast(&buffer_map_complete),
});
Expand Down