+ state->jit_function[RAST_EDGE_TEST]( &state->jit_context,
+ x, y,
+ inputs->facing,
+ inputs->a0,
+ inputs->dadx,
+ inputs->dady,
+ color,
+ depth,
+ c1, c2, c3,
+ inputs->step[0],
+ inputs->step[1],
+ inputs->step[2]);
+}
+
+
+/**
+ * Set top row and left column of the tile's pixels to white. For debugging.
+ */
+static void
+outline_tile(uint8_t *tile)
+{
+ const uint8_t val = 0xff;
+ unsigned i;
+
+ for (i = 0; i < TILE_SIZE; i++) {
+ TILE_PIXEL(tile, i, 0, 0) = val;
+ TILE_PIXEL(tile, i, 0, 1) = val;
+ TILE_PIXEL(tile, i, 0, 2) = val;
+ TILE_PIXEL(tile, i, 0, 3) = val;
+
+ TILE_PIXEL(tile, 0, i, 0) = val;
+ TILE_PIXEL(tile, 0, i, 1) = val;
+ TILE_PIXEL(tile, 0, i, 2) = val;
+ TILE_PIXEL(tile, 0, i, 3) = val;
+ }
+}
+
+
+/**
+ * Draw grid of gray lines at 16-pixel intervals across the tile to
+ * show the sub-tile boundaries. For debugging.
+ */
+static void
+outline_subtiles(uint8_t *tile)
+{
+ const uint8_t val = 0x80;
+ const unsigned step = 16;
+ unsigned i, j;
+
+ for (i = 0; i < TILE_SIZE; i += step) {
+ for (j = 0; j < TILE_SIZE; j++) {
+ TILE_PIXEL(tile, i, j, 0) = val;
+ TILE_PIXEL(tile, i, j, 1) = val;
+ TILE_PIXEL(tile, i, j, 2) = val;
+ TILE_PIXEL(tile, i, j, 3) = val;
+
+ TILE_PIXEL(tile, j, i, 0) = val;
+ TILE_PIXEL(tile, j, i, 1) = val;
+ TILE_PIXEL(tile, j, i, 2) = val;
+ TILE_PIXEL(tile, j, i, 3) = val;
+ }
+ }
+
+ outline_tile(tile);
+}
+
+
+
+/**
+ * Write the rasterizer's color tile to the framebuffer.
+ */
+static void
+lp_rast_store_color(struct lp_rasterizer_task *task)
+{
+ struct lp_rasterizer *rast = task->rast;
+ const unsigned x = task->x, y = task->y;
+ unsigned i;
+
+ for (i = 0; i < rast->state.nr_cbufs; i++) {
+ if (x >= rast->cbuf[i].width)
+ continue;
+
+ if (y >= rast->cbuf[i].height)
+ continue;
+
+ LP_DBG(DEBUG_RAST, "%s [%u] %d,%d\n", __FUNCTION__,
+ task->thread_index, x, y);
+
+ if (LP_DEBUG & DEBUG_SHOW_SUBTILES)
+ outline_subtiles(task->tile.color[i]);
+ else if (LP_DEBUG & DEBUG_SHOW_TILES)
+ outline_tile(task->tile.color[i]);
+
+ lp_tile_write_4ub(rast->cbuf[i].format,
+ task->tile.color[i],
+ rast->cbuf[i].map,
+ rast->cbuf[i].stride,
+ x, y,
+ TILE_SIZE, TILE_SIZE);
+
+ LP_COUNT(nr_color_tile_store);
+ }
+}
+
+
+
+/**
+ * Signal on a fence. This is called during bin execution/rasterization.
+ * Called per thread.
+ */
+void
+lp_rast_fence(struct lp_rasterizer_task *task,
+ const union lp_rast_cmd_arg arg)
+{
+ struct lp_fence *fence = arg.fence;
+ lp_fence_signal(fence);
+}
+
+
+
+
+/**
+ * Rasterize commands for a single bin.
+ * \param x, y position of the bin's tile in the framebuffer
+ * Must be called between lp_rast_begin() and lp_rast_end().
+ * Called per thread.
+ */
+static void
+rasterize_bin(struct lp_rasterizer_task *task,
+ const struct cmd_bin *bin,
+ int x, int y)
+{
+ const struct cmd_block_list *commands = &bin->commands;
+ struct cmd_block *block;
+ unsigned k;
+
+ lp_rast_start_tile( task, x * TILE_SIZE, y * TILE_SIZE );
+
+ /* simply execute each of the commands in the block list */
+ for (block = commands->head; block; block = block->next) {
+ for (k = 0; k < block->count; k++) {
+ block->cmd[k]( task, block->arg[k] );
+ }
+ }
+
+ /* Write the rasterizer's tiles to the framebuffer.
+ */
+ if (task->rast->state.write_color)
+ lp_rast_store_color(task);
+
+ /* Free data for this bin.
+ */
+ lp_scene_bin_reset( task->rast->curr_scene, x, y);
+}
+
+
+#define RAST(x) { lp_rast_##x, #x }
+
+static struct {
+ lp_rast_cmd cmd;
+ const char *name;
+} cmd_names[] =
+{
+ RAST(load_color),
+ RAST(clear_color),
+ RAST(clear_zstencil),
+ RAST(triangle),
+ RAST(shade_tile),
+ RAST(set_state),
+ RAST(fence),
+};
+
+static void
+debug_bin( const struct cmd_bin *bin )
+{
+ const struct cmd_block *head = bin->commands.head;
+ int i, j;
+
+ for (i = 0; i < head->count; i++) {
+ debug_printf("%d: ", i);
+ for (j = 0; j < Elements(cmd_names); j++) {
+ if (head->cmd[i] == cmd_names[j].cmd) {
+ debug_printf("%s\n", cmd_names[j].name);
+ break;
+ }
+ }
+ if (j == Elements(cmd_names))
+ debug_printf("...other\n");
+ }
+
+}
+
+/* An empty bin is one that just loads the contents of the tile and
+ * stores them again unchanged. This typically happens when bins have
+ * been flushed for some reason in the middle of a frame, or when
+ * incremental updates are being made to a render target.
+ *
+ * Try to avoid doing pointless work in this case.
+ */
+static boolean
+is_empty_bin( const struct cmd_bin *bin )
+{
+ const struct cmd_block *head = bin->commands.head;
+ int i;
+
+ if (0)
+ debug_bin(bin);
+
+ /* We emit at most two load-tile commands at the start of the first
+ * command block. In addition we seem to emit a couple of
+ * set-state commands even in empty bins.
+ *
+ * As a heuristic, if a bin has more than 4 commands, consider it
+ * non-empty.
+ */
+ if (head->next != NULL ||
+ head->count > 4) {
+ return FALSE;
+ }
+
+ for (i = 0; i < head->count; i++)
+ if (head->cmd[i] != lp_rast_load_color &&
+ head->cmd[i] != lp_rast_set_state) {
+ return FALSE;
+ }
+
+ return TRUE;
+}