Skip to content

Commit

Permalink
Merge pull request #7 from Copper280z/main
Browse files Browse the repository at this point in the history
  • Loading branch information
hazeycode authored Dec 1, 2024
2 parents 66aa9c5 + d401e84 commit dbb3e60
Showing 1 changed file with 19 additions and 5 deletions.
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).
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

0 comments on commit dbb3e60

Please sign in to comment.