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>
This commit is contained in:
Dave Airlie
2019-01-24 13:07:42 +10:00
committed by Erik Faye-Lund
parent 26c6640835
commit dc91a02a72
4 changed files with 54 additions and 0 deletions

View 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 \

View 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',

View 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);

View File

@@ -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;
}