Renderer: RenderWindow now requires a RenderDevice

This commit is contained in:
Lynix 2021-05-16 23:13:00 +02:00
parent 40772f2137
commit 13feaf4aab
30 changed files with 132 additions and 107 deletions

View File

@ -57,16 +57,16 @@ int main()
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 180.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ_Normal_UV);
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
const Nz::RenderDeviceInfo& deviceInfo = device->GetDeviceInfo();
std::string windowTitle = "Graphics Test";
if (!window.Create(Nz::VideoMode(1280, 720, 32), windowTitle))
if (!window.Create(device, Nz::VideoMode(1280, 720, 32), windowTitle))
{
std::cout << "Failed to create Window" << std::endl;
return __LINE__;
}
std::shared_ptr<Nz::RenderDevice> device = window.GetRenderDevice();
const Nz::RenderDeviceInfo& deviceInfo = device->GetDeviceInfo();
Nz::MeshRef drfreak = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams);
if (!drfreak)
{

View File

@ -31,15 +31,15 @@ int main()
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 180.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ_Normal_UV);
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
std::string windowTitle = "Graphics Test";
if (!window.Create(Nz::VideoMode(800, 600, 32), windowTitle))
if (!window.Create(device, Nz::VideoMode(800, 600, 32), windowTitle))
{
std::cout << "Failed to create Window" << std::endl;
return __LINE__;
}
std::shared_ptr<Nz::RenderDevice> device = window.GetRenderDevice();
Nz::MeshRef drfreak = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams);
if (!drfreak)
{

View File

@ -90,15 +90,15 @@ int main()
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 180.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ_Normal_UV);
std::shared_ptr<Nz::RenderDevice> device = Nz::Renderer::Instance()->InstanciateRenderDevice(0);
std::string windowTitle = "Render Test";
if (!window.Create(Nz::VideoMode(800, 600, 32), windowTitle))
if (!window.Create(device, Nz::VideoMode(800, 600, 32), windowTitle))
{
std::cout << "Failed to create Window" << std::endl;
return __LINE__;
}
std::shared_ptr<Nz::RenderDevice> device = window.GetRenderDevice();
Nz::ShaderWriter::States states;
states.enabledOptions = 0;
states.optimize = true;

View File

@ -31,7 +31,7 @@ namespace Nz
Graphics(Config config);
~Graphics();
inline RenderDevice& GetRenderDevice();
inline const std::shared_ptr<RenderDevice>& GetRenderDevice() const;
inline TextureSamplerCache& GetSamplerCache();
inline const std::shared_ptr<AbstractBuffer>& GetViewerDataUBO();

View File

@ -7,9 +7,9 @@
namespace Nz
{
inline RenderDevice& Graphics::GetRenderDevice()
inline const std::shared_ptr<RenderDevice>& Graphics::GetRenderDevice() const
{
return *m_renderDevice;
return m_renderDevice;
}
inline TextureSamplerCache& Graphics::GetSamplerCache()

View File

@ -51,7 +51,7 @@ namespace Nz
});
}
m_pipelineLayout = Graphics::Instance()->GetRenderDevice().InstantiateRenderPipelineLayout(std::move(info));
m_pipelineLayout = Graphics::Instance()->GetRenderDevice()->InstantiateRenderPipelineLayout(std::move(info));
}
inline auto MaterialSettings::GetBuilderData() const -> const Builder&

View File

@ -37,13 +37,10 @@ namespace Nz
const OpenGLFramebuffer& GetFramebuffer() const override;
const OpenGLRenderPass& GetRenderPass() const override;
std::shared_ptr<RenderDevice> GetRenderDevice() override;
void Present();
private:
std::size_t m_currentFrame;
std::shared_ptr<OpenGLDevice> m_device;
std::vector<std::unique_ptr<OpenGLRenderImage>> m_renderImage;
std::unique_ptr<GL::Context> m_context;
OpenGLRenderPass m_renderPass;

View File

@ -19,7 +19,7 @@ namespace Nz
class NAZARA_OPENGLRENDERER_API OpenGLRenderer : public RendererImpl
{
public:
OpenGLRenderer() = default;
OpenGLRenderer();
~OpenGLRenderer();
std::unique_ptr<RenderSurface> CreateRenderSurfaceImpl() override;
@ -30,7 +30,7 @@ namespace Nz
RenderAPI QueryAPI() const override;
std::string QueryAPIString() const override;
UInt32 QueryAPIVersion() const override;
std::vector<RenderDeviceInfo> QueryRenderDevices() const override;
const std::vector<RenderDeviceInfo>& QueryRenderDevices() const override;
bool Prepare(const ParameterList& parameters) override;
@ -39,6 +39,7 @@ namespace Nz
std::shared_ptr<OpenGLDevice> m_device;
std::unique_ptr<GL::Loader> m_loader;
std::vector<RenderDeviceInfo> m_deviceInfos;
};
}

View File

@ -25,19 +25,19 @@ namespace Nz
{
public:
inline RenderWindow();
inline RenderWindow(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
inline explicit RenderWindow(void* handle, const RenderWindowParameters &parameters = RenderWindowParameters());
inline RenderWindow(std::shared_ptr<RenderDevice> renderDevice, VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
inline RenderWindow(std::shared_ptr<RenderDevice> renderDevice, void* handle, const RenderWindowParameters& parameters = RenderWindowParameters());
inline ~RenderWindow();
inline bool Create(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
inline bool Create(void* handle, const RenderWindowParameters &parameters = RenderWindowParameters());
bool Create(std::shared_ptr<RenderDevice> renderDevice, VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
bool Create(std::shared_ptr<RenderDevice> renderDevice, void* handle, const RenderWindowParameters &parameters = RenderWindowParameters());
void Display();
void EnableVerticalSync(bool enabled);
inline RenderWindowImpl* GetImpl();
std::shared_ptr<RenderDevice> GetRenderDevice();
inline const std::shared_ptr<RenderDevice>& GetRenderDevice() const;
inline RenderSurface* GetSurface();
inline bool IsValid() const;
@ -53,9 +53,10 @@ namespace Nz
void OnWindowResized() override;
private:
std::shared_ptr<RenderDevice> m_renderDevice;
std::unique_ptr<RenderSurface> m_surface;
std::unique_ptr<RenderWindowImpl> m_impl;
Clock m_clock;
std::unique_ptr<RenderSurface> m_surface;
RenderWindowParameters m_parameters;
unsigned int m_framerateLimit;
};

View File

@ -12,19 +12,19 @@ namespace Nz
{
}
inline RenderWindow::RenderWindow(VideoMode mode, const std::string& title, WindowStyleFlags style, const RenderWindowParameters& parameters) :
inline RenderWindow::RenderWindow(std::shared_ptr<RenderDevice> renderDevice, VideoMode mode, const std::string& title, WindowStyleFlags style, const RenderWindowParameters& parameters) :
RenderWindow()
{
ErrorFlags errFlags(ErrorFlag_ThrowException, true);
Create(mode, title, style, parameters);
Create(std::move(renderDevice), mode, title, style, parameters);
}
inline RenderWindow::RenderWindow(void* handle, const RenderWindowParameters& parameters)
inline RenderWindow::RenderWindow(std::shared_ptr<RenderDevice> renderDevice, void* handle, const RenderWindowParameters& parameters)
{
ErrorFlags errFlags(ErrorFlag_ThrowException, true);
Create(handle, parameters);
Create(std::move(renderDevice), handle, parameters);
}
inline RenderWindow::~RenderWindow()
@ -32,25 +32,16 @@ namespace Nz
Destroy();
}
inline bool RenderWindow::Create(VideoMode mode, const std::string& title, WindowStyleFlags style, const RenderWindowParameters& parameters)
{
m_parameters = parameters;
return Window::Create(mode, title, style);
}
inline bool RenderWindow::Create(void* handle, const RenderWindowParameters& parameters)
{
m_parameters = parameters;
return Window::Create(handle);
}
inline RenderWindowImpl* RenderWindow::GetImpl()
{
return m_impl.get();
}
inline const std::shared_ptr<RenderDevice>& RenderWindow::GetRenderDevice() const
{
return m_renderDevice;
}
inline RenderSurface* RenderWindow::GetSurface()
{
return m_surface.get();

View File

@ -20,6 +20,7 @@ namespace Nz
class CommandPool;
class Framebuffer;
class RendererImpl;
class RenderDevice;
class RenderPass;
class RenderSurface;
@ -35,7 +36,6 @@ namespace Nz
virtual std::shared_ptr<CommandPool> CreateCommandPool(QueueType queueType) = 0;
virtual const Framebuffer& GetFramebuffer() const = 0;
virtual std::shared_ptr<RenderDevice> GetRenderDevice() = 0;
virtual const RenderPass& GetRenderPass() const = 0;
};
}

View File

@ -34,6 +34,14 @@ namespace Nz
inline RendererImpl* GetRendererImpl();
std::shared_ptr<RenderDevice> InstanciateRenderDevice(std::size_t deviceIndex);
RenderAPI QueryAPI() const;
std::string QueryAPIString() const;
UInt32 QueryAPIVersion() const;
const std::vector<RenderDeviceInfo>& QueryRenderDevices() const;
struct Config
{
Nz::RenderAPI preferredAPI = Nz::RenderAPI::Unknown;

View File

@ -43,7 +43,7 @@ namespace Nz
virtual std::string QueryAPIString() const = 0;
virtual UInt32 QueryAPIVersion() const = 0;
virtual std::vector<RenderDeviceInfo> QueryRenderDevices() const = 0;
virtual const std::vector<RenderDeviceInfo>& QueryRenderDevices() const = 0;
virtual bool Prepare(const ParameterList& parameters) = 0;
};

View File

@ -55,8 +55,6 @@ namespace Nz
inline const VulkanRenderPass& GetRenderPass() const override;
inline const Vk::Swapchain& GetSwapchain() const;
inline std::shared_ptr<RenderDevice> GetRenderDevice() override;
void Present(UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE);
VkRenderWindow& operator=(const VkRenderWindow&) = delete;

View File

@ -36,11 +36,6 @@ namespace Nz
{
return m_swapchain;
}
inline std::shared_ptr<RenderDevice> VkRenderWindow::GetRenderDevice()
{
return m_device;
}
}
#include <Nazara/VulkanRenderer/DebugOff.hpp>

View File

@ -33,7 +33,7 @@ namespace Nz
RenderAPI QueryAPI() const override;
std::string QueryAPIString() const override;
UInt32 QueryAPIVersion() const override;
std::vector<RenderDeviceInfo> QueryRenderDevices() const override;
const std::vector<RenderDeviceInfo>& QueryRenderDevices() const override;
bool Prepare(const ParameterList& parameters) override;
@ -41,6 +41,7 @@ namespace Nz
private:
std::list<Vk::Device> m_devices;
std::vector<RenderDeviceInfo> m_deviceInfos;
ParameterList m_initializationParameters;
Vk::Instance m_instance;
};

View File

@ -16,8 +16,8 @@ namespace Nz
m_attachmentToTextureMapping(std::move(attachmentIdToTextureMapping)),
m_passIdToPhysicalPassMapping(std::move(passIdToPhysicalPassMapping))
{
RenderDevice& renderDevice = Graphics::Instance()->GetRenderDevice();
m_commandPool = renderDevice.InstantiateCommandPool(QueueType::Graphics);
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
m_commandPool = renderDevice->InstantiateCommandPool(QueueType::Graphics);
}
void BakedFrameGraph::Execute(RenderFrame& renderFrame)
@ -115,7 +115,7 @@ namespace Nz
void BakedFrameGraph::Resize(unsigned int width, unsigned int height)
{
RenderDevice& renderDevice = Graphics::Instance()->GetRenderDevice();
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
// Delete previous textures to make some room in VRAM
for (auto& passData : m_passes)
@ -136,7 +136,7 @@ namespace Nz
textureCreationParams.usageFlags = textureData.usage;
textureCreationParams.pixelFormat = textureData.format;
textureData.texture = renderDevice.InstantiateTexture(textureCreationParams);
textureData.texture = renderDevice->InstantiateTexture(textureCreationParams);
}
std::vector<std::shared_ptr<Texture>> textures;
@ -160,7 +160,7 @@ namespace Nz
passData.renderRect.Set(0, 0, int(framebufferWidth), int(framebufferHeight));
passData.framebuffer = renderDevice.InstantiateFramebuffer(framebufferWidth, framebufferHeight, passData.renderPass, textures);
passData.framebuffer = renderDevice->InstantiateFramebuffer(framebufferWidth, framebufferHeight, passData.renderPass, textures);
}
}
}

View File

@ -612,7 +612,7 @@ namespace Nz
void FrameGraph::BuildPhysicalPasses()
{
RenderDevice& renderDevice = Graphics::Instance()->GetRenderDevice();
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
std::unordered_map<std::size_t /*textureId*/, TextureLayout> textureLayouts;
@ -845,7 +845,7 @@ namespace Nz
BuildPhysicalPassDependencies(colorAttachmentCount, depthStencilAttachmentIndex.has_value(), renderPassAttachments, subpassesDesc, subpassesDeps);
m_pending.renderPasses.push_back(renderDevice.InstantiateRenderPass(std::move(renderPassAttachments), std::move(subpassesDesc), std::move(subpassesDeps)));
m_pending.renderPasses.push_back(renderDevice->InstantiateRenderPass(std::move(renderPassAttachments), std::move(subpassesDesc), std::move(subpassesDeps)));
physicalPassIndex++;
}

View File

@ -15,7 +15,7 @@ namespace Nz
{
assert(mesh->GetAnimationType() == AnimationType_Static);
RenderDevice& renderDevice = Graphics::Instance()->GetRenderDevice();
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
m_subMeshes.reserve(mesh->GetSubMeshCount());
for (std::size_t i = 0; i < mesh->GetSubMeshCount(); ++i)
@ -34,7 +34,7 @@ namespace Nz
const SoftwareBuffer* vertexBufferContent = static_cast<const SoftwareBuffer*>(vertexBuffer->GetBuffer()->GetImpl());
auto& submeshData = m_subMeshes.emplace_back();
submeshData.indexBuffer = renderDevice.InstantiateBuffer(BufferType_Index);
submeshData.indexBuffer = renderDevice->InstantiateBuffer(BufferType_Index);
if (!submeshData.indexBuffer->Initialize(indexBuffer->GetStride() * indexBuffer->GetIndexCount(), BufferUsage_DeviceLocal))
throw std::runtime_error("failed to create index buffer");
@ -43,7 +43,7 @@ namespace Nz
submeshData.indexCount = indexBuffer->GetIndexCount();
submeshData.vertexBuffer = renderDevice.InstantiateBuffer(BufferType_Vertex);
submeshData.vertexBuffer = renderDevice->InstantiateBuffer(BufferType_Vertex);
if (!submeshData.vertexBuffer->Initialize(vertexBuffer->GetStride() * vertexBuffer->GetVertexCount(), BufferUsage_DeviceLocal))
throw std::runtime_error("failed to create vertex buffer");

View File

@ -19,7 +19,6 @@ namespace Nz
ModuleBase("Graphics", this)
{
Renderer* renderer = Renderer::Instance();
RendererImpl* rendererImpl = renderer->GetRendererImpl(); //< FIXME
std::vector<RenderDeviceInfo> renderDeviceInfo = rendererImpl->QueryRenderDevices();
if (renderDeviceInfo.empty())
throw std::runtime_error("no render device available");
@ -35,7 +34,7 @@ namespace Nz
}
}
m_renderDevice = rendererImpl->InstanciateRenderDevice(bestRenderDeviceIndex);
m_renderDevice = renderer->InstanciateRenderDevice(bestRenderDeviceIndex);
if (!m_renderDevice)
throw std::runtime_error("failed to instantiate render device");

View File

@ -43,7 +43,7 @@ namespace Nz
{
auto& uniformBuffer = m_uniformBuffers.emplace_back();
uniformBuffer.buffer = Graphics::Instance()->GetRenderDevice().InstantiateBuffer(Nz::BufferType_Uniform);
uniformBuffer.buffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(Nz::BufferType_Uniform);
if (!uniformBuffer.buffer->Initialize(uniformBufferInfo.blockSize, BufferUsage_Dynamic))
throw std::runtime_error("failed to initialize UBO memory");

View File

@ -56,7 +56,7 @@ namespace Nz
renderPipelineInfo.vertexBuffers = vertexBuffers;
return m_renderPipelines.emplace_back(Graphics::Instance()->GetRenderDevice().InstantiateRenderPipeline(std::move(renderPipelineInfo)));
return m_renderPipelines.emplace_back(Graphics::Instance()->GetRenderDevice()->InstantiateRenderPipeline(std::move(renderPipelineInfo)));
}
/*!
* \brief Returns a reference to a MaterialPipeline built with MaterialPipelineInfo

View File

@ -15,7 +15,7 @@ namespace Nz
{
Nz::PredefinedInstanceData instanceUboOffsets = Nz::PredefinedInstanceData::GetOffsets();
m_instanceDataBuffer = Graphics::Instance()->GetRenderDevice().InstantiateBuffer(BufferType_Uniform);
m_instanceDataBuffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(BufferType_Uniform);
if (!m_instanceDataBuffer->Initialize(instanceUboOffsets.totalSize, Nz::BufferUsage_DeviceLocal | Nz::BufferUsage_Dynamic))
throw std::runtime_error("failed to initialize viewer data UBO");

View File

@ -61,7 +61,7 @@ namespace Nz
states.enabledOptions = combination;
states.sanitized = true;
std::shared_ptr<ShaderModule> stage = Graphics::Instance()->GetRenderDevice().InstantiateShaderModule(m_shaderStage, m_shaderAst, std::move(states));
std::shared_ptr<ShaderModule> stage = Graphics::Instance()->GetRenderDevice()->InstantiateShaderModule(m_shaderStage, m_shaderAst, std::move(states));
it = m_combinations.emplace(combination, std::move(stage)).first;
}

View File

@ -41,11 +41,11 @@ namespace Nz
DummySurface* dummySurface = static_cast<DummySurface*>(surface);
OpenGLRenderer* glRenderer = static_cast<OpenGLRenderer*>(renderer);
m_device = std::static_pointer_cast<OpenGLDevice>(glRenderer->InstanciateRenderDevice(0));
OpenGLDevice& device = static_cast<OpenGLDevice&>(*m_owner.GetRenderDevice());
GL::ContextParams contextParams;
m_context = m_device->CreateContext(contextParams, dummySurface->GetWindowHandle());
m_context = device.CreateContext(contextParams, dummySurface->GetWindowHandle());
if (!m_context)
return false;
@ -75,11 +75,6 @@ namespace Nz
return m_renderPass;
}
std::shared_ptr<RenderDevice> OpenGLRenderWindow::GetRenderDevice()
{
return m_device;
}
void OpenGLRenderWindow::Present()
{
m_context->SwapBuffers();

View File

@ -24,6 +24,13 @@
namespace Nz
{
OpenGLRenderer::OpenGLRenderer()
{
auto& dummyDevice = m_deviceInfos.emplace_back();
dummyDevice.name = "OpenGL Default Device";
dummyDevice.type = RenderDeviceType::Unknown;
}
OpenGLRenderer::~OpenGLRenderer()
{
m_device.reset();
@ -107,13 +114,8 @@ namespace Nz
return 300;
}
std::vector<RenderDeviceInfo> OpenGLRenderer::QueryRenderDevices() const
const std::vector<RenderDeviceInfo>& OpenGLRenderer::QueryRenderDevices() const
{
std::vector<RenderDeviceInfo> devices;
auto& dummyDevice = devices.emplace_back();
dummyDevice.name = "OpenGL Default Device";
dummyDevice.type = RenderDeviceType::Unknown;
return devices;
return m_deviceInfos;
}
}

View File

@ -11,6 +11,22 @@
namespace Nz
{
bool RenderWindow::Create(std::shared_ptr<RenderDevice> renderDevice, VideoMode mode, const std::string& title, WindowStyleFlags style, const RenderWindowParameters& parameters)
{
m_parameters = parameters;
m_renderDevice = std::move(renderDevice);
return Window::Create(mode, title, style);
}
bool RenderWindow::Create(std::shared_ptr<RenderDevice> renderDevice, void* handle, const RenderWindowParameters& parameters)
{
m_parameters = parameters;
m_renderDevice = std::move(renderDevice);
return Window::Create(handle);
}
void RenderWindow::Display()
{
if (m_framerateLimit > 0)
@ -28,17 +44,9 @@ namespace Nz
///TODO
}
std::shared_ptr<RenderDevice> RenderWindow::GetRenderDevice()
{
if (!m_impl)
return std::shared_ptr<RenderDevice>();
return m_impl->GetRenderDevice();
}
bool RenderWindow::OnWindowCreated()
{
RendererImpl *rendererImpl = Renderer::Instance()->GetRendererImpl();
RendererImpl* rendererImpl = Renderer::Instance()->GetRendererImpl();
auto surface = rendererImpl->CreateRenderSurfaceImpl();
if (!surface->Create(GetSystemHandle()))
{
@ -64,6 +72,7 @@ namespace Nz
void RenderWindow::OnWindowDestroy()
{
m_impl.reset();
m_renderDevice.reset();
m_surface.reset();
}

View File

@ -134,5 +134,30 @@ namespace Nz
m_rendererImpl.reset();
}
std::shared_ptr<RenderDevice> Renderer::InstanciateRenderDevice(std::size_t deviceIndex)
{
return m_rendererImpl->InstanciateRenderDevice(deviceIndex);
}
RenderAPI Renderer::QueryAPI() const
{
return m_rendererImpl->QueryAPI();
}
std::string Renderer::QueryAPIString() const
{
return m_rendererImpl->QueryAPIString();
}
UInt32 Renderer::QueryAPIVersion() const
{
return m_rendererImpl->QueryAPIVersion();
}
const std::vector<RenderDeviceInfo>& Renderer::QueryRenderDevices() const
{
return m_rendererImpl->QueryRenderDevices();
}
Renderer* Renderer::s_instance = nullptr;
}

View File

@ -105,14 +105,16 @@ namespace Nz
bool VkRenderWindow::Create(RendererImpl* /*renderer*/, RenderSurface* surface, const RenderWindowParameters& parameters)
{
const auto& deviceInfo = Vulkan::GetPhysicalDevices()[0];
VulkanDevice& referenceDevice = static_cast<VulkanDevice&>(*m_owner.GetRenderDevice());
const auto& physDeviceInfo = referenceDevice.GetPhysicalDeviceInfo();
Vk::Surface& vulkanSurface = static_cast<VulkanSurface*>(surface)->GetSurface();
UInt32 graphicsFamilyQueueIndex;
UInt32 presentableFamilyQueueIndex;
UInt32 transferFamilyQueueIndex;
m_device = Vulkan::SelectDevice(deviceInfo, vulkanSurface, &graphicsFamilyQueueIndex, &presentableFamilyQueueIndex, &transferFamilyQueueIndex);
m_device = Vulkan::SelectDevice(physDeviceInfo, vulkanSurface, &graphicsFamilyQueueIndex, &presentableFamilyQueueIndex, &transferFamilyQueueIndex);
if (!m_device)
{
NazaraError("Failed to get compatible Vulkan device");
@ -124,7 +126,7 @@ namespace Nz
m_transferQueue = m_device->GetQueue(transferFamilyQueueIndex, 0);
std::vector<VkSurfaceFormatKHR> surfaceFormats;
if (!vulkanSurface.GetFormats(deviceInfo.physDevice, &surfaceFormats))
if (!vulkanSurface.GetFormats(physDeviceInfo.physDevice, &surfaceFormats))
{
NazaraError("Failed to query supported surface formats");
return false;
@ -192,7 +194,7 @@ namespace Nz
if (m_depthStencilFormat != VK_FORMAT_MAX_ENUM)
{
VkFormatProperties formatProperties = m_device->GetInstance().GetPhysicalDeviceFormatProperties(deviceInfo.physDevice, m_depthStencilFormat);
VkFormatProperties formatProperties = m_device->GetInstance().GetPhysicalDeviceFormatProperties(physDeviceInfo.physDevice, m_depthStencilFormat);
if (formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
break; //< Found it

View File

@ -40,7 +40,16 @@ namespace Nz
bool VulkanRenderer::Prepare(const ParameterList& parameters)
{
return Vulkan::Initialize(APIVersion, parameters);
if (!Vulkan::Initialize(APIVersion, parameters))
return false;
const auto& physDevices = Vulkan::GetPhysicalDevices();
m_deviceInfos.reserve(physDevices.size());
for (const Vk::PhysicalDevice& physDevice : physDevices)
m_deviceInfos.push_back(Vulkan::BuildRenderDeviceInfo(physDevice));
return true;
}
RenderAPI VulkanRenderer::QueryAPI() const
@ -61,16 +70,8 @@ namespace Nz
return APIVersion;
}
std::vector<RenderDeviceInfo> VulkanRenderer::QueryRenderDevices() const
const std::vector<RenderDeviceInfo>& VulkanRenderer::QueryRenderDevices() const
{
const auto& physDevices = Vulkan::GetPhysicalDevices();
std::vector<RenderDeviceInfo> devices;
devices.reserve(physDevices.size());
for (const Vk::PhysicalDevice& physDevice : physDevices)
devices.push_back(Vulkan::BuildRenderDeviceInfo(physDevice));
return devices;
return m_deviceInfos;
}
}