nir/lower_io: Eliminate oob writes and return zero for oob reads
authorDanylo Piliaiev <danylo.piliaiev@globallogic.com>
Fri, 21 Aug 2020 10:42:55 +0000 (13:42 +0300)
committerMarge Bot <eric+marge@anholt.net>
Tue, 22 Sep 2020 09:06:52 +0000 (09:06 +0000)
commit66669eb5295c207622425d9767422a62e1228407
tree0099eb854c9a191a01b93478ee9a28eaddb93641
parent8e1193b8d37b15a18153c7a2774e120b8d3d13dc
nir/lower_io: Eliminate oob writes and return zero for oob reads

Out-of-bounds writes could be eliminated per spec:

Section 5.11 (Out-of-Bounds Accesses) of the GLSL 4.60 spec says:

 "In the subsections described above for array, vector, matrix and
  structure accesses, any out-of-bounds access produced undefined
  behavior....
  Out-of-bounds writes may be discarded or overwrite
  other variables of the active program.
  Out-of-bounds reads return undefined values, which
  include values from other variables of the active program or zero."

GL_KHR_robustness and GL_ARB_robustness encourage us to return zero
for reads.

Otherwise get_io_offset would return out-of-bound offset which may
result in out-of-bound loading/storing of inputs/outputs,
that could cause issues in drivers down the line.

E.g. this fixes such dereference:
 int vue_slot = vue_map->varying_to_slot[intrin->const_index[0]];
in brw_nir.c

CC: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6428>
src/compiler/nir/nir_lower_io.c