lp_rast_debug.c revision 4195febeecd2d2f5571afdb90cbb185a4759f50a
1f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell#include "util/u_math.h"
2f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell#include "lp_rast_priv.h"
3f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell#include "lp_state_fs.h"
4f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
5f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic INLINE int u_bit_scan(unsigned *mask)
6f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
7f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int i = ffs(*mask) - 1;
8f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   *mask &= ~(1 << i);
9f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   return i;
10f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
11f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
12f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstruct tile {
13f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int coverage;
14f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int overdraw;
154195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell   const struct lp_rast_state *state;
16f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   char data[TILE_SIZE][TILE_SIZE];
17f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell};
18f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
19f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic char get_label( int i )
20f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
21f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   static const char *cmd_labels = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
22f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned max_label = (2*26+10);
23f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
24f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   if (i < max_label)
25f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      return cmd_labels[i];
26f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   else
27f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      return '?';
28f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
29f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
30f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
31f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
32f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic const char *cmd_names[LP_RAST_OP_MAX] =
33f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
34f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "clear_color",
35f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "clear_zstencil",
36f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "triangle_1",
37f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "triangle_2",
38f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "triangle_3",
39f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "triangle_4",
40f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "triangle_5",
41f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "triangle_6",
42f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "triangle_7",
43f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "triangle_8",
44c4046d4fda2fe838659bff99bfa17f57f895a943Keith Whitwell   "triangle_3_4",
45f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "triangle_3_16",
460ff132e5a633170afaed0aea54d01438c895b8abKeith Whitwell   "triangle_4_16",
47f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "shade_tile",
48f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "shade_tile_opaque",
49f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "begin_query",
50f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   "end_query",
514195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell   "set_state",
52f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell};
53f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
54f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic const char *cmd_name(unsigned cmd)
55f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
56f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   assert(Elements(cmd_names) > cmd);
57f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   return cmd_names[cmd];
58f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
59f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
60f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic const struct lp_fragment_shader_variant *
614195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwellget_variant( const struct lp_rast_state *state,
624195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell             const struct cmd_block *block,
634195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell             int k )
64f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
65f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   if (block->cmd[k] == LP_RAST_OP_SHADE_TILE ||
664195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell       block->cmd[k] == LP_RAST_OP_SHADE_TILE_OPAQUE ||
674195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell       block->cmd[k] == LP_RAST_OP_TRIANGLE_1 ||
68f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell       block->cmd[k] == LP_RAST_OP_TRIANGLE_2 ||
69f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell       block->cmd[k] == LP_RAST_OP_TRIANGLE_3 ||
70f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell       block->cmd[k] == LP_RAST_OP_TRIANGLE_4 ||
71f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell       block->cmd[k] == LP_RAST_OP_TRIANGLE_5 ||
72f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell       block->cmd[k] == LP_RAST_OP_TRIANGLE_6 ||
73f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell       block->cmd[k] == LP_RAST_OP_TRIANGLE_7)
744195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell      return state->variant;
75f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
76f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   return NULL;
77f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
78f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
79f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
80f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic boolean
814195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwellis_blend( const struct lp_rast_state *state,
824195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell          const struct cmd_block *block,
83f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell          int k )
84f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
854195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell   const struct lp_fragment_shader_variant *variant = get_variant(state, block, k);
86f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
87f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   if (variant)
88f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      return  variant->key.blend.rt[0].blend_enable;
89f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
90f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   return FALSE;
91f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
92f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
93f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
94f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
95f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic void
96f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelldebug_bin( const struct cmd_bin *bin )
97f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
984195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell   const struct lp_rast_state *state;
99f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   const struct cmd_block *head = bin->head;
100f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int i, j = 0;
101f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
102f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   debug_printf("bin %d,%d:\n", bin->x, bin->y);
103f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
104f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   while (head) {
105f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (i = 0; i < head->count; i++, j++) {
1064195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell         if (head->cmd[i] == LP_RAST_OP_SET_STATE)
1074195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell            state = head->arg[i].state;
1084195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell
109f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         debug_printf("%d: %s %s\n", j,
110f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                      cmd_name(head->cmd[i]),
1114195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell                      is_blend(state, head, i) ? "blended" : "");
112f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
113f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      head = head->next;
114f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
115f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
116f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
117f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
118f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic void plot(struct tile *tile,
119f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                 int x, int y,
120f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                 char val,
121f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                 boolean blend)
122f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
123f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   if (tile->data[x][y] == ' ')
124f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      tile->coverage++;
125f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   else
126f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      tile->overdraw++;
127f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
128f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   tile->data[x][y] = val;
129f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
130f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
131f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
132f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
133f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
134f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
135f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
136f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic int
137f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelldebug_shade_tile(int x, int y,
138f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                 const union lp_rast_cmd_arg arg,
139f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                 struct tile *tile,
140f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                 char val)
141f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
142f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   const struct lp_rast_shader_inputs *inputs = arg.shade_tile;
1434195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell   boolean blend = tile->state->variant->key.blend.rt[0].blend_enable;
144f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned i,j;
145f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
146f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   if (inputs->disable)
147f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      return 0;
148f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
149f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (i = 0; i < TILE_SIZE; i++)
150f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (j = 0; j < TILE_SIZE; j++)
151f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         plot(tile, i, j, val, blend);
152f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
153f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   return TILE_SIZE * TILE_SIZE;
154f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
155f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
156f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic int
157f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelldebug_clear_tile(int x, int y,
158f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                 const union lp_rast_cmd_arg arg,
159f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                 struct tile *tile,
160f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                 char val)
161f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
162f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned i,j;
163f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
164f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (i = 0; i < TILE_SIZE; i++)
165f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (j = 0; j < TILE_SIZE; j++)
166f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         plot(tile, i, j, val, FALSE);
167f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
168f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   return TILE_SIZE * TILE_SIZE;
169f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
170f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
171f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
172f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
173f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic int
174f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelldebug_triangle(int tilex, int tiley,
175f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               const union lp_rast_cmd_arg arg,
176f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               struct tile *tile,
177f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               char val)
178f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
179f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   const struct lp_rast_triangle *tri = arg.triangle.tri;
180f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned plane_mask = arg.triangle.plane_mask;
181f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   struct lp_rast_plane plane[8];
182f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int x, y;
183f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int count = 0;
184f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned i, nr_planes = 0;
1854195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell   boolean blend = tile->state->variant->key.blend.rt[0].blend_enable;
186f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
187f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   if (tri->inputs.disable) {
188f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      /* This triangle was partially binned and has been disabled */
189f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      return 0;
190f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
191f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
192f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   while (plane_mask) {
193f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      plane[nr_planes] = tri->plane[u_bit_scan(&plane_mask)];
194f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      plane[nr_planes].c = (plane[nr_planes].c +
195f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                            plane[nr_planes].dcdy * tiley -
196f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                            plane[nr_planes].dcdx * tilex);
197f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      nr_planes++;
198f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
199f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
200f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for(y = 0; y < TILE_SIZE; y++)
201f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   {
202f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for(x = 0; x < TILE_SIZE; x++)
203f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      {
204f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         for (i = 0; i < nr_planes; i++)
205f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            if (plane[i].c <= 0)
206f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               goto out;
207f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
208f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         plot(tile, x, y, val, blend);
209f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         count++;
210f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
211f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      out:
212f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         for (i = 0; i < nr_planes; i++)
213f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            plane[i].c -= plane[i].dcdx;
214f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
215f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
216f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (i = 0; i < nr_planes; i++) {
217f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         plane[i].c += plane[i].dcdx * TILE_SIZE;
218f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         plane[i].c += plane[i].dcdy;
219f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
220f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
221f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   return count;
222f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
223f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
224f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
225f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
226f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
227f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
228f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic void
229f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelldo_debug_bin( struct tile *tile,
230f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell              const struct cmd_bin *bin,
231f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell              boolean print_cmds)
232f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
233f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned k, j = 0;
234f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   const struct cmd_block *block;
235f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
236f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int tx = bin->x * TILE_SIZE;
237f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int ty = bin->y * TILE_SIZE;
238f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
239f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   memset(tile->data, ' ', sizeof tile->data);
240f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   tile->coverage = 0;
241f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   tile->overdraw = 0;
242f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
243f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (block = bin->head; block; block = block->next) {
244f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (k = 0; k < block->count; k++, j++) {
2454195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell         boolean blend = is_blend(tile->state, block, k);
246f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         char val = get_label(j);
247f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         int count = 0;
248f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
249f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (print_cmds)
250f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_printf("%c: %15s", val, cmd_name(block->cmd[k]));
2514195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell
2524195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell         if (block->cmd[k] == LP_RAST_OP_SET_STATE)
2534195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell            tile->state = block->arg[k].state;
254f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
255f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (block->cmd[k] == LP_RAST_OP_CLEAR_COLOR ||
256f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_CLEAR_ZSTENCIL)
257f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            count = debug_clear_tile(tx, ty, block->arg[k], tile, val);
258f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
259f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (block->cmd[k] == LP_RAST_OP_SHADE_TILE ||
260f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_SHADE_TILE_OPAQUE)
261f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            count = debug_shade_tile(tx, ty, block->arg[k], tile, val);
262f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
263f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (block->cmd[k] == LP_RAST_OP_TRIANGLE_1 ||
264f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_2 ||
265f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_3 ||
266f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_4 ||
267f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_5 ||
268f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_6 ||
269f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_7)
270f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            count = debug_triangle(tx, ty, block->arg[k], tile, val);
271f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
272f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (print_cmds) {
273f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_printf(" % 5d", count);
274f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
275f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            if (blend)
276f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               debug_printf(" blended");
277f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
278f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_printf("\n");
279f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         }
280f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
281f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
282f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
283f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
284f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellvoid
285f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_debug_bin( const struct cmd_bin *bin)
286f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
287f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   struct tile tile;
288f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int x,y;
289f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
290f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   if (bin->head) {
291f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      do_debug_bin(&tile, bin, TRUE);
292f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
293f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("------------------------------------------------------------------\n");
294f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (y = 0; y < TILE_SIZE; y++) {
295f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         for (x = 0; x < TILE_SIZE; x++) {
296f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_printf("%c", tile.data[y][x]);
297f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         }
298f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         debug_printf("|\n");
299f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
300f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("------------------------------------------------------------------\n");
301f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
302f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("each pixel drawn avg %f times\n",
303f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                   ((float)tile.overdraw + tile.coverage)/(float)tile.coverage);
304f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
305f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
306f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
307f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
308f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
309f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
310f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
311f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
312f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell/** Return number of bytes used for a single bin */
313f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic unsigned
314f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned y )
315f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
316f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   struct cmd_bin *bin = lp_scene_get_bin((struct lp_scene *) scene, x, y);
317f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   const struct cmd_block *cmd;
318f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned size = 0;
319f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (cmd = bin->head; cmd; cmd = cmd->next) {
320f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      size += (cmd->count *
321f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               (sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg)));
322f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
323f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   return size;
324f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
325f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
326f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
327f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
328f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellvoid
329f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_debug_draw_bins_by_coverage( struct lp_scene *scene )
330f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
331f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned x, y;
332f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned total = 0;
333f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned possible = 0;
334f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   static unsigned long long _total;
335f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   static unsigned long long _possible;
336f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
337f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (x = 0; x < scene->tiles_x; x++)
338f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("-");
339f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   debug_printf("\n");
340f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
341f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (y = 0; y < scene->tiles_y; y++) {
342f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (x = 0; x < scene->tiles_x; x++) {
343f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         struct cmd_bin *bin = lp_scene_get_bin(scene, x, y);
344f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         const char *bits = "0123456789";
345f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         struct tile tile;
346f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
347f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (bin->head) {
348f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            //lp_debug_bin(bin);
349f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
350f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            do_debug_bin(&tile, bin, FALSE);
351f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
352f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            total += tile.coverage;
353f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            possible += 64*64;
354f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
355f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            if (tile.coverage == 64*64)
356f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               debug_printf("*");
357f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            else if (tile.coverage) {
358f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               int bit = tile.coverage/(64.0*64.0)*10;
359f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               debug_printf("%c", bits[MIN2(bit,10)]);
360f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            }
361f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            else
362f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               debug_printf("?");
363f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         }
364f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         else {
365f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_printf(" ");
366f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         }
367f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
368f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("|\n");
369f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
370f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
371f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (x = 0; x < scene->tiles_x; x++)
372f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("-");
373f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   debug_printf("\n");
374f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
375f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   debug_printf("this tile total: %u possible %u: percentage: %f\n",
376f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                total,
377f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                possible,
378f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                total * 100.0 / (float)possible);
379f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
380f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   _total += total;
381f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   _possible += possible;
382f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
383f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   debug_printf("overall   total: %llu possible %llu: percentage: %f\n",
384f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                _total,
385f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                _possible,
386f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                _total * 100.0 / (double)_possible);
387f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
388f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
389f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
390f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellvoid
391f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_debug_draw_bins_by_cmd_length( struct lp_scene *scene )
392f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
393f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned x, y;
394f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
395f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (y = 0; y < scene->tiles_y; y++) {
396f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (x = 0; x < scene->tiles_x; x++) {
397f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         const char *bits = " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW";
398f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         int sz = lp_scene_bin_size(scene, x, y);
399f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         int sz2 = util_unsigned_logbase2(sz);
400f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         debug_printf("%c", bits[MIN2(sz2,32)]);
401f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
402f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("\n");
403f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
404f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
405f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
406f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
407f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellvoid
408f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_debug_bins( struct lp_scene *scene )
409f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
410f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned x, y;
411f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
412f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (y = 0; y < scene->tiles_y; y++) {
413f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (x = 0; x < scene->tiles_x; x++) {
414f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         struct cmd_bin *bin = lp_scene_get_bin(scene, x, y);
415f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (bin->head) {
416f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_bin(bin);
417f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         }
418f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
419f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
420f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
421