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:
parent
1f74114bfe
commit
ba70fac14d
|
@ -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
|
||||
|
|
|
@ -15,7 +15,10 @@
|
|||
#ifndef DAWNNATIVE_CACHED_OBJECT_H_
|
||||
#define DAWNNATIVE_CACHED_OBJECT_H_
|
||||
|
||||
#include "dawn/native/Forward.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue