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