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 char data
[TILE_SIZE
][TILE_SIZE
];
18 static char get_label( int i
)
20 static const char *cmd_labels
= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
21 unsigned max_label
= (2*26+10);
31 static const char *cmd_names
[LP_RAST_OP_MAX
] =
52 static const char *cmd_name(unsigned cmd
)
54 assert(Elements(cmd_names
) > cmd
);
55 return cmd_names
[cmd
];
58 static const struct lp_fragment_shader_variant
*
59 get_variant( 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 return block
->arg
[k
].shade_tile
->state
->variant
;
66 if (block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
67 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
68 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
69 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
70 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
71 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
72 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
73 return block
->arg
[k
].triangle
.tri
->inputs
.state
->variant
;
80 is_blend( const struct cmd_block
*block
,
83 const struct lp_fragment_shader_variant
*variant
= get_variant(block
, k
);
86 return variant
->key
.blend
.rt
[0].blend_enable
;
94 debug_bin( const struct cmd_bin
*bin
)
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 debug_printf("%d: %s %s\n", j
,
104 cmd_name(head
->cmd
[i
]),
105 is_blend(head
, i
) ? "blended" : "");
112 static void plot(struct tile
*tile
,
117 if (tile
->data
[x
][y
] == ' ')
122 tile
->data
[x
][y
] = val
;
131 debug_shade_tile(int x
, int y
,
132 const union lp_rast_cmd_arg arg
,
136 const struct lp_rast_shader_inputs
*inputs
= arg
.shade_tile
;
137 boolean blend
= inputs
->state
->variant
->key
.blend
.rt
[0].blend_enable
;
143 for (i
= 0; i
< TILE_SIZE
; i
++)
144 for (j
= 0; j
< TILE_SIZE
; j
++)
145 plot(tile
, i
, j
, val
, blend
);
147 return TILE_SIZE
* TILE_SIZE
;
151 debug_clear_tile(int x
, int y
,
152 const union lp_rast_cmd_arg arg
,
158 for (i
= 0; i
< TILE_SIZE
; i
++)
159 for (j
= 0; j
< TILE_SIZE
; j
++)
160 plot(tile
, i
, j
, val
, FALSE
);
162 return TILE_SIZE
* TILE_SIZE
;
168 debug_triangle(int tilex
, int tiley
,
169 const union lp_rast_cmd_arg arg
,
173 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
174 unsigned plane_mask
= arg
.triangle
.plane_mask
;
175 struct lp_rast_plane plane
[8];
178 unsigned i
, nr_planes
= 0;
179 boolean blend
= tri
->inputs
.state
->variant
->key
.blend
.rt
[0].blend_enable
;
181 if (tri
->inputs
.disable
) {
182 /* This triangle was partially binned and has been disabled */
187 plane
[nr_planes
] = tri
->plane
[u_bit_scan(&plane_mask
)];
188 plane
[nr_planes
].c
= (plane
[nr_planes
].c
+
189 plane
[nr_planes
].dcdy
* tiley
-
190 plane
[nr_planes
].dcdx
* tilex
);
194 for(y
= 0; y
< TILE_SIZE
; y
++)
196 for(x
= 0; x
< TILE_SIZE
; x
++)
198 for (i
= 0; i
< nr_planes
; i
++)
202 plot(tile
, x
, y
, val
, blend
);
206 for (i
= 0; i
< nr_planes
; i
++)
207 plane
[i
].c
-= plane
[i
].dcdx
;
210 for (i
= 0; i
< nr_planes
; i
++) {
211 plane
[i
].c
+= plane
[i
].dcdx
* TILE_SIZE
;
212 plane
[i
].c
+= plane
[i
].dcdy
;
223 do_debug_bin( struct tile
*tile
,
224 const struct cmd_bin
*bin
,
228 const struct cmd_block
*block
;
230 int tx
= bin
->x
* TILE_SIZE
;
231 int ty
= bin
->y
* TILE_SIZE
;
233 memset(tile
->data
, ' ', sizeof tile
->data
);
237 for (block
= bin
->head
; block
; block
= block
->next
) {
238 for (k
= 0; k
< block
->count
; k
++, j
++) {
239 boolean blend
= is_blend(block
, k
);
240 char val
= get_label(j
);
244 debug_printf("%c: %15s", val
, cmd_name(block
->cmd
[k
]));
246 if (block
->cmd
[k
] == LP_RAST_OP_CLEAR_COLOR
||
247 block
->cmd
[k
] == LP_RAST_OP_CLEAR_ZSTENCIL
)
248 count
= debug_clear_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
250 if (block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE
||
251 block
->cmd
[k
] == LP_RAST_OP_SHADE_TILE_OPAQUE
)
252 count
= debug_shade_tile(tx
, ty
, block
->arg
[k
], tile
, val
);
254 if (block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_1
||
255 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_2
||
256 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_3
||
257 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_4
||
258 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_5
||
259 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_6
||
260 block
->cmd
[k
] == LP_RAST_OP_TRIANGLE_7
)
261 count
= debug_triangle(tx
, ty
, block
->arg
[k
], tile
, val
);
264 debug_printf(" % 5d", count
);
267 debug_printf(" blended");
276 lp_debug_bin( const struct cmd_bin
*bin
)
282 do_debug_bin(&tile
, bin
, TRUE
);
284 debug_printf("------------------------------------------------------------------\n");
285 for (y
= 0; y
< TILE_SIZE
; y
++) {
286 for (x
= 0; x
< TILE_SIZE
; x
++) {
287 debug_printf("%c", tile
.data
[y
][x
]);
291 debug_printf("------------------------------------------------------------------\n");
293 debug_printf("each pixel drawn avg %f times\n",
294 ((float)tile
.overdraw
+ tile
.coverage
)/(float)tile
.coverage
);
303 /** Return number of bytes used for a single bin */
305 lp_scene_bin_size( const struct lp_scene
*scene
, unsigned x
, unsigned y
)
307 struct cmd_bin
*bin
= lp_scene_get_bin((struct lp_scene
*) scene
, x
, y
);
308 const struct cmd_block
*cmd
;
310 for (cmd
= bin
->head
; cmd
; cmd
= cmd
->next
) {
311 size
+= (cmd
->count
*
312 (sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg
)));
320 lp_debug_draw_bins_by_coverage( struct lp_scene
*scene
)
324 unsigned possible
= 0;
325 static unsigned long long _total
;
326 static unsigned long long _possible
;
328 for (x
= 0; x
< scene
->tiles_x
; x
++)
332 for (y
= 0; y
< scene
->tiles_y
; y
++) {
333 for (x
= 0; x
< scene
->tiles_x
; x
++) {
334 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);
335 const char *bits
= "0123456789";
341 do_debug_bin(&tile
, bin
, FALSE
);
343 total
+= tile
.coverage
;
346 if (tile
.coverage
== 64*64)
348 else if (tile
.coverage
) {
349 int bit
= tile
.coverage
/(64.0*64.0)*10;
350 debug_printf("%c", bits
[MIN2(bit
,10)]);
362 for (x
= 0; x
< scene
->tiles_x
; x
++)
366 debug_printf("this tile total: %u possible %u: percentage: %f\n",
369 total
* 100.0 / (float)possible
);
372 _possible
+= possible
;
374 debug_printf("overall total: %llu possible %llu: percentage: %f\n",
377 _total
* 100.0 / (double)_possible
);
382 lp_debug_draw_bins_by_cmd_length( struct lp_scene
*scene
)
386 for (y
= 0; y
< scene
->tiles_y
; y
++) {
387 for (x
= 0; x
< scene
->tiles_x
; x
++) {
388 const char *bits
= " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW";
389 int sz
= lp_scene_bin_size(scene
, x
, y
);
390 int sz2
= util_unsigned_logbase2(sz
);
391 debug_printf("%c", bits
[MIN2(sz2
,32)]);
399 lp_debug_bins( struct lp_scene
*scene
)
403 for (y
= 0; y
< scene
->tiles_y
; y
++) {
404 for (x
= 0; x
< scene
->tiles_x
; x
++) {
405 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, x
, y
);