summaryrefslogtreecommitdiff
path: root/drivers/vulkan/SCsub
blob: 6a2a57d18c4ba522afaaf4ce16ee42ea683ab3f9 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python

Import("env")

thirdparty_obj = []

# FIXME: Refactor all this to reduce code duplication.
if env["platform"] == "android":
    # Use NDK Vulkan headers
    thirdparty_dir = env["ANDROID_NDK_ROOT"] + "/sources/third_party/vulkan/src"
    thirdparty_includes = [
        thirdparty_dir,
        thirdparty_dir + "/include",
        thirdparty_dir + "/layers",
        thirdparty_dir + "/layers/generated",
    ]
    env.Prepend(CPPPATH=thirdparty_includes)

    # Build Vulkan memory allocator
    env_thirdparty = env.Clone()
    env_thirdparty.disable_warnings()

    thirdparty_dir = "#thirdparty/vulkan"
    vma_sources = [thirdparty_dir + "/android/vk_mem_alloc.cpp"]
    env_thirdparty.add_source_files(thirdparty_obj, vma_sources)

elif env["platform"] == "iphone":
    # Use bundled Vulkan headers
    thirdparty_dir = "#thirdparty/vulkan"
    env.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include", thirdparty_dir + "/loader"])

    # Build Vulkan memory allocator
    env_thirdparty = env.Clone()
    env_thirdparty.disable_warnings()

    vma_sources = [thirdparty_dir + "/vk_mem_alloc.cpp"]
    env_thirdparty.add_source_files(thirdparty_obj, vma_sources)

elif env["builtin_vulkan"]:
    # Use bundled Vulkan headers
    thirdparty_dir = "#thirdparty/vulkan"
    env.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include", thirdparty_dir + "/loader"])

    # Build Vulkan loader library
    env_thirdparty = env.Clone()
    env_thirdparty.disable_warnings()

    loader_sources = [
        "cJSON.c",
        "debug_utils.c",
        "dev_ext_trampoline.c",
        "loader.c",
        "murmurhash.c",
        "phys_dev_ext.c",
        "trampoline.c",
        "unknown_ext_chain.c",
        "wsi.c",
        "extension_manual.c",
    ]
    vma_sources = [thirdparty_dir + "/vk_mem_alloc.cpp"]

    if env["platform"] == "windows":
        loader_sources.append("dirent_on_windows.c")
        env_thirdparty.AppendUnique(
            CPPDEFINES=[
                "VK_USE_PLATFORM_WIN32_KHR",
                "VULKAN_NON_CMAKE_BUILD",
                "WIN32_LEAN_AND_MEAN",
                'API_NAME=\\"%s\\"' % "Vulkan",
            ]
        )
        if not env.msvc:  # Windows 7+, missing in mingw headers
            env_thirdparty.AppendUnique(
                CPPDEFINES=["CM_GETIDLIST_FILTER_CLASS=0x00000200", "CM_GETIDLIST_FILTER_PRESENT=0x00000100"]
            )
    elif env["platform"] == "osx":
        env_thirdparty.AppendUnique(
            CPPDEFINES=[
                "VK_USE_PLATFORM_MACOS_MVK",
                "VULKAN_NON_CMAKE_BUILD",
                'SYSCONFDIR=\\"%s\\"' % "/etc",
                'FALLBACK_DATA_DIRS=\\"%s\\"' % "/usr/local/share:/usr/share",
                'FALLBACK_CONFIG_DIRS=\\"%s\\"' % "/etc/xdg",
            ]
        )
    elif env["platform"] == "linuxbsd":
        env_thirdparty.AppendUnique(
            CPPDEFINES=[
                "VK_USE_PLATFORM_XLIB_KHR",
                "VULKAN_NON_CMAKE_BUILD",
                'SYSCONFDIR=\\"%s\\"' % "/etc",
                'FALLBACK_DATA_DIRS=\\"%s\\"' % "/usr/local/share:/usr/share",
                'FALLBACK_CONFIG_DIRS=\\"%s\\"' % "/etc/xdg",
            ]
        )
        import platform

        if platform.system() == "Linux":
            # In glibc since 2.17 and musl libc since 1.1.24. Used by loader.c.
            env_thirdparty.AppendUnique(CPPDEFINES=["HAVE_SECURE_GETENV"])

    loader_sources = [thirdparty_dir + "/loader/" + file for file in loader_sources]
    env_thirdparty.add_source_files(thirdparty_obj, loader_sources)
    env_thirdparty.add_source_files(thirdparty_obj, vma_sources)

else:  # Always build VMA.
    thirdparty_dir = "#thirdparty/vulkan"
    env.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include"])

    # Build Vulkan loader library
    env_thirdparty = env.Clone()
    env_thirdparty.disable_warnings()
    vma_sources = [thirdparty_dir + "/vk_mem_alloc.cpp"]

    env_thirdparty.add_source_files(thirdparty_obj, vma_sources)


env.drivers_sources += thirdparty_obj


# Godot source files

driver_obj = []

env.add_source_files(driver_obj, "*.cpp")
env.drivers_sources += driver_obj

# Needed to force rebuilding the driver files when the thirdparty code is updated.
env.Depends(driver_obj, thirdparty_obj)