Class Device

Class Documentation

class inexor::vulkan_renderer::wrapper::Device

A RAII wrapper class for VkDevice, VkPhysicalDevice and VkQueues.

Note

There is no method is_layer_supported in this wrapper class because device layers are deprecated.

Public Functions

Device(const wrapper::Instance &instance, VkSurfaceKHR surface, bool enable_vulkan_debug_markers, bool prefer_distinct_transfer_queue, std::optional<std::uint32_t> preferred_physical_device_index = std::nullopt)

Default constructor.

Todo:

Add overloaded constructors for VkPhysicalDeviceFeatures and requested device extensions in the future!

Parameters
  • instance – The instance wrapper from which the device will be created.

  • surface – The surface which will be associated with the device.

  • enable_vulkan_debug_markers – True if Vulkan debug markers should be enabled, false otherwise.

  • prefer_distinct_transfer_queue – True if a distinct data transfer queue (if available) should be enabled, false otherwise.

  • preferred_physical_device_index – The index of the preferred graphics card which should be used, starting from 0. If the graphics card index is invalid or if the graphics card is unsuitable for the application’s purpose, another graphics card will be selected automatically. See the details of the device selection mechanism!

Device(const Device&) = delete
Device(Device&&) noexcept
~Device()
Device &operator=(const Device&) = delete
Device &operator=(Device&&) = delete
inline VkDevice device() const
inline VkPhysicalDevice physical_device() const
inline VmaAllocator allocator() const
inline const std::string &gpu_name() const
inline VkQueue graphics_queue() const
inline VkQueue present_queue() const
inline VkQueue transfer_queue() const

Note

Transfer queues are the fastest way to copy data across the PCIe bus. They are heavily underutilized even in modern games. Transfer queues can be used asynchronously to graphics queue.

inline std::uint32_t graphics_queue_family_index() const
inline std::uint32_t present_queue_family_index() const
inline std::uint32_t transfer_queue_family_index() const
void set_debug_marker_name(void *object, VkDebugReportObjectTypeEXT object_type, const std::string &name) const

Assign an internal Vulkan debug marker name to a Vulkan object. This internal name can be seen in external debuggers like RenderDoc.

Note

This method is only available in debug mode with VK_EXT_debug_marker device extension enabled.

Parameters
  • object – The Vulkan object.

  • object_type – The Vulkan debug report object type.

  • name – The internal name of the Vulkan object.

void set_memory_block_attachment(void *object, VkDebugReportObjectTypeEXT object_type, std::uint64_t name, std::size_t memory_size, const void *memory_block) const

Assigns a block of memory to a Vulkan resource. This memory block can be seen in external debuggers like RenderDoc.

Note

This method is only available in debug mode with VK_EXT_debug_marker device extension enabled.

Parameters
  • object – The Vulkan object.

  • object_type – The Vulkan debug report object type.

  • name – The name of the memory block which will be connected to this object.

  • memory_size – The size of the memory block in bytes.

  • memory_address – The memory address to read from.

void bind_debug_region(VkCommandBuffer command_buffer, const std::string &name, std::array<float, 4> color) const

Vulkan debug markers: Annotation of a rendering region.

Parameters
  • color – [in] The rgba color of the rendering region.

  • name – [in] The name of the rendering region.

  • command_buffer – [in] The associated command buffer. The rendering region will be visible in external debuggers like RenderDoc.

void insert_debug_marker(VkCommandBuffer command_buffer, const std::string &name, std::array<float, 4> color) const

Insert a debug markers into the current renderpass using vkCmdDebugMarkerInsertEXT. This debug markers can be seen in external debuggers like RenderDoc.

Parameters
  • command_buffer – The command buffer which is associated to the debug marker.

  • name – The name of the debug marker.

  • color – An array of red, green, blue and alpha values for the debug region’s color.

void end_debug_region(VkCommandBuffer command_buffer) const

End the debug region of the current renderpass using vkCmdDebugMarkerEndEXT.

Parameters

command_buffer – The command buffer which is associated to the debug marker.

Public Static Functions

static bool is_extension_supported(VkPhysicalDevice graphics_card, const std::string &extension)

Check if a certain device extension is available for a specific graphics card.

Parameters
  • graphics_card – The graphics card.

  • extension – The name of the device extension.

Returns

true if the requested device extension is available.

static bool is_swapchain_supported(VkPhysicalDevice graphics_card)

Check if a swapchain is available for a specific graphics card.

Parameters

graphics_card – The graphics card.

Returns

true if swapchain is supported.

static bool is_presentation_supported(VkPhysicalDevice graphics_card, VkSurfaceKHR surface)

Check if presentation is available for a specific combination of graphics card and surface.

Parameters
  • graphics_card – The graphics card.

  • surface – The (window) surface.

Returns

true if presentation is supported.

Private Members

VkDevice m_device = {VK_NULL_HANDLE}
VkPhysicalDevice m_graphics_card = {VK_NULL_HANDLE}
VmaAllocator m_allocator = {VK_NULL_HANDLE}
std::string m_gpu_name
VkQueue m_graphics_queue = {VK_NULL_HANDLE}
VkQueue m_present_queue = {VK_NULL_HANDLE}
VkQueue m_transfer_queue = {VK_NULL_HANDLE}
VkSurfaceKHR m_surface = {VK_NULL_HANDLE}
std::uint32_t m_present_queue_family_index = {0}
std::uint32_t m_graphics_queue_family_index = {0}
std::uint32_t m_transfer_queue_family_index = {0}
PFN_vkDebugMarkerSetObjectTagEXT m_vk_debug_marker_set_object_tag = {nullptr}
PFN_vkDebugMarkerSetObjectNameEXT m_vk_debug_marker_set_object_name = {nullptr}
PFN_vkCmdDebugMarkerBeginEXT m_vk_cmd_debug_marker_begin = {nullptr}
PFN_vkCmdDebugMarkerEndEXT m_vk_cmd_debug_marker_end = {nullptr}
PFN_vkCmdDebugMarkerInsertEXT m_vk_cmd_debug_marker_insert = {nullptr}
PFN_vkSetDebugUtilsObjectNameEXT m_vk_set_debug_utils_object_name = {nullptr}
const bool m_enable_vulkan_debug_markers = {false}