Update Vulkan's shader module destruction to remove cache for cleanup.

- Turns internal cache into a pointer so that we can deallocate it earlier for the destroy.

Bug: dawn:628
Change-Id: I69fd1e4be5ed5d8b7a28efebd9c2852bab3224b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/70182
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
Loko Kung 2021-11-24 19:46:17 +00:00 committed by Dawn LUCI CQ
parent 0cee4d9834
commit f008bb3b7e
2 changed files with 15 additions and 4 deletions

View File

@ -77,7 +77,9 @@ namespace dawn_native { namespace vulkan {
}
ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor)
: ShaderModuleBase(device, descriptor), mTransformedShaderModuleCache(device) {
: ShaderModuleBase(device, descriptor),
mTransformedShaderModuleCache(
std::make_unique<ConcurrentTransformedShaderModuleCache>(device)) {
}
MaybeError ShaderModule::Initialize(ShaderModuleParseResult* parseResult) {
@ -97,16 +99,24 @@ namespace dawn_native { namespace vulkan {
return InitializeBase(parseResult);
}
void ShaderModule::DestroyImpl() {
// Remove reference to internal cache to trigger cleanup.
mTransformedShaderModuleCache = nullptr;
}
ShaderModule::~ShaderModule() = default;
ResultOrError<VkShaderModule> ShaderModule::GetTransformedModuleHandle(
const char* entryPointName,
PipelineLayout* layout) {
// If the shader was destroyed, we should never call this function.
ASSERT(IsAlive());
ScopedTintICEHandler scopedICEHandler(GetDevice());
auto cacheKey = std::make_pair(layout, entryPointName);
VkShaderModule cachedShaderModule =
mTransformedShaderModuleCache.FindShaderModule(cacheKey);
mTransformedShaderModuleCache->FindShaderModule(cacheKey);
if (cachedShaderModule != VK_NULL_HANDLE) {
return cachedShaderModule;
}
@ -180,7 +190,7 @@ namespace dawn_native { namespace vulkan {
"CreateShaderModule"));
if (newHandle != VK_NULL_HANDLE) {
newHandle =
mTransformedShaderModuleCache.AddOrGetCachedShaderModule(cacheKey, newHandle);
mTransformedShaderModuleCache->AddOrGetCachedShaderModule(cacheKey, newHandle);
}
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_SHADER_MODULE,

View File

@ -40,6 +40,7 @@ namespace dawn_native { namespace vulkan {
ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor);
~ShaderModule() override;
MaybeError Initialize(ShaderModuleParseResult* parseResult);
void DestroyImpl() override;
// New handles created by GetTransformedModuleHandle at pipeline creation time
class ConcurrentTransformedShaderModuleCache {
@ -58,7 +59,7 @@ namespace dawn_native { namespace vulkan {
PipelineLayoutEntryPointPairHashFunc>
mTransformedShaderModuleCache;
};
ConcurrentTransformedShaderModuleCache mTransformedShaderModuleCache;
std::unique_ptr<ConcurrentTransformedShaderModuleCache> mTransformedShaderModuleCache;
};
}} // namespace dawn_native::vulkan