Ensures blob cache is always available, even if it is just a placeholder
Bug: dawn:549 Change-Id: I7efbaa58d93691648107fc6b94d76596a77f6516 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/111140 Reviewed-by: Austin Eng <enga@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
parent
36e6b82df7
commit
bf3fecfc4b
|
@ -129,11 +129,7 @@ class CacheRequestImpl {
|
|||
using ReturnType = ResultOrError<CacheResultType>;
|
||||
|
||||
CacheKey key = r.CreateCacheKey(device);
|
||||
BlobCache* cache = device->GetBlobCache();
|
||||
Blob blob;
|
||||
if (cache != nullptr) {
|
||||
blob = cache->Load(key);
|
||||
}
|
||||
Blob blob = device->GetBlobCache()->Load(key);
|
||||
|
||||
if (!blob.Empty()) {
|
||||
// Cache hit. Handle the cached blob.
|
||||
|
|
|
@ -618,27 +618,18 @@ BlobCache* DeviceBase::GetBlobCache() {
|
|||
// TODO(crbug.com/dawn/1481): Shader caching currently has a dependency on the WGSL writer to
|
||||
// generate cache keys. We can lift the dependency once we also cache frontend parsing,
|
||||
// transformations, and reflection.
|
||||
if (!IsToggleEnabled(Toggle::DisableBlobCache)) {
|
||||
return mAdapter->GetInstance()->GetBlobCache();
|
||||
}
|
||||
return mAdapter->GetInstance()->GetBlobCache(!IsToggleEnabled(Toggle::DisableBlobCache));
|
||||
#endif
|
||||
return nullptr;
|
||||
return mAdapter->GetInstance()->GetBlobCache(false);
|
||||
}
|
||||
|
||||
Blob DeviceBase::LoadCachedBlob(const CacheKey& key) {
|
||||
BlobCache* blobCache = GetBlobCache();
|
||||
if (!blobCache) {
|
||||
return Blob();
|
||||
}
|
||||
return blobCache->Load(key);
|
||||
return GetBlobCache()->Load(key);
|
||||
}
|
||||
|
||||
void DeviceBase::StoreCachedBlob(const CacheKey& key, const Blob& blob) {
|
||||
if (!blob.Empty()) {
|
||||
BlobCache* blobCache = GetBlobCache();
|
||||
if (blobCache) {
|
||||
blobCache->Store(key, blob);
|
||||
}
|
||||
GetBlobCache()->Store(key, blob);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -456,8 +456,11 @@ dawn::platform::Platform* InstanceBase::GetPlatform() {
|
|||
return mPlatform;
|
||||
}
|
||||
|
||||
BlobCache* InstanceBase::GetBlobCache() {
|
||||
return mBlobCache.get();
|
||||
BlobCache* InstanceBase::GetBlobCache(bool enabled) {
|
||||
if (enabled) {
|
||||
return mBlobCache.get();
|
||||
}
|
||||
return &mPassthroughBlobCache;
|
||||
}
|
||||
|
||||
uint64_t InstanceBase::GetDeviceCountForTesting() const {
|
||||
|
|
|
@ -93,7 +93,7 @@ class InstanceBase final : public RefCountedWithExternalCount {
|
|||
void SetPlatform(dawn::platform::Platform* platform);
|
||||
void SetPlatformForTesting(dawn::platform::Platform* platform);
|
||||
dawn::platform::Platform* GetPlatform();
|
||||
BlobCache* GetBlobCache();
|
||||
BlobCache* GetBlobCache(bool enabled = true);
|
||||
|
||||
uint64_t GetDeviceCountForTesting() const;
|
||||
void IncrementDeviceCountForTesting();
|
||||
|
@ -139,6 +139,7 @@ class InstanceBase final : public RefCountedWithExternalCount {
|
|||
dawn::platform::Platform* mPlatform = nullptr;
|
||||
std::unique_ptr<dawn::platform::Platform> mDefaultPlatform;
|
||||
std::unique_ptr<BlobCache> mBlobCache;
|
||||
BlobCache mPassthroughBlobCache;
|
||||
|
||||
std::vector<std::unique_ptr<BackendConnection>> mBackends;
|
||||
std::vector<Ref<AdapterBase>> mAdapters;
|
||||
|
|
|
@ -21,7 +21,7 @@ PipelineCacheBase::PipelineCacheBase(BlobCache* cache, const CacheKey& key)
|
|||
|
||||
Blob PipelineCacheBase::Initialize() {
|
||||
ASSERT(!mInitialized);
|
||||
Blob blob = mCache != nullptr ? mCache->Load(mKey) : Blob();
|
||||
Blob blob = mCache->Load(mKey);
|
||||
mCacheHit = !blob.Empty();
|
||||
mInitialized = true;
|
||||
return blob;
|
||||
|
@ -33,9 +33,6 @@ bool PipelineCacheBase::CacheHit() const {
|
|||
}
|
||||
|
||||
MaybeError PipelineCacheBase::Flush() {
|
||||
if (mCache == nullptr) {
|
||||
return {};
|
||||
}
|
||||
// Try to write the data out to the persistent cache.
|
||||
Blob blob;
|
||||
DAWN_TRY(SerializeToBlobImpl(&blob));
|
||||
|
|
|
@ -648,9 +648,7 @@ ResultOrError<CompiledShader> ShaderModule::Compile(
|
|||
device->EmitLog(WGPULoggingType_Info, dumpedMsg.str().c_str());
|
||||
}
|
||||
|
||||
if (BlobCache* cache = device->GetBlobCache()) {
|
||||
cache->EnsureStored(compiledShader);
|
||||
}
|
||||
device->GetBlobCache()->EnsureStored(compiledShader);
|
||||
|
||||
// Clear the hlslSource. It is only used for logging and should not be used
|
||||
// outside of the compilation.
|
||||
|
|
|
@ -366,9 +366,7 @@ MaybeError ShaderModule::CreateFunction(SingleShaderStage stage,
|
|||
out->function = AcquireNSPRef([*library newFunctionWithName:name.Get()]);
|
||||
}
|
||||
|
||||
if (BlobCache* cache = GetDevice()->GetBlobCache()) {
|
||||
cache->EnsureStored(mslCompilation);
|
||||
}
|
||||
GetDevice()->GetBlobCache()->EnsureStored(mslCompilation);
|
||||
|
||||
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) &&
|
||||
GetEntryPoint(entryPointName).usedVertexInputs.any()) {
|
||||
|
|
|
@ -299,9 +299,7 @@ ResultOrError<GLuint> ShaderModule::CompileShader(const OpenGLFunctions& gl,
|
|||
}
|
||||
}
|
||||
|
||||
if (BlobCache* cache = GetDevice()->GetBlobCache()) {
|
||||
cache->EnsureStored(compilationResult);
|
||||
}
|
||||
GetDevice()->GetBlobCache()->EnsureStored(compilationResult);
|
||||
*needsPlaceholderSampler = compilationResult->needsPlaceholderSampler;
|
||||
*combinedSamplers = std::move(compilationResult->combinedSamplerInfo);
|
||||
return shader;
|
||||
|
|
|
@ -375,9 +375,8 @@ ResultOrError<ShaderModule::ModuleAndSpirv> ShaderModule::GetHandleAndSpirv(
|
|||
|
||||
ModuleAndSpirv moduleAndSpirv;
|
||||
if (newHandle != VK_NULL_HANDLE) {
|
||||
if (BlobCache* cache = device->GetBlobCache()) {
|
||||
cache->EnsureStored(compilation);
|
||||
}
|
||||
device->GetBlobCache()->EnsureStored(compilation);
|
||||
|
||||
// Set the label on `newHandle` now, and not on `moduleAndSpirv.module` later
|
||||
// since `moduleAndSpirv.module` may be in use by multiple threads.
|
||||
SetDebugName(ToBackend(GetDevice()), newHandle, "Dawn_ShaderModule", GetLabel());
|
||||
|
|
Loading…
Reference in New Issue