Skip to content

Commit b582a62

Browse files
Updated to zig 0.15.1 (#20)
1 parent 96f3ce2 commit b582a62

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

build.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub fn build(b: *std.Build) void {
112112

113113
const zdawn = b.addLibrary(.{
114114
.name = "zdawn",
115+
.use_llvm = true,
115116
.root_module = b.createModule(.{
116117
.target = target,
117118
.optimize = optimize,
@@ -143,6 +144,7 @@ pub fn build(b: *std.Build) void {
143144

144145
const tests = b.addTest(.{
145146
.name = "zgpu-tests",
147+
.use_llvm = true,
146148
.root_module = b.createModule(.{
147149
.root_source_file = b.path("src/zgpu.zig"),
148150
.target = target,

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.name = .zgpu,
33
.fingerprint = 0x670ebe04e453a19e,
44
.version = "0.12.0-dev",
5-
.minimum_zig_version = "0.14.0",
5+
.minimum_zig_version = "0.15.1",
66
.paths = .{
77
"build.zig",
88
"build.zig.zon",

src/wgpu.zig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,62 +1273,62 @@ pub const CreateComputePipelineAsyncCallback = *const fn (
12731273
pipeline: ComputePipeline,
12741274
message: ?[*:0]const u8,
12751275
userdata: ?*anyopaque,
1276-
) callconv(.C) void;
1276+
) callconv(.c) void;
12771277

12781278
pub const CreateRenderPipelineAsyncCallback = *const fn (
12791279
status: CreatePipelineAsyncStatus,
12801280
pipeline: RenderPipeline,
12811281
message: ?[*:0]const u8,
12821282
userdata: ?*anyopaque,
1283-
) callconv(.C) void;
1283+
) callconv(.c) void;
12841284

12851285
pub const ErrorCallback = *const fn (
12861286
err_type: ErrorType,
12871287
message: ?[*:0]const u8,
12881288
userdata: ?*anyopaque,
1289-
) callconv(.C) void;
1289+
) callconv(.c) void;
12901290

12911291
pub const LoggingCallback = *const fn (
12921292
log_type: LoggingType,
12931293
message: ?[*:0]const u8,
12941294
userdata: ?*anyopaque,
1295-
) callconv(.C) void;
1295+
) callconv(.c) void;
12961296

12971297
pub const DeviceLostCallback = *const fn (
12981298
reason: DeviceLostReason,
12991299
message: ?[*:0]const u8,
13001300
userdata: ?*anyopaque,
1301-
) callconv(.C) void;
1301+
) callconv(.c) void;
13021302

13031303
pub const RequestAdapterCallback = *const fn (
13041304
status: RequestAdapterStatus,
13051305
adapter: Adapter,
13061306
message: ?[*:0]const u8,
13071307
userdata: ?*anyopaque,
1308-
) callconv(.C) void;
1308+
) callconv(.c) void;
13091309

13101310
pub const RequestDeviceCallback = *const fn (
13111311
status: RequestDeviceStatus,
13121312
device: Device,
13131313
message: ?[*:0]const u8,
13141314
userdata: ?*anyopaque,
1315-
) callconv(.C) void;
1315+
) callconv(.c) void;
13161316

13171317
pub const BufferMapCallback = *const fn (
13181318
status: BufferMapAsyncStatus,
13191319
userdata: ?*anyopaque,
1320-
) callconv(.C) void;
1320+
) callconv(.c) void;
13211321

13221322
pub const QueueWorkDoneCallback = *const fn (
13231323
status: QueueWorkDoneStatus,
13241324
userdata: ?*anyopaque,
1325-
) callconv(.C) void;
1325+
) callconv(.c) void;
13261326

13271327
pub const CompilationInfoCallback = *const fn (
13281328
status: CompilationInfoRequestStatus,
13291329
info: *const CompilationInfo,
13301330
userdata: ?*anyopaque,
1331-
) callconv(.C) void;
1331+
) callconv(.c) void;
13321332

13331333
pub const Adapter = *opaque {
13341334
pub fn createDevice(adapter: Adapter, descriptor: DeviceDescriptor) Device {
@@ -2238,7 +2238,7 @@ pub const Queue = *opaque {
22382238
queue: Queue,
22392239
callback: QueueWorkDoneCallback,
22402240
userdata: ?*anyopaque,
2241-
) callconv(.C) void,
2241+
) callconv(.c) void,
22422242
.{ .name = "wgpuQueueOnSubmittedWorkDone" },
22432243
);
22442244
oswd(queue, callback, userdata);
@@ -2249,7 +2249,7 @@ pub const Queue = *opaque {
22492249
signal_value: u64,
22502250
callback: QueueWorkDoneCallback,
22512251
userdata: ?*anyopaque,
2252-
) callconv(.C) void,
2252+
) callconv(.c) void,
22532253
.{ .name = "wgpuQueueOnSubmittedWorkDone" },
22542254
);
22552255
oswd(queue, signal_value, callback, userdata);

src/zgpu.zig

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub const GraphicsContext = struct {
138138
adapter: wgpu.Adapter,
139139
message: ?[*:0]const u8,
140140
userdata: ?*anyopaque,
141-
) callconv(.C) void {
141+
) callconv(.c) void {
142142
_ = message;
143143
const response = @as(*Response, @ptrCast(@alignCast(userdata)));
144144
response.status = status;
@@ -197,7 +197,7 @@ pub const GraphicsContext = struct {
197197
device: wgpu.Device,
198198
message: ?[*:0]const u8,
199199
userdata: ?*anyopaque,
200-
) callconv(.C) void {
200+
) callconv(.c) void {
201201
_ = message;
202202
const response = @as(*Response, @ptrCast(@alignCast(userdata)));
203203
response.status = status;
@@ -374,7 +374,7 @@ pub const GraphicsContext = struct {
374374
gctx.uniformsNextStagingBuffer();
375375
}
376376

377-
fn uniformsMappedCallback(status: wgpu.BufferMapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void {
377+
fn uniformsMappedCallback(status: wgpu.BufferMapAsyncStatus, userdata: ?*anyopaque) callconv(.c) void {
378378
const usb = @as(*UniformsStagingBuffer, @ptrCast(@alignCast(userdata)));
379379
assert(usb.slice == null);
380380
if (status == .success) {
@@ -471,19 +471,22 @@ pub const GraphicsContext = struct {
471471
defer stage_commands.release();
472472

473473
// TODO: We support up to 32 command buffers for now. Make it more robust.
474-
var command_buffers = std.BoundedArray(wgpu.CommandBuffer, 32).init(0) catch unreachable;
475-
command_buffers.append(stage_commands) catch unreachable;
476-
command_buffers.appendSlice(commands) catch unreachable;
474+
var buffer: [32]wgpu.CommandBuffer = undefined;
475+
var fb_allocator = std.heap.FixedBufferAllocator.init(@ptrCast(&buffer));
476+
477+
var command_buffers = std.ArrayList(wgpu.CommandBuffer).initCapacity(fb_allocator.allocator(), 32) catch unreachable;
478+
command_buffers.append(fb_allocator.allocator(), stage_commands) catch unreachable;
479+
command_buffers.appendSlice(fb_allocator.allocator(), commands) catch unreachable;
477480

478481
gctx.queue.onSubmittedWorkDone(0, gpuWorkDone, @ptrCast(&gctx.stats.gpu_frame_number));
479-
gctx.queue.submit(command_buffers.slice());
482+
gctx.queue.submit(command_buffers.items);
480483

481484
gctx.stats.tick(gctx.window_provider.getTime());
482485

483486
gctx.uniformsNextStagingBuffer();
484487
}
485488

486-
fn gpuWorkDone(status: wgpu.QueueWorkDoneStatus, userdata: ?*anyopaque) callconv(.C) void {
489+
fn gpuWorkDone(status: wgpu.QueueWorkDoneStatus, userdata: ?*anyopaque) callconv(.c) void {
487490
const gpu_frame_number: *u64 = @ptrCast(@alignCast(userdata));
488491
gpu_frame_number.* += 1;
489492
if (status != .success) {
@@ -632,7 +635,7 @@ pub const GraphicsContext = struct {
632635
pipeline: wgpu.RenderPipeline,
633636
message: ?[*:0]const u8,
634637
userdata: ?*anyopaque,
635-
) callconv(.C) void {
638+
) callconv(.c) void {
636639
const op = @as(*AsyncCreateOpRender, @ptrCast(@alignCast(userdata)));
637640
if (status == .success) {
638641
op.result.* = op.gctx.render_pipeline_pool.addResource(
@@ -693,7 +696,7 @@ pub const GraphicsContext = struct {
693696
pipeline: wgpu.ComputePipeline,
694697
message: ?[*:0]const u8,
695698
userdata: ?*anyopaque,
696-
) callconv(.C) void {
699+
) callconv(.c) void {
697700
const op = @as(*AsyncCreateOpCompute, @ptrCast(@alignCast(userdata)));
698701
if (status == .success) {
699702
op.result.* = op.gctx.compute_pipeline_pool.addResource(
@@ -1762,29 +1765,29 @@ fn msgSend(obj: anytype, sel_name: [:0]const u8, args: anytype, comptime ReturnT
17621765
const args_meta = @typeInfo(@TypeOf(args)).@"struct".fields;
17631766

17641767
const FnType = switch (args_meta.len) {
1765-
0 => *const fn (@TypeOf(obj), objc.SEL) callconv(.C) ReturnType,
1766-
1 => *const fn (@TypeOf(obj), objc.SEL, args_meta[0].type) callconv(.C) ReturnType,
1768+
0 => *const fn (@TypeOf(obj), objc.SEL) callconv(.c) ReturnType,
1769+
1 => *const fn (@TypeOf(obj), objc.SEL, args_meta[0].type) callconv(.c) ReturnType,
17671770
2 => *const fn (
17681771
@TypeOf(obj),
17691772
objc.SEL,
17701773
args_meta[0].type,
17711774
args_meta[1].type,
1772-
) callconv(.C) ReturnType,
1775+
) callconv(.c) ReturnType,
17731776
3 => *const fn (
17741777
@TypeOf(obj),
17751778
objc.SEL,
17761779
args_meta[0].type,
17771780
args_meta[1].type,
17781781
args_meta[2].type,
1779-
) callconv(.C) ReturnType,
1782+
) callconv(.c) ReturnType,
17801783
4 => *const fn (
17811784
@TypeOf(obj),
17821785
objc.SEL,
17831786
args_meta[0].type,
17841787
args_meta[1].type,
17851788
args_meta[2].type,
17861789
args_meta[3].type,
1787-
) callconv(.C) ReturnType,
1790+
) callconv(.c) ReturnType,
17881791
else => @compileError("[zgpu] Unsupported number of args"),
17891792
};
17901793

@@ -1798,7 +1801,7 @@ fn logUnhandledError(
17981801
err_type: wgpu.ErrorType,
17991802
message: ?[*:0]const u8,
18001803
userdata: ?*anyopaque,
1801-
) callconv(.C) void {
1804+
) callconv(.c) void {
18021805
_ = userdata;
18031806
switch (err_type) {
18041807
.no_error => std.log.info("[zgpu] No error: {?s}", .{message}),
@@ -1855,14 +1858,14 @@ fn formatToShaderFormat(format: wgpu.TextureFormat) []const u8 {
18551858
};
18561859
}
18571860

1858-
usingnamespace if (emscripten) struct {
1859-
// Missing symbols
1860-
var wgpuDeviceTickWarnPrinted: bool = false;
1861-
pub export fn wgpuDeviceTick() void {
1861+
var wgpuDeviceTickWarnPrinted: bool = false;
1862+
1863+
pub fn wgpuDeviceTick() void {
1864+
if (emscripten) {
18621865
if (!wgpuDeviceTickWarnPrinted) {
18631866
std.log.warn("wgpuDeviceTick(): this fn should be avoided! RequestAnimationFrame() is advised for smooth rendering in browser.", .{});
18641867
wgpuDeviceTickWarnPrinted = true;
18651868
}
18661869
emscripten_sleep(1);
18671870
}
1868-
} else struct {};
1871+
}

0 commit comments

Comments
 (0)