summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2008-01-01 15:21:14 -0700
committerBrian <brian.paul@tungstengraphics.com>2008-01-01 15:21:50 -0700
commitda92ac01e80e8a83233b1d4a881503bfc2806a1a (patch)
tree83116117a8eae67ae44c49b2cd90341d5c7462a6
parent57a711f7275993e75aa00918065b876776618a17 (diff)
Plug in more infrastructure for actual rendering.
Track vertex/fragment shader state. Plug in pipe->draw_arrays(), pipe->draw_elements(). Plug render stage (a stub) into end of 'draw' pipeline. Specify a hard-coded vertex format for now.
-rw-r--r--src/mesa/pipe/cell/ppu/Makefile3
-rw-r--r--src/mesa/pipe/cell/ppu/cell_context.c9
-rw-r--r--src/mesa/pipe/cell/ppu/cell_context.h27
-rw-r--r--src/mesa/pipe/cell/ppu/cell_draw_arrays.c169
-rw-r--r--src/mesa/pipe/cell/ppu/cell_draw_arrays.h42
-rw-r--r--src/mesa/pipe/cell/ppu/cell_render.c129
-rw-r--r--src/mesa/pipe/cell/ppu/cell_render.h36
-rw-r--r--src/mesa/pipe/cell/ppu/cell_state.h2
-rw-r--r--src/mesa/pipe/cell/ppu/cell_state_derived.c222
-rw-r--r--src/mesa/pipe/cell/ppu/cell_state_fs.c103
10 files changed, 675 insertions, 67 deletions
diff --git a/src/mesa/pipe/cell/ppu/Makefile b/src/mesa/pipe/cell/ppu/Makefile
index f597784d65..2758e1b77f 100644
--- a/src/mesa/pipe/cell/ppu/Makefile
+++ b/src/mesa/pipe/cell/ppu/Makefile
@@ -17,9 +17,12 @@ SPU_CODE_MODULE = ../spu/g3d_spu.a
SOURCES = \
cell_context.c \
+ cell_draw_arrays.c \
cell_flush.c \
+ cell_render.c \
cell_state_blend.c \
cell_state_clip.c \
+ cell_state_derived.c \
cell_state_fs.c \
cell_state_rasterizer.c \
cell_state_sampler.c \
diff --git a/src/mesa/pipe/cell/ppu/cell_context.c b/src/mesa/pipe/cell/ppu/cell_context.c
index 281fc6ec31..82b69ac33e 100644
--- a/src/mesa/pipe/cell/ppu/cell_context.c
+++ b/src/mesa/pipe/cell/ppu/cell_context.c
@@ -40,7 +40,9 @@
#include "pipe/cell/common.h"
#include "pipe/draw/draw_context.h"
#include "cell_context.h"
+#include "cell_draw_arrays.h"
#include "cell_flush.h"
+#include "cell_render.h"
#include "cell_state.h"
#include "cell_surface.h"
#include "cell_spu.h"
@@ -212,12 +214,9 @@ cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws)
cell->pipe.set_vertex_buffer = cell_set_vertex_buffer;
cell->pipe.set_vertex_element = cell_set_vertex_element;
-#if 0
- cell->pipe.set_feedback_buffer = cell_set_feedback_buffer;
cell->pipe.draw_arrays = cell_draw_arrays;
cell->pipe.draw_elements = cell_draw_elements;
-#endif
cell->pipe.clear = cell_clear_surface;
cell->pipe.flush = cell_flush;
@@ -235,6 +234,10 @@ cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws)
cell->draw = draw_create();
+ cell->render_stage = cell_draw_render_stage(cell);
+ draw_set_rasterize_stage(cell->draw, cell->render_stage);
+
+
/*
* SPU stuff
*/
diff --git a/src/mesa/pipe/cell/ppu/cell_context.h b/src/mesa/pipe/cell/ppu/cell_context.h
index f8d6cc5d32..5f6f987d8f 100644
--- a/src/mesa/pipe/cell/ppu/cell_context.h
+++ b/src/mesa/pipe/cell/ppu/cell_context.h
@@ -31,9 +31,25 @@
#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/draw/draw_vertex.h"
#include "cell_winsys.h"
+struct cell_vertex_shader_state
+{
+ struct pipe_shader_state shader;
+ void *draw_data;
+};
+
+
+struct cell_fragment_shader_state
+{
+ struct pipe_shader_state shader;
+ void *data;
+};
+
+
struct cell_context
{
struct pipe_context pipe;
@@ -44,6 +60,8 @@ struct cell_context
const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
const struct pipe_depth_stencil_alpha_state *depth_stencil;
const struct pipe_rasterizer_state *rasterizer;
+ const struct cell_vertex_shader_state *vs;
+ const struct cell_fragment_shader_state *fs;
struct pipe_blend_color blend_color;
struct pipe_clip_state clip;
@@ -55,13 +73,20 @@ struct cell_context
struct pipe_viewport_state viewport;
struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX];
struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX];
+
+
uint dirty;
/** The primitive drawing context */
struct draw_context *draw;
- struct draw_stage *setup;
+ struct draw_stage *render_stage;
struct draw_stage *vbuf;
+ struct vertex_info vertex_info;
+
+ /** Mapped constant buffers */
+ void *mapped_constants[PIPE_SHADER_TYPES];
+
uint num_spus;
diff --git a/src/mesa/pipe/cell/ppu/cell_draw_arrays.c b/src/mesa/pipe/cell/ppu/cell_draw_arrays.c
new file mode 100644
index 0000000000..c014f5b29d
--- /dev/null
+++ b/src/mesa/pipe/cell/ppu/cell_draw_arrays.c
@@ -0,0 +1,169 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/* Author:
+ * Brian Paul
+ * Keith Whitwell
+ */
+
+
+#include "pipe/p_defines.h"
+#include "pipe/p_context.h"
+#include "pipe/p_winsys.h"
+
+#include "cell_context.h"
+#include "cell_draw_arrays.h"
+#include "cell_state.h"
+
+#include "pipe/draw/draw_context.h"
+
+
+
+static void
+cell_map_constant_buffers(struct cell_context *sp)
+{
+ struct pipe_winsys *ws = sp->pipe.winsys;
+ uint i;
+ for (i = 0; i < 2; i++) {
+ if (sp->constants[i].size)
+ sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer,
+ PIPE_BUFFER_FLAG_READ);
+ }
+
+ draw_set_mapped_constant_buffer(sp->draw,
+ sp->mapped_constants[PIPE_SHADER_VERTEX]);
+}
+
+static void
+cell_unmap_constant_buffers(struct cell_context *sp)
+{
+ struct pipe_winsys *ws = sp->pipe.winsys;
+ uint i;
+ for (i = 0; i < 2; i++) {
+ if (sp->constants[i].size)
+ ws->buffer_unmap(ws, sp->constants[i].buffer);
+ sp->mapped_constants[i] = NULL;
+ }
+}
+
+
+boolean
+cell_draw_arrays(struct pipe_context *pipe, unsigned mode,
+ unsigned start, unsigned count)
+{
+ return cell_draw_elements(pipe, NULL, 0, mode, start, count);
+}
+
+
+
+/**
+ * Draw vertex arrays, with optional indexing.
+ * Basically, map the vertex buffers (and drawing surfaces), then hand off
+ * the drawing to the 'draw' module.
+ *
+ * XXX should the element buffer be specified/bound with a separate function?
+ */
+boolean
+cell_draw_elements(struct pipe_context *pipe,
+ struct pipe_buffer_handle *indexBuffer,
+ unsigned indexSize,
+ unsigned mode, unsigned start, unsigned count)
+{
+ struct cell_context *sp = cell_context(pipe);
+ struct draw_context *draw = sp->draw;
+ unsigned i;
+
+ /* first, check that the primitive is not malformed. It is the
+ * state tracker's responsibility to do send only correctly formed
+ * primitives down. It currently isn't doing that though...
+ */
+#if 1
+ count = draw_trim_prim( mode, count );
+#else
+ if (!draw_validate_prim( mode, count ))
+ assert(0);
+#endif
+
+ if (sp->dirty)
+ cell_update_derived( sp );
+
+#if 0
+ cell_map_surfaces(sp);
+#endif
+ cell_map_constant_buffers(sp);
+
+ /*
+ * Map vertex buffers
+ */
+ for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
+ if (sp->vertex_buffer[i].buffer) {
+ void *buf
+ = pipe->winsys->buffer_map(pipe->winsys,
+ sp->vertex_buffer[i].buffer,
+ PIPE_BUFFER_FLAG_READ);
+ draw_set_mapped_vertex_buffer(draw, i, buf);
+ }
+ }
+ /* Map index buffer, if present */
+ if (indexBuffer) {
+ void *mapped_indexes
+ = pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
+ PIPE_BUFFER_FLAG_READ);
+ draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
+ }
+ else {
+ /* no index/element buffer */
+ draw_set_mapped_element_buffer(draw, 0, NULL);
+ }
+
+
+ /* draw! */
+ draw_arrays(draw, mode, start, count);
+
+ /* always flush for now */
+ draw_flush(draw);
+
+ /*
+ * unmap vertex/index buffers
+ */
+ for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
+ if (sp->vertex_buffer[i].buffer) {
+ pipe->winsys->buffer_unmap(pipe->winsys, sp->vertex_buffer[i].buffer);
+ draw_set_mapped_vertex_buffer(draw, i, NULL);
+ }
+ }
+ if (indexBuffer) {
+ pipe->winsys->buffer_unmap(pipe->winsys, indexBuffer);
+ draw_set_mapped_element_buffer(draw, 0, NULL);
+ }
+
+
+ /* Note: leave drawing surfaces mapped */
+ cell_unmap_constant_buffers(sp);
+
+ return TRUE;
+}
diff --git a/src/mesa/pipe/cell/ppu/cell_draw_arrays.h b/src/mesa/pipe/cell/ppu/cell_draw_arrays.h
new file mode 100644
index 0000000000..bd5b703f3b
--- /dev/null
+++ b/src/mesa/pipe/cell/ppu/cell_draw_arrays.h
@@ -0,0 +1,42 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef CELL_DRAW_ARRAYS_H
+#define CELL_DRAW_ARRAYS_H
+
+
+boolean cell_draw_arrays(struct pipe_context *pipe, unsigned mode,
+ unsigned start, unsigned count);
+
+boolean cell_draw_elements(struct pipe_context *pipe,
+ struct pipe_buffer_handle *indexBuffer,
+ unsigned indexSize,
+ unsigned mode, unsigned start, unsigned count);
+
+
+
+#endif /* CELL_DRAW_ARRAYS_H */
diff --git a/src/mesa/pipe/cell/ppu/cell_render.c b/src/mesa/pipe/cell/ppu/cell_render.c
new file mode 100644
index 0000000000..c7f0cf6be6
--- /dev/null
+++ b/src/mesa/pipe/cell/ppu/cell_render.c
@@ -0,0 +1,129 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * \brief Last stage of 'draw' pipeline: send tris to SPUs.
+ * \author Brian Paul
+ */
+
+#include "cell_context.h"
+#include "cell_render.h"
+#include "pipe/p_util.h"
+#include "pipe/draw/draw_private.h"
+
+
+struct render_stage {
+ struct draw_stage stage; /**< This must be first (base class) */
+
+ struct cell_context *cell;
+};
+
+
+static INLINE struct render_stage *
+render_stage(struct draw_stage *stage)
+{
+ return (struct render_stage *) stage;
+}
+
+
+static void render_begin( struct draw_stage *stage )
+{
+#if 0
+ struct render_stage *render = render_stage(stage);
+ struct cell_context *sp = render->cell;
+ const struct pipe_shader_state *fs = &render->cell->fs->shader;
+ render->quad.nr_attrs = render->cell->nr_frag_attrs;
+
+ render->firstFpInput = fs->input_semantic_name[0];
+
+ sp->quad.first->begin(sp->quad.first);
+#endif
+}
+
+
+static void render_end( struct draw_stage *stage )
+{
+}
+
+
+static void reset_stipple_counter( struct draw_stage *stage )
+{
+ struct render_stage *render = render_stage(stage);
+ /*render->cell->line_stipple_counter = 0;*/
+}
+
+
+static void
+render_point(struct draw_stage *stage, struct prim_header *prim)
+{
+}
+
+
+static void
+render_line(struct draw_stage *stage, struct prim_header *prim)
+{
+}
+
+
+static void
+render_tri(struct draw_stage *stage, struct prim_header *prim)
+{
+ printf("Cell render tri\n");
+}
+
+
+static void render_destroy( struct draw_stage *stage )
+{
+ FREE( stage );
+}
+
+
+/**
+ * Create a new draw/render stage. This will be plugged into the
+ * draw module as the last pipeline stage.
+ */
+struct draw_stage *cell_draw_render_stage( struct cell_context *cell )
+{
+ struct render_stage *render = CALLOC_STRUCT(render_stage);
+
+ render->cell = cell;
+ render->stage.draw = cell->draw;
+ render->stage.begin = render_begin;
+ render->stage.point = render_point;
+ render->stage.line = render_line;
+ render->stage.tri = render_tri;
+ render->stage.end = render_end;
+ render->stage.reset_stipple_counter = reset_stipple_counter;
+ render->stage.destroy = render_destroy;
+
+ /*
+ render->quad.coef = render->coef;
+ render->quad.posCoef = &render->posCoef;
+ */
+
+ return &render->stage;
+}
diff --git a/src/mesa/pipe/cell/ppu/cell_render.h b/src/mesa/pipe/cell/ppu/cell_render.h
new file mode 100644
index 0000000000..d66e1bdb79
--- /dev/null
+++ b/src/mesa/pipe/cell/ppu/cell_render.h
@@ -0,0 +1,36 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef CELL_RENDER_H
+#define CELL_RENDER_H
+
+struct cell_context;
+struct draw_stage;
+
+extern struct draw_stage *cell_draw_render_stage( struct cell_context *cell );
+
+#endif /* CELL_RENDER_H */
diff --git a/src/mesa/pipe/cell/ppu/cell_state.h b/src/mesa/pipe/cell/ppu/cell_state.h
index 63dbac2f02..d2091f8edf 100644
--- a/src/mesa/pipe/cell/ppu/cell_state.h
+++ b/src/mesa/pipe/cell/ppu/cell_state.h
@@ -104,4 +104,6 @@ void cell_set_viewport_state( struct pipe_context *,
const struct pipe_viewport_state * );
+void cell_update_derived( struct cell_context *softpipe );
+
#endif
diff --git a/src/mesa/pipe/cell/ppu/cell_state_derived.c b/src/mesa/pipe/cell/ppu/cell_state_derived.c
new file mode 100644
index 0000000000..ee7c0204b8
--- /dev/null
+++ b/src/mesa/pipe/cell/ppu/cell_state_derived.c
@@ -0,0 +1,222 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "pipe/p_util.h"
+#include "pipe/p_shader_tokens.h"
+#include "pipe/draw/draw_context.h"
+#include "pipe/draw/draw_vertex.h"
+#include "cell_context.h"
+#include "cell_state.h"
+
+
+/**
+ * Determine which post-transform / pre-rasterization vertex attributes
+ * we need.
+ * Derived from: fs, setup states.
+ */
+static void calculate_vertex_layout( struct cell_context *cell )
+{
+#if 0
+ const struct pipe_shader_state *vs = cell->vs->state;
+ const struct pipe_shader_state *fs = &cell->fs->shader;
+ const enum interp_mode colorInterp
+ = cell->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
+ struct vertex_info *vinfo = &cell->vertex_info;
+ boolean emitBack0 = FALSE, emitBack1 = FALSE, emitPsize = FALSE;
+ uint front0 = 0, back0 = 0, front1 = 0, back1 = 0;
+ uint i;
+#endif
+ const enum interp_mode colorInterp
+ = cell->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
+ struct vertex_info *vinfo = &cell->vertex_info;
+ uint front0;
+
+ memset(vinfo, 0, sizeof(*vinfo));
+
+#if 0
+ if (fs->input_semantic_name[0] == TGSI_SEMANTIC_POSITION) {
+ /* Need Z if depth test is enabled or the fragment program uses the
+ * fragment position (XYZW).
+ */
+ }
+
+ cell->psize_slot = -1;
+#endif
+
+ /* always emit vertex pos */
+ draw_emit_vertex_attr(vinfo, FORMAT_4F, INTERP_LINEAR);
+
+#if 1
+ front0 = draw_emit_vertex_attr(vinfo, FORMAT_4F, colorInterp);
+#endif
+
+#if 0
+ /*
+ * XXX I think we need to reconcile the vertex shader outputs with
+ * the fragment shader inputs here to make sure the slots line up.
+ * Might just be getting lucky so far.
+ * Or maybe do that in the state tracker?
+ */
+
+ for (i = 0; i < vs->num_outputs; i++) {
+ switch (vs->output_semantic_name[i]) {
+
+ case TGSI_SEMANTIC_POSITION:
+ /* vertex programs always emit position, but might not be
+ * needed for fragment progs.
+ */
+ /* no-op */
+ break;
+
+ case TGSI_SEMANTIC_COLOR:
+ if (vs->output_semantic_index[i] == 0) {
+ front0 = draw_emit_vertex_attr(vinfo, FORMAT_4F, colorInterp);
+ }
+ else {
+ assert(vs->output_semantic_index[i] == 1);
+ front1 = draw_emit_vertex_attr(vinfo, FORMAT_4F, colorInterp);
+ }
+ break;
+
+ case TGSI_SEMANTIC_BCOLOR:
+ if (vs->output_semantic_index[i] == 0) {
+ emitBack0 = TRUE;
+ }
+ else {
+ assert(vs->output_semantic_index[i] == 1);
+ emitBack1 = TRUE;
+ }
+ break;
+
+ case TGSI_SEMANTIC_FOG:
+ draw_emit_vertex_attr(vinfo, FORMAT_1F, INTERP_PERSPECTIVE);
+ break;
+
+ case TGSI_SEMANTIC_PSIZE:
+ /* XXX only emit if drawing points or front/back polygon mode
+ * is point mode
+ */
+ emitPsize = TRUE;
+ break;
+
+ case TGSI_SEMANTIC_GENERIC:
+ /* this includes texcoords and varying vars */
+ draw_emit_vertex_attr(vinfo, FORMAT_4F, INTERP_PERSPECTIVE);
+ break;
+
+ default:
+ assert(0);
+ }
+ }
+
+ cell->nr_frag_attrs = fs->num_inputs;
+
+ /* We want these after all other attribs since they won't get passed
+ * to the fragment shader. All prior vertex output attribs should match
+ * up 1:1 with the fragment shader inputs.
+ */
+ if (emitBack0) {
+ back0 = draw_emit_vertex_attr(vinfo, FORMAT_4F, colorInterp);
+ }
+ if (emitBack1) {
+ back1 = draw_emit_vertex_attr(vinfo, FORMAT_4F, colorInterp);
+ }
+ if (emitPsize) {
+ cell->psize_slot
+ = draw_emit_vertex_attr(vinfo, FORMAT_1F, INTERP_CONSTANT);
+ }
+
+ /* If the attributes have changed, tell the draw module about
+ * the new vertex layout.
+ */
+ /* XXX we also need to do this when the shading mode (interp modes) change: */
+#endif
+
+ if (1/*vinfo->attr_mask != cell->attr_mask*/) {
+ /*cell->attr_mask = vinfo->attr_mask;*/
+
+ draw_set_vertex_info( cell->draw, vinfo);
+
+#if 0
+ draw_set_twoside_attributes(cell->draw,
+ front0, back0, front1, back1);
+#endif
+ }
+}
+
+
+#if 0
+/**
+ * Recompute cliprect from scissor bounds, scissor enable and surface size.
+ */
+static void
+compute_cliprect(struct cell_context *sp)
+{
+ unsigned surfWidth, surfHeight;
+
+ if (sp->framebuffer.num_cbufs > 0) {
+ surfWidth = sp->framebuffer.cbufs[0]->width;
+ surfHeight = sp->framebuffer.cbufs[0]->height;
+ }
+ else {
+ /* no surface? */
+ surfWidth = sp->scissor.maxx;
+ surfHeight = sp->scissor.maxy;
+ }
+
+ if (sp->rasterizer->scissor) {
+ /* clip to scissor rect */
+ sp->cliprect.minx = MAX2(sp->scissor.minx, 0);
+ sp->cliprect.miny = MAX2(sp->scissor.miny, 0);
+ sp->cliprect.maxx = MIN2(sp->scissor.maxx, surfWidth);
+ sp->cliprect.maxy = MIN2(sp->scissor.maxy, surfHeight);
+ }
+ else {
+ /* clip to surface bounds */
+ sp->cliprect.minx = 0;
+ sp->cliprect.miny = 0;
+ sp->cliprect.maxx = surfWidth;
+ sp->cliprect.maxy = surfHeight;
+ }
+}
+#endif
+
+
+void cell_update_derived( struct cell_context *cell )
+{
+ if (cell->dirty & (CELL_NEW_RASTERIZER | CELL_NEW_FS))
+ calculate_vertex_layout( cell );
+
+#if 0
+ if (cell->dirty & (CELL_NEW_SCISSOR |
+ CELL_NEW_DEPTH_STENCIL_ALPHA |
+ CELL_NEW_FRAMEBUFFER))
+ compute_cliprect(cell);
+#endif
+
+ cell->dirty = 0;
+}
diff --git a/src/mesa/pipe/cell/ppu/cell_state_fs.c b/src/mesa/pipe/cell/ppu/cell_state_fs.c
index 910f210cdc..5a935f2de1 100644
--- a/src/mesa/pipe/cell/ppu/cell_state_fs.c
+++ b/src/mesa/pipe/cell/ppu/cell_state_fs.c
@@ -28,8 +28,8 @@
#include "pipe/p_defines.h"
#include "pipe/p_util.h"
#include "pipe/p_winsys.h"
-#if 0
#include "pipe/draw/draw_context.h"
+#if 0
#include "pipe/p_shader_tokens.h"
#include "pipe/llvm/gallivm.h"
#include "pipe/tgsi/util/tgsi_dump.h"
@@ -40,25 +40,22 @@
#include "cell_state.h"
-void * cell_create_fs_state(struct pipe_context *pipe,
- const struct pipe_shader_state *templ)
+void *
+cell_create_fs_state(struct pipe_context *pipe,
+ const struct pipe_shader_state *templ)
{
struct cell_context *cell = cell_context(pipe);
+ struct cell_fragment_shader_state *state;
- return malloc(5); /* XXX temp */
-
-#if 0
- /* Decide whether we'll be codegenerating this shader and if so do
- * that now.
- */
+ state = CALLOC_STRUCT(cell_fragment_shader_state);
+ if (!state)
+ return NULL;
- struct sp_fragment_shader_state *state = MALLOC( sizeof(struct sp_fragment_shader_state) );
state->shader = *templ;
- if( cell->dump_fs ) {
- tgsi_dump(
- state->shader.tokens,
- 0 );
+#if 0
+ if (cell->dump_fs) {
+ tgsi_dump(state->shader.tokens, 0);
}
#if defined(__i386__) || defined(__386__)
@@ -76,32 +73,32 @@ void * cell_create_fs_state(struct pipe_context *pipe,
else
gallivm_cpu_jit_compile(gallivm_global_cpu_engine(), state->llvm_prog);
#endif
- return state;
#endif
+
+ return state;
}
-void cell_bind_fs_state(struct pipe_context *pipe, void *fs)
+
+void
+cell_bind_fs_state(struct pipe_context *pipe, void *fs)
{
struct cell_context *cell = cell_context(pipe);
-#if 0
- cell->fs = (struct sp_fragment_shader_state *) fs;
- cell->dirty |= SP_NEW_FS;
-#endif
+ cell->fs = (struct cell_fragment_shader_state *) fs;
+
+ cell->dirty |= CELL_NEW_FS;
}
-void cell_delete_fs_state(struct pipe_context *pipe,
- void *shader)
+
+void
+cell_delete_fs_state(struct pipe_context *pipe, void *fs)
{
-#if 0
- struct sp_fragment_shader_state *state = shader;
+ struct cell_context *cell = cell_context(pipe);
-#if defined(__i386__) || defined(__386__)
- x86_release_func( &state->sse2_program );
-#endif
+ struct cell_fragment_shader_state *state =
+ (struct cell_fragment_shader_state *) fs;
FREE( state );
-#endif
}
@@ -109,73 +106,56 @@ void *
cell_create_vs_state(struct pipe_context *pipe,
const struct pipe_shader_state *templ)
{
- return malloc(5); /* XXX */
-#if 0
struct cell_context *cell = cell_context(pipe);
- struct sp_vertex_shader_state *state;
+ struct cell_vertex_shader_state *state;
- state = MALLOC( sizeof(struct sp_vertex_shader_state) );
- if (state == NULL ) {
+ state = CALLOC_STRUCT(cell_vertex_shader_state);
+ if (!state)
return NULL;
- }
- state->state = MALLOC( sizeof(struct pipe_shader_state) );
- if (state->state == NULL) {
- FREE( state );
- return NULL;
- }
- memcpy( state->state, templ, sizeof(struct pipe_shader_state) );
+ state->shader = *templ;
- state->draw_data = draw_create_vertex_shader(cell->draw,
- state->state);
+ state->draw_data = draw_create_vertex_shader(cell->draw, &state->shader);
if (state->draw_data == NULL) {
- FREE( state->state );
FREE( state );
return NULL;
}
return state;
-#endif
}
-
void
cell_bind_vs_state(struct pipe_context *pipe, void *vs)
{
-#if 0
struct cell_context *cell = cell_context(pipe);
- cell->vs = (const struct sp_vertex_shader_state *)vs;
+ cell->vs = (const struct cell_vertex_shader_state *) vs;
draw_bind_vertex_shader(cell->draw, cell->vs->draw_data);
- cell->dirty |= SP_NEW_VS;
-#endif
+ cell->dirty |= CELL_NEW_VS;
}
+
void
cell_delete_vs_state(struct pipe_context *pipe, void *vs)
{
-#if 0
struct cell_context *cell = cell_context(pipe);
- struct sp_vertex_shader_state *state =
- (struct sp_vertex_shader_state *)vs;
+ struct cell_vertex_shader_state *state =
+ (struct cell_vertex_shader_state *) vs;
draw_delete_vertex_shader(cell->draw, state->draw_data);
- FREE( state->state );
FREE( state );
-#endif
}
-
-void cell_set_constant_buffer(struct pipe_context *pipe,
- uint shader, uint index,
- const struct pipe_constant_buffer *buf)
+void
+cell_set_constant_buffer(struct pipe_context *pipe,
+ uint shader, uint index,
+ const struct pipe_constant_buffer *buf)
{
-#if 0
struct cell_context *cell = cell_context(pipe);
struct pipe_winsys *ws = pipe->winsys;
@@ -188,8 +168,5 @@ void cell_set_constant_buffer(struct pipe_context *pipe,
buf->buffer);
cell->constants[shader].size = buf->size;
- cell->dirty |= SP_NEW_CONSTANTS;
-#endif
+ cell->dirty |= CELL_NEW_CONSTANTS;
}
-
-