i965/vec4: Dynamically assign the VS/GS binding table offsets.
authorEric Anholt <eric@anholt.net>
Thu, 3 Oct 2013 16:55:06 +0000 (09:55 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 15 Oct 2013 17:18:48 +0000 (10:18 -0700)
Note that the dropped comment in brw_context.h is mostly (better written)
in brw_binding_table.c as well.

Reviewed-by: Paul Berry <stereotype441@gmail.com>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_vec4.cpp
src/mesa/drivers/dri/i965/brw_vec4_generator.cpp

index 4e26460267bfdf3e998571c50db2bb706f6a1f2f..68a786785657b9174c147e7ce1ba5a761830cf14 100644 (file)
@@ -678,62 +678,11 @@ struct brw_gs_prog_data
 /** Maximum number of actual buffers used for stream output */
 #define BRW_MAX_SOL_BUFFERS 4
 
-/**
- * Helpers to create Surface Binding Table indexes for draw buffers,
- * textures, and constant buffers.
- *
- * Shader threads access surfaces via numeric handles, rather than directly
- * using pointers.  The binding table maps these numeric handles to the
- * address of the actual buffer.
- *
- * For example, a shader might ask to sample from "surface 7."  In this case,
- * bind[7] would contain a pointer to a texture.
- *
- *
- * Our VS (and Gen7 GS) binding tables are programmed as follows:
- *
- *    +-----+-------------------------+
- *    |   0 | Pull Constant Buffer    |
- *    +-----+-------------------------+
- *    |   1 | Texture 0               |
- *    |   . |     .                   |
- *    |   : |     :                   |
- *    |  16 | Texture 15              |
- *    +-----+-------------------------+
- *    |  17 | UBO 0                   |
- *    |   . |     .                   |
- *    |   : |     :                   |
- *    |  28 | UBO 11                  |
- *    |-----|-------------------------|
- *    |  29 | Shader time buffer      |
- *    |-----|-------------------------|
- *    |  30 | Gather texture 0        |
- *    |   . |     .                   |
- *    |   : |     :                   |
- *    |  45 | Gather texture 15       |
- *    +-------------------------------+
- *
- * Our (gen6) GS binding tables are programmed as follows:
- *
- *    +-----+-------------------------+
- *    |   0 | SOL Binding 0           |
- *    |   . |     .                   |
- *    |   : |     :                   |
- *    |  63 | SOL Binding 63          |
- *    +-----+-------------------------+
- */
 #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))
-#define SURF_INDEX_VEC4_UBO(u)       (SURF_INDEX_VEC4_TEXTURE(BRW_MAX_TEX_UNIT) + u)
-#define SURF_INDEX_VEC4_SHADER_TIME  (SURF_INDEX_VEC4_UBO(12))
-#define SURF_INDEX_VEC4_GATHER_TEXTURE(t)   (SURF_INDEX_VEC4_SHADER_TIME + 1 + (t))
-#define BRW_MAX_VEC4_SURFACES        (SURF_INDEX_VEC4_GATHER_TEXTURE(BRW_MAX_TEX_UNIT))
-
 #define SURF_INDEX_GEN6_SOL_BINDING(t) (t)
 #define BRW_MAX_GEN6_GS_SURFACES       SURF_INDEX_GEN6_SOL_BINDING(BRW_MAX_SOL_BINDINGS)
 
index 14ba251d4fb28c32b64ad1c6a7a5682ed32faca4..6689a3d3c012e3207c1cfde1568a9997e9a30a73 100644 (file)
@@ -1424,11 +1424,30 @@ vec4_visitor::emit_shader_time_write(enum shader_time_shader_type type,
 void
 vec4_visitor::assign_binding_table_offsets()
 {
-   prog_data->base.binding_table.texture_start = SURF_INDEX_VEC4_TEXTURE(0);
-   prog_data->base.binding_table.ubo_start = SURF_INDEX_VEC4_UBO(0);
-   prog_data->base.binding_table.shader_time_start = SURF_INDEX_VEC4_SHADER_TIME;
-   prog_data->base.binding_table.gather_texture_start = SURF_INDEX_VEC4_GATHER_TEXTURE(0);
-   prog_data->base.binding_table.pull_constants_start = SURF_INDEX_VEC4_CONST_BUFFER;
+   int num_textures = _mesa_fls(prog->SamplersUsed);
+   int next = 0;
+
+   prog_data->base.binding_table.texture_start = next;
+   next += num_textures;
+
+   if (shader) {
+      prog_data->base.binding_table.ubo_start = next;
+      next += shader->base.NumUniformBlocks;
+   }
+
+   if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
+      prog_data->base.binding_table.shader_time_start = next;
+      next++;
+   }
+
+   if (prog->UsesGather) {
+      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. */
+   prog_data->base.binding_table.pull_constants_start = next;
+   next++;
 
    /* prog_data->base.binding_table.size will be set by mark_surface_used. */
 }
index ca5ac722bee029c5ffb29f7a6afdd3689c2602eb..1b597b55861af5b0682e53ae38f55377a1f91bdb 100644 (file)
@@ -155,7 +155,7 @@ vec4_generator::~vec4_generator()
 void
 vec4_generator::mark_surface_used(unsigned surf_index)
 {
-   assert(surf_index < BRW_MAX_VEC4_SURFACES);
+   assert(surf_index < BRW_MAX_SURFACES);
 
    prog_data->base.binding_table.size_bytes =
       MAX2(prog_data->base.binding_table.size_bytes, (surf_index + 1) * 4);