nir: add a pass to optimize "gl_FragDepth = gl_FragCoord.z" away

gl_FragDepth default value is gl_FragCoord.z so if a shader does:

   gl_FragDepth = gl_FragCoord.z

we can drop this assignment.

v2: use nir_ssa_scalar_resolved and don't do this is gl_FragDepth
    is wrote multiple times (Jason)
v3: - move to its own pass (Jason)
    - handle var = NULL (Rhys)
v4: refactoring (Jason)

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10697>
This commit is contained in:
Pierre-Eric Pelloux-Prayer
2021-05-07 16:36:47 +02:00
parent a6176881a6
commit 7684d57a05
4 changed files with 115 additions and 0 deletions

View File

@@ -223,6 +223,7 @@ files_libnir = files(
'nir_opt_dead_cf.c',
'nir_opt_dead_write_vars.c',
'nir_opt_find_array_copies.c',
'nir_opt_fragdepth.c',
'nir_opt_gcm.c',
'nir_opt_idiv_const.c',
'nir_opt_if.c',