Cleans up lingering "Blueprint" type usages after AttachmentState merge.
Bug: dawn:1769
Change-Id: Ia90c90d72be9b6ac1b32f0a0c082e80a8401a5d7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/139507
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/common/ContentLessObjectCache.h b/src/dawn/common/ContentLessObjectCache.h
index bcfef2d..551f796 100644
--- a/src/dawn/common/ContentLessObjectCache.h
+++ b/src/dawn/common/ContentLessObjectCache.h
@@ -30,11 +30,8 @@
// This means that any RefCountedT that is inserted into the cache needs to make sure that their
// DeleteThis function erases itself from the cache. Otherwise, the cache can grow indefinitely via
// leaked pointers to deleted Refs.
-template <typename RefCountedT, typename BlueprintT = RefCountedT>
+template <typename RefCountedT>
class ContentLessObjectCache {
- static_assert(std::is_convertible_v<RefCountedT*, BlueprintT*>,
- "RefCountedT* must be convertible to a BlueprintT*.");
-
public:
// The dtor asserts that the cache is empty to aid in finding pointer leaks that can be possible
// if the RefCountedT doesn't correctly implement the DeleteThis function to erase itself from
@@ -68,7 +65,7 @@
// Returns a valid Ref<T> if the underlying RefCounted object's refcount has not reached 0.
// Otherwise, returns nullptr.
- Ref<RefCountedT> Find(BlueprintT* blueprint) {
+ Ref<RefCountedT> Find(RefCountedT* blueprint) {
std::lock_guard<std::mutex> lock(mMutex);
auto it = mCache.find(blueprint);
if (it != mCache.end()) {
@@ -95,9 +92,10 @@
private:
std::mutex mMutex;
- std::
- unordered_set<BlueprintT*, typename BlueprintT::HashFunc, typename BlueprintT::EqualityFunc>
- mCache;
+ std::unordered_set<RefCountedT*,
+ typename RefCountedT::HashFunc,
+ typename RefCountedT::EqualityFunc>
+ mCache;
};
} // namespace dawn
diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp
index 3741ce3..f920ead 100644
--- a/src/dawn/native/Device.cpp
+++ b/src/dawn/native/Device.cpp
@@ -70,10 +70,10 @@
ContentLessObjectCache<ShaderModuleBase> shaderModules;
};
-// Tries to find the blueprint in the cache, creating and inserting into the cache if not found.
-template <typename RefCountedT, typename BlueprintT, typename CreateFn>
-auto GetOrCreate(ContentLessObjectCache<RefCountedT, BlueprintT>& cache,
- BlueprintT* blueprint,
+// Tries to find an object in the cache, creating and inserting into the cache if not found.
+template <typename RefCountedT, typename CreateFn>
+auto GetOrCreate(ContentLessObjectCache<RefCountedT>& cache,
+ RefCountedT* blueprint,
CreateFn createFn) {
using ReturnType = decltype(createFn());
diff --git a/src/dawn/tests/unittests/ContentLessObjectCacheTests.cpp b/src/dawn/tests/unittests/ContentLessObjectCacheTests.cpp
index 6c67223..0b86e15 100644
--- a/src/dawn/tests/unittests/ContentLessObjectCacheTests.cpp
+++ b/src/dawn/tests/unittests/ContentLessObjectCacheTests.cpp
@@ -25,34 +25,11 @@
namespace dawn {
namespace {
-using ::testing::Test;
-using ::testing::Types;
-
-class BlueprintT {
+class RefCountedT : public RefCounted {
public:
- explicit BlueprintT(size_t value) : mValue(value) {}
-
- size_t GetValue() const { return mValue; }
-
- struct HashFunc {
- size_t operator()(const BlueprintT* x) const { return x->mValue; }
- };
-
- struct EqualityFunc {
- bool operator()(const BlueprintT* l, const BlueprintT* r) const {
- return l->mValue == r->mValue;
- }
- };
-
- protected:
- size_t mValue;
-};
-
-class RefCountedT : public BlueprintT, public RefCounted {
- public:
- explicit RefCountedT(size_t value) : BlueprintT(value) {}
+ explicit RefCountedT(size_t value) : mValue(value) {}
RefCountedT(size_t value, std::function<void(RefCountedT*)> deleteFn)
- : BlueprintT(value), mDeleteFn(deleteFn) {}
+ : mValue(value), mDeleteFn(deleteFn) {}
~RefCountedT() override { mDeleteFn(this); }
@@ -67,36 +44,19 @@
};
private:
+ size_t mValue;
std::function<void(RefCountedT*)> mDeleteFn = [](RefCountedT*) -> void {};
};
-template <typename Blueprint>
-class ContentLessObjectCacheTest : public Test {};
-
-class BlueprintTypeNames {
- public:
- template <typename T>
- static std::string GetName(int) {
- if (std::is_same<T, RefCountedT>()) {
- return "RefCountedT";
- }
- if (std::is_same<T, BlueprintT>()) {
- return "BlueprintT";
- }
- }
-};
-using BlueprintTypes = Types<RefCountedT, BlueprintT>;
-TYPED_TEST_SUITE(ContentLessObjectCacheTest, BlueprintTypes, BlueprintTypeNames);
-
// Empty cache returns true on Empty().
-TYPED_TEST(ContentLessObjectCacheTest, Empty) {
- ContentLessObjectCache<RefCountedT, TypeParam> cache;
+TEST(ContentLessObjectCacheTest, Empty) {
+ ContentLessObjectCache<RefCountedT> cache;
EXPECT_TRUE(cache.Empty());
}
// Non-empty cache returns false on Empty().
-TYPED_TEST(ContentLessObjectCacheTest, NonEmpty) {
- ContentLessObjectCache<RefCountedT, TypeParam> cache;
+TEST(ContentLessObjectCacheTest, NonEmpty) {
+ ContentLessObjectCache<RefCountedT> cache;
Ref<RefCountedT> object =
AcquireRef(new RefCountedT(1, [&](RefCountedT* x) { cache.Erase(x); }));
EXPECT_TRUE(cache.Insert(object.Get()).second);
@@ -104,20 +64,20 @@
}
// Object inserted into the cache are findable.
-TYPED_TEST(ContentLessObjectCacheTest, Insert) {
- ContentLessObjectCache<RefCountedT, TypeParam> cache;
+TEST(ContentLessObjectCacheTest, Insert) {
+ ContentLessObjectCache<RefCountedT> cache;
Ref<RefCountedT> object =
AcquireRef(new RefCountedT(1, [&](RefCountedT* x) { cache.Erase(x); }));
EXPECT_TRUE(cache.Insert(object.Get()).second);
- TypeParam blueprint(1);
+ RefCountedT blueprint(1);
Ref<RefCountedT> cached = cache.Find(&blueprint);
EXPECT_TRUE(object.Get() == cached.Get());
}
// Duplicate insert calls on different objects with the same hash only inserts the first.
-TYPED_TEST(ContentLessObjectCacheTest, InsertDuplicate) {
- ContentLessObjectCache<RefCountedT, TypeParam> cache;
+TEST(ContentLessObjectCacheTest, InsertDuplicate) {
+ ContentLessObjectCache<RefCountedT> cache;
Ref<RefCountedT> object1 =
AcquireRef(new RefCountedT(1, [&](RefCountedT* x) { cache.Erase(x); }));
EXPECT_TRUE(cache.Insert(object1.Get()).second);
@@ -125,14 +85,14 @@
Ref<RefCountedT> object2 = AcquireRef(new RefCountedT(1));
EXPECT_FALSE(cache.Insert(object2.Get()).second);
- TypeParam blueprint(1);
+ RefCountedT blueprint(1);
Ref<RefCountedT> cached = cache.Find(&blueprint);
EXPECT_TRUE(object1.Get() == cached.Get());
}
// Erasing the only entry leaves the cache empty.
-TYPED_TEST(ContentLessObjectCacheTest, Erase) {
- ContentLessObjectCache<RefCountedT, TypeParam> cache;
+TEST(ContentLessObjectCacheTest, Erase) {
+ ContentLessObjectCache<RefCountedT> cache;
Ref<RefCountedT> object = AcquireRef(new RefCountedT(1));
EXPECT_TRUE(cache.Insert(object.Get()).second);
EXPECT_FALSE(cache.Empty());
@@ -142,8 +102,8 @@
}
// Erasing a hash equivalent but not pointer equivalent entry is a no-op.
-TYPED_TEST(ContentLessObjectCacheTest, EraseDuplicate) {
- ContentLessObjectCache<RefCountedT, TypeParam> cache;
+TEST(ContentLessObjectCacheTest, EraseDuplicate) {
+ ContentLessObjectCache<RefCountedT> cache;
Ref<RefCountedT> object1 =
AcquireRef(new RefCountedT(1, [&](RefCountedT* x) { cache.Erase(x); }));
EXPECT_TRUE(cache.Insert(object1.Get()).second);
@@ -175,10 +135,10 @@
};
// Inserting and finding elements should respect the results from the insert call.
-TYPED_TEST(ContentLessObjectCacheTest, InsertingAndFinding) {
+TEST(ContentLessObjectCacheTest, InsertingAndFinding) {
constexpr size_t kNumObjects = 100;
constexpr size_t kNumThreads = 8;
- ContentLessObjectCache<RefCountedT, TypeParam> cache;
+ ContentLessObjectCache<RefCountedT> cache;
std::vector<Ref<RefCountedT>> objects(kNumObjects);
auto f = [&] {
@@ -191,7 +151,7 @@
}
}
for (size_t i = 0; i < kNumObjects; i++) {
- TypeParam blueprint(i);
+ RefCountedT blueprint(i);
Ref<RefCountedT> cached = cache.Find(&blueprint);
EXPECT_NE(cached.Get(), nullptr);
EXPECT_EQ(cached.Get(), objects[i].Get());
@@ -208,10 +168,10 @@
}
// Finding an element that is in the process of deletion should return nullptr.
-TYPED_TEST(ContentLessObjectCacheTest, FindDeleting) {
+TEST(ContentLessObjectCacheTest, FindDeleting) {
Signal signalA, signalB;
- ContentLessObjectCache<RefCountedT, TypeParam> cache;
+ ContentLessObjectCache<RefCountedT> cache;
Ref<RefCountedT> object = AcquireRef(new RefCountedT(1, [&](RefCountedT* x) {
signalA.Fire();
signalB.Wait();
@@ -224,7 +184,7 @@
// Thread B will try to Find the entry before it is completely destroyed.
auto threadB = [&] {
signalA.Wait();
- TypeParam blueprint(1);
+ RefCountedT blueprint(1);
EXPECT_TRUE(cache.Find(&blueprint) == nullptr);
signalB.Fire();
};
@@ -237,10 +197,10 @@
// Inserting an element that has an entry which is in process of deletion should insert the new
// object.
-TYPED_TEST(ContentLessObjectCacheTest, InsertDeleting) {
+TEST(ContentLessObjectCacheTest, InsertDeleting) {
Signal signalA, signalB;
- ContentLessObjectCache<RefCountedT, TypeParam> cache;
+ ContentLessObjectCache<RefCountedT> cache;
Ref<RefCountedT> object1 = AcquireRef(new RefCountedT(1, [&](RefCountedT* x) {
signalA.Fire();
signalB.Wait();
@@ -266,7 +226,7 @@
tA.join();
tB.join();
- TypeParam blueprint(1);
+ RefCountedT blueprint(1);
Ref<RefCountedT> cached = cache.Find(&blueprint);
EXPECT_TRUE(object2.Get() == cached.Get());
}