1 #include <inttypes.h> /* for PRIu64 macro */
2 #include "util/u_math.h"
3 #include "lp_rast_priv.h"
4 #include "lp_state_fs.h"
9 const struct lp_rast_state
*state
;
10 char data
[TILE_SIZE
][TILE_SIZE
];
13 static char get_label( int i
)
15 static const char *cmd_labels
= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
16 unsigned max_label
= (2*26+10);
26 static const char *cmd_names
[LP_RAST_OP_MAX
] =
59 static const char *cmd_name(unsigned cmd
)
61 assert(Elements(cmd_names
) > cmd
);
62 return cmd_names
[cmd
];
65 static const struct lp_fragment_shader_variant
*
66 get_variant( const struct lp_rast_state
*state
,
67 const struct cmd_block
*block
,
73 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
74 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
||
75 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
76 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
77 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
78 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
79 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
80 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
81 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
82 return state
->variant
;
89 is_blend( const struct lp_rast_state
*state
,
90 const struct cmd_block
*block
,
93 const struct lp_fragment_shader_variant
*variant
= get_variant(state
, block
, k
);
96 return variant
->key
.blend
.rt
[0].blend_enable
;
104 debug_bin( const struct cmd_bin
*bin
, int x
, int y
)
106 const struct lp_rast_state
*state
= NULL
;
107 const struct cmd_block
*head
= bin
->head
;
110 debug_printf("bin %d,%d:\n", x
, y
);
113 for (i
= 0; i
< head
->count
; i
++, j
++) {
114 if (head
->cmd
[i
] == LP_RAST_OP_SET_STATE
)
115 state
= head
->arg
[i
].state
;
117 debug_printf("%d: %s %s\n", j
,
118 cmd_name(head
->cmd
[i
]),
119 is_blend(state
, head
, i
) ? "blended" : "");
126 static void plot(struct tile
*tile
,
131 if (tile
->data
[x
][y
] == ' ')
136 tile
->data
[x
][y
] = val
;
145 debug_shade_tile(int x
, int y
,
146 const union lp_rast_cmd_arg arg
,
150 const struct lp_rast_shader_inputs
*inputs
= arg
.shade_tile
;
157 blend
= tile
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
162 for (i
= 0; i
< TILE_SIZE
; i
++)
163 for (j
= 0; j
< TILE_SIZE
; j
++)
164 plot(tile
, i
, j
, val
, blend
);
166 return TILE_SIZE
* TILE_SIZE
;
170 debug_clear_tile(int x
, int y
,
171 const union lp_rast_cmd_arg arg
,
177 for (i
= 0; i
< TILE_SIZE
; i
++)
178 for (j
= 0; j
< TILE_SIZE
; j
++)
179 plot(tile
, i
, j
, val
, FALSE
);
181 return TILE_SIZE
* TILE_SIZE
;
187 debug_triangle(int tilex
, int tiley
,
188 const union lp_rast_cmd_arg arg
,
192 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
193 unsigned plane_mask
= arg
.triangle
.plane_mask
;
194 const struct lp_rast_plane
*tri_plane
= GET_PLANES(tri
);
195 struct lp_rast_plane plane
[8];
198 unsigned i
, nr_planes
= 0;
199 boolean blend
= tile
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
201 if (tri
->inputs
.disable
) {
202 /* This triangle was partially binned and has been disabled */
207 plane
[nr_planes
] = tri_plane
[u_bit_scan(&plane_mask
)];
208 plane
[nr_planes
].c
= (plane
[nr_planes
].c
+
209 IMUL64(plane
[nr_planes
].dcdy
, tiley
) -
210 IMUL64(plane
[nr_planes
].dcdx
, tilex
));
214 for(y
= 0; y
< TILE_SIZE
; y
++)
216 for(x
= 0; x
< TILE_SIZE
; x
++)
218 for (i
= 0; i
< nr_planes
; i
++)
222 plot(tile
, x
, y
, val
, blend
);
226 for (i
= 0; i
< nr_planes
; i
++)
227 plane
[i
].c
-= plane
[i
].dcdx
;
230 for (i
= 0; i
< nr_planes
; i
++) {
231 plane
[i
].c
+= IMUL64(plane
[i
].dcdx
, TILE_SIZE
);
232 plane
[i
].c
+= plane
[i
].dcdy
;
243 do_debug_bin( struct tile
*tile
,
244 const struct cmd_bin
*bin
,
249 const struct cmd_block
*block
;
251 int tx
= x
* TILE_SIZE
;
252 int ty
= y
* TILE_SIZE
;
254 memset(tile
->data
, ' ', sizeof tile
->data
);
259 for (block
= bin
->head
; block
; block
= block
->next
) {
260 for (k
= 0; k
< block
->count
; k
++, j
++) {
261 boolean blend
= is_blend(tile
->state
, block
, k
);
262 char val
= get_label(j
);
266 debug_printf("%c: %15s", val
, cmd_name(block
->cmd
[k
]));
268 if (block
->cmd
[k
] == LP_RAST_OP_SET_STATE
)
269 tile
->state
= block
->arg
[k
].state
;
271 if (block
->cmd
[k
] == LP_RAST_OP_CLEAR_COLOR
||
272 block
->cmd
[k
] == LP_RAST_OP_CLEAR_ZSTENCIL
)
273 count
= debug_clear_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
275 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
276 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
)
277 count
= debug_shade_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
279 if (block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
280 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
281 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
282 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
283 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
284 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
285 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
286 count
= debug_triangle(tx
, ty
, block
->arg
[k
], tile
, val
);
289 debug_printf(" % 5d", count
);
292 debug_printf(" blended");
301 lp_debug_bin( const struct cmd_bin
*bin
, int i
, int j
)
307 do_debug_bin(&tile
, bin
, i
, j
, TRUE
);
309 debug_printf("------------------------------------------------------------------\n");
310 for (y
= 0; y
< TILE_SIZE
; y
++) {
311 for (x
= 0; x
< TILE_SIZE
; x
++) {
312 debug_printf("%c", tile
.data
[y
][x
]);
316 debug_printf("------------------------------------------------------------------\n");
318 debug_printf("each pixel drawn avg %f times\n",
319 ((float)tile
.overdraw
+ tile
.coverage
)/(float)tile
.coverage
);
328 /** Return number of bytes used for a single bin */
330 lp_scene_bin_size( const struct lp_scene
*scene
, unsigned x
, unsigned y
)
332 struct cmd_bin
*bin
= lp_scene_get_bin((struct lp_scene
*) scene
, x
, y
);
333 const struct cmd_block
*cmd
;
335 for (cmd
= bin
->head
; cmd
; cmd
= cmd
->next
) {
336 size
+= (cmd
->count
*
337 (sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg
)));
345 lp_debug_draw_bins_by_coverage( struct lp_scene
*scene
)
349 unsigned possible
= 0;
350 static uint64_t _total
= 0;
351 static uint64_t _possible
= 0;
353 for (x
= 0; x
< scene
->tiles_x
; x
++)
357 for (y
= 0; y
< scene
->tiles_y
; y
++) {
358 for (x
= 0; x
< scene
->tiles_x
; x
++) {
359 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);
360 const char *bits
= "0123456789";
364 //lp_debug_bin(bin, x, y);
366 do_debug_bin(&tile
, bin
, x
, y
, FALSE
);
368 total
+= tile
.coverage
;
371 if (tile
.coverage
== 64*64)
373 else if (tile
.coverage
) {
374 int bit
= tile
.coverage
/(64.0*64.0)*10;
375 debug_printf("%c", bits
[MIN2(bit
,10)]);
387 for (x
= 0; x
< scene
->tiles_x
; x
++)
391 debug_printf("this tile total: %u possible %u: percentage: %f\n",
394 total
* 100.0 / (float)possible
);
397 _possible
+= possible
;
400 debug_printf("overall total: %" PRIu64
401 " possible %" PRIu64
": percentage: %f\n",
404 (double) _total
* 100.0 / (double)_possible
);
409 lp_debug_draw_bins_by_cmd_length( struct lp_scene
*scene
)
413 for (y
= 0; y
< scene
->tiles_y
; y
++) {
414 for (x
= 0; x
< scene
->tiles_x
; x
++) {
415 const char *bits
= " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW";
416 unsigned sz
= lp_scene_bin_size(scene
, x
, y
);
417 unsigned sz2
= util_logbase2(sz
);
418 debug_printf("%c", bits
[MIN2(sz2
,32)]);
426 lp_debug_bins( struct lp_scene
*scene
)
430 for (y
= 0; y
< scene
->tiles_y
; y
++) {
431 for (x
= 0; x
< scene
->tiles_x
; x
++) {
432 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);
434 debug_bin(bin
, x
, y
);