Renderer: Add RenderDevice::GetDeviceInfo()
This commit is contained in:
parent
adbf1e1da0
commit
aeac3282e4
|
|
@ -12,6 +12,7 @@
|
||||||
#include <Nazara/OpenGLRenderer/Config.hpp>
|
#include <Nazara/OpenGLRenderer/Config.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
|
||||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
@ -30,6 +31,7 @@ namespace Nz
|
||||||
std::unique_ptr<GL::Context> CreateContext(const GL::ContextParams& params) const;
|
std::unique_ptr<GL::Context> CreateContext(const GL::ContextParams& params) const;
|
||||||
std::unique_ptr<GL::Context> CreateContext(const GL::ContextParams& params, WindowHandle handle) const;
|
std::unique_ptr<GL::Context> CreateContext(const GL::ContextParams& params, WindowHandle handle) const;
|
||||||
|
|
||||||
|
const RenderDeviceInfo& GetDeviceInfo() const override;
|
||||||
inline const GL::Context& GetReferenceContext() const;
|
inline const GL::Context& GetReferenceContext() const;
|
||||||
|
|
||||||
std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) override;
|
std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) override;
|
||||||
|
|
@ -57,6 +59,7 @@ namespace Nz
|
||||||
|
|
||||||
std::unique_ptr<GL::Context> m_referenceContext;
|
std::unique_ptr<GL::Context> m_referenceContext;
|
||||||
mutable std::unordered_set<const GL::Context*> m_contexts;
|
mutable std::unordered_set<const GL::Context*> m_contexts;
|
||||||
|
RenderDeviceInfo m_deviceInfo;
|
||||||
GL::Loader& m_loader;
|
GL::Loader& m_loader;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <Nazara/Renderer/Config.hpp>
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
#include <Nazara/Renderer/Enums.hpp>
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
#include <Nazara/Renderer/Framebuffer.hpp>
|
#include <Nazara/Renderer/Framebuffer.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
||||||
#include <Nazara/Renderer/RenderPass.hpp>
|
#include <Nazara/Renderer/RenderPass.hpp>
|
||||||
#include <Nazara/Renderer/RenderPipeline.hpp>
|
#include <Nazara/Renderer/RenderPipeline.hpp>
|
||||||
#include <Nazara/Renderer/RenderPipelineLayout.hpp>
|
#include <Nazara/Renderer/RenderPipelineLayout.hpp>
|
||||||
|
|
@ -33,6 +34,8 @@ namespace Nz
|
||||||
RenderDevice() = default;
|
RenderDevice() = default;
|
||||||
virtual ~RenderDevice();
|
virtual ~RenderDevice();
|
||||||
|
|
||||||
|
virtual const RenderDeviceInfo& GetDeviceInfo() const = 0;
|
||||||
|
|
||||||
virtual std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) = 0;
|
virtual std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) = 0;
|
||||||
virtual std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) = 0;
|
virtual std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) = 0;
|
||||||
virtual std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) = 0;
|
virtual std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) = 0;
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,18 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Renderer/Enums.hpp>
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
struct RenderDeviceLimits
|
||||||
|
{
|
||||||
|
UInt64 minUniformBufferOffsetAlignment;
|
||||||
|
};
|
||||||
|
|
||||||
struct RenderDeviceInfo
|
struct RenderDeviceInfo
|
||||||
{
|
{
|
||||||
|
RenderDeviceLimits limits;
|
||||||
RenderDeviceType type;
|
RenderDeviceType type;
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Core/Initializer.hpp>
|
#include <Nazara/Core/Initializer.hpp>
|
||||||
#include <Nazara/Core/ParameterList.hpp>
|
#include <Nazara/Core/ParameterList.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
|
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Wrapper/Instance.hpp>
|
#include <Nazara/VulkanRenderer/Wrapper/Instance.hpp>
|
||||||
|
|
@ -35,6 +36,8 @@ namespace Nz
|
||||||
Vulkan() = delete;
|
Vulkan() = delete;
|
||||||
~Vulkan() = delete;
|
~Vulkan() = delete;
|
||||||
|
|
||||||
|
static RenderDeviceInfo BuildRenderDeviceInfo(const Vk::PhysicalDevice& physDevice);
|
||||||
|
|
||||||
static std::shared_ptr<VulkanDevice> CreateDevice(const Vk::PhysicalDevice& deviceInfo);
|
static std::shared_ptr<VulkanDevice> CreateDevice(const Vk::PhysicalDevice& deviceInfo);
|
||||||
static std::shared_ptr<VulkanDevice> CreateDevice(const Vk::PhysicalDevice& deviceInfo, const Vk::Surface& surface, UInt32* graphicsFamilyIndex, UInt32* presentableFamilyIndex, UInt32* transferFamilyIndex);
|
static std::shared_ptr<VulkanDevice> CreateDevice(const Vk::PhysicalDevice& deviceInfo, const Vk::Surface& surface, UInt32* graphicsFamilyIndex, UInt32* presentableFamilyIndex, UInt32* transferFamilyIndex);
|
||||||
static std::shared_ptr<VulkanDevice> CreateDevice(const Vk::PhysicalDevice& deviceInfo, const QueueFamily* queueFamilies, std::size_t queueFamilyCount);
|
static std::shared_ptr<VulkanDevice> CreateDevice(const Vk::PhysicalDevice& deviceInfo, const QueueFamily* queueFamilies, std::size_t queueFamilyCount);
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,13 @@ namespace Nz
|
||||||
class NAZARA_VULKANRENDERER_API VulkanDevice : public RenderDevice, public Vk::Device
|
class NAZARA_VULKANRENDERER_API VulkanDevice : public RenderDevice, public Vk::Device
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Device::Device;
|
inline VulkanDevice(Vk::Instance& instance, RenderDeviceInfo renderDeviceInfo);
|
||||||
VulkanDevice(const VulkanDevice&) = delete;
|
VulkanDevice(const VulkanDevice&) = delete;
|
||||||
VulkanDevice(VulkanDevice&&) = delete; ///TODO?
|
VulkanDevice(VulkanDevice&&) = delete; ///TODO?
|
||||||
~VulkanDevice();
|
~VulkanDevice();
|
||||||
|
|
||||||
|
const RenderDeviceInfo& GetDeviceInfo() const override;
|
||||||
|
|
||||||
std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) override;
|
std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) override;
|
||||||
std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) override;
|
std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) override;
|
||||||
std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) override;
|
std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) override;
|
||||||
|
|
@ -36,6 +38,9 @@ namespace Nz
|
||||||
|
|
||||||
VulkanDevice& operator=(const VulkanDevice&) = delete;
|
VulkanDevice& operator=(const VulkanDevice&) = delete;
|
||||||
VulkanDevice& operator=(VulkanDevice&&) = delete; ///TODO?
|
VulkanDevice& operator=(VulkanDevice&&) = delete; ///TODO?
|
||||||
|
|
||||||
|
private:
|
||||||
|
RenderDeviceInfo m_renderDeviceInfo;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,11 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
inline VulkanDevice::VulkanDevice(Vk::Instance& instance, RenderDeviceInfo renderDeviceInfo) :
|
||||||
|
Device(instance),
|
||||||
|
m_renderDeviceInfo(std::move(renderDeviceInfo))
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,8 @@
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz::Vk
|
||||||
{
|
{
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
struct PhysicalDevice
|
struct PhysicalDevice
|
||||||
{
|
{
|
||||||
VkPhysicalDevice physDevice;
|
VkPhysicalDevice physDevice;
|
||||||
|
|
@ -24,7 +22,6 @@ namespace Nz
|
||||||
std::unordered_set<std::string> extensions;
|
std::unordered_set<std::string> extensions;
|
||||||
std::vector<VkQueueFamilyProperties> queueFamilies;
|
std::vector<VkQueueFamilyProperties> queueFamilies;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NAZARA_VULKANRENDERER_VKPHYSICALDEVICE_HPP
|
#endif // NAZARA_VULKANRENDERER_VKPHYSICALDEVICE_HPP
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,35 @@ namespace Nz
|
||||||
if (!m_referenceContext)
|
if (!m_referenceContext)
|
||||||
throw std::runtime_error("failed to create reference context");
|
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<const char*>(vendorStr));
|
||||||
|
|
||||||
|
if (rendererStr)
|
||||||
|
{
|
||||||
|
if (vendorStr)
|
||||||
|
m_deviceInfo.name += " - ";
|
||||||
|
|
||||||
|
m_deviceInfo.name.append(reinterpret_cast<const char*>(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<UInt64>(minUboOffsetAlignment);
|
||||||
|
|
||||||
m_contexts.insert(m_referenceContext.get());
|
m_contexts.insert(m_referenceContext.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,6 +79,11 @@ namespace Nz
|
||||||
return contextPtr;
|
return contextPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const RenderDeviceInfo& OpenGLDevice::GetDeviceInfo() const
|
||||||
|
{
|
||||||
|
return m_deviceInfo;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<AbstractBuffer> OpenGLDevice::InstantiateBuffer(BufferType type)
|
std::shared_ptr<AbstractBuffer> OpenGLDevice::InstantiateBuffer(BufferType type)
|
||||||
{
|
{
|
||||||
return std::make_shared<OpenGLBuffer>(*this, type);
|
return std::make_shared<OpenGLBuffer>(*this, type);
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,42 @@
|
||||||
|
|
||||||
namespace Nz
|
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()
|
Vk::Instance& Vulkan::GetInstance()
|
||||||
{
|
{
|
||||||
return s_instance;
|
return s_instance;
|
||||||
|
|
@ -508,7 +544,7 @@ namespace Nz
|
||||||
nullptr
|
nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<VulkanDevice> device = std::make_shared<VulkanDevice>(s_instance);
|
std::shared_ptr<VulkanDevice> device = std::make_shared<VulkanDevice>(s_instance, BuildRenderDeviceInfo(deviceInfo));
|
||||||
if (!device->Create(deviceInfo, createInfo))
|
if (!device->Create(deviceInfo, createInfo))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to create Vulkan Device: " + TranslateVulkanError(device->GetLastErrorCode()));
|
NazaraError("Failed to create Vulkan Device: " + TranslateVulkanError(device->GetLastErrorCode()));
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,11 @@ namespace Nz
|
||||||
{
|
{
|
||||||
VulkanDevice::~VulkanDevice() = default;
|
VulkanDevice::~VulkanDevice() = default;
|
||||||
|
|
||||||
|
const RenderDeviceInfo& VulkanDevice::GetDeviceInfo() const
|
||||||
|
{
|
||||||
|
return m_renderDeviceInfo;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<AbstractBuffer> VulkanDevice::InstantiateBuffer(BufferType type)
|
std::shared_ptr<AbstractBuffer> VulkanDevice::InstantiateBuffer(BufferType type)
|
||||||
{
|
{
|
||||||
return std::make_shared<VulkanBuffer>(*this, type);
|
return std::make_shared<VulkanBuffer>(*this, type);
|
||||||
|
|
|
||||||
|
|
@ -69,36 +69,7 @@ namespace Nz
|
||||||
devices.reserve(physDevices.size());
|
devices.reserve(physDevices.size());
|
||||||
|
|
||||||
for (const Vk::PhysicalDevice& physDevice : physDevices)
|
for (const Vk::PhysicalDevice& physDevice : physDevices)
|
||||||
{
|
devices.push_back(Vulkan::BuildRenderDeviceInfo(physDevice));
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue