diff options
author | Dave Airlie <[email protected]> | 2019-01-24 13:07:42 +1000 |
---|---|---|
committer | Erik Faye-Lund <[email protected]> | 2019-10-17 10:41:36 +0200 |
commit | dc91a02a72cd677b132c00b1fae2aeffefa1de1c (patch) | |
tree | 3f63a418d1f96a2afee5defdc75def1960e5a0c6 /src/compiler/nir/nir_lower_flatshade.c | |
parent | 26c6640835936a77d87030ce8e90f9b9f5be783e (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 <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_lower_flatshade.c')
-rw-r--r-- | src/compiler/nir/nir_lower_flatshade.c | 50 |
1 files changed, 50 insertions, 0 deletions
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; +} |