GpuBuffer init now take a EnumSet of BufferUsage and not a c.WGPUBufferUsage
This commit is contained in:
parent
d42c521a96
commit
c3166e552b
@ -7,18 +7,38 @@ size: u64,
|
|||||||
usage: c.WGPUBufferUsage,
|
usage: c.WGPUBufferUsage,
|
||||||
gloc: *GpuAllocator,
|
gloc: *GpuAllocator,
|
||||||
|
|
||||||
|
const BufferUsage = enum(u64) {
|
||||||
|
None = 0x0000000000000000,
|
||||||
|
MapRead = 0x0000000000000001,
|
||||||
|
MapWrite = 0x0000000000000002,
|
||||||
|
CopySrc = 0x0000000000000004,
|
||||||
|
CopyDst = 0x0000000000000008,
|
||||||
|
Index = 0x0000000000000010,
|
||||||
|
Vertex = 0x0000000000000020,
|
||||||
|
Uniform = 0x0000000000000040,
|
||||||
|
Storage = 0x0000000000000080,
|
||||||
|
Indirect = 0x0000000000000100,
|
||||||
|
QueryResolve = 0x0000000000000200,
|
||||||
|
};
|
||||||
|
|
||||||
/// Allocates the underlying WebGPU handle and registers it to the parent GpuAllocator
|
/// Allocates the underlying WebGPU handle and registers it to the parent GpuAllocator
|
||||||
pub fn init(gloc: *GpuAllocator, T: type, len: usize, usage: c.WGPUBufferUsage) !@This() {
|
pub fn init(gloc: *GpuAllocator, T: type, len: usize, usage: std.EnumSet(BufferUsage)) !@This() {
|
||||||
switch (@typeInfo(T)) {
|
switch (@typeInfo(T)) {
|
||||||
.int, .float => {},
|
.int, .float => {},
|
||||||
else => @compileError("GpuBuffer can only use int and float type"),
|
else => @compileError("GpuBuffer can only use int and float type"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var use: u64 = 0;
|
||||||
|
var iter = usage.iterator();
|
||||||
|
while (iter.next()) |flag| use |= @intFromEnum(flag);
|
||||||
|
|
||||||
const bytes = @sizeOf(T) * len;
|
const bytes = @sizeOf(T) * len;
|
||||||
const raw_handle = try gloc.registerBuffer(bytes, usage);
|
const raw_handle = try gloc.registerBuffer(bytes, use);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.raw = raw_handle,
|
.raw = raw_handle,
|
||||||
.size = bytes,
|
.size = bytes,
|
||||||
.usage = usage,
|
.usage = use,
|
||||||
.gloc = gloc,
|
.gloc = gloc,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ pub fn initZero(gloc: *GpuAllocator, len: usize) !Vec {
|
|||||||
gloc,
|
gloc,
|
||||||
f16,
|
f16,
|
||||||
len,
|
len,
|
||||||
c.WGPUBufferUsage_Storage | c.WGPUBufferUsage_CopyDst | c.WGPUBufferUsage_CopySrc,
|
.initMany(&.{ .Storage, .CopyDst, .CopySrc }),
|
||||||
),
|
),
|
||||||
.len = len,
|
.len = len,
|
||||||
};
|
};
|
||||||
@ -68,7 +68,7 @@ pub fn read(self: Vec, gloc: *GpuAllocator, alloc: std.mem.Allocator) ![]f16 {
|
|||||||
gloc,
|
gloc,
|
||||||
f16,
|
f16,
|
||||||
self.len,
|
self.len,
|
||||||
c.WGPUBufferUsage_MapRead | c.WGPUBufferUsage_CopyDst,
|
.initMany(&.{ .MapRead, .CopyDst }),
|
||||||
);
|
);
|
||||||
defer staging.deinit();
|
defer staging.deinit();
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ fn dispatch2in1out(
|
|||||||
gloc,
|
gloc,
|
||||||
u32,
|
u32,
|
||||||
1,
|
1,
|
||||||
c.WGPUBufferUsage_Uniform | c.WGPUBufferUsage_CopyDst,
|
.initMany(&.{ .Uniform, .CopyDst }),
|
||||||
);
|
);
|
||||||
defer info_buf.deinit();
|
defer info_buf.deinit();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user