pan/bi: Do more mesa/st stuff in standalone compiler

From freedreno.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12026>
This commit is contained in:
Alyssa Rosenzweig 2021-07-19 13:41:49 -04:00 committed by Marge Bot
parent f01f5e7168
commit 18dedd80db

View file

@ -1,5 +1,8 @@
/*
* Copyright (C) 2021 Collabora, Ltd.
* Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
* Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
* Copyright © 2015 Red Hat
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -57,6 +60,55 @@ filename_to_stage(const char *stage)
unreachable("Should've returned or bailed");
}
static int
st_packed_uniforms_type_size(const struct glsl_type *type, bool bindless)
{
return glsl_count_dword_slots(type, bindless);
}
static int
glsl_type_size(const struct glsl_type *type, bool bindless)
{
return glsl_count_attribute_slots(type, false);
}
static void
insert_sorted(struct exec_list *var_list, nir_variable *new_var)
{
nir_foreach_variable_in_list (var, var_list) {
if (var->data.location > new_var->data.location) {
exec_node_insert_node_before(&var->node, &new_var->node);
return;
}
}
exec_list_push_tail(var_list, &new_var->node);
}
static void
sort_varyings(nir_shader *nir, nir_variable_mode mode)
{
struct exec_list new_list;
exec_list_make_empty(&new_list);
nir_foreach_variable_with_modes_safe (var, nir, mode) {
exec_node_remove(&var->node);
insert_sorted(&new_list, var);
}
exec_list_append(&nir->variables, &new_list);
}
static void
fixup_varying_slots(nir_shader *nir, nir_variable_mode mode)
{
nir_foreach_variable_with_modes (var, nir, mode) {
if (var->data.location >= VARYING_SLOT_VAR0) {
var->data.location += 9;
} else if ((var->data.location >= VARYING_SLOT_TEX0) &&
(var->data.location <= VARYING_SLOT_TEX7)) {
var->data.location += VARYING_SLOT_VAR0 - VARYING_SLOT_TEX0;
}
}
}
static void
compile_shader(int stages, char **files)
{
@ -93,11 +145,41 @@ compile_shader(int stages, char **files)
for (unsigned i = 0; i < stages; ++i) {
nir[i] = glsl_to_nir(&local_ctx, prog, shader_types[i], &bifrost_nir_options);
if (shader_types[i] == MESA_SHADER_VERTEX) {
nir_assign_var_locations(nir[i], nir_var_shader_in, &nir[i]->num_inputs,
glsl_type_size);
sort_varyings(nir[i], nir_var_shader_out);
nir_assign_var_locations(nir[i], nir_var_shader_out, &nir[i]->num_outputs,
glsl_type_size);
fixup_varying_slots(nir[i], nir_var_shader_out);
} else if (shader_types[i] == MESA_SHADER_FRAGMENT) {
sort_varyings(nir[i], nir_var_shader_in);
nir_assign_var_locations(nir[i], nir_var_shader_in, &nir[i]->num_inputs,
glsl_type_size);
fixup_varying_slots(nir[i], nir_var_shader_in);
nir_assign_var_locations(nir[i], nir_var_shader_out, &nir[i]->num_outputs,
glsl_type_size);
}
nir_assign_var_locations(nir[i], nir_var_uniform, &nir[i]->num_uniforms,
glsl_type_size);
NIR_PASS_V(nir[i], nir_lower_global_vars_to_local);
NIR_PASS_V(nir[i], nir_lower_io_to_temporaries, nir_shader_get_entrypoint(nir[i]), true, i == 0);
NIR_PASS_V(nir[i], nir_opt_copy_prop_vars);
NIR_PASS_V(nir[i], nir_opt_combine_stores, nir_var_all);
NIR_PASS_V(nir[i], nir_lower_system_values);
NIR_PASS_V(nir[i], gl_nir_lower_samplers, prog);
NIR_PASS_V(nir[i], nir_split_var_copies);
NIR_PASS_V(nir[i], nir_lower_var_copies);
NIR_PASS_V(nir[i], nir_lower_io, nir_var_uniform,
st_packed_uniforms_type_size,
(nir_lower_io_options)0);
NIR_PASS_V(nir[i], nir_lower_uniforms_to_ubo, true, false);
/* before buffers and vars_to_ssa */
NIR_PASS_V(nir[i], gl_nir_lower_images, true);