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 const struct lp_rast_state
*state
;
16 char data
[TILE_SIZE
][TILE_SIZE
];
19 static char get_label( int i
)
21 static const char *cmd_labels
= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
22 unsigned max_label
= (2*26+10);
32 static const char *cmd_names
[LP_RAST_OP_MAX
] =
54 static const char *cmd_name(unsigned cmd
)
56 assert(Elements(cmd_names
) > cmd
);
57 return cmd_names
[cmd
];
60 static const struct lp_fragment_shader_variant
*
61 get_variant( const struct lp_rast_state
*state
,
62 const struct cmd_block
*block
,
65 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
66 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
||
67 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
68 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
69 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
70 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
71 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
72 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
73 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
74 return state
->variant
;
81 is_blend( const struct lp_rast_state
*state
,
82 const struct cmd_block
*block
,
85 const struct lp_fragment_shader_variant
*variant
= get_variant(state
, block
, k
);
88 return variant
->key
.blend
.rt
[0].blend_enable
;
96 debug_bin( const struct cmd_bin
*bin
)
98 const struct lp_rast_state
*state
= NULL
;
99 const struct cmd_block
*head
= bin
->head
;
102 debug_printf("bin %d,%d:\n", bin
->x
, bin
->y
);
105 for (i
= 0; i
< head
->count
; i
++, j
++) {
106 if (head
->cmd
[i
] == LP_RAST_OP_SET_STATE
)
107 state
= head
->arg
[i
].state
;
109 debug_printf("%d: %s %s\n", j
,
110 cmd_name(head
->cmd
[i
]),
111 is_blend(state
, head
, i
) ? "blended" : "");
118 static void plot(struct tile
*tile
,
123 if (tile
->data
[x
][y
] == ' ')
128 tile
->data
[x
][y
] = val
;
137 debug_shade_tile(int x
, int y
,
138 const union lp_rast_cmd_arg arg
,
142 const struct lp_rast_shader_inputs
*inputs
= arg
.shade_tile
;
143 boolean blend
= tile
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
149 for (i
= 0; i
< TILE_SIZE
; i
++)
150 for (j
= 0; j
< TILE_SIZE
; j
++)
151 plot(tile
, i
, j
, val
, blend
);
153 return TILE_SIZE
* TILE_SIZE
;
157 debug_clear_tile(int x
, int y
,
158 const union lp_rast_cmd_arg arg
,
164 for (i
= 0; i
< TILE_SIZE
; i
++)
165 for (j
= 0; j
< TILE_SIZE
; j
++)
166 plot(tile
, i
, j
, val
, FALSE
);
168 return TILE_SIZE
* TILE_SIZE
;
174 debug_triangle(int tilex
, int tiley
,
175 const union lp_rast_cmd_arg arg
,
179 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
180 unsigned plane_mask
= arg
.triangle
.plane_mask
;
181 const struct lp_rast_plane
*tri_plane
= GET_PLANES(tri
);
182 struct lp_rast_plane plane
[8];
185 unsigned i
, nr_planes
= 0;
186 boolean blend
= tile
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
188 if (tri
->inputs
.disable
) {
189 /* This triangle was partially binned and has been disabled */
194 plane
[nr_planes
] = tri_plane
[u_bit_scan(&plane_mask
)];
195 plane
[nr_planes
].c
= (plane
[nr_planes
].c
+
196 plane
[nr_planes
].dcdy
* tiley
-
197 plane
[nr_planes
].dcdx
* tilex
);
201 for(y
= 0; y
< TILE_SIZE
; y
++)
203 for(x
= 0; x
< TILE_SIZE
; x
++)
205 for (i
= 0; i
< nr_planes
; i
++)
209 plot(tile
, x
, y
, val
, blend
);
213 for (i
= 0; i
< nr_planes
; i
++)
214 plane
[i
].c
-= plane
[i
].dcdx
;
217 for (i
= 0; i
< nr_planes
; i
++) {
218 plane
[i
].c
+= plane
[i
].dcdx
* TILE_SIZE
;
219 plane
[i
].c
+= plane
[i
].dcdy
;
230 do_debug_bin( struct tile
*tile
,
231 const struct cmd_bin
*bin
,
235 const struct cmd_block
*block
;
237 int tx
= bin
->x
* TILE_SIZE
;
238 int ty
= bin
->y
* TILE_SIZE
;
240 memset(tile
->data
, ' ', sizeof tile
->data
);
244 for (block
= bin
->head
; block
; block
= block
->next
) {
245 for (k
= 0; k
< block
->count
; k
++, j
++) {
246 boolean blend
= is_blend(tile
->state
, block
, k
);
247 char val
= get_label(j
);
251 debug_printf("%c: %15s", val
, cmd_name(block
->cmd
[k
]));
253 if (block
->cmd
[k
] == LP_RAST_OP_SET_STATE
)
254 tile
->state
= block
->arg
[k
].state
;
256 if (block
->cmd
[k
] == LP_RAST_OP_CLEAR_COLOR
||
257 block
->cmd
[k
] == LP_RAST_OP_CLEAR_ZSTENCIL
)
258 count
= debug_clear_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
260 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
261 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
)
262 count
= debug_shade_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
264 if (block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
265 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
266 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
267 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
268 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
269 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
270 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
271 count
= debug_triangle(tx
, ty
, block
->arg
[k
], tile
, val
);
274 debug_printf(" % 5d", count
);
277 debug_printf(" blended");
286 lp_debug_bin( const struct cmd_bin
*bin
)
292 do_debug_bin(&tile
, bin
, TRUE
);
294 debug_printf("------------------------------------------------------------------\n");
295 for (y
= 0; y
< TILE_SIZE
; y
++) {
296 for (x
= 0; x
< TILE_SIZE
; x
++) {
297 debug_printf("%c", tile
.data
[y
][x
]);
301 debug_printf("------------------------------------------------------------------\n");
303 debug_printf("each pixel drawn avg %f times\n",
304 ((float)tile
.overdraw
+ tile
.coverage
)/(float)tile
.coverage
);
313 /** Return number of bytes used for a single bin */
315 lp_scene_bin_size( const struct lp_scene
*scene
, unsigned x
, unsigned y
)
317 struct cmd_bin
*bin
= lp_scene_get_bin((struct lp_scene
*) scene
, x
, y
);
318 const struct cmd_block
*cmd
;
320 for (cmd
= bin
->head
; cmd
; cmd
= cmd
->next
) {
321 size
+= (cmd
->count
*
322 (sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg
)));
330 lp_debug_draw_bins_by_coverage( struct lp_scene
*scene
)
334 unsigned possible
= 0;
335 static unsigned long long _total
;
336 static unsigned long long _possible
;
338 for (x
= 0; x
< scene
->tiles_x
; x
++)
342 for (y
= 0; y
< scene
->tiles_y
; y
++) {
343 for (x
= 0; x
< scene
->tiles_x
; x
++) {
344 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);
345 const char *bits
= "0123456789";
351 do_debug_bin(&tile
, bin
, FALSE
);
353 total
+= tile
.coverage
;
356 if (tile
.coverage
== 64*64)
358 else if (tile
.coverage
) {
359 int bit
= tile
.coverage
/(64.0*64.0)*10;
360 debug_printf("%c", bits
[MIN2(bit
,10)]);
372 for (x
= 0; x
< scene
->tiles_x
; x
++)
376 debug_printf("this tile total: %u possible %u: percentage: %f\n",
379 total
* 100.0 / (float)possible
);
382 _possible
+= possible
;
384 debug_printf("overall total: %llu possible %llu: percentage: %f\n",
387 _total
* 100.0 / (double)_possible
);
392 lp_debug_draw_bins_by_cmd_length( struct lp_scene
*scene
)
396 for (y
= 0; y
< scene
->tiles_y
; y
++) {
397 for (x
= 0; x
< scene
->tiles_x
; x
++) {
398 const char *bits
= " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW";
399 int sz
= lp_scene_bin_size(scene
, x
, y
);
400 int sz2
= util_unsigned_logbase2(sz
);
401 debug_printf("%c", bits
[MIN2(sz2
,32)]);
409 lp_debug_bins( struct lp_scene
*scene
)
413 for (y
= 0; y
< scene
->tiles_y
; y
++) {
414 for (x
= 0; x
< scene
->tiles_x
; x
++) {
415 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);