gpu: implement Device.createBindGroup
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
48dcfad65c
commit
8588a08e05
2 changed files with 56 additions and 10 deletions
|
|
@ -15,6 +15,7 @@ const SwapChain = @import("SwapChain.zig");
|
|||
const RenderPipeline = @import("RenderPipeline.zig");
|
||||
const CommandEncoder = @import("CommandEncoder.zig");
|
||||
const ComputePipeline = @import("ComputePipeline.zig");
|
||||
const BindGroup = @import("BindGroup.zig");
|
||||
|
||||
const Device = @This();
|
||||
|
||||
|
|
@ -24,9 +25,9 @@ ptr: *anyopaque,
|
|||
vtable: *const VTable,
|
||||
|
||||
pub const VTable = struct {
|
||||
// TODO:
|
||||
// createBindGroup: fn (ptr: *anyopaque, descriptor: *const BindGroup.Descriptor) BindGroup,
|
||||
// WGPU_EXPORT WGPUBindGroup wgpuDeviceCreateBindGroup(WGPUDevice device, WGPUBindGroupDescriptor const * descriptor);
|
||||
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);
|
||||
// createBuffer: fn (ptr: *anyopaque, descriptor: *const Buffer.Descriptor) Buffer,
|
||||
|
|
@ -88,15 +89,8 @@ pub const VTable = struct {
|
|||
// WGPU_EXPORT void wgpuDeviceSetUncapturedErrorCallback(WGPUDevice device, WGPUErrorCallback callback, void * userdata);
|
||||
// tick: fn (ptr: *anyopaque) void,
|
||||
// WGPU_EXPORT void wgpuDeviceTick(WGPUDevice device);
|
||||
|
||||
reference: fn (ptr: *anyopaque) void,
|
||||
release: fn (ptr: *anyopaque) void,
|
||||
};
|
||||
|
||||
pub inline fn getQueue(device: Device) Queue {
|
||||
return device.vtable.getQueue(device.ptr);
|
||||
}
|
||||
|
||||
pub inline fn reference(device: Device) void {
|
||||
device.vtable.reference(device.ptr);
|
||||
}
|
||||
|
|
@ -105,6 +99,14 @@ pub inline fn release(device: Device) void {
|
|||
device.vtable.release(device.ptr);
|
||||
}
|
||||
|
||||
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 createShaderModule(device: Device, descriptor: *const ShaderModule.Descriptor) ShaderModule {
|
||||
return device.vtable.createShaderModule(device.ptr, descriptor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -321,6 +321,50 @@ const device_vtable = Device.VTable{
|
|||
return wrapQueue(c.wgpuDeviceGetQueue(@ptrCast(c.WGPUDevice, ptr)));
|
||||
}
|
||||
}).getQueue,
|
||||
.createBindGroup = (struct {
|
||||
pub fn createBindGroup(ptr: *anyopaque, descriptor: *const BindGroup.Descriptor) BindGroup {
|
||||
var few_entries: [16]c.WGPUBindGroupEntry = undefined;
|
||||
const entries = if (descriptor.entries.len <= 8) blk: {
|
||||
for (descriptor.entries) |entry, i| {
|
||||
few_entries[i] = c.WGPUBindGroupEntry{
|
||||
.nextInChain = null,
|
||||
.binding = entry.binding,
|
||||
.buffer = @ptrCast(c.WGPUBuffer, entry.buffer.ptr),
|
||||
.offset = entry.offset,
|
||||
.size = entry.size,
|
||||
.sampler = @ptrCast(c.WGPUSampler, entry.sampler.ptr),
|
||||
.textureView = @ptrCast(c.WGPUTextureView, entry.texture_view.ptr),
|
||||
};
|
||||
}
|
||||
break :blk few_entries[0..descriptor.entries.len];
|
||||
} else blk: {
|
||||
const mem = std.heap.page_allocator.alloc(c.WGPUBindGroupEntry, descriptor.entries.len) catch unreachable;
|
||||
for (descriptor.entries) |entry, i| {
|
||||
mem[i] = c.WGPUBindGroupEntry{
|
||||
.nextInChain = null,
|
||||
.binding = entry.binding,
|
||||
.buffer = @ptrCast(c.WGPUBuffer, entry.buffer.ptr),
|
||||
.offset = entry.offset,
|
||||
.size = entry.size,
|
||||
.sampler = @ptrCast(c.WGPUSampler, entry.sampler.ptr),
|
||||
.textureView = @ptrCast(c.WGPUTextureView, entry.texture_view.ptr),
|
||||
};
|
||||
}
|
||||
break :blk mem;
|
||||
};
|
||||
defer if (entries.len > 8) std.heap.page_allocator.free(entries);
|
||||
|
||||
const desc = c.WGPUBindGroupDescriptor{
|
||||
.nextInChain = null,
|
||||
.label = if (descriptor.label) |l| l else null,
|
||||
.layout = @ptrCast(c.WGPUBindGroupLayout, descriptor.layout.ptr),
|
||||
.entryCount = @intCast(u32, entries.len),
|
||||
.entries = &entries[0],
|
||||
};
|
||||
|
||||
return wrapBindGroup(c.wgpuDeviceCreateBindGroup(@ptrCast(c.WGPUDevice, ptr), &desc));
|
||||
}
|
||||
}).createBindGroup,
|
||||
.createShaderModule = (struct {
|
||||
pub fn createShaderModule(ptr: *anyopaque, descriptor: *const ShaderModule.Descriptor) ShaderModule {
|
||||
switch (descriptor.code) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue