Add object name setters (#895)

This commit is contained in:
Benjamin Saunders 2017-12-13 00:50:08 -08:00 committed by Pierre Krieger
parent 80e1ed6dc3
commit 70013d2678
28 changed files with 124 additions and 3 deletions

View File

@ -6,6 +6,8 @@
- Fix occasional truncation of glslang_validator when glsl-to-spirv is rebuilt
- Fix linking against MoltenVK >= 0.19.0
- Added `AutoCommandBufferBuilder::copy_image`
- Added `VulkanObject::TYPE` to look up the `DebugReportObjectTypeEXT` of an object
- Added `Device::set_object_name` and `Device::set_object_name_raw`
# Version 0.7.2 (2017-10-09)

View File

@ -999,7 +999,15 @@ pub const DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT: u32 = 24;
pub const DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT: u32 = 25;
pub const DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT: u32 = 26;
pub const DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT: u32 = 27;
pub const DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT: u32 = 28;
#[deprecated = "Renamed to DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT"]
pub const DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT: u32 = DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT;
pub const DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT: u32 = 28;
pub const DEBUG_REPORT_OBJECT_TYPE_DISPLAY_KHR_EXT: u32 = 29;
pub const DEBUG_REPORT_OBJECT_TYPE_DISPLAY_MODE_KHR_EXT: u32 = 30;
pub const DEBUG_REPORT_OBJECT_TYPE_OBJECT_TABLE_NVX_EXT: u32 = 31;
pub const DEBUG_REPORT_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NVX_EXT: u32 = 32;
pub const DEBUG_REPORT_OBJECT_TYPE_VALIDATION_CACHE_EXT: u32 = 33;
pub const DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_KHR_EXT: u32 = 1000085000;
pub type DebugReportErrorEXT = u32;
pub const DEBUG_REPORT_ERROR_NONE_EXT: u32 = 0;

View File

@ -298,6 +298,8 @@ impl UnsafeBuffer {
unsafe impl VulkanObject for UnsafeBuffer {
type Object = vk::Buffer;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT;
#[inline]
fn internal_object(&self) -> vk::Buffer {
self.buffer

View File

@ -201,6 +201,8 @@ unsafe impl<F, B> VulkanObject for BufferView<F, B>
{
type Object = vk::BufferView;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT;
#[inline]
fn internal_object(&self) -> vk::BufferView {
self.view

View File

@ -225,6 +225,8 @@ unsafe impl DeviceOwned for UnsafeCommandPool {
unsafe impl VulkanObject for UnsafeCommandPool {
type Object = vk::CommandPool;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT;
#[inline]
fn internal_object(&self) -> vk::CommandPool {
self.pool
@ -247,6 +249,8 @@ pub struct UnsafeCommandPoolAlloc(vk::CommandBuffer);
unsafe impl VulkanObject for UnsafeCommandPoolAlloc {
type Object = vk::CommandBuffer;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT;
#[inline]
fn internal_object(&self) -> vk::CommandBuffer {
self.0

View File

@ -1542,6 +1542,8 @@ unsafe impl<P> DeviceOwned for UnsafeCommandBufferBuilder<P> {
unsafe impl<P> VulkanObject for UnsafeCommandBufferBuilder<P> {
type Object = vk::CommandBuffer;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT;
#[inline]
fn internal_object(&self) -> vk::CommandBuffer {
debug_assert!(self.cmd.is_some());
@ -1950,6 +1952,8 @@ unsafe impl<P> DeviceOwned for UnsafeCommandBuffer<P> {
unsafe impl<P> VulkanObject for UnsafeCommandBuffer<P> {
type Object = vk::CommandBuffer;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT;
#[inline]
fn internal_object(&self) -> vk::CommandBuffer {
self.cmd_raw

View File

@ -732,6 +732,8 @@ impl UnsafeDescriptorSet {
unsafe impl VulkanObject for UnsafeDescriptorSet {
type Object = vk::DescriptorSet;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT;
#[inline]
fn internal_object(&self) -> vk::DescriptorSet {
self.set

View File

@ -127,6 +127,8 @@ impl fmt::Debug for UnsafeDescriptorSetLayout {
unsafe impl VulkanObject for UnsafeDescriptorSetLayout {
type Object = vk::DescriptorSetLayout;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT;
#[inline]
fn internal_object(&self) -> vk::DescriptorSetLayout {
self.layout

View File

@ -253,6 +253,8 @@ pub struct PipelineLayoutSys<'a>(&'a vk::PipelineLayout);
unsafe impl<'a> VulkanObject for PipelineLayoutSys<'a> {
type Object = vk::PipelineLayout;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT;
#[inline]
fn internal_object(&self) -> vk::PipelineLayout {
*self.0

View File

@ -103,6 +103,7 @@ use std::sync::Arc;
use std::sync::Mutex;
use std::sync::MutexGuard;
use std::sync::Weak;
use std::ffi::CStr;
use command_buffer::pool::StandardCommandPool;
use descriptor::descriptor_set::StdDescriptorPool;
@ -116,6 +117,7 @@ use Error;
use OomError;
use SynchronizedVulkanObject;
use VulkanObject;
use VulkanHandle;
use check_errors;
use vk;
@ -465,6 +467,35 @@ impl Device {
pub(crate) fn event_pool(&self) -> &Mutex<Vec<vk::Event>> {
&self.event_pool
}
/// Assigns a human-readable name to `object` for debugging purposes.
///
/// # Panics
/// * If the `VK_EXT_debug_marker` device extension is not loaded.
/// * If `object` is not owned by this device.
pub fn set_object_name<T: VulkanObject + DeviceOwned>(&self, object: &T, name: &CStr) -> Result<(), OomError> {
assert!(object.device().internal_object() == self.internal_object());
unsafe { self.set_object_name_raw(T::TYPE, object.internal_object().value(), name) }
}
/// Assigns a human-readable name to `object` for debugging purposes.
///
/// # Panics
/// * If the `VK_EXT_debug_marker` device extension is not loaded.
///
/// # Safety
/// `object` must be a Vulkan handle owned by this device, and its type must be accurately described by `ty`.
pub unsafe fn set_object_name_raw(&self, ty: vk::DebugReportObjectTypeEXT, object: u64, name: &CStr) -> Result<(), OomError> {
let info = vk::DebugMarkerObjectNameInfoEXT {
sType: vk::STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT,
pNext: ptr::null(),
objectType: ty,
object: object,
name: name.as_ptr(),
};
check_errors(self.vk.DebugMarkerSetObjectNameEXT(self.device, &info))?;
Ok(())
}
}
impl fmt::Debug for Device {
@ -477,6 +508,8 @@ impl fmt::Debug for Device {
unsafe impl VulkanObject for Device {
type Object = vk::Device;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT;
#[inline]
fn internal_object(&self) -> vk::Device {
self.device

View File

@ -457,6 +457,8 @@ pub struct FramebufferSys<'a>(vk::Framebuffer, PhantomData<&'a ()>);
unsafe impl<'a> VulkanObject for FramebufferSys<'a> {
type Object = vk::Framebuffer;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT;
#[inline]
fn internal_object(&self) -> vk::Framebuffer {
self.0

View File

@ -496,6 +496,8 @@ pub struct RenderPassSys<'a>(vk::RenderPass, PhantomData<&'a ()>);
unsafe impl<'a> VulkanObject for RenderPassSys<'a> {
type Object = vk::RenderPass;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT;
#[inline]
fn internal_object(&self) -> vk::RenderPass {
self.0

View File

@ -783,6 +783,8 @@ impl UnsafeImage {
unsafe impl VulkanObject for UnsafeImage {
type Object = vk::Image;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT;
#[inline]
fn internal_object(&self) -> vk::Image {
self.image
@ -1081,6 +1083,8 @@ impl UnsafeImageView {
unsafe impl VulkanObject for UnsafeImageView {
type Object = vk::ImageView;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT;
#[inline]
fn internal_object(&self) -> vk::ImageView {
self.view

View File

@ -468,6 +468,8 @@ impl fmt::Debug for Instance {
unsafe impl VulkanObject for Instance {
type Object = vk::Instance;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT;
#[inline]
fn internal_object(&self) -> vk::Instance {
self.instance
@ -940,6 +942,8 @@ impl<'a> PhysicalDevice<'a> {
unsafe impl<'a> VulkanObject for PhysicalDevice<'a> {
type Object = vk::PhysicalDevice;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT;
#[inline]
fn internal_object(&self) -> vk::PhysicalDevice {
self.infos().device

View File

@ -107,10 +107,26 @@ unsafe impl<T: ?Sized> SafeDeref for Arc<T> {
unsafe impl<T: ?Sized> SafeDeref for Box<T> {
}
pub trait VulkanHandle {
fn value(&self) -> u64;
}
impl VulkanHandle for usize {
#[inline]
fn value(&self) -> u64 { *self as u64 }
}
impl VulkanHandle for u64 {
#[inline]
fn value(&self) -> u64 { *self }
}
/// Gives access to the internal identifier of an object.
pub unsafe trait VulkanObject {
/// The type of the object.
type Object;
type Object: VulkanHandle;
/// The `DebugReportObjectTypeEXT` of the internal Vulkan handle.
const TYPE: vk::DebugReportObjectTypeEXT;
/// Returns a reference to the object.
fn internal_object(&self) -> Self::Object;
@ -120,7 +136,7 @@ pub unsafe trait VulkanObject {
// TODO: remove ; crappy design
pub unsafe trait SynchronizedVulkanObject {
/// The type of the object.
type Object;
type Object: VulkanHandle;
/// Returns a reference to the object.
fn internal_object_guard(&self) -> MutexGuard<Self::Object>;

View File

@ -229,6 +229,8 @@ impl fmt::Debug for DeviceMemory {
unsafe impl VulkanObject for DeviceMemory {
type Object = vk::DeviceMemory;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT;
#[inline]
fn internal_object(&self) -> vk::DeviceMemory {
self.memory

View File

@ -219,6 +219,8 @@ impl PipelineCache {
unsafe impl VulkanObject for PipelineCache {
type Object = vk::PipelineCache;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT;
#[inline]
fn internal_object(&self) -> vk::PipelineCache {
self.cache

View File

@ -212,6 +212,8 @@ pub struct ComputePipelineSys<'a>(vk::Pipeline, PhantomData<&'a ()>);
unsafe impl<'a> VulkanObject for ComputePipelineSys<'a> {
type Object = vk::Pipeline;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT;
#[inline]
fn internal_object(&self) -> vk::Pipeline {
self.0
@ -272,6 +274,8 @@ unsafe impl<Pl> DeviceOwned for ComputePipeline<Pl> {
unsafe impl<Pl> VulkanObject for ComputePipeline<Pl> {
type Object = vk::Pipeline;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT;
#[inline]
fn internal_object(&self) -> vk::Pipeline {
self.inner.pipeline

View File

@ -302,6 +302,8 @@ unsafe impl<C, Mv, L, Rp> RenderPassDescClearValues<C> for GraphicsPipeline<Mv,
unsafe impl<Mv, L, Rp> VulkanObject for GraphicsPipeline<Mv, L, Rp> {
type Object = vk::Pipeline;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT;
#[inline]
fn internal_object(&self) -> vk::Pipeline {
self.inner.pipeline
@ -477,6 +479,8 @@ pub struct GraphicsPipelineSys<'a>(vk::Pipeline, PhantomData<&'a ()>);
unsafe impl<'a> VulkanObject for GraphicsPipelineSys<'a> {
type Object = vk::Pipeline;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT;
#[inline]
fn internal_object(&self) -> vk::Pipeline {
self.0

View File

@ -166,6 +166,8 @@ impl ShaderModule {
unsafe impl VulkanObject for ShaderModule {
type Object = vk::ShaderModule;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT;
#[inline]
fn internal_object(&self) -> vk::ShaderModule {
self.module

View File

@ -114,6 +114,8 @@ impl UnsafeQueryPool {
unsafe impl VulkanObject for UnsafeQueryPool {
type Object = vk::QueryPool;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT;
#[inline]
fn internal_object(&self) -> vk::QueryPool {
self.pool

View File

@ -482,6 +482,8 @@ unsafe impl DeviceOwned for Sampler {
unsafe impl VulkanObject for Sampler {
type Object = vk::Sampler;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT;
#[inline]
fn internal_object(&self) -> vk::Sampler {
self.sampler

View File

@ -310,6 +310,8 @@ impl Display {
unsafe impl VulkanObject for Display {
type Object = vk::DisplayKHR;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_DISPLAY_KHR_EXT;
#[inline]
fn internal_object(&self) -> vk::DisplayKHR {
self.properties.display
@ -378,6 +380,8 @@ impl DisplayMode {
unsafe impl VulkanObject for DisplayMode {
type Object = vk::DisplayModeKHR;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_DISPLAY_MODE_KHR_EXT;
#[inline]
fn internal_object(&self) -> vk::DisplayModeKHR {
self.display_mode

View File

@ -591,6 +591,8 @@ unsafe impl SurfaceSwapchainLock for Surface {
unsafe impl VulkanObject for Surface {
type Object = vk::SurfaceKHR;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT;
#[inline]
fn internal_object(&self) -> vk::SurfaceKHR {
self.surface

View File

@ -560,6 +560,8 @@ impl Swapchain {
unsafe impl VulkanObject for Swapchain {
type Object = vk::SwapchainKHR;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT;
#[inline]
fn internal_object(&self) -> vk::SwapchainKHR {
self.swapchain

View File

@ -164,6 +164,8 @@ unsafe impl DeviceOwned for Event {
unsafe impl VulkanObject for Event {
type Object = vk::Event;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT;
#[inline]
fn internal_object(&self) -> vk::Event {
self.event

View File

@ -307,6 +307,8 @@ unsafe impl<D> VulkanObject for Fence<D>
{
type Object = vk::Fence;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT;
#[inline]
fn internal_object(&self) -> vk::Fence {
self.fence

View File

@ -102,6 +102,8 @@ unsafe impl<D> VulkanObject for Semaphore<D>
{
type Object = vk::Semaphore;
const TYPE: vk::DebugReportObjectTypeEXT = vk::DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT;
#[inline]
fn internal_object(&self) -> vk::Semaphore {
self.semaphore