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
char data[TILE_SIZE][TILE_SIZE];
18
static char get_label( int i )
20
static const char *cmd_labels = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
21
unsigned max_label = (2*26+10);
31
static const char *cmd_names[LP_RAST_OP_MAX] =
50
static const char *cmd_name(unsigned cmd)
52
assert(Elements(cmd_names) > cmd);
53
return cmd_names[cmd];
56
static const struct lp_fragment_shader_variant *
57
get_variant( const struct cmd_block *block,
60
if (block->cmd[k] == LP_RAST_OP_SHADE_TILE ||
61
block->cmd[k] == LP_RAST_OP_SHADE_TILE_OPAQUE)
62
return block->arg[k].shade_tile->state->variant;
64
if (block->cmd[k] == LP_RAST_OP_TRIANGLE_1 ||
65
block->cmd[k] == LP_RAST_OP_TRIANGLE_2 ||
66
block->cmd[k] == LP_RAST_OP_TRIANGLE_3 ||
67
block->cmd[k] == LP_RAST_OP_TRIANGLE_4 ||
68
block->cmd[k] == LP_RAST_OP_TRIANGLE_5 ||
69
block->cmd[k] == LP_RAST_OP_TRIANGLE_6 ||
70
block->cmd[k] == LP_RAST_OP_TRIANGLE_7)
71
return block->arg[k].triangle.tri->inputs.state->variant;
78
is_blend( const struct cmd_block *block,
81
const struct lp_fragment_shader_variant *variant = get_variant(block, k);
84
return variant->key.blend.rt[0].blend_enable;
92
debug_bin( const struct cmd_bin *bin )
94
const struct cmd_block *head = bin->head;
97
debug_printf("bin %d,%d:\n", bin->x, bin->y);
100
for (i = 0; i < head->count; i++, j++) {
101
debug_printf("%d: %s %s\n", j,
102
cmd_name(head->cmd[i]),
103
is_blend(head, i) ? "blended" : "");
110
static void plot(struct tile *tile,
115
if (tile->data[x][y] == ' ')
120
tile->data[x][y] = val;
129
debug_shade_tile(int x, int y,
130
const union lp_rast_cmd_arg arg,
134
const struct lp_rast_shader_inputs *inputs = arg.shade_tile;
135
boolean blend = inputs->state->variant->key.blend.rt[0].blend_enable;
141
for (i = 0; i < TILE_SIZE; i++)
142
for (j = 0; j < TILE_SIZE; j++)
143
plot(tile, i, j, val, blend);
145
return TILE_SIZE * TILE_SIZE;
149
debug_clear_tile(int x, int y,
150
const union lp_rast_cmd_arg arg,
156
for (i = 0; i < TILE_SIZE; i++)
157
for (j = 0; j < TILE_SIZE; j++)
158
plot(tile, i, j, val, FALSE);
160
return TILE_SIZE * TILE_SIZE;
166
debug_triangle(int tilex, int tiley,
167
const union lp_rast_cmd_arg arg,
171
const struct lp_rast_triangle *tri = arg.triangle.tri;
172
unsigned plane_mask = arg.triangle.plane_mask;
173
struct lp_rast_plane plane[8];
176
unsigned i, nr_planes = 0;
177
boolean blend = tri->inputs.state->variant->key.blend.rt[0].blend_enable;
179
if (tri->inputs.disable) {
180
/* This triangle was partially binned and has been disabled */
185
plane[nr_planes] = tri->plane[u_bit_scan(&plane_mask)];
186
plane[nr_planes].c = (plane[nr_planes].c +
187
plane[nr_planes].dcdy * tiley -
188
plane[nr_planes].dcdx * tilex);
192
for(y = 0; y < TILE_SIZE; y++)
194
for(x = 0; x < TILE_SIZE; x++)
196
for (i = 0; i < nr_planes; i++)
200
plot(tile, x, y, val, blend);
204
for (i = 0; i < nr_planes; i++)
205
plane[i].c -= plane[i].dcdx;
208
for (i = 0; i < nr_planes; i++) {
209
plane[i].c += plane[i].dcdx * TILE_SIZE;
210
plane[i].c += plane[i].dcdy;
221
do_debug_bin( struct tile *tile,
222
const struct cmd_bin *bin,
226
const struct cmd_block *block;
228
int tx = bin->x * TILE_SIZE;
229
int ty = bin->y * TILE_SIZE;
231
memset(tile->data, ' ', sizeof tile->data);
235
for (block = bin->head; block; block = block->next) {
236
for (k = 0; k < block->count; k++, j++) {
237
boolean blend = is_blend(block, k);
238
char val = get_label(j);
242
debug_printf("%c: %15s", val, cmd_name(block->cmd[k]));
244
if (block->cmd[k] == LP_RAST_OP_CLEAR_COLOR ||
245
block->cmd[k] == LP_RAST_OP_CLEAR_ZSTENCIL)
246
count = debug_clear_tile(tx, ty, block->arg[k], tile, val);
248
if (block->cmd[k] == LP_RAST_OP_SHADE_TILE ||
249
block->cmd[k] == LP_RAST_OP_SHADE_TILE_OPAQUE)
250
count = debug_shade_tile(tx, ty, block->arg[k], tile, val);
252
if (block->cmd[k] == LP_RAST_OP_TRIANGLE_1 ||
253
block->cmd[k] == LP_RAST_OP_TRIANGLE_2 ||
254
block->cmd[k] == LP_RAST_OP_TRIANGLE_3 ||
255
block->cmd[k] == LP_RAST_OP_TRIANGLE_4 ||
256
block->cmd[k] == LP_RAST_OP_TRIANGLE_5 ||
257
block->cmd[k] == LP_RAST_OP_TRIANGLE_6 ||
258
block->cmd[k] == LP_RAST_OP_TRIANGLE_7)
259
count = debug_triangle(tx, ty, block->arg[k], tile, val);
262
debug_printf(" % 5d", count);
265
debug_printf(" blended");
274
lp_debug_bin( const struct cmd_bin *bin)
280
do_debug_bin(&tile, bin, TRUE);
282
debug_printf("------------------------------------------------------------------\n");
283
for (y = 0; y < TILE_SIZE; y++) {
284
for (x = 0; x < TILE_SIZE; x++) {
285
debug_printf("%c", tile.data[y][x]);
289
debug_printf("------------------------------------------------------------------\n");
291
debug_printf("each pixel drawn avg %f times\n",
292
((float)tile.overdraw + tile.coverage)/(float)tile.coverage);
301
/** Return number of bytes used for a single bin */
303
lp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned y )
305
struct cmd_bin *bin = lp_scene_get_bin((struct lp_scene *) scene, x, y);
306
const struct cmd_block *cmd;
308
for (cmd = bin->head; cmd; cmd = cmd->next) {
309
size += (cmd->count *
310
(sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg)));
318
lp_debug_draw_bins_by_coverage( struct lp_scene *scene )
322
unsigned possible = 0;
323
static unsigned long long _total;
324
static unsigned long long _possible;
326
for (x = 0; x < scene->tiles_x; x++)
330
for (y = 0; y < scene->tiles_y; y++) {
331
for (x = 0; x < scene->tiles_x; x++) {
332
struct cmd_bin *bin = lp_scene_get_bin(scene, x, y);
333
const char *bits = "0123456789";
339
do_debug_bin(&tile, bin, FALSE);
341
total += tile.coverage;
344
if (tile.coverage == 64*64)
346
else if (tile.coverage) {
347
int bit = tile.coverage/(64.0*64.0)*10;
348
debug_printf("%c", bits[MIN2(bit,10)]);
360
for (x = 0; x < scene->tiles_x; x++)
364
debug_printf("this tile total: %u possible %u: percentage: %f\n",
367
total * 100.0 / (float)possible);
370
_possible += possible;
372
debug_printf("overall total: %llu possible %llu: percentage: %f\n",
375
_total * 100.0 / (double)_possible);
380
lp_debug_draw_bins_by_cmd_length( struct lp_scene *scene )
384
for (y = 0; y < scene->tiles_y; y++) {
385
for (x = 0; x < scene->tiles_x; x++) {
386
const char *bits = " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW";
387
int sz = lp_scene_bin_size(scene, x, y);
388
int sz2 = util_unsigned_logbase2(sz);
389
debug_printf("%c", bits[MIN2(sz2,32)]);
397
lp_debug_bins( struct lp_scene *scene )
401
for (y = 0; y < scene->tiles_y; y++) {
402
for (x = 0; x < scene->tiles_x; x++) {
403
struct cmd_bin *bin = lp_scene_get_bin(scene, x, y);