Meson doesn't allow setting environment variables for custom targets, so
we either need to not pass this as an environment variable or use a
shell script to wrap the invocation. The chosen solution has the
advantage of working for both autotools and meson.

v2: - put rules back in top scope (Ken)

Reviewed-by: Kenneth Graunke <kenn...@whitecape.org>
Signed-off-by: Dylan Baker <dylanx.c.ba...@intel.com>
---
 src/intel/Makefile.compiler.am                 |  2 +-
 src/intel/compiler/brw_nir_trig_workarounds.py | 33 +++++++++++++++++++-------
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/intel/Makefile.compiler.am b/src/intel/Makefile.compiler.am
index 3ab550c96b1..45e7a6ccce8 100644
--- a/src/intel/Makefile.compiler.am
+++ b/src/intel/Makefile.compiler.am
@@ -35,7 +35,7 @@ BUILT_SOURCES += $(COMPILER_GENERATED_FILES)
 compiler/brw_nir_trig_workarounds.c: compiler/brw_nir_trig_workarounds.py \
                                      
$(top_srcdir)/src/compiler/nir/nir_algebraic.py
        $(MKDIR_GEN)
-       $(AM_V_GEN) PYTHONPATH=$(top_srcdir)/src/compiler/nir $(PYTHON2) 
$(PYTHON_FLAGS) $(srcdir)/compiler/brw_nir_trig_workarounds.py > $@ || ($(RM) 
$@; false)
+       $(AM_V_GEN) $(PYTHON2) $(PYTHON_FLAGS) 
$(srcdir)/compiler/brw_nir_trig_workarounds.py -p 
$(top_srcdir)/src/compiler/nir > $@ || ($(RM) $@; false)
 
 EXTRA_DIST += \
        compiler/brw_nir_trig_workarounds.py
diff --git a/src/intel/compiler/brw_nir_trig_workarounds.py 
b/src/intel/compiler/brw_nir_trig_workarounds.py
index 6a77d64dbd4..3d08b9a41ea 100644
--- a/src/intel/compiler/brw_nir_trig_workarounds.py
+++ b/src/intel/compiler/brw_nir_trig_workarounds.py
@@ -20,8 +20,6 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 # IN THE SOFTWARE.
 
-import nir_algebraic
-
 # Prior to Kaby Lake, The SIN and COS instructions on Intel hardware can
 # produce values slightly outside of the [-1.0, 1.0] range for a small set of
 # values.  Obviously, this can break everyone's expectations about trig
@@ -33,11 +31,30 @@ import nir_algebraic
 # amplitude slightly.  Apparently this also minimizes the error function,
 # reducing the maximum error from 0.00006 to about 0.00003.
 
-trig_workarounds = [
-   (('fsin', 'x'), ('fmul', ('fsin', 'x'), 0.99997)),
-   (('fcos', 'x'), ('fmul', ('fcos', 'x'), 0.99997)),
+import argparse
+import sys
+
+TRIG_WORKAROUNDS = [
+    (('fsin', 'x'), ('fmul', ('fsin', 'x'), 0.99997)),
+    (('fcos', 'x'), ('fmul', ('fcos', 'x'), 0.99997)),
 ]
 
-print '#include "brw_nir.h"'
-print nir_algebraic.AlgebraicPass("brw_nir_apply_trig_workarounds",
-                                  trig_workarounds).render()
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-p', '--import-path', required=True)
+    args = parser.parse_args()
+    sys.path.insert(0, args.import_path)
+    run()
+
+
+def run():
+    import nir_algebraic  # pylint: disable=import-error
+
+    print '#include "brw_nir.h"'
+    print nir_algebraic.AlgebraicPass("brw_nir_apply_trig_workarounds",
+                                      TRIG_WORKAROUNDS).render()
+
+
+if __name__ == '__main__':
+    main()
-- 
2.14.1

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to