1 #include "util/u_math.h"
2 #include "lp_rast_priv.h"
3 #include "lp_state_fs.h"
8 const struct lp_rast_state
*state
;
9 char data
[TILE_SIZE
][TILE_SIZE
];
12 static char get_label( int i
)
14 static const char *cmd_labels
= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
15 unsigned max_label
= (2*26+10);
25 static const char *cmd_names
[LP_RAST_OP_MAX
] =
47 static const char *cmd_name(unsigned cmd
)
49 assert(Elements(cmd_names
) > cmd
);
50 return cmd_names
[cmd
];
53 static const struct lp_fragment_shader_variant
*
54 get_variant( const struct lp_rast_state
*state
,
55 const struct cmd_block
*block
,
61 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
62 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
||
63 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
64 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
65 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
66 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
67 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
68 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
69 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
70 return state
->variant
;
77 is_blend( const struct lp_rast_state
*state
,
78 const struct cmd_block
*block
,
81 const struct lp_fragment_shader_variant
*variant
= get_variant(state
, block
, k
);
84 return variant
->key
.blend
.rt
[0].blend_enable
;
92 debug_bin( const struct cmd_bin
*bin
)
94 const struct lp_rast_state
*state
= NULL
;
95 const struct cmd_block
*head
= bin
->head
;
98 debug_printf("bin %d,%d:\n", bin
->x
, bin
->y
);
101 for (i
= 0; i
< head
->count
; i
++, j
++) {
102 if (head
->cmd
[i
] == LP_RAST_OP_SET_STATE
)
103 state
= head
->arg
[i
].state
;
105 debug_printf("%d: %s %s\n", j
,
106 cmd_name(head
->cmd
[i
]),
107 is_blend(state
, head
, i
) ? "blended" : "");
114 static void plot(struct tile
*tile
,
119 if (tile
->data
[x
][y
] == ' ')
124 tile
->data
[x
][y
] = val
;
133 debug_shade_tile(int x
, int y
,
134 const union lp_rast_cmd_arg arg
,
138 const struct lp_rast_shader_inputs
*inputs
= arg
.shade_tile
;
145 blend
= tile
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
150 for (i
= 0; i
< TILE_SIZE
; i
++)
151 for (j
= 0; j
< TILE_SIZE
; j
++)
152 plot(tile
, i
, j
, val
, blend
);
154 return TILE_SIZE
* TILE_SIZE
;
158 debug_clear_tile(int x
, int y
,
159 const union lp_rast_cmd_arg arg
,
165 for (i
= 0; i
< TILE_SIZE
; i
++)
166 for (j
= 0; j
< TILE_SIZE
; j
++)
167 plot(tile
, i
, j
, val
, FALSE
);
169 return TILE_SIZE
* TILE_SIZE
;
175 debug_triangle(int tilex
, int tiley
,
176 const union lp_rast_cmd_arg arg
,
180 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
181 unsigned plane_mask
= arg
.triangle
.plane_mask
;
182 const struct lp_rast_plane
*tri_plane
= GET_PLANES(tri
);
183 struct lp_rast_plane plane
[8];
186 unsigned i
, nr_planes
= 0;
187 boolean blend
= tile
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
189 if (tri
->inputs
.disable
) {
190 /* This triangle was partially binned and has been disabled */
195 plane
[nr_planes
] = tri_plane
[u_bit_scan(&plane_mask
)];
196 plane
[nr_planes
].c
= (plane
[nr_planes
].c
+
197 plane
[nr_planes
].dcdy
* tiley
-
198 plane
[nr_planes
].dcdx
* tilex
);
202 for(y
= 0; y
< TILE_SIZE
; y
++)
204 for(x
= 0; x
< TILE_SIZE
; x
++)
206 for (i
= 0; i
< nr_planes
; i
++)
210 plot(tile
, x
, y
, val
, blend
);
214 for (i
= 0; i
< nr_planes
; i
++)
215 plane
[i
].c
-= plane
[i
].dcdx
;
218 for (i
= 0; i
< nr_planes
; i
++) {
219 plane
[i
].c
+= plane
[i
].dcdx
* TILE_SIZE
;
220 plane
[i
].c
+= plane
[i
].dcdy
;
231 do_debug_bin( struct tile
*tile
,
232 const struct cmd_bin
*bin
,
236 const struct cmd_block
*block
;
238 int tx
= bin
->x
* TILE_SIZE
;
239 int ty
= bin
->y
* TILE_SIZE
;
241 memset(tile
->data
, ' ', sizeof tile
->data
);
246 for (block
= bin
->head
; block
; block
= block
->next
) {
247 for (k
= 0; k
< block
->count
; k
++, j
++) {
248 boolean blend
= is_blend(tile
->state
, block
, k
);
249 char val
= get_label(j
);
253 debug_printf("%c: %15s", val
, cmd_name(block
->cmd
[k
]));
255 if (block
->cmd
[k
] == LP_RAST_OP_SET_STATE
)
256 tile
->state
= block
->arg
[k
].state
;
258 if (block
->cmd
[k
] == LP_RAST_OP_CLEAR_COLOR
||
259 block
->cmd
[k
] == LP_RAST_OP_CLEAR_ZSTENCIL
)
260 count
= debug_clear_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
262 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
263 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
)
264 count
= debug_shade_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
266 if (block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
267 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
268 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
269 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
270 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
271 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
272 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
273 count
= debug_triangle(tx
, ty
, block
->arg
[k
], tile
, val
);
276 debug_printf(" % 5d", count
);
279 debug_printf(" blended");
288 lp_debug_bin( const struct cmd_bin
*bin
)
294 do_debug_bin(&tile
, bin
, TRUE
);
296 debug_printf("------------------------------------------------------------------\n");
297 for (y
= 0; y
< TILE_SIZE
; y
++) {
298 for (x
= 0; x
< TILE_SIZE
; x
++) {
299 debug_printf("%c", tile
.data
[y
][x
]);
303 debug_printf("------------------------------------------------------------------\n");
305 debug_printf("each pixel drawn avg %f times\n",
306 ((float)tile
.overdraw
+ tile
.coverage
)/(float)tile
.coverage
);
315 /** Return number of bytes used for a single bin */
317 lp_scene_bin_size( const struct lp_scene
*scene
, unsigned x
, unsigned y
)
319 struct cmd_bin
*bin
= lp_scene_get_bin((struct lp_scene
*) scene
, x
, y
);
320 const struct cmd_block
*cmd
;
322 for (cmd
= bin
->head
; cmd
; cmd
= cmd
->next
) {
323 size
+= (cmd
->count
*
324 (sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg
)));
332 lp_debug_draw_bins_by_coverage( struct lp_scene
*scene
)
336 unsigned possible
= 0;
337 static unsigned long long _total
;
338 static unsigned long long _possible
;
340 for (x
= 0; x
< scene
->tiles_x
; x
++)
344 for (y
= 0; y
< scene
->tiles_y
; y
++) {
345 for (x
= 0; x
< scene
->tiles_x
; x
++) {
346 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);
347 const char *bits
= "0123456789";
353 do_debug_bin(&tile
, bin
, FALSE
);
355 total
+= tile
.coverage
;
358 if (tile
.coverage
== 64*64)
360 else if (tile
.coverage
) {
361 int bit
= tile
.coverage
/(64.0*64.0)*10;
362 debug_printf("%c", bits
[MIN2(bit
,10)]);
374 for (x
= 0; x
< scene
->tiles_x
; x
++)
378 debug_printf("this tile total: %u possible %u: percentage: %f\n",
381 total
* 100.0 / (float)possible
);
384 _possible
+= possible
;
386 debug_printf("overall total: %llu possible %llu: percentage: %f\n",
389 _total
* 100.0 / (double)_possible
);
394 lp_debug_draw_bins_by_cmd_length( struct lp_scene
*scene
)
398 for (y
= 0; y
< scene
->tiles_y
; y
++) {
399 for (x
= 0; x
< scene
->tiles_x
; x
++) {
400 const char *bits
= " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW";
401 unsigned sz
= lp_scene_bin_size(scene
, x
, y
);
402 unsigned sz2
= util_logbase2(sz
);
403 debug_printf("%c", bits
[MIN2(sz2
,32)]);
411 lp_debug_bins( struct lp_scene
*scene
)
415 for (y
= 0; y
< scene
->tiles_y
; y
++) {
416 for (x
= 0; x
< scene
->tiles_x
; x
++) {
417 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);