Bug 1370007 Generate Shaders on a MinGW Cross Compile on Linux draft
authorTom Ritter <tom@mozilla.com>
Fri, 07 Jul 2017 16:10:15 -0500
changeset 605514 7da381f696e0440950c65e57121d0d613c8b265a
parent 599048 2403cb851fe3e56b9018eaa645c78e913d927812
child 605520 9b368f8677ecf8066f5b6f00363fa7e9d9457a54
child 605529 1ee141aab4ce25cc4b814c341a0b9febdbe8e0f6
child 605655 e66957a7cf432350e3fe730cca5dbe07e9711a4d
child 605710 ee59df726cb659df22e86bdccbf5f286edb4ae94
child 605770 3405616ad14b1fb81f237323a3908990063f2127
push id67433
push userbmo:tom@mozilla.com
push dateFri, 07 Jul 2017 21:11:00 +0000
bugs1370007, 1365859
milestone56.0a1
Bug 1370007 Generate Shaders on a MinGW Cross Compile on Linux Bug 1365859 introduced a dependency on the Visual Studio binary 'fxc' to generate Shader bytecode. This was unavailable when compiling for Windows on Linux as part of a MinGW build. This commit adds a configure check for fxc, and also searches for fxc2, which was written (https://github.com/tomrittervg/fxc2) to be a tiny application that wraps D3DCompileFromFile and can produce similar (but not exactly the same) output as fxc. fxc2 is compiled using MinGW for Windows, and runs under wine, so we need to check for wine also. Finally, fxc outputs some include information fxc2 doesn't, so we will just change that assert to not take effect. MozReview-Commit-ID: 8LVxuODi6cV
build/moz.configure/toolchain.configure
gfx/layers/d3d11/genshaders.py
gfx/layers/moz.build
old mode 100644
new mode 100755
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1023,16 +1023,24 @@ set_config('VISIBILITY_FLAGS', visibilit
 # We only want to include windows.configure when we are compiling on
 # Windows, for Windows.
 @depends(target, host)
 def is_windows(target, host):
     return host.kernel == 'WINNT' and target.kernel == 'WINNT'
 
 include('windows.configure', when=is_windows)
 
+# Shader Compiler for Windows (and MinGW Cross Compile)
+# ==============================================================
+
+fxc = check_prog('FXC', ('fxc.exe', 'fxc2.exe'), when=depends(target)
+                 (lambda t: t.kernel == 'WINNT'))
+wine = check_prog('WINE', ['wine'], when=depends(target, host)
+                  (lambda t, h: t.kernel == 'WINNT' and h.kernel == 'Linux'))
+
 # Security Hardening
 # ==============================================================
 
 option('--enable-hardening', env='MOZ_SECURITY_HARDENING',
        help='Enables security hardening compiler options')
 
 @depends('--enable-hardening', c_compiler)
 def security_hardening_cflags(value, c_compiler):
old mode 100644
new mode 100755
--- a/gfx/layers/d3d11/genshaders.py
+++ b/gfx/layers/d3d11/genshaders.py
@@ -5,16 +5,17 @@ import argparse
 import codecs
 import locale
 import os
 import re
 import subprocess
 import sys
 import tempfile
 import yaml
+import buildconfig
 
 def shell_main():
   parser = argparse.ArgumentParser()
   parser.add_argument('-o', '--output', type=str, required=True,
                       help='Output file')
   parser.add_argument('manifest', type=str,
                       help='Manifest source file')
   args = parser.parse_args()
@@ -65,39 +66,43 @@ def process_manifest(output_fp, manifest
 
   output_fp.write(FOOTER)
   return deps
 
 def run_fxc(shader_model,
             shader_file,
             shader_name,
             output_fp):
+  fxc_location = buildconfig.substs['FXC']
+
   argv = [
-    'fxc',
+    fxc_location,
     '-nologo',
     '-T{0}'.format(shader_model),
     shader_file,
     '-E{0}'.format(shader_name),
     '-Vn{0}'.format(shader_name),
     '-Vi',
   ]
+  if 'Linux' in buildconfig.substs['HOST_OS_ARCH']:
+    argv.insert(0, buildconfig.substs['WINE'])
   if shader_model.startswith('vs_'):
     argv += ['-DVERTEX_SHADER']
   elif shader_model.startswith('ps_'):
     argv += ['-DPIXEL_SHADER']
 
   deps = None
   with ScopedTempFilename() as temp_filename:
     argv += ['-Fh{0}'.format(temp_filename)]
 
     sys.stdout.write('{0}\n'.format(' '.join(argv)))
     proc_stdout = subprocess.check_output(argv)
     proc_stdout = decode_console_text(sys.stdout, proc_stdout)
     deps = find_dependencies(proc_stdout)
-    assert len(deps) > 0
+    assert 'fxc2' in fxc_location or len(deps) > 0
 
     with open(temp_filename, 'r') as temp_fp:
       output_fp.write(temp_fp.read())
 
   output_fp.write("ShaderBytes s{0} = {{ {0}, sizeof({0}) }};\n".format(
     shader_name))
   return deps
 
old mode 100644
new mode 100755