Skip to content

Commit 50be300

Browse files
Add toggle to Dawn as a dependency flag (#9)
1 parent 987809e commit 50be300

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

build.zig

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const log = std.log.scoped(.zgpu);
44
const default_options = struct {
55
const uniforms_buffer_size = 4 * 1024 * 1024;
66
const dawn_skip_validation = false;
7+
const dawn_allow_unsafe_apis = false;
78
const buffer_pool_size = 256;
89
const texture_pool_size = 256;
910
const texture_view_pool_size = 256;
@@ -32,6 +33,11 @@ pub fn build(b: *std.Build) void {
3233
"dawn_skip_validation",
3334
"Disable Dawn validation",
3435
) orelse default_options.dawn_skip_validation,
36+
.dawn_allow_unsafe_apis = b.option(
37+
bool,
38+
"dawn_allow_unsafe_apis",
39+
"Allow unsafe WebGPU APIs (e.g. timestamp queries)",
40+
) orelse default_options.dawn_allow_unsafe_apis,
3541
.buffer_pool_size = b.option(
3642
u32,
3743
"buffer_pool_size",

src/zgpu.zig

+12-6
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,26 @@ pub const GraphicsContext = struct {
205205
}
206206
}).callback;
207207

208-
const toggles = [_][*:0]const u8{"skip_validation"};
208+
var toggles: [2][*:0]const u8 = undefined;
209+
var num_toggles: usize = 0;
210+
if (zgpu_options.dawn_skip_validation) {
211+
toggles[num_toggles] = "skip_validation";
212+
num_toggles += 1;
213+
}
214+
if (zgpu_options.dawn_allow_unsafe_apis) {
215+
toggles[num_toggles] = "allow_unsafe_apis";
216+
num_toggles += 1;
217+
}
209218
const dawn_toggles = wgpu.DawnTogglesDescriptor{
210219
.chain = .{ .next = null, .struct_type = .dawn_toggles_descriptor },
211-
.enabled_toggles_count = toggles.len,
220+
.enabled_toggles_count = num_toggles,
212221
.enabled_toggles = &toggles,
213222
};
214223

215224
var response = Response{};
216225
adapter.requestDevice(
217226
wgpu.DeviceDescriptor{
218-
.next_in_chain = if (zgpu_options.dawn_skip_validation)
219-
@ptrCast(&dawn_toggles)
220-
else
221-
null,
227+
.next_in_chain = @ptrCast(&dawn_toggles),
222228
.required_features_count = options.required_features.len,
223229
.required_features = options.required_features.ptr,
224230
.required_limits = @ptrCast(options.required_limits),

0 commit comments

Comments
 (0)