diff --git a/src/gallium/drivers/r300/compiler/r300_nir.c b/src/gallium/drivers/r300/compiler/r300_nir.c index b84f29e5f39..127ff6bd311 100644 --- a/src/gallium/drivers/r300/compiler/r300_nir.c +++ b/src/gallium/drivers/r300/compiler/r300_nir.c @@ -68,6 +68,8 @@ r300_optimize_nir(struct nir_shader *s, struct pipe_screen *screen) NIR_PASS(progress, s, nir_copy_prop); NIR_PASS(progress, s, nir_opt_algebraic); + if (s->info.stage == MESA_SHADER_VERTEX) + 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); diff --git a/src/gallium/drivers/r300/compiler/r300_nir.h b/src/gallium/drivers/r300/compiler/r300_nir.h index d1624b15269..f1f4184fe19 100644 --- a/src/gallium/drivers/r300/compiler/r300_nir.h +++ b/src/gallium/drivers/r300/compiler/r300_nir.h @@ -32,4 +32,6 @@ extern bool r300_transform_vs_trig_input(struct nir_shader *shader); extern bool r300_transform_fs_trig_input(struct nir_shader *shader); +extern bool r300_nir_fuse_fround_d3d9(struct nir_shader *shader); + #endif /* R300_NIR_H */ diff --git a/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py b/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py index 78e990710aa..c1647792771 100644 --- a/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py +++ b/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py @@ -43,6 +43,19 @@ transform_trig_input_fs_r500 = [ (('fcos', 'a'), ('fcos', ('ffract', ('fmul', 'a', 1 / (2 * pi))))), ] +# The is a pattern produced by wined3d for A0 register load. +# The specific pattern wined3d emits looks like this +# A0.x = (int(floor(abs(R0.x) + 0.5) * sign(R0.x))); +# however we lower both sign and floor so here we check for the already lowered +# sequence. +r300_nir_fuse_fround_d3d9 = [ + (('fmul', ('fadd', ('fadd', ('fabs', 'a') , 0.5), + ('fneg', ('ffract', ('fadd', ('fabs', 'a') , 0.5)))), + ('fadd', ('b2f', ('!flt', 0.0, 'a')), + ('fneg', ('b2f', ('!flt', 'a', 0.0))))), + ('fround_even', 'a')) +] + def main(): parser = argparse.ArgumentParser() parser.add_argument('-p', '--import-path', required=True) @@ -61,6 +74,8 @@ def main(): f.write(nir_algebraic.AlgebraicPass("r300_transform_fs_trig_input", transform_trig_input_fs_r500).render()) + f.write(nir_algebraic.AlgebraicPass("r300_nir_fuse_fround_d3d9", + r300_nir_fuse_fround_d3d9).render()) if __name__ == '__main__': main()