Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/graphics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,7 @@ pub fn LargeBuffer(comptime Entry: type) type { // MARK: LargerBuffer
c.glBufferStorage(c.GL_SHADER_STORAGE_BUFFER, bytes, null, flags);
self.ssbo.bind(self.binding);
self.capacity = size;
self.used = 0;
}

pub fn init(self: *Self, allocator: NeverFailingAllocator, size: u31, binding: c_uint) void {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ pub fn DynamicPackedIntArray(size: comptime_int) type { // MARK: DynamicPackedIn
pub fn initCapacity(bitSize: u5) Self {
std.debug.assert(bitSize == 0 or bitSize & bitSize - 1 == 0); // Must be a power of 2
return .{
.data = dynamicIntArrayAllocator.allocator().alignedAlloc(u32, 64, @as(usize, @divExact(size, @bitSizeOf(u32)))*bitSize),
.data = dynamicIntArrayAllocator.allocator().alignedAlloc(u32, .@"64", @as(usize, @divExact(size, @bitSizeOf(u32)))*bitSize),
.bitSize = bitSize,
};
}
Expand Down
15 changes: 8 additions & 7 deletions src/utils/heap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub const StackAllocator = struct { // MARK: StackAllocator
pub fn init(backingAllocator: NeverFailingAllocator, size: u31) StackAllocator {
return .{
.backingAllocator = backingAllocator,
.buffer = backingAllocator.alignedAlloc(u8, 4096, size),
.buffer = backingAllocator.alignedAlloc(u8, .fromByteUnits(4096), size),
.index = 0,
};
}
Expand Down Expand Up @@ -341,20 +341,20 @@ pub const NeverFailingAllocator = struct { // MARK: NeverFailingAllocator
self: NeverFailingAllocator,
comptime T: type,
/// null means naturally aligned
comptime alignment: ?u29,
comptime alignment: ?Alignment,
n: usize,
) []align(alignment orelse @alignOf(T)) T {
) []align(if (alignment) |a| a.toByteUnits() else @alignOf(T)) T {
return self.allocator.alignedAlloc(T, alignment, n) catch unreachable;
}

pub inline fn allocAdvancedWithRetAddr(
self: NeverFailingAllocator,
comptime T: type,
/// null means naturally aligned
comptime alignment: ?u29,
comptime alignment: ?Alignment,
n: usize,
return_address: usize,
) []align(alignment orelse @alignOf(T)) T {
) []align(if (alignment) |a| a.toByteUnits() else @alignOf(T)) T {
return self.allocator.allocAdvancedWithRetAddr(T, alignment, n, return_address) catch unreachable;
}

Expand Down Expand Up @@ -483,6 +483,7 @@ pub const NeverFailingArenaAllocator = struct { // MARK: NeverFailingArena
}

pub fn shrinkAndFree(self: *NeverFailingArenaAllocator) void {
if(true) return;
const node = self.arena.state.buffer_list.first orelse return;
const allocBuf = @as([*]u8, @ptrCast(node))[0..node.data];
const dataSize = std.mem.alignForward(usize, @sizeOf(std.SinglyLinkedList(usize).Node) + self.arena.state.end_index, @alignOf(std.SinglyLinkedList(usize).Node));
Expand Down Expand Up @@ -570,7 +571,7 @@ pub fn MemoryPool(Item: type) type { // MARK: MemoryPool
main.utils.assertLocked(&pool.mutex);
pool.totalAllocations += 1;
pool.freeAllocations += 1;
const mem = pool.arena.allocator().alignedAlloc(u8, item_alignment, item_size);
const mem = pool.arena.allocator().alignedAlloc(u8, .fromByteUnits(item_alignment), item_size);
return mem[0..item_size]; // coerce slice to array pointer
}
};
Expand Down Expand Up @@ -634,7 +635,7 @@ pub fn PowerOfTwoPoolAllocator(minSize: comptime_int, maxSize: comptime_int, max
fn allocNew(self: *Bucket, arena: NeverFailingAllocator, size: usize) [*]align(alignment) u8 {
self.totalAllocations += 1;
self.freeAllocations += 1;
return arena.alignedAlloc(u8, alignment, size).ptr;
return arena.alignedAlloc(u8, .fromByteUnits(alignment), size).ptr;
}
};

Expand Down
Loading