Merge branch 'master' into vulkan
This commit is contained in:
225
xenia-build
225
xenia-build
@@ -74,7 +74,16 @@ def import_vs_environment():
|
||||
install_path = None
|
||||
env_tool_args = None
|
||||
|
||||
vswhere = subprocess.check_output('third_party/vswhere/vswhere.exe -version "[15,)" -latest -prerelease -format json -utf8', shell=False, universal_newlines=True, encoding="utf-8")
|
||||
vswhere = subprocess.check_output(
|
||||
'third_party/vswhere/vswhere.exe -version "[15,)" -latest -prerelease -format json -utf8 -products '
|
||||
"Microsoft.VisualStudio.Product.Enterprise "
|
||||
"Microsoft.VisualStudio.Product.Professional "
|
||||
"Microsoft.VisualStudio.Product.Community "
|
||||
"Microsoft.VisualStudio.Product.BuildTools",
|
||||
shell=False,
|
||||
universal_newlines=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
if vswhere:
|
||||
vswhere = json.loads(vswhere)
|
||||
if vswhere and len(vswhere) > 0:
|
||||
@@ -85,7 +94,7 @@ def import_vs_environment():
|
||||
if 'VS140COMNTOOLS' in os.environ:
|
||||
version = 2015
|
||||
vcvars_path = os.environ['VS140COMNTOOLS']
|
||||
vcvars_path = os.path.join(tools_path, '..\\..\\vc\\vcvarsall.bat')
|
||||
vcvars_path = os.path.join(vcvars_path, '..\\..\\vc\\vcvarsall.bat')
|
||||
env_tool_args = [vcvars_path, 'x64', '&&', 'set']
|
||||
else:
|
||||
vsdevcmd_path = os.path.join(install_path, 'Common7\\Tools\\VsDevCmd.bat')
|
||||
@@ -252,6 +261,7 @@ def shell_call(command, throw_on_error=True, stdout_path=None, stderr_path=None,
|
||||
def generate_version_h():
|
||||
"""Generates a build/version.h file that contains current git info.
|
||||
"""
|
||||
header_file = 'build/version.h'
|
||||
if git_is_repository():
|
||||
(branch_name, commit, commit_short) = git_get_head_info()
|
||||
else:
|
||||
@@ -259,17 +269,25 @@ def generate_version_h():
|
||||
commit = ':(-dont-do-this'
|
||||
commit_short = ':('
|
||||
|
||||
contents = '''// Autogenerated by `xb premake`.
|
||||
#ifndef GENERATED_VERSION_H_
|
||||
#define GENERATED_VERSION_H_
|
||||
#define XE_BUILD_BRANCH "%s"
|
||||
#define XE_BUILD_COMMIT "%s"
|
||||
#define XE_BUILD_COMMIT_SHORT "%s"
|
||||
#define XE_BUILD_DATE __DATE__
|
||||
#endif // GENERATED_VERSION_H_
|
||||
''' % (branch_name, commit, commit_short)
|
||||
with open('build/version.h', 'w') as f:
|
||||
f.write(contents)
|
||||
contents_new = '''// Autogenerated by `xb premake`.
|
||||
#ifndef GENERATED_VERSION_H_
|
||||
#define GENERATED_VERSION_H_
|
||||
#define XE_BUILD_BRANCH "{}"
|
||||
#define XE_BUILD_COMMIT "{}"
|
||||
#define XE_BUILD_COMMIT_SHORT "{}"
|
||||
#define XE_BUILD_DATE __DATE__
|
||||
#endif // GENERATED_VERSION_H_
|
||||
'''.format(branch_name, commit, commit_short)
|
||||
|
||||
contents_old = None
|
||||
if os.path.exists(header_file) and os.path.getsize(header_file) < 1024:
|
||||
with open(header_file, 'r') as f:
|
||||
contents_old = f.read()
|
||||
|
||||
if contents_old != contents_new:
|
||||
with open(header_file, 'w') as f:
|
||||
f.write(contents_new)
|
||||
|
||||
|
||||
def generate_source_class(path):
|
||||
header_path = '{}.h'.format(path)
|
||||
@@ -285,7 +303,7 @@ def generate_source_class(path):
|
||||
# remove header if source file generation failed
|
||||
os.remove(os.path.join(source_root, header_path))
|
||||
return 1
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
def generate_source_file(path):
|
||||
@@ -309,10 +327,10 @@ def generate_source_file(path):
|
||||
except Exception as e:
|
||||
print('ERROR: Could not write to file [path {}]'.format(path))
|
||||
return 1
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
|
||||
def git_get_head_info():
|
||||
"""Queries the current branch and commit checksum from git.
|
||||
@@ -544,6 +562,7 @@ def discover_commands(subparsers):
|
||||
'pull': PullCommand(subparsers),
|
||||
'premake': PremakeCommand(subparsers),
|
||||
'build': BuildCommand(subparsers),
|
||||
'buildshaders': BuildShadersCommand(subparsers),
|
||||
'devenv': DevenvCommand(subparsers),
|
||||
'genspirv': GenSpirvCommand(subparsers),
|
||||
'gentests': GenTestsCommand(subparsers),
|
||||
@@ -557,8 +576,6 @@ def discover_commands(subparsers):
|
||||
'tidy': TidyCommand(subparsers),
|
||||
'stub': StubCommand(subparsers),
|
||||
}
|
||||
if sys.platform == 'win32':
|
||||
commands['gendxbc'] = GenDxbcCommand(subparsers)
|
||||
return commands
|
||||
|
||||
|
||||
@@ -811,6 +828,84 @@ class BuildCommand(BaseBuildCommand):
|
||||
return result
|
||||
|
||||
|
||||
class BuildShadersCommand(Command):
|
||||
"""'buildshaders' command."""
|
||||
|
||||
def __init__(self, subparsers, *args, **kwargs):
|
||||
super(BuildShadersCommand, self).__init__(
|
||||
subparsers,
|
||||
name='buildshaders',
|
||||
help_short='Generates shader binaries for inclusion in C++ files.',
|
||||
help_long='''
|
||||
Generates the shader binaries under src/*/shaders/bytecode/.
|
||||
Run after modifying any .hs/vs/ds/gs/ps/cs.hlsl files.
|
||||
Direct3D shaders can be built only on a Windows host.
|
||||
''',
|
||||
*args, **kwargs)
|
||||
self.parser.add_argument(
|
||||
'--target', action='append', choices=['dxbc'], default=[],
|
||||
help='Builds only the given target(s).')
|
||||
|
||||
def execute(self, args, pass_args, cwd):
|
||||
src_paths = [os.path.join(root, name)
|
||||
for root, dirs, files in os.walk('src')
|
||||
for name in files
|
||||
if (name.endswith('.hs.hlsl') or
|
||||
name.endswith('.vs.hlsl') or
|
||||
name.endswith('.ds.hlsl') or
|
||||
name.endswith('.gs.hlsl') or
|
||||
name.endswith('.ps.hlsl') or
|
||||
name.endswith('.cs.hlsl'))]
|
||||
targets = args['target']
|
||||
all_targets = len(targets) == 0
|
||||
|
||||
# Direct3D DXBC.
|
||||
if all_targets or 'dxbc' in targets:
|
||||
if sys.platform == 'win32':
|
||||
print('Building Direct3D 12 Shader Model 5.1 DXBC shaders...')
|
||||
windows_sdk_bin_path = os.path.join(
|
||||
os.environ['ProgramFiles(x86)'], 'Windows Kits/10/bin/x64')
|
||||
fxc = os.path.join(windows_sdk_bin_path, 'fxc')
|
||||
# Ensure we have the tools.
|
||||
if not os.path.exists(windows_sdk_bin_path):
|
||||
print('ERROR: could not find Windows 10 SDK binaries')
|
||||
return 1
|
||||
elif not has_bin(fxc):
|
||||
print('ERROR: could not find fxc')
|
||||
return 1
|
||||
# Build DXBC.
|
||||
for src_path in src_paths:
|
||||
print('- %s > d3d12_5_1' % (src_path))
|
||||
dxbc_identifier = \
|
||||
os.path.basename(src_path)[:-5].replace('.', '_')
|
||||
dxbc_dir_path = os.path.join(os.path.dirname(src_path),
|
||||
'bytecode/d3d12_5_1')
|
||||
os.makedirs(dxbc_dir_path, exist_ok=True)
|
||||
dxbc_file_path_base = os.path.join(dxbc_dir_path,
|
||||
dxbc_identifier)
|
||||
if subprocess.call([
|
||||
fxc,
|
||||
'/Fh', dxbc_file_path_base + '.h',
|
||||
'/T', dxbc_identifier[-2:] + '_5_1',
|
||||
'/Vn', dxbc_identifier,
|
||||
'/WX',
|
||||
'/nologo',
|
||||
src_path
|
||||
], stdout=subprocess.DEVNULL):
|
||||
print('ERROR: failed to build a DXBC shader')
|
||||
return 1
|
||||
else:
|
||||
if all_targets:
|
||||
print('WARNING: Direct3D DXBC shader building is supported '
|
||||
'only on Windows')
|
||||
else:
|
||||
print('ERROR: Direct3D DXBC shader building is supported '
|
||||
'only on Windows')
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
class GenSpirvCommand(Command):
|
||||
"""'genspirv' command."""
|
||||
|
||||
@@ -905,96 +1000,6 @@ class GenSpirvCommand(Command):
|
||||
return 0
|
||||
|
||||
|
||||
class GenDxbcCommand(Command):
|
||||
"""'gendxbc' command."""
|
||||
|
||||
def __init__(self, subparsers, *args, **kwargs):
|
||||
super(GenDxbcCommand, self).__init__(
|
||||
subparsers,
|
||||
name='gendxbc',
|
||||
help_short='Generates Direct3D shader binaries and header files.',
|
||||
help_long='''
|
||||
Generates the .cso/.h binaries under src/xenia/*/shaders/bytecode/d3d12_5_1/.
|
||||
Run after modifying any .hs/vs/ds/gs/ps/cs.hlsl files.
|
||||
''',
|
||||
*args, **kwargs)
|
||||
|
||||
def execute(self, args, pass_args, cwd):
|
||||
print('Building Direct3D shaders...')
|
||||
print('')
|
||||
|
||||
windows_sdk_bin_path = os.path.join(os.environ['ProgramFiles(x86)'],
|
||||
'Windows Kits/10/bin/x64')
|
||||
fxc = os.path.join(windows_sdk_bin_path, 'fxc')
|
||||
|
||||
# Ensure we have the tools.
|
||||
if not os.path.exists(windows_sdk_bin_path):
|
||||
print('ERROR: could not find Windows 10 SDK binaries')
|
||||
return 1
|
||||
elif not has_bin(fxc):
|
||||
print('ERROR: could not find fxc')
|
||||
return 1
|
||||
|
||||
src_files = [os.path.join(root, name)
|
||||
for root, dirs, files in os.walk('src')
|
||||
for name in files
|
||||
if (name.endswith('.hs.hlsl') or
|
||||
name.endswith('.vs.hlsl') or
|
||||
name.endswith('.ds.hlsl') or
|
||||
name.endswith('.gs.hlsl') or
|
||||
name.endswith('.ps.hlsl') or
|
||||
name.endswith('.cs.hlsl'))]
|
||||
|
||||
# TODO(Triang3l): Handle any_errors.
|
||||
any_errors = False
|
||||
for src_file in src_files:
|
||||
print('- %s' % (src_file))
|
||||
src_name = os.path.splitext(os.path.basename(src_file))[0]
|
||||
identifier = os.path.basename(src_file)[:-5].replace('.', '_')
|
||||
|
||||
bin_path = os.path.join(os.path.dirname(src_file),
|
||||
'bytecode/d3d12_5_1')
|
||||
if not os.path.exists(bin_path):
|
||||
os.mkdir(bin_path)
|
||||
cso_file = os.path.join(bin_path, identifier) + '.cso'
|
||||
txt_file = os.path.join(bin_path, identifier) + '.txt'
|
||||
h_file = os.path.join(bin_path, identifier) + '.h'
|
||||
|
||||
# HLSL source -> .cso binary and DXBC disassembly.
|
||||
shell_call([
|
||||
fxc,
|
||||
'/nologo',
|
||||
'/T', identifier[-2:] + '_5_1',
|
||||
'/Fo', cso_file,
|
||||
'/Fc', txt_file,
|
||||
src_file,
|
||||
])
|
||||
|
||||
# bin2c so we get a header file we can compile in.
|
||||
with open(h_file, 'w') as out_file:
|
||||
out_file.write('// generated from `xb gendxbc`\n')
|
||||
out_file.write('// source: %s\n' % os.path.basename(src_file))
|
||||
out_file.write('const uint8_t %s[] = {' % (identifier))
|
||||
with open(cso_file, 'rb') as in_file:
|
||||
index = 0
|
||||
c = in_file.read(1)
|
||||
while len(c) != 0:
|
||||
if index % 12 == 0:
|
||||
out_file.write('\n ')
|
||||
else:
|
||||
out_file.write(' ')
|
||||
index += 1
|
||||
out_file.write('0x%02X,' % ord(c))
|
||||
c = in_file.read(1)
|
||||
out_file.write('\n};\n')
|
||||
|
||||
if any_errors:
|
||||
print('ERROR: failed to build one or more shaders.')
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
class TestCommand(BaseBuildCommand):
|
||||
"""'test' command."""
|
||||
|
||||
@@ -1612,7 +1617,7 @@ class StubCommand(Command):
|
||||
status = generate_source_class(path)
|
||||
if status > 0:
|
||||
return status
|
||||
|
||||
|
||||
print('Created class \'{0}\' at {1}'.format(class_name, target_dir))
|
||||
|
||||
elif args['file']:
|
||||
@@ -1623,7 +1628,7 @@ class StubCommand(Command):
|
||||
status = generate_source_file(path)
|
||||
if status > 0:
|
||||
return status
|
||||
|
||||
|
||||
print('Created file \'{0}\' at {1}'.format(file_name, target_dir))
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user