Signed-off-by: Connor Abbott <cwabbo...@gmail.com> --- src/compiler/nir/nir_lower_tex.c | 58 +++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 30 deletions(-)
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 4999603..7eebd6b 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -38,12 +38,6 @@ #include "nir.h" #include "nir_builder.h" -typedef struct { - nir_builder b; - const nir_lower_tex_options *options; - bool progress; -} lower_tex_state; - static void project_src(nir_builder *b, nir_tex_instr *tex) { @@ -276,26 +270,26 @@ swizzle_result(nir_builder *b, nir_tex_instr *tex, const uint8_t swizzle[4]) } static bool -nir_lower_tex_block(nir_block *block, void *void_state) +nir_lower_tex_block(nir_block *block, nir_builder *b, + const nir_lower_tex_options *options) { - lower_tex_state *state = void_state; - nir_builder *b = &state->b; + bool progress = false; nir_foreach_instr_safe(block, instr) { if (instr->type != nir_instr_type_tex) continue; nir_tex_instr *tex = nir_instr_as_tex(instr); - bool lower_txp = !!(state->options->lower_txp & (1 << tex->sampler_dim)); + bool lower_txp = !!(options->lower_txp & (1 << tex->sampler_dim)); /* mask of src coords to saturate (clamp): */ unsigned sat_mask = 0; - if ((1 << tex->sampler_index) & state->options->saturate_r) + if ((1 << tex->sampler_index) & options->saturate_r) sat_mask |= (1 << 2); /* .z */ - if ((1 << tex->sampler_index) & state->options->saturate_t) + if ((1 << tex->sampler_index) & options->saturate_t) sat_mask |= (1 << 1); /* .y */ - if ((1 << tex->sampler_index) & state->options->saturate_s) + if ((1 << tex->sampler_index) & options->saturate_s) sat_mask |= (1 << 0); /* .x */ /* If we are clamping any coords, we must lower projector first @@ -303,53 +297,57 @@ nir_lower_tex_block(nir_block *block, void *void_state) */ if (lower_txp || sat_mask) { project_src(b, tex); - state->progress = true; + progress = true; } if ((tex->sampler_dim == GLSL_SAMPLER_DIM_RECT) && - state->options->lower_rect) { + options->lower_rect) { lower_rect(b, tex); - state->progress = true; + progress = true; } if (sat_mask) { saturate_src(b, tex, sat_mask); - state->progress = true; + progress = true; } - if (((1 << tex->texture_index) & state->options->swizzle_result) && + if (((1 << tex->texture_index) & options->swizzle_result) && !nir_tex_instr_is_query(tex) && !(tex->is_shadow && tex->is_new_style_shadow)) { - swizzle_result(b, tex, state->options->swizzles[tex->texture_index]); - state->progress = true; + swizzle_result(b, tex, options->swizzles[tex->texture_index]); + progress = true; } } - return true; + return progress; } -static void -nir_lower_tex_impl(nir_function_impl *impl, lower_tex_state *state) +static bool +nir_lower_tex_impl(nir_function_impl *impl, + const nir_lower_tex_options *options) { - nir_builder_init(&state->b, impl); + bool progress = false; + nir_builder builder; + nir_builder_init(&builder, impl); - nir_foreach_block(impl, nir_lower_tex_block, state); + nir_foreach_block(impl, block) { + progress |= nir_lower_tex_block(block, &builder, options); + } nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + return progress; } bool nir_lower_tex(nir_shader *shader, const nir_lower_tex_options *options) { - lower_tex_state state; - state.options = options; - state.progress = false; + bool progress = false; nir_foreach_function(shader, function) { if (function->impl) - nir_lower_tex_impl(function->impl, &state); + progress |= nir_lower_tex_impl(function->impl, options); } - return state.progress; + return progress; } -- 2.5.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev