I have been changing some vulkan code to use the vulkan.hpp structures and methods.
Since I like RAIIs, I am using the Unique wrappers, to not have to explicitely handle resource management.
So far I have been able to create 2 versions of each wrapping method I am making, one version creates a non unique object, and another method calls the first and then initializes a unique handle from the first. Example:
vector<vk::UniqueFramebuffer> CreateFramebuffersUnique(vk::SurfaceKHR surface,
vk::PhysicalDevice phys_device, vk::Device device, vk::RenderPass render_pass,
vector<vk::ImageView> image_views)
{
auto framebuffers =
CreateFramebuffers(surface, phys_device, device, render_pass, image_views);
vector<vk::UniqueFramebuffer> u_framebuffers;
for(auto &fb : framebuffers)
u_framebuffers.push_back(vk::UniqueFramebuffer(fb, device));
return u_framebuffers;
}
The above method creates an array of framebuffers and then re-initializes each framebuffer as a unique framebuffer prior of returning it.
I tried doing the same with command buffers:
vector<vk::UniqueCommandBuffer> CreateCommandBuffersUnique(vk::SurfaceKHR &surface,
vk::PhysicalDevice &phys_device, vk::Device &device, vk::RenderPass &render_pass,
vk::Pipeline &graphics_pipeline, vk::CommandPool &command_pool,
vector<vk::Framebuffer> &framebuffers)
{
auto command_buffers = CreateCommandBuffers(surface, phys_device, device, render_pass,
graphics_pipeline, command_pool, framebuffers);
vector<vk::UniqueCommandBuffer> u_command_buffers;
for(auto &cb : command_buffers)
u_command_buffers.push_back(vk::UniqueCommandBuffer(cb, device));
return u_command_buffers;
}
The above technically works, but upon program termination, the validation layers complain about a mistake upon resorce de allocation:
validation layer: vkFreeCommandBuffers: required parameter commandPool specified as VK_NULL_HANDLE
UNASSIGNED-GeneralParameterError-RequiredParameter
4096
validation layer: Invalid CommandPool Object 0x0. The Vulkan spec states: commandPool must be a valid VkCommandPool handle (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-vkFreeCommandBuffers-commandPool-parameter)
VUID-vkFreeCommandBuffers-commandPool-parameter
This happens because the command pool field of the unique handle is not set properly:
(gdb) p t_command_buffers[0]
$6 = {<vk::PoolFree<vk::Device, vk::CommandPool, vk::DispatchLoaderStatic>> = {m_owner = {m_device = 0x555555ec14e0}, m_pool = {m_commandPool = 0x0},
m_dispatch = 0x7fffffffe2f7}, m_value = {m_commandBuffer = 0x555555fe6390}}
I checked, and although there is a commandBuffer.getPool(), there is no setPool().
Any suggestions on properly setting the field?