intel/fs: fix scheduling of HALT instructions
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Mon, 3 Apr 2023 11:52:59 +0000 (14:52 +0300)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Thu, 4 May 2023 21:43:25 +0000 (00:43 +0300)
commit9471ffa70a03265d966594d3e290ce646f5c2f9a
treedf62afa392d3dd8af150d67de3e0445bf0677e9a
parent9b6945bb65284f28cbed3b53ffc3bb37ba66b7b1
intel/fs: fix scheduling of HALT instructions

With the following test :

dEQP-VK.spirv_assembly.instruction.terminate_invocation.terminate.no_out_of_bounds_load

There is a :

shader_start:
   ...                                 <- no control flow
   g0 = some_alu
   g1 = fbl
   g2 = broadcast g3, g1
   g4 = get_buffer_size g2
   ...                                 <- no control flow
   halt                                <- on some lanes
   g5 = send <surface>, g4

eliminate_find_live_channel will remove the fbl/broadcast because it
assumes lane0 is active at get_buffer_size :

shader_start:
   ...                                 <- no control flow
   g0 = some_alu
   g4 = get_buffer_size g0
   ...                                 <- no control flow
   halt                                <- on some lanes
   g5 = send <surface>, g4

But then the instruction scheduler will move the get_buffer_size after
the halt :

shader_start:
   ...                                 <- no control flow
   halt                                <- on some lanes
   g0 = some_alu
   g4 = get_buffer_size g0
   g5 = send <surface>, g4

get_buffer_size pulls the surface index from lane0 in g0 which could
have been turned off by the halt and we end up accessing an invalid
surface handle.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: mesa-stable
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20765>
src/intel/compiler/brw_schedule_instructions.cpp