[Mesa-dev] [PATCH 05/20] i965: Store gather table information in the program data

Abdiel Janulgue abdiel.janulgue at linux.intel.com
Fri Sep 11 01:33:19 PDT 2015


The resource streamer is able to gather and pack sparsely-located
constant data from any buffer object by a referring to a gather table
This patch adds support for keeping track of these constant data
fetches into a gather table.

The gather table is generated from two sources. Ordinary uniform fetches
are stored first. These are then combined with a separate table containing
UBO entries. The separate entry for UBOs is needed to make it easier to
generate the gather mask when combining and packing the constant data.

Signed-off-by: Abdiel Janulgue <abdiel.janulgue at linux.intel.com>
---
 src/mesa/drivers/dri/i965/brw_context.h  | 11 +++++++++++
 src/mesa/drivers/dri/i965/brw_gs.c       |  5 +++++
 src/mesa/drivers/dri/i965/brw_program.c  |  5 +++++
 src/mesa/drivers/dri/i965/brw_shader.cpp |  5 ++++-
 src/mesa/drivers/dri/i965/brw_shader.h   | 11 +++++++++++
 src/mesa/drivers/dri/i965/brw_vs.c       |  6 ++++++
 src/mesa/drivers/dri/i965/brw_wm.c       |  5 +++++
 7 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 33c49b7..de0db5a 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -364,9 +364,12 @@ struct brw_stage_prog_data {
    GLuint nr_params;       /**< number of float params/constants */
    GLuint nr_pull_params;
    unsigned nr_image_params;
+   unsigned nr_ubo_params;
+   unsigned nr_gather_table;
 
    unsigned curb_read_length;
    unsigned total_scratch;
+   unsigned max_ubo_const_block;
 
    /**
     * Register where the thread expects to find input data from the URB
@@ -385,6 +388,14 @@ struct brw_stage_prog_data {
    const gl_constant_value **param;
    const gl_constant_value **pull_param;
 
+   /** Combined gather table containing uniform and UBO entries */
+   struct {
+      int reg;
+      unsigned channel_mask;
+      unsigned const_block;
+      unsigned const_offset;
+   } *gather_table;
+
    /**
     * Image metadata passed to the shader as uniforms.  This is deliberately
     * ignored by brw_stage_prog_data_compare() because its contents don't have
diff --git a/src/mesa/drivers/dri/i965/brw_gs.c b/src/mesa/drivers/dri/i965/brw_gs.c
index 16ea684..17e87b8 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_gs.c
@@ -72,6 +72,11 @@ brw_codegen_gs_prog(struct brw_context *brw,
       rzalloc_array(NULL, struct brw_image_param, gs->NumImages);
    c.prog_data.base.base.nr_params = param_count;
    c.prog_data.base.base.nr_image_params = gs->NumImages;
+   c.prog_data.base.base.nr_gather_table = 0;
+   c.prog_data.base.base.gather_table =
+      rzalloc_size(NULL, sizeof(*c.prog_data.base.base.gather_table) *
+                   (c.prog_data.base.base.nr_params +
+                    c.prog_data.base.base.nr_ubo_params));
 
    if (brw->gen >= 7) {
       if (gp->program.OutputType == GL_POINTS) {
diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c
index 1ac0ed2..aa805be 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -558,6 +558,10 @@ brw_stage_prog_data_compare(const struct brw_stage_prog_data *a,
    if (memcmp(a->pull_param, b->pull_param, a->nr_pull_params * sizeof(void *)))
       return false;
 
+   if (memcmp(a->gather_table, b->gather_table,
+              a->nr_gather_table * sizeof(*a->gather_table)))
+      return false;
+
    return true;
 }
 
@@ -568,6 +572,7 @@ brw_stage_prog_data_free(const void *p)
 
    ralloc_free(prog_data->param);
    ralloc_free(prog_data->pull_param);
+   ralloc_free(prog_data->gather_table);
 }
 
 void
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index de1a7fe..9d45cfe 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -917,7 +917,10 @@ backend_shader::backend_shader(const struct brw_compiler *compiler,
      stage_prog_data(stage_prog_data),
      mem_ctx(mem_ctx),
      cfg(NULL),
-     stage(stage)
+     stage(stage),
+     use_gather_constants(false),
+     nr_ubo_gather_table(0),
+     ubo_gather_table(NULL)
 {
    debug_enabled = INTEL_DEBUG & intel_debug_flag_for_shader_stage(stage);
    stage_name = _mesa_shader_stage_to_string(stage);
diff --git a/src/mesa/drivers/dri/i965/brw_shader.h b/src/mesa/drivers/dri/i965/brw_shader.h
index ccccf4d..f0afce5 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.h
+++ b/src/mesa/drivers/dri/i965/brw_shader.h
@@ -275,6 +275,17 @@ public:
                                          unsigned n) = 0;
    void setup_image_uniform_values(unsigned param_offset,
                                    const gl_uniform_storage *storage);
+   bool use_gather_constants;
+   unsigned nr_ubo_gather_table;
+
+   /** Gather table for UBO entries only */
+   struct gather_table {
+      int reg;
+      unsigned channel_mask;
+      unsigned const_block;
+      unsigned const_offset;
+   };
+   gather_table *ubo_gather_table;
 };
 
 uint32_t brw_texture_offset(int *offsets, unsigned num_components);
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index 4e0d34f..8501796 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -141,6 +141,12 @@ brw_codegen_vs_prog(struct brw_context *brw,
                     stage_prog_data->nr_image_params);
    stage_prog_data->nr_params = param_count;
 
+   stage_prog_data->nr_gather_table = 0;
+   stage_prog_data->gather_table =
+      rzalloc_size(NULL, sizeof(*stage_prog_data->gather_table) *
+                   (stage_prog_data->nr_params +
+                    stage_prog_data->nr_ubo_params));
+
    GLbitfield64 outputs_written = vp->program.Base.OutputsWritten;
    prog_data.inputs_read = vp->program.Base.InputsRead;
 
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index 6ee9284..204baa6 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -208,6 +208,11 @@ brw_codegen_wm_prog(struct brw_context *brw,
                     prog_data.base.nr_image_params);
    prog_data.base.nr_params = param_count;
 
+   prog_data.base.nr_gather_table = 0;
+   prog_data.base.gather_table =
+      rzalloc_size(NULL, sizeof(*prog_data.base.gather_table) *
+                   (prog_data.base.nr_params + prog_data.base.nr_ubo_params));
+
    prog_data.barycentric_interp_modes =
       brw_compute_barycentric_interp_modes(brw, key->flat_shade,
                                            key->persample_shading,
-- 
1.9.1



More information about the mesa-dev mailing list