nir: add a pass to optimize "gl_FragDepth = gl_FragCoord.z" away
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Fri, 7 May 2021 14:36:47 +0000 (16:36 +0200)
committerPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Wed, 11 Aug 2021 09:00:11 +0000 (11:00 +0200)
commit7684d57a051fdeb7f4ecfc970fd51f0c3bb9dfad
tree52bd8fd0ae7469aa6b8621cb159405c2df7c9eda
parenta6176881a64909715e5c9ea3a1eac063656472f6
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>
src/compiler/nir/meson.build
src/compiler/nir/nir.h
src/compiler/nir/nir_opt_fragdepth.c [new file with mode: 0644]
src/mesa/state_tracker/st_glsl_to_nir.cpp