Remove Vulkan from master branch

Former-commit-id: 4bc44622fc88c08e4718484ee74128a4a8a326e0 [formerly 6ecba7b84dc522ace503113d60a54d3e30edb058] [formerly d80ca9f0e519522d7e0dc9ccb0e4b0a4aa1a13ab [formerly abef6064b63ddae172eb7e9c09bab1b7faf5c399]]
Former-commit-id: f94d82bcc372d4f19f51280c25d2e98f99bfdbcf [formerly f1953666e292997824ce70da96758e3b67d4ac37]
Former-commit-id: 1148ef1a828bb3599f41a432de67148fd4ef98f8
This commit is contained in:
Lynix
2016-08-17 13:00:03 +02:00
parent 5ad6132998
commit 318e6368a2
31 changed files with 0 additions and 2641 deletions

View File

@@ -1,31 +0,0 @@
// Copyright (C) 2014 AUTHORS
// This file is part of the "Nazara Engine - Module name"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Vulkan/Config.hpp>
#if NAZARA_VULKAN_MANAGE_MEMORY
#include <Nazara/Core/MemoryManager.hpp>
#include <new> // Nécessaire ?
void* operator new(std::size_t size)
{
return Nz::MemoryManager::Allocate(size, false);
}
void* operator new[](std::size_t size)
{
return Nz::MemoryManager::Allocate(size, true);
}
void operator delete(void* pointer) noexcept
{
Nz::MemoryManager::Free(pointer, false);
}
void operator delete[](void* pointer) noexcept
{
Nz::MemoryManager::Free(pointer, true);
}
#endif // NAZARA_VULKAN_MANAGE_MEMORY

View File

@@ -1,53 +0,0 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Vulkan/VkCommandPool.hpp>
#include <Nazara/Vulkan/VkCommandBuffer.hpp>
#include <Nazara/Vulkan/Debug.hpp>
namespace Nz
{
namespace Vk
{
CommandBuffer CommandPool::AllocateCommandBuffer(VkCommandBufferLevel level)
{
VkCommandBufferAllocateInfo createInfo =
{
VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
nullptr,
m_handle,
level,
1U
};
VkCommandBuffer handle = VK_NULL_HANDLE;
m_lastErrorCode = m_device.vkAllocateCommandBuffers(m_device, &createInfo, &handle);
return CommandBuffer(*this, handle);
}
std::vector<CommandBuffer> CommandPool::AllocateCommandBuffers(UInt32 commandBufferCount, VkCommandBufferLevel level)
{
VkCommandBufferAllocateInfo createInfo =
{
VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
nullptr,
m_handle,
level,
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;
}
}
}

View File

@@ -1,178 +0,0 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Vulkan/VkDevice.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Vulkan/Debug.hpp>
namespace Nz
{
namespace Vk
{
bool Device::Create(VkPhysicalDevice device, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator)
{
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;
}
}
}

View File

@@ -1,193 +0,0 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Vulkan/VkInstance.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Vulkan/Debug.hpp>
namespace Nz
{
namespace Vk
{
bool Instance::Create(const VkInstanceCreateInfo& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = Loader::vkCreateInstance(&createInfo, allocator, &m_instance);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to create Vulkan instance");
return false;
}
// Store the allocator to access them when needed
if (allocator)
m_allocator = *allocator;
else
m_allocator.pfnAllocation = nullptr;
// Parse extensions and layers
for (UInt32 i = 0; i < createInfo.enabledExtensionCount; ++i)
m_loadedExtensions.insert(createInfo.ppEnabledExtensionNames[i]);
for (UInt32 i = 0; i < createInfo.enabledLayerCount; ++i)
m_loadedLayers.insert(createInfo.ppEnabledLayerNames[i]);
// And now load everything
#define NAZARA_VULKAN_LOAD_INSTANCE(func) func = reinterpret_cast<PFN_##func>(GetProcAddr(#func))
try
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
// Vulkan core
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateDevice);
NAZARA_VULKAN_LOAD_INSTANCE(vkDestroyInstance);
NAZARA_VULKAN_LOAD_INSTANCE(vkEnumeratePhysicalDevices);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetDeviceProcAddr);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceFeatures);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceFormatProperties);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceImageFormatProperties);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceMemoryProperties);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceProperties);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceQueueFamilyProperties);
// VK_KHR_display
if (IsExtensionLoaded("VK_KHR_display"))
{
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateDisplayModeKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateDisplayPlaneSurfaceKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetDisplayModePropertiesKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetDisplayPlaneCapabilitiesKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetDisplayPlaneSupportedDisplaysKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceDisplayPlanePropertiesKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceDisplayPropertiesKHR);
}
// VK_KHR_surface
if (IsExtensionLoaded("VK_KHR_surface"))
{
NAZARA_VULKAN_LOAD_INSTANCE(vkDestroySurfaceKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceSurfaceFormatsKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceSurfacePresentModesKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceSurfaceSupportKHR);
}
// VK_EXT_debug_report
if (IsExtensionLoaded("VK_EXT_debug_report"))
{
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateDebugReportCallbackEXT);
NAZARA_VULKAN_LOAD_INSTANCE(vkDestroyDebugReportCallbackEXT);
NAZARA_VULKAN_LOAD_INSTANCE(vkDebugReportMessageEXT);
}
#ifdef VK_USE_PLATFORM_ANDROID_KHR
// VK_KHR_android_surface
if (IsExtensionLoaded("VK_KHR_android_surface"))
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateAndroidSurfaceKHR);
#endif
#ifdef VK_USE_PLATFORM_MIR_KHR
// VK_KHR_mir_surface
if (IsExtensionLoaded("VK_KHR_mir_surface"))
{
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateMirSurfaceKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceMirPresentationSupportKHR);
}
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
// VK_KHR_xcb_surface
if (IsExtensionLoaded("VK_KHR_xcb_surface"))
{
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateXcbSurfaceKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceXcbPresentationSupportKHR);
}
#endif
#ifdef VK_USE_PLATFORM_XLIB_KHR
// VK_KHR_xlib_surface
if (IsExtensionLoaded("VK_KHR_xlib_surface"))
{
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateXlibSurfaceKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceXlibPresentationSupportKHR);
}
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
// VK_KHR_wayland_surface
if (IsExtensionLoaded("VK_KHR_wayland_surface"))
{
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateWaylandSurfaceKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceWaylandPresentationSupportKHR);
}
#endif
#ifdef VK_USE_PLATFORM_WIN32_KHR
// VK_KHR_win32_surface
if (IsExtensionLoaded("VK_KHR_win32_surface"))
{
NAZARA_VULKAN_LOAD_INSTANCE(vkCreateWin32SurfaceKHR);
NAZARA_VULKAN_LOAD_INSTANCE(vkGetPhysicalDeviceWin32PresentationSupportKHR);
}
#endif
}
catch (const std::exception& e)
{
NazaraError(String("Failed to query instance function: ") + e.what());
return false;
}
#undef NAZARA_VULKAN_LOAD_INSTANCE
return true;
}
bool Instance::EnumeratePhysicalDevices(std::vector<VkPhysicalDevice>* devices)
{
NazaraAssert(devices, "Invalid device vector");
// First, query physical device count
UInt32 deviceCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS || deviceCount == 0)
{
NazaraError("Failed to query physical device count");
return false;
}
// Now we can get the list of the available physical device
devices->resize(deviceCount);
m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, devices->data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query physical devices");
return false;
}
return true;
}
bool Instance::GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector<VkQueueFamilyProperties>* queueFamilyProperties)
{
NazaraAssert(queueFamilyProperties, "Invalid device vector");
// First, query physical device count
UInt32 queueFamiliesCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamiliesCount, nullptr);
if (queueFamiliesCount == 0)
{
NazaraError("Failed to query physical device count");
return false;
}
// Now we can get the list of the available physical device
queueFamilyProperties->resize(queueFamiliesCount);
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamiliesCount, queueFamilyProperties->data());
return true;
}
}
}

View File

@@ -1,117 +0,0 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Vulkan/VkLoader.hpp>
#include <Nazara/Vulkan/Debug.hpp>
namespace Nz
{
namespace Vk
{
bool Loader::EnumerateInstanceExtensionProperties(std::vector<VkExtensionProperties>* properties, const char* layerName)
{
NazaraAssert(properties, "Invalid device vector");
// First, query physical device count
UInt32 propertyCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
s_lastErrorCode = vkEnumerateInstanceExtensionProperties(layerName, &propertyCount, properties->data());
if (s_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to get instance extension properties count");
return false;
}
// Now we can get the list of the available physical device
properties->resize(propertyCount);
s_lastErrorCode = vkEnumerateInstanceExtensionProperties(layerName, &propertyCount, properties->data());
if (s_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to enumerate instance extension properties");
return false;
}
return true;
}
bool Loader::EnumerateInstanceLayerProperties(std::vector<VkLayerProperties>* properties)
{
NazaraAssert(properties, "Invalid device vector");
// First, query physical device count
UInt32 propertyCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
s_lastErrorCode = vkEnumerateInstanceLayerProperties(&propertyCount, properties->data());
if (s_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to get instance layer properties count");
return false;
}
// Now we can get the list of the available physical device
properties->resize(propertyCount);
s_lastErrorCode = vkEnumerateInstanceLayerProperties(&propertyCount, properties->data());
if (s_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to enumerate instance layer properties");
return false;
}
return true;
}
bool Loader::Initialize()
{
#ifdef NAZARA_PLATFORM_WINDOWS
s_vulkanLib.Load("vulkan-1.dll");
#elif defined(NAZARA_PLATFORM_LINUX)
s_vulkanLib.Load("libvulkan.so");
#else
#error Unhandled platform
#endif
if (!s_vulkanLib.IsLoaded())
{
NazaraError("Failed to open vulkan library: " + s_vulkanLib.GetLastError());
return false;
}
// vkGetInstanceProcAddr is the only function that's garantee to be exported
vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(s_vulkanLib.GetSymbol("vkGetInstanceProcAddr"));
if (!vkGetInstanceProcAddr)
{
NazaraError("Failed to get symbol \"vkGetInstanceProcAddr\": " + s_vulkanLib.GetLastError());
return false;
}
// all other functions should be loaded using vkGetInstanceProcAddr
#define NAZARA_VULKAN_LOAD_GLOBAL(func) func = reinterpret_cast<PFN_##func>(vkGetInstanceProcAddr(nullptr, #func))
NAZARA_VULKAN_LOAD_GLOBAL(vkCreateInstance);
NAZARA_VULKAN_LOAD_GLOBAL(vkEnumerateInstanceExtensionProperties);
NAZARA_VULKAN_LOAD_GLOBAL(vkEnumerateInstanceLayerProperties);
#undef NAZARA_VULKAN_LOAD_GLOBAL
s_lastErrorCode = VkResult::VK_SUCCESS;
return true;
}
#define NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL(func) PFN_##func Loader::func = nullptr
NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL(vkCreateInstance);
NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL(vkEnumerateInstanceExtensionProperties);
NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL(vkEnumerateInstanceLayerProperties);
NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL(vkGetInstanceProcAddr);
#undef NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL
DynLib Loader::s_vulkanLib;
VkResult Loader::s_lastErrorCode;
void Loader::Uninitialize()
{
s_vulkanLib.Unload();
}
}
}

View File

@@ -1,70 +0,0 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Vulkan/Vulkan.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/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;
}