Skip to content

Commit

Permalink
vk: Determine object type enum when setting object name
Browse files Browse the repository at this point in the history
Uses compile-time type-information provided by vulkan-hpp to automatically determine a vulkan-object's `objectType` when calling `setObjectName`.
  • Loading branch information
Wunkolo authored and flyinghead committed Oct 8, 2024
1 parent 86657c0 commit ff6a311
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/rend/vulkan/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void VulkanOverlay::Prepare(vk::CommandBuffer cmdBuffer, bool vmu, bool crosshai
texture->deferDeleteResource(VulkanContext::Instance());
texture = createTexture(cmdBuffer, 48, 32, (u8*)vmu_lcd_data[i]);
#ifdef VK_DEBUG
VulkanContext::Instance()->setObjectName((VkImageView)texture->GetImageView(), vk::ImageView::objectType, "VMU " + std::to_string(i));
VulkanContext::Instance()->setObjectName(texture->GetImageView(), "VMU " + std::to_string(i));
#endif
this->vmuLastChanged[i] = ::vmuLastChanged[i];
}
Expand Down
10 changes: 5 additions & 5 deletions core/rend/vulkan/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ void Texture::CreateImage(vk::ImageTiling tiling, vk::ImageUsageFlags usage, vk:
#ifdef VK_DEBUG
char name[128];
sprintf(name, "texture @ %x", startAddress);
VulkanContext::Instance()->setObjectName((VkImage)image.get(), vk::Image::objectType, name);
VulkanContext::Instance()->setObjectName((VkImageView)imageView.get(), vk::ImageView::objectType, name);
VulkanContext::Instance()->setObjectName(image.get(), name);
VulkanContext::Instance()->setObjectName(imageView.get(), name);
#endif
}

Expand Down Expand Up @@ -444,7 +444,7 @@ void FramebufferAttachment::Init(u32 width, u32 height, vk::Format format, const
image = device.createImageUnique(imageCreateInfo);
#ifdef VK_DEBUG
if (!name.empty())
VulkanContext::Instance()->setObjectName((VkImage)image.get(), vk::Image::objectType, name);
VulkanContext::Instance()->setObjectName(image.get(), name);
#endif

VmaAllocationCreateInfo allocCreateInfo = { VmaAllocationCreateFlags(), VmaMemoryUsage::VMA_MEMORY_USAGE_GPU_ONLY };
Expand All @@ -459,7 +459,7 @@ void FramebufferAttachment::Init(u32 width, u32 height, vk::Format format, const
imageView = device.createImageViewUnique(imageViewCreateInfo);
#ifdef VK_DEBUG
if (!name.empty())
VulkanContext::Instance()->setObjectName((VkImageView)imageView.get(), vk::ImageView::objectType, name);
VulkanContext::Instance()->setObjectName(imageView.get(), name);
#endif

if ((usage & vk::ImageUsageFlagBits::eDepthStencilAttachment) && (usage & vk::ImageUsageFlagBits::eInputAttachment))
Expand All @@ -469,7 +469,7 @@ void FramebufferAttachment::Init(u32 width, u32 height, vk::Format format, const
stencilView = device.createImageViewUnique(imageViewCreateInfo);
#ifdef VK_DEBUG
if (!name.empty())
VulkanContext::Instance()->setObjectName((VkImageView)stencilView.get(), vk::ImageView::objectType, name);
VulkanContext::Instance()->setObjectName(stencilView.get(), name);
#endif
}
}
Expand Down
5 changes: 4 additions & 1 deletion core/rend/vulkan/vk_context_lr.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ class VulkanContext : public GraphicsContext, public FlightManager
commandPool.addToFlight(object);
}
#ifdef VK_DEBUG
void setObjectName(VkHandle object, vk::ObjectType objectType, const std::string& name) {}
template<typename HandleType, typename = std::enable_if_t<vk::isVulkanHandleType<HandleType>::value>>
void setObjectName(const HandleType& object, const std::string& name)
{
}
#endif

constexpr static int VENDOR_AMD = 0x1022;
Expand Down
7 changes: 4 additions & 3 deletions core/rend/vulkan/vulkan_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ class VulkanContext : public GraphicsContext, public FlightManager
}

#ifdef VK_DEBUG
void setObjectName(VkHandle object, vk::ObjectType objectType, const std::string& name)
template<typename HandleType, typename = std::enable_if_t<vk::isVulkanHandleType<HandleType>::value>>
void setObjectName(const HandleType& object, const std::string& name)
{
vk::DebugUtilsObjectNameInfoEXT nameInfo {};
nameInfo.objectType = objectType;
nameInfo.objectHandle = (uint64_t)object;
nameInfo.objectType = HandleType::objectType;
nameInfo.objectHandle = reinterpret_cast<uint64_t>(static_cast<typename HandleType::NativeType>(object));
nameInfo.pObjectName = name.c_str();
if (device) {
vk::Result e = device->setDebugUtilsObjectNameEXT(&nameInfo);
Expand Down

0 comments on commit ff6a311

Please sign in to comment.