| 1 |
|
| 2 |
from misc.utility.scons_hints import * |
| 3 |
|
| 4 |
import os |
| 5 |
import re |
| 6 |
import sys |
| 7 |
from pathlib import Path |
| 8 |
|
| 9 |
import methods |
| 10 |
from methods import print_error |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
req_version_major = 25 |
| 15 |
req_version_minor = 3 |
| 16 |
|
| 17 |
Import("env") |
| 18 |
env_d3d12_rdd = env.Clone() |
| 19 |
|
| 20 |
|
| 21 |
if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]): |
| 22 |
env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_ENABLED"]) |
| 23 |
if env["agility_sdk_multiarch"]: |
| 24 |
env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_MULTIARCH_ENABLED"]) |
| 25 |
|
| 26 |
|
| 27 |
if env["use_pix"]: |
| 28 |
env_d3d12_rdd.Append(CPPDEFINES=["PIX_ENABLED"]) |
| 29 |
env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"]) |
| 30 |
|
| 31 |
|
| 32 |
if "dcomp" in env.get("supported", []): |
| 33 |
env_d3d12_rdd.Append(CPPDEFINES=["DCOMP_ENABLED"]) |
| 34 |
env.Append(CPPDEFINES=["DCOMP_ENABLED"]) |
| 35 |
|
| 36 |
|
| 37 |
mesa_libs = env["mesa_libs"] |
| 38 |
if env.msvc and os.path.exists(env["mesa_libs"] + "-" + env["arch"] + "-msvc"): |
| 39 |
mesa_libs = env["mesa_libs"] + "-" + env["arch"] + "-msvc" |
| 40 |
elif env["use_llvm"] and os.path.exists(env["mesa_libs"] + "-" + env["arch"] + "-llvm"): |
| 41 |
mesa_libs = env["mesa_libs"] + "-" + env["arch"] + "-llvm" |
| 42 |
elif not env["use_llvm"] and os.path.exists(env["mesa_libs"] + "-" + env["arch"] + "-gcc"): |
| 43 |
mesa_libs = env["mesa_libs"] + "-" + env["arch"] + "-gcc" |
| 44 |
|
| 45 |
mesa_dir = (mesa_libs + "/godot-mesa").replace("\\", "/") |
| 46 |
mesa_gen_dir = (mesa_libs + "/godot-mesa/generated").replace("\\", "/") |
| 47 |
mesa_absdir = Dir(mesa_dir).abspath |
| 48 |
mesa_gen_absdir = Dir(mesa_dir + "/generated").abspath |
| 49 |
|
| 50 |
custom_build_steps = [ |
| 51 |
[ |
| 52 |
"src/compiler", |
| 53 |
"glsl/ir_expression_operation.py enum > %s/ir_expression_operation.h", |
| 54 |
"ir_expression_operation.h", |
| 55 |
], |
| 56 |
["src/compiler/nir", "nir_builder_opcodes_h.py > %s/nir_builder_opcodes.h", "nir_builder_opcodes.h"], |
| 57 |
["src/compiler/nir", "nir_constant_expressions.py > %s/nir_constant_expressions.c", "nir_constant_expressions.c"], |
| 58 |
["src/compiler/nir", "nir_intrinsics_h.py --outdir %s", "nir_intrinsics.h"], |
| 59 |
["src/compiler/nir", "nir_intrinsics_c.py --outdir %s", "nir_intrinsics.c"], |
| 60 |
["src/compiler/nir", "nir_intrinsics_indices_h.py --outdir %s", "nir_intrinsics_indices.h"], |
| 61 |
["src/compiler/nir", "nir_opcodes_h.py > %s/nir_opcodes.h", "nir_opcodes.h"], |
| 62 |
["src/compiler/nir", "nir_opcodes_c.py > %s/nir_opcodes.c", "nir_opcodes.c"], |
| 63 |
["src/compiler/nir", "nir_opt_algebraic.py > %s/nir_opt_algebraic.c", "nir_opt_algebraic.c"], |
| 64 |
["src/compiler/spirv", "vtn_generator_ids_h.py spir-v.xml %s/vtn_generator_ids.h", "vtn_generator_ids.h"], |
| 65 |
[ |
| 66 |
"src/microsoft/compiler", |
| 67 |
"dxil_nir_algebraic.py -p ../../../src/compiler/nir > %s/dxil_nir_algebraic.c", |
| 68 |
"dxil_nir_algebraic.c", |
| 69 |
], |
| 70 |
["src/util", "format_srgb.py > %s/format_srgb.c", "format_srgb.c"], |
| 71 |
["src/util/format", "u_format_table.py u_format.csv --header > %s/u_format_pack.h", "u_format_pack.h"], |
| 72 |
["src/util/format", "u_format_table.py u_format.csv > %s/u_format_table.c", "u_format_table.c"], |
| 73 |
] |
| 74 |
|
| 75 |
mesa_gen_include_paths = [mesa_gen_dir + "/src"] |
| 76 |
|
| 77 |
|
| 78 |
for v in custom_build_steps: |
| 79 |
subdir = v[0] |
| 80 |
cmd = v[1] |
| 81 |
gen_filename = v[2] |
| 82 |
|
| 83 |
in_dir = str(Path(mesa_absdir + "/" + subdir)) |
| 84 |
out_full_path = mesa_dir + "/generated/" + subdir |
| 85 |
out_file_full_path = out_full_path + "/" + gen_filename |
| 86 |
|
| 87 |
if gen_filename.endswith(".h"): |
| 88 |
mesa_gen_include_paths += [out_full_path.replace("\\", "/")] |
| 89 |
|
| 90 |
mesa_private_inc_paths = [v[0] for v in os.walk(mesa_absdir)] |
| 91 |
mesa_private_inc_paths = [v.replace(mesa_absdir, mesa_dir) for v in mesa_private_inc_paths] |
| 92 |
mesa_private_inc_paths = [v.replace("\\", "/") for v in mesa_private_inc_paths] |
| 93 |
|
| 94 |
mesa_private_inc_paths = [v for v in mesa_private_inc_paths if not v.startswith(mesa_gen_dir)] |
| 95 |
mesa_private_inc_paths.sort() |
| 96 |
|
| 97 |
mesa_private_inc_paths += mesa_gen_include_paths |
| 98 |
|
| 99 |
|
| 100 |
mesa_blacklist_inc_paths = [ |
| 101 |
"src/c11", |
| 102 |
] |
| 103 |
mesa_blacklist_inc_paths = [mesa_dir + "/" + v for v in mesa_blacklist_inc_paths] |
| 104 |
mesa_private_inc_paths = [v for v in mesa_private_inc_paths if v not in mesa_blacklist_inc_paths] |
| 105 |
|
| 106 |
|
| 107 |
extra_defines = [ |
| 108 |
"WINDOWS_NO_FUTEX", |
| 109 |
] |
| 110 |
|
| 111 |
mesa_ver = Path(mesa_absdir + "/VERSION.info") |
| 112 |
if not mesa_ver.is_file(): |
| 113 |
mesa_ver = Path(mesa_absdir + "/VERSION") |
| 114 |
|
| 115 |
match = re.match(r"([0-9]*).([0-9]*).([0-9]*)-?([0-9.+]*)", mesa_ver.read_text().strip()) |
| 116 |
if ( |
| 117 |
match is None |
| 118 |
or int(match.group(1)) != req_version_major |
| 119 |
or (int(match.group(1)) == req_version_major and int(match.group(2)) < req_version_minor) |
| 120 |
): |
| 121 |
print_error( |
| 122 |
"The Direct3D 12 rendering driver dependencies are outdated or missing.\n" |
| 123 |
"You can re-install them by running `python misc\\scripts\\install_d3d12_sdk_windows.py`.\n" |
| 124 |
) |
| 125 |
sys.exit(255) |
| 126 |
|
| 127 |
|
| 128 |
extra_defines += [ |
| 129 |
"__STDC_CONSTANT_MACROS", |
| 130 |
"__STDC_FORMAT_MACROS", |
| 131 |
"__STDC_LIMIT_MACROS", |
| 132 |
("PACKAGE_VERSION", '\\"' + mesa_ver.read_text().strip() + '\\"'), |
| 133 |
("PACKAGE_BUGREPORT", '\\"https://gitlab.freedesktop.org/mesa/mesa/-/issues\\"'), |
| 134 |
"PIPE_SUBSYSTEM_WINDOWS_USER", |
| 135 |
("_Static_assert", "static_assert"), |
| 136 |
"HAVE_STRUCT_TIMESPEC", |
| 137 |
] |
| 138 |
|
| 139 |
if env.msvc: |
| 140 |
extra_defines += [ |
| 141 |
"_USE_MATH_DEFINES", |
| 142 |
"VC_EXTRALEAN", |
| 143 |
"_CRT_SECURE_NO_WARNINGS", |
| 144 |
"_CRT_SECURE_NO_DEPRECATE", |
| 145 |
"_SCL_SECURE_NO_WARNINGS", |
| 146 |
"_SCL_SECURE_NO_DEPRECATE", |
| 147 |
"_ALLOW_KEYWORD_MACROS", |
| 148 |
"NOMINMAX", |
| 149 |
] |
| 150 |
else: |
| 151 |
extra_defines += [ |
| 152 |
|
| 153 |
("__REQUIRED_RPCNDR_H_VERSION__", 475), |
| 154 |
] |
| 155 |
if methods.using_gcc(env) and methods.get_compiler_version(env)["major"] < 13: |
| 156 |
|
| 157 |
env_d3d12_rdd.Append(CCFLAGS=["-Wno-unknown-pragmas"]) |
| 158 |
|
| 159 |
|
| 160 |
env_d3d12_rdd.Prepend(CPPPATH=mesa_private_inc_paths) |
| 161 |
|
| 162 |
env_d3d12_rdd.Append(CPPDEFINES=extra_defines) |
| 163 |
|
| 164 |
|
| 165 |
thirdparty_obj = [] |
| 166 |
|
| 167 |
env_thirdparty = env_d3d12_rdd.Clone() |
| 168 |
env_thirdparty.disable_warnings() |
| 169 |
|
| 170 |
env_thirdparty.Prepend( |
| 171 |
CPPPATH=[ |
| 172 |
"#thirdparty/directx_headers/include/directx", |
| 173 |
"#thirdparty/directx_headers/include/dxguids", |
| 174 |
"#thirdparty/d3d12ma", |
| 175 |
] |
| 176 |
) |
| 177 |
|
| 178 |
env_thirdparty.add_source_files(thirdparty_obj, "#thirdparty/d3d12ma/D3D12MemAlloc.cpp") |
| 179 |
env.drivers_sources += thirdparty_obj |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
driver_obj = [] |
| 184 |
env_d3d12_rdd.add_source_files(driver_obj, "*.cpp") |
| 185 |
env.drivers_sources += driver_obj |
| 186 |
|
| 187 |
|
| 188 |
env.Depends(driver_obj, thirdparty_obj) |