i965: Don't add base_binding_table_index if it's zero
authorNeil Roberts <neil@linux.intel.com>
Fri, 29 May 2015 12:41:48 +0000 (13:41 +0100)
committerNeil Roberts <neil@linux.intel.com>
Sat, 30 May 2015 23:48:57 +0000 (00:48 +0100)
When calculating the binding table index for non-constant sampler
array indexing it needs to add the base binding table index which is a
constant within the generated code. Often this base is zero so we can
avoid a redundant instruction in that case.

It looks like nothing in shader-db is doing non-constant sampler array
indexing so this patch doesn't make any difference but it might be
worth having anyway.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
Acked-by: Ben Widawsky <ben@bwidawsk.net>
src/mesa/drivers/dri/i965/brw_fs_generator.cpp
src/mesa/drivers/dri/i965/brw_vec4_generator.cpp

index ea46b1a19179abca8282168ea1b45d39fd0a9f32..40a3db3040e54cb8071ceae66eb0084fd5893100 100644 (file)
@@ -789,7 +789,8 @@ fs_generator::generate_tex(fs_inst *inst, struct brw_reg dst, struct brw_reg src
 
       /* addr = ((sampler * 0x101) + base_binding_table_index) & 0xfff */
       brw_MUL(p, addr, sampler_reg, brw_imm_ud(0x101));
-      brw_ADD(p, addr, addr, brw_imm_ud(base_binding_table_index));
+      if (base_binding_table_index)
+         brw_ADD(p, addr, addr, brw_imm_ud(base_binding_table_index));
       brw_AND(p, addr, addr, brw_imm_ud(0xfff));
 
       brw_pop_insn_state(p);
index 9699607ed281febf38da3db8b0d49f4afb0d87c8..ead620b3c00bd277b2b2123bf72670840d6d7d2a 100644 (file)
@@ -408,7 +408,8 @@ vec4_generator::generate_tex(vec4_instruction *inst,
 
       /* addr = ((sampler * 0x101) + base_binding_table_index) & 0xfff */
       brw_MUL(p, addr, sampler_reg, brw_imm_ud(0x101));
-      brw_ADD(p, addr, addr, brw_imm_ud(base_binding_table_index));
+      if (base_binding_table_index)
+         brw_ADD(p, addr, addr, brw_imm_ud(base_binding_table_index));
       brw_AND(p, addr, addr, brw_imm_ud(0xfff));
 
       brw_pop_insn_state(p);