-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Consider providing a Device::set_debug_utils_object_name shortcut on individual objects #2242
Comments
Good idea! Do you think we still need the method on |
If we remove the method on Device, then the functionality will only be available via a trait, which may make it harder to discover by users. Also, while playing with this in parallel, I realized that ergonomics of debug utils names could be further improved by making it possible to call set_debug_utils_name directly on a Vulkano object that maps to some underlying Vulkan object, like StorageImage or SubBuffer. This could be an argument for having some sort of |
...also, I think I found a little use after free problem in the implementation :( pub fn set_debug_utils_object_name<T: VulkanObject + DeviceOwned>(
&self,
object: &T,
object_name: Option<&str>,
) -> Result<(), OomError> {
assert!(object.device().handle() == self.handle());
// Building a CString, so far, so good...
let object_name_vk = object_name.map(|object_name| CString::new(object_name).unwrap());
let info = ash::vk::DebugUtilsObjectNameInfoEXT {
object_type: T::Handle::TYPE,
object_handle: object.handle().as_raw(),
// ...but this map_or moves the CString, which will be dropped once this statement is done evaluating...
p_object_name: object_name_vk.map_or(ptr::null(), |object_name| object_name.as_ptr()),
..Default::default()
};
// ...and thus the pointer will be dangling by the time we call Vulkan.
unsafe {
let fns = self.instance().fns();
(fns.ext_debug_utils.set_debug_utils_object_name_ext)(self.handle, &info)
.result()
.map_err(RuntimeError::from)?;
}
Ok(())
} I think this can be fixed by using as_ref() to borrow the CString, instead of moving it (and later dropping it), as follows: p_object_name: object_name_vk.as_ref().map_or(ptr::null(), |object_name| object_name.as_ptr()), |
* Improve debug messenger, remove second `Instance` constructor * #2242 * Doctest fix * Take Arc out * DeviceOwnedVulkanObject * Update vulkano/src/device/mod.rs Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com> * Update vulkano/src/instance/debug.rs Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com> * Fixes --------- Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>
…o-rs#2275) * Improve debug messenger, remove second `Instance` constructor * vulkano-rs#2242 * Doctest fix * Take Arc out * DeviceOwnedVulkanObject * Update vulkano/src/device/mod.rs Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com> * Update vulkano/src/instance/debug.rs Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com> * Fixes --------- Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>
This could be done by adding a set_debug_utils_name method to the VulkanObject of DeviceOwned trait, with an appropriate where bound so that it is only available where the other trait is present. From my perspective, it would make a little more sense to put it on the VulkanObject trait, since it's a Vulkan thing.
The rationale for this proposal is that DeviceOwned objects, by definition, know which device they belong to. And from this perspective, needing to get my hand to a
&Device
just to set their debug utils name feels like unnecessary ceremony.Further, use of Vulkan requires creating a lots of objects, which in an ideal world would all be annotated with names in debugging/profiling mode so that tools provide more explicit output. Therefore, the ergonomics benefits of such a shortcut would quickly add up.
The text was updated successfully, but these errors were encountered: