[toggles] Set labels on backend objects only if toggle is set
We have found that in Chrome, setting these labels can be a source of
non-trivial overhead on performance benchmarks. This CL guards setting
of these labels with the `use_user_defined_labels_in_backend` toggle.
Note that labels will still be set on frontend objects, and hence will
still be available in e.g. Dawn error messages. The labels on the
backend objects are relevant only when debugging via platform-specific
facilities (e.g., XCode).
This CL also changes the `use_user_defined_labels_in_backend` toggle to
default to true on Vulkan. These labels are necessary on Vulkan to map
errors back to the devices with which objects generating the errors
are associated. See a detailed description here [1].
[1] https://dawn-review.googlesource.com/c/dawn/+/174740
Bug: dawn:2383
Change-Id: I6fb38e23bc841bd9771d383a41828a6495c8febb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/174780
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Blundell <blundell@chromium.org>
diff --git a/src/dawn/native/Adapter.cpp b/src/dawn/native/Adapter.cpp
index d284148..5b0ba9e 100644
--- a/src/dawn/native/Adapter.cpp
+++ b/src/dawn/native/Adapter.cpp
@@ -211,6 +211,9 @@
// Default toggles for all backend
deviceToggles.Default(Toggle::LazyClearResourceOnFirstUse, true);
deviceToggles.Default(Toggle::TimestampQuantization, true);
+ if (mPhysicalDevice->GetInstance()->IsBackendValidationEnabled()) {
+ deviceToggles.Default(Toggle::UseUserDefinedLabelsInBackend, true);
+ }
// Backend-specific forced and default device toggles
mPhysicalDevice->SetupBackendDeviceToggles(&deviceToggles);
diff --git a/src/dawn/native/Toggles.cpp b/src/dawn/native/Toggles.cpp
index eff62ee..7dbbf6a 100644
--- a/src/dawn/native/Toggles.cpp
+++ b/src/dawn/native/Toggles.cpp
@@ -224,7 +224,12 @@
"https://crbug.com/dawn/1016", ToggleStage::Device}},
{Toggle::UseUserDefinedLabelsInBackend,
{"use_user_defined_labels_in_backend",
- "Enables calls to SetLabel to be forwarded to backend-specific APIs that label objects.",
+ "Enables setting labels on backend-specific APIs that label objects. The labels used will be "
+ "those of the corresponding frontend objects if non-empty and default labels otherwise. "
+ "Defaults to false. NOTE: On Vulkan, backend labels are currently always set (with default "
+ "labels if this toggle is not set). The reason is that Dawn currently uses backend "
+ "object labels on Vulkan to map errors back to the device with which the backend objects "
+ "included in the error are associated.",
"https://crbug.com/dawn/840", ToggleStage::Device}},
{Toggle::UsePlaceholderFragmentInVertexOnlyPipeline,
{"use_placeholder_fragment_in_vertex_only_pipeline",
diff --git a/src/dawn/native/d3d11/UtilsD3D11.cpp b/src/dawn/native/d3d11/UtilsD3D11.cpp
index a453b2d..ba185b7 100644
--- a/src/dawn/native/d3d11/UtilsD3D11.cpp
+++ b/src/dawn/native/d3d11/UtilsD3D11.cpp
@@ -61,11 +61,15 @@
ID3D11DeviceChild* object,
const char* prefix,
std::string label) {
+ if (!device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) {
+ return;
+ }
+
if (!object) {
return;
}
- if (label.empty() || !device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) {
+ if (label.empty()) {
object->SetPrivateData(WKPDID_D3DDebugObjectName, strlen(prefix), prefix);
return;
}
diff --git a/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp b/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp
index 34c0bcc..f17def9 100644
--- a/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp
+++ b/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp
@@ -423,6 +423,11 @@
// WebGPU allows empty scissors without empty viewports.
D3D12_MESSAGE_ID_DRAW_EMPTY_SCISSOR_RECTANGLE,
+ // Backend textures can be reused across different frontend textures,
+ // which can result in changes to the label of the backend texture if
+ // the user has assigned distinct labels to the different frontend textures.
+ D3D12_MESSAGE_ID_SETPRIVATEDATA_CHANGINGPARAMS,
+
//
// Temporary IDs: list of warnings that should be fixed or promoted
//
diff --git a/src/dawn/native/d3d12/UtilsD3D12.cpp b/src/dawn/native/d3d12/UtilsD3D12.cpp
index 5a294f3..ea12054 100644
--- a/src/dawn/native/d3d12/UtilsD3D12.cpp
+++ b/src/dawn/native/d3d12/UtilsD3D12.cpp
@@ -335,11 +335,15 @@
}
void SetDebugName(Device* device, ID3D12Object* object, const char* prefix, std::string label) {
+ if (!device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) {
+ return;
+ }
+
if (!object) {
return;
}
- if (label.empty() || !device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) {
+ if (label.empty()) {
object->SetPrivateData(WKPDID_D3DDebugObjectName, strlen(prefix), prefix);
return;
}
diff --git a/src/dawn/native/metal/UtilsMetal.h b/src/dawn/native/metal/UtilsMetal.h
index 1f06b17..ee41923 100644
--- a/src/dawn/native/metal/UtilsMetal.h
+++ b/src/dawn/native/metal/UtilsMetal.h
@@ -58,6 +58,9 @@
// backend resources.
template <typename T>
void SetDebugName(DeviceBase* device, T* mtlObj, const char* prefix, std::string label = "") {
+ if (!device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) {
+ return;
+ }
if (mtlObj == nullptr) {
return;
}
diff --git a/src/dawn/native/vulkan/UtilsVulkan.cpp b/src/dawn/native/vulkan/UtilsVulkan.cpp
index 4cbf88b..22e59a6 100644
--- a/src/dawn/native/vulkan/UtilsVulkan.cpp
+++ b/src/dawn/native/vulkan/UtilsVulkan.cpp
@@ -242,6 +242,12 @@
// Prefix with the device's message ID so that if this label appears in a validation
// message it can be parsed out and the message can be associated with the right device.
objectNameStream << device->GetDebugPrefix() << kDeviceDebugSeparator << prefix;
+
+ // NOTE: Whereas other platforms set backend labels *only* if the
+ // `UseUserDefinedLabelsInBackend` toggle is enabled, on Vulkan these
+ // labels must always be set as they currently provide the only way to
+ // map Vulkan errors that include backend objects back to the device
+ // with which the backend objects are associated.
if (!label.empty() && device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) {
objectNameStream << "_" << label;
}