nir: add a pass to lower flat shading.
authorDave Airlie <airlied@redhat.com>
Thu, 24 Jan 2019 03:07:42 +0000 (13:07 +1000)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 17 Oct 2019 08:41:36 +0000 (10:41 +0200)
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>
src/compiler/Makefile.sources
src/compiler/nir/meson.build
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_flatshade.c [new file with mode: 0644]

index b6429366b052c157871be928459ccf7905c88fe8..f54de56e8e6f031924e667c4ab030b52e9242567 100644 (file)
@@ -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 \
index d18c683eb0ca0b581f31dbf0bbe73a9a7ce87d50..b6e8ea0878efe7bb5e10b389e7ab03382b542641 100644 (file)
@@ -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',
index 960184b7f3c1e6a7b4708fb186a675d7679dbe13..fd7f3635cbee75266b39457ee0b82507eb38a6e0 100644 (file)
@@ -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 (file)
index 0000000..8185784
--- /dev/null
@@ -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;
+}