1 #include "util/u_math.h"
2 #include "lp_rast_priv.h"
3 #include "lp_state_fs.h"
5 static INLINE
int u_bit_scan(unsigned *mask
)
7 int i
= ffs(*mask
) - 1;
15 const struct lp_rast_state
*state
;
16 char data
[TILE_SIZE
][TILE_SIZE
];
19 static char get_label( int i
)
21 static const char *cmd_labels
= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
22 unsigned max_label
= (2*26+10);
32 static const char *cmd_names
[LP_RAST_OP_MAX
] =
54 static const char *cmd_name(unsigned cmd
)
56 assert(Elements(cmd_names
) > cmd
);
57 return cmd_names
[cmd
];
60 static const struct lp_fragment_shader_variant
*
61 get_variant( const struct lp_rast_state
*state
,
62 const struct cmd_block
*block
,
65 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
66 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
||
67 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
68 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
69 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
70 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
71 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
72 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
73 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
74 return state
->variant
;
81 is_blend( const struct lp_rast_state
*state
,
82 const struct cmd_block
*block
,
85 const struct lp_fragment_shader_variant
*variant
= get_variant(state
, block
, k
);
88 return variant
->key
.blend
.rt
[0].blend_enable
;
96 debug_bin( const struct cmd_bin
*bin
)
98 const struct lp_rast_state
*state
= NULL
;
99 const struct cmd_block
*head
= bin
->head
;
102 debug_printf("bin %d,%d:\n", bin
->x
, bin
->y
);
105 for (i
= 0; i
< head
->count
; i
++, j
++) {
106 if (head
->cmd
[i
] == LP_RAST_OP_SET_STATE
)
107 state
= head
->arg
[i
].state
;
109 debug_printf("%d: %s %s\n", j
,
110 cmd_name(head
->cmd
[i
]),
111 is_blend(state
, head
, i
) ? "blended" : "");
118 static void plot(struct tile
*tile
,
123 if (tile
->data
[x
][y
] == ' ')
128 tile
->data
[x
][y
] = val
;
137 debug_shade_tile(int x
, int y
,
138 const union lp_rast_cmd_arg arg
,
142 const struct lp_rast_shader_inputs
*inputs
= arg
.shade_tile
;
143 boolean blend
= tile
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
149 for (i
= 0; i
< TILE_SIZE
; i
++)
150 for (j
= 0; j
< TILE_SIZE
; j
++)
151 plot(tile
, i
, j
, val
, blend
);
153 return TILE_SIZE
* TILE_SIZE
;
157 debug_clear_tile(int x
, int y
,
158 const union lp_rast_cmd_arg arg
,
164 for (i
= 0; i
< TILE_SIZE
; i
++)
165 for (j
= 0; j
< TILE_SIZE
; j
++)
166 plot(tile
, i
, j
, val
, FALSE
);
168 return TILE_SIZE
* TILE_SIZE
;
174 debug_triangle(int tilex
, int tiley
,
175 const union lp_rast_cmd_arg arg
,
179 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
180 unsigned plane_mask
= arg
.triangle
.plane_mask
;
181 const struct lp_rast_plane
*tri_plane
= GET_PLANES(tri
);
182 struct lp_rast_plane plane
[8];
185 unsigned i
, nr_planes
= 0;
186 boolean blend
= tile
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
188 if (tri
->inputs
.disable
) {
189 /* This triangle was partially binned and has been disabled */
194 plane
[nr_planes
] = tri_plane
[u_bit_scan(&plane_mask
)];
195 plane
[nr_planes
].c
= (plane
[nr_planes
].c
+
196 plane
[nr_planes
].dcdy
* tiley
-
197 plane
[nr_planes
].dcdx
* tilex
);
201 for(y
= 0; y
< TILE_SIZE
; y
++)
203 for(x
= 0; x
< TILE_SIZE
; x
++)
205 for (i
= 0; i
< nr_planes
; i
++)
209 plot(tile
, x
, y
, val
, blend
);
213 for (i
= 0; i
< nr_planes
; i
++)
214 plane
[i
].c
-= plane
[i
].dcdx
;
217 for (i
= 0; i
< nr_planes
; i
++) {
218 plane
[i
].c
+= plane
[i
].dcdx
* TILE_SIZE
;
219 plane
[i
].c
+= plane
[i
].dcdy
;
230 do_debug_bin( struct tile
*tile
,
231 const struct cmd_bin
*bin
,
235 const struct cmd_block
*block
;
237 int tx
= bin
->x
* TILE_SIZE
;
238 int ty
= bin
->y
* TILE_SIZE
;
240 memset(tile
->data
, ' ', sizeof tile
->data
);
245 for (block
= bin
->head
; block
; block
= block
->next
) {
246 for (k
= 0; k
< block
->count
; k
++, j
++) {
247 boolean blend
= is_blend(tile
->state
, block
, k
);
248 char val
= get_label(j
);
252 debug_printf("%c: %15s", val
, cmd_name(block
->cmd
[k
]));
254 if (block
->cmd
[k
] == LP_RAST_OP_SET_STATE
)
255 tile
->state
= block
->arg
[k
].state
;
257 if (block
->cmd
[k
] == LP_RAST_OP_CLEAR_COLOR
||
258 block
->cmd
[k
] == LP_RAST_OP_CLEAR_ZSTENCIL
)
259 count
= debug_clear_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
261 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
262 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
)
263 count
= debug_shade_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
265 if (block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
266 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
267 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
268 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
269 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
270 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
271 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
272 count
= debug_triangle(tx
, ty
, block
->arg
[k
], tile
, val
);
275 debug_printf(" % 5d", count
);
278 debug_printf(" blended");
287 lp_debug_bin( const struct cmd_bin
*bin
)
293 do_debug_bin(&tile
, bin
, TRUE
);
295 debug_printf("------------------------------------------------------------------\n");
296 for (y
= 0; y
< TILE_SIZE
; y
++) {
297 for (x
= 0; x
< TILE_SIZE
; x
++) {
298 debug_printf("%c", tile
.data
[y
][x
]);
302 debug_printf("------------------------------------------------------------------\n");
304 debug_printf("each pixel drawn avg %f times\n",
305 ((float)tile
.overdraw
+ tile
.coverage
)/(float)tile
.coverage
);
314 /** Return number of bytes used for a single bin */
316 lp_scene_bin_size( const struct lp_scene
*scene
, unsigned x
, unsigned y
)
318 struct cmd_bin
*bin
= lp_scene_get_bin((struct lp_scene
*) scene
, x
, y
);
319 const struct cmd_block
*cmd
;
321 for (cmd
= bin
->head
; cmd
; cmd
= cmd
->next
) {
322 size
+= (cmd
->count
*
323 (sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg
)));
331 lp_debug_draw_bins_by_coverage( struct lp_scene
*scene
)
335 unsigned possible
= 0;
336 static unsigned long long _total
;
337 static unsigned long long _possible
;
339 for (x
= 0; x
< scene
->tiles_x
; x
++)
343 for (y
= 0; y
< scene
->tiles_y
; y
++) {
344 for (x
= 0; x
< scene
->tiles_x
; x
++) {
345 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);
346 const char *bits
= "0123456789";
352 do_debug_bin(&tile
, bin
, FALSE
);
354 total
+= tile
.coverage
;
357 if (tile
.coverage
== 64*64)
359 else if (tile
.coverage
) {
360 int bit
= tile
.coverage
/(64.0*64.0)*10;
361 debug_printf("%c", bits
[MIN2(bit
,10)]);
373 for (x
= 0; x
< scene
->tiles_x
; x
++)
377 debug_printf("this tile total: %u possible %u: percentage: %f\n",
380 total
* 100.0 / (float)possible
);
383 _possible
+= possible
;
385 debug_printf("overall total: %llu possible %llu: percentage: %f\n",
388 _total
* 100.0 / (double)_possible
);
393 lp_debug_draw_bins_by_cmd_length( struct lp_scene
*scene
)
397 for (y
= 0; y
< scene
->tiles_y
; y
++) {
398 for (x
= 0; x
< scene
->tiles_x
; x
++) {
399 const char *bits
= " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW";
400 unsigned sz
= lp_scene_bin_size(scene
, x
, y
);
401 unsigned sz2
= util_logbase2(sz
);
402 debug_printf("%c", bits
[MIN2(sz2
,32)]);
410 lp_debug_bins( struct lp_scene
*scene
)
414 for (y
= 0; y
< scene
->tiles_y
; y
++) {
415 for (x
= 0; x
< scene
->tiles_x
; x
++) {
416 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);