Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1b0f79e

Browse files
vontureCommit Bot
authored andcommitted
Vulkan: Use atomics in SerialFactory.
This allows serials to be generated from multiple threads without locking for very little/no cost. BUG=angleproject:2464 Change-Id: Id61d170e7a985c3100da0057156859ffcb083dad Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1516514 Commit-Queue: Geoff Lang <[email protected]> Reviewed-by: Shahbaz Youssefi <[email protected]>
1 parent 29ac274 commit 1b0f79e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/libANGLE/renderer/renderer_utils.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <cstdint>
1414

15+
#include <atomic>
1516
#include <limits>
1617
#include <map>
1718

@@ -61,8 +62,6 @@ class ResourceSerial
6162
uintptr_t mValue;
6263
};
6364

64-
class SerialFactory;
65-
6665
class Serial final
6766
{
6867
public:
@@ -93,27 +92,32 @@ class Serial final
9392
constexpr uint64_t getValue() const { return mValue; }
9493

9594
private:
96-
friend class SerialFactory;
95+
template <typename T>
96+
friend class SerialFactoryBase;
9797
constexpr explicit Serial(uint64_t value) : mValue(value) {}
9898
uint64_t mValue;
9999
static constexpr uint64_t kInvalid = 0;
100100
};
101101

102-
class SerialFactory final : angle::NonCopyable
102+
template <typename SerialBaseType>
103+
class SerialFactoryBase final : angle::NonCopyable
103104
{
104105
public:
105-
SerialFactory() : mSerial(1) {}
106+
SerialFactoryBase() : mSerial(1) {}
106107

107108
Serial generate()
108109
{
109-
ASSERT(mSerial != std::numeric_limits<uint64_t>::max());
110+
ASSERT(mSerial + 1 > mSerial);
110111
return Serial(mSerial++);
111112
}
112113

113114
private:
114-
uint64_t mSerial;
115+
SerialBaseType mSerial;
115116
};
116117

118+
using SerialFactory = SerialFactoryBase<uint64_t>;
119+
using AtomicSerialFactory = SerialFactoryBase<std::atomic<uint64_t>>;
120+
117121
using MipGenerationFunction = void (*)(size_t sourceWidth,
118122
size_t sourceHeight,
119123
size_t sourceDepth,

src/libANGLE/renderer/vulkan/RendererVk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ class RendererVk : angle::NonCopyable
187187
uint32_t mCurrentQueueFamilyIndex;
188188
uint32_t mMaxVertexAttribDivisor;
189189
VkDevice mDevice;
190-
SerialFactory mQueueSerialFactory;
191-
SerialFactory mShaderSerialFactory;
190+
AtomicSerialFactory mQueueSerialFactory;
191+
AtomicSerialFactory mShaderSerialFactory;
192192
Serial mCurrentQueueSerial;
193193

194194
bool mDeviceLost;

0 commit comments

Comments
 (0)