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
] =
48 static const char *cmd_name(unsigned cmd
)
50 assert(Elements(cmd_names
) > cmd
);
51 return cmd_names
[cmd
];
54 static const struct lp_fragment_shader_variant
*
55 get_variant( const struct lp_rast_state
*state
,
56 const struct cmd_block
*block
,
62 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
63 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
||
64 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 state
->variant
;
78 is_blend( const struct lp_rast_state
*state
,
79 const struct cmd_block
*block
,
82 const struct lp_fragment_shader_variant
*variant
= get_variant(state
, block
, k
);
85 return variant
->key
.blend
.rt
[0].blend_enable
;
93 debug_bin( const struct cmd_bin
*bin
, int x
, int y
)
95 const struct lp_rast_state
*state
= NULL
;
96 const struct cmd_block
*head
= bin
->head
;
99 debug_printf("bin %d,%d:\n", x
, y
);
102 for (i
= 0; i
< head
->count
; i
++, j
++) {
103 if (head
->cmd
[i
] == LP_RAST_OP_SET_STATE
)
104 state
= head
->arg
[i
].state
;
106 debug_printf("%d: %s %s\n", j
,
107 cmd_name(head
->cmd
[i
]),
108 is_blend(state
, head
, i
) ? "blended" : "");
115 static void plot(struct tile
*tile
,
120 if (tile
->data
[x
][y
] == ' ')
125 tile
->data
[x
][y
] = val
;
134 debug_shade_tile(int x
, int y
,
135 const union lp_rast_cmd_arg arg
,
139 const struct lp_rast_shader_inputs
*inputs
= arg
.shade_tile
;
146 blend
= tile
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
151 for (i
= 0; i
< TILE_SIZE
; i
++)
152 for (j
= 0; j
< TILE_SIZE
; j
++)
153 plot(tile
, i
, j
, val
, blend
);
155 return TILE_SIZE
* TILE_SIZE
;
159 debug_clear_tile(int x
, int y
,
160 const union lp_rast_cmd_arg arg
,
166 for (i
= 0; i
< TILE_SIZE
; i
++)
167 for (j
= 0; j
< TILE_SIZE
; j
++)
168 plot(tile
, i
, j
, val
, FALSE
);
170 return TILE_SIZE
* TILE_SIZE
;
176 debug_triangle(int tilex
, int tiley
,
177 const union lp_rast_cmd_arg arg
,
181 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
182 unsigned plane_mask
= arg
.triangle
.plane_mask
;
183 const struct lp_rast_plane
*tri_plane
= GET_PLANES(tri
);
184 struct lp_rast_plane plane
[8];
187 unsigned i
, nr_planes
= 0;
188 boolean blend
= tile
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
190 if (tri
->inputs
.disable
) {
191 /* This triangle was partially binned and has been disabled */
196 plane
[nr_planes
] = tri_plane
[u_bit_scan(&plane_mask
)];
197 plane
[nr_planes
].c
= (plane
[nr_planes
].c
+
198 IMUL64(plane
[nr_planes
].dcdy
, tiley
) -
199 IMUL64(plane
[nr_planes
].dcdx
, tilex
));
203 for(y
= 0; y
< TILE_SIZE
; y
++)
205 for(x
= 0; x
< TILE_SIZE
; x
++)
207 for (i
= 0; i
< nr_planes
; i
++)
211 plot(tile
, x
, y
, val
, blend
);
215 for (i
= 0; i
< nr_planes
; i
++)
216 plane
[i
].c
-= plane
[i
].dcdx
;
219 for (i
= 0; i
< nr_planes
; i
++) {
220 plane
[i
].c
+= IMUL64(plane
[i
].dcdx
, TILE_SIZE
);
221 plane
[i
].c
+= plane
[i
].dcdy
;
232 do_debug_bin( struct tile
*tile
,
233 const struct cmd_bin
*bin
,
238 const struct cmd_block
*block
;
240 int tx
= x
* TILE_SIZE
;
241 int ty
= y
* TILE_SIZE
;
243 memset(tile
->data
, ' ', sizeof tile
->data
);
248 for (block
= bin
->head
; block
; block
= block
->next
) {
249 for (k
= 0; k
< block
->count
; k
++, j
++) {
250 boolean blend
= is_blend(tile
->state
, block
, k
);
251 char val
= get_label(j
);
255 debug_printf("%c: %15s", val
, cmd_name(block
->cmd
[k
]));
257 if (block
->cmd
[k
] == LP_RAST_OP_SET_STATE
)
258 tile
->state
= block
->arg
[k
].state
;
260 if (block
->cmd
[k
] == LP_RAST_OP_CLEAR_COLOR
||
261 block
->cmd
[k
] == LP_RAST_OP_CLEAR_ZSTENCIL
)
262 count
= debug_clear_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
264 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
265 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
)
266 count
= debug_shade_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
268 if (block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
269 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
270 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
271 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
272 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
273 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
274 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
275 count
= debug_triangle(tx
, ty
, block
->arg
[k
], tile
, val
);
278 debug_printf(" % 5d", count
);
281 debug_printf(" blended");
290 lp_debug_bin( const struct cmd_bin
*bin
, int i
, int j
)
296 do_debug_bin(&tile
, bin
, i
, j
, TRUE
);
298 debug_printf("------------------------------------------------------------------\n");
299 for (y
= 0; y
< TILE_SIZE
; y
++) {
300 for (x
= 0; x
< TILE_SIZE
; x
++) {
301 debug_printf("%c", tile
.data
[y
][x
]);
305 debug_printf("------------------------------------------------------------------\n");
307 debug_printf("each pixel drawn avg %f times\n",
308 ((float)tile
.overdraw
+ tile
.coverage
)/(float)tile
.coverage
);
317 /** Return number of bytes used for a single bin */
319 lp_scene_bin_size( const struct lp_scene
*scene
, unsigned x
, unsigned y
)
321 struct cmd_bin
*bin
= lp_scene_get_bin((struct lp_scene
*) scene
, x
, y
);
322 const struct cmd_block
*cmd
;
324 for (cmd
= bin
->head
; cmd
; cmd
= cmd
->next
) {
325 size
+= (cmd
->count
*
326 (sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg
)));
334 lp_debug_draw_bins_by_coverage( struct lp_scene
*scene
)
338 unsigned possible
= 0;
339 static uint64_t _total
= 0;
340 static uint64_t _possible
= 0;
342 for (x
= 0; x
< scene
->tiles_x
; x
++)
346 for (y
= 0; y
< scene
->tiles_y
; y
++) {
347 for (x
= 0; x
< scene
->tiles_x
; x
++) {
348 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);
349 const char *bits
= "0123456789";
353 //lp_debug_bin(bin, x, y);
355 do_debug_bin(&tile
, bin
, x
, y
, FALSE
);
357 total
+= tile
.coverage
;
360 if (tile
.coverage
== 64*64)
362 else if (tile
.coverage
) {
363 int bit
= tile
.coverage
/(64.0*64.0)*10;
364 debug_printf("%c", bits
[MIN2(bit
,10)]);
376 for (x
= 0; x
< scene
->tiles_x
; x
++)
380 debug_printf("this tile total: %u possible %u: percentage: %f\n",
383 total
* 100.0 / (float)possible
);
386 _possible
+= possible
;
389 debug_printf("overall total: %" PRIu64
390 " possible %" PRIu64
": percentage: %f\n",
393 (double) _total
* 100.0 / (double)_possible
);
398 lp_debug_draw_bins_by_cmd_length( struct lp_scene
*scene
)
402 for (y
= 0; y
< scene
->tiles_y
; y
++) {
403 for (x
= 0; x
< scene
->tiles_x
; x
++) {
404 const char *bits
= " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW";
405 unsigned sz
= lp_scene_bin_size(scene
, x
, y
);
406 unsigned sz2
= util_logbase2(sz
);
407 debug_printf("%c", bits
[MIN2(sz2
,32)]);
415 lp_debug_bins( struct lp_scene
*scene
)
419 for (y
= 0; y
< scene
->tiles_y
; y
++) {
420 for (x
= 0; x
< scene
->tiles_x
; x
++) {
421 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);
423 debug_bin(bin
, x
, y
);