From 85d94ff0c581f76375142163b27235da55562762 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 5 Aug 2008 00:57:35 +0000 Subject: [PATCH] pstats pixel count for tinydisplay --- panda/src/pstatclient/pStatProperties.cxx | 1 + .../tinydisplay/tinyGraphicsStateGuardian.cxx | 56 +++++++++++++++++++ .../tinydisplay/tinyGraphicsStateGuardian.h | 9 +++ panda/src/tinydisplay/zbuffer.cxx | 12 ++++ panda/src/tinydisplay/zbuffer.h | 20 +++++++ panda/src/tinydisplay/ztriangle.h | 3 + panda/src/tinydisplay/ztriangle_two.h | 27 +++++++-- 7 files changed, 123 insertions(+), 5 deletions(-) diff --git a/panda/src/pstatclient/pStatProperties.cxx b/panda/src/pstatclient/pStatProperties.cxx index 43194ecb9e..d65d50f141 100644 --- a/panda/src/pstatclient/pStatProperties.cxx +++ b/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:Display lists", { 0.8, 0.5, 1.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:GeomNodes", { 0.8, 0.2, 0.0 } }, { 1, "Geoms", { 0.4, 0.8, 0.3 }, "", 500.0 }, diff --git a/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx b/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx index 5da4b38dbe..923f88347b 100644 --- a/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx +++ b/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx @@ -32,6 +32,15 @@ TypeHandle TinyGraphicsStateGuardian::_type_handle; PStatCollector TinyGraphicsStateGuardian::_vertices_immediate_pcollector("Vertices:Immediate mode"); 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 @@ -341,6 +350,16 @@ begin_frame(Thread *current_thread) { #ifdef DO_PSTATS _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 return true; @@ -424,9 +443,21 @@ void TinyGraphicsStateGuardian:: end_frame(Thread *current_thread) { GraphicsStateGuardian::end_frame(current_thread); +#ifdef DO_PSTATS // Flush any PCollectors specific to this kind of GSG. _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. _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]; + +#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; } @@ -1028,6 +1071,19 @@ draw_points(const GeomPrimitivePipelineReader *reader, bool force) { //////////////////////////////////////////////////////////////////// void TinyGraphicsStateGuardian:: 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(); } diff --git a/panda/src/tinydisplay/tinyGraphicsStateGuardian.h b/panda/src/tinydisplay/tinyGraphicsStateGuardian.h index 7e234702ad..d7eb43e545 100644 --- a/panda/src/tinydisplay/tinyGraphicsStateGuardian.h +++ b/panda/src/tinydisplay/tinyGraphicsStateGuardian.h @@ -152,6 +152,15 @@ private: static PStatCollector _vertices_immediate_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: static TypeHandle get_class_type() { diff --git a/panda/src/tinydisplay/zbuffer.cxx b/panda/src/tinydisplay/zbuffer.cxx index 0e5ee62150..b91b0c61a3 100644 --- a/panda/src/tinydisplay/zbuffer.cxx +++ b/panda/src/tinydisplay/zbuffer.cxx @@ -10,6 +10,18 @@ #include "zbuffer.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, int nb_colors, unsigned char *color_indexes, diff --git a/panda/src/tinydisplay/zbuffer.h b/panda/src/tinydisplay/zbuffer.h index 31131c14b9..83163f6370 100644 --- a/panda/src/tinydisplay/zbuffer.h +++ b/panda/src/tinydisplay/zbuffer.h @@ -136,6 +136,26 @@ struct ZBufferPoint { /* 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, int nb_colors, unsigned char *color_indexes, diff --git a/panda/src/tinydisplay/ztriangle.h b/panda/src/tinydisplay/ztriangle.h index 73bc901fe7..0c7cb0d7aa 100644 --- a/panda/src/tinydisplay/ztriangle.h +++ b/panda/src/tinydisplay/ztriangle.h @@ -39,6 +39,8 @@ EARLY_OUT(); + COUNT_PIXELS(PIXEL_COUNT, p0, p1, p2); + /* we sort the vertex with increasing y */ if (p1->y < p0->y) { t = p0; @@ -382,3 +384,4 @@ #undef DRAW_INIT #undef DRAW_LINE #undef PUT_PIXEL +#undef PIXEL_COUNT diff --git a/panda/src/tinydisplay/ztriangle_two.h b/panda/src/tinydisplay/ztriangle_two.h index bd2e3a4357..3f60426d16 100644 --- a/panda/src/tinydisplay/ztriangle_two.h +++ b/panda/src/tinydisplay/ztriangle_two.h @@ -21,6 +21,8 @@ static void FNAME(white_untextured) (ZBuffer *zb, z+=dzdx; \ } +#define PIXEL_COUNT pixel_count_white_untextured + #include "ztriangle.h" } @@ -58,6 +60,8 @@ static void FNAME(flat_untextured) (ZBuffer *zb, z+=dzdx; \ } +#define PIXEL_COUNT pixel_count_flat_untextured + #include "ztriangle.h" } @@ -105,6 +109,8 @@ static void FNAME(smooth_untextured) (ZBuffer *zb, oa1+=dadx; \ } +#define PIXEL_COUNT pixel_count_smooth_untextured + #include "ztriangle.h" } @@ -140,6 +146,8 @@ static void FNAME(white_textured) (ZBuffer *zb, t+=dtdx; \ } +#define PIXEL_COUNT pixel_count_white_textured + #include "ztriangle.h" } @@ -193,6 +201,8 @@ static void FNAME(flat_textured) (ZBuffer *zb, t+=dtdx; \ } +#define PIXEL_COUNT pixel_count_flat_textured + #include "ztriangle.h" } @@ -256,6 +266,8 @@ static void FNAME(smooth_textured) (ZBuffer *zb, t+=dtdx; \ } +#define PIXEL_COUNT pixel_count_smooth_textured + #include "ztriangle.h" } @@ -275,8 +287,8 @@ static void FNAME(white_perspective) (ZBuffer *zb, #define NB_INTERP 8 -#define EARLY_OUT() \ - { \ +#define EARLY_OUT() \ + { \ } #define DRAW_INIT() \ @@ -364,6 +376,8 @@ static void FNAME(white_perspective) (ZBuffer *zb, } \ } +#define PIXEL_COUNT pixel_count_white_perspective + #include "ztriangle.h" } @@ -382,9 +396,8 @@ static void FNAME(flat_perspective) (ZBuffer *zb, #define INTERP_STZ #define INTERP_RGB - -#define EARLY_OUT() \ - { \ +#define EARLY_OUT() \ + { \ } #define DRAW_INIT() \ @@ -493,6 +506,8 @@ static void FNAME(flat_perspective) (ZBuffer *zb, } \ } +#define PIXEL_COUNT pixel_count_flat_perspective + #include "ztriangle.h" } @@ -630,6 +645,8 @@ static void FNAME(smooth_perspective) (ZBuffer *zb, } \ } +#define PIXEL_COUNT pixel_count_smooth_perspective + #include "ztriangle.h" }