mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-22 11:20:11 +01:00
nir: add pass to lower discard() to demote()
This pass is intended to work around game bugs, only! It also lowers nir_intrinsic_load_helper_invocation to nir_intrinsic_is_helper_invocation for consistency. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4047>
This commit is contained in:
parent
5adcfa68a9
commit
ce87da71e9
4 changed files with 73 additions and 0 deletions
|
|
@ -245,6 +245,7 @@ NIR_FILES = \
|
|||
nir/nir_lower_clip_cull_distance_arrays.c \
|
||||
nir/nir_lower_clip_halfz.c \
|
||||
nir/nir_lower_variable_initializers.c \
|
||||
nir/nir_lower_discard_to_demote.c \
|
||||
nir/nir_lower_double_ops.c \
|
||||
nir/nir_lower_drawpixels.c \
|
||||
nir/nir_lower_fb_read.c \
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ files_libnir = files(
|
|||
'nir_lower_clip_cull_distance_arrays.c',
|
||||
'nir_lower_clip_halfz.c',
|
||||
'nir_lower_variable_initializers.c',
|
||||
'nir_lower_discard_to_demote.c',
|
||||
'nir_lower_double_ops.c',
|
||||
'nir_lower_drawpixels.c',
|
||||
'nir_lower_fb_read.c',
|
||||
|
|
|
|||
|
|
@ -4197,6 +4197,8 @@ typedef enum {
|
|||
bool nir_lower_interpolation(nir_shader *shader,
|
||||
nir_lower_interpolation_options options);
|
||||
|
||||
bool nir_lower_discard_to_demote(nir_shader *shader);
|
||||
|
||||
bool nir_normalize_cubemap_coords(nir_shader *shader);
|
||||
|
||||
void nir_live_ssa_defs_impl(nir_function_impl *impl);
|
||||
|
|
|
|||
69
src/compiler/nir/nir_lower_discard_to_demote.c
Normal file
69
src/compiler/nir/nir_lower_discard_to_demote.c
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright © 2020 Valve 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nir.h"
|
||||
|
||||
/**
|
||||
* This pass is intended as workaround for game bugs to force correct
|
||||
* derivatives after kill. This lowering is not valid in the general case
|
||||
* as it might change the result of subgroup operations and loop behavior.
|
||||
*
|
||||
* discard() will be lowered as demote() and gl_HelperInvocation
|
||||
* will be lowered as helperInvocationEXT().
|
||||
*/
|
||||
bool
|
||||
nir_lower_discard_to_demote(nir_shader *shader)
|
||||
{
|
||||
if (shader->info.stage != MESA_SHADER_FRAGMENT)
|
||||
return false;
|
||||
|
||||
bool progress = false;
|
||||
|
||||
nir_foreach_function(function, shader) {
|
||||
nir_foreach_block(block, function->impl) {
|
||||
nir_foreach_instr(instr, block) {
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
continue;
|
||||
|
||||
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
|
||||
switch (intrin->intrinsic) {
|
||||
case nir_intrinsic_discard:
|
||||
intrin->intrinsic = nir_intrinsic_demote;
|
||||
break;
|
||||
case nir_intrinsic_discard_if:
|
||||
intrin->intrinsic = nir_intrinsic_demote_if;
|
||||
break;
|
||||
case nir_intrinsic_load_helper_invocation:
|
||||
intrin->intrinsic = nir_intrinsic_is_helper_invocation;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
progress = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue