GpuBuffer can be for any float and init now
This commit is contained in:
parent
545e67d72f
commit
0fc5f5dbb8
@ -8,7 +8,12 @@ usage: c.WGPUBufferUsage,
|
||||
gloc: *GpuAllocator,
|
||||
|
||||
/// Allocates the underlying WebGPU handle and registers it to the parent GpuAllocator
|
||||
pub fn init(gloc: *GpuAllocator, bytes: u64, usage: c.WGPUBufferUsage) !@This() {
|
||||
pub fn init(gloc: *GpuAllocator, T: type, len: usize, usage: c.WGPUBufferUsage) !@This() {
|
||||
switch (@typeInfo(T)) {
|
||||
.int, .float => {},
|
||||
else => @compileError("GpuBuffer can only use int and float type"),
|
||||
}
|
||||
const bytes = @sizeOf(T) * len;
|
||||
const raw_handle = try gloc.registerBuffer(bytes, usage);
|
||||
return .{
|
||||
.raw = raw_handle,
|
||||
|
||||
@ -15,7 +15,8 @@ pub fn initZero(gloc: *GpuAllocator, len: usize) !Vec {
|
||||
return .{
|
||||
.buf = try GpuBuffer.init(
|
||||
gloc,
|
||||
len * @sizeOf(f32),
|
||||
f32,
|
||||
len,
|
||||
c.WGPUBufferUsage_Storage | c.WGPUBufferUsage_CopyDst | c.WGPUBufferUsage_CopySrc,
|
||||
),
|
||||
.len = len,
|
||||
@ -65,7 +66,8 @@ pub fn read(self: Vec, gloc: *GpuAllocator, alloc: std.mem.Allocator) ![]f32 {
|
||||
|
||||
const staging = try GpuBuffer.init(
|
||||
gloc,
|
||||
bytes,
|
||||
f32,
|
||||
self.len,
|
||||
c.WGPUBufferUsage_MapRead | c.WGPUBufferUsage_CopyDst,
|
||||
);
|
||||
defer staging.deinit();
|
||||
@ -125,7 +127,8 @@ fn dispatch2in1out(
|
||||
// Create uniform buffer for this specific chunk's size
|
||||
const info_buf = try GpuBuffer.init(
|
||||
gloc,
|
||||
@sizeOf(u32),
|
||||
u32,
|
||||
1,
|
||||
c.WGPUBufferUsage_Uniform | c.WGPUBufferUsage_CopyDst,
|
||||
);
|
||||
defer info_buf.deinit();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user