lp_rast_debug.c revision 36dde032a4f7d6a8b68c1adc8e829816e2e8826e
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{
9822725eb3e87921632a24579d63bb20c35a122afaVinson Lee   const struct lp_rast_state *state = NULL;
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;
1819bf8a55c4b29d55320fc2e7875ecf0e9ca164ee8Keith Whitwell   const struct lp_rast_plane *tri_plane = GET_PLANES(tri);
182f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   struct lp_rast_plane plane[8];
183f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int x, y;
184f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int count = 0;
185f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned i, nr_planes = 0;
1864195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell   boolean blend = tile->state->variant->key.blend.rt[0].blend_enable;
187f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
188f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   if (tri->inputs.disable) {
189f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      /* This triangle was partially binned and has been disabled */
190f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      return 0;
191f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
192f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
193f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   while (plane_mask) {
1949bf8a55c4b29d55320fc2e7875ecf0e9ca164ee8Keith Whitwell      plane[nr_planes] = tri_plane[u_bit_scan(&plane_mask)];
195f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      plane[nr_planes].c = (plane[nr_planes].c +
196f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                            plane[nr_planes].dcdy * tiley -
197f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                            plane[nr_planes].dcdx * tilex);
198f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      nr_planes++;
199f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
200f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
201f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for(y = 0; y < TILE_SIZE; y++)
202f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   {
203f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for(x = 0; x < TILE_SIZE; x++)
204f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      {
205f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         for (i = 0; i < nr_planes; i++)
206f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            if (plane[i].c <= 0)
207f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               goto out;
208f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
209f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         plot(tile, x, y, val, blend);
210f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         count++;
211f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
212f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      out:
213f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         for (i = 0; i < nr_planes; i++)
214f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            plane[i].c -= plane[i].dcdx;
215f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
216f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
217f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (i = 0; i < nr_planes; i++) {
218f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         plane[i].c += plane[i].dcdx * TILE_SIZE;
219f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         plane[i].c += plane[i].dcdy;
220f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
221f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
222f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   return count;
223f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
224f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
225f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
226f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
227f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
228f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
229f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic void
230f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelldo_debug_bin( struct tile *tile,
231f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell              const struct cmd_bin *bin,
232f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell              boolean print_cmds)
233f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
234f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned k, j = 0;
235f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   const struct cmd_block *block;
236f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
237f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int tx = bin->x * TILE_SIZE;
238f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int ty = bin->y * TILE_SIZE;
239f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
240f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   memset(tile->data, ' ', sizeof tile->data);
241f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   tile->coverage = 0;
242f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   tile->overdraw = 0;
24336dde032a4f7d6a8b68c1adc8e829816e2e8826eVinson Lee   tile->state = NULL;
244f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
245f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (block = bin->head; block; block = block->next) {
246f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (k = 0; k < block->count; k++, j++) {
2474195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell         boolean blend = is_blend(tile->state, block, k);
248f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         char val = get_label(j);
249f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         int count = 0;
250f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
251f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (print_cmds)
252f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_printf("%c: %15s", val, cmd_name(block->cmd[k]));
2534195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell
2544195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell         if (block->cmd[k] == LP_RAST_OP_SET_STATE)
2554195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell            tile->state = block->arg[k].state;
256f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
257f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (block->cmd[k] == LP_RAST_OP_CLEAR_COLOR ||
258f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_CLEAR_ZSTENCIL)
259f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            count = debug_clear_tile(tx, ty, block->arg[k], tile, val);
260f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
261f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (block->cmd[k] == LP_RAST_OP_SHADE_TILE ||
262f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_SHADE_TILE_OPAQUE)
263f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            count = debug_shade_tile(tx, ty, block->arg[k], tile, val);
264f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
265f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (block->cmd[k] == LP_RAST_OP_TRIANGLE_1 ||
266f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_2 ||
267f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_3 ||
268f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_4 ||
269f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_5 ||
270f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_6 ||
271f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell             block->cmd[k] == LP_RAST_OP_TRIANGLE_7)
272f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            count = debug_triangle(tx, ty, block->arg[k], tile, val);
273f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
274f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (print_cmds) {
275f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_printf(" % 5d", count);
276f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
277f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            if (blend)
278f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               debug_printf(" blended");
279f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
280f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_printf("\n");
281f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         }
282f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
283f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
284f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
285f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
286f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellvoid
287f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_debug_bin( const struct cmd_bin *bin)
288f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
289f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   struct tile tile;
290f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   int x,y;
291f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
292f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   if (bin->head) {
293f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      do_debug_bin(&tile, bin, TRUE);
294f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
295f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("------------------------------------------------------------------\n");
296f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (y = 0; y < TILE_SIZE; y++) {
297f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         for (x = 0; x < TILE_SIZE; x++) {
298f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_printf("%c", tile.data[y][x]);
299f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         }
300f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         debug_printf("|\n");
301f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
302f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("------------------------------------------------------------------\n");
303f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
304f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("each pixel drawn avg %f times\n",
305f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                   ((float)tile.overdraw + tile.coverage)/(float)tile.coverage);
306f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
307f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
308f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
309f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
310f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
311f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
312f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
313f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
314f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell/** Return number of bytes used for a single bin */
315f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellstatic unsigned
316f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned y )
317f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
318f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   struct cmd_bin *bin = lp_scene_get_bin((struct lp_scene *) scene, x, y);
319f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   const struct cmd_block *cmd;
320f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned size = 0;
321f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (cmd = bin->head; cmd; cmd = cmd->next) {
322f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      size += (cmd->count *
323f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               (sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg)));
324f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
325f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   return size;
326f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
327f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
328f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
329f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
330f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellvoid
331f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_debug_draw_bins_by_coverage( struct lp_scene *scene )
332f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
333f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned x, y;
334f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned total = 0;
335f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned possible = 0;
336f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   static unsigned long long _total;
337f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   static unsigned long long _possible;
338f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
339f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (x = 0; x < scene->tiles_x; x++)
340f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("-");
341f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   debug_printf("\n");
342f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
343f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (y = 0; y < scene->tiles_y; y++) {
344f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (x = 0; x < scene->tiles_x; x++) {
345f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         struct cmd_bin *bin = lp_scene_get_bin(scene, x, y);
346f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         const char *bits = "0123456789";
347f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         struct tile tile;
348f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
349f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (bin->head) {
350f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            //lp_debug_bin(bin);
351f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
352f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            do_debug_bin(&tile, bin, FALSE);
353f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
354f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            total += tile.coverage;
355f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            possible += 64*64;
356f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
357f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            if (tile.coverage == 64*64)
358f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               debug_printf("*");
359f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            else if (tile.coverage) {
360f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               int bit = tile.coverage/(64.0*64.0)*10;
361f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               debug_printf("%c", bits[MIN2(bit,10)]);
362f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            }
363f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            else
364f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell               debug_printf("?");
365f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         }
366f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         else {
367f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_printf(" ");
368f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         }
369f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
370f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("|\n");
371f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
372f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
373f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (x = 0; x < scene->tiles_x; x++)
374f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("-");
375f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   debug_printf("\n");
376f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
377f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   debug_printf("this tile total: %u possible %u: percentage: %f\n",
378f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                total,
379f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                possible,
380f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                total * 100.0 / (float)possible);
381f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
382f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   _total += total;
383f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   _possible += possible;
384f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
385f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   debug_printf("overall   total: %llu possible %llu: percentage: %f\n",
386f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                _total,
387f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                _possible,
388f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell                _total * 100.0 / (double)_possible);
389f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
390f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
391f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
392f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellvoid
393f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_debug_draw_bins_by_cmd_length( struct lp_scene *scene )
394f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
395f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned x, y;
396f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
397f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (y = 0; y < scene->tiles_y; y++) {
398f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (x = 0; x < scene->tiles_x; x++) {
399f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         const char *bits = " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW";
400f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         int sz = lp_scene_bin_size(scene, x, y);
401f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         int sz2 = util_unsigned_logbase2(sz);
402f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         debug_printf("%c", bits[MIN2(sz2,32)]);
403f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
404f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      debug_printf("\n");
405f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
406f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
407f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
408f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
409f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellvoid
410f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_debug_bins( struct lp_scene *scene )
411f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell{
412f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   unsigned x, y;
413f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell
414f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   for (y = 0; y < scene->tiles_y; y++) {
415f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      for (x = 0; x < scene->tiles_x; x++) {
416f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         struct cmd_bin *bin = lp_scene_get_bin(scene, x, y);
417f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         if (bin->head) {
418f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell            debug_bin(bin);
419f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell         }
420f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell      }
421f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell   }
422f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwell}
423