// Copyright (C) 2020 Jérôme Leclercq // This file is part of the "Nazara Engine - Vulkan Renderer" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_VULKANRENDERER_VKDEVICE_HPP #define NAZARA_VULKANRENDERER_VKDEVICE_HPP #include #include #include #include #include #include namespace Nz { namespace Vk { class Device; class Instance; class Queue; using DeviceHandle = std::shared_ptr; class NAZARA_VULKANRENDERER_API Device : public std::enable_shared_from_this { public: struct QueueFamilyInfo; struct QueueInfo; using QueueList = std::vector; inline Device(Instance& instance); Device(const Device&) = delete; Device(Device&&) = delete; inline ~Device(); bool Create(VkPhysicalDevice device, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); inline void Destroy(); inline const std::vector& GetEnabledQueues() const; inline const QueueList& GetEnabledQueues(UInt32 familyQueue) const; Queue GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex); inline Instance& GetInstance(); inline const Instance& GetInstance() const; inline VkResult GetLastErrorCode() const; inline VkPhysicalDevice GetPhysicalDevice() const; inline bool IsExtensionLoaded(const std::string& extensionName); inline bool IsLayerLoaded(const std::string& layerName); inline bool WaitForIdle(); Device& operator=(const Device&) = delete; Device& operator=(Device&&) = delete; inline operator VkDevice(); // Vulkan functions #define NAZARA_VULKANRENDERER_DEVICE_EXT_BEGIN(ext) #define NAZARA_VULKANRENDERER_DEVICE_EXT_END() #define NAZARA_VULKANRENDERER_DEVICE_FUNCTION(func) PFN_##func func; #include #undef NAZARA_VULKANRENDERER_DEVICE_EXT_BEGIN #undef NAZARA_VULKANRENDERER_DEVICE_EXT_END #undef NAZARA_VULKANRENDERER_DEVICE_FUNCTION struct QueueInfo { QueueFamilyInfo* familyInfo; VkQueue queue; float priority; }; struct QueueFamilyInfo { QueueList queues; VkExtent3D minImageTransferGranularity; VkQueueFlags flags; UInt32 familyIndex; UInt32 timestampValidBits; }; private: inline PFN_vkVoidFunction GetProcAddr(const char* name); Instance& m_instance; const Vk::PhysicalDevice* m_physicalDevice; VkAllocationCallbacks m_allocator; VkDevice m_device; VkResult m_lastErrorCode; std::unordered_set m_loadedExtensions; std::unordered_set m_loadedLayers; std::vector m_enabledQueuesInfos; std::vector m_queuesByFamily; }; } } #include #endif // NAZARA_VULKANRENDERER_VKDEVICE_HPP