[Mesa-dev] [PATCH 2/2] i965: Don't add base_binding_table_index if it's zero

Neil Roberts neil at linux.intel.com
Fri May 29 06:53:35 PDT 2015


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.
---
 src/mesa/drivers/dri/i965/brw_fs_generator.cpp   | 3 ++-
 src/mesa/drivers/dri/i965/brw_vec4_generator.cpp | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
index ea46b1a..40a3db3 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
@@ -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);
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
index 1d3f5ed..cf1aa83 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
@@ -409,7 +409,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);
-- 
1.9.3



More information about the mesa-dev mailing list