Merge branch 'master' of https://github.com/DigitalPulseSoftware/NazaraEngine into Documentation-Update
Former-commit-id: 601bee6e41fcb3951f3ae9070a277896aeb52d80 [formerly ea8c1543b3df294643130613a6df14ad17bc1dd5] Former-commit-id: 08bda7de77c7615d6ba76eed38075a0c667ff72d
This commit is contained in:
commit
363299f4de
|
|
@ -35,6 +35,7 @@ build/**/*.vcxprojResolveAssemblyReference.cache
|
|||
build/**/*.nativecodeanalysis.all.xml
|
||||
build/**/*.nativecodeanalysis.xml
|
||||
build/**/*.VC.opendb
|
||||
build/**/*.VC.db
|
||||
|
||||
# Compiled Object files
|
||||
build/**/*.slo
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
// This file was automatically generated on 03 Mar 2016 at 14:09:12
|
||||
// This file was automatically generated on 01 Jun 2016 at 13:11:09
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_COMPONENTS_GLOBAL_HPP
|
||||
#define NDK_COMPONENTS_GLOBAL_HPP
|
||||
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/CollisionComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/PhysicsComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#endif
|
||||
|
||||
#endif // NDK_COMPONENTS_GLOBAL_HPP
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_CAMERACOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_CAMERACOMPONENT_HPP
|
||||
|
||||
|
|
@ -108,3 +109,4 @@ namespace Ndk
|
|||
#include <NDK/Components/CameraComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_CAMERACOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
||||
|
||||
|
|
@ -80,3 +81,4 @@ namespace Ndk
|
|||
#include <NDK/Components/GraphicsComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
|
||||
|
|
@ -28,3 +29,4 @@ namespace Ndk
|
|||
#include <NDK/Components/LightComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_COMPONENTS_LISTENERCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_LISTENERCOMPONENT_HPP
|
||||
|
||||
|
|
@ -30,3 +31,4 @@ namespace Ndk
|
|||
#include <NDK/Components/ListenerComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_LISTENERCOMPONENT_HPP
|
||||
#endif // NDK_SERVER
|
||||
|
|
@ -1,16 +1,13 @@
|
|||
// This file was automatically generated on 03 Mar 2016 at 14:09:12
|
||||
// This file was automatically generated on 01 Jun 2016 at 13:11:09
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SYSTEMS_GLOBAL_HPP
|
||||
#define NDK_SYSTEMS_GLOBAL_HPP
|
||||
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
#endif // NDK_SYSTEMS_GLOBAL_HPP
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_SYSTEMS_LISTENERSYSTEM_HPP
|
||||
#define NDK_SYSTEMS_LISTENERSYSTEM_HPP
|
||||
|
||||
|
|
@ -27,3 +28,4 @@ namespace Ndk
|
|||
#include <NDK/Systems/ListenerSystem.inl>
|
||||
|
||||
#endif // NDK_SYSTEMS_LISTENERSYSTEM_HPP
|
||||
#endif // NDK_SERVER
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#ifndef NDK_SYSTEMS_RENDERSYSTEM_HPP
|
||||
#define NDK_SYSTEMS_RENDERSYSTEM_HPP
|
||||
|
||||
|
|
@ -70,3 +71,4 @@ namespace Ndk
|
|||
#include <NDK/Systems/RenderSystem.inl>
|
||||
|
||||
#endif // NDK_SYSTEMS_RENDERSYSTEM_HPP
|
||||
#endif // NDK_SERVER
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace Ndk
|
|||
static_assert(std::is_base_of<BaseSystem, SystemType>::value, "SystemType is not a component");
|
||||
|
||||
// Allocation et affectation du component
|
||||
std::unique_ptr<SystemType> ptr(new SystemType(std::forward(args)...));
|
||||
std::unique_ptr<SystemType> ptr(new SystemType(std::forward<Args>(args)...));
|
||||
return static_cast<SystemType&>(AddSystem(std::move(ptr)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -112,6 +112,12 @@ namespace Ndk
|
|||
// Uninitialize the SDK
|
||||
s_referenceCounter = 0;
|
||||
|
||||
// Components
|
||||
BaseComponent::Uninitialize();
|
||||
|
||||
// Systems
|
||||
BaseSystem::Uninitialize();
|
||||
|
||||
// Uninitialize the engine
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ function NazaraBuild:Execute()
|
|||
if (os.is64bit()) then
|
||||
platformData = {"x64", "x86"}
|
||||
else
|
||||
platformData = {"x64", "x86"}
|
||||
platformData = {"x86", "x64"}
|
||||
end
|
||||
|
||||
if (self.Actions[_ACTION] == nil) then
|
||||
local makeLibDir = os.is("windows") and "mingw" or "gmake"
|
||||
|
||||
if (#self.OrderedExtLibs > 0) then
|
||||
if (_OPTIONS["with-extlibs"]) then
|
||||
workspace("NazaraExtlibs")
|
||||
platforms(platformData)
|
||||
|
||||
|
|
@ -196,9 +196,7 @@ function NazaraBuild:Execute()
|
|||
targetdir("../lib/" .. makeLibDir .. "/x64")
|
||||
|
||||
-- Copy the module binaries to the example folder
|
||||
if (os.is("windows")) then
|
||||
self:MakeCopyAfterBuild(moduleTable)
|
||||
end
|
||||
self:MakeCopyAfterBuild(moduleTable)
|
||||
|
||||
configuration({"vs*", "x86"})
|
||||
libdirs("../extlibs/lib/msvc/x86")
|
||||
|
|
@ -310,7 +308,7 @@ function NazaraBuild:Execute()
|
|||
targetdir("../plugins/" .. toolTable.Name .. "/lib/" .. makeLibDir .. "/x64")
|
||||
end
|
||||
|
||||
-- Copy the module binaries to the example folder
|
||||
-- Copy the tool binaries to the example folder
|
||||
if (toolTable.CopyTargetToExampleDir) then
|
||||
self:MakeCopyAfterBuild(toolTable)
|
||||
end
|
||||
|
|
@ -450,6 +448,11 @@ end
|
|||
|
||||
function NazaraBuild:Initialize()
|
||||
-- Commençons par les options
|
||||
newoption({
|
||||
trigger = "server",
|
||||
description = "Excludes client-only modules/tools/examples"
|
||||
})
|
||||
|
||||
newoption({
|
||||
trigger = "united",
|
||||
description = "Builds all the modules as one united library"
|
||||
|
|
@ -491,26 +494,24 @@ function NazaraBuild:Initialize()
|
|||
ACTION = nil
|
||||
|
||||
-- Extern libraries
|
||||
if (_OPTIONS["with-extlibs"]) then
|
||||
local extlibs = os.matchfiles("../extlibs/build/*.lua")
|
||||
for k,v in pairs(extlibs) do
|
||||
local f, err = loadfile(v)
|
||||
if (f) then
|
||||
LIBRARY = {}
|
||||
self:SetupInfoTable(LIBRARY)
|
||||
local extlibs = os.matchfiles("../extlibs/build/*.lua")
|
||||
for k,v in pairs(extlibs) do
|
||||
local f, err = loadfile(v)
|
||||
if (f) then
|
||||
LIBRARY = {}
|
||||
self:SetupInfoTable(LIBRARY)
|
||||
|
||||
f()
|
||||
f()
|
||||
|
||||
local succeed, err = self:RegisterExternLibrary(LIBRARY)
|
||||
if (not succeed) then
|
||||
print("Unable to register extern library: " .. err)
|
||||
end
|
||||
else
|
||||
print("Unable to load extern library file: " .. err)
|
||||
end
|
||||
end
|
||||
LIBRARY = nil
|
||||
end
|
||||
local succeed, err = self:RegisterExternLibrary(LIBRARY)
|
||||
if (not succeed) then
|
||||
print("Unable to register extern library: " .. err)
|
||||
end
|
||||
else
|
||||
print("Unable to load extern library file: " .. err)
|
||||
end
|
||||
end
|
||||
LIBRARY = nil
|
||||
|
||||
-- Then the modules
|
||||
local modules = os.matchfiles("scripts/modules/*.lua")
|
||||
|
|
@ -605,13 +606,20 @@ function NazaraBuild:Initialize()
|
|||
self.OrderedExtLibs = {}
|
||||
self.OrderedModules = {}
|
||||
self.OrderedTools = {}
|
||||
local tables = {self.Examples, self.ExtLibs, self.Modules, self.Tools}
|
||||
local orderedTables = {self.OrderedExamples, self.OrderedExtLibs, self.OrderedModules, self.OrderedTools}
|
||||
local tables = {self.ExtLibs, self.Modules, self.Tools, self.Examples}
|
||||
local orderedTables = {self.OrderedExtLibs, self.OrderedModules, self.OrderedTools, self.OrderedExamples}
|
||||
for k,projects in ipairs(tables) do
|
||||
-- Begin by resolving every project (because of dependencies in the same category)
|
||||
for projectId,projectTable in pairs(projects) do
|
||||
self:Process(projectTable)
|
||||
|
||||
table.insert(orderedTables[k], projectTable)
|
||||
self:Resolve(projectTable)
|
||||
end
|
||||
|
||||
for projectId,projectTable in pairs(projects) do
|
||||
if (self:Process(projectTable)) then
|
||||
table.insert(orderedTables[k], projectTable)
|
||||
else
|
||||
print("Rejected client-only " .. projectTable.Name .. " " .. projectTable.Type)
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(orderedTables[k], function (a, b) return a.Name < b.Name end)
|
||||
|
|
@ -772,13 +780,22 @@ local PosixOSes = {
|
|||
}
|
||||
|
||||
function NazaraBuild:Process(infoTable)
|
||||
local libraries = {}
|
||||
if (infoTable.ClientOnly and _OPTIONS["server"]) then
|
||||
return false
|
||||
end
|
||||
|
||||
local libraries = {}
|
||||
for k, library in pairs(infoTable.Libraries) do
|
||||
local moduleName = library:match("Nazara(%w+)")
|
||||
local moduleTable = moduleName and self.Modules[moduleName:lower()]
|
||||
local toolTable = moduleName and self.Tools[moduleName:lower()]
|
||||
|
||||
if (moduleTable) then
|
||||
if (moduleTable.ClientOnly and _OPTIONS["server"]) then
|
||||
infoTable.ClientOnly = true
|
||||
return false -- We depend on a client-only library
|
||||
end
|
||||
|
||||
if (_OPTIONS["united"]) then
|
||||
library = "NazaraEngine"
|
||||
else
|
||||
|
|
@ -794,6 +811,11 @@ function NazaraBuild:Process(infoTable)
|
|||
else
|
||||
local extLibTable = self.ExtLibs[library:lower()]
|
||||
if (extLibTable) then
|
||||
if (extLibTable.ClientOnly and _OPTIONS["server"]) then
|
||||
infoTable.ClientOnly = true
|
||||
return false -- We depend on a client-only library
|
||||
end
|
||||
|
||||
library = extLibTable.Name
|
||||
|
||||
table.insert(infoTable.ConfigurationLibraries.DebugStatic, library .. "-s-d")
|
||||
|
|
@ -802,6 +824,11 @@ function NazaraBuild:Process(infoTable)
|
|||
table.insert(infoTable.ConfigurationLibraries.ReleaseDynamic, library .. "-s")
|
||||
else
|
||||
if (toolTable and toolTable.Kind == "library") then
|
||||
if (toolTable.ClientOnly and _OPTIONS["server"]) then
|
||||
infoTable.ClientOnly = true
|
||||
return false -- We depend on a client-only library
|
||||
end
|
||||
|
||||
library = "Nazara" .. toolTable.Name
|
||||
|
||||
-- Import tools includes
|
||||
|
|
@ -862,6 +889,14 @@ function NazaraBuild:Process(infoTable)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function NazaraBuild:Resolve(infoTable)
|
||||
if (type(infoTable.Libraries) == "function") then
|
||||
infoTable.Libraries = infoTable.Libraries()
|
||||
end
|
||||
end
|
||||
|
||||
function NazaraBuild:MakeCopyAfterBuild(infoTable)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
MODULE.Name = "Audio"
|
||||
|
||||
MODULE.ClientOnly = true
|
||||
|
||||
MODULE.Defines = {
|
||||
"NAZARA_AUDIO_OPENAL"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@ MODULE.Name = "Physics"
|
|||
|
||||
MODULE.Libraries = {
|
||||
"NazaraCore",
|
||||
"newton"
|
||||
"Newton"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
MODULE.Name = "Renderer"
|
||||
|
||||
MODULE.ClientOnly = true
|
||||
|
||||
MODULE.Defines = {
|
||||
"NAZARA_RENDERER_OPENGL"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
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"
|
||||
}
|
||||
|
|
@ -22,14 +22,11 @@ TOOL.Files = {
|
|||
"../SDK/src/NDK/**.cpp"
|
||||
}
|
||||
|
||||
TOOL.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraAudio",
|
||||
"NazaraLua",
|
||||
"NazaraNetwork",
|
||||
"NazaraNoise",
|
||||
"NazaraPhysics",
|
||||
"NazaraUtility",
|
||||
"NazaraRenderer",
|
||||
"NazaraGraphics"
|
||||
}
|
||||
TOOL.Libraries = function()
|
||||
local libraries = {}
|
||||
for k,v in pairs(NazaraBuild.Modules) do
|
||||
table.insert(libraries, "Nazara" .. v.Name)
|
||||
end
|
||||
|
||||
return libraries
|
||||
end
|
||||
|
|
@ -37,11 +37,14 @@ TOOL.FilesExcluded = {
|
|||
"../SDK/**/LuaBinding_Renderer.*"
|
||||
}
|
||||
|
||||
TOOL.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraLua",
|
||||
"NazaraNetwork",
|
||||
"NazaraNoise",
|
||||
"NazaraPhysics",
|
||||
"NazaraUtility"
|
||||
}
|
||||
|
||||
TOOL.Libraries = function()
|
||||
local libraries = {}
|
||||
for k,v in pairs(NazaraBuild.Modules) do
|
||||
if (not v.ClientOnly) then
|
||||
table.insert(libraries, "Nazara" .. v.Name)
|
||||
end
|
||||
end
|
||||
|
||||
return libraries
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
EXAMPLE.Name = "Tut00_EmptyProject"
|
||||
|
||||
EXAMPLE.Console = true
|
||||
|
||||
EXAMPLE.Files = {
|
||||
"main.cpp"
|
||||
}
|
||||
|
||||
EXAMPLE.Libraries = {
|
||||
"NazaraAudio",
|
||||
"NazaraCore",
|
||||
"NazaraGraphics",
|
||||
"NazaraLua",
|
||||
"NazaraNetwork",
|
||||
"NazaraNoise",
|
||||
"NazaraPhysics",
|
||||
"NazaraRenderer",
|
||||
"NazaraUtility",
|
||||
"NazaraSDK"
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#include <Nazara/Audio.hpp>
|
||||
#include <Nazara/Core.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Lua.hpp>
|
||||
#include <Nazara/Network.hpp>
|
||||
#include <Nazara/Noise.hpp>
|
||||
#include <Nazara/Physics.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <NDK/Application.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
int main()
|
||||
{
|
||||
// This "example" has only one purpose: Giving an empty project for you to test whatever you want
|
||||
// If you wish to have multiple test projects, you only have to copy/paste this directory and change the name in the build.lua
|
||||
Ndk::Application app;
|
||||
|
||||
// Do what you want here
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
#include <Nazara/Physics/Enums.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
struct NewtonCollision;
|
||||
class NewtonCollision;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
#include <Nazara/Physics/Config.hpp>
|
||||
#include <Nazara/Physics/Geom.hpp>
|
||||
|
||||
struct NewtonBody;
|
||||
class NewtonBody;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics/Config.hpp>
|
||||
|
||||
struct NewtonWorld;
|
||||
class NewtonWorld;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ namespace Nz
|
|||
case PixelFormatType_DXT1:
|
||||
case PixelFormatType_DXT3:
|
||||
case PixelFormatType_DXT5:
|
||||
return (((width + 3) / 4) * ((height + 3) / 4) * (format == PixelFormatType_DXT1) ? 8 : 16) * depth;
|
||||
return (((width + 3) / 4) * ((height + 3) / 4) * ((format == PixelFormatType_DXT1) ? 8 : 16)) * depth;
|
||||
|
||||
default:
|
||||
NazaraError("Unsupported format");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
// This file was automatically generated on 15 May 2016 at 00:11:13
|
||||
|
||||
/*
|
||||
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_GLOBAL_VULKAN_HPP
|
||||
#define NAZARA_GLOBAL_VULKAN_HPP
|
||||
|
||||
#include <Nazara/Vulkan/Config.hpp>
|
||||
#include <Nazara/Vulkan/VkCommandBuffer.hpp>
|
||||
#include <Nazara/Vulkan/VkCommandPool.hpp>
|
||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
||||
#include <Nazara/Vulkan/VkLoader.hpp>
|
||||
#include <Nazara/Vulkan/VkSemaphore.hpp>
|
||||
#include <Nazara/Vulkan/VkSurface.hpp>
|
||||
#include <Nazara/Vulkan/VkSwapchain.hpp>
|
||||
#include <Nazara/Vulkan/Vulkan.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_VULKAN_HPP
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
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
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// 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
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// 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
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
// 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
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
// 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/Vulkan/VkCommandPool.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class NAZARA_VULKAN_API CommandBuffer
|
||||
{
|
||||
friend CommandPool;
|
||||
|
||||
public:
|
||||
CommandBuffer(const CommandBuffer&) = delete;
|
||||
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 bool End();
|
||||
|
||||
inline void Free();
|
||||
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
CommandBuffer& operator=(const CommandBuffer&) = delete;
|
||||
CommandBuffer& operator=(CommandBuffer&&) = delete;
|
||||
|
||||
inline operator VkCommandBuffer();
|
||||
|
||||
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
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
// 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 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 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::Free()
|
||||
{
|
||||
if (m_handle)
|
||||
m_pool->GetDevice().vkFreeCommandBuffers(m_pool->GetDevice(), *m_pool, 1, &m_handle);
|
||||
}
|
||||
|
||||
inline VkResult CommandBuffer::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline CommandBuffer::operator VkCommandBuffer()
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// 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:
|
||||
inline CommandPool(Device& instance);
|
||||
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(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(Device& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle);
|
||||
static inline void DestroyHelper(Device& device, VkCommandPool handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/VkCommandPool.inl>
|
||||
|
||||
#endif // NAZARA_VULKAN_VKCOMMANDPOOL_HPP
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// 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 CommandPool::CommandPool(Device& device) :
|
||||
DeviceObject(device)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool CommandPool::Create(UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkCommandPoolCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
queueFamilyIndex
|
||||
};
|
||||
|
||||
return Create(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(Device& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle)
|
||||
{
|
||||
return device.vkCreateCommandPool(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void CommandPool::DestroyHelper(Device& device, VkCommandPool handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device.vkDestroyCommandPool(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
// 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:
|
||||
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 Queue GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex);
|
||||
inline Instance& GetInstance();
|
||||
inline const Instance& GetInstance() const;
|
||||
inline VkResult GetLastErrorCode() 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(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(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(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
|
||||
|
||||
private:
|
||||
inline PFN_vkVoidFunction GetProcAddr(const char* name);
|
||||
|
||||
Instance& m_instance;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkDevice m_device;
|
||||
VkResult m_lastErrorCode;
|
||||
std::unordered_set<String> m_loadedExtensions;
|
||||
std::unordered_set<String> m_loadedLayers;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/VkDevice.inl>
|
||||
|
||||
#endif // NAZARA_VULKAN_VKDEVICE_HPP
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
// 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(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
inline Device::~Device()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline void Device::Destroy()
|
||||
{
|
||||
if (m_device)
|
||||
{
|
||||
vkDeviceWaitIdle(m_device);
|
||||
vkDestroyDevice(m_device, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
inline Queue Device::GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex)
|
||||
{
|
||||
VkQueue queue;
|
||||
vkGetDeviceQueue(m_device, queueFamilyIndex, queueIndex, &queue);
|
||||
|
||||
return Queue(*this, 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 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>
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
// 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(Device& instance);
|
||||
DeviceObject(const DeviceObject&) = delete;
|
||||
DeviceObject(DeviceObject&&);
|
||||
inline ~DeviceObject();
|
||||
|
||||
inline bool Create(const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
inline Device& GetDevice();
|
||||
inline const Device& GetDevice() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
DeviceObject& operator=(const DeviceObject&) = delete;
|
||||
DeviceObject& operator=(DeviceObject&&) = delete;
|
||||
|
||||
inline operator VkType();
|
||||
|
||||
protected:
|
||||
Device& m_device;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkType m_handle;
|
||||
VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/VkDeviceObject.inl>
|
||||
|
||||
#endif // NAZARA_VULKAN_VKDEVICEOBJECT_HPP
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
// 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(Device& device) :
|
||||
m_device(device),
|
||||
m_handle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline DeviceObject<C, VkType, CreateInfo>::DeviceObject(DeviceObject&& object) :
|
||||
m_device(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 CreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
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 (m_handle != VK_NULL_HANDLE)
|
||||
C::DestroyHelper(m_device, m_handle, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline Device& DeviceObject<C, VkType, CreateInfo>::GetDevice()
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline const Device& 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()
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
// 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 void GetPhysicalDeviceFeatures(VkPhysicalDevice device, VkPhysicalDeviceFeatures* features);
|
||||
inline void GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format, VkFormatProperties* formatProperties);
|
||||
inline bool GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties);
|
||||
inline void GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device, VkPhysicalDeviceMemoryProperties* properties);
|
||||
inline void GetPhysicalDeviceProperties(VkPhysicalDevice device, VkPhysicalDeviceProperties* properties);
|
||||
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
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
// 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);
|
||||
}
|
||||
|
||||
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 void Instance::GetPhysicalDeviceFeatures(VkPhysicalDevice device, VkPhysicalDeviceFeatures* features)
|
||||
{
|
||||
return vkGetPhysicalDeviceFeatures(device, features);
|
||||
}
|
||||
|
||||
inline void Instance::GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format, VkFormatProperties* formatProperties)
|
||||
{
|
||||
return vkGetPhysicalDeviceFormatProperties(device, format, 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 void Instance::GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device, VkPhysicalDeviceMemoryProperties* memoryProperties)
|
||||
{
|
||||
return vkGetPhysicalDeviceMemoryProperties(device, memoryProperties);
|
||||
}
|
||||
|
||||
inline void Instance::GetPhysicalDeviceProperties(VkPhysicalDevice device, VkPhysicalDeviceProperties* properties)
|
||||
{
|
||||
return vkGetPhysicalDeviceProperties(device, 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>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
// 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
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// 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>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
// 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(Device& device, VkQueue queue);
|
||||
inline Queue(const Queue& queue);
|
||||
inline Queue(Queue&& queue);
|
||||
inline ~Queue() = default;
|
||||
|
||||
inline Device& GetDevice();
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
inline bool Present(const VkPresentInfoKHR& presentInfo);
|
||||
inline bool Present(VkSwapchainKHR swapchain, UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE);
|
||||
|
||||
inline bool Submit(const VkSubmitInfo& submit, VkFence fence = VK_NULL_HANDLE);
|
||||
inline bool Submit(UInt32 submitCount, const VkSubmitInfo* submits, VkFence fence = VK_NULL_HANDLE);
|
||||
|
||||
inline bool WaitIdle();
|
||||
|
||||
Queue& operator=(const Queue& queue) = delete;
|
||||
Queue& operator=(Queue&&) = delete;
|
||||
|
||||
inline operator VkQueue();
|
||||
|
||||
protected:
|
||||
Device& m_device;
|
||||
VkQueue m_handle;
|
||||
VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/VkQueue.inl>
|
||||
|
||||
#endif // NAZARA_VULKAN_VKQUEUE_HPP
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
// 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 Queue::Queue(Device& 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 Device& Queue::GetDevice()
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
inline VkResult Queue::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline bool Queue::Present(const VkPresentInfoKHR& presentInfo)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return Submit(1, &submit, fence);
|
||||
}
|
||||
|
||||
inline bool Queue::Submit(UInt32 submitCount, const VkSubmitInfo* submits, VkFence fence)
|
||||
{
|
||||
m_lastErrorCode = m_device.vkQueueSubmit(m_handle, submitCount, submits, fence);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Queue::WaitIdle()
|
||||
{
|
||||
m_lastErrorCode = m_device.vkQueueWaitIdle(m_handle);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Queue::operator VkQueue()
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
// 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:
|
||||
inline Semaphore(Device& instance);
|
||||
Semaphore(const Semaphore&) = delete;
|
||||
Semaphore(Semaphore&&) = default;
|
||||
~Semaphore() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(VkSemaphoreCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
Semaphore& operator=(const Semaphore&) = delete;
|
||||
Semaphore& operator=(Semaphore&&) = delete;
|
||||
|
||||
private:
|
||||
static VkResult CreateHelper(Device& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle);
|
||||
static void DestroyHelper(Device& device, VkSemaphore handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/VkSemaphore.inl>
|
||||
|
||||
#endif // NAZARA_VULKAN_VKSEMAPHORE_HPP
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// 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 Semaphore::Semaphore(Device& device) :
|
||||
DeviceObject(device)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool Semaphore::Create(VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkSemaphoreCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
||||
nullptr,
|
||||
flags
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
|
||||
VkResult Semaphore::CreateHelper(Device& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle)
|
||||
{
|
||||
return device.vkCreateSemaphore(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
void Semaphore::DestroyHelper(Device& device, VkSemaphore handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device.vkDestroySemaphore(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
// 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);
|
||||
bool GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats);
|
||||
bool GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes);
|
||||
bool GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported);
|
||||
|
||||
inline bool IsSupported() const;
|
||||
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
Surface& operator=(const Surface&) = delete;
|
||||
Surface& operator=(Surface&&) = delete;
|
||||
|
||||
inline operator VkSurfaceKHR();
|
||||
|
||||
private:
|
||||
inline bool Create(const VkAllocationCallbacks* allocator);
|
||||
|
||||
Instance& m_instance;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkSurfaceKHR m_surface;
|
||||
VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/VkSurface.inl>
|
||||
|
||||
#endif // NAZARA_VULKAN_VKSURFACE_HPP
|
||||
|
|
@ -0,0 +1,311 @@
|
|||
// 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);
|
||||
}
|
||||
|
||||
inline VkResult Surface::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline bool Surface::GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities)
|
||||
{
|
||||
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)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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>
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// 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>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Swapchain : public DeviceObject<Swapchain, VkSwapchainKHR, VkSwapchainCreateInfoKHR>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
inline Swapchain(Device& instance);
|
||||
Swapchain(const Swapchain&) = delete;
|
||||
Swapchain(Swapchain&&) = default;
|
||||
~Swapchain() = default;
|
||||
|
||||
inline bool AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex);
|
||||
|
||||
inline bool Create(const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline VkImage GetImage(UInt32 index) const;
|
||||
inline const std::vector<VkImage>& GetImages() const;
|
||||
inline UInt32 GetImageCount() const;
|
||||
|
||||
inline bool IsSupported() const;
|
||||
|
||||
Swapchain& operator=(const Swapchain&) = delete;
|
||||
Swapchain& operator=(Swapchain&&) = delete;
|
||||
|
||||
private:
|
||||
static VkResult CreateHelper(Device& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle);
|
||||
static void DestroyHelper(Device& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator);
|
||||
|
||||
std::vector<VkImage> m_images;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/VkSwapchain.inl>
|
||||
|
||||
#endif // NAZARA_VULKAN_VKSWAPCHAIN_HPP
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
// 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 Swapchain::Swapchain(Device& device) :
|
||||
DeviceObject(device)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool Swapchain::AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex)
|
||||
{
|
||||
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 VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
if (!DeviceObject::Create(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;
|
||||
}
|
||||
|
||||
m_images.resize(imageCount);
|
||||
m_lastErrorCode = m_device.vkGetSwapchainImagesKHR(m_device, m_handle, &imageCount, m_images.data());
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query swapchain images");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline VkImage Swapchain::GetImage(UInt32 index) const
|
||||
{
|
||||
return m_images[index];
|
||||
}
|
||||
|
||||
inline const std::vector<VkImage>& Swapchain::GetImages() const
|
||||
{
|
||||
return m_images;
|
||||
}
|
||||
|
||||
inline UInt32 Swapchain::GetImageCount() const
|
||||
{
|
||||
return m_images.size();
|
||||
}
|
||||
|
||||
inline bool Swapchain::IsSupported() const
|
||||
{
|
||||
if (!m_device.IsExtensionLoaded("VK_KHR_swapchain"))
|
||||
return false;
|
||||
}
|
||||
|
||||
VkResult Swapchain::CreateHelper(Device& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle)
|
||||
{
|
||||
return device.vkCreateSwapchainKHR(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
void Swapchain::DestroyHelper(Device& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device.vkDestroySwapchainKHR(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
// 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/Vulkan/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKAN_API Vulkan
|
||||
{
|
||||
public:
|
||||
Vulkan() = delete;
|
||||
~Vulkan() = delete;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_VULKAN_HPP
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -94,6 +94,7 @@ float VectorToDepthValue(vec3 vec, float zNear, float zFar)
|
|||
return (normZ + 1.0) * 0.5;
|
||||
}
|
||||
|
||||
#if SHADOW_MAPPING
|
||||
float CalculateDirectionalShadowFactor(int lightIndex)
|
||||
{
|
||||
vec4 lightSpacePos = vLightSpacePos[lightIndex];
|
||||
|
|
@ -119,6 +120,7 @@ float CalculateSpotShadowFactor(int lightIndex)
|
|||
|
||||
return visibility;
|
||||
}
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -68,7 +68,7 @@ namespace Nz
|
|||
PhysObject::~PhysObject()
|
||||
{
|
||||
if (m_body)
|
||||
NewtonDestroyBody(m_world->GetHandle(), m_body);
|
||||
NewtonDestroyBody(m_body);
|
||||
}
|
||||
|
||||
void PhysObject::AddForce(const Vector3f& force, CoordSys coordSys)
|
||||
|
|
@ -304,11 +304,13 @@ namespace Nz
|
|||
Vector3f min, max;
|
||||
NewtonBodyGetAABB(m_body, min, max);
|
||||
|
||||
NewtonWorldForEachBodyInAABBDo(m_world->GetHandle(), min, max, [](const NewtonBody* const body, void* const userData)
|
||||
NewtonWorldForEachBodyInAABBDo(m_world->GetHandle(), min, max, [](const NewtonBody* const body, void* const userData) -> int
|
||||
{
|
||||
NazaraUnused(userData);
|
||||
NewtonBodySetSleepState(body, 0);
|
||||
}, nullptr);
|
||||
return 1;
|
||||
},
|
||||
nullptr);
|
||||
}
|
||||
/*for (std::set<PhysObjectListener*>::iterator it = m_listeners.begin(); it != m_listeners.end(); ++it)
|
||||
(*it)->PhysObjectOnUpdate(this);*/
|
||||
|
|
@ -317,7 +319,7 @@ namespace Nz
|
|||
PhysObject& PhysObject::operator=(PhysObject&& object)
|
||||
{
|
||||
if (m_body)
|
||||
NewtonDestroyBody(m_world->GetHandle(), m_body);
|
||||
NewtonDestroyBody(m_body);
|
||||
|
||||
m_body = object.m_body;
|
||||
m_forceAccumulator = std::move(object.m_forceAccumulator);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
// 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
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// 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,
|
||||
1U
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
// 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)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateDevice(device, &createInfo, allocator, &m_device);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to create Vulkan device");
|
||||
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]);
|
||||
|
||||
#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(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(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(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
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
// 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/Log.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <Nazara/Vulkan/Config.hpp>
|
||||
#include <Nazara/Vulkan/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
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
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
NazaraNotice("Initialized: Vulkan module");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Vulkan::IsInitialized()
|
||||
{
|
||||
return s_moduleReferenceCounter != 0;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
NazaraNotice("Uninitialized: Vulkan module");
|
||||
|
||||
// Free module dependencies
|
||||
Utility::Uninitialize();
|
||||
}
|
||||
|
||||
unsigned int Vulkan::s_moduleReferenceCounter = 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue