diff --git a/include/Nazara/OpenGLRenderer/OpenGLDevice.hpp b/include/Nazara/OpenGLRenderer/OpenGLDevice.hpp index b897ef728..acf85a863 100644 --- a/include/Nazara/OpenGLRenderer/OpenGLDevice.hpp +++ b/include/Nazara/OpenGLRenderer/OpenGLDevice.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -30,6 +31,7 @@ namespace Nz std::unique_ptr CreateContext(const GL::ContextParams& params) const; std::unique_ptr CreateContext(const GL::ContextParams& params, WindowHandle handle) const; + const RenderDeviceInfo& GetDeviceInfo() const override; inline const GL::Context& GetReferenceContext() const; std::shared_ptr InstantiateBuffer(BufferType type) override; @@ -57,6 +59,7 @@ namespace Nz std::unique_ptr m_referenceContext; mutable std::unordered_set m_contexts; + RenderDeviceInfo m_deviceInfo; GL::Loader& m_loader; }; } diff --git a/include/Nazara/Renderer/RenderDevice.hpp b/include/Nazara/Renderer/RenderDevice.hpp index 8132eb118..414c1d905 100644 --- a/include/Nazara/Renderer/RenderDevice.hpp +++ b/include/Nazara/Renderer/RenderDevice.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,8 @@ namespace Nz RenderDevice() = default; virtual ~RenderDevice(); + virtual const RenderDeviceInfo& GetDeviceInfo() const = 0; + virtual std::shared_ptr InstantiateBuffer(BufferType type) = 0; virtual std::shared_ptr InstantiateCommandPool(QueueType queueType) = 0; virtual std::shared_ptr InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr& renderPass, const std::vector>& attachments) = 0; diff --git a/include/Nazara/Renderer/RenderDeviceInfo.hpp b/include/Nazara/Renderer/RenderDeviceInfo.hpp index 5e6853ca0..d11f9e7c6 100644 --- a/include/Nazara/Renderer/RenderDeviceInfo.hpp +++ b/include/Nazara/Renderer/RenderDeviceInfo.hpp @@ -9,11 +9,18 @@ #include #include +#include namespace Nz { + struct RenderDeviceLimits + { + UInt64 minUniformBufferOffsetAlignment; + }; + struct RenderDeviceInfo { + RenderDeviceLimits limits; RenderDeviceType type; std::string name; }; diff --git a/include/Nazara/VulkanRenderer/Vulkan.hpp b/include/Nazara/VulkanRenderer/Vulkan.hpp index 12db5feb9..44368576e 100644 --- a/include/Nazara/VulkanRenderer/Vulkan.hpp +++ b/include/Nazara/VulkanRenderer/Vulkan.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,8 @@ namespace Nz Vulkan() = delete; ~Vulkan() = delete; + static RenderDeviceInfo BuildRenderDeviceInfo(const Vk::PhysicalDevice& physDevice); + static std::shared_ptr CreateDevice(const Vk::PhysicalDevice& deviceInfo); static std::shared_ptr CreateDevice(const Vk::PhysicalDevice& deviceInfo, const Vk::Surface& surface, UInt32* graphicsFamilyIndex, UInt32* presentableFamilyIndex, UInt32* transferFamilyIndex); static std::shared_ptr CreateDevice(const Vk::PhysicalDevice& deviceInfo, const QueueFamily* queueFamilies, std::size_t queueFamilyCount); @@ -43,7 +46,7 @@ namespace Nz static const std::vector& GetPhysicalDevices(); static const Vk::PhysicalDevice& GetPhysicalDeviceInfo(VkPhysicalDevice physDevice); - + static bool Initialize(UInt32 targetApiVersion, const ParameterList& parameters); static bool IsInitialized(); diff --git a/include/Nazara/VulkanRenderer/VulkanDevice.hpp b/include/Nazara/VulkanRenderer/VulkanDevice.hpp index 603532e18..df82f2392 100644 --- a/include/Nazara/VulkanRenderer/VulkanDevice.hpp +++ b/include/Nazara/VulkanRenderer/VulkanDevice.hpp @@ -18,11 +18,13 @@ namespace Nz class NAZARA_VULKANRENDERER_API VulkanDevice : public RenderDevice, public Vk::Device { public: - using Device::Device; + inline VulkanDevice(Vk::Instance& instance, RenderDeviceInfo renderDeviceInfo); VulkanDevice(const VulkanDevice&) = delete; VulkanDevice(VulkanDevice&&) = delete; ///TODO? ~VulkanDevice(); + const RenderDeviceInfo& GetDeviceInfo() const override; + std::shared_ptr InstantiateBuffer(BufferType type) override; std::shared_ptr InstantiateCommandPool(QueueType queueType) override; std::shared_ptr InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr& renderPass, const std::vector>& attachments) override; @@ -36,6 +38,9 @@ namespace Nz VulkanDevice& operator=(const VulkanDevice&) = delete; VulkanDevice& operator=(VulkanDevice&&) = delete; ///TODO? + + private: + RenderDeviceInfo m_renderDeviceInfo; }; } diff --git a/include/Nazara/VulkanRenderer/VulkanDevice.inl b/include/Nazara/VulkanRenderer/VulkanDevice.inl index dd44f8b19..6c5f8a58b 100644 --- a/include/Nazara/VulkanRenderer/VulkanDevice.inl +++ b/include/Nazara/VulkanRenderer/VulkanDevice.inl @@ -7,6 +7,11 @@ namespace Nz { + inline VulkanDevice::VulkanDevice(Vk::Instance& instance, RenderDeviceInfo renderDeviceInfo) : + Device(instance), + m_renderDeviceInfo(std::move(renderDeviceInfo)) + { + } } #include diff --git a/include/Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp b/include/Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp index 5e027252f..4b81e27fa 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp @@ -11,20 +11,17 @@ #include #include -namespace Nz +namespace Nz::Vk { - namespace Vk + struct PhysicalDevice { - struct PhysicalDevice - { - VkPhysicalDevice physDevice; - VkPhysicalDeviceFeatures features; - VkPhysicalDeviceMemoryProperties memoryProperties; - VkPhysicalDeviceProperties properties; - std::unordered_set extensions; - std::vector queueFamilies; - }; - } + VkPhysicalDevice physDevice; + VkPhysicalDeviceFeatures features; + VkPhysicalDeviceMemoryProperties memoryProperties; + VkPhysicalDeviceProperties properties; + std::unordered_set extensions; + std::vector queueFamilies; + }; } #endif // NAZARA_VULKANRENDERER_VKPHYSICALDEVICE_HPP diff --git a/src/Nazara/OpenGLRenderer/OpenGLDevice.cpp b/src/Nazara/OpenGLRenderer/OpenGLDevice.cpp index 902bfda5f..c48885bde 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLDevice.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLDevice.cpp @@ -26,6 +26,35 @@ namespace Nz if (!m_referenceContext) throw std::runtime_error("failed to create reference context"); + if (!GL::Context::SetCurrentContext(m_referenceContext.get())) + throw std::runtime_error("failed to activate reference context"); + + const GLubyte* vendorStr = m_referenceContext->glGetString(GL_VENDOR); + const GLubyte* rendererStr = m_referenceContext->glGetString(GL_RENDERER); + + m_deviceInfo.name = "OpenGL Device ("; + + if (vendorStr) + m_deviceInfo.name.append(reinterpret_cast(vendorStr)); + + if (rendererStr) + { + if (vendorStr) + m_deviceInfo.name += " - "; + + m_deviceInfo.name.append(reinterpret_cast(rendererStr)); + } + + m_deviceInfo.name += ')'; + + m_deviceInfo.type = RenderDeviceType::Unknown; + + GLint minUboOffsetAlignment; + m_referenceContext->glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &minUboOffsetAlignment); + + assert(minUboOffsetAlignment >= 1); + m_deviceInfo.limits.minUniformBufferOffsetAlignment = static_cast(minUboOffsetAlignment); + m_contexts.insert(m_referenceContext.get()); } @@ -50,6 +79,11 @@ namespace Nz return contextPtr; } + const RenderDeviceInfo& OpenGLDevice::GetDeviceInfo() const + { + return m_deviceInfo; + } + std::shared_ptr OpenGLDevice::InstantiateBuffer(BufferType type) { return std::make_shared(*this, type); diff --git a/src/Nazara/VulkanRenderer/Vulkan.cpp b/src/Nazara/VulkanRenderer/Vulkan.cpp index ba667ff8a..df7cc8439 100644 --- a/src/Nazara/VulkanRenderer/Vulkan.cpp +++ b/src/Nazara/VulkanRenderer/Vulkan.cpp @@ -16,6 +16,42 @@ namespace Nz { + RenderDeviceInfo Vulkan::BuildRenderDeviceInfo(const Vk::PhysicalDevice& physDevice) + { + RenderDeviceInfo deviceInfo; + deviceInfo.name = physDevice.properties.deviceName; + + deviceInfo.limits.minUniformBufferOffsetAlignment = physDevice.properties.limits.minUniformBufferOffsetAlignment; + + switch (physDevice.properties.deviceType) + { + case VK_PHYSICAL_DEVICE_TYPE_CPU: + deviceInfo.type = RenderDeviceType::Software; + break; + + case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: + deviceInfo.type = RenderDeviceType::Dedicated; + break; + + case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: + deviceInfo.type = RenderDeviceType::Integrated; + break; + + case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: + deviceInfo.type = RenderDeviceType::Virtual; + break; + + default: + NazaraWarning("Device " + deviceInfo.name + " has handled device type (0x" + NumberToString(physDevice.properties.deviceType, 16) + ')'); + // fallthrough + case VK_PHYSICAL_DEVICE_TYPE_OTHER: + deviceInfo.type = RenderDeviceType::Unknown; + break; + } + + return deviceInfo; + } + Vk::Instance& Vulkan::GetInstance() { return s_instance; @@ -508,7 +544,7 @@ namespace Nz nullptr }; - std::shared_ptr device = std::make_shared(s_instance); + std::shared_ptr device = std::make_shared(s_instance, BuildRenderDeviceInfo(deviceInfo)); if (!device->Create(deviceInfo, createInfo)) { NazaraError("Failed to create Vulkan Device: " + TranslateVulkanError(device->GetLastErrorCode())); diff --git a/src/Nazara/VulkanRenderer/VulkanDevice.cpp b/src/Nazara/VulkanRenderer/VulkanDevice.cpp index 464368c65..2ad97a936 100644 --- a/src/Nazara/VulkanRenderer/VulkanDevice.cpp +++ b/src/Nazara/VulkanRenderer/VulkanDevice.cpp @@ -17,6 +17,11 @@ namespace Nz { VulkanDevice::~VulkanDevice() = default; + const RenderDeviceInfo& VulkanDevice::GetDeviceInfo() const + { + return m_renderDeviceInfo; + } + std::shared_ptr VulkanDevice::InstantiateBuffer(BufferType type) { return std::make_shared(*this, type); diff --git a/src/Nazara/VulkanRenderer/VulkanRenderer.cpp b/src/Nazara/VulkanRenderer/VulkanRenderer.cpp index cb349a454..4fa5604e1 100644 --- a/src/Nazara/VulkanRenderer/VulkanRenderer.cpp +++ b/src/Nazara/VulkanRenderer/VulkanRenderer.cpp @@ -69,36 +69,7 @@ namespace Nz devices.reserve(physDevices.size()); for (const Vk::PhysicalDevice& physDevice : physDevices) - { - RenderDeviceInfo& device = devices.emplace_back(); - device.name = physDevice.properties.deviceName; - - switch (physDevice.properties.deviceType) - { - case VK_PHYSICAL_DEVICE_TYPE_CPU: - device.type = RenderDeviceType::Software; - break; - - case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: - device.type = RenderDeviceType::Dedicated; - break; - - case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: - device.type = RenderDeviceType::Integrated; - break; - - case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: - device.type = RenderDeviceType::Virtual; - break; - - default: - NazaraWarning("Device " + device.name + " has handled device type (0x" + NumberToString(physDevice.properties.deviceType, 16) + ')'); - // fallthrough - case VK_PHYSICAL_DEVICE_TYPE_OTHER: - device.type = RenderDeviceType::Unknown; - break; - } - } + devices.push_back(Vulkan::BuildRenderDeviceInfo(physDevice)); return devices; }