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>
diff --git a/src/dawn_native/DynamicUploader.cpp b/src/dawn_native/DynamicUploader.cpp
index b77cb94..876b789 100644
--- a/src/dawn_native/DynamicUploader.cpp
+++ b/src/dawn_native/DynamicUploader.cpp
@@ -44,14 +44,14 @@
}
}
- 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 @@
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.
diff --git a/src/dawn_native/RingBufferAllocator.h b/src/dawn_native/RingBufferAllocator.h
index 630da98..82241b3 100644
--- a/src/dawn_native/RingBufferAllocator.h
+++ b/src/dawn_native/RingBufferAllocator.h
@@ -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 @@
bool Empty() const;
size_t GetUsedSize() const;
+ static constexpr size_t kInvalidOffset = std::numeric_limits<size_t>::max();
+
private:
struct Request {
size_t endOffset;
diff --git a/src/tests/unittests/RingBufferAllocatorTests.cpp b/src/tests/unittests/RingBufferAllocatorTests.cpp
index cc381cc..2455e8d 100644
--- a/src/tests/unittests/RingBufferAllocatorTests.cpp
+++ b/src/tests/unittests/RingBufferAllocatorTests.cpp
@@ -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 @@
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 @@
//
// 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 @@
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 @@
//
// 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);