static void cell_set_framebuffer_state(struct pipe_context *pipe, const struct pipe_framebuffer_state *fb) { struct cell_context *cell = cell_context(pipe); if (1 /*memcmp(&cell->framebuffer, fb, sizeof(*fb))*/) { uint i; /* unmap old surfaces */ cell_unmap_surfaces(cell); /* Finish any pending rendering to the current surface before * installing a new surface! */ cell_flush_int(cell, CELL_FLUSH_WAIT); /* update my state * (this is also where old surfaces will finally get freed) */ cell->framebuffer.width = fb->width; cell->framebuffer.height = fb->height; cell->framebuffer.nr_cbufs = fb->nr_cbufs; for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { pipe_surface_reference(&cell->framebuffer.cbufs[i], fb->cbufs[i]); } pipe_surface_reference(&cell->framebuffer.zsbuf, fb->zsbuf); /* map new surfaces */ cell_map_surfaces(cell); cell->dirty |= CELL_NEW_FRAMEBUFFER; } }
/** * Called via pipe->flush() */ void cell_flush(struct pipe_context *pipe, struct pipe_fence_handle **fence) { struct cell_context *cell = cell_context(pipe); if (fence) { *fence = NULL; } flags |= CELL_FLUSH_WAIT; draw_flush( cell->draw ); cell_flush_int(cell, flags); }
struct pipe_context * cell_create_context(struct pipe_screen *screen, void *priv ) { struct cell_context *cell; uint i; /* some fields need to be 16-byte aligned, so align the whole object */ cell = (struct cell_context*) align_malloc(sizeof(struct cell_context), 16); if (!cell) return NULL; memset(cell, 0, sizeof(*cell)); cell->winsys = NULL; /* XXX: fixme - get this from screen? */ cell->pipe.winsys = NULL; cell->pipe.screen = screen; cell->pipe.priv = priv; cell->pipe.destroy = cell_destroy_context; cell->pipe.clear = cell_clear; cell->pipe.flush = cell_flush; #if 0 cell->pipe.begin_query = cell_begin_query; cell->pipe.end_query = cell_end_query; cell->pipe.wait_query = cell_wait_query; #endif cell_init_draw_functions(cell); cell_init_state_functions(cell); cell_init_shader_functions(cell); cell_init_surface_functions(cell); cell_init_vertex_functions(cell); cell_init_texture_transfer_funcs(cell); cell->draw = cell_draw_create(cell); /* Create cache of fragment ops generated code */ cell->fragment_ops_cache = util_new_keymap(sizeof(struct cell_fragment_ops_key), ~0, NULL); cell_init_vbuf(cell); draw_set_rasterize_stage(cell->draw, cell->vbuf); /* convert all points/lines to tris for the time being */ draw_wide_point_threshold(cell->draw, 0.0); draw_wide_line_threshold(cell->draw, 0.0); /* get env vars or read config file to get debug flags */ cell->debug_flags = debug_get_flags_option("CELL_DEBUG", cell_debug_flags, 0 ); for (i = 0; i < CELL_NUM_BUFFERS; i++) cell_fence_init(&cell->fenced_buffers[i].fence); /* * SPU stuff */ /* This call only works with SDK 3.0. Anyone still using 2.1??? */ cell->num_cells = spe_cpu_info_get(SPE_COUNT_PHYSICAL_CPU_NODES, -1); cell->num_spus = spe_cpu_info_get(SPE_COUNT_USABLE_SPES, -1); if (cell->debug_flags) { printf("Cell: found %d Cell(s) with %u SPUs\n", cell->num_cells, cell->num_spus); } if (getenv("CELL_NUM_SPUS")) { cell->num_spus = atoi(getenv("CELL_NUM_SPUS")); assert(cell->num_spus > 0); } cell_start_spus(cell); cell_init_batch_buffers(cell); /* make sure SPU initializations are done before proceeding */ cell_flush_int(cell, CELL_FLUSH_WAIT); return &cell->pipe; }
/** * Run the vertex shader on all vertices in the vertex queue. * Called by the draw module when the vertx cache needs to be flushed. */ void cell_vertex_shader_queue_flush(struct draw_context *draw) { #if 0 struct cell_context *const cell = (struct cell_context *) draw->driver_private; struct cell_command_vs *const vs = &cell_global.command[0].vs; uint64_t *batch; struct cell_array_info *array_info; unsigned i, j; struct cell_attribute_fetch_code *cf; assert(draw->vs.queue_nr != 0); /* XXX: do this on statechange: */ draw_update_vertex_fetch(draw); cell_update_vertex_fetch(draw); batch = cell_batch_alloc(cell, sizeof(batch[0]) + sizeof(*cf)); batch[0] = CELL_CMD_STATE_ATTRIB_FETCH; cf = (struct cell_attribute_fetch_code *) (&batch[1]); cf->base = (uint64_t) cell->attrib_fetch.store; cf->size = ROUNDUP16((unsigned)((void *) cell->attrib_fetch.csr - (void *) cell->attrib_fetch.store)); for (i = 0; i < draw->vertex_fetch.nr_attrs; i++) { const enum pipe_format format = draw->vertex_element[i].src_format; const unsigned count = ((pf_size_x(format) != 0) + (pf_size_y(format) != 0) + (pf_size_z(format) != 0) + (pf_size_w(format) != 0)); const unsigned size = pf_size_x(format) * count; batch = cell_batch_alloc(cell, sizeof(batch[0]) + sizeof(*array_info)); batch[0] = CELL_CMD_STATE_VS_ARRAY_INFO; array_info = (struct cell_array_info *) &batch[1]; assert(draw->vertex_fetch.src_ptr[i] != NULL); array_info->base = (uintptr_t) draw->vertex_fetch.src_ptr[i]; array_info->attr = i; array_info->pitch = draw->vertex_fetch.pitch[i]; array_info->size = size; array_info->function_offset = cell->attrib_fetch_offsets[i]; } batch = cell_batch_alloc(cell, sizeof(batch[0]) + sizeof(struct pipe_viewport_state)); batch[0] = CELL_CMD_STATE_VIEWPORT; (void) memcpy(&batch[1], &draw->viewport, sizeof(struct pipe_viewport_state)); { uint64_t uniforms = (uintptr_t) draw->user.constants; batch = cell_batch_alloc(cell, 2 *sizeof(batch[0])); batch[0] = CELL_CMD_STATE_UNIFORMS; batch[1] = uniforms; } cell_batch_flush(cell); vs->opcode = CELL_CMD_VS_EXECUTE; vs->nr_attrs = draw->vertex_fetch.nr_attrs; (void) memcpy(vs->plane, draw->plane, sizeof(draw->plane)); vs->nr_planes = draw->nr_planes; for (i = 0; i < draw->vs.queue_nr; i += SPU_VERTS_PER_BATCH) { const unsigned n = MIN2(SPU_VERTS_PER_BATCH, draw->vs.queue_nr - i); for (j = 0; j < n; j++) { vs->elts[j] = draw->vs.queue[i + j].elt; vs->vOut[j] = (uintptr_t) draw->vs.queue[i + j].vertex; } for (/* empty */; j < SPU_VERTS_PER_BATCH; j++) { vs->elts[j] = vs->elts[0]; vs->vOut[j] = (uintptr_t) draw->vs.queue[i + j].vertex; } vs->num_elts = n; send_mbox_message(cell_global.spe_contexts[0], CELL_CMD_VS_EXECUTE); cell_flush_int(cell, CELL_FLUSH_WAIT); } draw->vs.post_nr = draw->vs.queue_nr; draw->vs.queue_nr = 0; #else assert(0); #endif }