cell_render.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00033 #include "cell_context.h"
00034 #include "cell_render.h"
00035 #include "cell_spu.h"
00036 #include "util/u_memory.h"
00037 #include "draw/draw_private.h"
00038 
00039 
00040 struct render_stage {
00041    struct draw_stage stage; 
00043    struct cell_context *cell;
00044 };
00045 
00046 
00047 static INLINE struct render_stage *
00048 render_stage(struct draw_stage *stage)
00049 {
00050    return (struct render_stage *) stage;
00051 }
00052 
00053 
00054 static void render_begin( struct draw_stage *stage )
00055 {
00056 #if 0
00057    struct render_stage *render = render_stage(stage);
00058    struct cell_context *sp = render->cell;
00059    const struct pipe_shader_state *fs = &render->cell->fs->shader;
00060    render->quad.nr_attrs = render->cell->nr_frag_attrs;
00061 
00062    render->firstFpInput = fs->input_semantic_name[0];
00063 
00064    sp->quad.first->begin(sp->quad.first);
00065 #endif
00066 }
00067 
00068 
00069 static void render_end( struct draw_stage *stage )
00070 {
00071 }
00072 
00073 
00074 static void reset_stipple_counter( struct draw_stage *stage )
00075 {
00076    struct render_stage *render = render_stage(stage);
00077    /*render->cell->line_stipple_counter = 0;*/
00078 }
00079 
00080 
00081 static void
00082 render_point(struct draw_stage *stage, struct prim_header *prim)
00083 {
00084 }
00085 
00086 
00087 static void
00088 render_line(struct draw_stage *stage, struct prim_header *prim)
00089 {
00090 }
00091 
00092 
00094 static void
00095 save_vertex(struct cell_prim_buffer *buf, uint pos,
00096             const struct vertex_header *vert)
00097 {
00098    uint attr, j;
00099 
00100    for (attr = 0; attr < 2; attr++) {
00101       for (j = 0; j < 4; j++) {
00102          buf->vertex[pos][attr][j] = vert->data[attr][j];
00103       }
00104    }
00105 
00106    /* update bounding box */
00107    if (vert->data[0][0] < buf->xmin)
00108       buf->xmin = vert->data[0][0];
00109    if (vert->data[0][0] > buf->xmax)
00110       buf->xmax = vert->data[0][0];
00111    if (vert->data[0][1] < buf->ymin)
00112       buf->ymin = vert->data[0][1];
00113    if (vert->data[0][1] > buf->ymax)
00114       buf->ymax = vert->data[0][1];
00115 }
00116 
00117 
00118 static void
00119 render_tri(struct draw_stage *stage, struct prim_header *prim)
00120 {
00121    struct render_stage *rs = render_stage(stage);
00122    struct cell_context *cell = rs->cell;
00123    struct cell_prim_buffer *buf = &cell->prim_buffer;
00124    uint i;
00125 
00126    if (buf->num_verts + 3 > CELL_MAX_VERTS) {
00127       cell_flush_prim_buffer(cell);
00128    }
00129 
00130    i = buf->num_verts;
00131    assert(i+2 <= CELL_MAX_VERTS);
00132    save_vertex(buf, i+0, prim->v[0]);
00133    save_vertex(buf, i+1, prim->v[1]);
00134    save_vertex(buf, i+2, prim->v[2]);
00135    buf->num_verts += 3;
00136 }
00137 
00138 
00143 void
00144 cell_flush_prim_buffer(struct cell_context *cell)
00145 {
00146    uint i;
00147 
00148    if (cell->prim_buffer.num_verts == 0)
00149       return;
00150 
00151    for (i = 0; i < cell->num_spus; i++) {
00152       struct cell_command_render *render = &cell_global.command[i].render;
00153       render->prim_type = PIPE_PRIM_TRIANGLES;
00154       render->num_verts = cell->prim_buffer.num_verts;
00155       render->vertex_size = cell->vertex_info->size * 4;
00156       render->xmin = cell->prim_buffer.xmin;
00157       render->ymin = cell->prim_buffer.ymin;
00158       render->xmax = cell->prim_buffer.xmax;
00159       render->ymax = cell->prim_buffer.ymax;
00160       render->vertex_data = &cell->prim_buffer.vertex;
00161       ASSERT_ALIGN16(render->vertex_data);
00162       send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_RENDER);
00163    }
00164 
00165    cell->prim_buffer.num_verts = 0;
00166 
00167    cell->prim_buffer.xmin = 1e100;
00168    cell->prim_buffer.ymin = 1e100;
00169    cell->prim_buffer.xmax = -1e100;
00170    cell->prim_buffer.ymax = -1e100;
00171 
00172    /* XXX temporary, need to double-buffer the prim buffer until we get
00173     * a real command buffer/list system.
00174     */
00175    cell_flush(&cell->pipe, 0x0);
00176 }
00177 
00178 
00179 
00180 static void render_destroy( struct draw_stage *stage )
00181 {
00182    FREE( stage );
00183 }
00184 
00185 
00190 struct draw_stage *cell_draw_render_stage( struct cell_context *cell )
00191 {
00192    struct render_stage *render = CALLOC_STRUCT(render_stage);
00193 
00194    render->cell = cell;
00195    render->stage.draw = cell->draw;
00196    render->stage.begin = render_begin;
00197    render->stage.point = render_point;
00198    render->stage.line = render_line;
00199    render->stage.tri = render_tri;
00200    render->stage.end = render_end;
00201    render->stage.reset_stipple_counter = reset_stipple_counter;
00202    render->stage.destroy = render_destroy;
00203 
00204    /*
00205    render->quad.coef = render->coef;
00206    render->quad.posCoef = &render->posCoef;
00207    */
00208 
00209    return &render->stage;
00210 }

Generated on Tue Sep 29 06:25:15 2009 for Gallium3D by  doxygen 1.5.4