i965/fs: Dynamically set up the WM binding table offsets.
authorEric Anholt <eric@anholt.net>
Thu, 3 Oct 2013 01:53:04 +0000 (18:53 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 15 Oct 2013 17:18:45 +0000 (10:18 -0700)
Reviewed-by: Paul Berry <stereotype441@gmail.com>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs_generator.cpp

index 222fdc2d0b0f07143b3384198a488cc0e143b9ea..4e26460267bfdf3e998571c50db2bb706f6a1f2f 100644 (file)
@@ -689,33 +689,6 @@ struct brw_gs_prog_data
  * For example, a shader might ask to sample from "surface 7."  In this case,
  * bind[7] would contain a pointer to a texture.
  *
- * Currently, our WM binding tables are (arbitrarily) programmed as follows:
- *
- *    +-------------------------------+
- *    |   0 | Draw buffer 0           |
- *    |   . |     .                   |
- *    |   : |     :                   |
- *    |   7 | Draw buffer 7           |
- *    |-----|-------------------------|
- *    |   8 | WM Pull Constant Buffer |
- *    |-----|-------------------------|
- *    |   9 | Texture 0               |
- *    |   . |     .                   |
- *    |   : |     :                   |
- *    |  24 | Texture 15              |
- *    |-----|-------------------------|
- *    |  25 | UBO 0                   |
- *    |   . |     .                   |
- *    |   : |     :                   |
- *    |  36 | UBO 11                  |
- *    |-----|-------------------------|
- *    |  37 | Shader time buffer      |
- *    |-----|-------------------------|
- *    |  38 | Gather texture 0        |
- *    |   . |     .                   |
- *    |   : |     :                   |
- *    |  53 | Gather texture 15       |
- *    +-------------------------------+
  *
  * Our VS (and Gen7 GS) binding tables are programmed as follows:
  *
@@ -749,14 +722,10 @@ struct brw_gs_prog_data
  *    |  63 | SOL Binding 63          |
  *    +-----+-------------------------+
  */
-#define SURF_INDEX_DRAW(d)           (d)
-#define SURF_INDEX_FRAG_CONST_BUFFER (BRW_MAX_DRAW_BUFFERS + 1)
-#define SURF_INDEX_TEXTURE(t)        (BRW_MAX_DRAW_BUFFERS + 2 + (t))
-#define SURF_INDEX_WM_UBO(u)         (SURF_INDEX_TEXTURE(BRW_MAX_TEX_UNIT) + u)
-#define SURF_INDEX_WM_SHADER_TIME    (SURF_INDEX_WM_UBO(12))
-#define SURF_INDEX_GATHER_TEXTURE(t) (SURF_INDEX_WM_SHADER_TIME + 1 + (t))
-/** Maximum size of the binding table. */
-#define BRW_MAX_WM_SURFACES          (SURF_INDEX_GATHER_TEXTURE(BRW_MAX_TEX_UNIT))
+#define BRW_MAX_SURFACES   (BRW_MAX_DRAW_BUFFERS +                      \
+                            BRW_MAX_TEX_UNIT * 2 + /* normal, gather */ \
+                            12 + /* ubo */                              \
+                            2 /* shader time, pull constants */)
 
 #define SURF_INDEX_VEC4_CONST_BUFFER (0)
 #define SURF_INDEX_VEC4_TEXTURE(t)   (SURF_INDEX_VEC4_CONST_BUFFER + 1 + (t))
@@ -985,7 +954,7 @@ struct brw_stage_state
 
    /* Binding table: pointers to SURFACE_STATE entries. */
    uint32_t bind_bo_offset;
-   uint32_t surf_offset[BRW_MAX_WM_SURFACES];
+   uint32_t surf_offset[BRW_MAX_SURFACES];
 
    /** SAMPLER_STATE count and table offset */
    uint32_t sampler_count;
index 265b4aaa050d955735ae7b535d23671edb839450..4d83c079c988e5822acc5ccf6d8c13f9dd4dcede 100644 (file)
@@ -2981,12 +2981,35 @@ fs_visitor::setup_payload_gen6()
 void
 fs_visitor::assign_binding_table_offsets()
 {
-   c->prog_data.binding_table.render_target_start = SURF_INDEX_DRAW(0);
-   c->prog_data.base.binding_table.texture_start = SURF_INDEX_TEXTURE(0);
-   c->prog_data.base.binding_table.ubo_start = SURF_INDEX_WM_UBO(0);
-   c->prog_data.base.binding_table.shader_time_start = SURF_INDEX_WM_SHADER_TIME;
-   c->prog_data.base.binding_table.gather_texture_start = SURF_INDEX_GATHER_TEXTURE(0);
-   c->prog_data.base.binding_table.pull_constants_start = SURF_INDEX_FRAG_CONST_BUFFER;
+   int num_textures = _mesa_fls(fp->Base.SamplersUsed);
+   int next = 0;
+
+   c->prog_data.binding_table.render_target_start = next;
+   next += c->key.nr_color_regions;
+
+   c->prog_data.base.binding_table.texture_start = next;
+   next += num_textures;
+
+   if (shader) {
+      c->prog_data.base.binding_table.ubo_start = next;
+      next += shader->base.NumUniformBlocks;
+   }
+
+   if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
+      c->prog_data.base.binding_table.shader_time_start = next;
+      next++;
+   }
+
+   if (fp->Base.UsesGather) {
+      c->prog_data.base.binding_table.gather_texture_start = next;
+      next += num_textures;
+   }
+
+   /* This may or may not be used depending on how the compile goes. */
+   c->prog_data.base.binding_table.pull_constants_start = next;
+   next++;
+
+   assert(next < BRW_MAX_SURFACES);
 
    /* c->prog_data.base.binding_table.size will be set by mark_surface_used. */
 }
index 05145d0880873463f46312f66531407ef3dd260b..fa15f7bac20d273012694d7fbc9b4e351cf5d117 100644 (file)
@@ -61,7 +61,7 @@ fs_generator::~fs_generator()
 void
 fs_generator::mark_surface_used(unsigned surf_index)
 {
-   assert(surf_index < BRW_MAX_WM_SURFACES);
+   assert(surf_index < BRW_MAX_SURFACES);
 
    c->prog_data.base.binding_table.size_bytes =
       MAX2(c->prog_data.base.binding_table.size_bytes, (surf_index + 1) * 4);