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:
parent
0cee4d9834
commit
f008bb3b7e
|
@ -77,7 +77,9 @@ namespace dawn_native { namespace vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor)
|
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) {
|
MaybeError ShaderModule::Initialize(ShaderModuleParseResult* parseResult) {
|
||||||
|
@ -97,16 +99,24 @@ namespace dawn_native { namespace vulkan {
|
||||||
return InitializeBase(parseResult);
|
return InitializeBase(parseResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShaderModule::DestroyImpl() {
|
||||||
|
// Remove reference to internal cache to trigger cleanup.
|
||||||
|
mTransformedShaderModuleCache = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
ShaderModule::~ShaderModule() = default;
|
ShaderModule::~ShaderModule() = default;
|
||||||
|
|
||||||
ResultOrError<VkShaderModule> ShaderModule::GetTransformedModuleHandle(
|
ResultOrError<VkShaderModule> ShaderModule::GetTransformedModuleHandle(
|
||||||
const char* entryPointName,
|
const char* entryPointName,
|
||||||
PipelineLayout* layout) {
|
PipelineLayout* layout) {
|
||||||
|
// If the shader was destroyed, we should never call this function.
|
||||||
|
ASSERT(IsAlive());
|
||||||
|
|
||||||
ScopedTintICEHandler scopedICEHandler(GetDevice());
|
ScopedTintICEHandler scopedICEHandler(GetDevice());
|
||||||
|
|
||||||
auto cacheKey = std::make_pair(layout, entryPointName);
|
auto cacheKey = std::make_pair(layout, entryPointName);
|
||||||
VkShaderModule cachedShaderModule =
|
VkShaderModule cachedShaderModule =
|
||||||
mTransformedShaderModuleCache.FindShaderModule(cacheKey);
|
mTransformedShaderModuleCache->FindShaderModule(cacheKey);
|
||||||
if (cachedShaderModule != VK_NULL_HANDLE) {
|
if (cachedShaderModule != VK_NULL_HANDLE) {
|
||||||
return cachedShaderModule;
|
return cachedShaderModule;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +190,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
"CreateShaderModule"));
|
"CreateShaderModule"));
|
||||||
if (newHandle != VK_NULL_HANDLE) {
|
if (newHandle != VK_NULL_HANDLE) {
|
||||||
newHandle =
|
newHandle =
|
||||||
mTransformedShaderModuleCache.AddOrGetCachedShaderModule(cacheKey, newHandle);
|
mTransformedShaderModuleCache->AddOrGetCachedShaderModule(cacheKey, newHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_SHADER_MODULE,
|
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_SHADER_MODULE,
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor);
|
ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor);
|
||||||
~ShaderModule() override;
|
~ShaderModule() override;
|
||||||
MaybeError Initialize(ShaderModuleParseResult* parseResult);
|
MaybeError Initialize(ShaderModuleParseResult* parseResult);
|
||||||
|
void DestroyImpl() override;
|
||||||
|
|
||||||
// New handles created by GetTransformedModuleHandle at pipeline creation time
|
// New handles created by GetTransformedModuleHandle at pipeline creation time
|
||||||
class ConcurrentTransformedShaderModuleCache {
|
class ConcurrentTransformedShaderModuleCache {
|
||||||
|
@ -58,7 +59,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
PipelineLayoutEntryPointPairHashFunc>
|
PipelineLayoutEntryPointPairHashFunc>
|
||||||
mTransformedShaderModuleCache;
|
mTransformedShaderModuleCache;
|
||||||
};
|
};
|
||||||
ConcurrentTransformedShaderModuleCache mTransformedShaderModuleCache;
|
std::unique_ptr<ConcurrentTransformedShaderModuleCache> mTransformedShaderModuleCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
}} // namespace dawn_native::vulkan
|
}} // namespace dawn_native::vulkan
|
||||||
|
|
Loading…
Reference in New Issue