Caching empty bind group layouts
Added Device::GetOrCreateEmptyBindGroupLayout which caches the result
after being run and modified PipelineBase::getBindGroupLayout to use
that instead of creating a new empty bind group layout each time.
Bug: dawn:466
Change-Id: I70a5719265784eb8f60c2eedf6db7596462b21bd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/23980
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Tomek Ponitka <tommek@google.com>
diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp
index 1c30cd5..b0ef00d 100644
--- a/src/dawn_native/Device.cpp
+++ b/src/dawn_native/Device.cpp
@@ -169,6 +169,8 @@
mDynamicUploader = nullptr;
mMapRequestTracker = nullptr;
+ mEmptyBindGroupLayout = nullptr;
+
AssumeCommandsComplete();
// Tell the backend that it can free all the objects now that the GPU timeline is empty.
ShutDownImpl();
@@ -411,6 +413,24 @@
ASSERT(removedCount == 1);
}
+ ResultOrError<BindGroupLayoutBase*> DeviceBase::GetOrCreateEmptyBindGroupLayout() {
+ if (!mEmptyBindGroupLayout) {
+ BindGroupLayoutDescriptor desc = {};
+ desc.entryCount = 0;
+ desc.entries = nullptr;
+
+ BindGroupLayoutBase* bgl = nullptr;
+ if (ConsumedError(GetOrCreateBindGroupLayout(&desc), &bgl)) {
+ return BindGroupLayoutBase::MakeError(this);
+ }
+ mEmptyBindGroupLayout = bgl;
+ return bgl;
+ } else {
+ mEmptyBindGroupLayout->Reference();
+ return mEmptyBindGroupLayout.Get();
+ }
+ }
+
ResultOrError<ComputePipelineBase*> DeviceBase::GetOrCreateComputePipeline(
const ComputePipelineDescriptor* descriptor) {
ComputePipelineBase blueprint(this, descriptor);