Commit 4610e5ef authored by Rob Clark's avatar Rob Clark

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: 's avatarRob Clark <robclark@freedesktop.org>
parent 21b4bcdd
#
# Copyright (C) 2016 Linaro, Ltd., Rob Herring <robh@kernel.org>
#
# 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))
......@@ -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)
......@@ -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
......
......@@ -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
......@@ -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);
......
......@@ -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);
......
#! /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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment