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