Browse Source

pstats pixel count for tinydisplay

David Rose 17 years ago
parent
commit
85d94ff0c5

+ 1 - 0
panda/src/pstatclient/pStatProperties.cxx

@@ -185,6 +185,7 @@ static LevelCollectorProperties level_properties[] = {
   { 1, "Vertices:Indexed triangle strips", { 0.5, 0.2, 0.8 } },
   { 1, "Vertices:Indexed triangle strips", { 0.5, 0.2, 0.8 } },
   { 1, "Vertices:Display lists",           { 0.8, 0.5, 1.0 } },
   { 1, "Vertices:Display lists",           { 0.8, 0.5, 1.0 } },
   { 1, "Vertices:Immediate mode",          { 1.0, 0.5, 0.0 } },
   { 1, "Vertices:Immediate mode",          { 1.0, 0.5, 0.0 } },
+  { 1, "Pixels",                           { 0.8, 0.3, 0.7 },  "M", 5, 1000000 },
   { 1, "Nodes",                            { 0.4, 0.2, 0.8 },  "", 500.0 },
   { 1, "Nodes",                            { 0.4, 0.2, 0.8 },  "", 500.0 },
   { 1, "Nodes:GeomNodes",                  { 0.8, 0.2, 0.0 } },
   { 1, "Nodes:GeomNodes",                  { 0.8, 0.2, 0.0 } },
   { 1, "Geoms",                            { 0.4, 0.8, 0.3 },  "", 500.0 },
   { 1, "Geoms",                            { 0.4, 0.8, 0.3 },  "", 500.0 },

+ 56 - 0
panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx

@@ -32,6 +32,15 @@ TypeHandle TinyGraphicsStateGuardian::_type_handle;
 
 
 PStatCollector TinyGraphicsStateGuardian::_vertices_immediate_pcollector("Vertices:Immediate mode");
 PStatCollector TinyGraphicsStateGuardian::_vertices_immediate_pcollector("Vertices:Immediate mode");
 PStatCollector TinyGraphicsStateGuardian::_draw_transform_pcollector("Draw:Transform");
 PStatCollector TinyGraphicsStateGuardian::_draw_transform_pcollector("Draw:Transform");
+PStatCollector TinyGraphicsStateGuardian::_pixel_count_white_untextured_pcollector("Pixels:White untextured");
+PStatCollector TinyGraphicsStateGuardian::_pixel_count_flat_untextured_pcollector("Pixels:Flat untextured");
+PStatCollector TinyGraphicsStateGuardian::_pixel_count_smooth_untextured_pcollector("Pixels:Smooth untextured");
+PStatCollector TinyGraphicsStateGuardian::_pixel_count_white_textured_pcollector("Pixels:White textured");
+PStatCollector TinyGraphicsStateGuardian::_pixel_count_flat_textured_pcollector("Pixels:Flat textured");
+PStatCollector TinyGraphicsStateGuardian::_pixel_count_smooth_textured_pcollector("Pixels:Smooth textured");
+PStatCollector TinyGraphicsStateGuardian::_pixel_count_white_perspective_pcollector("Pixels:White perspective");
+PStatCollector TinyGraphicsStateGuardian::_pixel_count_flat_perspective_pcollector("Pixels:Flat perspective");
+PStatCollector TinyGraphicsStateGuardian::_pixel_count_smooth_perspective_pcollector("Pixels:Smooth perspective");
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: TinyGraphicsStateGuardian::Constructor
 //     Function: TinyGraphicsStateGuardian::Constructor
@@ -341,6 +350,16 @@ begin_frame(Thread *current_thread) {
 
 
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
   _vertices_immediate_pcollector.clear_level();
   _vertices_immediate_pcollector.clear_level();
+
+  _pixel_count_white_untextured_pcollector.clear_level();
+  _pixel_count_flat_untextured_pcollector.clear_level();
+  _pixel_count_smooth_untextured_pcollector.clear_level();
+  _pixel_count_white_textured_pcollector.clear_level();
+  _pixel_count_flat_textured_pcollector.clear_level();
+  _pixel_count_smooth_textured_pcollector.clear_level();
+  _pixel_count_white_perspective_pcollector.clear_level();
+  _pixel_count_flat_perspective_pcollector.clear_level();
+  _pixel_count_smooth_perspective_pcollector.clear_level();
 #endif
 #endif
 
 
   return true;
   return true;
@@ -424,9 +443,21 @@ void TinyGraphicsStateGuardian::
 end_frame(Thread *current_thread) {
 end_frame(Thread *current_thread) {
   GraphicsStateGuardian::end_frame(current_thread);
   GraphicsStateGuardian::end_frame(current_thread);
 
 
+#ifdef DO_PSTATS
   // Flush any PCollectors specific to this kind of GSG.
   // Flush any PCollectors specific to this kind of GSG.
   _vertices_immediate_pcollector.flush_level();
   _vertices_immediate_pcollector.flush_level();
 
 
+  _pixel_count_white_untextured_pcollector.flush_level();
+  _pixel_count_flat_untextured_pcollector.flush_level();
+  _pixel_count_smooth_untextured_pcollector.flush_level();
+  _pixel_count_white_textured_pcollector.flush_level();
+  _pixel_count_flat_textured_pcollector.flush_level();
+  _pixel_count_smooth_textured_pcollector.flush_level();
+  _pixel_count_white_perspective_pcollector.flush_level();
+  _pixel_count_flat_perspective_pcollector.flush_level();
+  _pixel_count_smooth_perspective_pcollector.flush_level();
+#endif  // DO_PSTATS
+
   // Evict any textures that exceed our texture memory.
   // Evict any textures that exceed our texture memory.
   _textures_lru.begin_epoch();
   _textures_lru.begin_epoch();
 }
 }
@@ -783,6 +814,18 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
   }
   }
 
 
   _c->zb_fill_tri = fill_tri_funcs[depth_write_state][color_write_state][alpha_test_state][depth_test_state][texfilter_state][shade_model_state][texturing_state];
   _c->zb_fill_tri = fill_tri_funcs[depth_write_state][color_write_state][alpha_test_state][depth_test_state][texfilter_state][shade_model_state][texturing_state];
+
+#ifdef DO_PSTATS
+  pixel_count_white_untextured = 0;
+  pixel_count_flat_untextured = 0;
+  pixel_count_smooth_untextured = 0;
+  pixel_count_white_textured = 0;
+  pixel_count_flat_textured = 0;
+  pixel_count_smooth_textured = 0;
+  pixel_count_white_perspective = 0;
+  pixel_count_flat_perspective = 0;
+  pixel_count_smooth_perspective = 0;
+#endif  // DO_PSTATS
   
   
   return true;
   return true;
 }
 }
@@ -1028,6 +1071,19 @@ draw_points(const GeomPrimitivePipelineReader *reader, bool force) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void TinyGraphicsStateGuardian::
 void TinyGraphicsStateGuardian::
 end_draw_primitives() {
 end_draw_primitives() {
+
+#ifdef DO_PSTATS
+  _pixel_count_white_untextured_pcollector.add_level(pixel_count_white_untextured);
+  _pixel_count_flat_untextured_pcollector.add_level(pixel_count_flat_untextured);
+  _pixel_count_smooth_untextured_pcollector.add_level(pixel_count_smooth_untextured);
+  _pixel_count_white_textured_pcollector.add_level(pixel_count_white_textured);
+  _pixel_count_flat_textured_pcollector.add_level(pixel_count_flat_textured);
+  _pixel_count_smooth_textured_pcollector.add_level(pixel_count_smooth_textured);
+  _pixel_count_white_perspective_pcollector.add_level(pixel_count_white_perspective);
+  _pixel_count_flat_perspective_pcollector.add_level(pixel_count_flat_perspective);
+  _pixel_count_smooth_perspective_pcollector.add_level(pixel_count_smooth_perspective);
+#endif  // DO_PSTATS
+
   GraphicsStateGuardian::end_draw_primitives();
   GraphicsStateGuardian::end_draw_primitives();
 }
 }
 
 

+ 9 - 0
panda/src/tinydisplay/tinyGraphicsStateGuardian.h

@@ -152,6 +152,15 @@ private:
 
 
   static PStatCollector _vertices_immediate_pcollector;
   static PStatCollector _vertices_immediate_pcollector;
   static PStatCollector _draw_transform_pcollector;
   static PStatCollector _draw_transform_pcollector;
+  static PStatCollector _pixel_count_white_untextured_pcollector;
+  static PStatCollector _pixel_count_flat_untextured_pcollector;
+  static PStatCollector _pixel_count_smooth_untextured_pcollector;
+  static PStatCollector _pixel_count_white_textured_pcollector;
+  static PStatCollector _pixel_count_flat_textured_pcollector;
+  static PStatCollector _pixel_count_smooth_textured_pcollector;
+  static PStatCollector _pixel_count_white_perspective_pcollector;
+  static PStatCollector _pixel_count_flat_perspective_pcollector;
+  static PStatCollector _pixel_count_smooth_perspective_pcollector;
 
 
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {

+ 12 - 0
panda/src/tinydisplay/zbuffer.cxx

@@ -10,6 +10,18 @@
 #include "zbuffer.h"
 #include "zbuffer.h"
 #include "pnotify.h"
 #include "pnotify.h"
 
 
+#ifdef DO_PSTATS
+int pixel_count_white_untextured;
+int pixel_count_flat_untextured;
+int pixel_count_smooth_untextured;
+int pixel_count_white_textured;
+int pixel_count_flat_textured;
+int pixel_count_smooth_textured;
+int pixel_count_white_perspective;
+int pixel_count_flat_perspective;
+int pixel_count_smooth_perspective;
+#endif  // DO_PSTATS
+
 ZBuffer *ZB_open(int xsize, int ysize, int mode,
 ZBuffer *ZB_open(int xsize, int ysize, int mode,
 		 int nb_colors,
 		 int nb_colors,
 		 unsigned char *color_indexes,
 		 unsigned char *color_indexes,

+ 20 - 0
panda/src/tinydisplay/zbuffer.h

@@ -136,6 +136,26 @@ struct ZBufferPoint {
 
 
 /* zbuffer.c */
 /* zbuffer.c */
 
 
+#ifdef DO_PSTATS
+extern int pixel_count_white_untextured;
+extern int pixel_count_flat_untextured;
+extern int pixel_count_smooth_untextured;
+extern int pixel_count_white_textured;
+extern int pixel_count_flat_textured;
+extern int pixel_count_smooth_textured;
+extern int pixel_count_white_perspective;
+extern int pixel_count_flat_perspective;
+extern int pixel_count_smooth_perspective;
+
+#define COUNT_PIXELS(pixel_count, p0, p1, p2) \
+  (pixel_count) += abs((p0)->x * ((p1)->y - (p2)->y) + (p1)->x * ((p2)->y - (p0)->y) + (p2)->x * ((p0)->y - (p1)->y)) / 2
+
+#else
+
+#define COUNT_PIXELS(pixel_count, p0, p1, p2)
+
+#endif  // DO_PSTATS
+
 ZBuffer *ZB_open(int xsize,int ysize,int mode,
 ZBuffer *ZB_open(int xsize,int ysize,int mode,
 		 int nb_colors,
 		 int nb_colors,
 		 unsigned char *color_indexes,
 		 unsigned char *color_indexes,

+ 3 - 0
panda/src/tinydisplay/ztriangle.h

@@ -39,6 +39,8 @@
 
 
   EARLY_OUT();
   EARLY_OUT();
 
 
+  COUNT_PIXELS(PIXEL_COUNT, p0, p1, p2);
+
   /* we sort the vertex with increasing y */
   /* we sort the vertex with increasing y */
   if (p1->y < p0->y) {
   if (p1->y < p0->y) {
     t = p0;
     t = p0;
@@ -382,3 +384,4 @@
 #undef DRAW_INIT
 #undef DRAW_INIT
 #undef DRAW_LINE  
 #undef DRAW_LINE  
 #undef PUT_PIXEL
 #undef PUT_PIXEL
+#undef PIXEL_COUNT

+ 22 - 5
panda/src/tinydisplay/ztriangle_two.h

@@ -21,6 +21,8 @@ static void FNAME(white_untextured) (ZBuffer *zb,
     z+=dzdx;                                                            \
     z+=dzdx;                                                            \
   }
   }
 
 
+#define PIXEL_COUNT pixel_count_white_untextured
+
 #include "ztriangle.h"
 #include "ztriangle.h"
 }
 }
 
 
@@ -58,6 +60,8 @@ static void FNAME(flat_untextured) (ZBuffer *zb,
     z+=dzdx;                                            \
     z+=dzdx;                                            \
   }
   }
 
 
+#define PIXEL_COUNT pixel_count_flat_untextured
+
 #include "ztriangle.h"
 #include "ztriangle.h"
 }
 }
 
 
@@ -105,6 +109,8 @@ static void FNAME(smooth_untextured) (ZBuffer *zb,
     oa1+=dadx;                                                          \
     oa1+=dadx;                                                          \
   }
   }
 
 
+#define PIXEL_COUNT pixel_count_smooth_untextured
+
 #include "ztriangle.h"
 #include "ztriangle.h"
 }
 }
 
 
@@ -140,6 +146,8 @@ static void FNAME(white_textured) (ZBuffer *zb,
     t+=dtdx;                                                            \
     t+=dtdx;                                                            \
   }
   }
 
 
+#define PIXEL_COUNT pixel_count_white_textured
+
 #include "ztriangle.h"
 #include "ztriangle.h"
 }
 }
 
 
@@ -193,6 +201,8 @@ static void FNAME(flat_textured) (ZBuffer *zb,
     t+=dtdx;                                                            \
     t+=dtdx;                                                            \
   }
   }
 
 
+#define PIXEL_COUNT pixel_count_flat_textured
+
 #include "ztriangle.h"
 #include "ztriangle.h"
 }
 }
 
 
@@ -256,6 +266,8 @@ static void FNAME(smooth_textured) (ZBuffer *zb,
     t+=dtdx;                                                            \
     t+=dtdx;                                                            \
   }
   }
 
 
+#define PIXEL_COUNT pixel_count_smooth_textured
+
 #include "ztriangle.h"
 #include "ztriangle.h"
 }
 }
 
 
@@ -275,8 +287,8 @@ static void FNAME(white_perspective) (ZBuffer *zb,
 
 
 #define NB_INTERP 8
 #define NB_INTERP 8
 
 
-#define EARLY_OUT() 				\
-  {						\
+#define EARLY_OUT()                                     \
+  {                                                     \
   }
   }
 
 
 #define DRAW_INIT()				\
 #define DRAW_INIT()				\
@@ -364,6 +376,8 @@ static void FNAME(white_perspective) (ZBuffer *zb,
     }                                                   \
     }                                                   \
   }
   }
   
   
+#define PIXEL_COUNT pixel_count_white_perspective
+
 #include "ztriangle.h"
 #include "ztriangle.h"
 }
 }
 
 
@@ -382,9 +396,8 @@ static void FNAME(flat_perspective) (ZBuffer *zb,
 #define INTERP_STZ
 #define INTERP_STZ
 #define INTERP_RGB
 #define INTERP_RGB
 
 
-
-#define EARLY_OUT() 				\
-  {						\
+#define EARLY_OUT()                                     \
+  {                                                     \
   }
   }
 
 
 #define DRAW_INIT() 				\
 #define DRAW_INIT() 				\
@@ -493,6 +506,8 @@ static void FNAME(flat_perspective) (ZBuffer *zb,
     }                                                   \
     }                                                   \
   }
   }
 
 
+#define PIXEL_COUNT pixel_count_flat_perspective
+
 #include "ztriangle.h"
 #include "ztriangle.h"
 }
 }
 
 
@@ -630,6 +645,8 @@ static void FNAME(smooth_perspective) (ZBuffer *zb,
     }                                                   \
     }                                                   \
   }
   }
 
 
+#define PIXEL_COUNT pixel_count_smooth_perspective
+
 #include "ztriangle.h"
 #include "ztriangle.h"
 }
 }