Vulkan: Add loading of Instance/Device
Former-commit-id: 0184f78824900bd46cff94dbfe829b126b8c984d
This commit is contained in:
38
include/Nazara/Vulkan.hpp
Normal file
38
include/Nazara/Vulkan.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// This file was automatically generated on 24 Apr 2016 at 02:26:55
|
||||
|
||||
/*
|
||||
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/VkDevice.hpp>
|
||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
||||
#include <Nazara/Vulkan/VkLoader.hpp>
|
||||
#include <Nazara/Vulkan/Vulkan.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_VULKAN_HPP
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Nazara Engine - Module name
|
||||
Nazara Engine - Vulkan
|
||||
|
||||
Copyright (C) YEAR AUTHORS (EMAIL)
|
||||
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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// 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
|
||||
|
||||
|
||||
62
include/Nazara/Vulkan/VkDevice.hpp
Normal file
62
include/Nazara/Vulkan/VkDevice.hpp
Normal file
@@ -0,0 +1,62 @@
|
||||
// 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/Vulkan/Config.hpp>
|
||||
#include <Nazara/Vulkan/VkLoader.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Instance;
|
||||
|
||||
class NAZARA_VULKAN_API 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 void GetDeviceQueue(UInt32 queueFamilyIndex, UInt32 queueIndex, VkQueue* queue);
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
inline bool WaitForIdle();
|
||||
|
||||
Device& operator=(const Device&) = delete;
|
||||
Device& operator=(Device&&) = delete;
|
||||
|
||||
// Vulkan functions
|
||||
#define NAZARA_VULKAN_DEVICE_FUNCTION(func) PFN_##func func
|
||||
|
||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDestroyDevice);
|
||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkDeviceWaitIdle);
|
||||
NAZARA_VULKAN_DEVICE_FUNCTION(vkGetDeviceQueue);
|
||||
|
||||
#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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/VkDevice.inl>
|
||||
|
||||
#endif // NAZARA_VULKAN_VKDEVICE_HPP
|
||||
67
include/Nazara/Vulkan/VkDevice.inl
Normal file
67
include/Nazara/Vulkan/VkDevice.inl
Normal file
@@ -0,0 +1,67 @@
|
||||
// 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/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 void Device::GetDeviceQueue(UInt32 queueFamilyIndex, UInt32 queueIndex, VkQueue* queue)
|
||||
{
|
||||
return vkGetDeviceQueue(m_device, queueFamilyIndex, queueIndex, queue);
|
||||
}
|
||||
|
||||
inline VkResult Device::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
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 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>
|
||||
74
include/Nazara/Vulkan/VkInstance.hpp
Normal file
74
include/Nazara/Vulkan/VkInstance.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// 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/Vulkan/Config.hpp>
|
||||
#include <Nazara/Vulkan/VkLoader.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
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 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;
|
||||
|
||||
Instance& operator=(const Instance&) = delete;
|
||||
Instance& operator=(Instance&&) = delete;
|
||||
|
||||
// Vulkan functions
|
||||
#define NAZARA_VULKAN_INSTANCE_FUNCTION(func) PFN_##func func
|
||||
|
||||
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);
|
||||
|
||||
#undef NAZARA_VULKAN_INSTANCE_FUNCTION
|
||||
|
||||
private:
|
||||
inline PFN_vkVoidFunction GetProcAddr(const char* name);
|
||||
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkInstance m_instance;
|
||||
VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/VkInstance.inl>
|
||||
|
||||
#endif // NAZARA_VULKAN_VKINSTANCE_HPP
|
||||
86
include/Nazara/Vulkan/VkInstance.inl
Normal file
86
include/Nazara/Vulkan/VkInstance.inl
Normal file
@@ -0,0 +1,86 @@
|
||||
// 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 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 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>
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// 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_LOADER_HPP
|
||||
#define NAZARA_VULKAN_LOADER_HPP
|
||||
#ifndef NAZARA_VULKAN_VKLOADER_HPP
|
||||
#define NAZARA_VULKAN_VKLOADER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/DynLib.hpp>
|
||||
@@ -14,21 +14,35 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKAN_API VkLoader
|
||||
namespace Vk
|
||||
{
|
||||
public:
|
||||
VkLoader() = delete;
|
||||
~VkLoader() = delete;
|
||||
class NAZARA_VULKAN_API Loader
|
||||
{
|
||||
public:
|
||||
Loader() = delete;
|
||||
~Loader() = delete;
|
||||
|
||||
static inline PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name);
|
||||
|
||||
static bool Initialize();
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static DynLib s_vulkanLib;
|
||||
};
|
||||
// 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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#define NAZARA_VULKAN_EXPORTED_FUNCTION(func) extern PFN_##func func;
|
||||
#include <Nazara/Vulkan/VkLoader.inl>
|
||||
|
||||
NAZARA_VULKAN_EXPORTED_FUNCTION(vkGetInstanceProcAddr);
|
||||
|
||||
#endif // NAZARA_VULKAN_LOADER_HPP
|
||||
#endif // NAZARA_VULKAN_VKLOADER_HPP
|
||||
|
||||
19
include/Nazara/Vulkan/VkLoader.inl
Normal file
19
include/Nazara/Vulkan/VkLoader.inl
Normal file
@@ -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>
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user