rusticl/kernel: assign sampler locations before DCEing variables

This fixes an issue hit by one of darktable's kernels, where the sampler
argument got assigned the location of a dead kernel parameter turning it
into a zombie and leading us to trash the kernel input buffer's layout.

Fixes: 25b8a34b48 ("rusticl/kernel: inline samplers")
Signed-off-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28121>
(cherry picked from commit 2df640c4f6)
This commit is contained in:
Karol Herbst 2024-03-12 00:08:43 +01:00 committed by Eric Engestrom
parent 29afc1c53e
commit 84abf14d9c
2 changed files with 18 additions and 17 deletions

View file

@ -1304,7 +1304,7 @@
"description": "rusticl/kernel: assign sampler locations before DCEing variables",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "25b8a34b48fce99164f1cb853bcde86d1cf6cba5",
"notes": null

View file

@ -458,22 +458,8 @@ fn lower_and_optimize_nir(
let mut args = KernelArg::from_spirv_nir(args, nir);
let mut internal_args = Vec::new();
let dv_opts = nir_remove_dead_variables_options {
can_remove_var: Some(can_remove_var),
can_remove_var_data: ptr::null_mut(),
};
nir_pass!(
nir,
nir_remove_dead_variables,
nir_variable_mode::nir_var_uniform
| nir_variable_mode::nir_var_image
| nir_variable_mode::nir_var_mem_constant
| nir_variable_mode::nir_var_mem_shared
| nir_variable_mode::nir_var_function_temp,
&dv_opts,
);
// asign locations for inline samplers
// asign locations for inline samplers.
// IMPORTANT: this needs to happen before nir_remove_dead_variables.
let mut last_loc = -1;
for v in nir
.variables_with_mode(nir_variable_mode::nir_var_uniform | nir_variable_mode::nir_var_image)
@ -501,6 +487,21 @@ fn lower_and_optimize_nir(
}
}
let dv_opts = nir_remove_dead_variables_options {
can_remove_var: Some(can_remove_var),
can_remove_var_data: ptr::null_mut(),
};
nir_pass!(
nir,
nir_remove_dead_variables,
nir_variable_mode::nir_var_uniform
| nir_variable_mode::nir_var_image
| nir_variable_mode::nir_var_mem_constant
| nir_variable_mode::nir_var_mem_shared
| nir_variable_mode::nir_var_function_temp,
&dv_opts,
);
nir_pass!(nir, nir_lower_readonly_images_to_tex, true);
nir_pass!(
nir,