i965/fs: Lower 32x32 bit multiplication on BXT.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_lower_unnormalized_offset.cpp
index 0581e0539aeeb57693a4f8bb51c726cde2f7602a..8c59b9e415bf2ca90ebc0154c358752e3a3ffae3 100644 (file)
@@ -52,11 +52,39 @@ public:
 ir_visitor_status
 brw_lower_unnormalized_offset_visitor::visit_leave(ir_texture *ir)
 {
-   if (ir->sampler->type->sampler_dimensionality != GLSL_SAMPLER_DIM_RECT ||
-       !ir->offset || ir->op != ir_tg4)
+   if (!ir->offset)
       return visit_continue;
 
-   ir->coordinate = add(ir->coordinate, i2f(ir->offset));
+   if (ir->op == ir_tg4 || ir->op == ir_tex) {
+      if (ir->sampler->type->sampler_dimensionality != GLSL_SAMPLER_DIM_RECT)
+         return visit_continue;
+   }
+   else if (ir->op != ir_txf) {
+      return visit_continue;
+   }
+
+   void *mem_ctx = ralloc_parent(ir);
+
+   if (ir->op == ir_txf) {
+      /* It appears that the ld instruction used for txf does its
+       * address bounds check before adding in the offset.  To work
+       * around this, just add the integer offset to the integer texel
+       * coordinate, and don't put the offset in the header.
+       */
+      ir_variable *var = new(mem_ctx) ir_variable(ir->coordinate->type,
+                                                  "coordinate",
+                                                  ir_var_temporary);
+      base_ir->insert_before(var);
+      base_ir->insert_before(assign(var, ir->coordinate));
+      base_ir->insert_before(assign(var,
+               add(swizzle_for_size(var, ir->offset->type->vector_elements), ir->offset),
+               (1 << ir->offset->type->vector_elements) - 1));
+
+      ir->coordinate = new(mem_ctx) ir_dereference_variable(var);
+   } else {
+      ir->coordinate = add(ir->coordinate, i2f(ir->offset));
+   }
+
    ir->offset = NULL;
 
    progress = true;