From cd6f736c0702da3e620d9c97a1a01d911d72381f Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Sat, 24 Dec 2016 10:39:19 -0800 Subject: [PATCH] nir/conditional_if: Properly use the builder We were passing around a void *mem_ctx and using that to initialize the builder which was wrong since that pointed to ralloc_parent(impl) which is the shader but the builder is supposed to be initialized with the nir_function_impl. Reviewed-by: Eduardo Lima Mitev Reviewed-by: Jordan Justen --- .../nir/nir_opt_conditional_discard.c | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/compiler/nir/nir_opt_conditional_discard.c b/src/compiler/nir/nir_opt_conditional_discard.c index 2fde1799a8d..3605eaf272f 100644 --- a/src/compiler/nir/nir_opt_conditional_discard.c +++ b/src/compiler/nir/nir_opt_conditional_discard.c @@ -30,10 +30,8 @@ */ static bool -nir_opt_conditional_discard_block(nir_block *block, void *mem_ctx) +nir_opt_conditional_discard_block(nir_builder *b, nir_block *block) { - nir_builder bld; - if (nir_cf_node_is_first(&block->cf_node)) return false; @@ -88,17 +86,16 @@ nir_opt_conditional_discard_block(nir_block *block, void *mem_ctx) nir_src cond; - nir_builder_init(&bld, mem_ctx); - bld.cursor = nir_before_cf_node(prev_node); + b->cursor = nir_before_cf_node(prev_node); if (intrin->intrinsic == nir_intrinsic_discard) cond = if_stmt->condition; else - cond = nir_src_for_ssa(nir_iand(&bld, - nir_ssa_for_src(&bld, if_stmt->condition, 1), - nir_ssa_for_src(&bld, intrin->src[0], 1))); + cond = nir_src_for_ssa(nir_iand(b, + nir_ssa_for_src(b, if_stmt->condition, 1), + nir_ssa_for_src(b, intrin->src[0], 1))); nir_intrinsic_instr *discard_if = - nir_intrinsic_instr_create(mem_ctx, nir_intrinsic_discard_if); + nir_intrinsic_instr_create(b->shader, nir_intrinsic_discard_if); nir_src_copy(&discard_if->src[0], &cond, discard_if); nir_instr_insert_before_cf(prev_node, &discard_if->instr); @@ -113,11 +110,13 @@ nir_opt_conditional_discard(nir_shader *shader) { bool progress = false; + nir_builder builder; + nir_foreach_function(function, shader) { if (function->impl) { - void *mem_ctx = ralloc_parent(function->impl); + nir_builder_init(&builder, function->impl); nir_foreach_block_safe(block, function->impl) { - progress |= nir_opt_conditional_discard_block(block, mem_ctx); + progress |= nir_opt_conditional_discard_block(&builder, block); } } } -- 2.30.2