Bug 1370007 Generate Shaders on a MinGW Cross Compile on Linux draft
authorTom Ritter <tom@mozilla.com>
Mon, 24 Jul 2017 14:32:08 -0500
changeset 614562 23eeba0374dbf27ce8d2b9b24566f02add845a62
parent 614544 462d7561089c98e33382384896434861ad7bc491
child 638904 fbc0d73e6562b8e8db2ea6ef2986e7675b1f040f
push id70053
push userbmo:tom@mozilla.com
push dateMon, 24 Jul 2017 19:32:36 +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
@@ -1042,16 +1042,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