i965: Move the common binding table offset code to brw_shader.cpp.
authorEric Anholt <eric@anholt.net>
Thu, 3 Oct 2013 16:58:43 +0000 (09:58 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 15 Oct 2013 17:18:50 +0000 (10:18 -0700)
Now that both vec4 and fs are dynamically assigning offsets, a lot of the
code is the same.

v2: Avoid passing around the next offset through the class.  (Review by
    Paul)

Reviewed-by: Paul Berry <stereotype441@gmail.com>
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
src/mesa/drivers/dri/i965/brw_shader.cpp
src/mesa/drivers/dri/i965/brw_shader.h
src/mesa/drivers/dri/i965/brw_vec4.cpp
src/mesa/drivers/dri/i965/brw_vec4.h
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp

index 4d83c079c988e5822acc5ccf6d8c13f9dd4dcede..aec6fc7f38ed0e1514b5ae997c98b7f2cc499072 100644 (file)
@@ -2981,37 +2981,12 @@ fs_visitor::setup_payload_gen6()
 void
 fs_visitor::assign_binding_table_offsets()
 {
-   int num_textures = _mesa_fls(fp->Base.SamplersUsed);
-   int next = 0;
+   uint32_t next_binding_table_offset = 0;
 
-   c->prog_data.binding_table.render_target_start = next;
-   next += c->key.nr_color_regions;
+   c->prog_data.binding_table.render_target_start = next_binding_table_offset;
+   next_binding_table_offset += 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. */
+   assign_common_binding_table_offsets(next_binding_table_offset);
 }
 
 bool
index b4fff50139fe40f7c330f9abf44363a2d9d87722..9f37013bddf587b3d930b7ce93ddcb24c6077d95 100644 (file)
@@ -2669,8 +2669,10 @@ fs_visitor::fs_visitor(struct brw_context *brw,
    this->c = c;
    this->brw = brw;
    this->fp = fp;
+   this->prog = &fp->Base;
    this->shader_prog = shader_prog;
    this->prog = &fp->Base;
+   this->stage_prog_data = &c->prog_data.base;
    this->ctx = &brw->ctx;
    this->mem_ctx = ralloc_context(NULL);
    if (shader_prog)
index 256f9b21e4ce3cddd740acad19b2665f9a0bc8f6..5992a1c33b5c55f22e7cd2f2abfdbe322fb34e7b 100644 (file)
@@ -597,3 +597,50 @@ backend_visitor::dump_instructions()
       dump_instruction(inst);
    }
 }
+
+
+/**
+ * Sets up the starting offsets for the groups of binding table entries
+ * commong to all pipeline stages.
+ *
+ * Unused groups are initialized to 0xd0d0d0d0 to make it obvious that they're
+ * unused but also make sure that addition of small offsets to them will
+ * trigger some of our asserts that surface indices are < BRW_MAX_SURFACES.
+ */
+void
+backend_visitor::assign_common_binding_table_offsets(uint32_t next_binding_table_offset)
+{
+   int num_textures = _mesa_fls(prog->SamplersUsed);
+
+   stage_prog_data->binding_table.texture_start = next_binding_table_offset;
+   next_binding_table_offset += num_textures;
+
+   if (shader) {
+      stage_prog_data->binding_table.ubo_start = next_binding_table_offset;
+      next_binding_table_offset += shader->base.NumUniformBlocks;
+   } else {
+      stage_prog_data->binding_table.ubo_start = 0xd0d0d0d0;
+   }
+
+   if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
+      stage_prog_data->binding_table.shader_time_start = next_binding_table_offset;
+      next_binding_table_offset++;
+   } else {
+      stage_prog_data->binding_table.shader_time_start = 0xd0d0d0d0;
+   }
+
+   if (prog->UsesGather) {
+      stage_prog_data->binding_table.gather_texture_start = next_binding_table_offset;
+      next_binding_table_offset += num_textures;
+   } else {
+      stage_prog_data->binding_table.gather_texture_start = 0xd0d0d0d0;
+   }
+
+   /* This may or may not be used depending on how the compile goes. */
+   stage_prog_data->binding_table.pull_constants_start = next_binding_table_offset;
+   next_binding_table_offset++;
+
+   assert(next_binding_table_offset <= BRW_MAX_SURFACES);
+
+   /* prog_data->base.binding_table.size will be set by mark_surface_used. */
+}
index 8b2d7a7ad17154a121df7b686dc2c0b9881f0b46..7cebf1ffdd1a61d5c7bc33f1c7b675e6c2de36b7 100644 (file)
@@ -60,6 +60,7 @@ public:
    struct brw_shader *shader;
    struct gl_shader_program *shader_prog;
    struct gl_program *prog;
+   struct brw_stage_prog_data *stage_prog_data;
 
    /** ralloc context for temporary data used during compile */
    void *mem_ctx;
@@ -72,6 +73,8 @@ public:
 
    virtual void dump_instruction(backend_instruction *inst) = 0;
    void dump_instructions();
+
+   void assign_common_binding_table_offsets(uint32_t next_binding_table_offset);
 };
 
 uint32_t brw_texture_offset(ir_constant *offset);
index 6689a3d3c012e3207c1cfde1568a9997e9a30a73..d3ee9a1f4c9327dd0b8f202ac4dd110c234ac754 100644 (file)
@@ -1421,37 +1421,6 @@ vec4_visitor::emit_shader_time_write(enum shader_time_shader_type type,
    emit(SHADER_OPCODE_SHADER_TIME_ADD, dst_reg(), src_reg(dst));
 }
 
-void
-vec4_visitor::assign_binding_table_offsets()
-{
-   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. */
-}
-
 bool
 vec4_visitor::run()
 {
@@ -1460,7 +1429,7 @@ vec4_visitor::run()
    if (INTEL_DEBUG & DEBUG_SHADER_TIME)
       emit_shader_time_begin();
 
-   assign_binding_table_offsets();
+   assign_common_binding_table_offsets(0);
 
    emit_prolog();
 
index 647ebe126a506d09eefba91234548138cfc83543..41d91e5c49df2379ea70f1cc51c66ad43c7b8fdc 100644 (file)
@@ -337,7 +337,6 @@ public:
    bool run(void);
    void fail(const char *msg, ...);
 
-   void assign_binding_table_offsets();
    int virtual_grf_alloc(int size);
    void setup_uniform_clipplane_values();
    void setup_uniform_values(ir_variable *ir);
index 4b9e7879a2c8a214c44bb4dda0878429ecfec69e..231815f12d4d100abcbb055b115f7c6436cf3bb7 100644 (file)
@@ -3162,6 +3162,7 @@ vec4_visitor::vec4_visitor(struct brw_context *brw,
    this->prog = prog;
    this->key = key;
    this->prog_data = prog_data;
+   this->stage_prog_data = &prog_data->base;
 
    this->variable_ht = hash_table_ctor(0,
                                       hash_table_pointer_hash,