Move the vk Serial class to renderer_utils.
This can be useful for other back-ends, for various types of state
management. Also redesign the class to use an opaque factory instead
of an increment operator. The class maintains the property of being
ordered. Also assume we don't overflow with 64-bit serials. We could
maybe redesign this to use 32-bit serials for memory constrained
situations, and handle overflow more gracefully.
I plan to use the serials to track state revisions for the vertex
array class, to avoid doing redundant work.
BUG=angleproject:1156
Change-Id: I02c78b228bc6e2fb3ee786fe67a4e607baaca18e
Reviewed-on: https://chromium-review.googlesource.com/529704
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/renderer_utils.h b/src/libANGLE/renderer/renderer_utils.h
index a146d0f..0936024 100644
--- a/src/libANGLE/renderer/renderer_utils.h
+++ b/src/libANGLE/renderer/renderer_utils.h
@@ -15,6 +15,7 @@
#include <limits>
#include <map>
+#include "common/angleutils.h"
#include "libANGLE/angletypes.h"
namespace angle
@@ -47,6 +48,43 @@
uintptr_t mValue;
};
+class SerialFactory;
+
+class Serial final
+{
+ public:
+ constexpr Serial() : mValue(0) {}
+ constexpr Serial(const Serial &other) = default;
+ Serial &operator=(const Serial &other) = default;
+
+ constexpr bool operator==(const Serial &other) const { return mValue == other.mValue; }
+ constexpr bool operator!=(const Serial &other) const { return mValue != other.mValue; }
+ constexpr bool operator>(const Serial &other) const { return mValue > other.mValue; }
+ constexpr bool operator>=(const Serial &other) const { return mValue >= other.mValue; }
+ constexpr bool operator<(const Serial &other) const { return mValue < other.mValue; }
+ constexpr bool operator<=(const Serial &other) const { return mValue <= other.mValue; }
+
+ private:
+ friend class SerialFactory;
+ constexpr explicit Serial(uint64_t value) : mValue(value) {}
+ uint64_t mValue;
+};
+
+class SerialFactory final : angle::NonCopyable
+{
+ public:
+ SerialFactory() : mSerial(1) {}
+
+ Serial generate()
+ {
+ ASSERT(mSerial != std::numeric_limits<uint64_t>::max());
+ return Serial(mSerial++);
+ }
+
+ private:
+ uint64_t mSerial;
+};
+
using MipGenerationFunction = void (*)(size_t sourceWidth,
size_t sourceHeight,
size_t sourceDepth,