diff options
Diffstat (limited to 'src/mesa/softpipe/state_tracker')
-rw-r--r-- | src/mesa/softpipe/state_tracker/Makefile | 2 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_atom.c | 168 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_atom.h | 55 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_atom_cbuf.c | 72 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_atom_clip.c | 75 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_atom_fs.c | 56 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_atom_setup.c | 175 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_atom_viewport.c | 117 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_cb_program.c | 165 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_context.c | 76 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_context.h | 109 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_draw.c | 107 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_draw.h | 40 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_program.h | 68 | ||||
-rw-r--r-- | src/mesa/softpipe/state_tracker/st_public.h | 43 |
15 files changed, 1328 insertions, 0 deletions
diff --git a/src/mesa/softpipe/state_tracker/Makefile b/src/mesa/softpipe/state_tracker/Makefile new file mode 100644 index 0000000000..0ab1dc6e6b --- /dev/null +++ b/src/mesa/softpipe/state_tracker/Makefile @@ -0,0 +1,2 @@ +default: + cd ../.. ; make
\ No newline at end of file diff --git a/src/mesa/softpipe/state_tracker/st_atom.c b/src/mesa/softpipe/state_tracker/st_atom.c new file mode 100644 index 0000000000..99fba398bf --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_atom.c @@ -0,0 +1,168 @@ +/************************************************************************** + * + * Copyright 2003 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 "glheader.h" +#include "context.h" + +#include "st_context.h" +#include "st_atom.h" + + + +/* This is used to initialize st->atoms[]. We could use this list + * directly except for a single atom, st_update_constants, which has a + * .dirty value which changes according to the parameters of the + * current fragment and vertex programs, and so cannot be a static + * value. + */ +static const struct st_tracked_state *atoms[] = +{ + &st_update_cbuf, + &st_update_clip, + &st_update_fs, + &st_update_setup, + &st_update_viewport, + /* will be patched out at runtime */ +/* &st_update_constants */ +}; + + +void st_init_atoms( struct st_context *st ) +{ + GLuint i; + + st->atoms = _mesa_malloc(sizeof(atoms)); + st->nr_atoms = sizeof(atoms)/sizeof(*atoms); + _mesa_memcpy(st->atoms, atoms, sizeof(atoms)); + + /* Patch in a pointer to the dynamic state atom: + */ + for (i = 0; i < st->nr_atoms; i++) + if (st->atoms[i] == &st_update_constants) + st->atoms[i] = &st->constants.tracked_state; + + _mesa_memcpy(&st->constants.tracked_state, + &st_update_constants, + sizeof(st_update_constants)); +} + + +void st_destroy_atoms( struct st_context *st ) +{ + if (st->atoms) { + _mesa_free(st->atoms); + st->atoms = NULL; + } +} + + +/*********************************************************************** + */ + +static GLboolean check_state( const struct st_state_flags *a, + const struct st_state_flags *b ) +{ + return ((a->mesa & b->mesa) || + (a->st & b->st)); +} + +static void accumulate_state( struct st_state_flags *a, + const struct st_state_flags *b ) +{ + a->mesa |= b->mesa; + a->st |= b->st; +} + + +static void xor_states( struct st_state_flags *result, + const struct st_state_flags *a, + const struct st_state_flags *b ) +{ + result->mesa = a->mesa ^ b->mesa; + result->st = a->st ^ b->st; +} + + +/*********************************************************************** + * Update all derived state: + */ + +void st_validate_state( struct st_context *st ) +{ + struct st_state_flags *state = &st->dirty; + GLuint i; + + if (state->st == 0) + return; + + if (1) { + /* Debug version which enforces various sanity checks on the + * state flags which are generated and checked to help ensure + * state atoms are ordered correctly in the list. + */ + struct st_state_flags examined, prev; + _mesa_memset(&examined, 0, sizeof(examined)); + prev = *state; + + for (i = 0; i < st->nr_atoms; i++) { + const struct st_tracked_state *atom = st->atoms[i]; + struct st_state_flags generated; + + assert(atom->dirty.mesa || + atom->dirty.st); + assert(atom->update); + + if (check_state(state, &atom->dirty)) { + st->atoms[i]->update( st ); + } + + accumulate_state(&examined, &atom->dirty); + + /* generated = (prev ^ state) + * if (examined & generated) + * fail; + */ + xor_states(&generated, &prev, state); + assert(!check_state(&examined, &generated)); + prev = *state; + } + } + else { + const GLuint nr = st->nr_atoms; + + for (i = 0; i < nr; i++) { + if (check_state(state, &st->atoms[i]->dirty)) + st->atoms[i]->update( st ); + } + } + + memset(state, 0, sizeof(*state)); +} + + + diff --git a/src/mesa/softpipe/state_tracker/st_atom.h b/src/mesa/softpipe/state_tracker/st_atom.h new file mode 100644 index 0000000000..87b72940b4 --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_atom.h @@ -0,0 +1,55 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell <keith@tungstengraphics.com> + */ + + +#ifndef ST_ATOM_H +#define ST_ATOM_H + +struct st_context; +struct st_tracked_state; + +void st_init_atoms( struct st_context *st ); +void st_destroy_atoms( struct st_context *st ); + + +void st_validate_state( struct st_context *st ); + + +const struct st_tracked_state st_update_cbuf; +const struct st_tracked_state st_update_clip; +const struct st_tracked_state st_update_fs; +const struct st_tracked_state st_update_setup; +const struct st_tracked_state st_update_viewport; +const struct st_tracked_state st_update_constants; + + +#endif diff --git a/src/mesa/softpipe/state_tracker/st_atom_cbuf.c b/src/mesa/softpipe/state_tracker/st_atom_cbuf.c new file mode 100644 index 0000000000..cd707ec5ef --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_atom_cbuf.c @@ -0,0 +1,72 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell <keith@tungstengraphics.com> + */ + +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + +extern GLboolean xmesa_get_cbuf_details( GLcontext *ctx, + void **ptr, + GLuint *cpp, + GLint *stride, + GLuint *format ); + + +/* This is a hack to work with the X11 driver as a test harness + */ +static void update_cbuf_state( struct st_context *st ) +{ + struct softpipe_surface cbuf; + GLboolean ok; + + ok = xmesa_get_cbuf_details( st->ctx, + (void **)&cbuf.ptr, + &cbuf.cpp, + &cbuf.stride, + &cbuf.format ); + + assert(ok); + + if (memcmp(&cbuf, &st->state.cbuf, sizeof(cbuf)) != 0) { + st->state.cbuf = cbuf; + st->softpipe->set_cbuf_state( st->softpipe, &cbuf ); + } +} + +const struct st_tracked_state st_update_cbuf = { + .dirty = { + .mesa = _NEW_BUFFERS, + .st = 0, + }, + .update = update_cbuf_state +}; + diff --git a/src/mesa/softpipe/state_tracker/st_atom_clip.c b/src/mesa/softpipe/state_tracker/st_atom_clip.c new file mode 100644 index 0000000000..1a0d2c4053 --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_atom_clip.c @@ -0,0 +1,75 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell <keith@tungstengraphics.com> + */ + + +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + + +/* Second state atom for user clip planes: + */ +static void update_clip( struct st_context *st ) +{ + struct softpipe_clip_state clip; + GLuint i; + + memset(&clip, 0, sizeof(clip)); + + for (i = 0; i < 6; i++) { + if (st->ctx->Transform.ClipPlanesEnabled & (1 << i)) { + memcpy(clip.ucp[clip.nr], + st->ctx->Transform._ClipUserPlane[i], + sizeof(clip.ucp[0])); + clip.nr++; + } + } + + if (memcmp(&clip, &st->state.clip, sizeof(clip)) != 0) { + st->state.clip = clip; + st->softpipe->set_clip_state(st->softpipe, &clip); + } +} + + +const struct st_tracked_state st_update_clip = { + .dirty = { + .mesa = (_NEW_TRANSFORM), + .st = 0, + }, + .update = update_clip +}; + + + + + diff --git a/src/mesa/softpipe/state_tracker/st_atom_fs.c b/src/mesa/softpipe/state_tracker/st_atom_fs.c new file mode 100644 index 0000000000..ca109d2d34 --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_atom_fs.c @@ -0,0 +1,56 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell <keith@tungstengraphics.com> + */ + +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + + +static void update_fs( struct st_context *st ) +{ + struct softpipe_fs_state fs; + + fs.fp = st->ctx->FragmentProgram._Current; + + if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0) { + st->state.fs = fs; + st->softpipe->set_fs_state(st->softpipe, &fs); + } +} + + +const struct st_tracked_state st_update_fs = { + .dirty = { + .mesa = 0, + .st = ST_NEW_FRAGMENT_PROGRAM, + }, + .update = update_fs +}; diff --git a/src/mesa/softpipe/state_tracker/st_atom_setup.c b/src/mesa/softpipe/state_tracker/st_atom_setup.c new file mode 100644 index 0000000000..2a582ea36c --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_atom_setup.c @@ -0,0 +1,175 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell <keith@tungstengraphics.com> + */ + + +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + +static GLuint translate_fill( GLenum mode ) +{ + switch (mode) { + case GL_POINT: return FILL_POINT; + case GL_LINE: return FILL_LINE; + case GL_FILL: return FILL_TRI; + default: assert(0); return 0; + } +} + +static GLboolean get_offset_flag( GLuint fill_mode, + const struct gl_polygon_attrib *Polygon ) +{ + switch (fill_mode) { + case FILL_POINT: return Polygon->OffsetPoint; + case FILL_LINE: return Polygon->OffsetLine; + case FILL_TRI: return Polygon->OffsetFill; + default: assert(0); return 0; + } +} + + +static void update_setup_state( struct st_context *st ) +{ + GLcontext *ctx = st->ctx; + struct softpipe_setup_state setup; + + memset(&setup, 0, sizeof(setup)); + + /* _NEW_POLYGON, _NEW_BUFFERS + */ + { + setup.front_winding = WINDING_CW; + + if (ctx->DrawBuffer && ctx->DrawBuffer->Name != 0) + setup.front_winding ^= WINDING_BOTH; + + if (ctx->Polygon.FrontFace != GL_CCW) + setup.front_winding ^= WINDING_BOTH; + } + + /* _NEW_LIGHT + */ + if (ctx->Light.ShadeModel == GL_FLAT) + setup.flatshade = 1; + + /* _NEW_LIGHT + * + * Not sure about the light->enabled requirement - does this still + * apply?? + */ + if (ctx->Light.Enabled && + ctx->Light.Model.TwoSide) + setup.light_twoside = 1; + + + /* _NEW_POLYGON + */ + if (ctx->Polygon.CullFlag) { + if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) { + setup.cull_mode = WINDING_BOTH; + } + else if (ctx->Polygon.CullFaceMode == GL_FRONT) { + setup.cull_mode = setup.front_winding; + } + else { + setup.cull_mode = setup.front_winding ^ WINDING_BOTH; + } + } + + /* _NEW_POLYGON + */ + { + GLuint fill_front = translate_fill( ctx->Polygon.FrontMode ); + GLuint fill_back = translate_fill( ctx->Polygon.BackMode ); + + if (setup.front_winding == WINDING_CW) { + setup.fill_cw = fill_front; + setup.fill_ccw = fill_back; + } + else { + setup.fill_cw = fill_back; + setup.fill_ccw = fill_front; + } + + /* Simplify when culling is active: + */ + if (setup.cull_mode & WINDING_CW) { + setup.fill_cw = setup.fill_ccw; + } + + if (setup.cull_mode & WINDING_CCW) { + setup.fill_ccw = setup.fill_cw; + } + } + + /* Hardware does offset for filled prims, but need to do it in + * software for unfilled. + * + * _NEW_POLYGON + */ + if (setup.fill_cw != FILL_TRI) + setup.offset_cw = get_offset_flag( setup.fill_cw, + &ctx->Polygon ); + + if (setup.fill_ccw != FILL_TRI) + setup.offset_ccw = get_offset_flag( setup.fill_ccw, + &ctx->Polygon ); + + + /* _NEW_BUFFERS, _NEW_POLYGON + */ + if (setup.fill_cw != FILL_TRI || + setup.fill_ccw != FILL_TRI) + { + GLfloat mrd = (ctx->DrawBuffer ? + ctx->DrawBuffer->_MRD : + 1.0); + + setup.offset_units = ctx->Polygon.OffsetFactor * mrd; + setup.offset_scale = (ctx->Polygon.OffsetUnits * mrd * + st->polygon_offset_scale); + } + + + if (memcmp(&setup, &st->state.setup, sizeof(setup)) != 0) { + st->state.setup = setup; + st->softpipe->set_setup_state( st->softpipe, &setup ); + } +} + +const struct st_tracked_state st_update_setup = { + .dirty = { + .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_BUFFERS), + .st = 0, + }, + .update = update_setup_state +}; diff --git a/src/mesa/softpipe/state_tracker/st_atom_viewport.c b/src/mesa/softpipe/state_tracker/st_atom_viewport.c new file mode 100644 index 0000000000..af896e2e31 --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_atom_viewport.c @@ -0,0 +1,117 @@ +/************************************************************************** + * + * 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 "context.h" +#include "colormac.h" +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + + + + + +/** + * Update the viewport transformation matrix. Depends on: + * - viewport pos/size + * - depthrange + * - window pos/size or FBO size + */ +static void update_viewport( struct st_context *st ) +{ + GLcontext *ctx = st->ctx; + const GLframebuffer *DrawBuffer = ctx->DrawBuffer; + GLfloat yScale = 1.0; + GLfloat yBias = 0.0; + + /* _NEW_BUFFERS + */ + if (DrawBuffer) { + +#if 0 + if (DrawBuffer->Name) { + /* User created FBO */ + struct st_renderbuffer *irb + = st_renderbuffer(DrawBuffer->_ColorDrawBuffers[0][0]); + if (irb && !irb->RenderToTexture) { + /* y=0=top */ + yScale = -1.0; + yBias = irb->Base.Height; + } + else { + /* y=0=bottom */ + yScale = 1.0; + yBias = 0.0; + } + } + else + { + /* window buffer, y=0=top */ + yScale = -1.0; + yBias = DrawBuffer->Height; + } +#endif + } + + { + /* _NEW_VIEWPORT + */ + GLfloat x = ctx->Viewport.X; + GLfloat y = ctx->Viewport.Y; + GLfloat z = ctx->Viewport.Near; + GLfloat half_width = ctx->Viewport.Width / 2.0; + GLfloat half_height = ctx->Viewport.Height / 2.0; + GLfloat half_depth = (ctx->Viewport.Far - ctx->Viewport.Near) / 2.0; + + struct softpipe_viewport vp; + + vp.scale[0] = half_width; + vp.scale[1] = half_height * yScale; + vp.scale[2] = half_depth; + vp.scale[3] = 1.0; + + vp.translate[0] = (half_width + x); + vp.translate[1] = (half_height + y) * yScale + yBias; + vp.translate[2] = (half_depth + z); + vp.translate[3] = 0.0; + + if (memcmp(&vp, &st->state.viewport, sizeof(vp)) != 0) { + st->state.viewport = vp; + st->softpipe->set_viewport(st->softpipe, &vp); + } + } +} + + +const struct st_tracked_state st_update_viewport = { + .dirty = { + .mesa = _NEW_BUFFERS | _NEW_VIEWPORT, + .st = 0, + }, + .update = update_viewport +}; diff --git a/src/mesa/softpipe/state_tracker/st_cb_program.c b/src/mesa/softpipe/state_tracker/st_cb_program.c new file mode 100644 index 0000000000..67a589ca8d --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_cb_program.c @@ -0,0 +1,165 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell <keith@tungstengraphics.com> + */ + +#include "st_context.h" +#include "st_program.h" + +#include "glheader.h" +#include "macros.h" +#include "enums.h" +#include "prog_instruction.h" +#include "prog_parameter.h" +#include "program.h" +#include "programopt.h" +#include "tnl/tnl.h" + + +static void st_bind_program( GLcontext *ctx, + GLenum target, + struct gl_program *prog ) +{ + struct st_context *st = st_context(ctx); + + switch (target) { + case GL_VERTEX_PROGRAM_ARB: + break; + case GL_FRAGMENT_PROGRAM_ARB: + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; + break; + } +} + +static struct gl_program *st_new_program( GLcontext *ctx, + GLenum target, + GLuint id ) +{ + struct st_context *st = st_context(ctx); + + switch (target) { + case GL_VERTEX_PROGRAM_ARB: + return _mesa_init_vertex_program(ctx, + CALLOC_STRUCT(gl_vertex_program), + target, + id); + + case GL_FRAGMENT_PROGRAM_ARB: { + struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program); + + prog->id = st->program_id++; + + return _mesa_init_fragment_program( ctx, + &prog->Base, + target, + id ); + } + + default: + return _mesa_new_program(ctx, target, id); + } +} + +static void st_delete_program( GLcontext *ctx, + struct gl_program *prog ) +{ + _mesa_delete_program( ctx, prog ); +} + + +static GLboolean st_is_program_native( GLcontext *ctx, + GLenum target, + struct gl_program *prog ) +{ + return GL_TRUE; +} + +static void st_program_string_notify( GLcontext *ctx, + GLenum target, + struct gl_program *prog ) +{ + if (target == GL_FRAGMENT_PROGRAM_ARB) { + struct st_context *st = st_context(ctx); + + if (prog == &st->ctx->FragmentProgram._Current->Base) + { + struct st_fragment_program *p = + (struct st_fragment_program *) prog; + + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; + + p->id = st->program_id++; +#if 0 + p->param_state = p->Base.Base.Parameters->StateFlags; + p->translated = 0; +#endif + + /* Gack! do this in the compiler: + */ + if (p->Base.FogOption) { + /* add extra instructions to do fog, then turn off FogOption field */ + _mesa_append_fog_code(ctx, &p->Base); + p->Base.FogOption = GL_NONE; + } + } + } + else if (target == GL_VERTEX_PROGRAM_ARB) { + + /* Also tell tnl about it: + */ + _tnl_program_string(ctx, target, prog); + } +} + + + +void st_init_cb_program( struct st_context *st ) +{ + struct dd_function_table *functions = &st->ctx->Driver; + + /* Need these flags: + */ + st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; + st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; + + + assert(functions->ProgramStringNotify == _tnl_program_string); + functions->BindProgram = st_bind_program; + functions->NewProgram = st_new_program; + functions->DeleteProgram = st_delete_program; + functions->IsProgramNative = st_is_program_native; + functions->ProgramStringNotify = st_program_string_notify; +} + + +void st_destroy_cb_program( struct st_context *st ) +{ +} + diff --git a/src/mesa/softpipe/state_tracker/st_context.c b/src/mesa/softpipe/state_tracker/st_context.c new file mode 100644 index 0000000000..8a06dd88df --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_context.c @@ -0,0 +1,76 @@ +/************************************************************************** + * + * Copyright 2003 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 "imports.h" +#include "st_public.h" +#include "st_context.h" +#include "st_atom.h" +#include "st_draw.h" +#include "st_program.h" +#include "softpipe/sp_context.h" + +void st_invalidate_state(GLcontext * ctx, GLuint new_state) +{ + struct st_context *st = st_context(ctx); + + st->dirty.mesa |= new_state; + st->dirty.st |= ST_NEW_MESA; +} + + +struct st_context *st_create_context( GLcontext *ctx, + struct softpipe_context *softpipe ) +{ + struct st_context *st = CALLOC_STRUCT( st_context ); + + ctx->st = st; + + st->ctx = ctx; + st->softpipe = softpipe; + + st->dirty.mesa = ~0; + st->dirty.st = ~0; + + st_init_atoms( st ); + st_init_draw( st ); + st_init_cb_program( st ); + + return st; +} + + +void st_destroy_context( struct st_context *st ) +{ + st_destroy_atoms( st ); + st_destroy_draw( st ); + st_destroy_cb_program( st ); + st->softpipe->destroy( st->softpipe ); + FREE( st ); +} + + + diff --git a/src/mesa/softpipe/state_tracker/st_context.h b/src/mesa/softpipe/state_tracker/st_context.h new file mode 100644 index 0000000000..08cee11797 --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_context.h @@ -0,0 +1,109 @@ +/************************************************************************** + * + * Copyright 2003 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 ST_CONTEXT_H +#define ST_CONTEXT_H + +#include "mtypes.h" +#include "softpipe/sp_state.h" + + +struct st_context; +struct st_region; +struct st_texture_object; +struct st_texture_image; +struct st_fragment_program; + +#define ST_NEW_MESA 0x1 /* Mesa state has changed */ +#define ST_NEW_FRAGMENT_PROGRAM 0x2 + +struct st_state_flags { + GLuint mesa; + GLuint st; +}; + +struct st_tracked_state { + struct st_state_flags dirty; + void (*update)( struct st_context *st ); +}; + + + + +struct st_context +{ + GLcontext *ctx; + + struct softpipe_context *softpipe; + + /* Eventually will use a cache to feed the softpipe with + * create/bind/delete calls to constant state objects. Not yet + * though, we just shove random objects across the interface. + */ + struct { + struct softpipe_viewport viewport; + struct softpipe_setup_state setup; + struct softpipe_fs_state fs; + struct softpipe_blend_state blend; + struct softpipe_surface cbuf; + struct softpipe_clip_state clip; + struct softpipe_scissor_rect scissor; + struct softpipe_poly_stipple poly_stipple; + } state; + + struct { + struct st_tracked_state tracked_state; + } constants; + + struct { + struct gl_fragment_program *fragment_program; + } cb; + + /* State to be validated: + */ + struct st_tracked_state **atoms; + GLuint nr_atoms; + + struct st_state_flags dirty; + + /* Counter to track program string changes: + */ + GLuint program_id; + + GLfloat polygon_offset_scale; /* ?? */ +}; + + +/* Need this so that we can implement Mesa callbacks in this module. + */ +static INLINE struct st_context *st_context(GLcontext *ctx) +{ + return ctx->st; +} + + +#endif diff --git a/src/mesa/softpipe/state_tracker/st_draw.c b/src/mesa/softpipe/state_tracker/st_draw.c new file mode 100644 index 0000000000..12646402ee --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_draw.c @@ -0,0 +1,107 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell <keith@tungstengraphics.com> + */ + +#include "imports.h" + +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +#include "st_context.h" +#include "st_atom.h" +#include "st_draw.h" +#include "softpipe/sp_context.h" + +/* + * TNL stage which feedsinto the above. + * + * XXX: this needs to go into each driver using this code, because we + * cannot make the leap from ctx->draw_context in this file. The + * driver needs to customize tnl anyway, so this isn't a big deal. + */ +static GLboolean draw( GLcontext * ctx, struct tnl_pipeline_stage *stage ) +{ + struct st_context *st = st_context(ctx); + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + + /* Validate driver and softpipe state: + */ + st_validate_state( st ); + + /* Call into the new draw code to handle the VB: + */ + st->softpipe->draw_vb( st->softpipe, VB ); + + /* Finished + */ + return GL_FALSE; +} + +const struct tnl_pipeline_stage st_draw = { + "check state and draw", + NULL, + NULL, + NULL, + NULL, + draw +}; + +static const struct tnl_pipeline_stage *intel_pipeline[] = { + &_tnl_vertex_transform_stage, + &_tnl_vertex_cull_stage, + &_tnl_normal_transform_stage, + &_tnl_lighting_stage, + &_tnl_fog_coordinate_stage, + &_tnl_texgen_stage, + &_tnl_texture_transform_stage, + &_tnl_point_attenuation_stage, + &_tnl_vertex_program_stage, + &st_draw, /* ADD: escape to softpipe */ + 0, +}; + +/* This is all a hack to keep using tnl until we have vertex programs + * up and running. + */ +void st_init_draw( struct st_context *st ) +{ + GLcontext *ctx = st->ctx; + + _tnl_destroy_pipeline( ctx ); + _tnl_install_pipeline( ctx, intel_pipeline ); +} + + +void st_destroy_draw( struct st_context *st ) +{ + /* Nothing to do. + */ +} diff --git a/src/mesa/softpipe/state_tracker/st_draw.h b/src/mesa/softpipe/state_tracker/st_draw.h new file mode 100644 index 0000000000..f51059706a --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_draw.h @@ -0,0 +1,40 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell <keith@tungstengraphics.com> + */ + + +#ifndef ST_DRAW_H +#define ST_DRAW_H + +void st_init_draw( struct st_context *st ); +void st_destroy_draw( struct st_context *st ); + +#endif diff --git a/src/mesa/softpipe/state_tracker/st_program.h b/src/mesa/softpipe/state_tracker/st_program.h new file mode 100644 index 0000000000..a47059d7a6 --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_program.h @@ -0,0 +1,68 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell <keith@tungstengraphics.com> + */ + + +#ifndef ST_PROGRAM_H +#define ST_PROGRAM_H + +struct st_fragment_program +{ + struct gl_fragment_program Base; + GLboolean error; /* If program is malformed for any reason. */ + + GLuint id; /* String id, for tracking + * ProgramStringNotify changes. + */ + +#if 0 + GLfloat (*cbuffer)[4]; + GLuint nr_constants; + + /* Translate all the parameters, etc, into a constant buffer which + * we update on state changes. + */ + struct + { + GLuint reg; /* Constant idx */ + const GLfloat *values; /* Pointer to tracked values */ + } *param; + GLuint nr_params; + + GLuint param_state; +#endif +}; + + +void st_init_cb_program( struct st_context *st ); +void st_destroy_cb_program( struct st_context *st ); + +#endif diff --git a/src/mesa/softpipe/state_tracker/st_public.h b/src/mesa/softpipe/state_tracker/st_public.h new file mode 100644 index 0000000000..8241dbd52d --- /dev/null +++ b/src/mesa/softpipe/state_tracker/st_public.h @@ -0,0 +1,43 @@ +/************************************************************************** + * + * 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 ST_PUBLIC_H +#define ST_PUBLIC_H + +#include "mtypes.h" + +struct st_context; +struct softpipe_context; + +struct st_context *st_create_context( GLcontext *ctx, + struct softpipe_context *softpipe); + +void st_destroy_context( struct st_context *st ); + +void st_invalidate_state(GLcontext * ctx, GLuint new_state); + +#endif |