gpu: implement Device.createBindGroupLayout
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
8588a08e05
commit
d635bee216
6 changed files with 63 additions and 11 deletions
|
|
@ -92,7 +92,8 @@ pub const BindingType = enum(u32) {
|
|||
read_only_storage = 0x00000003,
|
||||
};
|
||||
|
||||
pub const BindingLayout = struct {
|
||||
pub const BindingLayout = extern struct {
|
||||
reserved: ?*anyopaque = null,
|
||||
type: BindingType,
|
||||
has_dynamic_offset: bool,
|
||||
min_binding_size: u64,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ const RenderPipeline = @import("RenderPipeline.zig");
|
|||
const CommandEncoder = @import("CommandEncoder.zig");
|
||||
const ComputePipeline = @import("ComputePipeline.zig");
|
||||
const BindGroup = @import("BindGroup.zig");
|
||||
const BindGroupLayout = @import("BindGroupLayout.zig");
|
||||
|
||||
const Device = @This();
|
||||
|
||||
|
|
@ -28,8 +29,7 @@ pub const VTable = struct {
|
|||
reference: fn (ptr: *anyopaque) void,
|
||||
release: fn (ptr: *anyopaque) void,
|
||||
createBindGroup: fn (ptr: *anyopaque, descriptor: *const BindGroup.Descriptor) BindGroup,
|
||||
// createBindGroupLayout: fn (ptr: *anyopaque, descriptor: *const BindGroupLayout.Descriptor) BindGroupLayout,
|
||||
// WGPU_EXPORT WGPUBindGroupLayout wgpuDeviceCreateBindGroupLayout(WGPUDevice device, WGPUBindGroupLayoutDescriptor const * descriptor);
|
||||
createBindGroupLayout: fn (ptr: *anyopaque, descriptor: *const BindGroupLayout.Descriptor) BindGroupLayout,
|
||||
// createBuffer: fn (ptr: *anyopaque, descriptor: *const Buffer.Descriptor) Buffer,
|
||||
// WGPU_EXPORT WGPUBuffer wgpuDeviceCreateBuffer(WGPUDevice device, WGPUBufferDescriptor const * descriptor);
|
||||
createCommandEncoder: fn (ptr: *anyopaque, descriptor: ?*const CommandEncoder.Descriptor) CommandEncoder,
|
||||
|
|
@ -103,8 +103,12 @@ pub inline fn getQueue(device: Device) Queue {
|
|||
return device.vtable.getQueue(device.ptr);
|
||||
}
|
||||
|
||||
pub inline fn createBindGroup(device: Device, descriptor: *const BindGroup.Descriptor) void {
|
||||
device.vtable.createBindGroup(device.ptr, descriptor);
|
||||
pub inline fn createBindGroup(device: Device, descriptor: *const BindGroup.Descriptor) BindGroup {
|
||||
return device.vtable.createBindGroup(device.ptr, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createBindGroupLayout(device: Device, descriptor: *const BindGroupLayout.Descriptor) BindGroupLayout {
|
||||
return device.vtable.createBindGroupLayout(device.ptr, descriptor);
|
||||
}
|
||||
|
||||
pub inline fn createShaderModule(device: Device, descriptor: *const ShaderModule.Descriptor) ShaderModule {
|
||||
|
|
@ -163,9 +167,11 @@ pub const LostReason = enum(u32) {
|
|||
|
||||
test {
|
||||
_ = VTable;
|
||||
_ = getQueue;
|
||||
_ = reference;
|
||||
_ = release;
|
||||
_ = getQueue;
|
||||
_ = createBindGroup;
|
||||
_ = createBindGroupLayout;
|
||||
_ = createShaderModule;
|
||||
_ = nativeCreateSwapChain;
|
||||
_ = destroy;
|
||||
|
|
|
|||
|
|
@ -365,6 +365,48 @@ const device_vtable = Device.VTable{
|
|||
return wrapBindGroup(c.wgpuDeviceCreateBindGroup(@ptrCast(c.WGPUDevice, ptr), &desc));
|
||||
}
|
||||
}).createBindGroup,
|
||||
.createBindGroupLayout = (struct {
|
||||
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{
|
||||
.nextInChain = null,
|
||||
.label = if (descriptor.label) |l| l else null,
|
||||
.entryCount = @intCast(u32, entries.len),
|
||||
.entries = &entries[0],
|
||||
};
|
||||
return wrapBindGroupLayout(c.wgpuDeviceCreateBindGroupLayout(@ptrCast(c.WGPUDevice, ptr), &desc));
|
||||
}
|
||||
}).createBindGroupLayout,
|
||||
.createShaderModule = (struct {
|
||||
pub fn createShaderModule(ptr: *anyopaque, descriptor: *const ShaderModule.Descriptor) ShaderModule {
|
||||
switch (descriptor.code) {
|
||||
|
|
@ -676,7 +718,7 @@ const queue_vtable = Queue.VTable{
|
|||
}
|
||||
|
||||
var few_commands: [16]c.WGPUCommandBuffer = undefined;
|
||||
const commands = if (cmds.len <= 8) blk: {
|
||||
const commands = if (cmds.len <= 16) blk: {
|
||||
for (cmds) |cmd, i| {
|
||||
few_commands[i] = @ptrCast(c.WGPUCommandBuffer, cmd.ptr);
|
||||
}
|
||||
|
|
@ -688,7 +730,7 @@ const queue_vtable = Queue.VTable{
|
|||
}
|
||||
break :blk mem;
|
||||
};
|
||||
defer if (cmds.len > 8) std.heap.page_allocator.free(cmds);
|
||||
defer if (cmds.len > 16) std.heap.page_allocator.free(cmds);
|
||||
|
||||
c.wgpuQueueSubmit(
|
||||
wgpu_queue,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ pub const BindingType = enum(u32) {
|
|||
comparison = 0x00000003,
|
||||
};
|
||||
|
||||
pub const BindingLayout = struct {
|
||||
pub const BindingLayout = extern struct {
|
||||
reserved: ?*anyopaque = null,
|
||||
type: BindingType,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -187,7 +187,8 @@ pub const SampleType = enum(u32) {
|
|||
uint = 0x00000005,
|
||||
};
|
||||
|
||||
pub const BindingLayout = struct {
|
||||
pub const BindingLayout = extern struct {
|
||||
reserved: ?*anyopaque = null,
|
||||
sample_type: SampleType,
|
||||
view_dimension: TextureView.Dimension,
|
||||
multisampled: bool,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ pub const PrimitiveState = struct {
|
|||
cull_mode: CullMode,
|
||||
};
|
||||
|
||||
pub const StorageTextureBindingLayout = struct {
|
||||
pub const StorageTextureBindingLayout = extern struct {
|
||||
reserved: ?*anyopaque = null,
|
||||
access: StorageTextureAccess,
|
||||
format: Texture.Format,
|
||||
view_dimension: TextureView.Dimension,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue