Joshua Simmons [Thu, 17 Nov 2022 08:03:32 +0000 (09:03 +0100)]
Improve default for ImageSubresourceRange
Previously it was hard-coding 1 for the `mip_level_count` and
`array_layer_count`, however we can use all bits set as a sentinel for
all remaining mip levels / array layers.
Joshua Simmons [Fri, 11 Nov 2022 22:24:48 +0000 (23:24 +0100)]
Fix memory safety issue in `HybridArena`
Calling `reset()` on an initialized, then moved `HybridArena` wouldn't
correctly update the page head pointer, causing reset to be called on
somebody else's bit of stack memory.
Joshua Simmons [Sat, 5 Nov 2022 12:53:12 +0000 (13:53 +0100)]
Use Rust's ThreadId instead of gettid
It's a little bit nasty due to needing to wrap it in Option, however it
avoids making the gettid syscall every time we do a lock / unlock
operation. Small performance improvement in debug mode.
Josh Simmons [Fri, 4 Nov 2022 20:59:59 +0000 (21:59 +0100)]
Fix reduction using the wrong rounding mode (#1)
Previously we were using `f32::round` in the reduction step, however
that isn't correct. We really need IEEE-754 tiesToEven semantics for the
rounding step, so manually implement that.
Joshua Simmons [Wed, 2 Nov 2022 21:16:50 +0000 (22:16 +0100)]
Add `Arena` and `HybridArena`
Add two variants on a simple bump allocator. Based loosly on the bumpalo
crate.
Provides two types, `Arena` which always allocates from the heap and
`HybridArena` which will first use a stack allocated page, then fall
back to allocating from the heap as well.
Joshua Simmons [Sat, 29 Oct 2022 14:12:39 +0000 (16:12 +0200)]
Rename `request_command_buffer` to `create_...`
The distinction between requesting and creating seems a bit tenuious and
probably just confusing. Might re-visit this later once the API is more
complete.
Joshua Simmons [Fri, 21 Oct 2022 21:05:21 +0000 (23:05 +0200)]
Be more defensive when doing range reduction
f32 as u32 saturates in rust, using to_int_unchecked wasn't currently
saturating on x86, but it's conceivable that it might. Go the long way
around by converting first to i32 and then to u32 in order to avoid the
possibility.
Joshua Simmons [Sat, 8 Oct 2022 11:03:44 +0000 (13:03 +0200)]
Improve pool implementation
Move virtual memory failures into the `virtual_reserve` and
`virtual_commit` signatures so we can give better assert messages on
failure.
Handle growth more accurately, allowing us to use the entire table
capacity before asserting.
Reserve a bit in the generation counter to keep track of whether a slot
is full by incrementing the counter on both allocation and deallocation.
This means exported handles can only ever have an odd generation
counter.
Assert when given a handle that has an invalid generation counter
(where the counter implies it would be pointing to an empty slot).
Both above changes together means it's no longer possible to create a
reference to an uninitialized slot, even when manually messing with the
handle or mixing handles between different pools.
Joshua Simmons [Thu, 6 Oct 2022 20:59:29 +0000 (22:59 +0200)]
Replace magic value in pool with random mixer
Instead of using a 4 bit magic number, and consequently restricting the
size of the pool, instead mix handles with a per-pool random integer
based on the pool's base memory address.
The associated tests will perhaps be a bit flaky, so disable them by
default.
Joshua Simmons [Sun, 2 Oct 2022 11:26:06 +0000 (13:26 +0200)]
Improve API of `ManualArc`
Consume the ManualArc when calling `release` to avoid needing to handle
double-free. Avoids unsafety in user code (was only protected by a debug
assert before)