File: main-dynamicVulkanLoading.cpp

package info (click to toggle)
cmake 4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 152,348 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (55 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1

#include <iostream>

#include <vulkan/vulkan.hpp>

using namespace std;

VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE

int main()
{
  // catch exceptions
  // (vulkan.hpp functions throws if they fail)
  try {

    // initialize dynamic dispatcher
    vk::detail::DynamicLoader dl;
    PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
      dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
    VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);

    // Vulkan instance
    vk::UniqueInstance instance =
      vk::createInstanceUnique(vk::InstanceCreateInfo{
        vk::InstanceCreateFlags(), // flags
        &(vk::ApplicationInfo const&)vk::ApplicationInfo{
          "CMake Test application", // application name
          VK_MAKE_VERSION(0, 0, 0), // application version
          "CMake Test Engine",      // engine name
          VK_MAKE_VERSION(0, 0, 0), // engine version
          VK_API_VERSION_1_0,       // api version
        },
        0,       // enabled layer count
        nullptr, // enabled layer names
        0,       // enabled extension count
        nullptr, // enabled extension names
      });
    VULKAN_HPP_DEFAULT_DISPATCHER.init(instance.get());

    // catch exceptions
  } catch (vk::Error& e) {
    cout << "Failed because of Vulkan exception: " << e.what() << endl;
  } catch (exception& e) {
    cout << "Failed because of exception: " << e.what() << endl;
  } catch (...) {
    cout << "Failed because of unspecified exception." << endl;
  }

  // We can't assert in this code because in general vk::createInstanceUnique
  // might throw if no driver is found - but if we get here, FindVulkan is
  // working

  return 0;
}