class
Device!The Device class is a wrapper around the vkLogicalDevice object.
Contents
This object is what most Vulkan resources and objects are spawned from, and is then responsible for managing these resources. Most Vulkan functions relating to resource creation, binding, or updating will take a VkDevice reference as a parameter. This is considered to be a "Logical device" as it represents a non-physical device and each physical device can actually store and handle multiple logical devices.
The vast majority of classes in this codebase contain a private const Device pointer, for use in their internal functions requiring this object's handle.
Constructors, destructors, conversion operators
- Device(const Instance* instance, const PhysicalDevice* p_device, VkSurfaceKHR surface = VK_NULL_HANDLE, const VprExtensionPack* extensions = nullptr, const char*const* layer_names = nullptr, const uint32_t layer_count = 0)
- Constructs a new VkDevice instance.
Public functions
- auto HasDedicatedComputeQueues() const -> bool
- Returns whether or not the currently active physical device, along with the logical device, supports/has queues dedicated compute operations.
- auto DedicatedAllocationExtensionsEnabled() const -> bool noexcept
- Returns true when the VK_KHR_dedicated_allocation extension and it's cohort has been loaded.
- void GetEnabledExtensions(size_t* num_extensions, char** extensions) const
- Important note - uses strdup, so the data must be free'd by the user once they are done reading the extensions array!
- auto GeneralQueue(const uint32_t& idx = 0) const -> VkQueue
- ! Returns queue that has support for most operation types.
- auto GetFormatTiling(const VkFormat& format, const VkFormatFeatureFlags& flags) const -> VkImageTiling
- !Checks whether or not the given format along with the specified flags supports optimal or linear tiling.
- auto FindSupportedFormat(const VkFormat* formats, const size_t num_formats, const VkImageTiling& tiling, const VkFormatFeatureFlags& flags) const -> VkFormat
- ! Checks a collection of possible formats, returning the one that supports the given tiling and feature flags.
- auto FindDepthFormat() const -> VkFormat
- Finds a Vulkan image format suitable for use in the depth buffer.
- auto GetMemoryTypeIdx(const uint32_t& type_bitfield, const VkMemoryPropertyFlags& property_flags, VkBool32* memory_type_found = nullptr) const -> uint32_t
- Returns the index of a memory type satisfying the requirements specified by the given parameters.
- auto DebugUtilsHandler() const -> const VkDebugUtilsFunctions&
- Used to retrieve structure of debug utils function pointers.
Function documentation
vpr:: Device:: Device(const Instance* instance,
const PhysicalDevice* p_device,
VkSurfaceKHR surface = VK_NULL_HANDLE,
const VprExtensionPack* extensions = nullptr,
const char*const* layer_names = nullptr,
const uint32_t layer_count = 0)
Constructs a new VkDevice instance.
Parameters | |
---|---|
instance | Parent instance this device belongs to |
p_device | Physical device that this device operators over and on |
surface | |
extensions | Used to decide what device-level extensions should be loaded. Throws if unable to load a required extension. If left to null, will only load what is required for presentation and try to load allocation extensions to improve that system |
layer_names | Names of layers to load - If left to null and the parent instance has validation enabled, uses the VK_LAYER_LUNARG_standard_validation set |
layer_count |
bool vpr:: Device:: DedicatedAllocationExtensionsEnabled() const noexcept
Returns true when the VK_KHR_dedicated_allocation extension and it's cohort has been loaded.
Used by memory allocation systems to improve fit and potential performance of certain memory allocations.
VkQueue vpr:: Device:: GeneralQueue(const uint32_t& idx = 0) const
! Returns queue that has support for most operation types.
Parameters | |
---|---|
idx | - in the case of a device with several "generalized" queues, selects which queue to return. |
First checks for graphics, compute, and transfer. Then proceeds to graphics and compute. Lastly, it will just return a graphics-only queue and log a warning.
VkImageTiling vpr:: Device:: GetFormatTiling(const VkFormat& format,
const VkFormatFeatureFlags& flags) const
!Checks whether or not the given format along with the specified flags supports optimal or linear tiling.
Parameters | |
---|---|
format | - Vulkan format enum specifying the type of image data |
flags | - flags specifying features of format: commonly what it is being used for, e.g cube map, sampled image, storage image, etc |
VkFormat vpr:: Device:: FindSupportedFormat(const VkFormat* formats,
const size_t num_formats,
const VkImageTiling& tiling,
const VkFormatFeatureFlags& flags) const
! Checks a collection of possible formats, returning the one that supports the given tiling and feature flags.
Parameters | |
---|---|
formats | |
num_formats | |
tiling | - required image tiling setting. |
flags | - features required, commonly related to intended use for the image. |
Returns | Returns found format if successful, otherwise returns VK_FORMAT_UNDEFINED and logs a detailed error. |
VkFormat vpr:: Device:: FindDepthFormat() const
Finds a Vulkan image format suitable for use in the depth buffer.
Currently could benefit from better quantification of what defines the "best" depth format, as this will depend on hardware and whether or not we are even using the stencil.
uint32_t vpr:: Device:: GetMemoryTypeIdx(const uint32_t& type_bitfield,
const VkMemoryPropertyFlags& property_flags,
VkBool32* memory_type_found = nullptr) const
Returns the index of a memory type satisfying the requirements specified by the given parameters.
Parameters | |
---|---|
type_bitfield | bitfield retrieved from VkMemoryRequirements |
property_flags | required properties that the memory type must support |
memory_type_found | written to, if non-null, based on search results |
Returns std::numeric_limits<uint32_t>::max() if the value cannot be found, and writes to memory_type_found