NDEVR
API Documentation
VulkanDevice.h
1#pragma once
2#include "../../VulkanGraphics/Headers/VulkanInstance.h"
3#include <NDEVR/GraphicsDevice.h>
4struct VkDeviceCreateInfo;
5namespace NDEVR
6{
14 {
15 public:
19 VulkanDevice(VkPhysicalDevice physical_device, const DynamicPointer<VulkanInstance>& instance);
24 VulkanDevice(VulkanDevice&& instance) noexcept;
26 virtual ~VulkanDevice(){};
32 UUID id() const override { return m_id; };
33
34 void init() override;
35 void cleanup();
36 bool isInitialized() const override { return m_is_init; }
37 bool isValid() const override;
38 void destroyImageView(VkImageView image_view);
39 VkCommandPool getCommandPool(uint04 id = Constant<uint04>::Invalid) const;
40 void destroyCommandPool(uint04 id);
41 VkQueue graphicsQueue(uint04 id = Constant<uint04>::Invalid) const;
42 VkQueue presentQueue(void* window) const;
43 VkCommandBuffer beginSingleTimeCommands(uint04 id = Constant<uint04>::Invalid) const;
44 void endSingleTimeCommands(VkCommandBuffer commandBuffer, bool wait_for_completion, uint04 id = Constant<uint04>::Invalid) const;
45 uint04 checkoutID() const;
46 void checkoutID(uint04 id) const;
47 void returnID(uint04 id = Constant<uint04>::Invalid) const;
48 uint04 maxSupportedSamples() const override;
49 virtual uint04 getThreadedID() const;
50 bool isSoftwareRendered() const;
51 #ifdef ANDROID
52 virtual bool supportsMultiThreading() const override { return false; }
53 #else
54 virtual bool supportsMultiThreading() const override { return true; }
55 #endif
56 virtual void waitForGraphicsQueue(uint04 id = Constant<uint04>::Invalid) const;
57 void logPhysicalDevice();
58 const VkPhysicalDeviceProperties& physicalProperties() const;
59 const VkPhysicalDeviceFeatures& physicalFeatures() const;
60 const VkPhysicalDeviceFeatures& enabledFeatures() const;
61 const void* initLockPtr() const override;//To initialize, must hold write lock, to use must hold read lock
62 VkPresentModeKHR chooseSwapPresentMode(const Buffer<VkPresentModeKHR>& availablePresentModes);
63 void addSurface(VkSurfaceKHR surface);
64 void removeSurface(VkSurfaceKHR surface);
65
66 VkFormat findDepthFormat() const;
67 DynamicPointer<VulkanInstance> instance() const;
68 VkInstance vkInstance() const { lib_assert(!m_instance.isNull(), "Instance not yet created, but access is attempted"); return m_instance->vkInstance(); }
69 VkDevice device() const { return m_device; }
70 const VkPhysicalDevice& physicalDevice() const { return m_physical_device; }
71 VulkanStagingRing* stagingRing() const;
72 void setLog(LogPtr log);
73 uint04 graphicsFamilyIndex() const { return m_graphics_family_index; };
74 LogPtr log() { return m_log; }
75 bool supportsTriangleFan() const {return m_instance->supportsTriangleFan();}
76 uint04 findMemoryType(uint04 typeFilter, uint04 properties) const;
77 protected:
78 void setQueueFamilies();
79 void setupLogicalDevice();
80 bool checkDeviceExtensionSupport(VkPhysicalDevice device);
81 void createCommandPool(uint04 thread) const;
82 virtual VkResult createLogicalDevice(const VkDeviceCreateInfo& create_info);
83 virtual void autoChoosePhysicalDevice();
84 protected:
85 LogPtr m_log = nullptr;
88 VkDevice m_device = vk_null;
89 VkPhysicalDevice m_physical_device = vk_null;
95 mutable VkPhysicalDeviceProperties* m_physical_properties = nullptr;
96 mutable VkPhysicalDeviceFeatures* m_physical_features = nullptr;
97 mutable VkPhysicalDeviceFeatures* m_enabled_features = nullptr;
98 uint04 m_graphics_family_index = Constant<uint04>::Invalid;
99 uint04 m_present_family_index = Constant<uint04>::Invalid;
101
103
110 bool m_is_init = false;
111 };
112}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
GraphicsDevice()
Default constructor.
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
void setDeviceLost()
Handles a device-lost event by cleaning up resources.
VkDevice m_device
The logical Vulkan device handle.
VulkanDevice(VkPhysicalDevice physical_device, const DynamicPointer< VulkanInstance > &instance)
Constructs a Vulkan device for a specific physical device.
VkPhysicalDevice m_physical_device
The physical device handle.
UUID id() const override
Returns the unique identifier for this device.
static DynamicPointer< VulkanDevice > & DefaultVulkanDevice()
Returns a reference to the global default Vulkan device.
DynamicPointer< VulkanInstance > m_instance
The Vulkan instance this device belongs to.
LogPtr m_log
Log for device messages.
Dictionary< uint04, uint04 > m_thread_checkouts
Thread-to-checkout-ID mapping.
VulkanStagingRing * m_staging_ring
Staging ring for CPU-to-GPU transfers.
Dictionary< uint04, VkQueue > m_graphics_queue
Graphics queues keyed by checkout ID.
Dictionary< uint04, uint04 > m_graphics_queue_index
Queue family indices keyed by checkout ID.
Dictionary< void *, VkQueue > m_present_queue
Present queues keyed by window handle.
bool m_is_init
Whether the device has been initialized.
Buffer< VkQueueFamilyProperties > m_queue_families
Available queue families on the physical device.
Buffer< String > m_device_layers
Enabled device layers.
uint04 m_graphics_family_index
The queue family index for graphics operations.
uint04 maxSupportedSamples() const override
Returns the maximum number of multisample samples supported.
Time m_creation_time
The time this device was created.
Buffer< VkSurfaceKHR > m_surfaces
Surfaces registered with this device.
virtual bool supportsMultiThreading() const override
Checks whether the device supports multi-threaded rendering.
Dictionary< uint04, VkCommandPool > m_command_pools
Command pools keyed by thread ID.
bool isValid() const override
Checks whether this device is valid and usable.
VkPhysicalDeviceFeatures * m_physical_features
Cached physical device features.
uint04 m_present_family_index
The queue family index for presentation.
UUID m_id
Unique identifier for this device.
void init() override
Initializes the graphics device.
bool m_is_software_rendered
Whether this is a software-rendered device.
bool isInitialized() const override
Checks whether the device has been initialized.
VulkanDevice(const DynamicPointer< VulkanInstance > &instance)
Constructs a Vulkan device that will auto-choose the best physical device.
VkPhysicalDeviceProperties * m_physical_properties
Cached physical device properties.
const void * initLockPtr() const override
Returns a pointer used for synchronizing device initialization.
virtual ~VulkanDevice()
Destructor.
VkPhysicalDeviceFeatures * m_enabled_features
Features enabled on the logical device.
Buffer< uint04 > m_checkouts
Available checkout IDs.
VulkanDevice(VulkanDevice &&instance) noexcept
Move constructor.
Buffer< String > m_device_extensions
Enabled device extensions.
A ring buffer for staging GPU uploads.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...