i965/fs: Track the binding table size in brw_wm_prog_data.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 15 Aug 2013 02:49:33 +0000 (19:49 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 19 Aug 2013 20:17:00 +0000 (13:17 -0700)
By tracking the maximum surface index used by the shader, we know just
how small we can make the binding table.

Since it depends entirely on the shader program, we can just compute
it once at compile time, rather than at binding table emit time (which
happens during drawing).

v2: Store binding_table_size, rather than max_surface_index, for
    consistency with the VS (which needs to be able to represent 0
    surfaces).

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_emit.cpp

index 909e0555ea1c1a75f01cf5500caf0d939cac0e5a..9178485cb5f227b643d92b164b1bd0420ad777be 100644 (file)
@@ -306,6 +306,8 @@ struct brw_wm_prog_data {
    GLuint reg_blocks_16;
    GLuint total_scratch;
 
+   unsigned binding_table_size;
+
    GLuint nr_params;       /**< number of float params/constants */
    GLuint nr_pull_params;
    bool dual_src_blend;
index 7feb2b680be505ae888c4d27d6289c21b0af2757..9d240b588ef14b146b0130a08e66c9c34dc35f77 100644 (file)
@@ -569,6 +569,8 @@ private:
                                  struct brw_reg offset,
                                  struct brw_reg value);
 
+   void mark_surface_used(unsigned surf_index);
+
    void patch_discard_jumps_to_fb_writes();
 
    struct brw_context *brw;
index b90cf0fb908a9c05f8cdee60a5c8720d7776d4dc..bfb3d331b0a7e962995f08d07218a59dca0c4160 100644 (file)
@@ -58,6 +58,15 @@ fs_generator::~fs_generator()
 {
 }
 
+void
+fs_generator::mark_surface_used(unsigned surf_index)
+{
+   assert(surf_index < BRW_MAX_WM_SURFACES);
+
+   c->prog_data.binding_table_size =
+      MAX2(c->prog_data.binding_table_size, surf_index + 1);
+}
+
 void
 fs_generator::patch_discard_jumps_to_fb_writes()
 {
@@ -175,6 +184,8 @@ fs_generator::generate_fb_write(fs_inst *inst)
                0,
                eot,
                inst->header_present);
+
+   mark_surface_used(SURF_INDEX_DRAW(inst->target));
 }
 
 /* Computes the integer pixel x,y values from the origin.
@@ -519,6 +530,8 @@ fs_generator::generate_tex(fs_inst *inst, struct brw_reg dst, struct brw_reg src
              inst->header_present,
              simd_mode,
              return_format);
+
+   mark_surface_used(SURF_INDEX_TEXTURE(inst->sampler));
 }
 
 
@@ -648,6 +661,8 @@ fs_generator::generate_uniform_pull_constant_load(fs_inst *inst,
 
    brw_oword_block_read(p, dst, brw_message_reg(inst->base_mrf),
                        read_offset, surf_index);
+
+   mark_surface_used(surf_index);
 }
 
 void
@@ -688,6 +703,8 @@ fs_generator::generate_uniform_pull_constant_load_gen7(fs_inst *inst,
                            false, /* no header */
                            BRW_SAMPLER_SIMD_MODE_SIMD4X2,
                            0);
+
+   mark_surface_used(surf_index);
 }
 
 void
@@ -753,6 +770,8 @@ fs_generator::generate_varying_pull_constant_load(fs_inst *inst,
                            inst->header_present,
                            simd_mode,
                            return_format);
+
+   mark_surface_used(surf_index);
 }
 
 void
@@ -795,6 +814,8 @@ fs_generator::generate_varying_pull_constant_load_gen7(fs_inst *inst,
                            false, /* no header */
                            simd_mode,
                            0);
+
+   mark_surface_used(surf_index);
 }
 
 /**
@@ -1040,6 +1061,8 @@ fs_generator::generate_shader_time_add(fs_inst *inst,
    brw_MOV(p, payload_value, value);
    brw_shader_time_add(p, payload, SURF_INDEX_WM_SHADER_TIME);
    brw_pop_insn_state(p);
+
+   mark_surface_used(SURF_INDEX_WM_SHADER_TIME);
 }
 
 void