nir: add deref lowering sanity checking

This will be removed at the end of the transition, but add some tracking
plus asserts to help ensure that lowering passes are called at the
correct point (pre or post deref instruction lowering) as passes are
converted and the point where lower_deref_instrs() is called is moved.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Acked-by: Rob Clark <robdclark@gmail.com>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Acked-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Rob Clark
2018-05-16 10:02:55 -04:00
committed by Jason Ekstrand
parent 74212c2414
commit d80c342d89
36 changed files with 85 additions and 0 deletions

View File

@@ -185,6 +185,8 @@ gl_nir_lower_atomics(nir_shader *shader,
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_atomic_counter_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (!function->impl) if (!function->impl)
continue; continue;

View File

@@ -155,6 +155,8 @@ gl_nir_lower_samplers(nir_shader *shader,
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_texture_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress |= lower_impl(function->impl, shader_program, progress |= lower_impl(function->impl, shader_program,

View File

@@ -233,6 +233,8 @@ gl_nir_lower_samplers_as_deref(nir_shader *shader,
bool progress = false; bool progress = false;
struct lower_samplers_as_deref_state state; struct lower_samplers_as_deref_state state;
nir_assert_lowered_derefs(shader, nir_lower_texture_derefs);
state.shader = shader; state.shader = shader;
state.shader_program = shader_program; state.shader_program = shader_program;
state.remap_table = _mesa_hash_table_create(NULL, _mesa_key_hash_string, state.remap_table = _mesa_hash_table_create(NULL, _mesa_key_hash_string,

View File

@@ -64,6 +64,7 @@ nir_shader_create(void *mem_ctx,
shader->num_outputs = 0; shader->num_outputs = 0;
shader->num_uniforms = 0; shader->num_uniforms = 0;
shader->num_shared = 0; shader->num_shared = 0;
shader->lowered_derefs = 0;
return shader; return shader;
} }

View File

@@ -2133,8 +2133,19 @@ typedef struct nir_shader {
* access plus one * access plus one
*/ */
unsigned num_inputs, num_uniforms, num_outputs, num_shared; unsigned num_inputs, num_uniforms, num_outputs, num_shared;
/* temporary, tracking for which derefs instructions have been lowered
* to deref chains
*/
unsigned lowered_derefs;
} nir_shader; } nir_shader;
#define nir_assert_lowered_derefs(shader, mask) \
assert(((shader)->lowered_derefs & (mask)) == (mask))
#define nir_assert_unlowered_derefs(shader, mask) \
assert(!((shader)->lowered_derefs & (mask)))
static inline nir_function_impl * static inline nir_function_impl *
nir_shader_get_entrypoint(nir_shader *shader) nir_shader_get_entrypoint(nir_shader *shader)
{ {
@@ -2681,6 +2692,7 @@ enum nir_lower_deref_flags {
nir_lower_atomic_counter_derefs = (1 << 3), nir_lower_atomic_counter_derefs = (1 << 3),
nir_lower_atomic_derefs = (1 << 4), nir_lower_atomic_derefs = (1 << 4),
nir_lower_image_derefs = (1 << 5), nir_lower_image_derefs = (1 << 5),
nir_lower_all_derefs = (1 << 6) - 1,
}; };
bool nir_lower_deref_instrs(nir_shader *shader, bool nir_lower_deref_instrs(nir_shader *shader,

View File

@@ -816,6 +816,7 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s)
ns->num_uniforms = s->num_uniforms; ns->num_uniforms = s->num_uniforms;
ns->num_outputs = s->num_outputs; ns->num_outputs = s->num_outputs;
ns->num_shared = s->num_shared; ns->num_shared = s->num_shared;
ns->lowered_derefs = s->lowered_derefs;
free_clone_state(&state); free_clone_state(&state);

View File

@@ -350,5 +350,7 @@ nir_lower_deref_instrs(nir_shader *shader,
progress |= nir_lower_deref_instrs_impl(function->impl, flags); progress |= nir_lower_deref_instrs_impl(function->impl, flags);
} }
shader->lowered_derefs |= flags;
return progress; return progress;
} }

View File

@@ -397,6 +397,8 @@ glsl_type_get_image_count(const struct glsl_type *type)
void void
nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint) nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint)
{ {
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs);
shader->info.num_textures = 0; shader->info.num_textures = 0;
shader->info.num_images = 0; shader->info.num_images = 0;
nir_foreach_variable(var, &shader->uniforms) { nir_foreach_variable(var, &shader->uniforms) {

View File

@@ -133,6 +133,8 @@ nir_remove_unused_varyings(nir_shader *producer, nir_shader *consumer)
{ {
assert(producer->info.stage != MESA_SHADER_FRAGMENT); assert(producer->info.stage != MESA_SHADER_FRAGMENT);
assert(consumer->info.stage != MESA_SHADER_VERTEX); assert(consumer->info.stage != MESA_SHADER_VERTEX);
nir_assert_lowered_derefs(producer, nir_lower_load_store_derefs);
nir_assert_lowered_derefs(consumer, nir_lower_load_store_derefs);
uint64_t read[4] = { 0 }, written[4] = { 0 }; uint64_t read[4] = { 0 }, written[4] = { 0 };
uint64_t patches_read[4] = { 0 }, patches_written[4] = { 0 }; uint64_t patches_read[4] = { 0 }, patches_written[4] = { 0 };

View File

@@ -827,6 +827,7 @@ void
nir_loop_analyze_impl(nir_function_impl *impl, nir_loop_analyze_impl(nir_function_impl *impl,
nir_variable_mode indirect_mask) nir_variable_mode indirect_mask)
{ {
nir_assert_lowered_derefs(impl->function->shader, nir_lower_load_store_derefs);
nir_index_ssa_defs(impl); nir_index_ssa_defs(impl);
foreach_list_typed(nir_cf_node, node, node, &impl->body) foreach_list_typed(nir_cf_node, node, node, &impl->body)
process_loops(node, indirect_mask); process_loops(node, indirect_mask);

View File

@@ -41,6 +41,8 @@ nir_lower_alpha_test(nir_shader *shader, enum compare_func func,
{ {
assert(shader->info.stage == MESA_SHADER_FRAGMENT); assert(shader->info.stage == MESA_SHADER_FRAGMENT);
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
nir_function_impl *impl = function->impl; nir_function_impl *impl = function->impl;
nir_builder b; nir_builder b;

View File

@@ -134,6 +134,8 @@ nir_lower_clamp_color_outputs(nir_shader *shader)
.shader = shader, .shader = shader,
}; };
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress |= lower_impl(&state, function->impl); progress |= lower_impl(&state, function->impl);

View File

@@ -194,6 +194,8 @@ nir_lower_clip_cull_distance_arrays(nir_shader *nir)
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(nir, nir_lower_load_store_derefs);
if (nir->info.stage <= MESA_SHADER_GEOMETRY) if (nir->info.stage <= MESA_SHADER_GEOMETRY)
progress |= combine_clip_cull(nir, &nir->outputs, true); progress |= combine_clip_cull(nir, &nir->outputs, true);

View File

@@ -253,6 +253,11 @@ nir_lower_drawpixels(nir_shader *shader,
.shader = shader, .shader = shader,
}; };
/* note that this pass already assumes texture/sampler derefs are already
* lowered to index
*/
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
assert(shader->info.stage == MESA_SHADER_FRAGMENT); assert(shader->info.stage == MESA_SHADER_FRAGMENT);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {

View File

@@ -76,6 +76,9 @@ nir_lower_global_vars_to_local(nir_shader *shader)
_mesa_hash_table_create(NULL, _mesa_hash_pointer, _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal); _mesa_key_pointer_equal);
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs |
nir_lower_atomic_counter_derefs | nir_lower_atomic_derefs | nir_lower_image_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) { if (function->impl) {
nir_foreach_block(block, function->impl) nir_foreach_block(block, function->impl)

View File

@@ -211,6 +211,8 @@ nir_lower_indirect_derefs(nir_shader *shader, nir_variable_mode modes)
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress = lower_indirects_impl(function->impl, modes) || progress; progress = lower_indirects_impl(function->impl, modes) || progress;

View File

@@ -511,6 +511,8 @@ nir_lower_io(nir_shader *shader, nir_variable_mode modes,
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs | nir_lower_atomic_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) { if (function->impl) {
progress |= nir_lower_io_impl(function->impl, modes, progress |= nir_lower_io_impl(function->impl, modes,

View File

@@ -356,6 +356,8 @@ nir_lower_io_arrays_to_elements_no_indirects(nir_shader *shader,
_mesa_hash_table_create(NULL, _mesa_hash_pointer, _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal); _mesa_key_pointer_equal);
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs);
uint64_t indirects[4] = {0}, patch_indirects[4] = {0}; uint64_t indirects[4] = {0}, patch_indirects[4] = {0};
lower_io_arrays_to_elements(shader, nir_var_shader_out, indirects, lower_io_arrays_to_elements(shader, nir_var_shader_out, indirects,
@@ -398,6 +400,9 @@ nir_lower_io_arrays_to_elements(nir_shader *producer, nir_shader *consumer)
_mesa_hash_table_create(NULL, _mesa_hash_pointer, _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal); _mesa_key_pointer_equal);
nir_assert_lowered_derefs(producer, nir_lower_load_store_derefs | nir_lower_interp_derefs);
nir_assert_lowered_derefs(consumer, nir_lower_load_store_derefs | nir_lower_interp_derefs);
uint64_t indirects[4] = {0}, patch_indirects[4] = {0}; uint64_t indirects[4] = {0}, patch_indirects[4] = {0};
create_indirects_mask(producer, indirects, patch_indirects, create_indirects_mask(producer, indirects, patch_indirects,
nir_var_shader_out); nir_var_shader_out);

View File

@@ -289,6 +289,8 @@ nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask)
_mesa_hash_table_create(NULL, _mesa_hash_pointer, _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal); _mesa_key_pointer_equal);
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) { if (function->impl) {
nir_builder b; nir_builder b;

View File

@@ -161,6 +161,8 @@ nir_lower_io_types(nir_shader *shader)
{ {
struct lower_io_types_state state; struct lower_io_types_state state;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
state.shader = shader; state.shader = shader;
exec_list_make_empty(&state.new_ins); exec_list_make_empty(&state.new_ins);
exec_list_make_empty(&state.new_outs); exec_list_make_empty(&state.new_outs);

View File

@@ -292,6 +292,8 @@ nir_lower_locals_to_regs(nir_shader *shader)
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress = nir_lower_locals_to_regs_impl(function->impl) || progress; progress = nir_lower_locals_to_regs_impl(function->impl) || progress;

View File

@@ -299,6 +299,8 @@ nir_lower_phis_to_scalar(nir_shader *shader)
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress = lower_phis_to_scalar_impl(function->impl) || progress; progress = lower_phis_to_scalar_impl(function->impl) || progress;

View File

@@ -203,6 +203,8 @@ nir_lower_system_values(nir_shader *shader)
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress = convert_impl(function->impl) || progress; progress = convert_impl(function->impl) || progress;

View File

@@ -865,6 +865,8 @@ nir_lower_tex(nir_shader *shader, const nir_lower_tex_options *options)
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_texture_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress |= nir_lower_tex_impl(function->impl, options); progress |= nir_lower_tex_impl(function->impl, options);

View File

@@ -192,6 +192,8 @@ nir_lower_var_copies(nir_shader *shader)
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress |= lower_var_copies_impl(function->impl); progress |= lower_var_copies_impl(function->impl);

View File

@@ -737,6 +737,8 @@ nir_lower_vars_to_ssa(nir_shader *shader)
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress |= nir_lower_vars_to_ssa_impl(function->impl); progress |= nir_lower_vars_to_ssa_impl(function->impl);

View File

@@ -107,6 +107,8 @@ nir_lower_wpos_center(nir_shader *shader, const bool for_sample_shading)
assert(shader->info.stage == MESA_SHADER_FRAGMENT); assert(shader->info.stage == MESA_SHADER_FRAGMENT);
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) { if (function->impl) {
nir_builder_init(&b, function->impl); nir_builder_init(&b, function->impl);

View File

@@ -352,6 +352,8 @@ nir_lower_wpos_ytransform(nir_shader *shader,
.shader = shader, .shader = shader,
}; };
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
assert(shader->info.stage == MESA_SHADER_FRAGMENT); assert(shader->info.stage == MESA_SHADER_FRAGMENT);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {

View File

@@ -768,6 +768,8 @@ nir_opt_copy_prop_vars(nir_shader *shader)
{ {
struct copy_prop_var_state state; struct copy_prop_var_state state;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
state.shader = shader; state.shader = shader;
state.mem_ctx = ralloc_context(NULL); state.mem_ctx = ralloc_context(NULL);
list_inithead(&state.copies); list_inithead(&state.copies);

View File

@@ -255,6 +255,8 @@ nir_opt_peephole_select(nir_shader *shader, unsigned limit)
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress |= nir_opt_peephole_select_impl(function->impl, limit); progress |= nir_opt_peephole_select_impl(function->impl, limit);

View File

@@ -133,6 +133,8 @@ nir_opt_undef(nir_shader *shader)
nir_builder b; nir_builder b;
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) { if (function->impl) {
nir_builder_init(&b, function->impl); nir_builder_init(&b, function->impl);

View File

@@ -184,6 +184,8 @@ nir_propagate_invariant(nir_shader *shader)
struct set *invariants = _mesa_set_create(NULL, _mesa_hash_pointer, struct set *invariants = _mesa_set_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal); _mesa_key_pointer_equal);
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
bool progress = false; bool progress = false;
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl && propagate_invariant_impl(function->impl, invariants)) if (function->impl && propagate_invariant_impl(function->impl, invariants))

View File

@@ -172,6 +172,8 @@ nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes)
struct set *live = struct set *live =
_mesa_set_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal); _mesa_set_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal);
nir_assert_lowered_derefs(shader, nir_lower_all_derefs);
add_var_use_shader(shader, live, modes); add_var_use_shader(shader, live, modes);
if (modes & nir_var_uniform) if (modes & nir_var_uniform)

View File

@@ -1215,6 +1215,7 @@ nir_serialize(struct blob *blob, const nir_shader *nir)
blob_write_uint32(blob, nir->num_uniforms); blob_write_uint32(blob, nir->num_uniforms);
blob_write_uint32(blob, nir->num_outputs); blob_write_uint32(blob, nir->num_outputs);
blob_write_uint32(blob, nir->num_shared); blob_write_uint32(blob, nir->num_shared);
blob_write_uint32(blob, nir->lowered_derefs);
blob_write_uint32(blob, exec_list_length(&nir->functions)); blob_write_uint32(blob, exec_list_length(&nir->functions));
nir_foreach_function(fxn, nir) { nir_foreach_function(fxn, nir) {
@@ -1270,6 +1271,7 @@ nir_deserialize(void *mem_ctx,
ctx.nir->num_uniforms = blob_read_uint32(blob); ctx.nir->num_uniforms = blob_read_uint32(blob);
ctx.nir->num_outputs = blob_read_uint32(blob); ctx.nir->num_outputs = blob_read_uint32(blob);
ctx.nir->num_shared = blob_read_uint32(blob); ctx.nir->num_shared = blob_read_uint32(blob);
ctx.nir->lowered_derefs = blob_read_uint32(blob);
unsigned num_functions = blob_read_uint32(blob); unsigned num_functions = blob_read_uint32(blob);
for (unsigned i = 0; i < num_functions; i++) for (unsigned i = 0; i < num_functions; i++)

View File

@@ -287,6 +287,8 @@ nir_split_var_copies(nir_shader *shader)
{ {
bool progress = false; bool progress = false;
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {
if (function->impl) if (function->impl)
progress = split_var_copies_impl(function->impl) || progress; progress = split_var_copies_impl(function->impl) || progress;

View File

@@ -239,6 +239,7 @@ lower_builtin_impl(lower_builtin_state *state, nir_function_impl *impl)
void void
st_nir_lower_builtin(nir_shader *shader) st_nir_lower_builtin(nir_shader *shader)
{ {
nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
lower_builtin_state state; lower_builtin_state state;
state.shader = shader; state.shader = shader;
nir_foreach_function(function, shader) { nir_foreach_function(function, shader) {