+#include "vulkancontext.h"
+#include "vulkancontext_platform.h"
#include <stdexcept>
#include <vector>
#define VK_USE_PLATFORM_XLIB_KHR
#include <vulkan/vulkan.h>
#include <msp/core/application.h>
+#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)
-{ }
-
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");
{
VkDebugReportCallbackCreateInfoEXT debug_report_create_info = { };
debug_report_create_info.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
- debug_report_create_info.flags = VK_DEBUG_REPORT_WARNING_BIT_EXT|VK_DEBUG_REPORT_ERROR_BIT_EXT|VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT;
+ debug_report_create_info.flags = VK_DEBUG_REPORT_WARNING_BIT_EXT|VK_DEBUG_REPORT_ERROR_BIT_EXT|VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT|VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
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());
continue;
if(supported)
- priv->physical_device = phys_devices[0];
+ {
+ priv->physical_device = phys_device;
+ break;
+ }
}
if(!priv->physical_device)
extensions.clear();
extensions.push_back("VK_KHR_swapchain");
+ VkPhysicalDeviceFeatures features = { };
+ features.geometryShader = (opts.enable_geometry_shader ? VK_TRUE : VK_FALSE);
+ features.tessellationShader = (opts.enable_tessellation_shader ? VK_TRUE : VK_FALSE);
+
VkDeviceCreateInfo device_create_info = { };
device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
device_create_info.queueCreateInfoCount = 1;
device_create_info.pQueueCreateInfos = &queue_create_info;
device_create_info.enabledExtensionCount = extensions.size();
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, VkDebugReportObjectTypeEXT obj_type, uint64_t obj_id, size_t, int32_t, const char *layer_prefix, const char *message, void *)
+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, "Vulkan debug report from %s: Object %d of type %d: %s\n", layer_prefix, obj_type, obj_id, message);
+ IO::print(IO::cerr, "%s\n", message);
+ if((flags&VK_DEBUG_REPORT_ERROR_BIT_EXT) && Debug::check_debugger()==Debug::GDB)
+ Debug::debug_break();
return VK_FALSE;
}