Add check for an invalid D3D12/Vk object in SetDebugLabel

Fixes a crash found while fuzzing by returning early when SetDebugName
is called with an empty D3D12/Vulkan object or when the device is lost.
Adds tests.

Bug: chromium:1245720
Change-Id: Ie443f690cf5635d017295a13e21c33dd2e97dc46
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/63363
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Brandon Jones (Intel) <brandon1.jones@intel.com>
This commit is contained in:
Brandon Jones 2021-09-02 21:15:40 +00:00 committed by Dawn LUCI CQ
parent c1bcbbf357
commit 8a0b49b6d6
4 changed files with 32 additions and 0 deletions

View File

@ -373,6 +373,10 @@ namespace dawn_native { namespace d3d12 {
} }
void SetDebugName(Device* device, ID3D12Object* object, const char* prefix, std::string label) { void SetDebugName(Device* device, ID3D12Object* object, const char* prefix, std::string label) {
if (!object) {
return;
}
if (label.empty() || !device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) { if (label.empty() || !device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) {
object->SetPrivateData(WKPDID_D3DDebugObjectName, strlen(prefix), prefix); object->SetPrivateData(WKPDID_D3DDebugObjectName, strlen(prefix), prefix);
return; return;

View File

@ -170,6 +170,10 @@ namespace dawn_native { namespace vulkan {
uint64_t objectHandle, uint64_t objectHandle,
const char* prefix, const char* prefix,
std::string label) { std::string label) {
if (!objectHandle) {
return;
}
if (device->GetGlobalInfo().HasExt(InstanceExt::DebugUtils)) { if (device->GetGlobalInfo().HasExt(InstanceExt::DebugUtils)) {
VkDebugUtilsObjectNameInfoEXT objectNameInfo; VkDebugUtilsObjectNameInfoEXT objectNameInfo;
objectNameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; objectNameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;

View File

@ -152,6 +152,18 @@ TEST_P(DestroyTest, TextureSubmitDestroySubmit) {
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands)); 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, DAWN_INSTANTIATE_TEST(DestroyTest,
D3D12Backend(), D3D12Backend(),
MetalBackend(), MetalBackend(),

View File

@ -506,6 +506,18 @@ TEST_P(DeviceLostTest, FreeBindGroupAfterDeviceLossWithPendingCommands) {
bg = nullptr; 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, DAWN_INSTANTIATE_TEST(DeviceLostTest,
D3D12Backend(), D3D12Backend(),
MetalBackend(), MetalBackend(),