[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 if validation is enabled. This is necessary as at least
on Vulkan Dawn's debugging facilities assume that these labels are
set [1]. It is consistent in any case, as a client enabling validation
indicates that they are more concerned about debuggability than
performance.
[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/dawn/src/dawn/native/vulkan/BackendVk.cpp;l=263?q=BackendVk.cpp&ss=chromium
Change-Id: I46fd862382f89e61588535c16daeba976d45825e
Bug: dawn:2383
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/172861
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 c846ed6..ffed27f 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 85fbc5e..3910bd3 100644
--- a/src/dawn/native/Toggles.cpp
+++ b/src/dawn/native/Toggles.cpp
@@ -224,7 +224,9 @@
"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 true if validation is enabled and false otherwise.",
"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..c853e33 100644
--- a/src/dawn/native/vulkan/UtilsVulkan.cpp
+++ b/src/dawn/native/vulkan/UtilsVulkan.cpp
@@ -227,6 +227,10 @@
uint64_t objectHandle,
const char* prefix,
std::string label) {
+ if (!device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) {
+ return;
+ }
+
if (!objectHandle) {
return;
}
@@ -242,7 +246,7 @@
// 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;
- if (!label.empty() && device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) {
+ if (!label.empty()) {
objectNameStream << "_" << label;
}
std::string objectName = objectNameStream.str();