i965: Track ARB program state along with GLSL state for shader_time.
authorEric Anholt <eric@anholt.net>
Tue, 19 Mar 2013 21:27:42 +0000 (14:27 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 28 Mar 2013 18:46:01 +0000 (11:46 -0700)
This will let us do much better printouts for non-GLSL programs.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_program.c
src/mesa/drivers/dri/i965/brw_vec4.cpp
src/mesa/drivers/dri/i965/brw_vec4.h

index 8ff70c96acb5c654ffeed34dc1f3bb6f07d0b172..1e2b8fc42345045cc28012611f0bfb30f7e12789 100644 (file)
@@ -1123,7 +1123,8 @@ struct brw_context
 
    struct {
       drm_intel_bo *bo;
-      struct gl_shader_program **programs;
+      struct gl_shader_program **shader_programs;
+      struct gl_program **programs;
       enum shader_time_shader_type *types;
       uint64_t *cumulative;
       int num_entries;
@@ -1187,6 +1188,10 @@ int brw_get_scratch_size(int size);
 void brw_get_scratch_bo(struct intel_context *intel,
                        drm_intel_bo **scratch_bo, int size);
 void brw_init_shader_time(struct brw_context *brw);
+int brw_get_shader_time_index(struct brw_context *brw,
+                              struct gl_shader_program *shader_prog,
+                              struct gl_program *prog,
+                              enum shader_time_shader_type type);
 void brw_collect_and_report_shader_time(struct brw_context *brw);
 void brw_destroy_shader_time(struct brw_context *brw);
 
index ecce66bc090cf0ef3837614d52256a0d4bad3385..01a1ec06ac03312222a8ee5a621439178c53a8d4 100644 (file)
@@ -605,18 +605,8 @@ void
 fs_visitor::emit_shader_time_write(enum shader_time_shader_type type,
                                    fs_reg value)
 {
-   /* Choose an index in the buffer and set up tracking information for our
-    * printouts.
-    */
-   int shader_time_index = brw->shader_time.num_entries++;
-   assert(shader_time_index <= brw->shader_time.max_entries);
-   brw->shader_time.types[shader_time_index] = type;
-   if (prog) {
-      _mesa_reference_shader_program(ctx,
-                                     &brw->shader_time.programs[shader_time_index],
-                                     prog);
-   }
-
+   int shader_time_index = brw_get_shader_time_index(brw, prog, &fp->Base,
+                                                     type);
    int base_mrf = 6;
 
    fs_reg offset_mrf = fs_reg(MRF, base_mrf);
index 254a53432c889332d781d1cb6a2866bfefd2ee52..1fabec45cf8cb778dd30c9796e92d50d6a36d2ea 100644 (file)
@@ -424,7 +424,7 @@ public:
    void dump_instructions();
    void dump_instruction(fs_inst *inst);
 
-   const struct gl_fragment_program *fp;
+   struct gl_fragment_program *fp;
    struct brw_wm_compile *c;
    unsigned int sanity_param_count;
 
index 62954d3cf7863f2eaa6225e5d02d11bcf95cc21f..7a1b3f2285386d87fedc09627ce0209e6c4d42b1 100644 (file)
@@ -230,7 +230,9 @@ brw_init_shader_time(struct brw_context *brw)
    brw->shader_time.bo = drm_intel_bo_alloc(intel->bufmgr, "shader time",
                                             max_entries * SHADER_TIME_STRIDE,
                                             4096);
-   brw->shader_time.programs = rzalloc_array(brw, struct gl_shader_program *,
+   brw->shader_time.shader_programs = rzalloc_array(brw, struct gl_shader_program *,
+                                                    max_entries);
+   brw->shader_time.programs = rzalloc_array(brw, struct gl_program *,
                                              max_entries);
    brw->shader_time.types = rzalloc_array(brw, enum shader_time_shader_type,
                                           max_entries);
@@ -369,8 +371,8 @@ brw_report_shader_time(struct brw_context *brw)
          continue;
 
       int shader_num = -1;
-      if (brw->shader_time.programs[i]) {
-         shader_num = brw->shader_time.programs[i]->Name;
+      if (brw->shader_time.shader_programs[i]) {
+         shader_num = brw->shader_time.shader_programs[i]->Name;
       }
 
       switch (brw->shader_time.types[i]) {
@@ -431,6 +433,36 @@ brw_collect_and_report_shader_time(struct brw_context *brw)
    }
 }
 
+/**
+ * Chooses an index in the shader_time buffer and sets up tracking information
+ * for our printouts.
+ *
+ * Note that this holds on to references to the underlying programs, which may
+ * change their lifetimes compared to normal operation.
+ */
+int
+brw_get_shader_time_index(struct brw_context *brw,
+                          struct gl_shader_program *shader_prog,
+                          struct gl_program *prog,
+                          enum shader_time_shader_type type)
+{
+   struct gl_context *ctx = &brw->intel.ctx;
+
+   int shader_time_index = brw->shader_time.num_entries++;
+   assert(shader_time_index < brw->shader_time.max_entries);
+   brw->shader_time.types[shader_time_index] = type;
+
+   _mesa_reference_shader_program(ctx,
+                                  &brw->shader_time.shader_programs[shader_time_index],
+                                  shader_prog);
+
+   _mesa_reference_program(ctx,
+                           &brw->shader_time.programs[shader_time_index],
+                           prog);
+
+   return shader_time_index;
+}
+
 void
 brw_destroy_shader_time(struct brw_context *brw)
 {
index 9ab599f4b2115bb186a6ccb2b4ce059addf7bef8..2756b71d9fcc75a6f8d38e1da0a4dab6f9f9bad1 100644 (file)
@@ -1225,17 +1225,8 @@ void
 vec4_visitor::emit_shader_time_write(enum shader_time_shader_type type,
                                      src_reg value)
 {
-   /* Choose an index in the buffer and set up tracking information for our
-    * printouts.
-    */
-   int shader_time_index = brw->shader_time.num_entries++;
-   assert(shader_time_index <= brw->shader_time.max_entries);
-   brw->shader_time.types[shader_time_index] = type;
-   if (prog) {
-      _mesa_reference_shader_program(ctx,
-                                     &brw->shader_time.programs[shader_time_index],
-                                     prog);
-   }
+   int shader_time_index = brw_get_shader_time_index(brw, prog, &vp->Base,
+                                                     type);
 
    int base_mrf = 6;
 
index 7d4ade50ccb6e89fd84f1671286257ce561ae968..61e18a66a404f132a08d1eddb9d847ab7d28b0c4 100644 (file)
@@ -224,7 +224,7 @@ public:
       return dst_reg(retype(brw_null_reg(), BRW_REGISTER_TYPE_D));
    }
 
-   const struct gl_vertex_program *vp;
+   struct gl_vertex_program *vp;
    struct brw_vs_compile *c;
    struct brw_vs_prog_data *prog_data;
    unsigned int sanity_param_count;