i965/fs: Handle zero-size allocations in fs_builder::vgrf().
authorFrancisco Jerez <currojerez@riseup.net>
Mon, 13 Jul 2015 12:39:03 +0000 (15:39 +0300)
committerFrancisco Jerez <currojerez@riseup.net>
Wed, 29 Jul 2015 11:12:49 +0000 (14:12 +0300)
This will be handy to avoid some ugly ternary operators in the next
patch, like:
 fs_reg reg = (size == 0 ? null_reg_ud() : vgrf(..., size));

Because a zero-size register allocation is guaranteed not to ever be
read or written we can just return the null register.  Another
possibility would be to actually allocate a zero-size VGRF what would
involve defining a zero-size register class in the register allocator
and a considerable amount of churn.

Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
src/mesa/drivers/dri/i965/brw_fs_builder.h

index eea1eae01298e234e6a3e4ad5fd59e423ffb0f52..e7d5f8a381d803b4a499bfadef582a585b74d962 100644 (file)
@@ -160,10 +160,13 @@ namespace brw {
       dst_reg
       vgrf(enum brw_reg_type type, unsigned n = 1) const
       {
-         return dst_reg(GRF, shader->alloc.allocate(
-                           DIV_ROUND_UP(n * type_sz(type) * dispatch_width(),
-                                        REG_SIZE)),
-                        type);
+         if (n > 0)
+            return dst_reg(GRF, shader->alloc.allocate(
+                              DIV_ROUND_UP(n * type_sz(type) * dispatch_width(),
+                                           REG_SIZE)),
+                           type);
+         else
+            return retype(null_reg_ud(), type);
       }
 
       /**