Commit d50151d3 by Jamie Madill Committed by Commit Bot

Move Serial utils to their own file.

This will let the front-end access them without pulling in the rest of renderer_utils. The Serial class in particular will be useful for capture/replay. Also adds a very minimal unit test. Bug: angleproject:4223 Change-Id: I9e63b8a8227a245b20a8f024b960fcf60c7840db Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1954611 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com>
parent e60d05b2
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "libANGLE/renderer/d3d/VertexDataManager.h" #include "libANGLE/renderer/d3d/VertexDataManager.h"
#include "libANGLE/renderer/d3d/formatutilsD3D.h" #include "libANGLE/renderer/d3d/formatutilsD3D.h"
#include "libANGLE/renderer/renderer_utils.h" #include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/serial_utils.h"
#include "platform/FeaturesD3D.h" #include "platform/FeaturesD3D.h"
namespace egl namespace egl
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" #include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" #include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
#include "libANGLE/renderer/serial_utils.h"
// Precompiled shaders // Precompiled shaders
#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/buffertotexture11_gs.h" #include "libANGLE/renderer/d3d/d3d11/shaders/compiled/buffertotexture11_gs.h"
......
...@@ -21,12 +21,11 @@ ...@@ -21,12 +21,11 @@
namespace gl namespace gl
{ {
class Buffer; class Buffer;
class Context;
struct Box; struct Box;
struct Extents; struct Extents;
struct PixelUnpackState; struct PixelUnpackState;
} // namespace gl } // namespace gl
namespace rx namespace rx
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/renderer/renderer_utils.h" #include "libANGLE/renderer/serial_utils.h"
namespace rx namespace rx
{ {
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
#include "libANGLE/renderer/d3d/ShaderExecutableD3D.h" #include "libANGLE/renderer/d3d/ShaderExecutableD3D.h"
#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" #include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h"
namespace gl
{
class Context;
} // namespace gl
namespace rx namespace rx
{ {
class Renderer11; class Renderer11;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
#include "libANGLE/renderer/TransformFeedbackImpl.h" #include "libANGLE/renderer/TransformFeedbackImpl.h"
#include "libANGLE/renderer/renderer_utils.h" #include "libANGLE/renderer/serial_utils.h"
namespace rx namespace rx
{ {
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <cstdint> #include <cstdint>
#include <atomic>
#include <limits> #include <limits>
#include <map> #include <map>
...@@ -44,83 +43,6 @@ namespace rx ...@@ -44,83 +43,6 @@ namespace rx
{ {
class ContextImpl; class ContextImpl;
class ResourceSerial
{
public:
constexpr ResourceSerial() : mValue(kDirty) {}
explicit constexpr ResourceSerial(uintptr_t value) : mValue(value) {}
constexpr bool operator==(ResourceSerial other) const { return mValue == other.mValue; }
constexpr bool operator!=(ResourceSerial other) const { return mValue != other.mValue; }
void dirty() { mValue = kDirty; }
void clear() { mValue = kEmpty; }
constexpr bool valid() const { return mValue != kEmpty && mValue != kDirty; }
constexpr bool empty() const { return mValue == kEmpty; }
private:
constexpr static uintptr_t kDirty = std::numeric_limits<uintptr_t>::max();
constexpr static uintptr_t kEmpty = 0;
uintptr_t mValue;
};
class Serial final
{
public:
constexpr Serial() : mValue(kInvalid) {}
constexpr Serial(const Serial &other) = default;
Serial &operator=(const Serial &other) = default;
constexpr bool operator==(const Serial &other) const
{
return mValue != kInvalid && mValue == other.mValue;
}
constexpr bool operator==(uint32_t value) const
{
return mValue != kInvalid && mValue == static_cast<uint64_t>(value);
}
constexpr bool operator!=(const Serial &other) const
{
return mValue == kInvalid || 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<(uint32_t value) const { return mValue < static_cast<uint64_t>(value); }
// Useful for serialization.
constexpr uint64_t getValue() const { return mValue; }
private:
template <typename T>
friend class SerialFactoryBase;
constexpr explicit Serial(uint64_t value) : mValue(value) {}
uint64_t mValue;
static constexpr uint64_t kInvalid = 0;
};
template <typename SerialBaseType>
class SerialFactoryBase final : angle::NonCopyable
{
public:
SerialFactoryBase() : mSerial(1) {}
Serial generate()
{
ASSERT(mSerial + 1 > mSerial);
return Serial(mSerial++);
}
private:
SerialBaseType mSerial;
};
using SerialFactory = SerialFactoryBase<uint64_t>;
using AtomicSerialFactory = SerialFactoryBase<std::atomic<uint64_t>>;
using MipGenerationFunction = void (*)(size_t sourceWidth, using MipGenerationFunction = void (*)(size_t sourceWidth,
size_t sourceHeight, size_t sourceHeight,
size_t sourceDepth, size_t sourceDepth,
......
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// serial_utils:
// Utilities for generating unique IDs for resources in ANGLE.
//
#ifndef LIBANGLE_RENDERER_SERIAL_UTILS_H_
#define LIBANGLE_RENDERER_SERIAL_UTILS_H_
#include <atomic>
#include "common/angleutils.h"
#include "common/debug.h"
namespace rx
{
class ResourceSerial
{
public:
constexpr ResourceSerial() : mValue(kDirty) {}
explicit constexpr ResourceSerial(uintptr_t value) : mValue(value) {}
constexpr bool operator==(ResourceSerial other) const { return mValue == other.mValue; }
constexpr bool operator!=(ResourceSerial other) const { return mValue != other.mValue; }
void dirty() { mValue = kDirty; }
void clear() { mValue = kEmpty; }
constexpr bool valid() const { return mValue != kEmpty && mValue != kDirty; }
constexpr bool empty() const { return mValue == kEmpty; }
private:
constexpr static uintptr_t kDirty = std::numeric_limits<uintptr_t>::max();
constexpr static uintptr_t kEmpty = 0;
uintptr_t mValue;
};
class Serial final
{
public:
constexpr Serial() : mValue(kInvalid) {}
constexpr Serial(const Serial &other) = default;
Serial &operator=(const Serial &other) = default;
constexpr bool operator==(const Serial &other) const
{
return mValue != kInvalid && mValue == other.mValue;
}
constexpr bool operator==(uint32_t value) const
{
return mValue != kInvalid && mValue == static_cast<uint64_t>(value);
}
constexpr bool operator!=(const Serial &other) const
{
return mValue == kInvalid || 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<(uint32_t value) const { return mValue < static_cast<uint64_t>(value); }
// Useful for serialization.
constexpr uint64_t getValue() const { return mValue; }
private:
template <typename T>
friend class SerialFactoryBase;
constexpr explicit Serial(uint64_t value) : mValue(value) {}
uint64_t mValue;
static constexpr uint64_t kInvalid = 0;
};
template <typename SerialBaseType>
class SerialFactoryBase final : angle::NonCopyable
{
public:
SerialFactoryBase() : mSerial(1) {}
Serial generate()
{
ASSERT(mSerial + 1 > mSerial);
return Serial(mSerial++);
}
private:
SerialBaseType mSerial;
};
using SerialFactory = SerialFactoryBase<uint64_t>;
using AtomicSerialFactory = SerialFactoryBase<std::atomic<uint64_t>>;
} // namespace rx
#endif // LIBANGLE_RENDERER_SERIAL_UTILS_H_
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// serial_utils_unittest:
// Unit tests for the Serial utils.
//
#include <gtest/gtest.h>
#include "libANGLE/renderer/serial_utils.h"
namespace rx
{
TEST(SerialTest, Monotonic)
{
SerialFactory factory;
Serial a = factory.generate();
Serial b = factory.generate();
EXPECT_GT(b, a);
Serial zero;
EXPECT_GT(a, zero);
EXPECT_GT(b, zero);
}
} // namespace rx
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#ifndef LIBANGLE_RENDERER_VULKAN_VK_UTILS_H_ #ifndef LIBANGLE_RENDERER_VULKAN_VK_UTILS_H_
#define LIBANGLE_RENDERER_VULKAN_VK_UTILS_H_ #define LIBANGLE_RENDERER_VULKAN_VK_UTILS_H_
#include <atomic>
#include <limits> #include <limits>
#include "common/FixedVector.h" #include "common/FixedVector.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/Observer.h" #include "libANGLE/Observer.h"
#include "libANGLE/renderer/serial_utils.h"
#include "libANGLE/renderer/vulkan/SecondaryCommandBuffer.h" #include "libANGLE/renderer/vulkan/SecondaryCommandBuffer.h"
#include "libANGLE/renderer/vulkan/vk_wrapper.h" #include "libANGLE/renderer/vulkan/vk_wrapper.h"
......
...@@ -304,6 +304,7 @@ libangle_headers = [ ...@@ -304,6 +304,7 @@ libangle_headers = [
"src/libANGLE/renderer/copyvertex.inc.h", "src/libANGLE/renderer/copyvertex.inc.h",
"src/libANGLE/renderer/load_functions_table.h", "src/libANGLE/renderer/load_functions_table.h",
"src/libANGLE/renderer/renderer_utils.h", "src/libANGLE/renderer/renderer_utils.h",
"src/libANGLE/renderer/serial_utils.h",
"src/libANGLE/validationEGL.h", "src/libANGLE/validationEGL.h",
"src/libANGLE/validationES.h", "src/libANGLE/validationES.h",
"src/libANGLE/validationES1.h", "src/libANGLE/validationES1.h",
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "common/tls.h" #include "common/tls.h"
#include "libGLESv2/resource.h" #include "libGLESv2/resource.h"
#include <atomic>
namespace gl namespace gl
{ {
// In single-threaded cases we can avoid a TLS lookup for the current Context. // In single-threaded cases we can avoid a TLS lookup for the current Context.
......
...@@ -44,6 +44,7 @@ angle_unittests_sources = [ ...@@ -44,6 +44,7 @@ angle_unittests_sources = [
"../libANGLE/renderer/ImageImpl_mock.h", "../libANGLE/renderer/ImageImpl_mock.h",
"../libANGLE/renderer/TextureImpl_mock.h", "../libANGLE/renderer/TextureImpl_mock.h",
"../libANGLE/renderer/TransformFeedbackImpl_mock.h", "../libANGLE/renderer/TransformFeedbackImpl_mock.h",
"../libANGLE/renderer/serial_utils_unittest.cpp",
"angle_unittests_utils.h", "angle_unittests_utils.h",
"compiler_tests/API_test.cpp", "compiler_tests/API_test.cpp",
"compiler_tests/AppendixALimitations_test.cpp", "compiler_tests/AppendixALimitations_test.cpp",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment