microsoft/clc: Re-order dead variable removal after uniform vars_to_explicit_types

Since vars_to_explicit_types is now where driver_location/offset is filled out,
we need to make sure that we still have all app-provided kernel arg variables
at that point in time so they all get assigned unique offsets. That means
that we can't have removed dead uniforms yet, which also means we can't have
filled out metadata for inline samplers (since usage of them generates tons
of duplicate uniforms).

Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9160>
This commit is contained in:
Jesse Natalie 2021-02-19 08:04:23 -08:00 committed by Marge Bot
parent 14a0004232
commit 11061c4e28

View file

@ -1147,43 +1147,22 @@ clc_to_dxil(struct clc_context *ctx,
} while (progress);
}
// Before removing dead uniforms, dedupe constant samplers to make more dead uniforms
NIR_PASS_V(nir, clc_nir_dedupe_const_samplers);
NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_uniform | nir_var_mem_ubo | nir_var_mem_constant | nir_var_function_temp, NULL);
NIR_PASS_V(nir, scale_fdiv);
dxil_wrap_sampler_state int_sampler_states[PIPE_MAX_SHADER_SAMPLER_VIEWS] = { {{0}} };
unsigned sampler_id = 0;
struct exec_list tmp_list;
exec_list_make_empty(&tmp_list);
struct exec_list inline_samplers_list;
exec_list_make_empty(&inline_samplers_list);
// Assign bindings for constant samplers, and move them to the end of the variable list
// Move inline samplers to the end of the uniforms 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] =
int_sampler_states[sampler_id].wrap[2] =
wrap_from_cl_addressing(var->data.sampler.addressing_mode);
int_sampler_states[sampler_id].is_nonnormalized_coords =
!var->data.sampler.normalized_coordinates;
int_sampler_states[sampler_id].is_linear_filtering =
var->data.sampler.filter_mode == SAMPLER_FILTER_MODE_LINEAR;
var->data.binding = sampler_id++;
assert(metadata->num_const_samplers < CLC_MAX_SAMPLERS);
metadata->const_samplers[metadata->num_const_samplers].sampler_id = var->data.binding;
metadata->const_samplers[metadata->num_const_samplers].addressing_mode = var->data.sampler.addressing_mode;
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_list_push_tail(&inline_samplers_list, &var->node);
}
}
exec_node_insert_list_after(exec_list_get_tail(&nir->variables), &tmp_list);
exec_node_insert_list_after(exec_list_get_tail(&nir->variables), &inline_samplers_list);
NIR_PASS_V(nir, nir_lower_variable_initializers, ~(nir_var_function_temp | nir_var_shader_temp));
@ -1276,6 +1255,32 @@ clc_to_dxil(struct clc_context *ctx,
}
}
// Before removing dead uniforms, dedupe constant samplers to make more dead uniforms
NIR_PASS_V(nir, clc_nir_dedupe_const_samplers);
NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_uniform | nir_var_mem_ubo | nir_var_mem_constant | nir_var_function_temp, NULL);
// Fill out inline sampler metadata, now that they've been deduped and dead ones removed
nir_foreach_variable_with_modes(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] =
int_sampler_states[sampler_id].wrap[2] =
wrap_from_cl_addressing(var->data.sampler.addressing_mode);
int_sampler_states[sampler_id].is_nonnormalized_coords =
!var->data.sampler.normalized_coordinates;
int_sampler_states[sampler_id].is_linear_filtering =
var->data.sampler.filter_mode == SAMPLER_FILTER_MODE_LINEAR;
var->data.binding = sampler_id++;
assert(metadata->num_const_samplers < CLC_MAX_SAMPLERS);
metadata->const_samplers[metadata->num_const_samplers].sampler_id = var->data.binding;
metadata->const_samplers[metadata->num_const_samplers].addressing_mode = var->data.sampler.addressing_mode;
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++;
}
}
// Needs to come before lower_explicit_io
NIR_PASS_V(nir, nir_lower_cl_images_to_tex);
struct clc_image_lower_context image_lower_context = { metadata, &srv_id, &uav_id };