MCPcopy Create free account
hub / github.com/SFML/SFML / setupInstance

Method setupInstance

examples/vulkan/Vulkan.cpp:405–505  ·  view source on GitHub ↗

Setup Vulkan instance

Source from the content-addressed store, hash-verified

403
404 // Setup Vulkan instance
405 void setupInstance()
406 {
407 // Load bootstrap entry points
408 gladLoadVulkan({}, getVulkanFunction);
409
410 if (!vkCreateInstance)
411 {
412 vulkanAvailable = false;
413 return;
414 }
415
416 // Retrieve the available instance layers
417 std::uint32_t objectCount = 0;
418
419 std::vector<VkLayerProperties> layers;
420
421 if (vkEnumerateInstanceLayerProperties(&objectCount, nullptr) != VK_SUCCESS)
422 {
423 vulkanAvailable = false;
424 return;
425 }
426
427 layers.resize(objectCount);
428
429 if (vkEnumerateInstanceLayerProperties(&objectCount, layers.data()) != VK_SUCCESS)
430 {
431 vulkanAvailable = false;
432 return;
433 }
434
435 // Activate the layers we are interested in
436 std::vector<const char*> validationLayers;
437
438 for (VkLayerProperties& layer : layers)
439 {
440 // VK_LAYER_LUNARG_standard_validation, meta-layer for the following layers:
441 // -- VK_LAYER_GOOGLE_threading
442 // -- VK_LAYER_LUNARG_parameter_validation
443 // -- VK_LAYER_LUNARG_device_limits
444 // -- VK_LAYER_LUNARG_object_tracker
445 // -- VK_LAYER_LUNARG_image
446 // -- VK_LAYER_LUNARG_core_validation
447 // -- VK_LAYER_LUNARG_swapchain
448 // -- VK_LAYER_GOOGLE_unique_objects
449 // These layers perform error checking and warn about bad or sub-optimal Vulkan API usage
450 // VK_LAYER_LUNARG_monitor appends an FPS counter to the window title
451 if (std::string_view(layer.layerName) == "VK_LAYER_LUNARG_standard_validation")
452 {
453 validationLayers.push_back("VK_LAYER_LUNARG_standard_validation");
454 }
455 else if (std::string_view(layer.layerName) == "VK_LAYER_LUNARG_monitor")
456 {
457 validationLayers.push_back("VK_LAYER_LUNARG_monitor");
458 }
459 }
460
461 // Retrieve the extensions we need to enable in order to use Vulkan with SFML
462 std::vector<const char*> requiredExtensions = sf::Vulkan::getGraphicsRequiredInstanceExtensions();

Callers

nothing calls this directly

Calls 4

gladLoadVulkanFunction · 0.85
VkApplicationInfoClass · 0.70
resizeMethod · 0.45

Tested by

no test coverage detected