zig-wgpu/src/GpuAllocator.zig
adrien f5daf66784 Changed GpuAllocator to be like std.mem.Allocator
Now it is 2 ptr and I created a GpuArena. Point is to be like Zig, a
const allocator and a var arena that track everything.
2026-05-18 14:07:28 +02:00

25 lines
779 B
Zig

// GpuAllocator.zig
const std = @import("std");
const GpuDevice = @import("GpuDevice.zig");
const c = @import("utils.zig").c;
const GpuAllocator = @This();
/// The function definitions our underlying implementations must satisfy
pub const VTable = struct {
alloc: *const fn (ctx: *anyopaque, bytes: u64, usage: c.WGPUBufferUsage) anyerror!c.WGPUBuffer,
free: *const fn (ctx: *anyopaque, buf_raw: c.WGPUBuffer, size: u64) void,
};
device: GpuDevice,
ptr: *anyopaque,
vtable: *const VTable,
pub fn allocBuffer(self: GpuAllocator, bytes: u64, usage: c.WGPUBufferUsage) !c.WGPUBuffer {
return self.vtable.alloc(self.ptr, bytes, usage);
}
pub fn freeBuffer(self: GpuAllocator, buf_raw: c.WGPUBuffer, size: u64) void {
self.vtable.free(self.ptr, buf_raw, size);
}