Moved all f32 out of GpuXxxx to all be in Vec

This commit is contained in:
adrien 2026-05-18 15:35:38 +02:00
parent 8e137c8f33
commit d2b0735540
4 changed files with 11 additions and 6 deletions

View File

@ -66,12 +66,13 @@ pub fn unmap(self: @This()) void {
/// CPU to GPU.
pub fn load(
self: @This(),
data: []const f16,
T: type,
data: []const T,
) !void {
c.wgpuQueueWriteBuffer(self.gloc.device.queue, self.raw, 0, data.ptr, self.size);
}
pub fn read(self: @This(), alloc: std.mem.Allocator, T: type) ![]f16 {
pub fn read(self: @This(), alloc: std.mem.Allocator, T: type) ![]T {
const out = try alloc.alloc(T, @divExact(self.size, @sizeOf(T)));
const staging = try init(

View File

@ -1,3 +1,6 @@
/// GpuProcess is just a pipeline with 2 inpout and 1 output
/// for now, to see if I make it a bit more generic
///
const std = @import("std");
const c = @import("utils.zig").c;
const sv = @import("utils.zig").sv;
@ -40,6 +43,7 @@ fn onMapped(
pub fn run(
self: @This(),
gloc: GpuAllocator,
T: type,
buf_a: GpuBuffer,
buf_b: GpuBuffer,
buf_out: GpuBuffer,
@ -50,7 +54,7 @@ pub fn run(
var offset: u64 = 0;
while (offset < bytes) {
const current_chunk_bytes = @min(max_chunk_bytes, bytes - offset);
const current_chunk_elements: u32 = @intCast(current_chunk_bytes / @sizeOf(f16));
const current_chunk_elements: u32 = @intCast(current_chunk_bytes / @sizeOf(T));
const info_buf = try GpuBuffer.init(
gloc,

View File

@ -34,7 +34,7 @@ pub fn deinit(self: Vec) void {
/// CPU to GPU.
pub fn load(self: Vec, data: []const f16) !void {
try self.buf.load(data);
try self.buf.load(f16, data);
}
pub fn byteSize(self: Vec) u64 {
@ -48,7 +48,7 @@ pub fn run(self: Vec, gloc: GpuAllocator, other: Vec, process: GpuProcess) !Vec
const result = try Vec.initZero(gloc, self.len);
errdefer result.deinit();
try process.run(gloc, self.buf, other.buf, result.buf);
try process.run(gloc, f32, self.buf, other.buf, result.buf);
return result;
}

View File

@ -2,4 +2,4 @@ pub const GpuAllocator = @import("GpuAllocator.zig");
pub const GpuArena = @import("GpuArena.zig");
pub const GpuBuffer = @import("GpuBuffer.zig");
pub const GpuDevice = @import("GpuDevice.zig");
pub const GpuPipeline = @import("GpuPipeline.zig");
pub const GpuProcess = @import("GpuProcess.zig");