Merge branch 'master' into vulkan
Former-commit-id: b13aa203a598667deb32eb7bc565377639a780dc [formerly 323ddcd0304d695bb1771c8cb940659f056b32d8] [formerly 2cfd96caad43772ede5a88f8cbae1a70b136a8c9 [formerly f37355fbdc3845fc3304f0a878e50e89772608a5]] Former-commit-id: 10126f258988cf17ea8b4524a81bff0cb2160cc4 [formerly f4381ead0f258e9ab99e198b61324a011515bbf3] Former-commit-id: 0fa94c32d68cef4bfa64e78f8a5f97f8fa270333
This commit is contained in:
commit
24a9993c10
|
|
@ -270,7 +270,6 @@ function NazaraBuild:Execute()
|
||||||
project(prefix .. toolTable.Name)
|
project(prefix .. toolTable.Name)
|
||||||
|
|
||||||
location(_ACTION .. "/tools")
|
location(_ACTION .. "/tools")
|
||||||
targetdir(toolTable.TargetDirectory)
|
|
||||||
|
|
||||||
if (toolTable.Kind == "plugin" or toolTable.Kind == "library") then
|
if (toolTable.Kind == "plugin" or toolTable.Kind == "library") then
|
||||||
kind("SharedLib")
|
kind("SharedLib")
|
||||||
|
|
@ -296,6 +295,8 @@ function NazaraBuild:Execute()
|
||||||
libdirs("../lib")
|
libdirs("../lib")
|
||||||
libdirs("../extlibs/lib/common")
|
libdirs("../extlibs/lib/common")
|
||||||
|
|
||||||
|
targetdir(toolTable.TargetDirectory)
|
||||||
|
|
||||||
configuration("x32")
|
configuration("x32")
|
||||||
libdirs(toolTable.LibraryPaths.x86)
|
libdirs(toolTable.LibraryPaths.x86)
|
||||||
|
|
||||||
|
|
@ -305,18 +306,17 @@ function NazaraBuild:Execute()
|
||||||
|
|
||||||
configuration({"codeblocks or codelite or gmake", "x32"})
|
configuration({"codeblocks or codelite or gmake", "x32"})
|
||||||
libdirs("../extlibs/lib/" .. makeLibDir .. "/x86")
|
libdirs("../extlibs/lib/" .. makeLibDir .. "/x86")
|
||||||
libdirs("../lib/" .. makeLibDir .. "/x86")
|
libdirs(toolTable.TargetDirectory .. "/" .. makeLibDir .. "/x86")
|
||||||
if (toolTable.Kind == "library") then
|
if (toolTable.Kind == "library") then
|
||||||
targetdir("../lib/" .. makeLibDir .. "/x86")
|
targetdir(toolTable.TargetDirectory .. "/" .. makeLibDir .. "/x86")
|
||||||
elseif (toolTable.Kind == "plugin") then
|
elseif (toolTable.Kind == "plugin") then
|
||||||
targetdir("../plugins/" .. toolTable.Name .. "/lib/" .. makeLibDir .. "/x86")
|
targetdir("../plugins/" .. toolTable.Name .. "/lib/" .. makeLibDir .. "/x86")
|
||||||
end
|
end
|
||||||
|
|
||||||
configuration({"codeblocks or codelite or gmake", "x64"})
|
configuration({"codeblocks or codelite or gmake", "x64"})
|
||||||
libdirs("../extlibs/lib/" .. makeLibDir .. "/x64")
|
libdirs("../extlibs/lib/" .. makeLibDir .. "/x64")
|
||||||
libdirs("../lib/" .. makeLibDir .. "/x64")
|
|
||||||
if (toolTable.Kind == "library") then
|
if (toolTable.Kind == "library") then
|
||||||
targetdir("../lib/" .. makeLibDir .. "/x64")
|
targetdir(toolTable.TargetDirectory .. "/" .. makeLibDir .. "/x64")
|
||||||
elseif (toolTable.Kind == "plugin") then
|
elseif (toolTable.Kind == "plugin") then
|
||||||
targetdir("../plugins/" .. toolTable.Name .. "/lib/" .. makeLibDir .. "/x64")
|
targetdir("../plugins/" .. toolTable.Name .. "/lib/" .. makeLibDir .. "/x64")
|
||||||
end
|
end
|
||||||
|
|
@ -325,7 +325,7 @@ function NazaraBuild:Execute()
|
||||||
libdirs("../extlibs/lib/msvc/x86")
|
libdirs("../extlibs/lib/msvc/x86")
|
||||||
libdirs("../lib/msvc/x86")
|
libdirs("../lib/msvc/x86")
|
||||||
if (toolTable.Kind == "library") then
|
if (toolTable.Kind == "library") then
|
||||||
targetdir("../lib/msvc/x86")
|
targetdir(toolTable.TargetDirectory .. "/msvc/x86")
|
||||||
elseif (toolTable.Kind == "plugin") then
|
elseif (toolTable.Kind == "plugin") then
|
||||||
targetdir("../plugins/" .. toolTable.Name .. "/lib/msvc/x86")
|
targetdir("../plugins/" .. toolTable.Name .. "/lib/msvc/x86")
|
||||||
end
|
end
|
||||||
|
|
@ -334,7 +334,7 @@ function NazaraBuild:Execute()
|
||||||
libdirs("../extlibs/lib/msvc/x64")
|
libdirs("../extlibs/lib/msvc/x64")
|
||||||
libdirs("../lib/msvc/x64")
|
libdirs("../lib/msvc/x64")
|
||||||
if (toolTable.Kind == "library") then
|
if (toolTable.Kind == "library") then
|
||||||
targetdir("../lib/msvc/x64")
|
targetdir(toolTable.TargetDirectory .. "/msvc/x64")
|
||||||
elseif (toolTable.Kind == "plugin") then
|
elseif (toolTable.Kind == "plugin") then
|
||||||
targetdir("../plugins/" .. toolTable.Name .. "/lib/msvc/x64")
|
targetdir("../plugins/" .. toolTable.Name .. "/lib/msvc/x64")
|
||||||
end
|
end
|
||||||
|
|
@ -343,7 +343,7 @@ function NazaraBuild:Execute()
|
||||||
libdirs("../extlibs/lib/xcode/x86")
|
libdirs("../extlibs/lib/xcode/x86")
|
||||||
libdirs("../lib/xcode/x86")
|
libdirs("../lib/xcode/x86")
|
||||||
if (toolTable.Kind == "library") then
|
if (toolTable.Kind == "library") then
|
||||||
targetdir("../lib/xcode/x86")
|
targetdir(toolTable.TargetDirectory .. "/xcode/x86")
|
||||||
elseif (toolTable.Kind == "plugin") then
|
elseif (toolTable.Kind == "plugin") then
|
||||||
targetdir("../plugins/" .. toolTable.Name .. "/lib/xcode/x86")
|
targetdir("../plugins/" .. toolTable.Name .. "/lib/xcode/x86")
|
||||||
end
|
end
|
||||||
|
|
@ -352,7 +352,7 @@ function NazaraBuild:Execute()
|
||||||
libdirs("../extlibs/lib/xcode/x64")
|
libdirs("../extlibs/lib/xcode/x64")
|
||||||
libdirs("../lib/xcode/x64")
|
libdirs("../lib/xcode/x64")
|
||||||
if (toolTable.Kind == "library") then
|
if (toolTable.Kind == "library") then
|
||||||
targetdir("../lib/xcode/x64")
|
targetdir(toolTable.TargetDirectory .. "/xcode/x64")
|
||||||
elseif (toolTable.Kind == "plugin") then
|
elseif (toolTable.Kind == "plugin") then
|
||||||
targetdir("../plugins/" .. toolTable.Name .. "/lib/xcode/x64")
|
targetdir("../plugins/" .. toolTable.Name .. "/lib/xcode/x64")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
MODULE.Name = "Vulkan"
|
|
||||||
|
|
||||||
MODULE.ClientOnly = true
|
|
||||||
|
|
||||||
MODULE.Defines = {
|
|
||||||
"VK_NO_PROTOTYPES"
|
|
||||||
}
|
|
||||||
|
|
||||||
MODULE.Libraries = {
|
|
||||||
"NazaraCore",
|
|
||||||
"NazaraUtility"
|
|
||||||
}
|
|
||||||
|
|
||||||
MODULE.OsDefines.Linux = {
|
|
||||||
-- "VK_USE_PLATFORM_MIR_KHR",
|
|
||||||
"VK_USE_PLATFORM_XCB_KHR"
|
|
||||||
-- "VK_USE_PLATFORM_XLIB_KHR",
|
|
||||||
-- "VK_USE_PLATFORM_WAYLAND_KHR"
|
|
||||||
}
|
|
||||||
|
|
||||||
MODULE.OsDefines.BSD = MODULE.OsDefines.Linux
|
|
||||||
MODULE.OsDefines.Solaris = MODULE.OsDefines.Linux
|
|
||||||
|
|
||||||
MODULE.OsDefines.Windows = {
|
|
||||||
"VK_USE_PLATFORM_WIN32_KHR"
|
|
||||||
}
|
|
||||||
|
|
||||||
MODULE.OsFiles.Windows = {
|
|
||||||
"../src/Nazara/Vulkan/Win32/**.hpp",
|
|
||||||
"../src/Nazara/Vulkan/Win32/**.cpp"
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,6 @@ TOOL.Name = "Assimp"
|
||||||
|
|
||||||
TOOL.Directory = "../plugins/Assimp"
|
TOOL.Directory = "../plugins/Assimp"
|
||||||
TOOL.Kind = "Plugin"
|
TOOL.Kind = "Plugin"
|
||||||
TOOL.TargetDirectory = "../SDK/lib"
|
|
||||||
|
|
||||||
TOOL.Includes = {
|
TOOL.Includes = {
|
||||||
"../extlibs/include",
|
"../extlibs/include",
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ TOOL.Name = "SDK"
|
||||||
|
|
||||||
TOOL.Directory = "../SDK"
|
TOOL.Directory = "../SDK"
|
||||||
TOOL.Kind = "Library"
|
TOOL.Kind = "Library"
|
||||||
TOOL.TargetDirectory = "../SDK/lib"
|
TOOL.TargetDirectory = "../lib"
|
||||||
|
|
||||||
TOOL.Defines = {
|
TOOL.Defines = {
|
||||||
"NDK_BUILD"
|
"NDK_BUILD"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ TOOL.Name = "SDKServer"
|
||||||
|
|
||||||
TOOL.Directory = "../SDK"
|
TOOL.Directory = "../SDK"
|
||||||
TOOL.Kind = "Library"
|
TOOL.Kind = "Library"
|
||||||
TOOL.TargetDirectory = "../SDK/lib"
|
TOOL.TargetDirectory = "../lib"
|
||||||
|
|
||||||
TOOL.Defines = {
|
TOOL.Defines = {
|
||||||
"NDK_BUILD",
|
"NDK_BUILD",
|
||||||
|
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
Nazara Engine - Vulkan
|
|
||||||
|
|
||||||
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
||||||
of the Software, and to permit persons to whom the Software is furnished to do
|
|
||||||
so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_CONFIG_VULKAN_HPP
|
|
||||||
#define NAZARA_CONFIG_VULKAN_HPP
|
|
||||||
|
|
||||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
|
||||||
|
|
||||||
// Utilise le MemoryManager pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
|
|
||||||
#define NAZARA_VULKAN_MANAGE_MEMORY 0
|
|
||||||
|
|
||||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
|
||||||
#define NAZARA_VULKAN_SAFE 1
|
|
||||||
|
|
||||||
/// Chaque modification d'un paramètre ci-dessous implique une modification (souvent mineure) du code
|
|
||||||
|
|
||||||
/// Vérification des valeurs et types de certaines constantes
|
|
||||||
#include <Nazara/Vulkan/ConfigCheck.hpp>
|
|
||||||
|
|
||||||
#if !defined(NAZARA_STATIC)
|
|
||||||
#ifdef NAZARA_VULKAN_BUILD
|
|
||||||
#define NAZARA_VULKAN_API NAZARA_EXPORT
|
|
||||||
#else
|
|
||||||
#define NAZARA_VULKAN_API NAZARA_IMPORT
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define NAZARA_VULKAN_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // NAZARA_CONFIG_MODULENAME_HPP
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_CONFIG_CHECK_VULKANE_HPP
|
|
||||||
#define NAZARA_CONFIG_CHECK_VULKANE_HPP
|
|
||||||
|
|
||||||
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
|
|
||||||
|
|
||||||
#include <type_traits>
|
|
||||||
#define CheckType(name, type, err) static_assert(std::is_ ##type <decltype(name)>::value, #type err)
|
|
||||||
#define CheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
|
|
||||||
|
|
||||||
// On force la valeur de MANAGE_MEMORY en mode debug
|
|
||||||
#if defined(NAZARA_DEBUG) && !NAZARA_VULKAN_MANAGE_MEMORY
|
|
||||||
#undef NAZARA_MODULENAME_MANAGE_MEMORY
|
|
||||||
#define NAZARA_MODULENAME_MANAGE_MEMORY 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // NAZARA_CONFIG_CHECK_VULKAN_HPP
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/Config.hpp>
|
|
||||||
#if NAZARA_MODULENAME_MANAGE_MEMORY
|
|
||||||
#include <Nazara/Core/Debug/NewRedefinition.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
|
|
||||||
#if NAZARA_MODULENAME_MANAGE_MEMORY
|
|
||||||
#undef delete
|
|
||||||
#undef new
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
// Copyright (C) 201 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_RENDERTARGET_HPP
|
|
||||||
#define NAZARA_RENDERTARGET_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Core/Signal.hpp>
|
|
||||||
#include <Nazara/Vulkan/Config.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkFrameBuffer.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkRenderPass.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkSemaphore.hpp>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
class Renderer;
|
|
||||||
|
|
||||||
class NAZARA_VULKAN_API RenderTarget
|
|
||||||
{
|
|
||||||
friend Renderer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
RenderTarget() = default;
|
|
||||||
RenderTarget(const RenderTarget&) = delete;
|
|
||||||
RenderTarget(RenderTarget&&) = delete; ///TOOD?
|
|
||||||
virtual ~RenderTarget();
|
|
||||||
|
|
||||||
virtual bool Acquire(UInt32* imageIndex) const = 0;
|
|
||||||
|
|
||||||
virtual void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) = 0;
|
|
||||||
virtual void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) = 0;
|
|
||||||
|
|
||||||
virtual const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const = 0;
|
|
||||||
virtual UInt32 GetFramebufferCount() const = 0;
|
|
||||||
|
|
||||||
const Vk::RenderPass& GetRenderPass() const { return m_renderPass; }
|
|
||||||
|
|
||||||
const Vk::Semaphore& GetRenderSemaphore() const { return m_imageReadySemaphore; }
|
|
||||||
|
|
||||||
virtual void Present(UInt32 imageIndex) = 0;
|
|
||||||
|
|
||||||
RenderTarget& operator=(const RenderTarget&) = delete;
|
|
||||||
RenderTarget& operator=(RenderTarget&&) = delete; ///TOOD?
|
|
||||||
|
|
||||||
// Signals:
|
|
||||||
NazaraSignal(OnRenderTargetRelease, const RenderTarget* /*renderTarget*/);
|
|
||||||
NazaraSignal(OnRenderTargetSizeChange, const RenderTarget* /*renderTarget*/);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Vk::RenderPass m_renderPass;
|
|
||||||
Vk::Semaphore m_imageReadySemaphore;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // NAZARA_RENDERTARGET_HPP
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
// Copyright (C) 2015 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_RENDERWINDOW_HPP
|
|
||||||
#define NAZARA_RENDERWINDOW_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Core/Clock.hpp>
|
|
||||||
#include <Nazara/Math/Rect.hpp>
|
|
||||||
#include <Nazara/Math/Vector3.hpp>
|
|
||||||
#include <Nazara/Vulkan/Config.hpp>
|
|
||||||
#include <Nazara/Vulkan/RenderTarget.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkCommandBuffer.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkCommandPool.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceMemory.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkFramebuffer.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkImage.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkSurface.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkSwapchain.hpp>
|
|
||||||
#include <Nazara/Utility/Window.hpp>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
class NAZARA_VULKAN_API RenderWindow : public RenderTarget, public Window
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RenderWindow();
|
|
||||||
RenderWindow(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
|
||||||
RenderWindow(WindowHandle handle);
|
|
||||||
RenderWindow(const RenderWindow&) = delete;
|
|
||||||
RenderWindow(RenderWindow&&) = delete; ///TODO
|
|
||||||
virtual ~RenderWindow();
|
|
||||||
|
|
||||||
bool Acquire(UInt32* index) const override;
|
|
||||||
|
|
||||||
void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
|
||||||
void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
|
||||||
|
|
||||||
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
|
||||||
bool Create(WindowHandle handle);
|
|
||||||
|
|
||||||
const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const override;
|
|
||||||
UInt32 GetFramebufferCount() const;
|
|
||||||
const Vk::DeviceHandle& GetDevice() const;
|
|
||||||
UInt32 GetPresentableFamilyQueue() const;
|
|
||||||
const Vk::Surface& GetSurface() const;
|
|
||||||
const Vk::Swapchain& GetSwapchain() const;
|
|
||||||
|
|
||||||
void Present(UInt32 imageIndex) override;
|
|
||||||
|
|
||||||
bool IsValid() const;
|
|
||||||
|
|
||||||
void SetDepthStencilFormats(std::vector<PixelFormatType> pixelFormat);
|
|
||||||
void SetPhysicalDevice(VkPhysicalDevice device);
|
|
||||||
|
|
||||||
RenderWindow& operator=(const RenderWindow&) = delete;
|
|
||||||
RenderWindow& operator=(RenderWindow&&) = delete; ///TODO
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool OnWindowCreated() override;
|
|
||||||
void OnWindowDestroy() override;
|
|
||||||
void OnWindowResized() override;
|
|
||||||
|
|
||||||
bool SetupDepthBuffer();
|
|
||||||
bool SetupRenderPass();
|
|
||||||
bool SetupSwapchain();
|
|
||||||
|
|
||||||
Clock m_clock;
|
|
||||||
VkColorSpaceKHR m_colorSpace;
|
|
||||||
VkFormat m_colorFormat;
|
|
||||||
VkFormat m_depthStencilFormat;
|
|
||||||
VkPhysicalDevice m_forcedPhysicalDevice;
|
|
||||||
std::vector<PixelFormatType> m_wantedDepthStencilFormats;
|
|
||||||
std::vector<Vk::Framebuffer> m_frameBuffers;
|
|
||||||
Vk::DeviceHandle m_device;
|
|
||||||
Vk::DeviceMemory m_depthBufferMemory;
|
|
||||||
Vk::Image m_depthBuffer;
|
|
||||||
Vk::ImageView m_depthBufferView;
|
|
||||||
Vk::Queue m_presentQueue;
|
|
||||||
Vk::Surface m_surface;
|
|
||||||
Vk::Swapchain m_swapchain;
|
|
||||||
UInt32 m_presentableFamilyQueue;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // NAZARA_RENDERWINDOW_HPP
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKBUFFER_HPP
|
|
||||||
#define NAZARA_VULKAN_VKBUFFER_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class Buffer : public DeviceObject<Buffer, VkBuffer, VkBufferCreateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Buffer() = default;
|
|
||||||
Buffer(const Buffer&) = delete;
|
|
||||||
Buffer(Buffer&&) = default;
|
|
||||||
~Buffer() = default;
|
|
||||||
|
|
||||||
bool BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset = 0);
|
|
||||||
|
|
||||||
using DeviceObject::Create;
|
|
||||||
inline bool Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
|
|
||||||
VkMemoryRequirements GetMemoryRequirements() const;
|
|
||||||
|
|
||||||
Buffer& operator=(const Buffer&) = delete;
|
|
||||||
Buffer& operator=(Buffer&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkBufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkBuffer* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkBuffer handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkBuffer.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKBUFFER_HPP
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkBuffer.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline bool Buffer::BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_device->vkBindBufferMemory(*m_device, m_handle, memory, offset);
|
|
||||||
if (m_lastErrorCode != VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to bind buffer memory");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Buffer::Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkBufferCreateInfo createInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
flags, // VkBufferCreateFlags flags;
|
|
||||||
size, // VkDeviceSize size;
|
|
||||||
usage, // VkBufferUsageFlags usage;
|
|
||||||
VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
|
|
||||||
0, // uint32_t queueFamilyIndexCount;
|
|
||||||
nullptr // const uint32_t* pQueueFamilyIndices;
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(device, createInfo, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkMemoryRequirements Buffer::GetMemoryRequirements() const
|
|
||||||
{
|
|
||||||
NazaraAssert(IsValid(), "Invalid buffer");
|
|
||||||
|
|
||||||
VkMemoryRequirements memoryRequirements;
|
|
||||||
m_device->vkGetBufferMemoryRequirements(*m_device, m_handle, &memoryRequirements);
|
|
||||||
|
|
||||||
return memoryRequirements;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult Buffer::CreateHelper(const DeviceHandle& device, const VkBufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkBuffer* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateBuffer(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Buffer::DestroyHelper(const DeviceHandle& device, VkBuffer handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyBuffer(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKCOMMANDBUFFER_HPP
|
|
||||||
#define NAZARA_VULKAN_VKCOMMANDBUFFER_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Math/Rect.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkCommandPool.hpp>
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class CommandBuffer
|
|
||||||
{
|
|
||||||
friend CommandPool;
|
|
||||||
|
|
||||||
public:
|
|
||||||
inline CommandBuffer();
|
|
||||||
CommandBuffer(const CommandBuffer&) = delete;
|
|
||||||
inline CommandBuffer(CommandBuffer&& commandBuffer);
|
|
||||||
inline ~CommandBuffer();
|
|
||||||
|
|
||||||
inline bool Begin(const VkCommandBufferBeginInfo& info);
|
|
||||||
inline bool Begin(VkCommandBufferUsageFlags flags);
|
|
||||||
inline bool Begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo& inheritanceInfo);
|
|
||||||
inline bool Begin(VkCommandBufferUsageFlags flags, VkRenderPass renderPass, UInt32 subpass, VkFramebuffer framebuffer, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics);
|
|
||||||
inline bool Begin(VkCommandBufferUsageFlags flags, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics);
|
|
||||||
|
|
||||||
inline void BeginRenderPass(const VkRenderPassBeginInfo& beginInfo, VkSubpassContents contents = VK_SUBPASS_CONTENTS_INLINE);
|
|
||||||
|
|
||||||
inline void BindDescriptorSet(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, const VkDescriptorSet& descriptorSets);
|
|
||||||
inline void BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets);
|
|
||||||
inline void BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets, UInt32 dynamicOffsetCount, const UInt32* dynamicOffsets);
|
|
||||||
inline void BindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType);
|
|
||||||
inline void BindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline);
|
|
||||||
inline void BindVertexBuffer(UInt32 binding, const VkBuffer buffer, const VkDeviceSize offset);
|
|
||||||
inline void BindVertexBuffers(UInt32 firstBinding, UInt32 bindingCount, const VkBuffer* buffer, const VkDeviceSize* offset);
|
|
||||||
|
|
||||||
inline void ClearAttachment(const VkClearAttachment& attachment, const VkClearRect& rect);
|
|
||||||
inline void ClearAttachments(UInt32 attachmentCount, const VkClearAttachment* attachments, UInt32 rectCount, const VkClearRect* rects);
|
|
||||||
|
|
||||||
inline void ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, const VkImageSubresourceRange& range);
|
|
||||||
inline void ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, UInt32 rangeCount, const VkImageSubresourceRange* ranges);
|
|
||||||
|
|
||||||
inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, const VkImageSubresourceRange& range);
|
|
||||||
inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, UInt32 rangeCount, const VkImageSubresourceRange* ranges);
|
|
||||||
|
|
||||||
inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
|
|
||||||
inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0);
|
|
||||||
|
|
||||||
inline bool End();
|
|
||||||
|
|
||||||
inline void EndRenderPass();
|
|
||||||
|
|
||||||
inline void Free();
|
|
||||||
|
|
||||||
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier);
|
|
||||||
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkMemoryBarrier& memoryBarrier, const VkBufferMemoryBarrier& bufferMemoryBarrier, const VkImageMemoryBarrier& imageMemoryBarrier);
|
|
||||||
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, UInt32 memoryBarrierCount, const VkMemoryBarrier* memoryBarriers, UInt32 bufferMemoryBarrierCount, const VkBufferMemoryBarrier* bufferMemoryBarriers, UInt32 imageMemoryBarrierCount, const VkImageMemoryBarrier* imageMemoryBarriers);
|
|
||||||
|
|
||||||
inline void SetScissor(const Recti& scissorRegion);
|
|
||||||
inline void SetScissor(const VkRect2D& scissorRegion);
|
|
||||||
inline void SetScissor(UInt32 firstScissor, UInt32 scissorCount, const VkRect2D* scissors);
|
|
||||||
inline void SetViewport(const Rectf& viewport, float minDepth, float maxDepth);
|
|
||||||
inline void SetViewport(const VkViewport& viewport);
|
|
||||||
inline void SetViewport(UInt32 firstViewport, UInt32 viewportCount, const VkViewport* viewports);
|
|
||||||
|
|
||||||
inline void SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout);
|
|
||||||
inline void SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange);
|
|
||||||
inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout);
|
|
||||||
inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange);
|
|
||||||
|
|
||||||
inline VkResult GetLastErrorCode() const;
|
|
||||||
|
|
||||||
CommandBuffer& operator=(const CommandBuffer&) = delete;
|
|
||||||
CommandBuffer& operator=(CommandBuffer&& commandBuffer);
|
|
||||||
|
|
||||||
inline operator VkCommandBuffer() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
inline CommandBuffer(CommandPool& pool, VkCommandBuffer handle);
|
|
||||||
|
|
||||||
CommandPoolHandle m_pool;
|
|
||||||
VkAllocationCallbacks m_allocator;
|
|
||||||
VkCommandBuffer m_handle;
|
|
||||||
VkResult m_lastErrorCode;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkCommandBuffer.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKCOMMANDBUFFER_HPP
|
|
||||||
|
|
@ -1,419 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkCommandBuffer.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline CommandBuffer::CommandBuffer() :
|
|
||||||
m_pool(),
|
|
||||||
m_handle(VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CommandBuffer::CommandBuffer(CommandPool& pool, VkCommandBuffer handle) :
|
|
||||||
m_pool(&pool),
|
|
||||||
m_handle(handle)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CommandBuffer::CommandBuffer(CommandBuffer&& commandBuffer) :
|
|
||||||
m_pool(std::move(commandBuffer.m_pool)),
|
|
||||||
m_allocator(commandBuffer.m_allocator),
|
|
||||||
m_handle(commandBuffer.m_handle),
|
|
||||||
m_lastErrorCode(commandBuffer.m_lastErrorCode)
|
|
||||||
{
|
|
||||||
commandBuffer.m_handle = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CommandBuffer::~CommandBuffer()
|
|
||||||
{
|
|
||||||
Free();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool CommandBuffer::Begin(const VkCommandBufferBeginInfo& info)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_pool->GetDevice()->vkBeginCommandBuffer(m_handle, &info);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to begin command buffer");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags)
|
|
||||||
{
|
|
||||||
VkCommandBufferBeginInfo beginInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
nullptr
|
|
||||||
};
|
|
||||||
|
|
||||||
return Begin(beginInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo& inheritanceInfo)
|
|
||||||
{
|
|
||||||
VkCommandBufferBeginInfo beginInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
&inheritanceInfo
|
|
||||||
};
|
|
||||||
|
|
||||||
return Begin(beginInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags, VkRenderPass renderPass, UInt32 subpass, VkFramebuffer framebuffer, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics)
|
|
||||||
{
|
|
||||||
NazaraAssert(flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, "Continue bit is required to ignore renderPass, subpass and framebuffer");
|
|
||||||
|
|
||||||
VkCommandBufferInheritanceInfo inheritanceInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
|
|
||||||
nullptr,
|
|
||||||
renderPass,
|
|
||||||
subpass,
|
|
||||||
framebuffer,
|
|
||||||
VkBool32((occlusionQueryEnable) ? VK_TRUE : VK_FALSE),
|
|
||||||
queryFlags,
|
|
||||||
pipelineStatistics
|
|
||||||
};
|
|
||||||
|
|
||||||
VkCommandBufferBeginInfo beginInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
&inheritanceInfo
|
|
||||||
};
|
|
||||||
|
|
||||||
return Begin(beginInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics)
|
|
||||||
{
|
|
||||||
NazaraAssert(flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, "Continue bit is required to ignore renderPass, subpass and framebuffer");
|
|
||||||
|
|
||||||
VkCommandBufferInheritanceInfo inheritanceInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
|
|
||||||
nullptr,
|
|
||||||
VK_NULL_HANDLE,
|
|
||||||
0,
|
|
||||||
VK_NULL_HANDLE,
|
|
||||||
VkBool32((occlusionQueryEnable) ? VK_TRUE : VK_FALSE),
|
|
||||||
queryFlags,
|
|
||||||
pipelineStatistics
|
|
||||||
};
|
|
||||||
|
|
||||||
VkCommandBufferBeginInfo beginInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
&inheritanceInfo
|
|
||||||
};
|
|
||||||
|
|
||||||
return Begin(beginInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::BeginRenderPass(const VkRenderPassBeginInfo& beginInfo, VkSubpassContents contents)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdBeginRenderPass(m_handle, &beginInfo, contents);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::BindDescriptorSet(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, const VkDescriptorSet& descriptorSets)
|
|
||||||
{
|
|
||||||
return BindDescriptorSets(pipelineBindPoint, layout, firstSet, 1U, &descriptorSets);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets)
|
|
||||||
{
|
|
||||||
return BindDescriptorSets(pipelineBindPoint, layout, firstSet, descriptorSetCount, descriptorSets, 0U, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets, UInt32 dynamicOffsetCount, const UInt32* dynamicOffsets)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdBindDescriptorSets(m_handle, pipelineBindPoint, layout, firstSet, descriptorSetCount, descriptorSets, dynamicOffsetCount, dynamicOffsets);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::BindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdBindIndexBuffer(m_handle, buffer, offset, indexType);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::BindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdBindPipeline(m_handle, pipelineBindPoint, pipeline);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::BindVertexBuffer(UInt32 binding, const VkBuffer buffer, const VkDeviceSize offset)
|
|
||||||
{
|
|
||||||
return BindVertexBuffers(binding, 1, &buffer, &offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::BindVertexBuffers(UInt32 firstBinding, UInt32 bindingCount, const VkBuffer* buffer, const VkDeviceSize* offset)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdBindVertexBuffers(m_handle, firstBinding, bindingCount, buffer, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::ClearAttachment(const VkClearAttachment& attachment, const VkClearRect& rect)
|
|
||||||
{
|
|
||||||
return ClearAttachments(1U, &attachment, 1U, &rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::ClearAttachments(UInt32 attachmentCount, const VkClearAttachment* attachments, UInt32 rectCount, const VkClearRect* rects)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdClearAttachments(m_handle, attachmentCount, attachments, rectCount, rects);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, const VkImageSubresourceRange& range)
|
|
||||||
{
|
|
||||||
return ClearColorImage(image, imageLayout, color, 1U, &range);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, UInt32 rangeCount, const VkImageSubresourceRange* ranges)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdClearColorImage(m_handle, image, imageLayout, &color, rangeCount, ranges);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, const VkImageSubresourceRange& range)
|
|
||||||
{
|
|
||||||
return ClearDepthStencilImage(image, imageLayout, depthStencil, 1U, &range);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, UInt32 rangeCount, const VkImageSubresourceRange * ranges)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdClearDepthStencilImage(m_handle, image, imageLayout, &depthStencil, rangeCount, ranges);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::Draw(UInt32 vertexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdDraw(m_handle, vertexCount, instanceCount, firstVertex, firstInstance);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstVertex, Int32 vertexOffset, UInt32 firstInstance)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdDrawIndexed(m_handle, indexCount, instanceCount, firstVertex, vertexOffset, firstInstance);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool CommandBuffer::End()
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_pool->GetDevice()->vkEndCommandBuffer(m_handle);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to end command buffer");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::EndRenderPass()
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdEndRenderPass(m_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::Free()
|
|
||||||
{
|
|
||||||
if (m_handle)
|
|
||||||
m_pool->GetDevice()->vkFreeCommandBuffers(*m_pool->GetDevice(), *m_pool, 1, &m_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier)
|
|
||||||
{
|
|
||||||
return PipelineBarrier(srcStageMask, dstStageMask, dependencyFlags, 0, nullptr, 0, nullptr, 1, &imageMemoryBarrier);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkMemoryBarrier& memoryBarrier, const VkBufferMemoryBarrier& bufferMemoryBarrier, const VkImageMemoryBarrier& imageMemoryBarrier)
|
|
||||||
{
|
|
||||||
return PipelineBarrier(srcStageMask, dstStageMask, dependencyFlags, 1, &memoryBarrier, 1, &bufferMemoryBarrier, 1, &imageMemoryBarrier);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, UInt32 memoryBarrierCount, const VkMemoryBarrier* memoryBarriers, UInt32 bufferMemoryBarrierCount, const VkBufferMemoryBarrier* bufferMemoryBarriers, UInt32 imageMemoryBarrierCount, const VkImageMemoryBarrier* imageMemoryBarriers)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdPipelineBarrier(m_handle, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, memoryBarriers, bufferMemoryBarrierCount, bufferMemoryBarriers, imageMemoryBarrierCount, imageMemoryBarriers);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::SetScissor(const Recti& scissorRegion)
|
|
||||||
{
|
|
||||||
VkRect2D rect = {
|
|
||||||
{scissorRegion.x, scissorRegion.y}, // VkOffset2D offset
|
|
||||||
{UInt32(scissorRegion.width), UInt32(scissorRegion.height)} // VkExtent2D extent
|
|
||||||
};
|
|
||||||
|
|
||||||
SetScissor(rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::SetScissor(const VkRect2D& scissorRegion)
|
|
||||||
{
|
|
||||||
return SetScissor(0, 1, &scissorRegion);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::SetScissor(UInt32 firstScissor, UInt32 scissorCount, const VkRect2D* scissors)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdSetScissor(m_handle, firstScissor, scissorCount, scissors);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout)
|
|
||||||
{
|
|
||||||
return SetImageLayout(image, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, oldImageLayout, newImageLayout);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange)
|
|
||||||
{
|
|
||||||
return SetImageLayout(image, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, oldImageLayout, newImageLayout, subresourceRange);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout)
|
|
||||||
{
|
|
||||||
VkImageSubresourceRange imageRange = {
|
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask
|
|
||||||
0, // uint32_t baseMipLevel
|
|
||||||
1, // uint32_t levelCount
|
|
||||||
0, // uint32_t baseArrayLayer
|
|
||||||
1 // uint32_t layerCount
|
|
||||||
};
|
|
||||||
|
|
||||||
return SetImageLayout(image, srcStageMask, dstStageMask, oldImageLayout, newImageLayout, imageRange);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange)
|
|
||||||
{
|
|
||||||
VkAccessFlags srcAccessMask;
|
|
||||||
switch (oldImageLayout)
|
|
||||||
{
|
|
||||||
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
|
|
||||||
srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
|
|
||||||
srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
|
|
||||||
srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
|
|
||||||
srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
|
|
||||||
srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
|
|
||||||
srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_PREINITIALIZED:
|
|
||||||
srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_GENERAL:
|
|
||||||
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
|
|
||||||
case VK_IMAGE_LAYOUT_UNDEFINED:
|
|
||||||
default:
|
|
||||||
srcAccessMask = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkAccessFlags dstAccessMask;
|
|
||||||
switch (newImageLayout)
|
|
||||||
{
|
|
||||||
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
|
|
||||||
if (oldImageLayout != VK_IMAGE_LAYOUT_UNDEFINED)
|
|
||||||
srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
|
||||||
|
|
||||||
dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
|
|
||||||
dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
|
|
||||||
if (srcAccessMask == 0)
|
|
||||||
srcAccessMask = VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
|
|
||||||
|
|
||||||
dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
|
|
||||||
dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
|
|
||||||
srcAccessMask |= VK_ACCESS_TRANSFER_READ_BIT;
|
|
||||||
dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
|
||||||
break;
|
|
||||||
case VK_IMAGE_LAYOUT_GENERAL:
|
|
||||||
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
|
|
||||||
case VK_IMAGE_LAYOUT_UNDEFINED:
|
|
||||||
default:
|
|
||||||
dstAccessMask = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkImageMemoryBarrier imageBarrier = {
|
|
||||||
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType
|
|
||||||
nullptr, // const void* pNext
|
|
||||||
srcAccessMask, // VkAccessFlags srcAccessMask
|
|
||||||
dstAccessMask, // VkAccessFlags dstAccessMask
|
|
||||||
oldImageLayout, // VkImageLayout oldLayout
|
|
||||||
newImageLayout, // VkImageLayout newLayout
|
|
||||||
VK_QUEUE_FAMILY_IGNORED, // uint32_t srcQueueFamilyIndex
|
|
||||||
VK_QUEUE_FAMILY_IGNORED, // uint32_t dstQueueFamilyIndex
|
|
||||||
image, // VkImage image
|
|
||||||
subresourceRange // VkImageSubresourceRange subresourceRange
|
|
||||||
};
|
|
||||||
|
|
||||||
return PipelineBarrier(srcStageMask, dstStageMask, 0, imageBarrier);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::SetViewport(const Rectf& viewport, float minDepth, float maxDepth)
|
|
||||||
{
|
|
||||||
VkViewport rect = {
|
|
||||||
viewport.x, // float x;
|
|
||||||
viewport.y, // float y;
|
|
||||||
viewport.width, // float width;
|
|
||||||
viewport.height, // float height;
|
|
||||||
minDepth, // float minDepth;
|
|
||||||
maxDepth // float maxDepth;
|
|
||||||
};
|
|
||||||
|
|
||||||
SetViewport(rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::SetViewport(const VkViewport& viewport)
|
|
||||||
{
|
|
||||||
return SetViewport(0, 1, &viewport);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandBuffer::SetViewport(UInt32 firstViewport, UInt32 viewportCount, const VkViewport* viewports)
|
|
||||||
{
|
|
||||||
return m_pool->GetDevice()->vkCmdSetViewport(m_handle, firstViewport, viewportCount, viewports);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult CommandBuffer::GetLastErrorCode() const
|
|
||||||
{
|
|
||||||
return m_lastErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CommandBuffer& CommandBuffer::operator=(CommandBuffer&& commandBuffer)
|
|
||||||
{
|
|
||||||
m_allocator = commandBuffer.m_allocator;
|
|
||||||
m_handle = commandBuffer.m_handle;
|
|
||||||
m_lastErrorCode = commandBuffer.m_lastErrorCode;
|
|
||||||
m_pool = std::move(commandBuffer.m_pool);
|
|
||||||
m_handle = commandBuffer.m_handle;
|
|
||||||
|
|
||||||
commandBuffer.m_handle = VK_NULL_HANDLE;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CommandBuffer::operator VkCommandBuffer() const
|
|
||||||
{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKCOMMANDPOOL_HPP
|
|
||||||
#define NAZARA_VULKAN_VKCOMMANDPOOL_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Core/HandledObject.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class CommandBuffer;
|
|
||||||
class CommandPool;
|
|
||||||
|
|
||||||
using CommandPoolHandle = ObjectHandle<CommandPool>;
|
|
||||||
|
|
||||||
class NAZARA_VULKAN_API CommandPool : public DeviceObject<CommandPool, VkCommandPool, VkCommandPoolCreateInfo>, public HandledObject<CommandPool>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CommandPool() = default;
|
|
||||||
CommandPool(const CommandPool&) = delete;
|
|
||||||
CommandPool(CommandPool&&) = default;
|
|
||||||
~CommandPool() = default;
|
|
||||||
|
|
||||||
CommandBuffer AllocateCommandBuffer(VkCommandBufferLevel level);
|
|
||||||
std::vector<CommandBuffer> AllocateCommandBuffers(UInt32 commandBufferCount, VkCommandBufferLevel level);
|
|
||||||
|
|
||||||
using DeviceObject::Create;
|
|
||||||
inline bool Create(const DeviceHandle& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
|
|
||||||
inline bool Reset(VkCommandPoolResetFlags flags);
|
|
||||||
|
|
||||||
CommandPool& operator=(const CommandPool&) = delete;
|
|
||||||
CommandPool& operator=(CommandPool&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkCommandPool handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkCommandPool.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKCOMMANDPOOL_HPP
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkCommandPool.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline bool CommandPool::Create(const DeviceHandle& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkCommandPoolCreateInfo createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
queueFamilyIndex
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(device, createInfo, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool CommandPool::Reset(VkCommandPoolResetFlags flags)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_device->vkResetCommandPool(*m_device, m_handle, flags);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult CommandPool::CreateHelper(const DeviceHandle& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateCommandPool(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void CommandPool::DestroyHelper(const DeviceHandle& device, VkCommandPool handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyCommandPool(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKDESCRIPTORPOOL_HPP
|
|
||||||
#define NAZARA_VULKAN_VKDESCRIPTORPOOL_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Core/HandledObject.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class DescriptorPool;
|
|
||||||
class DescriptorSet;
|
|
||||||
|
|
||||||
using DescriptorPoolHandle = ObjectHandle<DescriptorPool>;
|
|
||||||
|
|
||||||
class NAZARA_VULKAN_API DescriptorPool : public DeviceObject<DescriptorPool, VkDescriptorPool, VkDescriptorPoolCreateInfo>, public HandledObject<DescriptorPool>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
DescriptorPool() = default;
|
|
||||||
DescriptorPool(const DescriptorPool&) = delete;
|
|
||||||
DescriptorPool(DescriptorPool&&) = default;
|
|
||||||
~DescriptorPool() = default;
|
|
||||||
|
|
||||||
DescriptorSet AllocateDescriptorSet(const VkDescriptorSetLayout& setLayouts);
|
|
||||||
std::vector<DescriptorSet> AllocateDescriptorSets(UInt32 descriptorSetCount, const VkDescriptorSetLayout* setLayouts);
|
|
||||||
|
|
||||||
using DeviceObject::Create;
|
|
||||||
inline bool Create(const DeviceHandle& device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool Create(const DeviceHandle& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
|
|
||||||
DescriptorPool& operator=(const DescriptorPool&) = delete;
|
|
||||||
DescriptorPool& operator=(DescriptorPool&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkDescriptorPool handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDescriptorPool.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKDESCRIPTORPOOL_HPP
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDescriptorPool.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline bool DescriptorPool::Create(const DeviceHandle& device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkDescriptorPoolCreateInfo createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
flags, // VkDescriptorPoolCreateFlags flags;
|
|
||||||
maxSets, // uint32_t maxSets;
|
|
||||||
1U, // uint32_t poolSizeCount;
|
|
||||||
&poolSize // const VkDescriptorPoolSize* pPoolSizes;
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(device, createInfo, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool DescriptorPool::Create(const DeviceHandle& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkDescriptorPoolCreateInfo createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
flags, // VkDescriptorPoolCreateFlags flags;
|
|
||||||
maxSets, // uint32_t maxSets;
|
|
||||||
poolSizeCount, // uint32_t poolSizeCount;
|
|
||||||
poolSize // const VkDescriptorPoolSize* pPoolSizes;
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(device, createInfo, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult DescriptorPool::CreateHelper(const DeviceHandle& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateDescriptorPool(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DescriptorPool::DestroyHelper(const DeviceHandle& device, VkDescriptorPool handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyDescriptorPool(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKDESCRIPTORSET_HPP
|
|
||||||
#define NAZARA_VULKAN_VKDESCRIPTORSET_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Math/Rect.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDescriptorPool.hpp>
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class DescriptorSet
|
|
||||||
{
|
|
||||||
friend DescriptorPool;
|
|
||||||
|
|
||||||
public:
|
|
||||||
inline DescriptorSet();
|
|
||||||
DescriptorSet(const DescriptorSet&) = delete;
|
|
||||||
inline DescriptorSet(DescriptorSet&& descriptorSet);
|
|
||||||
inline ~DescriptorSet();
|
|
||||||
|
|
||||||
inline void Free();
|
|
||||||
|
|
||||||
inline VkResult GetLastErrorCode() const;
|
|
||||||
|
|
||||||
inline void WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range);
|
|
||||||
inline void WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo);
|
|
||||||
inline void WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range);
|
|
||||||
inline void WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorBufferInfo& bufferInfo);
|
|
||||||
inline void WriteUniformDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo);
|
|
||||||
inline void WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo);
|
|
||||||
|
|
||||||
DescriptorSet& operator=(const DescriptorSet&) = delete;
|
|
||||||
DescriptorSet& operator=(DescriptorSet&& descriptorSet);
|
|
||||||
|
|
||||||
inline operator VkDescriptorSet() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
inline DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle);
|
|
||||||
|
|
||||||
DescriptorPoolHandle m_pool;
|
|
||||||
VkAllocationCallbacks m_allocator;
|
|
||||||
VkDescriptorSet m_handle;
|
|
||||||
VkResult m_lastErrorCode;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDescriptorSet.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKDESCRIPTORSET_HPP
|
|
||||||
|
|
@ -1,122 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDescriptorSet.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline DescriptorSet::DescriptorSet() :
|
|
||||||
m_pool(),
|
|
||||||
m_handle(VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline DescriptorSet::DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle) :
|
|
||||||
m_pool(&pool),
|
|
||||||
m_handle(handle)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) :
|
|
||||||
m_pool(std::move(descriptorSet.m_pool)),
|
|
||||||
m_allocator(descriptorSet.m_allocator),
|
|
||||||
m_handle(descriptorSet.m_handle),
|
|
||||||
m_lastErrorCode(descriptorSet.m_lastErrorCode)
|
|
||||||
{
|
|
||||||
descriptorSet.m_handle = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline DescriptorSet::~DescriptorSet()
|
|
||||||
{
|
|
||||||
Free();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DescriptorSet::Free()
|
|
||||||
{
|
|
||||||
if (m_handle)
|
|
||||||
m_pool->GetDevice()->vkFreeDescriptorSets(*m_pool->GetDevice(), *m_pool, 1, &m_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult DescriptorSet::GetLastErrorCode() const
|
|
||||||
{
|
|
||||||
return m_lastErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range)
|
|
||||||
{
|
|
||||||
return WriteUniformDescriptor(binding, 0U, buffer, offset, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo)
|
|
||||||
{
|
|
||||||
return WriteUniformDescriptors(binding, 0U, 1U, &bufferInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range)
|
|
||||||
{
|
|
||||||
VkDescriptorBufferInfo bufferInfo =
|
|
||||||
{
|
|
||||||
buffer, // VkBuffer buffer;
|
|
||||||
offset, // VkDeviceSize offset;
|
|
||||||
range // VkDeviceSize range;
|
|
||||||
};
|
|
||||||
|
|
||||||
return WriteUniformDescriptor(binding, arrayElement, bufferInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorBufferInfo& bufferInfo)
|
|
||||||
{
|
|
||||||
return WriteUniformDescriptors(binding, arrayElement, 1U, &bufferInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo)
|
|
||||||
{
|
|
||||||
return WriteUniformDescriptors(binding, 0U, descriptorCount, bufferInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo)
|
|
||||||
{
|
|
||||||
VkWriteDescriptorSet writeDescriptorSet =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
m_handle, // VkDescriptorSet dstSet;
|
|
||||||
binding, // uint32_t dstBinding;
|
|
||||||
arrayElement, // uint32_t dstArrayElement;
|
|
||||||
descriptorCount, // uint32_t descriptorCount;
|
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType descriptorType;
|
|
||||||
nullptr, // const VkDescriptorImageInfo* pImageInfo;
|
|
||||||
bufferInfo, // const VkDescriptorBufferInfo* pBufferInfo;
|
|
||||||
nullptr // const VkBufferView* pTexelBufferView;
|
|
||||||
};
|
|
||||||
|
|
||||||
return m_pool->GetDevice()->vkUpdateDescriptorSets(*m_pool->GetDevice(), 1U, &writeDescriptorSet, 0U, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline DescriptorSet& DescriptorSet::operator=(DescriptorSet&& descriptorSet)
|
|
||||||
{
|
|
||||||
m_allocator = descriptorSet.m_allocator;
|
|
||||||
m_handle = descriptorSet.m_handle;
|
|
||||||
m_lastErrorCode = descriptorSet.m_lastErrorCode;
|
|
||||||
m_pool = std::move(descriptorSet.m_pool);
|
|
||||||
m_handle = descriptorSet.m_handle;
|
|
||||||
|
|
||||||
descriptorSet.m_handle = VK_NULL_HANDLE;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline DescriptorSet::operator VkDescriptorSet() const
|
|
||||||
{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKDESCRIPTORSETLAYOUT_HPP
|
|
||||||
#define NAZARA_VULKAN_VKDESCRIPTORSETLAYOUT_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class DescriptorSetLayout : public DeviceObject<DescriptorSetLayout, VkDescriptorSetLayout, VkDescriptorSetLayoutCreateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
DescriptorSetLayout() = default;
|
|
||||||
DescriptorSetLayout(const DescriptorSetLayout&) = delete;
|
|
||||||
DescriptorSetLayout(DescriptorSetLayout&&) = default;
|
|
||||||
~DescriptorSetLayout() = default;
|
|
||||||
|
|
||||||
using DeviceObject::Create;
|
|
||||||
inline bool Create(const DeviceHandle& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool Create(const DeviceHandle& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
|
|
||||||
DescriptorSetLayout& operator=(const DescriptorSetLayout&) = delete;
|
|
||||||
DescriptorSetLayout& operator=(DescriptorSetLayout&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkDescriptorSetLayout handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDescriptorSetLayout.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKDESCRIPTORSETLAYOUT_HPP
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDescriptorSetLayout.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline bool DescriptorSetLayout::Create(const DeviceHandle& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return Create(device, 1U, &binding, flags, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool DescriptorSetLayout::Create(const DeviceHandle& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkDescriptorSetLayoutCreateInfo createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
flags, // VkDescriptorSetLayoutCreateFlags flags;
|
|
||||||
bindingCount, // uint32_t bindingCount;
|
|
||||||
binding // const VkDescriptorSetLayoutBinding* pBindings;
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(device, createInfo, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult DescriptorSetLayout::CreateHelper(const DeviceHandle& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateDescriptorSetLayout(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DescriptorSetLayout::DestroyHelper(const DeviceHandle& device, VkDescriptorSetLayout handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyDescriptorSetLayout(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,232 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKDEVICE_HPP
|
|
||||||
#define NAZARA_VULKAN_VKDEVICE_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Core/HandledObject.hpp>
|
|
||||||
#include <Nazara/Vulkan/Config.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkLoader.hpp>
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class Device;
|
|
||||||
class Queue;
|
|
||||||
class Instance;
|
|
||||||
|
|
||||||
using DeviceHandle = ObjectHandle<Device>;
|
|
||||||
|
|
||||||
class NAZARA_VULKAN_API Device : public HandledObject<Device>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct QueueFamilyInfo;
|
|
||||||
struct QueueInfo;
|
|
||||||
using QueueList = std::vector<QueueInfo>;
|
|
||||||
|
|
||||||
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<QueueFamilyInfo>& GetEnabledQueues() const;
|
|
||||||
inline const QueueList& GetEnabledQueues(UInt32 familyQueue) const;
|
|
||||||
|
|
||||||
inline 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 String& extensionName);
|
|
||||||
inline bool IsLayerLoaded(const String& layerName);
|
|
||||||
|
|
||||||
inline bool WaitForIdle();
|
|
||||||
|
|
||||||
Device& operator=(const Device&) = delete;
|
|
||||||
Device& operator=(Device&&) = delete;
|
|
||||||
|
|
||||||
inline operator VkDevice();
|
|
||||||
|
|
||||||
// Vulkan functions
|
|
||||||
#define NAZARA_VULKAN_DEVICE_FUNCTION(func) PFN_##func func
|
|
||||||
|
|
||||||
// Vulkan core
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkAllocateCommandBuffers);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkAllocateDescriptorSets);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkAllocateMemory);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkBeginCommandBuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkBindBufferMemory);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkBindImageMemory);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdBeginQuery);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdBeginRenderPass);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdBindDescriptorSets);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdBindIndexBuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdBindPipeline);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdBindVertexBuffers);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdBlitImage);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdClearAttachments);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdClearColorImage);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdClearDepthStencilImage);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdCopyBuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdCopyBufferToImage);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdCopyImage);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdCopyImageToBuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdCopyQueryPoolResults);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdDispatch);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdDispatchIndirect);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdDraw);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdDrawIndexed);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdDrawIndexedIndirect);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdDrawIndirect);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdEndQuery);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdEndRenderPass);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdExecuteCommands);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdFillBuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdNextSubpass);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdPipelineBarrier);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdPushConstants);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdResetEvent);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdResetQueryPool);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdResolveImage);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdSetBlendConstants);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdSetDepthBias);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdSetDepthBounds);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdSetEvent);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdSetLineWidth);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdSetScissor);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdSetStencilCompareMask);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdSetStencilReference);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdSetStencilWriteMask);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdSetViewport);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdUpdateBuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdWaitEvents);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCmdWriteTimestamp);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateBuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateBufferView);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateCommandPool);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateComputePipelines);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateDescriptorPool);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateDescriptorSetLayout);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateEvent);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateFramebuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateGraphicsPipelines);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateImage);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateImageView);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreatePipelineCache);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreatePipelineLayout);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateRenderPass);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateSampler);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateSemaphore);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateShaderModule);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyBuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyBufferView);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyCommandPool);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyDescriptorPool);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyDescriptorSetLayout);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyDevice);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyEvent);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyFramebuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyImage);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyImageView);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyPipeline);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyPipelineCache);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyPipelineLayout);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyRenderPass);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroySampler);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroySemaphore);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyShaderModule);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDeviceWaitIdle);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkEndCommandBuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkFreeCommandBuffers);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkFreeDescriptorSets);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkFreeMemory);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkFlushMappedMemoryRanges);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetBufferMemoryRequirements);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetDeviceMemoryCommitment);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetDeviceQueue);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetEventStatus);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetFenceStatus);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetImageMemoryRequirements);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetImageSparseMemoryRequirements);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetImageSubresourceLayout);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetRenderAreaGranularity);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkInvalidateMappedMemoryRanges);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkMapMemory);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkMergePipelineCaches);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkQueueSubmit);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkQueueWaitIdle);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkResetCommandBuffer);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkResetCommandPool);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkResetDescriptorPool);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkResetFences);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkResetEvent);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkSetEvent);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkUnmapMemory);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkUpdateDescriptorSets);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkWaitForFences);
|
|
||||||
|
|
||||||
// VK_KHR_display_swapchain
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateSharedSwapchainsKHR);
|
|
||||||
|
|
||||||
// VK_KHR_surface
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroySurfaceKHR);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfaceFormatsKHR);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfacePresentModesKHR);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfaceSupportKHR);
|
|
||||||
|
|
||||||
// VK_KHR_swapchain
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkAcquireNextImageKHR);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkCreateSwapchainKHR);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroySwapchainKHR);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetSwapchainImagesKHR);
|
|
||||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkQueuePresentKHR);
|
|
||||||
|
|
||||||
#undef NAZARA_VULKAN_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;
|
|
||||||
VkAllocationCallbacks m_allocator;
|
|
||||||
VkDevice m_device;
|
|
||||||
VkPhysicalDevice m_physicalDevice;
|
|
||||||
VkResult m_lastErrorCode;
|
|
||||||
std::unordered_set<String> m_loadedExtensions;
|
|
||||||
std::unordered_set<String> m_loadedLayers;
|
|
||||||
std::vector<QueueFamilyInfo> m_enabledQueuesInfos;
|
|
||||||
std::vector<const QueueList*> m_queuesByFamily;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDevice.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKDEVICE_HPP
|
|
||||||
|
|
@ -1,117 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkQueue.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline Device::Device(Instance& instance) :
|
|
||||||
m_instance(instance),
|
|
||||||
m_device(VK_NULL_HANDLE),
|
|
||||||
m_physicalDevice(VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Device::~Device()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Device::Destroy()
|
|
||||||
{
|
|
||||||
if (m_device != VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
vkDeviceWaitIdle(m_device);
|
|
||||||
vkDestroyDevice(m_device, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
|
||||||
|
|
||||||
m_device = VK_NULL_HANDLE;
|
|
||||||
m_physicalDevice = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const std::vector<Device::QueueFamilyInfo>& Device::GetEnabledQueues() const
|
|
||||||
{
|
|
||||||
return m_enabledQueuesInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const Device::QueueList& Device::GetEnabledQueues(UInt32 familyQueue) const
|
|
||||||
{
|
|
||||||
NazaraAssert(familyQueue < m_enabledQueuesInfos.size(), "Invalid family queue");
|
|
||||||
|
|
||||||
return *m_queuesByFamily[familyQueue];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Queue Device::GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex)
|
|
||||||
{
|
|
||||||
VkQueue queue;
|
|
||||||
vkGetDeviceQueue(m_device, queueFamilyIndex, queueIndex, &queue);
|
|
||||||
|
|
||||||
return Queue(CreateHandle(), queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Instance& Device::GetInstance()
|
|
||||||
{
|
|
||||||
return m_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const Instance& Device::GetInstance() const
|
|
||||||
{
|
|
||||||
return m_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult Device::GetLastErrorCode() const
|
|
||||||
{
|
|
||||||
return m_lastErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkPhysicalDevice Device::GetPhysicalDevice() const
|
|
||||||
{
|
|
||||||
return m_physicalDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Device::IsExtensionLoaded(const String& extensionName)
|
|
||||||
{
|
|
||||||
return m_loadedExtensions.count(extensionName) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Device::IsLayerLoaded(const String& layerName)
|
|
||||||
{
|
|
||||||
return m_loadedLayers.count(layerName) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Device::WaitForIdle()
|
|
||||||
{
|
|
||||||
m_lastErrorCode = vkDeviceWaitIdle(m_device);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to wait for device idle");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Device::operator VkDevice()
|
|
||||||
{
|
|
||||||
return m_device;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline PFN_vkVoidFunction Device::GetProcAddr(const char* name)
|
|
||||||
{
|
|
||||||
PFN_vkVoidFunction func = m_instance.GetDeviceProcAddr(m_device, name);
|
|
||||||
if (!func)
|
|
||||||
NazaraError("Failed to get " + String(name) + " address");
|
|
||||||
|
|
||||||
return func;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKDEVICEMEMORY_HPP
|
|
||||||
#define NAZARA_VULKAN_VKDEVICEMEMORY_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class DeviceMemory : public DeviceObject<DeviceMemory, VkDeviceMemory, VkMemoryAllocateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
DeviceMemory();
|
|
||||||
DeviceMemory(const DeviceMemory&) = delete;
|
|
||||||
DeviceMemory(DeviceMemory&& memory);
|
|
||||||
~DeviceMemory() = default;
|
|
||||||
|
|
||||||
using DeviceObject::Create;
|
|
||||||
inline bool Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool Create(const DeviceHandle& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
|
|
||||||
inline void* GetMappedPointer();
|
|
||||||
|
|
||||||
inline bool Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags = 0);
|
|
||||||
|
|
||||||
inline void Unmap();
|
|
||||||
|
|
||||||
DeviceMemory& operator=(const DeviceMemory&) = delete;
|
|
||||||
DeviceMemory& operator=(DeviceMemory&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator);
|
|
||||||
|
|
||||||
void* m_mappedPtr;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDeviceMemory.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKDEVICEMEMORY_HPP
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDeviceMemory.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkPhysicalDevice.hpp>
|
|
||||||
#include <Nazara/Vulkan/Vulkan.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline DeviceMemory::DeviceMemory() :
|
|
||||||
m_mappedPtr(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceMemory::DeviceMemory(DeviceMemory&& memory) :
|
|
||||||
DeviceObject(std::move(memory))
|
|
||||||
{
|
|
||||||
m_mappedPtr = memory.m_mappedPtr;
|
|
||||||
memory.m_mappedPtr = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkMemoryAllocateInfo allocInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
size, // VkDeviceSize allocationSize;
|
|
||||||
memoryType // uint32_t memoryTypeIndex;
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(device, allocInfo, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
const Vk::PhysicalDevice& deviceInfo = Vulkan::GetPhysicalDeviceInfo(device->GetPhysicalDevice());
|
|
||||||
|
|
||||||
UInt32 typeMask = 1;
|
|
||||||
for (UInt32 i = 0; i < VK_MAX_MEMORY_TYPES; ++i)
|
|
||||||
{
|
|
||||||
if (typeBits & typeMask)
|
|
||||||
{
|
|
||||||
if ((deviceInfo.memoryProperties.memoryTypes[i].propertyFlags & properties) == properties)
|
|
||||||
return Create(device, size, i, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
typeMask <<= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
NazaraError("Failed to find a memory type suitable for typeBits: " + String::Number(typeBits) + " and properties: 0x" + String::Number(properties, 16));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void* DeviceMemory::GetMappedPointer()
|
|
||||||
{
|
|
||||||
return m_mappedPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool DeviceMemory::Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_device->vkMapMemory(*m_device, m_handle, offset, size, flags, &m_mappedPtr);
|
|
||||||
if (m_lastErrorCode != VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to map device memory");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DeviceMemory::Unmap()
|
|
||||||
{
|
|
||||||
NazaraAssert(m_mappedPtr != nullptr, "Memory is not mapped");
|
|
||||||
|
|
||||||
m_device->vkUnmapMemory(*m_device, m_handle);
|
|
||||||
m_mappedPtr = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult DeviceMemory::CreateHelper(const DeviceHandle& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle)
|
|
||||||
{
|
|
||||||
return device->vkAllocateMemory(*device, allocInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void DeviceMemory::DestroyHelper(const DeviceHandle& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkFreeMemory(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKDEVICEOBJECT_HPP
|
|
||||||
#define NAZARA_VULKAN_VKDEVICEOBJECT_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
template<typename C, typename VkType, typename CreateInfo>
|
|
||||||
class DeviceObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline DeviceObject();
|
|
||||||
DeviceObject(const DeviceObject&) = delete;
|
|
||||||
DeviceObject(DeviceObject&&);
|
|
||||||
inline ~DeviceObject();
|
|
||||||
|
|
||||||
inline bool Create(const DeviceHandle& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline void Destroy();
|
|
||||||
|
|
||||||
inline bool IsValid() const;
|
|
||||||
|
|
||||||
inline const DeviceHandle& GetDevice() const;
|
|
||||||
inline VkResult GetLastErrorCode() const;
|
|
||||||
|
|
||||||
DeviceObject& operator=(const DeviceObject&) = delete;
|
|
||||||
DeviceObject& operator=(DeviceObject&&) = delete;
|
|
||||||
|
|
||||||
inline operator VkType() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
DeviceHandle m_device;
|
|
||||||
VkAllocationCallbacks m_allocator;
|
|
||||||
VkType m_handle;
|
|
||||||
mutable VkResult m_lastErrorCode;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKDEVICEOBJECT_HPP
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkCommandPool.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
template<typename C, typename VkType, typename CreateInfo>
|
|
||||||
inline DeviceObject<C, VkType, CreateInfo>::DeviceObject() :
|
|
||||||
m_handle(VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename C, typename VkType, typename CreateInfo>
|
|
||||||
inline DeviceObject<C, VkType, CreateInfo>::DeviceObject(DeviceObject&& object) :
|
|
||||||
m_device(std::move(object.m_device)),
|
|
||||||
m_allocator(object.m_allocator),
|
|
||||||
m_handle(object.m_handle),
|
|
||||||
m_lastErrorCode(object.m_lastErrorCode)
|
|
||||||
{
|
|
||||||
object.m_handle = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename C, typename VkType, typename CreateInfo>
|
|
||||||
inline DeviceObject<C, VkType, CreateInfo>::~DeviceObject()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename C, typename VkType, typename CreateInfo>
|
|
||||||
inline bool DeviceObject<C, VkType, CreateInfo>::Create(const DeviceHandle& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
m_device = device;
|
|
||||||
m_lastErrorCode = C::CreateHelper(m_device, &createInfo, allocator, &m_handle);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create Vulkan object");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the allocator to access them when needed
|
|
||||||
if (allocator)
|
|
||||||
m_allocator = *allocator;
|
|
||||||
else
|
|
||||||
m_allocator.pfnAllocation = nullptr;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename C, typename VkType, typename CreateInfo>
|
|
||||||
inline void DeviceObject<C, VkType, CreateInfo>::Destroy()
|
|
||||||
{
|
|
||||||
if (IsValid())
|
|
||||||
{
|
|
||||||
C::DestroyHelper(m_device, m_handle, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
|
||||||
m_handle = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename C, typename VkType, typename CreateInfo>
|
|
||||||
inline bool DeviceObject<C, VkType, CreateInfo>::IsValid() const
|
|
||||||
{
|
|
||||||
return m_handle != VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename C, typename VkType, typename CreateInfo>
|
|
||||||
inline const DeviceHandle& DeviceObject<C, VkType, CreateInfo>::GetDevice() const
|
|
||||||
{
|
|
||||||
return m_device;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename C, typename VkType, typename CreateInfo>
|
|
||||||
inline VkResult DeviceObject<C, VkType, CreateInfo>::GetLastErrorCode() const
|
|
||||||
{
|
|
||||||
return m_lastErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename C, typename VkType, typename CreateInfo>
|
|
||||||
inline DeviceObject<C, VkType, CreateInfo>::operator VkType() const
|
|
||||||
{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
#include "VkDeviceObject.hpp"
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKFRAMEBUFFER_HPP
|
|
||||||
#define NAZARA_VULKAN_VKFRAMEBUFFER_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class Framebuffer : public DeviceObject<Framebuffer, VkFramebuffer, VkFramebufferCreateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Framebuffer() = default;
|
|
||||||
Framebuffer(const Framebuffer&) = delete;
|
|
||||||
Framebuffer(Framebuffer&&) = default;
|
|
||||||
~Framebuffer() = default;
|
|
||||||
|
|
||||||
Framebuffer& operator=(const Framebuffer&) = delete;
|
|
||||||
Framebuffer& operator=(Framebuffer&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkFramebufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFramebuffer* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkFramebuffer handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkFramebuffer.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKFRAMEBUFFER_HPP
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkFramebuffer.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline VkResult Framebuffer::CreateHelper(const DeviceHandle& device, const VkFramebufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFramebuffer* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateFramebuffer(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Framebuffer::DestroyHelper(const DeviceHandle& device, VkFramebuffer handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyFramebuffer(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKIMAGE_HPP
|
|
||||||
#define NAZARA_VULKAN_VKIMAGE_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class Image : public DeviceObject<Image, VkImage, VkImageCreateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Image() = default;
|
|
||||||
Image(const Image&) = delete;
|
|
||||||
Image(Image&&) = default;
|
|
||||||
~Image() = default;
|
|
||||||
|
|
||||||
bool BindImageMemory(VkDeviceMemory memory, VkDeviceSize offset = 0);
|
|
||||||
|
|
||||||
VkMemoryRequirements GetMemoryRequirements() const;
|
|
||||||
|
|
||||||
Image& operator=(const Image&) = delete;
|
|
||||||
Image& operator=(Image&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkImage handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkImage.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKIMAGE_HPP
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkImage.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline bool Image::BindImageMemory(VkDeviceMemory memory, VkDeviceSize offset)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_device->vkBindImageMemory(*m_device, m_handle, memory, offset);
|
|
||||||
if (m_lastErrorCode != VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to bind buffer memory");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkMemoryRequirements Image::GetMemoryRequirements() const
|
|
||||||
{
|
|
||||||
NazaraAssert(IsValid(), "Invalid image");
|
|
||||||
|
|
||||||
VkMemoryRequirements memoryRequirements;
|
|
||||||
m_device->vkGetImageMemoryRequirements(*m_device, m_handle, &memoryRequirements);
|
|
||||||
|
|
||||||
return memoryRequirements;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult Image::CreateHelper(const DeviceHandle& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateImage(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Image::DestroyHelper(const DeviceHandle& device, VkImage handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyImage(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKIMAGEVIEW_HPP
|
|
||||||
#define NAZARA_VULKAN_VKIMAGEVIEW_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class ImageView : public DeviceObject<ImageView, VkImageView, VkImageViewCreateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ImageView() = default;
|
|
||||||
ImageView(const ImageView&) = delete;
|
|
||||||
ImageView(ImageView&&) = default;
|
|
||||||
~ImageView() = default;
|
|
||||||
|
|
||||||
ImageView& operator=(const ImageView&) = delete;
|
|
||||||
ImageView& operator=(ImageView&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkImageViewCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImageView* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkImageView handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkImageView.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKIMAGEVIEW_HPP
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkImageView.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline VkResult ImageView::CreateHelper(const DeviceHandle& device, const VkImageViewCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImageView* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateImageView(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void ImageView::DestroyHelper(const DeviceHandle& device, VkImageView handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyImageView(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,141 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKINSTANCE_HPP
|
|
||||||
#define NAZARA_VULKAN_VKINSTANCE_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Core/String.hpp>
|
|
||||||
#include <Nazara/Vulkan/Config.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkLoader.hpp>
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class NAZARA_VULKAN_API Instance
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline Instance();
|
|
||||||
Instance(const Instance&) = delete;
|
|
||||||
Instance(Instance&&) = delete;
|
|
||||||
inline ~Instance();
|
|
||||||
|
|
||||||
bool Create(const VkInstanceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool Create(const String& appName, UInt32 appVersion, const String& engineName, UInt32 engineVersion, const std::vector<const char*>& layers, const std::vector<const char*>& extensions, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline void Destroy();
|
|
||||||
|
|
||||||
bool EnumeratePhysicalDevices(std::vector<VkPhysicalDevice>* physicalDevices);
|
|
||||||
|
|
||||||
inline PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* name);
|
|
||||||
|
|
||||||
inline VkPhysicalDeviceFeatures GetPhysicalDeviceFeatures(VkPhysicalDevice device);
|
|
||||||
inline VkFormatProperties GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format);
|
|
||||||
inline bool GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties);
|
|
||||||
inline VkPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device);
|
|
||||||
inline VkPhysicalDeviceProperties GetPhysicalDeviceProperties(VkPhysicalDevice device);
|
|
||||||
bool GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector<VkQueueFamilyProperties>* queueFamilyProperties);
|
|
||||||
|
|
||||||
inline VkResult GetLastErrorCode() const;
|
|
||||||
|
|
||||||
inline bool IsExtensionLoaded(const String& extensionName);
|
|
||||||
inline bool IsLayerLoaded(const String& layerName);
|
|
||||||
|
|
||||||
Instance& operator=(const Instance&) = delete;
|
|
||||||
Instance& operator=(Instance&&) = delete;
|
|
||||||
|
|
||||||
inline operator VkInstance();
|
|
||||||
|
|
||||||
// Vulkan functions
|
|
||||||
#define NAZARA_VULKAN_INSTANCE_FUNCTION(func) PFN_##func func
|
|
||||||
|
|
||||||
// Vulkan core
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkCreateDevice);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkDestroyInstance);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkEnumeratePhysicalDevices);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetDeviceProcAddr);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceFeatures);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceFormatProperties);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceImageFormatProperties);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceMemoryProperties);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceProperties);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceQueueFamilyProperties);
|
|
||||||
|
|
||||||
// VK_KHR_display
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkCreateDisplayModeKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkCreateDisplayPlaneSurfaceKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetDisplayModePropertiesKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetDisplayPlaneCapabilitiesKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetDisplayPlaneSupportedDisplaysKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPlanePropertiesKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPropertiesKHR);
|
|
||||||
|
|
||||||
// VK_KHR_surface
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkDestroySurfaceKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceFormatsKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfacePresentModesKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceSupportKHR);
|
|
||||||
|
|
||||||
// VK_EXT_debug_report
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkCreateDebugReportCallbackEXT);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkDestroyDebugReportCallbackEXT);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkDebugReportMessageEXT);
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
|
||||||
// VK_KHR_android_surface
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkCreateAndroidSurfaceKHR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
|
||||||
// VK_KHR_mir_surface
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkCreateMirSurfaceKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceMirPresentationSupportKHR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
||||||
// VK_KHR_xcb_surface
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkCreateXcbSurfaceKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceXcbPresentationSupportKHR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
|
||||||
// VK_KHR_xlib_surface
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkCreateXlibSurfaceKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceXlibPresentationSupportKHR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
||||||
// VK_KHR_wayland_surface
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkCreateWaylandSurfaceKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceWaylandPresentationSupportKHR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
|
||||||
// VK_KHR_win32_surface
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkCreateWin32SurfaceKHR);
|
|
||||||
NAZARA_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceWin32PresentationSupportKHR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef NAZARA_VULKAN_INSTANCE_FUNCTION
|
|
||||||
|
|
||||||
private:
|
|
||||||
inline PFN_vkVoidFunction GetProcAddr(const char* name);
|
|
||||||
|
|
||||||
VkAllocationCallbacks m_allocator;
|
|
||||||
VkInstance m_instance;
|
|
||||||
VkResult m_lastErrorCode;
|
|
||||||
std::unordered_set<String> m_loadedExtensions;
|
|
||||||
std::unordered_set<String> m_loadedLayers;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkInstance.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKINSTANCE_HPP
|
|
||||||
|
|
@ -1,143 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline Instance::Instance() :
|
|
||||||
m_instance(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Instance::~Instance()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Instance::Create(const String& appName, UInt32 appVersion, const String& engineName, UInt32 engineVersion, const std::vector<const char*>& layers, const std::vector<const char*>& extensions, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkApplicationInfo appInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
|
||||||
nullptr,
|
|
||||||
appName.GetConstBuffer(),
|
|
||||||
appVersion,
|
|
||||||
engineName.GetConstBuffer(),
|
|
||||||
engineVersion
|
|
||||||
};
|
|
||||||
|
|
||||||
VkInstanceCreateInfo instanceInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
|
||||||
nullptr,
|
|
||||||
0,
|
|
||||||
&appInfo,
|
|
||||||
static_cast<UInt32>(layers.size()),
|
|
||||||
(!layers.empty()) ? layers.data() : nullptr,
|
|
||||||
static_cast<UInt32>(extensions.size()),
|
|
||||||
(!extensions.empty()) ? extensions.data() : nullptr
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(instanceInfo, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Instance::Destroy()
|
|
||||||
{
|
|
||||||
if (m_instance)
|
|
||||||
{
|
|
||||||
vkDestroyInstance(m_instance, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
|
||||||
m_instance = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline PFN_vkVoidFunction Instance::GetDeviceProcAddr(VkDevice device, const char* name)
|
|
||||||
{
|
|
||||||
PFN_vkVoidFunction func = vkGetDeviceProcAddr(device, name);
|
|
||||||
if (!func)
|
|
||||||
NazaraError("Failed to get " + String(name) + " address");
|
|
||||||
|
|
||||||
return func;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult Instance::GetLastErrorCode() const
|
|
||||||
{
|
|
||||||
return m_lastErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Instance::IsExtensionLoaded(const String& extensionName)
|
|
||||||
{
|
|
||||||
return m_loadedExtensions.count(extensionName) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Instance::IsLayerLoaded(const String& layerName)
|
|
||||||
{
|
|
||||||
return m_loadedLayers.count(layerName) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Instance::operator VkInstance()
|
|
||||||
{
|
|
||||||
return m_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkPhysicalDeviceFeatures Instance::GetPhysicalDeviceFeatures(VkPhysicalDevice device)
|
|
||||||
{
|
|
||||||
VkPhysicalDeviceFeatures features;
|
|
||||||
vkGetPhysicalDeviceFeatures(device, &features);
|
|
||||||
|
|
||||||
return features;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkFormatProperties Instance::GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format)
|
|
||||||
{
|
|
||||||
VkFormatProperties formatProperties;
|
|
||||||
vkGetPhysicalDeviceFormatProperties(device, format, &formatProperties);
|
|
||||||
|
|
||||||
return formatProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Instance::GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = vkGetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, imageFormatProperties);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to get physical device image format properties");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkPhysicalDeviceMemoryProperties Instance::GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device)
|
|
||||||
{
|
|
||||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
|
||||||
vkGetPhysicalDeviceMemoryProperties(device, &memoryProperties);
|
|
||||||
|
|
||||||
return memoryProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkPhysicalDeviceProperties Instance::GetPhysicalDeviceProperties(VkPhysicalDevice device)
|
|
||||||
{
|
|
||||||
VkPhysicalDeviceProperties properties;
|
|
||||||
vkGetPhysicalDeviceProperties(device, &properties);
|
|
||||||
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline PFN_vkVoidFunction Instance::GetProcAddr(const char* name)
|
|
||||||
{
|
|
||||||
PFN_vkVoidFunction func = Loader::GetInstanceProcAddr(m_instance, name);
|
|
||||||
if (!func)
|
|
||||||
NazaraError("Failed to get " + String(name) + " address");
|
|
||||||
|
|
||||||
return func;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKLOADER_HPP
|
|
||||||
#define NAZARA_VULKAN_VKLOADER_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Core/DynLib.hpp>
|
|
||||||
#include <Nazara/Vulkan/Config.hpp>
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class NAZARA_VULKAN_API Loader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Loader() = delete;
|
|
||||||
~Loader() = delete;
|
|
||||||
|
|
||||||
static bool EnumerateInstanceExtensionProperties(std::vector<VkExtensionProperties>* properties, const char* layerName = nullptr);
|
|
||||||
static bool EnumerateInstanceLayerProperties(std::vector<VkLayerProperties>* properties);
|
|
||||||
|
|
||||||
static inline PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name);
|
|
||||||
|
|
||||||
static bool Initialize();
|
|
||||||
static void Uninitialize();
|
|
||||||
|
|
||||||
// Vulkan functions
|
|
||||||
#define NAZARA_VULKAN_GLOBAL_FUNCTION(func) static PFN_##func func
|
|
||||||
|
|
||||||
NAZARA_VULKAN_GLOBAL_FUNCTION(vkCreateInstance);
|
|
||||||
NAZARA_VULKAN_GLOBAL_FUNCTION(vkEnumerateInstanceExtensionProperties);
|
|
||||||
NAZARA_VULKAN_GLOBAL_FUNCTION(vkEnumerateInstanceLayerProperties);
|
|
||||||
NAZARA_VULKAN_GLOBAL_FUNCTION(vkGetInstanceProcAddr);
|
|
||||||
|
|
||||||
#undef NAZARA_VULKAN_GLOBAL_FUNCTION
|
|
||||||
|
|
||||||
private:
|
|
||||||
static DynLib s_vulkanLib;
|
|
||||||
static VkResult s_lastErrorCode;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkLoader.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKLOADER_HPP
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkLoader.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline PFN_vkVoidFunction Loader::GetInstanceProcAddr(VkInstance instance, const char* name)
|
|
||||||
{
|
|
||||||
return vkGetInstanceProcAddr(instance, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKPHYSICALDEVICE_HPP
|
|
||||||
#define NAZARA_VULKAN_VKPHYSICALDEVICE_HPP
|
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
struct PhysicalDevice
|
|
||||||
{
|
|
||||||
VkPhysicalDevice device;
|
|
||||||
VkPhysicalDeviceFeatures features;
|
|
||||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
|
||||||
VkPhysicalDeviceProperties properties;
|
|
||||||
std::vector<VkQueueFamilyProperties> queues;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKPHYSICALDEVICE_HPP
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKPIPELINE_HPP
|
|
||||||
#define NAZARA_VULKAN_VKPIPELINE_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class Pipeline
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline Pipeline();
|
|
||||||
Pipeline(const Pipeline&) = delete;
|
|
||||||
Pipeline(Pipeline&&);
|
|
||||||
inline ~Pipeline();
|
|
||||||
|
|
||||||
inline bool CreateCompute(const DeviceHandle& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache = VK_NULL_HANDLE, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool CreateGraphics(const DeviceHandle& device, const VkGraphicsPipelineCreateInfo& createInfo, VkPipelineCache cache = VK_NULL_HANDLE, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline void Destroy();
|
|
||||||
|
|
||||||
inline const DeviceHandle& GetDevice() const;
|
|
||||||
inline VkResult GetLastErrorCode() const;
|
|
||||||
|
|
||||||
Pipeline& operator=(const Pipeline&) = delete;
|
|
||||||
Pipeline& operator=(Pipeline&&) = delete;
|
|
||||||
|
|
||||||
inline operator VkPipeline() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
inline bool Create(const DeviceHandle& device, VkResult result, const VkAllocationCallbacks* allocator);
|
|
||||||
|
|
||||||
DeviceHandle m_device;
|
|
||||||
VkAllocationCallbacks m_allocator;
|
|
||||||
VkPipeline m_handle;
|
|
||||||
mutable VkResult m_lastErrorCode;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkPipeline.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKPIPELINE_HPP
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkPipeline.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline Pipeline::Pipeline() :
|
|
||||||
m_handle(VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Pipeline::Pipeline(Pipeline&& object) :
|
|
||||||
m_device(std::move(object.m_device)),
|
|
||||||
m_allocator(object.m_allocator),
|
|
||||||
m_handle(object.m_handle),
|
|
||||||
m_lastErrorCode(object.m_lastErrorCode)
|
|
||||||
{
|
|
||||||
object.m_handle = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Pipeline::~Pipeline()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Pipeline::CreateCompute(const DeviceHandle& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return Create(device, device->vkCreateComputePipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Pipeline::CreateGraphics(const DeviceHandle& device, const VkGraphicsPipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return Create(device, device->vkCreateGraphicsPipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Pipeline::Destroy()
|
|
||||||
{
|
|
||||||
if (m_handle != VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
m_device->vkDestroyPipeline(*m_device, m_handle, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
|
||||||
m_handle = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const DeviceHandle& Pipeline::GetDevice() const
|
|
||||||
{
|
|
||||||
return m_device;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult Pipeline::GetLastErrorCode() const
|
|
||||||
{
|
|
||||||
return m_lastErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Pipeline::operator VkPipeline() const
|
|
||||||
{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Pipeline::Create(const DeviceHandle& device, VkResult result, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
m_device = device;
|
|
||||||
m_lastErrorCode = result;
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create Vulkan object");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the allocator to access them when needed
|
|
||||||
if (allocator)
|
|
||||||
m_allocator = *allocator;
|
|
||||||
else
|
|
||||||
m_allocator.pfnAllocation = nullptr;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKPIPELINECACHE_HPP
|
|
||||||
#define NAZARA_VULKAN_VKPIPELINECACHE_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class PipelineCache : public DeviceObject<PipelineCache, VkPipelineCache, VkPipelineCacheCreateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
PipelineCache() = default;
|
|
||||||
PipelineCache(const PipelineCache&) = delete;
|
|
||||||
PipelineCache(PipelineCache&&) = default;
|
|
||||||
~PipelineCache() = default;
|
|
||||||
|
|
||||||
PipelineCache& operator=(const PipelineCache&) = delete;
|
|
||||||
PipelineCache& operator=(PipelineCache&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkPipelineCacheCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineCache* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkPipelineCache handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkPipelineCache.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKPIPELINECACHE_HPP
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkPipelineCache.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline VkResult PipelineCache::CreateHelper(const DeviceHandle& device, const VkPipelineCacheCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineCache* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreatePipelineCache(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void PipelineCache::DestroyHelper(const DeviceHandle& device, VkPipelineCache handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyPipelineCache(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKPIPELINELAYOUT_HPP
|
|
||||||
#define NAZARA_VULKAN_VKPIPELINELAYOUT_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class PipelineLayout : public DeviceObject<PipelineLayout, VkPipelineLayout, VkPipelineLayoutCreateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
PipelineLayout() = default;
|
|
||||||
PipelineLayout(const PipelineLayout&) = delete;
|
|
||||||
PipelineLayout(PipelineLayout&&) = default;
|
|
||||||
~PipelineLayout() = default;
|
|
||||||
|
|
||||||
PipelineLayout& operator=(const PipelineLayout&) = delete;
|
|
||||||
PipelineLayout& operator=(PipelineLayout&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineLayout* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkPipelineLayout handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkPipelineLayout.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKPIPELINELAYOUT_HPP
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkPipelineLayout.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline VkResult PipelineLayout::CreateHelper(const DeviceHandle& device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineLayout* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreatePipelineLayout(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void PipelineLayout::DestroyHelper(const DeviceHandle& device, VkPipelineLayout handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyPipelineLayout(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKQUEUE_HPP
|
|
||||||
#define NAZARA_VULKAN_VKQUEUE_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class Queue
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline Queue();
|
|
||||||
inline Queue(const DeviceHandle& device, VkQueue queue);
|
|
||||||
inline Queue(const Queue& queue);
|
|
||||||
inline Queue(Queue&& queue);
|
|
||||||
inline ~Queue() = default;
|
|
||||||
|
|
||||||
inline const DeviceHandle& GetDevice() const;
|
|
||||||
inline VkResult GetLastErrorCode() const;
|
|
||||||
|
|
||||||
inline bool Present(const VkPresentInfoKHR& presentInfo) const;
|
|
||||||
inline bool Present(VkSwapchainKHR swapchain, UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE) const;
|
|
||||||
|
|
||||||
inline bool Submit(const VkSubmitInfo& submit, VkFence fence = VK_NULL_HANDLE) const;
|
|
||||||
inline bool Submit(UInt32 submitCount, const VkSubmitInfo* submits, VkFence fence = VK_NULL_HANDLE) const;
|
|
||||||
|
|
||||||
inline bool WaitIdle() const;
|
|
||||||
|
|
||||||
Queue& operator=(const Queue& queue) = delete;
|
|
||||||
inline Queue& operator=(Queue&&);
|
|
||||||
|
|
||||||
inline operator VkQueue();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
DeviceHandle m_device;
|
|
||||||
VkQueue m_handle;
|
|
||||||
mutable VkResult m_lastErrorCode;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkQueue.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKQUEUE_HPP
|
|
||||||
|
|
@ -1,115 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkQueue.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline Queue::Queue() :
|
|
||||||
Queue(DeviceHandle(), VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Queue::Queue(const DeviceHandle& device, VkQueue queue) :
|
|
||||||
m_device(device),
|
|
||||||
m_handle(queue),
|
|
||||||
m_lastErrorCode(VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Queue::Queue(const Queue& queue) :
|
|
||||||
m_device(queue.m_device),
|
|
||||||
m_handle(queue.m_handle),
|
|
||||||
m_lastErrorCode(queue.m_lastErrorCode)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Queue::Queue(Queue&& queue) :
|
|
||||||
m_device(queue.m_device),
|
|
||||||
m_handle(queue.m_handle),
|
|
||||||
m_lastErrorCode(queue.m_lastErrorCode)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const DeviceHandle& Queue::GetDevice() const
|
|
||||||
{
|
|
||||||
return m_device;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult Queue::GetLastErrorCode() const
|
|
||||||
{
|
|
||||||
return m_lastErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Queue::Present(const VkPresentInfoKHR& presentInfo) const
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_device->vkQueuePresentKHR(m_handle, &presentInfo);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Queue::Present(VkSwapchainKHR swapchain, UInt32 imageIndex, VkSemaphore waitSemaphore) const
|
|
||||||
{
|
|
||||||
VkPresentInfoKHR presentInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
|
|
||||||
nullptr,
|
|
||||||
(waitSemaphore) ? 1U : 0U,
|
|
||||||
&waitSemaphore,
|
|
||||||
1U,
|
|
||||||
&swapchain,
|
|
||||||
&imageIndex,
|
|
||||||
nullptr
|
|
||||||
};
|
|
||||||
|
|
||||||
return Present(presentInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Queue::Submit(const VkSubmitInfo& submit, VkFence fence) const
|
|
||||||
{
|
|
||||||
return Submit(1, &submit, fence);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Queue::Submit(UInt32 submitCount, const VkSubmitInfo* submits, VkFence fence) const
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_device->vkQueueSubmit(m_handle, submitCount, submits, fence);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Queue::WaitIdle() const
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_device->vkQueueWaitIdle(m_handle);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Queue& Queue::operator=(Queue&& queue)
|
|
||||||
{
|
|
||||||
m_device = std::move(queue.m_device);
|
|
||||||
m_handle = queue.m_handle;
|
|
||||||
m_lastErrorCode = queue.m_lastErrorCode;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Queue::operator VkQueue()
|
|
||||||
{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKRENDERPASS_HPP
|
|
||||||
#define NAZARA_VULKAN_VKRENDERPASS_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class RenderPass : public DeviceObject<RenderPass, VkRenderPass, VkRenderPassCreateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
RenderPass() = default;
|
|
||||||
RenderPass(const RenderPass&) = delete;
|
|
||||||
RenderPass(RenderPass&&) = default;
|
|
||||||
~RenderPass() = default;
|
|
||||||
|
|
||||||
RenderPass& operator=(const RenderPass&) = delete;
|
|
||||||
RenderPass& operator=(RenderPass&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkRenderPassCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkRenderPass* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkRenderPass handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkRenderPass.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKRENDERPASS_HPP
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkRenderPass.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline VkResult RenderPass::CreateHelper(const DeviceHandle& device, const VkRenderPassCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkRenderPass* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateRenderPass(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void RenderPass::DestroyHelper(const DeviceHandle& device, VkRenderPass handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyRenderPass(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKSEMAPHORE_HPP
|
|
||||||
#define NAZARA_VULKAN_VKSEMAPHORE_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class Semaphore : public DeviceObject<Semaphore, VkSemaphore, VkSemaphoreCreateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Semaphore() = default;
|
|
||||||
Semaphore(const Semaphore&) = delete;
|
|
||||||
Semaphore(Semaphore&&) = default;
|
|
||||||
~Semaphore() = default;
|
|
||||||
|
|
||||||
using DeviceObject::Create;
|
|
||||||
inline bool Create(const DeviceHandle& device, VkSemaphoreCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
|
|
||||||
Semaphore& operator=(const Semaphore&) = delete;
|
|
||||||
Semaphore& operator=(Semaphore&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkSemaphore handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkSemaphore.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKSEMAPHORE_HPP
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkSemaphore.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline bool Semaphore::Create(const DeviceHandle& device, VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkSemaphoreCreateInfo createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
|
||||||
nullptr,
|
|
||||||
flags
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(device, createInfo, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult Semaphore::CreateHelper(const DeviceHandle& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateSemaphore(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Semaphore::DestroyHelper(const DeviceHandle& device, VkSemaphore handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroySemaphore(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKSHADERMODULE_HPP
|
|
||||||
#define NAZARA_VULKAN_VKSHADERMODULE_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class ShaderModule : public DeviceObject<ShaderModule, VkShaderModule, VkShaderModuleCreateInfo>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ShaderModule() = default;
|
|
||||||
ShaderModule(const ShaderModule&) = delete;
|
|
||||||
ShaderModule(ShaderModule&&) = default;
|
|
||||||
~ShaderModule() = default;
|
|
||||||
|
|
||||||
using DeviceObject::Create;
|
|
||||||
inline bool Create(const DeviceHandle& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
|
|
||||||
ShaderModule& operator=(const ShaderModule&) = delete;
|
|
||||||
ShaderModule& operator=(ShaderModule&&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkShaderModule handle, const VkAllocationCallbacks* allocator);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkShaderModule.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKSHADERMODULE_HPP
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkShaderModule.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline bool ShaderModule::Create(const DeviceHandle& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkShaderModuleCreateInfo createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
size,
|
|
||||||
code
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(device, createInfo, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult ShaderModule::CreateHelper(const DeviceHandle& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateShaderModule(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void ShaderModule::DestroyHelper(const DeviceHandle& device, VkShaderModule handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroyShaderModule(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKSURFACE_HPP
|
|
||||||
#define NAZARA_VULKAN_VKSURFACE_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/Config.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkLoader.hpp>
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class Instance;
|
|
||||||
|
|
||||||
class Surface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline Surface(Instance& instance);
|
|
||||||
Surface(const Surface&) = delete;
|
|
||||||
Surface(Surface&& surface);
|
|
||||||
inline ~Surface();
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
|
||||||
// VK_KHR_android_surface
|
|
||||||
inline bool Create(const VkAndroidSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
|
||||||
// VK_KHR_mir_surface
|
|
||||||
inline bool Create(const VkMirSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool Create(MirConnection* connection, MirSurface* surface, VkMirSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
||||||
// VK_KHR_xcb_surface
|
|
||||||
inline bool Create(const VkXcbSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
|
||||||
// VK_KHR_xlib_surface
|
|
||||||
inline bool Create(const VkXlibSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
||||||
// VK_KHR_wayland_surface
|
|
||||||
inline bool Create(const VkWaylandSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
|
||||||
// VK_KHR_win32_surface
|
|
||||||
inline bool Create(const VkWin32SurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
inline bool Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
inline void Destroy();
|
|
||||||
|
|
||||||
bool GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities) const;
|
|
||||||
bool GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats) const;
|
|
||||||
bool GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes) const;
|
|
||||||
bool GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported) const;
|
|
||||||
|
|
||||||
inline bool IsSupported() const;
|
|
||||||
|
|
||||||
inline VkResult GetLastErrorCode() const;
|
|
||||||
|
|
||||||
Surface& operator=(const Surface&) = delete;
|
|
||||||
Surface& operator=(Surface&&) = delete;
|
|
||||||
|
|
||||||
inline operator VkSurfaceKHR() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
inline bool Create(const VkAllocationCallbacks* allocator);
|
|
||||||
|
|
||||||
Instance& m_instance;
|
|
||||||
VkAllocationCallbacks m_allocator;
|
|
||||||
VkSurfaceKHR m_surface;
|
|
||||||
mutable VkResult m_lastErrorCode;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkSurface.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKSURFACE_HPP
|
|
||||||
|
|
@ -1,314 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkSurface.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline Surface::Surface(Instance& instance) :
|
|
||||||
m_instance(instance),
|
|
||||||
m_surface(VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Surface::Surface(Surface&& surface) :
|
|
||||||
m_instance(surface.m_instance),
|
|
||||||
m_allocator(surface.m_allocator),
|
|
||||||
m_surface(surface.m_surface),
|
|
||||||
m_lastErrorCode(surface.m_lastErrorCode)
|
|
||||||
{
|
|
||||||
surface.m_surface = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Surface::~Surface()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
|
||||||
inline bool Surface::Create(const VkAndroidSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_instance.vkCreateAndroidSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
|
||||||
return Create(allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkAndroidSurfaceCreateInfoKHR createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
window
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(createInfo, allocator);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
|
||||||
inline bool Surface::Create(const VkMirSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_instance.vkCreateMirSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
|
||||||
return Create(allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::Create(MirConnection* connection, MirSurface* surface, VkMirSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkMirSurfaceCreateInfoKHR createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
connection,
|
|
||||||
surface
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(createInfo, allocator);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
||||||
inline bool Surface::Create(const VkXcbSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_instance.vkCreateXcbSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
|
||||||
return Create(allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkXcbSurfaceCreateInfoKHR createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
connection,
|
|
||||||
window
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(createInfo, allocator);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
|
||||||
inline bool Surface::Create(const VkXlibSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_instance.vkCreateXlibSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
|
||||||
return Create(allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkXlibSurfaceCreateInfoKHR createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
display,
|
|
||||||
window
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(createInfo, allocator);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
||||||
inline bool Surface::Create(const VkWaylandSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_instance.vkCreateWaylandSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
|
||||||
return Create(allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkWaylandSurfaceCreateInfoKHR createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
display,
|
|
||||||
surface
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(createInfo, allocator);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
|
||||||
inline bool Surface::Create(const VkWin32SurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_instance.vkCreateWin32SurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
|
||||||
return Create(allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
VkWin32SurfaceCreateInfoKHR createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
|
|
||||||
nullptr,
|
|
||||||
flags,
|
|
||||||
instance,
|
|
||||||
handle
|
|
||||||
};
|
|
||||||
|
|
||||||
return Create(createInfo, allocator);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
inline void Surface::Destroy()
|
|
||||||
{
|
|
||||||
if (m_surface != VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
m_instance.vkDestroySurfaceKHR(m_instance, m_surface, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
|
||||||
m_surface = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult Surface::GetLastErrorCode() const
|
|
||||||
{
|
|
||||||
return m_lastErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities) const
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, m_surface, surfaceCapabilities);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query surface capabilities");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats) const
|
|
||||||
{
|
|
||||||
// First, query format count
|
|
||||||
UInt32 surfaceCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
|
|
||||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, nullptr);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS || surfaceCount == 0)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query format count");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we can get the list of the available physical device
|
|
||||||
surfaceFormats->resize(surfaceCount);
|
|
||||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, surfaceFormats->data());
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query formats");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes) const
|
|
||||||
{
|
|
||||||
// First, query present modes count
|
|
||||||
UInt32 presentModeCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
|
|
||||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, nullptr);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS || presentModeCount == 0)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query present mode count");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we can get the list of the available physical device
|
|
||||||
presentModes->resize(presentModeCount);
|
|
||||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, presentModes->data());
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query present modes");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported) const
|
|
||||||
{
|
|
||||||
VkBool32 presentationSupported = VK_FALSE;
|
|
||||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, m_surface, &presentationSupported);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query surface capabilities");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
*supported = (presentationSupported == VK_TRUE);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::IsSupported() const
|
|
||||||
{
|
|
||||||
if (!m_instance.IsExtensionLoaded("VK_KHR_surface"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
|
||||||
if (m_instance.IsExtensionLoaded("VK_KHR_android_surface"))
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
|
||||||
if (m_instance.IsExtensionLoaded("VK_KHR_mir_surface"))
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
||||||
if (m_instance.IsExtensionLoaded("VK_KHR_xcb_surface"))
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
|
||||||
if (m_instance.IsExtensionLoaded("VK_KHR_xlib_surface"))
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
||||||
if (m_instance.IsExtensionLoaded("VK_KHR_wayland_surface"))
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
|
||||||
if (m_instance.IsExtensionLoaded("VK_KHR_win32_surface"))
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Surface::operator VkSurfaceKHR() const
|
|
||||||
{
|
|
||||||
return m_surface;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Surface::Create(const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create Vulkan surface");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the allocator to access them when needed
|
|
||||||
if (allocator)
|
|
||||||
m_allocator = *allocator;
|
|
||||||
else
|
|
||||||
m_allocator.pfnAllocation = nullptr;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_VKSWAPCHAIN_HPP
|
|
||||||
#define NAZARA_VULKAN_VKSWAPCHAIN_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkImageView.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
class Swapchain : public DeviceObject<Swapchain, VkSwapchainKHR, VkSwapchainCreateInfoKHR>
|
|
||||||
{
|
|
||||||
friend DeviceObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
struct Buffer;
|
|
||||||
|
|
||||||
Swapchain() = default;
|
|
||||||
Swapchain(const Swapchain&) = delete;
|
|
||||||
Swapchain(Swapchain&&) = default;
|
|
||||||
~Swapchain() = default;
|
|
||||||
|
|
||||||
inline bool AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex) const;
|
|
||||||
|
|
||||||
inline bool Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
|
||||||
|
|
||||||
inline const Buffer& GetBuffer(UInt32 index) const;
|
|
||||||
inline const std::vector<Buffer>& GetBuffers() const;
|
|
||||||
inline UInt32 GetBufferCount() const;
|
|
||||||
|
|
||||||
inline bool IsSupported() const;
|
|
||||||
|
|
||||||
Swapchain& operator=(const Swapchain&) = delete;
|
|
||||||
Swapchain& operator=(Swapchain&&) = delete;
|
|
||||||
|
|
||||||
struct Buffer
|
|
||||||
{
|
|
||||||
VkImage image;
|
|
||||||
ImageView view;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle);
|
|
||||||
static inline void DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator);
|
|
||||||
|
|
||||||
std::vector<Buffer> m_buffers;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkSwapchain.inl>
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_VKSWAPCHAIN_HPP
|
|
||||||
|
|
@ -1,121 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkSwapchain.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
inline bool Swapchain::AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex) const
|
|
||||||
{
|
|
||||||
m_lastErrorCode = m_device->vkAcquireNextImageKHR(*m_device, m_handle, timeout, semaphore, fence, imageIndex);
|
|
||||||
switch (m_lastErrorCode)
|
|
||||||
{
|
|
||||||
case VkResult::VK_SUBOPTIMAL_KHR:
|
|
||||||
case VkResult::VK_SUCCESS:
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Swapchain::Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
if (!DeviceObject::Create(device, createInfo, allocator))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
UInt32 imageCount = 0;
|
|
||||||
m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, nullptr);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS || imageCount == 0)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query swapchain image count");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<VkImage> images(imageCount);
|
|
||||||
m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, images.data());
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query swapchain images");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_buffers.resize(imageCount);
|
|
||||||
for (UInt32 i = 0; i < imageCount; ++i)
|
|
||||||
{
|
|
||||||
m_buffers[i].image = images[i];
|
|
||||||
|
|
||||||
VkImageViewCreateInfo imageViewCreateInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
0, // VkImageViewCreateFlags flags;
|
|
||||||
m_buffers[i].image, // VkImage image;
|
|
||||||
VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
|
|
||||||
createInfo.imageFormat, // VkFormat format;
|
|
||||||
{ // VkComponentMapping components;
|
|
||||||
VK_COMPONENT_SWIZZLE_R, // VkComponentSwizzle .r;
|
|
||||||
VK_COMPONENT_SWIZZLE_G, // VkComponentSwizzle .g;
|
|
||||||
VK_COMPONENT_SWIZZLE_B, // VkComponentSwizzle .b;
|
|
||||||
VK_COMPONENT_SWIZZLE_A // VkComponentSwizzle .a;
|
|
||||||
},
|
|
||||||
{ // VkImageSubresourceRange subresourceRange;
|
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags .aspectMask;
|
|
||||||
0, // uint32_t .baseMipLevel;
|
|
||||||
1, // uint32_t .levelCount;
|
|
||||||
0, // uint32_t .baseArrayLayer;
|
|
||||||
1 // uint32_t .layerCount;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!m_buffers[i].view.Create(m_device, imageViewCreateInfo))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create image view for image #" + String::Number(i));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const Swapchain::Buffer& Swapchain::GetBuffer(UInt32 index) const
|
|
||||||
{
|
|
||||||
return m_buffers[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const std::vector<Swapchain::Buffer>& Swapchain::GetBuffers() const
|
|
||||||
{
|
|
||||||
return m_buffers;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline UInt32 Swapchain::GetBufferCount() const
|
|
||||||
{
|
|
||||||
return static_cast<UInt32>(m_buffers.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Swapchain::IsSupported() const
|
|
||||||
{
|
|
||||||
if (!m_device->IsExtensionLoaded("VK_KHR_swapchain"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkResult Swapchain::CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle)
|
|
||||||
{
|
|
||||||
return device->vkCreateSwapchainKHR(*device, createInfo, allocator, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Swapchain::DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
return device->vkDestroySwapchainKHR(*device, handle, allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_VULKAN_HPP
|
|
||||||
#define NAZARA_VULKAN_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Core/Initializer.hpp>
|
|
||||||
#include <Nazara/Core/ParameterList.hpp>
|
|
||||||
#include <Nazara/Vulkan/Config.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkPhysicalDevice.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkSurface.hpp>
|
|
||||||
#include <list>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
class NAZARA_VULKAN_API Vulkan
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Vulkan() = delete;
|
|
||||||
~Vulkan() = delete;
|
|
||||||
|
|
||||||
static Vk::DeviceHandle CreateDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
|
||||||
|
|
||||||
static Vk::Instance& GetInstance();
|
|
||||||
|
|
||||||
static const std::vector<Vk::PhysicalDevice>& GetPhysicalDevices();
|
|
||||||
static const Vk::PhysicalDevice& GetPhysicalDeviceInfo(VkPhysicalDevice physDevice);
|
|
||||||
|
|
||||||
static bool Initialize();
|
|
||||||
|
|
||||||
static bool IsInitialized();
|
|
||||||
|
|
||||||
static Vk::DeviceHandle SelectDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
|
||||||
|
|
||||||
static void SetParameters(const ParameterList& parameters);
|
|
||||||
|
|
||||||
static void Uninitialize();
|
|
||||||
|
|
||||||
private:
|
|
||||||
static std::list<Vk::Device> s_devices;
|
|
||||||
static std::vector<Vk::PhysicalDevice> s_physDevices;
|
|
||||||
static Vk::Instance s_instance;
|
|
||||||
static ParameterList s_initializationParameters;
|
|
||||||
static unsigned int s_moduleReferenceCounter;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_HPP
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
// Copyright (C) 2014 AUTHORS
|
|
||||||
// This file is part of the "Nazara Engine - Module name"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/Config.hpp>
|
|
||||||
#if NAZARA_VULKAN_MANAGE_MEMORY
|
|
||||||
|
|
||||||
#include <Nazara/Core/MemoryManager.hpp>
|
|
||||||
#include <new> // Nécessaire ?
|
|
||||||
|
|
||||||
void* operator new(std::size_t size)
|
|
||||||
{
|
|
||||||
return Nz::MemoryManager::Allocate(size, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* operator new[](std::size_t size)
|
|
||||||
{
|
|
||||||
return Nz::MemoryManager::Allocate(size, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator delete(void* pointer) noexcept
|
|
||||||
{
|
|
||||||
Nz::MemoryManager::Free(pointer, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator delete[](void* pointer) noexcept
|
|
||||||
{
|
|
||||||
Nz::MemoryManager::Free(pointer, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // NAZARA_VULKAN_MANAGE_MEMORY
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/RenderTarget.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
RenderTarget::~RenderTarget()
|
|
||||||
{
|
|
||||||
OnRenderTargetRelease(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,530 +0,0 @@
|
||||||
// Copyright (C) 2015 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/RenderWindow.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
|
||||||
#include <Nazara/Utility/PixelFormat.hpp>
|
|
||||||
#include <Nazara/Vulkan/Vulkan.hpp>
|
|
||||||
#include <array>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
RenderWindow::RenderWindow() :
|
|
||||||
RenderTarget(), Window(),
|
|
||||||
m_surface(Nz::Vulkan::GetInstance()),
|
|
||||||
m_forcedPhysicalDevice(nullptr),
|
|
||||||
m_depthStencilFormat(VK_FORMAT_MAX_ENUM)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderWindow::RenderWindow(VideoMode mode, const String& title, UInt32 style) :
|
|
||||||
RenderWindow()
|
|
||||||
{
|
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
|
||||||
Create(mode, title, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderWindow::RenderWindow(WindowHandle handle) :
|
|
||||||
RenderWindow()
|
|
||||||
{
|
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
|
||||||
Create(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderWindow::~RenderWindow()
|
|
||||||
{
|
|
||||||
// Nécessaire si Window::Destroy est appelé par son destructeur
|
|
||||||
OnWindowDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderWindow::Acquire(UInt32* imageIndex) const
|
|
||||||
{
|
|
||||||
if (!m_swapchain.AcquireNextImage(std::numeric_limits<UInt64>::max(), m_imageReadySemaphore, VK_NULL_HANDLE, imageIndex))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to acquire next image");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderWindow::BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer)
|
|
||||||
{
|
|
||||||
//commandBuffer.SetImageLayout(m_swapchain.GetBuffer(imageIndex).image, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
|
||||||
|
|
||||||
// Temporary
|
|
||||||
if (m_depthStencilFormat != VK_FORMAT_MAX_ENUM)
|
|
||||||
{
|
|
||||||
VkImageSubresourceRange imageRange = {
|
|
||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageAspectFlags aspectMask
|
|
||||||
0, // uint32_t baseMipLevel
|
|
||||||
1, // uint32_t levelCount
|
|
||||||
0, // uint32_t baseArrayLayer
|
|
||||||
1 // uint32_t layerCount
|
|
||||||
};
|
|
||||||
|
|
||||||
commandBuffer.SetImageLayout(m_depthBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, imageRange);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderWindow::BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer)
|
|
||||||
{
|
|
||||||
//commandBuffer.SetImageLayout(m_swapchain.GetBuffer(imageIndex).image, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Vk::Framebuffer& RenderWindow::GetFrameBuffer(UInt32 imageIndex) const
|
|
||||||
{
|
|
||||||
return m_frameBuffers[imageIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 RenderWindow::GetFramebufferCount() const
|
|
||||||
{
|
|
||||||
return static_cast<UInt32>(m_frameBuffers.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderWindow::Create(VideoMode mode, const String& title, UInt32 style)
|
|
||||||
{
|
|
||||||
return Window::Create(mode, title, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderWindow::Create(WindowHandle handle)
|
|
||||||
{
|
|
||||||
return Window::Create(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Vk::DeviceHandle& RenderWindow::GetDevice() const
|
|
||||||
{
|
|
||||||
return m_device;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 RenderWindow::GetPresentableFamilyQueue() const
|
|
||||||
{
|
|
||||||
return m_presentableFamilyQueue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Vk::Surface& RenderWindow::GetSurface() const
|
|
||||||
{
|
|
||||||
return m_surface;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Vk::Swapchain& RenderWindow::GetSwapchain() const
|
|
||||||
{
|
|
||||||
return m_swapchain;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderWindow::Present(UInt32 imageIndex)
|
|
||||||
{
|
|
||||||
NazaraAssert(imageIndex < m_frameBuffers.size(), "Invalid image index");
|
|
||||||
|
|
||||||
m_presentQueue.Present(m_swapchain, imageIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderWindow::IsValid() const
|
|
||||||
{
|
|
||||||
return m_impl != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderWindow::SetDepthStencilFormats(std::vector<PixelFormatType> pixelFormat)
|
|
||||||
{
|
|
||||||
m_wantedDepthStencilFormats = std::move(pixelFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderWindow::SetPhysicalDevice(VkPhysicalDevice device)
|
|
||||||
{
|
|
||||||
m_forcedPhysicalDevice = device;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderWindow::OnWindowCreated()
|
|
||||||
{
|
|
||||||
OnRenderTargetSizeChange(this);
|
|
||||||
|
|
||||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
|
||||||
HWND handle = reinterpret_cast<HWND>(GetHandle());
|
|
||||||
HINSTANCE instance = reinterpret_cast<HINSTANCE>(GetWindowLongPtrW(handle, GWLP_HINSTANCE));
|
|
||||||
bool success = m_surface.Create(instance, handle);
|
|
||||||
#else
|
|
||||||
#error This OS is not supported by Vulkan
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create Vulkan surface");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_device = Vulkan::SelectDevice(m_forcedPhysicalDevice, m_surface, &m_presentableFamilyQueue);
|
|
||||||
if (!m_device)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to get compatible Vulkan device");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_presentQueue = m_device->GetQueue(m_presentableFamilyQueue, 0);
|
|
||||||
|
|
||||||
std::vector<VkSurfaceFormatKHR> surfaceFormats;
|
|
||||||
if (!m_surface.GetFormats(m_forcedPhysicalDevice, &surfaceFormats))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query supported surface formats");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (surfaceFormats.size() == 1 && surfaceFormats[0].format == VK_FORMAT_UNDEFINED)
|
|
||||||
m_colorFormat = VK_FORMAT_B8G8R8A8_UNORM;
|
|
||||||
else
|
|
||||||
m_colorFormat = surfaceFormats[0].format;
|
|
||||||
|
|
||||||
m_colorSpace = surfaceFormats[0].colorSpace;
|
|
||||||
|
|
||||||
if (!m_wantedDepthStencilFormats.empty())
|
|
||||||
{
|
|
||||||
const Vk::PhysicalDevice& deviceInfo = Vulkan::GetPhysicalDeviceInfo(m_forcedPhysicalDevice);
|
|
||||||
|
|
||||||
for (PixelFormatType format : m_wantedDepthStencilFormats)
|
|
||||||
{
|
|
||||||
switch (format)
|
|
||||||
{
|
|
||||||
case PixelFormatType_Depth16:
|
|
||||||
m_depthStencilFormat = VK_FORMAT_D16_UNORM;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PixelFormatType_Depth24:
|
|
||||||
case PixelFormatType_Depth24Stencil8:
|
|
||||||
m_depthStencilFormat = VK_FORMAT_D24_UNORM_S8_UINT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PixelFormatType_Depth32:
|
|
||||||
m_depthStencilFormat = VK_FORMAT_D32_SFLOAT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PixelFormatType_Stencil1:
|
|
||||||
case PixelFormatType_Stencil4:
|
|
||||||
case PixelFormatType_Stencil8:
|
|
||||||
m_depthStencilFormat = VK_FORMAT_S8_UINT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PixelFormatType_Stencil16:
|
|
||||||
m_depthStencilFormat = VK_FORMAT_MAX_ENUM;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
PixelFormatContent formatContent = PixelFormat::GetContent(format);
|
|
||||||
if (formatContent != PixelFormatContent_DepthStencil && formatContent != PixelFormatContent_Stencil)
|
|
||||||
NazaraWarning("Invalid format " + PixelFormat::GetName(format) + " for depth-stencil attachment");
|
|
||||||
|
|
||||||
m_depthStencilFormat = VK_FORMAT_MAX_ENUM;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_depthStencilFormat != VK_FORMAT_MAX_ENUM)
|
|
||||||
{
|
|
||||||
VkFormatProperties formatProperties = m_device->GetInstance().GetPhysicalDeviceFormatProperties(m_forcedPhysicalDevice, m_depthStencilFormat);
|
|
||||||
if (formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
|
||||||
break; //< Found it
|
|
||||||
|
|
||||||
m_depthStencilFormat = VK_FORMAT_MAX_ENUM;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SetupSwapchain())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create swapchain");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_depthStencilFormat != VK_FORMAT_MAX_ENUM && !SetupDepthBuffer())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create depth buffer");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SetupRenderPass())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create render pass");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 imageCount = m_swapchain.GetBufferCount();
|
|
||||||
|
|
||||||
// Framebuffers
|
|
||||||
m_frameBuffers.resize(imageCount);
|
|
||||||
for (UInt32 i = 0; i < imageCount; ++i)
|
|
||||||
{
|
|
||||||
std::array<VkImageView, 2> attachments = {m_swapchain.GetBuffer(i).view, m_depthBufferView};
|
|
||||||
|
|
||||||
VkFramebufferCreateInfo frameBufferCreate = {
|
|
||||||
VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
0, // VkFramebufferCreateFlags flags;
|
|
||||||
m_renderPass, // VkRenderPass renderPass;
|
|
||||||
(attachments[1] != VK_NULL_HANDLE) ? 2U : 1U, // uint32_t attachmentCount;
|
|
||||||
attachments.data(), // const VkImageView* pAttachments;
|
|
||||||
GetWidth(), // uint32_t width;
|
|
||||||
GetHeight(), // uint32_t height;
|
|
||||||
1U // uint32_t layers;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!m_frameBuffers[i].Create(m_device, frameBufferCreate))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create framebuffer for image #" + String::Number(i));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_imageReadySemaphore.Create(m_device);
|
|
||||||
|
|
||||||
m_clock.Restart();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderWindow::OnWindowDestroy()
|
|
||||||
{
|
|
||||||
m_device->WaitForIdle();
|
|
||||||
m_frameBuffers.clear();
|
|
||||||
m_renderPass.Destroy();
|
|
||||||
|
|
||||||
m_swapchain.Destroy();
|
|
||||||
m_surface.Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderWindow::OnWindowResized()
|
|
||||||
{
|
|
||||||
OnRenderTargetSizeChange(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderWindow::SetupDepthBuffer()
|
|
||||||
{
|
|
||||||
VkImageCreateInfo imageCreateInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
0U, // VkImageCreateFlags flags;
|
|
||||||
VK_IMAGE_TYPE_2D, // VkImageType imageType;
|
|
||||||
m_depthStencilFormat, // VkFormat format;
|
|
||||||
{GetWidth(), GetHeight(), 1U}, // VkExtent3D extent;
|
|
||||||
1U, // uint32_t mipLevels;
|
|
||||||
1U, // uint32_t arrayLayers;
|
|
||||||
VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
|
|
||||||
VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
|
|
||||||
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
|
|
||||||
VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
|
|
||||||
0U, // uint32_t queueFamilyIndexCount;
|
|
||||||
nullptr, // const uint32_t* pQueueFamilyIndices;
|
|
||||||
VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!m_depthBuffer.Create(m_device, imageCreateInfo))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create depth buffer");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkMemoryRequirements memoryReq = m_depthBuffer.GetMemoryRequirements();
|
|
||||||
if (!m_depthBufferMemory.Create(m_device, memoryReq.size, memoryReq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to allocate depth buffer memory");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_depthBuffer.BindImageMemory(m_depthBufferMemory))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to bind depth buffer to buffer");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkImageViewCreateInfo imageViewCreateInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
0, // VkImageViewCreateFlags flags;
|
|
||||||
m_depthBuffer, // VkImage image;
|
|
||||||
VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
|
|
||||||
m_depthStencilFormat, // VkFormat format;
|
|
||||||
{ // VkComponentMapping components;
|
|
||||||
VK_COMPONENT_SWIZZLE_R, // VkComponentSwizzle .r;
|
|
||||||
VK_COMPONENT_SWIZZLE_G, // VkComponentSwizzle .g;
|
|
||||||
VK_COMPONENT_SWIZZLE_B, // VkComponentSwizzle .b;
|
|
||||||
VK_COMPONENT_SWIZZLE_A // VkComponentSwizzle .a;
|
|
||||||
},
|
|
||||||
{ // VkImageSubresourceRange subresourceRange;
|
|
||||||
VK_IMAGE_ASPECT_DEPTH_BIT, // VkImageAspectFlags .aspectMask;
|
|
||||||
0, // uint32_t .baseMipLevel;
|
|
||||||
1, // uint32_t .levelCount;
|
|
||||||
0, // uint32_t .baseArrayLayer;
|
|
||||||
1 // uint32_t .layerCount;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!m_depthBufferView.Create(m_device, imageViewCreateInfo))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create depth buffer view");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderWindow::SetupRenderPass()
|
|
||||||
{
|
|
||||||
std::array<VkAttachmentDescription, 2> attachments = {
|
|
||||||
{
|
|
||||||
{
|
|
||||||
0, // VkAttachmentDescriptionFlags flags;
|
|
||||||
m_colorFormat, // VkFormat format;
|
|
||||||
VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
|
|
||||||
VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp loadOp;
|
|
||||||
VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
|
|
||||||
VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
|
|
||||||
VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
|
|
||||||
VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
|
|
||||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR // VkImageLayout finalLayout;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
0, // VkAttachmentDescriptionFlags flags;
|
|
||||||
m_depthStencilFormat, // VkFormat format;
|
|
||||||
VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
|
|
||||||
VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
|
|
||||||
VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp storeOp;
|
|
||||||
VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
|
|
||||||
VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
|
|
||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
|
|
||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
VkAttachmentReference colorReference = {
|
|
||||||
0, // uint32_t attachment;
|
|
||||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
|
|
||||||
};
|
|
||||||
|
|
||||||
VkAttachmentReference depthReference = {
|
|
||||||
1, // uint32_t attachment;
|
|
||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL // VkImageLayout layout;
|
|
||||||
};
|
|
||||||
|
|
||||||
VkSubpassDescription subpass = {
|
|
||||||
0, // VkSubpassDescriptionFlags flags;
|
|
||||||
VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
|
|
||||||
0U, // uint32_t inputAttachmentCount;
|
|
||||||
nullptr, // const VkAttachmentReference* pInputAttachments;
|
|
||||||
1U, // uint32_t colorAttachmentCount;
|
|
||||||
&colorReference, // const VkAttachmentReference* pColorAttachments;
|
|
||||||
nullptr, // const VkAttachmentReference* pResolveAttachments;
|
|
||||||
(m_depthStencilFormat != VK_FORMAT_MAX_ENUM) ? &depthReference : nullptr, // const VkAttachmentReference* pDepthStencilAttachment;
|
|
||||||
0U, // uint32_t preserveAttachmentCount;
|
|
||||||
nullptr // const uint32_t* pPreserveAttachments;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::array<VkSubpassDependency, 2> dependencies;
|
|
||||||
// First dependency at the start of the renderpass
|
|
||||||
// Does the transition from final to initial layout
|
|
||||||
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; // Producer of the dependency
|
|
||||||
dependencies[0].dstSubpass = 0; // Consumer is our single subpass that will wait for the execution depdendency
|
|
||||||
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
||||||
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
||||||
dependencies[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
||||||
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
||||||
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
|
||||||
|
|
||||||
// Second dependency at the end the renderpass
|
|
||||||
// Does the transition from the initial to the final layout
|
|
||||||
dependencies[1].srcSubpass = 0; // Producer of the dependency is our single subpass
|
|
||||||
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL; // Consumer are all commands outside of the renderpass
|
|
||||||
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
||||||
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
||||||
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
||||||
dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
||||||
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
|
||||||
|
|
||||||
VkRenderPassCreateInfo createInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
0, // VkRenderPassCreateFlags flags;
|
|
||||||
(m_depthStencilFormat != VK_FORMAT_MAX_ENUM) ? 2U : 1U, // uint32_t attachmentCount;
|
|
||||||
attachments.data(), // const VkAttachmentDescription* pAttachments;
|
|
||||||
1U, // uint32_t subpassCount;
|
|
||||||
&subpass, // const VkSubpassDescription* pSubpasses;
|
|
||||||
dependencies.size(), // uint32_t dependencyCount;
|
|
||||||
dependencies.data() // const VkSubpassDependency* pDependencies;
|
|
||||||
};
|
|
||||||
|
|
||||||
return m_renderPass.Create(m_device, createInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderWindow::SetupSwapchain()
|
|
||||||
{
|
|
||||||
VkSurfaceCapabilitiesKHR surfaceCapabilities;
|
|
||||||
if (!m_surface.GetCapabilities(m_forcedPhysicalDevice, &surfaceCapabilities))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query surface capabilities");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Nz::UInt32 imageCount = surfaceCapabilities.minImageCount + 1;
|
|
||||||
if (surfaceCapabilities.maxImageCount > 0 && imageCount > surfaceCapabilities.maxImageCount)
|
|
||||||
imageCount = surfaceCapabilities.maxImageCount;
|
|
||||||
|
|
||||||
VkExtent2D extent;
|
|
||||||
if (surfaceCapabilities.currentExtent.width == -1)
|
|
||||||
{
|
|
||||||
extent.width = Nz::Clamp<Nz::UInt32>(GetWidth(), surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width);
|
|
||||||
extent.height = Nz::Clamp<Nz::UInt32>(GetHeight(), surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
extent = surfaceCapabilities.currentExtent;
|
|
||||||
|
|
||||||
std::vector<VkPresentModeKHR> presentModes;
|
|
||||||
if (!m_surface.GetPresentModes(m_forcedPhysicalDevice, &presentModes))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query supported present modes");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR;
|
|
||||||
for (VkPresentModeKHR presentMode : presentModes)
|
|
||||||
{
|
|
||||||
if (presentMode == VK_PRESENT_MODE_MAILBOX_KHR)
|
|
||||||
{
|
|
||||||
swapchainPresentMode = VK_PRESENT_MODE_MAILBOX_KHR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (presentMode == VK_PRESENT_MODE_IMMEDIATE_KHR)
|
|
||||||
swapchainPresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkSwapchainCreateInfoKHR swapchainInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
|
|
||||||
nullptr,
|
|
||||||
0,
|
|
||||||
m_surface,
|
|
||||||
imageCount,
|
|
||||||
m_colorFormat,
|
|
||||||
m_colorSpace,
|
|
||||||
extent,
|
|
||||||
1,
|
|
||||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
|
||||||
VK_SHARING_MODE_EXCLUSIVE,
|
|
||||||
0, nullptr,
|
|
||||||
surfaceCapabilities.currentTransform,
|
|
||||||
VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
|
|
||||||
swapchainPresentMode,
|
|
||||||
VK_TRUE,
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!m_swapchain.Create(m_device, swapchainInfo))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create swapchain");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkCommandPool.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkCommandBuffer.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
CommandBuffer CommandPool::AllocateCommandBuffer(VkCommandBufferLevel level)
|
|
||||||
{
|
|
||||||
VkCommandBufferAllocateInfo createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
|
||||||
nullptr,
|
|
||||||
m_handle,
|
|
||||||
level,
|
|
||||||
1U
|
|
||||||
};
|
|
||||||
|
|
||||||
VkCommandBuffer handle = VK_NULL_HANDLE;
|
|
||||||
m_lastErrorCode = m_device->vkAllocateCommandBuffers(*m_device, &createInfo, &handle);
|
|
||||||
|
|
||||||
return CommandBuffer(*this, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<CommandBuffer> CommandPool::AllocateCommandBuffers(UInt32 commandBufferCount, VkCommandBufferLevel level)
|
|
||||||
{
|
|
||||||
VkCommandBufferAllocateInfo createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
|
||||||
nullptr,
|
|
||||||
m_handle,
|
|
||||||
level,
|
|
||||||
commandBufferCount
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<VkCommandBuffer> handles(commandBufferCount, VK_NULL_HANDLE);
|
|
||||||
m_lastErrorCode = m_device->vkAllocateCommandBuffers(*m_device, &createInfo, handles.data());
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
return std::vector<CommandBuffer>();
|
|
||||||
|
|
||||||
std::vector<CommandBuffer> commandBuffers;
|
|
||||||
for (UInt32 i = 0; i < commandBufferCount; ++i)
|
|
||||||
commandBuffers.emplace_back(CommandBuffer(*this, handles[i]));
|
|
||||||
|
|
||||||
return commandBuffers;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDescriptorPool.hpp>
|
|
||||||
#include <Nazara/Vulkan/VkDescriptorSet.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
DescriptorSet DescriptorPool::AllocateDescriptorSet(const VkDescriptorSetLayout& setLayouts)
|
|
||||||
{
|
|
||||||
VkDescriptorSetAllocateInfo createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
m_handle, // VkDescriptorPool descriptorPool;
|
|
||||||
1U, // uint32_t descriptorSetCount;
|
|
||||||
&setLayouts // const VkDescriptorSetLayout* pSetLayouts;
|
|
||||||
};
|
|
||||||
|
|
||||||
VkDescriptorSet handle = VK_NULL_HANDLE;
|
|
||||||
m_lastErrorCode = m_device->vkAllocateDescriptorSets(*m_device, &createInfo, &handle);
|
|
||||||
|
|
||||||
return DescriptorSet(*this, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<DescriptorSet> DescriptorPool::AllocateDescriptorSets(UInt32 descriptorSetCount, const VkDescriptorSetLayout* setLayouts)
|
|
||||||
{
|
|
||||||
VkDescriptorSetAllocateInfo createInfo =
|
|
||||||
{
|
|
||||||
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
m_handle, // VkDescriptorPool descriptorPool;
|
|
||||||
descriptorSetCount, // uint32_t descriptorSetCount;
|
|
||||||
setLayouts // const VkDescriptorSetLayout* pSetLayouts;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<VkDescriptorSet> handles(descriptorSetCount, VK_NULL_HANDLE);
|
|
||||||
m_lastErrorCode = m_device->vkAllocateDescriptorSets(*m_device, &createInfo, handles.data());
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
return std::vector<DescriptorSet>();
|
|
||||||
|
|
||||||
std::vector<DescriptorSet> descriptorSets;
|
|
||||||
for (UInt32 i = 0; i < descriptorSetCount; ++i)
|
|
||||||
descriptorSets.emplace_back(DescriptorSet(*this, handles[i]));
|
|
||||||
|
|
||||||
return descriptorSets;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,222 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
bool Device::Create(VkPhysicalDevice device, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
std::vector<VkQueueFamilyProperties> queuesProperties;
|
|
||||||
if (!m_instance.GetPhysicalDeviceQueueFamilyProperties(device, &queuesProperties))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query queue family properties");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_lastErrorCode = m_instance.vkCreateDevice(device, &createInfo, allocator, &m_device);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create Vulkan device");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_physicalDevice = device;
|
|
||||||
|
|
||||||
// Store the allocator to access them when needed
|
|
||||||
if (allocator)
|
|
||||||
m_allocator = *allocator;
|
|
||||||
else
|
|
||||||
m_allocator.pfnAllocation = nullptr;
|
|
||||||
|
|
||||||
// Parse extensions and layers
|
|
||||||
for (UInt32 i = 0; i < createInfo.enabledExtensionCount; ++i)
|
|
||||||
m_loadedExtensions.insert(createInfo.ppEnabledExtensionNames[i]);
|
|
||||||
|
|
||||||
for (UInt32 i = 0; i < createInfo.enabledLayerCount; ++i)
|
|
||||||
m_loadedLayers.insert(createInfo.ppEnabledLayerNames[i]);
|
|
||||||
|
|
||||||
// Load all device-related functions
|
|
||||||
#define NAZARA_VULKAN_LOAD_DEVICE(func) func = reinterpret_cast<PFN_##func>(GetProcAddr(#func))
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
|
||||||
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkAllocateCommandBuffers);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkAllocateDescriptorSets);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkAllocateMemory);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkBeginCommandBuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkBindBufferMemory);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkBindImageMemory);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdBeginQuery);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdBeginRenderPass);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdBindDescriptorSets);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdBindIndexBuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdBindPipeline);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdBindVertexBuffers);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdBlitImage);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdClearAttachments);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdClearColorImage);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdClearDepthStencilImage);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdCopyBuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdCopyBufferToImage);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdCopyImage);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdCopyImageToBuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdCopyQueryPoolResults);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdDispatch);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdDispatchIndirect);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdDraw);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdDrawIndexed);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdDrawIndexedIndirect);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdDrawIndirect);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdEndQuery);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdEndRenderPass);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdExecuteCommands);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdFillBuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdNextSubpass);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdPipelineBarrier);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdPushConstants);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdResetEvent);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdResetQueryPool);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdResolveImage);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdSetBlendConstants);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdSetDepthBias);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdSetDepthBounds);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdSetEvent);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdSetLineWidth);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdSetScissor);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdSetStencilCompareMask);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdSetStencilReference);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdSetStencilWriteMask);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdSetViewport);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdUpdateBuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdWaitEvents);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCmdWriteTimestamp);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateBuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateBufferView);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateCommandPool);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateComputePipelines);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateDescriptorPool);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateDescriptorSetLayout);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateEvent);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateFramebuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateGraphicsPipelines);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateImage);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateImageView);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreatePipelineCache);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreatePipelineLayout);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateRenderPass);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateSampler);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateSemaphore);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateShaderModule);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyBuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyBufferView);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyCommandPool);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyDescriptorPool);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyDescriptorSetLayout);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyDevice);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyEvent);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyFramebuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyImage);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyImageView);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyPipeline);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyPipelineCache);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyPipelineLayout);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyRenderPass);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroySampler);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroySemaphore);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroyShaderModule);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDeviceWaitIdle);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkEndCommandBuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkFreeCommandBuffers);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkFreeDescriptorSets);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkFreeMemory);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkFlushMappedMemoryRanges);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkGetBufferMemoryRequirements);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkGetDeviceMemoryCommitment);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkGetDeviceQueue);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkGetEventStatus);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkGetFenceStatus);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkGetImageMemoryRequirements);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkGetImageSparseMemoryRequirements);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkGetImageSubresourceLayout);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkGetRenderAreaGranularity);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkInvalidateMappedMemoryRanges);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkMapMemory);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkMergePipelineCaches);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkQueueSubmit);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkQueueWaitIdle);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkResetCommandBuffer);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkResetCommandPool);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkResetDescriptorPool);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkResetFences);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkResetEvent);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkSetEvent);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkUnmapMemory);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkUpdateDescriptorSets);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkWaitForFences);
|
|
||||||
|
|
||||||
// VK_KHR_display_swapchain
|
|
||||||
if (IsExtensionLoaded("VK_KHR_display_swapchain"))
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateSharedSwapchainsKHR);
|
|
||||||
|
|
||||||
// VK_KHR_swapchain
|
|
||||||
if (IsExtensionLoaded("VK_KHR_swapchain"))
|
|
||||||
{
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkAcquireNextImageKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkCreateSwapchainKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkDestroySwapchainKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkGetSwapchainImagesKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_DEVICE(vkQueuePresentKHR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const std::exception& e)
|
|
||||||
{
|
|
||||||
NazaraError(String("Failed to query device function: ") + e.what());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef NAZARA_VULKAN_LOAD_DEVICE
|
|
||||||
|
|
||||||
// And retains informations about queues
|
|
||||||
UInt32 maxFamilyIndex = 0;
|
|
||||||
m_enabledQueuesInfos.resize(createInfo.queueCreateInfoCount);
|
|
||||||
for (UInt32 i = 0; i < createInfo.queueCreateInfoCount; ++i)
|
|
||||||
{
|
|
||||||
const VkDeviceQueueCreateInfo& queueCreateInfo = createInfo.pQueueCreateInfos[i];
|
|
||||||
QueueFamilyInfo& info = m_enabledQueuesInfos[i];
|
|
||||||
|
|
||||||
info.familyIndex = queueCreateInfo.queueFamilyIndex;
|
|
||||||
if (info.familyIndex > maxFamilyIndex)
|
|
||||||
maxFamilyIndex = info.familyIndex;
|
|
||||||
|
|
||||||
const VkQueueFamilyProperties& queueProperties = queuesProperties[info.familyIndex];
|
|
||||||
info.flags = queueProperties.queueFlags;
|
|
||||||
info.minImageTransferGranularity = queueProperties.minImageTransferGranularity;
|
|
||||||
info.timestampValidBits = queueProperties.timestampValidBits;
|
|
||||||
|
|
||||||
info.queues.resize(queueCreateInfo.queueCount);
|
|
||||||
for (UInt32 queueIndex = 0; queueIndex < queueCreateInfo.queueCount; ++queueIndex)
|
|
||||||
{
|
|
||||||
QueueInfo& queueInfo = info.queues[queueIndex];
|
|
||||||
queueInfo.familyInfo = &info;
|
|
||||||
queueInfo.priority = queueCreateInfo.pQueuePriorities[queueIndex];
|
|
||||||
vkGetDeviceQueue(m_device, info.familyIndex, queueIndex, &queueInfo.queue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_queuesByFamily.resize(maxFamilyIndex + 1);
|
|
||||||
for (const QueueFamilyInfo& familyInfo : m_enabledQueuesInfos)
|
|
||||||
m_queuesByFamily[familyInfo.familyIndex] = &familyInfo.queues;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,193 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
bool Instance::Create(const VkInstanceCreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
m_lastErrorCode = Loader::vkCreateInstance(&createInfo, allocator, &m_instance);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create Vulkan instance");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the allocator to access them when needed
|
|
||||||
if (allocator)
|
|
||||||
m_allocator = *allocator;
|
|
||||||
else
|
|
||||||
m_allocator.pfnAllocation = nullptr;
|
|
||||||
|
|
||||||
// Parse extensions and layers
|
|
||||||
for (UInt32 i = 0; i < createInfo.enabledExtensionCount; ++i)
|
|
||||||
m_loadedExtensions.insert(createInfo.ppEnabledExtensionNames[i]);
|
|
||||||
|
|
||||||
for (UInt32 i = 0; i < createInfo.enabledLayerCount; ++i)
|
|
||||||
m_loadedLayers.insert(createInfo.ppEnabledLayerNames[i]);
|
|
||||||
|
|
||||||
// And now load everything
|
|
||||||
#define NAZARA_VULKAN_LOAD_INSTANCE(func) func = reinterpret_cast<PFN_##func>(GetProcAddr(#func))
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
|
||||||
|
|
||||||
// Vulkan core
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateDevice);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkDestroyInstance);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkEnumeratePhysicalDevices);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetDeviceProcAddr);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceFeatures);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceFormatProperties);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceImageFormatProperties);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceMemoryProperties);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceProperties);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceQueueFamilyProperties);
|
|
||||||
|
|
||||||
// VK_KHR_display
|
|
||||||
if (IsExtensionLoaded("VK_KHR_display"))
|
|
||||||
{
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateDisplayModeKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateDisplayPlaneSurfaceKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetDisplayModePropertiesKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetDisplayPlaneCapabilitiesKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetDisplayPlaneSupportedDisplaysKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceDisplayPlanePropertiesKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceDisplayPropertiesKHR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// VK_KHR_surface
|
|
||||||
if (IsExtensionLoaded("VK_KHR_surface"))
|
|
||||||
{
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkDestroySurfaceKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceSurfaceFormatsKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceSurfacePresentModesKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceSurfaceSupportKHR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// VK_EXT_debug_report
|
|
||||||
if (IsExtensionLoaded("VK_EXT_debug_report"))
|
|
||||||
{
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateDebugReportCallbackEXT);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkDestroyDebugReportCallbackEXT);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkDebugReportMessageEXT);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
|
||||||
// VK_KHR_android_surface
|
|
||||||
if (IsExtensionLoaded("VK_KHR_android_surface"))
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateAndroidSurfaceKHR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
|
||||||
// VK_KHR_mir_surface
|
|
||||||
if (IsExtensionLoaded("VK_KHR_mir_surface"))
|
|
||||||
{
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateMirSurfaceKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceMirPresentationSupportKHR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
||||||
// VK_KHR_xcb_surface
|
|
||||||
if (IsExtensionLoaded("VK_KHR_xcb_surface"))
|
|
||||||
{
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateXcbSurfaceKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceXcbPresentationSupportKHR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
|
||||||
// VK_KHR_xlib_surface
|
|
||||||
if (IsExtensionLoaded("VK_KHR_xlib_surface"))
|
|
||||||
{
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateXlibSurfaceKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceXlibPresentationSupportKHR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
||||||
// VK_KHR_wayland_surface
|
|
||||||
if (IsExtensionLoaded("VK_KHR_wayland_surface"))
|
|
||||||
{
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateWaylandSurfaceKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceWaylandPresentationSupportKHR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
|
||||||
// VK_KHR_win32_surface
|
|
||||||
if (IsExtensionLoaded("VK_KHR_win32_surface"))
|
|
||||||
{
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateWin32SurfaceKHR);
|
|
||||||
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceWin32PresentationSupportKHR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
catch (const std::exception& e)
|
|
||||||
{
|
|
||||||
NazaraError(String("Failed to query instance function: ") + e.what());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef NAZARA_VULKAN_LOAD_INSTANCE
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Instance::EnumeratePhysicalDevices(std::vector<VkPhysicalDevice>* devices)
|
|
||||||
{
|
|
||||||
NazaraAssert(devices, "Invalid device vector");
|
|
||||||
|
|
||||||
// First, query physical device count
|
|
||||||
UInt32 deviceCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
|
|
||||||
m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, nullptr);
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS || deviceCount == 0)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query physical device count");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we can get the list of the available physical device
|
|
||||||
devices->resize(deviceCount);
|
|
||||||
m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, devices->data());
|
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query physical devices");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Instance::GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector<VkQueueFamilyProperties>* queueFamilyProperties)
|
|
||||||
{
|
|
||||||
NazaraAssert(queueFamilyProperties, "Invalid device vector");
|
|
||||||
|
|
||||||
// First, query physical device count
|
|
||||||
UInt32 queueFamiliesCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
|
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamiliesCount, nullptr);
|
|
||||||
if (queueFamiliesCount == 0)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to query physical device count");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we can get the list of the available physical device
|
|
||||||
queueFamilyProperties->resize(queueFamiliesCount);
|
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamiliesCount, queueFamilyProperties->data());
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,117 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/VkLoader.hpp>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
namespace Vk
|
|
||||||
{
|
|
||||||
bool Loader::EnumerateInstanceExtensionProperties(std::vector<VkExtensionProperties>* properties, const char* layerName)
|
|
||||||
{
|
|
||||||
NazaraAssert(properties, "Invalid device vector");
|
|
||||||
|
|
||||||
// First, query physical device count
|
|
||||||
UInt32 propertyCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
|
|
||||||
s_lastErrorCode = vkEnumerateInstanceExtensionProperties(layerName, &propertyCount, properties->data());
|
|
||||||
if (s_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to get instance extension properties count");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we can get the list of the available physical device
|
|
||||||
properties->resize(propertyCount);
|
|
||||||
s_lastErrorCode = vkEnumerateInstanceExtensionProperties(layerName, &propertyCount, properties->data());
|
|
||||||
if (s_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to enumerate instance extension properties");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Loader::EnumerateInstanceLayerProperties(std::vector<VkLayerProperties>* properties)
|
|
||||||
{
|
|
||||||
NazaraAssert(properties, "Invalid device vector");
|
|
||||||
|
|
||||||
// First, query physical device count
|
|
||||||
UInt32 propertyCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
|
|
||||||
s_lastErrorCode = vkEnumerateInstanceLayerProperties(&propertyCount, properties->data());
|
|
||||||
if (s_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to get instance layer properties count");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we can get the list of the available physical device
|
|
||||||
properties->resize(propertyCount);
|
|
||||||
s_lastErrorCode = vkEnumerateInstanceLayerProperties(&propertyCount, properties->data());
|
|
||||||
if (s_lastErrorCode != VkResult::VK_SUCCESS)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to enumerate instance layer properties");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Loader::Initialize()
|
|
||||||
{
|
|
||||||
#ifdef NAZARA_PLATFORM_WINDOWS
|
|
||||||
s_vulkanLib.Load("vulkan-1.dll");
|
|
||||||
#elif defined(NAZARA_PLATFORM_LINUX)
|
|
||||||
s_vulkanLib.Load("libvulkan.so");
|
|
||||||
#else
|
|
||||||
#error Unhandled platform
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!s_vulkanLib.IsLoaded())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to open vulkan library: " + s_vulkanLib.GetLastError());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// vkGetInstanceProcAddr is the only function that's garantee to be exported
|
|
||||||
vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(s_vulkanLib.GetSymbol("vkGetInstanceProcAddr"));
|
|
||||||
if (!vkGetInstanceProcAddr)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to get symbol \"vkGetInstanceProcAddr\": " + s_vulkanLib.GetLastError());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// all other functions should be loaded using vkGetInstanceProcAddr
|
|
||||||
#define NAZARA_VULKAN_LOAD_GLOBAL(func) func = reinterpret_cast<PFN_##func>(vkGetInstanceProcAddr(nullptr, #func))
|
|
||||||
|
|
||||||
NAZARA_VULKAN_LOAD_GLOBAL(vkCreateInstance);
|
|
||||||
NAZARA_VULKAN_LOAD_GLOBAL(vkEnumerateInstanceExtensionProperties);
|
|
||||||
NAZARA_VULKAN_LOAD_GLOBAL(vkEnumerateInstanceLayerProperties);
|
|
||||||
|
|
||||||
#undef NAZARA_VULKAN_LOAD_GLOBAL
|
|
||||||
|
|
||||||
s_lastErrorCode = VkResult::VK_SUCCESS;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL(func) PFN_##func Loader::func = nullptr
|
|
||||||
|
|
||||||
NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL(vkCreateInstance);
|
|
||||||
NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL(vkEnumerateInstanceExtensionProperties);
|
|
||||||
NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL(vkEnumerateInstanceLayerProperties);
|
|
||||||
NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL(vkGetInstanceProcAddr);
|
|
||||||
|
|
||||||
#undef NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL
|
|
||||||
|
|
||||||
DynLib Loader::s_vulkanLib;
|
|
||||||
VkResult Loader::s_lastErrorCode;
|
|
||||||
|
|
||||||
void Loader::Uninitialize()
|
|
||||||
{
|
|
||||||
s_vulkanLib.Unload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,451 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Vulkan"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Vulkan/Vulkan.hpp>
|
|
||||||
#include <Nazara/Core/CallOnExit.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
|
||||||
#include <Nazara/Core/Log.hpp>
|
|
||||||
#include <Nazara/Utility/Utility.hpp>
|
|
||||||
#include <Nazara/Vulkan/Config.hpp>
|
|
||||||
#include <array>
|
|
||||||
#include <Nazara/Vulkan/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
Vk::Instance& Vulkan::GetInstance()
|
|
||||||
{
|
|
||||||
return s_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<Vk::PhysicalDevice>& Vulkan::GetPhysicalDevices()
|
|
||||||
{
|
|
||||||
return s_physDevices;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Vk::PhysicalDevice& Vulkan::GetPhysicalDeviceInfo(VkPhysicalDevice physDevice)
|
|
||||||
{
|
|
||||||
for (const Vk::PhysicalDevice& info : s_physDevices)
|
|
||||||
{
|
|
||||||
if (info.device == physDevice)
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This cannot happen if physDevice is valid, as we retrieved every physical device
|
|
||||||
NazaraInternalError("Invalid physical device: " + String::Pointer(physDevice));
|
|
||||||
|
|
||||||
static Vk::PhysicalDevice dummy;
|
|
||||||
return dummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Vulkan::Initialize()
|
|
||||||
{
|
|
||||||
if (s_moduleReferenceCounter > 0)
|
|
||||||
{
|
|
||||||
s_moduleReferenceCounter++;
|
|
||||||
return true; // Already initialized
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize module dependencies
|
|
||||||
if (!Utility::Initialize())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to initialize utility module");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_moduleReferenceCounter++;
|
|
||||||
|
|
||||||
CallOnExit onExit(Vulkan::Uninitialize);
|
|
||||||
|
|
||||||
// Initialize module here
|
|
||||||
if (!Vk::Loader::Initialize())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load Vulkan API, it may be not installed on your system");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String appName = "Another application made with Nazara Engine";
|
|
||||||
String engineName = "Nazara Engine - Vulkan Renderer";
|
|
||||||
UInt32 apiVersion = VK_MAKE_VERSION(1, 0, 8);
|
|
||||||
UInt32 appVersion = VK_MAKE_VERSION(1, 0, 0);
|
|
||||||
UInt32 engineVersion = VK_MAKE_VERSION(1, 0, 0);
|
|
||||||
|
|
||||||
s_initializationParameters.GetStringParameter("VkAppInfo_OverrideApplicationName", &appName);
|
|
||||||
s_initializationParameters.GetStringParameter("VkAppInfo_OverrideEngineName", &engineName);
|
|
||||||
|
|
||||||
bool bParam;
|
|
||||||
int iParam;
|
|
||||||
|
|
||||||
if (s_initializationParameters.GetIntegerParameter("VkAppInfo_OverrideAPIVersion", &iParam))
|
|
||||||
apiVersion = iParam;
|
|
||||||
|
|
||||||
if (s_initializationParameters.GetIntegerParameter("VkAppInfo_OverrideApplicationVersion", &iParam))
|
|
||||||
appVersion = iParam;
|
|
||||||
|
|
||||||
if (s_initializationParameters.GetIntegerParameter("VkAppInfo_OverrideEngineVersion", &iParam))
|
|
||||||
engineVersion = iParam;
|
|
||||||
|
|
||||||
VkApplicationInfo appInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
|
||||||
nullptr,
|
|
||||||
appName.GetConstBuffer(),
|
|
||||||
appVersion,
|
|
||||||
engineName.GetConstBuffer(),
|
|
||||||
engineVersion,
|
|
||||||
apiVersion
|
|
||||||
};
|
|
||||||
|
|
||||||
VkInstanceCreateFlags createFlags = 0;
|
|
||||||
|
|
||||||
if (s_initializationParameters.GetIntegerParameter("VkInstanceInfo_OverrideCreateFlags", &iParam))
|
|
||||||
createFlags = static_cast<VkInstanceCreateFlags>(iParam);
|
|
||||||
|
|
||||||
std::vector<const char*> enabledLayers;
|
|
||||||
std::vector<const char*> enabledExtensions;
|
|
||||||
|
|
||||||
if (!s_initializationParameters.GetBooleanParameter("VkInstanceInfo_OverrideEnabledLayers", &bParam) || !bParam)
|
|
||||||
{
|
|
||||||
//< Nazara default layers goes here
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<String> additionalLayers; // Just to keep the String alive
|
|
||||||
if (s_initializationParameters.GetIntegerParameter("VkInstanceInfo_EnabledLayerCount", &iParam))
|
|
||||||
{
|
|
||||||
additionalLayers.reserve(iParam);
|
|
||||||
for (int i = 0; i < iParam; ++i)
|
|
||||||
{
|
|
||||||
Nz::String parameterName = "VkInstanceInfo_EnabledLayer" + String::Number(i);
|
|
||||||
Nz::String layer;
|
|
||||||
if (s_initializationParameters.GetStringParameter(parameterName, &layer))
|
|
||||||
{
|
|
||||||
additionalLayers.emplace_back(std::move(layer));
|
|
||||||
enabledLayers.push_back(additionalLayers.back().GetConstBuffer());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
NazaraWarning("Parameter " + parameterName + " expected");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!s_initializationParameters.GetBooleanParameter("VkInstanceInfo_OverrideEnabledExtensions", &bParam) || !bParam)
|
|
||||||
{
|
|
||||||
enabledExtensions.push_back("VK_KHR_surface");
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
|
||||||
enabledExtensions.push_back("VK_KHR_android_surface");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
|
||||||
enabledExtensions.push_back("VK_KHR_mir_surface");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
|
||||||
enabledExtensions.push_back("VK_KHR_xcb_surface");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
|
||||||
enabledExtensions.push_back("VK_KHR_xlib_surface");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
|
||||||
enabledExtensions.push_back("VK_KHR_wayland_surface");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
|
||||||
enabledExtensions.push_back("VK_KHR_win32_surface");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<String> additionalExtensions; // Just to keep the String alive
|
|
||||||
if (s_initializationParameters.GetIntegerParameter("VkInstanceInfo_EnabledExtensionCount", &iParam))
|
|
||||||
{
|
|
||||||
additionalExtensions.reserve(iParam);
|
|
||||||
for (int i = 0; i < iParam; ++i)
|
|
||||||
{
|
|
||||||
Nz::String parameterName = "VkInstanceInfo_EnabledExtension" + String::Number(i);
|
|
||||||
Nz::String extension;
|
|
||||||
if (s_initializationParameters.GetStringParameter(parameterName, &extension))
|
|
||||||
{
|
|
||||||
additionalExtensions.emplace_back(std::move(extension));
|
|
||||||
enabledExtensions.push_back(additionalExtensions.back().GetConstBuffer());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
NazaraWarning("Parameter " + parameterName + " expected");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VkInstanceCreateInfo instanceInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
|
||||||
nullptr,
|
|
||||||
createFlags,
|
|
||||||
&appInfo,
|
|
||||||
UInt32(enabledLayers.size()),
|
|
||||||
enabledLayers.data(),
|
|
||||||
UInt32(enabledExtensions.size()),
|
|
||||||
enabledExtensions.data()
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!s_instance.Create(instanceInfo))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create instance");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<VkPhysicalDevice> physDevices;
|
|
||||||
if (!s_instance.EnumeratePhysicalDevices(&physDevices))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to enumerate physical devices");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_physDevices.reserve(physDevices.size());
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < physDevices.size(); ++i)
|
|
||||||
{
|
|
||||||
VkPhysicalDevice physDevice = physDevices[i];
|
|
||||||
|
|
||||||
Vk::PhysicalDevice deviceInfo;
|
|
||||||
if (!s_instance.GetPhysicalDeviceQueueFamilyProperties(physDevice, &deviceInfo.queues))
|
|
||||||
{
|
|
||||||
NazaraWarning("Failed to query physical device queue family properties");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
deviceInfo.device = physDevice;
|
|
||||||
|
|
||||||
deviceInfo.features = s_instance.GetPhysicalDeviceFeatures(physDevice);
|
|
||||||
deviceInfo.memoryProperties = s_instance.GetPhysicalDeviceMemoryProperties(physDevice);
|
|
||||||
deviceInfo.properties = s_instance.GetPhysicalDeviceProperties(physDevice);
|
|
||||||
|
|
||||||
s_physDevices.emplace_back(std::move(deviceInfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s_physDevices.empty())
|
|
||||||
{
|
|
||||||
NazaraError("No valid physical device found");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
onExit.Reset();
|
|
||||||
|
|
||||||
NazaraNotice("Initialized: Vulkan module");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Vulkan::IsInitialized()
|
|
||||||
{
|
|
||||||
return s_moduleReferenceCounter != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vk::DeviceHandle Vulkan::CreateDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue)
|
|
||||||
{
|
|
||||||
Nz::ErrorFlags errFlags(ErrorFlag_ThrowException, true);
|
|
||||||
|
|
||||||
std::vector<VkQueueFamilyProperties> queueFamilies;
|
|
||||||
s_instance.GetPhysicalDeviceQueueFamilyProperties(gpu, &queueFamilies);
|
|
||||||
|
|
||||||
// Find a queue that supports graphics operations
|
|
||||||
UInt32 graphicsQueueNodeIndex = UINT32_MAX;
|
|
||||||
UInt32 presentQueueNodeIndex = UINT32_MAX;
|
|
||||||
UInt32 transfertQueueNodeFamily = UINT32_MAX;
|
|
||||||
for (UInt32 i = 0; i < queueFamilies.size(); i++)
|
|
||||||
{
|
|
||||||
bool supportPresentation = false;
|
|
||||||
if (!surface.GetSupportPresentation(gpu, i, &supportPresentation))
|
|
||||||
NazaraWarning("Failed to get presentation support of queue family #" + String::Number(i));
|
|
||||||
|
|
||||||
if (queueFamilies[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
|
||||||
{
|
|
||||||
if (graphicsQueueNodeIndex == UINT32_MAX)
|
|
||||||
graphicsQueueNodeIndex = i;
|
|
||||||
|
|
||||||
if (supportPresentation)
|
|
||||||
{
|
|
||||||
graphicsQueueNodeIndex = i;
|
|
||||||
presentQueueNodeIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (supportPresentation)
|
|
||||||
presentQueueNodeIndex = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (UInt32 i = 0; i < queueFamilies.size(); i++)
|
|
||||||
{
|
|
||||||
if (queueFamilies[i].queueFlags & VK_QUEUE_TRANSFER_BIT)
|
|
||||||
{
|
|
||||||
transfertQueueNodeFamily = i;
|
|
||||||
if (transfertQueueNodeFamily != graphicsQueueNodeIndex)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::array<UInt32, 3> usedQueueFamilies = {graphicsQueueNodeIndex, presentQueueNodeIndex, transfertQueueNodeFamily};
|
|
||||||
std::array<float, 3> priorities = {1.f, 1.f, 1.f};
|
|
||||||
|
|
||||||
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
|
|
||||||
for (UInt32 queueFamily : usedQueueFamilies)
|
|
||||||
{
|
|
||||||
auto it = std::find_if(queueCreateInfos.begin(), queueCreateInfos.end(), [queueFamily] (const VkDeviceQueueCreateInfo& createInfo)
|
|
||||||
{
|
|
||||||
return createInfo.queueFamilyIndex == queueFamily;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (it == queueCreateInfos.end())
|
|
||||||
{
|
|
||||||
VkDeviceQueueCreateInfo createInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType;
|
|
||||||
nullptr, // const void* pNext;
|
|
||||||
0, // VkDeviceQueueCreateFlags flags;
|
|
||||||
queueFamily, // uint32_t queueFamilyIndex;
|
|
||||||
1, // uint32_t queueCount;
|
|
||||||
priorities.data() // const float* pQueuePriorities;
|
|
||||||
};
|
|
||||||
|
|
||||||
queueCreateInfos.emplace_back(createInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<const char*> enabledLayers;
|
|
||||||
std::vector<const char*> enabledExtensions;
|
|
||||||
|
|
||||||
bool bParam;
|
|
||||||
int iParam;
|
|
||||||
|
|
||||||
if (!s_initializationParameters.GetBooleanParameter("VkDeviceInfo_OverrideEnabledLayers", &bParam) || !bParam)
|
|
||||||
{
|
|
||||||
//< Nazara default layers goes here
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<String> additionalLayers; // Just to keep the String alive
|
|
||||||
if (s_initializationParameters.GetIntegerParameter("VkDeviceInfo_EnabledLayerCount", &iParam))
|
|
||||||
{
|
|
||||||
additionalLayers.reserve(iParam);
|
|
||||||
for (int i = 0; i < iParam; ++i)
|
|
||||||
{
|
|
||||||
Nz::String parameterName = "VkDeviceInfo_EnabledLayer" + String::Number(i);
|
|
||||||
Nz::String layer;
|
|
||||||
if (s_initializationParameters.GetStringParameter(parameterName, &layer))
|
|
||||||
{
|
|
||||||
additionalLayers.emplace_back(std::move(layer));
|
|
||||||
enabledLayers.push_back(additionalLayers.back().GetConstBuffer());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
NazaraWarning("Parameter " + parameterName + " expected");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!s_initializationParameters.GetBooleanParameter("VkDeviceInfo_OverrideEnabledExtensions", &bParam) || !bParam)
|
|
||||||
enabledExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
|
||||||
|
|
||||||
std::vector<String> additionalExtensions; // Just to keep the String alive
|
|
||||||
if (s_initializationParameters.GetIntegerParameter("VkDeviceInfo_EnabledExtensionCount", &iParam))
|
|
||||||
{
|
|
||||||
for (int i = 0; i < iParam; ++i)
|
|
||||||
{
|
|
||||||
Nz::String parameterName = "VkDeviceInfo_EnabledExtension" + String::Number(i);
|
|
||||||
Nz::String extension;
|
|
||||||
if (s_initializationParameters.GetStringParameter(parameterName, &extension))
|
|
||||||
{
|
|
||||||
additionalExtensions.emplace_back(std::move(extension));
|
|
||||||
enabledExtensions.push_back(additionalExtensions.back().GetConstBuffer());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
NazaraWarning("Parameter " + parameterName + " expected");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VkDeviceCreateInfo createInfo = {
|
|
||||||
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
|
||||||
nullptr,
|
|
||||||
0,
|
|
||||||
UInt32(queueCreateInfos.size()),
|
|
||||||
queueCreateInfos.data(),
|
|
||||||
UInt32(enabledLayers.size()),
|
|
||||||
enabledLayers.data(),
|
|
||||||
UInt32(enabledExtensions.size()),
|
|
||||||
enabledExtensions.data(),
|
|
||||||
nullptr
|
|
||||||
};
|
|
||||||
|
|
||||||
///TODO: First create then move
|
|
||||||
s_devices.emplace_back(s_instance);
|
|
||||||
|
|
||||||
Vk::Device& device = s_devices.back();
|
|
||||||
device.Create(gpu, createInfo);
|
|
||||||
|
|
||||||
*presentableFamilyQueue = presentQueueNodeIndex;
|
|
||||||
|
|
||||||
return device.CreateHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
Vk::DeviceHandle Vulkan::SelectDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue)
|
|
||||||
{
|
|
||||||
// First, try to find a device compatible with that surface
|
|
||||||
for (Vk::Device& device : s_devices)
|
|
||||||
{
|
|
||||||
if (device.GetPhysicalDevice() == gpu)
|
|
||||||
{
|
|
||||||
const std::vector<Vk::Device::QueueFamilyInfo>& queueFamilyInfo = device.GetEnabledQueues();
|
|
||||||
UInt32 presentableQueueFamilyIndex = UINT32_MAX;
|
|
||||||
for (Vk::Device::QueueFamilyInfo queueInfo : queueFamilyInfo)
|
|
||||||
{
|
|
||||||
bool supported = false;
|
|
||||||
if (surface.GetSupportPresentation(gpu, queueInfo.familyIndex, &supported) && supported)
|
|
||||||
{
|
|
||||||
if (presentableQueueFamilyIndex == UINT32_MAX || queueInfo.flags & VK_QUEUE_GRAPHICS_BIT)
|
|
||||||
{
|
|
||||||
presentableQueueFamilyIndex = queueInfo.familyIndex;
|
|
||||||
if (queueInfo.flags & VK_QUEUE_GRAPHICS_BIT)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (presentableQueueFamilyIndex != UINT32_MAX)
|
|
||||||
*presentableFamilyQueue = presentableQueueFamilyIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// No device had support for that surface, create one
|
|
||||||
return CreateDevice(gpu, surface, presentableFamilyQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vulkan::SetParameters(const ParameterList& parameters)
|
|
||||||
{
|
|
||||||
s_initializationParameters = parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vulkan::Uninitialize()
|
|
||||||
{
|
|
||||||
if (s_moduleReferenceCounter != 1)
|
|
||||||
{
|
|
||||||
// Either the module is not initialized, either it was initialized multiple times
|
|
||||||
if (s_moduleReferenceCounter > 1)
|
|
||||||
s_moduleReferenceCounter--;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_moduleReferenceCounter = 0;
|
|
||||||
|
|
||||||
// Uninitialize module here
|
|
||||||
s_devices.clear();
|
|
||||||
s_instance.Destroy();
|
|
||||||
|
|
||||||
Vk::Loader::Uninitialize();
|
|
||||||
|
|
||||||
NazaraNotice("Uninitialized: Vulkan module");
|
|
||||||
|
|
||||||
// Free module dependencies
|
|
||||||
Utility::Uninitialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<Vk::Device> Vulkan::s_devices;
|
|
||||||
std::vector<Vk::PhysicalDevice> Vulkan::s_physDevices;
|
|
||||||
Vk::Instance Vulkan::s_instance;
|
|
||||||
ParameterList Vulkan::s_initializationParameters;
|
|
||||||
unsigned int Vulkan::s_moduleReferenceCounter = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue