Refactored how debug labels are set with Vulkan

Use templated functions to make calling SetDebugLabel safer, with
less opportunities to screw up the casting and automatic lookup
of the VkObjectType for most handles.

Change-Id: I0938ad6fd7d5fe81569bdee5bc7ec7e396db7bcd
Bug: dawn:1323
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86580
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Brandon Jones <bajones@google.com>
This commit is contained in:
Brandon Jones 2022-04-13 14:00:16 +00:00 committed by Dawn LUCI CQ
parent 007b976e6f
commit 76ce8c3007
15 changed files with 70 additions and 43 deletions

View File

@ -192,8 +192,7 @@ namespace dawn::native::vulkan {
}
void BindGroupLayout::SetLabelImpl() {
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT,
reinterpret_cast<uint64_t&>(mHandle), "Dawn_BindGroupLayout", GetLabel());
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_BindGroupLayout", GetLabel());
}
} // namespace dawn::native::vulkan

View File

@ -157,8 +157,7 @@ namespace dawn::native::vulkan {
}
void BindGroup::SetLabelImpl() {
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_DESCRIPTOR_SET,
reinterpret_cast<uint64_t&>(mDescriptorSetAllocation.set), "Dawn_BindGroup",
SetDebugName(ToBackend(GetDevice()), mDescriptorSetAllocation.set, "Dawn_BindGroup",
GetLabel());
}

View File

@ -381,8 +381,7 @@ namespace dawn::native::vulkan {
}
void Buffer::SetLabelImpl() {
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_BUFFER,
reinterpret_cast<uint64_t&>(mHandle), "Dawn_Buffer", GetLabel());
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_Buffer", GetLabel());
}
void Buffer::InitializeToZero(CommandRecordingContext* recordingContext) {

View File

@ -93,8 +93,7 @@ namespace dawn::native::vulkan {
}
void ComputePipeline::SetLabelImpl() {
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_PIPELINE,
reinterpret_cast<uint64_t&>(mHandle), "Dawn_ComputePipeline", GetLabel());
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_ComputePipeline", GetLabel());
}
ComputePipeline::~ComputePipeline() = default;

View File

@ -1053,11 +1053,7 @@ namespace dawn::native::vulkan {
}
void Device::SetLabelImpl() {
// VKDevice reinterpret_casts to a uint64_t rather than a uint64_t& like most other types
// because it's a dispatchable handle, and thus doesn't have the VkHandle wrapper that
// Dawn creates for anything defined with VK_DEFINE_NON_DISPATCHABLE_HANDLE.
SetDebugName(this, VK_OBJECT_TYPE_DEVICE, reinterpret_cast<uint64_t>(mVkDevice),
"Dawn_Device", GetLabel());
SetDebugName(this, VK_OBJECT_TYPE_DEVICE, mVkDevice, "Dawn_Device", GetLabel());
}
} // namespace dawn::native::vulkan

View File

@ -83,8 +83,7 @@ namespace dawn::native::vulkan {
}
void PipelineLayout::SetLabelImpl() {
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_PIPELINE_LAYOUT,
reinterpret_cast<uint64_t&>(mHandle), "Dawn_PipelineLayout", GetLabel());
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_PipelineLayout", GetLabel());
}
} // namespace dawn::native::vulkan

View File

@ -110,8 +110,7 @@ namespace dawn::native::vulkan {
}
void QuerySet::SetLabelImpl() {
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_QUERY_POOL,
reinterpret_cast<uint64_t&>(mHandle), "Dawn_QuerySet", GetLabel());
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_QuerySet", GetLabel());
}
} // namespace dawn::native::vulkan

View File

@ -66,14 +66,9 @@ namespace dawn::native::vulkan {
void Queue::SetLabelImpl() {
Device* device = ToBackend(GetDevice());
// VKDevice reinterpret_casts to a uint64_t rather than a uint64_t& like most other types
// because it's a dispatchable handle, and thus doesn't have the VkHandle wrapper that
// Dawn creates for anything defined with VK_DEFINE_NON_DISPATCHABLE_HANDLE.
// TODO(crbug.com/dawn/1344): When we start using multiple queues this needs to be adjusted
// so it doesn't always change the default queue's label.
SetDebugName(device, VK_OBJECT_TYPE_QUEUE, reinterpret_cast<uint64_t>(device->GetQueue()),
"Dawn_Queue", GetLabel());
SetDebugName(device, VK_OBJECT_TYPE_QUEUE, device->GetQueue(), "Dawn_Queue", GetLabel());
}
} // namespace dawn::native::vulkan

View File

@ -574,8 +574,7 @@ namespace dawn::native::vulkan {
}
void RenderPipeline::SetLabelImpl() {
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_PIPELINE,
reinterpret_cast<uint64_t&>(mHandle), "Dawn_RenderPipeline", GetLabel());
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_RenderPipeline", GetLabel());
}
VkPipelineVertexInputStateCreateInfo RenderPipeline::ComputeVertexInputDesc(

View File

@ -124,8 +124,7 @@ namespace dawn::native::vulkan {
}
void Sampler::SetLabelImpl() {
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_SAMPLER,
reinterpret_cast<uint64_t&>(mHandle), "Dawn_Sampler", GetLabel());
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_Sampler", GetLabel());
}
} // namespace dawn::native::vulkan

View File

@ -245,9 +245,7 @@ namespace dawn::native::vulkan {
mTransformedShaderModuleCache->AddOrGet(cacheKey, newHandle, std::move(spirv));
}
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_SHADER_MODULE,
reinterpret_cast<uint64_t&>(moduleAndSpirv.first), "Dawn_ShaderModule",
GetLabel());
SetDebugName(ToBackend(GetDevice()), moduleAndSpirv.first, "Dawn_ShaderModule", GetLabel());
return std::move(moduleAndSpirv);
#else

View File

@ -58,8 +58,7 @@ namespace dawn::native::vulkan {
return DAWN_INTERNAL_ERROR("Unable to map staging buffer.");
}
SetDebugName(mDevice, VK_OBJECT_TYPE_BUFFER, reinterpret_cast<uint64_t&>(mBuffer),
"Dawn_StagingBuffer");
SetDebugName(mDevice, mBuffer, "Dawn_StagingBuffer");
return {};
}

View File

@ -889,8 +889,7 @@ namespace dawn::native::vulkan {
}
void Texture::SetLabelHelper(const char* prefix) {
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_IMAGE,
reinterpret_cast<uint64_t&>(mHandle), prefix, GetLabel());
SetDebugName(ToBackend(GetDevice()), mHandle, prefix, GetLabel());
}
void Texture::SetLabelImpl() {
@ -1423,8 +1422,7 @@ namespace dawn::native::vulkan {
}
void TextureView::SetLabelImpl() {
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_IMAGE_VIEW,
reinterpret_cast<uint64_t&>(mHandle), "Dawn_InternalTextureView", GetLabel());
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_TextureView", GetLabel());
}
} // namespace dawn::native::vulkan

View File

@ -26,6 +26,25 @@
namespace dawn::native::vulkan {
#define VK_OBJECT_TYPE_GETTER(object, objectType) \
template <> \
VkObjectType GetVkObjectType<object>(object handle) { \
return objectType; \
}
VK_OBJECT_TYPE_GETTER(VkBuffer, VK_OBJECT_TYPE_BUFFER)
VK_OBJECT_TYPE_GETTER(VkDescriptorSetLayout, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
VK_OBJECT_TYPE_GETTER(VkDescriptorSet, VK_OBJECT_TYPE_DESCRIPTOR_SET)
VK_OBJECT_TYPE_GETTER(VkPipeline, VK_OBJECT_TYPE_PIPELINE)
VK_OBJECT_TYPE_GETTER(VkPipelineLayout, VK_OBJECT_TYPE_PIPELINE_LAYOUT)
VK_OBJECT_TYPE_GETTER(VkQueryPool, VK_OBJECT_TYPE_QUERY_POOL)
VK_OBJECT_TYPE_GETTER(VkSampler, VK_OBJECT_TYPE_SAMPLER)
VK_OBJECT_TYPE_GETTER(VkShaderModule, VK_OBJECT_TYPE_SHADER_MODULE)
VK_OBJECT_TYPE_GETTER(VkImage, VK_OBJECT_TYPE_IMAGE)
VK_OBJECT_TYPE_GETTER(VkImageView, VK_OBJECT_TYPE_IMAGE_VIEW)
#undef VK_OBJECT_TYPE_GETTER
VkCompareOp ToVulkanCompareOp(wgpu::CompareFunction op) {
switch (op) {
case wgpu::CompareFunction::Never:
@ -182,11 +201,11 @@ namespace dawn::native::vulkan {
return region;
}
void SetDebugName(Device* device,
VkObjectType objectType,
uint64_t objectHandle,
const char* prefix,
std::string label) {
void SetDebugNameInternal(Device* device,
VkObjectType objectType,
uint64_t objectHandle,
const char* prefix,
std::string label) {
if (!objectHandle) {
return;
}

View File

@ -103,11 +103,41 @@ namespace dawn::native::vulkan {
const TextureCopy& textureCopy,
const Extent3D& copySize);
// Gets the associated VkObjectType for any non-dispatchable handle
template <class HandleType>
VkObjectType GetVkObjectType(HandleType handle);
void SetDebugNameInternal(Device* device,
VkObjectType objectType,
uint64_t objectHandle,
const char* prefix,
std::string label);
// The majority of Vulkan handles are "non-dispatchable". Dawn wraps these by overriding
// VK_DEFINE_NON_DISPATCHABLE_HANDLE to add some capabilities like making null comparisons
// easier. In those cases we can make setting the debug name a bit easier by getting the
// object type automatically and handling the indirection to the native handle.
template <typename Tag, typename HandleType>
void SetDebugName(Device* device,
detail::VkHandle<Tag, HandleType> objectHandle,
const char* prefix,
std::string label = "") {
SetDebugNameInternal(device, GetVkObjectType(objectHandle),
reinterpret_cast<uint64_t>(objectHandle.GetHandle()), prefix, label);
}
// Handles like VkQueue and VKDevice require a special path because they are dispatchable, so
// they require an explicit VkObjectType and cast to a uint64_t directly rather than by getting
// the non-dispatchable wrapper's underlying handle.
template <typename HandleType>
void SetDebugName(Device* device,
VkObjectType objectType,
uint64_t objectHandle,
HandleType objectHandle,
const char* prefix,
std::string label = "");
std::string label = "") {
SetDebugNameInternal(device, objectType, reinterpret_cast<uint64_t>(objectHandle), prefix,
label);
}
// Returns nullptr or &specializationInfo
// specializationInfo, specializationDataEntries, specializationMapEntries needs to