diff --git a/src/dawn_native/d3d12/UtilsD3D12.cpp b/src/dawn_native/d3d12/UtilsD3D12.cpp index 98f056bc96..38479eba10 100644 --- a/src/dawn_native/d3d12/UtilsD3D12.cpp +++ b/src/dawn_native/d3d12/UtilsD3D12.cpp @@ -373,6 +373,10 @@ namespace dawn_native { namespace d3d12 { } void SetDebugName(Device* device, ID3D12Object* object, const char* prefix, std::string label) { + if (!object) { + return; + } + if (label.empty() || !device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) { object->SetPrivateData(WKPDID_D3DDebugObjectName, strlen(prefix), prefix); return; diff --git a/src/dawn_native/vulkan/UtilsVulkan.cpp b/src/dawn_native/vulkan/UtilsVulkan.cpp index eb46180c4d..fd7a4ae8df 100644 --- a/src/dawn_native/vulkan/UtilsVulkan.cpp +++ b/src/dawn_native/vulkan/UtilsVulkan.cpp @@ -170,6 +170,10 @@ namespace dawn_native { namespace vulkan { uint64_t objectHandle, const char* prefix, std::string label) { + if (!objectHandle) { + return; + } + if (device->GetGlobalInfo().HasExt(InstanceExt::DebugUtils)) { VkDebugUtilsObjectNameInfoEXT objectNameInfo; objectNameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; diff --git a/src/tests/end2end/DestroyTests.cpp b/src/tests/end2end/DestroyTests.cpp index 19ef4b5925..b6889766cf 100644 --- a/src/tests/end2end/DestroyTests.cpp +++ b/src/tests/end2end/DestroyTests.cpp @@ -152,6 +152,18 @@ TEST_P(DestroyTest, TextureSubmitDestroySubmit) { ASSERT_DEVICE_ERROR(queue.Submit(1, &commands)); } +// Attempting to set an object label after it has been destroyed should not cause an error. +TEST_P(DestroyTest, DestroyThenSetLabel) { + DAWN_TEST_UNSUPPORTED_IF(UsesWire()); + std::string label = "test"; + wgpu::BufferDescriptor descriptor; + descriptor.size = 4; + descriptor.usage = wgpu::BufferUsage::Uniform; + wgpu::Buffer buffer = device.CreateBuffer(&descriptor); + buffer.Destroy(); + buffer.SetLabel(label.c_str()); +} + DAWN_INSTANTIATE_TEST(DestroyTest, D3D12Backend(), MetalBackend(), diff --git a/src/tests/end2end/DeviceLostTests.cpp b/src/tests/end2end/DeviceLostTests.cpp index d0f092fbd7..3866a0747e 100644 --- a/src/tests/end2end/DeviceLostTests.cpp +++ b/src/tests/end2end/DeviceLostTests.cpp @@ -506,6 +506,18 @@ TEST_P(DeviceLostTest, FreeBindGroupAfterDeviceLossWithPendingCommands) { bg = nullptr; } +// Attempting to set an object label after device loss should not cause an error. +TEST_P(DeviceLostTest, SetLabelAfterDeviceLoss) { + DAWN_TEST_UNSUPPORTED_IF(UsesWire()); + std::string label = "test"; + wgpu::BufferDescriptor descriptor; + descriptor.size = 4; + descriptor.usage = wgpu::BufferUsage::Uniform; + wgpu::Buffer buffer = device.CreateBuffer(&descriptor); + LoseForTesting(); + buffer.SetLabel(label.c_str()); +} + DAWN_INSTANTIATE_TEST(DeviceLostTest, D3D12Backend(), MetalBackend(),