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/Wrapper/Context.hpp>
|
||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
||||
#include <unordered_set>
|
||||
#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, WindowHandle handle) const;
|
||||
|
||||
const RenderDeviceInfo& GetDeviceInfo() const override;
|
||||
inline const GL::Context& GetReferenceContext() const;
|
||||
|
||||
std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) override;
|
||||
|
|
@ -57,6 +59,7 @@ namespace Nz
|
|||
|
||||
std::unique_ptr<GL::Context> m_referenceContext;
|
||||
mutable std::unordered_set<const GL::Context*> m_contexts;
|
||||
RenderDeviceInfo m_deviceInfo;
|
||||
GL::Loader& m_loader;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Renderer/Framebuffer.hpp>
|
||||
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
||||
#include <Nazara/Renderer/RenderPass.hpp>
|
||||
#include <Nazara/Renderer/RenderPipeline.hpp>
|
||||
#include <Nazara/Renderer/RenderPipelineLayout.hpp>
|
||||
|
|
@ -33,6 +34,8 @@ namespace Nz
|
|||
RenderDevice() = default;
|
||||
virtual ~RenderDevice();
|
||||
|
||||
virtual const RenderDeviceInfo& GetDeviceInfo() const = 0;
|
||||
|
||||
virtual std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) = 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;
|
||||
|
|
|
|||
|
|
@ -9,11 +9,18 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct RenderDeviceLimits
|
||||
{
|
||||
UInt64 minUniformBufferOffsetAlignment;
|
||||
};
|
||||
|
||||
struct RenderDeviceInfo
|
||||
{
|
||||
RenderDeviceLimits limits;
|
||||
RenderDeviceType type;
|
||||
std::string name;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
#include <Nazara/Core/ParameterList.hpp>
|
||||
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Instance.hpp>
|
||||
|
|
@ -35,6 +36,8 @@ namespace Nz
|
|||
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, 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);
|
||||
|
|
@ -43,7 +46,7 @@ namespace Nz
|
|||
|
||||
static const std::vector<Vk::PhysicalDevice>& GetPhysicalDevices();
|
||||
static const Vk::PhysicalDevice& GetPhysicalDeviceInfo(VkPhysicalDevice physDevice);
|
||||
|
||||
|
||||
static bool Initialize(UInt32 targetApiVersion, const ParameterList& parameters);
|
||||
|
||||
static bool IsInitialized();
|
||||
|
|
|
|||
|
|
@ -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<AbstractBuffer> InstantiateBuffer(BufferType type) 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;
|
||||
|
|
@ -36,6 +38,9 @@ namespace Nz
|
|||
|
||||
VulkanDevice& operator=(const VulkanDevice&) = delete;
|
||||
VulkanDevice& operator=(VulkanDevice&&) = delete; ///TODO?
|
||||
|
||||
private:
|
||||
RenderDeviceInfo m_renderDeviceInfo;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
inline VulkanDevice::VulkanDevice(Vk::Instance& instance, RenderDeviceInfo renderDeviceInfo) :
|
||||
Device(instance),
|
||||
m_renderDeviceInfo(std::move(renderDeviceInfo))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -11,20 +11,17 @@
|
|||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::Vk
|
||||
{
|
||||
namespace Vk
|
||||
struct PhysicalDevice
|
||||
{
|
||||
struct PhysicalDevice
|
||||
{
|
||||
VkPhysicalDevice physDevice;
|
||||
VkPhysicalDeviceFeatures features;
|
||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||
VkPhysicalDeviceProperties properties;
|
||||
std::unordered_set<std::string> extensions;
|
||||
std::vector<VkQueueFamilyProperties> queueFamilies;
|
||||
};
|
||||
}
|
||||
VkPhysicalDevice physDevice;
|
||||
VkPhysicalDeviceFeatures features;
|
||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||
VkPhysicalDeviceProperties properties;
|
||||
std::unordered_set<std::string> extensions;
|
||||
std::vector<VkQueueFamilyProperties> queueFamilies;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKPHYSICALDEVICE_HPP
|
||||
|
|
|
|||
|
|
@ -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<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());
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +79,11 @@ namespace Nz
|
|||
return contextPtr;
|
||||
}
|
||||
|
||||
const RenderDeviceInfo& OpenGLDevice::GetDeviceInfo() const
|
||||
{
|
||||
return m_deviceInfo;
|
||||
}
|
||||
|
||||
std::shared_ptr<AbstractBuffer> OpenGLDevice::InstantiateBuffer(BufferType type)
|
||||
{
|
||||
return std::make_shared<OpenGLBuffer>(*this, type);
|
||||
|
|
|
|||
|
|
@ -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<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))
|
||||
{
|
||||
NazaraError("Failed to create Vulkan Device: " + TranslateVulkanError(device->GetLastErrorCode()));
|
||||
|
|
|
|||
|
|
@ -17,6 +17,11 @@ namespace Nz
|
|||
{
|
||||
VulkanDevice::~VulkanDevice() = default;
|
||||
|
||||
const RenderDeviceInfo& VulkanDevice::GetDeviceInfo() const
|
||||
{
|
||||
return m_renderDeviceInfo;
|
||||
}
|
||||
|
||||
std::shared_ptr<AbstractBuffer> VulkanDevice::InstantiateBuffer(BufferType type)
|
||||
{
|
||||
return std::make_shared<VulkanBuffer>(*this, type);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue