gpu: correct alignment casts of callback helpers

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-12 00:03:46 -07:00 committed by Stephen Gutekanst
parent 6357f3a767
commit 4429be4f5f
4 changed files with 72 additions and 72 deletions

View file

@ -18,75 +18,75 @@ pub const BindGroupLayout = opaque {
texture: Texture.BindingLayout = .{}, texture: Texture.BindingLayout = .{},
storage_texture: StorageTextureBindingLayout = .{}, storage_texture: StorageTextureBindingLayout = .{},
/// Helper to create a buffer BindGroupLayout.Entry. /// Helper to create a buffer BindGroupLayout.Entry.
pub fn buffer( pub fn buffer(
binding: u32, binding: u32,
visibility: ShaderStageFlags, visibility: ShaderStageFlags,
binding_type: Buffer.BindingType, binding_type: Buffer.BindingType,
has_dynamic_offset: bool, has_dynamic_offset: bool,
min_binding_size: u64, min_binding_size: u64,
) Entry { ) Entry {
return .{ return .{
.binding = binding, .binding = binding,
.visibility = visibility, .visibility = visibility,
.buffer = .{ .buffer = .{
.type = binding_type, .type = binding_type,
.has_dynamic_offset = has_dynamic_offset, .has_dynamic_offset = has_dynamic_offset,
.min_binding_size = min_binding_size, .min_binding_size = min_binding_size,
}, },
}; };
} }
/// Helper to create a sampler BindGroupLayout.Entry. /// Helper to create a sampler BindGroupLayout.Entry.
pub fn sampler( pub fn sampler(
binding: u32, binding: u32,
visibility: ShaderStageFlags, visibility: ShaderStageFlags,
binding_type: Sampler.BindingType, binding_type: Sampler.BindingType,
) Entry { ) Entry {
return .{ return .{
.binding = binding, .binding = binding,
.visibility = visibility, .visibility = visibility,
.sampler = .{ .type = binding_type }, .sampler = .{ .type = binding_type },
}; };
} }
/// Helper to create a texture BindGroupLayout.Entry. /// Helper to create a texture BindGroupLayout.Entry.
pub fn texture( pub fn texture(
binding: u32, binding: u32,
visibility: ShaderStageFlags, visibility: ShaderStageFlags,
sample_type: Texture.SampleType, sample_type: Texture.SampleType,
view_dimension: TextureView.Dimension, view_dimension: TextureView.Dimension,
multisampled: bool, multisampled: bool,
) Entry { ) Entry {
return .{ return .{
.binding = binding, .binding = binding,
.visibility = visibility, .visibility = visibility,
.texture = .{ .texture = .{
.sample_type = sample_type, .sample_type = sample_type,
.view_dimension = view_dimension, .view_dimension = view_dimension,
.multisampled = multisampled, .multisampled = multisampled,
}, },
}; };
} }
/// Helper to create a storage texture BindGroupLayout.Entry. /// Helper to create a storage texture BindGroupLayout.Entry.
pub fn storageTexture( pub fn storageTexture(
binding: u32, binding: u32,
visibility: ShaderStageFlags, visibility: ShaderStageFlags,
access: StorageTextureAccess, access: StorageTextureAccess,
format: Texture.Format, format: Texture.Format,
view_dimension: TextureView.Dimension, view_dimension: TextureView.Dimension,
) Entry { ) Entry {
return .{ return .{
.binding = binding, .binding = binding,
.visibility = visibility, .visibility = visibility,
.storage_texture = .{ .storage_texture = .{
.access = access, .access = access,
.format = format, .format = format,
.view_dimension = view_dimension, .view_dimension = view_dimension,
}, },
}; };
} }
}; };
pub const Descriptor = extern struct { pub const Descriptor = extern struct {

View file

@ -122,7 +122,7 @@ pub const Buffer = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn callback(status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void { pub fn callback(status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void {
callback(status, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata))); callback(status, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)));
} }
}; };
Impl.bufferMapAsync(buffer, mode, offset, size, Helper.callback, if (Context == void) null else context); Impl.bufferMapAsync(buffer, mode, offset, size, Helper.callback, if (Context == void) null else context);

View file

@ -226,7 +226,7 @@ pub const Device = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
callback(typ, message, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata))); callback(typ, message, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)));
} }
}; };
return Impl.devicePopErrorScope(device, Helper.callback, if (Context == void) null else context); return Impl.devicePopErrorScope(device, Helper.callback, if (Context == void) null else context);
@ -245,7 +245,7 @@ pub const Device = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn callback(reason: LostReason, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { pub fn callback(reason: LostReason, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
callback(reason, message, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata))); callback(reason, message, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)));
} }
}; };
Impl.deviceSetDeviceLostCallback(device, Helper.callback, if (Context == void) null else context); Impl.deviceSetDeviceLostCallback(device, Helper.callback, if (Context == void) null else context);
@ -264,7 +264,7 @@ pub const Device = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn callback(typ: LoggingType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { pub fn callback(typ: LoggingType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
callback(typ, message, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata))); callback(typ, message, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)));
} }
}; };
Impl.deviceSetLoggingCallback(device, Helper.callback, if (Context == void) null else context); Impl.deviceSetLoggingCallback(device, Helper.callback, if (Context == void) null else context);
@ -279,7 +279,7 @@ pub const Device = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
callback(typ, message, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata))); callback(typ, message, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)));
} }
}; };
Impl.deviceSetUncapturedErrorCallback(device, Helper.callback, if (Context == void) null else context); Impl.deviceSetUncapturedErrorCallback(device, Helper.callback, if (Context == void) null else context);

View file

@ -40,7 +40,7 @@ pub const Queue = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn callback(status: WorkDoneStatus, userdata: ?*anyopaque) callconv(.C) void { pub fn callback(status: WorkDoneStatus, userdata: ?*anyopaque) callconv(.C) void {
callback(status, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata))); callback(status, if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)));
} }
}; };
Impl.queueOnSubmittedWorkDone(queue, signal_value, Helper.callback, if (Context == void) null else context); Impl.queueOnSubmittedWorkDone(queue, signal_value, Helper.callback, if (Context == void) null else context);