summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2019-01-24 13:07:42 +1000
committerErik Faye-Lund <erik.faye-lund@collabora.com>2019-10-17 10:41:36 +0200
commitdc91a02a72cd677b132c00b1fae2aeffefa1de1c (patch)
tree3f63a418d1f96a2afee5defdc75def1960e5a0c6
parent26c6640835936a77d87030ce8e90f9b9f5be783e (diff)
nir: add a pass to lower flat shading.
This takes any color or backcolor that has unspecified shading and converts it to flat shading. Reviewed-by: Marek Olšák <marek.olsak@amd.com>
-rw-r--r--src/compiler/Makefile.sources1
-rw-r--r--src/compiler/nir/meson.build1
-rw-r--r--src/compiler/nir/nir.h2
-rw-r--r--src/compiler/nir/nir_lower_flatshade.c50
4 files changed, 54 insertions, 0 deletions
diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
index b6429366b05..f54de56e8e6 100644
--- a/src/compiler/Makefile.sources
+++ b/src/compiler/Makefile.sources
@@ -245,6 +245,7 @@ NIR_FILES = \
nir/nir_lower_double_ops.c \
nir/nir_lower_drawpixels.c \
nir/nir_lower_fb_read.c \
+ nir/nir_lower_flatshade.c \
nir/nir_lower_flrp.c \
nir/nir_lower_fragcoord_wtrans.c \
nir/nir_lower_frexp.c \
diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build
index d18c683eb0c..b6e8ea0878e 100644
--- a/src/compiler/nir/meson.build
+++ b/src/compiler/nir/meson.build
@@ -126,6 +126,7 @@ files_libnir = files(
'nir_lower_double_ops.c',
'nir_lower_drawpixels.c',
'nir_lower_fb_read.c',
+ 'nir_lower_flatshade.c',
'nir_lower_flrp.c',
'nir_lower_fragcoord_wtrans.c',
'nir_lower_frexp.c',
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 960184b7f3c..fd7f3635cbe 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -3916,6 +3916,8 @@ void nir_lower_two_sided_color(nir_shader *shader);
bool nir_lower_clamp_color_outputs(nir_shader *shader);
+bool nir_lower_flatshade(nir_shader *shader);
+
void nir_lower_passthrough_edgeflags(nir_shader *shader);
bool nir_lower_patch_vertices(nir_shader *nir, unsigned static_count,
const gl_state_index16 *uniform_state_tokens);
diff --git a/src/compiler/nir/nir_lower_flatshade.c b/src/compiler/nir/nir_lower_flatshade.c
new file mode 100644
index 00000000000..81857847398
--- /dev/null
+++ b/src/compiler/nir/nir_lower_flatshade.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2015 Red Hat
+ *
+ * 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.
+ */
+
+
+#include "nir.h"
+#include "nir_builder.h"
+
+static bool
+lower_input(nir_shader *shader, nir_variable *var)
+{
+ if (var->data.interpolation == INTERP_MODE_NONE &&
+ (var->data.location == VARYING_SLOT_COL0 ||
+ var->data.location == VARYING_SLOT_COL1 ||
+ var->data.location == VARYING_SLOT_BFC0 ||
+ var->data.location == VARYING_SLOT_BFC1))
+ var->data.interpolation = INTERP_MODE_FLAT;
+ return true;
+}
+
+bool
+nir_lower_flatshade(nir_shader *shader)
+{
+ bool progress = false;
+
+ nir_foreach_variable(var, &shader->inputs) {
+ progress |= lower_input(shader, var);
+ }
+
+ return progress;
+}