From 63a38b945dc4ffe9bdebd0b9760ec3efbb35700a Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Wed, 3 Dec 2025 12:41:13 -0500 Subject: [PATCH] tu: Call nir_lower_sysvals_to_varyings once Remove the early call to nir_lower_sysvals_to_varyings. This guarantees that we only call it after lower_system_values has replaced the variables with intrinsics. It turns out that a sequence like this doesn't work: 1. shader declares Layer builtin as a signed integer 2. nir_lower_sysvals_to_varyings turns it into a varying (but keeps the signed integer type) 3. nir_lower_input_attachments (or some other pass) creates a nir_load_layer_id intrinsic. 4. nir_lower_sysvals_to_varyings is called again, and when creating the varying variable it passes an unsigned type to nir_get_variable_with_location(), which asserts because there is already a signed integer variable. By making lower_sysvals_to_varyings happen late for layer, we can avoid this happening by lowering away the variable before (2). Fixes: 5bbbf5cf9ba ("tu: Set use_layer_id_sysval for nir_lower_input_attachments") Part-of: --- src/freedreno/vulkan/tu_shader.cc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/freedreno/vulkan/tu_shader.cc b/src/freedreno/vulkan/tu_shader.cc index 2e0014daa2f..d77083b7c8f 100644 --- a/src/freedreno/vulkan/tu_shader.cc +++ b/src/freedreno/vulkan/tu_shader.cc @@ -224,12 +224,6 @@ tu_spirv_to_nir(struct tu_device *dev, nir_print_shader(nir, stderr); } - const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = { - .point_coord = true, - .layer_id = true, - }; - NIR_PASS(_, nir, nir_lower_sysvals_to_varyings, &sysvals_to_varyings); - NIR_PASS(_, nir, nir_lower_global_vars_to_local); /* Older glslang missing bf6efd0316d8 ("SPV: Fix #2293: keep relaxed @@ -2791,6 +2785,7 @@ tu_shader_create(struct tu_device *dev, NIR_PASS(_, nir, nir_lower_input_attachments, &att_options); const nir_lower_sysvals_to_varyings_options sysval_options = { + .point_coord = true, .layer_id = true, .view_index = true, };