Move kInvalidOffset to RingBufferAllocator namespace.

BUG=dawn:27

Change-Id: I1c580d8e41c4f9bb10b638297b4c3a3fa61a0d93
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11680
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Bryan Bernhart 2019-09-27 21:26:13 +00:00 committed by Commit Bot service account
parent f622a44750
commit 52bd6b7da6
3 changed files with 15 additions and 10 deletions

View File

@ -44,14 +44,14 @@ namespace dawn_native {
}
}
size_t startOffset = kInvalidOffset;
size_t startOffset = RingBufferAllocator::kInvalidOffset;
if (targetRingBuffer != nullptr) {
startOffset = targetRingBuffer->mAllocator.Allocate(allocationSize, serial);
}
// Upon failure, append a newly created (and much larger) ring buffer to fulfill the
// request.
if (startOffset == kInvalidOffset) {
if (startOffset == RingBufferAllocator::kInvalidOffset) {
// Compute the new max size (in powers of two to preserve alignment).
size_t newMaxSize = targetRingBuffer->mAllocator.GetSize() * 2;
while (newMaxSize < allocationSize) {
@ -66,7 +66,7 @@ namespace dawn_native {
startOffset = targetRingBuffer->mAllocator.Allocate(allocationSize, serial);
}
ASSERT(startOffset != kInvalidOffset);
ASSERT(startOffset != RingBufferAllocator::kInvalidOffset);
// Allocate the staging buffer backing the ringbuffer.
// Note: the first ringbuffer will be lazily created.

View File

@ -23,8 +23,6 @@
// RingBufferAllocator is the front-end implementation used to manage a ring buffer in GPU memory.
namespace dawn_native {
static constexpr size_t kInvalidOffset = std::numeric_limits<size_t>::max();
class RingBufferAllocator {
public:
RingBufferAllocator(size_t maxSize);
@ -37,6 +35,8 @@ namespace dawn_native {
bool Empty() const;
size_t GetUsedSize() const;
static constexpr size_t kInvalidOffset = std::numeric_limits<size_t>::max();
private:
struct Request {
size_t endOffset;

View File

@ -18,6 +18,8 @@
using namespace dawn_native;
constexpr size_t RingBufferAllocator::kInvalidOffset;
// Number of basic tests for Ringbuffer
TEST(RingBufferAllocatorTests, BasicTest) {
constexpr size_t sizeInBytes = 64000;
@ -29,14 +31,14 @@ TEST(RingBufferAllocatorTests, BasicTest) {
ASSERT_EQ(allocator.GetSize(), sizeInBytes);
// Ensure failure upon sub-allocating an oversized request.
ASSERT_EQ(allocator.Allocate(sizeInBytes + 1, 0), kInvalidOffset);
ASSERT_EQ(allocator.Allocate(sizeInBytes + 1, 0), RingBufferAllocator::kInvalidOffset);
// Fill the entire buffer with two requests of equal size.
ASSERT_EQ(allocator.Allocate(sizeInBytes / 2, 1), 0u);
ASSERT_EQ(allocator.Allocate(sizeInBytes / 2, 2), 32000u);
// Ensure the buffer is full.
ASSERT_EQ(allocator.Allocate(1, 3), kInvalidOffset);
ASSERT_EQ(allocator.Allocate(1, 3), RingBufferAllocator::kInvalidOffset);
}
// Tests that several ringbuffer allocations do not fail.
@ -104,7 +106,8 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
//
// Ensure an oversized allocation fails (only 8 bytes left)
ASSERT_EQ(allocator.Allocate(frameSizeInBytes * 3, serial + 1), kInvalidOffset);
ASSERT_EQ(allocator.Allocate(frameSizeInBytes * 3, serial + 1),
RingBufferAllocator::kInvalidOffset);
ASSERT_EQ(allocator.GetUsedSize(), frameSizeInBytes * 8);
// Reclaim the first 3 frames.
@ -130,7 +133,8 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
ASSERT_EQ(allocator.GetUsedSize(), frameSizeInBytes * maxNumOfFrames);
// Ensure we are full.
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial + 1), kInvalidOffset);
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial + 1),
RingBufferAllocator::kInvalidOffset);
// Reclaim the next two frames.
allocator.Deallocate(5);
@ -152,7 +156,8 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
//
// Ensure we are full.
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial + 1), kInvalidOffset);
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial + 1),
RingBufferAllocator::kInvalidOffset);
// Reclaim all.
allocator.Deallocate(maxNumOfFrames);