gpu: improve ABI compatibility of BindGroupLayout.Entry
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
d635bee216
commit
789f6291e4
2 changed files with 4 additions and 34 deletions
|
|
@ -34,7 +34,8 @@ pub const Descriptor = struct {
|
||||||
entries: []const Entry,
|
entries: []const Entry,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Entry = struct {
|
pub const Entry = extern struct {
|
||||||
|
reserved: ?*anyopaque = null,
|
||||||
binding: u32,
|
binding: u32,
|
||||||
visibility: ShaderStage,
|
visibility: ShaderStage,
|
||||||
buffer: Buffer.BindingLayout,
|
buffer: Buffer.BindingLayout,
|
||||||
|
|
|
||||||
|
|
@ -367,42 +367,11 @@ const device_vtable = Device.VTable{
|
||||||
}).createBindGroup,
|
}).createBindGroup,
|
||||||
.createBindGroupLayout = (struct {
|
.createBindGroupLayout = (struct {
|
||||||
pub fn createBindGroupLayout(ptr: *anyopaque, descriptor: *const BindGroupLayout.Descriptor) BindGroupLayout {
|
pub fn createBindGroupLayout(ptr: *anyopaque, descriptor: *const BindGroupLayout.Descriptor) BindGroupLayout {
|
||||||
var few_entries: [16]c.WGPUBindGroupLayoutEntry = undefined;
|
|
||||||
const entries = if (descriptor.entries.len <= 8) blk: {
|
|
||||||
for (descriptor.entries) |entry, i| {
|
|
||||||
few_entries[i] = c.WGPUBindGroupLayoutEntry{
|
|
||||||
.nextInChain = null,
|
|
||||||
.binding = entry.binding,
|
|
||||||
.visibility = @enumToInt(entry.visibility),
|
|
||||||
.buffer = @bitCast(c.WGPUBufferBindingLayout, entry.buffer),
|
|
||||||
.sampler = @bitCast(c.WGPUSamplerBindingLayout, entry.sampler),
|
|
||||||
.texture = @bitCast(c.WGPUTextureBindingLayout, entry.texture),
|
|
||||||
.storageTexture = @bitCast(c.WGPUStorageTextureBindingLayout, entry.storage_texture),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
break :blk few_entries[0..descriptor.entries.len];
|
|
||||||
} else blk: {
|
|
||||||
const mem = std.heap.page_allocator.alloc(c.WGPUBindGroupLayoutEntry, descriptor.entries.len) catch unreachable;
|
|
||||||
for (descriptor.entries) |entry, i| {
|
|
||||||
mem[i] = c.WGPUBindGroupLayoutEntry{
|
|
||||||
.nextInChain = null,
|
|
||||||
.binding = entry.binding,
|
|
||||||
.visibility = @enumToInt(entry.visibility),
|
|
||||||
.buffer = @bitCast(c.WGPUBufferBindingLayout, entry.buffer),
|
|
||||||
.sampler = @bitCast(c.WGPUSamplerBindingLayout, entry.sampler),
|
|
||||||
.texture = @bitCast(c.WGPUTextureBindingLayout, entry.texture),
|
|
||||||
.storageTexture = @bitCast(c.WGPUStorageTextureBindingLayout, entry.storage_texture),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
break :blk mem;
|
|
||||||
};
|
|
||||||
defer if (entries.len > 8) std.heap.page_allocator.free(entries);
|
|
||||||
|
|
||||||
const desc = c.WGPUBindGroupLayoutDescriptor{
|
const desc = c.WGPUBindGroupLayoutDescriptor{
|
||||||
.nextInChain = null,
|
.nextInChain = null,
|
||||||
.label = if (descriptor.label) |l| l else null,
|
.label = if (descriptor.label) |l| l else null,
|
||||||
.entryCount = @intCast(u32, entries.len),
|
.entryCount = @intCast(u32, descriptor.entries.len),
|
||||||
.entries = &entries[0],
|
.entries = @ptrCast(*const c.WGPUBindGroupLayoutEntry, &descriptor.entries[0]),
|
||||||
};
|
};
|
||||||
return wrapBindGroupLayout(c.wgpuDeviceCreateBindGroupLayout(@ptrCast(c.WGPUDevice, ptr), &desc));
|
return wrapBindGroupLayout(c.wgpuDeviceCreateBindGroupLayout(@ptrCast(c.WGPUDevice, ptr), &desc));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue