From: Rob Clark Date: Sat, 23 Apr 2016 13:03:28 +0000 (-0400) Subject: freedreno/ir3: fix sin/cos X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4610e5ef28e4f209617c3cabf5a2dd699e52cc33;p=mesa.git freedreno/ir3: fix sin/cos We seem to need range reduction to get sane results. Fixes glmark2 jellyfish bench, and a whole bunch of dEQP-GLES3.functional.shaders.builtin_functions.precision.{sin,cos,tan}.* v2: squashed in android build fixes from Rob Herring Signed-off-by: Rob Clark --- diff --git a/src/gallium/drivers/freedreno/.gitignore b/src/gallium/drivers/freedreno/.gitignore index 150f5d19f5b..174165ee592 100644 --- a/src/gallium/drivers/freedreno/.gitignore +++ b/src/gallium/drivers/freedreno/.gitignore @@ -1 +1,2 @@ ir3_compiler +ir3_nir_trig.c diff --git a/src/gallium/drivers/freedreno/Android.gen.mk b/src/gallium/drivers/freedreno/Android.gen.mk new file mode 100644 index 00000000000..072cf998aed --- /dev/null +++ b/src/gallium/drivers/freedreno/Android.gen.mk @@ -0,0 +1,38 @@ +# +# Copyright (C) 2016 Linaro, Ltd., Rob Herring +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +ifeq ($(LOCAL_MODULE_CLASS),) +LOCAL_MODULE_CLASS := STATIC_LIBRARIES +endif + +ir3_nir_trig_deps := \ + $(LOCAL_PATH)/ir3/ir3_nir_trig.py \ + $(MESA_TOP)/src/compiler/nir/nir_algebraic.py + +intermediates := $(call local-generated-sources-dir) + +$(intermediates)/ir3/ir3_nir_trig.c: $(ir3_nir_trig_deps) + @mkdir -p $(dir $@) + $(hide) PYTHONPATH=$(MESA_TOP)/src/compiler/nir $(MESA_PYTHON2) $< > $@ + +LOCAL_GENERATED_SOURCES += $(addprefix $(intermediates)/, \ + $(ir3_GENERATED_FILES)) diff --git a/src/gallium/drivers/freedreno/Android.mk b/src/gallium/drivers/freedreno/Android.mk index d25adb467e5..f630dc175f0 100644 --- a/src/gallium/drivers/freedreno/Android.mk +++ b/src/gallium/drivers/freedreno/Android.mk @@ -44,5 +44,6 @@ LOCAL_SHARED_LIBRARIES := libdrm libdrm_freedreno LOCAL_STATIC_LIBRARIES := libmesa_glsl libmesa_nir LOCAL_MODULE := libmesa_pipe_freedreno +include $(LOCAL_PATH)/Android.gen.mk include $(GALLIUM_COMMON_MK) include $(BUILD_STATIC_LIBRARY) diff --git a/src/gallium/drivers/freedreno/Makefile.am b/src/gallium/drivers/freedreno/Makefile.am index 329a4204c3a..9c0ccdf1eca 100644 --- a/src/gallium/drivers/freedreno/Makefile.am +++ b/src/gallium/drivers/freedreno/Makefile.am @@ -5,9 +5,14 @@ AM_CFLAGS = \ -Wno-packed-bitfield-compat \ -I$(top_srcdir)/src/gallium/drivers/freedreno/ir3 \ -I$(top_builddir)/src/compiler/nir \ + -I$(top_srcdir)/src/compiler/nir \ $(GALLIUM_DRIVER_CFLAGS) \ $(FREEDRENO_CFLAGS) +ir3/ir3_nir_trig.c: ir3/ir3_nir_trig.py $(top_srcdir)/src/compiler/nir/nir_algebraic.py + $(MKDIR_GEN) + $(AM_V_GEN) PYTHONPATH=$(top_srcdir)/src/compiler/nir $(PYTHON2) $(PYTHON_FLAGS) $(srcdir)/ir3/ir3_nir_trig.py > $@ || ($(RM) $@; false) + noinst_LTLIBRARIES = libfreedreno.la libfreedreno_la_SOURCES = \ @@ -15,7 +20,11 @@ libfreedreno_la_SOURCES = \ $(a2xx_SOURCES) \ $(a3xx_SOURCES) \ $(a4xx_SOURCES) \ - $(ir3_SOURCES) + $(ir3_SOURCES) \ + $(ir3_GENERATED_FILES) + +BUILT_SOURCES := $(ir3_GENERATED_FILES) +CLEANFILES := $(BUILT_SOURCES) noinst_PROGRAMS = ir3_compiler diff --git a/src/gallium/drivers/freedreno/Makefile.sources b/src/gallium/drivers/freedreno/Makefile.sources index 74ef4168655..edba36999e2 100644 --- a/src/gallium/drivers/freedreno/Makefile.sources +++ b/src/gallium/drivers/freedreno/Makefile.sources @@ -136,3 +136,6 @@ ir3_SOURCES := \ ir3/ir3_sched.c \ ir3/ir3_shader.c \ ir3/ir3_shader.h + +ir3_GENERATED_FILES := \ + ir3/ir3_nir_trig.c diff --git a/src/gallium/drivers/freedreno/ir3/ir3_nir.c b/src/gallium/drivers/freedreno/ir3/ir3_nir.c index 897b3b963be..d3ee2a7f74b 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_nir.c +++ b/src/gallium/drivers/freedreno/ir3/ir3_nir.c @@ -120,6 +120,11 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s, if (key->color_two_side) { OPT_V(s, nir_lower_two_sided_color); } + } else { + /* only want to do this the first time (when key is null) + * and not again on any potential 2nd variant lowering pass: + */ + OPT_V(s, ir3_nir_apply_trig_workarounds); } OPT_V(s, nir_lower_tex, &tex_options); diff --git a/src/gallium/drivers/freedreno/ir3/ir3_nir.h b/src/gallium/drivers/freedreno/ir3/ir3_nir.h index e2d88596094..a2cf3478936 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_nir.h +++ b/src/gallium/drivers/freedreno/ir3/ir3_nir.h @@ -35,6 +35,7 @@ #include "ir3_shader.h" bool ir3_nir_lower_if_else(nir_shader *shader); +bool ir3_nir_apply_trig_workarounds(nir_shader *shader); struct nir_shader * ir3_tgsi_to_nir(const struct tgsi_token *tokens); bool ir3_key_lowers_nir(const struct ir3_shader_key *key); diff --git a/src/gallium/drivers/freedreno/ir3/ir3_nir_trig.py b/src/gallium/drivers/freedreno/ir3/ir3_nir_trig.py new file mode 100755 index 00000000000..f49bccee019 --- /dev/null +++ b/src/gallium/drivers/freedreno/ir3/ir3_nir_trig.py @@ -0,0 +1,33 @@ +#! /usr/bin/env python +# +# Copyright (C) 2016 Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +import nir_algebraic + +trig_workarounds = [ + (('fsin', 'x'), ('fsin', ('fsub', ('fmul', 6.283185, ('ffract', ('fadd', ('fmul', 0.159155, 'x'), 0.5))), 3.141593))), + (('fcos', 'x'), ('fcos', ('fsub', ('fmul', 6.283185, ('ffract', ('fadd', ('fmul', 0.159155, 'x'), 0.5))), 3.141593))), +] + +print '#include "ir3_nir.h"' +print nir_algebraic.AlgebraicPass("ir3_nir_apply_trig_workarounds", + trig_workarounds).render()