Changed how Allocator work to be more Zig like

Now GpuArena doesn't do everything.

- Created GpuDeviceAllocator that allocate to the device
- GpuArena become GpuArenaAllocator and use a child_allocator like
std.heap.ArenaAllocator
This commit is contained in:
adrien
2026-05-20 13:32:37 +02:00
parent a06b040a29
commit 7d425e4061
6 changed files with 101 additions and 42 deletions
+2 -3
View File
@@ -1,7 +1,7 @@
const std = @import("std");
const gpu = @import("gpu");
const GpuDevice = gpu.GpuDevice;
const GpuArena = gpu.GpuArena;
const GpuArenaAllocator = gpu.GpuArenaAllocator;
const GpuAllocator = gpu.GpuAllocator;
const GpuBuffer = gpu.GpuBuffer;
const GpuCompute = gpu.GpuCompute;
@@ -60,9 +60,8 @@ pub fn main(init: std.process.Init) !void {
const device = try GpuDevice.init(.{ .vram_bytes_limit = 4 * 1024 * 1024 * 1024 });
defer device.deinit();
var grena = GpuArena.init(init.gpa, device);
var grena = GpuArenaAllocator.init(init.gpa, device.gpuAllocator());
defer grena.deinit();
const gloc = grena.gpuAllocator();
const add_pip = try GpuCompute.init(gloc, @embedFile("shaders/add.wgsl"), .{ .bindings = &.{
+2 -2
View File
@@ -1,7 +1,7 @@
const std = @import("std");
const gpu = @import("gpu");
const GpuDevice = gpu.GpuDevice;
const GpuArena = gpu.GpuArena;
const GpuArenaAllocator = gpu.GpuArenaAllocator;
const GpuBuffer = gpu.GpuBuffer;
const GpuRender = gpu.GpuRender;
const GpuTexture = gpu.GpuTexture;
@@ -22,7 +22,7 @@ pub fn main(init: std.process.Init) !void {
defer device.deinit();
// 2. Init VRAM Arena
var grena = GpuArena.init(allocator, device);
var grena = GpuArenaAllocator.init(allocator, device.gpuAllocator());
defer grena.deinit();
const gloc = grena.gpuAllocator();
+2 -2
View File
@@ -1,7 +1,7 @@
const std = @import("std");
const gpu = @import("gpu");
const GpuDevice = gpu.GpuDevice;
const GpuArena = gpu.GpuArena;
const GpuArenaAllocator = gpu.GpuArenaAllocator;
const GpuBuffer = gpu.GpuBuffer;
const GpuCompute = gpu.GpuCompute;
@@ -13,7 +13,7 @@ pub fn main(init: std.process.Init) !void {
defer device.deinit();
// 2. Create a GPU Arena to manage VRAM
var grena = GpuArena.init(allocator, device);
var grena = GpuArenaAllocator.init(allocator, device.gpuAllocator());
defer grena.deinit();
const gloc = grena.gpuAllocator();