The trigger for this commit was when we found that we were not calling nir_metadata_preserve when lowering the layout code. But then I found that it would be better to just update the code to use nir_shader_instructions_pass, so we can avoid to manually: * Initialize the nir_builder * Call nir_foreach functions (we pass the callback) * Call nir_metadata_preserve functions (that as mentioned we were not calling) We also get a nice cleanup of several functions by reducing the number of parameters (we pass a state struct). Reviewed-by: Iago Toral Quiroga <itoral@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17609>