static void
r300_optimize_nir(struct nir_shader *s, struct pipe_screen *screen)
{
+ bool is_r500 = r300_screen(screen)->caps.is_r500;
+
bool progress;
do {
progress = false;
NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_algebraic);
- if (s->info.stage == MESA_SHADER_VERTEX)
+ if (s->info.stage == MESA_SHADER_VERTEX) {
+ if (!is_r500)
+ NIR_PASS(progress, s, r300_nir_lower_bool_to_float);
NIR_PASS(progress, s, r300_nir_fuse_fround_d3d9);
+ }
NIR_PASS(progress, s, nir_opt_constant_folding);
NIR_PASS(progress, s, nir_opt_remove_phis);
NIR_PASS(progress, s, nir_opt_conditional_discard);
NIR_PASS(progress, s, nir_opt_dead_write_vars);
NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
- NIR_PASS(progress, s, nir_opt_peephole_select,
- r300_screen(screen)->caps.is_r500 ? 8 : ~0 , true, true);
+ NIR_PASS(progress, s, nir_opt_peephole_select, is_r500 ? 8 : ~0, true, true);
NIR_PASS(progress, s, nir_opt_algebraic);
NIR_PASS(progress, s, nir_opt_constant_folding);
nir_load_store_vectorize_options vectorize_opts = {
import sys
from math import pi
+# Convenience variables
+a = 'a'
+b = 'b'
+c = 'c'
+d = 'd'
+e = 'e'
+
# Transform input to range [-PI, PI]:
#
# y = frac(x / 2PI + 0.5) * 2PI - PI
sys.path.insert(0, args.import_path)
import nir_algebraic # pylint: disable=import-error
+ ignore_exact = nir_algebraic.ignore_exact
+
+ r300_nir_lower_bool_to_float = [
+ (('bcsel@32(is_only_used_as_float)', ignore_exact('feq', 'a@32', 'b@32'), c, d),
+ ('fadd', ('fmul', c, ('seq', a, b)), ('fsub', d, ('fmul', d, ('seq', a, b)))),
+ "!options->has_fused_comp_and_csel"),
+ (('bcsel@32(is_only_used_as_float)', ignore_exact('fneu', 'a@32', 'b@32'), c, d),
+ ('fadd', ('fmul', c, ('sne', a, b)), ('fsub', d, ('fmul', d, ('sne', a, b)))),
+ "!options->has_fused_comp_and_csel"),
+ (('bcsel@32(is_only_used_as_float)', ignore_exact('flt', 'a@32', 'b@32'), c, d),
+ ('fadd', ('fmul', c, ('slt', a, b)), ('fsub', d, ('fmul', d, ('slt', a, b)))),
+ "!options->has_fused_comp_and_csel"),
+ (('bcsel@32(is_only_used_as_float)', ignore_exact('fge', 'a@32', 'b@32'), c, d),
+ ('fadd', ('fmul', c, ('sge', a, b)), ('fsub', d, ('fmul', d, ('sge', a, b)))),
+ "!options->has_fused_comp_and_csel"),
+]
with open(args.output, 'w') as f:
f.write('#include "compiler/r300_nir.h"')
f.write(nir_algebraic.AlgebraicPass("r300_nir_fuse_fround_d3d9",
r300_nir_fuse_fround_d3d9).render())
+ f.write(nir_algebraic.AlgebraicPass("r300_nir_lower_bool_to_float",
+ r300_nir_lower_bool_to_float).render())
+
if __name__ == '__main__':
main()