+#include "vulkancontext.h"
+#include "vulkancontext_platform.h"
#include <stdexcept>
#include <vector>
#define VK_USE_PLATFORM_XLIB_KHR
#include <msp/debug/debugapi.h>
#include <msp/io/print.h>
#include "display_private.h"
-#include "vulkancontext.h"
-#include "vulkancontext_platform.h"
#include "window_private.h"
using namespace std;
}
}
-VulkanOptions::VulkanOptions():
- enable_validation(false),
- enable_debug_report(false),
- enable_geometry_shader(false),
- enable_tessellation_shader(false)
-{ }
-
void VulkanContext::platform_init(const VulkanOptions &opts)
{
instance_create_info.enabledExtensionCount = extensions.size();
instance_create_info.ppEnabledExtensionNames = extensions.data();
- VkResult result = f.vkCreateInstance(&instance_create_info, 0, &priv->instance);
+ VkResult result = f.vkCreateInstance(&instance_create_info, nullptr, &priv->instance);
if(result!=VK_SUCCESS)
throw vulkan_error(result, "vkCreateInstance");
debug_report_create_info.pfnCallback = &Private::debug_report_func;
debug_report_create_info.pUserData = this;
- result = f.vkCreateDebugReportCallback(priv->instance, &debug_report_create_info, 0, &priv->debug_report_callback);
+ result = f.vkCreateDebugReportCallback(priv->instance, &debug_report_create_info, nullptr, &priv->debug_report_callback);
if(result!=VK_SUCCESS)
throw vulkan_error(result, "vkCreateDebugReportCallback");
}
- else
- priv->debug_report_callback = 0;
VkXlibSurfaceCreateInfoKHR surface_create_info = { };
surface_create_info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
surface_create_info.dpy = display.get_private().display;
surface_create_info.window = window.get_private().window;
- result = f.vkCreateXlibSurface(priv->instance, &surface_create_info, 0, &priv->surface);
+ result = f.vkCreateXlibSurface(priv->instance, &surface_create_info, nullptr, &priv->surface);
if(result!=VK_SUCCESS)
throw vulkan_error(result, "vkCreateXlibSurface");
unsigned n_phys_devices = 0;
- result = f.vkEnumeratePhysicalDevices(priv->instance, &n_phys_devices, 0);
+ result = f.vkEnumeratePhysicalDevices(priv->instance, &n_phys_devices, nullptr);
if(result!=VK_SUCCESS)
throw vulkan_error(result, "vkEnumeratePhysicalDevices");
else if(!n_phys_devices)
if(result!=VK_SUCCESS)
throw vulkan_error(result, "vkEnumeratePhysicalDevices");
- priv->physical_device = 0;
unsigned gfx_queue_index = 0;
for(unsigned i=0; i<n_phys_devices; ++i)
{
VkPhysicalDevice phys_device = phys_devices[i];
unsigned n_queue_families = 0;
- f.vkGetPhysicalDeviceQueueFamilyProperties(phys_device, &n_queue_families, 0);
+ f.vkGetPhysicalDeviceQueueFamilyProperties(phys_device, &n_queue_families, nullptr);
vector<VkQueueFamilyProperties> queue_family_props(n_queue_families);
f.vkGetPhysicalDeviceQueueFamilyProperties(phys_device, &n_queue_families, queue_family_props.data());
device_create_info.ppEnabledExtensionNames = extensions.data();
device_create_info.pEnabledFeatures = &features;
- result = f.vkCreateDevice(priv->physical_device, &device_create_info, 0, &priv->device);
+ result = f.vkCreateDevice(priv->physical_device, &device_create_info, nullptr, &priv->device);
if(result!=VK_SUCCESS)
throw vulkan_error(result, "vkCreateDevice");
catch(...)
{
if(priv->device)
- f.vkDestroyDevice(priv->device, 0);
+ f.vkDestroyDevice(priv->device, nullptr);
if(priv->surface)
- f.vkDestroySurface(priv->instance, priv->surface, 0);
+ f.vkDestroySurface(priv->instance, priv->surface, nullptr);
if(priv->debug_report_callback)
- f.vkDestroyDebugReportCallback(priv->instance, priv->debug_report_callback, 0);
+ f.vkDestroyDebugReportCallback(priv->instance, priv->debug_report_callback, nullptr);
if(priv->instance)
- f.vkDestroyInstance(priv->instance, 0);
+ f.vkDestroyInstance(priv->instance, nullptr);
delete priv;
throw;
}
VulkanContext::~VulkanContext()
{
const VulkanFunctions &f = priv->functions;
- f.vkDestroyDevice(priv->device, 0);
- f.vkDestroySurface(priv->instance, priv->surface, 0);
+ f.vkDestroyDevice(priv->device, nullptr);
+ f.vkDestroySurface(priv->instance, priv->surface, nullptr);
if(priv->debug_report_callback)
- f.vkDestroyDebugReportCallback(priv->instance, priv->debug_report_callback, 0);
- f.vkDestroyInstance(priv->instance, 0);
+ f.vkDestroyDebugReportCallback(priv->instance, priv->debug_report_callback, nullptr);
+ f.vkDestroyInstance(priv->instance, nullptr);
delete priv;
}
-void (*VulkanContext::_get_function(const std::string &name) const)()
+void (*VulkanContext::_get_function(const string &name) const)()
{
return vkGetInstanceProcAddr(priv->instance, name.c_str());
}
-VulkanContext::Private::Private():
- instance(0),
- physical_device(0),
- device(0),
- graphics_queue(0),
- debug_report_callback(0)
-{ }
-
VkBool32 VulkanContext::Private::debug_report_func(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT, uint64_t, size_t, int32_t, const char *, const char *message, void *)
{
IO::print(IO::cerr, "%s\n", message);