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:
parent
007b976e6f
commit
76ce8c3007
|
@ -192,8 +192,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BindGroupLayout::SetLabelImpl() {
|
void BindGroupLayout::SetLabelImpl() {
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT,
|
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_BindGroupLayout", GetLabel());
|
||||||
reinterpret_cast<uint64_t&>(mHandle), "Dawn_BindGroupLayout", GetLabel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan
|
} // namespace dawn::native::vulkan
|
||||||
|
|
|
@ -157,8 +157,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BindGroup::SetLabelImpl() {
|
void BindGroup::SetLabelImpl() {
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_DESCRIPTOR_SET,
|
SetDebugName(ToBackend(GetDevice()), mDescriptorSetAllocation.set, "Dawn_BindGroup",
|
||||||
reinterpret_cast<uint64_t&>(mDescriptorSetAllocation.set), "Dawn_BindGroup",
|
|
||||||
GetLabel());
|
GetLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -381,8 +381,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::SetLabelImpl() {
|
void Buffer::SetLabelImpl() {
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_BUFFER,
|
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_Buffer", GetLabel());
|
||||||
reinterpret_cast<uint64_t&>(mHandle), "Dawn_Buffer", GetLabel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::InitializeToZero(CommandRecordingContext* recordingContext) {
|
void Buffer::InitializeToZero(CommandRecordingContext* recordingContext) {
|
||||||
|
|
|
@ -93,8 +93,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputePipeline::SetLabelImpl() {
|
void ComputePipeline::SetLabelImpl() {
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_PIPELINE,
|
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_ComputePipeline", GetLabel());
|
||||||
reinterpret_cast<uint64_t&>(mHandle), "Dawn_ComputePipeline", GetLabel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputePipeline::~ComputePipeline() = default;
|
ComputePipeline::~ComputePipeline() = default;
|
||||||
|
|
|
@ -1053,11 +1053,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::SetLabelImpl() {
|
void Device::SetLabelImpl() {
|
||||||
// VKDevice reinterpret_casts to a uint64_t rather than a uint64_t& like most other types
|
SetDebugName(this, VK_OBJECT_TYPE_DEVICE, mVkDevice, "Dawn_Device", GetLabel());
|
||||||
// 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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan
|
} // namespace dawn::native::vulkan
|
||||||
|
|
|
@ -83,8 +83,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLayout::SetLabelImpl() {
|
void PipelineLayout::SetLabelImpl() {
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_PIPELINE_LAYOUT,
|
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_PipelineLayout", GetLabel());
|
||||||
reinterpret_cast<uint64_t&>(mHandle), "Dawn_PipelineLayout", GetLabel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan
|
} // namespace dawn::native::vulkan
|
||||||
|
|
|
@ -110,8 +110,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuerySet::SetLabelImpl() {
|
void QuerySet::SetLabelImpl() {
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_QUERY_POOL,
|
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_QuerySet", GetLabel());
|
||||||
reinterpret_cast<uint64_t&>(mHandle), "Dawn_QuerySet", GetLabel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan
|
} // namespace dawn::native::vulkan
|
||||||
|
|
|
@ -66,14 +66,9 @@ namespace dawn::native::vulkan {
|
||||||
|
|
||||||
void Queue::SetLabelImpl() {
|
void Queue::SetLabelImpl() {
|
||||||
Device* device = ToBackend(GetDevice());
|
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
|
// 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.
|
// so it doesn't always change the default queue's label.
|
||||||
SetDebugName(device, VK_OBJECT_TYPE_QUEUE, reinterpret_cast<uint64_t>(device->GetQueue()),
|
SetDebugName(device, VK_OBJECT_TYPE_QUEUE, device->GetQueue(), "Dawn_Queue", GetLabel());
|
||||||
"Dawn_Queue", GetLabel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan
|
} // namespace dawn::native::vulkan
|
||||||
|
|
|
@ -574,8 +574,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderPipeline::SetLabelImpl() {
|
void RenderPipeline::SetLabelImpl() {
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_PIPELINE,
|
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_RenderPipeline", GetLabel());
|
||||||
reinterpret_cast<uint64_t&>(mHandle), "Dawn_RenderPipeline", GetLabel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPipelineVertexInputStateCreateInfo RenderPipeline::ComputeVertexInputDesc(
|
VkPipelineVertexInputStateCreateInfo RenderPipeline::ComputeVertexInputDesc(
|
||||||
|
|
|
@ -124,8 +124,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sampler::SetLabelImpl() {
|
void Sampler::SetLabelImpl() {
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_SAMPLER,
|
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_Sampler", GetLabel());
|
||||||
reinterpret_cast<uint64_t&>(mHandle), "Dawn_Sampler", GetLabel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan
|
} // namespace dawn::native::vulkan
|
||||||
|
|
|
@ -245,9 +245,7 @@ namespace dawn::native::vulkan {
|
||||||
mTransformedShaderModuleCache->AddOrGet(cacheKey, newHandle, std::move(spirv));
|
mTransformedShaderModuleCache->AddOrGet(cacheKey, newHandle, std::move(spirv));
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_SHADER_MODULE,
|
SetDebugName(ToBackend(GetDevice()), moduleAndSpirv.first, "Dawn_ShaderModule", GetLabel());
|
||||||
reinterpret_cast<uint64_t&>(moduleAndSpirv.first), "Dawn_ShaderModule",
|
|
||||||
GetLabel());
|
|
||||||
|
|
||||||
return std::move(moduleAndSpirv);
|
return std::move(moduleAndSpirv);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -58,8 +58,7 @@ namespace dawn::native::vulkan {
|
||||||
return DAWN_INTERNAL_ERROR("Unable to map staging buffer.");
|
return DAWN_INTERNAL_ERROR("Unable to map staging buffer.");
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDebugName(mDevice, VK_OBJECT_TYPE_BUFFER, reinterpret_cast<uint64_t&>(mBuffer),
|
SetDebugName(mDevice, mBuffer, "Dawn_StagingBuffer");
|
||||||
"Dawn_StagingBuffer");
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -889,8 +889,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::SetLabelHelper(const char* prefix) {
|
void Texture::SetLabelHelper(const char* prefix) {
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_IMAGE,
|
SetDebugName(ToBackend(GetDevice()), mHandle, prefix, GetLabel());
|
||||||
reinterpret_cast<uint64_t&>(mHandle), prefix, GetLabel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::SetLabelImpl() {
|
void Texture::SetLabelImpl() {
|
||||||
|
@ -1423,8 +1422,7 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureView::SetLabelImpl() {
|
void TextureView::SetLabelImpl() {
|
||||||
SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_IMAGE_VIEW,
|
SetDebugName(ToBackend(GetDevice()), mHandle, "Dawn_TextureView", GetLabel());
|
||||||
reinterpret_cast<uint64_t&>(mHandle), "Dawn_InternalTextureView", GetLabel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan
|
} // namespace dawn::native::vulkan
|
||||||
|
|
|
@ -26,6 +26,25 @@
|
||||||
|
|
||||||
namespace dawn::native::vulkan {
|
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) {
|
VkCompareOp ToVulkanCompareOp(wgpu::CompareFunction op) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case wgpu::CompareFunction::Never:
|
case wgpu::CompareFunction::Never:
|
||||||
|
@ -182,11 +201,11 @@ namespace dawn::native::vulkan {
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDebugName(Device* device,
|
void SetDebugNameInternal(Device* device,
|
||||||
VkObjectType objectType,
|
VkObjectType objectType,
|
||||||
uint64_t objectHandle,
|
uint64_t objectHandle,
|
||||||
const char* prefix,
|
const char* prefix,
|
||||||
std::string label) {
|
std::string label) {
|
||||||
if (!objectHandle) {
|
if (!objectHandle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,11 +103,41 @@ namespace dawn::native::vulkan {
|
||||||
const TextureCopy& textureCopy,
|
const TextureCopy& textureCopy,
|
||||||
const Extent3D& copySize);
|
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,
|
void SetDebugName(Device* device,
|
||||||
VkObjectType objectType,
|
VkObjectType objectType,
|
||||||
uint64_t objectHandle,
|
HandleType objectHandle,
|
||||||
const char* prefix,
|
const char* prefix,
|
||||||
std::string label = "");
|
std::string label = "") {
|
||||||
|
SetDebugNameInternal(device, objectType, reinterpret_cast<uint64_t>(objectHandle), prefix,
|
||||||
|
label);
|
||||||
|
}
|
||||||
|
|
||||||
// Returns nullptr or &specializationInfo
|
// Returns nullptr or &specializationInfo
|
||||||
// specializationInfo, specializationDataEntries, specializationMapEntries needs to
|
// specializationInfo, specializationDataEntries, specializationMapEntries needs to
|
||||||
|
|
Loading…
Reference in New Issue