On Wed, Jul 4, 2018 at 9:59 AM Jason Ekstrand <ja...@jlekstrand.net> wrote: > > Many fragment shaders do a discard using relatively little information > but still put the discard fairly far down in the shader for no good > reason. If the discard is moved higher up, we can possibly avoid doing > some or almost all of the work in the shader. When this lets us skip > texturing operations, it's an especially high win. > > One of the biggest offenders here is DXVK. The D3D APIs have different > rules for discards than OpenGL and Vulkan. One effective way (which is > what DXVK uses) to implement DX behavior on top of GL or Vulkan is to > wait until the very end of the shader to discard. This ends up in the > pessimal case where we always do all of the work before discarding. > This pass helps some DXVK shaders significantly. > > v2 (Jason Ekstrand): > - Fix a couple of typos (Grazvydas, Ian) > - Use the new nir_instr_move helper > - Find all movable discards before moving anything so we don't > accidentally re-order anything and break dependencies > --- > src/compiler/Makefile.sources | 1 + > src/compiler/nir/meson.build | 1 + > src/compiler/nir/nir.h | 10 + > src/compiler/nir/nir_opt_discard.c | 396 +++++++++++++++++++++++++++++ > 4 files changed, 408 insertions(+) > create mode 100644 src/compiler/nir/nir_opt_discard.c > > diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources > index 9e3fbdc2612..8600ce81281 100644 > --- a/src/compiler/Makefile.sources > +++ b/src/compiler/Makefile.sources > @@ -271,6 +271,7 @@ NIR_FILES = \ > nir/nir_opt_cse.c \ > nir/nir_opt_dce.c \ > nir/nir_opt_dead_cf.c \ > + nir/nir_opt_discard.c \ > nir/nir_opt_gcm.c \ > nir/nir_opt_global_to_local.c \ > nir/nir_opt_if.c \ > diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build > index 28aa8de7014..e339258bb94 100644 > --- a/src/compiler/nir/meson.build > +++ b/src/compiler/nir/meson.build > @@ -156,6 +156,7 @@ files_libnir = files( > 'nir_opt_cse.c', > 'nir_opt_dce.c', > 'nir_opt_dead_cf.c', > + 'nir_opt_discard.c', > 'nir_opt_gcm.c', > 'nir_opt_global_to_local.c', > 'nir_opt_if.c', > diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h > index c40a88c8ccc..dac019c17e8 100644 > --- a/src/compiler/nir/nir.h > +++ b/src/compiler/nir/nir.h > @@ -2022,6 +2022,13 @@ typedef struct nir_shader_compiler_options { > */ > bool vs_inputs_dual_locations; > > + /** > + * Whether or not derivatives are still a safe operation after a discard > + * has occurred. Optimization passes may be able to be a bit more > + * agressive if this is true.
s/agressive/aggressive/ _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev