Skip to content

Add Buffer functions and fix misleading comments #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/wgpu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1347,8 +1347,8 @@ pub const Buffer = *opaque {
}
extern fn wgpuBufferGetConstMappedRange(buffer: Buffer, offset: usize, size: usize) ?*const anyopaque;

// `offset` has to be a multiple of 8 (otherwise `null` will be returned).
// `@sizeOf(T) * len` has to be a multiple of 4 (otherwise `null` will be returned).
// `offset` - in bytes, has to be a multiple of 8 (otherwise `null` will be returned).
// `len` - length of slice to return, in elements of type T, `@sizeOf(T) * len` has to be a multiple of 4 (otherwise `null` will be returned).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
We should probably use doc-comments /// here so this gets displayed in users editors.

pub fn getMappedRange(buffer: Buffer, comptime T: type, offset: usize, len: usize) ?[]T {
if (len == 0) return null;
const ptr = wgpuBufferGetMappedRange(buffer, offset, @sizeOf(T) * len);
Expand All @@ -1357,9 +1357,23 @@ pub const Buffer = *opaque {
}
extern fn wgpuBufferGetMappedRange(buffer: Buffer, offset: usize, size: usize) ?*anyopaque;

// `offset` has to be a multiple of 8 (Dawn's validation layer will warn).
// `size` has to be a multiple of 4 (Dawn's validation layer will warn).
// `size == 0` will map entire range (from 'offset' to the end of the buffer).
pub fn getMapState(buffer: Buffer) BufferMapState {
return wgpuBufferGetMapState(buffer);
}
extern fn wgpuBufferGetMapState(buffer: Buffer) BufferMapState;

pub fn getSize(buffer: Buffer) usize {
return @intCast(wgpuBufferGetSize(buffer));
}
extern fn wgpuBufferGetSize(buffer: Buffer) u64;

pub fn getUsage(buffer: Buffer) BufferUsage {
return wgpuBufferGetUsage(buffer);
}
extern fn wgpuBufferGetUsage(buffer: Buffer) BufferUsage;

// `offset` - in bytes, has to be a multiple of 8 (Dawn's validation layer will warn).
// `size` - size of buffer to map in bytes, has to be a multiple of 4 (Dawn's validation layer will warn).
pub fn mapAsync(
buffer: Buffer,
mode: MapMode,
Expand Down
Loading