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 <shrekshao@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
Loko Kung 2022-03-03 20:08:22 +00:00 committed by Dawn LUCI CQ
parent 1f74114bfe
commit ba70fac14d
2 changed files with 39 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include "dawn/native/CachedObject.h" #include "dawn/native/CachedObject.h"
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
#include "dawn/native/Device.h"
namespace dawn::native { namespace dawn::native {
@ -41,4 +42,26 @@ namespace dawn::native {
mIsContentHashInitialized = true; 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 } // namespace dawn::native

View File

@ -15,7 +15,10 @@
#ifndef DAWNNATIVE_CACHED_OBJECT_H_ #ifndef DAWNNATIVE_CACHED_OBJECT_H_
#define DAWNNATIVE_CACHED_OBJECT_H_ #define DAWNNATIVE_CACHED_OBJECT_H_
#include "dawn/native/Forward.h"
#include <cstddef> #include <cstddef>
#include <string>
namespace dawn::native { namespace dawn::native {
@ -35,6 +38,14 @@ namespace dawn::native {
size_t GetContentHash() const; size_t GetContentHash() const;
void SetContentHash(size_t contentHash); 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: private:
friend class DeviceBase; friend class DeviceBase;
void SetIsCachedReference(); void SetIsCachedReference();
@ -44,8 +55,13 @@ namespace dawn::native {
// Called by ObjectContentHasher upon creation to record the object. // Called by ObjectContentHasher upon creation to record the object.
virtual size_t ComputeContentHash() = 0; 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; size_t mContentHash = 0;
bool mIsContentHashInitialized = false; bool mIsContentHashInitialized = false;
std::string mCacheKeyBase = "";
bool mIsCacheKeyBaseInitialized = false;
}; };
} // namespace dawn::native } // namespace dawn::native