gpu: make CommandEncoder.writeBuffer use a slice helper

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-11 06:25:55 -07:00 committed by Stephen Gutekanst
parent 64b67f1b8a
commit 1848ac8ac7
2 changed files with 16 additions and 3 deletions

View file

@ -152,6 +152,7 @@ Some WebGPU APIs expose slices as pointers and lengths, we either wrap these to
The slice helpers are:
* `Adapter.enumerateFeaturesOwned`
* `CommandEncoder.writeBuffer`
* `Queue.writeTexture`
* `Queue.writeBuffer`
@ -217,7 +218,6 @@ The following are definitive candidates for helpers we haven't implemented yet:
* `gpu.Buffer.getConstMappedRange` (slices)
* `gpu.Buffer.getMappedRange` (slices)
* `gpu.CommandEncoder.writeBuffer` (slices)
* `gpu.ComputePassEncoder.setBindGroup` (slice param)
* `gpu.Device.enumerateFeatures` (owned slice)
* `gpu.RenderBundleEncoder.setBindGroup` (slice param)

View file

@ -81,8 +81,21 @@ pub const CommandEncoder = opaque {
Impl.commandEncoderSetLabel(command_encoder, label);
}
pub inline fn writeBuffer(command_encoder: *CommandEncoder, buffer: *Buffer, buffer_offset: u64, data: [*]const u8, size: u64) void {
Impl.commandEncoderWriteBuffer(command_encoder, buffer, buffer_offset, data, size);
pub inline fn writeBuffer(
command_encoder: *CommandEncoder,
buffer: *Buffer,
buffer_offset_bytes: u64,
data_slice: anytype,
) void {
Impl.commandEncoderWriteBuffer(
command_encoder,
buffer,
buffer_offset_bytes,
data,
size,
@ptrCast([*]const u8, data_slice.ptr),
@intCast(u64, data_slice.len) * @sizeOf(std.meta.Elem(@TypeOf(data_slice))),
);
}
pub inline fn writeTimestamp(command_encoder: *CommandEncoder, query_set: *QuerySet, query_index: u32) void {