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
)
95 const struct lp_rast_state
*state
= NULL
;
96 const struct cmd_block
*head
= bin
->head
;
99 debug_printf("bin %d,%d:\n", bin
->x
, bin
->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 plane
[nr_planes
].dcdy
* tiley
-
199 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
+= 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
,
237 const struct cmd_block
*block
;
239 int tx
= bin
->x
* TILE_SIZE
;
240 int ty
= bin
->y
* TILE_SIZE
;
242 memset(tile
->data
, ' ', sizeof tile
->data
);
247 for (block
= bin
->head
; block
; block
= block
->next
) {
248 for (k
= 0; k
< block
->count
; k
++, j
++) {
249 boolean blend
= is_blend(tile
->state
, block
, k
);
250 char val
= get_label(j
);
254 debug_printf("%c: %15s", val
, cmd_name(block
->cmd
[k
]));
256 if (block
->cmd
[k
] == LP_RAST_OP_SET_STATE
)
257 tile
->state
= block
->arg
[k
].state
;
259 if (block
->cmd
[k
] == LP_RAST_OP_CLEAR_COLOR
||
260 block
->cmd
[k
] == LP_RAST_OP_CLEAR_ZSTENCIL
)
261 count
= debug_clear_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
263 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
264 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
)
265 count
= debug_shade_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
267 if (block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
268 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
269 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
270 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
271 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
272 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
273 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
274 count
= debug_triangle(tx
, ty
, block
->arg
[k
], tile
, val
);
277 debug_printf(" % 5d", count
);
280 debug_printf(" blended");
289 lp_debug_bin( const struct cmd_bin
*bin
)
295 do_debug_bin(&tile
, bin
, TRUE
);
297 debug_printf("------------------------------------------------------------------\n");
298 for (y
= 0; y
< TILE_SIZE
; y
++) {
299 for (x
= 0; x
< TILE_SIZE
; x
++) {
300 debug_printf("%c", tile
.data
[y
][x
]);
304 debug_printf("------------------------------------------------------------------\n");
306 debug_printf("each pixel drawn avg %f times\n",
307 ((float)tile
.overdraw
+ tile
.coverage
)/(float)tile
.coverage
);
316 /** Return number of bytes used for a single bin */
318 lp_scene_bin_size( const struct lp_scene
*scene
, unsigned x
, unsigned y
)
320 struct cmd_bin
*bin
= lp_scene_get_bin((struct lp_scene
*) scene
, x
, y
);
321 const struct cmd_block
*cmd
;
323 for (cmd
= bin
->head
; cmd
; cmd
= cmd
->next
) {
324 size
+= (cmd
->count
*
325 (sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg
)));
333 lp_debug_draw_bins_by_coverage( struct lp_scene
*scene
)
337 unsigned possible
= 0;
338 static uint64_t _total
= 0;
339 static uint64_t _possible
= 0;
341 for (x
= 0; x
< scene
->tiles_x
; x
++)
345 for (y
= 0; y
< scene
->tiles_y
; y
++) {
346 for (x
= 0; x
< scene
->tiles_x
; x
++) {
347 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);
348 const char *bits
= "0123456789";
354 do_debug_bin(&tile
, bin
, FALSE
);
356 total
+= tile
.coverage
;
359 if (tile
.coverage
== 64*64)
361 else if (tile
.coverage
) {
362 int bit
= tile
.coverage
/(64.0*64.0)*10;
363 debug_printf("%c", bits
[MIN2(bit
,10)]);
375 for (x
= 0; x
< scene
->tiles_x
; x
++)
379 debug_printf("this tile total: %u possible %u: percentage: %f\n",
382 total
* 100.0 / (float)possible
);
385 _possible
+= possible
;
388 debug_printf("overall total: %" PRIu64
389 " possible %" PRIu64
": percentage: %f\n",
392 (double) _total
* 100.0 / (double)_possible
);
397 lp_debug_draw_bins_by_cmd_length( struct lp_scene
*scene
)
401 for (y
= 0; y
< scene
->tiles_y
; y
++) {
402 for (x
= 0; x
< scene
->tiles_x
; x
++) {
403 const char *bits
= " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW";
404 unsigned sz
= lp_scene_bin_size(scene
, x
, y
);
405 unsigned sz2
= util_logbase2(sz
);
406 debug_printf("%c", bits
[MIN2(sz2
,32)]);
414 lp_debug_bins( struct lp_scene
*scene
)
418 for (y
= 0; y
< scene
->tiles_y
; y
++) {
419 for (x
= 0; x
< scene
->tiles_x
; x
++) {
420 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);