nir: Distinguish between normal uniforms and UBOs

Previously, NIR had a single nir_var_uniform mode used for atomic
counters, UBOs, samplers, images, and normal uniforms.  This commit
splits this into nir_var_uniform and nir_var_ubo where nir_var_uniform
is still a bit of a catch-all but the nir_var_ubo is specific to UBOs.
While we're at it, we also rename shader_storage to ssbo to follow the
convention.

We need this so that we can distinguish between normal uniforms and UBO
access at the deref level without going all the way back variable and
seeing if it has an interface type.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
This commit is contained in:
Jason Ekstrand 2018-12-14 11:21:50 -06:00 committed by Jason Ekstrand
parent c9a4135e14
commit a700a82bda
13 changed files with 44 additions and 38 deletions

View File

@ -101,7 +101,7 @@ lower_deref_instr(nir_builder *b, nir_intrinsic_instr *instr,
nir_variable *var = nir_deref_instr_get_variable(deref);
if (var->data.mode != nir_var_uniform &&
var->data.mode != nir_var_shader_storage &&
var->data.mode != nir_var_ssbo &&
var->data.mode != nir_var_shared)
return false; /* atomics passed as function arguments can't be lowered */

View File

@ -354,11 +354,14 @@ nir_visitor::visit(ir_variable *ir)
break;
case ir_var_uniform:
var->data.mode = nir_var_uniform;
if (ir->get_interface_type())
var->data.mode = nir_var_ubo;
else
var->data.mode = nir_var_uniform;
break;
case ir_var_shader_storage:
var->data.mode = nir_var_shader_storage;
var->data.mode = nir_var_ssbo;
break;
case ir_var_system_value:

View File

@ -142,7 +142,8 @@ nir_shader_add_variable(nir_shader *shader, nir_variable *var)
break;
case nir_var_uniform:
case nir_var_shader_storage:
case nir_var_ubo:
case nir_var_ssbo:
exec_list_push_tail(&shader->uniforms, &var->node);
break;

View File

@ -100,8 +100,9 @@ typedef enum {
nir_var_global = (1 << 2),
nir_var_local = (1 << 3),
nir_var_uniform = (1 << 4),
nir_var_shader_storage = (1 << 5),
nir_var_ubo = (1 << 5),
nir_var_system_value = (1 << 6),
nir_var_ssbo = (1 << 7),
nir_var_shared = (1 << 8),
nir_var_all = ~0,
} nir_variable_mode;

View File

@ -223,8 +223,7 @@ nir_lower_atomics_to_ssbo(nir_shader *shader, unsigned ssbo_offset)
snprintf(name, sizeof(name), "counter%d", var->data.binding);
ssbo = nir_variable_create(shader, nir_var_shader_storage,
type, name);
ssbo = nir_variable_create(shader, nir_var_ssbo, type, name);
ssbo->data.binding = var->data.binding;
struct glsl_struct_field field = {

View File

@ -54,8 +54,7 @@ nir_assign_var_locations(struct exec_list *var_list, unsigned *size,
* UBOs have their own address spaces, so don't count them towards the
* number of global uniforms
*/
if ((var->data.mode == nir_var_uniform || var->data.mode == nir_var_shader_storage) &&
var->interface_type != NULL)
if (var->data.mode == nir_var_ubo || var->data.mode == nir_var_ssbo)
continue;
var->data.driver_location = location;

View File

@ -136,7 +136,7 @@ gather_vars_written(struct copy_prop_var_state *state,
written->modes |= nir_var_shader_out |
nir_var_global |
nir_var_local |
nir_var_shader_storage |
nir_var_ssbo |
nir_var_shared;
continue;
}
@ -149,7 +149,7 @@ gather_vars_written(struct copy_prop_var_state *state,
case nir_intrinsic_barrier:
case nir_intrinsic_memory_barrier:
written->modes |= nir_var_shader_out |
nir_var_shader_storage |
nir_var_ssbo |
nir_var_shared;
break;
@ -617,7 +617,7 @@ copy_prop_vars_block(struct copy_prop_var_state *state,
apply_barrier_for_modes(copies, nir_var_shader_out |
nir_var_global |
nir_var_local |
nir_var_shader_storage |
nir_var_ssbo |
nir_var_shared);
continue;
}
@ -630,7 +630,7 @@ copy_prop_vars_block(struct copy_prop_var_state *state,
case nir_intrinsic_barrier:
case nir_intrinsic_memory_barrier:
apply_barrier_for_modes(copies, nir_var_shader_out |
nir_var_shader_storage |
nir_var_ssbo |
nir_var_shared);
break;

View File

@ -121,7 +121,7 @@ remove_dead_write_vars_local(void *mem_ctx, nir_block *block)
clear_unused_for_modes(&unused_writes, nir_var_shader_out |
nir_var_global |
nir_var_local |
nir_var_shader_storage |
nir_var_ssbo |
nir_var_shared);
continue;
}
@ -134,7 +134,7 @@ remove_dead_write_vars_local(void *mem_ctx, nir_block *block)
case nir_intrinsic_barrier:
case nir_intrinsic_memory_barrier: {
clear_unused_for_modes(&unused_writes, nir_var_shader_out |
nir_var_shader_storage |
nir_var_ssbo |
nir_var_shared);
break;
}

View File

@ -412,10 +412,12 @@ get_variable_mode_str(nir_variable_mode mode, bool want_local_global_mode)
return "shader_out";
case nir_var_uniform:
return "uniform";
case nir_var_shader_storage:
return "shader_storage";
case nir_var_ubo:
return "ubo";
case nir_var_system_value:
return "system";
case nir_var_ssbo:
return "ssbo";
case nir_var_shared:
return "shared";
case nir_var_global:
@ -503,7 +505,8 @@ print_var_decl(nir_variable *var, print_state *state)
if (var->data.mode == nir_var_shader_in ||
var->data.mode == nir_var_shader_out ||
var->data.mode == nir_var_uniform ||
var->data.mode == nir_var_shader_storage) {
var->data.mode == nir_var_ubo ||
var->data.mode == nir_var_ssbo) {
const char *loc = NULL;
char buf[4];

View File

@ -237,7 +237,7 @@ TEST_F(nir_redundant_load_vars_test, invalidate_live_load_in_the_end_of_loop)
* body.
*/
nir_variable *v = create_int(nir_var_shader_storage, "v");
nir_variable *v = create_int(nir_var_ssbo, "v");
nir_load_var(b, v);
@ -433,7 +433,7 @@ TEST_F(nir_copy_prop_vars_test, store_store_load_different_components_in_many_bl
TEST_F(nir_copy_prop_vars_test, memory_barrier_in_two_blocks)
{
nir_variable **v = create_many_int(nir_var_shader_storage, "v", 4);
nir_variable **v = create_many_int(nir_var_ssbo, "v", 4);
nir_store_var(b, v[0], nir_imm_int(b, 1), 1);
nir_store_var(b, v[1], nir_imm_int(b, 2), 1);
@ -490,7 +490,7 @@ TEST_F(nir_copy_prop_vars_test, simple_store_load_in_two_blocks)
TEST_F(nir_dead_write_vars_test, no_dead_writes_in_block)
{
nir_variable **v = create_many_int(nir_var_shader_storage, "v", 2);
nir_variable **v = create_many_int(nir_var_ssbo, "v", 2);
nir_store_var(b, v[0], nir_load_var(b, v[1]), 1);
@ -500,7 +500,7 @@ TEST_F(nir_dead_write_vars_test, no_dead_writes_in_block)
TEST_F(nir_dead_write_vars_test, no_dead_writes_different_components_in_block)
{
nir_variable **v = create_many_ivec2(nir_var_shader_storage, "v", 3);
nir_variable **v = create_many_ivec2(nir_var_ssbo, "v", 3);
nir_store_var(b, v[0], nir_load_var(b, v[1]), 1 << 0);
nir_store_var(b, v[0], nir_load_var(b, v[2]), 1 << 1);
@ -511,7 +511,7 @@ TEST_F(nir_dead_write_vars_test, no_dead_writes_different_components_in_block)
TEST_F(nir_dead_write_vars_test, no_dead_writes_in_if_statement)
{
nir_variable **v = create_many_int(nir_var_shader_storage, "v", 6);
nir_variable **v = create_many_int(nir_var_ssbo, "v", 6);
nir_store_var(b, v[2], nir_load_var(b, v[0]), 1);
nir_store_var(b, v[3], nir_load_var(b, v[1]), 1);
@ -531,7 +531,7 @@ TEST_F(nir_dead_write_vars_test, no_dead_writes_in_if_statement)
TEST_F(nir_dead_write_vars_test, no_dead_writes_in_loop_statement)
{
nir_variable **v = create_many_int(nir_var_shader_storage, "v", 3);
nir_variable **v = create_many_int(nir_var_ssbo, "v", 3);
nir_store_var(b, v[0], nir_load_var(b, v[1]), 1);
@ -553,7 +553,7 @@ TEST_F(nir_dead_write_vars_test, no_dead_writes_in_loop_statement)
TEST_F(nir_dead_write_vars_test, dead_write_in_block)
{
nir_variable **v = create_many_int(nir_var_shader_storage, "v", 3);
nir_variable **v = create_many_int(nir_var_ssbo, "v", 3);
nir_store_var(b, v[0], nir_load_var(b, v[1]), 1);
nir_ssa_def *load_v2 = nir_load_var(b, v[2]);
@ -571,7 +571,7 @@ TEST_F(nir_dead_write_vars_test, dead_write_in_block)
TEST_F(nir_dead_write_vars_test, dead_write_components_in_block)
{
nir_variable **v = create_many_ivec2(nir_var_shader_storage, "v", 3);
nir_variable **v = create_many_ivec2(nir_var_ssbo, "v", 3);
nir_store_var(b, v[0], nir_load_var(b, v[1]), 1 << 0);
nir_ssa_def *load_v2 = nir_load_var(b, v[2]);
@ -595,7 +595,7 @@ TEST_F(nir_dead_write_vars_test, dead_write_components_in_block)
TEST_F(nir_dead_write_vars_test, DISABLED_dead_write_in_two_blocks)
{
nir_variable **v = create_many_int(nir_var_shader_storage, "v", 3);
nir_variable **v = create_many_int(nir_var_ssbo, "v", 3);
nir_store_var(b, v[0], nir_load_var(b, v[1]), 1);
nir_ssa_def *load_v2 = nir_load_var(b, v[2]);
@ -617,7 +617,7 @@ TEST_F(nir_dead_write_vars_test, DISABLED_dead_write_in_two_blocks)
TEST_F(nir_dead_write_vars_test, DISABLED_dead_write_components_in_two_blocks)
{
nir_variable **v = create_many_ivec2(nir_var_shader_storage, "v", 3);
nir_variable **v = create_many_ivec2(nir_var_ssbo, "v", 3);
nir_store_var(b, v[0], nir_load_var(b, v[1]), 1 << 0);
@ -639,7 +639,7 @@ TEST_F(nir_dead_write_vars_test, DISABLED_dead_write_components_in_two_blocks)
TEST_F(nir_dead_write_vars_test, DISABLED_dead_writes_in_if_statement)
{
nir_variable **v = create_many_int(nir_var_shader_storage, "v", 4);
nir_variable **v = create_many_int(nir_var_ssbo, "v", 4);
/* Both branches will overwrite, making the previous store dead. */
nir_store_var(b, v[0], nir_load_var(b, v[1]), 1);
@ -670,7 +670,7 @@ TEST_F(nir_dead_write_vars_test, DISABLED_dead_writes_in_if_statement)
TEST_F(nir_dead_write_vars_test, DISABLED_memory_barrier_in_two_blocks)
{
nir_variable **v = create_many_int(nir_var_shader_storage, "v", 2);
nir_variable **v = create_many_int(nir_var_ssbo, "v", 2);
nir_store_var(b, v[0], nir_imm_int(b, 1), 1);
nir_store_var(b, v[1], nir_imm_int(b, 2), 1);
@ -693,7 +693,7 @@ TEST_F(nir_dead_write_vars_test, DISABLED_memory_barrier_in_two_blocks)
TEST_F(nir_dead_write_vars_test, DISABLED_unrelated_barrier_in_two_blocks)
{
nir_variable **v = create_many_int(nir_var_shader_storage, "v", 3);
nir_variable **v = create_many_int(nir_var_ssbo, "v", 3);
nir_variable *out = create_int(nir_var_shader_out, "out");
nir_store_var(b, out, nir_load_var(b, v[1]), 1);

View File

@ -1497,10 +1497,10 @@ vtn_storage_class_to_mode(struct vtn_builder *b,
case SpvStorageClassUniform:
if (interface_type->block) {
mode = vtn_variable_mode_ubo;
nir_mode = 0;
nir_mode = nir_var_ubo;
} else if (interface_type->buffer_block) {
mode = vtn_variable_mode_ssbo;
nir_mode = 0;
nir_mode = nir_var_ssbo;
} else {
/* Default-block uniforms, coming from gl_spirv */
mode = vtn_variable_mode_uniform;
@ -1509,7 +1509,7 @@ vtn_storage_class_to_mode(struct vtn_builder *b,
break;
case SpvStorageClassStorageBuffer:
mode = vtn_variable_mode_ssbo;
nir_mode = 0;
nir_mode = nir_var_ssbo;
break;
case SpvStorageClassUniformConstant:
mode = vtn_variable_mode_uniform;

View File

@ -675,7 +675,8 @@ void si_nir_scan_shader(const struct nir_shader *nir,
* so we don't need to worry about the ordering.
*/
if (variable->interface_type != NULL) {
if (variable->data.mode == nir_var_uniform) {
if (variable->data.mode == nir_var_uniform ||
variable->data.mode == nir_var_ubo) {
unsigned block_count;
if (base_type != GLSL_TYPE_INTERFACE) {
@ -699,7 +700,7 @@ void si_nir_scan_shader(const struct nir_shader *nir,
_mesa_set_add(ubo_set, variable->interface_type);
}
if (variable->data.mode == nir_var_shader_storage) {
if (variable->data.mode == nir_var_ssbo) {
/* TODO: make this more accurate */
info->shader_buffers_declared =
u_bit_consecutive(0, SI_NUM_SHADER_BUFFERS);

View File

@ -253,8 +253,7 @@ st_nir_assign_uniform_locations(struct gl_context *ctx,
* UBO's have their own address spaces, so don't count them towards the
* number of global uniforms
*/
if ((uniform->data.mode == nir_var_uniform || uniform->data.mode == nir_var_shader_storage) &&
uniform->interface_type != NULL)
if (uniform->data.mode == nir_var_ubo || uniform->data.mode == nir_var_ssbo)
continue;
const struct glsl_type *type = glsl_without_array(uniform->type);