From 0cd2eab1b80f80663179b227258766e6e29cdede Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Thu, 18 Feb 2021 11:05:43 -0800 Subject: [PATCH] microsoft/clc: Move inline samplers to the end of the variable list Since inline samplers are uniforms, just like kernel args, and nir_lower_vars_to_explicit_types will assign driver_location based on order in the variable list, move the inline samplers to the end of the list to prevent them from creating gaps in the kernel arg offsets. Fixes: ff05da7f ("microsoft: Add CLC frontend and kernel/compute support to DXIL converter") Reviewed-By: Bill Kristiansen Part-of: (cherry picked from commit 3ee8f2ccba93a984f895eeff6d908979e22215b3) --- .pick_status.json | 2 +- src/microsoft/clc/clc_compiler.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 1b06f7f4a2a..cd29750f225 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -4198,7 +4198,7 @@ "description": "microsoft/clc: Move inline samplers to the end of the variable list", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": "ff05da7f8dc4aa531704d48f718514e3b1fff45d" }, diff --git a/src/microsoft/clc/clc_compiler.c b/src/microsoft/clc/clc_compiler.c index 78424678e58..ca26a74eaf5 100644 --- a/src/microsoft/clc/clc_compiler.c +++ b/src/microsoft/clc/clc_compiler.c @@ -1209,8 +1209,11 @@ clc_to_dxil(struct clc_context *ctx, NIR_PASS_V(nir, scale_fdiv); - // Assign bindings for constant samplers - nir_foreach_variable_with_modes(var, nir, nir_var_uniform) { + struct exec_list tmp_list; + exec_list_make_empty(&tmp_list); + + // Assign bindings for constant samplers, and move them to the end of the variable list + nir_foreach_variable_with_modes_safe(var, nir, nir_var_uniform) { if (glsl_type_is_sampler(var->type) && var->data.sampler.is_inline_sampler) { int_sampler_states[sampler_id].wrap[0] = int_sampler_states[sampler_id].wrap[1] = @@ -1228,8 +1231,12 @@ clc_to_dxil(struct clc_context *ctx, metadata->const_samplers[metadata->num_const_samplers].normalized_coords = var->data.sampler.normalized_coordinates; metadata->const_samplers[metadata->num_const_samplers].filter_mode = var->data.sampler.filter_mode; metadata->num_const_samplers++; + + exec_node_remove(&var->node); + exec_list_push_tail(&tmp_list, &var->node); } } + exec_node_insert_list_after(exec_list_get_tail(&nir->variables), &tmp_list); NIR_PASS_V(nir, nir_lower_variable_initializers, ~(nir_var_function_temp | nir_var_shader_temp));