mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-07 23:23:32 +00:00
Rename INVALID_OFFSET to kInvalidOffset.
BUG=dawn:27 Change-Id: Ida590a2b3cf3da17bbedf6ef61d72eaaa443bc4b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11561 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
64f4dd7127
commit
86ac0b93c9
@ -91,7 +91,7 @@ namespace dawn_native {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return INVALID_OFFSET; // No free block exists at any level.
|
return kInvalidOffset; // No free block exists at any level.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inserts existing free block into the free-list.
|
// Inserts existing free block into the free-list.
|
||||||
@ -141,7 +141,7 @@ namespace dawn_native {
|
|||||||
|
|
||||||
uint64_t BuddyAllocator::Allocate(uint64_t allocationSize, uint64_t alignment) {
|
uint64_t BuddyAllocator::Allocate(uint64_t allocationSize, uint64_t alignment) {
|
||||||
if (allocationSize == 0 || allocationSize > mMaxBlockSize) {
|
if (allocationSize == 0 || allocationSize > mMaxBlockSize) {
|
||||||
return INVALID_OFFSET;
|
return kInvalidOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the level
|
// Compute the level
|
||||||
@ -152,8 +152,8 @@ namespace dawn_native {
|
|||||||
uint64_t currBlockLevel = GetNextFreeAlignedBlock(allocationSizeToLevel, alignment);
|
uint64_t currBlockLevel = GetNextFreeAlignedBlock(allocationSizeToLevel, alignment);
|
||||||
|
|
||||||
// Error when no free blocks exist (allocator is full)
|
// Error when no free blocks exist (allocator is full)
|
||||||
if (currBlockLevel == INVALID_OFFSET) {
|
if (currBlockLevel == kInvalidOffset) {
|
||||||
return INVALID_OFFSET;
|
return kInvalidOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split free blocks level-by-level.
|
// Split free blocks level-by-level.
|
||||||
|
@ -22,9 +22,7 @@
|
|||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
|
|
||||||
static constexpr uint64_t INVALID_OFFSET = std::numeric_limits<uint64_t>::max();
|
// Buddy allocator uses the buddy memory allocation technique to satisfy an allocation request.
|
||||||
|
|
||||||
// Buddy allocator uses the buddy memory allocation technique to satisify an allocation request.
|
|
||||||
// Memory is split into halves until just large enough to fit to the request. This
|
// Memory is split into halves until just large enough to fit to the request. This
|
||||||
// requires the allocation size to be a power-of-two value. The allocator "allocates" a block by
|
// requires the allocation size to be a power-of-two value. The allocator "allocates" a block by
|
||||||
// returning the starting offset whose size is guaranteed to be greater than or equal to the
|
// returning the starting offset whose size is guaranteed to be greater than or equal to the
|
||||||
@ -47,6 +45,8 @@ namespace dawn_native {
|
|||||||
// For testing purposes only.
|
// For testing purposes only.
|
||||||
uint64_t ComputeTotalNumOfFreeBlocksForTesting() const;
|
uint64_t ComputeTotalNumOfFreeBlocksForTesting() const;
|
||||||
|
|
||||||
|
static constexpr uint64_t kInvalidOffset = std::numeric_limits<uint64_t>::max();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t ComputeLevelFromBlockSize(uint64_t blockSize) const;
|
uint32_t ComputeLevelFromBlockSize(uint64_t blockSize) const;
|
||||||
uint64_t GetNextFreeAlignedBlock(size_t allocationBlockLevel, uint64_t alignment) const;
|
uint64_t GetNextFreeAlignedBlock(size_t allocationBlockLevel, uint64_t alignment) const;
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
using namespace dawn_native;
|
using namespace dawn_native;
|
||||||
|
|
||||||
|
constexpr uint64_t BuddyAllocator::kInvalidOffset;
|
||||||
|
|
||||||
// Verify the buddy allocator with a basic test.
|
// Verify the buddy allocator with a basic test.
|
||||||
TEST(BuddyAllocatorTests, SingleBlock) {
|
TEST(BuddyAllocatorTests, SingleBlock) {
|
||||||
// After one 32 byte allocation:
|
// After one 32 byte allocation:
|
||||||
@ -29,17 +31,17 @@ TEST(BuddyAllocatorTests, SingleBlock) {
|
|||||||
BuddyAllocator allocator(maxBlockSize);
|
BuddyAllocator allocator(maxBlockSize);
|
||||||
|
|
||||||
// Check that we cannot allocate a oversized block.
|
// Check that we cannot allocate a oversized block.
|
||||||
ASSERT_EQ(allocator.Allocate(maxBlockSize * 2), INVALID_OFFSET);
|
ASSERT_EQ(allocator.Allocate(maxBlockSize * 2), BuddyAllocator::kInvalidOffset);
|
||||||
|
|
||||||
// Check that we cannot allocate a zero sized block.
|
// Check that we cannot allocate a zero sized block.
|
||||||
ASSERT_EQ(allocator.Allocate(0u), INVALID_OFFSET);
|
ASSERT_EQ(allocator.Allocate(0u), BuddyAllocator::kInvalidOffset);
|
||||||
|
|
||||||
// Allocate the block.
|
// Allocate the block.
|
||||||
uint64_t blockOffset = allocator.Allocate(maxBlockSize);
|
uint64_t blockOffset = allocator.Allocate(maxBlockSize);
|
||||||
ASSERT_EQ(blockOffset, 0u);
|
ASSERT_EQ(blockOffset, 0u);
|
||||||
|
|
||||||
// Check that we are full.
|
// Check that we are full.
|
||||||
ASSERT_EQ(allocator.Allocate(maxBlockSize), INVALID_OFFSET);
|
ASSERT_EQ(allocator.Allocate(maxBlockSize), BuddyAllocator::kInvalidOffset);
|
||||||
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 0u);
|
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 0u);
|
||||||
|
|
||||||
// Deallocate the block.
|
// Deallocate the block.
|
||||||
@ -86,7 +88,7 @@ TEST(BuddyAllocatorTests, SingleSplitBlock) {
|
|||||||
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 1u);
|
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 1u);
|
||||||
|
|
||||||
// Check that we cannot allocate a block that is oversized.
|
// Check that we cannot allocate a block that is oversized.
|
||||||
ASSERT_EQ(allocator.Allocate(maxBlockSize * 2), INVALID_OFFSET);
|
ASSERT_EQ(allocator.Allocate(maxBlockSize * 2), BuddyAllocator::kInvalidOffset);
|
||||||
|
|
||||||
// Re-allocate the largest block allowed after merging.
|
// Re-allocate the largest block allowed after merging.
|
||||||
blockOffset = allocator.Allocate(maxBlockSize);
|
blockOffset = allocator.Allocate(maxBlockSize);
|
||||||
@ -188,7 +190,7 @@ TEST(BuddyAllocatorTests, MultipleSplitBlockIncreasingSize) {
|
|||||||
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 0u);
|
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 0u);
|
||||||
|
|
||||||
// Check if we're full.
|
// Check if we're full.
|
||||||
ASSERT_EQ(allocator.Allocate(32), INVALID_OFFSET);
|
ASSERT_EQ(allocator.Allocate(32), BuddyAllocator::kInvalidOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify very small allocations using a larger allocator works correctly.
|
// Verify very small allocations using a larger allocator works correctly.
|
||||||
@ -284,7 +286,7 @@ TEST(BuddyAllocatorTests, SameSizeVariousAlignment) {
|
|||||||
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 2u);
|
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 2u);
|
||||||
|
|
||||||
// Check that we cannot fit another.
|
// Check that we cannot fit another.
|
||||||
ASSERT_EQ(allocator.Allocate(8, 16), INVALID_OFFSET);
|
ASSERT_EQ(allocator.Allocate(8, 16), BuddyAllocator::kInvalidOffset);
|
||||||
|
|
||||||
// Allocate Ac (zero splits and Ab's buddy is now the first free block).
|
// Allocate Ac (zero splits and Ab's buddy is now the first free block).
|
||||||
ASSERT_EQ(allocator.Allocate(8, 8), 24u);
|
ASSERT_EQ(allocator.Allocate(8, 8), 24u);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user