From ba70fac14d80fc24007688954dec6c14fbeca9fc Mon Sep 17 00:00:00 2001 From: Loko Kung Date: Thu, 3 Mar 2022 20:08:22 +0000 Subject: [PATCH] Extends current CachedObject interface to allow setting and getting cache keys. Bug: dawn:549 Change-Id: I52d9321207d67b0214a52acc75456ee8d7943e8c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/81943 Reviewed-by: Shrek Shao Reviewed-by: Austin Eng Commit-Queue: Loko Kung --- src/dawn/native/CachedObject.cpp | 23 +++++++++++++++++++++++ src/dawn/native/CachedObject.h | 16 ++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/dawn/native/CachedObject.cpp b/src/dawn/native/CachedObject.cpp index 9a6d064701..538b7b5ccf 100644 --- a/src/dawn/native/CachedObject.cpp +++ b/src/dawn/native/CachedObject.cpp @@ -15,6 +15,7 @@ #include "dawn/native/CachedObject.h" #include "dawn/common/Assert.h" +#include "dawn/native/Device.h" namespace dawn::native { @@ -41,4 +42,26 @@ namespace dawn::native { mIsContentHashInitialized = true; } + const std::string& CachedObject::GetCacheKey() const { + ASSERT(mIsCacheKeyBaseInitialized); + return mCacheKeyBase; + } + + std::string CachedObject::GetCacheKey(DeviceBase* device) const { + ASSERT(mIsCacheKeyBaseInitialized); + // TODO(dawn:549) Prepend/append with device/adapter information. + return mCacheKeyBase; + } + + void CachedObject::SetCacheKey(const std::string& cacheKey) { + ASSERT(!mIsContentHashInitialized); + mCacheKeyBase = cacheKey; + mIsCacheKeyBaseInitialized = true; + } + + std::string CachedObject::ComputeCacheKeyBase() const { + // This implementation should never be called. Only overrides should be called. + UNREACHABLE(); + } + } // namespace dawn::native diff --git a/src/dawn/native/CachedObject.h b/src/dawn/native/CachedObject.h index b6c011511f..3cf79a2190 100644 --- a/src/dawn/native/CachedObject.h +++ b/src/dawn/native/CachedObject.h @@ -15,7 +15,10 @@ #ifndef DAWNNATIVE_CACHED_OBJECT_H_ #define DAWNNATIVE_CACHED_OBJECT_H_ +#include "dawn/native/Forward.h" + #include +#include namespace dawn::native { @@ -35,6 +38,14 @@ namespace dawn::native { size_t GetContentHash() const; void SetContentHash(size_t contentHash); + // Two versions of GetCacheKey, when passed a device, prepends the stored cache + // key base with device and adapter information. When called without passing a + // device, returns the stored cache key base. This is useful when the instance + // is a member to a parent class. + const std::string& GetCacheKey() const; + std::string GetCacheKey(DeviceBase* device) const; + void SetCacheKey(const std::string& cacheKey); + private: friend class DeviceBase; void SetIsCachedReference(); @@ -44,8 +55,13 @@ namespace dawn::native { // Called by ObjectContentHasher upon creation to record the object. virtual size_t ComputeContentHash() = 0; + // Not all classes implement cache key computation, so by default we assert. + virtual std::string ComputeCacheKeyBase() const; + size_t mContentHash = 0; bool mIsContentHashInitialized = false; + std::string mCacheKeyBase = ""; + bool mIsCacheKeyBaseInitialized = false; }; } // namespace dawn::native