Automatically name image/buffer allocations

This commit is contained in:
Patrick Nicolas
2025-08-16 14:15:29 +02:00
parent dc04f7edcc
commit c15de9bf27
10 changed files with 75 additions and 62 deletions
+10 -4
View File
@@ -902,10 +902,16 @@ void application::initialize_vulkan()
pipeline_cache = vk::raii::PipelineCache(vk_device, pipeline_cache_info);
allocator.emplace(VmaAllocatorCreateInfo{
.physicalDevice = *vk_physical_device,
.device = *vk_device,
.instance = *vk_instance,
});
.physicalDevice = *vk_physical_device,
.device = *vk_device,
.instance = *vk_instance,
},
#ifndef NDEBUG
debug_utils_found
#else
false
#endif
);
}
void application::log_views()
+32 -36
View File
@@ -139,46 +139,42 @@ text_rasterizer::text_rasterizer(vk::raii::Device & device, vk::raii::PhysicalDe
image_allocation text_rasterizer::create_image(vk::Extent2D size)
{
image_allocation alloc{device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = text::format,
.extent = {
.width = size.width,
.height = size.height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 1,
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst,
.sharingMode = vk::SharingMode::eExclusive,
.initialLayout = vk::ImageLayout::eUndefined,
},
VmaAllocationCreateInfo{
.flags = 0,
.usage = VMA_MEMORY_USAGE_AUTO,
}};
application::set_debug_reports_name<vk::Image>(alloc, "text_rasterizer image");
return alloc;
return {device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = text::format,
.extent = {
.width = size.width,
.height = size.height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 1,
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst,
.sharingMode = vk::SharingMode::eExclusive,
.initialLayout = vk::ImageLayout::eUndefined,
},
VmaAllocationCreateInfo{
.flags = 0,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"text_rasterizer image"};
}
buffer_allocation text_rasterizer::create_buffer(size_t size)
{
buffer_allocation alloc{device,
vk::BufferCreateInfo{
.size = size,
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
}};
application::set_debug_reports_name<vk::Buffer>(alloc, "text_rasterizer buffer");
return alloc;
return {device,
vk::BufferCreateInfo{
.size = size,
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"text_rasterizer buffer"};
}
text_rasterizer::~text_rasterizer()
+6
View File
@@ -131,6 +131,12 @@ public:
std::tie(resource, allocation) = traits::create(device, create_info, alloc_info);
vmaSetAllocationName(vk_allocator::instance(), allocation, name.c_str());
if (vk_allocator::instance().has_debug_utils)
device.setDebugUtilsObjectNameEXT(vk::DebugUtilsObjectNameInfoEXT{
.objectType = T::objectType,
.objectHandle = uint64_t(CType(*resource)),
.pObjectName = name.c_str(),
});
}
basic_allocation(const basic_allocation &) = delete;
+2 -1
View File
@@ -20,7 +20,8 @@
#include "vk_allocator.h"
#include "vk/check.h"
vk_allocator::vk_allocator(const VmaAllocatorCreateInfo & info)
vk_allocator::vk_allocator(const VmaAllocatorCreateInfo & info, bool has_debug_utils) :
has_debug_utils(has_debug_utils)
{
CHECK_VK(vmaCreateAllocator(&info, &handle));
}
+2 -1
View File
@@ -27,7 +27,8 @@ class vk_allocator : public singleton<vk_allocator>
VmaAllocator handle = nullptr;
public:
vk_allocator(const VmaAllocatorCreateInfo &);
const bool has_debug_utils;
vk_allocator(const VmaAllocatorCreateInfo &, bool has_debug_utils);
~vk_allocator();
operator VmaAllocator()
+5 -2
View File
@@ -232,9 +232,12 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
for (uint32_t i = 0; i < cn->image_count; i++)
{
auto & image = cn->psc.images[i].image;
image = image_allocation(device, image_info.get(), {.usage = VMA_MEMORY_USAGE_AUTO});
image = image_allocation(
device,
image_info.get(),
{.usage = VMA_MEMORY_USAGE_AUTO},
std::format("comp target image {}", i));
cn->images[i].handle = image;
cn->wivrn_bundle->name(vk::Image(image), "comp target image");
}
for (uint32_t i = 0; i < cn->image_count; i++)
-1
View File
@@ -335,7 +335,6 @@ wivrn_foveation::wivrn_foveation(wivrn_vk_bundle & bundle, const xrt_hmd_parts &
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
},
"foveation staging buffer");
bundle.name(vk::Buffer(host_buffer), "foveation staging buffer");
}
bundle.name(command_pool, "foveation command pool");
bundle.name(cmd, "foveation command buffer");
+8 -8
View File
@@ -176,8 +176,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
img_create_info,
{
.usage = VMA_MEMORY_USAGE_AUTO,
});
vk.name(vk::Image(dpb_image), "vulkan encoder DPB image");
},
"vulkan encoder DPB image");
}
// Output buffer
@@ -195,8 +195,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
});
vk.name(vk::Buffer(item.output_buffer), "vulkan encode output buffer");
},
"vulkan encode output buffer");
if (not(item.output_buffer.properties() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
{
@@ -208,8 +208,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
});
vk.name(vk::Buffer(item.host_buffer), "vulkan encode host buffer");
},
"vulkan encode host buffer");
}
}
@@ -292,8 +292,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
},
{
.usage = VMA_MEMORY_USAGE_AUTO,
});
vk.name(vk::Image(slot_data[i].tmp_image), "vulkan encoder temporary image");
},
"vulkan encoder temporary image");
image_view_template.image = vk::Image(slot_data[i].tmp_image);
slot_data[i].view = vk.device.createImageView(image_view_template);
vk.name(slot_data[i].view, "vulkan encoder temporary image view");
+4 -4
View File
@@ -168,7 +168,8 @@ video_encoder_x264::video_encoder_x264(
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
});
},
"x264 luma buffer");
i.chroma = buffer_allocation(
vk.device, {
.size = vk::DeviceSize(settings.video_width * settings.video_height / 2),
@@ -177,9 +178,8 @@ video_encoder_x264::video_encoder_x264(
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
});
vk.name(vk::Buffer(i.luma), "x264 luma buffer");
vk.name(vk::Buffer(i.chroma), "x264 chroma buffer");
},
"x264 chroma buffer");
auto & pic = i.pic;
x264_picture_init(&pic);
+6 -5
View File
@@ -83,11 +83,12 @@ wivrn::wivrn_vk_bundle::wivrn_vk_bundle(vk_bundle & vk, std::span<const char *>
physical_device(instance, vk.physical_device),
device(physical_device, vk.device),
allocator({
.physicalDevice = vk.physical_device,
.device = vk.device,
.instance = vk.instance,
.vulkanApiVersion = VK_MAKE_VERSION(1, 3, 0), // FIXME: sync with wivrn_session.cpp
}),
.physicalDevice = vk.physical_device,
.device = vk.device,
.instance = vk.instance,
.vulkanApiVersion = VK_MAKE_VERSION(1, 3, 0), // FIXME: sync with wivrn_session.cpp
},
vk.has_EXT_debug_utils),
queue(device, vk.queue_family_index, vk.queue_index),
queue_family_index(vk.queue_family_index),
#ifdef VK_KHR_video_encode_queue