From 4f442d9ef5db42867c99a7288b4114a0340f73e6 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 2 Aug 2007 13:59:31 +0100 Subject: Reroute some clear functionality. Still require the intelClear() call to flush batchbuffers. That will be removed later... --- src/mesa/state_tracker/st_cb_clear.c | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/mesa/state_tracker/st_cb_clear.c (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c new file mode 100644 index 0000000000..d9cb83b8ad --- /dev/null +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -0,0 +1,89 @@ +/************************************************************************** + * + * 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 + * Brian Paul + */ + +#include "st_context.h" +#include "glheader.h" +#include "macros.h" +#include "enums.h" +#include "st_context.h" +#include "st_atom.h" +#include "pipe/p_context.h" + + + +/* XXX: doesn't pick up the differences between front/back/left/right + * clears. Need to sort that out... + */ +static void st_clear(GLcontext *ctx, GLbitfield mask) +{ + struct st_context *st = ctx->st; + GLboolean color = (mask & BUFFER_BITS_COLOR) ? GL_TRUE : GL_FALSE; + GLboolean depth = (mask & BUFFER_BIT_DEPTH) ? GL_TRUE : GL_FALSE; + GLboolean stencil = (mask & BUFFER_BIT_STENCIL) ? GL_TRUE : GL_FALSE; + GLboolean accum = (mask & BUFFER_BIT_ACCUM) ? GL_TRUE : GL_FALSE; + GLboolean fullscreen = 1; /* :-) */ + + /* This makes sure the softpipe has the latest scissor, etc values */ + st_validate_state( st ); + + if (fullscreen) { + /* pipe->clear() should clear a particular surface, so that we + * can iterate over render buffers at this level and clear the + * ones GL is asking for. + * + * Will probably need something like pipe->clear_z_stencil() to + * cope with the special case of paired and unpaired z/stencil + * buffers, though could perhaps deal with them explicitly at + * this level. + */ + st->pipe->clear(st->pipe, color, depth, stencil, accum); + } + else { + /* Convert to geometry, etc: + */ + } +} + + +void st_init_cb_clear( struct st_context *st ) +{ + struct dd_function_table *functions = &st->ctx->Driver; + + functions->Clear = st_clear; +} + + +void st_destroy_cb_clear( struct st_context *st ) +{ +} + -- cgit v1.2.3 From e415dced44bd716185e63df0c8c17f57de2b29e2 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 2 Aug 2007 10:29:42 -0600 Subject: sketch out clearing with quads --- src/mesa/state_tracker/st_cb_clear.c | 84 +++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 5 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index d9cb83b8ad..523a9b682c 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -31,17 +31,85 @@ * Brian Paul */ -#include "st_context.h" #include "glheader.h" #include "macros.h" #include "enums.h" -#include "st_context.h" #include "st_atom.h" +#include "st_context.h" +#include "st_cb_clear.h" +#include "st_public.h" #include "pipe/p_context.h" +#include "pipe/p_defines.h" + + + +/** + * Do glClear by drawing a quadrilateral. + */ +static void +clear_with_quad(GLcontext *ctx, + GLboolean color, GLboolean depth, + GLboolean stencil, GLboolean accum) +{ + struct st_context *st = ctx->st; + struct pipe_blend_state blend; + struct pipe_depth_state depth_test; + struct pipe_stencil_state stencil_test; + GLfloat z = ctx->Depth.Clear; + + /* depth state: always pass */ + memset(&depth_test, 0, sizeof(depth)); + if (depth) { + depth_test.enabled = 1; + depth_test.writemask = 1; + depth_test.func = PIPE_FUNC_ALWAYS; + } + st->pipe->set_depth_state(st->pipe, &depth_test); + + /* stencil state: always set to ref value */ + memset(&stencil_test, 0, sizeof(stencil)); + if (stencil) { + stencil_test.front_enabled = 1; + stencil_test.front_func = PIPE_FUNC_ALWAYS; + stencil_test.front_fail_op = PIPE_STENCIL_OP_REPLACE; + stencil_test.front_zpass_op = PIPE_STENCIL_OP_REPLACE; + stencil_test.front_zfail_op = PIPE_STENCIL_OP_REPLACE; + stencil_test.ref_value[0] = ctx->Stencil.Clear; + stencil_test.value_mask[0] = 0xff; + stencil_test.write_mask[0] = ctx->Stencil.WriteMask[0]; + } + st->pipe->set_stencil_state(st->pipe, &stencil_test); + + /* blend state: RGBA masking */ + memset(&blend, 0, sizeof(blend)); + if (color) { + if (ctx->Color.ColorMask[0]) + blend.colormask |= PIPE_MASK_R; + if (ctx->Color.ColorMask[1]) + blend.colormask |= PIPE_MASK_G; + if (ctx->Color.ColorMask[2]) + blend.colormask |= PIPE_MASK_B; + if (ctx->Color.ColorMask[3]) + blend.colormask |= PIPE_MASK_A; + if (st->ctx->Color.DitherFlag) + blend.dither = 1; + } + st->pipe->set_blend_state(st->pipe, &blend); + /* + * XXX Render quad here + */ -/* XXX: doesn't pick up the differences between front/back/left/right + /* Restore GL state */ + st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); +} + + + +/** + * Called via ctx->Driver.Clear() + * XXX: doesn't pick up the differences between front/back/left/right * clears. Need to sort that out... */ static void st_clear(GLcontext *ctx, GLbitfield mask) @@ -51,12 +119,17 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) GLboolean depth = (mask & BUFFER_BIT_DEPTH) ? GL_TRUE : GL_FALSE; GLboolean stencil = (mask & BUFFER_BIT_STENCIL) ? GL_TRUE : GL_FALSE; GLboolean accum = (mask & BUFFER_BIT_ACCUM) ? GL_TRUE : GL_FALSE; + GLboolean maskColor, maskStencil; GLboolean fullscreen = 1; /* :-) */ + GLuint stencilMax = 1 << ctx->DrawBuffer->_StencilBuffer->StencilBits; /* This makes sure the softpipe has the latest scissor, etc values */ st_validate_state( st ); - if (fullscreen) { + maskColor = st->state.blend.colormask != PIPE_MASK_RGBA; + maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; + + if (fullscreen && !maskColor) { /* pipe->clear() should clear a particular surface, so that we * can iterate over render buffers at this level and clear the * ones GL is asking for. @@ -71,6 +144,7 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) else { /* Convert to geometry, etc: */ + clear_with_quad(ctx, color, depth, stencil, accum); } } -- cgit v1.2.3 From 0e067f1fb20094417e84e1b18f2302251cece2ca Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 2 Aug 2007 18:25:10 +0100 Subject: Remove references to accum buffers in softpipe. Also some minor clear fixes. --- src/mesa/pipe/p_context.h | 2 +- src/mesa/pipe/p_state.h | 1 - src/mesa/pipe/softpipe/sp_clear.c | 13 +------------ src/mesa/pipe/softpipe/sp_clear.h | 2 +- src/mesa/state_tracker/st_cb_clear.c | 20 +++++++++++++------- src/mesa/state_tracker/st_draw.h | 2 +- 6 files changed, 17 insertions(+), 23 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 4f5937b8f3..2ce2781771 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -57,7 +57,7 @@ struct pipe_context { /** Clear framebuffer */ void (*clear)(struct pipe_context *pipe, GLboolean color, GLboolean depth, - GLboolean stencil, GLboolean accum); + GLboolean stencil); /** occlusion counting (XXX this may be temporary - we should probably * have generic query objects with begin/end methods) diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index d6ed514fb1..699efd5877 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -202,7 +202,6 @@ struct pipe_framebuffer_state struct pipe_surface *zbuf; /**< Z buffer */ struct pipe_surface *sbuf; /**< Stencil buffer */ - struct pipe_surface *abuf; /**< Accum buffer */ }; diff --git a/src/mesa/pipe/softpipe/sp_clear.c b/src/mesa/pipe/softpipe/sp_clear.c index 09cc643003..e9b142e780 100644 --- a/src/mesa/pipe/softpipe/sp_clear.c +++ b/src/mesa/pipe/softpipe/sp_clear.c @@ -63,7 +63,7 @@ color_value(GLuint format, const GLfloat color[4]) void softpipe_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, - GLboolean stencil, GLboolean accum) + GLboolean stencil) { struct softpipe_context *softpipe = softpipe_context(pipe); GLint x, y, w, h; @@ -152,15 +152,4 @@ softpipe_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearVal, mask); } } - - if (accum) { - /* XXX there might be no notion of accum buffers in 'pipe'. - * Just implement them with a deep RGBA surface format... - */ - struct pipe_surface *ps = softpipe->framebuffer.abuf; - GLuint clearVal = 0x0; /* XXX FIX */ - GLuint mask = ~0; - assert(ps); - pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearVal, mask); - } } diff --git a/src/mesa/pipe/softpipe/sp_clear.h b/src/mesa/pipe/softpipe/sp_clear.h index f9db99dd32..d41cc1d070 100644 --- a/src/mesa/pipe/softpipe/sp_clear.h +++ b/src/mesa/pipe/softpipe/sp_clear.h @@ -37,7 +37,7 @@ struct pipe_context; extern void softpipe_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, - GLboolean stencil, GLboolean accum); + GLboolean stencil); #endif /* SP_CLEAR_H */ diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 523a9b682c..a7a3b5eba1 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -49,7 +49,7 @@ static void clear_with_quad(GLcontext *ctx, GLboolean color, GLboolean depth, - GLboolean stencil, GLboolean accum) + GLboolean stencil) { struct st_context *st = ctx->st; struct pipe_blend_state blend; @@ -119,17 +119,18 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) GLboolean depth = (mask & BUFFER_BIT_DEPTH) ? GL_TRUE : GL_FALSE; GLboolean stencil = (mask & BUFFER_BIT_STENCIL) ? GL_TRUE : GL_FALSE; GLboolean accum = (mask & BUFFER_BIT_ACCUM) ? GL_TRUE : GL_FALSE; + GLboolean maskColor, maskStencil; GLboolean fullscreen = 1; /* :-) */ - GLuint stencilMax = 1 << ctx->DrawBuffer->_StencilBuffer->StencilBits; + GLuint stencilMax = stencil ? (1 << ctx->DrawBuffer->_StencilBuffer->StencilBits) : 0; /* This makes sure the softpipe has the latest scissor, etc values */ st_validate_state( st ); - maskColor = st->state.blend.colormask != PIPE_MASK_RGBA; - maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; + maskColor = color && st->state.blend.colormask != PIPE_MASK_RGBA; + maskStencil = stencil && ctx->Stencil.WriteMask[0] != stencilMax; - if (fullscreen && !maskColor) { + if (fullscreen && !maskColor && !maskStencil) { /* pipe->clear() should clear a particular surface, so that we * can iterate over render buffers at this level and clear the * ones GL is asking for. @@ -139,12 +140,17 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) * buffers, though could perhaps deal with them explicitly at * this level. */ - st->pipe->clear(st->pipe, color, depth, stencil, accum); + st->pipe->clear(st->pipe, color, depth, stencil); + + /* And here we would do a clear on whatever surface we are using + * to implement accum buffers: + */ + assert(!accum); } else { /* Convert to geometry, etc: */ - clear_with_quad(ctx, color, depth, stencil, accum); + clear_with_quad(ctx, color, depth, stencil); } } diff --git a/src/mesa/state_tracker/st_draw.h b/src/mesa/state_tracker/st_draw.h index 7a3ba52130..0afadab577 100644 --- a/src/mesa/state_tracker/st_draw.h +++ b/src/mesa/state_tracker/st_draw.h @@ -39,6 +39,6 @@ void st_destroy_draw( struct st_context *st ); /** XXX temporary here */ void st_clear(struct st_context *st, GLboolean color, GLboolean depth, - GLboolean stencil, GLboolean accum); + GLboolean stencil); #endif -- cgit v1.2.3 From 55314f8f311bff065f609ff17c8421a8d5216b84 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 2 Aug 2007 12:12:48 -0600 Subject: Implement new draw_vertices() path for simple vertex array drawing, use it for glClear. --- src/mesa/pipe/draw/draw_context.h | 5 +++ src/mesa/pipe/draw/draw_vb.c | 61 ++++++++++++++++++++++++++++++-- src/mesa/pipe/p_context.h | 5 +++ src/mesa/pipe/softpipe/sp_context.c | 20 +++++++++++ src/mesa/state_tracker/st_cb_clear.c | 67 ++++++++++++++++++++++++++++++------ 5 files changed, 146 insertions(+), 12 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/draw/draw_context.h b/src/mesa/pipe/draw/draw_context.h index c298d4f46d..be0a18d6d7 100644 --- a/src/mesa/pipe/draw/draw_context.h +++ b/src/mesa/pipe/draw/draw_context.h @@ -70,5 +70,10 @@ void draw_set_vertex_attributes( struct draw_context *draw, void draw_vb(struct draw_context *draw, struct vertex_buffer *VB ); +void draw_vertices(struct draw_context *draw, + GLuint mode, + GLuint numVertex, const GLfloat *verts, + GLuint numAttribs, const GLuint attribs[]); + #endif /* DRAW_CONTEXT_H */ diff --git a/src/mesa/pipe/draw/draw_vb.c b/src/mesa/pipe/draw/draw_vb.c index ac126c5baa..f9c10e5f97 100644 --- a/src/mesa/pipe/draw/draw_vb.c +++ b/src/mesa/pipe/draw/draw_vb.c @@ -57,7 +57,7 @@ static void draw_allocate_vertices( struct draw_context *draw, GLuint nr_vertices ) { draw->nr_vertices = nr_vertices; - draw->verts = MALLOC( nr_vertices * draw->vertex_size ); + draw->verts = (GLubyte *) malloc( nr_vertices * draw->vertex_size ); draw->pipeline.first->begin( draw->pipeline.first ); } @@ -453,7 +453,7 @@ static void draw_release_vertices( struct draw_context *draw ) { draw->pipeline.first->end( draw->pipeline.first ); - FREE(draw->verts); + free(draw->verts); draw->verts = NULL; } @@ -646,6 +646,63 @@ void draw_vb(struct draw_context *draw, } +/** + * XXX Temporary mechanism to draw simple vertex arrays. + * All attribs are GLfloat[4]. Arrays are interleaved, in GL-speak. + */ +void +draw_vertices(struct draw_context *draw, + GLuint mode, + GLuint numVerts, const GLfloat *vertices, + GLuint numAttrs, const GLuint attribs[]) +{ + /*GLuint first, incr;*/ + GLuint i, j; + + assert(mode <= GL_POLYGON); + + draw->vertex_size + = sizeof(struct vertex_header) + numAttrs * 4 * sizeof(GLfloat); + + /*draw_prim_info(mode, &first, &incr);*/ + draw_allocate_vertices( draw, numVerts ); + if (draw->prim != mode) + draw_set_prim( draw, mode ); + + /* setup attr info */ + draw->nr_attrs = numAttrs + 2; + draw->attrs[0].attrib = VF_ATTRIB_VERTEX_HEADER; + draw->attrs[0].format = EMIT_1F; + draw->attrs[1].attrib = VF_ATTRIB_CLIP_POS; + draw->attrs[1].format = EMIT_4F; + for (j = 0; j < numAttrs; j++) { + draw->vf_attr_to_slot[attribs[j]] = 2+j; + draw->attrs[2+j].attrib = attribs[j]; + draw->attrs[2+j].format = EMIT_4F; + } + + /* build vertices */ + for (i = 0; i < numVerts; i++) { + struct vertex_header *v + = (struct vertex_header *) (draw->verts + i * draw->vertex_size); + v->clipmask = 0x0; + v->edgeflag = 0; + for (j = 0; j < numAttrs; j++) { + COPY_4FV(v->data[j], vertices + (i * numAttrs + j) * 4); + } + } + + /* draw */ + draw_prim(draw, 0, numVerts); + + /* clean up */ + draw_release_vertices( draw ); + draw->verts = NULL; + draw->in_vb = 0; +} + + + /** * Accumulate another attribute's info. * Note the "- 2" factor here. We need this because the vertex->data[] diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 2ce2781771..0972fd58b5 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -55,6 +55,11 @@ struct pipe_context { void (*draw_vb)( struct pipe_context *pipe, struct vertex_buffer *VB ); + void (*draw_vertices)( struct pipe_context *pipe, + GLuint mode, + GLuint numVertex, const GLfloat *verts, + GLuint numAttribs, const GLuint attribs[]); + /** Clear framebuffer */ void (*clear)(struct pipe_context *pipe, GLboolean color, GLboolean depth, GLboolean stencil); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 434e18308a..9fba9605e8 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -102,6 +102,25 @@ static void softpipe_draw_vb( struct pipe_context *pipe, } +static void +softpipe_draw_vertices(struct pipe_context *pipe, + GLuint mode, + GLuint numVertex, const GLfloat *verts, + GLuint numAttribs, const GLuint attribs[]) +{ + struct softpipe_context *softpipe = softpipe_context( pipe ); + + if (softpipe->dirty) + softpipe_update_derived( softpipe ); + + /* XXX move mapping/unmapping to higher/coarser level? */ + map_surfaces(softpipe); + draw_vertices(softpipe->draw, mode, numVertex, verts, numAttribs, attribs); + unmap_surfaces(softpipe); +} + + + static void softpipe_reset_occlusion_counter(struct pipe_context *pipe) { struct softpipe_context *softpipe = softpipe_context( pipe ); @@ -137,6 +156,7 @@ struct pipe_context *softpipe_create( void ) softpipe->pipe.set_texture_state = softpipe_set_texture_state; softpipe->pipe.set_viewport_state = softpipe_set_viewport_state; softpipe->pipe.draw_vb = softpipe_draw_vb; + softpipe->pipe.draw_vertices = softpipe_draw_vertices; softpipe->pipe.clear = softpipe_clear; softpipe->pipe.reset_occlusion_counter = softpipe_reset_occlusion_counter; softpipe->pipe.get_occlusion_counter = softpipe_get_occlusion_counter; diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index a7a3b5eba1..8e2e30253e 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -40,6 +40,51 @@ #include "st_public.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "vf/vf.h" + + +/** + * Draw a screen-aligned quadrilateral. + * Coords are window coords. + */ +static void +draw_quad(GLcontext *ctx, + float x0, float y0, float x1, float y1, GLfloat z, + const GLfloat color[4]) +{ + static const GLuint attribs[2] = { + VF_ATTRIB_POS, + VF_ATTRIB_COLOR0 + }; + GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */ + GLuint i; + + /* positions */ + verts[0][0][0] = x0; + verts[0][0][1] = y0; + + verts[1][0][0] = x1; + verts[1][0][1] = y0; + + verts[2][0][0] = x1; + verts[2][0][1] = y1; + + verts[3][0][0] = x0; + verts[3][0][1] = y1; + + /* same for all verts: */ + for (i = 0; i < 4; i++) { + verts[i][0][2] = z; + verts[i][0][3] = 1.0; + verts[i][1][0] = color[0]; + verts[i][1][1] = color[1]; + verts[i][1][2] = color[2]; + verts[i][1][3] = color[3]; + } + + ctx->st->pipe->draw_vertices(ctx->st->pipe, GL_QUADS, + 4, (GLfloat *) verts, 2, attribs); +} @@ -48,14 +93,12 @@ */ static void clear_with_quad(GLcontext *ctx, - GLboolean color, GLboolean depth, - GLboolean stencil) + GLboolean color, GLboolean depth, GLboolean stencil) { struct st_context *st = ctx->st; struct pipe_blend_state blend; struct pipe_depth_state depth_test; struct pipe_stencil_state stencil_test; - GLfloat z = ctx->Depth.Clear; /* depth state: always pass */ memset(&depth_test, 0, sizeof(depth)); @@ -96,13 +139,19 @@ clear_with_quad(GLcontext *ctx, } st->pipe->set_blend_state(st->pipe, &blend); - - /* - * XXX Render quad here - */ + draw_quad(ctx, + ctx->Scissor.X, ctx->Scissor.Y, + ctx->Scissor.X + ctx->Scissor.Width, + ctx->Scissor.Y + ctx->Scissor.Height, + ctx->Depth.Clear, ctx->Color.ClearColor); /* Restore GL state */ + st->pipe->set_blend_state(st->pipe, &st->state.blend); + st->pipe->set_depth_state(st->pipe, &st->state.depth); + st->pipe->set_stencil_state(st->pipe, &st->state.stencil); + /* OR: st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); + */ } @@ -121,7 +170,7 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) GLboolean accum = (mask & BUFFER_BIT_ACCUM) ? GL_TRUE : GL_FALSE; GLboolean maskColor, maskStencil; - GLboolean fullscreen = 1; /* :-) */ + GLboolean fullscreen = !ctx->Scissor.Enabled; GLuint stencilMax = stencil ? (1 << ctx->DrawBuffer->_StencilBuffer->StencilBits) : 0; /* This makes sure the softpipe has the latest scissor, etc values */ @@ -148,8 +197,6 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) assert(!accum); } else { - /* Convert to geometry, etc: - */ clear_with_quad(ctx, color, depth, stencil); } } -- cgit v1.2.3 From 406da44da31f71afd98fc45e2bbfbf41deff1d12 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 2 Aug 2007 13:48:02 -0600 Subject: setup more state for clear_with_quad() --- src/mesa/state_tracker/st_cb_clear.c | 49 +++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 8e2e30253e..85df549404 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -96,12 +96,34 @@ clear_with_quad(GLcontext *ctx, GLboolean color, GLboolean depth, GLboolean stencil) { struct st_context *st = ctx->st; + struct pipe_alpha_test_state alpha_test; struct pipe_blend_state blend; struct pipe_depth_state depth_test; struct pipe_stencil_state stencil_test; + struct pipe_setup_state setup; + + /* alpha state: disabled */ + memset(&alpha_test, 0, sizeof(alpha_test)); + st->pipe->set_alpha_test_state(st->pipe, &alpha_test); + + /* blend state: RGBA masking */ + memset(&blend, 0, sizeof(blend)); + if (color) { + if (ctx->Color.ColorMask[0]) + blend.colormask |= PIPE_MASK_R; + if (ctx->Color.ColorMask[1]) + blend.colormask |= PIPE_MASK_G; + if (ctx->Color.ColorMask[2]) + blend.colormask |= PIPE_MASK_B; + if (ctx->Color.ColorMask[3]) + blend.colormask |= PIPE_MASK_A; + if (st->ctx->Color.DitherFlag) + blend.dither = 1; + } + st->pipe->set_blend_state(st->pipe, &blend); /* depth state: always pass */ - memset(&depth_test, 0, sizeof(depth)); + memset(&depth_test, 0, sizeof(depth_test)); if (depth) { depth_test.enabled = 1; depth_test.writemask = 1; @@ -109,8 +131,12 @@ clear_with_quad(GLcontext *ctx, } st->pipe->set_depth_state(st->pipe, &depth_test); + /* setup state: nothing */ + memset(&setup, 0, sizeof(setup)); + st->pipe->set_setup_state(st->pipe, &setup); + /* stencil state: always set to ref value */ - memset(&stencil_test, 0, sizeof(stencil)); + memset(&stencil_test, 0, sizeof(stencil_test)); if (stencil) { stencil_test.front_enabled = 1; stencil_test.front_func = PIPE_FUNC_ALWAYS; @@ -123,22 +149,7 @@ clear_with_quad(GLcontext *ctx, } st->pipe->set_stencil_state(st->pipe, &stencil_test); - /* blend state: RGBA masking */ - memset(&blend, 0, sizeof(blend)); - if (color) { - if (ctx->Color.ColorMask[0]) - blend.colormask |= PIPE_MASK_R; - if (ctx->Color.ColorMask[1]) - blend.colormask |= PIPE_MASK_G; - if (ctx->Color.ColorMask[2]) - blend.colormask |= PIPE_MASK_B; - if (ctx->Color.ColorMask[3]) - blend.colormask |= PIPE_MASK_A; - if (st->ctx->Color.DitherFlag) - blend.dither = 1; - } - st->pipe->set_blend_state(st->pipe, &blend); - + /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, ctx->Scissor.X, ctx->Scissor.Y, ctx->Scissor.X + ctx->Scissor.Width, @@ -146,8 +157,10 @@ clear_with_quad(GLcontext *ctx, ctx->Depth.Clear, ctx->Color.ClearColor); /* Restore GL state */ + st->pipe->set_alpha_test_state(st->pipe, &st->state.alpha_test); st->pipe->set_blend_state(st->pipe, &st->state.blend); st->pipe->set_depth_state(st->pipe, &st->state.depth); + st->pipe->set_setup_state(st->pipe, &st->state.setup); st->pipe->set_stencil_state(st->pipe, &st->state.stencil); /* OR: st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); -- cgit v1.2.3 From 47fdaf0ed9ef2f89cdaa97d0d48b1f1194d710c6 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 2 Aug 2007 16:08:18 -0600 Subject: pipe->clear() now takes a surface, rather than color/depth/stencil flags. pipe->clear() only used to clear whole buffers (no scissor) w/out masking. Draw a colored quadrilateral in all other cases. --- src/mesa/drivers/x11/xm_api.c | 5 +- src/mesa/drivers/x11/xm_dd.c | 23 ++- src/mesa/drivers/x11/xmesaP.h | 7 +- src/mesa/pipe/p_context.h | 6 +- src/mesa/pipe/softpipe/sp_clear.c | 109 +------------- src/mesa/pipe/softpipe/sp_clear.h | 4 +- src/mesa/state_tracker/st_cb_clear.c | 274 ++++++++++++++++++++++++++++++----- 7 files changed, 270 insertions(+), 158 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index 92d37085d1..7fb99df5f4 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -1573,8 +1573,11 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) st_create_context( mesaCtx, softpipe_create() ); + mesaCtx->Driver.Clear = xmesa_clear_buffers; + /* mesaCtx->st->pipe->clear = xmesa_clear; - + */ + return c; } diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c index 87f8ede50b..f64f8780cf 100644 --- a/src/mesa/drivers/x11/xm_dd.c +++ b/src/mesa/drivers/x11/xm_dd.c @@ -381,8 +381,8 @@ clear_nbit_ximage(GLcontext *ctx, struct xmesa_renderbuffer *xrb, -static void -clear_buffers(GLcontext *ctx, GLbitfield buffers) +void +xmesa_clear_buffers(GLcontext *ctx, GLbitfield buffers) { if (ctx->DrawBuffer->Name == 0) { /* this is a window system framebuffer */ @@ -395,7 +395,6 @@ clear_buffers(GLcontext *ctx, GLbitfield buffers) /* we can't handle color or index masking */ if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) { -#if 0 if (buffers & BUFFER_BIT_FRONT_LEFT) { /* clear front color buffer */ struct gl_renderbuffer *frontRb @@ -419,14 +418,6 @@ clear_buffers(GLcontext *ctx, GLbitfield buffers) buffers &= ~BUFFER_BIT_BACK_LEFT; } } -#else - /* Clear with state-tracker/pipe interface */ - struct st_context *st = st_context(ctx); - GLboolean color = (buffers & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT)) ? 1: 0; - GLboolean depth = (buffers & BUFFER_BIT_DEPTH) ? 1 : 0; - GLboolean stencil = (buffers & BUFFER_BIT_STENCIL) ? 1 : 0; - st_clear(st, color, depth, stencil); -#endif } } if (buffers) @@ -434,6 +425,7 @@ clear_buffers(GLcontext *ctx, GLbitfield buffers) } +#if 0 void xmesa_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, GLboolean stencil, GLboolean accum) @@ -458,9 +450,14 @@ xmesa_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, xrb->clearFunc(ctx, xrb, x, y, w, h); } } - } +#endif + +void +xmesa_clear(struct pipe_context *pipe, struct pipe_surface *ps, GLuint value) +{ +} #ifndef XFree86Server @@ -1113,7 +1110,7 @@ xmesa_init_driver_functions( XMesaVisual xmvisual, driver->IndexMask = index_mask; driver->ColorMask = color_mask; driver->Enable = enable; - driver->Clear = clear_buffers; + driver->Clear = xmesa_clear_buffers; driver->Viewport = xmesa_viewport; #ifndef XFree86Server driver->CopyPixels = xmesa_CopyPixels; diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h index fb1c1f8c3b..dd95aed4d0 100644 --- a/src/mesa/drivers/x11/xmesaP.h +++ b/src/mesa/drivers/x11/xmesaP.h @@ -593,7 +593,10 @@ extern struct pipe_surface * xmesa_new_surface(GLcontext *ctx, struct xmesa_renderbuffer *xrb); extern void -xmesa_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, - GLboolean stencil, GLboolean accum); +xmesa_clear(struct pipe_context *pipe, struct pipe_surface *ps, GLuint value); + +extern void +xmesa_clear_buffers(GLcontext *ctx, GLbitfield buffers); + #endif diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 0972fd58b5..4f8bdae140 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -60,9 +60,9 @@ struct pipe_context { GLuint numVertex, const GLfloat *verts, GLuint numAttribs, const GLuint attribs[]); - /** Clear framebuffer */ - void (*clear)(struct pipe_context *pipe, GLboolean color, GLboolean depth, - GLboolean stencil); + /** Clear a surface to given value (no scissor; clear whole surface) */ + void (*clear)(struct pipe_context *pipe, struct pipe_surface *ps, + GLuint clearValue); /** occlusion counting (XXX this may be temporary - we should probably * have generic query objects with begin/end methods) diff --git a/src/mesa/pipe/softpipe/sp_clear.c b/src/mesa/pipe/softpipe/sp_clear.c index e9b142e780..d7684d2044 100644 --- a/src/mesa/pipe/softpipe/sp_clear.c +++ b/src/mesa/pipe/softpipe/sp_clear.c @@ -38,32 +38,13 @@ #include "colormac.h" -static GLuint -color_value(GLuint format, const GLfloat color[4]) -{ - GLubyte r, g, b, a; - - UNCLAMPED_FLOAT_TO_UBYTE(r, color[0]); - UNCLAMPED_FLOAT_TO_UBYTE(g, color[1]); - UNCLAMPED_FLOAT_TO_UBYTE(b, color[2]); - UNCLAMPED_FLOAT_TO_UBYTE(a, color[3]); - - switch (format) { - case PIPE_FORMAT_U_R8_G8_B8_A8: - return (r << 24) | (g << 16) | (b << 8) | a; - case PIPE_FORMAT_U_A8_R8_G8_B8: - return (a << 24) | (r << 16) | (g << 8) | b; - case PIPE_FORMAT_U_R5_G6_B5: - return ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); - default: - return 0; - } -} - - +/** + * Clear the given surface to the specified value. + * No masking, no scissor (clear entire buffer). + */ void -softpipe_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, - GLboolean stencil) +softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps, + GLuint clearValue) { struct softpipe_context *softpipe = softpipe_context(pipe); GLint x, y, w, h; @@ -75,81 +56,5 @@ softpipe_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, w = softpipe->framebuffer.cbufs[0]->width; h = softpipe->framebuffer.cbufs[0]->height; - if (color) { - GLuint i; - for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) { - struct pipe_surface *ps = softpipe->framebuffer.cbufs[i]; - GLuint clearVal = color_value(ps->format, - softpipe->clear_color.color); - pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearVal, ~0); - } - } - - if (depth && stencil && - softpipe->framebuffer.zbuf == softpipe->framebuffer.sbuf) { - /* clear Z and stencil together */ - struct pipe_surface *ps = softpipe->framebuffer.zbuf; - if (ps->format == PIPE_FORMAT_S8_Z24) { - GLuint mask = (softpipe->stencil.write_mask[0] << 8) | 0xffffff; - GLuint clearVal = (GLuint) (softpipe->depth_test.clear * 0xffffff); - - assert (mask == ~0); - - clearVal |= (softpipe->stencil.clear_value << 24); - pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearVal, ~0); - } - else { - /* XXX Z24_S8 format? */ - assert(0); - } - } - else { - /* separate Z and stencil */ - if (depth) { - struct pipe_surface *ps = softpipe->framebuffer.zbuf; - GLuint clearVal; - - switch (ps->format) { - case PIPE_FORMAT_U_Z16: - clearVal = (GLuint) (softpipe->depth_test.clear * 65535.0); - break; - case PIPE_FORMAT_U_Z32: - clearVal = (GLuint) (softpipe->depth_test.clear * 0xffffffff); - break; - case PIPE_FORMAT_S8_Z24: - clearVal = (GLuint) (softpipe->depth_test.clear * 0xffffff); - break; - default: - assert(0); - } - - pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearVal, ~0); - } - - if (stencil) { - struct pipe_surface *ps = softpipe->framebuffer.sbuf; - GLuint clearVal = softpipe->stencil.clear_value; - - /* If this is not ~0, we shouldn't get here - clear should be - * done with geometry instead. - */ - GLuint mask = softpipe->stencil.write_mask[0]; - - assert((mask & 0xff) == 0xff); - - switch (ps->format) { - case PIPE_FORMAT_S8_Z24: - clearVal = clearVal << 24; - mask = mask << 24; - break; - case PIPE_FORMAT_U_S8: - /* nothing */ - break; - default: - assert(0); - } - - pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearVal, mask); - } - } + pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearValue, ~0); } diff --git a/src/mesa/pipe/softpipe/sp_clear.h b/src/mesa/pipe/softpipe/sp_clear.h index d41cc1d070..e706e731c2 100644 --- a/src/mesa/pipe/softpipe/sp_clear.h +++ b/src/mesa/pipe/softpipe/sp_clear.h @@ -36,8 +36,8 @@ struct pipe_context; extern void -softpipe_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, - GLboolean stencil); +softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps, + GLuint clearValue); #endif /* SP_CLEAR_H */ diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 85df549404..bd58abc4d1 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -43,6 +43,65 @@ #include "vf/vf.h" + +static GLuint +color_value(GLuint pipeFormat, const GLfloat color[4]) +{ + GLubyte r, g, b, a; + + UNCLAMPED_FLOAT_TO_UBYTE(r, color[0]); + UNCLAMPED_FLOAT_TO_UBYTE(g, color[1]); + UNCLAMPED_FLOAT_TO_UBYTE(b, color[2]); + UNCLAMPED_FLOAT_TO_UBYTE(a, color[3]); + + switch (pipeFormat) { + case PIPE_FORMAT_U_R8_G8_B8_A8: + return (r << 24) | (g << 16) | (b << 8) | a; + case PIPE_FORMAT_U_A8_R8_G8_B8: + return (a << 24) | (r << 16) | (g << 8) | b; + case PIPE_FORMAT_U_R5_G6_B5: + return ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); + default: + return 0; + } +} + + +static GLuint +depth_value(GLuint pipeFormat, GLfloat value) +{ + GLuint val; + switch (pipeFormat) { + case PIPE_FORMAT_U_Z16: + val = (GLuint) (value * 0xffffff); + break; + case PIPE_FORMAT_U_Z32: + val = (GLuint) (value * 0xffffffff); + break; + case PIPE_FORMAT_S8_Z24: + /*case PIPE_FORMAT_Z24_S8:*/ + val = (GLuint) (value * 0xffffff); + break; + default: + assert(0); + } + return val; +} + + +static GLboolean +is_depth_stencil_format(GLuint pipeFormat) +{ + switch (pipeFormat) { + case PIPE_FORMAT_S8_Z24: + /*case PIPE_FORMAT_Z24_S8:*/ + return GL_TRUE; + default: + return GL_FALSE; + } +} + + /** * Draw a screen-aligned quadrilateral. * Coords are window coords. @@ -92,7 +151,8 @@ draw_quad(GLcontext *ctx, * Do glClear by drawing a quadrilateral. */ static void -clear_with_quad(GLcontext *ctx, +clear_with_quad(GLcontext *ctx, GLuint x0, GLuint y0, + GLuint x1, GLuint y1, GLboolean color, GLboolean depth, GLboolean stencil) { struct st_context *st = ctx->st; @@ -133,6 +193,8 @@ clear_with_quad(GLcontext *ctx, /* setup state: nothing */ memset(&setup, 0, sizeof(setup)); + if (ctx->Scissor.Enabled) + setup.scissor = 1; st->pipe->set_setup_state(st->pipe, &setup); /* stencil state: always set to ref value */ @@ -145,18 +207,14 @@ clear_with_quad(GLcontext *ctx, stencil_test.front_zfail_op = PIPE_STENCIL_OP_REPLACE; stencil_test.ref_value[0] = ctx->Stencil.Clear; stencil_test.value_mask[0] = 0xff; - stencil_test.write_mask[0] = ctx->Stencil.WriteMask[0]; + stencil_test.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; } st->pipe->set_stencil_state(st->pipe, &stencil_test); /* draw quad matching scissor rect (XXX verify coord round-off) */ - draw_quad(ctx, - ctx->Scissor.X, ctx->Scissor.Y, - ctx->Scissor.X + ctx->Scissor.Width, - ctx->Scissor.Y + ctx->Scissor.Height, - ctx->Depth.Clear, ctx->Color.ClearColor); + draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); - /* Restore GL state */ + /* Restore pipe state */ st->pipe->set_alpha_test_state(st->pipe, &st->state.alpha_test); st->pipe->set_blend_state(st->pipe, &st->state.blend); st->pipe->set_depth_state(st->pipe, &st->state.depth); @@ -168,6 +226,141 @@ clear_with_quad(GLcontext *ctx, } +static void +clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) +{ + if (ctx->Color.ColorMask[0] && + ctx->Color.ColorMask[1] && + ctx->Color.ColorMask[2] && + ctx->Color.ColorMask[3] && + !ctx->Scissor.Enabled) + { + /* clear whole buffer w/out masking */ + GLuint clearValue + = color_value(rb->surface->format, ctx->Color.ClearColor); + ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + } + else { + /* masking or scissoring */ + clear_with_quad(ctx, + ctx->DrawBuffer->_Xmin, + ctx->DrawBuffer->_Xmin, + ctx->DrawBuffer->_Xmax, + ctx->DrawBuffer->_Ymax, + GL_TRUE, GL_FALSE, GL_FALSE); + } +} + + +static void +clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) +{ + if (!ctx->Scissor.Enabled) { + /* clear whole buffer w/out masking */ + GLuint clearValue + = color_value(rb->surface->format, ctx->Accum.ClearColor); + /* Note that clearValue is 32 bits but the accum buffer will + * typically be 64bpp... + */ + ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + } + else { + /* scissoring */ + /* XXX point framebuffer.cbufs[0] at the accum buffer */ + clear_with_quad(ctx, + ctx->DrawBuffer->_Xmin, + ctx->DrawBuffer->_Xmin, + ctx->DrawBuffer->_Xmax, + ctx->DrawBuffer->_Ymax, + GL_TRUE, GL_FALSE, GL_FALSE); + } +} + + +static void +clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) +{ + if (!ctx->Scissor.Enabled && + !is_depth_stencil_format(rb->surface->format)) { + /* clear whole depth buffer w/out masking */ + GLuint clearValue = depth_value(rb->surface->format, ctx->Depth.Clear); + ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + } + else { + /* masking or scissoring or combined z/stencil buffer */ + clear_with_quad(ctx, + ctx->DrawBuffer->_Xmin, + ctx->DrawBuffer->_Xmin, + ctx->DrawBuffer->_Xmax, + ctx->DrawBuffer->_Ymax, + GL_FALSE, GL_TRUE, GL_FALSE); + } +} + + +static void +clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) +{ + const GLuint stencilMax = (1 << rb->StencilBits) - 1; + GLboolean maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; + + if (!maskStencil && !ctx->Scissor.Enabled && + !is_depth_stencil_format(rb->surface->format)) { + /* clear whole stencil buffer w/out masking */ + GLuint clearValue = ctx->Stencil.Clear; + ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + } + else { + /* masking or scissoring */ + clear_with_quad(ctx, + ctx->DrawBuffer->_Xmin, + ctx->DrawBuffer->_Xmin, + ctx->DrawBuffer->_Xmax, + ctx->DrawBuffer->_Ymax, + GL_FALSE, GL_FALSE, GL_TRUE); + } +} + + +static void +clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) +{ + const GLuint stencilMax = 1 << rb->StencilBits; + GLboolean maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; + + assert(is_depth_stencil_format(rb->surface->format)); + + if (!maskStencil && !ctx->Scissor.Enabled) { + /* clear whole buffer w/out masking */ + GLuint clearValue = depth_value(rb->surface->format, ctx->Depth.Clear); + + switch (rb->surface->format) { + case PIPE_FORMAT_S8_Z24: + clearValue |= ctx->Stencil.Clear << 24; + break; +#if 0 + case PIPE_FORMAT_Z24_S8: + clearValue = (clearValue << 8) | clearVal; + break; +#endif + default: + assert(0); + } + + ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + } + else { + /* masking or scissoring */ + clear_with_quad(ctx, + ctx->DrawBuffer->_Xmin, + ctx->DrawBuffer->_Xmin, + ctx->DrawBuffer->_Xmax, + ctx->DrawBuffer->_Ymax, + GL_FALSE, GL_TRUE, GL_TRUE); + } +} + + /** * Called via ctx->Driver.Clear() @@ -176,41 +369,52 @@ clear_with_quad(GLcontext *ctx, */ static void st_clear(GLcontext *ctx, GLbitfield mask) { + static const GLbitfield BUFFER_BITS_DS + = (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL); struct st_context *st = ctx->st; - GLboolean color = (mask & BUFFER_BITS_COLOR) ? GL_TRUE : GL_FALSE; - GLboolean depth = (mask & BUFFER_BIT_DEPTH) ? GL_TRUE : GL_FALSE; - GLboolean stencil = (mask & BUFFER_BIT_STENCIL) ? GL_TRUE : GL_FALSE; - GLboolean accum = (mask & BUFFER_BIT_ACCUM) ? GL_TRUE : GL_FALSE; - - GLboolean maskColor, maskStencil; - GLboolean fullscreen = !ctx->Scissor.Enabled; - GLuint stencilMax = stencil ? (1 << ctx->DrawBuffer->_StencilBuffer->StencilBits) : 0; + struct gl_renderbuffer *depthRb + = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; + struct gl_renderbuffer *stencilRb + = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer; /* This makes sure the softpipe has the latest scissor, etc values */ st_validate_state( st ); - maskColor = color && st->state.blend.colormask != PIPE_MASK_RGBA; - maskStencil = stencil && ctx->Stencil.WriteMask[0] != stencilMax; - - if (fullscreen && !maskColor && !maskStencil) { - /* pipe->clear() should clear a particular surface, so that we - * can iterate over render buffers at this level and clear the - * ones GL is asking for. - * - * Will probably need something like pipe->clear_z_stencil() to - * cope with the special case of paired and unpaired z/stencil - * buffers, though could perhaps deal with them explicitly at - * this level. - */ - st->pipe->clear(st->pipe, color, depth, stencil); + /* + * XXX TO-DO: + * If we're going to use clear_with_quad() for any reason, use it to + * clear as many other buffers as possible. + * As it is now, we sometimes call clear_with_quad() three times to clear + * color/depth/stencil individually... + */ + + if (mask & BUFFER_BITS_COLOR) { + GLuint b; + for (b = 0; b < BUFFER_COUNT; b++) { + if (BUFFER_BITS_COLOR & mask & (1 << b)) { + clear_color_buffer(ctx, + ctx->DrawBuffer->Attachment[b].Renderbuffer); + } + } + } - /* And here we would do a clear on whatever surface we are using - * to implement accum buffers: - */ - assert(!accum); + if (mask & BUFFER_BIT_ACCUM) { + clear_accum_buffer(ctx, + ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer); + } + + if ((mask & BUFFER_BITS_DS) == BUFFER_BITS_DS && depthRb == stencilRb) { + /* clearing combined depth + stencil */ + clear_depth_stencil_buffer(ctx, depthRb); } else { - clear_with_quad(ctx, color, depth, stencil); + /* separate depth/stencil clears */ + if (mask & BUFFER_BIT_DEPTH) { + clear_depth_buffer(ctx, depthRb); + } + if (mask & BUFFER_BIT_STENCIL) { + clear_stencil_buffer(ctx, stencilRb); + } } } -- cgit v1.2.3 From fc9ff31298952f0a7e4cdfae95059144a5be6e1b Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 2 Aug 2007 20:36:36 -0600 Subject: trim #includes --- src/mesa/state_tracker/st_cb_clear.c | 1 - src/mesa/state_tracker/st_cb_drawpixels.c | 3 --- 2 files changed, 4 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index bd58abc4d1..c907b0ed22 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -33,7 +33,6 @@ #include "glheader.h" #include "macros.h" -#include "enums.h" #include "st_atom.h" #include "st_context.h" #include "st_cb_clear.h" diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 7209db00a3..13f5c5f3c7 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -32,9 +32,6 @@ #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" -- cgit v1.2.3 From 6da9234fd437f97267e7831f034c78b31156d939 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 6 Aug 2007 20:53:28 +0100 Subject: New st_init_*_functions() to initialize the driver functions table. We need to do these initializations before initializing the Mesa context because context init involves creating texture/program/etc objects. --- src/mesa/state_tracker/st_cb_bufferobjects.c | 18 ++++++++--------- src/mesa/state_tracker/st_cb_bufferobjects.h | 11 +++++------ src/mesa/state_tracker/st_cb_clear.c | 10 +--------- src/mesa/state_tracker/st_cb_clear.h | 5 +++-- src/mesa/state_tracker/st_cb_drawpixels.c | 8 +------- src/mesa/state_tracker/st_cb_drawpixels.h | 4 +--- src/mesa/state_tracker/st_cb_fbo.c | 9 +-------- src/mesa/state_tracker/st_cb_fbo.h | 5 ++--- src/mesa/state_tracker/st_cb_program.c | 29 ++++++++++------------------ src/mesa/state_tracker/st_cb_texture.c | 12 +++--------- src/mesa/state_tracker/st_cb_texture.h | 6 +----- src/mesa/state_tracker/st_context.c | 18 +++++++++++++++++ src/mesa/state_tracker/st_context.h | 7 +++---- src/mesa/state_tracker/st_program.h | 5 +++-- 14 files changed, 60 insertions(+), 87 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index a667b3e775..d020eb2007 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -192,15 +192,13 @@ st_bufferobj_unmap(GLcontext *ctx, void -st_init_cb_bufferobjects( struct st_context *st ) +st_init_bufferobject_functions(struct dd_function_table *functions) { - GLcontext *ctx = st->ctx; - - ctx->Driver.NewBufferObject = st_bufferobj_alloc; - ctx->Driver.DeleteBuffer = st_bufferobj_free; - ctx->Driver.BufferData = st_bufferobj_data; - ctx->Driver.BufferSubData = st_bufferobj_subdata; - ctx->Driver.GetBufferSubData = st_bufferobj_get_subdata; - ctx->Driver.MapBuffer = st_bufferobj_map; - ctx->Driver.UnmapBuffer = st_bufferobj_unmap; + functions->NewBufferObject = st_bufferobj_alloc; + functions->DeleteBuffer = st_bufferobj_free; + functions->BufferData = st_bufferobj_data; + functions->BufferSubData = st_bufferobj_subdata; + functions->GetBufferSubData = st_bufferobj_get_subdata; + functions->MapBuffer = st_bufferobj_map; + functions->UnmapBuffer = st_bufferobj_unmap; } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.h b/src/mesa/state_tracker/st_cb_bufferobjects.h index 2787411c5f..2090a743e0 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.h +++ b/src/mesa/state_tracker/st_cb_bufferobjects.h @@ -1,4 +1,4 @@ - /************************************************************************** +/************************************************************************** * * Copyright 2005 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. @@ -43,11 +43,6 @@ struct st_buffer_object }; -/* Hook the bufferobject implementation into mesa: - */ -void st_init_cb_bufferobjects( struct st_context *st ); - - /* Are the obj->Name tests necessary? Unfortunately yes, mesa * allocates a couple of gl_buffer_object structs statically, and the * Name == 0 test is the only way to identify them and avoid casting @@ -63,4 +58,8 @@ st_buffer_object(struct gl_buffer_object *obj) } +extern void +st_init_bufferobject_functions(struct dd_function_table *functions); + + #endif diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index c907b0ed22..0ec7784d84 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -418,15 +418,7 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) } -void st_init_cb_clear( struct st_context *st ) +void st_init_clear_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->Clear = st_clear; } - - -void st_destroy_cb_clear( struct st_context *st ) -{ -} - diff --git a/src/mesa/state_tracker/st_cb_clear.h b/src/mesa/state_tracker/st_cb_clear.h index 32086971b5..c715e56bd5 100644 --- a/src/mesa/state_tracker/st_cb_clear.h +++ b/src/mesa/state_tracker/st_cb_clear.h @@ -29,9 +29,10 @@ #ifndef ST_CB_CLEAR_H #define ST_CB_CLEAR_H -extern void st_init_cb_clear( struct st_context *st ); -extern void st_destroy_cb_clear( struct st_context *st ); +extern void +st_init_clear_functions(struct dd_function_table *functions); + #endif /* ST_CB_CLEAR_H */ diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 13f5c5f3c7..92a4e305d1 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -262,14 +262,8 @@ st_drawpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } -void st_init_cb_drawpixels( struct st_context *st ) +void st_init_drawpixels_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->DrawPixels = st_drawpixels; } - -void st_destroy_cb_drawpixels( struct st_context *st ) -{ -} diff --git a/src/mesa/state_tracker/st_cb_drawpixels.h b/src/mesa/state_tracker/st_cb_drawpixels.h index 8c36aaa931..71ba487020 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.h +++ b/src/mesa/state_tracker/st_cb_drawpixels.h @@ -30,9 +30,7 @@ #define ST_CB_DRAWPIXELS_H -void st_init_cb_drawpixels( struct st_context *st ); - -void st_destroy_cb_drawpixels( struct st_context *st ); +extern void st_init_drawpixels_functions(struct dd_function_table *functions); #endif /* ST_CB_DRAWPIXELS_H */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 6b9ae88dbe..d0205fd635 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -322,10 +322,8 @@ st_finish_render_texture(GLcontext *ctx, -void st_init_cb_fbo( struct st_context *st ) +void st_init_fbo_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->NewFramebuffer = st_new_framebuffer; functions->NewRenderbuffer = st_new_renderbuffer; functions->BindFramebuffer = st_bind_framebuffer; @@ -336,8 +334,3 @@ void st_init_cb_fbo( struct st_context *st ) functions->ResizeBuffers = st_resize_buffers; */ } - - -void st_destroy_cb_fbo( struct st_context *st ) -{ -} diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index f4fa66df59..6142434ec6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -30,9 +30,8 @@ #define ST_CB_FBO_H -extern void st_init_cb_fbo( struct st_context *st ); - -extern void st_destroy_cb_fbo( struct st_context *st ); +extern void +st_init_fbo_functions(struct dd_function_table *functions); #endif /* ST_CB_FBO_H */ diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 6da2aeb2f2..ed47c12066 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -32,7 +32,6 @@ #include "st_context.h" #include "st_program.h" - #include "glheader.h" #include "macros.h" #include "enums.h" @@ -44,6 +43,11 @@ #include "pipe/tgsi/mesa/tgsi_mesa.h" +/* Counter to track program string changes: + */ +static GLuint program_id = 0; + + static void st_bind_program( GLcontext *ctx, GLenum target, struct gl_program *prog ) @@ -70,7 +74,7 @@ static struct gl_program *st_new_program( GLcontext *ctx, case GL_VERTEX_PROGRAM_ARB: { struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program); - prog->id = st->program_id++; + prog->id = program_id++; prog->dirty = 1; return _mesa_init_vertex_program( ctx, @@ -84,7 +88,7 @@ static struct gl_program *st_new_program( GLcontext *ctx, { struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program); - prog->id = st->program_id++; + prog->id = program_id++; prog->dirty = 1; return _mesa_init_fragment_program( ctx, @@ -124,7 +128,7 @@ static void st_program_string_notify( GLcontext *ctx, if (prog == &ctx->FragmentProgram._Current->Base) st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; - p->id = st->program_id++; + p->id = program_id++; p->param_state = p->Base.Base.Parameters->StateFlags; } else if (target == GL_VERTEX_PROGRAM_ARB) { @@ -133,7 +137,7 @@ static void st_program_string_notify( GLcontext *ctx, if (prog == &ctx->VertexProgram._Current->Base) st->dirty.st |= ST_NEW_VERTEX_PROGRAM; - p->id = st->program_id++; + p->id = program_id++; p->param_state = p->Base.Base.Parameters->StateFlags; /* Also tell tnl about it: @@ -144,15 +148,8 @@ static void st_program_string_notify( GLcontext *ctx, -void st_init_cb_program( struct st_context *st ) +void st_init_program_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - - /* Need these flags: - */ - st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; - st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; - #if 0 assert(functions->ProgramStringNotify == _tnl_program_string); #endif @@ -162,9 +159,3 @@ void st_init_cb_program( struct st_context *st ) 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/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index a0245b553f..5872ae3e74 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1241,7 +1241,7 @@ do_copy_texsubimage(GLcontext *ctx, get_teximage_source(ctx, internalFormat); if (!stImage->mt || !src) { - DBG("%s fail %p %p\n", __FUNCTION__, stImage->mt, src); + DBG("%s fail %p %p\n", __FUNCTION__, (void *) stImage->mt, (void *) src); return GL_FALSE; } @@ -1726,10 +1726,9 @@ st_tex_unmap_images(struct pipe_context *pipe, -void st_init_cb_texture( struct st_context *st ) +void +st_init_texture_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->ChooseTextureFormat = st_ChooseTextureFormat; functions->TexImage1D = st_TexImage1D; functions->TexImage2D = st_TexImage2D; @@ -1756,8 +1755,3 @@ void st_init_cb_texture( struct st_context *st ) functions->TextureMemCpy = do_memcpy; } - - -void st_destroy_cb_texture( struct st_context *st ) -{ -} diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h index c474d16465..c732881c39 100644 --- a/src/mesa/state_tracker/st_cb_texture.h +++ b/src/mesa/state_tracker/st_cb_texture.h @@ -9,11 +9,7 @@ st_finalize_mipmap_tree(GLcontext *ctx, extern void -st_init_cb_texture( struct st_context *st ); - - -extern void -st_destroy_cb_texture( struct st_context *st ); +st_init_texture_functions(struct dd_function_table *functions); #endif /* ST_CB_TEXTURE_H */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 2b96286770..0ea06c692d 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -28,6 +28,7 @@ #include "imports.h" #include "st_public.h" #include "st_context.h" +#include "st_cb_bufferobjects.h" #include "st_cb_clear.h" #include "st_cb_drawpixels.h" #include "st_cb_texture.h" @@ -61,10 +62,17 @@ struct st_context *st_create_context( GLcontext *ctx, st_init_atoms( st ); st_init_draw( st ); + /* Need these flags: + */ + st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; + st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; + +#if 0 st_init_cb_clear( st ); st_init_cb_program( st ); st_init_cb_drawpixels( st ); st_init_cb_texture( st ); +#endif return st; } @@ -75,11 +83,13 @@ void st_destroy_context( struct st_context *st ) st_destroy_atoms( st ); st_destroy_draw( st ); +#if 0 st_destroy_cb_clear( st ); st_destroy_cb_program( st ); st_destroy_cb_drawpixels( st ); /*st_destroy_cb_teximage( st );*/ st_destroy_cb_texture( st ); +#endif st->pipe->destroy( st->pipe ); FREE( st ); @@ -87,3 +97,11 @@ void st_destroy_context( struct st_context *st ) +void st_init_driver_functions(struct dd_function_table *functions) +{ + st_init_bufferobject_functions(functions); + st_init_clear_functions(functions); + st_init_drawpixels_functions(functions); + st_init_program_functions(functions); + st_init_texture_functions(functions); +} diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index ef3cdb3b09..fe73630c75 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -97,10 +97,6 @@ struct st_context struct st_state_flags dirty; - /* Counter to track program string changes: - */ - GLuint program_id; - GLfloat polygon_offset_scale; /* ?? */ }; @@ -113,4 +109,7 @@ static INLINE struct st_context *st_context(GLcontext *ctx) } +extern void st_init_driver_functions(struct dd_function_table *functions); + + #endif diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index f6d5f6d76c..8dcb2ceb48 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -87,8 +87,9 @@ struct st_vertex_program GLuint param_state; }; -void st_init_cb_program( struct st_context *st ); -void st_destroy_cb_program( struct st_context *st ); + +extern void st_init_program_functions(struct dd_function_table *functions); + static inline struct st_fragment_program * st_fragment_program( struct gl_fragment_program *fp ) -- cgit v1.2.3 From 7faa3542f062dfa32e1596f5ce2b531cb8b4eeef Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 8 Aug 2007 16:08:45 -0600 Subject: setup frag shader state: color pass-through program --- src/mesa/state_tracker/st_cb_clear.c | 64 ++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 0ec7784d84..d862f7ba46 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -31,18 +31,22 @@ * Brian Paul */ -#include "glheader.h" -#include "macros.h" +#include "main/glheader.h" +#include "main/macros.h" +#include "shader/prog_instruction.h" #include "st_atom.h" #include "st_context.h" #include "st_cb_clear.h" +#include "st_program.h" #include "st_public.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/tgsi/mesa/mesa_to_tgsi.h" #include "vf/vf.h" + static GLuint color_value(GLuint pipeFormat, const GLfloat color[4]) { @@ -101,6 +105,49 @@ is_depth_stencil_format(GLuint pipeFormat) } + +/** + * Create a simple fragment shader that just passes through the fragment color. + */ +static struct st_fragment_program * +make_color_shader(struct st_context *st) +{ + GLcontext *ctx = st->ctx; + struct st_fragment_program *stfp; + struct gl_program *p; + GLboolean b; + + p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); + if (!p) + return NULL; + + p->NumInstructions = 2; + p->Instructions = _mesa_alloc_instructions(2); + if (!p->Instructions) { + ctx->Driver.DeleteProgram(ctx, p); + return NULL; + } + _mesa_init_instructions(p->Instructions, 2); + p->Instructions[0].Opcode = OPCODE_MOV; + p->Instructions[0].DstReg.File = PROGRAM_OUTPUT; + p->Instructions[0].DstReg.Index = 0; + p->Instructions[0].SrcReg[0].File = PROGRAM_INPUT; + p->Instructions[0].SrcReg[0].Index = FRAG_ATTRIB_COL0; + p->Instructions[1].Opcode = OPCODE_END; + + p->InputsRead = FRAG_BIT_COL0; + p->OutputsWritten = (1 << FRAG_RESULT_COLR); + + stfp = (struct st_fragment_program *) p; + /* compile into tgsi format */ + b = tgsi_mesa_compile_fp_program(&stfp->Base, + stfp->tokens, ST_FP_MAX_TOKENS); + assert(b); + + return stfp; +} + + /** * Draw a screen-aligned quadrilateral. * Coords are window coords. @@ -154,12 +201,14 @@ clear_with_quad(GLcontext *ctx, GLuint x0, GLuint y0, GLuint x1, GLuint y1, GLboolean color, GLboolean depth, GLboolean stencil) { + static struct st_fragment_program *stfp = NULL; struct st_context *st = ctx->st; struct pipe_alpha_test_state alpha_test; struct pipe_blend_state blend; struct pipe_depth_state depth_test; struct pipe_stencil_state stencil_test; struct pipe_setup_state setup; + struct pipe_fs_state fs; /* alpha state: disabled */ memset(&alpha_test, 0, sizeof(alpha_test)); @@ -210,6 +259,16 @@ clear_with_quad(GLcontext *ctx, GLuint x0, GLuint y0, } st->pipe->set_stencil_state(st->pipe, &stencil_test); + /* fragment shader state: color pass-through program */ + if (!stfp) { + stfp = make_color_shader(st); + } + memset(&fs, 0, sizeof(fs)); + fs.inputs_read = stfp->Base.Base.InputsRead; + fs.tokens = &stfp->tokens[0]; + fs.constants = NULL; + st->pipe->set_fs_state(st->pipe, &fs); + /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); @@ -217,6 +276,7 @@ clear_with_quad(GLcontext *ctx, GLuint x0, GLuint y0, st->pipe->set_alpha_test_state(st->pipe, &st->state.alpha_test); st->pipe->set_blend_state(st->pipe, &st->state.blend); st->pipe->set_depth_state(st->pipe, &st->state.depth); + st->pipe->set_fs_state(st->pipe, &st->state.fs); st->pipe->set_setup_state(st->pipe, &st->state.setup); st->pipe->set_stencil_state(st->pipe, &st->state.stencil); /* OR: -- cgit v1.2.3 From f5713c7d2e7ba8e1170fd9b1dd95379662ab6117 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 9 Aug 2007 12:59:11 -0600 Subject: Checkpoint intel_renderbuffer removal. Remove surface ptr from gl_renderbuffer. Use st_renderbuffer in most places. More clean-up. --- src/mesa/drivers/dri/intel_winsys/intel_blit.c | 14 +++-- src/mesa/main/mtypes.h | 2 - src/mesa/main/renderbuffer.c | 14 ++++- src/mesa/pipe/p_state.h | 2 - src/mesa/state_tracker/st_atom_framebuffer.c | 27 +++++---- src/mesa/state_tracker/st_cb_clear.c | 35 +++++++---- src/mesa/state_tracker/st_cb_fbo.c | 82 +++++++++----------------- src/mesa/state_tracker/st_cb_fbo.h | 23 ++++++-- 8 files changed, 107 insertions(+), 92 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_blit.c b/src/mesa/drivers/dri/intel_winsys/intel_blit.c index 48bbbbeac9..aa4135ed2d 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_blit.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_blit.c @@ -38,6 +38,7 @@ #include "vblank.h" #include "pipe/p_context.h" +#include "state_tracker/st_cb_fbo.h" #define FILE_DEBUG_FLAG DEBUG_BLIT @@ -106,12 +107,17 @@ intelCopyBuffer(__DRIdrawablePrivate * dPriv, const struct pipe_surface *backSurf; const struct pipe_region *backRegion; int srcpitch; + struct st_renderbuffer *strb; /* blit from back color buffer if it exists, else front buffer */ - if (intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer) - backSurf = intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer->surface; - else - backSurf = intel_fb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer->surface; + strb = st_renderbuffer(intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer); + if (strb) { + backSurf = strb->surface; + } + else { + strb = st_renderbuffer(intel_fb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer); + backSurf = strb->surface; + } backRegion = backSurf->region; srcpitch = backRegion->pitch; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index d70df5d945..0a64e0c58c 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2269,8 +2269,6 @@ struct gl_renderbuffer GLubyte StencilBits; GLvoid *Data; /**< This may not be used by some kinds of RBs */ - struct pipe_surface *surface; - /* Used to wrap one renderbuffer around another: */ struct gl_renderbuffer *Wrapped; diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c index d89704196a..e7aeea8e3e 100644 --- a/src/mesa/main/renderbuffer.c +++ b/src/mesa/main/renderbuffer.c @@ -1067,9 +1067,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->PutMonoValues = put_mono_values_ubyte; rb->StencilBits = 8 * sizeof(GLubyte); pixelSize = sizeof(GLubyte); +#if 0 if (!rb->surface) rb->surface = (struct pipe_surface *) pipe->surface_alloc(pipe, PIPE_FORMAT_U_S8); +#endif break; case GL_STENCIL_INDEX16_EXT: rb->_ActualFormat = GL_STENCIL_INDEX16_EXT; @@ -1100,9 +1102,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->PutValues = put_values_ushort; rb->PutMonoValues = put_mono_values_ushort; rb->DepthBits = 8 * sizeof(GLushort); +#if 0 if (!rb->surface) rb->surface = (struct pipe_surface *) pipe->surface_alloc(pipe, PIPE_FORMAT_U_Z16); +#endif pixelSize = sizeof(GLushort); break; case GL_DEPTH_COMPONENT24: @@ -1125,9 +1129,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->_ActualFormat = GL_DEPTH_COMPONENT32; rb->DepthBits = 32; } +#if 0 if (!rb->surface) rb->surface = (struct pipe_surface *) pipe->surface_alloc(pipe, PIPE_FORMAT_U_Z32); +#endif pixelSize = sizeof(GLuint); break; case GL_DEPTH_STENCIL_EXT: @@ -1145,9 +1151,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->PutMonoValues = put_mono_values_uint; rb->DepthBits = 24; rb->StencilBits = 8; +#if 0 if (!rb->surface) rb->surface = (struct pipe_surface *) pipe->surface_alloc(pipe, PIPE_FORMAT_S8_Z24); +#endif pixelSize = sizeof(GLuint); break; case GL_COLOR_INDEX8_EXT: @@ -1210,7 +1218,7 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, ASSERT(rb->PutMonoValues); /* free old buffer storage */ - if (rb->surface) { + if (0/**rb->surface**/) { /* pipe_surface/region */ } else if (rb->Data) { @@ -1221,8 +1229,9 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, if (width > 0 && height > 0) { /* allocate new buffer storage */ - if (rb->surface) { + if (0/**rb->surface**/) { /* pipe_surface/region */ +#if 0 if (rb->surface->region) { pipe->region_unmap(pipe, rb->surface->region); pipe->region_release(pipe, &rb->surface->region); @@ -1231,6 +1240,7 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, /* XXX probably don't want to really map here */ pipe->region_map(pipe, rb->surface->region); rb->Data = rb->surface->region->map; +#endif } else { /* legacy renderbuffer (this will go away) */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 2dcd2db868..ee29e38a48 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -260,8 +260,6 @@ struct pipe_surface GLuint offset; /**< offset from start of region, in bytes */ GLint refcount; - void *rb; /**< Ptr back to renderbuffer (temporary?) */ - /** get block/tile of pixels from surface */ void (*get_tile)(struct pipe_surface *ps, GLuint x, GLuint y, GLuint w, GLuint h, GLfloat *p); diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index 7edd044ad9..f054eb8f21 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -33,6 +33,7 @@ #include "st_context.h" #include "st_atom.h" +#include "st_cb_fbo.h" #include "pipe/p_context.h" @@ -44,7 +45,7 @@ static void update_framebuffer_state( struct st_context *st ) { struct pipe_framebuffer_state framebuffer; - struct gl_renderbuffer *rb; + struct st_renderbuffer *strb; GLuint i; memset(&framebuffer, 0, sizeof(framebuffer)); @@ -54,21 +55,23 @@ update_framebuffer_state( struct st_context *st ) */ framebuffer.num_cbufs = st->ctx->DrawBuffer->_NumColorDrawBuffers[0]; for (i = 0; i < framebuffer.num_cbufs; i++) { - rb = st->ctx->DrawBuffer->_ColorDrawBuffers[0][i]; - assert(rb->surface); - framebuffer.cbufs[i] = rb->surface; + strb = st_renderbuffer(st->ctx->DrawBuffer->_ColorDrawBuffers[0][i]); + assert(strb->surface); + framebuffer.cbufs[i] = strb->surface; } - rb = st->ctx->DrawBuffer->_DepthBuffer; - if (rb) { - assert(rb->Wrapped->surface); - framebuffer.zbuf = rb->Wrapped->surface; + strb = st_renderbuffer(st->ctx->DrawBuffer->_DepthBuffer); + if (strb) { + strb = st_renderbuffer(strb->Base.Wrapped); + assert(strb->surface); + framebuffer.zbuf = strb->surface; } - rb = st->ctx->DrawBuffer->_StencilBuffer; - if (rb) { - assert(rb->Wrapped->surface); - framebuffer.sbuf = rb->Wrapped->surface; + strb = st_renderbuffer(st->ctx->DrawBuffer->_StencilBuffer); + if (strb) { + strb = st_renderbuffer(strb->Base.Wrapped); + assert(strb->surface); + framebuffer.sbuf = strb->surface; } if (memcmp(&framebuffer, &st->state.framebuffer, sizeof(framebuffer)) != 0) { diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index d862f7ba46..4da3a2500d 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -37,6 +37,7 @@ #include "st_atom.h" #include "st_context.h" #include "st_cb_clear.h" +#include "st_cb_fbo.h" #include "st_program.h" #include "st_public.h" #include "pipe/p_context.h" @@ -288,6 +289,8 @@ clear_with_quad(GLcontext *ctx, GLuint x0, GLuint y0, static void clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + if (ctx->Color.ColorMask[0] && ctx->Color.ColorMask[1] && ctx->Color.ColorMask[2] && @@ -296,8 +299,8 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { /* clear whole buffer w/out masking */ GLuint clearValue - = color_value(rb->surface->format, ctx->Color.ClearColor); - ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + = color_value(strb->surface->format, ctx->Color.ClearColor); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } else { /* masking or scissoring */ @@ -314,14 +317,16 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + if (!ctx->Scissor.Enabled) { /* clear whole buffer w/out masking */ GLuint clearValue - = color_value(rb->surface->format, ctx->Accum.ClearColor); + = color_value(strb->surface->format, ctx->Accum.ClearColor); /* Note that clearValue is 32 bits but the accum buffer will * typically be 64bpp... */ - ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } else { /* scissoring */ @@ -339,11 +344,13 @@ clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + if (!ctx->Scissor.Enabled && - !is_depth_stencil_format(rb->surface->format)) { + !is_depth_stencil_format(strb->surface->format)) { /* clear whole depth buffer w/out masking */ - GLuint clearValue = depth_value(rb->surface->format, ctx->Depth.Clear); - ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } else { /* masking or scissoring or combined z/stencil buffer */ @@ -360,14 +367,15 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); const GLuint stencilMax = (1 << rb->StencilBits) - 1; GLboolean maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; if (!maskStencil && !ctx->Scissor.Enabled && - !is_depth_stencil_format(rb->surface->format)) { + !is_depth_stencil_format(strb->surface->format)) { /* clear whole stencil buffer w/out masking */ GLuint clearValue = ctx->Stencil.Clear; - ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } else { /* masking or scissoring */ @@ -384,16 +392,17 @@ clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); const GLuint stencilMax = 1 << rb->StencilBits; GLboolean maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; - assert(is_depth_stencil_format(rb->surface->format)); + assert(is_depth_stencil_format(strb->surface->format)); if (!maskStencil && !ctx->Scissor.Enabled) { /* clear whole buffer w/out masking */ - GLuint clearValue = depth_value(rb->surface->format, ctx->Depth.Clear); + GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); - switch (rb->surface->format) { + switch (strb->surface->format) { case PIPE_FORMAT_S8_Z24: clearValue |= ctx->Stencil.Clear << 24; break; @@ -406,7 +415,7 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) assert(0); } - ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } else { /* masking or scissoring */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 3cd1fbe851..02bdb5aba5 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -46,29 +46,6 @@ #include "st_cb_teximage.h" -/** - * Derived renderbuffer class. Just need to add a pointer to the - * pipe surface. - */ -struct st_renderbuffer -{ - struct gl_renderbuffer Base; -#if 0 - struct pipe_surface *surface; -#endif -}; - - -/** - * Cast wrapper. - */ -static INLINE struct st_renderbuffer * -st_renderbuffer(struct gl_renderbuffer *rb) -{ - return (struct st_renderbuffer *) rb; -} - - struct pipe_format_info { GLuint format; @@ -168,29 +145,29 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, cpp = info->size; - if (!strb->Base.surface) { - strb->Base.surface = pipe->surface_alloc(pipe, pipeFormat); - if (!strb->Base.surface) + if (!strb->surface) { + strb->surface = pipe->surface_alloc(pipe, pipeFormat); + if (!strb->surface) return GL_FALSE; } /* free old region */ - if (strb->Base.surface->region) { - pipe->region_release(pipe, &strb->Base.surface->region); + if (strb->surface->region) { + pipe->region_release(pipe, &strb->surface->region); } /* Choose a pitch to match hardware requirements: */ pitch = ((cpp * width + 63) & ~63) / cpp; /* XXX fix: device-specific */ - strb->Base.surface->region = pipe->region_alloc(pipe, cpp, pitch, height); - if (!strb->Base.surface->region) + strb->surface->region = pipe->region_alloc(pipe, cpp, pitch, height); + if (!strb->surface->region) return GL_FALSE; /* out of memory, try s/w buffer? */ - ASSERT(strb->Base.surface->region->buffer); + ASSERT(strb->surface->region->buffer); - strb->Base.Width = strb->Base.surface->width = width; - strb->Base.Height = strb->Base.surface->height = height; + strb->Base.Width = strb->surface->width = width; + strb->Base.Height = strb->surface->height = height; return GL_TRUE; } @@ -206,11 +183,11 @@ st_renderbuffer_delete(struct gl_renderbuffer *rb) struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); ASSERT(strb); - if (strb && strb->Base.surface) { - if (rb->surface->region) { - pipe->region_release(pipe, &strb->Base.surface->region); + if (strb && strb->surface) { + if (strb->surface->region) { + pipe->region_release(pipe, &strb->surface->region); } - free(strb->Base.surface); + free(strb->surface); } free(strb); } @@ -285,28 +262,28 @@ st_new_renderbuffer_fb(struct pipe_region *region, GLuint width, GLuint height) struct gl_renderbuffer * st_new_renderbuffer_fb(GLuint intFormat) { - struct st_renderbuffer *irb; + struct st_renderbuffer *strb; - irb = CALLOC_STRUCT(st_renderbuffer); - if (!irb) { + strb = CALLOC_STRUCT(st_renderbuffer); + if (!strb) { _mesa_error(NULL, GL_OUT_OF_MEMORY, "creating renderbuffer"); return NULL; } - _mesa_init_renderbuffer(&irb->Base, 0); - irb->Base.ClassID = 0x42; /* XXX temp */ - irb->Base.InternalFormat = intFormat; + _mesa_init_renderbuffer(&strb->Base, 0); + strb->Base.ClassID = 0x42; /* XXX temp */ + strb->Base.InternalFormat = intFormat; switch (intFormat) { case GL_RGB5: case GL_RGBA8: - irb->Base._BaseFormat = GL_RGBA; + strb->Base._BaseFormat = GL_RGBA; break; case GL_DEPTH_COMPONENT16: - irb->Base._BaseFormat = GL_DEPTH_COMPONENT; + strb->Base._BaseFormat = GL_DEPTH_COMPONENT; break; case GL_DEPTH24_STENCIL8_EXT: - irb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT; + strb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT; break; default: _mesa_problem(NULL, @@ -315,15 +292,14 @@ st_new_renderbuffer_fb(GLuint intFormat) } /* st-specific methods */ - irb->Base.Delete = st_renderbuffer_delete; - irb->Base.AllocStorage = st_renderbuffer_alloc_storage; - irb->Base.GetPointer = null_get_pointer; - /* span routines set in alloc_storage function */ + strb->Base.Delete = st_renderbuffer_delete; + strb->Base.AllocStorage = st_renderbuffer_alloc_storage; + strb->Base.GetPointer = null_get_pointer; - irb->Base.surface = NULL;/*intel_new_surface(intFormat);*/ - /*irb->Base.surface->rb = irb;*/ + /* surface is allocate in alloc_renderbuffer_storage() */ + strb->surface = NULL; - return &irb->Base; + return &strb->Base; } #endif diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index 7f52ab10d7..b2e7ba810c 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -30,10 +30,25 @@ #define ST_CB_FBO_H -/* -extern struct gl_renderbuffer * -st_new_renderbuffer_fb(struct pipe_region *region, GLuint width, GLuint height); -*/ + +/** + * Derived renderbuffer class. Just need to add a pointer to the + * pipe surface. + */ +struct st_renderbuffer +{ + struct gl_renderbuffer Base; + struct pipe_surface *surface; +}; + + +static INLINE struct st_renderbuffer * +st_renderbuffer(struct gl_renderbuffer *rb) +{ + return (struct st_renderbuffer *) rb; +} + + extern struct gl_renderbuffer * st_new_renderbuffer_fb(GLuint intFormat); -- cgit v1.2.3 From be57c1aac46e6af2f1dd8ce1f10334d034ac7464 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 9 Aug 2007 19:04:28 -0600 Subject: comments --- src/mesa/state_tracker/st_cb_clear.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 4da3a2500d..e3392101a8 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -129,11 +129,13 @@ make_color_shader(struct st_context *st) return NULL; } _mesa_init_instructions(p->Instructions, 2); + /* MOV result.color, fragment.color; */ p->Instructions[0].Opcode = OPCODE_MOV; p->Instructions[0].DstReg.File = PROGRAM_OUTPUT; - p->Instructions[0].DstReg.Index = 0; + p->Instructions[0].DstReg.Index = FRAG_RESULT_COLR; p->Instructions[0].SrcReg[0].File = PROGRAM_INPUT; p->Instructions[0].SrcReg[0].Index = FRAG_ATTRIB_COL0; + /* END; */ p->Instructions[1].Opcode = OPCODE_END; p->InputsRead = FRAG_BIT_COL0; -- cgit v1.2.3 From 1c8bcc733d695732ca704565b3a10ac5f4172ea3 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 10 Aug 2007 16:25:21 -0600 Subject: Y invert, clean-up --- src/mesa/state_tracker/st_cb_clear.c | 156 +++++++++++++++++------------------ 1 file changed, 74 insertions(+), 82 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index e3392101a8..2583b4f1bd 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -198,79 +198,96 @@ draw_quad(GLcontext *ctx, /** * Do glClear by drawing a quadrilateral. + * The vertices of the quad will be computed from the + * ctx->DrawBuffer->_X/Ymin/max fields. */ static void -clear_with_quad(GLcontext *ctx, GLuint x0, GLuint y0, - GLuint x1, GLuint y1, +clear_with_quad(GLcontext *ctx, GLboolean color, GLboolean depth, GLboolean stencil) { - static struct st_fragment_program *stfp = NULL; struct st_context *st = ctx->st; - struct pipe_alpha_test_state alpha_test; - struct pipe_blend_state blend; - struct pipe_depth_state depth_test; - struct pipe_stencil_state stencil_test; - struct pipe_setup_state setup; - struct pipe_fs_state fs; + const GLfloat x0 = ctx->DrawBuffer->_Xmin; + const GLfloat y0 = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymax; + const GLfloat x1 = ctx->DrawBuffer->_Xmax; + const GLfloat y1 = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymin; /* alpha state: disabled */ - memset(&alpha_test, 0, sizeof(alpha_test)); - st->pipe->set_alpha_test_state(st->pipe, &alpha_test); + { + struct pipe_alpha_test_state alpha_test; + memset(&alpha_test, 0, sizeof(alpha_test)); + st->pipe->set_alpha_test_state(st->pipe, &alpha_test); + } /* blend state: RGBA masking */ - memset(&blend, 0, sizeof(blend)); - if (color) { - if (ctx->Color.ColorMask[0]) - blend.colormask |= PIPE_MASK_R; - if (ctx->Color.ColorMask[1]) - blend.colormask |= PIPE_MASK_G; - if (ctx->Color.ColorMask[2]) - blend.colormask |= PIPE_MASK_B; - if (ctx->Color.ColorMask[3]) - blend.colormask |= PIPE_MASK_A; - if (st->ctx->Color.DitherFlag) - blend.dither = 1; + { + struct pipe_blend_state blend; + memset(&blend, 0, sizeof(blend)); + if (color) { + if (ctx->Color.ColorMask[0]) + blend.colormask |= PIPE_MASK_R; + if (ctx->Color.ColorMask[1]) + blend.colormask |= PIPE_MASK_G; + if (ctx->Color.ColorMask[2]) + blend.colormask |= PIPE_MASK_B; + if (ctx->Color.ColorMask[3]) + blend.colormask |= PIPE_MASK_A; + if (st->ctx->Color.DitherFlag) + blend.dither = 1; + } + st->pipe->set_blend_state(st->pipe, &blend); } - st->pipe->set_blend_state(st->pipe, &blend); /* depth state: always pass */ - memset(&depth_test, 0, sizeof(depth_test)); - if (depth) { - depth_test.enabled = 1; - depth_test.writemask = 1; - depth_test.func = PIPE_FUNC_ALWAYS; + { + struct pipe_depth_state depth_test; + memset(&depth_test, 0, sizeof(depth_test)); + if (depth) { + depth_test.enabled = 1; + depth_test.writemask = 1; + depth_test.func = PIPE_FUNC_ALWAYS; + } + st->pipe->set_depth_state(st->pipe, &depth_test); } - st->pipe->set_depth_state(st->pipe, &depth_test); /* setup state: nothing */ - memset(&setup, 0, sizeof(setup)); - if (ctx->Scissor.Enabled) - setup.scissor = 1; - st->pipe->set_setup_state(st->pipe, &setup); + { + struct pipe_setup_state setup; + memset(&setup, 0, sizeof(setup)); + if (ctx->Scissor.Enabled) + setup.scissor = 1; + st->pipe->set_setup_state(st->pipe, &setup); + } /* stencil state: always set to ref value */ - memset(&stencil_test, 0, sizeof(stencil_test)); - if (stencil) { - stencil_test.front_enabled = 1; - stencil_test.front_func = PIPE_FUNC_ALWAYS; - stencil_test.front_fail_op = PIPE_STENCIL_OP_REPLACE; - stencil_test.front_zpass_op = PIPE_STENCIL_OP_REPLACE; - stencil_test.front_zfail_op = PIPE_STENCIL_OP_REPLACE; - stencil_test.ref_value[0] = ctx->Stencil.Clear; - stencil_test.value_mask[0] = 0xff; - stencil_test.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; + { + struct pipe_stencil_state stencil_test; + memset(&stencil_test, 0, sizeof(stencil_test)); + if (stencil) { + stencil_test.front_enabled = 1; + stencil_test.front_func = PIPE_FUNC_ALWAYS; + stencil_test.front_fail_op = PIPE_STENCIL_OP_REPLACE; + stencil_test.front_zpass_op = PIPE_STENCIL_OP_REPLACE; + stencil_test.front_zfail_op = PIPE_STENCIL_OP_REPLACE; + stencil_test.ref_value[0] = ctx->Stencil.Clear; + stencil_test.value_mask[0] = 0xff; + stencil_test.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; + } + st->pipe->set_stencil_state(st->pipe, &stencil_test); } - st->pipe->set_stencil_state(st->pipe, &stencil_test); /* fragment shader state: color pass-through program */ - if (!stfp) { - stfp = make_color_shader(st); + { + static struct st_fragment_program *stfp = NULL; + struct pipe_fs_state fs; + if (!stfp) { + stfp = make_color_shader(st); + } + memset(&fs, 0, sizeof(fs)); + fs.inputs_read = stfp->Base.Base.InputsRead; + fs.tokens = &stfp->tokens[0]; + fs.constants = NULL; + st->pipe->set_fs_state(st->pipe, &fs); } - memset(&fs, 0, sizeof(fs)); - fs.inputs_read = stfp->Base.Base.InputsRead; - fs.tokens = &stfp->tokens[0]; - fs.constants = NULL; - st->pipe->set_fs_state(st->pipe, &fs); /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); @@ -306,12 +323,7 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) } else { /* masking or scissoring */ - clear_with_quad(ctx, - ctx->DrawBuffer->_Xmin, - ctx->DrawBuffer->_Xmin, - ctx->DrawBuffer->_Xmax, - ctx->DrawBuffer->_Ymax, - GL_TRUE, GL_FALSE, GL_FALSE); + clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE); } } @@ -333,12 +345,7 @@ clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) else { /* scissoring */ /* XXX point framebuffer.cbufs[0] at the accum buffer */ - clear_with_quad(ctx, - ctx->DrawBuffer->_Xmin, - ctx->DrawBuffer->_Xmin, - ctx->DrawBuffer->_Xmax, - ctx->DrawBuffer->_Ymax, - GL_TRUE, GL_FALSE, GL_FALSE); + clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE); } } @@ -356,12 +363,7 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) } else { /* masking or scissoring or combined z/stencil buffer */ - clear_with_quad(ctx, - ctx->DrawBuffer->_Xmin, - ctx->DrawBuffer->_Xmin, - ctx->DrawBuffer->_Xmax, - ctx->DrawBuffer->_Ymax, - GL_FALSE, GL_TRUE, GL_FALSE); + clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE); } } @@ -381,12 +383,7 @@ clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) } else { /* masking or scissoring */ - clear_with_quad(ctx, - ctx->DrawBuffer->_Xmin, - ctx->DrawBuffer->_Xmin, - ctx->DrawBuffer->_Xmax, - ctx->DrawBuffer->_Ymax, - GL_FALSE, GL_FALSE, GL_TRUE); + clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE); } } @@ -421,12 +418,7 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) } else { /* masking or scissoring */ - clear_with_quad(ctx, - ctx->DrawBuffer->_Xmin, - ctx->DrawBuffer->_Xmin, - ctx->DrawBuffer->_Xmax, - ctx->DrawBuffer->_Ymax, - GL_FALSE, GL_TRUE, GL_TRUE); + clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE); } } -- cgit v1.2.3 From 8571c4babf82b2fe78dba06458070eb4010cfc18 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 13 Aug 2007 16:16:42 -0600 Subject: added an assertion --- src/mesa/state_tracker/st_cb_clear.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 2583b4f1bd..80f136e0a6 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -454,8 +454,10 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) GLuint b; for (b = 0; b < BUFFER_COUNT; b++) { if (BUFFER_BITS_COLOR & mask & (1 << b)) { - clear_color_buffer(ctx, - ctx->DrawBuffer->Attachment[b].Renderbuffer); + struct gl_renderbuffer *rb + = ctx->DrawBuffer->Attachment[b].Renderbuffer; + assert(rb); + clear_color_buffer(ctx, rb); } } } -- cgit v1.2.3 From 94a4910c9a1ef48470f45c01c379254cb033119f Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 15 Aug 2007 19:13:03 -0600 Subject: added PIPE_PRIM_x tokens (matching GL), use in a few places --- src/mesa/pipe/p_defines.h | 14 +++++ src/mesa/pipe/softpipe/sp_draw_arrays.c | 90 +++++++++++++++---------------- src/mesa/state_tracker/st_cb_clear.c | 2 +- src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- 4 files changed, 61 insertions(+), 47 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h index addbb026bf..43d1c438ae 100644 --- a/src/mesa/pipe/p_defines.h +++ b/src/mesa/pipe/p_defines.h @@ -276,5 +276,19 @@ #define PIPE_FLUSH_TEXTURE_CACHE 0x2 +/** + * Primitive types: + */ +#define PIPE_PRIM_POINTS 0 +#define PIPE_PRIM_LINES 1 +#define PIPE_PRIM_LINE_LOOP 2 +#define PIPE_PRIM_LINE_STRIP 3 +#define PIPE_PRIM_TRIANGLES 4 +#define PIPE_PRIM_TRIANGLE_STRIP 5 +#define PIPE_PRIM_TRIANGLE_FAN 6 +#define PIPE_PRIM_QUADS 7 +#define PIPE_PRIM_QUAD_STRIP 8 +#define PIPE_PRIM_POLYGON 9 + #endif diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c index c466884fdd..43a53f108c 100644 --- a/src/mesa/pipe/softpipe/sp_draw_arrays.c +++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c @@ -75,7 +75,7 @@ static unsigned reduced_prim[GL_POLYGON + 1] = { */ static void run_vertex_program(struct draw_context *draw, - const void *vbuffer, GLuint elem, + const void *vbuffer, unsigned elem, struct vertex_header *vOut) { const float *vIn, *cIn; @@ -224,8 +224,8 @@ static void draw_invalidate_vcache( struct draw_context *draw ) * vertices. Flush primitive and/or vertex queues if necessary to * make space. */ -static struct prim_header *get_queued_prim( struct draw_context *draw, - GLuint nr_verts ) +static struct prim_header * +get_queued_prim( struct draw_context *draw, unsigned nr_verts ) { if (draw->pq.queue_nr + 1 >= PRIM_QUEUE_LENGTH || draw->vcache.overflow + nr_verts >= VCACHE_OVERFLOW) @@ -242,8 +242,8 @@ static struct prim_header *get_queued_prim( struct draw_context *draw, /* Check if vertex is in cache, otherwise add it. It won't go through * VS yet, not until there is a flush operation or the VS queue fills up. */ -static struct vertex_header *get_vertex( struct draw_context *draw, - GLuint i ) +static struct vertex_header * +get_vertex( struct draw_context *draw, unsigned i ) { unsigned slot = (i + (i>>5)) & 31; @@ -273,8 +273,8 @@ static struct vertex_header *get_vertex( struct draw_context *draw, -static void draw_set_prim( struct draw_context *draw, - GLenum prim ) +static void +draw_set_prim( struct draw_context *draw, unsigned prim ) { if (reduced_prim[prim] != draw->reduced_prim) { draw_flush( draw ); @@ -286,7 +286,7 @@ static void draw_set_prim( struct draw_context *draw, static void do_point( struct draw_context *draw, - GLuint i0 ) + unsigned i0 ) { struct prim_header *prim = get_queued_prim( draw, 1 ); @@ -299,8 +299,8 @@ static void do_point( struct draw_context *draw, static void do_line( struct draw_context *draw, GLboolean reset_stipple, - GLuint i0, - GLuint i1 ) + unsigned i0, + unsigned i1 ) { struct prim_header *prim = get_queued_prim( draw, 2 ); @@ -312,9 +312,9 @@ static void do_line( struct draw_context *draw, } static void do_triangle( struct draw_context *draw, - GLuint i0, - GLuint i1, - GLuint i2 ) + unsigned i0, + unsigned i1, + unsigned i2 ) { struct prim_header *prim = get_queued_prim( draw, 3 ); @@ -328,10 +328,10 @@ static void do_triangle( struct draw_context *draw, static void do_ef_triangle( struct draw_context *draw, GLboolean reset_stipple, - GLuint ef_mask, - GLuint i0, - GLuint i1, - GLuint i2 ) + unsigned ef_mask, + unsigned i0, + unsigned i1, + unsigned i2 ) { struct prim_header *prim = get_queued_prim( draw, 3 ); struct vertex_header *v0 = draw->get_vertex( draw, i0 ); @@ -362,22 +362,22 @@ static void do_quad( struct draw_context *draw, static void draw_prim( struct draw_context *draw, - GLuint start, - GLuint count ) + unsigned start, + unsigned count ) { - GLuint i; + unsigned i; // _mesa_printf("%s (%d) %d/%d\n", __FUNCTION__, draw->prim, start, count ); switch (draw->prim) { - case GL_POINTS: + case PIPE_PRIM_POINTS: for (i = 0; i < count; i ++) { do_point( draw, start + i ); } break; - case GL_LINES: + case PIPE_PRIM_LINES: for (i = 0; i+1 < count; i += 2) { do_line( draw, TRUE, @@ -386,7 +386,7 @@ static void draw_prim( struct draw_context *draw, } break; - case GL_LINE_LOOP: + case PIPE_PRIM_LINE_LOOP: if (count >= 2) { for (i = 1; i < count; i++) { do_line( draw, @@ -402,7 +402,7 @@ static void draw_prim( struct draw_context *draw, } break; - case GL_LINE_STRIP: + case PIPE_PRIM_LINE_STRIP: if (count >= 2) { for (i = 1; i < count; i++) { do_line( draw, @@ -413,7 +413,7 @@ static void draw_prim( struct draw_context *draw, } break; - case GL_TRIANGLES: + case PIPE_PRIM_TRIANGLES: for (i = 0; i+2 < count; i += 3) { do_ef_triangle( draw, 1, @@ -424,7 +424,7 @@ static void draw_prim( struct draw_context *draw, } break; - case GL_TRIANGLE_STRIP: + case PIPE_PRIM_TRIANGLE_STRIP: for (i = 0; i+2 < count; i++) { if (i & 1) { do_triangle( draw, @@ -441,7 +441,7 @@ static void draw_prim( struct draw_context *draw, } break; - case GL_TRIANGLE_FAN: + case PIPE_PRIM_TRIANGLE_FAN: if (count >= 3) { for (i = 0; i+2 < count; i++) { do_triangle( draw, @@ -453,7 +453,7 @@ static void draw_prim( struct draw_context *draw, break; - case GL_QUADS: + case PIPE_PRIM_QUADS: for (i = 0; i+3 < count; i += 4) { do_quad( draw, start + i + 0, @@ -463,7 +463,7 @@ static void draw_prim( struct draw_context *draw, } break; - case GL_QUAD_STRIP: + case PIPE_PRIM_QUAD_STRIP: for (i = 0; i+3 < count; i += 2) { do_quad( draw, start + i + 2, @@ -473,7 +473,7 @@ static void draw_prim( struct draw_context *draw, } break; - case GL_POLYGON: + case PIPE_PRIM_POLYGON: if (count >= 3) { unsigned ef_mask = (1<<2) | (1<<0); @@ -502,43 +502,43 @@ static void draw_prim( struct draw_context *draw, -static GLuint draw_prim_info(GLenum mode, GLuint *first, GLuint *incr) +static unsigned draw_prim_info(unsigned mode, unsigned *first, unsigned *incr) { switch (mode) { - case GL_POINTS: + case PIPE_PRIM_POINTS: *first = 1; *incr = 1; return 0; - case GL_LINES: + case PIPE_PRIM_LINES: *first = 2; *incr = 2; return 0; - case GL_LINE_STRIP: + case PIPE_PRIM_LINE_STRIP: *first = 2; *incr = 1; return 0; - case GL_LINE_LOOP: + case PIPE_PRIM_LINE_LOOP: *first = 2; *incr = 1; return 1; - case GL_TRIANGLES: + case PIPE_PRIM_TRIANGLES: *first = 3; *incr = 3; return 0; - case GL_TRIANGLE_STRIP: + case PIPE_PRIM_TRIANGLE_STRIP: *first = 3; *incr = 1; return 0; - case GL_TRIANGLE_FAN: - case GL_POLYGON: + case PIPE_PRIM_TRIANGLE_FAN: + case PIPE_PRIM_POLYGON: *first = 3; *incr = 1; return 1; - case GL_QUADS: + case PIPE_PRIM_QUADS: *first = 4; *incr = 4; return 0; - case GL_QUAD_STRIP: + case PIPE_PRIM_QUAD_STRIP: *first = 4; *incr = 2; return 0; @@ -551,7 +551,7 @@ static GLuint draw_prim_info(GLenum mode, GLuint *first, GLuint *incr) } -static GLuint trim( GLuint count, GLuint first, GLuint incr ) +static unsigned trim( unsigned count, unsigned first, unsigned incr ) { if (count < first) return 0; @@ -627,10 +627,10 @@ do { \ void draw_set_vertex_attributes2( struct draw_context *draw, - const GLuint *slot_to_vf_attr, - GLuint nr_attrs ) + const unsigned *slot_to_vf_attr, + unsigned nr_attrs ) { - GLuint i; + unsigned i; memset(draw->vf_attr_to_slot, 0, sizeof(draw->vf_attr_to_slot)); draw->nr_attrs = 0; diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 80f136e0a6..2f7ade73e4 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -190,7 +190,7 @@ draw_quad(GLcontext *ctx, verts[i][1][3] = color[3]; } - ctx->st->pipe->draw_vertices(ctx->st->pipe, GL_QUADS, + ctx->st->pipe->draw_vertices(ctx->st->pipe, PIPE_PRIM_QUADS, 4, (GLfloat *) verts, 2, attribs); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index df0b14463b..dd27760a58 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -235,7 +235,7 @@ draw_quad(struct st_context *st, GLfloat x0, GLfloat y0, GLfloat z, verts[i][1][3] = 1.0; /*Q*/ } - st->pipe->draw_vertices(st->pipe, GL_QUADS, + st->pipe->draw_vertices(st->pipe, PIPE_PRIM_QUADS, 4, (GLfloat *) verts, 2, attribs); } -- cgit v1.2.3 From de653b4c9bddcec46f3ddf411ec082dd178d7b38 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 16 Aug 2007 13:33:43 -0600 Subject: Begin added vertex shader state/support. Renamed pipe_fs_state to pipe_shader_state since it can be used for both vertex and fragment shader info. --- src/mesa/pipe/i915simple/i915_context.h | 2 +- src/mesa/pipe/i915simple/i915_state.c | 2 +- src/mesa/pipe/p_context.h | 5 +- src/mesa/pipe/p_state.h | 4 +- src/mesa/pipe/softpipe/sp_context.h | 4 +- src/mesa/pipe/softpipe/sp_state.h | 5 +- src/mesa/pipe/softpipe/sp_state_fs.c | 14 +++--- src/mesa/state_tracker/st_atom_fs.c | 83 ++++++++++++++++++++++++++++++- src/mesa/state_tracker/st_cb_clear.c | 2 +- src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_context.h | 3 +- src/mesa/state_tracker/st_program.h | 2 + 12 files changed, 111 insertions(+), 17 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index d69657daa9..1e48485c56 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -105,7 +105,7 @@ struct i915_context struct pipe_clip_state clip; struct pipe_depth_state depth_test; struct pipe_framebuffer_state framebuffer; - struct pipe_fs_state fs; + struct pipe_shader_state fs; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index f874b21016..06fa716c4f 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -111,7 +111,7 @@ static void i915_set_polygon_stipple( struct pipe_context *pipe, static void i915_set_fs_state( struct pipe_context *pipe, - const struct pipe_fs_state *fs ) + const struct pipe_shader_state *fs ) { struct i915_context *i915 = i915_context(pipe); diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 6679aae089..320b4877c3 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -117,7 +117,10 @@ struct pipe_context { const struct pipe_framebuffer_state * ); void (*set_fs_state)( struct pipe_context *, - const struct pipe_fs_state * ); + const struct pipe_shader_state * ); + + void (*set_vs_state)( struct pipe_context *, + const struct pipe_shader_state * ); void (*set_polygon_stipple)( struct pipe_context *, const struct pipe_poly_stipple * ); diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 4878cb41bd..c1972c56b3 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -121,8 +121,8 @@ struct pipe_constant_buffer { }; -struct pipe_fs_state { - unsigned inputs_read; /* FRAG_ATTRIB_* */ +struct pipe_shader_state { + unsigned inputs_read; /* FRAG/VERT_ATTRIB_* */ const struct tgsi_token *tokens; struct pipe_constant_buffer *constants; /* XXX temporary? */ }; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index f45cb6fe2c..8f184c644a 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -63,6 +63,7 @@ enum interp_mode { #define SP_NEW_TEXTURE 0x800 #define SP_NEW_STENCIL 0x1000 #define SP_NEW_VERTEX 0x2000 +#define SP_NEW_VS 0x4000 struct softpipe_context { @@ -79,7 +80,8 @@ struct softpipe_context { struct pipe_clip_state clip; struct pipe_depth_state depth_test; struct pipe_framebuffer_state framebuffer; - struct pipe_fs_state fs; + struct pipe_shader_state fs; + struct pipe_shader_state vs; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index d754acaa38..f25a20a5e3 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -56,7 +56,10 @@ void softpipe_set_depth_test_state( struct pipe_context *, const struct pipe_depth_state * ); void softpipe_set_fs_state( struct pipe_context *, - const struct pipe_fs_state * ); + const struct pipe_shader_state * ); + +void softpipe_set_vs_state( struct pipe_context *, + const struct pipe_shader_state * ); void softpipe_set_polygon_stipple( struct pipe_context *, const struct pipe_poly_stipple * ); diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c index c7ef1f1cfc..3505c2f1fb 100644 --- a/src/mesa/pipe/softpipe/sp_state_fs.c +++ b/src/mesa/pipe/softpipe/sp_state_fs.c @@ -31,7 +31,7 @@ void softpipe_set_fs_state( struct pipe_context *pipe, - const struct pipe_fs_state *fs ) + const struct pipe_shader_state *fs ) { struct softpipe_context *softpipe = softpipe_context(pipe); @@ -41,10 +41,12 @@ void softpipe_set_fs_state( struct pipe_context *pipe, } +void softpipe_set_vs_state( struct pipe_context *pipe, + const struct pipe_shader_state *vs ) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + memcpy(&softpipe->vs, vs, sizeof(*vs)); - - - - - + softpipe->dirty |= SP_NEW_VS; +} diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index 58875de3f9..9731ab6cee 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -39,6 +39,11 @@ #define TGSI_DEBUG 0 + +/** + ** Fragment programs + **/ + static void compile_fs( struct st_context *st, struct st_fragment_program *fs ) { @@ -53,7 +58,7 @@ static void compile_fs( struct st_context *st, static void update_fs( struct st_context *st ) { - struct pipe_fs_state fs; + struct pipe_shader_state fs; struct st_fragment_program *fp = NULL; struct gl_program_parameter_list *params = NULL; @@ -103,3 +108,79 @@ const struct st_tracked_state st_update_fs = { }, .update = update_fs }; + + + +/** + ** Vertex programs + **/ + + +static void compile_vs( struct st_context *st, + struct st_vertex_program *vs ) +{ + /* XXX: fix static allocation of tokens: + */ + tgsi_mesa_compile_vp_program( &vs->Base, vs->tokens, ST_FP_MAX_TOKENS ); + + if (TGSI_DEBUG) + tgsi_dump( vs->tokens, TGSI_DUMP_VERBOSE ); +} + + +static void update_vs( struct st_context *st ) +{ + struct pipe_shader_state vs; + struct st_vertex_program *vp = NULL; + struct gl_program_parameter_list *params = NULL; + + if (st->ctx->Shader.CurrentProgram && + st->ctx->Shader.CurrentProgram->LinkStatus && + st->ctx->Shader.CurrentProgram->VertexProgram) { + struct gl_vertex_program *f + = st->ctx->Shader.CurrentProgram->VertexProgram; + vp = st_vertex_program(f); + params = f->Base.Parameters; + } + else if (st->ctx->VertexProgram._Current) { + vp = st_vertex_program(st->ctx->VertexProgram._Current); + params = st->ctx->VertexProgram._Current->Base.Parameters; + } + + /* XXXX temp */ + if (!vp) + return; + + if (vp && params) { + /* load program's constants array */ + vp->constants.nr_constants = params->NumParameters; + memcpy(vp->constants.constant, + params->ParameterValues, + params->NumParameters * sizeof(GLfloat) * 4); + } + + if (vp->dirty) + compile_vs( st, vp ); + + memset( &vs, 0, sizeof(vs) ); + vs.inputs_read = vp->Base.Base.InputsRead; + vs.tokens = &vp->tokens[0]; + vs.constants = &vp->constants; + + if (memcmp(&vs, &st->state.vs, sizeof(vs)) != 0 || + vp->dirty) + { + vp->dirty = 0; + st->state.vs = vs; + st->pipe->set_vs_state(st->pipe, &vs); + } +} + + +const struct st_tracked_state st_update_vs = { + .dirty = { + .mesa = _NEW_PROGRAM, + .st = ST_NEW_VERTEX_PROGRAM, + }, + .update = update_vs +}; diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 2f7ade73e4..3777c53d48 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -278,7 +278,7 @@ clear_with_quad(GLcontext *ctx, /* fragment shader state: color pass-through program */ { static struct st_fragment_program *stfp = NULL; - struct pipe_fs_state fs; + struct pipe_shader_state fs; if (!stfp) { stfp = make_color_shader(st); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index dd27760a58..11261f1d99 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -272,7 +272,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* fragment shader state: color pass-through program */ { static struct st_fragment_program *stfp = NULL; - struct pipe_fs_state fs; + struct pipe_shader_state fs; if (!stfp) { stfp = make_drawpixels_shader(ctx->st); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 13843d9b7f..25ed20a5f8 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -73,7 +73,8 @@ struct st_context struct pipe_clip_state clip; struct pipe_depth_state depth; struct pipe_framebuffer_state framebuffer; - struct pipe_fs_state fs; + struct pipe_shader_state fs; + struct pipe_shader_state vs; struct pipe_poly_stipple poly_stipple; struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; struct pipe_scissor_state scissor; diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 8dcb2ceb48..b077fdf069 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -83,7 +83,9 @@ struct st_vertex_program * ProgramStringNotify changes. */ + struct tgsi_token tokens[ST_FP_MAX_TOKENS]; GLboolean dirty; + struct pipe_constant_buffer constants; GLuint param_state; }; -- cgit v1.2.3 From 78d6d5e8fe7281f67b7ce8d9911e4f280435b1f5 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 16 Aug 2007 17:32:24 -0600 Subject: make pass-through vertex shader --- src/mesa/state_tracker/st_cb_clear.c | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 3777c53d48..492073e840 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -151,9 +151,63 @@ make_color_shader(struct st_context *st) } +/** + * Create a simple vertex shader that just passes through the + * vertex position and color. + */ +static struct st_vertex_program * +make_vertex_shader(struct st_context *st) +{ + GLcontext *ctx = st->ctx; + struct st_vertex_program *stvp; + struct gl_program *p; + GLboolean b; + + p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); + if (!p) + return NULL; + + p->NumInstructions = 3; + p->Instructions = _mesa_alloc_instructions(3); + if (!p->Instructions) { + ctx->Driver.DeleteProgram(ctx, p); + return NULL; + } + _mesa_init_instructions(p->Instructions, 3); + /* MOV result.pos, vertex.pos; */ + p->Instructions[0].Opcode = OPCODE_MOV; + p->Instructions[0].DstReg.File = PROGRAM_OUTPUT; + p->Instructions[0].DstReg.Index = VERT_RESULT_HPOS; + p->Instructions[0].SrcReg[0].File = PROGRAM_INPUT; + p->Instructions[0].SrcReg[0].Index = VERT_ATTRIB_POS; + /* MOV result.color, vertex.color; */ + p->Instructions[1].Opcode = OPCODE_MOV; + p->Instructions[1].DstReg.File = PROGRAM_OUTPUT; + p->Instructions[1].DstReg.Index = VERT_RESULT_COL0; + p->Instructions[1].SrcReg[0].File = PROGRAM_INPUT; + p->Instructions[1].SrcReg[0].Index = VERT_ATTRIB_COLOR0; + /* END; */ + p->Instructions[2].Opcode = OPCODE_END; + + p->InputsRead = VERT_BIT_POS | VERT_BIT_COLOR0; + p->OutputsWritten = ((1 << VERT_RESULT_COL0) | + (1 << VERT_RESULT_HPOS)); + + stvp = (struct st_vertex_program *) p; + /* compile into tgsi format */ + b = tgsi_mesa_compile_vp_program(&stvp->Base, + stvp->tokens, ST_FP_MAX_TOKENS); + assert(b); + + return stvp; +} + + + /** * Draw a screen-aligned quadrilateral. * Coords are window coords. + * XXX need to emit clip coords when using a vertex program! */ static void draw_quad(GLcontext *ctx, -- cgit v1.2.3 From 04f2078860d0649b016e9281f86725cb42e15b42 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 17 Aug 2007 10:27:37 +0100 Subject: added assertions, disable debug output --- src/mesa/state_tracker/st_cb_clear.c | 2 ++ src/mesa/state_tracker/st_cb_fbo.c | 5 +++++ 2 files changed, 7 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 492073e840..d584f0cafc 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -409,6 +409,8 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *strb = st_renderbuffer(rb); + assert(strb->surface->format); + if (!ctx->Scissor.Enabled && !is_depth_stencil_format(strb->surface->format)) { /* clear whole depth buffer w/out masking */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 7336327330..2b9aa3e9d2 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -104,6 +104,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, return GL_FALSE; /* out of memory, try s/w buffer? */ ASSERT(strb->surface->region->buffer); + ASSERT(strb->surface->format); strb->Base.Width = strb->surface->width = width; strb->Base.Height = strb->surface->height = height; @@ -319,8 +320,10 @@ st_render_texture(GLcontext *ctx, att->Zoffset); assert(strb->surface); + /* printf("RENDER TO TEXTURE obj=%p mt=%p surf=%p %d x %d\n", att->Texture, mt, strb->surface, rb->Width, rb->Height); + */ /* Invalidate buffer state so that the pipe's framebuffer state * gets updated. @@ -344,7 +347,9 @@ st_finish_render_texture(GLcontext *ctx, ctx->st->pipe->flush(ctx->st->pipe, 0x0); + /* printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); + */ pipe_surface_unreference(&strb->surface); -- cgit v1.2.3 From 5b59e6116db5241dc9a08b98e5eb8f0c770c05ea Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 17 Aug 2007 10:49:36 +0100 Subject: Use simple st->pipe->clear() in more cases for depth/stencil clears. --- src/mesa/state_tracker/st_cb_clear.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index d584f0cafc..f6c65ff466 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -408,18 +408,19 @@ static void clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *strb = st_renderbuffer(rb); + const GLboolean isDS = is_depth_stencil_format(strb->surface->format); assert(strb->surface->format); - if (!ctx->Scissor.Enabled && - !is_depth_stencil_format(strb->surface->format)) { - /* clear whole depth buffer w/out masking */ - GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); - ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); + if (ctx->Scissor.Enabled || + (isDS && ctx->DrawBuffer->Visual.stencilBits > 0)) { + /* scissoring or we have a combined depth/stencil buffer */ + clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE); } else { - /* masking or scissoring or combined z/stencil buffer */ - clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE); + /* simple clear of whole buffer */ + GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } } @@ -428,18 +429,20 @@ static void clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *strb = st_renderbuffer(rb); + const GLboolean isDS = is_depth_stencil_format(strb->surface->format); const GLuint stencilMax = (1 << rb->StencilBits) - 1; GLboolean maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; - if (!maskStencil && !ctx->Scissor.Enabled && - !is_depth_stencil_format(strb->surface->format)) { - /* clear whole stencil buffer w/out masking */ - GLuint clearValue = ctx->Stencil.Clear; - ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); + if (maskStencil || + ctx->Scissor.Enabled || + (isDS && ctx->DrawBuffer->Visual.depthBits > 0)) { + /* masking or scissoring or combined depth/stencil buffer */ + clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE); } else { - /* masking or scissoring */ - clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE); + /* simple clear of whole buffer */ + GLuint clearValue = ctx->Stencil.Clear; + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } } -- cgit v1.2.3 From 51da8ee85eccf0df3721cbd863cd174382d1ddfd Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 20 Aug 2007 16:21:08 -0600 Subject: Start to remove the temporary draw_vb() and draw_vertices() code. new st_draw_vertices() utility used by glClear and glDrawPixels --- src/mesa/pipe/draw/draw_arrays.c | 7 +-- src/mesa/pipe/draw/draw_vb.c | 66 ---------------------------- src/mesa/pipe/i915simple/i915_context.c | 5 ++- src/mesa/pipe/softpipe/sp_context.c | 6 +++ src/mesa/sources | 3 +- src/mesa/state_tracker/st_cb_clear.c | 29 +++++++++++-- src/mesa/state_tracker/st_cb_drawpixels.c | 12 +++--- src/mesa/state_tracker/st_draw.c | 72 +++++++++++++++++++++++++++++++ src/mesa/state_tracker/st_draw.h | 12 ++++-- 9 files changed, 126 insertions(+), 86 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/draw/draw_arrays.c b/src/mesa/pipe/draw/draw_arrays.c index 59098fe242..fe9ec44425 100644 --- a/src/mesa/pipe/draw/draw_arrays.c +++ b/src/mesa/pipe/draw/draw_arrays.c @@ -170,11 +170,12 @@ run_vertex_program(struct draw_context *draw, unsigned attr; for (attr = 0; attr < 16; attr++) { if (draw->vertex_shader.inputs_read & (1 << attr)) { + unsigned buf = draw->vertex_element[attr].vertex_buffer_index; const void *src - = (const void *) ((const ubyte *) draw->mapped_vbuffer[attr] - + draw->vertex_buffer[attr].buffer_offset + = (const void *) ((const ubyte *) draw->mapped_vbuffer[buf] + + draw->vertex_buffer[buf].buffer_offset + draw->vertex_element[attr].src_offset - + elts[j] * draw->vertex_buffer[attr].pitch); + + elts[j] * draw->vertex_buffer[buf].pitch); float p[4]; fetch_attrib4(src, draw->vertex_element[attr].src_format, p); diff --git a/src/mesa/pipe/draw/draw_vb.c b/src/mesa/pipe/draw/draw_vb.c index 0eefb0b250..f83f8b8a0e 100644 --- a/src/mesa/pipe/draw/draw_vb.c +++ b/src/mesa/pipe/draw/draw_vb.c @@ -259,72 +259,6 @@ void draw_vb(struct draw_context *draw, #endif /*MESA*/ -/** - * XXX Temporary mechanism to draw simple vertex arrays. - * All attribs are float[4]. Arrays are interleaved, in GL-speak. - */ -void -draw_vertices(struct draw_context *draw, - unsigned mode, - unsigned numVerts, const float *vertices, - unsigned numAttrs, const unsigned attribs[]) -{ - /*unsigned first, incr;*/ - unsigned i, j; - - assert(mode <= PIPE_PRIM_POLYGON); - - draw->vs_flush = vs_flush; - - draw->vertex_size - = sizeof(struct vertex_header) + numAttrs * 4 * sizeof(float); - - - /* no element/index buffer */ - draw_set_mapped_element_buffer(draw, 0, NULL); - - /*draw_prim_info(mode, &first, &incr);*/ - draw_allocate_vertices( draw, numVerts ); - draw->pipeline.first->begin( draw->pipeline.first ); - - if (draw->prim != mode) - draw_set_prim( draw, mode ); - - /* setup attr info */ - draw->nr_attrs = numAttrs + 2; - draw->attrs[0].attrib = VF_ATTRIB_VERTEX_HEADER; - draw->attrs[0].format = EMIT_1F; - draw->attrs[1].attrib = VF_ATTRIB_CLIP_POS; - draw->attrs[1].format = EMIT_4F; - for (j = 0; j < numAttrs; j++) { - draw->vf_attr_to_slot[attribs[j]] = 2+j; - draw->attrs[2+j].attrib = attribs[j]; - draw->attrs[2+j].format = EMIT_4F; - } - - /* build vertices */ - for (i = 0; i < numVerts; i++) { - struct vertex_header *v - = (struct vertex_header *) (draw->verts + i * draw->vertex_size); - v->clipmask = 0x0; - v->edgeflag = 0; - for (j = 0; j < numAttrs; j++) { - COPY_4FV(v->data[j], vertices + (i * numAttrs + j) * 4); - } - } - - /* draw */ - draw_prim(draw, 0, numVerts); - draw_flush(draw); - draw->pipeline.first->end( draw->pipeline.first ); - - - /* clean up */ - draw_release_vertices( draw ); - draw->verts = NULL; - draw->in_vb = 0; -} - #if 000 /** diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index 8a8582e0b2..c7d469583c 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -155,7 +155,9 @@ static void i915_draw_vb( struct pipe_context *pipe, if (i915->dirty) i915_update_derived( i915 ); +#if 0 draw_vb( i915->draw, VB ); +#endif } @@ -169,8 +171,9 @@ i915_draw_vertices(struct pipe_context *pipe, if (i915->dirty) i915_update_derived( i915 ); - +#if 0 draw_vertices(i915->draw, mode, numVertex, verts, numAttribs, attribs); +#endif } diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index e7694bbe86..91ede05c05 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -195,6 +195,7 @@ static void softpipe_destroy( struct pipe_context *pipe ) } +#if 0 static void softpipe_draw_vb( struct pipe_context *pipe, struct vertex_buffer *VB ) { @@ -208,6 +209,7 @@ static void softpipe_draw_vb( struct pipe_context *pipe, draw_vb( softpipe->draw, VB ); softpipe_unmap_surfaces(softpipe); } +#endif static void @@ -223,7 +225,9 @@ softpipe_draw_vertices(struct pipe_context *pipe, /* XXX move mapping/unmapping to higher/coarser level? */ softpipe_map_surfaces(softpipe); +#if 0 draw_vertices(softpipe->draw, mode, numVertex, verts, numAttribs, attribs); +#endif softpipe_unmap_surfaces(softpipe); } @@ -285,8 +289,10 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.set_vertex_buffer = softpipe_set_vertex_buffer; softpipe->pipe.set_vertex_element = softpipe_set_vertex_element; +#if 0 softpipe->pipe.draw_vb = softpipe_draw_vb; softpipe->pipe.draw_vertices = softpipe_draw_vertices; +#endif softpipe->pipe.draw_arrays = softpipe_draw_arrays; softpipe->pipe.draw_elements = softpipe_draw_elements; diff --git a/src/mesa/sources b/src/mesa/sources index 0731e64d8a..0fe97e0287 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -164,8 +164,7 @@ DRAW_SOURCES = \ pipe/draw/draw_offset.c \ pipe/draw/draw_prim.c \ pipe/draw/draw_twoside.c \ - pipe/draw/draw_unfilled.c \ - pipe/draw/draw_vb.c + pipe/draw/draw_unfilled.c TGSICORE_SOURCES = \ pipe/tgsi/core/tgsi_build.c \ diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index f6c65ff466..bd050ca2cd 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -38,11 +38,17 @@ #include "st_context.h" #include "st_cb_clear.h" #include "st_cb_fbo.h" +#include "st_draw.h" #include "st_program.h" #include "st_public.h" + #include "pipe/p_context.h" +#include "pipe/p_state.h" #include "pipe/p_defines.h" +#include "pipe/p_winsys.h" + #include "pipe/tgsi/mesa/mesa_to_tgsi.h" + #include "vf/vf.h" @@ -215,8 +221,8 @@ draw_quad(GLcontext *ctx, const GLfloat color[4]) { static const GLuint attribs[2] = { - VF_ATTRIB_POS, - VF_ATTRIB_COLOR0 + 0, /* pos */ + 3 /* color */ }; GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */ GLuint i; @@ -244,8 +250,7 @@ draw_quad(GLcontext *ctx, verts[i][1][3] = color[3]; } - ctx->st->pipe->draw_vertices(ctx->st->pipe, PIPE_PRIM_QUADS, - 4, (GLfloat *) verts, 2, attribs); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, attribs); } @@ -343,6 +348,21 @@ clear_with_quad(GLcontext *ctx, st->pipe->set_fs_state(st->pipe, &fs); } + /* vertex shader state: color/position pass-through */ + { + static struct st_vertex_program *stvp = NULL; + struct pipe_shader_state vs; + if (!stvp) { + stvp = make_vertex_shader(st); + } + memset(&vs, 0, sizeof(vs)); + vs.inputs_read = stvp->Base.Base.InputsRead; + vs.outputs_written = stvp->Base.Base.OutputsWritten; + vs.tokens = &stvp->tokens[0]; + vs.constants = NULL; + st->pipe->set_vs_state(st->pipe, &vs); + } + /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); @@ -351,6 +371,7 @@ clear_with_quad(GLcontext *ctx, st->pipe->set_blend_state(st->pipe, &st->state.blend); st->pipe->set_depth_state(st->pipe, &st->state.depth); st->pipe->set_fs_state(st->pipe, &st->state.fs); + st->pipe->set_vs_state(st->pipe, &st->state.vs); st->pipe->set_setup_state(st->pipe, &st->state.setup); st->pipe->set_stencil_state(st->pipe, &st->state.stencil); /* OR: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 11261f1d99..1aa56fcf8b 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -38,6 +38,7 @@ #include "st_program.h" #include "st_cb_drawpixels.h" #include "st_cb_texture.h" +#include "st_draw.h" #include "st_format.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -193,12 +194,12 @@ free_mipmap_tree(struct pipe_context *pipe, struct pipe_mipmap_tree *mt) * Y=0=top */ static void -draw_quad(struct st_context *st, GLfloat x0, GLfloat y0, GLfloat z, +draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, GLfloat x1, GLfloat y1) { static const GLuint attribs[2] = { - VF_ATTRIB_POS, - VF_ATTRIB_TEX0 + 0, /* pos */ + 8 /* tex0 */ }; GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */ GLuint i; @@ -235,8 +236,7 @@ draw_quad(struct st_context *st, GLfloat x0, GLfloat y0, GLfloat z, verts[i][1][3] = 1.0; /*Q*/ } - st->pipe->draw_vertices(st->pipe, PIPE_PRIM_QUADS, - 4, (GLfloat *) verts, 2, attribs); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (GLfloat *) verts, 2, attribs); } @@ -310,7 +310,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, y1 = ctx->DrawBuffer->Height - 1 - (y + height * ctx->Pixel.ZoomY); /* draw textured quad */ - draw_quad(ctx->st, x0, y0, z, x1, y1); + draw_quad(ctx, x0, y0, z, x1, y1); /* restore GL state */ pipe->set_setup_state(pipe, &ctx->st->state.setup); diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index e82f7cff2b..a409dd9764 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -66,7 +66,9 @@ static GLboolean draw( GLcontext * ctx, struct tnl_pipeline_stage *stage ) { struct st_context *st = st_context(ctx); +#if 0 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; +#endif /* Validate driver and pipe state: */ @@ -74,7 +76,9 @@ static GLboolean draw( GLcontext * ctx, struct tnl_pipeline_stage *stage ) /* Call into the new draw code to handle the VB: */ +#if 0 st->pipe->draw_vb( st->pipe, VB ); +#endif /* Finished */ @@ -289,6 +293,72 @@ draw_vbo(GLcontext *ctx, +/** + * Utility function for drawing simple primitives (such as quads for + * glClear and glDrawPixels). Coordinates are in screen space. + * \param mode one of PIPE_PRIM_x + * \param numVertex number of vertices + * \param verts vertex data (all attributes are float[4]) + * \param numAttribs number of attributes per vertex + * \param attribs index of each attribute (0=pos, 3=color, etc) + */ +void +st_draw_vertices(GLcontext *ctx, unsigned prim, + unsigned numVertex, float *verts, + unsigned numAttribs, const unsigned attribs[]) +{ + const float width = ctx->DrawBuffer->Width; + const float height = ctx->DrawBuffer->Height; + const unsigned vertex_bytes = numVertex * numAttribs * 4 * sizeof(float); + struct pipe_context *pipe = ctx->st->pipe; + struct pipe_buffer_handle *vbuf; + struct pipe_vertex_buffer vbuffer; + struct pipe_vertex_element velement; + unsigned i; + + assert(numAttribs > 0); + assert(attribs[0] == 0); /* position */ + + /* convert to clip coords */ + for (i = 0; i < numVertex; i++) { + float x = verts[i * numAttribs * 4 + 0]; + float y = verts[i * numAttribs * 4 + 1]; + x = x / width * 2.0 - 1.0; + y = y / height * 2.0 - 1.0; + verts[i * numAttribs * 4 + 0] = x; + verts[i * numAttribs * 4 + 1] = y; + } + + /* XXX create one-time */ + vbuf = pipe->winsys->buffer_create(pipe->winsys, 32); + pipe->winsys->buffer_data(pipe->winsys, vbuf, vertex_bytes, verts); + + /* tell pipe about the vertex buffer */ + vbuffer.buffer = vbuf; + vbuffer.pitch = numAttribs * 4 * sizeof(float); /* vertex size */ + vbuffer.buffer_offset = 0; + pipe->set_vertex_buffer(pipe, 0, &vbuffer); + + /* tell pipe about the vertex attributes */ + for (i = 0; i < numAttribs; i++) { + velement.src_offset = i * 4 * sizeof(GLfloat); + velement.vertex_buffer_index = 0; + velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + velement.dst_offset = 0; + pipe->set_vertex_element(pipe, attribs[i], &velement); + } + + /* draw */ + pipe->draw_arrays(pipe, prim, 0, numVertex); + + /* XXX: do one-time */ + pipe->winsys->buffer_unreference(pipe->winsys, &vbuf); +} + + + + + /* This is all a hack to keep using tnl until we have vertex programs * up and running. @@ -307,8 +377,10 @@ void st_init_draw( struct st_context *st ) vbo->draw_prims = draw_vbo; #endif +#if 0 _tnl_destroy_pipeline( ctx ); _tnl_install_pipeline( ctx, st_pipeline ); +#endif /* USE_NEW_DRAW */ _tnl_ProgramCacheInit( ctx ); diff --git a/src/mesa/state_tracker/st_draw.h b/src/mesa/state_tracker/st_draw.h index 0afadab577..0005fbc51f 100644 --- a/src/mesa/state_tracker/st_draw.h +++ b/src/mesa/state_tracker/st_draw.h @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2004 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -34,11 +34,15 @@ #ifndef ST_DRAW_H #define ST_DRAW_H + void st_init_draw( struct st_context *st ); + void st_destroy_draw( struct st_context *st ); -/** XXX temporary here */ -void st_clear(struct st_context *st, GLboolean color, GLboolean depth, - GLboolean stencil); +void +st_draw_vertices(GLcontext *ctx, unsigned prim, + unsigned numVertex, float *verts, + unsigned numAttribs, const unsigned attribs[]); + #endif -- cgit v1.2.3 From d054331c4788b0a5f13f4d7a9b497d274d267acb Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 20 Aug 2007 18:24:02 -0600 Subject: Update glClear and glDrawPixels code. Since they're implemented by drawing quadrilaterals (and go through vertex transformation and viewport mapping) we don't have to invert Y coords. --- src/mesa/pipe/draw/draw_arrays.c | 5 +- src/mesa/state_tracker/st_cb_clear.c | 13 +++-- src/mesa/state_tracker/st_cb_drawpixels.c | 94 +++++++++++++++++++++++++++---- 3 files changed, 95 insertions(+), 17 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/draw/draw_arrays.c b/src/mesa/pipe/draw/draw_arrays.c index 17ed255f85..34a031ddf0 100644 --- a/src/mesa/pipe/draw/draw_arrays.c +++ b/src/mesa/pipe/draw/draw_arrays.c @@ -248,10 +248,11 @@ run_vertex_program(struct draw_context *draw, vOut[j]->data[0][2] = z * scale[2] + trans[2]; vOut[j]->data[0][3] = w; #if 0 - printf("wincoord: %f %f %f\n", + printf("wincoord: %f %f %f %f\n", vOut[j]->data[0][0], vOut[j]->data[0][1], - vOut[j]->data[0][2]); + vOut[j]->data[0][2], + vOut[j]->data[0][3]); #endif /* remaining attributes: */ diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index bd050ca2cd..1ed48facd1 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -212,8 +212,8 @@ make_vertex_shader(struct st_context *st) /** * Draw a screen-aligned quadrilateral. - * Coords are window coords. - * XXX need to emit clip coords when using a vertex program! + * Coords are window coords with y=0=bottom. These coords will be transformed + * by the vertex shader and viewport transform (which will flip Y if needed). */ static void draw_quad(GLcontext *ctx, @@ -266,9 +266,9 @@ clear_with_quad(GLcontext *ctx, { struct st_context *st = ctx->st; const GLfloat x0 = ctx->DrawBuffer->_Xmin; - const GLfloat y0 = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymax; + const GLfloat y0 = ctx->DrawBuffer->_Ymin; const GLfloat x1 = ctx->DrawBuffer->_Xmax; - const GLfloat y1 = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymin; + const GLfloat y1 = ctx->DrawBuffer->_Ymax; /* alpha state: disabled */ { @@ -312,8 +312,13 @@ clear_with_quad(GLcontext *ctx, { struct pipe_setup_state setup; memset(&setup, 0, sizeof(setup)); +#if 0 + /* don't do per-pixel scissor; we'll just draw a PIPE_PRIM_QUAD + * that matches the scissor bounds. + */ if (ctx->Scissor.Enabled) setup.scissor = 1; +#endif st->pipe->set_setup_state(st->pipe, &setup); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 1aa56fcf8b..108304f5e2 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -49,11 +49,11 @@ /** - * Create a simple fragment shader that passes the texture color through - * to the fragment color. + * Create a simple fragment shader that does a TEX() instruction to get + * the fragment color. */ static struct st_fragment_program * -make_drawpixels_shader(struct st_context *st) +make_fragment_shader(struct st_context *st) { GLcontext *ctx = st->ctx; struct st_fragment_program *stfp; @@ -95,6 +95,59 @@ make_drawpixels_shader(struct st_context *st) } +/** + * Create a simple vertex shader that just passes through the + * vertex position and color. + */ +static struct st_vertex_program * +make_vertex_shader(struct st_context *st) +{ + GLcontext *ctx = st->ctx; + struct st_vertex_program *stvp; + struct gl_program *p; + GLboolean b; + + p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); + if (!p) + return NULL; + + p->NumInstructions = 3; + p->Instructions = _mesa_alloc_instructions(3); + if (!p->Instructions) { + ctx->Driver.DeleteProgram(ctx, p); + return NULL; + } + _mesa_init_instructions(p->Instructions, 3); + /* MOV result.pos, vertex.pos; */ + p->Instructions[0].Opcode = OPCODE_MOV; + p->Instructions[0].DstReg.File = PROGRAM_OUTPUT; + p->Instructions[0].DstReg.Index = VERT_RESULT_HPOS; + p->Instructions[0].SrcReg[0].File = PROGRAM_INPUT; + p->Instructions[0].SrcReg[0].Index = VERT_ATTRIB_POS; + /* MOV result.color, vertex.color; */ + p->Instructions[1].Opcode = OPCODE_MOV; + p->Instructions[1].DstReg.File = PROGRAM_OUTPUT; + p->Instructions[1].DstReg.Index = VERT_RESULT_TEX0; + p->Instructions[1].SrcReg[0].File = PROGRAM_INPUT; + p->Instructions[1].SrcReg[0].Index = VERT_ATTRIB_TEX0; + /* END; */ + p->Instructions[2].Opcode = OPCODE_END; + + p->InputsRead = VERT_BIT_POS | VERT_BIT_TEX0; + p->OutputsWritten = ((1 << VERT_RESULT_TEX0) | + (1 << VERT_RESULT_HPOS)); + + stvp = (struct st_vertex_program *) p; + /* compile into tgsi format */ + b = tgsi_mesa_compile_vp_program(&stvp->Base, + stvp->tokens, ST_FP_MAX_TOKENS); + assert(b); + + return stvp; +} + + + static struct pipe_mipmap_tree * make_mipmap_tree(struct st_context *st, GLsizei width, GLsizei height, GLenum format, GLenum type, @@ -156,7 +209,7 @@ make_mipmap_tree(struct st_context *st, assert(success); } - mt->target = GL_TEXTURE_2D; + mt->target = PIPE_TEXTURE_2D; mt->internal_format = GL_RGBA; mt->format = pipeFormat; mt->first_level = 0; @@ -191,7 +244,7 @@ free_mipmap_tree(struct pipe_context *pipe, struct pipe_mipmap_tree *mt) /** * Draw textured quad. - * Y=0=top + * Coords are window coords with y=0=bottom. */ static void draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, @@ -236,7 +289,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, verts[i][1][3] = 1.0; /*Q*/ } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (GLfloat *) verts, 2, attribs); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, attribs); } @@ -269,12 +322,12 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->set_setup_state(pipe, &setup); } - /* fragment shader state: color pass-through program */ + /* fragment shader state: TEX lookup program */ { static struct st_fragment_program *stfp = NULL; struct pipe_shader_state fs; if (!stfp) { - stfp = make_drawpixels_shader(ctx->st); + stfp = make_fragment_shader(ctx->st); } memset(&fs, 0, sizeof(fs)); fs.inputs_read = stfp->Base.Base.InputsRead; @@ -283,6 +336,21 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->set_fs_state(pipe, &fs); } + /* vertex shader state: position + texcoord pass-through */ + { + static struct st_vertex_program *stvp = NULL; + struct pipe_shader_state vs; + if (!stvp) { + stvp = make_vertex_shader(ctx->st); + } + memset(&vs, 0, sizeof(vs)); + vs.inputs_read = stvp->Base.Base.InputsRead; + vs.outputs_written = stvp->Base.Base.OutputsWritten; + vs.tokens = &stvp->tokens[0]; + vs.constants = NULL; + pipe->set_vs_state(pipe, &vs); + } + /* texture sampling state: */ { struct pipe_sampler_state sampler; @@ -303,11 +371,14 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->set_texture_state(pipe, unit, mt); } - /* compute window coords (y=0=top) with pixel zoom */ + /* Compute window coords (y=0=bottom) with pixel zoom. + * Recall that these coords are transformed by the current + * vertex shader and viewport transformation. + */ x0 = x; - y0 = ctx->DrawBuffer->Height - 1 - y; x1 = x + width * ctx->Pixel.ZoomX; - y1 = ctx->DrawBuffer->Height - 1 - (y + height * ctx->Pixel.ZoomY); + y0 = y; + y1 = y + height * ctx->Pixel.ZoomY; /* draw textured quad */ draw_quad(ctx, x0, y0, z, x1, y1); @@ -315,6 +386,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* restore GL state */ pipe->set_setup_state(pipe, &ctx->st->state.setup); pipe->set_fs_state(pipe, &ctx->st->state.fs); + pipe->set_vs_state(pipe, &ctx->st->state.vs); pipe->set_texture_state(pipe, unit, ctx->st->state.texture[unit]); pipe->set_sampler_state(pipe, unit, &ctx->st->state.sampler[unit]); -- cgit v1.2.3 From d640198b2d52c104c707522e79d53a36f708ccd0 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 20 Aug 2007 21:45:14 +0100 Subject: Set viewport state so viewport matches window dims. trivial/readpixels.c works again. --- src/mesa/state_tracker/st_cb_clear.c | 46 +++++++++++++++++++++---------- src/mesa/state_tracker/st_cb_drawpixels.c | 17 ++++++++++++ 2 files changed, 49 insertions(+), 14 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 1ed48facd1..2f2d11c014 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -265,6 +265,7 @@ clear_with_quad(GLcontext *ctx, GLboolean color, GLboolean depth, GLboolean stencil) { struct st_context *st = ctx->st; + struct pipe_context *pipe = ctx->st->pipe; const GLfloat x0 = ctx->DrawBuffer->_Xmin; const GLfloat y0 = ctx->DrawBuffer->_Ymin; const GLfloat x1 = ctx->DrawBuffer->_Xmax; @@ -274,7 +275,7 @@ clear_with_quad(GLcontext *ctx, { struct pipe_alpha_test_state alpha_test; memset(&alpha_test, 0, sizeof(alpha_test)); - st->pipe->set_alpha_test_state(st->pipe, &alpha_test); + pipe->set_alpha_test_state(pipe, &alpha_test); } /* blend state: RGBA masking */ @@ -293,7 +294,7 @@ clear_with_quad(GLcontext *ctx, if (st->ctx->Color.DitherFlag) blend.dither = 1; } - st->pipe->set_blend_state(st->pipe, &blend); + pipe->set_blend_state(pipe, &blend); } /* depth state: always pass */ @@ -305,7 +306,7 @@ clear_with_quad(GLcontext *ctx, depth_test.writemask = 1; depth_test.func = PIPE_FUNC_ALWAYS; } - st->pipe->set_depth_state(st->pipe, &depth_test); + pipe->set_depth_state(pipe, &depth_test); } /* setup state: nothing */ @@ -319,7 +320,7 @@ clear_with_quad(GLcontext *ctx, if (ctx->Scissor.Enabled) setup.scissor = 1; #endif - st->pipe->set_setup_state(st->pipe, &setup); + pipe->set_setup_state(pipe, &setup); } /* stencil state: always set to ref value */ @@ -336,7 +337,7 @@ clear_with_quad(GLcontext *ctx, stencil_test.value_mask[0] = 0xff; stencil_test.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; } - st->pipe->set_stencil_state(st->pipe, &stencil_test); + pipe->set_stencil_state(pipe, &stencil_test); } /* fragment shader state: color pass-through program */ @@ -350,7 +351,7 @@ clear_with_quad(GLcontext *ctx, fs.inputs_read = stfp->Base.Base.InputsRead; fs.tokens = &stfp->tokens[0]; fs.constants = NULL; - st->pipe->set_fs_state(st->pipe, &fs); + pipe->set_fs_state(pipe, &fs); } /* vertex shader state: color/position pass-through */ @@ -365,20 +366,37 @@ clear_with_quad(GLcontext *ctx, vs.outputs_written = stvp->Base.Base.OutputsWritten; vs.tokens = &stvp->tokens[0]; vs.constants = NULL; - st->pipe->set_vs_state(st->pipe, &vs); + pipe->set_vs_state(pipe, &vs); + } + + /* viewport state: viewport matching window dims */ + { + const float width = ctx->DrawBuffer->Width; + const float height = ctx->DrawBuffer->Height; + struct pipe_viewport_state vp; + vp.scale[0] = 0.5 * width; + vp.scale[1] = -0.5 * height; + vp.scale[2] = 0.5; + vp.scale[3] = 1.0; + vp.translate[0] = 0.5 * width; + vp.translate[1] = 0.5 * height; + vp.translate[2] = 0.5; + vp.translate[3] = 0.0; + pipe->set_viewport_state(pipe, &vp); } /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); /* Restore pipe state */ - st->pipe->set_alpha_test_state(st->pipe, &st->state.alpha_test); - st->pipe->set_blend_state(st->pipe, &st->state.blend); - st->pipe->set_depth_state(st->pipe, &st->state.depth); - st->pipe->set_fs_state(st->pipe, &st->state.fs); - st->pipe->set_vs_state(st->pipe, &st->state.vs); - st->pipe->set_setup_state(st->pipe, &st->state.setup); - st->pipe->set_stencil_state(st->pipe, &st->state.stencil); + pipe->set_alpha_test_state(pipe, &st->state.alpha_test); + pipe->set_blend_state(pipe, &st->state.blend); + pipe->set_depth_state(pipe, &st->state.depth); + pipe->set_fs_state(pipe, &st->state.fs); + pipe->set_vs_state(pipe, &st->state.vs); + pipe->set_setup_state(pipe, &st->state.setup); + pipe->set_stencil_state(pipe, &st->state.stencil); + pipe->set_viewport_state(pipe, &ctx->st->state.viewport); /* OR: st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); */ diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 108304f5e2..d3f060e691 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -364,6 +364,22 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->set_sampler_state(pipe, unit, &sampler); } + /* viewport state: viewport matching window dims */ + { + const float width = ctx->DrawBuffer->Width; + const float height = ctx->DrawBuffer->Height; + struct pipe_viewport_state vp; + vp.scale[0] = 0.5 * width; + vp.scale[1] = -0.5 * height; + vp.scale[2] = 0.5; + vp.scale[3] = 1.0; + vp.translate[0] = 0.5 * width; + vp.translate[1] = 0.5 * height; + vp.translate[2] = 0.5; + vp.translate[3] = 0.0; + pipe->set_viewport_state(pipe, &vp); + } + /* mipmap tree state: */ { mt = make_mipmap_tree(ctx->st, width, height, format, type, @@ -389,6 +405,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->set_vs_state(pipe, &ctx->st->state.vs); pipe->set_texture_state(pipe, unit, ctx->st->state.texture[unit]); pipe->set_sampler_state(pipe, unit, &ctx->st->state.sampler[unit]); + pipe->set_viewport_state(pipe, &ctx->st->state.viewport); free_mipmap_tree(pipe, mt); } -- cgit v1.2.3 From c0bb4ba9e665e40a325d82aa2ee48d7b8abd603b Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 22 Aug 2007 12:24:51 -0600 Subject: Rework of shader constant buffers. They're now totally independent of the actual shaders. Also, implemented in terms of pipe_buffer_handles/objects. --- src/mesa/pipe/draw/draw_context.h | 2 + src/mesa/pipe/draw/draw_prim.c | 9 ++- src/mesa/pipe/draw/draw_private.h | 2 + src/mesa/pipe/i915simple/i915_context.c | 3 + src/mesa/pipe/i915simple/i915_context.h | 16 ++++-- src/mesa/pipe/i915simple/i915_fpc.h | 8 +-- src/mesa/pipe/i915simple/i915_fpc_emit.c | 81 +++++++-------------------- src/mesa/pipe/i915simple/i915_fpc_translate.c | 20 ++++--- src/mesa/pipe/i915simple/i915_state.c | 40 +++++++++++++ src/mesa/pipe/i915simple/i915_state_emit.c | 6 +- src/mesa/pipe/p_context.h | 6 +- src/mesa/pipe/p_defines.h | 8 +++ src/mesa/pipe/p_state.h | 8 ++- src/mesa/pipe/softpipe/sp_context.c | 1 + src/mesa/pipe/softpipe/sp_context.h | 7 ++- src/mesa/pipe/softpipe/sp_draw_arrays.c | 31 ++++++++++ src/mesa/pipe/softpipe/sp_quad_fs.c | 3 +- src/mesa/pipe/softpipe/sp_state.h | 4 ++ src/mesa/pipe/softpipe/sp_state_fs.c | 25 ++++++++- src/mesa/state_tracker/st_atom_fs.c | 38 ++++++++++--- src/mesa/state_tracker/st_atom_vs.c | 49 +++++++++------- src/mesa/state_tracker/st_cb_clear.c | 2 - src/mesa/state_tracker/st_cb_drawpixels.c | 2 - src/mesa/state_tracker/st_context.h | 7 ++- src/mesa/state_tracker/st_program.h | 4 +- 25 files changed, 257 insertions(+), 125 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/draw/draw_context.h b/src/mesa/pipe/draw/draw_context.h index 2fce1322c5..893db1e0c6 100644 --- a/src/mesa/pipe/draw/draw_context.h +++ b/src/mesa/pipe/draw/draw_context.h @@ -103,6 +103,8 @@ void draw_set_mapped_element_buffer( struct draw_context *draw, void draw_set_mapped_vertex_buffer(struct draw_context *draw, unsigned attr, const void *buffer); +void draw_set_mapped_constant_buffer(struct draw_context *draw, + const void *buffer); void draw_set_vertex_buffer(struct draw_context *draw, diff --git a/src/mesa/pipe/draw/draw_prim.c b/src/mesa/pipe/draw/draw_prim.c index 97484d5fb9..94cedb02a9 100644 --- a/src/mesa/pipe/draw/draw_prim.c +++ b/src/mesa/pipe/draw/draw_prim.c @@ -165,7 +165,7 @@ run_vertex_program(struct draw_context *draw, NULL /*samplers*/ ); /* Consts does not require 16 byte alignment. */ - machine.Consts = draw->vertex_shader.constants->constant; + machine.Consts = (float (*)[4]) draw->mapped_constants; machine.Inputs = ALIGN16_ASSIGN(inputs); machine.Outputs = ALIGN16_ASSIGN(outputs); @@ -742,6 +742,13 @@ void draw_set_mapped_vertex_buffer(struct draw_context *draw, } +void draw_set_mapped_constant_buffer(struct draw_context *draw, + const void *buffer) +{ + draw->mapped_constants = buffer; +} + + unsigned draw_prim_info(unsigned prim, unsigned *first, unsigned *incr) { diff --git a/src/mesa/pipe/draw/draw_private.h b/src/mesa/pipe/draw/draw_private.h index 85feb14688..75f7c5d84e 100644 --- a/src/mesa/pipe/draw/draw_private.h +++ b/src/mesa/pipe/draw/draw_private.h @@ -167,6 +167,8 @@ struct draw_context unsigned eltSize; /**< bytes per index (0, 1, 2 or 4) */ /** The mapped vertex arrays */ const void *mapped_vbuffer[PIPE_ATTRIB_MAX]; + /** The mapped constant buffers (for vertex shader) */ + const void *mapped_constants; /* Clip derived state: */ diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index 9856c7c10c..f4121419f7 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -186,6 +186,9 @@ static boolean i915_draw_elements( struct pipe_context *pipe, draw_set_mapped_element_buffer(draw, 0, NULL); } + draw_set_mapped_constant_buffer(draw, + i915->current.constants[PIPE_SHADER_VERTEX]); + /* draw! */ draw_arrays(i915->draw, prim, start, count); diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index b40dfa695b..a037b20289 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -30,10 +30,10 @@ #include "pipe/p_context.h" +#include "pipe/p_defines.h" #include "pipe/p_state.h" - #define I915_TEX_UNITS 8 #define I915_DYNAMIC_MODES4 0 @@ -74,6 +74,7 @@ #define I915_CACHE_CONSTANTS 5 #define I915_MAX_CACHE 6 +#define I915_MAX_CONSTANT 32 struct i915_cache_context; @@ -85,10 +86,14 @@ struct i915_state unsigned immediate[I915_MAX_IMMEDIATE]; unsigned dynamic[I915_MAX_DYNAMIC]; + float constants[PIPE_SHADER_TYPES][I915_MAX_CONSTANT][4]; + /** number of constants passed in through a constant buffer */ + uint num_user_constants[PIPE_SHADER_TYPES]; + /** user constants, plus extra constants from shader translation */ + uint num_constants[PIPE_SHADER_TYPES]; + uint *program; uint program_len; - uint *constants; - uint num_constants; unsigned sampler[I915_TEX_UNITS][3]; unsigned sampler_enable_flags; @@ -112,6 +117,7 @@ struct i915_context struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; + struct pipe_constant_buffer constants[PIPE_SHADER_TYPES]; struct pipe_depth_state depth_test; struct pipe_framebuffer_state framebuffer; struct pipe_shader_state fs; @@ -124,8 +130,6 @@ struct i915_context struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; - struct pipe_constant_buffer temp_constants; /*XXX temporary*/ - unsigned dirty; unsigned *batch_start; @@ -156,6 +160,8 @@ struct i915_context #define I915_NEW_SAMPLER 0x400 #define I915_NEW_TEXTURE 0x800 #define I915_NEW_STENCIL 0x1000 +#define I915_NEW_CONSTANTS 0x2000 + /* Driver's internally generated state flags: */ diff --git a/src/mesa/pipe/i915simple/i915_fpc.h b/src/mesa/pipe/i915simple/i915_fpc.h index 30bc290ad8..afef706418 100644 --- a/src/mesa/pipe/i915simple/i915_fpc.h +++ b/src/mesa/pipe/i915simple/i915_fpc.h @@ -37,7 +37,6 @@ #define I915_PROGRAM_SIZE 192 -#define I915_MAX_CONSTANT 32 #define MAX_VARYING 8 @@ -99,9 +98,10 @@ struct i915_fp_compile { uint declarations[I915_PROGRAM_SIZE]; uint program[I915_PROGRAM_SIZE]; - uint constant_flags[I915_MAX_CONSTANT]; - - struct pipe_constant_buffer *constants; + /** points into the i915->current.constants array: */ + float (*constants)[4]; + uint num_constants; + uint constant_flags[I915_MAX_CONSTANT]; /**< status of each constant */ uint *csr; /* Cursor, points into program. */ diff --git a/src/mesa/pipe/i915simple/i915_fpc_emit.c b/src/mesa/pipe/i915simple/i915_fpc_emit.c index 26a4f36e71..dfbc5f180c 100644 --- a/src/mesa/pipe/i915simple/i915_fpc_emit.c +++ b/src/mesa/pipe/i915simple/i915_fpc_emit.c @@ -244,25 +244,14 @@ i915_emit_const1f(struct i915_fp_compile * p, float c0) if (p->constant_flags[reg] == I915_CONSTFLAG_PARAM) continue; for (idx = 0; idx < 4; idx++) { -#if 0 - if (!(p->constant_flags[reg] & (1 << idx)) || - p->fp->constant[reg][idx] == c0) { - p->fp->constant[reg][idx] = c0; - p->constant_flags[reg] |= 1 << idx; - if (reg + 1 > p->fp->nr_constants) - p->fp->nr_constants = reg + 1; - return swizzle(UREG(REG_TYPE_CONST, reg), idx, ZERO, ZERO, ONE); - } -#else if (!(p->constant_flags[reg] & (1 << idx)) || - p->constants->constant[reg][idx] == c0) { - p->constants->constant[reg][idx] = c0; + p->constants[reg][idx] == c0) { + p->constants[reg][idx] = c0; p->constant_flags[reg] |= 1 << idx; - if (reg + 1 > p->constants->nr_constants) - p->constants->nr_constants = reg + 1; + if (reg + 1 > p->num_constants) + p->num_constants = reg + 1; return swizzle(UREG(REG_TYPE_CONST, reg), idx, ZERO, ZERO, ONE); } -#endif } } @@ -291,23 +280,12 @@ i915_emit_const2f(struct i915_fp_compile * p, float c0, float c1) continue; for (idx = 0; idx < 3; idx++) { if (!(p->constant_flags[reg] & (3 << idx))) { -#if 0 - p->fp->constant[reg][idx] = c0; - p->fp->constant[reg][idx + 1] = c1; + p->constants[reg][idx + 0] = c0; + p->constants[reg][idx + 1] = c1; p->constant_flags[reg] |= 3 << idx; - if (reg + 1 > p->fp->nr_constants) - p->fp->nr_constants = reg + 1; - return swizzle(UREG(REG_TYPE_CONST, reg), idx, idx + 1, ZERO, - ONE); -#else - p->constants->constant[reg][idx + 0] = c0; - p->constants->constant[reg][idx + 1] = c1; - p->constant_flags[reg] |= 3 << idx; - if (reg + 1 > p->constants->nr_constants) - p->constants->nr_constants = reg + 1; - return swizzle(UREG(REG_TYPE_CONST, reg), idx, idx + 1, ZERO, - ONE); -#endif + if (reg + 1 > p->num_constants) + p->num_constants = reg + 1; + return swizzle(UREG(REG_TYPE_CONST, reg), idx, idx + 1, ZERO, ONE); } } } @@ -326,40 +304,21 @@ i915_emit_const4f(struct i915_fp_compile * p, for (reg = 0; reg < I915_MAX_CONSTANT; reg++) { if (p->constant_flags[reg] == 0xf && -#if 0 - p->fp->constant[reg][0] == c0 && - p->fp->constant[reg][1] == c1 && - p->fp->constant[reg][2] == c2 && - p->fp->constant[reg][3] == c3 -#else - p->constants->constant[reg][0] == c0 && - p->constants->constant[reg][1] == c1 && - p->constants->constant[reg][2] == c2 && - p->constants->constant[reg][3] == c3 -#endif - ) { + p->constants[reg][0] == c0 && + p->constants[reg][1] == c1 && + p->constants[reg][2] == c2 && + p->constants[reg][3] == c3) { return UREG(REG_TYPE_CONST, reg); } else if (p->constant_flags[reg] == 0) { -#if 0 - p->fp->constant[reg][0] = c0; - p->fp->constant[reg][1] = c1; - p->fp->constant[reg][2] = c2; - p->fp->constant[reg][3] = c3; -#else - p->constants->constant[reg][0] = c0; - p->constants->constant[reg][1] = c1; - p->constants->constant[reg][2] = c2; - p->constants->constant[reg][3] = c3; -#endif + + p->constants[reg][0] = c0; + p->constants[reg][1] = c1; + p->constants[reg][2] = c2; + p->constants[reg][3] = c3; p->constant_flags[reg] = 0xf; -#if 0 - if (reg + 1 > p->fp->nr_constants) - p->fp->nr_constants = reg + 1; -#else - if (reg + 1 > p->constants->nr_constants) - p->constants->nr_constants = reg + 1; -#endif + if (reg + 1 > p->num_constants) + p->num_constants = reg + 1; return UREG(REG_TYPE_CONST, reg); } } diff --git a/src/mesa/pipe/i915simple/i915_fpc_translate.c b/src/mesa/pipe/i915simple/i915_fpc_translate.c index db2691ebe1..dcf0d18f4e 100644 --- a/src/mesa/pipe/i915simple/i915_fpc_translate.c +++ b/src/mesa/pipe/i915simple/i915_fpc_translate.c @@ -102,8 +102,8 @@ i915_use_passthrough_shader(struct i915_context *i915) i915->current.program_len = Elements(passthrough); } - i915->current.constants = NULL; - i915->current.num_constants = 0; + i915->current.num_constants[PIPE_SHADER_FRAGMENT] = 0; + i915->current.num_user_constants[PIPE_SHADER_FRAGMENT] = 0; } @@ -870,11 +870,11 @@ i915_init_compile(struct i915_context *i915, p->shader = &i915->fs; - /* a bit of a hack, need to improve constant buffer infrastructure */ - if (i915->fs.constants) - p->constants = i915->fs.constants; - else - p->constants = &i915->temp_constants; + /* new constants found during translation get appended after the + * user-provided constants. + */ + p->constants = i915->current.constants[PIPE_SHADER_FRAGMENT]; + p->num_constants = i915->current.num_user_constants[PIPE_SHADER_FRAGMENT]; p->nr_tex_indirect = 1; /* correct? */ p->nr_tex_insn = 0; @@ -960,8 +960,10 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p) program_size * sizeof(uint)); } - i915->current.constants = (uint *) p->constants->constant; - i915->current.num_constants = p->constants->nr_constants; + /* update number of constants */ + i915->current.num_constants[PIPE_SHADER_FRAGMENT] = p->num_constants; + assert(i915->current.num_constants[PIPE_SHADER_FRAGMENT] + >= i915->current.num_user_constants[PIPE_SHADER_FRAGMENT]); } /* Release the compilation struct: diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index e8ffd1fd7b..8f8b13253d 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -30,6 +30,7 @@ #include "pipe/draw/draw_context.h" +#include "pipe/p_winsys.h" #include "i915_context.h" #include "i915_state.h" @@ -131,6 +132,44 @@ static void i915_set_vs_state( struct pipe_context *pipe, } +static void i915_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + const struct pipe_constant_buffer *buf) +{ + struct i915_context *i915 = i915_context(pipe); + struct pipe_winsys *ws = pipe->winsys; + + assert(shader < PIPE_SHADER_TYPES); + assert(index == 0); + + /* Make a copy of shader constants. + * During fragment program translation we may add additional + * constants to the array. + * + * We want to consider the situation where some user constants + * (ex: a material color) may change frequently but the shader program + * stays the same. In that case we should only be updating the first + * N constants, leaving any extras from shader translation alone. + */ + { + void *mapped; + if (buf->size && + (mapped = ws->buffer_map(ws, buf->buffer, PIPE_BUFFER_FLAG_READ))) { + memcpy(i915->current.constants[shader], mapped, buf->size); + fprintf(stderr, "i915 problem: map of constant buffer failed\n"); + ws->buffer_unmap(ws, buf->buffer); + i915->current.num_user_constants[shader] + = buf->size / (4 * sizeof(float)); + } + else { + i915->current.num_user_constants[shader] = 0; + } + } + + i915->dirty |= I915_NEW_CONSTANTS; +} + + static void i915_set_sampler_state(struct pipe_context *pipe, unsigned unit, const struct pipe_sampler_state *sampler) @@ -256,6 +295,7 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.set_blend_state = i915_set_blend_state; i915->pipe.set_clip_state = i915_set_clip_state; i915->pipe.set_clear_color_state = i915_set_clear_color_state; + i915->pipe.set_constant_buffer = i915_set_constant_buffer; i915->pipe.set_depth_state = i915_set_depth_test_state; i915->pipe.set_framebuffer_state = i915_set_framebuffer_state; i915->pipe.set_fs_state = i915_set_fs_state; diff --git a/src/mesa/pipe/i915simple/i915_state_emit.c b/src/mesa/pipe/i915simple/i915_state_emit.c index dcf02abb14..dff9d40a83 100644 --- a/src/mesa/pipe/i915simple/i915_state_emit.c +++ b/src/mesa/pipe/i915simple/i915_state_emit.c @@ -216,9 +216,11 @@ i915_emit_hardware_state(struct i915_context *i915 ) /* constants */ if (i915->hardware_dirty & I915_HW_PROGRAM) { - const uint nr = i915->current.num_constants; + const uint nr = i915->current.num_constants[PIPE_SHADER_FRAGMENT]; + assert(nr <= I915_MAX_CONSTANT); if (nr > 0) { - const uint *c = (const uint *) i915->current.constants; + const uint *c + = (const uint *) i915->current.constants[PIPE_SHADER_FRAGMENT]; uint i; OUT_BATCH( _3DSTATE_PIXEL_SHADER_CONSTANTS | (nr * 4) ); OUT_BATCH( (1 << (nr - 1)) | ((1 << (nr - 1)) - 1) ); diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 3a656b272e..0d90a967cc 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -99,8 +99,12 @@ struct pipe_context { void (*set_clear_color_state)( struct pipe_context *, const struct pipe_clear_color_state * ); + void (*set_constant_buffer)( struct pipe_context *, + uint shader, uint index, + const struct pipe_constant_buffer *buf ); + void (*set_depth_state)( struct pipe_context *, - const struct pipe_depth_state * ); + const struct pipe_depth_state * ); void (*set_framebuffer_state)( struct pipe_context *, const struct pipe_framebuffer_state * ); diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h index 43d1c438ae..636711938c 100644 --- a/src/mesa/pipe/p_defines.h +++ b/src/mesa/pipe/p_defines.h @@ -276,6 +276,14 @@ #define PIPE_FLUSH_TEXTURE_CACHE 0x2 +/** + * Shaders + */ +#define PIPE_SHADER_VERTEX 0 +#define PIPE_SHADER_FRAGMENT 1 +#define PIPE_SHADER_TYPES 2 + + /** * Primitive types: */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 42bf50a617..317e8e5634 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -115,9 +115,12 @@ struct pipe_clip_state { }; +/** + * Constants for vertex/fragment shaders + */ struct pipe_constant_buffer { - float constant[PIPE_MAX_CONSTANT][4]; - unsigned nr_constants; + struct pipe_buffer_handle *buffer; + unsigned size; /** in bytes */ }; @@ -125,7 +128,6 @@ struct pipe_shader_state { unsigned inputs_read; /**< FRAG/VERT_ATTRIB_x */ unsigned outputs_written; /**< FRAG/VERT_RESULT_x */ const struct tgsi_token *tokens; - struct pipe_constant_buffer *constants; /* XXX temporary? */ }; struct pipe_depth_state diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index ab9becc99e..5404b7f790 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -237,6 +237,7 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.set_blend_state = softpipe_set_blend_state; softpipe->pipe.set_clip_state = softpipe_set_clip_state; softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state; + softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer; softpipe->pipe.set_depth_state = softpipe_set_depth_test_state; softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.set_fs_state = softpipe_set_fs_state; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 14ae9f2105..6458573917 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -33,6 +33,7 @@ #include "pipe/p_state.h" #include "pipe/p_context.h" +#include "pipe/p_defines.h" #include "sp_quad.h" @@ -64,6 +65,7 @@ enum interp_mode { #define SP_NEW_STENCIL 0x1000 #define SP_NEW_VERTEX 0x2000 #define SP_NEW_VS 0x4000 +#define SP_NEW_CONSTANTS 0x8000 struct softpipe_context { @@ -78,6 +80,7 @@ struct softpipe_context { struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; + struct pipe_constant_buffer constants[2]; struct pipe_depth_state depth_test; struct pipe_framebuffer_state framebuffer; struct pipe_shader_state fs; @@ -105,7 +108,9 @@ struct softpipe_context { * Mapped vertex buffers */ ubyte *mapped_vbuffer[PIPE_ATTRIB_MAX]; - + + /** Mapped constant buffers */ + void *mapped_constants[PIPE_SHADER_TYPES]; /* FS + setup derived state: */ diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c index 0392b6b64e..5198a493da 100644 --- a/src/mesa/pipe/softpipe/sp_draw_arrays.c +++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c @@ -43,6 +43,34 @@ +static void +softpipe_map_constant_buffers(struct softpipe_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 +softpipe_unmap_constant_buffers(struct softpipe_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 softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start, unsigned count) @@ -81,6 +109,8 @@ softpipe_draw_elements(struct pipe_context *pipe, softpipe_map_surfaces(sp); + softpipe_map_constant_buffers(sp); + /* * Map vertex buffers */ @@ -123,6 +153,7 @@ softpipe_draw_elements(struct pipe_context *pipe, } softpipe_unmap_surfaces(sp); + softpipe_unmap_constant_buffers(sp); return TRUE; } diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c index c20f09d309..ceba94aa94 100755 --- a/src/mesa/pipe/softpipe/sp_quad_fs.c +++ b/src/mesa/pipe/softpipe/sp_quad_fs.c @@ -33,6 +33,7 @@ */ #include "pipe/p_util.h" +#include "pipe/p_defines.h" #include "sp_context.h" #include "sp_headers.h" @@ -83,7 +84,7 @@ shade_quad( qss->samplers ); /* Consts does not require 16 byte alignment. */ - machine.Consts = softpipe->fs.constants->constant; + machine.Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT]; machine.Inputs = ALIGN16_ASSIGN(inputs); machine.Outputs = ALIGN16_ASSIGN(outputs); diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 5e1ecd94e0..354580b2a5 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -52,6 +52,10 @@ void softpipe_set_clear_color_state( struct pipe_context *, void softpipe_set_clip_state( struct pipe_context *, const struct pipe_clip_state * ); +void softpipe_set_constant_buffer(struct pipe_context *, + uint shader, uint index, + const struct pipe_constant_buffer *buf); + void softpipe_set_depth_test_state( struct pipe_context *, const struct pipe_depth_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c index bab407f047..9e3ff6d35c 100644 --- a/src/mesa/pipe/softpipe/sp_state_fs.c +++ b/src/mesa/pipe/softpipe/sp_state_fs.c @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -28,6 +28,8 @@ #include "sp_context.h" #include "sp_state.h" +#include "pipe/p_defines.h" +#include "pipe/p_winsys.h" #include "pipe/draw/draw_context.h" @@ -53,3 +55,24 @@ void softpipe_set_vs_state( struct pipe_context *pipe, draw_set_vertex_shader(softpipe->draw, vs); } + + +void softpipe_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + const struct pipe_constant_buffer *buf) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + struct pipe_winsys *ws = pipe->winsys; + + assert(shader < PIPE_SHADER_TYPES); + assert(index == 0); + + /* note: reference counting */ + ws->buffer_unreference(ws, &softpipe->constants[shader].buffer); + softpipe->constants[shader].buffer = ws->buffer_reference(ws, buf->buffer); + softpipe->constants[shader].size = buf->size; + + softpipe->dirty |= SP_NEW_CONSTANTS; +} + + diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index 9aba9aaa56..019b6457e0 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -32,6 +32,8 @@ #include "shader/prog_parameter.h" #include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_winsys.h" #include "pipe/tgsi/mesa/mesa_to_tgsi.h" #include "pipe/tgsi/core/tgsi_dump.h" @@ -53,12 +55,36 @@ static void compile_fs( struct st_context *st, } +static void +update_fs_constants(struct st_context *st, + struct gl_program_parameter_list *params) + +{ + const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4; + struct pipe_winsys *ws = st->pipe->winsys; + struct pipe_constant_buffer *cbuf + = &st->state.constants[PIPE_SHADER_FRAGMENT]; + + if (!cbuf->buffer) + cbuf->buffer = ws->buffer_create(ws, 1); + + /* load Mesa constants into the constant buffer */ + if (paramBytes) + ws->buffer_data(ws, cbuf->buffer, paramBytes, params->ParameterValues); + + cbuf->size = paramBytes; + + st->pipe->set_constant_buffer(st->pipe, PIPE_SHADER_FRAGMENT, 0, cbuf); +} + + static void update_fs( struct st_context *st ) { struct pipe_shader_state fs; struct st_fragment_program *fp = NULL; struct gl_program_parameter_list *params = NULL; + /* find active shader and params */ if (st->ctx->Shader.CurrentProgram && st->ctx->Shader.CurrentProgram->LinkStatus && st->ctx->Shader.CurrentProgram->FragmentProgram) { @@ -72,25 +98,21 @@ static void update_fs( struct st_context *st ) params = st->ctx->FragmentProgram._Current->Base.Parameters; } + /* update constants */ if (fp && params) { - /* load program's constants array */ - _mesa_load_state_parameters(st->ctx, params); - - fp->constants.nr_constants = params->NumParameters; - memcpy(fp->constants.constant, - params->ParameterValues, - params->NumParameters * sizeof(GLfloat) * 4); + update_fs_constants(st, params); } + /* translate shader to TGSI format */ if (fp->dirty) compile_fs( st, fp ); + /* update pipe state */ memset( &fs, 0, sizeof(fs) ); fs.inputs_read = fp->Base.Base.InputsRead; fs.outputs_written = fp->Base.Base.OutputsWritten; fs.tokens = &fp->tokens[0]; - fs.constants = &fp->constants; if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0 || fp->dirty) diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index c8bd805e02..8a38020afd 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -34,6 +34,8 @@ #include "tnl/t_vp_build.h" #include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_winsys.h" #include "pipe/tgsi/mesa/mesa_to_tgsi.h" #include "pipe/tgsi/core/tgsi_dump.h" @@ -56,17 +58,36 @@ static void compile_vs( struct st_context *st, } +static void +update_vs_constants(struct st_context *st, + struct gl_program_parameter_list *params) + +{ + const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4; + struct pipe_winsys *ws = st->pipe->winsys; + struct pipe_constant_buffer *cbuf + = &st->state.constants[PIPE_SHADER_VERTEX]; + + if (!cbuf->buffer) + cbuf->buffer = ws->buffer_create(ws, 1); + + /* load Mesa constants into the constant buffer */ + if (paramBytes) + ws->buffer_data(ws, cbuf->buffer, paramBytes, params->ParameterValues); + + cbuf->size = paramBytes; + + st->pipe->set_constant_buffer(st->pipe, PIPE_SHADER_VERTEX, 0, cbuf); +} + + static void update_vs( struct st_context *st ) { struct pipe_shader_state vs; struct st_vertex_program *vp = NULL; struct gl_program_parameter_list *params = NULL; -#if 0 - if (st->ctx->VertexProgram._MaintainTnlProgram) - _tnl_UpdateFixedFunctionProgram( st->ctx ); -#endif - + /* find active shader and params */ if (st->ctx->Shader.CurrentProgram && st->ctx->Shader.CurrentProgram->LinkStatus && st->ctx->Shader.CurrentProgram->VertexProgram) { @@ -80,31 +101,21 @@ static void update_vs( struct st_context *st ) params = st->ctx->VertexProgram._Current->Base.Parameters; } - /* XXXX temp */ -#if 1 - if (!vp) - return; -#endif + /* update constants */ if (vp && params) { - /* load program's constants array */ - - /* XXX this should probably be done elsewhere/separately */ _mesa_load_state_parameters(st->ctx, params); - - vp->constants.nr_constants = params->NumParameters; - memcpy(vp->constants.constant, - params->ParameterValues, - params->NumParameters * sizeof(GLfloat) * 4); + update_vs_constants(st, params); } + /* translate shader to TGSI format */ if (vp->dirty) compile_vs( st, vp ); + /* update pipe state */ memset( &vs, 0, sizeof(vs) ); vs.outputs_written = vp->Base.Base.OutputsWritten; vs.inputs_read = vp->Base.Base.InputsRead; vs.tokens = &vp->tokens[0]; - vs.constants = &vp->constants; if (memcmp(&vs, &st->state.vs, sizeof(vs)) != 0 || vp->dirty) diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 2f2d11c014..e3690deb5a 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -350,7 +350,6 @@ clear_with_quad(GLcontext *ctx, memset(&fs, 0, sizeof(fs)); fs.inputs_read = stfp->Base.Base.InputsRead; fs.tokens = &stfp->tokens[0]; - fs.constants = NULL; pipe->set_fs_state(pipe, &fs); } @@ -365,7 +364,6 @@ clear_with_quad(GLcontext *ctx, vs.inputs_read = stvp->Base.Base.InputsRead; vs.outputs_written = stvp->Base.Base.OutputsWritten; vs.tokens = &stvp->tokens[0]; - vs.constants = NULL; pipe->set_vs_state(pipe, &vs); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index d3f060e691..a45700e1db 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -332,7 +332,6 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, memset(&fs, 0, sizeof(fs)); fs.inputs_read = stfp->Base.Base.InputsRead; fs.tokens = &stfp->tokens[0]; - fs.constants = NULL; pipe->set_fs_state(pipe, &fs); } @@ -347,7 +346,6 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, vs.inputs_read = stvp->Base.Base.InputsRead; vs.outputs_written = stvp->Base.Base.OutputsWritten; vs.tokens = &stvp->tokens[0]; - vs.constants = NULL; pipe->set_vs_state(pipe, &vs); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 35774a790e..38d6a3ed86 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -71,16 +71,17 @@ struct st_context struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; + struct pipe_constant_buffer constants[2]; struct pipe_depth_state depth; struct pipe_framebuffer_state framebuffer; - struct pipe_shader_state fs; - struct pipe_shader_state vs; + struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; struct pipe_scissor_state scissor; struct pipe_setup_state setup; + struct pipe_shader_state fs; + struct pipe_shader_state vs; struct pipe_stencil_state stencil; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; } state; diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index b077fdf069..3ff4f4e9c7 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -53,8 +53,6 @@ struct st_fragment_program struct tgsi_token tokens[ST_FP_MAX_TOKENS]; GLboolean dirty; - struct pipe_constant_buffer constants; - #if 0 GLfloat (*cbuffer)[4]; GLuint nr_constants; @@ -85,7 +83,9 @@ struct st_vertex_program struct tgsi_token tokens[ST_FP_MAX_TOKENS]; GLboolean dirty; +#if 0 struct pipe_constant_buffer constants; +#endif GLuint param_state; }; -- cgit v1.2.3 From d8b16d416de95daa4f0ede9b839bdbf0fa6bf1b1 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 23 Aug 2007 17:00:47 -0600 Subject: Checkpoint: new vertex/fragment attribute naming Replace VF_ATTRIB_x with TGSI_ATTRIB_x When converting mesa programs to TGSI programs, also convert the InputsRead and OutputsWritten to a mask of TGSI_ATTRIB_ bits. Still need to do conversion for vertex programs... --- src/mesa/pipe/draw/draw_arrays.c | 9 +-- src/mesa/pipe/draw/draw_clip.c | 4 +- src/mesa/pipe/draw/draw_flatshade.c | 8 +-- src/mesa/pipe/draw/draw_private.h | 3 +- src/mesa/pipe/draw/draw_twoside.c | 8 +-- src/mesa/pipe/draw/draw_vertex.h | 83 +---------------------- src/mesa/pipe/i915simple/i915_fpc_emit.c | 9 --- src/mesa/pipe/i915simple/i915_fpc_translate.c | 39 +++++------ src/mesa/pipe/i915simple/i915_state_derived.c | 96 ++++++++++----------------- src/mesa/pipe/p_state.h | 4 +- src/mesa/pipe/softpipe/sp_prim_setup.c | 17 ++--- src/mesa/pipe/softpipe/sp_quad_fs.c | 3 +- src/mesa/pipe/softpipe/sp_state_derived.c | 72 ++++++++++---------- src/mesa/pipe/tgsi/core/tgsi_token.h | 41 ------------ src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c | 84 ++++++++++++++++++++--- src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h | 25 +++++++ src/mesa/state_tracker/st_atom_fs.c | 6 +- src/mesa/state_tracker/st_cb_clear.c | 3 +- 18 files changed, 228 insertions(+), 286 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/draw/draw_arrays.c b/src/mesa/pipe/draw/draw_arrays.c index 784eb3f2e6..f6bf174dc0 100644 --- a/src/mesa/pipe/draw/draw_arrays.c +++ b/src/mesa/pipe/draw/draw_arrays.c @@ -78,6 +78,7 @@ emit_vertex_attr(struct vertex_info *vinfo, uint vfAttr, uint format) vinfo->slot_to_attrib[n] = vfAttr; if (n >= 2) { /* the first two slots are the vertex header & clippos */ + assert(vfAttr < Elements(vinfo->attrib_to_slot)); vinfo->attrib_to_slot[vfAttr] = n - 2; } /*printf("Vertex slot %d = vfattrib %d\n", n, vfAttr);*/ @@ -128,16 +129,16 @@ draw_set_vertex_attributes( struct draw_context *draw, struct vertex_info *vinfo = &draw->vertex_info; unsigned i; - assert(slot_to_vf_attr[0] == VF_ATTRIB_POS); + assert(slot_to_vf_attr[0] == TGSI_ATTRIB_POS); memset(vinfo, 0, sizeof(*vinfo)); /* * First three attribs are always the same: header, clip pos, winpos */ - emit_vertex_attr(vinfo, VF_ATTRIB_VERTEX_HEADER, FORMAT_1F); - emit_vertex_attr(vinfo, VF_ATTRIB_CLIP_POS, FORMAT_4F); - emit_vertex_attr(vinfo, VF_ATTRIB_POS, FORMAT_4F_VIEWPORT); + emit_vertex_attr(vinfo, TGSI_ATTRIB_VERTEX_HEADER, FORMAT_1F); + emit_vertex_attr(vinfo, TGSI_ATTRIB_CLIP_POS, FORMAT_4F); + emit_vertex_attr(vinfo, TGSI_ATTRIB_POS, FORMAT_4F_VIEWPORT); /* * Remaining attribs (color, texcoords, etc) diff --git a/src/mesa/pipe/draw/draw_clip.c b/src/mesa/pipe/draw/draw_clip.c index 1c2491d2c6..f46f4e3de6 100644 --- a/src/mesa/pipe/draw/draw_clip.c +++ b/src/mesa/pipe/draw/draw_clip.c @@ -380,8 +380,8 @@ static void clip_begin( struct draw_stage *stage ) /* sanity checks. If these fail, review the clip/interp code! */ assert(stage->draw->vertex_info.num_attribs >= 3); - assert(stage->draw->vertex_info.slot_to_attrib[0] == VF_ATTRIB_VERTEX_HEADER); - assert(stage->draw->vertex_info.slot_to_attrib[1] == VF_ATTRIB_CLIP_POS); + assert(stage->draw->vertex_info.slot_to_attrib[0] == TGSI_ATTRIB_VERTEX_HEADER); + assert(stage->draw->vertex_info.slot_to_attrib[1] == TGSI_ATTRIB_CLIP_POS); /* Hacky bitmask to use when we hit CLIP_USER_BIT: */ diff --git a/src/mesa/pipe/draw/draw_flatshade.c b/src/mesa/pipe/draw/draw_flatshade.c index 34588c83b6..d8db1f748c 100644 --- a/src/mesa/pipe/draw/draw_flatshade.c +++ b/src/mesa/pipe/draw/draw_flatshade.c @@ -72,10 +72,10 @@ static INLINE void copy_colors( struct draw_stage *stage, const struct flatshade_stage *flatshade = flatshade_stage(stage); const unsigned *lookup = flatshade->lookup; - copy_attr( lookup[VF_ATTRIB_COLOR0], dst, src ); - copy_attr( lookup[VF_ATTRIB_COLOR1], dst, src ); - copy_attr( lookup[VF_ATTRIB_BFC0], dst, src ); - copy_attr( lookup[VF_ATTRIB_BFC1], dst, src ); + copy_attr( lookup[TGSI_ATTRIB_COLOR0], dst, src ); + copy_attr( lookup[TGSI_ATTRIB_COLOR1], dst, src ); + copy_attr( lookup[TGSI_ATTRIB_BFC0], dst, src ); + copy_attr( lookup[TGSI_ATTRIB_BFC1], dst, src ); } diff --git a/src/mesa/pipe/draw/draw_private.h b/src/mesa/pipe/draw/draw_private.h index 531bb2e254..c5d4c62f71 100644 --- a/src/mesa/pipe/draw/draw_private.h +++ b/src/mesa/pipe/draw/draw_private.h @@ -61,7 +61,8 @@ struct vertex_header { float data[][4]; /* Note variable size */ }; -#define MAX_VERTEX_SIZE ((2 + FRAG_ATTRIB_MAX) * 4 * sizeof(float)) +/* XXX This is too large */ +#define MAX_VERTEX_SIZE ((2 + TGSI_ATTRIB_MAX) * 4 * sizeof(float)) diff --git a/src/mesa/pipe/draw/draw_twoside.c b/src/mesa/pipe/draw/draw_twoside.c index 822cadd61f..4fd87786f8 100644 --- a/src/mesa/pipe/draw/draw_twoside.c +++ b/src/mesa/pipe/draw/draw_twoside.c @@ -79,12 +79,12 @@ static struct vertex_header *copy_bfc( struct twoside_stage *twoside, { struct vertex_header *tmp = dup_vert( &twoside->stage, v, idx ); - copy_color( twoside->lookup[VF_ATTRIB_COLOR0], - twoside->lookup[VF_ATTRIB_BFC0], + copy_color( twoside->lookup[TGSI_ATTRIB_COLOR0], + twoside->lookup[TGSI_ATTRIB_BFC0], tmp ); - copy_color( twoside->lookup[VF_ATTRIB_COLOR1], - twoside->lookup[VF_ATTRIB_BFC1], + copy_color( twoside->lookup[TGSI_ATTRIB_COLOR1], + twoside->lookup[TGSI_ATTRIB_BFC1], tmp ); return tmp; diff --git a/src/mesa/pipe/draw/draw_vertex.h b/src/mesa/pipe/draw/draw_vertex.h index 3262431487..0e15ea89a2 100644 --- a/src/mesa/pipe/draw/draw_vertex.h +++ b/src/mesa/pipe/draw/draw_vertex.h @@ -33,84 +33,7 @@ #ifndef DRAW_VERTEX_H #define DRAW_VERTEX_H - -/*** - *** XXX There's a lot of legacy tokens here that'll eventually go away. - *** (at least we don't include vf/vf.h anymore) - ***/ - - -enum { - VF_ATTRIB_POS = 0, - VF_ATTRIB_WEIGHT = 1, - VF_ATTRIB_NORMAL = 2, - VF_ATTRIB_COLOR0 = 3, - VF_ATTRIB_COLOR1 = 4, - VF_ATTRIB_FOG = 5, - VF_ATTRIB_COLOR_INDEX = 6, - VF_ATTRIB_EDGEFLAG = 7, - VF_ATTRIB_TEX0 = 8, - VF_ATTRIB_TEX1 = 9, - VF_ATTRIB_TEX2 = 10, - VF_ATTRIB_TEX3 = 11, - VF_ATTRIB_TEX4 = 12, - VF_ATTRIB_TEX5 = 13, - VF_ATTRIB_TEX6 = 14, - VF_ATTRIB_TEX7 = 15, - VF_ATTRIB_VAR0 = 16, - VF_ATTRIB_VAR1 = 17, - VF_ATTRIB_VAR2 = 18, - VF_ATTRIB_VAR3 = 19, - VF_ATTRIB_VAR4 = 20, - VF_ATTRIB_VAR5 = 21, - VF_ATTRIB_VAR6 = 22, - VF_ATTRIB_VAR7 = 23, - VF_ATTRIB_POINTSIZE = 24, - VF_ATTRIB_BFC0 = 25, - VF_ATTRIB_BFC1 = 26, - VF_ATTRIB_CLIP_POS = 27, - VF_ATTRIB_VERTEX_HEADER = 28, - VF_ATTRIB_MAX = 29 -}; - -#define MAX_VARYING 8 -enum -{ - FRAG_ATTRIB_WPOS = 0, - FRAG_ATTRIB_COL0 = 1, - FRAG_ATTRIB_COL1 = 2, - FRAG_ATTRIB_FOGC = 3, - FRAG_ATTRIB_TEX0 = 4, - FRAG_ATTRIB_TEX1 = 5, - FRAG_ATTRIB_TEX2 = 6, - FRAG_ATTRIB_TEX3 = 7, - FRAG_ATTRIB_TEX4 = 8, - FRAG_ATTRIB_TEX5 = 9, - FRAG_ATTRIB_TEX6 = 10, - FRAG_ATTRIB_TEX7 = 11, - FRAG_ATTRIB_VAR0 = 12, /**< shader varying */ - FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + MAX_VARYING) -}; - -#define FRAG_BIT_WPOS (1 << FRAG_ATTRIB_WPOS) -#define FRAG_BIT_COL0 (1 << FRAG_ATTRIB_COL0) -#define FRAG_BIT_COL1 (1 << FRAG_ATTRIB_COL1) -#define FRAG_BIT_FOGC (1 << FRAG_ATTRIB_FOGC) -#define FRAG_BIT_TEX0 (1 << FRAG_ATTRIB_TEX0) - - - -#define MAX_DRAW_BUFFERS 4 - -enum -{ - FRAG_RESULT_COLR = 0, - FRAG_RESULT_COLH = 1, - FRAG_RESULT_DEPR = 2, - FRAG_RESULT_DATA0 = 3, - FRAG_RESULT_MAX = (FRAG_RESULT_DATA0 + MAX_DRAW_BUFFERS) -}; - +#include "pipe/tgsi/core/tgsi_attribs.h" #define MAX_VERT_ATTRIBS 12 /* OK? */ @@ -127,10 +50,10 @@ enum struct vertex_info { uint num_attribs; - uint hwfmt[2]; /**< hardware format info for this format */ + uint hwfmt[4]; /**< hardware format info for this format */ uint attr_mask; /**< mask of VF_ATTR_ bits */ uint slot_to_attrib[MAX_VERT_ATTRIBS]; - uint attrib_to_slot[VF_ATTRIB_MAX]; + uint attrib_to_slot[TGSI_ATTRIB_MAX]; uint interp_mode[MAX_VERT_ATTRIBS]; uint format[MAX_VERT_ATTRIBS]; /**< FORMAT_x */ uint size; /**< total vertex size in dwords */ diff --git a/src/mesa/pipe/i915simple/i915_fpc_emit.c b/src/mesa/pipe/i915simple/i915_fpc_emit.c index f062885f8a..c8d36435d9 100644 --- a/src/mesa/pipe/i915simple/i915_fpc_emit.c +++ b/src/mesa/pipe/i915simple/i915_fpc_emit.c @@ -353,23 +353,14 @@ i915_emit_param4fv(struct i915_fp_compile * p, const float * values) return UREG(REG_TYPE_CONST, fp->param[i].reg); } -#if 0 - if (fp->nr_constants == I915_MAX_CONSTANT || - fp->nr_params == I915_MAX_CONSTANT) { -#else if (p->constants->nr_constants == I915_MAX_CONSTANT || fp->nr_params == I915_MAX_CONSTANT) { -#endif i915_program_error(p, "i915_emit_param4fv: out of constants\n"); return 0; } { -#if 0 - int reg = fp->nr_constants++; -#else int reg = p->constants->nr_constants++; -#endif int i = fp->nr_params++; assert (p->constant_flags[reg] == 0); diff --git a/src/mesa/pipe/i915simple/i915_fpc_translate.c b/src/mesa/pipe/i915simple/i915_fpc_translate.c index be3de0f3f4..e7315d2263 100644 --- a/src/mesa/pipe/i915simple/i915_fpc_translate.c +++ b/src/mesa/pipe/i915simple/i915_fpc_translate.c @@ -154,31 +154,31 @@ src_vector(struct i915_fp_compile *p, index = p->vertex_info->slot_to_attrib[index]; switch (index) { - case VF_ATTRIB_POS: + case TGSI_ATTRIB_POS: assert(p->wpos_tex != -1); src = i915_emit_decl(p, REG_TYPE_T, p->wpos_tex, D0_CHANNEL_ALL); break; - case VF_ATTRIB_COLOR0: + case TGSI_ATTRIB_COLOR0: src = i915_emit_decl(p, REG_TYPE_T, T_DIFFUSE, D0_CHANNEL_ALL); break; - case VF_ATTRIB_COLOR1: + case TGSI_ATTRIB_COLOR1: src = i915_emit_decl(p, REG_TYPE_T, T_SPECULAR, D0_CHANNEL_XYZ); src = swizzle(src, X, Y, Z, ONE); break; - case VF_ATTRIB_FOG: + case TGSI_ATTRIB_FOG: src = i915_emit_decl(p, REG_TYPE_T, T_FOG_W, D0_CHANNEL_W); src = swizzle(src, W, W, W, W); break; - case VF_ATTRIB_TEX0: - case VF_ATTRIB_TEX1: - case VF_ATTRIB_TEX2: - case VF_ATTRIB_TEX3: - case VF_ATTRIB_TEX4: - case VF_ATTRIB_TEX5: - case VF_ATTRIB_TEX6: - case VF_ATTRIB_TEX7: + case TGSI_ATTRIB_TEX0: + case TGSI_ATTRIB_TEX1: + case TGSI_ATTRIB_TEX2: + case TGSI_ATTRIB_TEX3: + case TGSI_ATTRIB_TEX4: + case TGSI_ATTRIB_TEX5: + case TGSI_ATTRIB_TEX6: + case TGSI_ATTRIB_TEX7: src = i915_emit_decl(p, REG_TYPE_T, - T_TEX0 + (index - VF_ATTRIB_TEX0), + T_TEX0 + (index - TGSI_ATTRIB_TEX0), D0_CHANNEL_ALL); break; default: @@ -237,9 +237,9 @@ get_result_vector(struct i915_fp_compile *p, switch (dest->DstRegister.File) { case TGSI_FILE_OUTPUT: switch (dest->DstRegister.Index) { - case 1: /*COLOR*/ /*FRAG_RESULT_COLR:*/ + case TGSI_ATTRIB_COLOR0: return UREG(REG_TYPE_OC, 0); - case 0: /*DEPTH*/ /*FRAG_RESULT_DEPR:*/ + case TGSI_ATTRIB_POS: return UREG(REG_TYPE_OD, 0); default: i915_program_error(p, "Bad inst->DstReg.Index"); @@ -989,14 +989,15 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p) static void i915_find_wpos_space(struct i915_fp_compile *p) { - const uint inputs = p->shader->inputs_read | FRAG_BIT_WPOS; /*XXX hack*/ + const uint inputs + = p->shader->inputs_read | (1 << TGSI_ATTRIB_POS); /*XXX hack*/ uint i; p->wpos_tex = -1; - if (inputs & FRAG_BIT_WPOS) { + if (inputs & (1 << TGSI_ATTRIB_POS)) { for (i = 0; i < I915_TEX_UNITS; i++) { - if ((inputs & (FRAG_BIT_TEX0 << i)) == 0) { + if ((inputs & (1 << (TGSI_ATTRIB_TEX0 + i))) == 0) { p->wpos_tex = i; return; } @@ -1017,7 +1018,7 @@ i915_find_wpos_space(struct i915_fp_compile *p) static void i915_fixup_depth_write(struct i915_fp_compile *p) { - if (p->shader->outputs_written & (1<shader->outputs_written & (1 << TGSI_ATTRIB_POS)) { uint depth = UREG(REG_TYPE_OD, 0); i915_emit_arith(p, diff --git a/src/mesa/pipe/i915simple/i915_state_derived.c b/src/mesa/pipe/i915simple/i915_state_derived.c index e8c7dfba6f..426d43f288 100644 --- a/src/mesa/pipe/i915simple/i915_state_derived.c +++ b/src/mesa/pipe/i915simple/i915_state_derived.c @@ -35,32 +35,6 @@ #include "i915_fpc.h" - -static const unsigned frag_to_vf[FRAG_ATTRIB_MAX] = -{ - VF_ATTRIB_POS, - VF_ATTRIB_COLOR0, - VF_ATTRIB_COLOR1, - VF_ATTRIB_FOG, - VF_ATTRIB_TEX0, - VF_ATTRIB_TEX1, - VF_ATTRIB_TEX2, - VF_ATTRIB_TEX3, - VF_ATTRIB_TEX4, - VF_ATTRIB_TEX5, - VF_ATTRIB_TEX6, - VF_ATTRIB_TEX7, - VF_ATTRIB_VAR0, - VF_ATTRIB_VAR1, - VF_ATTRIB_VAR2, - VF_ATTRIB_VAR3, - VF_ATTRIB_VAR4, - VF_ATTRIB_VAR5, - VF_ATTRIB_VAR6, - VF_ATTRIB_VAR7, -}; - - static INLINE void emit_vertex_attr(struct vertex_info *vinfo, uint vfAttr, uint format) { @@ -118,44 +92,45 @@ static void calculate_vertex_layout( struct i915_context *i915 ) { const unsigned inputsRead = i915->fs.inputs_read; struct vertex_info *vinfo = &i915->current.vertex_info; - uint i; memset(vinfo, 0, sizeof(*vinfo)); /* TODO - Figure out if we need to do perspective divide, etc. */ - emit_vertex_attr(vinfo, VF_ATTRIB_POS, FORMAT_3F); + + /* pos */ + emit_vertex_attr(vinfo, TGSI_ATTRIB_POS, FORMAT_3F); vinfo->hwfmt[0] |= S4_VFMT_XYZ; - - /* Pull in the rest of the attributes. They are all in float4 - * format. Future optimizations could be to keep some attributes - * as fixed point or ubyte format. - */ - for (i = 1; i < FRAG_ATTRIB_TEX0; i++) { - if (inputsRead & (1 << i)) { - assert(i < Elements(frag_to_vf)); - if (i915->setup.flatshade - && (i == FRAG_ATTRIB_COL0 || i == FRAG_ATTRIB_COL1)) { - emit_vertex_attr(vinfo, frag_to_vf[i], FORMAT_4UB); - } - else { - emit_vertex_attr(vinfo, frag_to_vf[i], FORMAT_4UB); - } - vinfo->hwfmt[0] |= S4_VFMT_COLOR; - } + + /* color0 */ + if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) { + emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0, FORMAT_4UB); + vinfo->hwfmt[0] |= S4_VFMT_COLOR; } - for (i = FRAG_ATTRIB_TEX0; i <= FRAG_ATTRIB_TEX7/*MAX*/; i++) { - uint hwtc; - if (inputsRead & (1 << i)) { - hwtc = TEXCOORDFMT_4D; - assert(i < sizeof(frag_to_vf) / sizeof(frag_to_vf[0])); - emit_vertex_attr(vinfo, frag_to_vf[i], FORMAT_4F); - } - else { - hwtc = TEXCOORDFMT_NOT_PRESENT; + /* color 1 */ + if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) { + assert(0); /* untested */ + emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1, FORMAT_4UB); + vinfo->hwfmt[0] |= S4_VFMT_SPEC_FOG; + } + + /* XXX fog? */ + + /* texcoords */ + { + uint i; + for (i = TGSI_ATTRIB_TEX0; i <= TGSI_ATTRIB_TEX7; i++) { + uint hwtc; + if (inputsRead & (1 << i)) { + emit_vertex_attr(vinfo, i, FORMAT_4F); + hwtc = TEXCOORDFMT_4D; + } + else { + hwtc = TEXCOORDFMT_NOT_PRESENT; + } + vinfo->hwfmt[1] |= hwtc << ((i - TGSI_ATTRIB_TEX0) * 4); } - vinfo->hwfmt[1] |= hwtc << ((i - FRAG_ATTRIB_TEX0) * 4); } /* Additional attributes required for setup: Just twosided @@ -163,12 +138,11 @@ static void calculate_vertex_layout( struct i915_context *i915 ) * the vertex header. */ if (i915->setup.light_twoside) { - if (inputsRead & FRAG_BIT_COL0) { - emit_vertex_attr(vinfo, VF_ATTRIB_BFC0, FORMAT_OMIT); - } - - if (inputsRead & FRAG_BIT_COL1) { - emit_vertex_attr(vinfo, VF_ATTRIB_BFC1, FORMAT_OMIT); + if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) { + emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0, FORMAT_OMIT); + } + if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) { + emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC1, FORMAT_OMIT); } } diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index d29b85117b..e562a8d058 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -125,8 +125,8 @@ struct pipe_constant_buffer { struct pipe_shader_state { - unsigned inputs_read; /**< FRAG/VERT_ATTRIB_x */ - unsigned outputs_written; /**< FRAG/VERT_RESULT_x */ + unsigned inputs_read; /**< TGSI_ATTRIB_ bits */ + unsigned outputs_written; /**< TGSI_ATTRIB_ bits */ const struct tgsi_token *tokens; }; diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index f779deac28..e8ed548cf0 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -40,10 +40,7 @@ #include "pipe/draw/draw_private.h" #include "pipe/p_util.h" - -/** XXX remove */ -#define FRAG_ATTRIB_WPOS 0 -#define FRAG_ATTRIB_MAX 13 +#include "pipe/draw/draw_vertex.h" /** @@ -82,7 +79,7 @@ struct setup_stage { float oneoverarea; - struct tgsi_interp_coef coef[FRAG_ATTRIB_MAX]; + struct tgsi_interp_coef coef[TGSI_ATTRIB_MAX]; struct quad_header quad; struct { @@ -369,7 +366,7 @@ static void const_coeff( struct setup_stage *setup, unsigned slot, unsigned i ) { - assert(slot < FRAG_ATTRIB_MAX); + assert(slot < TGSI_ATTRIB_MAX); assert(i <= 3); setup->coef[slot].dadx[i] = 0; @@ -394,7 +391,7 @@ static void tri_linear_coeff( struct setup_stage *setup, float a = setup->ebot.dy * majda - botda * setup->emaj.dy; float b = setup->emaj.dx * botda - majda * setup->ebot.dx; - assert(slot < FRAG_ATTRIB_MAX); + assert(slot < TGSI_ATTRIB_MAX); assert(i <= 3); setup->coef[slot].dadx[i] = a * setup->oneoverarea; @@ -445,7 +442,7 @@ static void tri_persp_coeff( struct setup_stage *setup, float a = setup->ebot.dy * majda - botda * setup->emaj.dy; float b = setup->emaj.dx * botda - majda * setup->ebot.dx; - assert(slot < FRAG_ATTRIB_MAX); + assert(slot < TGSI_ATTRIB_MAX); assert(i <= 3); setup->coef[slot].dadx[i] = a * setup->oneoverarea; @@ -891,8 +888,8 @@ setup_point(struct draw_stage *stage, struct prim_header *prim) const float halfSize = 0.5f * setup->softpipe->setup.point_size; const boolean round = setup->softpipe->setup.point_smooth; const struct vertex_header *v0 = prim->v[0]; - const float x = v0->data[FRAG_ATTRIB_WPOS][0]; - const float y = v0->data[FRAG_ATTRIB_WPOS][1]; + const float x = v0->data[TGSI_ATTRIB_POS][0]; + const float y = v0->data[TGSI_ATTRIB_POS][1]; unsigned slot, j; /* For points, all interpolants are constant-valued. diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c index 8a419c9ac7..8d41e09465 100755 --- a/src/mesa/pipe/softpipe/sp_quad_fs.c +++ b/src/mesa/pipe/softpipe/sp_quad_fs.c @@ -34,6 +34,7 @@ #include "pipe/p_util.h" #include "pipe/p_defines.h" +#include "pipe/tgsi/core/tgsi_attribs.h" #include "sp_context.h" #include "sp_headers.h" @@ -138,7 +139,7 @@ shade_quad( /* store result color */ memcpy( quad->outputs.color, - &machine.Outputs[1].xyzw[0].f[0], + &machine.Outputs[TGSI_ATTRIB_COLOR0].xyzw[0].f[0], sizeof( quad->outputs.color ) ); #if 0 diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index af230111dc..5c119ec8cd 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -33,41 +33,43 @@ #include "sp_context.h" #include "sp_state.h" +#include "pipe/tgsi/core/tgsi_attribs.h" -#define EMIT_ATTR( VF_ATTR, FRAG_ATTR, INTERP ) \ + +#define EMIT_ATTR( ATTR, FRAG_ATTR, INTERP ) \ do { \ - slot_to_vf_attr[softpipe->nr_attrs] = VF_ATTR; \ - softpipe->vf_attr_to_slot[VF_ATTR] = softpipe->nr_attrs; \ + slot_to_vf_attr[softpipe->nr_attrs] = ATTR; \ + softpipe->vf_attr_to_slot[ATTR] = softpipe->nr_attrs; \ softpipe->fp_attr_to_slot[FRAG_ATTR] = softpipe->nr_attrs; \ softpipe->interp[softpipe->nr_attrs] = INTERP; \ softpipe->nr_attrs++; \ - attr_mask |= (1 << (VF_ATTR)); \ + attr_mask |= (1 << (ATTR)); \ } while (0) static const unsigned frag_to_vf[PIPE_ATTRIB_MAX] = { - VF_ATTRIB_POS, - VF_ATTRIB_COLOR0, - VF_ATTRIB_COLOR1, - VF_ATTRIB_FOG, - VF_ATTRIB_TEX0, - VF_ATTRIB_TEX1, - VF_ATTRIB_TEX2, - VF_ATTRIB_TEX3, - VF_ATTRIB_TEX4, - VF_ATTRIB_TEX5, - VF_ATTRIB_TEX6, - VF_ATTRIB_TEX7, - VF_ATTRIB_VAR0, - VF_ATTRIB_VAR1, - VF_ATTRIB_VAR2, - VF_ATTRIB_VAR3, - VF_ATTRIB_VAR4, - VF_ATTRIB_VAR5, - VF_ATTRIB_VAR6, - VF_ATTRIB_VAR7, + TGSI_ATTRIB_POS, + TGSI_ATTRIB_COLOR0, + TGSI_ATTRIB_COLOR1, + TGSI_ATTRIB_FOG, + TGSI_ATTRIB_TEX0, + TGSI_ATTRIB_TEX1, + TGSI_ATTRIB_TEX2, + TGSI_ATTRIB_TEX3, + TGSI_ATTRIB_TEX4, + TGSI_ATTRIB_TEX5, + TGSI_ATTRIB_TEX6, + TGSI_ATTRIB_TEX7, + TGSI_ATTRIB_VAR0, + TGSI_ATTRIB_VAR1, + TGSI_ATTRIB_VAR2, + TGSI_ATTRIB_VAR3, + TGSI_ATTRIB_VAR4, + TGSI_ATTRIB_VAR5, + TGSI_ATTRIB_VAR6, + TGSI_ATTRIB_VAR7, }; @@ -79,7 +81,7 @@ static const unsigned frag_to_vf[PIPE_ATTRIB_MAX] = static void calculate_vertex_layout( struct softpipe_context *softpipe ) { const unsigned inputsRead = softpipe->fs.inputs_read; - unsigned slot_to_vf_attr[VF_ATTRIB_MAX]; + unsigned slot_to_vf_attr[TGSI_ATTRIB_MAX]; unsigned attr_mask = 0x0; unsigned i; @@ -87,7 +89,7 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) * fragment position (XYZW). */ if (softpipe->depth_test.enabled || - (inputsRead & (1 << FRAG_ATTRIB_WPOS))) + (inputsRead & (1 << TGSI_ATTRIB_POS))) softpipe->need_z = TRUE; else softpipe->need_z = FALSE; @@ -95,7 +97,7 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) /* Need W if we do any perspective-corrected interpolation or the * fragment program uses the fragment position. */ - if (inputsRead & (1 << FRAG_ATTRIB_WPOS)) + if (inputsRead & (1 << TGSI_ATTRIB_POS)) softpipe->need_w = TRUE; else softpipe->need_w = FALSE; @@ -109,24 +111,24 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) /* TODO - Figure out if we need to do perspective divide, etc. */ - EMIT_ATTR(VF_ATTRIB_POS, FRAG_ATTRIB_WPOS, INTERP_LINEAR); + EMIT_ATTR(TGSI_ATTRIB_POS, TGSI_ATTRIB_POS, INTERP_LINEAR); /* Pull in the rest of the attributes. They are all in float4 * format. Future optimizations could be to keep some attributes * as fixed point or ubyte format. */ - for (i = 1; i < FRAG_ATTRIB_TEX0; i++) { + for (i = 1; i < TGSI_ATTRIB_TEX0; i++) { if (inputsRead & (1 << i)) { assert(i < sizeof(frag_to_vf) / sizeof(frag_to_vf[0])); if (softpipe->setup.flatshade - && (i == FRAG_ATTRIB_COL0 || i == FRAG_ATTRIB_COL1)) + && (i == TGSI_ATTRIB_COLOR0 || i == TGSI_ATTRIB_COLOR1)) EMIT_ATTR(frag_to_vf[i], i, INTERP_CONSTANT); else EMIT_ATTR(frag_to_vf[i], i, INTERP_LINEAR); } } - for (i = FRAG_ATTRIB_TEX0; i < FRAG_ATTRIB_MAX; i++) { + for (i = TGSI_ATTRIB_TEX0; i < TGSI_ATTRIB_MAX; i++) { if (inputsRead & (1 << i)) { assert(i < sizeof(frag_to_vf) / sizeof(frag_to_vf[0])); EMIT_ATTR(frag_to_vf[i], i, INTERP_PERSPECTIVE); @@ -141,12 +143,12 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) * the vertex header. */ if (softpipe->setup.light_twoside) { - if (inputsRead & FRAG_BIT_COL0) { - EMIT_ATTR(VF_ATTRIB_BFC0, FRAG_ATTRIB_MAX, 0); /* XXX: mark as discarded after setup */ + if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) { + EMIT_ATTR(TGSI_ATTRIB_BFC0, TGSI_ATTRIB_MAX, 0); /* XXX: mark as discarded after setup */ } - if (inputsRead & FRAG_BIT_COL1) { - EMIT_ATTR(VF_ATTRIB_BFC1, FRAG_ATTRIB_MAX, 0); /* XXX: discard after setup */ + if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) { + EMIT_ATTR(TGSI_ATTRIB_BFC1, TGSI_ATTRIB_MAX, 0); /* XXX: discard after setup */ } } diff --git a/src/mesa/pipe/tgsi/core/tgsi_token.h b/src/mesa/pipe/tgsi/core/tgsi_token.h index a12a2d7370..ca53071a60 100644 --- a/src/mesa/pipe/tgsi/core/tgsi_token.h +++ b/src/mesa/pipe/tgsi/core/tgsi_token.h @@ -1478,47 +1478,6 @@ struct tgsi_dst_register_ext_predicate }; -/** - * The specific values here are not important. - */ -enum { - TGSI_ATTRIB_POS = 0, - TGSI_ATTRIB_WEIGHT = 1, - TGSI_ATTRIB_NORMAL = 2, - TGSI_ATTRIB_COLOR0 = 3, - TGSI_ATTRIB_COLOR1 = 4, - TGSI_ATTRIB_FOG = 5, - TGSI_ATTRIB_COLOR_INDEX = 6, /* XXX omit? */ - TGSI_ATTRIB_EDGEFLAG = 7, - TGSI_ATTRIB_TEX0 = 8, - TGSI_ATTRIB_TEX1 = 9, - TGSI_ATTRIB_TEX2 = 10, - TGSI_ATTRIB_TEX3 = 11, - TGSI_ATTRIB_TEX4 = 12, - TGSI_ATTRIB_TEX5 = 13, - TGSI_ATTRIB_TEX6 = 14, - TGSI_ATTRIB_TEX7 = 15, - TGSI_ATTRIB_VAR0 = 16, - TGSI_ATTRIB_VAR1 = 17, - TGSI_ATTRIB_VAR2 = 18, - TGSI_ATTRIB_VAR3 = 19, - TGSI_ATTRIB_VAR4 = 20, - TGSI_ATTRIB_VAR5 = 21, - TGSI_ATTRIB_VAR6 = 22, - TGSI_ATTRIB_VAR7 = 23, - TGSI_ATTRIB_POINTSIZE = 24, - TGSI_ATTRIB_BFC0 = 25, - TGSI_ATTRIB_BFC1 = 26, - TGSI_ATTRIB_CLIP_POS = 27, - TGSI_ATTRIB_VERTEX_HEADER = 28, - TGSI_ATTRIB_MAX = 29 -}; - - -#define TGSI_MAX_TEXTURE 8 -#define TGSI_MAX_VARYING 8 - - #if defined __cplusplus } // extern "C" #endif // defined __cplusplus diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c index dfb263ebdc..993d220c50 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c @@ -1,5 +1,7 @@ #include "tgsi_platform.h" #include "tgsi_mesa.h" +#include "pipe/tgsi/core/tgsi_attribs.h" +#include "pipe/tgsi/mesa/mesa_to_tgsi.h" #define TGSI_DEBUG 1 @@ -7,8 +9,8 @@ /** * Convert a VERT_ATTRIB_x to a TGSI_ATTRIB_y */ -static GLuint -translate_vertex_input(GLuint attrib) +uint +tgsi_mesa_translate_vertex_input(GLuint attrib) { /* XXX these could be implemented with array lookups too.... */ switch (attrib) { @@ -70,8 +72,8 @@ translate_vertex_input(GLuint attrib) /** * Convert VERT_RESULT_x to TGSI_ATTRIB_y */ -static GLuint -translate_vertex_ouput(GLuint attrib) +uint +tgsi_mesa_translate_vertex_output(GLuint attrib) { switch (attrib) { case VERT_RESULT_HPOS: @@ -130,8 +132,8 @@ translate_vertex_ouput(GLuint attrib) /** * Convert a FRAG_ATTRIB_x to a TGSI_ATTRIB_y */ -static GLuint -translate_fragment_input(GLuint attrib) +uint +tgsi_mesa_translate_fragment_input(GLuint attrib) { switch (attrib) { case FRAG_ATTRIB_WPOS: @@ -184,8 +186,8 @@ translate_fragment_input(GLuint attrib) /** * Convert FRAG_RESULT_x to TGSI_ATTRIB_y */ -static GLuint -translate_fragment_output(GLuint attrib) +uint +tgsi_mesa_translate_fragment_output(GLuint attrib) { switch (attrib) { case FRAG_RESULT_DEPR: @@ -209,6 +211,68 @@ translate_fragment_output(GLuint attrib) } +uint +tgsi_mesa_translate_vertex_input_mask(GLbitfield mask) +{ + uint tgsiMask = 0x0; + uint i; + for (i = 0; i < VERT_ATTRIB_MAX && mask; i++) { + if (mask & (1 << i)) { + tgsiMask |= 1 << tgsi_mesa_translate_vertex_input(i); + } + mask &= ~(1 << i); + } + return tgsiMask; +} + + +uint +tgsi_mesa_translate_vertex_output_mask(GLbitfield mask) +{ + uint tgsiMask = 0x0; + uint i; + for (i = 0; i < VERT_RESULT_MAX && mask; i++) { + if (mask & (1 << i)) { + tgsiMask |= 1 << tgsi_mesa_translate_vertex_output(i); + } + mask &= ~(1 << i); + } + return tgsiMask; +} + +uint +tgsi_mesa_translate_fragment_input_mask(GLbitfield mask) +{ + uint tgsiMask = 0x0; + uint i; + for (i = 0; i < FRAG_ATTRIB_MAX && mask; i++) { + if (mask & (1 << i)) { + tgsiMask |= 1 << tgsi_mesa_translate_fragment_input(i); + } + mask &= ~(1 << i); + } + return tgsiMask; +} + + +uint +tgsi_mesa_translate_fragment_output_mask(GLbitfield mask) +{ + uint tgsiMask = 0x0; + uint i; + for (i = 0; i < FRAG_RESULT_MAX && mask; i++) { + if (mask & (1 << i)) { + tgsiMask |= 1 << tgsi_mesa_translate_fragment_output(i); + } + mask &= ~(1 << i); + } + return tgsiMask; +} + + + + + /* * Map mesa register file to TGSI register file. @@ -290,11 +354,11 @@ map_register_file_index( * color results -> index 1, 2, ... */ if( index == FRAG_RESULT_DEPR ) { - mapped_index = 0; + mapped_index = TGSI_ATTRIB_POS; } else { assert( index == FRAG_RESULT_COLR ); - mapped_index = index + 1; + mapped_index = TGSI_ATTRIB_COLOR0; } } else { diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h index 9256318997..fda3fa397f 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h @@ -19,6 +19,31 @@ tgsi_mesa_compile_vp_program( struct tgsi_token *tokens, GLuint maxTokens ); +uint +tgsi_mesa_translate_vertex_input(GLuint attrib); + +uint +tgsi_mesa_translate_vertex_output(GLuint attrib); + +uint +tgsi_mesa_translate_fragment_input(GLuint attrib); + +uint +tgsi_mesa_translate_fragment_output(GLuint attrib); + +uint +tgsi_mesa_translate_vertex_input_mask(GLbitfield mask); + +uint +tgsi_mesa_translate_vertex_output_mask(GLbitfield mask); + +uint +tgsi_mesa_translate_fragment_input_mask(GLbitfield mask); + +uint +tgsi_mesa_translate_fragment_output_mask(GLbitfield mask); + + #if defined __cplusplus } // extern "C" #endif // defined __cplusplus diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index 019b6457e0..a34a227ac0 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -110,8 +110,10 @@ static void update_fs( struct st_context *st ) /* update pipe state */ memset( &fs, 0, sizeof(fs) ); - fs.inputs_read = fp->Base.Base.InputsRead; - fs.outputs_written = fp->Base.Base.OutputsWritten; + fs.inputs_read + = tgsi_mesa_translate_fragment_input_mask(fp->Base.Base.InputsRead); + fs.outputs_written + = tgsi_mesa_translate_fragment_output_mask(fp->Base.Base.OutputsWritten); fs.tokens = &fp->tokens[0]; if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0 || diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index e3690deb5a..69b985e405 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -348,7 +348,8 @@ clear_with_quad(GLcontext *ctx, stfp = make_color_shader(st); } memset(&fs, 0, sizeof(fs)); - fs.inputs_read = stfp->Base.Base.InputsRead; + fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead); + fs.outputs_written = tgsi_mesa_translate_fragment_output_mask(stfp->Base.Base.OutputsWritten); fs.tokens = &stfp->tokens[0]; pipe->set_fs_state(pipe, &fs); } -- cgit v1.2.3 From def8bb784cf403474eea3b4d25a3262155dc38f2 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 24 Aug 2007 19:36:23 -0600 Subject: code re-org, minor improvements --- src/mesa/state_tracker/st_cb_clear.c | 64 ++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 6 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 69b985e405..fa222df2a4 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -93,6 +93,7 @@ depth_value(GLuint pipeFormat, GLfloat value) val = (GLuint) (value * 0xffffff); break; default: + val = 0; assert(0); } return val; @@ -402,6 +403,52 @@ clear_with_quad(GLcontext *ctx, } +/** + * Determine if we need to clear the depth buffer by drawing a quad. + */ +static INLINE GLboolean +check_clear_color_with_quad(GLcontext *ctx) +{ + return !(ctx->Color.ColorMask[0] && + ctx->Color.ColorMask[1] && + ctx->Color.ColorMask[2] && + ctx->Color.ColorMask[3] && + !ctx->Scissor.Enabled); +} + + +/** + * Determine if we need to clear the depth buffer by drawing a quad. + */ +static INLINE GLboolean +check_clear_depth_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) +{ + const struct st_renderbuffer *strb = st_renderbuffer(rb); + const GLboolean isDS = is_depth_stencil_format(strb->surface->format); + return ctx->Scissor.Enabled + || (isDS && ctx->DrawBuffer->Visual.stencilBits > 0); +} + + +/** + * Determine if we need to clear the stencil buffer by drawing a quad. + */ +static INLINE GLboolean +check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) +{ + const struct st_renderbuffer *strb = st_renderbuffer(rb); + const GLboolean isDS = is_depth_stencil_format(strb->surface->format); + const GLuint stencilMax = (1 << rb->StencilBits) - 1; + const GLboolean maskStencil + = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; + return maskStencil + || ctx->Scissor.Enabled + || (isDS && ctx->DrawBuffer->Visual.depthBits > 0); +} + + + + static void clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { @@ -474,7 +521,8 @@ clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) struct st_renderbuffer *strb = st_renderbuffer(rb); const GLboolean isDS = is_depth_stencil_format(strb->surface->format); const GLuint stencilMax = (1 << rb->StencilBits) - 1; - GLboolean maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; + GLboolean maskStencil + = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; if (maskStencil || ctx->Scissor.Enabled || @@ -494,8 +542,9 @@ static void clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *strb = st_renderbuffer(rb); - const GLuint stencilMax = 1 << rb->StencilBits; - GLboolean maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; + const GLuint stencilMax = (1 << rb->StencilBits) - 1; + GLboolean maskStencil + = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; assert(is_depth_stencil_format(strb->surface->format)); @@ -540,6 +589,7 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; struct gl_renderbuffer *stencilRb = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer; + GLbitfield cmask = mask & BUFFER_BITS_COLOR; /* This makes sure the softpipe has the latest scissor, etc values */ st_validate_state( st ); @@ -552,15 +602,17 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) * color/depth/stencil individually... */ - if (mask & BUFFER_BITS_COLOR) { + if (cmask) { GLuint b; - for (b = 0; b < BUFFER_COUNT; b++) { - if (BUFFER_BITS_COLOR & mask & (1 << b)) { + for (b = 0; cmask; b++) { + if (cmask & (1 << b)) { struct gl_renderbuffer *rb = ctx->DrawBuffer->Attachment[b].Renderbuffer; assert(rb); clear_color_buffer(ctx, rb); + cmask &= ~(1 << b); /* turn off bit */ } + assert(b < BUFFER_COUNT); } } -- cgit v1.2.3 From 9780327c5d95586a88fce94d7b47342355ead118 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Fri, 14 Sep 2007 04:08:58 -0400 Subject: First stab at immutable state objects (create/bind/delete) We want our state objects to be immutable, handled via the create/bind/delete calls instead of struct propagation. Only implementing the blend state to see how it would look like and work. --- src/mesa/cso_cache/cso_cache.c | 176 ++++++++++++++++++++++++ src/mesa/cso_cache/cso_cache.h | 75 ++++++++++ src/mesa/pipe/failover/fo_context.h | 3 +- src/mesa/pipe/failover/fo_state.c | 9 +- src/mesa/pipe/failover/fo_state_emit.c | 2 +- src/mesa/pipe/i915simple/i915_context.h | 3 +- src/mesa/pipe/i915simple/i915_state.c | 29 +++- src/mesa/pipe/i915simple/i915_state_dynamic.c | 14 +- src/mesa/pipe/i915simple/i915_state_immediate.c | 20 +-- src/mesa/pipe/p_context.h | 12 +- src/mesa/pipe/softpipe/sp_context.c | 5 +- src/mesa/pipe/softpipe/sp_context.h | 3 +- src/mesa/pipe/softpipe/sp_quad.c | 4 +- src/mesa/pipe/softpipe/sp_quad_blend.c | 12 +- src/mesa/pipe/softpipe/sp_quad_colormask.c | 8 +- src/mesa/pipe/softpipe/sp_state.h | 10 +- src/mesa/pipe/softpipe/sp_state_blend.c | 19 ++- src/mesa/sources | 4 + src/mesa/state_tracker/st_atom_blend.c | 11 +- src/mesa/state_tracker/st_cb_clear.c | 7 +- src/mesa/state_tracker/st_cb_drawpixels.c | 4 +- src/mesa/state_tracker/st_context.c | 4 + src/mesa/state_tracker/st_context.h | 7 +- 23 files changed, 382 insertions(+), 59 deletions(-) create mode 100644 src/mesa/cso_cache/cso_cache.c create mode 100644 src/mesa/cso_cache/cso_cache.h (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/cso_cache/cso_cache.c b/src/mesa/cso_cache/cso_cache.c new file mode 100644 index 0000000000..bb853308be --- /dev/null +++ b/src/mesa/cso_cache/cso_cache.c @@ -0,0 +1,176 @@ +/************************************************************************** + * + * 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: Zack Rusin + */ + +#include "cso_cache.h" + +#if 1 +static unsigned hash_key( const void *key, unsigned key_size ) +{ + unsigned *ikey = (unsigned *)key; + unsigned hash = 0, i; + + assert(key_size % 4 == 0); + + /* I'm sure this can be improved on: + */ + for (i = 0; i < key_size/4; i++) + hash ^= ikey[i]; + + return hash; +} +#else +static unsigned hash_key(const unsigned char *p, int n) +{ + unsigned h = 0; + unsigned g; + + while (n--) { + h = (h << 4) + *p++; + if ((g = (h & 0xf0000000)) != 0) + h ^= g >> 23; + h &= ~g; + } + return h; +} +#endif + +unsigned cso_construct_key(void *item, int item_size) +{ + return hash_key((const unsigned char*)(item), item_size); +} + +struct cso_cache_item * +cso_insert_state(struct cso_cache *sc, + unsigned hash_key, + void *state, int state_size) +{ + struct cso_cache_item *found_state = + _mesa_HashLookup(sc->hash, hash_key); + struct cso_cache_item *item = + malloc(sizeof(struct cso_cache_item)); + _mesa_printf("inserting state ========= key = %d\n", hash_key); + item->key = hash_key; + item->state_size = state_size; + item->state = state; + item->next = 0; + + if (found_state) { + while (found_state->next) + found_state = found_state->next; + found_state->next = item; + } else + _mesa_HashInsert(sc->hash, hash_key, item); + return item; +} + +struct cso_cache_item * +cso_find_state(struct cso_cache *sc, + unsigned hash_key, + void *state, int state_size) +{ + struct cso_cache_item *found_state = + _mesa_HashLookup(sc->hash, hash_key); + + while (found_state && + (found_state->state_size != state_size || + memcmp(found_state->state, state, state_size))) { + found_state = found_state->next; + } + + _mesa_printf("finding state ========== %d (%p)\n", hash_key, found_state); + return found_state; +} + +struct cso_cache_item * +cso_remove_state(struct cso_cache *sc, + unsigned hash_key, + void *state, int state_size) +{ + struct cso_cache_item *found_state = + _mesa_HashLookup(sc->hash, hash_key); + struct cso_cache_item *prev = 0; + + while (found_state && + (found_state->state_size != state_size || + memcmp(found_state->state, state, state_size))) { + prev = found_state; + found_state = found_state->next; + } + if (found_state) { + if (prev) + prev->next = found_state->next; + else { + if (found_state->next) + _mesa_HashInsert(sc->hash, hash_key, found_state->next); + else + _mesa_HashRemove(sc->hash, hash_key); + } + } + return found_state; +} + +struct cso_cache *cso_cache_create(void) +{ + struct cso_cache *sc = malloc(sizeof(struct cso_cache)); + + sc->hash = _mesa_NewHashTable(); + + return sc; +} + +void cso_cache_destroy(struct cso_cache *sc) +{ + assert(sc); + assert(sc->hash); + _mesa_DeleteHashTable(sc->hash); + free(sc); +} + +/* This function will either find the state of the given template + * in the cache or it will create a new state state from the given + * template, will insert it in the cache and return it. + */ +struct pipe_blend_state * cso_cached_blend_state( + struct st_context *st, + const struct pipe_blend_state *blend) +{ + unsigned hash_key = cso_construct_key((void*)blend, sizeof(struct pipe_blend_state)); + struct cso_cache_item *cache_item = cso_find_state(st->cache, + hash_key, + (void*)blend, + sizeof(struct pipe_blend_state)); + if (!cache_item) { + const struct pipe_blend_state *created_state = st->pipe->create_blend_state( + st->pipe, blend); + cache_item = cso_insert_state(st->cache, hash_key, + (void*)created_state, sizeof(struct pipe_blend_state)); + } + return (struct pipe_blend_state*)cache_item->state; +} diff --git a/src/mesa/cso_cache/cso_cache.h b/src/mesa/cso_cache/cso_cache.h new file mode 100644 index 0000000000..ca0a2d576a --- /dev/null +++ b/src/mesa/cso_cache/cso_cache.h @@ -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: + * Zack Rusin + */ + +#ifndef CSO_CACHE_H +#define CSO_CACHE_H + +#include "state_tracker/st_context.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" + + +#include "main/hash.h" + +struct cso_cache_item { + unsigned key; + + unsigned state_size; + const void *state; + + struct cso_cache_item *next; +}; + +struct cso_cache { + struct _mesa_HashTable *hash; +}; + +void cso_cache_destroy(struct cso_cache *sc); +struct cso_cache *cso_cache_create(void); + +unsigned cso_construct_key(void *item, int item_size); + +struct cso_cache_item *cso_insert_state(struct cso_cache *sc, + unsigned hash_key, + void *state, int state_size); +struct cso_cache_item *cso_find_state(struct cso_cache *sc, + unsigned hash_key, + void *state, int state_size); +struct cso_cache_item *cso_remove_state(struct cso_cache *sc, + unsigned hash_key, + void *state, int state_size); + +struct pipe_blend_state *cso_cached_blend_state( + struct st_context *pipe, + const struct pipe_blend_state *state); + +#endif diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index 5666d4e830..b065aa832a 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -67,8 +67,9 @@ struct failover_context { /* The most recent drawing state as set by the driver: */ + const struct pipe_blend_state *blend; + struct pipe_alpha_test_state alpha_test; - struct pipe_blend_state blend; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index 097acf7d57..2357d7ef5c 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -58,14 +58,14 @@ failover_set_alpha_test_state(struct pipe_context *pipe, static void -failover_set_blend_state( struct pipe_context *pipe, +failover_bind_blend_state( struct pipe_context *pipe, const struct pipe_blend_state *blend ) { struct failover_context *failover = failover_context(pipe); - failover->blend = *blend; + failover->blend = blend; failover->dirty |= FO_NEW_BLEND; - failover->hw->set_blend_state( failover->hw, blend ); + failover->hw->bind_blend_state( failover->hw, blend ); } @@ -266,9 +266,10 @@ failover_set_vertex_element(struct pipe_context *pipe, void failover_init_state_functions( struct failover_context *failover ) { + failover->pipe.bind_blend_state = failover_bind_blend_state; + failover->pipe.set_alpha_test_state = failover_set_alpha_test_state; failover->pipe.set_blend_color = failover_set_blend_color; - failover->pipe.set_blend_state = failover_set_blend_state; failover->pipe.set_clip_state = failover_set_clip_state; failover->pipe.set_clear_color_state = failover_set_clear_color_state; failover->pipe.set_depth_state = failover_set_depth_test_state; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index 52fcf5dbc9..77413d100b 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -59,7 +59,7 @@ failover_state_emit( struct failover_context *failover ) failover->sw->set_alpha_test_state( failover->sw, &failover->alpha_test ); if (failover->dirty & FO_NEW_BLEND) - failover->sw->set_blend_state( failover->sw, &failover->blend ); + failover->sw->bind_blend_state( failover->sw, failover->blend ); if (failover->dirty & FO_NEW_BLEND_COLOR) failover->sw->set_blend_color( failover->sw, &failover->blend_color ); diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index c30c79d83c..215c5294fa 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -123,8 +123,9 @@ struct i915_context /* The most recent drawing state as set by the driver: */ + const struct pipe_blend_state *blend; + struct pipe_alpha_test_state alpha_test; - struct pipe_blend_state blend; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index f5ea721cc8..478988fd4a 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -37,17 +37,37 @@ /* None of this state is actually used for anything yet. */ -static void i915_set_blend_state( struct pipe_context *pipe, + +static const struct pipe_blend_state * +i915_create_blend_state(struct pipe_context *pipe, + const struct pipe_blend_state *blend) +{ + /*struct i915_context *i915 = i915_context(pipe);*/ + + struct pipe_blend_state *new_blend = malloc(sizeof(struct pipe_blend_state)); + memcpy(new_blend, blend, sizeof(struct pipe_blend_state)); + + return new_blend; +} + +static void i915_bind_blend_state( struct pipe_context *pipe, const struct pipe_blend_state *blend ) { struct i915_context *i915 = i915_context(pipe); - i915->blend = *blend; + i915->blend = blend; i915->dirty |= I915_NEW_BLEND; } +static void i915_delete_blend_state( struct pipe_context *pipe, + const struct pipe_blend_state *blend ) +{ + /*struct i915_context *i915 = i915_context(pipe);*/ + free(blend); +} + static void i915_set_blend_color( struct pipe_context *pipe, const struct pipe_blend_color *blend_color ) { @@ -289,9 +309,12 @@ static void i915_set_vertex_element( struct pipe_context *pipe, void i915_init_state_functions( struct i915_context *i915 ) { + i915->pipe.create_blend_state = i915_create_blend_state; + i915->pipe.bind_blend_state = i915_bind_blend_state; + i915->pipe.delete_blend_state = i915_delete_blend_state; + i915->pipe.set_alpha_test_state = i915_set_alpha_test_state; i915->pipe.set_blend_color = i915_set_blend_color; - i915->pipe.set_blend_state = i915_set_blend_state; i915->pipe.set_clip_state = i915_set_clip_state; i915->pipe.set_clear_color_state = i915_set_clear_color_state; i915->pipe.set_constant_buffer = i915_set_constant_buffer; diff --git a/src/mesa/pipe/i915simple/i915_state_dynamic.c b/src/mesa/pipe/i915simple/i915_state_dynamic.c index e648357754..49a30fac11 100644 --- a/src/mesa/pipe/i915simple/i915_state_dynamic.c +++ b/src/mesa/pipe/i915simple/i915_state_dynamic.c @@ -82,7 +82,7 @@ static void upload_MODES4( struct i915_context *i915 ) { modes4 |= (_3DSTATE_MODES_4_CMD | ENABLE_LOGIC_OP_FUNC | - LOGIC_OP_FUNC(i915_translate_logic_op(i915->blend.logicop_func))); + LOGIC_OP_FUNC(i915_translate_logic_op(i915->blend->logicop_func))); } /* Always, so that we know when state is in-active: @@ -204,13 +204,13 @@ static void upload_IAB( struct i915_context *i915 ) unsigned iab = 0; { - unsigned eqRGB = i915->blend.rgb_func; - unsigned srcRGB = i915->blend.rgb_src_factor; - unsigned dstRGB = i915->blend.rgb_dst_factor; + unsigned eqRGB = i915->blend->rgb_func; + unsigned srcRGB = i915->blend->rgb_src_factor; + unsigned dstRGB = i915->blend->rgb_dst_factor; - unsigned eqA = i915->blend.alpha_func; - unsigned srcA = i915->blend.alpha_src_factor; - unsigned dstA = i915->blend.alpha_dst_factor; + unsigned eqA = i915->blend->alpha_func; + unsigned srcA = i915->blend->alpha_src_factor; + unsigned dstA = i915->blend->alpha_dst_factor; /* Special handling for MIN/MAX filter modes handled at * state_tracker level. diff --git a/src/mesa/pipe/i915simple/i915_state_immediate.c b/src/mesa/pipe/i915simple/i915_state_immediate.c index 38a24733e1..aaca534f5a 100644 --- a/src/mesa/pipe/i915simple/i915_state_immediate.c +++ b/src/mesa/pipe/i915simple/i915_state_immediate.c @@ -145,22 +145,22 @@ static void upload_S5( struct i915_context *i915 ) } /* I915_NEW_BLEND */ - if (i915->blend.logicop_enable) + if (i915->blend->logicop_enable) LIS5 |= S5_LOGICOP_ENABLE; - if (i915->blend.dither) + if (i915->blend->dither) LIS5 |= S5_COLOR_DITHER_ENABLE; - if ((i915->blend.colormask & PIPE_MASK_R) == 0) + if ((i915->blend->colormask & PIPE_MASK_R) == 0) LIS5 |= S5_WRITEDISABLE_RED; - if ((i915->blend.colormask & PIPE_MASK_G) == 0) + if ((i915->blend->colormask & PIPE_MASK_G) == 0) LIS5 |= S5_WRITEDISABLE_GREEN; - if ((i915->blend.colormask & PIPE_MASK_B) == 0) + if ((i915->blend->colormask & PIPE_MASK_B) == 0) LIS5 |= S5_WRITEDISABLE_BLUE; - if ((i915->blend.colormask & PIPE_MASK_A) == 0) + if ((i915->blend->colormask & PIPE_MASK_A) == 0) LIS5 |= S5_WRITEDISABLE_ALPHA; @@ -205,11 +205,11 @@ static void upload_S6( struct i915_context *i915 ) /* I915_NEW_BLEND */ - if (i915->blend.blend_enable) + if (i915->blend->blend_enable) { - unsigned funcRGB = i915->blend.rgb_func; - unsigned srcRGB = i915->blend.rgb_src_factor; - unsigned dstRGB = i915->blend.rgb_dst_factor; + unsigned funcRGB = i915->blend->rgb_func; + unsigned srcRGB = i915->blend->rgb_src_factor; + unsigned dstRGB = i915->blend->rgb_dst_factor; LIS6 |= (S6_CBUF_BLEND_ENABLE | SRC_BLND_FACT(i915_translate_blend_factor(srcRGB)) | diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index ec5555c38e..b9af69fc05 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -31,7 +31,7 @@ #include "p_state.h" #include "p_compiler.h" - +struct pipe_state_cache; /** * Software pipeline rendering context. Basically a collection of * state setting functions, plus VBO drawing entrypoint. @@ -85,12 +85,16 @@ struct pipe_context { /* * State functions */ + const struct pipe_blend_state * (*create_blend_state)(struct pipe_context *, + const struct pipe_blend_state *); + void (*bind_blend_state)(struct pipe_context *, + const struct pipe_blend_state *); + void (*delete_blend_state)(struct pipe_context *, + const struct pipe_blend_state *); + void (*set_alpha_test_state)( struct pipe_context *, const struct pipe_alpha_test_state * ); - void (*set_blend_state)( struct pipe_context *, - const struct pipe_blend_state * ); - void (*set_blend_color)( struct pipe_context *, const struct pipe_blend_color * ); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 92357808e2..b9c7013e9e 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -250,9 +250,12 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.max_texture_size = softpipe_max_texture_size; /* state setters */ + softpipe->pipe.create_blend_state = softpipe_create_blend_state; + softpipe->pipe.bind_blend_state = softpipe_bind_blend_state; + softpipe->pipe.delete_blend_state = softpipe_delete_blend_state; + softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state; softpipe->pipe.set_blend_color = softpipe_set_blend_color; - softpipe->pipe.set_blend_state = softpipe_set_blend_state; softpipe->pipe.set_clip_state = softpipe_set_clip_state; softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state; softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 13d1143c89..7fecf2974a 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -71,8 +71,9 @@ struct softpipe_context { /* The most recent drawing state as set by the driver: */ + const struct pipe_blend_state *blend; + struct pipe_alpha_test_state alpha_test; - struct pipe_blend_state blend; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; diff --git a/src/mesa/pipe/softpipe/sp_quad.c b/src/mesa/pipe/softpipe/sp_quad.c index 0f0736479f..2fcbea1f22 100644 --- a/src/mesa/pipe/softpipe/sp_quad.c +++ b/src/mesa/pipe/softpipe/sp_quad.c @@ -11,12 +11,12 @@ sp_build_quad_pipeline(struct softpipe_context *sp) sp->quad.first = sp->quad.output; - if (sp->blend.colormask != 0xf) { + if (sp->blend->colormask != 0xf) { sp->quad.colormask->next = sp->quad.first; sp->quad.first = sp->quad.colormask; } - if (sp->blend.blend_enable) { + if (sp->blend->blend_enable) { sp->quad.blend->next = sp->quad.first; sp->quad.first = sp->quad.blend; } diff --git a/src/mesa/pipe/softpipe/sp_quad_blend.c b/src/mesa/pipe/softpipe/sp_quad_blend.c index e5335f3b19..6c7135e53c 100755 --- a/src/mesa/pipe/softpipe/sp_quad_blend.c +++ b/src/mesa/pipe/softpipe/sp_quad_blend.c @@ -111,7 +111,7 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad) /* * Compute src/first term RGB */ - switch (softpipe->blend.rgb_src_factor) { + switch (softpipe->blend->rgb_src_factor) { case PIPE_BLENDFACTOR_ONE: VEC4_COPY(source[0], quad->outputs.color[0]); /* R */ VEC4_COPY(source[1], quad->outputs.color[1]); /* G */ @@ -253,7 +253,7 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad) /* * Compute src/first term A */ - switch (softpipe->blend.alpha_src_factor) { + switch (softpipe->blend->alpha_src_factor) { case PIPE_BLENDFACTOR_ONE: VEC4_COPY(source[3], quad->outputs.color[3]); /* A */ break; @@ -275,7 +275,7 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad) /* * Compute dest/second term RGB */ - switch (softpipe->blend.rgb_dst_factor) { + switch (softpipe->blend->rgb_dst_factor) { case PIPE_BLENDFACTOR_ONE: /* dest = dest * 1 NO-OP, leave dest as-is */ break; @@ -301,7 +301,7 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad) /* * Compute dest/second term A */ - switch (softpipe->blend.alpha_dst_factor) { + switch (softpipe->blend->alpha_dst_factor) { case PIPE_BLENDFACTOR_ONE: /* dest = dest * 1 NO-OP, leave dest as-is */ break; @@ -323,7 +323,7 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad) /* * Combine RGB terms */ - switch (softpipe->blend.rgb_func) { + switch (softpipe->blend->rgb_func) { case PIPE_BLEND_ADD: VEC4_ADD(quad->outputs.color[0], source[0], dest[0]); /* R */ VEC4_ADD(quad->outputs.color[1], source[1], dest[1]); /* G */ @@ -356,7 +356,7 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad) /* * Combine A terms */ - switch (softpipe->blend.alpha_func) { + switch (softpipe->blend->alpha_func) { case PIPE_BLEND_ADD: VEC4_ADD(quad->outputs.color[3], source[3], dest[3]); /* A */ break; diff --git a/src/mesa/pipe/softpipe/sp_quad_colormask.c b/src/mesa/pipe/softpipe/sp_quad_colormask.c index 7bb65bf8c8..c3e110532a 100644 --- a/src/mesa/pipe/softpipe/sp_quad_colormask.c +++ b/src/mesa/pipe/softpipe/sp_quad_colormask.c @@ -49,19 +49,19 @@ colormask_quad(struct quad_stage *qs, struct quad_header *quad) sps->read_quad_f_swz(sps, quad->x0, quad->y0, dest); /* R */ - if (!(softpipe->blend.colormask & PIPE_MASK_R)) + if (!(softpipe->blend->colormask & PIPE_MASK_R)) COPY_4V(quad->outputs.color[0], dest[0]); /* G */ - if (!(softpipe->blend.colormask & PIPE_MASK_G)) + if (!(softpipe->blend->colormask & PIPE_MASK_G)) COPY_4V(quad->outputs.color[1], dest[1]); /* B */ - if (!(softpipe->blend.colormask & PIPE_MASK_B)) + if (!(softpipe->blend->colormask & PIPE_MASK_B)) COPY_4V(quad->outputs.color[2], dest[2]); /* A */ - if (!(softpipe->blend.colormask & PIPE_MASK_A)) + if (!(softpipe->blend->colormask & PIPE_MASK_A)) COPY_4V(quad->outputs.color[3], dest[3]); /* pass quad to next stage */ diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index f40ebe3e2b..e2b1a2a164 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -33,6 +33,13 @@ #include "pipe/p_state.h" +const struct pipe_blend_state * +softpipe_create_blend_state(struct pipe_context *, + const struct pipe_blend_state *); +void softpipe_bind_blend_state(struct pipe_context *, + const struct pipe_blend_state *); +void softpipe_delete_blend_state(struct pipe_context *, + const struct pipe_blend_state *); void softpipe_set_framebuffer_state( struct pipe_context *, const struct pipe_framebuffer_state * ); @@ -40,9 +47,6 @@ void softpipe_set_framebuffer_state( struct pipe_context *, void softpipe_set_alpha_test_state( struct pipe_context *, const struct pipe_alpha_test_state * ); -void softpipe_set_blend_state( struct pipe_context *, - const struct pipe_blend_state * ); - void softpipe_set_blend_color( struct pipe_context *pipe, const struct pipe_blend_color *blend_color ); diff --git a/src/mesa/pipe/softpipe/sp_state_blend.c b/src/mesa/pipe/softpipe/sp_state_blend.c index b2e85d86cc..57f2df7923 100644 --- a/src/mesa/pipe/softpipe/sp_state_blend.c +++ b/src/mesa/pipe/softpipe/sp_state_blend.c @@ -30,17 +30,32 @@ #include "sp_context.h" #include "sp_state.h" +const struct pipe_blend_state * +softpipe_create_blend_state(struct pipe_context *pipe, + const struct pipe_blend_state *blend) +{ + struct pipe_blend_state *new_blend = malloc(sizeof(struct pipe_blend_state)); + memcpy(new_blend, blend, sizeof(struct pipe_blend_state)); + + return new_blend; +} -void softpipe_set_blend_state( struct pipe_context *pipe, +void softpipe_bind_blend_state( struct pipe_context *pipe, const struct pipe_blend_state *blend ) { struct softpipe_context *softpipe = softpipe_context(pipe); - softpipe->blend = *blend; + softpipe->blend = blend; softpipe->dirty |= SP_NEW_BLEND; } +void softpipe_delete_blend_state(struct pipe_context *pipe, + const struct pipe_blend_state *blend ) +{ + free(blend); +} + void softpipe_set_blend_color( struct pipe_context *pipe, const struct pipe_blend_color *blend_color ) diff --git a/src/mesa/sources b/src/mesa/sources index ec561294c5..e57942d664 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -186,6 +186,9 @@ TGSIDECO_SOURCES = \ TGSIMESA_SOURCES = \ pipe/tgsi/mesa/mesa_to_tgsi.c +STATECACHE_SOURCES = \ + cso_cache/cso_cache.c + STATETRACKER_SOURCES = \ state_tracker/st_atom.c \ state_tracker/st_atom_alphatest.c \ @@ -373,6 +376,7 @@ SOLO_SOURCES = \ $(TGSIEXEC_SOURCES) \ $(TGSIDECO_SOURCES) \ $(TGSIMESA_SOURCES) \ + $(STATECACHE_SOURCES) \ $(STATETRACKER_SOURCES) \ $(TNL_SOURCES) \ $(SHADER_SOURCES) \ diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c index afd21a6141..d007d50ad3 100644 --- a/src/mesa/state_tracker/st_atom_blend.c +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -36,6 +36,7 @@ #include "st_atom.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "cso_cache/cso_cache.h" /** @@ -209,10 +210,14 @@ update_blend( struct st_context *st ) if (st->ctx->Color.DitherFlag) blend.dither = 1; - if (memcmp(&blend, &st->state.blend, sizeof(blend)) != 0) { + struct pipe_blend_state *real_blend = + cso_cached_blend_state(st, &blend); + + if (st->state.blend != real_blend) { /* state has changed */ - st->state.blend = blend; /* struct copy */ - st->pipe->set_blend_state(st->pipe, &blend); /* set new state */ + st->state.blend = real_blend; + /* bind new state */ + st->pipe->bind_blend_state(st->pipe, real_blend); } if (memcmp(st->ctx->Color.BlendColor, &st->state.blend_color, 4 * sizeof(GLfloat)) != 0) { diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index fa222df2a4..dc8a84af08 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -49,6 +49,8 @@ #include "pipe/tgsi/mesa/mesa_to_tgsi.h" +#include "cso_cache/cso_cache.h" + #include "vf/vf.h" @@ -295,7 +297,8 @@ clear_with_quad(GLcontext *ctx, if (st->ctx->Color.DitherFlag) blend.dither = 1; } - pipe->set_blend_state(pipe, &blend); + const struct pipe_blend_state *state = cso_cached_blend_state(st, &blend); + pipe->bind_blend_state(pipe, state); } /* depth state: always pass */ @@ -390,7 +393,7 @@ clear_with_quad(GLcontext *ctx, /* Restore pipe state */ pipe->set_alpha_test_state(pipe, &st->state.alpha_test); - pipe->set_blend_state(pipe, &st->state.blend); + pipe->bind_blend_state(pipe, st->state.blend); pipe->set_depth_state(pipe, &st->state.depth); pipe->set_fs_state(pipe, &st->state.fs); pipe->set_vs_state(pipe, &st->state.vs); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index e2280cdafa..c2d231cdb5 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -474,8 +474,8 @@ static GLboolean any_fragment_ops(const struct st_context *st) { if (st->state.alpha_test.enabled || - st->state.blend.blend_enable || - st->state.blend.logicop_enable || + st->state.blend->blend_enable || + st->state.blend->logicop_enable || st->state.depth.enabled) /* XXX more checks */ return GL_TRUE; diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 6ab643f1fe..26815d5cd4 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -45,6 +45,7 @@ #include "st_program.h" #include "pipe/p_context.h" #include "pipe/draw/draw_context.h" +#include "cso_cache/cso_cache.h" void st_invalidate_state(GLcontext * ctx, GLuint new_state) @@ -71,6 +72,8 @@ struct st_context *st_create_context( GLcontext *ctx, st->dirty.mesa = ~0; st->dirty.st = ~0; + st->cache = cso_cache_create(); + st_init_atoms( st ); st_init_draw( st ); @@ -112,6 +115,7 @@ void st_destroy_context( struct st_context *st ) /*st_destroy_cb_teximage( st );*/ st_destroy_cb_texture( st ); #endif + cso_cache_destroy( st->cache ); st->pipe->destroy( st->pipe ); FREE( st ); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 56cae7d973..bd2efdb960 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -39,7 +39,7 @@ struct st_texture_image; struct st_fragment_program; struct draw_context; struct draw_stage; - +struct cso_cache; #define ST_NEW_MESA 0x1 /* Mesa state has changed */ #define ST_NEW_FRAGMENT_PROGRAM 0x2 @@ -74,8 +74,9 @@ struct st_context * though, we just shove random objects across the interface. */ struct { + const struct pipe_blend_state *blend; + struct pipe_alpha_test_state alpha_test; - struct pipe_blend_state blend; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; @@ -122,6 +123,8 @@ struct st_context struct st_fragment_program *fp; struct pipe_buffer_handle *default_attrib_buffer; + + struct cso_cache *cache; }; -- cgit v1.2.3 From e16c045b83f5c5b4f4064df67623bb76b46b6619 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 17 Sep 2007 07:56:56 -0400 Subject: Implementing a better hash, removing state_tracker dependency from the cache. Replacing mesa's main hash with one that handles collisions, moving state_tracker related caching to the state tracker to keep cso cache independent of it. Cleanups. --- src/mesa/cso_cache/cso_cache.c | 139 +++++------- src/mesa/cso_cache/cso_cache.h | 43 ++-- src/mesa/cso_cache/cso_hash.c | 381 +++++++++++++++++++++++++++++++++ src/mesa/cso_cache/cso_hash.h | 62 ++++++ src/mesa/sources | 2 + src/mesa/state_tracker/st_atom_blend.c | 5 +- src/mesa/state_tracker/st_cache.c | 61 ++++++ src/mesa/state_tracker/st_cache.h | 43 ++++ src/mesa/state_tracker/st_cb_clear.c | 5 +- src/mesa/state_tracker/st_context.c | 2 +- 10 files changed, 627 insertions(+), 116 deletions(-) create mode 100644 src/mesa/cso_cache/cso_hash.c create mode 100644 src/mesa/cso_cache/cso_hash.h create mode 100644 src/mesa/state_tracker/st_cache.c create mode 100644 src/mesa/state_tracker/st_cache.h (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/cso_cache/cso_cache.c b/src/mesa/cso_cache/cso_cache.c index bb853308be..784d1f970f 100644 --- a/src/mesa/cso_cache/cso_cache.c +++ b/src/mesa/cso_cache/cso_cache.c @@ -29,9 +29,10 @@ */ #include "cso_cache.h" +#include "cso_hash.h" #if 1 -static unsigned hash_key( const void *key, unsigned key_size ) +static unsigned hash_key(const void *key, unsigned key_size) { unsigned *ikey = (unsigned *)key; unsigned hash = 0, i; @@ -63,114 +64,84 @@ static unsigned hash_key(const unsigned char *p, int n) unsigned cso_construct_key(void *item, int item_size) { - return hash_key((const unsigned char*)(item), item_size); + return hash_key((item), item_size); } -struct cso_cache_item * +static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_type type) +{ + struct cso_hash *hash = 0; + + switch(type) { + case CSO_BLEND: + hash = sc->blend_hash; + } + + return hash; +} + +static int _cso_size_for_type(enum cso_cache_type type) +{ + switch(type) { + case CSO_BLEND: + return sizeof(struct pipe_blend_state); + } + return 0; +} + +struct cso_hash_iter cso_insert_state(struct cso_cache *sc, - unsigned hash_key, - void *state, int state_size) + unsigned hash_key, enum cso_cache_type type, + void *state) { - struct cso_cache_item *found_state = - _mesa_HashLookup(sc->hash, hash_key); - struct cso_cache_item *item = - malloc(sizeof(struct cso_cache_item)); - _mesa_printf("inserting state ========= key = %d\n", hash_key); - item->key = hash_key; - item->state_size = state_size; - item->state = state; - item->next = 0; - - if (found_state) { - while (found_state->next) - found_state = found_state->next; - found_state->next = item; - } else - _mesa_HashInsert(sc->hash, hash_key, item); - return item; + struct cso_hash *hash = _cso_hash_for_type(sc, type); + return cso_hash_insert(hash, hash_key, state); } -struct cso_cache_item * +struct cso_hash_iter cso_find_state(struct cso_cache *sc, - unsigned hash_key, - void *state, int state_size) + unsigned hash_key, enum cso_cache_type type) { - struct cso_cache_item *found_state = - _mesa_HashLookup(sc->hash, hash_key); + struct cso_hash *hash = _cso_hash_for_type(sc, type); - while (found_state && - (found_state->state_size != state_size || - memcmp(found_state->state, state, state_size))) { - found_state = found_state->next; - } - - _mesa_printf("finding state ========== %d (%p)\n", hash_key, found_state); - return found_state; + return cso_hash_find(hash, hash_key); } -struct cso_cache_item * -cso_remove_state(struct cso_cache *sc, - unsigned hash_key, - void *state, int state_size) +struct cso_hash_iter cso_find_state_template(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type, + void *templ) { - struct cso_cache_item *found_state = - _mesa_HashLookup(sc->hash, hash_key); - struct cso_cache_item *prev = 0; - - while (found_state && - (found_state->state_size != state_size || - memcmp(found_state->state, state, state_size))) { - prev = found_state; - found_state = found_state->next; - } - if (found_state) { - if (prev) - prev->next = found_state->next; - else { - if (found_state->next) - _mesa_HashInsert(sc->hash, hash_key, found_state->next); - else - _mesa_HashRemove(sc->hash, hash_key); - } + struct cso_hash_iter iter = cso_find_state(sc, hash_key, type); + int size = _cso_size_for_type(type); + while (!cso_hash_iter_is_null(iter)) { + void *iter_data = cso_hash_iter_data(iter); + if (!memcmp(iter_data, templ, size)) + return iter; + iter = cso_hash_iter_next(iter); } - return found_state; + return iter; +} + +void * cso_take_state(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type) +{ + struct cso_hash *hash = _cso_hash_for_type(sc, type); + return cso_hash_take(hash, hash_key); } struct cso_cache *cso_cache_create(void) { struct cso_cache *sc = malloc(sizeof(struct cso_cache)); - sc->hash = _mesa_NewHashTable(); + sc->blend_hash = cso_hash_create(); return sc; } -void cso_cache_destroy(struct cso_cache *sc) +void cso_cache_delete(struct cso_cache *sc) { assert(sc); - assert(sc->hash); - _mesa_DeleteHashTable(sc->hash); + assert(sc->blend_hash); + cso_hash_delete(sc->blend_hash); free(sc); } -/* This function will either find the state of the given template - * in the cache or it will create a new state state from the given - * template, will insert it in the cache and return it. - */ -struct pipe_blend_state * cso_cached_blend_state( - struct st_context *st, - const struct pipe_blend_state *blend) -{ - unsigned hash_key = cso_construct_key((void*)blend, sizeof(struct pipe_blend_state)); - struct cso_cache_item *cache_item = cso_find_state(st->cache, - hash_key, - (void*)blend, - sizeof(struct pipe_blend_state)); - if (!cache_item) { - const struct pipe_blend_state *created_state = st->pipe->create_blend_state( - st->pipe, blend); - cache_item = cso_insert_state(st->cache, hash_key, - (void*)created_state, sizeof(struct pipe_blend_state)); - } - return (struct pipe_blend_state*)cache_item->state; -} diff --git a/src/mesa/cso_cache/cso_cache.h b/src/mesa/cso_cache/cso_cache.h index ca0a2d576a..c022b98d43 100644 --- a/src/mesa/cso_cache/cso_cache.h +++ b/src/mesa/cso_cache/cso_cache.h @@ -33,43 +33,34 @@ #ifndef CSO_CACHE_H #define CSO_CACHE_H -#include "state_tracker/st_context.h" #include "pipe/p_context.h" #include "pipe/p_state.h" -#include "main/hash.h" - -struct cso_cache_item { - unsigned key; - - unsigned state_size; - const void *state; - - struct cso_cache_item *next; -}; +struct cso_hash; struct cso_cache { - struct _mesa_HashTable *hash; + struct cso_hash *blend_hash; }; -void cso_cache_destroy(struct cso_cache *sc); -struct cso_cache *cso_cache_create(void); +enum cso_cache_type { + CSO_BLEND, +}; unsigned cso_construct_key(void *item, int item_size); -struct cso_cache_item *cso_insert_state(struct cso_cache *sc, - unsigned hash_key, - void *state, int state_size); -struct cso_cache_item *cso_find_state(struct cso_cache *sc, - unsigned hash_key, - void *state, int state_size); -struct cso_cache_item *cso_remove_state(struct cso_cache *sc, - unsigned hash_key, - void *state, int state_size); +struct cso_cache *cso_cache_create(void); +void cso_cache_delete(struct cso_cache *sc); -struct pipe_blend_state *cso_cached_blend_state( - struct st_context *pipe, - const struct pipe_blend_state *state); +struct cso_hash_iter cso_insert_state(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type, + void *state); +struct cso_hash_iter cso_find_state(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type); +struct cso_hash_iter cso_find_state_template(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type, + void *templ); +void * cso_take_state(struct cso_cache *sc, unsigned hash_key, + enum cso_cache_type type); #endif diff --git a/src/mesa/cso_cache/cso_hash.c b/src/mesa/cso_cache/cso_hash.c new file mode 100644 index 0000000000..fe033c9e91 --- /dev/null +++ b/src/mesa/cso_cache/cso_hash.c @@ -0,0 +1,381 @@ +/************************************************************************** + * + * 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: + * Zack Rusin + */ + +#include "cso_hash.h" + +#include +#include +#include +#include + +#define MAX(a, b) ((a > b) ? (a) : (b)) + +static const int MinNumBits = 4; + +static const unsigned char prime_deltas[] = { + 0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 9, 25, 3, + 1, 21, 3, 21, 7, 15, 9, 5, 3, 29, 15, 0, 0, 0, 0, 0 +}; + +static int primeForNumBits(int numBits) +{ + return (1 << numBits) + prime_deltas[numBits]; +} + +/* + Returns the smallest integer n such that + primeForNumBits(n) >= hint. +*/ +static int countBits(int hint) +{ + int numBits = 0; + int bits = hint; + + while (bits > 1) { + bits >>= 1; + numBits++; + } + + if (numBits >= (int)sizeof(prime_deltas)) { + numBits = sizeof(prime_deltas) - 1; + } else if (primeForNumBits(numBits) < hint) { + ++numBits; + } + return numBits; +} + +struct cso_node { + struct cso_node *next; + unsigned key; + void *value; +}; + +struct cso_hash_data { + struct cso_node *fakeNext; + struct cso_node **buckets; + int size; + int nodeSize; + short userNumBits; + short numBits; + int numBuckets; +}; + +struct cso_hash { + union { + struct cso_hash_data *d; + struct cso_node *e; + } data; +}; + +static void *cso_data_allocate_node(struct cso_hash_data *hash) +{ + return malloc(hash->nodeSize); +} + +static void cso_data_free_node(void *node) +{ + free(node); +} + +static struct cso_node * +cso_hash_create_node(struct cso_hash *hash, + unsigned akey, void *avalue, + struct cso_node **anextNode) +{ + struct cso_node *node = cso_data_allocate_node(hash->data.d); + node->key = akey; + node->value = avalue; + + node->next = (struct cso_node*)(*anextNode); + *anextNode = node; + ++hash->data.d->size; + return node; +} + +static void cso_data_rehash(struct cso_hash_data *hash, int hint) +{ + if (hint < 0) { + hint = countBits(-hint); + if (hint < MinNumBits) + hint = MinNumBits; + hash->userNumBits = hint; + while (primeForNumBits(hint) < (hash->size >> 1)) + ++hint; + } else if (hint < MinNumBits) { + hint = MinNumBits; + } + + if (hash->numBits != hint) { + struct cso_node *e = (struct cso_node *)(hash); + struct cso_node **oldBuckets = hash->buckets; + int oldNumBuckets = hash->numBuckets; + int i = 0; + + hash->numBits = hint; + hash->numBuckets = primeForNumBits(hint); + hash->buckets = malloc(sizeof(struct cso_node*) * hash->numBuckets); + for (i = 0; i < hash->numBuckets; ++i) + hash->buckets[i] = e; + + for (i = 0; i < oldNumBuckets; ++i) { + struct cso_node *firstNode = oldBuckets[i]; + while (firstNode != e) { + unsigned h = firstNode->key; + struct cso_node *lastNode = firstNode; + while (lastNode->next != e && lastNode->next->key == h) + lastNode = lastNode->next; + + struct cso_node *afterLastNode = lastNode->next; + struct cso_node **beforeFirstNode = &hash->buckets[h % hash->numBuckets]; + while (*beforeFirstNode != e) + beforeFirstNode = &(*beforeFirstNode)->next; + lastNode->next = *beforeFirstNode; + *beforeFirstNode = firstNode; + firstNode = afterLastNode; + } + } + free(oldBuckets); + } +} + +static void cso_data_might_grow(struct cso_hash_data *hash) +{ + if (hash->size >= hash->numBuckets) + cso_data_rehash(hash, hash->numBits + 1); +} + +static void cso_data_has_shrunk(struct cso_hash_data *hash) +{ + if (hash->size <= (hash->numBuckets >> 3) && + hash->numBits > hash->userNumBits) { + int max = MAX(hash->numBits-2, hash->userNumBits); + cso_data_rehash(hash, max); + } +} + +static struct cso_node *cso_data_first_node(struct cso_hash_data *hash) +{ + struct cso_node *e = (struct cso_node *)(hash); + struct cso_node **bucket = hash->buckets; + int n = hash->numBuckets; + while (n--) { + if (*bucket != e) + return *bucket; + ++bucket; + } + return e; +} + +static struct cso_node **cso_hash_find_node(struct cso_hash *hash, unsigned akey) +{ + struct cso_node **node; + + if (hash->data.d->numBuckets) { + node = (struct cso_node **)(&hash->data.d->buckets[akey % hash->data.d->numBuckets]); + assert(*node == hash->data.e || (*node)->next); + while (*node != hash->data.e && (*node)->key != akey) + node = &(*node)->next; + } else { + node = (struct cso_node **)((const struct cso_node * const *)(&hash->data.e)); + } + return node; +} + +struct cso_hash_iter cso_hash_insert(struct cso_hash *hash, + unsigned key, void *data) +{ + cso_data_might_grow(hash->data.d); + + struct cso_node **nextNode = cso_hash_find_node(hash, key); + struct cso_node *node = cso_hash_create_node(hash, key, data, nextNode); + struct cso_hash_iter iter = {hash, node}; + return iter; +} + +struct cso_hash * cso_hash_create(void) +{ + struct cso_hash *hash = malloc(sizeof(struct cso_hash)); + hash->data.d = malloc(sizeof(struct cso_hash_data)); + hash->data.d->fakeNext = 0; + hash->data.d->buckets = 0; + hash->data.d->size = 0; + hash->data.d->nodeSize = sizeof(struct cso_node); + hash->data.d->userNumBits = MinNumBits; + hash->data.d->numBits = 0; + hash->data.d->numBuckets = 0; + + return hash; +} + +void cso_hash_delete(struct cso_hash *hash) +{ + struct cso_node *e_for_x = (struct cso_node *)(hash->data.d); + struct cso_node **bucket = (struct cso_node **)(hash->data.d->buckets); + int n = hash->data.d->numBuckets; + while (n--) { + struct cso_node *cur = *bucket++; + while (cur != e_for_x) { + struct cso_node *next = cur->next; + cso_data_free_node(cur); + cur = next; + } + } + free(hash->data.d->buckets); + free(hash->data.d); + free(hash); +} + +struct cso_hash_iter cso_hash_find(struct cso_hash *hash, + unsigned key) +{ + struct cso_node **nextNode = cso_hash_find_node(hash, key); + struct cso_hash_iter iter = {hash, *nextNode}; + return iter; +} + +unsigned cso_hash_iter_key(struct cso_hash_iter iter) +{ + if (!iter.node || iter.hash->data.e == iter.node) + return 0; + return iter.node->key; +} + +void * cso_hash_iter_data(struct cso_hash_iter iter) +{ + if (!iter.node || iter.hash->data.e == iter.node) + return 0; + return iter.node->value; +} + +static struct cso_node *cso_hash_data_next(struct cso_node *node) +{ + union { + struct cso_node *next; + struct cso_node *e; + struct cso_hash_data *d; + } a; + a.next = node->next; + if (!a.next) { + fprintf(stderr, "iterating beyond the last element\n"); + return 0; + } + if (a.next->next) + return a.next; + + int start = (node->key % a.d->numBuckets) + 1; + struct cso_node **bucket = a.d->buckets + start; + int n = a.d->numBuckets - start; + while (n--) { + if (*bucket != a.e) + return *bucket; + ++bucket; + } + return a.e; +} + + +static struct cso_node *cso_hash_data_prev(struct cso_node *node) +{ + union { + struct cso_node *e; + struct cso_hash_data *d; + } a; + + a.e = node; + while (a.e->next) + a.e = a.e->next; + + int start; + if (node == a.e) + start = a.d->numBuckets - 1; + else + start = node->key % a.d->numBuckets; + + struct cso_node *sentinel = node; + struct cso_node **bucket = a.d->buckets + start; + while (start >= 0) { + if (*bucket != sentinel) { + struct cso_node *prev = *bucket; + while (prev->next != sentinel) + prev = prev->next; + return prev; + } + + sentinel = a.e; + --bucket; + --start; + } + fprintf(stderr, "iterating backward beyond first element\n"); + return a.e; +} + +struct cso_hash_iter cso_hash_iter_next(struct cso_hash_iter iter) +{ + struct cso_hash_iter next = {iter.hash, cso_hash_data_next(iter.node)}; + return next; +} + +int cso_hash_iter_is_null(struct cso_hash_iter iter) +{ + if (!iter.node || iter.node == iter.hash->data.e) + return 1; + return 0; +} + +void * cso_hash_take(struct cso_hash *hash, + unsigned akey) +{ + struct cso_node **node = cso_hash_find_node(hash, akey); + if (*node != hash->data.e) { + void *t = (*node)->value; + struct cso_node *next = (*node)->next; + cso_data_free_node(*node); + *node = next; + --hash->data.d->size; + cso_data_has_shrunk(hash->data.d); + return t; + } + return 0; +} + +struct cso_hash_iter cso_hash_iter_prev(struct cso_hash_iter iter) +{ + struct cso_hash_iter prev = {iter.hash, + cso_hash_data_prev(iter.node)}; + return prev; +} + +struct cso_hash_iter cso_hash_first_node(struct cso_hash *hash) +{ + struct cso_hash_iter iter = {hash, cso_data_first_node(hash->data.d)}; + return iter; +} diff --git a/src/mesa/cso_cache/cso_hash.h b/src/mesa/cso_cache/cso_hash.h new file mode 100644 index 0000000000..b4aa111860 --- /dev/null +++ b/src/mesa/cso_cache/cso_hash.h @@ -0,0 +1,62 @@ +/************************************************************************** + * + * 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: + * Zack Rusin + */ + +#ifndef CSO_HASH_H +#define CSO_HASH_H + +struct cso_hash; +struct cso_node; + +struct cso_hash_iter { + struct cso_hash *hash; + struct cso_node *node; +}; + +struct cso_hash *cso_hash_create(void); +void cso_hash_delete(struct cso_hash *hash); + +struct cso_hash_iter cso_hash_insert(struct cso_hash *hash, unsigned key, + void *data); +void *cso_hash_take(struct cso_hash *hash, unsigned key); + +struct cso_hash_iter cso_hash_first_node(struct cso_hash *hash); +struct cso_hash_iter cso_hash_find(struct cso_hash *hash, unsigned key); + + +int cso_hash_iter_is_null(struct cso_hash_iter iter); +unsigned cso_hash_iter_key(struct cso_hash_iter iter); +void *cso_hash_iter_data(struct cso_hash_iter iter); + +struct cso_hash_iter cso_hash_iter_next(struct cso_hash_iter iter); +struct cso_hash_iter cso_hash_iter_prev(struct cso_hash_iter iter); + +#endif diff --git a/src/mesa/sources b/src/mesa/sources index e57942d664..90fa5c65bf 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -187,6 +187,7 @@ TGSIMESA_SOURCES = \ pipe/tgsi/mesa/mesa_to_tgsi.c STATECACHE_SOURCES = \ + cso_cache/cso_hash.c \ cso_cache/cso_cache.c STATETRACKER_SOURCES = \ @@ -220,6 +221,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_cb_readpixels.c \ state_tracker/st_cb_strings.c \ state_tracker/st_cb_texture.c \ + state_tracker/st_cache.c \ state_tracker/st_context.c \ state_tracker/st_draw.c \ state_tracker/st_format.c \ diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c index d007d50ad3..d94beb66c7 100644 --- a/src/mesa/state_tracker/st_atom_blend.c +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -33,10 +33,11 @@ #include "st_context.h" +#include "st_cache.h" #include "st_atom.h" + #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "cso_cache/cso_cache.h" /** @@ -211,7 +212,7 @@ update_blend( struct st_context *st ) blend.dither = 1; struct pipe_blend_state *real_blend = - cso_cached_blend_state(st, &blend); + st_cached_blend_state(st, &blend); if (st->state.blend != real_blend) { /* state has changed */ diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c new file mode 100644 index 0000000000..0205b1cab3 --- /dev/null +++ b/src/mesa/state_tracker/st_cache.c @@ -0,0 +1,61 @@ +/************************************************************************** + * + * 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: + * Zack Rusin + */ + +#include "st_cache.h" + +#include "st_context.h" + +#include "pipe/p_state.h" + +#include "cso_cache/cso_cache.h" +#include "cso_cache/cso_hash.h" + +/* This function will either find the state of the given template + * in the cache or it will create a new state state from the given + * template, will insert it in the cache and return it. + */ +struct pipe_blend_state * st_cached_blend_state( + struct st_context *st, + const struct pipe_blend_state *blend) +{ + unsigned hash_key = cso_construct_key((void*)blend, sizeof(struct pipe_blend_state)); + struct cso_hash_iter iter = cso_find_state_template(st->cache, + hash_key, CSO_BLEND, + (void*)blend); + if (cso_hash_iter_is_null(iter)) { + const struct pipe_blend_state *created_state = st->pipe->create_blend_state( + st->pipe, blend); + iter = cso_insert_state(st->cache, hash_key, CSO_BLEND, + (void*)created_state); + } + return (struct pipe_blend_state*)(cso_hash_iter_data(iter)); +} diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h new file mode 100644 index 0000000000..29b1d00dca --- /dev/null +++ b/src/mesa/state_tracker/st_cache.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. + * + **************************************************************************/ + + /* + * Authors: + * Zack Rusin + */ + +#ifndef ST_CACHE_H +#define ST_CACHE_H + +struct pipe_blend_state; +struct st_context; + +struct pipe_blend_state * st_cached_blend_state( + struct st_context *st, + const struct pipe_blend_state *blend); + +#endif diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index dc8a84af08..55e03f644e 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -35,6 +35,7 @@ #include "main/macros.h" #include "shader/prog_instruction.h" #include "st_atom.h" +#include "st_cache.h" #include "st_context.h" #include "st_cb_clear.h" #include "st_cb_fbo.h" @@ -49,8 +50,6 @@ #include "pipe/tgsi/mesa/mesa_to_tgsi.h" -#include "cso_cache/cso_cache.h" - #include "vf/vf.h" @@ -297,7 +296,7 @@ clear_with_quad(GLcontext *ctx, if (st->ctx->Color.DitherFlag) blend.dither = 1; } - const struct pipe_blend_state *state = cso_cached_blend_state(st, &blend); + const struct pipe_blend_state *state = st_cached_blend_state(st, &blend); pipe->bind_blend_state(pipe, state); } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 26815d5cd4..f9717465f4 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -115,7 +115,7 @@ void st_destroy_context( struct st_context *st ) /*st_destroy_cb_teximage( st );*/ st_destroy_cb_texture( st ); #endif - cso_cache_destroy( st->cache ); + cso_cache_delete( st->cache ); st->pipe->destroy( st->pipe ); FREE( st ); -- cgit v1.2.3 From d6ac959833a8e40a27907940969c622692f749b1 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 17 Sep 2007 11:55:18 -0400 Subject: Combing depth and stencil objects and making them immutable. Converting depth and stencil objects into a single state object (d3d10 like) and making it immutable. --- src/mesa/cso_cache/cso_cache.c | 6 + src/mesa/cso_cache/cso_cache.h | 4 +- src/mesa/pipe/failover/fo_context.h | 40 ++++--- src/mesa/pipe/failover/fo_state.c | 25 +---- src/mesa/pipe/failover/fo_state_emit.c | 7 +- src/mesa/pipe/i915simple/i915_context.h | 22 ++-- src/mesa/pipe/i915simple/i915_state.c | 44 +++++--- src/mesa/pipe/i915simple/i915_state_dynamic.c | 24 ++-- src/mesa/pipe/i915simple/i915_state_immediate.c | 22 ++-- src/mesa/pipe/p_context.h | 14 ++- src/mesa/pipe/p_state.h | 48 ++++---- src/mesa/pipe/softpipe/sp_context.c | 5 +- src/mesa/pipe/softpipe/sp_context.h | 26 ++--- src/mesa/pipe/softpipe/sp_quad.c | 8 +- src/mesa/pipe/softpipe/sp_quad_depth_test.c | 4 +- src/mesa/pipe/softpipe/sp_quad_fs.c | 2 +- src/mesa/pipe/softpipe/sp_quad_stencil.c | 32 +++--- src/mesa/pipe/softpipe/sp_state.h | 15 ++- src/mesa/pipe/softpipe/sp_state_blend.c | 34 +++--- src/mesa/pipe/softpipe/sp_state_derived.c | 7 +- src/mesa/sources | 1 - src/mesa/state_tracker/st_atom.c | 3 +- src/mesa/state_tracker/st_atom.h | 3 +- src/mesa/state_tracker/st_atom_depth.c | 108 +++++++++++++++--- src/mesa/state_tracker/st_atom_stencil.c | 141 ------------------------ src/mesa/state_tracker/st_cache.c | 17 +++ src/mesa/state_tracker/st_cache.h | 3 + src/mesa/state_tracker/st_cb_clear.c | 51 ++++----- src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_context.h | 3 +- 30 files changed, 337 insertions(+), 384 deletions(-) delete mode 100644 src/mesa/state_tracker/st_atom_stencil.c (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/cso_cache/cso_cache.c b/src/mesa/cso_cache/cso_cache.c index 61da590575..a4730394f8 100644 --- a/src/mesa/cso_cache/cso_cache.c +++ b/src/mesa/cso_cache/cso_cache.c @@ -76,6 +76,8 @@ static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_ hash = sc->blend_hash; case CSO_SAMPLER: hash = sc->sampler_hash; + case CSO_DEPTH_STENCIL: + hash = sc->depth_stencil_hash; } return hash; @@ -88,6 +90,8 @@ static int _cso_size_for_type(enum cso_cache_type type) return sizeof(struct pipe_blend_state); case CSO_SAMPLER: return sizeof(struct pipe_sampler_state); + case CSO_DEPTH_STENCIL: + return sizeof(struct pipe_depth_stencil_state); } return 0; } @@ -138,6 +142,7 @@ struct cso_cache *cso_cache_create(void) sc->blend_hash = cso_hash_create(); sc->sampler_hash = cso_hash_create(); + sc->depth_stencil_hash = cso_hash_create(); return sc; } @@ -147,6 +152,7 @@ void cso_cache_delete(struct cso_cache *sc) assert(sc); cso_hash_delete(sc->blend_hash); cso_hash_delete(sc->sampler_hash); + cso_hash_delete(sc->depth_stencil_hash); free(sc); } diff --git a/src/mesa/cso_cache/cso_cache.h b/src/mesa/cso_cache/cso_cache.h index 05a4cfcbdd..c340cf7f67 100644 --- a/src/mesa/cso_cache/cso_cache.h +++ b/src/mesa/cso_cache/cso_cache.h @@ -42,11 +42,13 @@ struct cso_hash; struct cso_cache { struct cso_hash *blend_hash; struct cso_hash *sampler_hash; + struct cso_hash *depth_stencil_hash; }; enum cso_cache_type { CSO_BLEND, - CSO_SAMPLER + CSO_SAMPLER, + CSO_DEPTH_STENCIL }; unsigned cso_construct_key(void *item, int item_size); diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index fa336193a8..63ec7239ab 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -36,25 +36,24 @@ -#define FO_NEW_VIEWPORT 0x1 -#define FO_NEW_SETUP 0x2 -#define FO_NEW_FRAGMENT_SHADER 0x4 -#define FO_NEW_BLEND 0x8 -#define FO_NEW_CLIP 0x10 -#define FO_NEW_SCISSOR 0x20 -#define FO_NEW_STIPPLE 0x40 -#define FO_NEW_FRAMEBUFFER 0x80 -#define FO_NEW_ALPHA_TEST 0x100 -#define FO_NEW_DEPTH_TEST 0x200 -#define FO_NEW_SAMPLER 0x400 -#define FO_NEW_TEXTURE 0x800 -#define FO_NEW_STENCIL 0x1000 -#define FO_NEW_VERTEX 0x2000 -#define FO_NEW_VERTEX_SHADER 0x4000 -#define FO_NEW_BLEND_COLOR 0x8000 -#define FO_NEW_CLEAR_COLOR 0x10000 -#define FO_NEW_VERTEX_BUFFER 0x20000 -#define FO_NEW_VERTEX_ELEMENT 0x40000 +#define FO_NEW_VIEWPORT 0x1 +#define FO_NEW_SETUP 0x2 +#define FO_NEW_FRAGMENT_SHADER 0x4 +#define FO_NEW_BLEND 0x8 +#define FO_NEW_CLIP 0x10 +#define FO_NEW_SCISSOR 0x20 +#define FO_NEW_STIPPLE 0x40 +#define FO_NEW_FRAMEBUFFER 0x80 +#define FO_NEW_ALPHA_TEST 0x100 +#define FO_NEW_DEPTH_STENCIL 0x200 +#define FO_NEW_SAMPLER 0x400 +#define FO_NEW_TEXTURE 0x800 +#define FO_NEW_VERTEX 0x2000 +#define FO_NEW_VERTEX_SHADER 0x4000 +#define FO_NEW_BLEND_COLOR 0x8000 +#define FO_NEW_CLEAR_COLOR 0x10000 +#define FO_NEW_VERTEX_BUFFER 0x20000 +#define FO_NEW_VERTEX_ELEMENT 0x40000 @@ -69,19 +68,18 @@ struct failover_context { */ const struct pipe_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + const struct pipe_depth_stencil_state *depth_stencil; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; - struct pipe_depth_state depth_test; struct pipe_framebuffer_state framebuffer; struct pipe_shader_state fragment_shader; struct pipe_shader_state vertex_shader; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_setup_state setup; - struct pipe_stencil_state stencil; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index f3a99e4198..43b9757b31 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -103,14 +103,14 @@ failover_set_clear_color_state( struct pipe_context *pipe, } static void -failover_set_depth_test_state(struct pipe_context *pipe, - const struct pipe_depth_state *depth) +failover_bind_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_state *depth_stencil) { struct failover_context *failover = failover_context(pipe); - failover->depth_test = *depth; - failover->dirty |= FO_NEW_DEPTH_TEST; - failover->hw->set_depth_state( failover->hw, depth ); + failover->depth_stencil = depth_stencil; + failover->dirty |= FO_NEW_DEPTH_STENCIL; + failover->hw->bind_depth_stencil_state( failover->hw, depth_stencil ); } static void @@ -183,18 +183,6 @@ failover_set_scissor_state( struct pipe_context *pipe, failover->hw->set_scissor_state( failover->hw, scissor ); } -static void -failover_set_stencil_state(struct pipe_context *pipe, - const struct pipe_stencil_state *stencil) -{ - struct failover_context *failover = failover_context(pipe); - - failover->stencil = *stencil; - failover->dirty |= FO_NEW_STENCIL; - failover->hw->set_stencil_state( failover->hw, stencil ); -} - - static void failover_bind_sampler_state(struct pipe_context *pipe, unsigned unit, @@ -268,19 +256,18 @@ failover_init_state_functions( struct failover_context *failover ) { failover->pipe.bind_blend_state = failover_bind_blend_state; failover->pipe.bind_sampler_state = failover_bind_sampler_state; + failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state; failover->pipe.set_alpha_test_state = failover_set_alpha_test_state; failover->pipe.set_blend_color = failover_set_blend_color; failover->pipe.set_clip_state = failover_set_clip_state; failover->pipe.set_clear_color_state = failover_set_clear_color_state; - failover->pipe.set_depth_state = failover_set_depth_test_state; failover->pipe.set_framebuffer_state = failover_set_framebuffer_state; failover->pipe.set_fs_state = failover_set_fs_state; failover->pipe.set_vs_state = failover_set_vs_state; failover->pipe.set_polygon_stipple = failover_set_polygon_stipple; failover->pipe.set_scissor_state = failover_set_scissor_state; failover->pipe.set_setup_state = failover_set_setup_state; - failover->pipe.set_stencil_state = failover_set_stencil_state; failover->pipe.set_texture_state = failover_set_texture_state; failover->pipe.set_viewport_state = failover_set_viewport_state; failover->pipe.set_vertex_buffer = failover_set_vertex_buffer; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index 9d462678c5..3a1865d766 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -70,8 +70,8 @@ failover_state_emit( struct failover_context *failover ) if (failover->dirty & FO_NEW_CLEAR_COLOR) failover->sw->set_clear_color_state( failover->sw, &failover->clear_color ); - if (failover->dirty & FO_NEW_DEPTH_TEST) - failover->sw->set_depth_state( failover->sw, &failover->depth_test ); + if (failover->dirty & FO_NEW_DEPTH_STENCIL) + failover->sw->bind_depth_stencil_state( failover->sw, failover->depth_stencil ); if (failover->dirty & FO_NEW_FRAMEBUFFER) failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer ); @@ -91,9 +91,6 @@ failover_state_emit( struct failover_context *failover ) if (failover->dirty & FO_NEW_SCISSOR) failover->sw->set_scissor_state( failover->sw, &failover->scissor ); - if (failover->dirty & FO_NEW_STENCIL) - failover->sw->set_stencil_state( failover->sw, &failover->stencil ); - if (failover->dirty & FO_NEW_VIEWPORT) failover->sw->set_viewport_state( failover->sw, &failover->viewport ); diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index 51baa281ec..518f780449 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -125,19 +125,18 @@ struct i915_context */ const struct pipe_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + const struct pipe_depth_stencil_state *depth_stencil; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; struct pipe_constant_buffer constants[PIPE_SHADER_TYPES]; - struct pipe_depth_state depth_test; struct pipe_framebuffer_state framebuffer; struct pipe_shader_state fs; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_setup_state setup; - struct pipe_stencil_state stencil; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; @@ -163,16 +162,15 @@ struct i915_context #define I915_NEW_SETUP 0x2 #define I915_NEW_FS 0x4 #define I915_NEW_BLEND 0x8 -#define I915_NEW_CLIP 0x10 -#define I915_NEW_SCISSOR 0x20 -#define I915_NEW_STIPPLE 0x40 -#define I915_NEW_FRAMEBUFFER 0x80 -#define I915_NEW_ALPHA_TEST 0x100 -#define I915_NEW_DEPTH_TEST 0x200 -#define I915_NEW_SAMPLER 0x400 -#define I915_NEW_TEXTURE 0x800 -#define I915_NEW_STENCIL 0x1000 -#define I915_NEW_CONSTANTS 0x2000 +#define I915_NEW_CLIP 0x10 +#define I915_NEW_SCISSOR 0x20 +#define I915_NEW_STIPPLE 0x40 +#define I915_NEW_FRAMEBUFFER 0x80 +#define I915_NEW_ALPHA_TEST 0x100 +#define I915_NEW_DEPTH_STENCIL 0x200 +#define I915_NEW_SAMPLER 0x400 +#define I915_NEW_TEXTURE 0x800 +#define I915_NEW_CONSTANTS 0x1000 /* Driver's internally generated state flags: diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 10060b45a4..5ac2e27d1a 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -107,38 +107,44 @@ static void i915_delete_sampler_state(struct pipe_context *pipe, /** XXX move someday? Or consolidate all these simple state setters * into one file. */ -static void i915_set_depth_test_state(struct pipe_context *pipe, - const struct pipe_depth_state *depth) -{ - struct i915_context *i915 = i915_context(pipe); - i915->depth_test = *depth; +static const struct pipe_depth_stencil_state * +i915_create_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_state *depth_stencil) +{ + struct pipe_depth_stencil_state *new_ds = + malloc(sizeof(struct pipe_depth_stencil_state)); + memcpy(new_ds, depth_stencil, sizeof(struct pipe_depth_stencil_state)); - i915->dirty |= I915_NEW_DEPTH_TEST; + return new_ds; } -static void i915_set_alpha_test_state(struct pipe_context *pipe, - const struct pipe_alpha_test_state *alpha) +static void i915_bind_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_state *depth_stencil) { struct i915_context *i915 = i915_context(pipe); - i915->alpha_test = *alpha; + i915->depth_stencil = depth_stencil; - i915->dirty |= I915_NEW_ALPHA_TEST; + i915->dirty |= I915_NEW_DEPTH_STENCIL; } -static void i915_set_stencil_state(struct pipe_context *pipe, - const struct pipe_stencil_state *stencil) +static void i915_delete_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_state *depth_stencil) +{ + free((struct pipe_depth_stencil_state *)depth_stencil); +} + +static void i915_set_alpha_test_state(struct pipe_context *pipe, + const struct pipe_alpha_test_state *alpha) { struct i915_context *i915 = i915_context(pipe); - i915->stencil = *stencil; + i915->alpha_test = *alpha; - i915->dirty |= I915_NEW_STENCIL; + i915->dirty |= I915_NEW_ALPHA_TEST; } - - static void i915_set_scissor_state( struct pipe_context *pipe, const struct pipe_scissor_state *scissor ) { @@ -328,19 +334,21 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.bind_sampler_state = i915_bind_sampler_state; i915->pipe.delete_sampler_state = i915_delete_sampler_state; + i915->pipe.create_depth_stencil_state = i915_create_depth_stencil_state; + i915->pipe.bind_depth_stencil_state = i915_bind_depth_stencil_state; + i915->pipe.delete_depth_stencil_state = i915_delete_depth_stencil_state; + i915->pipe.set_alpha_test_state = i915_set_alpha_test_state; i915->pipe.set_blend_color = i915_set_blend_color; i915->pipe.set_clip_state = i915_set_clip_state; i915->pipe.set_clear_color_state = i915_set_clear_color_state; i915->pipe.set_constant_buffer = i915_set_constant_buffer; - i915->pipe.set_depth_state = i915_set_depth_test_state; i915->pipe.set_framebuffer_state = i915_set_framebuffer_state; i915->pipe.set_fs_state = i915_set_fs_state; i915->pipe.set_vs_state = i915_set_vs_state; i915->pipe.set_polygon_stipple = i915_set_polygon_stipple; i915->pipe.set_scissor_state = i915_set_scissor_state; i915->pipe.set_setup_state = i915_set_setup_state; - i915->pipe.set_stencil_state = i915_set_stencil_state; i915->pipe.set_texture_state = i915_set_texture_state; i915->pipe.set_viewport_state = i915_set_viewport_state; i915->pipe.set_vertex_buffer = i915_set_vertex_buffer; diff --git a/src/mesa/pipe/i915simple/i915_state_dynamic.c b/src/mesa/pipe/i915simple/i915_state_dynamic.c index 49a30fac11..9140eee7c2 100644 --- a/src/mesa/pipe/i915simple/i915_state_dynamic.c +++ b/src/mesa/pipe/i915simple/i915_state_dynamic.c @@ -68,8 +68,8 @@ static void upload_MODES4( struct i915_context *i915 ) /* I915_NEW_STENCIL */ { - int testmask = i915->stencil.value_mask[0] & 0xff; - int writemask = i915->stencil.write_mask[0] & 0xff; + int testmask = i915->depth_stencil->stencil.value_mask[0] & 0xff; + int writemask = i915->depth_stencil->stencil.write_mask[0] & 0xff; modes4 |= (_3DSTATE_MODES_4_CMD | ENABLE_STENCIL_TEST_MASK | @@ -94,7 +94,7 @@ static void upload_MODES4( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_MODES4 = { - .dirty = I915_NEW_BLEND | I915_NEW_STENCIL, + .dirty = I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL, .update = upload_MODES4 }; @@ -112,14 +112,14 @@ static void upload_BFO( struct i915_context *i915 ) /* _NEW_STENCIL */ - if (i915->stencil.back_enabled) { - int test = i915_translate_compare_func(i915->stencil.back_func); - int fop = i915_translate_stencil_op(i915->stencil.back_fail_op); - int dfop = i915_translate_stencil_op(i915->stencil.back_zfail_op); - int dpop = i915_translate_stencil_op(i915->stencil.back_zpass_op); - int ref = i915->stencil.ref_value[1] & 0xff; - int tmask = i915->stencil.value_mask[1] & 0xff; - int wmask = i915->stencil.write_mask[1] & 0xff; + if (i915->depth_stencil->stencil.back_enabled) { + int test = i915_translate_compare_func(i915->depth_stencil->stencil.back_func); + int fop = i915_translate_stencil_op(i915->depth_stencil->stencil.back_fail_op); + int dfop = i915_translate_stencil_op(i915->depth_stencil->stencil.back_zfail_op); + int dpop = i915_translate_stencil_op(i915->depth_stencil->stencil.back_zpass_op); + int ref = i915->depth_stencil->stencil.ref_value[1] & 0xff; + int tmask = i915->depth_stencil->stencil.value_mask[1] & 0xff; + int wmask = i915->depth_stencil->stencil.write_mask[1] & 0xff; bf[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | BFO_ENABLE_STENCIL_FUNCS | @@ -157,7 +157,7 @@ static void upload_BFO( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_BFO = { - .dirty = I915_NEW_STENCIL, + .dirty = I915_NEW_DEPTH_STENCIL, .update = upload_BFO }; diff --git a/src/mesa/pipe/i915simple/i915_state_immediate.c b/src/mesa/pipe/i915simple/i915_state_immediate.c index aaca534f5a..484913d308 100644 --- a/src/mesa/pipe/i915simple/i915_state_immediate.c +++ b/src/mesa/pipe/i915simple/i915_state_immediate.c @@ -128,12 +128,12 @@ static void upload_S5( struct i915_context *i915 ) unsigned LIS5 = 0; /* I915_NEW_STENCIL */ - if (i915->stencil.front_enabled) { - int test = i915_translate_compare_func(i915->stencil.front_func); - int fop = i915_translate_stencil_op(i915->stencil.front_fail_op); - int dfop = i915_translate_stencil_op(i915->stencil.front_zfail_op); - int dpop = i915_translate_stencil_op(i915->stencil.front_zpass_op); - int ref = i915->stencil.ref_value[0] & 0xff; + if (i915->depth_stencil->stencil.front_enabled) { + int test = i915_translate_compare_func(i915->depth_stencil->stencil.front_func); + int fop = i915_translate_stencil_op(i915->depth_stencil->stencil.front_fail_op); + int dfop = i915_translate_stencil_op(i915->depth_stencil->stencil.front_zfail_op); + int dpop = i915_translate_stencil_op(i915->depth_stencil->stencil.front_zpass_op); + int ref = i915->depth_stencil->stencil.ref_value[0] & 0xff; LIS5 |= (S5_STENCIL_TEST_ENABLE | S5_STENCIL_WRITE_ENABLE | @@ -179,7 +179,7 @@ static void upload_S5( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_S5 = { - .dirty = (I915_NEW_STENCIL | I915_NEW_BLEND | I915_NEW_SETUP), + .dirty = (I915_NEW_DEPTH_STENCIL | I915_NEW_BLEND | I915_NEW_SETUP), .update = upload_S5 }; @@ -219,13 +219,13 @@ static void upload_S6( struct i915_context *i915 ) /* I915_NEW_DEPTH */ - if (i915->depth_test.enabled) { - int func = i915_translate_compare_func(i915->depth_test.func); + if (i915->depth_stencil->depth.enabled) { + int func = i915_translate_compare_func(i915->depth_stencil->depth.func); LIS6 |= (S6_DEPTH_TEST_ENABLE | (func << S6_DEPTH_TEST_FUNC_SHIFT)); - if (i915->depth_test.writemask) + if (i915->depth_stencil->depth.writemask) LIS6 |= S6_DEPTH_WRITE_ENABLE; } @@ -236,7 +236,7 @@ static void upload_S6( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_S6 = { - .dirty = I915_NEW_ALPHA_TEST | I915_NEW_BLEND | I915_NEW_DEPTH_TEST, + .dirty = I915_NEW_ALPHA_TEST | I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL, .update = upload_S6 }; diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 0913e49096..488f002531 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -101,6 +101,14 @@ struct pipe_context { void (*delete_sampler_state)(struct pipe_context *, const struct pipe_sampler_state *); + const struct pipe_depth_stencil_state * (*create_depth_stencil_state)( + struct pipe_context *, + const struct pipe_depth_stencil_state *); + void (*bind_depth_stencil_state)(struct pipe_context *, + const struct pipe_depth_stencil_state *); + void (*delete_depth_stencil_state)(struct pipe_context *, + const struct pipe_depth_stencil_state *); + void (*set_alpha_test_state)( struct pipe_context *, const struct pipe_alpha_test_state * ); @@ -116,9 +124,6 @@ struct pipe_context { void (*set_constant_buffer)( struct pipe_context *, uint shader, uint index, const struct pipe_constant_buffer *buf ); - - void (*set_depth_state)( struct pipe_context *, - const struct pipe_depth_state * ); void (*set_feedback_state)( struct pipe_context *, const struct pipe_feedback_state *); @@ -141,9 +146,6 @@ struct pipe_context { void (*set_scissor_state)( struct pipe_context *, const struct pipe_scissor_state * ); - void (*set_stencil_state)( struct pipe_context *, - const struct pipe_stencil_state * ); - void (*set_texture_state)( struct pipe_context *, unsigned unit, struct pipe_mipmap_tree * ); diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index b994d17ea9..30e559b594 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -146,13 +146,31 @@ struct pipe_shader_state { void *executable; }; -struct pipe_depth_state +struct pipe_depth_stencil_state { - unsigned enabled:1; /**< depth test enabled? */ - unsigned writemask:1; /**< allow depth buffer writes? */ - unsigned func:3; /**< depth test func (PIPE_FUNC_x) */ - unsigned occlusion_count:1; /**< XXX move this elsewhere? */ - float clear; /**< Clear value in [0,1] (XXX correct place?) */ + struct { + unsigned enabled:1; /**< depth test enabled? */ + unsigned writemask:1; /**< allow depth buffer writes? */ + unsigned func:3; /**< depth test func (PIPE_FUNC_x) */ + unsigned occlusion_count:1; /**< XXX move this elsewhere? */ + float clear; /**< Clear value in [0,1] (XXX correct place?) */ + } depth; + struct { + unsigned front_enabled:1; + unsigned front_func:3; /**< PIPE_FUNC_x */ + unsigned front_fail_op:3; /**< PIPE_STENCIL_OP_x */ + unsigned front_zpass_op:3; /**< PIPE_STENCIL_OP_x */ + unsigned front_zfail_op:3; /**< PIPE_STENCIL_OP_x */ + unsigned back_enabled:1; + unsigned back_func:3; /**< PIPE_FUNC_x */ + unsigned back_fail_op:3; /**< PIPE_STENCIL_OP_x */ + unsigned back_zpass_op:3; /**< PIPE_STENCIL_OP_x */ + unsigned back_zfail_op:3; /**< PIPE_STENCIL_OP_x */ + ubyte ref_value[2]; /**< [0] = front, [1] = back */ + ubyte value_mask[2]; + ubyte write_mask[2]; + ubyte clear_value; + } stencil; }; struct pipe_alpha_test_state { @@ -188,24 +206,6 @@ struct pipe_clear_color_state float color[4]; }; -struct pipe_stencil_state { - unsigned front_enabled:1; - unsigned front_func:3; /**< PIPE_FUNC_x */ - unsigned front_fail_op:3; /**< PIPE_STENCIL_OP_x */ - unsigned front_zpass_op:3; /**< PIPE_STENCIL_OP_x */ - unsigned front_zfail_op:3; /**< PIPE_STENCIL_OP_x */ - unsigned back_enabled:1; - unsigned back_func:3; /**< PIPE_FUNC_x */ - unsigned back_fail_op:3; /**< PIPE_STENCIL_OP_x */ - unsigned back_zpass_op:3; /**< PIPE_STENCIL_OP_x */ - unsigned back_zfail_op:3; /**< PIPE_STENCIL_OP_x */ - ubyte ref_value[2]; /**< [0] = front, [1] = back */ - ubyte value_mask[2]; - ubyte write_mask[2]; - ubyte clear_value; -}; - - struct pipe_framebuffer_state { /** multiple colorbuffers for multiple render targets */ diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index bab7985e8d..9a8b55bb0e 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -256,13 +256,15 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.create_sampler_state = softpipe_create_sampler_state; softpipe->pipe.bind_sampler_state = softpipe_bind_sampler_state; softpipe->pipe.delete_sampler_state = softpipe_delete_sampler_state; + softpipe->pipe.create_depth_stencil_state = softpipe_create_depth_stencil_state; + softpipe->pipe.bind_depth_stencil_state = softpipe_bind_depth_stencil_state; + softpipe->pipe.delete_depth_stencil_state = softpipe_delete_depth_stencil_state; softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state; softpipe->pipe.set_blend_color = softpipe_set_blend_color; softpipe->pipe.set_clip_state = softpipe_set_clip_state; softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state; softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer; - softpipe->pipe.set_depth_state = softpipe_set_depth_test_state; softpipe->pipe.set_feedback_state = softpipe_set_feedback_state; softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.set_fs_state = softpipe_set_fs_state; @@ -270,7 +272,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; softpipe->pipe.set_scissor_state = softpipe_set_scissor_state; softpipe->pipe.set_setup_state = softpipe_set_setup_state; - softpipe->pipe.set_stencil_state = softpipe_set_stencil_state; softpipe->pipe.set_texture_state = softpipe_set_texture_state; softpipe->pipe.set_viewport_state = softpipe_set_viewport_state; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 5cee1a3cf9..4cbb0f891e 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -50,18 +50,17 @@ struct draw_stage; #define SP_NEW_SETUP 0x2 #define SP_NEW_FS 0x4 #define SP_NEW_BLEND 0x8 -#define SP_NEW_CLIP 0x10 -#define SP_NEW_SCISSOR 0x20 -#define SP_NEW_STIPPLE 0x40 -#define SP_NEW_FRAMEBUFFER 0x80 -#define SP_NEW_ALPHA_TEST 0x100 -#define SP_NEW_DEPTH_TEST 0x200 -#define SP_NEW_SAMPLER 0x400 -#define SP_NEW_TEXTURE 0x800 -#define SP_NEW_STENCIL 0x1000 -#define SP_NEW_VERTEX 0x2000 -#define SP_NEW_VS 0x4000 -#define SP_NEW_CONSTANTS 0x8000 +#define SP_NEW_CLIP 0x10 +#define SP_NEW_SCISSOR 0x20 +#define SP_NEW_STIPPLE 0x40 +#define SP_NEW_FRAMEBUFFER 0x80 +#define SP_NEW_ALPHA_TEST 0x100 +#define SP_NEW_DEPTH_STENCIL 0x200 +#define SP_NEW_SAMPLER 0x400 +#define SP_NEW_TEXTURE 0x800 +#define SP_NEW_VERTEX 0x1000 +#define SP_NEW_VS 0x2000 +#define SP_NEW_CONSTANTS 0x4000 struct softpipe_context { @@ -73,13 +72,13 @@ struct softpipe_context { */ const struct pipe_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + const struct pipe_depth_stencil_state *depth_stencil; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; struct pipe_constant_buffer constants[2]; - struct pipe_depth_state depth_test; struct pipe_feedback_state feedback; struct pipe_framebuffer_state framebuffer; struct pipe_shader_state fs; @@ -87,7 +86,6 @@ struct softpipe_context { struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_setup_state setup; - struct pipe_stencil_state stencil; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/softpipe/sp_quad.c b/src/mesa/pipe/softpipe/sp_quad.c index 2fcbea1f22..1f45776d47 100644 --- a/src/mesa/pipe/softpipe/sp_quad.c +++ b/src/mesa/pipe/softpipe/sp_quad.c @@ -31,7 +31,7 @@ sp_build_quad_pipeline(struct softpipe_context *sp) sp->quad.first = sp->quad.bufloop; } - if (sp->depth_test.occlusion_count) { + if (sp->depth_stencil->depth.occlusion_count) { sp->quad.occlusion->next = sp->quad.first; sp->quad.first = sp->quad.occlusion; } @@ -43,12 +43,12 @@ sp_build_quad_pipeline(struct softpipe_context *sp) sp->quad.first = sp->quad.coverage; } - if ( sp->stencil.front_enabled - || sp->stencil.front_enabled) { + if ( sp->depth_stencil->stencil.front_enabled + || sp->depth_stencil->stencil.back_enabled) { sp->quad.stencil_test->next = sp->quad.first; sp->quad.first = sp->quad.stencil_test; } - else if (sp->depth_test.enabled && + else if (sp->depth_stencil->depth.enabled && sp->framebuffer.zbuf) { sp->quad.depth_test->next = sp->quad.first; sp->quad.first = sp->quad.depth_test; diff --git a/src/mesa/pipe/softpipe/sp_quad_depth_test.c b/src/mesa/pipe/softpipe/sp_quad_depth_test.c index 5d46e70393..ff1d84a02d 100644 --- a/src/mesa/pipe/softpipe/sp_quad_depth_test.c +++ b/src/mesa/pipe/softpipe/sp_quad_depth_test.c @@ -77,7 +77,7 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) /* get zquad from zbuffer */ sps->read_quad_z(sps, quad->x0, quad->y0, bzzzz); - switch (softpipe->depth_test.func) { + switch (softpipe->depth_stencil->depth.func) { case PIPE_FUNC_NEVER: /* zmask = 0 */ break; @@ -129,7 +129,7 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) quad->mask &= zmask; - if (softpipe->depth_test.writemask) { + if (softpipe->depth_stencil->depth.writemask) { /* This is also efficient with sse / spe instructions: */ diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c index cb0b6d8a77..46ad08aaa1 100755 --- a/src/mesa/pipe/softpipe/sp_quad_fs.c +++ b/src/mesa/pipe/softpipe/sp_quad_fs.c @@ -179,7 +179,7 @@ static void shade_begin(struct quad_stage *qs) unsigned i, entry; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - qss->samplers[i].state = &softpipe->sampler[i]; + qss->samplers[i].state = softpipe->sampler[i]; qss->samplers[i].texture = softpipe->texture[i]; qss->samplers[i].get_samples = sp_get_samples; qss->samplers[i].pipe = &softpipe->pipe; diff --git a/src/mesa/pipe/softpipe/sp_quad_stencil.c b/src/mesa/pipe/softpipe/sp_quad_stencil.c index 47b3b4f089..56cc6907b2 100644 --- a/src/mesa/pipe/softpipe/sp_quad_stencil.c +++ b/src/mesa/pipe/softpipe/sp_quad_stencil.c @@ -207,23 +207,23 @@ stencil_test_quad(struct quad_stage *qs, struct quad_header *quad) /* choose front or back face function, operator, etc */ /* XXX we could do these initializations once per primitive */ - if (softpipe->stencil.back_enabled && quad->facing) { - func = softpipe->stencil.back_func; - failOp = softpipe->stencil.back_fail_op; - zFailOp = softpipe->stencil.back_zfail_op; - zPassOp = softpipe->stencil.back_zpass_op; - ref = softpipe->stencil.ref_value[1]; - wrtMask = softpipe->stencil.write_mask[1]; - valMask = softpipe->stencil.value_mask[1]; + if (softpipe->depth_stencil->stencil.back_enabled && quad->facing) { + func = softpipe->depth_stencil->stencil.back_func; + failOp = softpipe->depth_stencil->stencil.back_fail_op; + zFailOp = softpipe->depth_stencil->stencil.back_zfail_op; + zPassOp = softpipe->depth_stencil->stencil.back_zpass_op; + ref = softpipe->depth_stencil->stencil.ref_value[1]; + wrtMask = softpipe->depth_stencil->stencil.write_mask[1]; + valMask = softpipe->depth_stencil->stencil.value_mask[1]; } else { - func = softpipe->stencil.front_func; - failOp = softpipe->stencil.front_fail_op; - zFailOp = softpipe->stencil.front_zfail_op; - zPassOp = softpipe->stencil.front_zpass_op; - ref = softpipe->stencil.ref_value[0]; - wrtMask = softpipe->stencil.write_mask[0]; - valMask = softpipe->stencil.value_mask[0]; + func = softpipe->depth_stencil->stencil.front_func; + failOp = softpipe->depth_stencil->stencil.front_fail_op; + zFailOp = softpipe->depth_stencil->stencil.front_zfail_op; + zPassOp = softpipe->depth_stencil->stencil.front_zpass_op; + ref = softpipe->depth_stencil->stencil.ref_value[0]; + wrtMask = softpipe->depth_stencil->stencil.write_mask[0]; + valMask = softpipe->depth_stencil->stencil.value_mask[0]; } assert(s_surf); /* shouldn't get here if there's no stencil buffer */ @@ -244,7 +244,7 @@ stencil_test_quad(struct quad_stage *qs, struct quad_header *quad) if (quad->mask) { /* now the pixels that passed the stencil test are depth tested */ - if (softpipe->depth_test.enabled) { + if (softpipe->depth_stencil->depth.enabled) { const unsigned origMask = quad->mask; sp_depth_test_quad(qs, quad); /* quad->mask is updated */ diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index c8c93709db..caec3b4519 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -50,6 +50,15 @@ void softpipe_bind_sampler_state(struct pipe_context *, void softpipe_delete_sampler_state(struct pipe_context *, const struct pipe_sampler_state *); + +const struct pipe_depth_stencil_state * +softpipe_create_depth_stencil_state(struct pipe_context *, + const struct pipe_depth_stencil_state *); +void softpipe_bind_depth_stencil_state(struct pipe_context *, + const struct pipe_depth_stencil_state *); +void softpipe_delete_depth_stencil_state(struct pipe_context *, + const struct pipe_depth_stencil_state *); + void softpipe_set_framebuffer_state( struct pipe_context *, const struct pipe_framebuffer_state * ); @@ -69,9 +78,6 @@ void softpipe_set_constant_buffer(struct pipe_context *, uint shader, uint index, const struct pipe_constant_buffer *buf); -void softpipe_set_depth_test_state( struct pipe_context *, - const struct pipe_depth_state * ); - void softpipe_set_feedback_state( struct pipe_context *, const struct pipe_feedback_state * ); @@ -90,9 +96,6 @@ void softpipe_set_scissor_state( struct pipe_context *, void softpipe_set_setup_state( struct pipe_context *, const struct pipe_setup_state * ); -void softpipe_set_stencil_state( struct pipe_context *, - const struct pipe_stencil_state * ); - void softpipe_set_texture_state( struct pipe_context *, unsigned unit, struct pipe_mipmap_tree * ); diff --git a/src/mesa/pipe/softpipe/sp_state_blend.c b/src/mesa/pipe/softpipe/sp_state_blend.c index 34da613f9d..83f456ded5 100644 --- a/src/mesa/pipe/softpipe/sp_state_blend.c +++ b/src/mesa/pipe/softpipe/sp_state_blend.c @@ -71,16 +71,6 @@ void softpipe_set_blend_color( struct pipe_context *pipe, /** XXX move someday? Or consolidate all these simple state setters * into one file. */ -void -softpipe_set_depth_test_state(struct pipe_context *pipe, - const struct pipe_depth_state *depth) -{ - struct softpipe_context *softpipe = softpipe_context(pipe); - - softpipe->depth_test = *depth; - - softpipe->dirty |= SP_NEW_DEPTH_TEST; -} void softpipe_set_alpha_test_state(struct pipe_context *pipe, @@ -93,14 +83,30 @@ softpipe_set_alpha_test_state(struct pipe_context *pipe, softpipe->dirty |= SP_NEW_ALPHA_TEST; } +const struct pipe_depth_stencil_state * +softpipe_create_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_state *depth_stencil) +{ + struct pipe_depth_stencil_state *new_ds = malloc(sizeof(struct pipe_depth_stencil_state)); + memcpy(new_ds, depth_stencil, sizeof(struct pipe_depth_stencil_state)); + + return new_ds; +} + void -softpipe_set_stencil_state(struct pipe_context *pipe, - const struct pipe_stencil_state *stencil) +softpipe_bind_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_state *depth_stencil) { struct softpipe_context *softpipe = softpipe_context(pipe); - softpipe->stencil = *stencil; + softpipe->depth_stencil = depth_stencil; - softpipe->dirty |= SP_NEW_STENCIL; + softpipe->dirty |= SP_NEW_DEPTH_STENCIL; } +void +softpipe_delete_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_state *depth) +{ + free((struct pipe_depth_stencil_state*)depth); +} diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index e08ed50a70..47743e185c 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -55,7 +55,7 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) /* Need Z if depth test is enabled or the fragment program uses the * fragment position (XYZW). */ - if (softpipe->depth_test.enabled || + if (softpipe->depth_stencil->depth.enabled || (inputsRead & (1 << TGSI_ATTRIB_POS))) softpipe->need_z = TRUE; else @@ -186,15 +186,14 @@ void softpipe_update_derived( struct softpipe_context *softpipe ) calculate_vertex_layout( softpipe ); if (softpipe->dirty & (SP_NEW_SCISSOR | - SP_NEW_STENCIL | + SP_NEW_DEPTH_STENCIL | SP_NEW_FRAMEBUFFER)) compute_cliprect(softpipe); if (softpipe->dirty & (SP_NEW_BLEND | - SP_NEW_DEPTH_TEST | + SP_NEW_DEPTH_STENCIL | SP_NEW_ALPHA_TEST | SP_NEW_FRAMEBUFFER | - SP_NEW_STENCIL | SP_NEW_SETUP | SP_NEW_FS)) sp_build_quad_pipeline(softpipe); diff --git a/src/mesa/sources b/src/mesa/sources index 90fa5c65bf..22b592df09 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -204,7 +204,6 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_sampler.c \ state_tracker/st_atom_scissor.c \ state_tracker/st_atom_setup.c \ - state_tracker/st_atom_stencil.c \ state_tracker/st_atom_stipple.c \ state_tracker/st_atom_texture.c \ state_tracker/st_atom_viewport.c \ diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 66ab5d7c3a..99d0bcb90b 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -46,7 +46,7 @@ static const struct st_tracked_state *atoms[] = { &st_update_framebuffer, &st_update_clear_color, - &st_update_depth, + &st_update_depth_stencil, &st_update_clip, &st_update_tnl, @@ -58,7 +58,6 @@ static const struct st_tracked_state *atoms[] = &st_update_viewport, &st_update_scissor, &st_update_blend, - &st_update_stencil, &st_update_sampler, &st_update_texture, &st_update_vs_constants, diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 447430bfef..0e362b1fbf 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -47,7 +47,7 @@ void st_validate_state( struct st_context *st ); const struct st_tracked_state st_update_framebuffer; const struct st_tracked_state st_update_clip; const struct st_tracked_state st_update_clear_color; -const struct st_tracked_state st_update_depth; +const struct st_tracked_state st_update_depth_stencil; const struct st_tracked_state st_update_tnl; const struct st_tracked_state st_update_fs; const struct st_tracked_state st_update_vs; @@ -56,7 +56,6 @@ const struct st_tracked_state st_update_polygon_stipple; const struct st_tracked_state st_update_viewport; const struct st_tracked_state st_update_scissor; const struct st_tracked_state st_update_blend; -const struct st_tracked_state st_update_stencil; const struct st_tracked_state st_update_sampler; const struct st_tracked_state st_update_texture; const struct st_tracked_state st_update_fs_constants; diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index df05c79e36..406773213d 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -29,15 +29,67 @@ * Authors: * Keith Whitwell * Brian Paul + * Zack Rusin */ #include "st_context.h" +#include "st_cache.h" #include "st_atom.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +/** + * Convert GLenum stencil func tokens to pipe tokens. + */ +static GLuint +gl_stencil_func_to_sp(GLenum func) +{ + /* Same values, just biased */ + assert(PIPE_FUNC_NEVER == GL_NEVER - GL_NEVER); + assert(PIPE_FUNC_LESS == GL_LESS - GL_NEVER); + assert(PIPE_FUNC_EQUAL == GL_EQUAL - GL_NEVER); + assert(PIPE_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); + assert(PIPE_FUNC_GREATER == GL_GREATER - GL_NEVER); + assert(PIPE_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); + assert(PIPE_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); + assert(PIPE_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); + assert(func >= GL_NEVER); + assert(func <= GL_ALWAYS); + return func - GL_NEVER; +} + + +/** + * Convert GLenum stencil op tokens to pipe tokens. + */ +static GLuint +gl_stencil_op_to_sp(GLenum func) +{ + switch (func) { + case GL_KEEP: + return PIPE_STENCIL_OP_KEEP; + case GL_ZERO: + return PIPE_STENCIL_OP_ZERO; + case GL_REPLACE: + return PIPE_STENCIL_OP_REPLACE; + case GL_INCR: + return PIPE_STENCIL_OP_INCR; + case GL_DECR: + return PIPE_STENCIL_OP_DECR; + case GL_INCR_WRAP: + return PIPE_STENCIL_OP_INCR_WRAP; + case GL_DECR_WRAP: + return PIPE_STENCIL_OP_DECR_WRAP; + case GL_INVERT: + return PIPE_STENCIL_OP_INVERT; + default: + assert("invalid GL token in gl_stencil_op_to_sp()" == NULL); + return 0; + } +} + /** * Convert GLenum depth func tokens to pipe tokens. */ @@ -59,35 +111,59 @@ gl_depth_func_to_sp(GLenum func) } -static void -update_depth( struct st_context *st ) +static void +update_depth_stencil(struct st_context *st) { - struct pipe_depth_state depth; + struct pipe_depth_stencil_state depth_stencil; - memset(&depth, 0, sizeof(depth)); + memset(&depth_stencil, 0, sizeof(depth_stencil)); - depth.enabled = st->ctx->Depth.Test; - depth.writemask = st->ctx->Depth.Mask; - depth.func = gl_depth_func_to_sp(st->ctx->Depth.Func); - depth.clear = st->ctx->Depth.Clear; + depth_stencil.depth.enabled = st->ctx->Depth.Test; + depth_stencil.depth.writemask = st->ctx->Depth.Mask; + depth_stencil.depth.func = gl_depth_func_to_sp(st->ctx->Depth.Func); + depth_stencil.depth.clear = st->ctx->Depth.Clear; if (st->ctx->Query.CurrentOcclusionObject && st->ctx->Query.CurrentOcclusionObject->Active) - depth.occlusion_count = 1; + depth_stencil.depth.occlusion_count = 1; + + if (st->ctx->Stencil.Enabled) { + depth_stencil.stencil.front_enabled = 1; + depth_stencil.stencil.front_func = gl_stencil_func_to_sp(st->ctx->Stencil.Function[0]); + depth_stencil.stencil.front_fail_op = gl_stencil_op_to_sp(st->ctx->Stencil.FailFunc[0]); + depth_stencil.stencil.front_zfail_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZFailFunc[0]); + depth_stencil.stencil.front_zpass_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZPassFunc[0]); + depth_stencil.stencil.ref_value[0] = st->ctx->Stencil.Ref[0] & 0xff; + depth_stencil.stencil.value_mask[0] = st->ctx->Stencil.ValueMask[0] & 0xff; + depth_stencil.stencil.write_mask[0] = st->ctx->Stencil.WriteMask[0] & 0xff; + if (st->ctx->Stencil.TestTwoSide) { + depth_stencil.stencil.back_enabled = 1; + depth_stencil.stencil.back_func = gl_stencil_func_to_sp(st->ctx->Stencil.Function[1]); + depth_stencil.stencil.back_fail_op = gl_stencil_op_to_sp(st->ctx->Stencil.FailFunc[1]); + depth_stencil.stencil.back_zfail_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZFailFunc[1]); + depth_stencil.stencil.back_zpass_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZPassFunc[1]); + depth_stencil.stencil.ref_value[1] = st->ctx->Stencil.Ref[1] & 0xff; + depth_stencil.stencil.value_mask[1] = st->ctx->Stencil.ValueMask[1] & 0xff; + depth_stencil.stencil.write_mask[1] = st->ctx->Stencil.WriteMask[1] & 0xff; + } + depth_stencil.stencil.clear_value = st->ctx->Stencil.Clear & 0xff; + } - if (memcmp(&depth, &st->state.depth, sizeof(depth)) != 0) { + struct pipe_depth_stencil_state *cached_state = + st_cached_depth_stencil_state(st, &depth_stencil); + if (st->state.depth_stencil != cached_state) { /* state has changed */ - st->state.depth = depth; /* struct copy */ - st->pipe->set_depth_state(st->pipe, &depth); /* set new state */ + st->state.depth_stencil = cached_state; + st->pipe->bind_depth_stencil_state(st->pipe, cached_state); /* set new state */ } } -const struct st_tracked_state st_update_depth = { - .name = "st_update_depth", +const struct st_tracked_state st_update_depth_stencil = { + .name = "st_update_depth_stencil", .dirty = { - .mesa = (_NEW_DEPTH), + .mesa = (_NEW_DEPTH|_NEW_STENCIL), .st = 0, }, - .update = update_depth + .update = update_depth_stencil }; diff --git a/src/mesa/state_tracker/st_atom_stencil.c b/src/mesa/state_tracker/st_atom_stencil.c deleted file mode 100644 index b8aec0b3b6..0000000000 --- a/src/mesa/state_tracker/st_atom_stencil.c +++ /dev/null @@ -1,141 +0,0 @@ -/************************************************************************** - * - * 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 - * Brian Paul - */ - - -#include "st_context.h" -#include "st_atom.h" -#include "pipe/p_context.h" -#include "pipe/p_defines.h" - - -/** - * Convert GLenum stencil func tokens to pipe tokens. - */ -static GLuint -gl_stencil_func_to_sp(GLenum func) -{ - /* Same values, just biased */ - assert(PIPE_FUNC_NEVER == GL_NEVER - GL_NEVER); - assert(PIPE_FUNC_LESS == GL_LESS - GL_NEVER); - assert(PIPE_FUNC_EQUAL == GL_EQUAL - GL_NEVER); - assert(PIPE_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); - assert(PIPE_FUNC_GREATER == GL_GREATER - GL_NEVER); - assert(PIPE_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); - assert(PIPE_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); - assert(PIPE_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); - assert(func >= GL_NEVER); - assert(func <= GL_ALWAYS); - return func - GL_NEVER; -} - - -/** - * Convert GLenum stencil op tokens to pipe tokens. - */ -static GLuint -gl_stencil_op_to_sp(GLenum func) -{ - switch (func) { - case GL_KEEP: - return PIPE_STENCIL_OP_KEEP; - case GL_ZERO: - return PIPE_STENCIL_OP_ZERO; - case GL_REPLACE: - return PIPE_STENCIL_OP_REPLACE; - case GL_INCR: - return PIPE_STENCIL_OP_INCR; - case GL_DECR: - return PIPE_STENCIL_OP_DECR; - case GL_INCR_WRAP: - return PIPE_STENCIL_OP_INCR_WRAP; - case GL_DECR_WRAP: - return PIPE_STENCIL_OP_DECR_WRAP; - case GL_INVERT: - return PIPE_STENCIL_OP_INVERT; - default: - assert("invalid GL token in gl_stencil_op_to_sp()" == NULL); - return 0; - } -} - - -static void -update_stencil( struct st_context *st ) -{ - struct pipe_stencil_state stencil; - - memset(&stencil, 0, sizeof(stencil)); - - if (st->ctx->Stencil.Enabled) { - stencil.front_enabled = 1; - stencil.front_func = gl_stencil_func_to_sp(st->ctx->Stencil.Function[0]); - stencil.front_fail_op = gl_stencil_op_to_sp(st->ctx->Stencil.FailFunc[0]); - stencil.front_zfail_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZFailFunc[0]); - stencil.front_zpass_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZPassFunc[0]); - stencil.ref_value[0] = st->ctx->Stencil.Ref[0] & 0xff; - stencil.value_mask[0] = st->ctx->Stencil.ValueMask[0] & 0xff; - stencil.write_mask[0] = st->ctx->Stencil.WriteMask[0] & 0xff; - if (st->ctx->Stencil.TestTwoSide) { - stencil.back_enabled = 1; - stencil.back_func = gl_stencil_func_to_sp(st->ctx->Stencil.Function[1]); - stencil.back_fail_op = gl_stencil_op_to_sp(st->ctx->Stencil.FailFunc[1]); - stencil.back_zfail_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZFailFunc[1]); - stencil.back_zpass_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZPassFunc[1]); - stencil.ref_value[1] = st->ctx->Stencil.Ref[1] & 0xff; - stencil.value_mask[1] = st->ctx->Stencil.ValueMask[1] & 0xff; - stencil.write_mask[1] = st->ctx->Stencil.WriteMask[1] & 0xff; - } - stencil.clear_value = st->ctx->Stencil.Clear & 0xff; - } - - if (memcmp(&stencil, &st->state.stencil, sizeof(stencil)) != 0) { - /* state has changed */ - st->state.stencil = stencil; /* struct copy */ - st->pipe->set_stencil_state(st->pipe, &stencil); /* set new state */ - } -} - - -const struct st_tracked_state st_update_stencil = { - .name = "st_update_stencil", - .dirty = { - .mesa = (_NEW_STENCIL), - .st = 0, - }, - .update = update_stencil -}; - - - - - diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index 99fb45f00a..64c03be99d 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -76,3 +76,20 @@ struct pipe_sampler_state * st_cached_sampler_state( } return (struct pipe_sampler_state*)(cso_hash_iter_data(iter)); } + +struct pipe_depth_stencil_state * st_cached_depth_stencil_state( + struct st_context *st, + const struct pipe_depth_stencil_state *depth_stencil) +{ + unsigned hash_key = cso_construct_key((void*)depth_stencil, sizeof(struct pipe_depth_stencil_state)); + struct cso_hash_iter iter = cso_find_state_template(st->cache, + hash_key, CSO_DEPTH_STENCIL, + (void*)depth_stencil); + if (cso_hash_iter_is_null(iter)) { + const struct pipe_depth_stencil_state *created_state = st->pipe->create_depth_stencil_state( + st->pipe, depth_stencil); + iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL, + (void*)created_state); + } + return (struct pipe_depth_stencil_state*)(cso_hash_iter_data(iter)); +} diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index 927585141c..78cb2e774e 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -45,5 +45,8 @@ struct pipe_sampler_state * st_cached_sampler_state( struct st_context *st, const struct pipe_sampler_state *sampler); +struct pipe_depth_stencil_state *st_cached_depth_stencil_state( + struct st_context *st, + const struct pipe_depth_stencil_state *sampler); #endif diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 55e03f644e..e9aabd15b5 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -283,6 +283,7 @@ clear_with_quad(GLcontext *ctx, /* blend state: RGBA masking */ { struct pipe_blend_state blend; + const struct pipe_blend_state *state; memset(&blend, 0, sizeof(blend)); if (color) { if (ctx->Color.ColorMask[0]) @@ -296,20 +297,34 @@ clear_with_quad(GLcontext *ctx, if (st->ctx->Color.DitherFlag) blend.dither = 1; } - const struct pipe_blend_state *state = st_cached_blend_state(st, &blend); + state = st_cached_blend_state(st, &blend); pipe->bind_blend_state(pipe, state); } - /* depth state: always pass */ + /* depth_stencil state: always pass/set to ref value */ { - struct pipe_depth_state depth_test; - memset(&depth_test, 0, sizeof(depth_test)); + struct pipe_depth_stencil_state depth_stencil; + struct pipe_depth_stencil_state *cached; + memset(&depth_stencil, 0, sizeof(depth_stencil)); if (depth) { - depth_test.enabled = 1; - depth_test.writemask = 1; - depth_test.func = PIPE_FUNC_ALWAYS; + depth_stencil.depth.enabled = 1; + depth_stencil.depth.writemask = 1; + depth_stencil.depth.func = PIPE_FUNC_ALWAYS; } - pipe->set_depth_state(pipe, &depth_test); + + if (stencil) { + depth_stencil.stencil.front_enabled = 1; + depth_stencil.stencil.front_func = PIPE_FUNC_ALWAYS; + depth_stencil.stencil.front_fail_op = PIPE_STENCIL_OP_REPLACE; + depth_stencil.stencil.front_zpass_op = PIPE_STENCIL_OP_REPLACE; + depth_stencil.stencil.front_zfail_op = PIPE_STENCIL_OP_REPLACE; + depth_stencil.stencil.ref_value[0] = ctx->Stencil.Clear; + depth_stencil.stencil.value_mask[0] = 0xff; + depth_stencil.stencil.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; + } + cached = + st_cached_depth_stencil_state(ctx->st, &depth_stencil); + pipe->bind_depth_stencil_state(pipe, cached); } /* setup state: nothing */ @@ -326,23 +341,6 @@ clear_with_quad(GLcontext *ctx, pipe->set_setup_state(pipe, &setup); } - /* stencil state: always set to ref value */ - { - struct pipe_stencil_state stencil_test; - memset(&stencil_test, 0, sizeof(stencil_test)); - if (stencil) { - stencil_test.front_enabled = 1; - stencil_test.front_func = PIPE_FUNC_ALWAYS; - stencil_test.front_fail_op = PIPE_STENCIL_OP_REPLACE; - stencil_test.front_zpass_op = PIPE_STENCIL_OP_REPLACE; - stencil_test.front_zfail_op = PIPE_STENCIL_OP_REPLACE; - stencil_test.ref_value[0] = ctx->Stencil.Clear; - stencil_test.value_mask[0] = 0xff; - stencil_test.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; - } - pipe->set_stencil_state(pipe, &stencil_test); - } - /* fragment shader state: color pass-through program */ { static struct st_fragment_program *stfp = NULL; @@ -393,11 +391,10 @@ clear_with_quad(GLcontext *ctx, /* Restore pipe state */ pipe->set_alpha_test_state(pipe, &st->state.alpha_test); pipe->bind_blend_state(pipe, st->state.blend); - pipe->set_depth_state(pipe, &st->state.depth); + pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil); pipe->set_fs_state(pipe, &st->state.fs); pipe->set_vs_state(pipe, &st->state.vs); pipe->set_setup_state(pipe, &st->state.setup); - pipe->set_stencil_state(pipe, &st->state.stencil); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); /* OR: st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 31a37e5cd4..a0012e3a8c 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -478,7 +478,7 @@ any_fragment_ops(const struct st_context *st) if (st->state.alpha_test.enabled || st->state.blend->blend_enable || st->state.blend->logicop_enable || - st->state.depth.enabled) + st->state.depth_stencil->depth.enabled) /* XXX more checks */ return GL_TRUE; else diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 13526ff9e7..7c887d0b55 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -76,13 +76,13 @@ struct st_context struct { const struct pipe_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + const struct pipe_depth_stencil_state *depth_stencil; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; struct pipe_constant_buffer constants[2]; - struct pipe_depth_state depth; struct pipe_feedback_state feedback; struct pipe_framebuffer_state framebuffer; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; @@ -91,7 +91,6 @@ struct st_context struct pipe_setup_state setup; struct pipe_shader_state fs; struct pipe_shader_state vs; - struct pipe_stencil_state stencil; struct pipe_viewport_state viewport; } state; -- cgit v1.2.3 From 294401814d1d89cc731de1c22c25333aa5d59374 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 17 Sep 2007 12:59:50 -0400 Subject: converting the setup state to immutable object and renaming it to rasterizer state --- src/mesa/cso_cache/cso_cache.c | 6 ++ src/mesa/cso_cache/cso_cache.h | 4 +- src/mesa/pipe/draw/draw_context.c | 16 ++--- src/mesa/pipe/draw/draw_context.h | 2 +- src/mesa/pipe/draw/draw_cull.c | 2 +- src/mesa/pipe/draw/draw_offset.c | 4 +- src/mesa/pipe/draw/draw_private.h | 2 +- src/mesa/pipe/draw/draw_twoside.c | 2 +- src/mesa/pipe/draw/draw_unfilled.c | 4 +- src/mesa/pipe/failover/fo_context.h | 8 +-- src/mesa/pipe/failover/fo_state.c | 14 ++-- src/mesa/pipe/failover/fo_state_emit.c | 4 +- src/mesa/pipe/i915simple/i915_context.h | 4 +- src/mesa/pipe/i915simple/i915_state.c | 30 ++++++-- src/mesa/pipe/i915simple/i915_state_derived.c | 6 +- src/mesa/pipe/i915simple/i915_state_dynamic.c | 16 ++--- src/mesa/pipe/i915simple/i915_state_immediate.c | 30 ++++---- src/mesa/pipe/p_context.h | 11 ++- src/mesa/pipe/p_state.h | 4 +- src/mesa/pipe/softpipe/sp_context.c | 4 +- src/mesa/pipe/softpipe/sp_context.h | 4 +- src/mesa/pipe/softpipe/sp_prim_setup.c | 18 ++--- src/mesa/pipe/softpipe/sp_quad.c | 8 +-- src/mesa/pipe/softpipe/sp_quad_coverage.c | 6 +- src/mesa/pipe/softpipe/sp_state.h | 12 ++-- src/mesa/pipe/softpipe/sp_state_derived.c | 10 +-- src/mesa/pipe/softpipe/sp_state_setup.c | 26 +++++-- src/mesa/state_tracker/st_atom.c | 2 +- src/mesa/state_tracker/st_atom.h | 2 +- src/mesa/state_tracker/st_atom_setup.c | 95 +++++++++++++------------ src/mesa/state_tracker/st_cache.c | 18 +++++ src/mesa/state_tracker/st_cache.h | 6 +- src/mesa/state_tracker/st_cb_clear.c | 12 ++-- src/mesa/state_tracker/st_cb_drawpixels.c | 8 ++- src/mesa/state_tracker/st_context.h | 2 +- src/mesa/state_tracker/st_draw.c | 2 +- 36 files changed, 245 insertions(+), 159 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/cso_cache/cso_cache.c b/src/mesa/cso_cache/cso_cache.c index a4730394f8..4aaadf00e6 100644 --- a/src/mesa/cso_cache/cso_cache.c +++ b/src/mesa/cso_cache/cso_cache.c @@ -78,6 +78,8 @@ static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_ hash = sc->sampler_hash; case CSO_DEPTH_STENCIL: hash = sc->depth_stencil_hash; + case CSO_RASTERIZER: + hash = sc->rasterizer_hash; } return hash; @@ -92,6 +94,8 @@ static int _cso_size_for_type(enum cso_cache_type type) return sizeof(struct pipe_sampler_state); case CSO_DEPTH_STENCIL: return sizeof(struct pipe_depth_stencil_state); + case CSO_RASTERIZER: + return sizeof(struct pipe_rasterizer_state); } return 0; } @@ -143,6 +147,7 @@ struct cso_cache *cso_cache_create(void) sc->blend_hash = cso_hash_create(); sc->sampler_hash = cso_hash_create(); sc->depth_stencil_hash = cso_hash_create(); + sc->rasterizer_hash = cso_hash_create(); return sc; } @@ -153,6 +158,7 @@ void cso_cache_delete(struct cso_cache *sc) cso_hash_delete(sc->blend_hash); cso_hash_delete(sc->sampler_hash); cso_hash_delete(sc->depth_stencil_hash); + cso_hash_delete(sc->rasterizer_hash); free(sc); } diff --git a/src/mesa/cso_cache/cso_cache.h b/src/mesa/cso_cache/cso_cache.h index c340cf7f67..23be9cd713 100644 --- a/src/mesa/cso_cache/cso_cache.h +++ b/src/mesa/cso_cache/cso_cache.h @@ -43,12 +43,14 @@ struct cso_cache { struct cso_hash *blend_hash; struct cso_hash *sampler_hash; struct cso_hash *depth_stencil_hash; + struct cso_hash *rasterizer_hash; }; enum cso_cache_type { CSO_BLEND, CSO_SAMPLER, - CSO_DEPTH_STENCIL + CSO_DEPTH_STENCIL, + CSO_RASTERIZER }; unsigned cso_construct_key(void *item, int item_size); diff --git a/src/mesa/pipe/draw/draw_context.c b/src/mesa/pipe/draw/draw_context.c index 4498293e92..f3236ad59e 100644 --- a/src/mesa/pipe/draw/draw_context.c +++ b/src/mesa/pipe/draw/draw_context.c @@ -98,19 +98,19 @@ static void validate_pipeline( struct draw_context *draw ) * shorter pipelines for lines & points. */ - if (draw->setup.fill_cw != PIPE_POLYGON_MODE_FILL || - draw->setup.fill_ccw != PIPE_POLYGON_MODE_FILL) { + if (draw->rasterizer->fill_cw != PIPE_POLYGON_MODE_FILL || + draw->rasterizer->fill_ccw != PIPE_POLYGON_MODE_FILL) { draw->pipeline.unfilled->next = next; next = draw->pipeline.unfilled; } - if (draw->setup.offset_cw || - draw->setup.offset_ccw) { + if (draw->rasterizer->offset_cw || + draw->rasterizer->offset_ccw) { draw->pipeline.offset->next = next; next = draw->pipeline.offset; } - if (draw->setup.light_twoside) { + if (draw->rasterizer->light_twoside) { draw->pipeline.twoside->next = next; next = draw->pipeline.twoside; } @@ -134,7 +134,7 @@ static void validate_pipeline( struct draw_context *draw ) * this for clipped primitives, ie it is a part of the clip * routine. */ - if (draw->setup.flatshade) { + if (draw->rasterizer->flatshade) { draw->pipeline.flatshade->next = next; next = draw->pipeline.flatshade; } @@ -161,9 +161,9 @@ void draw_set_feedback_state( struct draw_context *draw, * This causes the drawing pipeline to be rebuilt. */ void draw_set_setup_state( struct draw_context *draw, - const struct pipe_setup_state *setup ) + const struct pipe_rasterizer_state *raster ) { - draw->setup = *setup; /* struct copy */ + draw->rasterizer = raster; validate_pipeline( draw ); } diff --git a/src/mesa/pipe/draw/draw_context.h b/src/mesa/pipe/draw/draw_context.h index 2babc02f45..2714252fc5 100644 --- a/src/mesa/pipe/draw/draw_context.h +++ b/src/mesa/pipe/draw/draw_context.h @@ -87,7 +87,7 @@ void draw_set_feedback_state( struct draw_context *draw, const struct pipe_feedback_state * ); void draw_set_setup_state( struct draw_context *draw, - const struct pipe_setup_state *setup ); + const struct pipe_rasterizer_state *raster ); void draw_set_setup_stage( struct draw_context *draw, struct draw_stage *stage ); diff --git a/src/mesa/pipe/draw/draw_cull.c b/src/mesa/pipe/draw/draw_cull.c index f3d56ad719..f898834ba5 100644 --- a/src/mesa/pipe/draw/draw_cull.c +++ b/src/mesa/pipe/draw/draw_cull.c @@ -54,7 +54,7 @@ static void cull_begin( struct draw_stage *stage ) { struct cull_stage *cull = cull_stage(stage); - cull->winding = stage->draw->setup.cull_mode; + cull->winding = stage->draw->rasterizer->cull_mode; stage->next->begin( stage->next ); } diff --git a/src/mesa/pipe/draw/draw_offset.c b/src/mesa/pipe/draw/draw_offset.c index 4f653e8c54..6acc7cbcd2 100644 --- a/src/mesa/pipe/draw/draw_offset.c +++ b/src/mesa/pipe/draw/draw_offset.c @@ -57,8 +57,8 @@ static void offset_begin( struct draw_stage *stage ) struct offset_stage *offset = offset_stage(stage); float mrd = 1.0f / 65535.0f; /* XXX this depends on depthbuffer bits! */ - offset->units = stage->draw->setup.offset_units * mrd; - offset->scale = stage->draw->setup.offset_scale; + offset->units = stage->draw->rasterizer->offset_units * mrd; + offset->scale = stage->draw->rasterizer->offset_scale; stage->next->begin( stage->next ); } diff --git a/src/mesa/pipe/draw/draw_private.h b/src/mesa/pipe/draw/draw_private.h index 8bcc3717c4..fb0aaff40d 100644 --- a/src/mesa/pipe/draw/draw_private.h +++ b/src/mesa/pipe/draw/draw_private.h @@ -137,7 +137,7 @@ struct draw_context } pipeline; /* pipe state that we need: */ - struct pipe_setup_state setup; + const struct pipe_rasterizer_state *rasterizer; struct pipe_feedback_state feedback; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/draw/draw_twoside.c b/src/mesa/pipe/draw/draw_twoside.c index 98eb088035..3eb8cce637 100644 --- a/src/mesa/pipe/draw/draw_twoside.c +++ b/src/mesa/pipe/draw/draw_twoside.c @@ -55,7 +55,7 @@ static void twoside_begin( struct draw_stage *stage ) * if the triangle is back-facing (negative). * sign = -1 for CCW, +1 for CW */ - twoside->sign = (stage->draw->setup.front_winding == PIPE_WINDING_CCW) ? -1.0f : 1.0f; + twoside->sign = (stage->draw->rasterizer->front_winding == PIPE_WINDING_CCW) ? -1.0f : 1.0f; stage->next->begin( stage->next ); } diff --git a/src/mesa/pipe/draw/draw_unfilled.c b/src/mesa/pipe/draw/draw_unfilled.c index b0d6f3d065..2d374329d8 100644 --- a/src/mesa/pipe/draw/draw_unfilled.c +++ b/src/mesa/pipe/draw/draw_unfilled.c @@ -59,8 +59,8 @@ static void unfilled_begin( struct draw_stage *stage ) { struct unfilled_stage *unfilled = unfilled_stage(stage); - unfilled->mode[0] = stage->draw->setup.fill_ccw; /* front */ - unfilled->mode[1] = stage->draw->setup.fill_cw; /* back */ + unfilled->mode[0] = stage->draw->rasterizer->fill_ccw; /* front */ + unfilled->mode[1] = stage->draw->rasterizer->fill_cw; /* back */ stage->next->begin( stage->next ); } diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index 63ec7239ab..b05ceb88ad 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -37,7 +37,7 @@ #define FO_NEW_VIEWPORT 0x1 -#define FO_NEW_SETUP 0x2 +#define FO_NEW_RASTERIZER 0x2 #define FO_NEW_FRAGMENT_SHADER 0x4 #define FO_NEW_BLEND 0x8 #define FO_NEW_CLIP 0x10 @@ -66,9 +66,10 @@ struct failover_context { /* The most recent drawing state as set by the driver: */ - const struct pipe_blend_state *blend; - const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + const struct pipe_blend_state *blend; + const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; + const struct pipe_rasterizer_state *rasterizer; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; @@ -79,7 +80,6 @@ struct failover_context { struct pipe_shader_state vertex_shader; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_setup_state setup; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index 43b9757b31..8e2b649590 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -160,15 +160,15 @@ failover_set_polygon_stipple( struct pipe_context *pipe, -static void -failover_set_setup_state( struct pipe_context *pipe, - const struct pipe_setup_state *setup ) +static void +failover_bind_rasterizer_state( struct pipe_context *pipe, + const struct pipe_rasterizer_state *setup ) { struct failover_context *failover = failover_context(pipe); - failover->setup = *setup; - failover->dirty |= FO_NEW_SETUP; - failover->hw->set_setup_state( failover->hw, setup ); + failover->rasterizer = setup; + failover->dirty |= FO_NEW_RASTERIZER; + failover->hw->bind_rasterizer_state( failover->hw, setup ); } @@ -257,6 +257,7 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.bind_blend_state = failover_bind_blend_state; failover->pipe.bind_sampler_state = failover_bind_sampler_state; failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state; + failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state; failover->pipe.set_alpha_test_state = failover_set_alpha_test_state; failover->pipe.set_blend_color = failover_set_blend_color; @@ -267,7 +268,6 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.set_vs_state = failover_set_vs_state; failover->pipe.set_polygon_stipple = failover_set_polygon_stipple; failover->pipe.set_scissor_state = failover_set_scissor_state; - failover->pipe.set_setup_state = failover_set_setup_state; failover->pipe.set_texture_state = failover_set_texture_state; failover->pipe.set_viewport_state = failover_set_viewport_state; failover->pipe.set_vertex_buffer = failover_set_vertex_buffer; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index 3a1865d766..1c9573a7b0 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -85,8 +85,8 @@ failover_state_emit( struct failover_context *failover ) if (failover->dirty & FO_NEW_STIPPLE) failover->sw->set_polygon_stipple( failover->sw, &failover->poly_stipple ); - if (failover->dirty & FO_NEW_SETUP) - failover->sw->set_setup_state( failover->sw, &failover->setup ); + if (failover->dirty & FO_NEW_RASTERIZER) + failover->sw->bind_rasterizer_state( failover->sw, failover->rasterizer ); if (failover->dirty & FO_NEW_SCISSOR) failover->sw->set_scissor_state( failover->sw, &failover->scissor ); diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index 518f780449..3fab821fde 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -126,6 +126,7 @@ struct i915_context const struct pipe_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; + const struct pipe_rasterizer_state *rasterizer; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; @@ -136,7 +137,6 @@ struct i915_context struct pipe_shader_state fs; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_setup_state setup; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; @@ -159,7 +159,7 @@ struct i915_context /* A flag for each state_tracker state object: */ #define I915_NEW_VIEWPORT 0x1 -#define I915_NEW_SETUP 0x2 +#define I915_NEW_RASTERIZER 0x2 #define I915_NEW_FS 0x4 #define I915_NEW_BLEND 0x8 #define I915_NEW_CLIP 0x10 diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 5ac2e27d1a..00764902bc 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -288,19 +288,36 @@ static void i915_set_viewport_state( struct pipe_context *pipe, } -static void i915_set_setup_state( struct pipe_context *pipe, - const struct pipe_setup_state *setup ) + +static const struct pipe_rasterizer_state * +i915_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *setup) +{ + struct pipe_rasterizer_state *raster = + malloc(sizeof(struct pipe_rasterizer_state)); + memcpy(raster, setup, sizeof(struct pipe_rasterizer_state)); + + return raster; +} + +static void i915_bind_rasterizer_state( struct pipe_context *pipe, + const struct pipe_rasterizer_state *setup ) { struct i915_context *i915 = i915_context(pipe); - i915->setup = *setup; + i915->rasterizer = setup; /* pass-through to draw module */ draw_set_setup_state(i915->draw, setup); - i915->dirty |= I915_NEW_SETUP; + i915->dirty |= I915_NEW_RASTERIZER; } +static void i915_delete_rasterizer_state( struct pipe_context *pipe, + const struct pipe_rasterizer_state *setup ) +{ + free((struct pipe_rasterizer_state*)setup); +} static void i915_set_vertex_buffer( struct pipe_context *pipe, unsigned index, @@ -338,6 +355,10 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.bind_depth_stencil_state = i915_bind_depth_stencil_state; i915->pipe.delete_depth_stencil_state = i915_delete_depth_stencil_state; + i915->pipe.create_rasterizer_state = i915_create_rasterizer_state; + i915->pipe.bind_rasterizer_state = i915_bind_rasterizer_state; + i915->pipe.delete_rasterizer_state = i915_delete_rasterizer_state; + i915->pipe.set_alpha_test_state = i915_set_alpha_test_state; i915->pipe.set_blend_color = i915_set_blend_color; i915->pipe.set_clip_state = i915_set_clip_state; @@ -348,7 +369,6 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.set_vs_state = i915_set_vs_state; i915->pipe.set_polygon_stipple = i915_set_polygon_stipple; i915->pipe.set_scissor_state = i915_set_scissor_state; - i915->pipe.set_setup_state = i915_set_setup_state; i915->pipe.set_texture_state = i915_set_texture_state; i915->pipe.set_viewport_state = i915_set_viewport_state; i915->pipe.set_vertex_buffer = i915_set_vertex_buffer; diff --git a/src/mesa/pipe/i915simple/i915_state_derived.c b/src/mesa/pipe/i915simple/i915_state_derived.c index 792bb93b17..504bc10a9e 100644 --- a/src/mesa/pipe/i915simple/i915_state_derived.c +++ b/src/mesa/pipe/i915simple/i915_state_derived.c @@ -44,7 +44,7 @@ static void calculate_vertex_layout( struct i915_context *i915 ) { const uint inputsRead = i915->fs.inputs_read; const interp_mode colorInterp - = i915->setup.flatshade ? INTERP_CONSTANT : INTERP_LINEAR; + = i915->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR; struct vertex_info *vinfo = &i915->current.vertex_info; uint front0 = 0, back0 = 0, front1 = 0, back1 = 0; boolean needW = 0; @@ -103,7 +103,7 @@ static void calculate_vertex_layout( struct i915_context *i915 ) * lighting. Edgeflag is dealt with specially by setting bits in * the vertex header. */ - if (i915->setup.light_twoside) { + if (i915->rasterizer->light_twoside) { if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) { back0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0, FORMAT_OMIT, colorInterp); @@ -142,7 +142,7 @@ static void calculate_vertex_layout( struct i915_context *i915 ) */ void i915_update_derived( struct i915_context *i915 ) { - if (i915->dirty & (I915_NEW_SETUP | I915_NEW_FS)) + if (i915->dirty & (I915_NEW_RASTERIZER | I915_NEW_FS)) calculate_vertex_layout( i915 ); if (i915->dirty & (I915_NEW_SAMPLER | I915_NEW_TEXTURE)) diff --git a/src/mesa/pipe/i915simple/i915_state_dynamic.c b/src/mesa/pipe/i915simple/i915_state_dynamic.c index 9140eee7c2..a9791962e2 100644 --- a/src/mesa/pipe/i915simple/i915_state_dynamic.c +++ b/src/mesa/pipe/i915simple/i915_state_dynamic.c @@ -261,10 +261,10 @@ static void upload_DEPTHSCALE( struct i915_context *i915 ) memset( ds, 0, sizeof(ds) ); - /* I915_NEW_SETUP + /* I915_NEW_RASTERIZER */ ds[0].u = _3DSTATE_DEPTH_OFFSET_SCALE; - ds[1].f = i915->setup.offset_scale; + ds[1].f = i915->rasterizer->offset_scale; set_dynamic_indirect( i915, I915_DYNAMIC_DEPTHSCALE_0, @@ -273,7 +273,7 @@ static void upload_DEPTHSCALE( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_DEPTHSCALE = { - .dirty = I915_NEW_SETUP, + .dirty = I915_NEW_RASTERIZER, .update = upload_DEPTHSCALE }; @@ -298,9 +298,9 @@ static void upload_STIPPLE( struct i915_context *i915 ) st[0] = _3DSTATE_STIPPLE; st[1] = 0; - /* I915_NEW_SETUP + /* I915_NEW_RASTERIZER */ - if (i915->setup.poly_stipple_enable) { + if (i915->rasterizer->poly_stipple_enable) { st[1] |= ST1_ENABLE; } @@ -333,7 +333,7 @@ static void upload_STIPPLE( struct i915_context *i915 ) const struct i915_tracked_state i915_upload_STIPPLE = { - .dirty = I915_NEW_SETUP | I915_NEW_STIPPLE, + .dirty = I915_NEW_RASTERIZER | I915_NEW_STIPPLE, .update = upload_STIPPLE }; @@ -346,7 +346,7 @@ static void upload_SCISSOR_ENABLE( struct i915_context *i915 ) { unsigned sc[1]; - if (i915->setup.scissor) + if (i915->rasterizer->scissor) sc[0] = _3DSTATE_SCISSOR_ENABLE_CMD | ENABLE_SCISSOR_RECT; else sc[0] = _3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT; @@ -358,7 +358,7 @@ static void upload_SCISSOR_ENABLE( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_SCISSOR_ENABLE = { - .dirty = I915_NEW_SETUP, + .dirty = I915_NEW_RASTERIZER, .update = upload_SCISSOR_ENABLE }; diff --git a/src/mesa/pipe/i915simple/i915_state_immediate.c b/src/mesa/pipe/i915simple/i915_state_immediate.c index 484913d308..73508f557f 100644 --- a/src/mesa/pipe/i915simple/i915_state_immediate.c +++ b/src/mesa/pipe/i915simple/i915_state_immediate.c @@ -62,8 +62,8 @@ static void upload_S2S4(struct i915_context *i915) assert(LIS4); /* should never be zero? */ } - /* I915_NEW_SETUP */ - switch (i915->setup.cull_mode) { + /* I915_NEW_RASTERIZER */ + switch (i915->rasterizer->cull_mode) { case PIPE_WINDING_NONE: LIS4 |= S4_CULLMODE_NONE; break; @@ -78,25 +78,25 @@ static void upload_S2S4(struct i915_context *i915) break; } - /* I915_NEW_SETUP */ + /* I915_NEW_RASTERIZER */ { - int line_width = CLAMP((int)(i915->setup.line_width * 2), 1, 0xf); + int line_width = CLAMP((int)(i915->rasterizer->line_width * 2), 1, 0xf); LIS4 |= line_width << S4_LINE_WIDTH_SHIFT; - if (i915->setup.line_smooth) + if (i915->rasterizer->line_smooth) LIS4 |= S4_LINE_ANTIALIAS_ENABLE; } - /* I915_NEW_SETUP */ + /* I915_NEW_RASTERIZER */ { - int point_size = CLAMP((int) i915->setup.point_size, 1, 0xff); + int point_size = CLAMP((int) i915->rasterizer->point_size, 1, 0xff); LIS4 |= point_size << S4_POINT_WIDTH_SHIFT; } - /* I915_NEW_SETUP */ - if (i915->setup.flatshade) { + /* I915_NEW_RASTERIZER */ + if (i915->rasterizer->flatshade) { LIS4 |= (S4_FLATSHADE_ALPHA | S4_FLATSHADE_COLOR | S4_FLATSHADE_SPECULAR); @@ -114,7 +114,7 @@ static void upload_S2S4(struct i915_context *i915) const struct i915_tracked_state i915_upload_S2S4 = { - .dirty = I915_NEW_SETUP | I915_NEW_VERTEX_FORMAT, + .dirty = I915_NEW_RASTERIZER | I915_NEW_VERTEX_FORMAT, .update = upload_S2S4 }; @@ -165,7 +165,7 @@ static void upload_S5( struct i915_context *i915 ) #if 0 - /* I915_NEW_SETUP */ + /* I915_NEW_RASTERIZER */ if (i915->state.Polygon->OffsetFill) { LIS5 |= S5_GLOBAL_DEPTH_OFFSET_ENABLE; } @@ -179,7 +179,7 @@ static void upload_S5( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_S5 = { - .dirty = (I915_NEW_DEPTH_STENCIL | I915_NEW_BLEND | I915_NEW_SETUP), + .dirty = (I915_NEW_DEPTH_STENCIL | I915_NEW_BLEND | I915_NEW_RASTERIZER), .update = upload_S5 }; @@ -247,9 +247,9 @@ static void upload_S7( struct i915_context *i915 ) { float LIS7; - /* I915_NEW_SETUP + /* I915_NEW_RASTERIZER */ - LIS7 = i915->setup.offset_units; /* probably incorrect */ + LIS7 = i915->rasterizer->offset_units; /* probably incorrect */ if (LIS7 != i915->current.immediate[I915_IMMEDIATE_S7]) { i915->current.immediate[I915_IMMEDIATE_S7] = LIS7; @@ -258,7 +258,7 @@ static void upload_S7( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_S7 = { - .dirty = I915_NEW_SETUP, + .dirty = I915_NEW_RASTERIZER, .update = upload_S7 }; diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 488f002531..dda758fe6a 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -101,6 +101,14 @@ struct pipe_context { void (*delete_sampler_state)(struct pipe_context *, const struct pipe_sampler_state *); + const struct pipe_rasterizer_state *(*create_rasterizer_state)( + struct pipe_context *, + const struct pipe_rasterizer_state *); + void (*bind_rasterizer_state)(struct pipe_context *, + const struct pipe_rasterizer_state *); + void (*delete_rasterizer_state)(struct pipe_context *, + const struct pipe_rasterizer_state *); + const struct pipe_depth_stencil_state * (*create_depth_stencil_state)( struct pipe_context *, const struct pipe_depth_stencil_state *); @@ -140,9 +148,6 @@ struct pipe_context { void (*set_polygon_stipple)( struct pipe_context *, const struct pipe_poly_stipple * ); - void (*set_setup_state)( struct pipe_context *, - const struct pipe_setup_state * ); - void (*set_scissor_state)( struct pipe_context *, const struct pipe_scissor_state * ); diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 30e559b594..048feede3b 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -65,9 +65,9 @@ struct pipe_buffer_handle; /** - * Primitive (point/line/tri) setup info + * Primitive (point/line/tri) rasterization info */ -struct pipe_setup_state +struct pipe_rasterizer_state { unsigned flatshade:1; unsigned light_twoside:1; diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 9a8b55bb0e..7753ce40d7 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -259,6 +259,9 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.create_depth_stencil_state = softpipe_create_depth_stencil_state; softpipe->pipe.bind_depth_stencil_state = softpipe_bind_depth_stencil_state; softpipe->pipe.delete_depth_stencil_state = softpipe_delete_depth_stencil_state; + softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state; + softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state; + softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state; softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state; softpipe->pipe.set_blend_color = softpipe_set_blend_color; @@ -271,7 +274,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.set_vs_state = softpipe_set_vs_state; softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; softpipe->pipe.set_scissor_state = softpipe_set_scissor_state; - softpipe->pipe.set_setup_state = softpipe_set_setup_state; softpipe->pipe.set_texture_state = softpipe_set_texture_state; softpipe->pipe.set_viewport_state = softpipe_set_viewport_state; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 4cbb0f891e..f1bb3d39a6 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -47,7 +47,7 @@ struct draw_stage; #define SP_NEW_VIEWPORT 0x1 -#define SP_NEW_SETUP 0x2 +#define SP_NEW_RASTERIZER 0x2 #define SP_NEW_FS 0x4 #define SP_NEW_BLEND 0x8 #define SP_NEW_CLIP 0x10 @@ -73,6 +73,7 @@ struct softpipe_context { const struct pipe_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; + const struct pipe_rasterizer_state *rasterizer; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; @@ -85,7 +86,6 @@ struct softpipe_context { struct pipe_shader_state vs; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_setup_state setup; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index 83d317c36f..c64a4e9708 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -351,7 +351,7 @@ static boolean setup_sort_vertices( struct setup_stage *setup, * - the GLSL gl_FrontFacing fragment attribute (bool) * - two-sided stencil test */ - setup->quad.facing = (prim->det > 0.0) ^ (setup->softpipe->setup.front_winding == PIPE_WINDING_CW); + setup->quad.facing = (prim->det > 0.0) ^ (setup->softpipe->rasterizer->front_winding == PIPE_WINDING_CW); return TRUE; } @@ -830,10 +830,10 @@ setup_line(struct draw_stage *stage, struct prim_header *prim) const int errorDec = error - dx; for (i = 0; i < dx; i++) { - if (!sp->setup.line_stipple_enable || + if (!sp->rasterizer->line_stipple_enable || stipple_test(sp->line_stipple_counter, - sp->setup.line_stipple_pattern, - sp->setup.line_stipple_factor + 1)) { + sp->rasterizer->line_stipple_pattern, + sp->rasterizer->line_stipple_factor + 1)) { plot(setup, x0, y0); } @@ -857,10 +857,10 @@ setup_line(struct draw_stage *stage, struct prim_header *prim) const int errorDec = error - dy; for (i = 0; i < dy; i++) { - if (!sp->setup.line_stipple_enable || + if (!sp->rasterizer->line_stipple_enable || stipple_test(sp->line_stipple_counter, - sp->setup.line_stipple_pattern, - sp->setup.line_stipple_factor + 1)) { + sp->rasterizer->line_stipple_pattern, + sp->rasterizer->line_stipple_factor + 1)) { plot(setup, x0, y0); } @@ -899,8 +899,8 @@ setup_point(struct draw_stage *stage, struct prim_header *prim) const int sizeAttr = setup->lookup[TGSI_ATTRIB_POINTSIZE]; const float halfSize = sizeAttr ? (0.5f * v0->data[sizeAttr][0]) - : (0.5f * setup->softpipe->setup.point_size); - const boolean round = setup->softpipe->setup.point_smooth; + : (0.5f * setup->softpipe->rasterizer->point_size); + const boolean round = setup->softpipe->rasterizer->point_smooth; const float x = v0->data[TGSI_ATTRIB_POS][0]; const float y = v0->data[TGSI_ATTRIB_POS][1]; unsigned slot, j; diff --git a/src/mesa/pipe/softpipe/sp_quad.c b/src/mesa/pipe/softpipe/sp_quad.c index 1f45776d47..fc4f8328cf 100644 --- a/src/mesa/pipe/softpipe/sp_quad.c +++ b/src/mesa/pipe/softpipe/sp_quad.c @@ -36,9 +36,9 @@ sp_build_quad_pipeline(struct softpipe_context *sp) sp->quad.first = sp->quad.occlusion; } - if (sp->setup.poly_smooth || - sp->setup.line_smooth || - sp->setup.point_smooth) { + if (sp->rasterizer->poly_smooth || + sp->rasterizer->line_smooth || + sp->rasterizer->point_smooth) { sp->quad.coverage->next = sp->quad.first; sp->quad.first = sp->quad.coverage; } @@ -65,7 +65,7 @@ sp_build_quad_pipeline(struct softpipe_context *sp) sp->quad.first = sp->quad.shade; } - if (sp->setup.poly_stipple_enable) { + if (sp->rasterizer->poly_stipple_enable) { sp->quad.polygon_stipple->next = sp->quad.first; sp->quad.first = sp->quad.polygon_stipple; } diff --git a/src/mesa/pipe/softpipe/sp_quad_coverage.c b/src/mesa/pipe/softpipe/sp_quad_coverage.c index 8dfec59350..89f50bcca2 100644 --- a/src/mesa/pipe/softpipe/sp_quad_coverage.c +++ b/src/mesa/pipe/softpipe/sp_quad_coverage.c @@ -47,9 +47,9 @@ coverage_quad(struct quad_stage *qs, struct quad_header *quad) { struct softpipe_context *softpipe = qs->softpipe; - if ((softpipe->setup.poly_smooth && quad->prim == PRIM_TRI) || - (softpipe->setup.line_smooth && quad->prim == PRIM_LINE) || - (softpipe->setup.point_smooth && quad->prim == PRIM_POINT)) { + if ((softpipe->rasterizer->poly_smooth && quad->prim == PRIM_TRI) || + (softpipe->rasterizer->line_smooth && quad->prim == PRIM_LINE) || + (softpipe->rasterizer->point_smooth && quad->prim == PRIM_POINT)) { unsigned j; for (j = 0; j < QUAD_SIZE; j++) { assert(quad->coverage[j] >= 0.0); diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index caec3b4519..62bd26c4df 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -50,7 +50,6 @@ void softpipe_bind_sampler_state(struct pipe_context *, void softpipe_delete_sampler_state(struct pipe_context *, const struct pipe_sampler_state *); - const struct pipe_depth_stencil_state * softpipe_create_depth_stencil_state(struct pipe_context *, const struct pipe_depth_stencil_state *); @@ -59,6 +58,14 @@ void softpipe_bind_depth_stencil_state(struct pipe_context *, void softpipe_delete_depth_stencil_state(struct pipe_context *, const struct pipe_depth_stencil_state *); +const struct pipe_rasterizer_state * +softpipe_create_rasterizer_state(struct pipe_context *, + const struct pipe_rasterizer_state *); +void softpipe_bind_rasterizer_state(struct pipe_context *, + const struct pipe_rasterizer_state *); +void softpipe_delete_rasterizer_state(struct pipe_context *, + const struct pipe_rasterizer_state *); + void softpipe_set_framebuffer_state( struct pipe_context *, const struct pipe_framebuffer_state * ); @@ -93,9 +100,6 @@ void softpipe_set_polygon_stipple( struct pipe_context *, void softpipe_set_scissor_state( struct pipe_context *, const struct pipe_scissor_state * ); -void softpipe_set_setup_state( struct pipe_context *, - const struct pipe_setup_state * ); - void softpipe_set_texture_state( struct pipe_context *, unsigned unit, struct pipe_mipmap_tree * ); diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index 47743e185c..8c6bacf65c 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -45,7 +45,7 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) { const uint inputsRead = softpipe->fs.inputs_read; const interp_mode colorInterp - = softpipe->setup.flatshade ? INTERP_CONSTANT : INTERP_LINEAR; + = softpipe->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR; struct vertex_info *vinfo = &softpipe->vertex_info; uint front0 = 0, back0 = 0, front1 = 0, back1 = 0; uint i; @@ -112,7 +112,7 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) * lighting. Edgeflag is dealt with specially by setting bits in * the vertex header. */ - if (softpipe->setup.light_twoside) { + if (softpipe->rasterizer->light_twoside) { if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) { back0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0, FORMAT_OMIT, colorInterp); @@ -160,7 +160,7 @@ compute_cliprect(struct softpipe_context *sp) surfHeight = sp->scissor.maxy; } - if (sp->setup.scissor) { + if (sp->rasterizer->scissor) { /* clip to scissor rect */ sp->cliprect.minx = MAX2(sp->scissor.minx, 0); sp->cliprect.miny = MAX2(sp->scissor.miny, 0); @@ -182,7 +182,7 @@ compute_cliprect(struct softpipe_context *sp) */ void softpipe_update_derived( struct softpipe_context *softpipe ) { - if (softpipe->dirty & (SP_NEW_SETUP | SP_NEW_FS)) + if (softpipe->dirty & (SP_NEW_RASTERIZER | SP_NEW_FS)) calculate_vertex_layout( softpipe ); if (softpipe->dirty & (SP_NEW_SCISSOR | @@ -194,7 +194,7 @@ void softpipe_update_derived( struct softpipe_context *softpipe ) SP_NEW_DEPTH_STENCIL | SP_NEW_ALPHA_TEST | SP_NEW_FRAMEBUFFER | - SP_NEW_SETUP | + SP_NEW_RASTERIZER | SP_NEW_FS)) sp_build_quad_pipeline(softpipe); diff --git a/src/mesa/pipe/softpipe/sp_state_setup.c b/src/mesa/pipe/softpipe/sp_state_setup.c index 4715a26f55..6788396355 100644 --- a/src/mesa/pipe/softpipe/sp_state_setup.c +++ b/src/mesa/pipe/softpipe/sp_state_setup.c @@ -31,17 +31,35 @@ #include "pipe/draw/draw_context.h" -void softpipe_set_setup_state( struct pipe_context *pipe, - const struct pipe_setup_state *setup ) + +const struct pipe_rasterizer_state * +softpipe_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *setup) +{ + struct pipe_rasterizer_state *raster = + malloc(sizeof(struct pipe_rasterizer_state)); + memcpy(raster, setup, sizeof(struct pipe_rasterizer_state)); + + return raster; +} + +void softpipe_bind_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *setup) { struct softpipe_context *softpipe = softpipe_context(pipe); /* pass-through to draw module */ draw_set_setup_state(softpipe->draw, setup); - memcpy( &softpipe->setup, setup, sizeof(*setup) ); + softpipe->rasterizer = setup; + + softpipe->dirty |= SP_NEW_RASTERIZER; +} - softpipe->dirty |= SP_NEW_SETUP; +void softpipe_delete_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *rasterizer) +{ + free((struct pipe_rasterizer_state*)rasterizer); } diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 99d0bcb90b..a4af3aeb20 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -53,7 +53,7 @@ static const struct st_tracked_state *atoms[] = &st_update_vs, &st_update_fs, - &st_update_setup, + &st_update_rasterizer, &st_update_polygon_stipple, &st_update_viewport, &st_update_scissor, diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 0e362b1fbf..26f6514698 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -51,7 +51,7 @@ const struct st_tracked_state st_update_depth_stencil; const struct st_tracked_state st_update_tnl; const struct st_tracked_state st_update_fs; const struct st_tracked_state st_update_vs; -const struct st_tracked_state st_update_setup; +const struct st_tracked_state st_update_rasterizer; const struct st_tracked_state st_update_polygon_stipple; const struct st_tracked_state st_update_viewport; const struct st_tracked_state st_update_scissor; diff --git a/src/mesa/state_tracker/st_atom_setup.c b/src/mesa/state_tracker/st_atom_setup.c index 09d921560d..cab8ad5cd6 100644 --- a/src/mesa/state_tracker/st_atom_setup.c +++ b/src/mesa/state_tracker/st_atom_setup.c @@ -32,6 +32,7 @@ #include "st_context.h" +#include "st_cache.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "st_atom.h" @@ -68,20 +69,21 @@ static GLboolean get_offset_flag( GLuint fill_mode, } -static void update_setup_state( struct st_context *st ) +static void update_raster_state( struct st_context *st ) { GLcontext *ctx = st->ctx; - struct pipe_setup_state setup; + struct pipe_rasterizer_state raster; + const struct pipe_rasterizer_state *cached; - memset(&setup, 0, sizeof(setup)); + memset(&raster, 0, sizeof(raster)); /* _NEW_POLYGON, _NEW_BUFFERS */ { if (ctx->Polygon.FrontFace == GL_CCW) - setup.front_winding = PIPE_WINDING_CCW; + raster.front_winding = PIPE_WINDING_CCW; else - setup.front_winding = PIPE_WINDING_CW; + raster.front_winding = PIPE_WINDING_CW; /* XXX * I think the intention here is that user-created framebuffer objects @@ -90,13 +92,13 @@ static void update_setup_state( struct st_context *st ) * But this is an implementation/driver-specific artifact - remove... */ if (ctx->DrawBuffer && ctx->DrawBuffer->Name != 0) - setup.front_winding ^= PIPE_WINDING_BOTH; + raster.front_winding ^= PIPE_WINDING_BOTH; } /* _NEW_LIGHT */ if (ctx->Light.ShadeModel == GL_FLAT) - setup.flatshade = 1; + raster.flatshade = 1; /* _NEW_LIGHT | _NEW_PROGRAM * @@ -105,23 +107,23 @@ static void update_setup_state( struct st_context *st ) * GL_VERTEX_PROGRAM_TWO_SIDE is set). Note the logic here. */ if (ctx->VertexProgram._Enabled) { - setup.light_twoside = ctx->VertexProgram.TwoSideEnabled; + raster.light_twoside = ctx->VertexProgram.TwoSideEnabled; } else if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) { - setup.light_twoside = 1; + raster.light_twoside = 1; } /* _NEW_POLYGON */ if (ctx->Polygon.CullFlag) { if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) { - setup.cull_mode = PIPE_WINDING_BOTH; + raster.cull_mode = PIPE_WINDING_BOTH; } else if (ctx->Polygon.CullFaceMode == GL_FRONT) { - setup.cull_mode = setup.front_winding; + raster.cull_mode = raster.front_winding; } else { - setup.cull_mode = setup.front_winding ^ PIPE_WINDING_BOTH; + raster.cull_mode = raster.front_winding ^ PIPE_WINDING_BOTH; } } @@ -131,23 +133,23 @@ static void update_setup_state( struct st_context *st ) GLuint fill_front = translate_fill( ctx->Polygon.FrontMode ); GLuint fill_back = translate_fill( ctx->Polygon.BackMode ); - if (setup.front_winding == PIPE_WINDING_CW) { - setup.fill_cw = fill_front; - setup.fill_ccw = fill_back; + if (raster.front_winding == PIPE_WINDING_CW) { + raster.fill_cw = fill_front; + raster.fill_ccw = fill_back; } else { - setup.fill_cw = fill_back; - setup.fill_ccw = fill_front; + raster.fill_cw = fill_back; + raster.fill_ccw = fill_front; } /* Simplify when culling is active: */ - if (setup.cull_mode & PIPE_WINDING_CW) { - setup.fill_cw = setup.fill_ccw; + if (raster.cull_mode & PIPE_WINDING_CW) { + raster.fill_cw = raster.fill_ccw; } - if (setup.cull_mode & PIPE_WINDING_CCW) { - setup.fill_ccw = setup.fill_cw; + if (raster.cull_mode & PIPE_WINDING_CCW) { + raster.fill_ccw = raster.fill_cw; } } @@ -155,67 +157,68 @@ static void update_setup_state( struct st_context *st ) */ if (ctx->Polygon.OffsetUnits != 0.0 || ctx->Polygon.OffsetFactor != 0.0) { - setup.offset_cw = get_offset_flag( setup.fill_cw, &ctx->Polygon ); - setup.offset_ccw = get_offset_flag( setup.fill_ccw, &ctx->Polygon ); - setup.offset_units = ctx->Polygon.OffsetUnits; - setup.offset_scale = ctx->Polygon.OffsetFactor; + raster.offset_cw = get_offset_flag( raster.fill_cw, &ctx->Polygon ); + raster.offset_ccw = get_offset_flag( raster.fill_ccw, &ctx->Polygon ); + raster.offset_units = ctx->Polygon.OffsetUnits; + raster.offset_scale = ctx->Polygon.OffsetFactor; } if (ctx->Polygon.SmoothFlag) - setup.poly_smooth = 1; + raster.poly_smooth = 1; if (ctx->Polygon.StippleFlag) - setup.poly_stipple_enable = 1; + raster.poly_stipple_enable = 1; /* _NEW_BUFFERS, _NEW_POLYGON */ - if (setup.fill_cw != PIPE_POLYGON_MODE_FILL || - setup.fill_ccw != PIPE_POLYGON_MODE_FILL) + if (raster.fill_cw != PIPE_POLYGON_MODE_FILL || + raster.fill_ccw != PIPE_POLYGON_MODE_FILL) { GLfloat mrd = (ctx->DrawBuffer ? ctx->DrawBuffer->_MRD : 1.0); - setup.offset_units = ctx->Polygon.OffsetFactor * mrd; - setup.offset_scale = (ctx->Polygon.OffsetUnits * mrd * + raster.offset_units = ctx->Polygon.OffsetFactor * mrd; + raster.offset_scale = (ctx->Polygon.OffsetUnits * mrd * st->polygon_offset_scale); } /* _NEW_POINT */ - setup.point_size = ctx->Point.Size; - setup.point_smooth = ctx->Point.SmoothFlag; + raster.point_size = ctx->Point.Size; + raster.point_smooth = ctx->Point.SmoothFlag; /* _NEW_LINE */ - setup.line_width = ctx->Line.Width; - setup.line_smooth = ctx->Line.SmoothFlag; - setup.line_stipple_enable = ctx->Line.StippleFlag; - setup.line_stipple_pattern = ctx->Line.StipplePattern; + raster.line_width = ctx->Line.Width; + raster.line_smooth = ctx->Line.SmoothFlag; + raster.line_stipple_enable = ctx->Line.StippleFlag; + raster.line_stipple_pattern = ctx->Line.StipplePattern; /* GL stipple factor is in [1,256], remap to [0, 255] here */ - setup.line_stipple_factor = ctx->Line.StippleFactor - 1; + raster.line_stipple_factor = ctx->Line.StippleFactor - 1; /* _NEW_MULTISAMPLE */ if (ctx->Multisample.Enabled) - setup.multisample = 1; + raster.multisample = 1; /* _NEW_SCISSOR */ if (ctx->Scissor.Enabled) - setup.scissor = 1; + raster.scissor = 1; - if (memcmp(&setup, &st->state.setup, sizeof(setup)) != 0) { - st->state.setup = setup; - st->pipe->set_setup_state( st->pipe, &setup ); + cached = st_cached_rasterizer_state(st, &raster); + if (st->state.rasterizer != cached) { + st->state.rasterizer = cached; + st->pipe->bind_rasterizer_state( st->pipe, cached ); } } -const struct st_tracked_state st_update_setup = { - .name = "st_update_setup", +const struct st_tracked_state st_update_rasterizer = { + .name = "st_update_rasterizer", .dirty = { .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_LINE | _NEW_SCISSOR | _NEW_POINT | _NEW_BUFFERS | _NEW_MULTISAMPLE), .st = 0, }, - .update = update_setup_state + .update = update_raster_state }; diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index 64c03be99d..a687c15587 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -93,3 +93,21 @@ struct pipe_depth_stencil_state * st_cached_depth_stencil_state( } return (struct pipe_depth_stencil_state*)(cso_hash_iter_data(iter)); } + +struct pipe_rasterizer_state * st_cached_rasterizer_state( + struct st_context *st, + const struct pipe_rasterizer_state *raster) +{ + unsigned hash_key = cso_construct_key((void*)raster, + sizeof(struct pipe_rasterizer_state)); + struct cso_hash_iter iter = cso_find_state_template(st->cache, + hash_key, CSO_RASTERIZER, + (void*)raster); + if (cso_hash_iter_is_null(iter)) { + const struct pipe_rasterizer_state *created_state = + st->pipe->create_rasterizer_state(st->pipe, raster); + iter = cso_insert_state(st->cache, hash_key, CSO_RASTERIZER, + (void*)created_state); + } + return (struct pipe_rasterizer_state*)(cso_hash_iter_data(iter)); +} diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index 78cb2e774e..a06af31123 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -47,6 +47,10 @@ struct pipe_sampler_state * st_cached_sampler_state( struct pipe_depth_stencil_state *st_cached_depth_stencil_state( struct st_context *st, - const struct pipe_depth_stencil_state *sampler); + const struct pipe_depth_stencil_state *depth_stencil); + +struct pipe_rasterizer_state *st_cached_rasterizer_state( + struct st_context *st, + const struct pipe_rasterizer_state *raster); #endif diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index e9aabd15b5..584bc1cc2a 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -329,16 +329,18 @@ clear_with_quad(GLcontext *ctx, /* setup state: nothing */ { - struct pipe_setup_state setup; - memset(&setup, 0, sizeof(setup)); + struct pipe_rasterizer_state raster; + const struct pipe_rasterizer_state *cached; + memset(&raster, 0, sizeof(raster)); #if 0 /* don't do per-pixel scissor; we'll just draw a PIPE_PRIM_QUAD * that matches the scissor bounds. */ if (ctx->Scissor.Enabled) - setup.scissor = 1; + raster.scissor = 1; #endif - pipe->set_setup_state(pipe, &setup); + cached = st_cached_rasterizer_state(ctx->st, &raster); + pipe->bind_rasterizer_state(pipe, cached); } /* fragment shader state: color pass-through program */ @@ -394,7 +396,7 @@ clear_with_quad(GLcontext *ctx, pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil); pipe->set_fs_state(pipe, &st->state.fs); pipe->set_vs_state(pipe, &st->state.vs); - pipe->set_setup_state(pipe, &st->state.setup); + pipe->bind_rasterizer_state(pipe, st->state.rasterizer); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); /* OR: st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index a0012e3a8c..78ede8e225 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -316,11 +316,13 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* setup state: just scissor */ { - struct pipe_setup_state setup; + struct pipe_rasterizer_state setup; + struct pipe_rasterizer_state *cached; memset(&setup, 0, sizeof(setup)); if (ctx->Scissor.Enabled) setup.scissor = 1; - pipe->set_setup_state(pipe, &setup); + cached = st_cached_rasterizer_state(ctx->st, &setup); + pipe->bind_rasterizer_state(pipe, cached); } /* fragment shader state: TEX lookup program */ @@ -400,7 +402,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, draw_quad(ctx, x0, y0, z, x1, y1); /* restore GL state */ - pipe->set_setup_state(pipe, &ctx->st->state.setup); + pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer); pipe->set_fs_state(pipe, &ctx->st->state.fs); pipe->set_vs_state(pipe, &ctx->st->state.vs); pipe->set_texture_state(pipe, unit, ctx->st->state.texture[unit]); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 7c887d0b55..516d319a6e 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -77,6 +77,7 @@ struct st_context const struct pipe_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; + const struct pipe_rasterizer_state *rasterizer; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; @@ -88,7 +89,6 @@ struct st_context struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_setup_state setup; struct pipe_shader_state fs; struct pipe_shader_state vs; struct pipe_viewport_state viewport; diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 69f4b7fa5b..1ea7799021 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -394,7 +394,7 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(draw); draw_set_viewport_state(draw, &st->state.viewport); draw_set_clip_state(draw, &st->state.clip); - draw_set_setup_state(draw, &st->state.setup); + draw_set_setup_state(draw, st->state.rasterizer); draw_set_vertex_shader(draw, &st->state.vs); /* XXX need to set vertex info too */ -- cgit v1.2.3 From ccd63b54cfbb6bb241d55f7ac95afcd14819f469 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Tue, 18 Sep 2007 13:24:44 -0400 Subject: Convert shader to an immutable state object. --- src/mesa/pipe/cso_cache/cso_cache.c | 13 +++++++++---- src/mesa/pipe/cso_cache/cso_cache.h | 4 +++- src/mesa/pipe/failover/fo_context.h | 4 ++-- src/mesa/pipe/failover/fo_state.c | 19 +++++++++---------- src/mesa/pipe/failover/fo_state_emit.c | 4 ++-- src/mesa/pipe/i915simple/i915_context.h | 2 +- src/mesa/pipe/i915simple/i915_fpc.h | 2 +- src/mesa/pipe/i915simple/i915_fpc_translate.c | 8 ++++---- src/mesa/pipe/i915simple/i915_state.c | 27 ++++++++++++++++++++++----- src/mesa/pipe/i915simple/i915_state_derived.c | 2 +- src/mesa/pipe/p_context.h | 16 ++++++++++------ src/mesa/pipe/softpipe/sp_context.c | 14 ++++++++------ src/mesa/pipe/softpipe/sp_context.h | 4 ++-- src/mesa/pipe/softpipe/sp_quad_fs.c | 2 +- src/mesa/pipe/softpipe/sp_state.h | 14 +++++++++----- src/mesa/pipe/softpipe/sp_state_derived.c | 2 +- src/mesa/pipe/softpipe/sp_state_fs.c | 24 ++++++++++++++++++++---- src/mesa/state_tracker/st_atom_fs.c | 16 +++++++++++----- src/mesa/state_tracker/st_atom_vs.c | 16 +++++++++++----- src/mesa/state_tracker/st_cache.c | 18 ++++++++++++++++++ src/mesa/state_tracker/st_cache.h | 4 ++++ src/mesa/state_tracker/st_cb_clear.c | 12 ++++++++---- src/mesa/state_tracker/st_cb_drawpixels.c | 12 ++++++++---- src/mesa/state_tracker/st_cb_rasterpos.c | 6 +++--- src/mesa/state_tracker/st_context.h | 4 ++-- src/mesa/state_tracker/st_draw.c | 6 +++--- src/mesa/state_tracker/st_program.h | 6 +++--- 27 files changed, 176 insertions(+), 85 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/cso_cache/cso_cache.c b/src/mesa/pipe/cso_cache/cso_cache.c index 4aaadf00e6..be653d9494 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.c +++ b/src/mesa/pipe/cso_cache/cso_cache.c @@ -80,6 +80,8 @@ static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_ hash = sc->depth_stencil_hash; case CSO_RASTERIZER: hash = sc->rasterizer_hash; + case CSO_SHADER: + hash = sc->shader_hash; } return hash; @@ -96,6 +98,8 @@ static int _cso_size_for_type(enum cso_cache_type type) return sizeof(struct pipe_depth_stencil_state); case CSO_RASTERIZER: return sizeof(struct pipe_rasterizer_state); + case CSO_SHADER: + return sizeof(struct pipe_shader_state); } return 0; } @@ -144,10 +148,11 @@ struct cso_cache *cso_cache_create(void) { struct cso_cache *sc = malloc(sizeof(struct cso_cache)); - sc->blend_hash = cso_hash_create(); - sc->sampler_hash = cso_hash_create(); + sc->blend_hash = cso_hash_create(); + sc->sampler_hash = cso_hash_create(); sc->depth_stencil_hash = cso_hash_create(); - sc->rasterizer_hash = cso_hash_create(); + sc->rasterizer_hash = cso_hash_create(); + sc->shader_hash = cso_hash_create(); return sc; } @@ -159,6 +164,6 @@ void cso_cache_delete(struct cso_cache *sc) cso_hash_delete(sc->sampler_hash); cso_hash_delete(sc->depth_stencil_hash); cso_hash_delete(sc->rasterizer_hash); + cso_hash_delete(sc->shader_hash); free(sc); } - diff --git a/src/mesa/pipe/cso_cache/cso_cache.h b/src/mesa/pipe/cso_cache/cso_cache.h index 23be9cd713..d9793ca855 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.h +++ b/src/mesa/pipe/cso_cache/cso_cache.h @@ -44,13 +44,15 @@ struct cso_cache { struct cso_hash *sampler_hash; struct cso_hash *depth_stencil_hash; struct cso_hash *rasterizer_hash; + struct cso_hash *shader_hash; }; enum cso_cache_type { CSO_BLEND, CSO_SAMPLER, CSO_DEPTH_STENCIL, - CSO_RASTERIZER + CSO_RASTERIZER, + CSO_SHADER }; unsigned cso_construct_key(void *item, int item_size); diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index b05ceb88ad..9556a17e4d 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -70,14 +70,14 @@ struct failover_context { const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; const struct pipe_rasterizer_state *rasterizer; + const struct pipe_shader_state *fragment_shader; + const struct pipe_shader_state *vertex_shader; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; struct pipe_framebuffer_state framebuffer; - struct pipe_shader_state fragment_shader; - struct pipe_shader_state vertex_shader; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index 8e2b649590..04ebd33d0d 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -125,28 +125,27 @@ failover_set_framebuffer_state(struct pipe_context *pipe, } static void -failover_set_fs_state(struct pipe_context *pipe, - const struct pipe_shader_state *fs) +failover_bind_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *fs) { struct failover_context *failover = failover_context(pipe); - failover->fragment_shader = *fs; + failover->fragment_shader = fs; failover->dirty |= FO_NEW_FRAGMENT_SHADER; - failover->hw->set_fs_state( failover->hw, fs ); + failover->hw->bind_fs_state( failover->hw, fs ); } static void -failover_set_vs_state(struct pipe_context *pipe, +failover_bind_vs_state(struct pipe_context *pipe, const struct pipe_shader_state *vs) { struct failover_context *failover = failover_context(pipe); - failover->vertex_shader = *vs; + failover->vertex_shader = vs; failover->dirty |= FO_NEW_VERTEX_SHADER; - failover->hw->set_vs_state( failover->hw, vs ); + failover->hw->bind_vs_state( failover->hw, vs ); } - static void failover_set_polygon_stipple( struct pipe_context *pipe, const struct pipe_poly_stipple *stipple ) @@ -258,14 +257,14 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.bind_sampler_state = failover_bind_sampler_state; failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state; failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state; + failover->pipe.bind_fs_state = failover_bind_fs_state; + failover->pipe.bind_vs_state = failover_bind_vs_state; failover->pipe.set_alpha_test_state = failover_set_alpha_test_state; failover->pipe.set_blend_color = failover_set_blend_color; failover->pipe.set_clip_state = failover_set_clip_state; failover->pipe.set_clear_color_state = failover_set_clear_color_state; failover->pipe.set_framebuffer_state = failover_set_framebuffer_state; - failover->pipe.set_fs_state = failover_set_fs_state; - failover->pipe.set_vs_state = failover_set_vs_state; failover->pipe.set_polygon_stipple = failover_set_polygon_stipple; failover->pipe.set_scissor_state = failover_set_scissor_state; failover->pipe.set_texture_state = failover_set_texture_state; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index 1c9573a7b0..9d304074d0 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -77,10 +77,10 @@ failover_state_emit( struct failover_context *failover ) failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer ); if (failover->dirty & FO_NEW_FRAGMENT_SHADER) - failover->sw->set_fs_state( failover->sw, &failover->fragment_shader ); + failover->sw->bind_fs_state( failover->sw, failover->fragment_shader ); if (failover->dirty & FO_NEW_VERTEX_SHADER) - failover->sw->set_vs_state( failover->sw, &failover->vertex_shader ); + failover->sw->bind_vs_state( failover->sw, failover->vertex_shader ); if (failover->dirty & FO_NEW_STIPPLE) failover->sw->set_polygon_stipple( failover->sw, &failover->poly_stipple ); diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index 3fab821fde..9052c92d72 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -127,6 +127,7 @@ struct i915_context const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; const struct pipe_rasterizer_state *rasterizer; + const struct pipe_shader_state *fs; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; @@ -134,7 +135,6 @@ struct i915_context struct pipe_clip_state clip; struct pipe_constant_buffer constants[PIPE_SHADER_TYPES]; struct pipe_framebuffer_state framebuffer; - struct pipe_shader_state fs; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; diff --git a/src/mesa/pipe/i915simple/i915_fpc.h b/src/mesa/pipe/i915simple/i915_fpc.h index 59fcbf40d9..84e4c5a6f3 100644 --- a/src/mesa/pipe/i915simple/i915_fpc.h +++ b/src/mesa/pipe/i915simple/i915_fpc.h @@ -44,7 +44,7 @@ * Program translation state */ struct i915_fp_compile { - struct pipe_shader_state *shader; + const struct pipe_shader_state *shader; struct vertex_info *vertex_info; diff --git a/src/mesa/pipe/i915simple/i915_fpc_translate.c b/src/mesa/pipe/i915simple/i915_fpc_translate.c index c2ad80c5d0..32c5600496 100644 --- a/src/mesa/pipe/i915simple/i915_fpc_translate.c +++ b/src/mesa/pipe/i915simple/i915_fpc_translate.c @@ -872,11 +872,11 @@ i915_translate_instructions(struct i915_fp_compile *p, static struct i915_fp_compile * i915_init_compile(struct i915_context *i915, - struct pipe_shader_state *fs) + const struct pipe_shader_state *fs) { struct i915_fp_compile *p = CALLOC_STRUCT(i915_fp_compile); - p->shader = &i915->fs; + p->shader = i915->fs; p->vertex_info = &i915->current.vertex_info; @@ -1032,8 +1032,8 @@ i915_fixup_depth_write(struct i915_fp_compile *p) void i915_translate_fragment_program( struct i915_context *i915 ) { - struct i915_fp_compile *p = i915_init_compile(i915, &i915->fs); - const struct tgsi_token *tokens = i915->fs.tokens; + struct i915_fp_compile *p = i915_init_compile(i915, i915->fs); + const struct tgsi_token *tokens = i915->fs->tokens; i915_find_wpos_space(p); diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 1dfa10ab28..fe835643e0 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -161,19 +161,29 @@ static void i915_set_polygon_stipple( struct pipe_context *pipe, } +static const struct pipe_shader_state * +i915_create_shader_state( struct pipe_context *pipe, + const struct pipe_shader_state *templ ) +{ + + struct pipe_shader_state *shader = malloc(sizeof(struct pipe_shader_state)); + memcpy(shader, templ, sizeof(struct pipe_shader_state)); + + return shader; +} -static void i915_set_fs_state( struct pipe_context *pipe, +static void i915_bind_fs_state( struct pipe_context *pipe, const struct pipe_shader_state *fs ) { struct i915_context *i915 = i915_context(pipe); - memcpy(&i915->fs, fs, sizeof(*fs)); + i915->fs = fs; i915->dirty |= I915_NEW_FS; } -static void i915_set_vs_state( struct pipe_context *pipe, +static void i915_bind_vs_state( struct pipe_context *pipe, const struct pipe_shader_state *vs ) { struct i915_context *i915 = i915_context(pipe); @@ -182,6 +192,11 @@ static void i915_set_vs_state( struct pipe_context *pipe, draw_set_vertex_shader(i915->draw, vs); } +static void i915_delete_shader_state( struct pipe_context *pipe, + const struct pipe_shader_state *shader ) +{ + free((struct pipe_shader_state*)shader); +} static void i915_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, @@ -358,6 +373,10 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.create_rasterizer_state = i915_create_rasterizer_state; i915->pipe.bind_rasterizer_state = i915_bind_rasterizer_state; i915->pipe.delete_rasterizer_state = i915_delete_rasterizer_state; + i915->pipe.create_shader_state = i915_create_shader_state; + i915->pipe.bind_fs_state = i915_bind_fs_state; + i915->pipe.bind_vs_state = i915_bind_vs_state; + i915->pipe.delete_shader_state = i915_delete_shader_state; i915->pipe.set_alpha_test_state = i915_set_alpha_test_state; i915->pipe.set_blend_color = i915_set_blend_color; @@ -365,8 +384,6 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.set_clear_color_state = i915_set_clear_color_state; i915->pipe.set_constant_buffer = i915_set_constant_buffer; i915->pipe.set_framebuffer_state = i915_set_framebuffer_state; - i915->pipe.set_fs_state = i915_set_fs_state; - i915->pipe.set_vs_state = i915_set_vs_state; i915->pipe.set_polygon_stipple = i915_set_polygon_stipple; i915->pipe.set_scissor_state = i915_set_scissor_state; i915->pipe.set_texture_state = i915_set_texture_state; diff --git a/src/mesa/pipe/i915simple/i915_state_derived.c b/src/mesa/pipe/i915simple/i915_state_derived.c index 504bc10a9e..8d404c55ab 100644 --- a/src/mesa/pipe/i915simple/i915_state_derived.c +++ b/src/mesa/pipe/i915simple/i915_state_derived.c @@ -42,7 +42,7 @@ */ static void calculate_vertex_layout( struct i915_context *i915 ) { - const uint inputsRead = i915->fs.inputs_read; + const uint inputsRead = i915->fs->inputs_read; const interp_mode colorInterp = i915->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR; struct vertex_info *vinfo = &i915->current.vertex_info; diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index dda758fe6a..c405051bce 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -117,6 +117,16 @@ struct pipe_context { void (*delete_depth_stencil_state)(struct pipe_context *, const struct pipe_depth_stencil_state *); + const struct pipe_shader_state * (*create_shader_state)( + struct pipe_context *, + const struct pipe_shader_state *); + void (*bind_fs_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*bind_vs_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*delete_shader_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*set_alpha_test_state)( struct pipe_context *, const struct pipe_alpha_test_state * ); @@ -139,12 +149,6 @@ struct pipe_context { void (*set_framebuffer_state)( struct pipe_context *, const struct pipe_framebuffer_state * ); - void (*set_fs_state)( struct pipe_context *, - const struct pipe_shader_state * ); - - void (*set_vs_state)( struct pipe_context *, - const struct pipe_shader_state * ); - void (*set_polygon_stipple)( struct pipe_context *, const struct pipe_poly_stipple * ); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index cf5fc2227e..25cb9d8745 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -251,17 +251,21 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, /* state setters */ softpipe->pipe.create_blend_state = softpipe_create_blend_state; - softpipe->pipe.bind_blend_state = softpipe_bind_blend_state; + softpipe->pipe.bind_blend_state = softpipe_bind_blend_state; softpipe->pipe.delete_blend_state = softpipe_delete_blend_state; softpipe->pipe.create_sampler_state = softpipe_create_sampler_state; - softpipe->pipe.bind_sampler_state = softpipe_bind_sampler_state; + softpipe->pipe.bind_sampler_state = softpipe_bind_sampler_state; softpipe->pipe.delete_sampler_state = softpipe_delete_sampler_state; softpipe->pipe.create_depth_stencil_state = softpipe_create_depth_stencil_state; - softpipe->pipe.bind_depth_stencil_state = softpipe_bind_depth_stencil_state; + softpipe->pipe.bind_depth_stencil_state = softpipe_bind_depth_stencil_state; softpipe->pipe.delete_depth_stencil_state = softpipe_delete_depth_stencil_state; softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state; - softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state; + softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state; softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state; + softpipe->pipe.create_shader_state = softpipe_create_shader_state; + softpipe->pipe.bind_fs_state = softpipe_bind_fs_state; + softpipe->pipe.bind_vs_state = softpipe_bind_vs_state; + softpipe->pipe.delete_shader_state = softpipe_delete_shader_state; softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state; softpipe->pipe.set_blend_color = softpipe_set_blend_color; @@ -270,8 +274,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer; softpipe->pipe.set_feedback_state = softpipe_set_feedback_state; softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; - softpipe->pipe.set_fs_state = softpipe_set_fs_state; - softpipe->pipe.set_vs_state = softpipe_set_vs_state; softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; softpipe->pipe.set_scissor_state = softpipe_set_scissor_state; softpipe->pipe.set_texture_state = softpipe_set_texture_state; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index f1bb3d39a6..5c17c47b12 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -74,6 +74,8 @@ struct softpipe_context { const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; const struct pipe_rasterizer_state *rasterizer; + const struct pipe_shader_state *fs; + const struct pipe_shader_state *vs; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; @@ -82,8 +84,6 @@ struct softpipe_context { struct pipe_constant_buffer constants[2]; struct pipe_feedback_state feedback; struct pipe_framebuffer_state framebuffer; - struct pipe_shader_state fs; - struct pipe_shader_state vs; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c index 46ad08aaa1..25bc170d8c 100755 --- a/src/mesa/pipe/softpipe/sp_quad_fs.c +++ b/src/mesa/pipe/softpipe/sp_quad_fs.c @@ -108,7 +108,7 @@ shade_quad( /* init machine state */ tgsi_exec_machine_init( &machine, - softpipe->fs.tokens, + softpipe->fs->tokens, PIPE_MAX_SAMPLERS, qss->samplers ); diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 62bd26c4df..04cc743bd0 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -88,11 +88,15 @@ void softpipe_set_constant_buffer(struct pipe_context *, void softpipe_set_feedback_state( struct pipe_context *, const struct pipe_feedback_state * ); -void softpipe_set_fs_state( struct pipe_context *, - const struct pipe_shader_state * ); - -void softpipe_set_vs_state( struct pipe_context *, - const struct pipe_shader_state * ); +const struct pipe_shader_state * +softpipe_create_shader_state( struct pipe_context *, + const struct pipe_shader_state * ); +void softpipe_bind_fs_state( struct pipe_context *, + const struct pipe_shader_state * ); +void softpipe_bind_vs_state( struct pipe_context *, + const struct pipe_shader_state * ); +void softpipe_delete_shader_state( struct pipe_context *, + const struct pipe_shader_state * ); void softpipe_set_polygon_stipple( struct pipe_context *, const struct pipe_poly_stipple * ); diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index 8c6bacf65c..9611a2ac99 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -43,7 +43,7 @@ */ static void calculate_vertex_layout( struct softpipe_context *softpipe ) { - const uint inputsRead = softpipe->fs.inputs_read; + const uint inputsRead = softpipe->fs->inputs_read; const interp_mode colorInterp = softpipe->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR; struct vertex_info *vinfo = &softpipe->vertex_info; diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c index 5ab246896b..fbbde2f520 100644 --- a/src/mesa/pipe/softpipe/sp_state_fs.c +++ b/src/mesa/pipe/softpipe/sp_state_fs.c @@ -33,23 +33,33 @@ #include "pipe/draw/draw_context.h" -void softpipe_set_fs_state( struct pipe_context *pipe, +const struct pipe_shader_state * +softpipe_create_shader_state( struct pipe_context *pipe, + const struct pipe_shader_state *templ ) +{ + struct pipe_shader_state *shader = malloc(sizeof(struct pipe_shader_state)); + memcpy(shader, templ, sizeof(struct pipe_shader_state)); + + return shader; +} + +void softpipe_bind_fs_state( struct pipe_context *pipe, const struct pipe_shader_state *fs ) { struct softpipe_context *softpipe = softpipe_context(pipe); - memcpy(&softpipe->fs, fs, sizeof(*fs)); + softpipe->fs = fs; softpipe->dirty |= SP_NEW_FS; } -void softpipe_set_vs_state( struct pipe_context *pipe, +void softpipe_bind_vs_state( struct pipe_context *pipe, const struct pipe_shader_state *vs ) { struct softpipe_context *softpipe = softpipe_context(pipe); - memcpy(&softpipe->vs, vs, sizeof(*vs)); + softpipe->vs = vs; softpipe->dirty |= SP_NEW_VS; @@ -57,6 +67,12 @@ void softpipe_set_vs_state( struct pipe_context *pipe, } +void softpipe_delete_shader_state( struct pipe_context *pipe, + const struct pipe_shader_state *shader ) +{ + free((struct pipe_shader_state*)shader); +} + void softpipe_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, const struct pipe_constant_buffer *buf) diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index d066547616..dc3e5258d8 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -38,6 +38,7 @@ #include "pipe/tgsi/exec/tgsi_dump.h" #include "st_context.h" +#include "st_cache.h" #include "st_atom.h" #include "st_program.h" @@ -46,16 +47,21 @@ static void compile_fs( struct st_context *st ) { struct st_fragment_program *fp = st->fp; + struct pipe_shader_state fs; + struct pipe_shader_state *cached; /* XXX: fix static allocation of tokens: */ tgsi_mesa_compile_fp_program( &fp->Base, fp->tokens, ST_FP_MAX_TOKENS ); - fp->fs.inputs_read + memset(&fs, 0, sizeof(fs)); + fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(fp->Base.Base.InputsRead); - fp->fs.outputs_written + fs.outputs_written = tgsi_mesa_translate_fragment_output_mask(fp->Base.Base.OutputsWritten); - fp->fs.tokens = &fp->tokens[0]; + fs.tokens = &fp->tokens[0]; + cached = st_cached_shader_state(st, &fs); + fp->fsx = cached; if (TGSI_DEBUG) tgsi_dump( fp->tokens, TGSI_DUMP_VERBOSE ); @@ -92,8 +98,8 @@ static void update_fs( struct st_context *st ) if (fp->dirty) compile_fs( st ); - st->state.fs = fp->fs; - st->pipe->set_fs_state(st->pipe, &st->state.fs); + st->state.fs = fp->fsx; + st->pipe->bind_fs_state(st->pipe, st->state.fs); } } diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index 289a3e4f46..18be71367a 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -41,6 +41,7 @@ #include "pipe/tgsi/exec/tgsi_core.h" #include "st_context.h" +#include "st_cache.h" #include "st_atom.h" #include "st_program.h" @@ -55,16 +56,21 @@ static void compile_vs( struct st_context *st ) { struct st_vertex_program *vp = st->vp; - + struct pipe_shader_state vs; + struct pipe_shader_state *cached; /* XXX: fix static allocation of tokens: */ tgsi_mesa_compile_vp_program( &vp->Base, vp->tokens, ST_FP_MAX_TOKENS ); - vp->vs.inputs_read + memset(&vs, 0, sizeof(vs)); + vs.inputs_read = tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead); - vp->vs.outputs_written + vs.outputs_written = tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten); - vp->vs.tokens = &vp->tokens[0]; + vs.tokens = &vp->tokens[0]; + + cached = st_cached_shader_state(st, &vs); + vp->vs = cached; if (TGSI_DEBUG) tgsi_dump( vp->tokens, 0 ); @@ -110,7 +116,7 @@ static void update_vs( struct st_context *st ) #endif st->state.vs = st->vp->vs; - st->pipe->set_vs_state(st->pipe, &st->state.vs); + st->pipe->bind_vs_state(st->pipe, st->state.vs); } } diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index e9c79634bd..7b851e3901 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -111,3 +111,21 @@ struct pipe_rasterizer_state * st_cached_rasterizer_state( } return (struct pipe_rasterizer_state*)(cso_hash_iter_data(iter)); } + +struct pipe_shader_state * st_cached_shader_state( + struct st_context *st, + const struct pipe_shader_state *templ) +{ + unsigned hash_key = cso_construct_key((void*)templ, + sizeof(struct pipe_shader_state)); + struct cso_hash_iter iter = cso_find_state_template(st->cache, + hash_key, CSO_SHADER, + (void*)templ); + if (cso_hash_iter_is_null(iter)) { + const struct pipe_shader_state *created_state = + st->pipe->create_shader_state(st->pipe, templ); + iter = cso_insert_state(st->cache, hash_key, CSO_SHADER, + (void*)created_state); + } + return (struct pipe_shader_state*)(cso_hash_iter_data(iter)); +} diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index a06af31123..6a897a9993 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -53,4 +53,8 @@ struct pipe_rasterizer_state *st_cached_rasterizer_state( struct st_context *st, const struct pipe_rasterizer_state *raster); +struct pipe_shader_state *st_cached_shader_state( + struct st_context *st, + const struct pipe_shader_state *templ); + #endif diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 584bc1cc2a..2ea498663b 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -347,6 +347,7 @@ clear_with_quad(GLcontext *ctx, { static struct st_fragment_program *stfp = NULL; struct pipe_shader_state fs; + const struct pipe_shader_state *cached; if (!stfp) { stfp = make_color_shader(st); } @@ -354,13 +355,15 @@ clear_with_quad(GLcontext *ctx, fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead); fs.outputs_written = tgsi_mesa_translate_fragment_output_mask(stfp->Base.Base.OutputsWritten); fs.tokens = &stfp->tokens[0]; - pipe->set_fs_state(pipe, &fs); + cached = st_cached_shader_state(st, &fs); + pipe->bind_fs_state(pipe, cached); } /* vertex shader state: color/position pass-through */ { static struct st_vertex_program *stvp = NULL; struct pipe_shader_state vs; + const struct pipe_shader_state *cached; if (!stvp) { stvp = make_vertex_shader(st); } @@ -368,7 +371,8 @@ clear_with_quad(GLcontext *ctx, vs.inputs_read = stvp->Base.Base.InputsRead; vs.outputs_written = stvp->Base.Base.OutputsWritten; vs.tokens = &stvp->tokens[0]; - pipe->set_vs_state(pipe, &vs); + cached = st_cached_shader_state(st, &vs); + pipe->bind_vs_state(pipe, cached); } /* viewport state: viewport matching window dims */ @@ -394,8 +398,8 @@ clear_with_quad(GLcontext *ctx, pipe->set_alpha_test_state(pipe, &st->state.alpha_test); pipe->bind_blend_state(pipe, st->state.blend); pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil); - pipe->set_fs_state(pipe, &st->state.fs); - pipe->set_vs_state(pipe, &st->state.vs); + pipe->bind_fs_state(pipe, st->state.fs); + pipe->bind_vs_state(pipe, st->state.vs); pipe->bind_rasterizer_state(pipe, st->state.rasterizer); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); /* OR: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 78ede8e225..37e40636f6 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -329,19 +329,22 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, { static struct st_fragment_program *stfp = NULL; struct pipe_shader_state fs; + struct pipe_shader_state *cached; if (!stfp) { stfp = make_fragment_shader(ctx->st); } memset(&fs, 0, sizeof(fs)); fs.inputs_read = stfp->Base.Base.InputsRead; fs.tokens = &stfp->tokens[0]; - pipe->set_fs_state(pipe, &fs); + cached = st_cached_shader_state(ctx->st, &fs); + pipe->bind_fs_state(pipe, cached); } /* vertex shader state: position + texcoord pass-through */ { static struct st_vertex_program *stvp = NULL; struct pipe_shader_state vs; + struct pipe_shader_state *cached; if (!stvp) { stvp = make_vertex_shader(ctx->st); } @@ -349,7 +352,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, vs.inputs_read = stvp->Base.Base.InputsRead; vs.outputs_written = stvp->Base.Base.OutputsWritten; vs.tokens = &stvp->tokens[0]; - pipe->set_vs_state(pipe, &vs); + cached = st_cached_shader_state(ctx->st, &vs); + pipe->bind_vs_state(pipe, cached); } /* texture sampling state: */ @@ -403,8 +407,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* restore GL state */ pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer); - pipe->set_fs_state(pipe, &ctx->st->state.fs); - pipe->set_vs_state(pipe, &ctx->st->state.vs); + pipe->bind_fs_state(pipe, ctx->st->state.fs); + pipe->bind_vs_state(pipe, ctx->st->state.vs); pipe->set_texture_state(pipe, unit, ctx->st->state.texture[unit]); pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 7bedf3f89f..98efe1a10b 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -53,7 +53,7 @@ static void setup_vertex_attribs(GLcontext *ctx) { struct pipe_context *pipe = ctx->st->pipe; - const uint inputAttrs = ctx->st->state.vs.inputs_read; + const uint inputAttrs = ctx->st->state.vs->inputs_read; uint attr; /* all attributes come from the default attribute buffer */ @@ -84,7 +84,7 @@ static void setup_feedback(GLcontext *ctx) { struct pipe_context *pipe = ctx->st->pipe; - const uint outputAttrs = ctx->st->state.vs.outputs_written; + const uint outputAttrs = ctx->st->state.vs->outputs_written; struct pipe_feedback_state feedback; uint i; @@ -307,7 +307,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4]) /* extract values and update rasterpos state */ { - const uint outputAttrs = ctx->st->state.vs.outputs_written; + const uint outputAttrs = ctx->st->state.vs->outputs_written; const float *pos, *color0, *color1, *tex0; float *buf = buf_map; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 516d319a6e..a8ae5d9c56 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -78,6 +78,8 @@ struct st_context const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; const struct pipe_rasterizer_state *rasterizer; + const struct pipe_shader_state *fs; + const struct pipe_shader_state *vs; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; @@ -89,8 +91,6 @@ struct st_context struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_shader_state fs; - struct pipe_shader_state vs; struct pipe_viewport_state viewport; } state; diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index f68e449f07..ac63a38720 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -193,7 +193,7 @@ st_draw_vbo(GLcontext *ctx, update_default_attribs_buffer(ctx); /* this must be after state validation */ - attrsNeeded = ctx->st->state.vs.inputs_read; + attrsNeeded = ctx->st->state.vs->inputs_read; /* tell pipe about the vertex array element/attributes */ for (attr = 0; attr < 16; attr++) { @@ -395,14 +395,14 @@ st_feedback_draw_vbo(GLcontext *ctx, draw_set_viewport_state(draw, &st->state.viewport); draw_set_clip_state(draw, &st->state.clip); draw_set_rasterizer_state(draw, st->state.rasterizer); - draw_set_vertex_shader(draw, &st->state.vs); + draw_set_vertex_shader(draw, st->state.vs); /* XXX need to set vertex info too */ update_default_attribs_buffer(ctx); /* this must be after state validation */ - attrsNeeded = ctx->st->state.vs.inputs_read; + attrsNeeded = ctx->st->state.vs->inputs_read; /* tell draw module about the vertex array element/attributes */ for (attr = 0; attr < 16; attr++) { diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 7a91983ce9..a2f114b1ba 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -53,8 +53,8 @@ struct st_fragment_program struct tgsi_token tokens[ST_FP_MAX_TOKENS]; GLboolean dirty; - - struct pipe_shader_state fs; + + const struct pipe_shader_state *fsx; GLuint param_state; }; @@ -75,7 +75,7 @@ struct st_vertex_program struct x86_function sse2_program; #endif - struct pipe_shader_state vs; + const struct pipe_shader_state *vs; GLuint param_state; }; -- cgit v1.2.3 From bb611c5f1f6aec7ac51d4fa3301422b47f6de795 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 18 Sep 2007 19:37:36 -0600 Subject: Checkpoint: rework shader input/output register mapping. This is a step toward removing TGSI_ATTRIB_ tokens. Basically, when translating Mesa programs to TGSI programs, pass in input and output register re-maps, plus interpolation info. There's some known breakage (cubemap.c) so more to be done... --- src/mesa/pipe/draw/draw_vertex_fetch.c | 39 +++++------ src/mesa/pipe/draw/draw_vertex_shader.c | 14 +++- src/mesa/pipe/p_state.h | 3 + src/mesa/pipe/softpipe/sp_prim_setup.c | 8 +++ src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c | 72 +++++++++++++++------ src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h | 5 ++ src/mesa/state_tracker/st_atom_fs.c | 23 ++++++- src/mesa/state_tracker/st_atom_vs.c | 46 +++++++++++-- src/mesa/state_tracker/st_cb_clear.c | 21 +++++- src/mesa/state_tracker/st_cb_drawpixels.c | 15 ++++- src/mesa/state_tracker/st_draw.c | 103 ++++++++++++++++-------------- src/mesa/state_tracker/st_program.h | 17 +++-- 12 files changed, 260 insertions(+), 106 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/draw/draw_vertex_fetch.c b/src/mesa/pipe/draw/draw_vertex_fetch.c index 0dbbdf17f2..ce402d681f 100644 --- a/src/mesa/pipe/draw/draw_vertex_fetch.c +++ b/src/mesa/pipe/draw/draw_vertex_fetch.c @@ -67,6 +67,10 @@ fetch_attrib4(const void *ptr, unsigned format, float attrib[4]) } } + +/** + * Fetch vertex attributes for 'count' vertices. + */ void draw_vertex_fetch( struct draw_context *draw, struct tgsi_exec_machine *machine, const unsigned *elts, @@ -74,27 +78,26 @@ void draw_vertex_fetch( struct draw_context *draw, { unsigned j; - - /* load machine inputs */ + /* loop over vertices */ for (j = 0; j < count; j++) { - unsigned attr; - for (attr = 0; attr < 16; attr++) { - if (draw->vertex_shader.inputs_read & (1 << attr)) { - unsigned buf = draw->vertex_element[attr].vertex_buffer_index; - const void *src - = (const void *) ((const ubyte *) draw->mapped_vbuffer[buf] - + draw->vertex_buffer[buf].buffer_offset - + draw->vertex_element[attr].src_offset - + elts[j] * draw->vertex_buffer[buf].pitch); - float p[4]; + uint attr; + /* loop over vertex attributes (vertex shader inputs) */ + for (attr = 0; attr < draw->vertex_shader.num_inputs; attr++) { + + unsigned buf = draw->vertex_element[attr].vertex_buffer_index; + const void *src + = (const void *) ((const ubyte *) draw->mapped_vbuffer[buf] + + draw->vertex_buffer[buf].buffer_offset + + draw->vertex_element[attr].src_offset + + elts[j] * draw->vertex_buffer[buf].pitch); + float p[4]; - fetch_attrib4(src, draw->vertex_element[attr].src_format, p); + fetch_attrib4(src, draw->vertex_element[attr].src_format, p); - machine->Inputs[attr].xyzw[0].f[j] = p[0]; /*X*/ - machine->Inputs[attr].xyzw[1].f[j] = p[1]; /*Y*/ - machine->Inputs[attr].xyzw[2].f[j] = p[2]; /*Z*/ - machine->Inputs[attr].xyzw[3].f[j] = p[3]; /*W*/ - } + machine->Inputs[attr].xyzw[0].f[j] = p[0]; /*X*/ + machine->Inputs[attr].xyzw[1].f[j] = p[1]; /*Y*/ + machine->Inputs[attr].xyzw[2].f[j] = p[2]; /*Z*/ + machine->Inputs[attr].xyzw[3].f[j] = p[3]; /*W*/ } } } diff --git a/src/mesa/pipe/draw/draw_vertex_shader.c b/src/mesa/pipe/draw/draw_vertex_shader.c index 8effc74cbe..cb6c605b8d 100644 --- a/src/mesa/pipe/draw/draw_vertex_shader.c +++ b/src/mesa/pipe/draw/draw_vertex_shader.c @@ -114,7 +114,6 @@ run_vertex_program(struct draw_context *draw, draw_vertex_fetch( draw, &machine, elts, count ); - /* run shader */ if( draw->vertex_shader.executable != NULL ) { #if defined(USE_X86_ASM) || defined(SLANG_X86) @@ -159,14 +158,23 @@ run_vertex_program(struct draw_context *draw, vOut[j]->data[0][2] = z * scale[2] + trans[2]; vOut[j]->data[0][3] = w; - /* remaining attributes are packed into sequential post-transform + /* Remaining attributes are packed into sequential post-transform * vertex attrib slots. + * Skip 0 since we just did it above. + * Subtract two because of the VERTEX_HEADER, CLIP_POS attribs. */ - for (slot = 1; slot < draw->vertex_info.num_attribs; slot++) { + for (slot = 1; slot < draw->vertex_info.num_attribs - 2; slot++) { vOut[j]->data[slot][0] = machine.Outputs[slot].xyzw[0].f[j]; vOut[j]->data[slot][1] = machine.Outputs[slot].xyzw[1].f[j]; vOut[j]->data[slot][2] = machine.Outputs[slot].xyzw[2].f[j]; vOut[j]->data[slot][3] = machine.Outputs[slot].xyzw[3].f[j]; + /* + printf("output %d: %f %f %f %f\n", slot, + vOut[j]->data[slot][0], + vOut[j]->data[slot][1], + vOut[j]->data[slot][2], + vOut[j]->data[slot][3]); + */ } } /* loop over vertices */ } diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 048feede3b..d2cc76a59b 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -144,6 +144,9 @@ struct pipe_shader_state { unsigned outputs_written; /**< TGSI_ATTRIB_ bits */ const struct tgsi_token *tokens; void *executable; + + uint num_inputs; + uint num_outputs; }; struct pipe_depth_stencil_state diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index d0baf0734b..8a4be79d11 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -448,6 +448,14 @@ static void tri_persp_coeff( struct setup_stage *setup, float a = setup->ebot.dy * majda - botda * setup->emaj.dy; float b = setup->emaj.dx * botda - majda * setup->ebot.dx; + /* + printf("tri persp %d,%d: %f %f %f\n", slot, i, + setup->vmin->data[slot][i], + setup->vmid->data[slot][i], + setup->vmax->data[slot][i] + ); + */ + assert(slot < TGSI_ATTRIB_MAX); assert(i <= 3); diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c index 2820706537..1f8d937bc6 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c @@ -211,6 +211,7 @@ tgsi_mesa_translate_fragment_output(GLuint attrib) } +#if 01 uint tgsi_mesa_translate_vertex_input_mask(GLbitfield mask) { @@ -224,7 +225,7 @@ tgsi_mesa_translate_vertex_input_mask(GLbitfield mask) } return tgsiMask; } - +#endif uint tgsi_mesa_translate_vertex_output_mask(GLbitfield mask) @@ -318,7 +319,9 @@ map_register_file_index( GLuint processor, GLuint file, GLuint index, - GLbitfield usage_bitmask ) + GLbitfield usage_bitmask, + const GLuint inputMapping[], + const GLuint outputMapping[]) { GLuint mapped_index; GLuint i; @@ -337,6 +340,12 @@ map_register_file_index( * etc. */ assert( index < 32 ); + if (inputMapping) { + printf("New map %d input %d to %d\n", processor, index, + inputMapping[index]); + return inputMapping[index]; + } + assert( usage_bitmask & (1 << index) ); mapped_index = 0; for( i = 0; i < index; i++ ) { @@ -344,7 +353,7 @@ map_register_file_index( mapped_index++; } } - printf("Map input %d to %d\n", index, mapped_index); + printf("Map %d input %d to %d\n", processor, index, mapped_index); break; case TGSI_FILE_OUTPUT: @@ -372,6 +381,8 @@ map_register_file_index( mapped_index++; } } + printf("Map VP output from %d to %d\n", index, mapped_index); + assert(outputMapping[index] == mapped_index); } break; @@ -443,6 +454,8 @@ compile_instruction( struct tgsi_full_instruction *fullinst, GLuint inputs_read, GLuint outputs_written, + const GLuint inputMapping[], + const GLuint outputMapping[], GLuint preamble_size, GLuint processor ) { @@ -462,7 +475,9 @@ compile_instruction( processor, fulldst->DstRegister.File, inst->DstReg.Index, - outputs_written + outputs_written, + NULL, + outputMapping ); fulldst->DstRegister.WriteMask = convert_writemask( inst->DstReg.WriteMask ); @@ -475,7 +490,9 @@ compile_instruction( processor, fullsrc->SrcRegister.File, inst->SrcReg[i].Index, - inputs_read ); + inputs_read, + inputMapping, + outputMapping ); for( j = 0; j < 4; j++ ) { GLuint swz; @@ -789,9 +806,20 @@ make_frag_output_decl( return decl; } + +/** + * Convert Mesa fragment program to TGSI format. + * \param inputMapping array to map original Mesa fragment program inputs + * registers to TGSI generic input indexes + * \param interpMode array[FRAG_ATTRIB_x] of TGSI_INTERPOLATE_LINEAR/PERSP. + * + */ GLboolean tgsi_mesa_compile_fp_program( const struct gl_fragment_program *program, + const GLuint inputMapping[], + const GLuint interpMode[], + const GLuint outputMapping[], struct tgsi_token *tokens, GLuint maxTokens ) { @@ -800,8 +828,10 @@ tgsi_mesa_compile_fp_program( struct tgsi_processor *processor; struct tgsi_full_declaration fulldecl; struct tgsi_full_instruction fullinst; + /* struct tgsi_full_dst_register *fulldst; struct tgsi_full_src_register *fullsrc; + */ GLuint inputs_read; GLboolean reads_wpos; GLuint preamble_size = 0; @@ -822,7 +852,7 @@ tgsi_mesa_compile_fp_program( /* * Declare input attributes. Note that we do not interpolate fragment position. */ - + reads_wpos = 1; /* Fragment position. */ if( reads_wpos ) { fulldecl = make_frag_input_decl( @@ -853,20 +883,16 @@ tgsi_mesa_compile_fp_program( for( i = 1; i < 32; i++ ) { if( inputs_read & (1 << i) ) { count++; + fulldecl = make_frag_input_decl(count, + count, + interpMode[i], + TGSI_WRITEMASK_XYZW ); + ti += tgsi_build_full_declaration(&fulldecl, + &tokens[ti], + header, + maxTokens - ti ); } - } - if( count > 0 ) { - fulldecl = make_frag_input_decl( - 1, - 1 + count - 1, - TGSI_INTERPOLATE_PERSPECTIVE, - TGSI_WRITEMASK_XYZW ); - ti += tgsi_build_full_declaration( - &fulldecl, - &tokens[ti], - header, - maxTokens - ti ); - } + } /* * Declare output attributes. @@ -932,6 +958,8 @@ tgsi_mesa_compile_fp_program( &fullinst, inputs_read, ~0, /*outputs_written*/ + inputMapping, + outputMapping, preamble_size, TGSI_PROCESSOR_FRAGMENT ) ) { assert( i == program->Base.NumInstructions - 1 ); @@ -955,8 +983,10 @@ tgsi_mesa_compile_fp_program( GLboolean tgsi_mesa_compile_vp_program( const struct gl_vertex_program *program, + const GLuint inputMapping[], + const GLuint outputMapping[], struct tgsi_token *tokens, - GLuint maxTokens ) + GLuint maxTokens) { GLuint i, ti; struct tgsi_header *header; @@ -983,6 +1013,8 @@ tgsi_mesa_compile_vp_program( &fullinst, inputs_read, outputs_written, + inputMapping, + outputMapping, 0, TGSI_PROCESSOR_VERTEX ) ) { assert( i == program->Base.NumInstructions - 1 ); diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h index fda3fa397f..017cfce72e 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h @@ -10,12 +10,17 @@ struct tgsi_token; GLboolean tgsi_mesa_compile_fp_program( const struct gl_fragment_program *program, + const GLuint inputMapping[], + const GLuint interpMode[], + const GLuint outputMapping[], struct tgsi_token *tokens, GLuint maxTokens ); GLboolean tgsi_mesa_compile_vp_program( const struct gl_vertex_program *program, + const GLuint inputMapping[], + const GLuint outputMapping[], struct tgsi_token *tokens, GLuint maxTokens ); diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index dc3e5258d8..3df2c6750a 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -42,17 +42,34 @@ #include "st_atom.h" #include "st_program.h" -#define TGSI_DEBUG 0 +#define TGSI_DEBUG 1 static void compile_fs( struct st_context *st ) { + /* Map FRAG_RESULT_COLR to output 1, map FRAG_RESULT_DEPR to output 0 */ + static const GLuint outputMapping[2] = {1, 0}; struct st_fragment_program *fp = st->fp; struct pipe_shader_state fs; struct pipe_shader_state *cached; + GLuint interpMode[16]; /* XXX size? */ + GLuint i; + + for (i = 0; i < 16; i++) { + if (fp->Base.Base.InputsRead & (1 << i)) { + if (i == FRAG_ATTRIB_COL0 || i == FRAG_ATTRIB_COL1) { + interpMode[i] = TGSI_INTERPOLATE_LINEAR; + } + else { + interpMode[i] = TGSI_INTERPOLATE_PERSPECTIVE; + } + } + } /* XXX: fix static allocation of tokens: */ - tgsi_mesa_compile_fp_program( &fp->Base, fp->tokens, ST_FP_MAX_TOKENS ); + tgsi_mesa_compile_fp_program( &fp->Base, NULL, interpMode, + outputMapping, + fp->tokens, ST_FP_MAX_TOKENS ); memset(&fs, 0, sizeof(fs)); fs.inputs_read @@ -64,7 +81,7 @@ static void compile_fs( struct st_context *st ) fp->fsx = cached; if (TGSI_DEBUG) - tgsi_dump( fp->tokens, TGSI_DUMP_VERBOSE ); + tgsi_dump( fp->tokens, 0/*TGSI_DUMP_VERBOSE*/ ); fp->dirty = 0; } diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index 8f1df80a7f..8de19e41ee 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -51,25 +51,61 @@ -/* translate shader to TGSI format -*/ +/** + * Translate Mesa shader to TGSI format + */ static void compile_vs( struct st_context *st ) { struct st_vertex_program *vp = st->vp; struct pipe_shader_state vs; struct pipe_shader_state *cached; + GLuint i; + + memset(&vs, 0, sizeof(vs)); + + /* + * Determine how many inputs there are. + * Also, compute two look-up tables that map between Mesa VERT_ATTRIB_x + * values and TGSI generic input indexes. + */ + for (i = 0; i < MAX_VERTEX_PROGRAM_ATTRIBS; i++) { + if (vp->Base.Base.InputsRead & (1 << i)) { + vp->input_to_index[i] = vs.num_inputs; + vp->index_to_input[vs.num_inputs] = i; + vs.num_inputs++; + } + } + + /* + * Determine output register mapping. + */ + for (i = 0; i < VERT_RESULT_MAX; i++) { + if (vp->Base.Base.OutputsWritten & (1 << i)) { + vp->output_to_index[i] = vs.num_outputs; + vp->index_to_output[vs.num_outputs] = i; + vs.num_outputs++; + } + } + + /* XXX: fix static allocation of tokens: */ - tgsi_mesa_compile_vp_program( &vp->Base, vp->tokens, ST_FP_MAX_TOKENS ); + tgsi_mesa_compile_vp_program( &vp->Base, + vp->input_to_index, + vp->output_to_index, + vp->tokens, ST_FP_MAX_TOKENS ); - memset(&vs, 0, sizeof(vs)); +#if 01 vs.inputs_read = tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead); +#endif vs.outputs_written = tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten); + vs.tokens = &vp->tokens[0]; cached = st_cached_shader_state(st, &vs); + vp->vs = cached; if (TGSI_DEBUG) @@ -121,7 +157,7 @@ static void update_vs( struct st_context *st ) const struct st_tracked_state st_update_vs = { .name = "st_update_vs", .dirty = { - .mesa = 0, + .mesa = _NEW_PROGRAM, .st = ST_NEW_VERTEX_PROGRAM, }, .update = update_vs diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 2ea498663b..65cac9dbde 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -119,12 +119,19 @@ is_depth_stencil_format(GLuint pipeFormat) * Create a simple fragment shader that just passes through the fragment color. */ static struct st_fragment_program * -make_color_shader(struct st_context *st) +make_frag_shader(struct st_context *st) { + static const GLuint outputMapping[] = { 1, 0 }; GLcontext *ctx = st->ctx; struct st_fragment_program *stfp; struct gl_program *p; GLboolean b; + GLuint interpMode[16]; + GLuint i; + + /* XXX temporary */ + for (i = 0; i < 16; i++) + interpMode[i] = TGSI_INTERPOLATE_LINEAR; p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); if (!p) @@ -151,7 +158,8 @@ make_color_shader(struct st_context *st) stfp = (struct st_fragment_program *) p; /* compile into tgsi format */ - b = tgsi_mesa_compile_fp_program(&stfp->Base, + b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode, + outputMapping, stfp->tokens, ST_FP_MAX_TOKENS); assert(b); @@ -166,6 +174,11 @@ make_color_shader(struct st_context *st) static struct st_vertex_program * make_vertex_shader(struct st_context *st) { + /* Map VERT_ATTRIB_POS to 0, VERT_ATTRIB_COLOR0 to 1 */ + static const GLuint inputMapping[4] = { 0, 0, 0, 1 }; + /* Map VERT_RESULT_HPOS to 0, VERT_RESULT_COL0 to 1 */ + static const GLuint outputMapping[2] = { 0, 1 }; + GLcontext *ctx = st->ctx; struct st_vertex_program *stvp; struct gl_program *p; @@ -204,6 +217,8 @@ make_vertex_shader(struct st_context *st) stvp = (struct st_vertex_program *) p; /* compile into tgsi format */ b = tgsi_mesa_compile_vp_program(&stvp->Base, + inputMapping, + outputMapping, stvp->tokens, ST_FP_MAX_TOKENS); assert(b); @@ -349,7 +364,7 @@ clear_with_quad(GLcontext *ctx, struct pipe_shader_state fs; const struct pipe_shader_state *cached; if (!stfp) { - stfp = make_color_shader(st); + stfp = make_frag_shader(st); } memset(&fs, 0, sizeof(fs)); fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 37e40636f6..731c060c11 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -56,10 +56,17 @@ static struct st_fragment_program * make_fragment_shader(struct st_context *st) { + static const GLuint outputMapping[2] = { 1, 0 }; GLcontext *ctx = st->ctx; struct st_fragment_program *stfp; struct gl_program *p; GLboolean b; + GLuint interpMode[16]; + GLuint i; + + /* XXX temporary */ + for (i = 0; i < 16; i++) + interpMode[i] = TGSI_INTERPOLATE_LINEAR; p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); if (!p) @@ -88,7 +95,8 @@ make_fragment_shader(struct st_context *st) stfp = (struct st_fragment_program *) p; /* compile into tgsi format */ - b = tgsi_mesa_compile_fp_program(&stfp->Base, + b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode, + outputMapping, stfp->tokens, ST_FP_MAX_TOKENS); assert(b); @@ -103,6 +111,8 @@ make_fragment_shader(struct st_context *st) static struct st_vertex_program * make_vertex_shader(struct st_context *st) { + /* Map VERT_RESULT_HPOS to 0, VERT_RESULT_TEX0 to 1 */ + static const GLuint outputMapping[] = { 0, 0, 0, 0, 1 }; GLcontext *ctx = st->ctx; struct st_vertex_program *stvp; struct gl_program *p; @@ -140,7 +150,8 @@ make_vertex_shader(struct st_context *st) stvp = (struct st_vertex_program *) p; /* compile into tgsi format */ - b = tgsi_mesa_compile_vp_program(&stvp->Base, + b = tgsi_mesa_compile_vp_program(&stvp->Base, NULL, + outputMapping, stvp->tokens, ST_FP_MAX_TOKENS); assert(b); diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index ac63a38720..bff0ad7ef7 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -37,10 +37,12 @@ #include "tnl/t_vp_build.h" -#include "st_context.h" #include "st_atom.h" -#include "st_draw.h" +#include "st_context.h" #include "st_cb_bufferobjects.h" +#include "st_draw.h" +#include "st_program.h" + #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_winsys.h" @@ -185,18 +187,22 @@ st_draw_vbo(GLcontext *ctx, GLuint max_index) { struct pipe_context *pipe = ctx->st->pipe; - GLuint attr, i; - GLbitfield attrsNeeded; + const struct st_vertex_program *vp = ctx->st->vp; + const struct pipe_shader_state *vs; const unsigned attr0_offset = (unsigned) arrays[0]->Ptr; + GLboolean needDefaultAttribs = GL_FALSE; + GLuint attr; st_validate_state(ctx->st); - update_default_attribs_buffer(ctx); - /* this must be after state validation */ - attrsNeeded = ctx->st->state.vs->inputs_read; + /* must do this after state validation! */ + vs = ctx->st->state.vs; + + /* loop over TGSI shader inputs */ + for (attr = 0; attr < vs->num_inputs; attr++) { + const GLuint mesaAttr = vp->index_to_input[attr]; + struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj; - /* tell pipe about the vertex array element/attributes */ - for (attr = 0; attr < 16; attr++) { struct pipe_vertex_buffer vbuffer; struct pipe_vertex_element velement; @@ -206,43 +212,40 @@ st_draw_vbo(GLcontext *ctx, velement.vertex_buffer_index = 0; velement.src_format = 0; - if (attrsNeeded & (1 << attr)) { - const GLuint mesaAttr = tgsi_attrib_to_mesa_attrib(attr); - struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj; - - if (bufobj && bufobj->Name) { - struct st_buffer_object *stobj = st_buffer_object(bufobj); - /* Recall that for VBOs, the gl_client_array->Ptr field is - * really an offset from the start of the VBO, not a pointer. - */ - unsigned offset = (unsigned) arrays[mesaAttr]->Ptr; - - assert(stobj->buffer); - - vbuffer.buffer = stobj->buffer; - vbuffer.buffer_offset = attr0_offset; /* in bytes */ - vbuffer.pitch = arrays[mesaAttr]->StrideB; /* in bytes */ - vbuffer.max_index = 0; /* need this? */ - - velement.src_offset = offset - attr0_offset; /* bytes */ - velement.vertex_buffer_index = attr; - velement.dst_offset = 0; /* need this? */ - velement.src_format = pipe_vertex_format(arrays[mesaAttr]->Type, - arrays[mesaAttr]->Size); - assert(velement.src_format); - } - else { - /* use the default attribute buffer */ - vbuffer.buffer = ctx->st->default_attrib_buffer; - vbuffer.buffer_offset = 0; - vbuffer.pitch = 0; /* must be zero! */ - vbuffer.max_index = 1; - - velement.src_offset = attr * 4 * sizeof(GLfloat); - velement.vertex_buffer_index = attr; - velement.dst_offset = 0; - velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - } + if (bufobj && bufobj->Name) { + struct st_buffer_object *stobj = st_buffer_object(bufobj); + /* Recall that for VBOs, the gl_client_array->Ptr field is + * really an offset from the start of the VBO, not a pointer. + */ + unsigned offset = (unsigned) arrays[mesaAttr]->Ptr; + + assert(stobj->buffer); + + vbuffer.buffer = stobj->buffer; + vbuffer.buffer_offset = attr0_offset; /* in bytes */ + vbuffer.pitch = arrays[mesaAttr]->StrideB; /* in bytes */ + vbuffer.max_index = 0; /* need this? */ + + velement.src_offset = offset - attr0_offset; /* bytes */ + velement.vertex_buffer_index = attr; + velement.dst_offset = 0; /* need this? */ + velement.src_format = pipe_vertex_format(arrays[mesaAttr]->Type, + arrays[mesaAttr]->Size); + assert(velement.src_format); + } + else { + /* use the default attribute buffer */ + needDefaultAttribs = GL_TRUE; + + vbuffer.buffer = ctx->st->default_attrib_buffer; + vbuffer.buffer_offset = 0; + vbuffer.pitch = 0; /* must be zero! */ + vbuffer.max_index = 1; + + velement.src_offset = mesaAttr * 4 * sizeof(GLfloat); + velement.vertex_buffer_index = attr; + velement.dst_offset = 0; + velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; } if (attr == 0) @@ -252,12 +255,17 @@ st_draw_vbo(GLcontext *ctx, pipe->set_vertex_element(pipe, attr, &velement); } + if (needDefaultAttribs) { + update_default_attribs_buffer(ctx); + } + + /* do actual drawing */ if (ib) { /* indexed primitive */ struct gl_buffer_object *bufobj = ib->obj; struct pipe_buffer_handle *bh = NULL; - unsigned indexSize; + unsigned indexSize, i; if (bufobj && bufobj->Name) { /* elements/indexes are in a real VBO */ @@ -285,6 +293,7 @@ st_draw_vbo(GLcontext *ctx, } else { /* non-indexed */ + GLuint i; for (i = 0; i < nr_prims; i++) { pipe->draw_arrays(pipe, prims[i].mode, prims[i].start, prims[i].count); } diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index a2f114b1ba..68ceba4d78 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -61,13 +61,20 @@ struct st_fragment_program struct st_vertex_program { - struct gl_vertex_program Base; - GLboolean error; /* If program is malformed for any reason. */ + struct gl_vertex_program Base; /**< The Mesa vertex program */ + GLboolean error; /**< Set if program is malformed for any reason. */ - GLuint id; /* String id, for tracking - * ProgramStringNotify changes. - */ + GLuint id; /**< String id, for tracking ProgramStringNotify changes. */ + + /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */ + GLuint input_to_index[MAX_VERTEX_PROGRAM_ATTRIBS]; + /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */ + GLuint index_to_input[MAX_VERTEX_PROGRAM_ATTRIBS]; + + GLuint output_to_index[MAX_VERTEX_PROGRAM_ATTRIBS]; + GLuint index_to_output[MAX_VERTEX_PROGRAM_ATTRIBS]; + /** The program in TGSI format */ struct tgsi_token tokens[ST_FP_MAX_TOKENS]; GLboolean dirty; -- cgit v1.2.3 From f22e920f478d8732695913ec0d1f7244b451a8f5 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Wed, 19 Sep 2007 06:46:32 -0400 Subject: Finish up conversions of shaders to immutable objects. Create/Delete calls should be split since in create we'll be compiling them so we want to know which one it is (vertex/fragment). --- src/mesa/pipe/cso_cache/cso_cache.c | 16 +++++++++++----- src/mesa/pipe/cso_cache/cso_cache.h | 6 ++++-- src/mesa/pipe/i915simple/i915_state.c | 6 ++++-- src/mesa/pipe/p_context.h | 11 ++++++++--- src/mesa/pipe/softpipe/sp_context.c | 10 ++++++---- src/mesa/state_tracker/st_atom_fs.c | 2 +- src/mesa/state_tracker/st_atom_vs.c | 2 +- src/mesa/state_tracker/st_cache.c | 26 ++++++++++++++++++++++---- src/mesa/state_tracker/st_cache.h | 7 ++++++- src/mesa/state_tracker/st_cb_clear.c | 4 ++-- src/mesa/state_tracker/st_cb_drawpixels.c | 4 ++-- 11 files changed, 67 insertions(+), 27 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/cso_cache/cso_cache.c b/src/mesa/pipe/cso_cache/cso_cache.c index be653d9494..e87733c7ab 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.c +++ b/src/mesa/pipe/cso_cache/cso_cache.c @@ -80,8 +80,10 @@ static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_ hash = sc->depth_stencil_hash; case CSO_RASTERIZER: hash = sc->rasterizer_hash; - case CSO_SHADER: - hash = sc->shader_hash; + case CSO_FRAGMENT_SHADER: + hash = sc->fs_hash; + case CSO_VERTEX_SHADER: + hash = sc->vs_hash; } return hash; @@ -98,7 +100,9 @@ static int _cso_size_for_type(enum cso_cache_type type) return sizeof(struct pipe_depth_stencil_state); case CSO_RASTERIZER: return sizeof(struct pipe_rasterizer_state); - case CSO_SHADER: + case CSO_FRAGMENT_SHADER: + return sizeof(struct pipe_shader_state); + case CSO_VERTEX_SHADER: return sizeof(struct pipe_shader_state); } return 0; @@ -152,7 +156,8 @@ struct cso_cache *cso_cache_create(void) sc->sampler_hash = cso_hash_create(); sc->depth_stencil_hash = cso_hash_create(); sc->rasterizer_hash = cso_hash_create(); - sc->shader_hash = cso_hash_create(); + sc->fs_hash = cso_hash_create(); + sc->vs_hash = cso_hash_create(); return sc; } @@ -164,6 +169,7 @@ void cso_cache_delete(struct cso_cache *sc) cso_hash_delete(sc->sampler_hash); cso_hash_delete(sc->depth_stencil_hash); cso_hash_delete(sc->rasterizer_hash); - cso_hash_delete(sc->shader_hash); + cso_hash_delete(sc->fs_hash); + cso_hash_delete(sc->vs_hash); free(sc); } diff --git a/src/mesa/pipe/cso_cache/cso_cache.h b/src/mesa/pipe/cso_cache/cso_cache.h index d9793ca855..352e1a6a59 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.h +++ b/src/mesa/pipe/cso_cache/cso_cache.h @@ -44,7 +44,8 @@ struct cso_cache { struct cso_hash *sampler_hash; struct cso_hash *depth_stencil_hash; struct cso_hash *rasterizer_hash; - struct cso_hash *shader_hash; + struct cso_hash *fs_hash; + struct cso_hash *vs_hash; }; enum cso_cache_type { @@ -52,7 +53,8 @@ enum cso_cache_type { CSO_SAMPLER, CSO_DEPTH_STENCIL, CSO_RASTERIZER, - CSO_SHADER + CSO_FRAGMENT_SHADER, + CSO_VERTEX_SHADER }; unsigned cso_construct_key(void *item, int item_size); diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index fe835643e0..aaf2ccf499 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -373,10 +373,12 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.create_rasterizer_state = i915_create_rasterizer_state; i915->pipe.bind_rasterizer_state = i915_bind_rasterizer_state; i915->pipe.delete_rasterizer_state = i915_delete_rasterizer_state; - i915->pipe.create_shader_state = i915_create_shader_state; + i915->pipe.create_fs_state = i915_create_shader_state; i915->pipe.bind_fs_state = i915_bind_fs_state; + i915->pipe.delete_fs_state = i915_delete_shader_state; + i915->pipe.create_vs_state = i915_create_shader_state; i915->pipe.bind_vs_state = i915_bind_vs_state; - i915->pipe.delete_shader_state = i915_delete_shader_state; + i915->pipe.delete_vs_state = i915_delete_shader_state; i915->pipe.set_alpha_test_state = i915_set_alpha_test_state; i915->pipe.set_blend_color = i915_set_blend_color; diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index c405051bce..5766b2b7df 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -117,15 +117,20 @@ struct pipe_context { void (*delete_depth_stencil_state)(struct pipe_context *, const struct pipe_depth_stencil_state *); - const struct pipe_shader_state * (*create_shader_state)( + const struct pipe_shader_state * (*create_fs_state)( struct pipe_context *, const struct pipe_shader_state *); void (*bind_fs_state)(struct pipe_context *, const struct pipe_shader_state *); + void (*delete_fs_state)(struct pipe_context *, + const struct pipe_shader_state *); + const struct pipe_shader_state * (*create_vs_state)( + struct pipe_context *, + const struct pipe_shader_state *); void (*bind_vs_state)(struct pipe_context *, const struct pipe_shader_state *); - void (*delete_shader_state)(struct pipe_context *, - const struct pipe_shader_state *); + void (*delete_vs_state)(struct pipe_context *, + const struct pipe_shader_state *); void (*set_alpha_test_state)( struct pipe_context *, const struct pipe_alpha_test_state * ); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 25cb9d8745..a56793d683 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -262,10 +262,12 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state; softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state; softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state; - softpipe->pipe.create_shader_state = softpipe_create_shader_state; - softpipe->pipe.bind_fs_state = softpipe_bind_fs_state; - softpipe->pipe.bind_vs_state = softpipe_bind_vs_state; - softpipe->pipe.delete_shader_state = softpipe_delete_shader_state; + softpipe->pipe.create_fs_state = softpipe_create_shader_state; + softpipe->pipe.bind_fs_state = softpipe_bind_fs_state; + softpipe->pipe.delete_fs_state = softpipe_delete_shader_state; + softpipe->pipe.create_vs_state = softpipe_create_shader_state; + softpipe->pipe.bind_vs_state = softpipe_bind_vs_state; + softpipe->pipe.delete_vs_state = softpipe_delete_shader_state; softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state; softpipe->pipe.set_blend_color = softpipe_set_blend_color; diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index 3df2c6750a..6dd576a57c 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -77,7 +77,7 @@ static void compile_fs( struct st_context *st ) fs.outputs_written = tgsi_mesa_translate_fragment_output_mask(fp->Base.Base.OutputsWritten); fs.tokens = &fp->tokens[0]; - cached = st_cached_shader_state(st, &fs); + cached = st_cached_fs_state(st, &fs); fp->fsx = cached; if (TGSI_DEBUG) diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index 8de19e41ee..166dc70b08 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -104,7 +104,7 @@ static void compile_vs( struct st_context *st ) vs.tokens = &vp->tokens[0]; - cached = st_cached_shader_state(st, &vs); + cached = st_cached_vs_state(st, &vs); vp->vs = cached; diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index 7b851e3901..d84a396e18 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -112,19 +112,37 @@ struct pipe_rasterizer_state * st_cached_rasterizer_state( return (struct pipe_rasterizer_state*)(cso_hash_iter_data(iter)); } -struct pipe_shader_state * st_cached_shader_state( +struct pipe_shader_state * st_cached_fs_state( struct st_context *st, const struct pipe_shader_state *templ) { unsigned hash_key = cso_construct_key((void*)templ, sizeof(struct pipe_shader_state)); struct cso_hash_iter iter = cso_find_state_template(st->cache, - hash_key, CSO_SHADER, + hash_key, CSO_FRAGMENT_SHADER, (void*)templ); if (cso_hash_iter_is_null(iter)) { const struct pipe_shader_state *created_state = - st->pipe->create_shader_state(st->pipe, templ); - iter = cso_insert_state(st->cache, hash_key, CSO_SHADER, + st->pipe->create_fs_state(st->pipe, templ); + iter = cso_insert_state(st->cache, hash_key, CSO_FRAGMENT_SHADER, + (void*)created_state); + } + return (struct pipe_shader_state*)(cso_hash_iter_data(iter)); +} + +struct pipe_shader_state * st_cached_vs_state( + struct st_context *st, + const struct pipe_shader_state *templ) +{ + unsigned hash_key = cso_construct_key((void*)templ, + sizeof(struct pipe_shader_state)); + struct cso_hash_iter iter = cso_find_state_template(st->cache, + hash_key, CSO_VERTEX_SHADER, + (void*)templ); + if (cso_hash_iter_is_null(iter)) { + const struct pipe_shader_state *created_state = + st->pipe->create_vs_state(st->pipe, templ); + iter = cso_insert_state(st->cache, hash_key, CSO_VERTEX_SHADER, (void*)created_state); } return (struct pipe_shader_state*)(cso_hash_iter_data(iter)); diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index 6a897a9993..bcbe19b823 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -53,7 +53,12 @@ struct pipe_rasterizer_state *st_cached_rasterizer_state( struct st_context *st, const struct pipe_rasterizer_state *raster); -struct pipe_shader_state *st_cached_shader_state( +struct pipe_shader_state *st_cached_fs_state( + struct st_context *st, + const struct pipe_shader_state *templ); + + +struct pipe_shader_state *st_cached_vs_state( struct st_context *st, const struct pipe_shader_state *templ); diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 65cac9dbde..7c669ab457 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -370,7 +370,7 @@ clear_with_quad(GLcontext *ctx, fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead); fs.outputs_written = tgsi_mesa_translate_fragment_output_mask(stfp->Base.Base.OutputsWritten); fs.tokens = &stfp->tokens[0]; - cached = st_cached_shader_state(st, &fs); + cached = st_cached_fs_state(st, &fs); pipe->bind_fs_state(pipe, cached); } @@ -386,7 +386,7 @@ clear_with_quad(GLcontext *ctx, vs.inputs_read = stvp->Base.Base.InputsRead; vs.outputs_written = stvp->Base.Base.OutputsWritten; vs.tokens = &stvp->tokens[0]; - cached = st_cached_shader_state(st, &vs); + cached = st_cached_vs_state(st, &vs); pipe->bind_vs_state(pipe, cached); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 731c060c11..67de781c83 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -347,7 +347,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, memset(&fs, 0, sizeof(fs)); fs.inputs_read = stfp->Base.Base.InputsRead; fs.tokens = &stfp->tokens[0]; - cached = st_cached_shader_state(ctx->st, &fs); + cached = st_cached_fs_state(ctx->st, &fs); pipe->bind_fs_state(pipe, cached); } @@ -363,7 +363,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, vs.inputs_read = stvp->Base.Base.InputsRead; vs.outputs_written = stvp->Base.Base.OutputsWritten; vs.tokens = &stvp->tokens[0]; - cached = st_cached_shader_state(ctx->st, &vs); + cached = st_cached_vs_state(ctx->st, &vs); pipe->bind_vs_state(pipe, cached); } -- cgit v1.2.3 From c0bf7322088715bb411068c3d631b0c4be8cdff5 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Wed, 19 Sep 2007 12:35:29 -0400 Subject: Redo the cso cache to map driver data in a lot more pleasing way. Drivers can now create whatever they want from the state template. We use cso_state object to store the template (necessary during lookups), and the driver data. Convert blend state to the new semantics. --- src/mesa/pipe/cso_cache/cso_cache.h | 5 +++++ src/mesa/pipe/failover/fo_context.h | 6 +++++- src/mesa/pipe/failover/fo_state.c | 34 ++++++++++++++++++++++++++++--- src/mesa/pipe/failover/fo_state_emit.c | 3 ++- src/mesa/pipe/i915simple/i915_state.c | 10 ++++----- src/mesa/pipe/p_context.h | 10 ++++----- src/mesa/pipe/softpipe/sp_state.h | 6 +++--- src/mesa/pipe/softpipe/sp_state_blend.c | 10 ++++----- src/mesa/state_tracker/st_atom_blend.c | 8 ++++---- src/mesa/state_tracker/st_cache.c | 21 ++++++++++--------- src/mesa/state_tracker/st_cache.h | 14 +++++++------ src/mesa/state_tracker/st_cb_clear.c | 8 ++++---- src/mesa/state_tracker/st_cb_drawpixels.c | 4 ++-- src/mesa/state_tracker/st_context.h | 3 ++- 14 files changed, 91 insertions(+), 51 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/cso_cache/cso_cache.h b/src/mesa/pipe/cso_cache/cso_cache.h index 352e1a6a59..7ac5908922 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.h +++ b/src/mesa/pipe/cso_cache/cso_cache.h @@ -48,6 +48,11 @@ struct cso_cache { struct cso_hash *vs_hash; }; +struct cso_blend { + struct pipe_blend_state state; + void *data; +}; + enum cso_cache_type { CSO_BLEND, CSO_SAMPLER, diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index 9556a17e4d..ea7fb109b3 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -60,13 +60,17 @@ #define FO_HW 0 #define FO_SW 1 +struct fo_state { + void *sw_state; + void *hw_state; +}; struct failover_context { struct pipe_context pipe; /**< base class */ /* The most recent drawing state as set by the driver: */ - const struct pipe_blend_state *blend; + const struct fo_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; const struct pipe_rasterizer_state *rasterizer; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index 04ebd33d0d..ba110a6e4f 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -57,17 +57,43 @@ failover_set_alpha_test_state(struct pipe_context *pipe, } -static void +static void * +failover_create_blend_state( struct pipe_context *pipe, + const struct pipe_blend_state *blend ) +{ + struct fo_state *state = malloc(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_blend_state(pipe, blend); + state->hw_state = failover->hw->create_blend_state(pipe, blend); + + return state; +} + +static void failover_bind_blend_state( struct pipe_context *pipe, - const struct pipe_blend_state *blend ) + void *blend ) { struct failover_context *failover = failover_context(pipe); - failover->blend = blend; + failover->blend = (struct fo_state *)blend; failover->dirty |= FO_NEW_BLEND; failover->hw->bind_blend_state( failover->hw, blend ); } +static void +failover_delete_blend_state( struct pipe_context *pipe, + void *blend ) +{ + struct fo_state *state = (struct fo_state*)blend; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_blend_state(pipe, state->sw_state); + failover->hw->delete_blend_state(pipe, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + free(state); +} static void failover_set_blend_color( struct pipe_context *pipe, @@ -253,7 +279,9 @@ failover_set_vertex_element(struct pipe_context *pipe, void failover_init_state_functions( struct failover_context *failover ) { + failover->pipe.create_blend_state = failover_create_blend_state; failover->pipe.bind_blend_state = failover_bind_blend_state; + failover->pipe.delete_blend_state = failover_delete_blend_state; failover->pipe.bind_sampler_state = failover_bind_sampler_state; failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state; failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index 9d304074d0..72697c01a9 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -59,7 +59,8 @@ failover_state_emit( struct failover_context *failover ) failover->sw->set_alpha_test_state( failover->sw, &failover->alpha_test ); if (failover->dirty & FO_NEW_BLEND) - failover->sw->bind_blend_state( failover->sw, failover->blend ); + failover->sw->bind_blend_state( failover->sw, + failover->blend->sw_state ); if (failover->dirty & FO_NEW_BLEND_COLOR) failover->sw->set_blend_color( failover->sw, &failover->blend_color ); diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index aaf2ccf499..86c108978f 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -38,7 +38,7 @@ /* None of this state is actually used for anything yet. */ -static const struct pipe_blend_state * +static void * i915_create_blend_state(struct pipe_context *pipe, const struct pipe_blend_state *blend) { @@ -49,20 +49,20 @@ i915_create_blend_state(struct pipe_context *pipe, } static void i915_bind_blend_state( struct pipe_context *pipe, - const struct pipe_blend_state *blend ) + void *blend ) { struct i915_context *i915 = i915_context(pipe); - i915->blend = blend; + i915->blend = (struct pipe_blend_state *)blend; i915->dirty |= I915_NEW_BLEND; } static void i915_delete_blend_state( struct pipe_context *pipe, - const struct pipe_blend_state *blend ) + void *blend ) { - free((void*)blend); + free(blend); } static void i915_set_blend_color( struct pipe_context *pipe, diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 5766b2b7df..adca6612d5 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -85,12 +85,10 @@ struct pipe_context { /* * State functions */ - const struct pipe_blend_state * (*create_blend_state)(struct pipe_context *, - const struct pipe_blend_state *); - void (*bind_blend_state)(struct pipe_context *, - const struct pipe_blend_state *); - void (*delete_blend_state)(struct pipe_context *, - const struct pipe_blend_state *); + void * (*create_blend_state)(struct pipe_context *, + const struct pipe_blend_state *); + void (*bind_blend_state)(struct pipe_context *, void *); + void (*delete_blend_state)(struct pipe_context *, void *); const struct pipe_sampler_state * (*create_sampler_state)( struct pipe_context *, diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 04cc743bd0..8e7776a6c7 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -33,13 +33,13 @@ #include "pipe/p_state.h" -const struct pipe_blend_state * +void * softpipe_create_blend_state(struct pipe_context *, const struct pipe_blend_state *); void softpipe_bind_blend_state(struct pipe_context *, - const struct pipe_blend_state *); + void *); void softpipe_delete_blend_state(struct pipe_context *, - const struct pipe_blend_state *); + void *); const struct pipe_sampler_state * softpipe_create_sampler_state(struct pipe_context *, diff --git a/src/mesa/pipe/softpipe/sp_state_blend.c b/src/mesa/pipe/softpipe/sp_state_blend.c index 83f456ded5..7a94e82d6f 100644 --- a/src/mesa/pipe/softpipe/sp_state_blend.c +++ b/src/mesa/pipe/softpipe/sp_state_blend.c @@ -30,7 +30,7 @@ #include "sp_context.h" #include "sp_state.h" -const struct pipe_blend_state * +void * softpipe_create_blend_state(struct pipe_context *pipe, const struct pipe_blend_state *blend) { @@ -41,19 +41,19 @@ softpipe_create_blend_state(struct pipe_context *pipe, } void softpipe_bind_blend_state( struct pipe_context *pipe, - const struct pipe_blend_state *blend ) + void *blend ) { struct softpipe_context *softpipe = softpipe_context(pipe); - softpipe->blend = blend; + softpipe->blend = (const struct pipe_blend_state *)blend; softpipe->dirty |= SP_NEW_BLEND; } void softpipe_delete_blend_state(struct pipe_context *pipe, - const struct pipe_blend_state *blend ) + void *blend ) { - free((struct pipe_blend_state *)blend); + free(blend); } diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c index d94beb66c7..d5eadc3541 100644 --- a/src/mesa/state_tracker/st_atom_blend.c +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -211,14 +211,14 @@ update_blend( struct st_context *st ) if (st->ctx->Color.DitherFlag) blend.dither = 1; - struct pipe_blend_state *real_blend = + const struct cso_blend *cso = st_cached_blend_state(st, &blend); - if (st->state.blend != real_blend) { + if (st->state.blend != cso) { /* state has changed */ - st->state.blend = real_blend; + st->state.blend = cso; /* bind new state */ - st->pipe->bind_blend_state(st->pipe, real_blend); + st->pipe->bind_blend_state(st->pipe, cso->data); } if (memcmp(st->ctx->Color.BlendColor, &st->state.blend_color, 4 * sizeof(GLfloat)) != 0) { diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index d84a396e18..bd6c63b7a1 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -43,21 +43,22 @@ * in the cache or it will create a new state state from the given * template, will insert it in the cache and return it. */ -struct pipe_blend_state * st_cached_blend_state( - struct st_context *st, - const struct pipe_blend_state *blend) +const struct cso_blend * st_cached_blend_state(struct st_context *st, + const struct pipe_blend_state *templ) { - unsigned hash_key = cso_construct_key((void*)blend, sizeof(struct pipe_blend_state)); + unsigned hash_key = cso_construct_key((void*)templ, sizeof(struct pipe_blend_state)); struct cso_hash_iter iter = cso_find_state_template(st->cache, hash_key, CSO_BLEND, - (void*)blend); + (void*)templ); if (cso_hash_iter_is_null(iter)) { - const struct pipe_blend_state *created_state = st->pipe->create_blend_state( - st->pipe, blend); - iter = cso_insert_state(st->cache, hash_key, CSO_BLEND, - (void*)created_state); + struct cso_blend *cso = malloc(sizeof(struct cso_blend)); + memcpy(&cso->state, templ, sizeof(struct pipe_blend_state)); + cso->data = st->pipe->create_blend_state(st->pipe, templ); + if (!cso->data) + cso->data = &cso->state; + iter = cso_insert_state(st->cache, hash_key, CSO_BLEND, cso); } - return (struct pipe_blend_state*)(cso_hash_iter_data(iter)); + return ((struct cso_blend *)cso_hash_iter_data(iter)); } struct pipe_sampler_state * st_cached_sampler_state( diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index bcbe19b823..fb0ff0d4db 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -33,17 +33,19 @@ #ifndef ST_CACHE_H #define ST_CACHE_H +#include "pipe/cso_cache/cso_cache.h" + struct pipe_blend_state; struct pipe_sampler_state; struct st_context; -struct pipe_blend_state * st_cached_blend_state( - struct st_context *st, - const struct pipe_blend_state *blend); +const struct cso_blend * +st_cached_blend_state(struct st_context *st, + const struct pipe_blend_state *blend); -struct pipe_sampler_state * st_cached_sampler_state( - struct st_context *st, - const struct pipe_sampler_state *sampler); +struct pipe_sampler_state * +st_cached_sampler_state(struct st_context *st, + const struct pipe_sampler_state *sampler); struct pipe_depth_stencil_state *st_cached_depth_stencil_state( struct st_context *st, diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 7c669ab457..3a6991754a 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -298,7 +298,7 @@ clear_with_quad(GLcontext *ctx, /* blend state: RGBA masking */ { struct pipe_blend_state blend; - const struct pipe_blend_state *state; + const struct cso_blend *cso; memset(&blend, 0, sizeof(blend)); if (color) { if (ctx->Color.ColorMask[0]) @@ -312,8 +312,8 @@ clear_with_quad(GLcontext *ctx, if (st->ctx->Color.DitherFlag) blend.dither = 1; } - state = st_cached_blend_state(st, &blend); - pipe->bind_blend_state(pipe, state); + cso = st_cached_blend_state(st, &blend); + pipe->bind_blend_state(pipe, cso->data); } /* depth_stencil state: always pass/set to ref value */ @@ -411,7 +411,7 @@ clear_with_quad(GLcontext *ctx, /* Restore pipe state */ pipe->set_alpha_test_state(pipe, &st->state.alpha_test); - pipe->bind_blend_state(pipe, st->state.blend); + pipe->bind_blend_state(pipe, st->state.blend->data); pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil); pipe->bind_fs_state(pipe, st->state.fs); pipe->bind_vs_state(pipe, st->state.vs); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 67de781c83..4a554cd5a4 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -493,8 +493,8 @@ static GLboolean any_fragment_ops(const struct st_context *st) { if (st->state.alpha_test.enabled || - st->state.blend->blend_enable || - st->state.blend->logicop_enable || + st->state.blend->state.blend_enable || + st->state.blend->state.logicop_enable || st->state.depth_stencil->depth.enabled) /* XXX more checks */ return GL_TRUE; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index a8ae5d9c56..966574b67c 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -40,6 +40,7 @@ struct st_fragment_program; struct draw_context; struct draw_stage; struct cso_cache; +struct cso_blend; #define ST_NEW_MESA 0x1 /* Mesa state has changed */ #define ST_NEW_FRAGMENT_PROGRAM 0x2 @@ -74,7 +75,7 @@ struct st_context * though, we just shove random objects across the interface. */ struct { - const struct pipe_blend_state *blend; + const struct cso_blend *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; const struct pipe_rasterizer_state *rasterizer; -- cgit v1.2.3 From fe555c39bb7fd530298b5be4a8f06bff41726c86 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Wed, 19 Sep 2007 14:01:18 -0400 Subject: Convert the rasterizer cso to the new semantics. Basically make cso hold the driver specific struct, while managing the template. --- src/mesa/pipe/cso_cache/cso_cache.h | 5 ++++ src/mesa/pipe/failover/fo_context.h | 2 +- src/mesa/pipe/failover/fo_state.c | 35 ++++++++++++++++++++++++---- src/mesa/pipe/failover/fo_state_emit.c | 3 ++- src/mesa/pipe/i915simple/i915_state.c | 18 ++++++-------- src/mesa/pipe/p_context.h | 11 ++++----- src/mesa/pipe/softpipe/sp_state.h | 8 +++---- src/mesa/pipe/softpipe/sp_state_rasterizer.c | 18 ++++++-------- src/mesa/state_tracker/st_atom_rasterizer.c | 10 ++++---- src/mesa/state_tracker/st_cache.c | 20 +++++++++------- src/mesa/state_tracker/st_cache.h | 6 ++--- src/mesa/state_tracker/st_cb_clear.c | 8 +++---- src/mesa/state_tracker/st_cb_drawpixels.c | 8 +++---- src/mesa/state_tracker/st_context.h | 2 +- src/mesa/state_tracker/st_draw.c | 2 +- 15 files changed, 90 insertions(+), 66 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/cso_cache/cso_cache.h b/src/mesa/pipe/cso_cache/cso_cache.h index 7ac5908922..cd4b64eec4 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.h +++ b/src/mesa/pipe/cso_cache/cso_cache.h @@ -53,6 +53,11 @@ struct cso_blend { void *data; }; +struct cso_rasterizer { + struct pipe_rasterizer_state state; + void *data; +}; + enum cso_cache_type { CSO_BLEND, CSO_SAMPLER, diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index ea7fb109b3..a649899010 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -73,7 +73,7 @@ struct failover_context { const struct fo_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; - const struct pipe_rasterizer_state *rasterizer; + const struct fo_state *rasterizer; const struct pipe_shader_state *fragment_shader; const struct pipe_shader_state *vertex_shader; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index ba110a6e4f..25725625e0 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -183,17 +183,42 @@ failover_set_polygon_stipple( struct pipe_context *pipe, failover->hw->set_polygon_stipple( failover->hw, stipple ); } +static void * +failover_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *templ) +{ + struct fo_state *state = malloc(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + state->sw_state = failover->sw->create_rasterizer_state(pipe, templ); + state->hw_state = failover->hw->create_rasterizer_state(pipe, templ); + + return state; +} static void -failover_bind_rasterizer_state( struct pipe_context *pipe, - const struct pipe_rasterizer_state *setup ) +failover_bind_rasterizer_state(struct pipe_context *pipe, + void *raster) { struct failover_context *failover = failover_context(pipe); - failover->rasterizer = setup; + failover->rasterizer = (struct fo_state *)raster; failover->dirty |= FO_NEW_RASTERIZER; - failover->hw->bind_rasterizer_state( failover->hw, setup ); + failover->hw->bind_rasterizer_state( failover->hw, raster ); +} + +static void +failover_delete_rasterizer_state(struct pipe_context *pipe, + void *raster) +{ + struct fo_state *state = (struct fo_state*)raster; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_rasterizer_state(pipe, state->sw_state); + failover->hw->delete_rasterizer_state(pipe, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + free(state); } @@ -284,7 +309,9 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.delete_blend_state = failover_delete_blend_state; failover->pipe.bind_sampler_state = failover_bind_sampler_state; failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state; + failover->pipe.create_rasterizer_state = failover_create_rasterizer_state; failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state; + failover->pipe.delete_rasterizer_state = failover_delete_rasterizer_state; failover->pipe.bind_fs_state = failover_bind_fs_state; failover->pipe.bind_vs_state = failover_bind_vs_state; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index 72697c01a9..f2b0b1edc0 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -87,7 +87,8 @@ failover_state_emit( struct failover_context *failover ) failover->sw->set_polygon_stipple( failover->sw, &failover->poly_stipple ); if (failover->dirty & FO_NEW_RASTERIZER) - failover->sw->bind_rasterizer_state( failover->sw, failover->rasterizer ); + failover->sw->bind_rasterizer_state( failover->sw, + failover->rasterizer->sw_state ); if (failover->dirty & FO_NEW_SCISSOR) failover->sw->set_scissor_state( failover->sw, &failover->scissor ); diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 4a4d26be65..66aa9a0274 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -371,23 +371,19 @@ static void i915_set_viewport_state( struct pipe_context *pipe, } -static const struct pipe_rasterizer_state * +static void * i915_create_rasterizer_state(struct pipe_context *pipe, const struct pipe_rasterizer_state *setup) { - struct pipe_rasterizer_state *raster = - malloc(sizeof(struct pipe_rasterizer_state)); - memcpy(raster, setup, sizeof(struct pipe_rasterizer_state)); - - return raster; + return 0; } static void i915_bind_rasterizer_state( struct pipe_context *pipe, - const struct pipe_rasterizer_state *setup ) + void *setup ) { struct i915_context *i915 = i915_context(pipe); - i915->rasterizer = setup; + i915->rasterizer = (struct pipe_rasterizer_state *)setup; /* pass-through to draw module */ draw_set_rasterizer_state(i915->draw, setup); @@ -395,10 +391,10 @@ static void i915_bind_rasterizer_state( struct pipe_context *pipe, i915->dirty |= I915_NEW_RASTERIZER; } -static void i915_delete_rasterizer_state( struct pipe_context *pipe, - const struct pipe_rasterizer_state *setup ) +static void i915_delete_rasterizer_state(struct pipe_context *pipe, + void *setup) { - free((struct pipe_rasterizer_state*)setup); + /* do nothing */ } static void i915_set_vertex_buffer( struct pipe_context *pipe, diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index adca6612d5..1c0ab794f0 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -99,13 +99,10 @@ struct pipe_context { void (*delete_sampler_state)(struct pipe_context *, const struct pipe_sampler_state *); - const struct pipe_rasterizer_state *(*create_rasterizer_state)( - struct pipe_context *, - const struct pipe_rasterizer_state *); - void (*bind_rasterizer_state)(struct pipe_context *, - const struct pipe_rasterizer_state *); - void (*delete_rasterizer_state)(struct pipe_context *, - const struct pipe_rasterizer_state *); + void *(*create_rasterizer_state)(struct pipe_context *, + const struct pipe_rasterizer_state *); + void (*bind_rasterizer_state)(struct pipe_context *, void *); + void (*delete_rasterizer_state)(struct pipe_context *, void *); const struct pipe_depth_stencil_state * (*create_depth_stencil_state)( struct pipe_context *, diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 8e7776a6c7..a20ae1d4a2 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -58,13 +58,13 @@ void softpipe_bind_depth_stencil_state(struct pipe_context *, void softpipe_delete_depth_stencil_state(struct pipe_context *, const struct pipe_depth_stencil_state *); -const struct pipe_rasterizer_state * +void * softpipe_create_rasterizer_state(struct pipe_context *, - const struct pipe_rasterizer_state *); -void softpipe_bind_rasterizer_state(struct pipe_context *, const struct pipe_rasterizer_state *); +void softpipe_bind_rasterizer_state(struct pipe_context *, + void *); void softpipe_delete_rasterizer_state(struct pipe_context *, - const struct pipe_rasterizer_state *); + void *); void softpipe_set_framebuffer_state( struct pipe_context *, const struct pipe_framebuffer_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_rasterizer.c b/src/mesa/pipe/softpipe/sp_state_rasterizer.c index d832adb91b..d7845cef82 100644 --- a/src/mesa/pipe/softpipe/sp_state_rasterizer.c +++ b/src/mesa/pipe/softpipe/sp_state_rasterizer.c @@ -32,34 +32,30 @@ -const struct pipe_rasterizer_state * +void * softpipe_create_rasterizer_state(struct pipe_context *pipe, - const struct pipe_rasterizer_state *setup) + const struct pipe_rasterizer_state *setup) { - struct pipe_rasterizer_state *raster = - malloc(sizeof(struct pipe_rasterizer_state)); - memcpy(raster, setup, sizeof(struct pipe_rasterizer_state)); - - return raster; + return 0; } void softpipe_bind_rasterizer_state(struct pipe_context *pipe, - const struct pipe_rasterizer_state *setup) + void *setup) { struct softpipe_context *softpipe = softpipe_context(pipe); /* pass-through to draw module */ draw_set_rasterizer_state(softpipe->draw, setup); - softpipe->rasterizer = setup; + softpipe->rasterizer = (struct pipe_rasterizer_state *)setup; softpipe->dirty |= SP_NEW_RASTERIZER; } void softpipe_delete_rasterizer_state(struct pipe_context *pipe, - const struct pipe_rasterizer_state *rasterizer) + void *rasterizer) { - free((struct pipe_rasterizer_state*)rasterizer); + /* do nothing */ } diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index cab8ad5cd6..e0d83ddaea 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -73,7 +73,7 @@ static void update_raster_state( struct st_context *st ) { GLcontext *ctx = st->ctx; struct pipe_rasterizer_state raster; - const struct pipe_rasterizer_state *cached; + const struct cso_rasterizer *cso; memset(&raster, 0, sizeof(raster)); @@ -206,10 +206,10 @@ static void update_raster_state( struct st_context *st ) if (ctx->Scissor.Enabled) raster.scissor = 1; - cached = st_cached_rasterizer_state(st, &raster); - if (st->state.rasterizer != cached) { - st->state.rasterizer = cached; - st->pipe->bind_rasterizer_state( st->pipe, cached ); + cso = st_cached_rasterizer_state(st, &raster); + if (st->state.rasterizer != cso) { + st->state.rasterizer = cso; + st->pipe->bind_rasterizer_state(st->pipe, cso->data); } } diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index bd6c63b7a1..0f233cea58 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -95,22 +95,24 @@ struct pipe_depth_stencil_state * st_cached_depth_stencil_state( return (struct pipe_depth_stencil_state*)(cso_hash_iter_data(iter)); } -struct pipe_rasterizer_state * st_cached_rasterizer_state( +const struct cso_rasterizer* st_cached_rasterizer_state( struct st_context *st, - const struct pipe_rasterizer_state *raster) + const struct pipe_rasterizer_state *templ) { - unsigned hash_key = cso_construct_key((void*)raster, + unsigned hash_key = cso_construct_key((void*)templ, sizeof(struct pipe_rasterizer_state)); struct cso_hash_iter iter = cso_find_state_template(st->cache, hash_key, CSO_RASTERIZER, - (void*)raster); + (void*)templ); if (cso_hash_iter_is_null(iter)) { - const struct pipe_rasterizer_state *created_state = - st->pipe->create_rasterizer_state(st->pipe, raster); - iter = cso_insert_state(st->cache, hash_key, CSO_RASTERIZER, - (void*)created_state); + struct cso_rasterizer *cso = malloc(sizeof(struct cso_rasterizer)); + memcpy(&cso->state, templ, sizeof(struct pipe_rasterizer_state)); + cso->data = st->pipe->create_rasterizer_state(st->pipe, templ); + if (!cso->data) + cso->data = &cso->state; + iter = cso_insert_state(st->cache, hash_key, CSO_RASTERIZER, cso); } - return (struct pipe_rasterizer_state*)(cso_hash_iter_data(iter)); + return (struct cso_rasterizer*)(cso_hash_iter_data(iter)); } struct pipe_shader_state * st_cached_fs_state( diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index fb0ff0d4db..5b8c6168a8 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -51,9 +51,9 @@ struct pipe_depth_stencil_state *st_cached_depth_stencil_state( struct st_context *st, const struct pipe_depth_stencil_state *depth_stencil); -struct pipe_rasterizer_state *st_cached_rasterizer_state( - struct st_context *st, - const struct pipe_rasterizer_state *raster); +const struct cso_rasterizer * +st_cached_rasterizer_state(struct st_context *st, + const struct pipe_rasterizer_state *raster); struct pipe_shader_state *st_cached_fs_state( struct st_context *st, diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 3a6991754a..5d5efd9eae 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -345,7 +345,7 @@ clear_with_quad(GLcontext *ctx, /* setup state: nothing */ { struct pipe_rasterizer_state raster; - const struct pipe_rasterizer_state *cached; + const struct cso_rasterizer *cso; memset(&raster, 0, sizeof(raster)); #if 0 /* don't do per-pixel scissor; we'll just draw a PIPE_PRIM_QUAD @@ -354,8 +354,8 @@ clear_with_quad(GLcontext *ctx, if (ctx->Scissor.Enabled) raster.scissor = 1; #endif - cached = st_cached_rasterizer_state(ctx->st, &raster); - pipe->bind_rasterizer_state(pipe, cached); + cso = st_cached_rasterizer_state(ctx->st, &raster); + pipe->bind_rasterizer_state(pipe, cso->data); } /* fragment shader state: color pass-through program */ @@ -415,7 +415,7 @@ clear_with_quad(GLcontext *ctx, pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil); pipe->bind_fs_state(pipe, st->state.fs); pipe->bind_vs_state(pipe, st->state.vs); - pipe->bind_rasterizer_state(pipe, st->state.rasterizer); + pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); /* OR: st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 4a554cd5a4..0fd728c930 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -328,12 +328,12 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* setup state: just scissor */ { struct pipe_rasterizer_state setup; - struct pipe_rasterizer_state *cached; + const struct cso_rasterizer *cso; memset(&setup, 0, sizeof(setup)); if (ctx->Scissor.Enabled) setup.scissor = 1; - cached = st_cached_rasterizer_state(ctx->st, &setup); - pipe->bind_rasterizer_state(pipe, cached); + cso = st_cached_rasterizer_state(ctx->st, &setup); + pipe->bind_rasterizer_state(pipe, cso->data); } /* fragment shader state: TEX lookup program */ @@ -417,7 +417,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, draw_quad(ctx, x0, y0, z, x1, y1); /* restore GL state */ - pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer); + pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer->data); pipe->bind_fs_state(pipe, ctx->st->state.fs); pipe->bind_vs_state(pipe, ctx->st->state.vs); pipe->set_texture_state(pipe, unit, ctx->st->state.texture[unit]); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 966574b67c..93b6425480 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -78,7 +78,7 @@ struct st_context const struct cso_blend *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; - const struct pipe_rasterizer_state *rasterizer; + const struct cso_rasterizer *rasterizer; const struct pipe_shader_state *fs; const struct pipe_shader_state *vs; diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 6efe3ce8b8..e36c10d595 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -404,7 +404,7 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(draw); draw_set_viewport_state(draw, &st->state.viewport); draw_set_clip_state(draw, &st->state.clip); - draw_set_rasterizer_state(draw, st->state.rasterizer); + draw_set_rasterizer_state(draw, st->state.rasterizer->data); draw_set_vertex_shader(draw, st->state.vs); /* XXX need to set vertex info too */ -- cgit v1.2.3 From 37cf13ed9a429c755f121daa1776b1b30a985ab3 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 19 Sep 2007 18:53:36 -0600 Subject: Checkpoint: replacement of TGSI_ATTRIB_x tokens with input/output semantics. TGSI_ATTRIB_x tokens still present and used in a few places. Expanded set of TGSI_SEMANTIC_x tokens for describing the meaning of inputs/outputs. These tokens are in a crude state ATM. Lots of #if 0 / disabled code to be removed yet, etc... Softpipe and i915 drivers should be in working condition but not heavily tested. --- src/mesa/pipe/draw/draw_vertex_shader.c | 4 + src/mesa/pipe/i915simple/i915_context.c | 14 +++ src/mesa/pipe/i915simple/i915_fpc.h | 2 + src/mesa/pipe/i915simple/i915_fpc_translate.c | 81 +++++++++++++++-- src/mesa/pipe/i915simple/i915_state_derived.c | 60 ++++++++++++- src/mesa/pipe/p_context.h | 3 +- src/mesa/pipe/p_defines.h | 7 ++ src/mesa/pipe/p_state.h | 11 ++- src/mesa/pipe/softpipe/sp_context.c | 10 +++ src/mesa/pipe/softpipe/sp_state_derived.c | 90 +++++++++---------- src/mesa/pipe/tgsi/exec/tgsi_build.c | 2 +- src/mesa/pipe/tgsi/exec/tgsi_dump.c | 18 +++- src/mesa/pipe/tgsi/exec/tgsi_token.h | 31 +++++-- src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c | 118 ++++++++++++++++++++----- src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h | 2 + src/mesa/state_tracker/st_atom_fs.c | 121 ++++++++++++++++++++------ src/mesa/state_tracker/st_atom_vs.c | 114 ++++++++++++++++-------- src/mesa/state_tracker/st_cb_clear.c | 45 ++-------- src/mesa/state_tracker/st_cb_drawpixels.c | 33 +------ src/mesa/state_tracker/st_cb_rasterpos.c | 13 ++- src/mesa/state_tracker/st_draw.c | 8 +- src/mesa/state_tracker/st_program.h | 27 ++++-- 22 files changed, 580 insertions(+), 234 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/draw/draw_vertex_shader.c b/src/mesa/pipe/draw/draw_vertex_shader.c index cb6c605b8d..2d424632e7 100644 --- a/src/mesa/pipe/draw/draw_vertex_shader.c +++ b/src/mesa/pipe/draw/draw_vertex_shader.c @@ -94,7 +94,11 @@ run_vertex_program(struct draw_context *draw, const float *trans = draw->viewport.translate; assert(count <= 4); +#if 0 assert(draw->vertex_shader.outputs_written & (1 << TGSI_ATTRIB_POS)); +#else + assert(draw->vertex_shader.output_semantics[0] == TGSI_SEMANTIC_POSITION); +#endif #ifdef DEBUG memset( &machine, 0, sizeof( machine ) ); diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index 36372898ce..715e1ef656 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -138,6 +138,18 @@ i915_max_texture_size(struct pipe_context *pipe, unsigned textureType, } +static int +i915_get_param(struct pipe_context *pipe, uint param) +{ + switch (param) { + case PIPE_PARAM_FS_NEEDS_POS: + return 0; + default: + return 0; + } +} + + static void i915_destroy( struct pipe_context *pipe ) { struct i915_context *i915 = i915_context( pipe ); @@ -272,6 +284,8 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys, i915->pipe.destroy = i915_destroy; i915->pipe.supported_formats = i915_supported_formats; i915->pipe.max_texture_size = i915_max_texture_size; + i915->pipe.get_param = i915_get_param; + i915->pipe.clear = i915_clear; i915->pipe.begin_query = i915_begin_query; diff --git a/src/mesa/pipe/i915simple/i915_fpc.h b/src/mesa/pipe/i915simple/i915_fpc.h index 84e4c5a6f3..5c4f2f90e9 100644 --- a/src/mesa/pipe/i915simple/i915_fpc.h +++ b/src/mesa/pipe/i915simple/i915_fpc.h @@ -51,6 +51,8 @@ struct i915_fp_compile { uint declarations[I915_PROGRAM_SIZE]; uint program[I915_PROGRAM_SIZE]; + uint input_semantic[PIPE_MAX_SHADER_INPUTS]; + /** points into the i915->current.constants array: */ float (*constants)[4]; uint num_constants; diff --git a/src/mesa/pipe/i915simple/i915_fpc_translate.c b/src/mesa/pipe/i915simple/i915_fpc_translate.c index 32c5600496..df8859bec8 100644 --- a/src/mesa/pipe/i915simple/i915_fpc_translate.c +++ b/src/mesa/pipe/i915simple/i915_fpc_translate.c @@ -128,7 +128,7 @@ src_vector(struct i915_fp_compile *p, const struct tgsi_full_src_register *source) { uint index = source->SrcRegister.Index; - uint src; + uint src, sem; switch (source->SrcRegister.File) { case TGSI_FILE_TEMPORARY: @@ -151,6 +151,46 @@ src_vector(struct i915_fp_compile *p, /* use vertex format info to map a slot number to a VF attrib */ assert(index < p->vertex_info->num_attribs); + + sem = p->input_semantic[index]; + +#if 1 + switch (sem) { + case TGSI_SEMANTIC_POSITION: + printf("SKIP SEM POS\n"); + /* + assert(p->wpos_tex != -1); + src = i915_emit_decl(p, REG_TYPE_T, p->wpos_tex, D0_CHANNEL_ALL); + */ + break; + case TGSI_SEMANTIC_COLOR0: + src = i915_emit_decl(p, REG_TYPE_T, T_DIFFUSE, D0_CHANNEL_ALL); + break; + case TGSI_SEMANTIC_COLOR1: + src = i915_emit_decl(p, REG_TYPE_T, T_SPECULAR, D0_CHANNEL_XYZ); + src = swizzle(src, X, Y, Z, ONE); + break; + case TGSI_SEMANTIC_FOG: + src = i915_emit_decl(p, REG_TYPE_T, T_FOG_W, D0_CHANNEL_W); + src = swizzle(src, W, W, W, W); + break; + case TGSI_SEMANTIC_TEX0: + case TGSI_SEMANTIC_TEX1: + case TGSI_SEMANTIC_TEX2: + case TGSI_SEMANTIC_TEX3: + case TGSI_SEMANTIC_TEX4: + case TGSI_SEMANTIC_TEX5: + case TGSI_SEMANTIC_TEX6: + case TGSI_SEMANTIC_TEX7: + src = i915_emit_decl(p, REG_TYPE_T, + T_TEX0 + (sem - TGSI_SEMANTIC_TEX0), + D0_CHANNEL_ALL); + break; + default: + i915_program_error(p, "Bad source->Index"); + return 0; + } +#else index = p->vertex_info->slot_to_attrib[index]; switch (index) { @@ -185,6 +225,7 @@ src_vector(struct i915_fp_compile *p, i915_program_error(p, "Bad source->Index"); return 0; } +#endif break; case TGSI_FILE_CONSTANT: @@ -220,9 +261,12 @@ src_vector(struct i915_fp_compile *p, } /* no abs() or post-abs negation */ +#if 0 + /* XXX assertions disabled to allow arbfplight.c to run */ + /* XXX enable these assertions, or fix things */ assert(!source->SrcRegisterExtMod.Absolute); assert(!source->SrcRegisterExtMod.Negate); - +#endif return src; } @@ -848,7 +892,15 @@ i915_translate_instructions(struct i915_fp_compile *p, switch( parse.FullToken.Token.Type ) { case TGSI_TOKEN_TYPE_DECLARATION: - /* XXX no-op? */ + if (parse.FullToken.FullDeclaration.Declaration.File + == TGSI_FILE_INPUT) { + /* save input register info for use in src_vector() */ + uint ind, sem; + ind = parse.FullToken.FullDeclaration.u.DeclarationRange.First; + sem = parse.FullToken.FullDeclaration.Semantic.SemanticName; + /*printf("FS Input DECL [%u] sem %u\n", ind, sem);*/ + p->input_semantic[ind] = sem; + } break; case TGSI_TOKEN_TYPE_IMMEDIATE: @@ -989,6 +1041,7 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p) static void i915_find_wpos_space(struct i915_fp_compile *p) { +#if 0 const uint inputs = p->shader->inputs_read | (1 << TGSI_ATTRIB_POS); /*XXX hack*/ uint i; @@ -1005,6 +1058,14 @@ i915_find_wpos_space(struct i915_fp_compile *p) i915_program_error(p, "No free texcoord for wpos value"); } +#else + if (p->shader->input_semantics[0] == TGSI_SEMANTIC_POSITION) { + /* frag shader using the fragment position input */ +#if 0 + assert(0); +#endif + } +#endif } @@ -1018,13 +1079,17 @@ i915_find_wpos_space(struct i915_fp_compile *p) static void i915_fixup_depth_write(struct i915_fp_compile *p) { - if (p->shader->outputs_written & (1 << TGSI_ATTRIB_POS)) { - uint depth = UREG(REG_TYPE_OD, 0); + /* XXX assuming depth is always in output[0] */ + if (p->shader->output_semantics[0] == TGSI_SEMANTIC_DEPTH) { + const uint depth = UREG(REG_TYPE_OD, 0); i915_emit_arith(p, - A0_MOV, - depth, A0_DEST_CHANNEL_W, 0, - swizzle(depth, X, Y, Z, Z), 0, 0); + A0_MOV, /* opcode */ + depth, /* dest reg */ + A0_DEST_CHANNEL_W, /* write mask */ + 0, /* saturate? */ + swizzle(depth, X, Y, Z, Z), /* src0 */ + 0, 0 /* src1, src2 */); } } diff --git a/src/mesa/pipe/i915simple/i915_state_derived.c b/src/mesa/pipe/i915simple/i915_state_derived.c index 8d404c55ab..dece697497 100644 --- a/src/mesa/pipe/i915simple/i915_state_derived.c +++ b/src/mesa/pipe/i915simple/i915_state_derived.c @@ -33,6 +33,7 @@ #include "i915_state.h" #include "i915_reg.h" #include "i915_fpc.h" +#include "pipe/tgsi/exec/tgsi_token.h" /** @@ -42,19 +43,71 @@ */ static void calculate_vertex_layout( struct i915_context *i915 ) { - const uint inputsRead = i915->fs->inputs_read; + const struct pipe_shader_state *fs = i915->fs; const interp_mode colorInterp = i915->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR; struct vertex_info *vinfo = &i915->current.vertex_info; uint front0 = 0, back0 = 0, front1 = 0, back1 = 0; boolean needW = 0; + uint i; + boolean texCoords[8]; + memset(texCoords, 0, sizeof(texCoords)); memset(vinfo, 0, sizeof(*vinfo)); /* pos */ draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_POS, FORMAT_3F, INTERP_LINEAR); /* Note: we'll set the S4_VFMT_XYZ[W] bits below */ + for (i = 0; i < fs->num_inputs; i++) { + switch (fs->input_semantics[i]) { + case TGSI_SEMANTIC_POSITION: + break; + case TGSI_SEMANTIC_COLOR0: + front0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0, + FORMAT_4UB, colorInterp); + vinfo->hwfmt[0] |= S4_VFMT_COLOR; + break; + case TGSI_SEMANTIC_COLOR1: + assert(0); /* untested */ + front1 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1, + FORMAT_4UB, colorInterp); + vinfo->hwfmt[0] |= S4_VFMT_SPEC_FOG; + break; + case TGSI_SEMANTIC_TEX0: + case TGSI_SEMANTIC_TEX1: + case TGSI_SEMANTIC_TEX2: + case TGSI_SEMANTIC_TEX3: + case TGSI_SEMANTIC_TEX4: + case TGSI_SEMANTIC_TEX5: + case TGSI_SEMANTIC_TEX6: + case TGSI_SEMANTIC_TEX7: + { + const uint unit = fs->input_semantics[i] - TGSI_SEMANTIC_TEX0; + uint hwtc; + texCoords[unit] = TRUE; + draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_TEX0 + i, + FORMAT_4F, INTERP_PERSPECTIVE); + hwtc = TEXCOORDFMT_4D; + needW = TRUE; + vinfo->hwfmt[1] |= hwtc << (unit * 4); + } + break; + default: + assert(0); + } + + } + + /* finish up texcoord fields */ + for (i = 0; i < 8; i++) { + if (!texCoords[i]) { + const uint hwtc = TEXCOORDFMT_NOT_PRESENT; + vinfo->hwfmt[1] |= hwtc << (i* 4); + } + } + +#if 0 /* color0 */ if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) { front0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0, @@ -88,6 +141,7 @@ static void calculate_vertex_layout( struct i915_context *i915 ) vinfo->hwfmt[1] |= hwtc << ((i - TGSI_ATTRIB_TEX0) * 4); } } +#endif /* go back and fill in the vertex position info now that we have needW */ if (needW) { @@ -104,11 +158,11 @@ static void calculate_vertex_layout( struct i915_context *i915 ) * the vertex header. */ if (i915->rasterizer->light_twoside) { - if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) { + if (front0) { back0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0, FORMAT_OMIT, colorInterp); } - if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) { + if (back0) { back1 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC1, FORMAT_OMIT, colorInterp); } diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 1c0ab794f0..65001dfdf9 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -57,7 +57,8 @@ struct pipe_context { const char *(*get_vendor)( struct pipe_context *pipe ); - + int (*get_param)( struct pipe_context *pipe, int param ); + /* * Drawing. diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h index b3ee890576..2a8109b10c 100644 --- a/src/mesa/pipe/p_defines.h +++ b/src/mesa/pipe/p_defines.h @@ -307,4 +307,11 @@ #define PIPE_QUERY_PRIMITIVES_EMITTED 2 #define PIPE_QUERY_TYPES 3 + +/** + * Pipe capabilities/queries + */ +#define PIPE_PARAM_FS_NEEDS_POS 1 + + #endif diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index d2cc76a59b..6396d49b84 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -50,6 +50,8 @@ #define PIPE_MAX_COLOR_BUFS 8 #define PIPE_MAX_TEXTURE_LEVELS 16 #define PIPE_MAX_FEEDBACK_ATTRIBS 16 +#define PIPE_MAX_SHADER_INPUTS 16 +#define PIPE_MAX_SHADER_OUTPUTS 16 /* fwd decl */ @@ -140,13 +142,14 @@ struct pipe_constant_buffer { struct pipe_shader_state { - unsigned inputs_read; /**< TGSI_ATTRIB_ bits */ - unsigned outputs_written; /**< TGSI_ATTRIB_ bits */ const struct tgsi_token *tokens; void *executable; - uint num_inputs; - uint num_outputs; + /** These fields somewhat constitute the shader "signature" */ + ubyte num_inputs; + ubyte num_outputs; + ubyte input_semantics[PIPE_MAX_SHADER_INPUTS]; + ubyte output_semantics[PIPE_MAX_SHADER_OUTPUTS]; }; struct pipe_depth_stencil_state diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index a56793d683..ebd5530950 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -236,6 +236,15 @@ static const char *softpipe_get_vendor( struct pipe_context *pipe ) return "Tungsten Graphics, Inc."; } +static int softpipe_get_param(struct pipe_context *pipe, uint param) +{ + switch (param) { + case PIPE_PARAM_FS_NEEDS_POS: + return 1; + default: + return 0; + } +} struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, struct softpipe_winsys *softpipe_winsys ) @@ -248,6 +257,7 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, /* queries */ softpipe->pipe.supported_formats = softpipe_supported_formats; softpipe->pipe.max_texture_size = softpipe_max_texture_size; + softpipe->pipe.get_param = softpipe_get_param; /* state setters */ softpipe->pipe.create_blend_state = softpipe_create_blend_state; diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index 9611a2ac99..0dd0eea0b8 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -34,6 +34,7 @@ #include "sp_state.h" #include "pipe/tgsi/exec/tgsi_attribs.h" +#include "pipe/tgsi/exec/tgsi_token.h" /** @@ -43,7 +44,7 @@ */ static void calculate_vertex_layout( struct softpipe_context *softpipe ) { - const uint inputsRead = softpipe->fs->inputs_read; + const struct pipe_shader_state *fs = softpipe->fs; const interp_mode colorInterp = softpipe->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR; struct vertex_info *vinfo = &softpipe->vertex_info; @@ -52,57 +53,59 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) memset(vinfo, 0, sizeof(*vinfo)); - /* Need Z if depth test is enabled or the fragment program uses the - * fragment position (XYZW). - */ - if (softpipe->depth_stencil->depth.enabled || - (inputsRead & (1 << TGSI_ATTRIB_POS))) + if (softpipe->depth_stencil->depth.enabled) softpipe->need_z = TRUE; else softpipe->need_z = FALSE; + softpipe->need_w = FALSE; - /* Need W if we do any perspective-corrected interpolation or the - * fragment program uses the fragment position. - */ - if (inputsRead & (1 << TGSI_ATTRIB_POS)) - softpipe->need_w = TRUE; - else - softpipe->need_w = FALSE; - - /* position */ + /* always emit vertex pos */ /* TODO - Figure out if we need to do perspective divide, etc. */ draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_POS, FORMAT_4F, INTERP_LINEAR); - - /* color0 */ - if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) { - front0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0, - FORMAT_4F, colorInterp); - } - - /* color1 */ - if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) { - front1 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1, - FORMAT_4F, colorInterp); - } - /* fog */ - if (inputsRead & (1 << TGSI_ATTRIB_FOG)) { - draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_FOG, - FORMAT_1F, INTERP_PERSPECTIVE); - } - - /* point size */ + for (i = 0; i < fs->num_inputs; i++) { + switch (fs->input_semantics[i]) { + case TGSI_SEMANTIC_POSITION: + /* Need Z if depth test is enabled or the fragment program uses the + * fragment position (XYZW). + */ + softpipe->need_z = TRUE; + softpipe->need_w = TRUE; + break; + case TGSI_SEMANTIC_COLOR0: + front0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0, + FORMAT_4F, colorInterp); + break; + case TGSI_SEMANTIC_COLOR1: + front1 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1, + FORMAT_4F, colorInterp); + break; + case TGSI_SEMANTIC_FOG: + draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_FOG, + FORMAT_1F, INTERP_PERSPECTIVE); + break; #if 0 - /* XXX only emit if drawing points or front/back polygon mode is point mode */ - draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_POINTSIZE, - FORMAT_4F, INTERP_CONSTANT); + case TGSI_SEMANTIC_PSIZE: + /* XXX only emit if drawing points or front/back polygon mode + * is point mode + */ + draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_POINTSIZE, + FORMAT_4F, INTERP_CONSTANT); + break; #endif - - /* texcoords and varying vars */ - for (i = TGSI_ATTRIB_TEX0; i < TGSI_ATTRIB_VAR7; i++) { - if (inputsRead & (1 << i)) { + /*case TGSI_SEMANTIC_TEXCOORD:*/ + case TGSI_SEMANTIC_TEX0: + draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_TEX0, + FORMAT_4F, INTERP_PERSPECTIVE); + softpipe->need_w = TRUE; + break; + case TGSI_SEMANTIC_OTHER: draw_emit_vertex_attr(vinfo, i, FORMAT_4F, INTERP_PERSPECTIVE); softpipe->need_w = TRUE; + break; + + default: + assert(0); } } @@ -113,12 +116,11 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) * the vertex header. */ if (softpipe->rasterizer->light_twoside) { - if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) { + if (front0) { back0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0, FORMAT_OMIT, colorInterp); } - - if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) { + if (back0) { back1 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC1, FORMAT_OMIT, colorInterp); } diff --git a/src/mesa/pipe/tgsi/exec/tgsi_build.c b/src/mesa/pipe/tgsi/exec/tgsi_build.c index 20e4cf17f0..1320872c64 100755 --- a/src/mesa/pipe/tgsi/exec/tgsi_build.c +++ b/src/mesa/pipe/tgsi/exec/tgsi_build.c @@ -325,7 +325,7 @@ tgsi_build_declaration_semantic( { struct tgsi_declaration_semantic ds; - assert( semantic_name <= TGSI_SEMANTIC_COLOR ); + assert( semantic_name <= TGSI_SEMANTIC_COUNT ); assert( semantic_index <= 0xFFFF ); ds = tgsi_default_declaration_semantic(); diff --git a/src/mesa/pipe/tgsi/exec/tgsi_dump.c b/src/mesa/pipe/tgsi/exec/tgsi_dump.c index e6e99d9d75..0a47ad2a8c 100755 --- a/src/mesa/pipe/tgsi/exec/tgsi_dump.c +++ b/src/mesa/pipe/tgsi/exec/tgsi_dump.c @@ -202,13 +202,27 @@ static const char *TGSI_INTERPOLATES_SHORT[] = static const char *TGSI_SEMANTICS[] = { "SEMANTIC_DEPTH", - "SEMANTIC_COLOR" + "SEMANTIC_COLOR0", + "SEMANTIC_COLOR1", + "SEMANTIC_COLOR0B", + "SEMANTIC_COLOR1B", + "SEMANTIC_POSITION", + "SEMANTIC_FOG", + "SEMANTIC_OTHER," + "SEMANTIC_TEX0", }; static const char *TGSI_SEMANTICS_SHORT[] = { "DEPTH", - "COLOR" + "COLOR0", + "COLOR1", + "COLOR0B", + "COLOR1B", + "POSITION", + "FOG", + "OTHER", + "TEX0" }; static const char *TGSI_IMMS[] = diff --git a/src/mesa/pipe/tgsi/exec/tgsi_token.h b/src/mesa/pipe/tgsi/exec/tgsi_token.h index ca53071a60..a642ba131a 100644 --- a/src/mesa/pipe/tgsi/exec/tgsi_token.h +++ b/src/mesa/pipe/tgsi/exec/tgsi_token.h @@ -73,11 +73,11 @@ struct tgsi_declaration { unsigned Type : 4; /* TGSI_TOKEN_TYPE_DECLARATION */ unsigned Size : 8; /* UINT */ - unsigned File : 4; /* TGSI_FILE_ */ - unsigned Declare : 4; /* TGSI_DECLARE_ */ - unsigned UsageMask : 4; /* TGSI_WRITEMASK_ */ - unsigned Interpolate : 1; /* BOOL */ - unsigned Semantic : 1; /* BOOL */ + unsigned File : 4; /* one of TGSI_FILE_x */ + unsigned Declare : 4; /* one of TGSI_DECLARE_x */ + unsigned UsageMask : 4; /* bitmask of TGSI_WRITEMASK_x flags */ + unsigned Interpolate : 1; /* BOOL, any interpolation info? */ + unsigned Semantic : 1; /* BOOL, any semantic info? */ unsigned Padding : 5; unsigned Extended : 1; /* BOOL */ }; @@ -103,12 +103,27 @@ struct tgsi_declaration_interpolation unsigned Padding : 28; }; -#define TGSI_SEMANTIC_DEPTH 0 -#define TGSI_SEMANTIC_COLOR 1 +#define TGSI_SEMANTIC_DEPTH 0 +#define TGSI_SEMANTIC_COLOR0 1 +#define TGSI_SEMANTIC_COLOR1 2 +#define TGSI_SEMANTIC_COLOR0B 3 /**< back-face primary color */ +#define TGSI_SEMANTIC_COLOR1B 4 /**< back-face secondary color */ +#define TGSI_SEMANTIC_POSITION 5 +#define TGSI_SEMANTIC_FOG 6 +#define TGSI_SEMANTIC_OTHER 7 /* XXX temp */ +#define TGSI_SEMANTIC_TEX0 8 +#define TGSI_SEMANTIC_TEX1 9 +#define TGSI_SEMANTIC_TEX2 10 +#define TGSI_SEMANTIC_TEX3 11 +#define TGSI_SEMANTIC_TEX4 12 +#define TGSI_SEMANTIC_TEX5 13 +#define TGSI_SEMANTIC_TEX6 14 +#define TGSI_SEMANTIC_TEX7 15 +#define TGSI_SEMANTIC_COUNT 16 /**< number of semantic values */ struct tgsi_declaration_semantic { - unsigned SemanticName : 8; /* TGSI_SEMANTIC_ */ + unsigned SemanticName : 8; /* one of TGSI_SEMANTIC_ */ unsigned SemanticIndex : 16; /* UINT */ unsigned Padding : 8; }; diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c index 1f8d937bc6..fb8365aab5 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c @@ -3,9 +3,9 @@ #include "pipe/tgsi/exec/tgsi_attribs.h" #include "pipe/tgsi/mesa/mesa_to_tgsi.h" -#define TGSI_DEBUG 1 - +#define TGSI_DEBUG 0 +#if 0 /** * Convert a VERT_ATTRIB_x to a TGSI_ATTRIB_y */ @@ -209,9 +209,10 @@ tgsi_mesa_translate_fragment_output(GLuint attrib) return 0; } } +#endif -#if 01 +#if 0 uint tgsi_mesa_translate_vertex_input_mask(GLbitfield mask) { @@ -225,7 +226,6 @@ tgsi_mesa_translate_vertex_input_mask(GLbitfield mask) } return tgsiMask; } -#endif uint tgsi_mesa_translate_vertex_output_mask(GLbitfield mask) @@ -271,6 +271,7 @@ tgsi_mesa_translate_fragment_output_mask(GLbitfield mask) } +#endif @@ -319,12 +320,16 @@ map_register_file_index( GLuint processor, GLuint file, GLuint index, +#if 0 GLbitfield usage_bitmask, +#endif const GLuint inputMapping[], const GLuint outputMapping[]) { GLuint mapped_index; +#if 0 GLuint i; +#endif assert(processor == TGSI_PROCESSOR_FRAGMENT || processor == TGSI_PROCESSOR_VERTEX); @@ -345,7 +350,8 @@ map_register_file_index( inputMapping[index]); return inputMapping[index]; } - + assert(0); +#if 0 assert( usage_bitmask & (1 << index) ); mapped_index = 0; for( i = 0; i < index; i++ ) { @@ -354,6 +360,7 @@ map_register_file_index( } } printf("Map %d input %d to %d\n", processor, index, mapped_index); +#endif break; case TGSI_FILE_OUTPUT: @@ -375,14 +382,17 @@ map_register_file_index( else { /* vertex output slots are tightly packed, find mapped pos */ /* mapped_index = VERT_RESULT_x */ +#if 0 mapped_index = 0; for( i = 0; i < index; i++ ) { if( usage_bitmask & (1 << i) ) { mapped_index++; } } - printf("Map VP output from %d to %d\n", index, mapped_index); assert(outputMapping[index] == mapped_index); +#endif + mapped_index = outputMapping[index]; + printf("Map VP output from %d to %d\n", index, mapped_index); } break; @@ -452,8 +462,10 @@ static GLboolean compile_instruction( const struct prog_instruction *inst, struct tgsi_full_instruction *fullinst, +#if 0 GLuint inputs_read, GLuint outputs_written, +#endif const GLuint inputMapping[], const GLuint outputMapping[], GLuint preamble_size, @@ -475,8 +487,14 @@ compile_instruction( processor, fulldst->DstRegister.File, inst->DstReg.Index, +#if 0 outputs_written, +#endif +#if 0 NULL, +#else + inputMapping, +#endif outputMapping ); fulldst->DstRegister.WriteMask = convert_writemask( inst->DstReg.WriteMask ); @@ -490,7 +508,9 @@ compile_instruction( processor, fullsrc->SrcRegister.File, inst->SrcReg[i].Index, +#if 0 inputs_read, +#endif inputMapping, outputMapping ); @@ -766,10 +786,10 @@ compile_instruction( static struct tgsi_full_declaration make_frag_input_decl( - GLuint first, - GLuint last, + GLuint index, GLuint interpolate, - GLuint usage_mask ) + GLuint usage_mask, + GLuint semantic_name ) { struct tgsi_full_declaration decl; @@ -777,9 +797,11 @@ make_frag_input_decl( decl.Declaration.File = TGSI_FILE_INPUT; decl.Declaration.Declare = TGSI_DECLARE_RANGE; decl.Declaration.UsageMask = usage_mask; + decl.Declaration.Semantic = 1; decl.Declaration.Interpolate = 1; - decl.u.DeclarationRange.First = first; - decl.u.DeclarationRange.Last = last; + decl.u.DeclarationRange.First = index; + decl.u.DeclarationRange.Last = index; + decl.Semantic.SemanticName = semantic_name; decl.Interpolation.Interpolate = interpolate; return decl; @@ -809,15 +831,20 @@ make_frag_output_decl( /** * Convert Mesa fragment program to TGSI format. - * \param inputMapping array to map original Mesa fragment program inputs - * registers to TGSI generic input indexes - * \param interpMode array[FRAG_ATTRIB_x] of TGSI_INTERPOLATE_LINEAR/PERSP. + * \param inputMapping maps Mesa fragment program inputs to TGSI generic + * input indexes + * \param inputSemantic the TGSI_SEMANTIC flag for each input + * \param interpMode the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input + * \param outputMapping maps Mesa fragment program outputs to TGSI + * generic outputs * */ GLboolean tgsi_mesa_compile_fp_program( const struct gl_fragment_program *program, + GLuint numInputs, const GLuint inputMapping[], + const ubyte inputSemantic[], const GLuint interpMode[], const GLuint outputMapping[], struct tgsi_token *tokens, @@ -831,9 +858,9 @@ tgsi_mesa_compile_fp_program( /* struct tgsi_full_dst_register *fulldst; struct tgsi_full_src_register *fullsrc; - */ GLuint inputs_read; GLboolean reads_wpos; + */ GLuint preamble_size = 0; *(struct tgsi_version *) &tokens[0] = tgsi_build_version(); @@ -846,6 +873,7 @@ tgsi_mesa_compile_fp_program( ti = 3; +#if 0 reads_wpos = program->Base.InputsRead & (1 << FRAG_ATTRIB_WPOS); inputs_read = program->Base.InputsRead | (1 << FRAG_ATTRIB_WPOS); @@ -856,10 +884,10 @@ tgsi_mesa_compile_fp_program( /* Fragment position. */ if( reads_wpos ) { fulldecl = make_frag_input_decl( - 0, 0, TGSI_INTERPOLATE_CONSTANT, - TGSI_WRITEMASK_XY ); + TGSI_WRITEMASK_XY, + TGSI_SEMANTIC_POSITION ); ti += tgsi_build_full_declaration( &fulldecl, &tokens[ti], @@ -869,10 +897,10 @@ tgsi_mesa_compile_fp_program( /* Fragment zw. */ fulldecl = make_frag_input_decl( - 0, 0, TGSI_INTERPOLATE_LINEAR, - reads_wpos ? TGSI_WRITEMASK_ZW : TGSI_WRITEMASK_Z ); + reads_wpos ? TGSI_WRITEMASK_ZW : TGSI_WRITEMASK_Z, + TGSI_SEMANTIC_POSITION ); ti += tgsi_build_full_declaration( &fulldecl, &tokens[ti], @@ -884,15 +912,55 @@ tgsi_mesa_compile_fp_program( if( inputs_read & (1 << i) ) { count++; fulldecl = make_frag_input_decl(count, - count, interpMode[i], - TGSI_WRITEMASK_XYZW ); + TGSI_WRITEMASK_XYZW, + inputSemantic[count] ); ti += tgsi_build_full_declaration(&fulldecl, &tokens[ti], header, maxTokens - ti ); } } +#else + + for (i = 0; i < numInputs; i++) { + switch (inputSemantic[i]) { + case TGSI_SEMANTIC_POSITION: + /* Fragment XY pos */ + fulldecl = make_frag_input_decl(i, + TGSI_INTERPOLATE_CONSTANT, + TGSI_WRITEMASK_XY, + TGSI_SEMANTIC_POSITION ); + ti += tgsi_build_full_declaration( + &fulldecl, + &tokens[ti], + header, + maxTokens - ti ); + /* Fragment ZW pos */ + fulldecl = make_frag_input_decl(i, + TGSI_INTERPOLATE_LINEAR, + TGSI_WRITEMASK_ZW, + TGSI_SEMANTIC_POSITION ); + ti += tgsi_build_full_declaration( + &fulldecl, + &tokens[ti], + header, + maxTokens - ti ); + break; + default: + fulldecl = make_frag_input_decl(i, + interpMode[i], + TGSI_WRITEMASK_XYZW, + inputSemantic[i] ); + ti += tgsi_build_full_declaration(&fulldecl, + &tokens[ti], + header, + maxTokens - ti ); + break; + } + } +#endif + /* * Declare output attributes. @@ -914,7 +982,7 @@ tgsi_mesa_compile_fp_program( if( program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR) ) { fulldecl = make_frag_output_decl( 1, - TGSI_SEMANTIC_COLOR, + TGSI_SEMANTIC_COLOR0, TGSI_WRITEMASK_XYZW ); ti += tgsi_build_full_declaration( &fulldecl, @@ -956,8 +1024,10 @@ tgsi_mesa_compile_fp_program( if( compile_instruction( &program->Base.Instructions[i], &fullinst, +#if 0 inputs_read, ~0, /*outputs_written*/ +#endif inputMapping, outputMapping, preamble_size, @@ -992,10 +1062,12 @@ tgsi_mesa_compile_vp_program( struct tgsi_header *header; struct tgsi_processor *processor; struct tgsi_full_instruction fullinst; +#if 0 GLuint inputs_read = ~0; GLuint outputs_written; outputs_written = program->Base.OutputsWritten; +#endif *(struct tgsi_version *) &tokens[0] = tgsi_build_version(); @@ -1011,8 +1083,10 @@ tgsi_mesa_compile_vp_program( if( compile_instruction( &program->Base.Instructions[i], &fullinst, +#if 0 inputs_read, outputs_written, +#endif inputMapping, outputMapping, 0, diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h index 017cfce72e..8105e9e738 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h @@ -10,7 +10,9 @@ struct tgsi_token; GLboolean tgsi_mesa_compile_fp_program( const struct gl_fragment_program *program, + GLuint numInputs, const GLuint inputMapping[], + const ubyte inputSemantic[], const GLuint interpMode[], const GLuint outputMapping[], struct tgsi_token *tokens, diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index 6dd576a57c..94b69c8df7 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -27,6 +27,7 @@ /* * Authors: * Keith Whitwell + * Brian Paul */ #include "shader/prog_parameter.h" @@ -42,55 +43,121 @@ #include "st_atom.h" #include "st_program.h" + #define TGSI_DEBUG 1 -static void compile_fs( struct st_context *st ) + +/** + * Translate a Mesa fragment shader into a TGSI shader. + * \return pointer to cached pipe_shader object. + */ +struct pipe_shader_state * +st_translate_fragment_shader(struct st_context *st, + struct st_fragment_program *stfp) { - /* Map FRAG_RESULT_COLR to output 1, map FRAG_RESULT_DEPR to output 0 */ - static const GLuint outputMapping[2] = {1, 0}; - struct st_fragment_program *fp = st->fp; + GLuint outputMapping[FRAG_RESULT_MAX]; + GLuint inputMapping[PIPE_MAX_SHADER_INPUTS]; struct pipe_shader_state fs; struct pipe_shader_state *cached; GLuint interpMode[16]; /* XXX size? */ GLuint i; + GLbitfield inputsRead = stfp->Base.Base.InputsRead; + + /* Check if all fragment programs need the fragment position (in order + * to do perspective-corrected interpolation). + */ + if (st->pipe->get_param(st->pipe, PIPE_PARAM_FS_NEEDS_POS)) + inputsRead |= FRAG_BIT_WPOS; + + memset(&fs, 0, sizeof(fs)); for (i = 0; i < 16; i++) { - if (fp->Base.Base.InputsRead & (1 << i)) { - if (i == FRAG_ATTRIB_COL0 || i == FRAG_ATTRIB_COL1) { - interpMode[i] = TGSI_INTERPOLATE_LINEAR; + if (inputsRead & (1 << i)) { + inputMapping[i] = fs.num_inputs; + + switch (i) { + case FRAG_ATTRIB_WPOS: + fs.input_semantics[fs.num_inputs] = TGSI_SEMANTIC_POSITION; + interpMode[fs.num_inputs] = TGSI_INTERPOLATE_CONSTANT; + break; + case FRAG_ATTRIB_COL0: + fs.input_semantics[fs.num_inputs] = TGSI_SEMANTIC_COLOR0; + interpMode[fs.num_inputs] = TGSI_INTERPOLATE_LINEAR; + break; + case FRAG_ATTRIB_COL1: + fs.input_semantics[fs.num_inputs] = TGSI_SEMANTIC_COLOR1; + interpMode[fs.num_inputs] = TGSI_INTERPOLATE_LINEAR; + break; + case FRAG_ATTRIB_TEX0: + fs.input_semantics[fs.num_inputs] = TGSI_SEMANTIC_TEX0; + interpMode[fs.num_inputs] = TGSI_INTERPOLATE_PERSPECTIVE; + break; + default: + assert(0); } - else { - interpMode[i] = TGSI_INTERPOLATE_PERSPECTIVE; + + fs.num_inputs++; + } + } + + /* + * Outputs + */ + for (i = 0; i < FRAG_RESULT_MAX; i++) { + if (stfp->Base.Base.OutputsWritten & (1 << i)) { + switch (i) { + case FRAG_RESULT_DEPR: + fs.output_semantics[fs.num_outputs] = TGSI_SEMANTIC_DEPTH; + outputMapping[i] = fs.num_outputs; + break; + case FRAG_RESULT_COLR: + fs.output_semantics[fs.num_outputs] = TGSI_SEMANTIC_COLOR0; + outputMapping[i] = fs.num_outputs; + break; + default: + assert(0); } + fs.num_outputs++; } } /* XXX: fix static allocation of tokens: */ - tgsi_mesa_compile_fp_program( &fp->Base, NULL, interpMode, + tgsi_mesa_compile_fp_program( &stfp->Base, + fs.num_inputs, + inputMapping, + fs.input_semantics, + interpMode, outputMapping, - fp->tokens, ST_FP_MAX_TOKENS ); + stfp->tokens, ST_FP_MAX_TOKENS ); - memset(&fs, 0, sizeof(fs)); +#if 0 fs.inputs_read - = tgsi_mesa_translate_fragment_input_mask(fp->Base.Base.InputsRead); + = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead); +#endif +#if 0 fs.outputs_written - = tgsi_mesa_translate_fragment_output_mask(fp->Base.Base.OutputsWritten); - fs.tokens = &fp->tokens[0]; + = tgsi_mesa_translate_fragment_output_mask(stfp->Base.Base.OutputsWritten); +#endif + + fs.tokens = &stfp->tokens[0]; + cached = st_cached_fs_state(st, &fs); - fp->fsx = cached; + stfp->fs = cached; if (TGSI_DEBUG) - tgsi_dump( fp->tokens, 0/*TGSI_DUMP_VERBOSE*/ ); + tgsi_dump( stfp->tokens, 0/*TGSI_DUMP_VERBOSE*/ ); + + stfp->dirty = 0; - fp->dirty = 0; + return cached; } static void update_fs( struct st_context *st ) { - struct st_fragment_program *fp = NULL; + struct st_fragment_program *stfp = NULL; /* find active shader and params. Changes to this Mesa state * should be covered by ST_NEW_FRAGMENT_PROGRAM, thanks to the @@ -101,21 +168,21 @@ static void update_fs( struct st_context *st ) st->ctx->Shader.CurrentProgram->FragmentProgram) { struct gl_fragment_program *f = st->ctx->Shader.CurrentProgram->FragmentProgram; - fp = st_fragment_program(f); + stfp = st_fragment_program(f); } else { assert(st->ctx->FragmentProgram._Current); - fp = st_fragment_program(st->ctx->FragmentProgram._Current); + stfp = st_fragment_program(st->ctx->FragmentProgram._Current); } - /* translate shader to TGSI format */ - if (st->fp != fp || fp->dirty) { - st->fp = fp; + /* if new binding, or shader has changed */ + if (st->fp != stfp || stfp->dirty) { + /* Bind the program */ + st->fp = stfp; - if (fp->dirty) - compile_fs( st ); + if (stfp->dirty) + st->state.fs = st_translate_fragment_shader( st, st->fp ); - st->state.fs = fp->fsx; st->pipe->bind_fs_state(st->pipe, st->state.fs); } } diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index 322fabc456..cf9dd810e9 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -49,14 +49,15 @@ #define TGSI_DEBUG 1 - - /** - * Translate Mesa shader to TGSI format + * Translate a Mesa vertex shader into a TGSI shader. + * \return pointer to cached pipe_shader object. */ -static void compile_vs( struct st_context *st ) +struct pipe_shader_state * +st_translate_vertex_shader(struct st_context *st, + struct st_vertex_program *stvp) { - struct st_vertex_program *vp = st->vp; + GLuint outputMapping[PIPE_MAX_SHADER_INPUTS]; struct pipe_shader_state vs; struct pipe_shader_state *cached; GLuint i; @@ -69,20 +70,56 @@ static void compile_vs( struct st_context *st ) * values and TGSI generic input indexes. */ for (i = 0; i < MAX_VERTEX_PROGRAM_ATTRIBS; i++) { - if (vp->Base.Base.InputsRead & (1 << i)) { - vp->input_to_index[i] = vs.num_inputs; - vp->index_to_input[vs.num_inputs] = i; + if (stvp->Base.Base.InputsRead & (1 << i)) { + stvp->input_to_index[i] = vs.num_inputs; + stvp->index_to_input[vs.num_inputs] = i; + switch (i) { + case VERT_ATTRIB_POS: + vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_POSITION; + break; + case VERT_ATTRIB_COLOR0: + vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR0; + break; + case VERT_ATTRIB_COLOR1: + vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR1; + break; + default: + vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_OTHER; + } vs.num_inputs++; } } /* - * Determine output register mapping. + * Determine number of outputs and the register mapping. */ for (i = 0; i < VERT_RESULT_MAX; i++) { - if (vp->Base.Base.OutputsWritten & (1 << i)) { - vp->output_to_index[i] = vs.num_outputs; - vp->index_to_output[vs.num_outputs] = i; + if (stvp->Base.Base.OutputsWritten & (1 << i)) { +#if 0 + stvp->output_to_index[i] = vs.num_outputs; + stvp->index_to_output[vs.num_outputs] = i; +#endif + outputMapping[i] = vs.num_outputs; + + switch (i) { + case VERT_RESULT_HPOS: + vs.output_semantics[vs.num_outputs] = TGSI_SEMANTIC_POSITION; + break; + case VERT_RESULT_COL0: + vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR0; + break; + case VERT_RESULT_COL1: + vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR1; + break; + case VERT_RESULT_BFC0: + vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR0B; + break; + case VERT_RESULT_BFC1: + vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR1B; + break; + default: + vs.output_semantics[vs.num_outputs] = TGSI_SEMANTIC_OTHER; + } vs.num_outputs++; } } @@ -90,43 +127,50 @@ static void compile_vs( struct st_context *st ) /* XXX: fix static allocation of tokens: */ - tgsi_mesa_compile_vp_program( &vp->Base, - vp->input_to_index, - vp->output_to_index, - vp->tokens, ST_FP_MAX_TOKENS ); + tgsi_mesa_compile_vp_program( &stvp->Base, + stvp->input_to_index, +#if 0 + stvp->output_to_index, +#else + outputMapping, +#endif + stvp->tokens, ST_FP_MAX_TOKENS ); -#if 01 +#if 0 vs.inputs_read - = tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead); + = tgsi_mesa_translate_vertex_input_mask(stvp->Base.Base.InputsRead); #endif +#if 0 vs.outputs_written - = tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten); + = tgsi_mesa_translate_vertex_output_mask(stvp->Base.Base.OutputsWritten); +#endif - vs.tokens = &vp->tokens[0]; + vs.tokens = &stvp->tokens[0]; cached = st_cached_vs_state(st, &vs); - - vp->vs = cached; + stvp->vs = cached; if (TGSI_DEBUG) - tgsi_dump( vp->tokens, 0 ); + tgsi_dump( stvp->tokens, 0 ); #if defined(USE_X86_ASM) || defined(SLANG_X86) - if (vp->sse2_program.csr == vp->sse2_program.store) - tgsi_emit_sse2( vp->tokens, &vp->sse2_program ); + if (stvp->sse2_program.csr == stvp->sse2_program.store) + tgsi_emit_sse2( stvp->tokens, &stvp->sse2_program ); if (!cached->executable) - cached->executable = (void *) x86_get_func( &vp->sse2_program ); + cached->executable = (void *) x86_get_func( &stvp->sse2_program ); #endif - vp->dirty = 0; + stvp->dirty = 0; + + return cached; } static void update_vs( struct st_context *st ) { - struct st_vertex_program *vp; + struct st_vertex_program *stvp; /* find active shader and params -- Should be covered by * ST_NEW_VERTEX_PROGRAM @@ -136,20 +180,20 @@ static void update_vs( struct st_context *st ) st->ctx->Shader.CurrentProgram->VertexProgram) { struct gl_vertex_program *f = st->ctx->Shader.CurrentProgram->VertexProgram; - vp = st_vertex_program(f); + stvp = st_vertex_program(f); } else { assert(st->ctx->VertexProgram._Current); - vp = st_vertex_program(st->ctx->VertexProgram._Current); + stvp = st_vertex_program(st->ctx->VertexProgram._Current); } - if (st->vp != vp || vp->dirty) { - st->vp = vp; + if (st->vp != stvp || stvp->dirty) { + /* Bind the vertex program */ + st->vp = stvp; - if (vp->dirty) - compile_vs( st ); + if (stvp->dirty) + st->state.vs = st_translate_vertex_shader( st, st->vp ); - st->state.vs = st->vp->vs; st->pipe->bind_vs_state(st->pipe, st->state.vs); } } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 5d5efd9eae..ee70ce3320 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -121,11 +121,9 @@ is_depth_stencil_format(GLuint pipeFormat) static struct st_fragment_program * make_frag_shader(struct st_context *st) { - static const GLuint outputMapping[] = { 1, 0 }; GLcontext *ctx = st->ctx; struct st_fragment_program *stfp; struct gl_program *p; - GLboolean b; GLuint interpMode[16]; GLuint i; @@ -157,11 +155,7 @@ make_frag_shader(struct st_context *st) p->OutputsWritten = (1 << FRAG_RESULT_COLR); stfp = (struct st_fragment_program *) p; - /* compile into tgsi format */ - b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode, - outputMapping, - stfp->tokens, ST_FP_MAX_TOKENS); - assert(b); + st_translate_fragment_shader(st, stfp); return stfp; } @@ -174,15 +168,9 @@ make_frag_shader(struct st_context *st) static struct st_vertex_program * make_vertex_shader(struct st_context *st) { - /* Map VERT_ATTRIB_POS to 0, VERT_ATTRIB_COLOR0 to 1 */ - static const GLuint inputMapping[4] = { 0, 0, 0, 1 }; - /* Map VERT_RESULT_HPOS to 0, VERT_RESULT_COL0 to 1 */ - static const GLuint outputMapping[2] = { 0, 1 }; - GLcontext *ctx = st->ctx; struct st_vertex_program *stvp; struct gl_program *p; - GLboolean b; p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); if (!p) @@ -215,12 +203,8 @@ make_vertex_shader(struct st_context *st) (1 << VERT_RESULT_HPOS)); stvp = (struct st_vertex_program *) p; - /* compile into tgsi format */ - b = tgsi_mesa_compile_vp_program(&stvp->Base, - inputMapping, - outputMapping, - stvp->tokens, ST_FP_MAX_TOKENS); - assert(b); + st_translate_vertex_shader(st, stvp); + assert(stvp->vs); return stvp; } @@ -361,33 +345,19 @@ clear_with_quad(GLcontext *ctx, /* fragment shader state: color pass-through program */ { static struct st_fragment_program *stfp = NULL; - struct pipe_shader_state fs; - const struct pipe_shader_state *cached; if (!stfp) { stfp = make_frag_shader(st); } - memset(&fs, 0, sizeof(fs)); - fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead); - fs.outputs_written = tgsi_mesa_translate_fragment_output_mask(stfp->Base.Base.OutputsWritten); - fs.tokens = &stfp->tokens[0]; - cached = st_cached_fs_state(st, &fs); - pipe->bind_fs_state(pipe, cached); + pipe->bind_fs_state(pipe, stfp->fs); } /* vertex shader state: color/position pass-through */ { static struct st_vertex_program *stvp = NULL; - struct pipe_shader_state vs; - const struct pipe_shader_state *cached; if (!stvp) { stvp = make_vertex_shader(st); } - memset(&vs, 0, sizeof(vs)); - vs.inputs_read = stvp->Base.Base.InputsRead; - vs.outputs_written = stvp->Base.Base.OutputsWritten; - vs.tokens = &stvp->tokens[0]; - cached = st_cached_vs_state(st, &vs); - pipe->bind_vs_state(pipe, cached); + pipe->bind_vs_state(pipe, stvp->vs); } /* viewport state: viewport matching window dims */ @@ -522,12 +492,15 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) assert(strb->surface->format); +#if 01 if (ctx->Scissor.Enabled || (isDS && ctx->DrawBuffer->Visual.stencilBits > 0)) { /* scissoring or we have a combined depth/stencil buffer */ clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE); } - else { + else +#endif + { /* simple clear of whole buffer */ GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 0fd728c930..d4f260ee54 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -56,11 +56,9 @@ static struct st_fragment_program * make_fragment_shader(struct st_context *st) { - static const GLuint outputMapping[2] = { 1, 0 }; GLcontext *ctx = st->ctx; struct st_fragment_program *stfp; struct gl_program *p; - GLboolean b; GLuint interpMode[16]; GLuint i; @@ -94,11 +92,7 @@ make_fragment_shader(struct st_context *st) p->OutputsWritten = (1 << FRAG_RESULT_COLR); stfp = (struct st_fragment_program *) p; - /* compile into tgsi format */ - b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode, - outputMapping, - stfp->tokens, ST_FP_MAX_TOKENS); - assert(b); + st_translate_fragment_shader(st, stfp); return stfp; } @@ -112,11 +106,9 @@ static struct st_vertex_program * make_vertex_shader(struct st_context *st) { /* Map VERT_RESULT_HPOS to 0, VERT_RESULT_TEX0 to 1 */ - static const GLuint outputMapping[] = { 0, 0, 0, 0, 1 }; GLcontext *ctx = st->ctx; struct st_vertex_program *stvp; struct gl_program *p; - GLboolean b; p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); if (!p) @@ -149,11 +141,7 @@ make_vertex_shader(struct st_context *st) (1 << VERT_RESULT_HPOS)); stvp = (struct st_vertex_program *) p; - /* compile into tgsi format */ - b = tgsi_mesa_compile_vp_program(&stvp->Base, NULL, - outputMapping, - stvp->tokens, ST_FP_MAX_TOKENS); - assert(b); + st_translate_vertex_shader(st, stvp); return stvp; } @@ -339,32 +327,19 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* fragment shader state: TEX lookup program */ { static struct st_fragment_program *stfp = NULL; - struct pipe_shader_state fs; - struct pipe_shader_state *cached; if (!stfp) { stfp = make_fragment_shader(ctx->st); } - memset(&fs, 0, sizeof(fs)); - fs.inputs_read = stfp->Base.Base.InputsRead; - fs.tokens = &stfp->tokens[0]; - cached = st_cached_fs_state(ctx->st, &fs); - pipe->bind_fs_state(pipe, cached); + pipe->bind_fs_state(pipe, stfp->fs); } /* vertex shader state: position + texcoord pass-through */ { static struct st_vertex_program *stvp = NULL; - struct pipe_shader_state vs; - struct pipe_shader_state *cached; if (!stvp) { stvp = make_vertex_shader(ctx->st); } - memset(&vs, 0, sizeof(vs)); - vs.inputs_read = stvp->Base.Base.InputsRead; - vs.outputs_written = stvp->Base.Base.OutputsWritten; - vs.tokens = &stvp->tokens[0]; - cached = st_cached_vs_state(ctx->st, &vs); - pipe->bind_vs_state(pipe, cached); + pipe->bind_vs_state(pipe, stvp->vs); } /* texture sampling state: */ diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 98efe1a10b..5245535a65 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -53,6 +53,7 @@ static void setup_vertex_attribs(GLcontext *ctx) { struct pipe_context *pipe = ctx->st->pipe; +#if 0 const uint inputAttrs = ctx->st->state.vs->inputs_read; uint attr; @@ -77,6 +78,9 @@ setup_vertex_attribs(GLcontext *ctx) pipe->set_vertex_element(pipe, attr, &velement); } } +#else + assert(0); +#endif } @@ -84,7 +88,7 @@ static void setup_feedback(GLcontext *ctx) { struct pipe_context *pipe = ctx->st->pipe; - const uint outputAttrs = ctx->st->state.vs->outputs_written; + const struct pipe_shader_state *vs = ctx->st->state.vs; struct pipe_feedback_state feedback; uint i; @@ -94,8 +98,8 @@ setup_feedback(GLcontext *ctx) feedback.discard = 1; feedback.num_attribs = 0; - for (i = 0; i < TGSI_ATTRIB_VAR0; i++) { - if ((1 << i) & outputAttrs) { + for (i = 0; i < vs->num_outputs; i++) { + if (1/***(1 << i) & outputAttrs***/) { feedback.attrib[feedback.num_attribs] = i; feedback.size[feedback.num_attribs] = 4; feedback.num_attribs++; @@ -306,6 +310,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4]) PIPE_BUFFER_FLAG_READ); /* extract values and update rasterpos state */ +#if 0 /* XXX update */ { const uint outputAttrs = ctx->st->state.vs->outputs_written; const float *pos, *color0, *color1, *tex0; @@ -333,7 +338,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4]) update_rasterpos(ctx, pos, color0, color1, tex0); } - +#endif /* free vertex feedback buffer */ pipe->winsys->buffer_unmap(pipe->winsys, fb_buf.buffer); diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 7075db82e9..238ade00ac 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -356,7 +356,7 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, velement.vertex_buffer_index = 0; velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; velement.dst_offset = 0; - pipe->set_vertex_element(pipe, attribs[i], &velement); + pipe->set_vertex_element(pipe, i/**attribs[i]**/, &velement); } /* draw */ @@ -411,7 +411,7 @@ st_feedback_draw_vbo(GLcontext *ctx, update_default_attribs_buffer(ctx); - +#if 0 /* this must be after state validation */ attrsNeeded = ctx->st->state.vs->inputs_read; @@ -480,7 +480,9 @@ st_feedback_draw_vbo(GLcontext *ctx, draw_set_mapped_vertex_buffer(draw, attr, map); } } - +#else + assert(0); +#endif if (ib) { unsigned indexSize; diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 68ceba4d78..4945141d15 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -45,16 +45,15 @@ 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. - */ + GLuint id; /**< String id, for tracking ProgramStringNotify changes. */ struct tgsi_token tokens[ST_FP_MAX_TOKENS]; GLboolean dirty; - const struct pipe_shader_state *fsx; + /** Pointer to the corresponding cached shader */ + const struct pipe_shader_state *fs; + GLuint param_state; }; @@ -63,16 +62,17 @@ struct st_vertex_program { struct gl_vertex_program Base; /**< The Mesa vertex program */ GLboolean error; /**< Set if program is malformed for any reason. */ - - GLuint id; /**< String id, for tracking ProgramStringNotify changes. */ + GLuint id; /**< String id, for tracking ProgramStringNotify changes. */ /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */ GLuint input_to_index[MAX_VERTEX_PROGRAM_ATTRIBS]; /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */ GLuint index_to_input[MAX_VERTEX_PROGRAM_ATTRIBS]; +#if 0 GLuint output_to_index[MAX_VERTEX_PROGRAM_ATTRIBS]; GLuint index_to_output[MAX_VERTEX_PROGRAM_ATTRIBS]; +#endif /** The program in TGSI format */ struct tgsi_token tokens[ST_FP_MAX_TOKENS]; @@ -82,7 +82,9 @@ struct st_vertex_program struct x86_function sse2_program; #endif + /** Pointer to the corresponding cached shader */ const struct pipe_shader_state *vs; + GLuint param_state; }; @@ -102,4 +104,15 @@ st_vertex_program( struct gl_vertex_program *vp ) return (struct st_vertex_program *)vp; } + +extern struct pipe_shader_state * +st_translate_fragment_shader(struct st_context *st, + struct st_fragment_program *fp); + + +extern struct pipe_shader_state * +st_translate_vertex_shader(struct st_context *st, + struct st_vertex_program *vp); + + #endif -- cgit v1.2.3 From daf5b0f41baa50951e7c2f9ea5cd90b119085a7f Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Thu, 20 Sep 2007 07:50:33 -0400 Subject: Switch fragment/vertex shaders to the new caching semantics. Allow driver custom allocation within cached objects. The shaders are currently twiced (by cso layer and by the program itself). --- src/mesa/pipe/cso_cache/cso_cache.h | 10 +++++ src/mesa/pipe/failover/fo_context.h | 4 +- src/mesa/pipe/failover/fo_state.c | 75 +++++++++++++++++++++++++++---- src/mesa/pipe/failover/fo_state_emit.c | 6 ++- src/mesa/pipe/i915simple/i915_state.c | 28 +++++------- src/mesa/pipe/p_context.h | 23 ++++------ src/mesa/pipe/softpipe/sp_state.h | 11 ++--- src/mesa/pipe/softpipe/sp_state_fs.c | 27 +++++------ src/mesa/state_tracker/st_atom_fs.c | 12 ++--- src/mesa/state_tracker/st_atom_vs.c | 18 ++++---- src/mesa/state_tracker/st_cache.c | 36 ++++++++------- src/mesa/state_tracker/st_cache.h | 12 ++--- src/mesa/state_tracker/st_cb_clear.c | 8 ++-- src/mesa/state_tracker/st_cb_drawpixels.c | 8 ++-- src/mesa/state_tracker/st_cb_rasterpos.c | 3 +- src/mesa/state_tracker/st_context.h | 4 +- src/mesa/state_tracker/st_draw.c | 6 +-- src/mesa/state_tracker/st_program.h | 10 +++-- 18 files changed, 181 insertions(+), 120 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/cso_cache/cso_cache.h b/src/mesa/pipe/cso_cache/cso_cache.h index cd4b64eec4..57d162b2ac 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.h +++ b/src/mesa/pipe/cso_cache/cso_cache.h @@ -58,6 +58,16 @@ struct cso_rasterizer { void *data; }; +struct cso_fragment_shader { + struct pipe_shader_state state; + void *data; +}; + +struct cso_vertex_shader { + struct pipe_shader_state state; + void *data; +}; + enum cso_cache_type { CSO_BLEND, CSO_SAMPLER, diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index a649899010..a81bfe82dd 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -74,8 +74,8 @@ struct failover_context { const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; const struct fo_state *rasterizer; - const struct pipe_shader_state *fragment_shader; - const struct pipe_shader_state *vertex_shader; + const struct fo_state *fragment_shader; + const struct fo_state *vertex_shader; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index 25725625e0..db3aea7756 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -150,26 +150,81 @@ failover_set_framebuffer_state(struct pipe_context *pipe, failover->hw->set_framebuffer_state( failover->hw, framebuffer ); } + +static void * +failover_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct fo_state *state = malloc(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_fs_state(pipe, templ); + state->hw_state = failover->hw->create_fs_state(pipe, templ); + + return state; +} + static void failover_bind_fs_state(struct pipe_context *pipe, - const struct pipe_shader_state *fs) + void *fs) { struct failover_context *failover = failover_context(pipe); - failover->fragment_shader = fs; + failover->fragment_shader = (struct fo_state *)fs; failover->dirty |= FO_NEW_FRAGMENT_SHADER; - failover->hw->bind_fs_state( failover->hw, fs ); + failover->hw->bind_fs_state(failover->hw, (struct pipe_shader_state *)fs); +} + +static void +failover_delete_fs_state(struct pipe_context *pipe, + void *fs) +{ + struct fo_state *state = (struct fo_state*)fs; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_fs_state(pipe, state->sw_state); + failover->hw->delete_fs_state(pipe, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + free(state); +} + +static void * +failover_create_vs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct fo_state *state = malloc(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_vs_state(pipe, templ); + state->hw_state = failover->hw->create_vs_state(pipe, templ); + + return state; } static void failover_bind_vs_state(struct pipe_context *pipe, - const struct pipe_shader_state *vs) + void *vs) { struct failover_context *failover = failover_context(pipe); - failover->vertex_shader = vs; + failover->vertex_shader = (struct fo_state*)vs; failover->dirty |= FO_NEW_VERTEX_SHADER; - failover->hw->bind_vs_state( failover->hw, vs ); + failover->hw->bind_vs_state(failover->hw, vs); +} + +static void +failover_delete_vs_state(struct pipe_context *pipe, + void *vs) +{ + struct fo_state *state = (struct fo_state*)vs; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_vs_state(pipe, state->sw_state); + failover->hw->delete_vs_state(pipe, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + free(state); } static void @@ -312,8 +367,12 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.create_rasterizer_state = failover_create_rasterizer_state; failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state; failover->pipe.delete_rasterizer_state = failover_delete_rasterizer_state; - failover->pipe.bind_fs_state = failover_bind_fs_state; - failover->pipe.bind_vs_state = failover_bind_vs_state; + failover->pipe.create_fs_state = failover_create_fs_state; + failover->pipe.bind_fs_state = failover_bind_fs_state; + failover->pipe.delete_fs_state = failover_delete_fs_state; + failover->pipe.create_vs_state = failover_create_vs_state; + failover->pipe.bind_vs_state = failover_bind_vs_state; + failover->pipe.delete_vs_state = failover_delete_vs_state; failover->pipe.set_alpha_test_state = failover_set_alpha_test_state; failover->pipe.set_blend_color = failover_set_blend_color; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index f2b0b1edc0..ec896fd020 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -78,10 +78,12 @@ failover_state_emit( struct failover_context *failover ) failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer ); if (failover->dirty & FO_NEW_FRAGMENT_SHADER) - failover->sw->bind_fs_state( failover->sw, failover->fragment_shader ); + failover->sw->bind_fs_state( failover->sw, + failover->fragment_shader->sw_state ); if (failover->dirty & FO_NEW_VERTEX_SHADER) - failover->sw->bind_vs_state( failover->sw, failover->vertex_shader ); + failover->sw->bind_vs_state( failover->sw, + failover->vertex_shader->sw_state ); if (failover->dirty & FO_NEW_STIPPLE) failover->sw->set_polygon_stipple( failover->sw, &failover->poly_stipple ); diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 66aa9a0274..1104c9519d 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -228,41 +228,37 @@ static void i915_set_polygon_stipple( struct pipe_context *pipe, } -static const struct pipe_shader_state * -i915_create_shader_state( struct pipe_context *pipe, - const struct pipe_shader_state *templ ) +static void * +i915_create_shader_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) { - - struct pipe_shader_state *shader = malloc(sizeof(struct pipe_shader_state)); - memcpy(shader, templ, sizeof(struct pipe_shader_state)); - - return shader; + return 0; } static void i915_bind_fs_state( struct pipe_context *pipe, - const struct pipe_shader_state *fs ) + void *fs ) { struct i915_context *i915 = i915_context(pipe); - i915->fs = fs; + i915->fs = (struct pipe_shader_state *)fs; i915->dirty |= I915_NEW_FS; } -static void i915_bind_vs_state( struct pipe_context *pipe, - const struct pipe_shader_state *vs ) +static void i915_bind_vs_state(struct pipe_context *pipe, + void *vs) { struct i915_context *i915 = i915_context(pipe); /* just pass-through to draw module */ - draw_set_vertex_shader(i915->draw, vs); + draw_set_vertex_shader(i915->draw, (const struct pipe_shader_state *)vs); } -static void i915_delete_shader_state( struct pipe_context *pipe, - const struct pipe_shader_state *shader ) +static void i915_delete_shader_state(struct pipe_context *pipe, + void *shader) { - free((struct pipe_shader_state*)shader); + /*do nothing*/ } static void i915_set_constant_buffer(struct pipe_context *pipe, diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 65001dfdf9..e17faad2c7 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -113,20 +113,15 @@ struct pipe_context { void (*delete_depth_stencil_state)(struct pipe_context *, const struct pipe_depth_stencil_state *); - const struct pipe_shader_state * (*create_fs_state)( - struct pipe_context *, - const struct pipe_shader_state *); - void (*bind_fs_state)(struct pipe_context *, - const struct pipe_shader_state *); - void (*delete_fs_state)(struct pipe_context *, - const struct pipe_shader_state *); - const struct pipe_shader_state * (*create_vs_state)( - struct pipe_context *, - const struct pipe_shader_state *); - void (*bind_vs_state)(struct pipe_context *, - const struct pipe_shader_state *); - void (*delete_vs_state)(struct pipe_context *, - const struct pipe_shader_state *); + void * (*create_fs_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*bind_fs_state)(struct pipe_context *, void *); + void (*delete_fs_state)(struct pipe_context *, void *); + + void * (*create_vs_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*bind_vs_state)(struct pipe_context *, void *); + void (*delete_vs_state)(struct pipe_context *, void *); void (*set_alpha_test_state)( struct pipe_context *, const struct pipe_alpha_test_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index a20ae1d4a2..5ed963c21d 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -88,15 +88,12 @@ void softpipe_set_constant_buffer(struct pipe_context *, void softpipe_set_feedback_state( struct pipe_context *, const struct pipe_feedback_state * ); -const struct pipe_shader_state * +void * softpipe_create_shader_state( struct pipe_context *, const struct pipe_shader_state * ); -void softpipe_bind_fs_state( struct pipe_context *, - const struct pipe_shader_state * ); -void softpipe_bind_vs_state( struct pipe_context *, - const struct pipe_shader_state * ); -void softpipe_delete_shader_state( struct pipe_context *, - const struct pipe_shader_state * ); +void softpipe_bind_fs_state( struct pipe_context *, void * ); +void softpipe_bind_vs_state( struct pipe_context *, void * ); +void softpipe_delete_shader_state( struct pipe_context *, void * ); void softpipe_set_polygon_stipple( struct pipe_context *, const struct pipe_poly_stipple * ); diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c index fbbde2f520..8306a95f44 100644 --- a/src/mesa/pipe/softpipe/sp_state_fs.c +++ b/src/mesa/pipe/softpipe/sp_state_fs.c @@ -33,44 +33,39 @@ #include "pipe/draw/draw_context.h" -const struct pipe_shader_state * -softpipe_create_shader_state( struct pipe_context *pipe, - const struct pipe_shader_state *templ ) +void * softpipe_create_shader_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) { - struct pipe_shader_state *shader = malloc(sizeof(struct pipe_shader_state)); - memcpy(shader, templ, sizeof(struct pipe_shader_state)); - - return shader; + /* we just want the pipe_shader_state template in the bind calls */ + return 0; } -void softpipe_bind_fs_state( struct pipe_context *pipe, - const struct pipe_shader_state *fs ) +void softpipe_bind_fs_state(struct pipe_context *pipe, void *fs) { struct softpipe_context *softpipe = softpipe_context(pipe); - softpipe->fs = fs; + softpipe->fs = (struct pipe_shader_state *)fs; softpipe->dirty |= SP_NEW_FS; } -void softpipe_bind_vs_state( struct pipe_context *pipe, - const struct pipe_shader_state *vs ) +void softpipe_bind_vs_state(struct pipe_context *pipe, void *vs) { struct softpipe_context *softpipe = softpipe_context(pipe); - softpipe->vs = vs; + softpipe->vs = (struct pipe_shader_state *)vs; softpipe->dirty |= SP_NEW_VS; - draw_set_vertex_shader(softpipe->draw, vs); + draw_set_vertex_shader(softpipe->draw, (struct pipe_shader_state *)vs); } void softpipe_delete_shader_state( struct pipe_context *pipe, - const struct pipe_shader_state *shader ) + void *shader ) { - free((struct pipe_shader_state*)shader); + /* do nothing */ } void softpipe_set_constant_buffer(struct pipe_context *pipe, diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index 94b69c8df7..91e58f5831 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -51,14 +51,14 @@ * Translate a Mesa fragment shader into a TGSI shader. * \return pointer to cached pipe_shader object. */ -struct pipe_shader_state * +const struct cso_fragment_shader * st_translate_fragment_shader(struct st_context *st, struct st_fragment_program *stfp) { GLuint outputMapping[FRAG_RESULT_MAX]; GLuint inputMapping[PIPE_MAX_SHADER_INPUTS]; struct pipe_shader_state fs; - struct pipe_shader_state *cached; + const struct cso_fragment_shader *cso; GLuint interpMode[16]; /* XXX size? */ GLuint i; GLbitfield inputsRead = stfp->Base.Base.InputsRead; @@ -142,15 +142,15 @@ st_translate_fragment_shader(struct st_context *st, fs.tokens = &stfp->tokens[0]; - cached = st_cached_fs_state(st, &fs); - stfp->fs = cached; + cso = st_cached_fs_state(st, &fs); + stfp->fs = cso; if (TGSI_DEBUG) tgsi_dump( stfp->tokens, 0/*TGSI_DUMP_VERBOSE*/ ); stfp->dirty = 0; - return cached; + return cso; } @@ -183,7 +183,7 @@ static void update_fs( struct st_context *st ) if (stfp->dirty) st->state.fs = st_translate_fragment_shader( st, st->fp ); - st->pipe->bind_fs_state(st->pipe, st->state.fs); + st->pipe->bind_fs_state(st->pipe, st->state.fs->data); } } diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index cf9dd810e9..078c052ae2 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -53,13 +53,13 @@ * Translate a Mesa vertex shader into a TGSI shader. * \return pointer to cached pipe_shader object. */ -struct pipe_shader_state * +const struct cso_vertex_shader * st_translate_vertex_shader(struct st_context *st, struct st_vertex_program *stvp) { GLuint outputMapping[PIPE_MAX_SHADER_INPUTS]; struct pipe_shader_state vs; - struct pipe_shader_state *cached; + const struct cso_vertex_shader *cso; GLuint i; memset(&vs, 0, sizeof(vs)); @@ -147,8 +147,8 @@ st_translate_vertex_shader(struct st_context *st, vs.tokens = &stvp->tokens[0]; - cached = st_cached_vs_state(st, &vs); - stvp->vs = cached; + cso = st_cached_vs_state(st, &vs); + stvp->vs = cso; if (TGSI_DEBUG) tgsi_dump( stvp->tokens, 0 ); @@ -157,13 +157,13 @@ st_translate_vertex_shader(struct st_context *st, if (stvp->sse2_program.csr == stvp->sse2_program.store) tgsi_emit_sse2( stvp->tokens, &stvp->sse2_program ); - if (!cached->executable) - cached->executable = (void *) x86_get_func( &stvp->sse2_program ); + if (!cso->state.executable) + cso->state.executable = (void *) x86_get_func( &stvp->sse2_program ); #endif stvp->dirty = 0; - return cached; + return cso; } @@ -191,10 +191,10 @@ static void update_vs( struct st_context *st ) /* Bind the vertex program */ st->vp = stvp; - if (stvp->dirty) + if (stvp->dirty) st->state.vs = st_translate_vertex_shader( st, st->vp ); - st->pipe->bind_vs_state(st->pipe, st->state.vs); + st->pipe->bind_vs_state(st->pipe, st->state.vs->data); } } diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index 0f233cea58..e5ba0592cf 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -115,9 +115,9 @@ const struct cso_rasterizer* st_cached_rasterizer_state( return (struct cso_rasterizer*)(cso_hash_iter_data(iter)); } -struct pipe_shader_state * st_cached_fs_state( - struct st_context *st, - const struct pipe_shader_state *templ) +const struct cso_fragment_shader * +st_cached_fs_state(struct st_context *st, + const struct pipe_shader_state *templ) { unsigned hash_key = cso_construct_key((void*)templ, sizeof(struct pipe_shader_state)); @@ -125,17 +125,19 @@ struct pipe_shader_state * st_cached_fs_state( hash_key, CSO_FRAGMENT_SHADER, (void*)templ); if (cso_hash_iter_is_null(iter)) { - const struct pipe_shader_state *created_state = - st->pipe->create_fs_state(st->pipe, templ); - iter = cso_insert_state(st->cache, hash_key, CSO_FRAGMENT_SHADER, - (void*)created_state); + struct cso_fragment_shader *cso = malloc(sizeof(struct cso_fragment_shader)); + memcpy(&cso->state, templ, sizeof(struct pipe_shader_state)); + cso->data = st->pipe->create_fs_state(st->pipe, templ); + if (!cso->data) + cso->data = &cso->state; + iter = cso_insert_state(st->cache, hash_key, CSO_FRAGMENT_SHADER, cso); } - return (struct pipe_shader_state*)(cso_hash_iter_data(iter)); + return (struct cso_fragment_shader*)(cso_hash_iter_data(iter)); } -struct pipe_shader_state * st_cached_vs_state( - struct st_context *st, - const struct pipe_shader_state *templ) +const struct cso_vertex_shader * +st_cached_vs_state(struct st_context *st, + const struct pipe_shader_state *templ) { unsigned hash_key = cso_construct_key((void*)templ, sizeof(struct pipe_shader_state)); @@ -143,10 +145,12 @@ struct pipe_shader_state * st_cached_vs_state( hash_key, CSO_VERTEX_SHADER, (void*)templ); if (cso_hash_iter_is_null(iter)) { - const struct pipe_shader_state *created_state = - st->pipe->create_vs_state(st->pipe, templ); - iter = cso_insert_state(st->cache, hash_key, CSO_VERTEX_SHADER, - (void*)created_state); + struct cso_vertex_shader *cso = malloc(sizeof(struct cso_vertex_shader)); + memcpy(&cso->state, templ, sizeof(struct pipe_shader_state)); + cso->data = st->pipe->create_vs_state(st->pipe, templ); + if (!cso->data) + cso->data = &cso->state; + iter = cso_insert_state(st->cache, hash_key, CSO_VERTEX_SHADER, cso); } - return (struct pipe_shader_state*)(cso_hash_iter_data(iter)); + return (struct cso_vertex_shader*)(cso_hash_iter_data(iter)); } diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index 5b8c6168a8..356dd98183 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -55,13 +55,13 @@ const struct cso_rasterizer * st_cached_rasterizer_state(struct st_context *st, const struct pipe_rasterizer_state *raster); -struct pipe_shader_state *st_cached_fs_state( - struct st_context *st, - const struct pipe_shader_state *templ); +const struct cso_fragment_shader * +st_cached_fs_state(struct st_context *st, + const struct pipe_shader_state *templ); -struct pipe_shader_state *st_cached_vs_state( - struct st_context *st, - const struct pipe_shader_state *templ); +const struct cso_vertex_shader * +st_cached_vs_state(struct st_context *st, + const struct pipe_shader_state *templ); #endif diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index ee70ce3320..03a81652cb 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -348,7 +348,7 @@ clear_with_quad(GLcontext *ctx, if (!stfp) { stfp = make_frag_shader(st); } - pipe->bind_fs_state(pipe, stfp->fs); + pipe->bind_fs_state(pipe, stfp->fs->data); } /* vertex shader state: color/position pass-through */ @@ -357,7 +357,7 @@ clear_with_quad(GLcontext *ctx, if (!stvp) { stvp = make_vertex_shader(st); } - pipe->bind_vs_state(pipe, stvp->vs); + pipe->bind_vs_state(pipe, stvp->vs->data); } /* viewport state: viewport matching window dims */ @@ -383,8 +383,8 @@ clear_with_quad(GLcontext *ctx, pipe->set_alpha_test_state(pipe, &st->state.alpha_test); pipe->bind_blend_state(pipe, st->state.blend->data); pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil); - pipe->bind_fs_state(pipe, st->state.fs); - pipe->bind_vs_state(pipe, st->state.vs); + pipe->bind_fs_state(pipe, st->state.fs->data); + pipe->bind_vs_state(pipe, st->state.vs->data); pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); /* OR: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index d4f260ee54..4e3c24353e 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -330,7 +330,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, if (!stfp) { stfp = make_fragment_shader(ctx->st); } - pipe->bind_fs_state(pipe, stfp->fs); + pipe->bind_fs_state(pipe, stfp->fs->data); } /* vertex shader state: position + texcoord pass-through */ @@ -339,7 +339,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, if (!stvp) { stvp = make_vertex_shader(ctx->st); } - pipe->bind_vs_state(pipe, stvp->vs); + pipe->bind_vs_state(pipe, stvp->vs->data); } /* texture sampling state: */ @@ -393,8 +393,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* restore GL state */ pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer->data); - pipe->bind_fs_state(pipe, ctx->st->state.fs); - pipe->bind_vs_state(pipe, ctx->st->state.vs); + pipe->bind_fs_state(pipe, ctx->st->state.fs->data); + pipe->bind_vs_state(pipe, ctx->st->state.vs->data); pipe->set_texture_state(pipe, unit, ctx->st->state.texture[unit]); pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 5245535a65..04b2016ffc 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -35,6 +35,7 @@ #include "st_context.h" #include "st_atom.h" +#include "st_cache.h" #include "st_draw.h" #include "st_program.h" #include "st_cb_rasterpos.h" @@ -88,7 +89,7 @@ static void setup_feedback(GLcontext *ctx) { struct pipe_context *pipe = ctx->st->pipe; - const struct pipe_shader_state *vs = ctx->st->state.vs; + const struct pipe_shader_state *vs = &ctx->st->state.vs->state; struct pipe_feedback_state feedback; uint i; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 93b6425480..df976260f8 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -79,8 +79,8 @@ struct st_context const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; const struct cso_rasterizer *rasterizer; - const struct pipe_shader_state *fs; - const struct pipe_shader_state *vs; + const struct cso_fragment_shader *fs; + const struct cso_vertex_shader *vs; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 238ade00ac..633e4d9470 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -198,7 +198,7 @@ st_draw_vbo(GLcontext *ctx, /* must get these after state validation! */ vp = ctx->st->vp; - vs = ctx->st->state.vs; + vs = &ctx->st->state.vs->state; /* loop over TGSI shader inputs */ for (attr = 0; attr < vs->num_inputs; attr++) { @@ -405,8 +405,8 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(draw); draw_set_viewport_state(draw, &st->state.viewport); draw_set_clip_state(draw, &st->state.clip); - draw_set_rasterizer_state(draw, st->state.rasterizer->data); - draw_set_vertex_shader(draw, st->state.vs); + draw_set_rasterizer_state(draw, &st->state.rasterizer->state); + draw_set_vertex_shader(draw, &st->state.vs->state); /* XXX need to set vertex info too */ diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 4945141d15..4f9ace3e6a 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -40,6 +40,8 @@ #define ST_FP_MAX_TOKENS 1024 +struct cso_fragment_shader; +struct cso_vertex_shader; struct st_fragment_program { @@ -52,7 +54,7 @@ struct st_fragment_program GLboolean dirty; /** Pointer to the corresponding cached shader */ - const struct pipe_shader_state *fs; + const struct cso_fragment_shader *fs; GLuint param_state; }; @@ -83,7 +85,7 @@ struct st_vertex_program #endif /** Pointer to the corresponding cached shader */ - const struct pipe_shader_state *vs; + const struct cso_vertex_shader *vs; GLuint param_state; }; @@ -105,12 +107,12 @@ st_vertex_program( struct gl_vertex_program *vp ) } -extern struct pipe_shader_state * +extern const struct cso_fragment_shader * st_translate_fragment_shader(struct st_context *st, struct st_fragment_program *fp); -extern struct pipe_shader_state * +extern const struct cso_vertex_shader * st_translate_vertex_shader(struct st_context *st, struct st_vertex_program *vp); -- cgit v1.2.3 From a6c0c5532f7bfa50ae54c36cf4d74ad4b9f926f8 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Thu, 20 Sep 2007 08:35:10 -0400 Subject: Convert depth_stencil state to the new semantics. --- src/mesa/pipe/cso_cache/cso_cache.h | 5 +++++ src/mesa/pipe/failover/fo_context.h | 2 +- src/mesa/pipe/failover/fo_state.c | 35 ++++++++++++++++++++++++++++--- src/mesa/pipe/failover/fo_state_emit.c | 3 ++- src/mesa/pipe/i915simple/i915_state.c | 16 ++++++-------- src/mesa/pipe/p_context.h | 11 ++++------ src/mesa/pipe/softpipe/sp_state.h | 14 +++++-------- src/mesa/pipe/softpipe/sp_state_blend.c | 16 ++++++-------- src/mesa/state_tracker/st_atom_depth.c | 10 ++++----- src/mesa/state_tracker/st_cache.c | 23 +++++++++++--------- src/mesa/state_tracker/st_cache.h | 6 +++--- src/mesa/state_tracker/st_cb_clear.c | 9 ++++---- src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_context.h | 2 +- 14 files changed, 88 insertions(+), 66 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/cso_cache/cso_cache.h b/src/mesa/pipe/cso_cache/cso_cache.h index 57d162b2ac..291759d5d1 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.h +++ b/src/mesa/pipe/cso_cache/cso_cache.h @@ -53,6 +53,11 @@ struct cso_blend { void *data; }; +struct cso_depth_stencil { + struct pipe_depth_stencil_state state; + void *data; +}; + struct cso_rasterizer { struct pipe_rasterizer_state state; void *data; diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index a81bfe82dd..7371ad4392 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -72,7 +72,7 @@ struct failover_context { */ const struct fo_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; - const struct pipe_depth_stencil_state *depth_stencil; + const struct fo_state *depth_stencil; const struct fo_state *rasterizer; const struct fo_state *fragment_shader; const struct fo_state *vertex_shader; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index db3aea7756..3379f45355 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -128,17 +128,44 @@ failover_set_clear_color_state( struct pipe_context *pipe, failover->hw->set_clear_color_state( failover->hw, clear_color ); } +static void * +failover_create_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_state *templ) +{ + struct fo_state *state = malloc(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_depth_stencil_state(pipe, templ); + state->hw_state = failover->hw->create_depth_stencil_state(pipe, templ); + + return state; +} + static void failover_bind_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_state *depth_stencil) + void *depth_stencil) { struct failover_context *failover = failover_context(pipe); - failover->depth_stencil = depth_stencil; + failover->depth_stencil = (struct fo_state *)depth_stencil; failover->dirty |= FO_NEW_DEPTH_STENCIL; failover->hw->bind_depth_stencil_state( failover->hw, depth_stencil ); } +static void +failover_delete_depth_stencil_state(struct pipe_context *pipe, + void *ds) +{ + struct fo_state *state = (struct fo_state*)ds; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_depth_stencil_state(pipe, state->sw_state); + failover->hw->delete_depth_stencil_state(pipe, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + free(state); +} + static void failover_set_framebuffer_state(struct pipe_context *pipe, const struct pipe_framebuffer_state *framebuffer) @@ -363,7 +390,9 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.bind_blend_state = failover_bind_blend_state; failover->pipe.delete_blend_state = failover_delete_blend_state; failover->pipe.bind_sampler_state = failover_bind_sampler_state; - failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state; + failover->pipe.create_depth_stencil_state = failover_create_depth_stencil_state; + failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state; + failover->pipe.delete_depth_stencil_state = failover_delete_depth_stencil_state; failover->pipe.create_rasterizer_state = failover_create_rasterizer_state; failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state; failover->pipe.delete_rasterizer_state = failover_delete_rasterizer_state; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index ec896fd020..da12b4e25c 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -72,7 +72,8 @@ failover_state_emit( struct failover_context *failover ) failover->sw->set_clear_color_state( failover->sw, &failover->clear_color ); if (failover->dirty & FO_NEW_DEPTH_STENCIL) - failover->sw->bind_depth_stencil_state( failover->sw, failover->depth_stencil ); + failover->sw->bind_depth_stencil_state( failover->sw, + failover->depth_stencil->sw_state ); if (failover->dirty & FO_NEW_FRAMEBUFFER) failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer ); diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 1104c9519d..be549ed6fd 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -175,31 +175,27 @@ static void i915_delete_sampler_state(struct pipe_context *pipe, * into one file. */ -static const struct pipe_depth_stencil_state * +static void * i915_create_depth_stencil_state(struct pipe_context *pipe, const struct pipe_depth_stencil_state *depth_stencil) { - struct pipe_depth_stencil_state *new_ds = - malloc(sizeof(struct pipe_depth_stencil_state)); - memcpy(new_ds, depth_stencil, sizeof(struct pipe_depth_stencil_state)); - - return new_ds; + return 0; } static void i915_bind_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_state *depth_stencil) + void *depth_stencil) { struct i915_context *i915 = i915_context(pipe); - i915->depth_stencil = depth_stencil; + i915->depth_stencil = (const struct pipe_depth_stencil_state *)depth_stencil; i915->dirty |= I915_NEW_DEPTH_STENCIL; } static void i915_delete_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_state *depth_stencil) + void *depth_stencil) { - free((struct pipe_depth_stencil_state *)depth_stencil); + /* do nothing */ } static void i915_set_alpha_test_state(struct pipe_context *pipe, diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index e17faad2c7..84aca20c58 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -105,13 +105,10 @@ struct pipe_context { void (*bind_rasterizer_state)(struct pipe_context *, void *); void (*delete_rasterizer_state)(struct pipe_context *, void *); - const struct pipe_depth_stencil_state * (*create_depth_stencil_state)( - struct pipe_context *, - const struct pipe_depth_stencil_state *); - void (*bind_depth_stencil_state)(struct pipe_context *, - const struct pipe_depth_stencil_state *); - void (*delete_depth_stencil_state)(struct pipe_context *, - const struct pipe_depth_stencil_state *); + void * (*create_depth_stencil_state)(struct pipe_context *, + const struct pipe_depth_stencil_state *); + void (*bind_depth_stencil_state)(struct pipe_context *, void *); + void (*delete_depth_stencil_state)(struct pipe_context *, void *); void * (*create_fs_state)(struct pipe_context *, const struct pipe_shader_state *); diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 5ed963c21d..08dfe208fb 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -50,21 +50,17 @@ void softpipe_bind_sampler_state(struct pipe_context *, void softpipe_delete_sampler_state(struct pipe_context *, const struct pipe_sampler_state *); -const struct pipe_depth_stencil_state * +void * softpipe_create_depth_stencil_state(struct pipe_context *, const struct pipe_depth_stencil_state *); -void softpipe_bind_depth_stencil_state(struct pipe_context *, - const struct pipe_depth_stencil_state *); -void softpipe_delete_depth_stencil_state(struct pipe_context *, - const struct pipe_depth_stencil_state *); +void softpipe_bind_depth_stencil_state(struct pipe_context *, void *); +void softpipe_delete_depth_stencil_state(struct pipe_context *, void *); void * softpipe_create_rasterizer_state(struct pipe_context *, const struct pipe_rasterizer_state *); -void softpipe_bind_rasterizer_state(struct pipe_context *, - void *); -void softpipe_delete_rasterizer_state(struct pipe_context *, - void *); +void softpipe_bind_rasterizer_state(struct pipe_context *, void *); +void softpipe_delete_rasterizer_state(struct pipe_context *, void *); void softpipe_set_framebuffer_state( struct pipe_context *, const struct pipe_framebuffer_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_blend.c b/src/mesa/pipe/softpipe/sp_state_blend.c index 7fb47e7aab..cf47607955 100644 --- a/src/mesa/pipe/softpipe/sp_state_blend.c +++ b/src/mesa/pipe/softpipe/sp_state_blend.c @@ -82,30 +82,26 @@ softpipe_set_alpha_test_state(struct pipe_context *pipe, softpipe->dirty |= SP_NEW_ALPHA_TEST; } -const struct pipe_depth_stencil_state * +void * softpipe_create_depth_stencil_state(struct pipe_context *pipe, const struct pipe_depth_stencil_state *depth_stencil) { - struct pipe_depth_stencil_state *new_ds = malloc(sizeof(struct pipe_depth_stencil_state)); - memcpy(new_ds, depth_stencil, sizeof(struct pipe_depth_stencil_state)); - - return new_ds; + return 0; } void softpipe_bind_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_state *depth_stencil) + void *depth_stencil) { struct softpipe_context *softpipe = softpipe_context(pipe); - softpipe->depth_stencil = depth_stencil; + softpipe->depth_stencil = (const struct pipe_depth_stencil_state *)depth_stencil; softpipe->dirty |= SP_NEW_DEPTH_STENCIL; } void -softpipe_delete_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_state *depth) +softpipe_delete_depth_stencil_state(struct pipe_context *pipe, void *depth) { - free((struct pipe_depth_stencil_state*)depth); + /* do nothing */ } diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index 406773213d..caf51f17ac 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -115,6 +115,7 @@ static void update_depth_stencil(struct st_context *st) { struct pipe_depth_stencil_state depth_stencil; + const struct cso_depth_stencil *cso; memset(&depth_stencil, 0, sizeof(depth_stencil)); @@ -149,12 +150,11 @@ update_depth_stencil(struct st_context *st) depth_stencil.stencil.clear_value = st->ctx->Stencil.Clear & 0xff; } - struct pipe_depth_stencil_state *cached_state = - st_cached_depth_stencil_state(st, &depth_stencil); - if (st->state.depth_stencil != cached_state) { + cso = st_cached_depth_stencil_state(st, &depth_stencil); + if (st->state.depth_stencil != cso) { /* state has changed */ - st->state.depth_stencil = cached_state; - st->pipe->bind_depth_stencil_state(st->pipe, cached_state); /* set new state */ + st->state.depth_stencil = cso; + st->pipe->bind_depth_stencil_state(st->pipe, cso->data); /* bind new state */ } } diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index e5ba0592cf..c1ec130b32 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -78,21 +78,24 @@ struct pipe_sampler_state * st_cached_sampler_state( return (struct pipe_sampler_state*)(cso_hash_iter_data(iter)); } -struct pipe_depth_stencil_state * st_cached_depth_stencil_state( - struct st_context *st, - const struct pipe_depth_stencil_state *depth_stencil) +const struct cso_depth_stencil * +st_cached_depth_stencil_state(struct st_context *st, + const struct pipe_depth_stencil_state *templ) { - unsigned hash_key = cso_construct_key((void*)depth_stencil, sizeof(struct pipe_depth_stencil_state)); + unsigned hash_key = cso_construct_key((void*)templ, + sizeof(struct pipe_depth_stencil_state)); struct cso_hash_iter iter = cso_find_state_template(st->cache, hash_key, CSO_DEPTH_STENCIL, - (void*)depth_stencil); + (void*)templ); if (cso_hash_iter_is_null(iter)) { - const struct pipe_depth_stencil_state *created_state = st->pipe->create_depth_stencil_state( - st->pipe, depth_stencil); - iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL, - (void*)created_state); + struct cso_depth_stencil *cso = malloc(sizeof(struct cso_depth_stencil)); + memcpy(&cso->state, templ, sizeof(struct pipe_depth_stencil_state)); + cso->data = st->pipe->create_depth_stencil_state(st->pipe, templ); + if (!cso->data) + cso->data = &cso->state; + iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL, cso); } - return (struct pipe_depth_stencil_state*)(cso_hash_iter_data(iter)); + return (struct cso_depth_stencil*)(cso_hash_iter_data(iter)); } const struct cso_rasterizer* st_cached_rasterizer_state( diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index 356dd98183..167d9ec11a 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -47,9 +47,9 @@ struct pipe_sampler_state * st_cached_sampler_state(struct st_context *st, const struct pipe_sampler_state *sampler); -struct pipe_depth_stencil_state *st_cached_depth_stencil_state( - struct st_context *st, - const struct pipe_depth_stencil_state *depth_stencil); +const struct cso_depth_stencil * +st_cached_depth_stencil_state(struct st_context *st, + const struct pipe_depth_stencil_state *depth_stencil); const struct cso_rasterizer * st_cached_rasterizer_state(struct st_context *st, diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 03a81652cb..bfc977daa4 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -303,7 +303,7 @@ clear_with_quad(GLcontext *ctx, /* depth_stencil state: always pass/set to ref value */ { struct pipe_depth_stencil_state depth_stencil; - struct pipe_depth_stencil_state *cached; + const struct cso_depth_stencil *cso; memset(&depth_stencil, 0, sizeof(depth_stencil)); if (depth) { depth_stencil.depth.enabled = 1; @@ -321,9 +321,8 @@ clear_with_quad(GLcontext *ctx, depth_stencil.stencil.value_mask[0] = 0xff; depth_stencil.stencil.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; } - cached = - st_cached_depth_stencil_state(ctx->st, &depth_stencil); - pipe->bind_depth_stencil_state(pipe, cached); + cso = st_cached_depth_stencil_state(ctx->st, &depth_stencil); + pipe->bind_depth_stencil_state(pipe, cso->data); } /* setup state: nothing */ @@ -382,7 +381,7 @@ clear_with_quad(GLcontext *ctx, /* Restore pipe state */ pipe->set_alpha_test_state(pipe, &st->state.alpha_test); pipe->bind_blend_state(pipe, st->state.blend->data); - pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil); + pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil->data); pipe->bind_fs_state(pipe, st->state.fs->data); pipe->bind_vs_state(pipe, st->state.vs->data); pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 4e3c24353e..95810b7baf 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -470,7 +470,7 @@ any_fragment_ops(const struct st_context *st) if (st->state.alpha_test.enabled || st->state.blend->state.blend_enable || st->state.blend->state.logicop_enable || - st->state.depth_stencil->depth.enabled) + st->state.depth_stencil->state.depth.enabled) /* XXX more checks */ return GL_TRUE; else diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index df976260f8..b82cf24273 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -77,7 +77,7 @@ struct st_context struct { const struct cso_blend *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; - const struct pipe_depth_stencil_state *depth_stencil; + const struct cso_depth_stencil *depth_stencil; const struct cso_rasterizer *rasterizer; const struct cso_fragment_shader *fs; const struct cso_vertex_shader *vs; -- cgit v1.2.3 From 086734502a614e7778533018846ee66a66df9821 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 20 Sep 2007 13:42:37 -0600 Subject: Checkpoint: vertex attribute clean-up. Remove/disable the attrib/slot mapping arrays in a few places. Work in progress... --- src/mesa/pipe/draw/draw_clip.c | 2 ++ src/mesa/pipe/draw/draw_feedback.c | 3 ++- src/mesa/pipe/draw/draw_private.h | 2 +- src/mesa/pipe/draw/draw_vertex.c | 19 +++++++------------ src/mesa/pipe/draw/draw_vertex.h | 16 ++++++++-------- src/mesa/pipe/draw/draw_vertex_fetch.c | 5 +++++ src/mesa/pipe/i915simple/i915_state_derived.c | 2 +- src/mesa/pipe/softpipe/sp_context.h | 1 + src/mesa/pipe/softpipe/sp_prim_setup.c | 11 ++++------- src/mesa/pipe/softpipe/sp_state_derived.c | 7 +++++-- src/mesa/state_tracker/st_atom_vs.c | 23 ++++++++++++----------- src/mesa/state_tracker/st_cb_clear.c | 2 +- src/mesa/state_tracker/st_cb_feedback.c | 10 ++++++++-- src/mesa/state_tracker/st_context.h | 12 ++++++++++-- src/mesa/state_tracker/st_program.h | 5 ----- 15 files changed, 67 insertions(+), 53 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/draw/draw_clip.c b/src/mesa/pipe/draw/draw_clip.c index 1396b60f45..e2af69e048 100644 --- a/src/mesa/pipe/draw/draw_clip.c +++ b/src/mesa/pipe/draw/draw_clip.c @@ -382,8 +382,10 @@ static void clip_begin( struct draw_stage *stage ) { /* sanity checks. If these fail, review the clip/interp code! */ assert(stage->draw->vertex_info.num_attribs >= 3); +#if 0 assert(stage->draw->vertex_info.slot_to_attrib[0] == TGSI_ATTRIB_VERTEX_HEADER); assert(stage->draw->vertex_info.slot_to_attrib[1] == TGSI_ATTRIB_CLIP_POS); +#endif stage->next->begin( stage->next ); } diff --git a/src/mesa/pipe/draw/draw_feedback.c b/src/mesa/pipe/draw/draw_feedback.c index ecdd98e83d..3b8400233e 100644 --- a/src/mesa/pipe/draw/draw_feedback.c +++ b/src/mesa/pipe/draw/draw_feedback.c @@ -78,7 +78,7 @@ feedback_vertex(struct draw_stage *stage, const struct vertex_header *vertex) * we can either address output buffer 0 (for interleaving) or * output buffer i (for non-interleaved). */ - +#if 0 for (i = 0; i < feedback->num_attribs; i++) { const uint attr = feedback->attrib[i]; const uint slot = stage->draw->vertex_info.attrib_to_slot[attr]; @@ -104,6 +104,7 @@ feedback_vertex(struct draw_stage *stage, const struct vertex_header *vertex) } fs->dest[i * select] += size; } +#endif fs->num_vert_emitted++; } diff --git a/src/mesa/pipe/draw/draw_private.h b/src/mesa/pipe/draw/draw_private.h index bd8c11eb94..1285f3200c 100644 --- a/src/mesa/pipe/draw/draw_private.h +++ b/src/mesa/pipe/draw/draw_private.h @@ -62,7 +62,7 @@ struct vertex_header { }; /* XXX This is too large */ -#define MAX_VERTEX_SIZE ((2 + TGSI_ATTRIB_MAX) * 4 * sizeof(float)) +#define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float)) diff --git a/src/mesa/pipe/draw/draw_vertex.c b/src/mesa/pipe/draw/draw_vertex.c index 1c7e1d8662..ab4e6c7864 100644 --- a/src/mesa/pipe/draw/draw_vertex.c +++ b/src/mesa/pipe/draw/draw_vertex.c @@ -45,17 +45,10 @@ static INLINE void -emit_vertex_attr(struct vertex_info *vinfo, uint vfAttr, +emit_vertex_attr(struct vertex_info *vinfo, /*uint vfAttr,*/ attrib_format format, interp_mode interp) { const uint n = vinfo->num_attribs; - vinfo->attr_mask |= (1 << vfAttr); - vinfo->slot_to_attrib[n] = vfAttr; - if (n >= 2) { - /* the first two slots are the vertex header & clippos */ - assert(vfAttr < Elements(vinfo->attrib_to_slot)); - vinfo->attrib_to_slot[vfAttr] = n - 2; - } vinfo->interp_mode[n] = interp; vinfo->format[n] = format; vinfo->num_attribs++; @@ -110,22 +103,24 @@ draw_set_vertex_attributes( struct draw_context *draw, struct vertex_info *vinfo = &draw->vertex_info; unsigned i; +#if 0 assert(slot_to_vf_attr[0] == TGSI_ATTRIB_POS); +#endif memset(vinfo, 0, sizeof(*vinfo)); /* * First three attribs are always the same: header, clip pos, winpos */ - emit_vertex_attr(vinfo, TGSI_ATTRIB_VERTEX_HEADER, FORMAT_1F, INTERP_NONE); - emit_vertex_attr(vinfo, TGSI_ATTRIB_CLIP_POS, FORMAT_4F, INTERP_LINEAR); - emit_vertex_attr(vinfo, TGSI_ATTRIB_POS, FORMAT_4F_VIEWPORT, INTERP_LINEAR); + emit_vertex_attr(vinfo, /*TGSI_ATTRIB_VERTEX_HEADER,*/ FORMAT_1F, INTERP_NONE); + emit_vertex_attr(vinfo, /*TGSI_ATTRIB_CLIP_POS,*/ FORMAT_4F, INTERP_LINEAR); + emit_vertex_attr(vinfo, /*TGSI_ATTRIB_POS,*/ FORMAT_4F_VIEWPORT, INTERP_LINEAR); /* * Remaining attribs (color, texcoords, etc) */ for (i = 1; i < nr_attrs; i++) { - emit_vertex_attr(vinfo, slot_to_vf_attr[i], FORMAT_4F, interps[i]); + emit_vertex_attr(vinfo, /*slot_to_vf_attr[i],*/ FORMAT_4F, interps[i]); } draw_compute_vertex_size(vinfo); diff --git a/src/mesa/pipe/draw/draw_vertex.h b/src/mesa/pipe/draw/draw_vertex.h index 4e3e86d86e..1d900b3a4e 100644 --- a/src/mesa/pipe/draw/draw_vertex.h +++ b/src/mesa/pipe/draw/draw_vertex.h @@ -68,16 +68,15 @@ typedef enum { } interp_mode; - +/** + * Information about post-transformed vertex layout. + */ struct vertex_info { uint num_attribs; uint hwfmt[4]; /**< hardware format info for this format */ - uint attr_mask; /**< mask of VF_ATTR_ bits */ - uint slot_to_attrib[MAX_VERT_ATTRIBS]; - uint attrib_to_slot[TGSI_ATTRIB_MAX]; - interp_mode interp_mode[MAX_VERT_ATTRIBS]; - attrib_format format[MAX_VERT_ATTRIBS]; /**< FORMAT_x */ + interp_mode interp_mode[PIPE_MAX_SHADER_OUTPUTS]; + attrib_format format[PIPE_MAX_SHADER_OUTPUTS]; /**< FORMAT_x */ uint size; /**< total vertex size in dwords */ }; @@ -92,9 +91,10 @@ draw_emit_vertex_attr(struct vertex_info *vinfo, uint vfAttr, attrib_format format, interp_mode interp) { const uint n = vinfo->num_attribs; - assert(n < MAX_VERT_ATTRIBS); + assert(n < PIPE_MAX_SHADER_OUTPUTS); + /* vinfo->attr_mask |= (1 << vfAttr); - vinfo->slot_to_attrib[n] = vfAttr; + */ vinfo->format[n] = format; vinfo->interp_mode[n] = interp; vinfo->num_attribs++; diff --git a/src/mesa/pipe/draw/draw_vertex_fetch.c b/src/mesa/pipe/draw/draw_vertex_fetch.c index ce402d681f..62e8d61be4 100644 --- a/src/mesa/pipe/draw/draw_vertex_fetch.c +++ b/src/mesa/pipe/draw/draw_vertex_fetch.c @@ -81,6 +81,9 @@ void draw_vertex_fetch( struct draw_context *draw, /* loop over vertices */ for (j = 0; j < count; j++) { uint attr; + + /*printf("fetch vertex %u: \n", j);*/ + /* loop over vertex attributes (vertex shader inputs) */ for (attr = 0; attr < draw->vertex_shader.num_inputs; attr++) { @@ -94,6 +97,8 @@ void draw_vertex_fetch( struct draw_context *draw, fetch_attrib4(src, draw->vertex_element[attr].src_format, p); + /*printf(" %u: %f %f %f %f\n", attr, p[0], p[1], p[2], p[3]);*/ + machine->Inputs[attr].xyzw[0].f[j] = p[0]; /*X*/ machine->Inputs[attr].xyzw[1].f[j] = p[1]; /*Y*/ machine->Inputs[attr].xyzw[2].f[j] = p[2]; /*Z*/ diff --git a/src/mesa/pipe/i915simple/i915_state_derived.c b/src/mesa/pipe/i915simple/i915_state_derived.c index 572d270f39..91d00fb1c2 100644 --- a/src/mesa/pipe/i915simple/i915_state_derived.c +++ b/src/mesa/pipe/i915simple/i915_state_derived.c @@ -173,7 +173,7 @@ static void calculate_vertex_layout( struct i915_context *i915 ) * vertex layout. We'll also update the hardware vertex format info. */ draw_set_vertex_attributes( i915->draw, - vinfo->slot_to_attrib, + NULL,/*vinfo->slot_to_attrib,*/ vinfo->interp_mode, vinfo->num_attribs); diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 5c17c47b12..95215eb640 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -111,6 +111,7 @@ struct softpipe_context { unsigned nr_frag_attrs; /**< number of active fragment attribs */ boolean need_z; /**< produce quad/fragment Z values? */ boolean need_w; /**< produce quad/fragment W values? */ + int psize_slot; /** Feedback buffers */ struct pipe_feedback_buffer feedback_buffer[PIPE_MAX_FEEDBACK_ATTRIBS]; diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index 8a4be79d11..913ae44601 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -79,8 +79,6 @@ struct setup_stage { float oneoverarea; - const unsigned *lookup; /**< vertex attribute positions */ - struct tgsi_interp_coef coef[TGSI_ATTRIB_MAX]; struct quad_header quad; @@ -249,7 +247,7 @@ static void print_vertex(const struct setup_stage *setup, { int i; printf("Vertex:\n"); - for (i = 0; i < setup->softpipe->nr_attrs; i++) { + for (i = 0; i < setup->quad.nr_attrs; i++) { printf(" %d: %f %f %f\n", i, v->data[i][0], v->data[i][1], v->data[i][2]); } @@ -907,8 +905,7 @@ setup_point(struct draw_stage *stage, struct prim_header *prim) { struct setup_stage *setup = setup_stage( stage ); const struct vertex_header *v0 = prim->v[0]; - - const int sizeAttr = setup->lookup[TGSI_ATTRIB_POINTSIZE]; + const int sizeAttr = setup->softpipe->psize_slot; const float halfSize = sizeAttr ? (0.5f * v0->data[sizeAttr][0]) : (0.5f * setup->softpipe->rasterizer->point_size); @@ -917,6 +914,8 @@ setup_point(struct draw_stage *stage, struct prim_header *prim) const float y = v0->data[TGSI_ATTRIB_POS][1]; unsigned slot, j; + assert(sizeAttr >= 0); + /* For points, all interpolants are constant-valued. * However, for point sprites, we'll need to setup texcoords appropriately. * XXX: which coefficients are the texcoords??? @@ -1097,7 +1096,5 @@ struct draw_stage *sp_draw_render_stage( struct softpipe_context *softpipe ) setup->quad.coef = setup->coef; - setup->lookup = softpipe->draw->vertex_info.attrib_to_slot; - return &setup->stage; } diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index 0dd0eea0b8..03b5d7ea3f 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -59,6 +59,8 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) softpipe->need_z = FALSE; softpipe->need_w = FALSE; + softpipe->psize_slot = -1; + /* always emit vertex pos */ /* TODO - Figure out if we need to do perspective divide, etc. */ draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_POS, FORMAT_4F, INTERP_LINEAR); @@ -93,6 +95,7 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) FORMAT_4F, INTERP_CONSTANT); break; #endif + softpipe->psize_slot = i; /*case TGSI_SEMANTIC_TEXCOORD:*/ case TGSI_SEMANTIC_TEX0: draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_TEX0, @@ -131,10 +134,10 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) */ /* XXX we also need to do this when the shading mode (interp modes) change: */ if (1/*vinfo->attr_mask != softpipe->attr_mask*/) { - softpipe->attr_mask = vinfo->attr_mask; + /*softpipe->attr_mask = vinfo->attr_mask;*/ draw_set_vertex_attributes( softpipe->draw, - vinfo->slot_to_attrib, + NULL,/*vinfo->slot_to_attrib,*/ vinfo->interp_mode, vinfo->num_attribs); diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index 9c2994fddf..2b8aef5c63 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -57,7 +57,6 @@ const struct cso_vertex_shader * st_translate_vertex_shader(struct st_context *st, struct st_vertex_program *stvp) { - GLuint outputMapping[PIPE_MAX_SHADER_INPUTS]; struct pipe_shader_state vs; const struct cso_vertex_shader *cso; GLuint i; @@ -83,6 +82,9 @@ st_translate_vertex_shader(struct st_context *st, case VERT_ATTRIB_COLOR1: vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR1; break; + case VERT_ATTRIB_TEX0: + vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_TEX0; + break; default: vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_OTHER; } @@ -95,11 +97,8 @@ st_translate_vertex_shader(struct st_context *st, */ for (i = 0; i < VERT_RESULT_MAX; i++) { if (stvp->Base.Base.OutputsWritten & (1 << i)) { -#if 0 - stvp->output_to_index[i] = vs.num_outputs; - stvp->index_to_output[vs.num_outputs] = i; -#endif - outputMapping[i] = vs.num_outputs; + /* put this attrib in the next available slot */ + st->vertex_attrib_to_slot[i] = vs.num_outputs; switch (i) { case VERT_RESULT_HPOS: @@ -129,11 +128,7 @@ st_translate_vertex_shader(struct st_context *st, */ tgsi_mesa_compile_vp_program( &stvp->Base, stvp->input_to_index, -#if 0 - stvp->output_to_index, -#else - outputMapping, -#endif + st->vertex_attrib_to_slot, stvp->tokens, ST_FP_MAX_TOKENS ); #if 0 @@ -195,6 +190,12 @@ static void update_vs( struct st_context *st ) st->vp = stvp; st->state.vs = stvp->vs; +#if 0 + printf("###### bind vp tokens: %p %p num_inp=%u\n", + stvp, stvp->tokens, stvp->vs->state.num_inputs); + if (TGSI_DEBUG) + tgsi_dump( stvp->tokens, 0 ); +#endif st->pipe->bind_vs_state(st->pipe, st->state.vs->data); } } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index bfc977daa4..5e63205088 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -491,7 +491,7 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) assert(strb->surface->format); -#if 01 +#if 0 if (ctx->Scissor.Enabled || (isDS && ctx->DrawBuffer->Visual.stencilBits > 0)) { /* scissoring or we have a combined depth/stencil buffer */ diff --git a/src/mesa/state_tracker/st_cb_feedback.c b/src/mesa/state_tracker/st_cb_feedback.c index 8e8084fe59..e846463c4c 100644 --- a/src/mesa/state_tracker/st_cb_feedback.c +++ b/src/mesa/state_tracker/st_cb_feedback.c @@ -87,6 +87,7 @@ static void feedback_vertex(GLcontext *ctx, const struct draw_context *draw, const struct vertex_header *v) { + const struct st_context *st = ctx->st; GLfloat win[4]; const GLfloat *color, *texcoord; const GLfloat ci = 0; @@ -97,13 +98,18 @@ feedback_vertex(GLcontext *ctx, const struct draw_context *draw, win[2] = v->data[0][2]; win[3] = 1.0F / v->data[0][3]; - slot = draw->vertex_info.attrib_to_slot[TGSI_ATTRIB_COLOR0]; + /* XXX + * When we compute vertex layout, save info about position of the + * color and texcoord attribs to use here. + */ + + slot = st->vertex_attrib_to_slot[VERT_RESULT_COL0]; if (slot) color = v->data[slot]; else color = ctx->Current.Attrib[VERT_ATTRIB_COLOR0]; - slot = draw->vertex_info.attrib_to_slot[TGSI_ATTRIB_TEX0]; + slot = st->vertex_attrib_to_slot[VERT_RESULT_TEX0]; if (slot) texcoord = v->data[slot]; else diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 8a57227c84..55a857f46d 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -119,9 +119,17 @@ struct st_context GLfloat polygon_offset_scale; /* ?? */ - struct st_vertex_program *vp; - struct st_fragment_program *fp; + /** Mapping from VERT_ATTRIB_x to post-transformed vertex slot */ + GLuint vertex_attrib_to_slot[VERT_RESULT_MAX]; + struct st_vertex_program *vp; /**< Currently bound vertex program */ + struct st_fragment_program *fp; /**< Currently bound fragment program */ + + /** + * Buffer object which stores the ctx->Current.Attrib[] values. + * Used for vertex array drawing when we we need an attribute for + * which there's no enabled array. + */ struct pipe_buffer_handle *default_attrib_buffer; struct cso_cache *cache; diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 4f9ace3e6a..c21e27628e 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -71,11 +71,6 @@ struct st_vertex_program /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */ GLuint index_to_input[MAX_VERTEX_PROGRAM_ATTRIBS]; -#if 0 - GLuint output_to_index[MAX_VERTEX_PROGRAM_ATTRIBS]; - GLuint index_to_output[MAX_VERTEX_PROGRAM_ATTRIBS]; -#endif - /** The program in TGSI format */ struct tgsi_token tokens[ST_FP_MAX_TOKENS]; GLboolean dirty; -- cgit v1.2.3 From 6cb87cf26f904b891faa42268f373864fa33541d Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Fri, 21 Sep 2007 07:00:20 -0400 Subject: Make the alpha test state a cso. --- src/mesa/pipe/cso_cache/cso_cache.c | 7 ++++ src/mesa/pipe/cso_cache/cso_cache.h | 13 +++++-- src/mesa/pipe/failover/fo_context.h | 4 +-- src/mesa/pipe/failover/fo_state.c | 45 +++++++++++++++++++++---- src/mesa/pipe/failover/fo_state_emit.c | 3 +- src/mesa/pipe/i915simple/i915_context.h | 2 +- src/mesa/pipe/i915simple/i915_state.c | 24 ++++++++++--- src/mesa/pipe/i915simple/i915_state_immediate.c | 6 ++-- src/mesa/pipe/p_context.h | 32 ++++++++++-------- src/mesa/pipe/softpipe/sp_context.c | 4 ++- src/mesa/pipe/softpipe/sp_context.h | 2 +- src/mesa/pipe/softpipe/sp_quad.c | 2 +- src/mesa/pipe/softpipe/sp_quad_alpha_test.c | 4 +-- src/mesa/pipe/softpipe/sp_state.h | 12 +++++-- src/mesa/pipe/softpipe/sp_state_blend.c | 20 +++++++++-- src/mesa/state_tracker/st_atom.c | 1 + src/mesa/state_tracker/st_atom.h | 1 + src/mesa/state_tracker/st_atom_alphatest.c | 15 ++++----- src/mesa/state_tracker/st_cache.c | 20 +++++++++++ src/mesa/state_tracker/st_cache.h | 4 +++ src/mesa/state_tracker/st_cb_clear.c | 6 ++-- src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_context.h | 10 +++--- 23 files changed, 176 insertions(+), 63 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/cso_cache/cso_cache.c b/src/mesa/pipe/cso_cache/cso_cache.c index 71f0d08726..0bba5914dc 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.c +++ b/src/mesa/pipe/cso_cache/cso_cache.c @@ -90,6 +90,9 @@ static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_ case CSO_VERTEX_SHADER: hash = sc->vs_hash; break; + case CSO_ALPHA_TEST: + hash = sc->alpha_hash; + break; } return hash; @@ -110,6 +113,8 @@ static int _cso_size_for_type(enum cso_cache_type type) return sizeof(struct pipe_shader_state); case CSO_VERTEX_SHADER: return sizeof(struct pipe_shader_state); + case CSO_ALPHA_TEST: + return sizeof(struct pipe_alpha_test_state); } return 0; } @@ -164,6 +169,7 @@ struct cso_cache *cso_cache_create(void) sc->rasterizer_hash = cso_hash_create(); sc->fs_hash = cso_hash_create(); sc->vs_hash = cso_hash_create(); + sc->alpha_hash = cso_hash_create(); return sc; } @@ -177,5 +183,6 @@ void cso_cache_delete(struct cso_cache *sc) cso_hash_delete(sc->rasterizer_hash); cso_hash_delete(sc->fs_hash); cso_hash_delete(sc->vs_hash); + cso_hash_delete(sc->alpha_hash); free(sc); } diff --git a/src/mesa/pipe/cso_cache/cso_cache.h b/src/mesa/pipe/cso_cache/cso_cache.h index 2acb58c66b..cd36dd51e9 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.h +++ b/src/mesa/pipe/cso_cache/cso_cache.h @@ -40,12 +40,13 @@ struct cso_hash; struct cso_cache { + struct cso_hash *alpha_hash; struct cso_hash *blend_hash; - struct cso_hash *sampler_hash; struct cso_hash *depth_stencil_hash; - struct cso_hash *rasterizer_hash; struct cso_hash *fs_hash; struct cso_hash *vs_hash; + struct cso_hash *rasterizer_hash; + struct cso_hash *sampler_hash; }; struct cso_blend { @@ -78,13 +79,19 @@ struct cso_sampler { void *data; }; +struct cso_alpha_test { + struct pipe_alpha_test_state state; + void *data; +}; + enum cso_cache_type { CSO_BLEND, CSO_SAMPLER, CSO_DEPTH_STENCIL, CSO_RASTERIZER, CSO_FRAGMENT_SHADER, - CSO_VERTEX_SHADER + CSO_VERTEX_SHADER, + CSO_ALPHA_TEST }; unsigned cso_construct_key(void *item, int item_size); diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index 8a2fbe2be9..7a597013ab 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -64,12 +64,13 @@ struct fo_state { void *sw_state; void *hw_state; }; -struct failover_context { +struct failover_context { struct pipe_context pipe; /**< base class */ /* The most recent drawing state as set by the driver: */ + const struct fo_state *alpha_test; const struct fo_state *blend; const struct fo_state *sampler[PIPE_MAX_SAMPLERS]; const struct fo_state *depth_stencil; @@ -77,7 +78,6 @@ struct failover_context { const struct fo_state *fragment_shader; const struct fo_state *vertex_shader; - struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index ce3f0ca635..f63137f591 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -45,15 +45,44 @@ * lower overheads. */ +static void * +failover_create_alpha_test_state(struct pipe_context *pipe, + const struct pipe_alpha_test_state *templ) +{ + struct fo_state *state = malloc(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_alpha_test_state(pipe, templ); + state->hw_state = failover->hw->create_alpha_test_state(pipe, templ); + + return state; +} + static void -failover_set_alpha_test_state(struct pipe_context *pipe, - const struct pipe_alpha_test_state *alpha) +failover_bind_alpha_test_state(struct pipe_context *pipe, + void *alpha) { struct failover_context *failover = failover_context(pipe); + struct fo_state *state = (struct fo_state *)alpha; - failover->alpha_test = *alpha; + failover->alpha_test = state; failover->dirty |= FO_NEW_ALPHA_TEST; - failover->hw->set_alpha_test_state( failover->hw, alpha ); + failover->hw->bind_alpha_test_state(failover->hw, + state->hw_state); +} + +static void +failover_delete_alpha_test_state(struct pipe_context *pipe, + void *alpha) +{ + struct fo_state *state = (struct fo_state*)alpha; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_alpha_test_state(pipe, state->sw_state); + failover->hw->delete_alpha_test_state(pipe, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + free(state); } @@ -95,7 +124,7 @@ failover_delete_blend_state( struct pipe_context *pipe, free(state); } -static void +static void failover_set_blend_color( struct pipe_context *pipe, const struct pipe_blend_color *blend_color ) { @@ -414,8 +443,11 @@ failover_set_vertex_element(struct pipe_context *pipe, void failover_init_state_functions( struct failover_context *failover ) { + failover->pipe.create_alpha_test_state = failover_create_alpha_test_state; + failover->pipe.bind_alpha_test_state = failover_bind_alpha_test_state; + failover->pipe.delete_alpha_test_state = failover_delete_alpha_test_state; failover->pipe.create_blend_state = failover_create_blend_state; - failover->pipe.bind_blend_state = failover_bind_blend_state; + failover->pipe.bind_blend_state = failover_bind_blend_state; failover->pipe.delete_blend_state = failover_delete_blend_state; failover->pipe.create_sampler_state = failover_create_sampler_state; failover->pipe.bind_sampler_state = failover_bind_sampler_state; @@ -433,7 +465,6 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.bind_vs_state = failover_bind_vs_state; failover->pipe.delete_vs_state = failover_delete_vs_state; - failover->pipe.set_alpha_test_state = failover_set_alpha_test_state; failover->pipe.set_blend_color = failover_set_blend_color; failover->pipe.set_clip_state = failover_set_clip_state; failover->pipe.set_clear_color_state = failover_set_clear_color_state; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index c0ea681024..a3aff8abd2 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -56,7 +56,8 @@ failover_state_emit( struct failover_context *failover ) unsigned i; if (failover->dirty & FO_NEW_ALPHA_TEST) - failover->sw->set_alpha_test_state( failover->sw, &failover->alpha_test ); + failover->sw->bind_alpha_test_state( failover->sw, + failover->alpha_test->sw_state ); if (failover->dirty & FO_NEW_BLEND) failover->sw->bind_blend_state( failover->sw, diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index f1e10f3433..9958a8592d 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -154,13 +154,13 @@ struct i915_context /* The most recent drawing state as set by the driver: */ + const struct pipe_alpha_test_state *alpha_test; const struct i915_blend_state *blend; const struct i915_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct i915_depth_stencil_state *depth_stencil; const struct i915_rasterizer_state *rasterizer; const struct pipe_shader_state *fs; - struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 525f8ce13a..8bfd2da3b5 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -394,16 +394,29 @@ static void i915_delete_depth_stencil_state(struct pipe_context *pipe, free(depth_stencil); } -static void i915_set_alpha_test_state(struct pipe_context *pipe, - const struct pipe_alpha_test_state *alpha) + +static void * +i915_create_alpha_test_state(struct pipe_context *pipe, + const struct pipe_alpha_test_state *alpha) +{ + return 0; +} + +static void i915_bind_alpha_test_state(struct pipe_context *pipe, + void *alpha) { struct i915_context *i915 = i915_context(pipe); - i915->alpha_test = *alpha; + i915->alpha_test = (const struct pipe_alpha_test_state*)alpha; i915->dirty |= I915_NEW_ALPHA_TEST; } +static void i915_delete_alpha_test_state(struct pipe_context *pipe, + void *alpha) +{ +} + static void i915_set_scissor_state( struct pipe_context *pipe, const struct pipe_scissor_state *scissor ) { @@ -664,6 +677,10 @@ static void i915_set_vertex_element( struct pipe_context *pipe, void i915_init_state_functions( struct i915_context *i915 ) { + i915->pipe.create_alpha_test_state = i915_create_alpha_test_state; + i915->pipe.bind_alpha_test_state = i915_bind_alpha_test_state; + i915->pipe.delete_alpha_test_state = i915_delete_alpha_test_state; + i915->pipe.create_blend_state = i915_create_blend_state; i915->pipe.bind_blend_state = i915_bind_blend_state; i915->pipe.delete_blend_state = i915_delete_blend_state; @@ -686,7 +703,6 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.bind_vs_state = i915_bind_vs_state; i915->pipe.delete_vs_state = i915_delete_shader_state; - i915->pipe.set_alpha_test_state = i915_set_alpha_test_state; i915->pipe.set_blend_color = i915_set_blend_color; i915->pipe.set_clip_state = i915_set_clip_state; i915->pipe.set_clear_color_state = i915_set_clear_color_state; diff --git a/src/mesa/pipe/i915simple/i915_state_immediate.c b/src/mesa/pipe/i915simple/i915_state_immediate.c index 874c3819f2..014fddfdda 100644 --- a/src/mesa/pipe/i915simple/i915_state_immediate.c +++ b/src/mesa/pipe/i915simple/i915_state_immediate.c @@ -121,9 +121,9 @@ static void upload_S6( struct i915_context *i915 ) /* I915_NEW_ALPHA_TEST */ - if (i915->alpha_test.enabled) { - int test = i915_translate_compare_func(i915->alpha_test.func); - ubyte refByte = float_to_ubyte(i915->alpha_test.ref); + if (i915->alpha_test->enabled) { + int test = i915_translate_compare_func(i915->alpha_test->func); + ubyte refByte = float_to_ubyte(i915->alpha_test->ref); LIS6 |= (S6_ALPHA_TEST_ENABLE | diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 07ee019880..8ba1031efe 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -86,26 +86,30 @@ struct pipe_context { /* * State functions */ + void * (*create_alpha_test_state)(struct pipe_context *, + const struct pipe_alpha_test_state *); + void (*bind_alpha_test_state)(struct pipe_context *, void *); + void (*delete_alpha_test_state)(struct pipe_context *, void *); + void * (*create_blend_state)(struct pipe_context *, const struct pipe_blend_state *); - void (*bind_blend_state)(struct pipe_context *, void *); - void (*delete_blend_state)(struct pipe_context *, void *); + void (*bind_blend_state)(struct pipe_context *, void *); + void (*delete_blend_state)(struct pipe_context *, void *); void * (*create_sampler_state)(struct pipe_context *, const struct pipe_sampler_state *); - void (*bind_sampler_state)(struct pipe_context *, unsigned unit, - void *); - void (*delete_sampler_state)(struct pipe_context *, void *); + void (*bind_sampler_state)(struct pipe_context *, unsigned unit, void *); + void (*delete_sampler_state)(struct pipe_context *, void *); - void *(*create_rasterizer_state)(struct pipe_context *, - const struct pipe_rasterizer_state *); - void (*bind_rasterizer_state)(struct pipe_context *, void *); - void (*delete_rasterizer_state)(struct pipe_context *, void *); + void * (*create_rasterizer_state)(struct pipe_context *, + const struct pipe_rasterizer_state *); + void (*bind_rasterizer_state)(struct pipe_context *, void *); + void (*delete_rasterizer_state)(struct pipe_context *, void *); void * (*create_depth_stencil_state)(struct pipe_context *, const struct pipe_depth_stencil_state *); - void (*bind_depth_stencil_state)(struct pipe_context *, void *); - void (*delete_depth_stencil_state)(struct pipe_context *, void *); + void (*bind_depth_stencil_state)(struct pipe_context *, void *); + void (*delete_depth_stencil_state)(struct pipe_context *, void *); void * (*create_fs_state)(struct pipe_context *, const struct pipe_shader_state *); @@ -117,9 +121,9 @@ struct pipe_context { void (*bind_vs_state)(struct pipe_context *, void *); void (*delete_vs_state)(struct pipe_context *, void *); - void (*set_alpha_test_state)( struct pipe_context *, - const struct pipe_alpha_test_state * ); - + /* The following look more properties than states. + * maybe combine a few of them into states or pass them + * in the bind calls to the state */ void (*set_blend_color)( struct pipe_context *, const struct pipe_blend_color * ); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index cac44606f7..a6ab45314c 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -260,6 +260,9 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.get_param = softpipe_get_param; /* state setters */ + softpipe->pipe.create_alpha_test_state = softpipe_create_alpha_test_state; + softpipe->pipe.bind_alpha_test_state = softpipe_bind_alpha_test_state; + softpipe->pipe.delete_alpha_test_state = softpipe_delete_alpha_test_state; softpipe->pipe.create_blend_state = softpipe_create_blend_state; softpipe->pipe.bind_blend_state = softpipe_bind_blend_state; softpipe->pipe.delete_blend_state = softpipe_delete_blend_state; @@ -279,7 +282,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.bind_vs_state = softpipe_bind_vs_state; softpipe->pipe.delete_vs_state = softpipe_delete_shader_state; - softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state; softpipe->pipe.set_blend_color = softpipe_set_blend_color; softpipe->pipe.set_clip_state = softpipe_set_clip_state; softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 95215eb640..7b1518cfac 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -70,6 +70,7 @@ struct softpipe_context { /* The most recent drawing state as set by the driver: */ + const struct pipe_alpha_test_state *alpha_test; const struct pipe_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_depth_stencil_state *depth_stencil; @@ -77,7 +78,6 @@ struct softpipe_context { const struct pipe_shader_state *fs; const struct pipe_shader_state *vs; - struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; diff --git a/src/mesa/pipe/softpipe/sp_quad.c b/src/mesa/pipe/softpipe/sp_quad.c index fc4f8328cf..74a21dc54b 100644 --- a/src/mesa/pipe/softpipe/sp_quad.c +++ b/src/mesa/pipe/softpipe/sp_quad.c @@ -54,7 +54,7 @@ sp_build_quad_pipeline(struct softpipe_context *sp) sp->quad.first = sp->quad.depth_test; } - if (sp->alpha_test.enabled) { + if (sp->alpha_test->enabled) { sp->quad.alpha_test->next = sp->quad.first; sp->quad.first = sp->quad.alpha_test; } diff --git a/src/mesa/pipe/softpipe/sp_quad_alpha_test.c b/src/mesa/pipe/softpipe/sp_quad_alpha_test.c index 64c1624bd0..4f28414b0e 100644 --- a/src/mesa/pipe/softpipe/sp_quad_alpha_test.c +++ b/src/mesa/pipe/softpipe/sp_quad_alpha_test.c @@ -14,10 +14,10 @@ static void alpha_test_quad(struct quad_stage *qs, struct quad_header *quad) { struct softpipe_context *softpipe = qs->softpipe; - const float ref = softpipe->alpha_test.ref; + const float ref = softpipe->alpha_test->ref; unsigned passMask = 0x0, j; - switch (softpipe->alpha_test.func) { + switch (softpipe->alpha_test->func) { case PIPE_FUNC_NEVER: quad->mask = 0x0; break; diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 62323c41c3..f0e1461d25 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -33,6 +33,15 @@ #include "pipe/p_state.h" + +void * +softpipe_create_alpha_test_state(struct pipe_context *, + const struct pipe_alpha_test_state *); +void +softpipe_bind_alpha_test_state(struct pipe_context *, void *); +void +softpipe_delete_alpha_test_state(struct pipe_context *, void *); + void * softpipe_create_blend_state(struct pipe_context *, const struct pipe_blend_state *); @@ -62,9 +71,6 @@ void softpipe_delete_rasterizer_state(struct pipe_context *, void *); void softpipe_set_framebuffer_state( struct pipe_context *, const struct pipe_framebuffer_state * ); -void softpipe_set_alpha_test_state( struct pipe_context *, - const struct pipe_alpha_test_state * ); - void softpipe_set_blend_color( struct pipe_context *pipe, const struct pipe_blend_color *blend_color ); diff --git a/src/mesa/pipe/softpipe/sp_state_blend.c b/src/mesa/pipe/softpipe/sp_state_blend.c index cf47607955..cb0921f687 100644 --- a/src/mesa/pipe/softpipe/sp_state_blend.c +++ b/src/mesa/pipe/softpipe/sp_state_blend.c @@ -71,17 +71,31 @@ void softpipe_set_blend_color( struct pipe_context *pipe, * into one file. */ +void * +softpipe_create_alpha_test_state(struct pipe_context *pipe, + const struct pipe_alpha_test_state *alpha) +{ + return 0; +} + void -softpipe_set_alpha_test_state(struct pipe_context *pipe, - const struct pipe_alpha_test_state *alpha) +softpipe_bind_alpha_test_state(struct pipe_context *pipe, + void *alpha) { struct softpipe_context *softpipe = softpipe_context(pipe); - softpipe->alpha_test = *alpha; + softpipe->alpha_test = (const struct pipe_alpha_test_state *)alpha; softpipe->dirty |= SP_NEW_ALPHA_TEST; } +void +softpipe_delete_alpha_test_state(struct pipe_context *pipe, + void *alpha) +{ + /* do nothing */ +} + void * softpipe_create_depth_stencil_state(struct pipe_context *pipe, const struct pipe_depth_stencil_state *depth_stencil) diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index a4af3aeb20..fc339b91ed 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -62,6 +62,7 @@ static const struct st_tracked_state *atoms[] = &st_update_texture, &st_update_vs_constants, &st_update_fs_constants, + &st_update_alpha_test }; diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 26f6514698..6710c1a269 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -60,6 +60,7 @@ const struct st_tracked_state st_update_sampler; const struct st_tracked_state st_update_texture; const struct st_tracked_state st_update_fs_constants; const struct st_tracked_state st_update_vs_constants; +const struct st_tracked_state st_update_alpha_test; #endif diff --git a/src/mesa/state_tracker/st_atom_alphatest.c b/src/mesa/state_tracker/st_atom_alphatest.c index 4378154053..873520ab02 100644 --- a/src/mesa/state_tracker/st_atom_alphatest.c +++ b/src/mesa/state_tracker/st_atom_alphatest.c @@ -33,6 +33,7 @@ #include "st_context.h" +#include "st_cache.h" #include "st_atom.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -63,6 +64,7 @@ static void update_alpha_test( struct st_context *st ) { struct pipe_alpha_test_state alpha; + const struct cso_alpha_test *cso; memset(&alpha, 0, sizeof(alpha)); @@ -71,11 +73,11 @@ update_alpha_test( struct st_context *st ) alpha.func = gl_alpha_func_to_sp(st->ctx->Color.AlphaFunc); alpha.ref = st->ctx->Color.AlphaRef; } - - if (memcmp(&alpha, &st->state.alpha_test, sizeof(alpha)) != 0) { + cso = st_cached_alpha_test_state(st, &alpha); + if (st->state.alpha_test != cso) { /* state has changed */ - st->state.alpha_test = alpha; /* struct copy */ - st->pipe->set_alpha_test_state(st->pipe, &alpha); /* set new state */ + st->state.alpha_test = cso; + st->pipe->bind_alpha_test_state(st->pipe, cso->data); /* bind new state */ } } @@ -88,8 +90,3 @@ const struct st_tracked_state st_update_alpha_test = { }, .update = update_alpha_test }; - - - - - diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index 01d1934232..1686721990 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -159,3 +159,23 @@ st_cached_vs_state(struct st_context *st, } return (struct cso_vertex_shader*)(cso_hash_iter_data(iter)); } + +const struct cso_alpha_test * +st_cached_alpha_test_state(struct st_context *st, + const struct pipe_alpha_test_state *templ) +{ + unsigned hash_key = cso_construct_key((void*)templ, + sizeof(struct pipe_alpha_test_state)); + struct cso_hash_iter iter = cso_find_state_template(st->cache, + hash_key, CSO_ALPHA_TEST, + (void*)templ); + if (cso_hash_iter_is_null(iter)) { + struct cso_alpha_test *cso = malloc(sizeof(struct cso_alpha_test)); + memcpy(&cso->state, templ, sizeof(struct pipe_alpha_test_state)); + cso->data = st->pipe->create_alpha_test_state(st->pipe, &cso->state); + if (!cso->data) + cso->data = &cso->state; + iter = cso_insert_state(st->cache, hash_key, CSO_ALPHA_TEST, cso); + } + return ((struct cso_alpha_test *)cso_hash_iter_data(iter)); +} diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index 483af6fdb4..422f668c56 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -39,6 +39,10 @@ struct pipe_blend_state; struct pipe_sampler_state; struct st_context; +const struct cso_alpha_test * +st_cached_alpha_test_state(struct st_context *st, + const struct pipe_alpha_test_state *alpha); + const struct cso_blend * st_cached_blend_state(struct st_context *st, const struct pipe_blend_state *blend); diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 5e63205088..c53446d588 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -275,8 +275,10 @@ clear_with_quad(GLcontext *ctx, /* alpha state: disabled */ { struct pipe_alpha_test_state alpha_test; + const struct cso_alpha_test *cso; memset(&alpha_test, 0, sizeof(alpha_test)); - pipe->set_alpha_test_state(pipe, &alpha_test); + cso = st_cached_alpha_test_state(st, &alpha_test); + pipe->bind_alpha_test_state(pipe, cso->data); } /* blend state: RGBA masking */ @@ -379,7 +381,7 @@ clear_with_quad(GLcontext *ctx, draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); /* Restore pipe state */ - pipe->set_alpha_test_state(pipe, &st->state.alpha_test); + pipe->bind_alpha_test_state(pipe, st->state.alpha_test->data); pipe->bind_blend_state(pipe, st->state.blend->data); pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil->data); pipe->bind_fs_state(pipe, st->state.fs->data); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index d814e34157..65c5465546 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -468,7 +468,7 @@ compatible_formats(GLenum format, GLenum type, GLuint pipeFormat) static GLboolean any_fragment_ops(const struct st_context *st) { - if (st->state.alpha_test.enabled || + if (st->state.alpha_test->state.enabled || st->state.blend->state.blend_enable || st->state.blend->state.logicop_enable || st->state.depth_stencil->state.depth.enabled) diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 55a857f46d..3713328eb1 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -75,14 +75,14 @@ struct st_context * though, we just shove random objects across the interface. */ struct { - const struct cso_blend *blend; - const struct cso_sampler *sampler[PIPE_MAX_SAMPLERS]; - const struct cso_depth_stencil *depth_stencil; - const struct cso_rasterizer *rasterizer; + const struct cso_alpha_test *alpha_test; + const struct cso_blend *blend; + const struct cso_sampler *sampler[PIPE_MAX_SAMPLERS]; + const struct cso_depth_stencil *depth_stencil; + const struct cso_rasterizer *rasterizer; const struct cso_fragment_shader *fs; const struct cso_vertex_shader *vs; - struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; -- cgit v1.2.3 From 46f606e9715145218331a04f0d1f66fb9f8531d6 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 21 Sep 2007 11:55:28 -0600 Subject: reenable some clear code that was temporarily disabled --- src/mesa/state_tracker/st_cb_clear.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index c53446d588..639e0ceb40 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -493,15 +493,12 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) assert(strb->surface->format); -#if 0 if (ctx->Scissor.Enabled || (isDS && ctx->DrawBuffer->Visual.stencilBits > 0)) { /* scissoring or we have a combined depth/stencil buffer */ clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE); } - else -#endif - { + else { /* simple clear of whole buffer */ GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); -- cgit v1.2.3 From 40c543eb71368c646259afb87d5c76551f6b45b7 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 25 Sep 2007 14:29:11 -0600 Subject: Translate mesa vertex/fragment programs to TGSI programs at same time to do proper linking. Previously, programs were translated independently during validation. The problem is the translation to TGSI format, which packs shader input/outputs into continuous slots, depends on which vertex program is being paired with which fragment shader. Now, we look at the outputs of the vertex program in conjunction with the inputs of the fragment shader to be sure the attributes match up correctly. The new 'linked_program_pair' class keeps track of the associations between vertex and fragment shaders. It's also the place where the TGSI tokens are kept since they're no longer per-program state but per-linkage. Still a few loose ends, like implementing some kind of hash/lookup table for linked_program_pairs. --- src/mesa/pipe/draw/draw_feedback.c | 7 +- src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c | 4 + src/mesa/sources | 4 +- src/mesa/state_tracker/st_atom.c | 3 +- src/mesa/state_tracker/st_atom.h | 3 +- src/mesa/state_tracker/st_atom_fs.c | 96 +++++++++++------- src/mesa/state_tracker/st_atom_vs.c | 156 +++++++++++++++++++----------- src/mesa/state_tracker/st_cb_clear.c | 6 +- src/mesa/state_tracker/st_cb_drawpixels.c | 6 +- src/mesa/state_tracker/st_cb_feedback.c | 4 +- src/mesa/state_tracker/st_cb_program.c | 88 ++++++++++------- src/mesa/state_tracker/st_cb_rasterpos.c | 61 ++++++------ src/mesa/state_tracker/st_context.h | 6 +- src/mesa/state_tracker/st_program.h | 27 ++++-- 14 files changed, 287 insertions(+), 184 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/draw/draw_feedback.c b/src/mesa/pipe/draw/draw_feedback.c index 3b8400233e..ee54db0ad5 100644 --- a/src/mesa/pipe/draw/draw_feedback.c +++ b/src/mesa/pipe/draw/draw_feedback.c @@ -78,11 +78,9 @@ feedback_vertex(struct draw_stage *stage, const struct vertex_header *vertex) * we can either address output buffer 0 (for interleaving) or * output buffer i (for non-interleaved). */ -#if 0 for (i = 0; i < feedback->num_attribs; i++) { - const uint attr = feedback->attrib[i]; - const uint slot = stage->draw->vertex_info.attrib_to_slot[attr]; - const float *src = attr ? vertex->data[slot] : vertex->clip; + const uint slot = feedback->attrib[i]; + const float *src = slot ? vertex->data[slot] : vertex->clip; const uint size = feedback->size[i]; float *dest = fs->dest[i * select]; @@ -104,7 +102,6 @@ feedback_vertex(struct draw_stage *stage, const struct vertex_header *vertex) } fs->dest[i * select] += size; } -#endif fs->num_vert_emitted++; } diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c index d0d97ab0f8..fa27fd3cd0 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c @@ -476,6 +476,8 @@ make_input_decl( { struct tgsi_full_declaration decl; + assert(semantic_name < TGSI_SEMANTIC_COUNT); + decl = tgsi_default_full_declaration(); decl.Declaration.File = TGSI_FILE_INPUT; decl.Declaration.Declare = TGSI_DECLARE_RANGE; @@ -500,6 +502,8 @@ make_output_decl( { struct tgsi_full_declaration decl; + assert(semantic_name < TGSI_SEMANTIC_COUNT); + decl = tgsi_default_full_declaration(); decl.Declaration.File = TGSI_FILE_OUTPUT; decl.Declaration.Declare = TGSI_DECLARE_RANGE; diff --git a/src/mesa/sources b/src/mesa/sources index 0d4fdc15f4..985bd2dce6 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -200,14 +200,13 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_depth.c \ state_tracker/st_atom_fixedfunction.c \ state_tracker/st_atom_framebuffer.c \ - state_tracker/st_atom_fs.c \ state_tracker/st_atom_sampler.c \ state_tracker/st_atom_scissor.c \ + state_tracker/st_atom_shader.c \ state_tracker/st_atom_rasterizer.c \ state_tracker/st_atom_stipple.c \ state_tracker/st_atom_texture.c \ state_tracker/st_atom_viewport.c \ - state_tracker/st_atom_vs.c \ state_tracker/st_cb_bufferobjects.c \ state_tracker/st_cb_clear.c \ state_tracker/st_cb_flush.c \ @@ -224,6 +223,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_context.c \ state_tracker/st_draw.c \ state_tracker/st_format.c \ + state_tracker/st_program.c \ state_tracker/st_mipmap_tree.c SHADER_SOURCES = \ diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index fc339b91ed..326042cb34 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -50,8 +50,7 @@ static const struct st_tracked_state *atoms[] = &st_update_clip, &st_update_tnl, - &st_update_vs, - &st_update_fs, + &st_update_shader, &st_update_rasterizer, &st_update_polygon_stipple, diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 6710c1a269..94cb7bee7a 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -49,8 +49,7 @@ const struct st_tracked_state st_update_clip; const struct st_tracked_state st_update_clear_color; const struct st_tracked_state st_update_depth_stencil; const struct st_tracked_state st_update_tnl; -const struct st_tracked_state st_update_fs; -const struct st_tracked_state st_update_vs; +const struct st_tracked_state st_update_shader; const struct st_tracked_state st_update_rasterizer; const struct st_tracked_state st_update_polygon_stipple; const struct st_tracked_state st_update_viewport; diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index dd4cdf0855..28019858f7 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -24,11 +24,12 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * **************************************************************************/ - /* - * Authors: - * Keith Whitwell - * Brian Paul - */ + +/* + * Authors: + * Keith Whitwell + * Brian Paul + */ #include "shader/prog_parameter.h" @@ -50,14 +51,20 @@ /** * Translate a Mesa fragment shader into a TGSI shader. + * \param inputMapping to map fragment program input registers to TGSI + * input slots + * \param tokensOut destination for TGSI tokens * \return pointer to cached pipe_shader object. */ const struct cso_fragment_shader * -st_translate_fragment_shader(struct st_context *st, - struct st_fragment_program *stfp) +st_translate_fragment_shader(const struct st_context *st, + struct st_fragment_program *stfp, + const GLuint inputMapping[], + struct tgsi_token *tokensOut, + GLuint maxTokens) { GLuint outputMapping[FRAG_RESULT_MAX]; - GLuint inputMapping[PIPE_MAX_SHADER_INPUTS]; + GLuint defaultInputMapping[FRAG_ATTRIB_MAX]; struct pipe_shader_state fs; const struct cso_fragment_shader *cso; GLuint interpMode[16]; /* XXX size? */ @@ -67,6 +74,7 @@ st_translate_fragment_shader(struct st_context *st, /* Check if all fragment programs need the fragment position (in order * to do perspective-corrected interpolation). */ + /* XXX temporary! */ if (st->pipe->get_param(st->pipe, PIPE_PARAM_FS_NEEDS_POS)) inputsRead |= FRAG_BIT_WPOS; @@ -77,28 +85,32 @@ st_translate_fragment_shader(struct st_context *st, */ for (attr = 0; attr < FRAG_ATTRIB_MAX; attr++) { if (inputsRead & (1 << attr)) { - inputMapping[attr] = fs.num_inputs; + const GLuint slot = fs.num_inputs; + + fs.num_inputs++; + + defaultInputMapping[attr] = slot; switch (attr) { case FRAG_ATTRIB_WPOS: - fs.input_semantic_name[fs.num_inputs] = TGSI_SEMANTIC_POSITION; - fs.input_semantic_index[fs.num_inputs] = 0; - interpMode[fs.num_inputs] = TGSI_INTERPOLATE_CONSTANT; + fs.input_semantic_name[slot] = TGSI_SEMANTIC_POSITION; + fs.input_semantic_index[slot] = 0; + interpMode[slot] = TGSI_INTERPOLATE_CONSTANT; break; case FRAG_ATTRIB_COL0: - fs.input_semantic_name[fs.num_inputs] = TGSI_SEMANTIC_COLOR; - fs.input_semantic_index[fs.num_inputs] = 0; - interpMode[fs.num_inputs] = TGSI_INTERPOLATE_LINEAR; + fs.input_semantic_name[slot] = TGSI_SEMANTIC_COLOR; + fs.input_semantic_index[slot] = 0; + interpMode[slot] = TGSI_INTERPOLATE_LINEAR; break; case FRAG_ATTRIB_COL1: - fs.input_semantic_name[fs.num_inputs] = TGSI_SEMANTIC_COLOR; - fs.input_semantic_index[fs.num_inputs] = 1; - interpMode[fs.num_inputs] = TGSI_INTERPOLATE_LINEAR; + fs.input_semantic_name[slot] = TGSI_SEMANTIC_COLOR; + fs.input_semantic_index[slot] = 1; + interpMode[slot] = TGSI_INTERPOLATE_LINEAR; break; case FRAG_ATTRIB_FOGC: - fs.input_semantic_name[fs.num_inputs] = TGSI_SEMANTIC_FOG; - fs.input_semantic_index[fs.num_inputs] = 0; - interpMode[fs.num_inputs] = TGSI_INTERPOLATE_PERSPECTIVE; + fs.input_semantic_name[slot] = TGSI_SEMANTIC_FOG; + fs.input_semantic_index[slot] = 0; + interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE; break; case FRAG_ATTRIB_TEX0: case FRAG_ATTRIB_TEX1: @@ -108,19 +120,17 @@ st_translate_fragment_shader(struct st_context *st, case FRAG_ATTRIB_TEX5: case FRAG_ATTRIB_TEX6: case FRAG_ATTRIB_TEX7: - fs.input_semantic_name[fs.num_inputs] = TGSI_SEMANTIC_GENERIC; - fs.input_semantic_index[fs.num_inputs] = attr - FRAG_ATTRIB_TEX0; - interpMode[fs.num_inputs] = TGSI_INTERPOLATE_PERSPECTIVE; + fs.input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; + fs.input_semantic_index[slot] = attr - FRAG_ATTRIB_TEX0; + interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE; break; case FRAG_ATTRIB_VAR0: /* fall-through */ default: - fs.input_semantic_name[fs.num_inputs] = TGSI_SEMANTIC_GENERIC; - fs.input_semantic_index[fs.num_inputs] = attr - FRAG_ATTRIB_VAR0; - interpMode[fs.num_inputs] = TGSI_INTERPOLATE_PERSPECTIVE; + fs.input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; + fs.input_semantic_index[slot] = attr - FRAG_ATTRIB_VAR0; + interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE; } - - fs.num_inputs++; } } @@ -145,35 +155,40 @@ st_translate_fragment_shader(struct st_context *st, } } + if (!inputMapping) + inputMapping = defaultInputMapping; + /* XXX: fix static allocation of tokens: */ tgsi_mesa_compile_fp_program( &stfp->Base, + /* inputs */ fs.num_inputs, inputMapping, fs.input_semantic_name, fs.input_semantic_index, interpMode, + /* outputs */ outputMapping, - stfp->tokens, ST_FP_MAX_TOKENS ); + /* tokenized result */ + tokensOut, maxTokens); + - fs.tokens = &stfp->tokens[0]; + fs.tokens = tokensOut; cso = st_cached_fs_state(st, &fs); stfp->fs = cso; if (TGSI_DEBUG) - tgsi_dump( stfp->tokens, 0/*TGSI_DUMP_VERBOSE*/ ); + tgsi_dump( tokensOut, 0/*TGSI_DUMP_VERBOSE*/ ); #if defined(USE_X86_ASM) || defined(SLANG_X86) if (stfp->sse2_program.csr == stfp->sse2_program.store) - tgsi_emit_sse2_fs( stfp->tokens, &stfp->sse2_program ); + tgsi_emit_sse2_fs( tokensOut, &stfp->sse2_program ); if (!cso->state.executable) ((struct cso_fragment_shader*)cso)->state.executable = (void *) x86_get_func( &stfp->sse2_program ); #endif - stfp->dirty = 0; - return cso; } @@ -200,8 +215,9 @@ static void update_fs( struct st_context *st ) } /* if new binding, or shader has changed */ - if (st->fp != stfp || stfp->dirty) { + if (st->fp != stfp /**|| stfp->dirty**/) { +#if 0 if (stfp->dirty) (void) st_translate_fragment_shader( st, stfp ); @@ -210,10 +226,17 @@ static void update_fs( struct st_context *st ) st->state.fs = stfp->fs; st->pipe->bind_fs_state(st->pipe, st->state.fs->data); +#else + + /* NEW */ + st->dirty.st |= ST_NEW_LINKAGE; + +#endif } } +#if 0 const struct st_tracked_state st_update_fs = { .name = "st_update_fs", .dirty = { @@ -222,3 +245,4 @@ const struct st_tracked_state st_update_fs = { }, .update = update_fs }; +#endif diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index a6c0d159d4..0f07906a96 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -51,15 +51,22 @@ /** * Translate a Mesa vertex shader into a TGSI shader. + * \param outputMapping to map vertex program output registers to TGSI + * output slots + * \param tokensOut destination for TGSI tokens * \return pointer to cached pipe_shader object. */ const struct cso_vertex_shader * -st_translate_vertex_shader(struct st_context *st, - struct st_vertex_program *stvp) +st_translate_vertex_shader(const struct st_context *st, + struct st_vertex_program *stvp, + const GLuint outputMapping[], + struct tgsi_token *tokensOut, + GLuint maxTokens) { + GLuint defaultOutputMapping[VERT_RESULT_MAX]; struct pipe_shader_state vs; const struct cso_vertex_shader *cso; - GLuint attr; + GLuint attr, i; memset(&vs, 0, sizeof(vs)); @@ -69,31 +76,36 @@ st_translate_vertex_shader(struct st_context *st, */ for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) { if (stvp->Base.Base.InputsRead & (1 << attr)) { - stvp->input_to_index[attr] = vs.num_inputs; - stvp->index_to_input[vs.num_inputs] = attr; + const GLuint slot = vs.num_inputs; + + vs.num_inputs++; + + stvp->input_to_index[attr] = slot; + stvp->index_to_input[slot] = attr; + switch (attr) { case VERT_ATTRIB_POS: - vs.input_semantic_name[vs.num_inputs] = TGSI_SEMANTIC_POSITION; - vs.input_semantic_index[vs.num_inputs] = 0; + vs.input_semantic_name[slot] = TGSI_SEMANTIC_POSITION; + vs.input_semantic_index[slot] = 0; break; case VERT_ATTRIB_WEIGHT: /* fall-through */ case VERT_ATTRIB_NORMAL: /* just label as a generic */ - vs.input_semantic_name[vs.num_inputs] = TGSI_SEMANTIC_GENERIC; - vs.input_semantic_index[vs.num_inputs] = 0; + vs.input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; + vs.input_semantic_index[slot] = 0; break; case VERT_ATTRIB_COLOR0: - vs.input_semantic_name[vs.num_inputs] = TGSI_SEMANTIC_COLOR; - vs.input_semantic_index[vs.num_inputs] = 0; + vs.input_semantic_name[slot] = TGSI_SEMANTIC_COLOR; + vs.input_semantic_index[slot] = 0; break; case VERT_ATTRIB_COLOR1: - vs.input_semantic_name[vs.num_inputs] = TGSI_SEMANTIC_COLOR; - vs.input_semantic_index[vs.num_inputs] = 1; + vs.input_semantic_name[slot] = TGSI_SEMANTIC_COLOR; + vs.input_semantic_index[slot] = 1; break; case VERT_ATTRIB_FOG: - vs.input_semantic_name[vs.num_inputs] = TGSI_SEMANTIC_FOG; - vs.input_semantic_index[vs.num_inputs] = 0; + vs.input_semantic_name[slot] = TGSI_SEMANTIC_FOG; + vs.input_semantic_index[slot] = 0; break; case VERT_ATTRIB_TEX0: case VERT_ATTRIB_TEX1: @@ -103,8 +115,8 @@ st_translate_vertex_shader(struct st_context *st, case VERT_ATTRIB_TEX5: case VERT_ATTRIB_TEX6: case VERT_ATTRIB_TEX7: - vs.input_semantic_name[vs.num_inputs] = TGSI_SEMANTIC_GENERIC; - vs.input_semantic_index[vs.num_inputs] = attr - VERT_ATTRIB_TEX0; + vs.input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; + vs.input_semantic_index[slot] = attr - VERT_ATTRIB_TEX0; break; case VERT_ATTRIB_GENERIC0: case VERT_ATTRIB_GENERIC1: @@ -115,53 +127,71 @@ st_translate_vertex_shader(struct st_context *st, case VERT_ATTRIB_GENERIC6: case VERT_ATTRIB_GENERIC7: assert(attr < VERT_ATTRIB_MAX); - vs.input_semantic_name[vs.num_inputs] = TGSI_SEMANTIC_GENERIC; - vs.input_semantic_index[vs.num_inputs] = attr - VERT_ATTRIB_GENERIC0; + vs.input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; + vs.input_semantic_index[slot] = attr - VERT_ATTRIB_GENERIC0; break; default: assert(0); } - vs.num_inputs++; } } + /* initialize output semantics to defaults */ + for (i = 0; i < PIPE_MAX_SHADER_OUTPUTS; i++) { + vs.output_semantic_name[i] = TGSI_SEMANTIC_GENERIC; + vs.output_semantic_index[i] = 0; + } + /* - * Determine number of outputs, the register mapping and - * the semantic information for each vertex output/result. + * Determine number of outputs, the (default) output register + * mapping and the semantic information for each output. */ for (attr = 0; attr < VERT_RESULT_MAX; attr++) { if (stvp->Base.Base.OutputsWritten & (1 << attr)) { - /* put this attrib in the next available slot */ - st->vertex_attrib_to_slot[attr] = vs.num_outputs; + GLuint slot; + + if (outputMapping) { + slot = outputMapping[attr]; + assert(slot != ~0); + } + else { + slot = vs.num_outputs; + vs.num_outputs++; + defaultOutputMapping[attr] = slot; + } + + /* + printf("Output %u -> slot %u\n", attr, slot); + */ switch (attr) { case VERT_RESULT_HPOS: - vs.output_semantic_name[vs.num_outputs] = TGSI_SEMANTIC_POSITION; - vs.output_semantic_index[vs.num_outputs] = 0; + vs.output_semantic_name[slot] = TGSI_SEMANTIC_POSITION; + vs.output_semantic_index[slot] = 0; break; case VERT_RESULT_COL0: - vs.output_semantic_name[vs.num_outputs] = TGSI_SEMANTIC_COLOR; - vs.output_semantic_index[vs.num_outputs] = 0; + vs.output_semantic_name[slot] = TGSI_SEMANTIC_COLOR; + vs.output_semantic_index[slot] = 0; break; case VERT_RESULT_COL1: - vs.output_semantic_name[vs.num_outputs] = TGSI_SEMANTIC_COLOR; - vs.output_semantic_index[vs.num_outputs] = 1; + vs.output_semantic_name[slot] = TGSI_SEMANTIC_COLOR; + vs.output_semantic_index[slot] = 1; break; case VERT_RESULT_BFC0: - vs.output_semantic_name[vs.num_outputs] = TGSI_SEMANTIC_BCOLOR; - vs.output_semantic_index[vs.num_outputs] = 0; + vs.output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR; + vs.output_semantic_index[slot] = 0; break; case VERT_RESULT_BFC1: - vs.output_semantic_name[vs.num_outputs] = TGSI_SEMANTIC_BCOLOR; - vs.output_semantic_index[vs.num_outputs] = 1; + vs.output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR; + vs.output_semantic_index[slot] = 1; break; case VERT_RESULT_FOGC: - vs.output_semantic_name[vs.num_outputs] = TGSI_SEMANTIC_FOG; - vs.output_semantic_index[vs.num_outputs] = 0; + vs.output_semantic_name[slot] = TGSI_SEMANTIC_FOG; + vs.output_semantic_index[slot] = 0; break; case VERT_RESULT_PSIZ: - vs.output_semantic_name[vs.num_outputs] = TGSI_SEMANTIC_PSIZE; - vs.output_semantic_index[vs.num_outputs] = 0; + vs.output_semantic_name[slot] = TGSI_SEMANTIC_PSIZE; + vs.output_semantic_index[slot] = 0; break; case VERT_RESULT_EDGE: assert(0); @@ -174,46 +204,59 @@ st_translate_vertex_shader(struct st_context *st, case VERT_RESULT_TEX5: case VERT_RESULT_TEX6: case VERT_RESULT_TEX7: - vs.output_semantic_name[vs.num_outputs] = TGSI_SEMANTIC_GENERIC; - vs.output_semantic_index[vs.num_outputs] = attr - VERT_RESULT_TEX0; + vs.output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; + vs.output_semantic_index[slot] = attr - VERT_RESULT_TEX0; break; case VERT_RESULT_VAR0: /* fall-through */ default: assert(attr - VERT_RESULT_VAR0 < MAX_VARYING); - vs.output_semantic_name[vs.num_outputs] = TGSI_SEMANTIC_GENERIC; - vs.output_semantic_index[vs.num_outputs] = attr - VERT_RESULT_VAR0; + vs.output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; + vs.output_semantic_index[slot] = attr - VERT_RESULT_VAR0; } - - vs.num_outputs++; } } + if (outputMapping) { + /* find max output slot referenced to compute vs.num_outputs */ + GLuint maxSlot = 0; + for (attr = 0; attr < VERT_RESULT_MAX; attr++) { + if (outputMapping[attr] != ~0 && outputMapping[attr] > maxSlot) + maxSlot = outputMapping[attr]; + } + vs.num_outputs = maxSlot + 1; + } + else { + outputMapping = defaultOutputMapping; + } + /* XXX: fix static allocation of tokens: */ tgsi_mesa_compile_vp_program( &stvp->Base, + /* inputs */ vs.num_inputs, stvp->input_to_index, vs.input_semantic_name, vs.input_semantic_index, + /* outputs */ vs.num_outputs, - st->vertex_attrib_to_slot, + outputMapping, vs.output_semantic_name, vs.output_semantic_index, - stvp->tokens, ST_FP_MAX_TOKENS ); - - vs.tokens = &stvp->tokens[0]; + /* tokenized result */ + tokensOut, maxTokens); + vs.tokens = tokensOut; cso = st_cached_vs_state(st, &vs); stvp->vs = cso; if (TGSI_DEBUG) - tgsi_dump( stvp->tokens, 0 ); + tgsi_dump( tokensOut, 0 ); #if defined(USE_X86_ASM) || defined(SLANG_X86) if (stvp->sse2_program.csr == stvp->sse2_program.store) - tgsi_emit_sse2( stvp->tokens, &stvp->sse2_program ); + tgsi_emit_sse2( tokensOut, &stvp->sse2_program ); if (!cso->state.executable) ((struct cso_vertex_shader*)cso)->state.executable = (void *) x86_get_func( &stvp->sse2_program ); @@ -246,6 +289,7 @@ static void update_vs( struct st_context *st ) } if (st->vp != stvp || stvp->dirty) { +#if 0 if (stvp->dirty) (void) st_translate_vertex_shader( st, stvp ); @@ -260,10 +304,15 @@ static void update_vs( struct st_context *st ) tgsi_dump( stvp->tokens, 0 ); #endif st->pipe->bind_vs_state(st->pipe, st->state.vs->data); +#else + /* NEW */ + st->dirty.st |= ST_NEW_LINKAGE; + +#endif } } - +#if 0 const struct st_tracked_state st_update_vs = { .name = "st_update_vs", .dirty = { @@ -272,7 +321,4 @@ const struct st_tracked_state st_update_vs = { }, .update = update_vs }; - - - - +#endif diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 639e0ceb40..367ae06cf3 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -155,7 +155,8 @@ make_frag_shader(struct st_context *st) p->OutputsWritten = (1 << FRAG_RESULT_COLR); stfp = (struct st_fragment_program *) p; - st_translate_fragment_shader(st, stfp); + st_translate_fragment_program(st, stfp, NULL, + stfp->tokens, ST_FP_MAX_TOKENS); return stfp; } @@ -203,7 +204,8 @@ make_vertex_shader(struct st_context *st) (1 << VERT_RESULT_HPOS)); stvp = (struct st_vertex_program *) p; - st_translate_vertex_shader(st, stvp); + st_translate_vertex_program(st, stvp, NULL, + stvp->tokens, ST_FP_MAX_TOKENS); assert(stvp->vs); return stvp; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 65c5465546..619c5d8ab7 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -92,7 +92,8 @@ make_fragment_shader(struct st_context *st) p->OutputsWritten = (1 << FRAG_RESULT_COLR); stfp = (struct st_fragment_program *) p; - st_translate_fragment_shader(st, stfp); + st_translate_fragment_program(st, stfp, NULL, + stfp->tokens, ST_FP_MAX_TOKENS); return stfp; } @@ -141,7 +142,8 @@ make_vertex_shader(struct st_context *st) (1 << VERT_RESULT_HPOS)); stvp = (struct st_vertex_program *) p; - st_translate_vertex_shader(st, stvp); + st_translate_vertex_program(st, stvp, NULL, + stvp->tokens, ST_FP_MAX_TOKENS); return stvp; } diff --git a/src/mesa/state_tracker/st_cb_feedback.c b/src/mesa/state_tracker/st_cb_feedback.c index 78cf4c2b4d..537a58f39d 100644 --- a/src/mesa/state_tracker/st_cb_feedback.c +++ b/src/mesa/state_tracker/st_cb_feedback.c @@ -102,13 +102,13 @@ feedback_vertex(GLcontext *ctx, const struct draw_context *draw, * color and texcoord attribs to use here. */ - slot = st->vertex_attrib_to_slot[VERT_RESULT_COL0]; + slot = st->vertex_result_to_slot[VERT_RESULT_COL0]; if (slot) color = v->data[slot]; else color = ctx->Current.Attrib[VERT_ATTRIB_COLOR0]; - slot = st->vertex_attrib_to_slot[VERT_RESULT_TEX0]; + slot = st->vertex_result_to_slot[VERT_RESULT_TEX0]; if (slot) texcoord = v->data[slot]; else diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 9f46f9e93f..aee316df6f 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -30,24 +30,26 @@ * Keith Whitwell */ +#include "main/glheader.h" +#include "main/macros.h" +#include "main/enums.h" +#include "shader/prog_instruction.h" +#include "shader/prog_parameter.h" +#include "shader/program.h" +#include "shader/programopt.h" + #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 "st_program.h" +#include "st_atom_shader.h" + #include "tnl/tnl.h" #include "pipe/tgsi/mesa/tgsi_mesa.h" -/* Counter to track program string changes: +/** + * Called via ctx->Driver.BindProgram() to bind an ARB vertex or + * fragment program. */ -static GLuint program_id = 0; - - static void st_bind_program( GLcontext *ctx, GLenum target, struct gl_program *prog ) @@ -62,8 +64,14 @@ static void st_bind_program( GLcontext *ctx, st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; break; } + st->dirty.st |= ST_NEW_LINKAGE; } + +/** + * Called via ctx->Driver.UseProgram() to bind a linked GLSL program + * (vertex shader + fragment shader). + */ static void st_use_program( GLcontext *ctx, GLuint program ) { @@ -71,6 +79,7 @@ static void st_use_program( GLcontext *ctx, st->dirty.st |= ST_NEW_VERTEX_PROGRAM; st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; + st->dirty.st |= ST_NEW_LINKAGE; } @@ -79,14 +88,13 @@ static struct gl_program *st_new_program( GLcontext *ctx, GLenum target, GLuint id ) { -// struct st_context *st = st_context(ctx); + struct st_context *st = st_context(ctx); switch (target) { case GL_VERTEX_PROGRAM_ARB: { struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program); - prog->id = program_id++; - prog->dirty = 1; + prog->serialNo = 1; #if defined(USE_X86_ASM) || defined(SLANG_X86) x86_init_func( &prog->sse2_program ); @@ -102,8 +110,7 @@ static struct gl_program *st_new_program( GLcontext *ctx, case GL_FRAGMENT_PROGRAM_NV: { struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program); - prog->id = program_id++; - prog->dirty = 1; + prog->serialNo = 1; #if defined(USE_X86_ASM) || defined(SLANG_X86) x86_init_func( &prog->sse2_program ); @@ -118,29 +125,40 @@ static struct gl_program *st_new_program( GLcontext *ctx, default: return _mesa_new_program(ctx, target, id); } + + st->dirty.st |= ST_NEW_LINKAGE; } + static void st_delete_program( GLcontext *ctx, struct gl_program *prog ) { + struct st_context *st = st_context(ctx); + switch( prog->Target ) { - case GL_VERTEX_PROGRAM_ARB: { + case GL_VERTEX_PROGRAM_ARB: + { + struct st_vertex_program *stvp = (struct st_vertex_program *) prog; #if defined(USE_X86_ASM) || defined(SLANG_X86) - struct st_vertex_program *p = (struct st_vertex_program *) prog; - - x86_release_func( &p->sse2_program ); + x86_release_func( &stvp->sse2_program ); #endif + st_remove_vertex_program(st, stvp); + } break; - } - case GL_FRAGMENT_PROGRAM_ARB: { + case GL_FRAGMENT_PROGRAM_ARB: + { + struct st_fragment_program *stfp + = (struct st_fragment_program *) prog; #if defined(USE_X86_ASM) || defined(SLANG_X86) - struct st_fragment_program *p = (struct st_fragment_program *) prog; - - x86_release_func( &p->sse2_program ); + x86_release_func( &stfp->sse2_program ); #endif + st_remove_fragment_program(st, stfp); + } break; + default: + assert(0); /* problem */ } - } + _mesa_delete_program( ctx, prog ); } @@ -160,27 +178,31 @@ static void st_program_string_notify( GLcontext *ctx, struct st_context *st = st_context(ctx); if (target == GL_FRAGMENT_PROGRAM_ARB) { - struct st_fragment_program *p = (struct st_fragment_program *)prog; + struct st_fragment_program *stfp = (struct st_fragment_program *) prog; if (prog == &ctx->FragmentProgram._Current->Base) st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; - p->id = program_id++; - p->param_state = p->Base.Base.Parameters->StateFlags; + stfp->serialNo++; + + stfp->param_state = stfp->Base.Base.Parameters->StateFlags; } else if (target == GL_VERTEX_PROGRAM_ARB) { - struct st_vertex_program *p = (struct st_vertex_program *)prog; + struct st_vertex_program *stvp = (struct st_vertex_program *) prog; if (prog == &ctx->VertexProgram._Current->Base) st->dirty.st |= ST_NEW_VERTEX_PROGRAM; - p->id = program_id++; - p->param_state = p->Base.Base.Parameters->StateFlags; + stvp->serialNo++; + + stvp->param_state = stvp->Base.Base.Parameters->StateFlags; /* Also tell tnl about it: */ _tnl_program_string(ctx, target, prog); } + + st->dirty.st |= ST_NEW_LINKAGE; } diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 2311bddc65..661d155e6d 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -53,9 +53,9 @@ static void setup_vertex_attribs(GLcontext *ctx) { struct pipe_context *pipe = ctx->st->pipe; -#if 0 - const uint inputAttrs = ctx->st->state.vs->inputs_read; - uint attr; + const struct cso_vertex_shader *vs = ctx->st->state.vs; + const struct st_vertex_program *stvp = ctx->st->vp; + uint slot; /* all attributes come from the default attribute buffer */ { @@ -67,20 +67,16 @@ setup_vertex_attribs(GLcontext *ctx) pipe->set_vertex_buffer(pipe, 0, &vbuffer); } - for (attr = 0; attr < 16; attr++) { + for (slot = 0; slot < vs->state.num_inputs; slot++) { struct pipe_vertex_element velement; + const GLuint attr = stvp->index_to_input[slot]; - if (inputAttrs & (1 << attr)) { - velement.src_offset = attr * 4 * sizeof(GLfloat); - velement.vertex_buffer_index = 0; - velement.dst_offset = 0; - velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - pipe->set_vertex_element(pipe, attr, &velement); - } + velement.src_offset = attr * 4 * sizeof(GLfloat); + velement.vertex_buffer_index = 0; + velement.dst_offset = 0; + velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + pipe->set_vertex_element(pipe, slot, &velement); } -#else - assert(0); -#endif } @@ -98,12 +94,11 @@ setup_feedback(GLcontext *ctx) feedback.discard = 1; feedback.num_attribs = 0; + /* feedback all results from vertex shader */ for (i = 0; i < vs->num_outputs; i++) { - if (1/***(1 << i) & outputAttrs***/) { - feedback.attrib[feedback.num_attribs] = i; - feedback.size[feedback.num_attribs] = 4; - feedback.num_attribs++; - } + feedback.attrib[feedback.num_attribs] = i; + feedback.size[feedback.num_attribs] = 4; + feedback.num_attribs++; } pipe->set_feedback_state(pipe, &feedback); @@ -261,13 +256,11 @@ update_rasterpos(GLcontext *ctx, static void st_RasterPos(GLcontext *ctx, const GLfloat v[4]) { - struct pipe_context *pipe = ctx->st->pipe; + const struct st_context *st = ctx->st; + struct pipe_context *pipe = st->pipe; float *buf_map; struct pipe_feedback_buffer fb_buf; - /** XXX TEMPORARILY DISABLE */ - return; - st_validate_state(ctx->st); /* setup vertex buffers */ @@ -277,7 +270,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4]) * Load the default attribute buffer with current attribs. */ { - struct pipe_buffer_handle *buf = ctx->st->default_attrib_buffer; + struct pipe_buffer_handle *buf = st->default_attrib_buffer; const unsigned size = sizeof(ctx->Current.Attrib); const void *data = ctx->Current.Attrib; /* colors, texcoords, etc */ @@ -313,17 +306,16 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4]) PIPE_BUFFER_FLAG_READ); /* extract values and update rasterpos state */ -#if 0 /* XXX update */ { - const uint outputAttrs = ctx->st->state.vs->outputs_written; + const GLuint *outputMapping = st->vertex_result_to_slot; const float *pos, *color0, *color1, *tex0; float *buf = buf_map; - assert(outputAttrs & (1 << TGSI_ATTRIB_POS)); + assert(outputMapping[VERT_RESULT_HPOS] != ~0); pos = buf; buf += 4; - if (outputAttrs & (1 << TGSI_ATTRIB_COLOR0)) { + if (outputMapping[VERT_RESULT_COL0] != ~0) { color0 = buf; buf += 4; } @@ -331,7 +323,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4]) color0 = ctx->Current.Attrib[VERT_ATTRIB_COLOR0]; } - if (outputAttrs & (1 << TGSI_ATTRIB_COLOR1)) { + if (outputMapping[VERT_RESULT_COL1] != ~0) { color1 = buf; buf += 4; } @@ -339,16 +331,23 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4]) color1 = ctx->Current.Attrib[VERT_ATTRIB_COLOR1]; } + if (outputMapping[VERT_RESULT_TEX0] != ~0) { + tex0 = buf; + buf += 4; + } + else { + tex0 = ctx->Current.Attrib[VERT_ATTRIB_TEX0]; + } + update_rasterpos(ctx, pos, color0, color1, tex0); } -#endif /* free vertex feedback buffer */ pipe->winsys->buffer_unmap(pipe->winsys, fb_buf.buffer); pipe->winsys->buffer_reference(pipe->winsys, &fb_buf.buffer, NULL); /* restore pipe state */ - pipe->set_feedback_state(pipe, &ctx->st->state.feedback); + pipe->set_feedback_state(pipe, &st->state.feedback); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 3713328eb1..24f0ff9aaf 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -45,6 +45,8 @@ struct cso_blend; #define ST_NEW_MESA 0x1 /* Mesa state has changed */ #define ST_NEW_FRAGMENT_PROGRAM 0x2 #define ST_NEW_VERTEX_PROGRAM 0x4 +#define ST_NEW_LINKAGE 0x8 + struct st_state_flags { GLuint mesa; @@ -119,8 +121,8 @@ struct st_context GLfloat polygon_offset_scale; /* ?? */ - /** Mapping from VERT_ATTRIB_x to post-transformed vertex slot */ - GLuint vertex_attrib_to_slot[VERT_RESULT_MAX]; + /** Mapping from VERT_RESULT_x to post-transformed vertex slot */ + const GLuint *vertex_result_to_slot; struct st_vertex_program *vp; /**< Currently bound vertex program */ struct st_fragment_program *fp; /**< Currently bound fragment program */ diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 419afa4e78..355dee574b 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -47,11 +47,11 @@ 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. */ + + GLuint serialNo; /** The program in TGSI format */ struct tgsi_token tokens[ST_FP_MAX_TOKENS]; - GLboolean dirty; #if defined(USE_X86_ASM) || defined(SLANG_X86) struct x86_function sse2_program; @@ -68,7 +68,8 @@ struct st_vertex_program { struct gl_vertex_program Base; /**< The Mesa vertex program */ GLboolean error; /**< Set if program is malformed for any reason. */ - GLuint id; /**< String id, for tracking ProgramStringNotify changes. */ + + GLuint serialNo; /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */ GLuint input_to_index[MAX_VERTEX_PROGRAM_ATTRIBS]; @@ -77,7 +78,6 @@ struct st_vertex_program /** The program in TGSI format */ struct tgsi_token tokens[ST_FP_MAX_TOKENS]; - GLboolean dirty; #if defined(USE_X86_ASM) || defined(SLANG_X86) struct x86_function sse2_program; @@ -90,7 +90,8 @@ struct st_vertex_program }; -extern void st_init_program_functions(struct dd_function_table *functions); +extern void +st_init_program_functions(struct dd_function_table *functions); static inline struct st_fragment_program * @@ -99,6 +100,7 @@ st_fragment_program( struct gl_fragment_program *fp ) return (struct st_fragment_program *)fp; } + static inline struct st_vertex_program * st_vertex_program( struct gl_vertex_program *vp ) { @@ -107,13 +109,18 @@ st_vertex_program( struct gl_vertex_program *vp ) extern const struct cso_fragment_shader * -st_translate_fragment_shader(struct st_context *st, - struct st_fragment_program *fp); +st_translate_fragment_program(struct st_context *st, + struct st_fragment_program *fp, + const GLuint inputMapping[], + struct tgsi_token *tokens, + GLuint maxTokens); extern const struct cso_vertex_shader * -st_translate_vertex_shader(struct st_context *st, - struct st_vertex_program *vp); - +st_translate_vertex_program(struct st_context *st, + struct st_vertex_program *vp, + const GLuint vert_output_to_slot[], + struct tgsi_token *tokens, + GLuint maxTokens); #endif -- cgit v1.2.3 From 0dfa5506a318b202ac955a59cc7c9b22b5ff3867 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 25 Sep 2007 16:56:35 -0600 Subject: st_draw_vertices() no longer needs attribs[] array parameter --- src/mesa/state_tracker/st_cb_clear.c | 6 +----- src/mesa/state_tracker/st_cb_drawpixels.c | 13 ++----------- src/mesa/state_tracker/st_draw.c | 5 ++--- src/mesa/state_tracker/st_draw.h | 2 +- 4 files changed, 6 insertions(+), 20 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 367ae06cf3..3a70d2f121 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -223,10 +223,6 @@ draw_quad(GLcontext *ctx, float x0, float y0, float x1, float y1, GLfloat z, const GLfloat color[4]) { - static const GLuint attribs[2] = { - 0, /* pos */ - 3 /* color */ - }; GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */ GLuint i; @@ -253,7 +249,7 @@ draw_quad(GLcontext *ctx, verts[i][1][3] = color[3]; } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, attribs); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 49120a4dea..9efd718834 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -312,10 +312,6 @@ static void draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, GLfloat x1, GLfloat y1) { - static const GLuint attribs[2] = { - 0, /* pos */ - 8 /* tex0 */ - }; GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */ GLuint i; @@ -351,7 +347,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, verts[i][1][3] = 1.0; /*Q*/ } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, attribs); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2); } @@ -359,11 +355,6 @@ static void draw_quad_colored(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, GLfloat x1, GLfloat y1, const GLfloat *color) { - static const GLuint attribs[3] = { - 0, /* pos */ - 1, /* color */ - 8 /* tex0 */ - }; GLfloat verts[4][3][4]; /* four verts, three attribs, XYZW */ GLuint i; @@ -403,7 +394,7 @@ draw_quad_colored(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, verts[i][2][3] = 1.0; /*Q*/ } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 3, attribs); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 3); } diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 0f45bf579a..ce5bf0c8a9 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -316,7 +316,7 @@ st_draw_vbo(GLcontext *ctx, void st_draw_vertices(GLcontext *ctx, unsigned prim, unsigned numVertex, float *verts, - unsigned numAttribs, const unsigned attribs[]) + unsigned numAttribs) { const float width = ctx->DrawBuffer->Width; const float height = ctx->DrawBuffer->Height; @@ -328,7 +328,6 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, unsigned i; assert(numAttribs > 0); - assert(attribs[0] == 0); /* position */ /* convert to clip coords */ for (i = 0; i < numVertex; i++) { @@ -356,7 +355,7 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, velement.vertex_buffer_index = 0; velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; velement.dst_offset = 0; - pipe->set_vertex_element(pipe, i/**attribs[i]**/, &velement); + pipe->set_vertex_element(pipe, i, &velement); } /* draw */ diff --git a/src/mesa/state_tracker/st_draw.h b/src/mesa/state_tracker/st_draw.h index 1fcd1b7e6b..89ee790c57 100644 --- a/src/mesa/state_tracker/st_draw.h +++ b/src/mesa/state_tracker/st_draw.h @@ -62,7 +62,7 @@ st_feedback_draw_vbo(GLcontext *ctx, void st_draw_vertices(GLcontext *ctx, unsigned prim, unsigned numVertex, float *verts, - unsigned numAttribs, const unsigned attribs[]); + unsigned numAttribs); #endif -- cgit v1.2.3 From 636480cc9c7836daf879cb45644900922cf31f47 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 28 Sep 2007 15:39:09 -0600 Subject: Instead of linked program pairs, keep a list of vertex programs translated for each fragment program. --- src/mesa/state_tracker/st_atom_shader.c | 337 ++++++++++-------------------- src/mesa/state_tracker/st_cb_clear.c | 4 +- src/mesa/state_tracker/st_cb_drawpixels.c | 4 +- src/mesa/state_tracker/st_cb_program.c | 12 ++ src/mesa/state_tracker/st_program.h | 30 ++- 5 files changed, 149 insertions(+), 238 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 9bba78f7a1..d7a89d1e95 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -51,105 +51,56 @@ #include "st_atom_shader.h" - /** - * Structure to describe a (vertex program, fragment program) pair - * which is linked together (used together to render something). This - * linkage basically servers the same purpose as the OpenGL Shading - * Language linker, but also applies to ARB programs and Mesa's - * fixed-function-generated programs. - * - * More background: - * - * The translation from Mesa programs to TGSI programs depends on the - * linkage between the vertex program and the fragment program. This is - * because we tightly pack the inputs and outputs of shaders into - * consecutive "slots". - * - * Suppose an app uses one vertex program "VP" (outputting pos, color and tex0) - * and two fragment programs: - * FP1: uses tex0 input only (input slot 0) - * FP2: uses color input only (input slot 0) - * - * When VP is used with FP1 we want VP.output[2] to match FP1.input[0], but - * when VP is used with FP2 we want VP.output[1] to match FP1.input[0]. - * - * We don't want to re-translate the vertex and/or fragment programs - * each time the VP/FP bindings/linkings change. The solution is this - * structure which stores the translated TGSI shaders on a per-linkage - * basis. - * + * This represents a vertex program, especially translated to match + * the inputs of a particular fragment shader. */ -struct linked_program_pair +struct translated_vertex_program { - struct st_vertex_program *vprog; /**< never changes */ - struct st_fragment_program *fprog; /**< never changes */ + /** The fragment shader "signature" this vertex shader is meant for: */ + GLbitfield frag_inputs; - struct tgsi_token vs_tokens[ST_FP_MAX_TOKENS]; - struct tgsi_token fs_tokens[ST_FP_MAX_TOKENS]; + /** Compared against master vertex program's serialNo: */ + GLuint serialNo; - const struct cso_vertex_shader *vs; - const struct cso_fragment_shader *fs; - - GLuint vertSerialNo, fragSerialNo; + /** Maps VERT_RESULT_x to slot */ + GLuint output_to_slot[VERT_RESULT_MAX]; - /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */ - GLuint vp_input_to_index[MAX_VERTEX_PROGRAM_ATTRIBS]; - /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */ - GLuint vp_index_to_input[MAX_VERTEX_PROGRAM_ATTRIBS]; + /** The program in TGSI format */ + struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; - GLuint vp_result_to_slot[VERT_RESULT_MAX]; + /** Pointer to the translated, cached vertex shader */ + const struct cso_vertex_shader *vs; - struct linked_program_pair *next; + struct translated_vertex_program *next; /**< next in linked list */ }; -/** XXX temporary - use some kind of hash table instead */ -static struct linked_program_pair *Pairs = NULL; - - -static void -find_and_remove(struct gl_program *prog) -{ - struct linked_program_pair *pair, *prev = NULL, *next; - for (pair = Pairs; pair; pair = next) { - next = pair->next; - if (pair->vprog == (struct st_vertex_program *) prog || - pair->fprog == (struct st_fragment_program *) prog) { - /* unlink */ - if (prev) - prev->next = next; - else - Pairs = next; - /* delete pair->vs */ - /* delete pair->fs */ - free(pair); - } - else { - prev = pair; - } - } -} - /** - * Delete any known program pairs that use the given vertex program. + * Free data hanging off the st vert prog. */ void st_remove_vertex_program(struct st_context *st, struct st_vertex_program *stvp) { - find_and_remove(&stvp->Base.Base); + /* no-op, for now? */ } /** - * Delete any known program pairs that use the given fragment program. + * Free data hanging off the st frag prog. */ void st_remove_fragment_program(struct st_context *st, struct st_fragment_program *stfp) { - find_and_remove(&stfp->Base.Base); + struct translated_vertex_program *xvp, *next; + + for (xvp = stfp->vertex_programs; xvp; xvp = next) { + next = xvp->next; + /* XXX free xvp->vs */ + free(xvp); + } } @@ -187,182 +138,122 @@ vp_out_to_fp_in(GLuint vertResult) /** - * Examine the outputs written by a vertex program and the inputs read - * by a fragment program to determine which match up and where they - * should be mapped into the generic shader output/input slots. - * \param vert_output_map returns the vertex output register mapping - * \param frag_input_map returns the fragment input register mapping + * Find a translated vertex program that corresponds to stvp and + * has outputs matched to stfp's inputs. + * This performs vertex and fragment translation (to TGSI) when needed. */ -static GLuint -link_outputs_to_inputs(GLbitfield outputsWritten, - GLbitfield inputsRead, - GLuint vert_output_map[], - GLuint frag_input_map[]) +static struct translated_vertex_program * +find_translated_vp(struct st_context *st, + struct st_vertex_program *stvp, + struct st_fragment_program *stfp) { static const GLuint UNUSED = ~0; - GLint vert_slot_to_attr[50], frag_slot_to_attr[50]; - GLuint outAttr, inAttr; - GLuint numIn = 0, dummySlot; - - for (inAttr = 0; inAttr < FRAG_ATTRIB_MAX; inAttr++) { - if (inputsRead & (1 << inAttr)) { - frag_input_map[inAttr] = numIn; - frag_slot_to_attr[numIn] = inAttr; - numIn++; - } - else { - frag_input_map[inAttr] = UNUSED; - } - } + struct translated_vertex_program *xvp; + const GLbitfield fragInputsRead + = stfp->Base.Base.InputsRead | FRAG_BIT_WPOS; - for (outAttr = 0; outAttr < VERT_RESULT_MAX; outAttr++) { - if (outputsWritten & (1 << outAttr)) { - /* see if the frag prog wants this vert output */ - GLint fpIn = vp_out_to_fp_in(outAttr); + /* + * Translate fragment program if needed. + */ + if (!stfp->fs) { + GLuint inAttr, numIn = 0; - if (fpIn >= 0) { - GLuint frag_slot = frag_input_map[fpIn]; - vert_output_map[outAttr] = frag_slot; - vert_slot_to_attr[frag_slot] = outAttr; + for (inAttr = 0; inAttr < FRAG_ATTRIB_MAX; inAttr++) { + if (fragInputsRead & (1 << inAttr)) { + stfp->input_to_slot[inAttr] = numIn; + numIn++; } else { - vert_output_map[outAttr] = UNUSED; + stfp->input_to_slot[inAttr] = UNUSED; } } - else { - vert_output_map[outAttr] = UNUSED; - } - } - /* - * We'll map all unused vertex program outputs to this slot. - * We'll also map all undefined fragment program inputs to this slot. - */ - dummySlot = numIn; + stfp->num_input_slots = numIn; - /* Map vert program outputs that aren't used to the dummy slot */ - for (outAttr = 0; outAttr < VERT_RESULT_MAX; outAttr++) { - if (outputsWritten & (1 << outAttr)) { - if (vert_output_map[outAttr] == UNUSED) - vert_output_map[outAttr] = dummySlot; - } + (void) st_translate_fragment_program(st, stfp, + stfp->input_to_slot, + stfp->tokens, + ST_MAX_SHADER_TOKENS); + assert(stfp->fs); } - /* Map frag program inputs that aren't defined to the dummy slot */ - for (inAttr = 0; inAttr < FRAG_ATTRIB_MAX; inAttr++) { - if (inputsRead & (1 << inAttr)) { - if (frag_input_map[inAttr] == UNUSED) - frag_input_map[inAttr] = dummySlot; - } - } -#if 0 - printf("vOut W slot\n"); - for (outAttr = 0; outAttr < VERT_RESULT_MAX; outAttr++) { - printf("%4d %c %4d\n", outAttr, - " *"[(outputsWritten >> outAttr) & 1], - vert_output_map[outAttr]); - } - printf("vIn R slot\n"); - for (inAttr = 0; inAttr < FRAG_ATTRIB_MAX; inAttr++) { - printf("%3d %c %4d\n", inAttr, - " *"[(inputsRead >> inAttr) & 1], - frag_input_map[inAttr]); + /* See if we've got a translated vertex program whose outputs match + * the fragment program's inputs. + * XXX This could be a hash lookup, using InputsRead as the key. + */ + for (xvp = stfp->vertex_programs; xvp; xvp = xvp->next) { + if (xvp->frag_inputs == stfp->Base.Base.InputsRead) { + break; + } } -#endif - return numIn; -} + /* No? Allocate translated vp object now */ + if (!xvp) { + xvp = CALLOC_STRUCT(translated_vertex_program); + xvp->frag_inputs = fragInputsRead; + xvp->next = stfp->vertex_programs; + stfp->vertex_programs = xvp; + } -static struct linked_program_pair * -lookup_program_pair(struct st_context *st, - struct st_vertex_program *vprog, - struct st_fragment_program *fprog) -{ - struct linked_program_pair *pair; - - /* search */ - for (pair = Pairs; pair; pair = pair->next) { - if (pair->vprog == vprog && pair->fprog == fprog) { - /* found it */ - break; + /* See if we need to translate vertex program to TGSI form */ + if (xvp->serialNo != stvp->serialNo) { + GLuint outAttr, dummySlot; + const GLbitfield outputsWritten = stvp->Base.Base.OutputsWritten; + + /* Compute mapping of vertex program outputs to slots, which depends + * on the fragment program's input->slot mapping. + */ + for (outAttr = 0; outAttr < VERT_RESULT_MAX; outAttr++) { + /* set default: */ + xvp->output_to_slot[outAttr] = UNUSED; + + if (outputsWritten & (1 << outAttr)) { + /* see if the frag prog wants this vert output */ + GLint fpIn = vp_out_to_fp_in(outAttr); + if (fpIn >= 0) { + xvp->output_to_slot[outAttr] = stfp->input_to_slot[fpIn]; + } + } } - } - /* - * Examine the outputs of the vertex shader and the inputs of the - * fragment shader to determine how to match both to a common set - * of slots. - */ - if (!pair) { - pair = CALLOC_STRUCT(linked_program_pair); - if (pair) { - pair->vprog = vprog; - pair->fprog = fprog; + /* Unneeded vertex program outputs will go to this slot. + * We could use this info to do dead code elimination in the + * vertex program. + */ + dummySlot = stfp->num_input_slots; + + /* Map vert program outputs that aren't used to the dummy slot */ + for (outAttr = 0; outAttr < VERT_RESULT_MAX; outAttr++) { + if (outputsWritten & (1 << outAttr)) { + if (xvp->output_to_slot[outAttr] == UNUSED) + xvp->output_to_slot[outAttr] = dummySlot; + } } - } - return pair; -} + xvp->vs = st_translate_vertex_program(st, stvp, + xvp->output_to_slot, + xvp->tokens, + ST_MAX_SHADER_TOKENS); + assert(xvp->vs); + stvp->vs = NULL; /* don't want to use this */ -static void -link_shaders(struct st_context *st, struct linked_program_pair *pair) -{ - struct st_vertex_program *vprog = pair->vprog; - struct st_fragment_program *fprog = pair->fprog; - - assert(vprog); - assert(fprog); - - if (pair->vertSerialNo != vprog->serialNo || - pair->fragSerialNo != fprog->serialNo) { - /* re-link and re-translate */ - GLuint vert_output_mapping[VERT_RESULT_MAX]; - GLuint frag_input_mapping[FRAG_ATTRIB_MAX]; - - link_outputs_to_inputs(vprog->Base.Base.OutputsWritten, - fprog->Base.Base.InputsRead | FRAG_BIT_WPOS, - vert_output_mapping, - frag_input_mapping); - - /* xlate vp to vs + vs tokens */ - st_translate_vertex_program(st, vprog, - vert_output_mapping, - pair->vs_tokens, ST_FP_MAX_TOKENS); - - pair->vprog = vprog; - /* temp hacks */ - pair->vs = vprog->vs; - vprog->vs = NULL; - - - /* xlate fp to fs + fs tokens */ - st_translate_fragment_program(st, fprog, - frag_input_mapping, - pair->fs_tokens, ST_FP_MAX_TOKENS); - pair->fprog = fprog; - /* temp hacks */ - pair->fs = fprog->fs; - fprog->fs = NULL; - - /* save pair */ - pair->next = Pairs; - Pairs = pair; - - pair->vertSerialNo = vprog->serialNo; - pair->fragSerialNo = fprog->serialNo; + /* translated VP is up to date now */ + xvp->serialNo = stvp->serialNo; } + + return xvp; } static void update_linkage( struct st_context *st ) { - struct linked_program_pair *pair; struct st_vertex_program *stvp; struct st_fragment_program *stfp; + struct translated_vertex_program *xvp; /* find active shader and params -- Should be covered by * ST_NEW_VERTEX_PROGRAM @@ -392,23 +283,17 @@ update_linkage( struct st_context *st ) stfp = st_fragment_program(st->ctx->FragmentProgram._Current); } + xvp = find_translated_vp(st, stvp, stfp); - pair = lookup_program_pair(st, stvp, stfp); - assert(pair); - link_shaders(st, pair); - - - /* Bind the vertex program and TGSI shader */ st->vp = stvp; - st->state.vs = pair->vs; + st->state.vs = xvp->vs; st->pipe->bind_vs_state(st->pipe, st->state.vs->data); - /* Bind the fragment program and TGSI shader */ st->fp = stfp; - st->state.fs = pair->fs; + st->state.fs = stfp->fs; st->pipe->bind_fs_state(st->pipe, st->state.fs->data); - st->vertex_result_to_slot = pair->vp_result_to_slot; + st->vertex_result_to_slot = xvp->output_to_slot; } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 3a70d2f121..cca4fa19a9 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -156,7 +156,7 @@ make_frag_shader(struct st_context *st) stfp = (struct st_fragment_program *) p; st_translate_fragment_program(st, stfp, NULL, - stfp->tokens, ST_FP_MAX_TOKENS); + stfp->tokens, ST_MAX_SHADER_TOKENS); return stfp; } @@ -205,7 +205,7 @@ make_vertex_shader(struct st_context *st) stvp = (struct st_vertex_program *) p; st_translate_vertex_program(st, stvp, NULL, - stvp->tokens, ST_FP_MAX_TOKENS); + stvp->tokens, ST_MAX_SHADER_TOKENS); assert(stvp->vs); return stvp; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index fb89ceef8c..f58b5d947d 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -131,7 +131,7 @@ make_fragment_shader(struct st_context *st, GLboolean bitmapMode) stfp = (struct st_fragment_program *) p; st_translate_fragment_program(st, stfp, NULL, - stfp->tokens, ST_FP_MAX_TOKENS); + stfp->tokens, ST_MAX_SHADER_TOKENS); return stfp; } @@ -203,7 +203,7 @@ make_vertex_shader(struct st_context *st, GLboolean passColor) stvp = (struct st_vertex_program *) p; st_translate_vertex_program(st, stvp, NULL, - stvp->tokens, ST_FP_MAX_TOKENS); + stvp->tokens, ST_MAX_SHADER_TOKENS); return stvp; } diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 3a7ce9405e..5c00dd1ae1 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -165,6 +165,12 @@ static void st_program_string_notify( GLcontext *ctx, stfp->serialNo++; + if (stfp->fs) { + /* free the TGSI code */ + // cso_delete(stfp->vs); + stfp->fs = NULL; + } + stfp->param_state = stfp->Base.Base.Parameters->StateFlags; } else if (target == GL_VERTEX_PROGRAM_ARB) { @@ -172,6 +178,12 @@ static void st_program_string_notify( GLcontext *ctx, stvp->serialNo++; + if (stvp->vs) { + /* free the TGSI code */ + // cso_delete(stfp->vs); + stvp->vs = NULL; + } + stvp->param_state = stvp->Base.Base.Parameters->StateFlags; /* Also tell tnl about it: diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 2b79201313..a714f3f5b0 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -38,20 +38,28 @@ #include "pipe/tgsi/exec/tgsi_token.h" #include "x86/rtasm/x86sse.h" -#define ST_FP_MAX_TOKENS 1024 + +#define ST_MAX_SHADER_TOKENS 1024 + struct cso_fragment_shader; struct cso_vertex_shader; +struct translated_vertex_program; + +/** + * Derived from Mesa gl_fragment_program: + */ struct st_fragment_program { struct gl_fragment_program Base; - GLboolean error; /* If program is malformed for any reason. */ - GLuint serialNo; + GLuint input_to_slot[FRAG_ATTRIB_MAX]; /**< Maps FRAG_ATTRIB_x to slot */ + GLuint num_input_slots; + /** The program in TGSI format */ - struct tgsi_token tokens[ST_FP_MAX_TOKENS]; + struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; #if defined(__i386__) || defined(__386__) struct x86_function sse2_program; @@ -61,23 +69,29 @@ struct st_fragment_program const struct cso_fragment_shader *fs; GLuint param_state; + + /** List of vertex programs which have been translated such that their + * outputs match this fragment program's inputs. + */ + struct translated_vertex_program *vertex_programs; }; +/** + * Derived from Mesa gl_fragment_program: + */ struct st_vertex_program { struct gl_vertex_program Base; /**< The Mesa vertex program */ - GLboolean error; /**< Set if program is malformed for any reason. */ - GLuint serialNo; /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */ GLuint input_to_index[MAX_VERTEX_PROGRAM_ATTRIBS]; /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */ - GLuint index_to_input[MAX_VERTEX_PROGRAM_ATTRIBS]; + GLuint index_to_input[PIPE_MAX_SHADER_INPUTS]; /** The program in TGSI format */ - struct tgsi_token tokens[ST_FP_MAX_TOKENS]; + struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; /** Pointer to the corresponding cached shader */ const struct cso_vertex_shader *vs; -- cgit v1.2.3 From e9df20c2fa7df8458a9f0781f31de51c4944d41f Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Wed, 3 Oct 2007 20:37:59 +0200 Subject: Some minor cleanups. --- src/mesa/state_tracker/st_cb_clear.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index cca4fa19a9..a854378b18 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -264,7 +264,7 @@ clear_with_quad(GLcontext *ctx, GLboolean color, GLboolean depth, GLboolean stencil) { struct st_context *st = ctx->st; - struct pipe_context *pipe = ctx->st->pipe; + struct pipe_context *pipe = st->pipe; const GLfloat x0 = ctx->DrawBuffer->_Xmin; const GLfloat y0 = ctx->DrawBuffer->_Ymin; const GLfloat x1 = ctx->DrawBuffer->_Xmax; @@ -321,7 +321,7 @@ clear_with_quad(GLcontext *ctx, depth_stencil.stencil.value_mask[0] = 0xff; depth_stencil.stencil.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; } - cso = st_cached_depth_stencil_state(ctx->st, &depth_stencil); + cso = st_cached_depth_stencil_state(st, &depth_stencil); pipe->bind_depth_stencil_state(pipe, cso->data); } @@ -337,7 +337,7 @@ clear_with_quad(GLcontext *ctx, if (ctx->Scissor.Enabled) raster.scissor = 1; #endif - cso = st_cached_rasterizer_state(ctx->st, &raster); + cso = st_cached_rasterizer_state(st, &raster); pipe->bind_rasterizer_state(pipe, cso->data); } @@ -385,7 +385,7 @@ clear_with_quad(GLcontext *ctx, pipe->bind_fs_state(pipe, st->state.fs->data); pipe->bind_vs_state(pipe, st->state.vs->data); pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); - pipe->set_viewport_state(pipe, &ctx->st->state.viewport); + pipe->set_viewport_state(pipe, &st->state.viewport); /* OR: st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); */ @@ -491,8 +491,7 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) assert(strb->surface->format); - if (ctx->Scissor.Enabled || - (isDS && ctx->DrawBuffer->Visual.stencilBits > 0)) { + if (check_clear_depth_with_quad(ctx, rb)) { /* scissoring or we have a combined depth/stencil buffer */ clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE); } -- cgit v1.2.3 From 45700ac280ddd5e23c57763129257d7fba171d9d Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 16 Oct 2007 18:45:42 -0600 Subject: use new st_clear_accum_buffer() function --- src/mesa/state_tracker/st_cb_clear.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index a854378b18..4f269ed3f7 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -37,6 +37,7 @@ #include "st_atom.h" #include "st_cache.h" #include "st_context.h" +#include "st_cb_accum.h" #include "st_cb_clear.h" #include "st_cb_fbo.h" #include "st_draw.h" @@ -461,28 +462,6 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) } -static void -clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) -{ - struct st_renderbuffer *strb = st_renderbuffer(rb); - - if (!ctx->Scissor.Enabled) { - /* clear whole buffer w/out masking */ - GLuint clearValue - = color_value(strb->surface->format, ctx->Accum.ClearColor); - /* Note that clearValue is 32 bits but the accum buffer will - * typically be 64bpp... - */ - ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); - } - else { - /* scissoring */ - /* XXX point framebuffer.cbufs[0] at the accum buffer */ - clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE); - } -} - - static void clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { @@ -605,8 +584,8 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) } if (mask & BUFFER_BIT_ACCUM) { - clear_accum_buffer(ctx, - ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer); + st_clear_accum_buffer(ctx, + ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer); } if ((mask & BUFFER_BITS_DS) == BUFFER_BITS_DS && depthRb == stencilRb) { -- cgit v1.2.3 From 2dd27cfdd981b3b2c973066082b1168c4cb6f42c Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 17 Oct 2007 11:24:06 -0600 Subject: Fix viewport Z scale/bias to get the right Z values from drawing the quad. --- src/mesa/state_tracker/st_cb_clear.c | 6 +++--- src/mesa/state_tracker/st_cb_drawpixels.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 4f269ed3f7..c0ea1a4bf6 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -326,7 +326,7 @@ clear_with_quad(GLcontext *ctx, pipe->bind_depth_stencil_state(pipe, cso->data); } - /* setup state: nothing */ + /* rasterizer state: nothing */ { struct pipe_rasterizer_state raster; const struct cso_rasterizer *cso; @@ -367,11 +367,11 @@ clear_with_quad(GLcontext *ctx, struct pipe_viewport_state vp; vp.scale[0] = 0.5 * width; vp.scale[1] = -0.5 * height; - vp.scale[2] = 0.5; + vp.scale[2] = 1.0; vp.scale[3] = 1.0; vp.translate[0] = 0.5 * width; vp.translate[1] = 0.5 * height; - vp.translate[2] = 0.5; + vp.translate[2] = 0.0; vp.translate[3] = 0.0; pipe->set_viewport_state(pipe, &vp); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 97d4f41ed9..9031ef46df 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -570,11 +570,11 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, struct pipe_viewport_state vp; vp.scale[0] = 0.5 * width; vp.scale[1] = -0.5 * height; - vp.scale[2] = 0.5; + vp.scale[2] = 1.0; vp.scale[3] = 1.0; vp.translate[0] = 0.5 * width; vp.translate[1] = 0.5 * height; - vp.translate[2] = 0.5; + vp.translate[2] = 0.0; vp.translate[3] = 0.0; pipe->set_viewport_state(pipe, &vp); } -- cgit v1.2.3 From f953c223df26293f955f7d0621a6f917e9cc9768 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 17 Oct 2007 16:23:25 -0600 Subject: remove #include vf.h --- src/mesa/state_tracker/st_cb_clear.c | 2 -- src/mesa/state_tracker/st_cb_drawpixels.c | 1 - src/mesa/state_tracker/st_cb_feedback.c | 1 - src/mesa/state_tracker/st_cb_rasterpos.c | 1 - 4 files changed, 5 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index c0ea1a4bf6..2e7d9f1a30 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -51,8 +51,6 @@ #include "pipe/tgsi/mesa/mesa_to_tgsi.h" -#include "vf/vf.h" - diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 9031ef46df..bb8a083883 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -47,7 +47,6 @@ #include "pipe/p_defines.h" #include "pipe/tgsi/mesa/mesa_to_tgsi.h" #include "shader/prog_instruction.h" -#include "vf/vf.h" diff --git a/src/mesa/state_tracker/st_cb_feedback.c b/src/mesa/state_tracker/st_cb_feedback.c index 923e1cdb89..a9fd2579a2 100644 --- a/src/mesa/state_tracker/st_cb_feedback.c +++ b/src/mesa/state_tracker/st_cb_feedback.c @@ -55,7 +55,6 @@ #include "pipe/p_defines.h" #include "pipe/p_winsys.h" #include "pipe/cso_cache/cso_cache.h" -#include "vf/vf.h" #include "pipe/draw/draw_context.h" #include "pipe/draw/draw_private.h" diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 653801001a..eb6ee51939 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -46,7 +46,6 @@ #include "pipe/p_defines.h" #include "pipe/p_winsys.h" #include "shader/prog_instruction.h" -#include "vf/vf.h" -- cgit v1.2.3 From 616112ea2e0eefea356be228bff8754ee955d8b3 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 25 Oct 2007 19:19:51 -0600 Subject: silence warning --- src/mesa/state_tracker/st_cb_clear.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 2e7d9f1a30..30672e0dd4 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -464,7 +464,9 @@ static void clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *strb = st_renderbuffer(rb); + /* const GLboolean isDS = is_depth_stencil_format(strb->surface->format); + */ assert(strb->surface->format); -- cgit v1.2.3 From ef6940f17220f1149dce6daf548bd0103d91a281 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 27 Oct 2007 09:03:15 -0600 Subject: Move mesa_to_tgsi.[ch] to state_tracker --- src/mesa/sources | 4 +--- src/mesa/state_tracker/st_atom_shader.c | 2 +- src/mesa/state_tracker/st_cb_clear.c | 2 +- src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_cb_program.c | 1 - src/mesa/state_tracker/st_mesa_to_tgsi.c | 37 ++++++++++++++++++++++++++-- src/mesa/state_tracker/st_mesa_to_tgsi.h | 40 ++++++++++++++++++++++++++----- src/mesa/state_tracker/st_program.c | 2 +- 8 files changed, 74 insertions(+), 16 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/sources b/src/mesa/sources index 6d1ba9b9bd..30d3c32b83 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -186,8 +186,6 @@ TGSIEXEC_SOURCES = \ TGSIDECO_SOURCES = \ pipe/tgsi/deco/deco_caps.c -TGSIMESA_SOURCES = \ - pipe/tgsi/mesa/mesa_to_tgsi.c ifeq ($(MESA_LLVM),1) LLVMTGSI_SOURCES = \ @@ -235,6 +233,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_debug.c \ state_tracker/st_draw.c \ state_tracker/st_format.c \ + state_tracker/st_mesa_to_tgsi.c \ state_tracker/st_program.c \ state_tracker/st_mipmap_tree.c @@ -389,7 +388,6 @@ SOLO_SOURCES = \ $(DRAW_SOURCES) \ $(TGSIEXEC_SOURCES) \ $(TGSIDECO_SOURCES) \ - $(TGSIMESA_SOURCES) \ $(STATECACHE_SOURCES) \ $(STATETRACKER_SOURCES) \ $(TNL_SOURCES) \ diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 919461bcb8..92ca22851e 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -41,7 +41,6 @@ #include "main/mtypes.h" #include "pipe/p_context.h" -#include "pipe/tgsi/mesa/mesa_to_tgsi.h" #include "pipe/tgsi/exec/tgsi_core.h" #include "st_context.h" @@ -49,6 +48,7 @@ #include "st_atom.h" #include "st_program.h" #include "st_atom_shader.h" +#include "st_mesa_to_tgsi.h" /** diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 30672e0dd4..2c79e2890d 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -43,13 +43,13 @@ #include "st_draw.h" #include "st_program.h" #include "st_public.h" +#include "st_mesa_to_tgsi.h" #include "pipe/p_context.h" #include "pipe/p_state.h" #include "pipe/p_defines.h" #include "pipe/p_winsys.h" -#include "pipe/tgsi/mesa/mesa_to_tgsi.h" diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 5d8890e022..896ba2b905 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -45,10 +45,10 @@ #include "st_cb_texture.h" #include "st_draw.h" #include "st_format.h" +#include "st_mesa_to_tgsi.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_winsys.h" -#include "pipe/tgsi/mesa/mesa_to_tgsi.h" #include "shader/prog_instruction.h" diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 26609e9645..a330c1c922 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -43,7 +43,6 @@ #include "st_program.h" #include "st_atom_shader.h" -#include "pipe/tgsi/mesa/tgsi_mesa.h" /** diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index 2c33f26d48..131e50bece 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -1,6 +1,39 @@ +/************************************************************************** + * + * 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 + * Michal Krol + */ + + #include "tgsi_platform.h" -#include "tgsi_mesa.h" -#include "pipe/tgsi/mesa/mesa_to_tgsi.h" +#include "pipe/tgsi/exec/tgsi_core.h" +#include "st_mesa_to_tgsi.h" #include "shader/prog_parameter.h" #define TGSI_DEBUG 0 diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.h b/src/mesa/state_tracker/st_mesa_to_tgsi.h index 13372d75fd..941a75ab05 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.h +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.h @@ -1,9 +1,37 @@ -#if !defined MESA_TO_TGSI_H -#define MESA_TO_TGSI_H +/************************************************************************** + * + * 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_MESA_TO_TGSI_H +#define ST_MESA_TO_TGSI_H #if defined __cplusplus extern "C" { -#endif // defined __cplusplus +#endif struct tgsi_token; @@ -25,8 +53,8 @@ tgsi_translate_mesa_program( #if defined __cplusplus -} // extern "C" -#endif // defined __cplusplus +} /* extern "C" */ +#endif -#endif // !defined MESA_TO_TGSI_H +#endif /* ST_MESA_TO_TGSI_H */ diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 9fc0798ec5..8c61815b9b 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -37,7 +37,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/draw/draw_context.h" -#include "pipe/tgsi/mesa/mesa_to_tgsi.h" #include "pipe/tgsi/exec/tgsi_core.h" #include "pipe/llvm/llvmtgsi.h" @@ -45,6 +44,7 @@ #include "st_cache.h" #include "st_atom.h" #include "st_program.h" +#include "st_mesa_to_tgsi.h" #define TGSI_DEBUG 0 -- cgit v1.2.3 From 187b631b6b3c504fa334e33f4b1af433b6232bac Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 7 Nov 2007 14:40:38 -0700 Subject: Float->uint conversion for PIPE_FORMAT_U_Z32 resulted in overflow in depth_value(). Special-case it. --- src/mesa/state_tracker/st_cb_clear.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 2c79e2890d..cb7e43fb8e 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -86,7 +86,11 @@ depth_value(GLuint pipeFormat, GLfloat value) val = (GLuint) (value * 0xffffff); break; case PIPE_FORMAT_U_Z32: - val = (GLuint) (value * 0xffffffff); + /* special-case to avoid overflow */ + if (value == 1.0) + val = 0xffffffff; + else + val = (GLuint) (value * 0xffffffff); break; case PIPE_FORMAT_S8_Z24: /*case PIPE_FORMAT_Z24_S8:*/ -- cgit v1.2.3 From c0b27149458c1c70b8664cdedb2be842229f4359 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 8 Nov 2007 14:40:29 -0700 Subject: simplify depth_value(), return proper value for Z16 format --- src/mesa/state_tracker/st_cb_clear.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index cb7e43fb8e..3e591170da 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -77,30 +77,24 @@ color_value(GLuint pipeFormat, const GLfloat color[4]) } -static GLuint +static uint depth_value(GLuint pipeFormat, GLfloat value) { - GLuint val; switch (pipeFormat) { case PIPE_FORMAT_U_Z16: - val = (GLuint) (value * 0xffffff); - break; + return (uint) (value * 0xffff); case PIPE_FORMAT_U_Z32: /* special-case to avoid overflow */ if (value == 1.0) - val = 0xffffffff; + return 0xffffffff; else - val = (GLuint) (value * 0xffffffff); - break; + return (uint) (value * 0xffffffff); case PIPE_FORMAT_S8_Z24: - /*case PIPE_FORMAT_Z24_S8:*/ - val = (GLuint) (value * 0xffffff); - break; + return (uint) (value * 0xffffff); default: - val = 0; assert(0); + return 0; } - return val; } @@ -480,7 +474,7 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) } else { /* simple clear of whole buffer */ - GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); + uint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } } -- cgit v1.2.3 From 0191570f024ba787799ca2bccd46549a8af74aa9 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 20 Nov 2007 08:30:10 -0700 Subject: initial support for PIPE_FORMAT_Z24_S8 --- src/mesa/pipe/p_format.h | 2 ++ src/mesa/state_tracker/st_cb_clear.c | 8 ++++---- src/mesa/state_tracker/st_cb_readpixels.c | 9 +++++++++ src/mesa/state_tracker/st_format.c | 9 +++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/p_format.h b/src/mesa/pipe/p_format.h index d478a6c58d..f42f987c4e 100644 --- a/src/mesa/pipe/p_format.h +++ b/src/mesa/pipe/p_format.h @@ -171,6 +171,7 @@ static INLINE uint pf_get(pipe_format_rgbazs_t f, uint shift, uint mask) #define _PIPE_FORMAT_RRRG _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G ) #define _PIPE_FORMAT_Z000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) #define _PIPE_FORMAT_SZ00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) +#define _PIPE_FORMAT_ZS00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) #define _PIPE_FORMAT_S000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) /** @@ -222,6 +223,7 @@ static INLINE uint pf_rev(pipe_format_ycbcr_t f) #define PIPE_FORMAT_U_Z32 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) /**< uint Z/depth */ #define PIPE_FORMAT_F_Z32 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) /**< float Z/depth */ #define PIPE_FORMAT_S8_Z24 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_SZ00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ) /**< 8-bit stencil + 24-bit Z */ +#define PIPE_FORMAT_Z24_S8 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_ZS00, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ) /**< 24-bit Z + 8-bit stencil */ #define PIPE_FORMAT_U_S8 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_S000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) /**< 8-bit stencil */ #define PIPE_FORMAT_R64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) #define PIPE_FORMAT_R64G64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 3e591170da..219a5afcbd 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -91,6 +91,8 @@ depth_value(GLuint pipeFormat, GLfloat value) return (uint) (value * 0xffffffff); case PIPE_FORMAT_S8_Z24: return (uint) (value * 0xffffff); + case PIPE_FORMAT_Z24_S8: + return ((uint) (value * 0xffffff)) << 8; default: assert(0); return 0; @@ -103,7 +105,7 @@ is_depth_stencil_format(GLuint pipeFormat) { switch (pipeFormat) { case PIPE_FORMAT_S8_Z24: - /*case PIPE_FORMAT_Z24_S8:*/ + case PIPE_FORMAT_Z24_S8: return GL_TRUE; default: return GL_FALSE; @@ -521,11 +523,9 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) case PIPE_FORMAT_S8_Z24: clearValue |= ctx->Stencil.Clear << 24; break; -#if 0 case PIPE_FORMAT_Z24_S8: - clearValue = (clearValue << 8) | clearVal; + clearValue |= clearValue | ctx->Stencil.Clear; break; -#endif default: assert(0); } diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index c347a0b688..2e7c01672a 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -100,6 +100,15 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } } break; + case PIPE_FORMAT_Z24_S8: + { + const uint *src = (uint *) stmap + srcY * ps->region->pitch + x; + GLint k; + for (k = 0; k < width; k++) { + values[k] = src[k] & 0xff; + } + } + break; default: assert(0); } diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index ddba650941..c6b5bc968f 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -320,6 +320,9 @@ default_depth_format( if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) { return PIPE_FORMAT_S8_Z24; } + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) { + return PIPE_FORMAT_Z24_S8; + } return PIPE_FORMAT_NONE; } @@ -486,6 +489,8 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_DEPTH_COMPONENT24: if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) return PIPE_FORMAT_S8_Z24; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) + return PIPE_FORMAT_Z24_S8; /* fall-through */ case GL_DEPTH_COMPONENT32: if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z32 )) @@ -503,12 +508,16 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, return PIPE_FORMAT_U_S8; if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) return PIPE_FORMAT_S8_Z24; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) + return PIPE_FORMAT_Z24_S8; return PIPE_FORMAT_NONE; case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) return PIPE_FORMAT_S8_Z24; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) + return PIPE_FORMAT_Z24_S8; return PIPE_FORMAT_NONE; default: -- cgit v1.2.3 From 146483d5412e14d6be63a9b9116ff683956ee294 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 5 Dec 2007 14:54:19 -0700 Subject: added PIPE_FORMAT_U_B8_G8_R8_A8 case in color_value() --- src/mesa/state_tracker/st_cb_clear.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 219a5afcbd..8ac6699776 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -69,9 +69,12 @@ color_value(GLuint pipeFormat, const GLfloat color[4]) return (r << 24) | (g << 16) | (b << 8) | a; case PIPE_FORMAT_U_A8_R8_G8_B8: return (a << 24) | (r << 16) | (g << 8) | b; + case PIPE_FORMAT_U_B8_G8_R8_A8: + return (b << 24) | (g << 16) | (r << 8) | a; case PIPE_FORMAT_U_R5_G6_B5: return ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); default: + assert(0); return 0; } } -- cgit v1.2.3 From d3e05111c8c8f87db7f577eb7096d65479a7e481 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 7 Dec 2007 16:15:14 -0700 Subject: Replace "duplicate" formats --- src/mesa/state_tracker/st_cb_clear.c | 24 ++++----- src/mesa/state_tracker/st_cb_drawpixels.c | 22 ++++---- src/mesa/state_tracker/st_cb_readpixels.c | 4 +- src/mesa/state_tracker/st_format.c | 88 +++++++++++++++---------------- 4 files changed, 69 insertions(+), 69 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 8ac6699776..1f0d1e6426 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -65,13 +65,13 @@ color_value(GLuint pipeFormat, const GLfloat color[4]) UNCLAMPED_FLOAT_TO_UBYTE(a, color[3]); switch (pipeFormat) { - case PIPE_FORMAT_U_R8_G8_B8_A8: + case PIPE_FORMAT_R8G8B8A8_UNORM: return (r << 24) | (g << 16) | (b << 8) | a; - case PIPE_FORMAT_U_A8_R8_G8_B8: + case PIPE_FORMAT_A8R8G8B8_UNORM: return (a << 24) | (r << 16) | (g << 8) | b; - case PIPE_FORMAT_U_B8_G8_R8_A8: + case PIPE_FORMAT_B8G8R8A8_UNORM: return (b << 24) | (g << 16) | (r << 8) | a; - case PIPE_FORMAT_U_R5_G6_B5: + case PIPE_FORMAT_R5G6B5_UNORM: return ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); default: assert(0); @@ -84,17 +84,17 @@ static uint depth_value(GLuint pipeFormat, GLfloat value) { switch (pipeFormat) { - case PIPE_FORMAT_U_Z16: + case PIPE_FORMAT_Z16_UNORM: return (uint) (value * 0xffff); - case PIPE_FORMAT_U_Z32: + case PIPE_FORMAT_Z32_UNORM: /* special-case to avoid overflow */ if (value == 1.0) return 0xffffffff; else return (uint) (value * 0xffffffff); - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: return (uint) (value * 0xffffff); - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: return ((uint) (value * 0xffffff)) << 8; default: assert(0); @@ -107,8 +107,8 @@ static GLboolean is_depth_stencil_format(GLuint pipeFormat) { switch (pipeFormat) { - case PIPE_FORMAT_S8_Z24: - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: return GL_TRUE; default: return GL_FALSE; @@ -523,10 +523,10 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); switch (strb->surface->format) { - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: clearValue |= ctx->Stencil.Clear << 24; break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: clearValue |= clearValue | ctx->Stencil.Clear; break; default: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index a61daffb20..464cf5ced3 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -734,42 +734,42 @@ compatible_formats(GLenum format, GLenum type, GLuint pipeFormat) static const GLuint one = 1; GLubyte littleEndian = *((GLubyte *) &one); - if (pipeFormat == PIPE_FORMAT_U_R8_G8_B8_A8 && + if (pipeFormat == PIPE_FORMAT_R8G8B8A8_UNORM && format == GL_RGBA && type == GL_UNSIGNED_BYTE && !littleEndian) { return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_R8_G8_B8_A8 && + else if (pipeFormat == PIPE_FORMAT_R8G8B8A8_UNORM && format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && littleEndian) { return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_A8_R8_G8_B8 && + else if (pipeFormat == PIPE_FORMAT_A8R8G8B8_UNORM && format == GL_BGRA && type == GL_UNSIGNED_BYTE && littleEndian) { return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_R5_G6_B5 && + else if (pipeFormat == PIPE_FORMAT_R5G6B5_UNORM && format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { /* endian don't care */ return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_R5_G6_B5 && + else if (pipeFormat == PIPE_FORMAT_R5G6B5_UNORM && format == GL_BGR && type == GL_UNSIGNED_SHORT_5_6_5_REV) { /* endian don't care */ return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_S8 && + else if (pipeFormat == PIPE_FORMAT_S8_UNORM && format == GL_STENCIL_INDEX && type == GL_UNSIGNED_BYTE) { return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_Z32 && + else if (pipeFormat == PIPE_FORMAT_Z32_UNORM && format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_INT) { return GL_TRUE; @@ -888,7 +888,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, memcpy(dest, values, spanWidth); } break; - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: { uint *dest = (uint *) stmap + spanY * ps->pitch + spanX; GLint k; @@ -998,8 +998,8 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, cpp = 1; comp = 0; } - else if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 )) { - format = PIPE_FORMAT_U_A8_R8_G8_B8; + else if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM )) { + format = PIPE_FORMAT_A8R8G8B8_UNORM; internal_format = GL_RGBA8; cpp = 4; comp = 3; /* alpha channel */ /*XXX little-endian dependency */ @@ -1167,7 +1167,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, src = buffer + i * width; switch (psDraw->format) { - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: { uint *dst4 = (uint *) dst; int j; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index e2243e7de4..96829fcfa0 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -90,7 +90,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, memcpy(values, src, width); } break; - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: { const uint *src = (uint *) stmap + srcY * ps->pitch + x; GLint k; @@ -99,7 +99,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } } break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: { const uint *src = (uint *) stmap + srcY * ps->pitch + x; GLint k; diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index f93f7f48d9..9e249a47a6 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -120,7 +120,7 @@ st_get_format_info( #endif /* Data type */ - if (format == PIPE_FORMAT_U_A1_R5_G5_B5 || format == PIPE_FORMAT_U_R5_G6_B5) { + if (format == PIPE_FORMAT_A1R5G5B5_UNORM || format == PIPE_FORMAT_R5G6B5_UNORM) { pinfo->datatype = GL_UNSIGNED_SHORT; } else { @@ -255,9 +255,9 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat) /* fix this */ case MESA_FORMAT_ARGB8888_REV: case MESA_FORMAT_ARGB8888: - return PIPE_FORMAT_U_A8_R8_G8_B8; + return PIPE_FORMAT_A8R8G8B8_UNORM; case MESA_FORMAT_ARGB4444: - return PIPE_FORMAT_U_A4_R4_G4_B4; + return PIPE_FORMAT_A4R4G4B4_UNORM; case MESA_FORMAT_AL88: return PIPE_FORMAT_U_A8_L8; case MESA_FORMAT_A8: @@ -267,7 +267,7 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat) case MESA_FORMAT_I8: return PIPE_FORMAT_U_I8; case MESA_FORMAT_Z16: - return PIPE_FORMAT_U_Z16; + return PIPE_FORMAT_Z16_UNORM; default: assert(0); return 0; @@ -282,10 +282,10 @@ default_rgba_format( struct pipe_context *pipe ) { static const uint colorFormats[] = { - PIPE_FORMAT_U_R8_G8_B8_A8, - PIPE_FORMAT_U_A8_R8_G8_B8, - PIPE_FORMAT_U_B8_G8_R8_A8, - PIPE_FORMAT_U_R5_G6_B5 + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_R5G6B5_UNORM }; uint i; for (i = 0; i < Elements(colorFormats); i++) { @@ -304,8 +304,8 @@ static GLuint default_deep_rgba_format( struct pipe_context *pipe ) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S_R16_G16_B16_A16 )) { - return PIPE_FORMAT_S_R16_G16_B16_A16; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_R16G16B16A16_SNORM )) { + return PIPE_FORMAT_R16G16B16A16_SNORM; } return PIPE_FORMAT_NONE; } @@ -319,10 +319,10 @@ default_depth_format( struct pipe_context *pipe ) { static const uint zFormats[] = { - PIPE_FORMAT_U_Z16, - PIPE_FORMAT_U_Z32, - PIPE_FORMAT_S8_Z24, - PIPE_FORMAT_Z24_S8 + PIPE_FORMAT_Z16_UNORM, + PIPE_FORMAT_Z32_UNORM, + PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_Z24S8_UNORM }; uint i; for (i = 0; i < Elements(zFormats); i++) { @@ -358,16 +358,16 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_COMPRESSED_RGBA: if (format == GL_BGRA) { if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 )) - return PIPE_FORMAT_U_A8_R8_G8_B8; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM )) + return PIPE_FORMAT_A8R8G8B8_UNORM; } else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A4_R4_G4_B4 )) - return PIPE_FORMAT_U_A4_R4_G4_B4; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM )) + return PIPE_FORMAT_A4R4G4B4_UNORM; } else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 )) - return PIPE_FORMAT_U_A1_R5_G5_B5; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM )) + return PIPE_FORMAT_A1R5G5B5_UNORM; } } return default_rgba_format( pipe ); @@ -376,8 +376,8 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_RGB: case GL_COMPRESSED_RGB: if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_R5_G6_B5 )) - return PIPE_FORMAT_U_R5_G6_B5; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_R5G6B5_UNORM )) + return PIPE_FORMAT_R5G6B5_UNORM; } return default_rgba_format( pipe ); @@ -390,13 +390,13 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_RGBA4: case GL_RGBA2: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A4_R4_G4_B4 )) - return PIPE_FORMAT_U_A4_R4_G4_B4; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM )) + return PIPE_FORMAT_A4R4G4B4_UNORM; return default_rgba_format( pipe ); case GL_RGB5_A1: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 )) - return PIPE_FORMAT_U_A1_R5_G5_B5; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM )) + return PIPE_FORMAT_A1R5G5B5_UNORM; return default_rgba_format( pipe ); case GL_RGB8: @@ -408,8 +408,8 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_RGB5: case GL_RGB4: case GL_R3_G3_B2: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 )) - return PIPE_FORMAT_U_A1_R5_G5_B5; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM )) + return PIPE_FORMAT_A1R5G5B5_UNORM; return default_rgba_format( pipe ); case GL_ALPHA: @@ -491,18 +491,18 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, #endif case GL_DEPTH_COMPONENT16: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z16 )) - return PIPE_FORMAT_U_Z16; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z16_UNORM )) + return PIPE_FORMAT_Z16_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT24: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) - return PIPE_FORMAT_S8_Z24; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) - return PIPE_FORMAT_Z24_S8; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM )) + return PIPE_FORMAT_S8Z24_UNORM; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM )) + return PIPE_FORMAT_Z24S8_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT32: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z32 )) - return PIPE_FORMAT_U_Z32; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z32_UNORM )) + return PIPE_FORMAT_Z32_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT: return default_depth_format( pipe ); @@ -514,18 +514,18 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_STENCIL_INDEX16_EXT: if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_S8 )) return PIPE_FORMAT_U_S8; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) - return PIPE_FORMAT_S8_Z24; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) - return PIPE_FORMAT_Z24_S8; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM )) + return PIPE_FORMAT_S8Z24_UNORM; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM )) + return PIPE_FORMAT_Z24S8_UNORM; return PIPE_FORMAT_NONE; case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) - return PIPE_FORMAT_S8_Z24; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) - return PIPE_FORMAT_Z24_S8; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM )) + return PIPE_FORMAT_S8Z24_UNORM; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM )) + return PIPE_FORMAT_Z24S8_UNORM; return PIPE_FORMAT_NONE; default: -- cgit v1.2.3 From 54fc80ab31f89520d3119196bfa9c6332b35fe2f Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 7 Dec 2007 16:46:30 -0700 Subject: Define PIPE_FORMAT_ tokens as an enum set, rather than #defines. This makes debugging a _lot_ easier. In gdb, "print format" used to display 613570600, now you see PIPE_FORMAT_A8R8G8B8_UNORM. --- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 2 +- src/mesa/pipe/draw/draw_vertex_fetch.c | 2 +- src/mesa/pipe/draw/draw_vertex_shader_llvm.c | 2 +- src/mesa/pipe/i915simple/i915_context.c | 5 +- src/mesa/pipe/i915simple/i915_state_emit.c | 4 +- src/mesa/pipe/i915simple/i915_state_sampler.c | 2 +- src/mesa/pipe/p_context.h | 2 +- src/mesa/pipe/p_format.h | 154 +++++++++++---------- src/mesa/pipe/p_state.h | 7 +- src/mesa/pipe/p_winsys.h | 4 +- src/mesa/pipe/softpipe/sp_context.c | 3 +- src/mesa/pipe/softpipe/sp_quad_depth_test.c | 2 +- src/mesa/pipe/softpipe/sp_tile_cache.c | 3 +- src/mesa/pipe/xlib/xm_winsys.c | 5 +- src/mesa/state_tracker/st_cb_clear.c | 6 +- src/mesa/state_tracker/st_cb_drawpixels.c | 5 +- src/mesa/state_tracker/st_cb_fbo.c | 5 +- src/mesa/state_tracker/st_format.c | 14 +- src/mesa/state_tracker/st_format.h | 18 ++- 19 files changed, 127 insertions(+), 118 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index 1b71d0ac10..1799e9b901 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -193,7 +193,7 @@ intel_i915_surface_pitch(struct pipe_winsys *winsys, static struct pipe_surface * -intel_i915_surface_alloc(struct pipe_winsys *winsys, unsigned format) +intel_i915_surface_alloc(struct pipe_winsys *winsys, enum pipe_format format) { struct pipe_surface *surf = CALLOC_STRUCT(pipe_surface); if (surf) { diff --git a/src/mesa/pipe/draw/draw_vertex_fetch.c b/src/mesa/pipe/draw/draw_vertex_fetch.c index 77df5c6427..e0759c2e9a 100644 --- a/src/mesa/pipe/draw/draw_vertex_fetch.c +++ b/src/mesa/pipe/draw/draw_vertex_fetch.c @@ -46,7 +46,7 @@ * XXX this might be a temporary thing. */ static void -fetch_attrib4(const void *ptr, unsigned format, float attrib[4]) +fetch_attrib4(const void *ptr, enum pipe_format format, float attrib[4]) { /* defaults */ attrib[1] = 0.0; diff --git a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c index 53a1776ffc..29de437595 100644 --- a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c +++ b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c @@ -43,7 +43,7 @@ #define DBG 0 static INLINE void -fetch_attrib4(const void *ptr, unsigned format, float attrib[4]) +fetch_attrib4(const void *ptr, enum pipe_format format, float attrib[4]) { /* defaults */ attrib[1] = 0.0; diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index cfce116920..b915a67790 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -45,7 +45,7 @@ */ static boolean i915_is_format_supported( struct pipe_context *pipe, - uint format ) + enum pipe_format format ) { #if 0 /* XXX: This is broken -- rewrite if still needed. */ @@ -101,8 +101,9 @@ i915_is_format_supported( struct pipe_context *pipe, case PIPE_FORMAT_R5G6B5_UNORM: case PIPE_FORMAT_S8Z24_UNORM: return TRUE; + default: + return FALSE; }; - return FALSE; #endif } diff --git a/src/mesa/pipe/i915simple/i915_state_emit.c b/src/mesa/pipe/i915simple/i915_state_emit.c index 1e0db91024..09bf1fa2d6 100644 --- a/src/mesa/pipe/i915simple/i915_state_emit.c +++ b/src/mesa/pipe/i915simple/i915_state_emit.c @@ -35,7 +35,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -static unsigned translate_format( unsigned format ) +static unsigned translate_format( enum pipe_format format ) { switch (format) { case PIPE_FORMAT_A8R8G8B8_UNORM: @@ -48,7 +48,7 @@ static unsigned translate_format( unsigned format ) } } -static unsigned translate_depth_format( unsigned zformat ) +static unsigned translate_depth_format( enum pipe_format zformat ) { switch (zformat) { case PIPE_FORMAT_S8Z24_UNORM: diff --git a/src/mesa/pipe/i915simple/i915_state_sampler.c b/src/mesa/pipe/i915simple/i915_state_sampler.c index dd2d51d9f6..59408b6ba0 100644 --- a/src/mesa/pipe/i915simple/i915_state_sampler.c +++ b/src/mesa/pipe/i915simple/i915_state_sampler.c @@ -127,7 +127,7 @@ void i915_update_samplers( struct i915_context *i915 ) static uint -translate_texture_format(uint pipeFormat) +translate_texture_format(enum pipe_format pipeFormat) { switch (pipeFormat) { case PIPE_FORMAT_U_L8: diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 2420d02213..b3a2122ade 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -51,7 +51,7 @@ struct pipe_context { * Queries */ boolean (*is_format_supported)( struct pipe_context *pipe, - uint format ); + enum pipe_format format ); const char *(*get_name)( struct pipe_context *pipe ); diff --git a/src/mesa/pipe/p_format.h b/src/mesa/pipe/p_format.h index 86728f77a2..8f11bfab76 100644 --- a/src/mesa/pipe/p_format.h +++ b/src/mesa/pipe/p_format.h @@ -198,86 +198,90 @@ static INLINE uint pf_rev(pipe_format_ycbcr_t f) * z24s8, compressed textures, ycbcr, etc that won't fit that model. */ -#define PIPE_FORMAT_NONE _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_0000, 0, 0, 0, 0, PIPE_FORMAT_TYPE_UNKNOWN ) -#define PIPE_FORMAT_A8R8G8B8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ARGB, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_B8G8R8A8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGRA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_A1R5G5B5_UNORM _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_A4R4G4B4_UNORM _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R5G6B5_UNORM _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_RGB0, 5, 6, 5, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_U_L8 _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte luminance */ -#define PIPE_FORMAT_U_A8 _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_000R, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte alpha */ -#define PIPE_FORMAT_U_I8 _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRR, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte intensity */ -#define PIPE_FORMAT_U_A8_L8 _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte alpha, luminance */ -#define PIPE_FORMAT_YCBCR _PIPE_FORMAT_YCBCR( 0 ) -#define PIPE_FORMAT_YCBCR_REV _PIPE_FORMAT_YCBCR( 1 ) -#define PIPE_FORMAT_Z16_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_Z32_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_Z32_FLOAT _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_S8Z24_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_SZ00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_Z24S8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ZS00, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_S8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_S000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R64G64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R64G64B64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R64G64B64A64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32_FLOAT _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32G32_FLOAT _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32G32B32_FLOAT _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32G32B32A32_FLOAT _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32G32_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32G32B32_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32G32B32A32_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32G32_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32G32B32_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32G32B32A32_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32G32_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32G32B32_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32G32B32A32_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R32G32_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R32G32B32_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R32G32B32A32_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16G16_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16G16B16_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16G16B16A16_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16G16_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16G16B16_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16G16B16A16_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16G16_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16G16B16_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16G16B16A16_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16G16_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16G16B16_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16G16B16A16_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8G8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8G8B8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8G8B8A8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8G8_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8G8B8_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8G8B8A8_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8G8_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8G8B8_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8G8B8A8_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8G8_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8G8B8_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8G8B8A8_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ) +enum pipe_format { + PIPE_FORMAT_NONE = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_0000, 0, 0, 0, 0, PIPE_FORMAT_TYPE_UNKNOWN ), + PIPE_FORMAT_A8R8G8B8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ARGB, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_B8G8R8A8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGRA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_A1R5G5B5_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_A4R4G4B4_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R5G6B5_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_RGB0, 5, 6, 5, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_U_L8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte luminance */ + PIPE_FORMAT_U_A8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_000R, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte alpha */ + PIPE_FORMAT_U_I8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRR, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte intensity */ + PIPE_FORMAT_U_A8_L8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte alpha, luminance */ + PIPE_FORMAT_YCBCR = _PIPE_FORMAT_YCBCR( 0 ), + PIPE_FORMAT_YCBCR_REV = _PIPE_FORMAT_YCBCR( 1 ), + PIPE_FORMAT_Z16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_Z32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_Z32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_S8Z24_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_SZ00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_Z24S8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ZS00, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_S8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_S000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte stencil */ + PIPE_FORMAT_R64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64B64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64B64A64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32B32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32B32A32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32B32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32B32A32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32B32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32B32A32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32B32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32B32A32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32B32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32B32A32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16B16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16B16A16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16B16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16B16A16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16B16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16B16A16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16B16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16B16A16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8B8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8B8A8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8B8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8B8A8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8B8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8B8A8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8B8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8B8A8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ) +}; + /** - * Duplicated formats: + * XXX should remove this, but S8_UNORM is a poor name */ #define PIPE_FORMAT_U_S8 PIPE_FORMAT_S8_UNORM + /** * Builds pipe format name from format token. */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 44dec9b773..6db9bbc953 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -39,6 +39,7 @@ #define PIPE_STATE_H #include "p_compiler.h" +#include "p_format.h" /** * Implementation limits @@ -265,7 +266,7 @@ struct pipe_surface struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ ubyte *map; /**< only non-NULL when surface is actually mapped */ unsigned map_refcount; /**< Reference count for mapping */ - unsigned format; /**< PIPE_FORMAT_x */ + enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned cpp; /**< bytes per pixel */ unsigned width, height; unsigned pitch; /**< in pixels */ @@ -286,7 +287,7 @@ struct pipe_texture unsigned target; /* XXX convert to PIPE_TEXTURE_x */ unsigned internal_format; /* XXX convert to PIPE_FORMAT_x */ - unsigned format; /**< PIPE_FORMAT_x */ + enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned first_level; unsigned last_level; @@ -331,7 +332,7 @@ struct pipe_vertex_element unsigned vertex_buffer_index:5; unsigned dst_offset:8; - unsigned src_format; /**< PIPE_FORMAT_* */ + enum pipe_format src_format; /**< PIPE_FORMAT_* */ }; diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 5adca1d6fd..438e8bdb63 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -29,6 +29,8 @@ #define P_WINSYS_H +#include "p_format.h" + /** * \file * This is the interface that Gallium3D requires any window system @@ -90,7 +92,7 @@ struct pipe_winsys /** allocate a new surface (no context dependency) */ struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws, - unsigned format); + enum pipe_format format); void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 54b2076b4a..bdfd6228ef 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -51,7 +51,8 @@ * parameter or another function. */ static boolean -softpipe_is_format_supported( struct pipe_context *pipe, uint format ) +softpipe_is_format_supported( struct pipe_context *pipe, + enum pipe_format format ) { struct softpipe_context *softpipe = softpipe_context( pipe ); /* ask winsys if the format is supported */ diff --git a/src/mesa/pipe/softpipe/sp_quad_depth_test.c b/src/mesa/pipe/softpipe/sp_quad_depth_test.c index 00128fa528..93ea1196f9 100644 --- a/src/mesa/pipe/softpipe/sp_quad_depth_test.c +++ b/src/mesa/pipe/softpipe/sp_quad_depth_test.c @@ -54,7 +54,7 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) { struct softpipe_context *softpipe = qs->softpipe; struct pipe_surface *ps = softpipe->framebuffer.zbuf; - const uint format = ps->format; + const enum pipe_format format = ps->format; unsigned bzzzz[QUAD_SIZE]; /**< Z values fetched from depth buffer */ unsigned qzzzz[QUAD_SIZE]; /**< Z values from the quad */ unsigned zmask = 0; diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index be5dd5c289..602b78ebe6 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -174,7 +174,8 @@ is_depth_stencil_surface(struct pipe_surface *ps) * Set pixels in a tile to the given clear color/value. */ static void -clear_tile(struct softpipe_cached_tile *tile, uint format, +clear_tile(struct softpipe_cached_tile *tile, + enum pipe_format format, const float clear_value[4]) { uint i, j; diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index 408797c688..976884ad52 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -301,7 +301,7 @@ xm_surface_pitch(struct pipe_winsys *winsys, unsigned cpp, unsigned width, * renderbuffers, etc. */ static struct pipe_surface * -xm_surface_alloc(struct pipe_winsys *ws, GLuint pipeFormat) +xm_surface_alloc(struct pipe_winsys *ws, enum pipe_format pipeFormat) { struct xmesa_surface *xms = CALLOC_STRUCT(xmesa_surface); @@ -379,7 +379,8 @@ xmesa_get_pipe_winsys(void) * can support any format. */ static boolean -xmesa_is_format_supported(struct softpipe_winsys *sws, uint format) +xmesa_is_format_supported(struct softpipe_winsys *sws, + enum pipe_format format) { struct xmesa_softpipe_winsys *xmws = xmesa_softpipe_winsys(sws); diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 1f0d1e6426..b4b2429a2a 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -55,7 +55,7 @@ static GLuint -color_value(GLuint pipeFormat, const GLfloat color[4]) +color_value(enum pipe_format pipeFormat, const GLfloat color[4]) { GLubyte r, g, b, a; @@ -81,7 +81,7 @@ color_value(GLuint pipeFormat, const GLfloat color[4]) static uint -depth_value(GLuint pipeFormat, GLfloat value) +depth_value(enum pipe_format pipeFormat, GLfloat value) { switch (pipeFormat) { case PIPE_FORMAT_Z16_UNORM: @@ -104,7 +104,7 @@ depth_value(GLuint pipeFormat, GLfloat value) static GLboolean -is_depth_stencil_format(GLuint pipeFormat) +is_depth_stencil_format(enum pipe_format pipeFormat) { switch (pipeFormat) { case PIPE_FORMAT_S8Z24_UNORM: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 464cf5ced3..c0e41dbeec 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -456,7 +456,8 @@ make_texture(struct st_context *st, struct pipe_context *pipe = st->pipe; const struct gl_texture_format *mformat; struct pipe_texture *pt; - GLuint pipeFormat, cpp; + enum pipe_format pipeFormat; + GLuint cpp; GLenum baseFormat; baseFormat = _mesa_base_format(format); @@ -729,7 +730,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, * XXX probably move this to a re-usable place. */ static GLboolean -compatible_formats(GLenum format, GLenum type, GLuint pipeFormat) +compatible_formats(GLenum format, GLenum type, enum pipe_format pipeFormat) { static const GLuint one = 1; GLubyte littleEndian = *((GLubyte *) &one); diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 0ee5f45aae..cbda56b5c3 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -55,7 +55,8 @@ * Compute the renderbuffer's Red/Green/EtcBit fields from the pipe format. */ static int -init_renderbuffer_bits(struct st_renderbuffer *strb, uint pipeFormat) +init_renderbuffer_bits(struct st_renderbuffer *strb, + enum pipe_format pipeFormat) { struct pipe_format_info info; @@ -86,7 +87,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - const uint pipeFormat + const enum pipe_format pipeFormat = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); GLuint cpp; GLbitfield flags = PIPE_SURFACE_FLAG_RENDER; /* want to render to surface */ diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 9e249a47a6..8d39e1bec6 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -99,9 +99,7 @@ format_size( * XXX temporary here */ GLboolean -st_get_format_info( - GLuint format, - struct pipe_format_info *pinfo ) +st_get_format_info(enum pipe_format format, struct pipe_format_info *pinfo) { if (pf_layout(format) == PIPE_FORMAT_LAYOUT_RGBAZS) { pipe_format_rgbazs_t info; @@ -222,10 +220,10 @@ st_get_format_info( * Return bytes per pixel for the given format. */ GLuint -st_sizeof_format(GLuint pipeFormat) +st_sizeof_format(enum pipe_format format) { struct pipe_format_info info; - if (!st_get_format_info( pipeFormat, &info )) { + if (!st_get_format_info( format, &info )) { assert( 0 ); return 0; } @@ -237,10 +235,10 @@ st_sizeof_format(GLuint pipeFormat) * Return bytes per pixel for the given format. */ GLenum -st_format_datatype(GLuint pipeFormat) +st_format_datatype(enum pipe_format format) { struct pipe_format_info info; - if (!st_get_format_info( pipeFormat, &info )) { + if (!st_get_format_info( format, &info )) { assert( 0 ); return 0; } @@ -248,7 +246,7 @@ st_format_datatype(GLuint pipeFormat) } -GLuint +enum pipe_format st_mesa_format_to_pipe_format(GLuint mesaFormat) { switch (mesaFormat) { diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h index 23abc36edf..6ccf5536f9 100644 --- a/src/mesa/state_tracker/st_format.h +++ b/src/mesa/state_tracker/st_format.h @@ -26,13 +26,13 @@ **************************************************************************/ -#ifndef ST_CB_TEXIMAGE_H -#define ST_CB_TEXIMAGE_H +#ifndef ST_FORMAT_H +#define ST_FORMAT_H struct pipe_format_info { - GLuint format; + enum pipe_format format; GLenum base_format; GLenum datatype; GLubyte red_bits; @@ -47,21 +47,19 @@ struct pipe_format_info }; -extern GLboolean -st_get_format_info( - GLuint format, - struct pipe_format_info *pinfo ); +GLboolean +st_get_format_info(enum pipe_format format, struct pipe_format_info *pinfo); extern GLuint -st_sizeof_format(GLuint pipeFormat); +st_sizeof_format(enum pipe_format format); extern GLenum -st_format_datatype(GLuint pipeFormat); +st_format_datatype(enum pipe_format format); -extern GLuint +extern enum pipe_format st_mesa_format_to_pipe_format(GLuint mesaFormat); -- cgit v1.2.3 From bfe79babf99e6b9435195178d1ea64687c60d161 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 17 Dec 2007 16:14:29 +0000 Subject: gallium: incorporate alpha state into depth_stencil state object. --- src/mesa/pipe/cell/ppu/cell_context.c | 4 -- src/mesa/pipe/cell/ppu/cell_context.h | 3 +- src/mesa/pipe/cell/ppu/cell_state.h | 9 +-- src/mesa/pipe/cell/ppu/cell_state_blend.c | 40 ++--------- src/mesa/pipe/cso_cache/cso_cache.c | 13 +--- src/mesa/pipe/cso_cache/cso_cache.h | 14 ++-- src/mesa/pipe/failover/fo_context.h | 1 - src/mesa/pipe/failover/fo_state.c | 60 +++------------- src/mesa/pipe/failover/fo_state_emit.c | 8 +-- src/mesa/pipe/i915simple/i915_context.h | 4 -- src/mesa/pipe/i915simple/i915_state.c | 86 ++++++++--------------- src/mesa/pipe/i915simple/i915_state_immediate.c | 6 +- src/mesa/pipe/i965simple/brw_cc.c | 49 ++++++------- src/mesa/pipe/i965simple/brw_context.h | 3 +- src/mesa/pipe/i965simple/brw_state.c | 42 ++--------- src/mesa/pipe/i965simple/brw_wm.c | 13 ++-- src/mesa/pipe/i965simple/brw_wm_state.c | 2 +- src/mesa/pipe/p_context.h | 13 ++-- src/mesa/pipe/p_state.h | 36 +++++----- src/mesa/pipe/softpipe/sp_context.c | 10 +-- src/mesa/pipe/softpipe/sp_context.h | 9 ++- src/mesa/pipe/softpipe/sp_quad.c | 8 +-- src/mesa/pipe/softpipe/sp_quad_alpha_test.c | 4 +- src/mesa/pipe/softpipe/sp_quad_stencil.c | 25 ++----- src/mesa/pipe/softpipe/sp_state.h | 9 +-- src/mesa/pipe/softpipe/sp_state_blend.c | 38 ++-------- src/mesa/pipe/softpipe/sp_state_derived.c | 8 +-- src/mesa/sources | 1 - src/mesa/state_tracker/st_atom.c | 3 +- src/mesa/state_tracker/st_atom.h | 3 +- src/mesa/state_tracker/st_atom_alphatest.c | 92 ------------------------- src/mesa/state_tracker/st_atom_depth.c | 55 ++++++++------- src/mesa/state_tracker/st_cache.c | 40 +++-------- src/mesa/state_tracker/st_cache.h | 9 +-- src/mesa/state_tracker/st_cb_clear.c | 35 ++++------ src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_context.h | 2 +- 37 files changed, 206 insertions(+), 553 deletions(-) delete mode 100644 src/mesa/state_tracker/st_atom_alphatest.c (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/pipe/cell/ppu/cell_context.c b/src/mesa/pipe/cell/ppu/cell_context.c index eff33da969..b448a8aa8c 100644 --- a/src/mesa/pipe/cell/ppu/cell_context.c +++ b/src/mesa/pipe/cell/ppu/cell_context.c @@ -176,10 +176,6 @@ cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws) /* state setters */ - cell->pipe.create_alpha_test_state = cell_create_alpha_test_state; - cell->pipe.bind_alpha_test_state = cell_bind_alpha_test_state; - cell->pipe.delete_alpha_test_state = cell_delete_alpha_test_state; - cell->pipe.create_blend_state = cell_create_blend_state; cell->pipe.bind_blend_state = cell_bind_blend_state; cell->pipe.delete_blend_state = cell_delete_blend_state; diff --git a/src/mesa/pipe/cell/ppu/cell_context.h b/src/mesa/pipe/cell/ppu/cell_context.h index 96f000eef4..f8d6cc5d32 100644 --- a/src/mesa/pipe/cell/ppu/cell_context.h +++ b/src/mesa/pipe/cell/ppu/cell_context.h @@ -40,10 +40,9 @@ struct cell_context struct cell_winsys *winsys; - const struct pipe_alpha_test_state *alpha_test; const struct pipe_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; - const struct pipe_depth_stencil_state *depth_stencil; + const struct pipe_depth_stencil_alpha_state *depth_stencil; const struct pipe_rasterizer_state *rasterizer; struct pipe_blend_color blend_color; diff --git a/src/mesa/pipe/cell/ppu/cell_state.h b/src/mesa/pipe/cell/ppu/cell_state.h index 4bad45950b..b01814202d 100644 --- a/src/mesa/pipe/cell/ppu/cell_state.h +++ b/src/mesa/pipe/cell/ppu/cell_state.h @@ -27,13 +27,6 @@ cell_set_framebuffer_state( struct pipe_context *, const struct pipe_framebuffer_state * ); -extern void * -cell_create_alpha_test_state(struct pipe_context *, - const struct pipe_alpha_test_state *); -extern void -cell_bind_alpha_test_state(struct pipe_context *, void *); -extern void -cell_delete_alpha_test_state(struct pipe_context *, void *); extern void * cell_create_blend_state(struct pipe_context *, const struct pipe_blend_state *); @@ -57,7 +50,7 @@ cell_delete_sampler_state(struct pipe_context *, void *); extern void * cell_create_depth_stencil_state(struct pipe_context *, - const struct pipe_depth_stencil_state *); + const struct pipe_depth_stencil_alpha_state *); extern void cell_bind_depth_stencil_state(struct pipe_context *, void *); diff --git a/src/mesa/pipe/cell/ppu/cell_state_blend.c b/src/mesa/pipe/cell/ppu/cell_state_blend.c index e807463d90..efcb9e38a4 100644 --- a/src/mesa/pipe/cell/ppu/cell_state_blend.c +++ b/src/mesa/pipe/cell/ppu/cell_state_blend.c @@ -69,44 +69,14 @@ void cell_set_blend_color( struct pipe_context *pipe, } -/** XXX move someday? Or consolidate all these simple state setters - * into one file. - */ - -void * -cell_create_alpha_test_state(struct pipe_context *pipe, - const struct pipe_alpha_test_state *alpha) -{ - struct pipe_alpha_test_state *state = MALLOC( sizeof(struct pipe_alpha_test_state) ); - memcpy(state, alpha, sizeof(struct pipe_alpha_test_state)); - return state; -} - -void -cell_bind_alpha_test_state(struct pipe_context *pipe, - void *alpha) -{ - struct cell_context *cell = cell_context(pipe); - - cell->alpha_test = (const struct pipe_alpha_test_state *)alpha; - - cell->dirty |= CELL_NEW_ALPHA_TEST; -} - -void -cell_delete_alpha_test_state(struct pipe_context *pipe, - void *alpha) -{ - FREE( alpha ); -} void * cell_create_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_state *depth_stencil) + const struct pipe_depth_stencil_alpha_state *depth_stencil) { - struct pipe_depth_stencil_state *state = - MALLOC( sizeof(struct pipe_depth_stencil_state) ); - memcpy(state, depth_stencil, sizeof(struct pipe_depth_stencil_state)); + struct pipe_depth_stencil_alpha_state *state = + MALLOC( sizeof(struct pipe_depth_stencil_alpha_state) ); + memcpy(state, depth_stencil, sizeof(struct pipe_depth_stencil_alpha_state)); return state; } @@ -116,7 +86,7 @@ cell_bind_depth_stencil_state(struct pipe_context *pipe, { struct cell_context *cell = cell_context(pipe); - cell->depth_stencil = (const struct pipe_depth_stencil_state *)depth_stencil; + cell->depth_stencil = (const struct pipe_depth_stencil_alpha_state *)depth_stencil; cell->dirty |= CELL_NEW_DEPTH_STENCIL; } diff --git a/src/mesa/pipe/cso_cache/cso_cache.c b/src/mesa/pipe/cso_cache/cso_cache.c index 0bba5914dc..9e77e0774d 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.c +++ b/src/mesa/pipe/cso_cache/cso_cache.c @@ -78,7 +78,7 @@ static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_ case CSO_SAMPLER: hash = sc->sampler_hash; break; - case CSO_DEPTH_STENCIL: + case CSO_DEPTH_STENCIL_ALPHA: hash = sc->depth_stencil_hash; break; case CSO_RASTERIZER: @@ -90,9 +90,6 @@ static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_ case CSO_VERTEX_SHADER: hash = sc->vs_hash; break; - case CSO_ALPHA_TEST: - hash = sc->alpha_hash; - break; } return hash; @@ -105,16 +102,14 @@ static int _cso_size_for_type(enum cso_cache_type type) return sizeof(struct pipe_blend_state); case CSO_SAMPLER: return sizeof(struct pipe_sampler_state); - case CSO_DEPTH_STENCIL: - return sizeof(struct pipe_depth_stencil_state); + case CSO_DEPTH_STENCIL_ALPHA: + return sizeof(struct pipe_depth_stencil_alpha_state); case CSO_RASTERIZER: return sizeof(struct pipe_rasterizer_state); case CSO_FRAGMENT_SHADER: return sizeof(struct pipe_shader_state); case CSO_VERTEX_SHADER: return sizeof(struct pipe_shader_state); - case CSO_ALPHA_TEST: - return sizeof(struct pipe_alpha_test_state); } return 0; } @@ -169,7 +164,6 @@ struct cso_cache *cso_cache_create(void) sc->rasterizer_hash = cso_hash_create(); sc->fs_hash = cso_hash_create(); sc->vs_hash = cso_hash_create(); - sc->alpha_hash = cso_hash_create(); return sc; } @@ -183,6 +177,5 @@ void cso_cache_delete(struct cso_cache *sc) cso_hash_delete(sc->rasterizer_hash); cso_hash_delete(sc->fs_hash); cso_hash_delete(sc->vs_hash); - cso_hash_delete(sc->alpha_hash); free(sc); } diff --git a/src/mesa/pipe/cso_cache/cso_cache.h b/src/mesa/pipe/cso_cache/cso_cache.h index cd36dd51e9..116e2eaa2c 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.h +++ b/src/mesa/pipe/cso_cache/cso_cache.h @@ -40,7 +40,6 @@ struct cso_hash; struct cso_cache { - struct cso_hash *alpha_hash; struct cso_hash *blend_hash; struct cso_hash *depth_stencil_hash; struct cso_hash *fs_hash; @@ -54,8 +53,8 @@ struct cso_blend { void *data; }; -struct cso_depth_stencil { - struct pipe_depth_stencil_state state; +struct cso_depth_stencil_alpha { + struct pipe_depth_stencil_alpha_state state; void *data; }; @@ -79,19 +78,14 @@ struct cso_sampler { void *data; }; -struct cso_alpha_test { - struct pipe_alpha_test_state state; - void *data; -}; enum cso_cache_type { CSO_BLEND, CSO_SAMPLER, - CSO_DEPTH_STENCIL, + CSO_DEPTH_STENCIL_ALPHA, CSO_RASTERIZER, CSO_FRAGMENT_SHADER, - CSO_VERTEX_SHADER, - CSO_ALPHA_TEST + CSO_VERTEX_SHADER }; unsigned cso_construct_key(void *item, int item_size); diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index f5eaa0b5fa..1dc87291c9 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -70,7 +70,6 @@ struct failover_context { /* The most recent drawing state as set by the driver: */ - const struct fo_state *alpha_test; const struct fo_state *blend; const struct fo_state *sampler[PIPE_MAX_SAMPLERS]; const struct fo_state *depth_stencil; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index 6b4f1517ac..fa700b9674 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -45,45 +45,6 @@ * lower overheads. */ -static void * -failover_create_alpha_test_state(struct pipe_context *pipe, - const struct pipe_alpha_test_state *templ) -{ - struct fo_state *state = malloc(sizeof(struct fo_state)); - struct failover_context *failover = failover_context(pipe); - - state->sw_state = failover->sw->create_alpha_test_state(pipe, templ); - state->hw_state = failover->hw->create_alpha_test_state(pipe, templ); - - return state; -} - -static void -failover_bind_alpha_test_state(struct pipe_context *pipe, - void *alpha) -{ - struct failover_context *failover = failover_context(pipe); - struct fo_state *state = (struct fo_state *)alpha; - - failover->alpha_test = state; - failover->dirty |= FO_NEW_ALPHA_TEST; - failover->hw->bind_alpha_test_state(failover->hw, - state->hw_state); -} - -static void -failover_delete_alpha_test_state(struct pipe_context *pipe, - void *alpha) -{ - struct fo_state *state = (struct fo_state*)alpha; - struct failover_context *failover = failover_context(pipe); - - failover->sw->delete_alpha_test_state(pipe, state->sw_state); - failover->hw->delete_alpha_test_state(pipe, state->hw_state); - state->sw_state = 0; - state->hw_state = 0; - free(state); -} static void * @@ -149,13 +110,13 @@ failover_set_clip_state( struct pipe_context *pipe, static void * failover_create_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_state *templ) + const struct pipe_depth_stencil_alpha_state *templ) { struct fo_state *state = malloc(sizeof(struct fo_state)); struct failover_context *failover = failover_context(pipe); - state->sw_state = failover->sw->create_depth_stencil_state(pipe, templ); - state->hw_state = failover->hw->create_depth_stencil_state(pipe, templ); + state->sw_state = failover->sw->create_depth_stencil_alpha_state(pipe, templ); + state->hw_state = failover->hw->create_depth_stencil_alpha_state(pipe, templ); return state; } @@ -168,7 +129,7 @@ failover_bind_depth_stencil_state(struct pipe_context *pipe, struct fo_state *state = (struct fo_state *)depth_stencil; failover->depth_stencil = state; failover->dirty |= FO_NEW_DEPTH_STENCIL; - failover->hw->bind_depth_stencil_state(failover->hw, state->hw_state); + failover->hw->bind_depth_stencil_alpha_state(failover->hw, state->hw_state); } static void @@ -178,8 +139,8 @@ failover_delete_depth_stencil_state(struct pipe_context *pipe, struct fo_state *state = (struct fo_state*)ds; struct failover_context *failover = failover_context(pipe); - failover->sw->delete_depth_stencil_state(pipe, state->sw_state); - failover->hw->delete_depth_stencil_state(pipe, state->hw_state); + failover->sw->delete_depth_stencil_alpha_state(pipe, state->sw_state); + failover->hw->delete_depth_stencil_alpha_state(pipe, state->hw_state); state->sw_state = 0; state->hw_state = 0; free(state); @@ -434,18 +395,15 @@ failover_set_vertex_element(struct pipe_context *pipe, void failover_init_state_functions( struct failover_context *failover ) { - failover->pipe.create_alpha_test_state = failover_create_alpha_test_state; - failover->pipe.bind_alpha_test_state = failover_bind_alpha_test_state; - failover->pipe.delete_alpha_test_state = failover_delete_alpha_test_state; failover->pipe.create_blend_state = failover_create_blend_state; failover->pipe.bind_blend_state = failover_bind_blend_state; failover->pipe.delete_blend_state = failover_delete_blend_state; failover->pipe.create_sampler_state = failover_create_sampler_state; failover->pipe.bind_sampler_state = failover_bind_sampler_state; failover->pipe.delete_sampler_state = failover_delete_sampler_state; - failover->pipe.create_depth_stencil_state = failover_create_depth_stencil_state; - failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state; - failover->pipe.delete_depth_stencil_state = failover_delete_depth_stencil_state; + failover->pipe.create_depth_stencil_alpha_state = failover_create_depth_stencil_state; + failover->pipe.bind_depth_stencil_alpha_state = failover_bind_depth_stencil_state; + failover->pipe.delete_depth_stencil_alpha_state = failover_delete_depth_stencil_state; failover->pipe.create_rasterizer_state = failover_create_rasterizer_state; failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state; failover->pipe.delete_rasterizer_state = failover_delete_rasterizer_state; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index c99ecd4f8d..c663dd4947 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -55,10 +55,6 @@ failover_state_emit( struct failover_context *failover ) { unsigned i; - if (failover->dirty & FO_NEW_ALPHA_TEST) - failover->sw->bind_alpha_test_state( failover->sw, - failover->alpha_test->sw_state ); - if (failover->dirty & FO_NEW_BLEND) failover->sw->bind_blend_state( failover->sw, failover->blend->sw_state ); @@ -70,8 +66,8 @@ failover_state_emit( struct failover_context *failover ) failover->sw->set_clip_state( failover->sw, &failover->clip ); if (failover->dirty & FO_NEW_DEPTH_STENCIL) - failover->sw->bind_depth_stencil_state( failover->sw, - failover->depth_stencil->sw_state ); + failover->sw->bind_depth_stencil_alpha_state( failover->sw, + failover->depth_stencil->sw_state ); if (failover->dirty & FO_NEW_FRAMEBUFFER) failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer ); diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index 80df7f0fba..2f1f036993 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -146,9 +146,6 @@ struct i915_sampler_state { const struct pipe_sampler_state *templ; }; -struct i915_alpha_test_state { - unsigned LIS6; -}; struct i915_texture { struct pipe_texture base; @@ -186,7 +183,6 @@ struct i915_context /* The most recent drawing state as set by the driver: */ - const struct i915_alpha_test_state *alpha_test; const struct i915_blend_state *blend; const struct i915_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct i915_depth_stencil_state *depth_stencil; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 2a9a587a37..f8332aab37 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -284,13 +284,13 @@ static void i915_delete_sampler_state(struct pipe_context *pipe, static void * i915_create_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_state *depth_stencil) + const struct pipe_depth_stencil_alpha_state *depth_stencil) { struct i915_depth_stencil_state *cso = CALLOC_STRUCT( i915_depth_stencil_state ); { - int testmask = depth_stencil->stencil.value_mask[0] & 0xff; - int writemask = depth_stencil->stencil.write_mask[0] & 0xff; + int testmask = depth_stencil->stencil[0].value_mask & 0xff; + int writemask = depth_stencil->stencil[0].write_mask & 0xff; cso->stencil_modes4 |= (_3DSTATE_MODES_4_CMD | ENABLE_STENCIL_TEST_MASK | @@ -299,12 +299,12 @@ i915_create_depth_stencil_state(struct pipe_context *pipe, STENCIL_WRITE_MASK(writemask)); } - if (depth_stencil->stencil.front_enabled) { - int test = i915_translate_compare_func(depth_stencil->stencil.front_func); - int fop = i915_translate_stencil_op(depth_stencil->stencil.front_fail_op); - int dfop = i915_translate_stencil_op(depth_stencil->stencil.front_zfail_op); - int dpop = i915_translate_stencil_op(depth_stencil->stencil.front_zpass_op); - int ref = depth_stencil->stencil.ref_value[0] & 0xff; + if (depth_stencil->stencil[0].enabled) { + int test = i915_translate_compare_func(depth_stencil->stencil[0].func); + int fop = i915_translate_stencil_op(depth_stencil->stencil[0].fail_op); + int dfop = i915_translate_stencil_op(depth_stencil->stencil[0].zfail_op); + int dpop = i915_translate_stencil_op(depth_stencil->stencil[0].zpass_op); + int ref = depth_stencil->stencil[0].ref_value & 0xff; cso->stencil_LIS5 |= (S5_STENCIL_TEST_ENABLE | S5_STENCIL_WRITE_ENABLE | @@ -315,14 +315,14 @@ i915_create_depth_stencil_state(struct pipe_context *pipe, (dpop << S5_STENCIL_PASS_Z_PASS_SHIFT)); } - if (depth_stencil->stencil.back_enabled) { - int test = i915_translate_compare_func(depth_stencil->stencil.back_func); - int fop = i915_translate_stencil_op(depth_stencil->stencil.back_fail_op); - int dfop = i915_translate_stencil_op(depth_stencil->stencil.back_zfail_op); - int dpop = i915_translate_stencil_op(depth_stencil->stencil.back_zpass_op); - int ref = depth_stencil->stencil.ref_value[1] & 0xff; - int tmask = depth_stencil->stencil.value_mask[1] & 0xff; - int wmask = depth_stencil->stencil.write_mask[1] & 0xff; + if (depth_stencil->stencil[1].enabled) { + int test = i915_translate_compare_func(depth_stencil->stencil[1].func); + int fop = i915_translate_stencil_op(depth_stencil->stencil[1].fail_op); + int dfop = i915_translate_stencil_op(depth_stencil->stencil[1].zfail_op); + int dpop = i915_translate_stencil_op(depth_stencil->stencil[1].zpass_op); + int ref = depth_stencil->stencil[1].ref_value & 0xff; + int tmask = depth_stencil->stencil[1].value_mask & 0xff; + int wmask = depth_stencil->stencil[1].write_mask & 0xff; cso->bfo[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | BFO_ENABLE_STENCIL_FUNCS | @@ -363,6 +363,15 @@ i915_create_depth_stencil_state(struct pipe_context *pipe, cso->depth_LIS6 |= S6_DEPTH_WRITE_ENABLE; } + if (depth_stencil->alpha.enabled) { + int test = i915_translate_compare_func(depth_stencil->alpha.func); + ubyte refByte = float_to_ubyte(depth_stencil->alpha.ref); + + cso->depth_LIS6 |= (S6_ALPHA_TEST_ENABLE | + (test << S6_ALPHA_TEST_FUNC_SHIFT) | + (((unsigned) refByte) << S6_ALPHA_REF_SHIFT)); + } + return cso; } @@ -383,39 +392,6 @@ static void i915_delete_depth_stencil_state(struct pipe_context *pipe, } -static void * -i915_create_alpha_test_state(struct pipe_context *pipe, - const struct pipe_alpha_test_state *alpha_test) -{ - struct i915_alpha_test_state *cso = CALLOC_STRUCT( i915_alpha_test_state ); - - if (alpha_test->enabled) { - int test = i915_translate_compare_func(alpha_test->func); - ubyte refByte = float_to_ubyte(alpha_test->ref); - - cso->LIS6 |= (S6_ALPHA_TEST_ENABLE | - (test << S6_ALPHA_TEST_FUNC_SHIFT) | - (((unsigned) refByte) << S6_ALPHA_REF_SHIFT)); - } - return cso; -} - -static void i915_bind_alpha_test_state(struct pipe_context *pipe, - void *alpha) -{ - struct i915_context *i915 = i915_context(pipe); - - i915->alpha_test = (const struct i915_alpha_test_state*)alpha; - - i915->dirty |= I915_NEW_ALPHA_TEST; -} - -static void i915_delete_alpha_test_state(struct pipe_context *pipe, - void *alpha) -{ - FREE(alpha); -} - static void i915_set_scissor_state( struct pipe_context *pipe, const struct pipe_scissor_state *scissor ) { @@ -674,10 +650,6 @@ static void i915_set_vertex_element( struct pipe_context *pipe, void i915_init_state_functions( struct i915_context *i915 ) { - i915->pipe.create_alpha_test_state = i915_create_alpha_test_state; - i915->pipe.bind_alpha_test_state = i915_bind_alpha_test_state; - i915->pipe.delete_alpha_test_state = i915_delete_alpha_test_state; - i915->pipe.create_blend_state = i915_create_blend_state; i915->pipe.bind_blend_state = i915_bind_blend_state; i915->pipe.delete_blend_state = i915_delete_blend_state; @@ -686,9 +658,9 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.bind_sampler_state = i915_bind_sampler_state; i915->pipe.delete_sampler_state = i915_delete_sampler_state; - i915->pipe.create_depth_stencil_state = i915_create_depth_stencil_state; - i915->pipe.bind_depth_stencil_state = i915_bind_depth_stencil_state; - i915->pipe.delete_depth_stencil_state = i915_delete_depth_stencil_state; + i915->pipe.create_depth_stencil_alpha_state = i915_create_depth_stencil_state; + i915->pipe.bind_depth_stencil_alpha_state = i915_bind_depth_stencil_state; + i915->pipe.delete_depth_stencil_alpha_state = i915_delete_depth_stencil_state; i915->pipe.create_rasterizer_state = i915_create_rasterizer_state; i915->pipe.bind_rasterizer_state = i915_bind_rasterizer_state; diff --git a/src/mesa/pipe/i915simple/i915_state_immediate.c b/src/mesa/pipe/i915simple/i915_state_immediate.c index da2402c018..752d25f233 100644 --- a/src/mesa/pipe/i915simple/i915_state_immediate.c +++ b/src/mesa/pipe/i915simple/i915_state_immediate.c @@ -159,10 +159,6 @@ static void upload_S6( struct i915_context *i915 ) unsigned LIS6 = (S6_COLOR_WRITE_ENABLE | (2 << S6_TRISTRIP_PV_SHIFT)); - /* I915_NEW_ALPHA_TEST - */ - LIS6 |= i915->alpha_test->LIS6; - /* I915_NEW_BLEND */ LIS6 |= i915->blend->LIS6; @@ -178,7 +174,7 @@ static void upload_S6( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_S6 = { - I915_NEW_ALPHA_TEST | I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL, + I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL, upload_S6 }; diff --git a/src/mesa/pipe/i965simple/brw_cc.c b/src/mesa/pipe/i965simple/brw_cc.c index 6cc1505311..dcee731895 100644 --- a/src/mesa/pipe/i965simple/brw_cc.c +++ b/src/mesa/pipe/i965simple/brw_cc.c @@ -156,38 +156,37 @@ static void upload_cc_unit( struct brw_context *brw ) memset(&cc, 0, sizeof(cc)); /* BRW_NEW_DEPTH_STENCIL */ - if (brw->attribs.DepthStencil->stencil.front_enabled) { - cc.cc0.stencil_enable = brw->attribs.DepthStencil->stencil.front_enabled; - cc.cc0.stencil_func = brw_translate_compare_func(brw->attribs.DepthStencil->stencil.front_func); - cc.cc0.stencil_fail_op = brw_translate_stencil_op(brw->attribs.DepthStencil->stencil.front_fail_op); + if (brw->attribs.DepthStencil->stencil[0].enabled) { + cc.cc0.stencil_enable = brw->attribs.DepthStencil->stencil[0].enabled; + cc.cc0.stencil_func = brw_translate_compare_func(brw->attribs.DepthStencil->stencil[0].func); + cc.cc0.stencil_fail_op = brw_translate_stencil_op(brw->attribs.DepthStencil->stencil[0].fail_op); cc.cc0.stencil_pass_depth_fail_op = brw_translate_stencil_op( - brw->attribs.DepthStencil->stencil.front_zfail_op); + brw->attribs.DepthStencil->stencil[0].zfail_op); cc.cc0.stencil_pass_depth_pass_op = brw_translate_stencil_op( - brw->attribs.DepthStencil->stencil.front_zpass_op); - cc.cc1.stencil_ref = brw->attribs.DepthStencil->stencil.ref_value[0]; - cc.cc1.stencil_write_mask = brw->attribs.DepthStencil->stencil.write_mask[0]; - cc.cc1.stencil_test_mask = brw->attribs.DepthStencil->stencil.value_mask[0]; + brw->attribs.DepthStencil->stencil[0].zpass_op); + cc.cc1.stencil_ref = brw->attribs.DepthStencil->stencil[0].ref_value; + cc.cc1.stencil_write_mask = brw->attribs.DepthStencil->stencil[0].write_mask; + cc.cc1.stencil_test_mask = brw->attribs.DepthStencil->stencil[0].value_mask; - if (brw->attribs.DepthStencil->stencil.back_enabled) { - cc.cc0.bf_stencil_enable = brw->attribs.DepthStencil->stencil.back_enabled; + if (brw->attribs.DepthStencil->stencil[1].enabled) { + cc.cc0.bf_stencil_enable = brw->attribs.DepthStencil->stencil[1].enabled; cc.cc0.bf_stencil_func = brw_translate_compare_func( - brw->attribs.DepthStencil->stencil.back_func); + brw->attribs.DepthStencil->stencil[1].func); cc.cc0.bf_stencil_fail_op = brw_translate_stencil_op( - brw->attribs.DepthStencil->stencil.back_fail_op); + brw->attribs.DepthStencil->stencil[1].fail_op); cc.cc0.bf_stencil_pass_depth_fail_op = brw_translate_stencil_op( - brw->attribs.DepthStencil->stencil.back_zfail_op); + brw->attribs.DepthStencil->stencil[1].zfail_op); cc.cc0.bf_stencil_pass_depth_pass_op = brw_translate_stencil_op( - brw->attribs.DepthStencil->stencil.back_zpass_op); - cc.cc1.bf_stencil_ref = brw->attribs.DepthStencil->stencil.ref_value[1]; - cc.cc2.bf_stencil_write_mask = brw->attribs.DepthStencil->stencil.write_mask[1]; - cc.cc2.bf_stencil_test_mask = brw->attribs.DepthStencil->stencil.value_mask[1]; + brw->attribs.DepthStencil->stencil[1].zpass_op); + cc.cc1.bf_stencil_ref = brw->attribs.DepthStencil->stencil[1].ref_value; + cc.cc2.bf_stencil_write_mask = brw->attribs.DepthStencil->stencil[1].write_mask; + cc.cc2.bf_stencil_test_mask = brw->attribs.DepthStencil->stencil[1].value_mask; } /* Not really sure about this: */ - if (brw->attribs.DepthStencil->stencil.write_mask[0] || - (brw->attribs.DepthStencil->stencil.back_enabled && - brw->attribs.DepthStencil->stencil.write_mask[1])) + if (brw->attribs.DepthStencil->stencil[0].write_mask || + brw->attribs.DepthStencil->stencil[1].write_mask) cc.cc0.stencil_write_enable = 1; } @@ -228,11 +227,13 @@ static void upload_cc_unit( struct brw_context *brw ) /* BRW_NEW_ALPHATEST */ - if (brw->attribs.AlphaTest->enabled) { + if (brw->attribs.DepthStencil->alpha.enabled) { cc.cc3.alpha_test = 1; - cc.cc3.alpha_test_func = brw_translate_compare_func(brw->attribs.AlphaTest->func); + cc.cc3.alpha_test_func = + brw_translate_compare_func(brw->attribs.DepthStencil->alpha.func); - UNCLAMPED_FLOAT_TO_UBYTE(cc.cc7.alpha_ref.ub[0], brw->attribs.AlphaTest->ref); + UNCLAMPED_FLOAT_TO_UBYTE(cc.cc7.alpha_ref.ub[0], + brw->attribs.DepthStencil->alpha.ref); cc.cc3.alpha_test_format = BRW_ALPHATEST_FORMAT_UNORM8; } diff --git a/src/mesa/pipe/i965simple/brw_context.h b/src/mesa/pipe/i965simple/brw_context.h index 318c6a7049..11146570be 100644 --- a/src/mesa/pipe/i965simple/brw_context.h +++ b/src/mesa/pipe/i965simple/brw_context.h @@ -479,9 +479,8 @@ struct brw_context struct { - const struct pipe_alpha_test_state *AlphaTest; const struct pipe_blend_state *Blend; - const struct pipe_depth_stencil_state *DepthStencil; + const struct pipe_depth_stencil_alpha_state *DepthStencil; const struct pipe_poly_stipple *PolygonStipple; const struct pipe_rasterizer_state *Raster; const struct pipe_sampler_state *Samplers[PIPE_MAX_SAMPLERS]; diff --git a/src/mesa/pipe/i965simple/brw_state.c b/src/mesa/pipe/i965simple/brw_state.c index 26450ae597..e7f5a27a38 100644 --- a/src/mesa/pipe/i965simple/brw_state.c +++ b/src/mesa/pipe/i965simple/brw_state.c @@ -116,9 +116,9 @@ static void brw_delete_sampler_state(struct pipe_context *pipe, static void * brw_create_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_state *depth_stencil) + const struct pipe_depth_stencil_alpha_state *depth_stencil) { - DUP( pipe_depth_stencil_state, depth_stencil ); + DUP( pipe_depth_stencil_alpha_state, depth_stencil ); } static void brw_bind_depth_stencil_state(struct pipe_context *pipe, @@ -126,7 +126,7 @@ static void brw_bind_depth_stencil_state(struct pipe_context *pipe, { struct brw_context *brw = brw_context(pipe); - brw->attribs.DepthStencil = (const struct pipe_depth_stencil_state *)depth_stencil; + brw->attribs.DepthStencil = (const struct pipe_depth_stencil_alpha_state *)depth_stencil; brw->state.dirty.brw |= BRW_NEW_DEPTH_STENCIL; } @@ -137,32 +137,6 @@ static void brw_delete_depth_stencil_state(struct pipe_context *pipe, free(depth_stencil); } -/************************************************************************ - * Alpha test - */ -static void * -brw_create_alpha_test_state(struct pipe_context *pipe, - const struct pipe_alpha_test_state *alpha_test) -{ - DUP(pipe_alpha_test_state, alpha_test); -} - -static void brw_bind_alpha_test_state(struct pipe_context *pipe, - void *alpha) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.AlphaTest = (const struct pipe_alpha_test_state*)alpha; - - brw->state.dirty.brw |= BRW_NEW_ALPHA_TEST; -} - -static void brw_delete_alpha_test_state(struct pipe_context *pipe, - void *alpha) -{ - free(alpha); -} - /************************************************************************ * Scissor */ @@ -415,10 +389,6 @@ static void brw_delete_rasterizer_state(struct pipe_context *pipe, void brw_init_state_functions( struct brw_context *brw ) { - brw->pipe.create_alpha_test_state = brw_create_alpha_test_state; - brw->pipe.bind_alpha_test_state = brw_bind_alpha_test_state; - brw->pipe.delete_alpha_test_state = brw_delete_alpha_test_state; - brw->pipe.create_blend_state = brw_create_blend_state; brw->pipe.bind_blend_state = brw_bind_blend_state; brw->pipe.delete_blend_state = brw_delete_blend_state; @@ -427,9 +397,9 @@ brw_init_state_functions( struct brw_context *brw ) brw->pipe.bind_sampler_state = brw_bind_sampler_state; brw->pipe.delete_sampler_state = brw_delete_sampler_state; - brw->pipe.create_depth_stencil_state = brw_create_depth_stencil_state; - brw->pipe.bind_depth_stencil_state = brw_bind_depth_stencil_state; - brw->pipe.delete_depth_stencil_state = brw_delete_depth_stencil_state; + brw->pipe.create_depth_stencil_alpha_state = brw_create_depth_stencil_state; + brw->pipe.bind_depth_stencil_alpha_state = brw_bind_depth_stencil_state; + brw->pipe.delete_depth_stencil_alpha_state = brw_delete_depth_stencil_state; brw->pipe.create_rasterizer_state = brw_create_rasterizer_state; brw->pipe.bind_rasterizer_state = brw_bind_rasterizer_state; diff --git a/src/mesa/pipe/i965simple/brw_wm.c b/src/mesa/pipe/i965simple/brw_wm.c index f0a38d384b..0ee0fbed51 100644 --- a/src/mesa/pipe/i965simple/brw_wm.c +++ b/src/mesa/pipe/i965simple/brw_wm.c @@ -93,15 +93,14 @@ static void brw_wm_populate_key( struct brw_context *brw, /* Build the index for table lookup */ - /* _NEW_COLOR */ + /* BRW_NEW_DEPTH_STENCIL */ if (fp->UsesKill || - brw->attribs.AlphaTest->enabled) + brw->attribs.DepthStencil->alpha.enabled) lookup |= IZ_PS_KILL_ALPHATEST_BIT; if (fp->ComputesDepth) lookup |= IZ_PS_COMPUTES_DEPTH_BIT; - /* _NEW_DEPTH */ if (brw->attribs.DepthStencil->depth.enabled) lookup |= IZ_DEPTH_TEST_ENABLE_BIT; @@ -109,13 +108,11 @@ static void brw_wm_populate_key( struct brw_context *brw, brw->attribs.DepthStencil->depth.writemask) /* ?? */ lookup |= IZ_DEPTH_WRITE_ENABLE_BIT; - /* _NEW_STENCIL */ - if (brw->attribs.DepthStencil->stencil.front_enabled) { + if (brw->attribs.DepthStencil->stencil[0].enabled) { lookup |= IZ_STENCIL_TEST_ENABLE_BIT; - if (brw->attribs.DepthStencil->stencil.write_mask[0] || - (brw->attribs.DepthStencil->stencil.back_enabled && - brw->attribs.DepthStencil->stencil.write_mask[1])) + if (brw->attribs.DepthStencil->stencil[0].write_mask || + brw->attribs.DepthStencil->stencil[1].write_mask) lookup |= IZ_STENCIL_WRITE_ENABLE_BIT; } diff --git a/src/mesa/pipe/i965simple/brw_wm_state.c b/src/mesa/pipe/i965simple/brw_wm_state.c index 52d2c85423..5ccd488842 100644 --- a/src/mesa/pipe/i965simple/brw_wm_state.c +++ b/src/mesa/pipe/i965simple/brw_wm_state.c @@ -122,7 +122,7 @@ static void upload_wm_unit(struct brw_context *brw ) /* BRW_NEW_ALPHA_TEST */ if (fp->UsesKill || - brw->attribs.AlphaTest->enabled) + brw->attribs.DepthStencil->alpha.enabled) wm.wm5.program_uses_killpixel = 1; wm.wm5.enable_8_pix = 1; diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 92ca7dd8e3..1afb38a868 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -102,11 +102,6 @@ struct pipe_context { /* * State functions */ - void * (*create_alpha_test_state)(struct pipe_context *, - const struct pipe_alpha_test_state *); - void (*bind_alpha_test_state)(struct pipe_context *, void *); - void (*delete_alpha_test_state)(struct pipe_context *, void *); - void * (*create_blend_state)(struct pipe_context *, const struct pipe_blend_state *); void (*bind_blend_state)(struct pipe_context *, void *); @@ -122,10 +117,10 @@ struct pipe_context { void (*bind_rasterizer_state)(struct pipe_context *, void *); void (*delete_rasterizer_state)(struct pipe_context *, void *); - void * (*create_depth_stencil_state)(struct pipe_context *, - const struct pipe_depth_stencil_state *); - void (*bind_depth_stencil_state)(struct pipe_context *, void *); - void (*delete_depth_stencil_state)(struct pipe_context *, void *); + void * (*create_depth_stencil_alpha_state)(struct pipe_context *, + const struct pipe_depth_stencil_alpha_state *); + void (*bind_depth_stencil_alpha_state)(struct pipe_context *, void *); + void (*delete_depth_stencil_alpha_state)(struct pipe_context *, void *); void * (*create_fs_state)(struct pipe_context *, const struct pipe_shader_state *); diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index af65d365bf..b7793c6d31 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -147,7 +147,7 @@ struct pipe_shader_state { ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS]; }; -struct pipe_depth_stencil_state +struct pipe_depth_stencil_alpha_state { struct { unsigned enabled:1; /**< depth test enabled? */ @@ -156,28 +156,24 @@ struct pipe_depth_stencil_state unsigned occlusion_count:1; /**< XXX move this elsewhere? */ } depth; struct { - unsigned front_enabled:1; - unsigned front_func:3; /**< PIPE_FUNC_x */ - unsigned front_fail_op:3; /**< PIPE_STENCIL_OP_x */ - unsigned front_zpass_op:3; /**< PIPE_STENCIL_OP_x */ - unsigned front_zfail_op:3; /**< PIPE_STENCIL_OP_x */ - unsigned back_enabled:1; - unsigned back_func:3; /**< PIPE_FUNC_x */ - unsigned back_fail_op:3; /**< PIPE_STENCIL_OP_x */ - unsigned back_zpass_op:3; /**< PIPE_STENCIL_OP_x */ - unsigned back_zfail_op:3; /**< PIPE_STENCIL_OP_x */ - ubyte ref_value[2]; /**< [0] = front, [1] = back */ - ubyte value_mask[2]; - ubyte write_mask[2]; - } stencil; -}; + unsigned enabled:1; + unsigned func:3; /**< PIPE_FUNC_x */ + unsigned fail_op:3; /**< PIPE_STENCIL_OP_x */ + unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */ + unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */ + ubyte ref_value; + ubyte value_mask; + ubyte write_mask; + } stencil[2]; /**< [0] = front, [1] = back */ -struct pipe_alpha_test_state { - unsigned enabled:1; - unsigned func:3; /**< PIPE_FUNC_x */ - float ref; /**< reference value */ + struct { + unsigned enabled:1; + unsigned func:3; /**< PIPE_FUNC_x */ + float ref; /**< reference value */ + } alpha; }; + struct pipe_blend_state { unsigned blend_enable:1; diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index b62e691e87..b6995b8a6c 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -240,10 +240,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.get_paramf = softpipe_get_paramf; /* state setters */ - softpipe->pipe.create_alpha_test_state = softpipe_create_alpha_test_state; - softpipe->pipe.bind_alpha_test_state = softpipe_bind_alpha_test_state; - softpipe->pipe.delete_alpha_test_state = softpipe_delete_alpha_test_state; - softpipe->pipe.create_blend_state = softpipe_create_blend_state; softpipe->pipe.bind_blend_state = softpipe_bind_blend_state; softpipe->pipe.delete_blend_state = softpipe_delete_blend_state; @@ -252,9 +248,9 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.bind_sampler_state = softpipe_bind_sampler_state; softpipe->pipe.delete_sampler_state = softpipe_delete_sampler_state; - softpipe->pipe.create_depth_stencil_state = softpipe_create_depth_stencil_state; - softpipe->pipe.bind_depth_stencil_state = softpipe_bind_depth_stencil_state; - softpipe->pipe.delete_depth_stencil_state = softpipe_delete_depth_stencil_state; + softpipe->pipe.create_depth_stencil_alpha_state = softpipe_create_depth_stencil_state; + softpipe->pipe.bind_depth_stencil_alpha_state = softpipe_bind_depth_stencil_state; + softpipe->pipe.delete_depth_stencil_alpha_state = softpipe_delete_depth_stencil_state; softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state; softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 8fd44933f2..8f14dd11d1 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -53,13 +53,13 @@ struct softpipe_tile_cache; #define SP_NEW_SCISSOR 0x20 #define SP_NEW_STIPPLE 0x40 #define SP_NEW_FRAMEBUFFER 0x80 -#define SP_NEW_ALPHA_TEST 0x100 -#define SP_NEW_DEPTH_STENCIL 0x200 +#define SP_NEW_DEPTH_STENCIL_ALPHA 0x100 +#define SP_NEW_CONSTANTS 0x200 #define SP_NEW_SAMPLER 0x400 #define SP_NEW_TEXTURE 0x800 #define SP_NEW_VERTEX 0x1000 #define SP_NEW_VS 0x2000 -#define SP_NEW_CONSTANTS 0x4000 +#define SP_NEW_QUERY 0x4000 struct sp_vertex_shader_state { struct pipe_shader_state *state; @@ -73,10 +73,9 @@ struct softpipe_context { /* The most recent drawing state as set by the driver: */ - const struct pipe_alpha_test_state *alpha_test; const struct pipe_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; - const struct pipe_depth_stencil_state *depth_stencil; + const struct pipe_depth_stencil_alpha_state *depth_stencil; const struct pipe_rasterizer_state *rasterizer; const struct sp_fragment_shader_state *fs; const struct sp_vertex_shader_state *vs; diff --git a/src/mesa/pipe/softpipe/sp_quad.c b/src/mesa/pipe/softpipe/sp_quad.c index 6330465a8b..a10c9c3e02 100644 --- a/src/mesa/pipe/softpipe/sp_quad.c +++ b/src/mesa/pipe/softpipe/sp_quad.c @@ -43,8 +43,8 @@ static void sp_build_depth_stencil( struct softpipe_context *sp ) { - if (sp->depth_stencil->stencil.front_enabled || - sp->depth_stencil->stencil.back_enabled) { + if (sp->depth_stencil->stencil[0].enabled || + sp->depth_stencil->stencil[1].enabled) { sp_push_quad_first( sp, sp->quad.stencil_test ); } else if (sp->depth_stencil->depth.enabled && @@ -59,7 +59,7 @@ sp_build_quad_pipeline(struct softpipe_context *sp) boolean early_depth_test = sp->depth_stencil->depth.enabled && sp->framebuffer.zbuf && - !sp->alpha_test->enabled && + !sp->depth_stencil->alpha.enabled && sp->fs->shader.output_semantic_name[0] != TGSI_SEMANTIC_POSITION; /* build up the pipeline in reverse order... */ @@ -98,7 +98,7 @@ sp_build_quad_pipeline(struct softpipe_context *sp) sp_build_depth_stencil( sp ); } - if (sp->alpha_test->enabled) { + if (sp->depth_stencil->alpha.enabled) { sp_push_quad_first( sp, sp->quad.alpha_test ); } diff --git a/src/mesa/pipe/softpipe/sp_quad_alpha_test.c b/src/mesa/pipe/softpipe/sp_quad_alpha_test.c index d056abe98d..4ffeac35e1 100644 --- a/src/mesa/pipe/softpipe/sp_quad_alpha_test.c +++ b/src/mesa/pipe/softpipe/sp_quad_alpha_test.c @@ -14,11 +14,11 @@ static void alpha_test_quad(struct quad_stage *qs, struct quad_header *quad) { struct softpipe_context *softpipe = qs->softpipe; - const float ref = softpipe->alpha_test->ref; + const float ref = softpipe->depth_stencil->alpha.ref; unsigned passMask = 0x0, j; const float *aaaa = quad->outputs.color[3]; - switch (softpipe->alpha_test->func) { + switch (softpipe->depth_stencil->alpha.func) { case PIPE_FUNC_NEVER: quad->mask = 0x0; break; diff --git a/src/mesa/pipe/softpipe/sp_quad_stencil.c b/src/mesa/pipe/softpipe/sp_quad_stencil.c index 3f3eca078b..a688a06c74 100644 --- a/src/mesa/pipe/softpipe/sp_quad_stencil.c +++ b/src/mesa/pipe/softpipe/sp_quad_stencil.c @@ -211,24 +211,13 @@ stencil_test_quad(struct quad_stage *qs, struct quad_header *quad) /* choose front or back face function, operator, etc */ /* XXX we could do these initializations once per primitive */ - if (softpipe->depth_stencil->stencil.back_enabled && quad->facing) { - func = softpipe->depth_stencil->stencil.back_func; - failOp = softpipe->depth_stencil->stencil.back_fail_op; - zFailOp = softpipe->depth_stencil->stencil.back_zfail_op; - zPassOp = softpipe->depth_stencil->stencil.back_zpass_op; - ref = softpipe->depth_stencil->stencil.ref_value[1]; - wrtMask = softpipe->depth_stencil->stencil.write_mask[1]; - valMask = softpipe->depth_stencil->stencil.value_mask[1]; - } - else { - func = softpipe->depth_stencil->stencil.front_func; - failOp = softpipe->depth_stencil->stencil.front_fail_op; - zFailOp = softpipe->depth_stencil->stencil.front_zfail_op; - zPassOp = softpipe->depth_stencil->stencil.front_zpass_op; - ref = softpipe->depth_stencil->stencil.ref_value[0]; - wrtMask = softpipe->depth_stencil->stencil.write_mask[0]; - valMask = softpipe->depth_stencil->stencil.value_mask[0]; - } + func = softpipe->depth_stencil->stencil[quad->facing].func; + failOp = softpipe->depth_stencil->stencil[quad->facing].fail_op; + zFailOp = softpipe->depth_stencil->stencil[quad->facing].zfail_op; + zPassOp = softpipe->depth_stencil->stencil[quad->facing].zpass_op; + ref = softpipe->depth_stencil->stencil[quad->facing].ref_value; + wrtMask = softpipe->depth_stencil->stencil[quad->facing].write_mask; + valMask = softpipe->depth_stencil->stencil[quad->facing].value_mask; assert(ps); /* shouldn't get here if there's no stencil buffer */ diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index a3bd078a71..76b79b5280 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -52,13 +52,6 @@ struct sp_fragment_shader_state { #endif }; -void * -softpipe_create_alpha_test_state(struct pipe_context *, - const struct pipe_alpha_test_state *); -void -softpipe_bind_alpha_test_state(struct pipe_context *, void *); -void -softpipe_delete_alpha_test_state(struct pipe_context *, void *); void * softpipe_create_blend_state(struct pipe_context *, @@ -76,7 +69,7 @@ void softpipe_delete_sampler_state(struct pipe_context *, void *); void * softpipe_create_depth_stencil_state(struct pipe_context *, - const struct pipe_depth_stencil_state *); + const struct pipe_depth_stencil_alpha_state *); void softpipe_bind_depth_stencil_state(struct pipe_context *, void *); void softpipe_delete_depth_stencil_state(struct pipe_context *, void *); diff --git a/src/mesa/pipe/softpipe/sp_state_blend.c b/src/mesa/pipe/softpipe/sp_state_blend.c index 5ceec2513f..160ca5cbc0 100644 --- a/src/mesa/pipe/softpipe/sp_state_blend.c +++ b/src/mesa/pipe/softpipe/sp_state_blend.c @@ -73,40 +73,14 @@ void softpipe_set_blend_color( struct pipe_context *pipe, * into one file. */ -void * -softpipe_create_alpha_test_state(struct pipe_context *pipe, - const struct pipe_alpha_test_state *alpha) -{ - struct pipe_alpha_test_state *state = MALLOC( sizeof(struct pipe_alpha_test_state) ); - memcpy(state, alpha, sizeof(struct pipe_alpha_test_state)); - return state; -} - -void -softpipe_bind_alpha_test_state(struct pipe_context *pipe, - void *alpha) -{ - struct softpipe_context *softpipe = softpipe_context(pipe); - - softpipe->alpha_test = (const struct pipe_alpha_test_state *)alpha; - - softpipe->dirty |= SP_NEW_ALPHA_TEST; -} - -void -softpipe_delete_alpha_test_state(struct pipe_context *pipe, - void *alpha) -{ - FREE( alpha ); -} void * softpipe_create_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_state *depth_stencil) + const struct pipe_depth_stencil_alpha_state *depth_stencil) { - struct pipe_depth_stencil_state *state = - MALLOC( sizeof(struct pipe_depth_stencil_state) ); - memcpy(state, depth_stencil, sizeof(struct pipe_depth_stencil_state)); + struct pipe_depth_stencil_alpha_state *state = + MALLOC( sizeof(struct pipe_depth_stencil_alpha_state) ); + memcpy(state, depth_stencil, sizeof(struct pipe_depth_stencil_alpha_state)); return state; } @@ -116,9 +90,9 @@ softpipe_bind_depth_stencil_state(struct pipe_context *pipe, { struct softpipe_context *softpipe = softpipe_context(pipe); - softpipe->depth_stencil = (const struct pipe_depth_stencil_state *)depth_stencil; + softpipe->depth_stencil = (const struct pipe_depth_stencil_alpha_state *)depth_stencil; - softpipe->dirty |= SP_NEW_DEPTH_STENCIL; + softpipe->dirty |= SP_NEW_DEPTH_STENCIL_ALPHA; } void diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index 736ac1c33b..94072a2d30 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -201,16 +201,16 @@ void softpipe_update_derived( struct softpipe_context *softpipe ) calculate_vertex_layout( softpipe ); if (softpipe->dirty & (SP_NEW_SCISSOR | - SP_NEW_DEPTH_STENCIL | + SP_NEW_DEPTH_STENCIL_ALPHA | SP_NEW_FRAMEBUFFER)) compute_cliprect(softpipe); if (softpipe->dirty & (SP_NEW_BLEND | - SP_NEW_DEPTH_STENCIL | - SP_NEW_ALPHA_TEST | + SP_NEW_DEPTH_STENCIL_ALPHA | SP_NEW_FRAMEBUFFER | SP_NEW_RASTERIZER | - SP_NEW_FS)) + SP_NEW_FS | + SP_NEW_QUERY)) sp_build_quad_pipeline(softpipe); softpipe->dirty = 0; diff --git a/src/mesa/sources b/src/mesa/sources index 5d29d20aed..56ea6dbce2 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -201,7 +201,6 @@ PIPEUTIL_SOURCES = \ STATETRACKER_SOURCES = \ state_tracker/st_atom.c \ - state_tracker/st_atom_alphatest.c \ state_tracker/st_atom_blend.c \ state_tracker/st_atom_clip.c \ state_tracker/st_atom_constbuf.c \ diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index bde81edd8c..0e22a2fa6e 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -45,7 +45,7 @@ static const struct st_tracked_state *atoms[] = { &st_update_framebuffer, - &st_update_depth_stencil, + &st_update_depth_stencil_alpha, &st_update_clip, &st_update_shader, @@ -59,7 +59,6 @@ static const struct st_tracked_state *atoms[] = &st_update_texture, &st_update_vs_constants, &st_update_fs_constants, - &st_update_alpha_test, &st_update_pixel_transfer }; diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 0114f42ba5..3a63e2dec0 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -46,7 +46,7 @@ void st_validate_state( struct st_context *st ); const struct st_tracked_state st_update_framebuffer; const struct st_tracked_state st_update_clip; -const struct st_tracked_state st_update_depth_stencil; +const struct st_tracked_state st_update_depth_stencil_alpha; const struct st_tracked_state st_update_shader; const struct st_tracked_state st_update_rasterizer; const struct st_tracked_state st_update_polygon_stipple; @@ -57,7 +57,6 @@ const struct st_tracked_state st_update_sampler; const struct st_tracked_state st_update_texture; const struct st_tracked_state st_update_fs_constants; const struct st_tracked_state st_update_vs_constants; -const struct st_tracked_state st_update_alpha_test; const struct st_tracked_state st_update_pixel_transfer; diff --git a/src/mesa/state_tracker/st_atom_alphatest.c b/src/mesa/state_tracker/st_atom_alphatest.c deleted file mode 100644 index 873520ab02..0000000000 --- a/src/mesa/state_tracker/st_atom_alphatest.c +++ /dev/null @@ -1,92 +0,0 @@ -/************************************************************************** - * - * 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 - * Brian Paul - */ - - -#include "st_context.h" -#include "st_cache.h" -#include "st_atom.h" -#include "pipe/p_context.h" -#include "pipe/p_defines.h" - - -/** - * Convert GLenum stencil func tokens to pipe tokens. - */ -static GLuint -gl_alpha_func_to_sp(GLenum func) -{ - /* Same values, just biased */ - assert(PIPE_FUNC_NEVER == GL_NEVER - GL_NEVER); - assert(PIPE_FUNC_LESS == GL_LESS - GL_NEVER); - assert(PIPE_FUNC_EQUAL == GL_EQUAL - GL_NEVER); - assert(PIPE_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); - assert(PIPE_FUNC_GREATER == GL_GREATER - GL_NEVER); - assert(PIPE_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); - assert(PIPE_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); - assert(PIPE_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); - assert(func >= GL_NEVER); - assert(func <= GL_ALWAYS); - return func - GL_NEVER; -} - - -static void -update_alpha_test( struct st_context *st ) -{ - struct pipe_alpha_test_state alpha; - const struct cso_alpha_test *cso; - - memset(&alpha, 0, sizeof(alpha)); - - if (st->ctx->Color.AlphaEnabled) { - alpha.enabled = 1; - alpha.func = gl_alpha_func_to_sp(st->ctx->Color.AlphaFunc); - alpha.ref = st->ctx->Color.AlphaRef; - } - cso = st_cached_alpha_test_state(st, &alpha); - if (st->state.alpha_test != cso) { - /* state has changed */ - st->state.alpha_test = cso; - st->pipe->bind_alpha_test_state(st->pipe, cso->data); /* bind new state */ - } -} - - -const struct st_tracked_state st_update_alpha_test = { - .name = "st_update_alpha_test", - .dirty = { - .mesa = (_NEW_COLOR), - .st = 0, - }, - .update = update_alpha_test -}; diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index e785434cec..7aecdbfbcc 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -91,10 +91,10 @@ gl_stencil_op_to_pipe(GLenum func) } static void -update_depth_stencil(struct st_context *st) +update_depth_stencil_alpha(struct st_context *st) { - struct pipe_depth_stencil_state depth_stencil; - const struct cso_depth_stencil *cso; + struct pipe_depth_stencil_alpha_state depth_stencil; + const struct cso_depth_stencil_alpha *cso; memset(&depth_stencil, 0, sizeof(depth_stencil)); @@ -107,40 +107,47 @@ update_depth_stencil(struct st_context *st) depth_stencil.depth.occlusion_count = 1; if (st->ctx->Stencil.Enabled) { - depth_stencil.stencil.front_enabled = 1; - depth_stencil.stencil.front_func = st_compare_func_to_pipe(st->ctx->Stencil.Function[0]); - depth_stencil.stencil.front_fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[0]); - depth_stencil.stencil.front_zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[0]); - depth_stencil.stencil.front_zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[0]); - depth_stencil.stencil.ref_value[0] = st->ctx->Stencil.Ref[0] & 0xff; - depth_stencil.stencil.value_mask[0] = st->ctx->Stencil.ValueMask[0] & 0xff; - depth_stencil.stencil.write_mask[0] = st->ctx->Stencil.WriteMask[0] & 0xff; + depth_stencil.stencil[0].enabled = 1; + depth_stencil.stencil[0].func = st_compare_func_to_pipe(st->ctx->Stencil.Function[0]); + depth_stencil.stencil[0].fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[0]); + depth_stencil.stencil[0].zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[0]); + depth_stencil.stencil[0].zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[0]); + depth_stencil.stencil[0].ref_value = st->ctx->Stencil.Ref[0] & 0xff; + depth_stencil.stencil[0].value_mask = st->ctx->Stencil.ValueMask[0] & 0xff; + depth_stencil.stencil[0].write_mask = st->ctx->Stencil.WriteMask[0] & 0xff; + if (st->ctx->Stencil.TestTwoSide) { - depth_stencil.stencil.back_enabled = 1; - depth_stencil.stencil.back_func = st_compare_func_to_pipe(st->ctx->Stencil.Function[1]); - depth_stencil.stencil.back_fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[1]); - depth_stencil.stencil.back_zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[1]); - depth_stencil.stencil.back_zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[1]); - depth_stencil.stencil.ref_value[1] = st->ctx->Stencil.Ref[1] & 0xff; - depth_stencil.stencil.value_mask[1] = st->ctx->Stencil.ValueMask[1] & 0xff; - depth_stencil.stencil.write_mask[1] = st->ctx->Stencil.WriteMask[1] & 0xff; + depth_stencil.stencil[1].enabled = 1; + depth_stencil.stencil[1].func = st_compare_func_to_pipe(st->ctx->Stencil.Function[1]); + depth_stencil.stencil[1].fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[1]); + depth_stencil.stencil[1].zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[1]); + depth_stencil.stencil[1].zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[1]); + depth_stencil.stencil[1].ref_value = st->ctx->Stencil.Ref[1] & 0xff; + depth_stencil.stencil[1].value_mask = st->ctx->Stencil.ValueMask[1] & 0xff; + depth_stencil.stencil[1].write_mask = st->ctx->Stencil.WriteMask[1] & 0xff; } } - cso = st_cached_depth_stencil_state(st, &depth_stencil); + if (st->ctx->Color.AlphaEnabled) { + depth_stencil.alpha.enabled = 1; + depth_stencil.alpha.func = st_compare_func_to_pipe(st->ctx->Color.AlphaFunc); + depth_stencil.alpha.ref = st->ctx->Color.AlphaRef; + } + + cso = st_cached_depth_stencil_alpha_state(st, &depth_stencil); if (st->state.depth_stencil != cso) { /* state has changed */ st->state.depth_stencil = cso; - st->pipe->bind_depth_stencil_state(st->pipe, cso->data); /* bind new state */ + st->pipe->bind_depth_stencil_alpha_state(st->pipe, cso->data); /* bind new state */ } } -const struct st_tracked_state st_update_depth_stencil = { +const struct st_tracked_state st_update_depth_stencil_alpha = { .name = "st_update_depth_stencil", .dirty = { - .mesa = (_NEW_DEPTH|_NEW_STENCIL), + .mesa = (_NEW_DEPTH|_NEW_STENCIL|_NEW_COLOR), .st = 0, }, - .update = update_depth_stencil + .update = update_depth_stencil_alpha }; diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index c0f712ba1d..e0965b217a 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -87,24 +87,25 @@ st_cached_sampler_state(struct st_context *st, return (struct cso_sampler*)(cso_hash_iter_data(iter)); } -const struct cso_depth_stencil * -st_cached_depth_stencil_state(struct st_context *st, - const struct pipe_depth_stencil_state *templ) +const struct cso_depth_stencil_alpha * +st_cached_depth_stencil_alpha_state(struct st_context *st, + const struct pipe_depth_stencil_alpha_state *templ) { unsigned hash_key = cso_construct_key((void*)templ, - sizeof(struct pipe_depth_stencil_state)); + sizeof(struct pipe_depth_stencil_alpha_state)); struct cso_hash_iter iter = cso_find_state_template(st->cache, - hash_key, CSO_DEPTH_STENCIL, + hash_key, + CSO_DEPTH_STENCIL_ALPHA, (void*)templ); if (cso_hash_iter_is_null(iter)) { - struct cso_depth_stencil *cso = malloc(sizeof(struct cso_depth_stencil)); - memcpy(&cso->state, templ, sizeof(struct pipe_depth_stencil_state)); - cso->data = st->pipe->create_depth_stencil_state(st->pipe, &cso->state); + struct cso_depth_stencil_alpha *cso = malloc(sizeof(struct cso_depth_stencil_alpha)); + memcpy(&cso->state, templ, sizeof(struct pipe_depth_stencil_alpha_state)); + cso->data = st->pipe->create_depth_stencil_alpha_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; - iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL, cso); + iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL_ALPHA, cso); } - return (struct cso_depth_stencil*)(cso_hash_iter_data(iter)); + return (struct cso_depth_stencil_alpha*)(cso_hash_iter_data(iter)); } const struct cso_rasterizer* st_cached_rasterizer_state( @@ -167,22 +168,3 @@ st_cached_vs_state(struct st_context *st, return (struct cso_vertex_shader*)(cso_hash_iter_data(iter)); } -const struct cso_alpha_test * -st_cached_alpha_test_state(struct st_context *st, - const struct pipe_alpha_test_state *templ) -{ - unsigned hash_key = cso_construct_key((void*)templ, - sizeof(struct pipe_alpha_test_state)); - struct cso_hash_iter iter = cso_find_state_template(st->cache, - hash_key, CSO_ALPHA_TEST, - (void*)templ); - if (cso_hash_iter_is_null(iter)) { - struct cso_alpha_test *cso = malloc(sizeof(struct cso_alpha_test)); - memcpy(&cso->state, templ, sizeof(struct pipe_alpha_test_state)); - cso->data = st->pipe->create_alpha_test_state(st->pipe, &cso->state); - if (!cso->data) - cso->data = &cso->state; - iter = cso_insert_state(st->cache, hash_key, CSO_ALPHA_TEST, cso); - } - return ((struct cso_alpha_test *)cso_hash_iter_data(iter)); -} diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index 422f668c56..e0c176b0ff 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -39,9 +39,6 @@ struct pipe_blend_state; struct pipe_sampler_state; struct st_context; -const struct cso_alpha_test * -st_cached_alpha_test_state(struct st_context *st, - const struct pipe_alpha_test_state *alpha); const struct cso_blend * st_cached_blend_state(struct st_context *st, @@ -51,9 +48,9 @@ const struct cso_sampler * st_cached_sampler_state(struct st_context *st, const struct pipe_sampler_state *sampler); -const struct cso_depth_stencil * -st_cached_depth_stencil_state(struct st_context *st, - const struct pipe_depth_stencil_state *depth_stencil); +const struct cso_depth_stencil_alpha * +st_cached_depth_stencil_alpha_state(struct st_context *st, + const struct pipe_depth_stencil_alpha_state *depth_stencil); const struct cso_rasterizer * st_cached_rasterizer_state(struct st_context *st, diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index b4b2429a2a..40319f4b4b 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -272,14 +272,6 @@ clear_with_quad(GLcontext *ctx, const GLfloat x1 = ctx->DrawBuffer->_Xmax; const GLfloat y1 = ctx->DrawBuffer->_Ymax; - /* alpha state: disabled */ - { - struct pipe_alpha_test_state alpha_test; - const struct cso_alpha_test *cso; - memset(&alpha_test, 0, sizeof(alpha_test)); - cso = st_cached_alpha_test_state(st, &alpha_test); - pipe->bind_alpha_test_state(pipe, cso->data); - } /* blend state: RGBA masking */ { @@ -304,8 +296,8 @@ clear_with_quad(GLcontext *ctx, /* depth_stencil state: always pass/set to ref value */ { - struct pipe_depth_stencil_state depth_stencil; - const struct cso_depth_stencil *cso; + struct pipe_depth_stencil_alpha_state depth_stencil; + const struct cso_depth_stencil_alpha *cso; memset(&depth_stencil, 0, sizeof(depth_stencil)); if (depth) { depth_stencil.depth.enabled = 1; @@ -314,17 +306,17 @@ clear_with_quad(GLcontext *ctx, } if (stencil) { - depth_stencil.stencil.front_enabled = 1; - depth_stencil.stencil.front_func = PIPE_FUNC_ALWAYS; - depth_stencil.stencil.front_fail_op = PIPE_STENCIL_OP_REPLACE; - depth_stencil.stencil.front_zpass_op = PIPE_STENCIL_OP_REPLACE; - depth_stencil.stencil.front_zfail_op = PIPE_STENCIL_OP_REPLACE; - depth_stencil.stencil.ref_value[0] = ctx->Stencil.Clear; - depth_stencil.stencil.value_mask[0] = 0xff; - depth_stencil.stencil.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; + depth_stencil.stencil[0].enabled = 1; + depth_stencil.stencil[0].func = PIPE_FUNC_ALWAYS; + depth_stencil.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE; + depth_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE; + depth_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE; + depth_stencil.stencil[0].ref_value = ctx->Stencil.Clear; + depth_stencil.stencil[0].value_mask = 0xff; + depth_stencil.stencil[0].write_mask = ctx->Stencil.WriteMask[0] & 0xff; } - cso = st_cached_depth_stencil_state(st, &depth_stencil); - pipe->bind_depth_stencil_state(pipe, cso->data); + cso = st_cached_depth_stencil_alpha_state(st, &depth_stencil); + pipe->bind_depth_stencil_alpha_state(pipe, cso->data); } /* rasterizer state: nothing */ @@ -381,9 +373,8 @@ clear_with_quad(GLcontext *ctx, draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); /* Restore pipe state */ - pipe->bind_alpha_test_state(pipe, st->state.alpha_test->data); pipe->bind_blend_state(pipe, st->state.blend->data); - pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil->data); + pipe->bind_depth_stencil_alpha_state(pipe, st->state.depth_stencil->data); pipe->bind_fs_state(pipe, st->state.fs->data); pipe->bind_vs_state(pipe, st->state.vs->data); pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 0bc48b7039..e70a5b49e1 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -789,7 +789,7 @@ compatible_formats(GLenum format, GLenum type, enum pipe_format pipeFormat) static GLboolean any_fragment_ops(const struct st_context *st) { - if (st->state.alpha_test->state.enabled || + if (st->state.depth_stencil->state.alpha.enabled || st->state.blend->state.blend_enable || st->state.blend->state.logicop_enable || st->state.depth_stencil->state.depth.enabled) diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 87646b3c71..c3919d474c 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -97,7 +97,7 @@ struct st_context const struct cso_alpha_test *alpha_test; const struct cso_blend *blend; const struct cso_sampler *sampler[PIPE_MAX_SAMPLERS]; - const struct cso_depth_stencil *depth_stencil; + const struct cso_depth_stencil_alpha *depth_stencil; const struct cso_rasterizer *rasterizer; const struct cso_fragment_shader *fs; const struct cso_vertex_shader *vs; -- cgit v1.2.3 From ac95fee4fffee77bb7bd798d094ed2e3a7c4019b Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 14 Jan 2008 19:12:46 -0700 Subject: Fix problems with vertex shaders and the private draw module. The CSO returned by pipe->create_vs_state() can't be passed to the private draw module. That was causing glRasterPos to blow up. Add a 'draw_shader' field to st_vertex_program for use with the private draw module. Change st_context->state.vs type from cso_vertex_shader to st_vertex_program. --- src/mesa/state_tracker/st_atom_shader.c | 23 +++++++++++++---------- src/mesa/state_tracker/st_cb_clear.c | 6 +++--- src/mesa/state_tracker/st_cb_drawpixels.c | 4 ++-- src/mesa/state_tracker/st_cb_program.c | 11 +++++++---- src/mesa/state_tracker/st_context.h | 2 +- src/mesa/state_tracker/st_debug.c | 4 ++-- src/mesa/state_tracker/st_draw.c | 12 ++++++++---- src/mesa/state_tracker/st_program.c | 6 ++---- src/mesa/state_tracker/st_program.h | 7 +++++-- 9 files changed, 43 insertions(+), 32 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 2a182c7d9c..1ed9333556 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -43,6 +43,8 @@ #include "pipe/p_context.h" #include "pipe/p_shader_tokens.h" +#include "pipe/cso_cache/cso_cache.h" + #include "st_context.h" #include "st_cache.h" #include "st_atom.h" @@ -71,8 +73,8 @@ struct translated_vertex_program /** The program in TGSI format */ struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; - /** Pointer to the translated, cached vertex shader */ - const struct cso_vertex_shader *vs; + /** Pointer to the translated vertex program */ + struct st_vertex_program *vp; struct translated_vertex_program *next; /**< next in linked list */ }; @@ -257,12 +259,13 @@ find_translated_vp(struct st_context *st, assert(stvp->Base.Base.NumInstructions > 1); - xvp->vs = st_translate_vertex_program(st, stvp, - xvp->output_to_slot, - xvp->tokens, - ST_MAX_SHADER_TOKENS); - assert(xvp->vs); - stvp->vs = NULL; /* don't want to use this */ + st_translate_vertex_program(st, stvp, + xvp->output_to_slot, + xvp->tokens, + ST_MAX_SHADER_TOKENS); + + assert(stvp->cso); + xvp->vp = stvp; /* translated VP is up to date now */ xvp->serialNo = stvp->serialNo; @@ -291,8 +294,8 @@ update_linkage( struct st_context *st ) xvp = find_translated_vp(st, stvp, stfp); st->vp = stvp; - st->state.vs = xvp->vs; - st->pipe->bind_vs_state(st->pipe, st->state.vs->data); + st->state.vs = xvp->vp; + st->pipe->bind_vs_state(st->pipe, st->state.vs->cso->data); st->fp = stfp; st->state.fs = stfp->fs; diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 40319f4b4b..758d4a4086 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -208,7 +208,7 @@ make_vertex_shader(struct st_context *st) stvp = (struct st_vertex_program *) p; st_translate_vertex_program(st, stvp, NULL, stvp->tokens, ST_MAX_SHADER_TOKENS); - assert(stvp->vs); + assert(stvp->cso); return stvp; } @@ -350,7 +350,7 @@ clear_with_quad(GLcontext *ctx, if (!stvp) { stvp = make_vertex_shader(st); } - pipe->bind_vs_state(pipe, stvp->vs->data); + pipe->bind_vs_state(pipe, stvp->cso->data); } /* viewport state: viewport matching window dims */ @@ -376,7 +376,7 @@ clear_with_quad(GLcontext *ctx, pipe->bind_blend_state(pipe, st->state.blend->data); pipe->bind_depth_stencil_alpha_state(pipe, st->state.depth_stencil->data); pipe->bind_fs_state(pipe, st->state.fs->data); - pipe->bind_vs_state(pipe, st->state.vs->data); + pipe->bind_vs_state(pipe, st->state.vs->cso->data); pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); pipe->set_viewport_state(pipe, &st->state.viewport); /* OR: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index be5434f91b..f4d6b9362c 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -662,7 +662,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->bind_fs_state(pipe, stfp->fs->data); /* vertex shader state: position + texcoord pass-through */ - pipe->bind_vs_state(pipe, stvp->vs->data); + pipe->bind_vs_state(pipe, stvp->cso->data); /* texture sampling state: */ { @@ -719,7 +719,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* restore GL state */ pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer->data); pipe->bind_fs_state(pipe, ctx->st->state.fs->data); - pipe->bind_vs_state(pipe, ctx->st->state.vs->data); + pipe->bind_vs_state(pipe, ctx->st->state.vs->cso->data); pipe->set_sampler_texture(pipe, unit, ctx->st->state.sampler_texture[unit]); pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]->data); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index aed6b1ee97..63a954264e 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -39,6 +39,8 @@ #include "shader/programopt.h" #include "shader/shader_api.h" +#include "pipe/cso_cache/cso_cache.h" + #include "st_context.h" #include "st_program.h" #include "st_atom_shader.h" @@ -181,10 +183,11 @@ static void st_program_string_notify( GLcontext *ctx, stvp->serialNo++; - if (stvp->vs) { - /* free the TGSI code */ - // cso_delete(stfp->vs); - stvp->vs = NULL; + if (stvp->cso) { + /* free the CSO data */ + st->pipe->delete_vs_state(st->pipe, stvp->cso->data); + FREE((void *) stvp->cso); + stvp->cso = NULL; } stvp->param_state = stvp->Base.Base.Parameters->StateFlags; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 0f40f3ceee..5ae21c93f9 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -100,7 +100,7 @@ struct st_context const struct cso_depth_stencil_alpha *depth_stencil; const struct cso_rasterizer *rasterizer; const struct cso_fragment_shader *fs; - const struct cso_vertex_shader *vs; + struct st_vertex_program *vs; struct pipe_blend_color blend_color; struct pipe_clip_state clip; diff --git a/src/mesa/state_tracker/st_debug.c b/src/mesa/state_tracker/st_debug.c index cffd66751d..57450e52bf 100644 --- a/src/mesa/state_tracker/st_debug.c +++ b/src/mesa/state_tracker/st_debug.c @@ -53,11 +53,11 @@ st_print_current(void) int i; printf("Vertex Transform Inputs:\n"); - for (i = 0; i < st->state.vs->state.num_inputs; i++) { + for (i = 0; i < st->state.vs->cso->state.num_inputs; i++) { printf(" Slot %d: VERT_ATTRIB_%d\n", i, st->vp->index_to_input[i]); } - tgsi_dump( st->state.vs->state.tokens, 0 ); + tgsi_dump( st->state.vs->cso->state.tokens, 0 ); if (st->vp->Base.Base.Parameters) _mesa_print_parameter_list(st->vp->Base.Base.Parameters); diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 96db9e3c03..94b3a9531a 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -241,7 +241,7 @@ st_draw_vbo(GLcontext *ctx, /* must get these after state validation! */ vp = ctx->st->vp; - vs = &ctx->st->state.vs->state; + vs = &ctx->st->state.vs->cso->state; /* loop over TGSI shader inputs to determine vertex buffer * and attribute info @@ -447,7 +447,7 @@ set_feedback_vertex_format(GLcontext *ctx) else { /* GL_FEEDBACK, or glRasterPos */ /* emit all attribs (pos, color, texcoord) as GLfloat[4] */ - vinfo.num_attribs = st->state.vs->state.num_outputs; + vinfo.num_attribs = st->state.vs->cso->state.num_outputs; for (i = 0; i < vinfo.num_attribs; i++) { vinfo.format[i] = FORMAT_4F; vinfo.interp_mode[i] = INTERP_LINEAR; @@ -491,7 +491,11 @@ st_feedback_draw_vbo(GLcontext *ctx, /* must get these after state validation! */ vp = ctx->st->vp; - vs = &ctx->st->state.vs->state; + vs = &ctx->st->state.vs->cso->state; + + if (!st->state.vs->draw_shader) { + st->state.vs->draw_shader = draw_create_vertex_shader(draw, vs); + } /* * Set up the draw module's state. @@ -503,7 +507,7 @@ st_feedback_draw_vbo(GLcontext *ctx, draw_set_viewport_state(draw, &st->state.viewport); draw_set_clip_state(draw, &st->state.clip); draw_set_rasterizer_state(draw, &st->state.rasterizer->state); - draw_bind_vertex_shader(draw, st->state.vs->data); + draw_bind_vertex_shader(draw, st->state.vs->draw_shader); set_feedback_vertex_format(ctx); /* loop over TGSI shader inputs to determine vertex buffer diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 1852228b29..1f1e6500e0 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -57,7 +57,7 @@ * \param tokensOut destination for TGSI tokens * \return pointer to cached pipe_shader object. */ -const struct cso_vertex_shader * +void st_translate_vertex_program(struct st_context *st, struct st_vertex_program *stvp, const GLuint outputMapping[], @@ -256,12 +256,10 @@ st_translate_vertex_program(struct st_context *st, vs.tokens = tokensOut; cso = st_cached_vs_state(st, &vs); - stvp->vs = cso; + stvp->cso = cso; if (TGSI_DEBUG) tgsi_dump( tokensOut, 0 ); - - return cso; } diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 049f9f659f..de02c3185f 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -90,7 +90,10 @@ struct st_vertex_program struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; /** Pointer to the corresponding cached shader */ - const struct cso_vertex_shader *vs; + const struct cso_vertex_shader *cso; + + /** For using our private draw module (glRasterPos) */ + struct draw_vertex_shader *draw_shader; GLuint param_state; }; @@ -122,7 +125,7 @@ st_translate_fragment_program(struct st_context *st, GLuint maxTokens); -extern const struct cso_vertex_shader * +extern void st_translate_vertex_program(struct st_context *st, struct st_vertex_program *vp, const GLuint vert_output_to_slot[], -- cgit v1.2.3 From 16ed55c6412d2bdc5bff78e99114490223fb4afe Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 28 Jan 2008 09:23:29 -0700 Subject: gallium: check if surface has defined status in check_clear_depth_with_quad() This was part of Keith's patch from Friday. --- src/mesa/state_tracker/st_cb_clear.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 758d4a4086..0cd469c156 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -408,7 +408,9 @@ check_clear_depth_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) const struct st_renderbuffer *strb = st_renderbuffer(rb); const GLboolean isDS = is_depth_stencil_format(strb->surface->format); return ctx->Scissor.Enabled - || (isDS && ctx->DrawBuffer->Visual.stencilBits > 0); + || (isDS && + strb->surface->status == PIPE_SURFACE_STATUS_DEFINED && + ctx->DrawBuffer->Visual.stencilBits > 0); } -- cgit v1.2.3 From 0b64ee6960f9e099bc1a6ca6fa10720fee875b3a Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 8 Feb 2008 14:51:32 -0700 Subject: gallium: added inClipCoords param to st_draw_vertices() to indicate coord system of vertices Also, export st_make_passthrough_vertex_shader() from st_cb_drawpixels.c --- src/mesa/state_tracker/st_cb_clear.c | 2 +- src/mesa/state_tracker/st_cb_drawpixels.c | 18 +++++++++--------- src/mesa/state_tracker/st_cb_drawpixels.h | 4 ++++ src/mesa/state_tracker/st_draw.c | 21 ++++++++++++--------- src/mesa/state_tracker/st_draw.h | 3 ++- 5 files changed, 28 insertions(+), 20 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 0cd469c156..ab98b54bab 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -251,7 +251,7 @@ draw_quad(GLcontext *ctx, verts[i][1][3] = color[3]; } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, GL_FALSE); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 34d420fcff..07886e7982 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -355,8 +355,8 @@ make_fragment_shader_z(struct st_context *st) * Create a simple vertex shader that just passes through the * vertex position and texcoord (and optionally, color). */ -static struct st_vertex_program * -make_vertex_shader(struct st_context *st, GLboolean passColor) +struct st_vertex_program * +st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor) { /* only make programs once and re-use */ static struct st_vertex_program *progs[2] = { NULL, NULL }; @@ -572,7 +572,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, verts[i][1][3] = 1.0; /*Q*/ } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, GL_FALSE); } @@ -625,7 +625,7 @@ draw_quad_colored(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, verts[i][2][3] = 1.0; /*Q*/ } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 3); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 3, GL_FALSE); } @@ -945,7 +945,7 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (format == GL_DEPTH_COMPONENT) { ps = st->state.framebuffer.zsbuf; stfp = make_fragment_shader_z(ctx->st); - stvp = make_vertex_shader(ctx->st, GL_TRUE); + stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE); color = ctx->Current.RasterColor; } else if (format == GL_STENCIL_INDEX) { @@ -956,7 +956,7 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, else { ps = st->state.framebuffer.cbufs[0]; stfp = combined_drawpix_fragment_program(ctx); - stvp = make_vertex_shader(ctx->st, GL_FALSE); + stvp = st_make_passthrough_vertex_shader(ctx->st, GL_FALSE); color = NULL; } @@ -1111,7 +1111,7 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, struct st_context *st = ctx->st; struct pipe_texture *pt; - stvp = make_vertex_shader(ctx->st, GL_TRUE); + stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE); stfp = combined_bitmap_fragment_program(ctx); st_validate_state(st); @@ -1229,13 +1229,13 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, rbRead = st_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer); color = NULL; stfp = combined_drawpix_fragment_program(ctx); - stvp = make_vertex_shader(ctx->st, GL_FALSE); + stvp = st_make_passthrough_vertex_shader(ctx->st, GL_FALSE); } else { rbRead = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer); color = ctx->Current.Attrib[VERT_ATTRIB_COLOR0]; stfp = make_fragment_shader_z(ctx->st); - stvp = make_vertex_shader(ctx->st, GL_TRUE); + stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE); } psRead = rbRead->surface; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.h b/src/mesa/state_tracker/st_cb_drawpixels.h index 71ba487020..b8b906f06b 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.h +++ b/src/mesa/state_tracker/st_cb_drawpixels.h @@ -30,6 +30,10 @@ #define ST_CB_DRAWPIXELS_H +extern struct st_vertex_program * +st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor); + + extern void st_init_drawpixels_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index c9b8e78485..ae9f5c8b11 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -354,7 +354,8 @@ st_draw_vbo(GLcontext *ctx, void st_draw_vertices(GLcontext *ctx, unsigned prim, unsigned numVertex, float *verts, - unsigned numAttribs) + unsigned numAttribs, + GLboolean inClipCoords) { const float width = ctx->DrawBuffer->Width; const float height = ctx->DrawBuffer->Height; @@ -367,14 +368,16 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, assert(numAttribs > 0); - /* convert to clip coords */ - for (i = 0; i < numVertex; i++) { - float x = verts[i * numAttribs * 4 + 0]; - float y = verts[i * numAttribs * 4 + 1]; - x = x / width * 2.0 - 1.0; - y = y / height * 2.0 - 1.0; - verts[i * numAttribs * 4 + 0] = x; - verts[i * numAttribs * 4 + 1] = y; + if (!inClipCoords) { + /* convert to clip coords */ + for (i = 0; i < numVertex; i++) { + float x = verts[i * numAttribs * 4 + 0]; + float y = verts[i * numAttribs * 4 + 1]; + x = x / width * 2.0 - 1.0; + y = y / height * 2.0 - 1.0; + verts[i * numAttribs * 4 + 0] = x; + verts[i * numAttribs * 4 + 1] = y; + } } /* XXX create one-time */ diff --git a/src/mesa/state_tracker/st_draw.h b/src/mesa/state_tracker/st_draw.h index 89ee790c57..171bde57e5 100644 --- a/src/mesa/state_tracker/st_draw.h +++ b/src/mesa/state_tracker/st_draw.h @@ -62,7 +62,8 @@ st_feedback_draw_vbo(GLcontext *ctx, void st_draw_vertices(GLcontext *ctx, unsigned prim, unsigned numVertex, float *verts, - unsigned numAttribs); + unsigned numAttribs, + GLboolean inClipCoords); #endif -- cgit v1.2.3 From 9677336845511be4852520d2e50f91f1df362f58 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 12 Feb 2008 16:10:11 -0700 Subject: gallium: rename st_fragment_program's fs field to cso to match st_vertex_program --- src/mesa/state_tracker/st_atom_shader.c | 8 ++++---- src/mesa/state_tracker/st_cb_clear.c | 2 +- src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_cb_program.c | 4 ++-- src/mesa/state_tracker/st_gen_mipmap.c | 2 +- src/mesa/state_tracker/st_program.c | 2 +- src/mesa/state_tracker/st_program.h | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 9196918509..2c6ec8421b 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -158,7 +158,7 @@ find_translated_vp(struct st_context *st, /* * Translate fragment program if needed. */ - if (!stfp->fs) { + if (!stfp->cso) { GLuint inAttr, numIn = 0; for (inAttr = 0; inAttr < FRAG_ATTRIB_MAX; inAttr++) { @@ -179,7 +179,7 @@ find_translated_vp(struct st_context *st, stfp->input_to_slot, stfp->tokens, ST_MAX_SHADER_TOKENS); - assert(stfp->fs); + assert(stfp->cso); } @@ -227,7 +227,7 @@ find_translated_vp(struct st_context *st, if (fpInAttrib >= 0) { GLuint fpInSlot = stfp->input_to_slot[fpInAttrib]; if (fpInSlot != ~0) { - GLuint vpOutSlot = stfp->fs->state.input_map[fpInSlot]; + GLuint vpOutSlot = stfp->cso->state.input_map[fpInSlot]; xvp->output_to_slot[outAttr] = vpOutSlot; numVpOuts++; } @@ -300,7 +300,7 @@ update_linkage( struct st_context *st ) st->pipe->bind_vs_state(st->pipe, st->state.vs->cso->data); st->fp = stfp; - st->state.fs = stfp->fs; + st->state.fs = stfp->cso; st->pipe->bind_fs_state(st->pipe, st->state.fs->data); st->vertex_result_to_slot = xvp->output_to_slot; diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index ab98b54bab..410062e1e8 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -341,7 +341,7 @@ clear_with_quad(GLcontext *ctx, if (!stfp) { stfp = make_frag_shader(st); } - pipe->bind_fs_state(pipe, stfp->fs->data); + pipe->bind_fs_state(pipe, stfp->cso->data); } /* vertex shader state: color/position pass-through */ diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 475e23653e..3245a7488b 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -665,7 +665,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, } /* fragment shader state: TEX lookup program */ - pipe->bind_fs_state(pipe, stfp->fs->data); + pipe->bind_fs_state(pipe, stfp->cso->data); /* vertex shader state: position + texcoord pass-through */ pipe->bind_vs_state(pipe, stvp->cso->data); diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index f1f33fb0dd..af3ee65504 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -168,10 +168,10 @@ static void st_program_string_notify( GLcontext *ctx, stfp->serialNo++; - if (stfp->fs) { + if (stfp->cso) { /* free the TGSI code */ // cso_delete(stfp->vs); - stfp->fs = NULL; + stfp->cso = NULL; } stfp->param_state = stfp->Base.Base.Parameters->StateFlags; diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index b4a21fd7e2..459941cca8 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -253,7 +253,7 @@ st_render_mipmap(struct st_context *st, pipe->bind_rasterizer_state(pipe, st->gen_mipmap.rasterizer_cso); /* bind shaders */ - pipe->bind_fs_state(pipe, st->gen_mipmap.stfp->fs->data); + pipe->bind_fs_state(pipe, st->gen_mipmap.stfp->cso->data); pipe->bind_vs_state(pipe, st->gen_mipmap.stvp->cso->data); /* diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 84a9094001..c8297baded 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -420,7 +420,7 @@ st_translate_fragment_program(struct st_context *st, fs.tokens = tokensOut; cso = st_cached_fs_state(st, &fs); - stfp->fs = cso; + stfp->cso = cso; if (0) _mesa_print_program(&stfp->Base.Base); diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index de02c3185f..ea1dde4a7a 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -62,7 +62,7 @@ struct st_fragment_program struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; /** Pointer to the corresponding cached shader */ - const struct cso_fragment_shader *fs; + const struct cso_fragment_shader *cso; GLuint param_state; -- cgit v1.2.3 From cf5ef20f436ac1d3efde2b7bff698decccb029e3 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 14 Feb 2008 16:53:51 +0000 Subject: gallium: Cleanups related to clears. --- src/mesa/state_tracker/st_cb_clear.c | 117 +++++++++++++++++++++++++---------- 1 file changed, 85 insertions(+), 32 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 410062e1e8..78baf772f4 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -272,6 +272,14 @@ clear_with_quad(GLcontext *ctx, const GLfloat x1 = ctx->DrawBuffer->_Xmax; const GLfloat y1 = ctx->DrawBuffer->_Ymax; + /* + printf("%s %s%s%s %f,%f %f,%f\n", __FUNCTION__, + color ? "color, " : "", + depth ? "depth, " : "", + stencil ? "stencil" : "", + x0, y0, + x1, y1); + */ /* blend state: RGBA masking */ { @@ -389,13 +397,44 @@ clear_with_quad(GLcontext *ctx, * Determine if we need to clear the depth buffer by drawing a quad. */ static INLINE GLboolean -check_clear_color_with_quad(GLcontext *ctx) +check_clear_color_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) +{ + const struct st_renderbuffer *strb = st_renderbuffer(rb); + + if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED) + return FALSE; + + if (ctx->Scissor.Enabled) + return TRUE; + + if (!ctx->Color.ColorMask[0] || + !ctx->Color.ColorMask[1] || + !ctx->Color.ColorMask[2] || + !ctx->Color.ColorMask[3]) + return TRUE; + + return FALSE; +} + + +static INLINE GLboolean +check_clear_depth_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) { - return !(ctx->Color.ColorMask[0] && - ctx->Color.ColorMask[1] && - ctx->Color.ColorMask[2] && - ctx->Color.ColorMask[3] && - !ctx->Scissor.Enabled); + const struct st_renderbuffer *strb = st_renderbuffer(rb); + const GLuint stencilMax = (1 << rb->StencilBits) - 1; + GLboolean maskStencil + = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; + + if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED) + return FALSE; + + if (ctx->Scissor.Enabled) + return TRUE; + + if (maskStencil) + return TRUE; + + return FALSE; } @@ -407,10 +446,19 @@ check_clear_depth_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) { const struct st_renderbuffer *strb = st_renderbuffer(rb); const GLboolean isDS = is_depth_stencil_format(strb->surface->format); - return ctx->Scissor.Enabled - || (isDS && - strb->surface->status == PIPE_SURFACE_STATUS_DEFINED && - ctx->DrawBuffer->Visual.stencilBits > 0); + + if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED) + return FALSE; + + if (ctx->Scissor.Enabled) + return TRUE; + + if (isDS && + strb->surface->status == PIPE_SURFACE_STATUS_DEFINED && + ctx->DrawBuffer->Visual.stencilBits > 0) + return TRUE; + + return FALSE; } @@ -425,9 +473,27 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) const GLuint stencilMax = (1 << rb->StencilBits) - 1; const GLboolean maskStencil = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; - return maskStencil - || ctx->Scissor.Enabled - || (isDS && ctx->DrawBuffer->Visual.depthBits > 0); + + if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED) + return FALSE; + + if (maskStencil) + return TRUE; + + if (ctx->Scissor.Enabled) + return TRUE; + + /* This is correct, but it is necessary to look at the depth clear + * value held in the surface when it comes time to issue the clear, + * rather than taking depth and stencil clear values from the + * current state. + */ + if (isDS && + strb->surface->status == PIPE_SURFACE_STATUS_DEFINED && + ctx->DrawBuffer->Visual.depthBits > 0) + return TRUE; + + return FALSE; } @@ -436,14 +502,10 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { - struct st_renderbuffer *strb = st_renderbuffer(rb); - - if (ctx->Color.ColorMask[0] && - ctx->Color.ColorMask[1] && - ctx->Color.ColorMask[2] && - ctx->Color.ColorMask[3] && - !ctx->Scissor.Enabled) + if (!check_clear_color_with_quad( ctx, rb )) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + /* clear whole buffer w/out masking */ GLuint clearValue = color_value(strb->surface->format, ctx->Color.ClearColor); @@ -482,14 +544,8 @@ static void clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *strb = st_renderbuffer(rb); - const GLboolean isDS = is_depth_stencil_format(strb->surface->format); - const GLuint stencilMax = (1 << rb->StencilBits) - 1; - GLboolean maskStencil - = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; - if (maskStencil || - ctx->Scissor.Enabled || - (isDS && ctx->DrawBuffer->Visual.depthBits > 0)) { + if (check_clear_stencil_with_quad(ctx, rb)) { /* masking or scissoring or combined depth/stencil buffer */ clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE); } @@ -505,13 +561,10 @@ static void clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *strb = st_renderbuffer(rb); - const GLuint stencilMax = (1 << rb->StencilBits) - 1; - GLboolean maskStencil - = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; assert(is_depth_stencil_format(strb->surface->format)); - if (!maskStencil && !ctx->Scissor.Enabled) { + if (check_clear_depth_stencil_with_quad(ctx, rb)) { /* clear whole buffer w/out masking */ GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); @@ -520,7 +573,7 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) clearValue |= ctx->Stencil.Clear << 24; break; case PIPE_FORMAT_Z24S8_UNORM: - clearValue |= clearValue | ctx->Stencil.Clear; + clearValue |= ctx->Stencil.Clear; break; default: assert(0); -- cgit v1.2.3 From 10d83df3a9cb76a3db76ec9970d7108cf9255d77 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 28 Feb 2008 09:07:03 +0000 Subject: gallium: State tracker cleanups wrt clears. --- src/mesa/state_tracker/st_cb_clear.c | 40 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 78baf772f4..e712fd84cd 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -502,37 +502,30 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { - if (!check_clear_color_with_quad( ctx, rb )) - { + if (check_clear_color_with_quad( ctx, rb )) { + /* masking or scissoring */ + clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE); + } + else { struct st_renderbuffer *strb = st_renderbuffer(rb); /* clear whole buffer w/out masking */ - GLuint clearValue - = color_value(strb->surface->format, ctx->Color.ClearColor); + uint clearValue = color_value(strb->surface->format, ctx->Color.ClearColor); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } - else { - /* masking or scissoring */ - clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE); - } } static void clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { - struct st_renderbuffer *strb = st_renderbuffer(rb); - /* - const GLboolean isDS = is_depth_stencil_format(strb->surface->format); - */ - - assert(strb->surface->format); - if (check_clear_depth_with_quad(ctx, rb)) { /* scissoring or we have a combined depth/stencil buffer */ clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE); } else { + struct st_renderbuffer *strb = st_renderbuffer(rb); + /* simple clear of whole buffer */ uint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); @@ -543,13 +536,13 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { - struct st_renderbuffer *strb = st_renderbuffer(rb); - if (check_clear_stencil_with_quad(ctx, rb)) { /* masking or scissoring or combined depth/stencil buffer */ clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE); } else { + struct st_renderbuffer *strb = st_renderbuffer(rb); + /* simple clear of whole buffer */ GLuint clearValue = ctx->Stencil.Clear; ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); @@ -560,11 +553,14 @@ clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { - struct st_renderbuffer *strb = st_renderbuffer(rb); - - assert(is_depth_stencil_format(strb->surface->format)); if (check_clear_depth_stencil_with_quad(ctx, rb)) { + /* masking or scissoring */ + clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE); + } + else { + struct st_renderbuffer *strb = st_renderbuffer(rb); + /* clear whole buffer w/out masking */ GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); @@ -581,10 +577,6 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } - else { - /* masking or scissoring */ - clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE); - } } -- cgit v1.2.3 From 339e7ec6805e6de8794514c0a935081b5d36d38f Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 11 Mar 2008 18:54:31 -0600 Subject: gallium: rework CSO-related code in state tracker Use the code in cso_context.c rather than st_cache.c. Basically, binding of state objects now goes through the CSO module. But Vertex/fragment shaders go through pipe->bind_fs/vs_state() since they're not cached by the CSO module at this time. Also, update softpipe driver to handle NULL state objects in various places. This happens during context destruction. May need to update other drivers... --- src/gallium/auxiliary/draw/draw_aaline.c | 3 +- src/gallium/auxiliary/draw/draw_aapoint.c | 3 +- src/gallium/auxiliary/draw/draw_pstipple.c | 3 +- src/gallium/drivers/softpipe/sp_state_fs.c | 3 +- src/mesa/sources | 1 - src/mesa/state_tracker/st_atom_blend.c | 52 ++++++-------- src/mesa/state_tracker/st_atom_depth.c | 60 +++++++--------- src/mesa/state_tracker/st_atom_rasterizer.c | 108 ++++++++++++++-------------- src/mesa/state_tracker/st_atom_sampler.c | 43 ++++++----- src/mesa/state_tracker/st_atom_shader.c | 28 ++------ src/mesa/state_tracker/st_cb_accum.c | 1 - src/mesa/state_tracker/st_cb_clear.c | 47 ++++++------ src/mesa/state_tracker/st_cb_drawpixels.c | 64 +++++++++-------- src/mesa/state_tracker/st_cb_program.c | 5 +- src/mesa/state_tracker/st_context.c | 9 ++- src/mesa/state_tracker/st_context.h | 19 ++--- src/mesa/state_tracker/st_debug.c | 6 +- src/mesa/state_tracker/st_draw.c | 13 ++-- src/mesa/state_tracker/st_gen_mipmap.c | 34 ++++----- src/mesa/state_tracker/st_mesa_to_tgsi.c | 5 +- src/mesa/state_tracker/st_mesa_to_tgsi.h | 2 +- src/mesa/state_tracker/st_program.c | 59 +++++++++------ src/mesa/state_tracker/st_program.h | 22 ++---- 23 files changed, 292 insertions(+), 298 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/gallium/auxiliary/draw/draw_aaline.c b/src/gallium/auxiliary/draw/draw_aaline.c index 3ec73b0800..6b1e640ae9 100644 --- a/src/gallium/auxiliary/draw/draw_aaline.c +++ b/src/gallium/auxiliary/draw/draw_aaline.c @@ -733,7 +733,8 @@ aaline_bind_fs_state(struct pipe_context *pipe, void *fs) /* save current */ aaline->fs = aafs; /* pass-through */ - aaline->driver_bind_fs_state(aaline->pipe, aafs->driver_fs); + aaline->driver_bind_fs_state(aaline->pipe, + (aafs ? aafs->driver_fs : NULL)); } diff --git a/src/gallium/auxiliary/draw/draw_aapoint.c b/src/gallium/auxiliary/draw/draw_aapoint.c index 70f696475f..99e9e9fe34 100644 --- a/src/gallium/auxiliary/draw/draw_aapoint.c +++ b/src/gallium/auxiliary/draw/draw_aapoint.c @@ -800,7 +800,8 @@ aapoint_bind_fs_state(struct pipe_context *pipe, void *fs) /* save current */ aapoint->fs = aafs; /* pass-through */ - aapoint->driver_bind_fs_state(aapoint->pipe, aafs->driver_fs); + aapoint->driver_bind_fs_state(aapoint->pipe, + (aafs ? aafs->driver_fs : NULL)); } diff --git a/src/gallium/auxiliary/draw/draw_pstipple.c b/src/gallium/auxiliary/draw/draw_pstipple.c index b3e52dc1c7..ed50d0805a 100644 --- a/src/gallium/auxiliary/draw/draw_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pstipple.c @@ -595,7 +595,8 @@ pstip_bind_fs_state(struct pipe_context *pipe, void *fs) /* save current */ pstip->fs = aafs; /* pass-through */ - pstip->driver_bind_fs_state(pstip->pipe, aafs->driver_fs); + pstip->driver_bind_fs_state(pstip->pipe, + (aafs ? aafs->driver_fs : NULL)); } diff --git a/src/gallium/drivers/softpipe/sp_state_fs.c b/src/gallium/drivers/softpipe/sp_state_fs.c index eb641ed321..4eefd1d61f 100644 --- a/src/gallium/drivers/softpipe/sp_state_fs.c +++ b/src/gallium/drivers/softpipe/sp_state_fs.c @@ -120,7 +120,8 @@ softpipe_bind_vs_state(struct pipe_context *pipe, void *vs) softpipe->vs = (const struct sp_vertex_shader *)vs; - draw_bind_vertex_shader(softpipe->draw, softpipe->vs->draw_data); + draw_bind_vertex_shader(softpipe->draw, + (softpipe->vs ? softpipe->vs->draw_data : NULL)); softpipe->dirty |= SP_NEW_VS; } diff --git a/src/mesa/sources b/src/mesa/sources index f0bf7b31fb..e3d5f22849 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -184,7 +184,6 @@ STATETRACKER_SOURCES = \ state_tracker/st_cb_readpixels.c \ state_tracker/st_cb_strings.c \ state_tracker/st_cb_texture.c \ - state_tracker/st_cache.c \ state_tracker/st_context.c \ state_tracker/st_debug.c \ state_tracker/st_draw.c \ diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c index 2a9d209153..6c13fc8141 100644 --- a/src/mesa/state_tracker/st_atom_blend.c +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -33,11 +33,11 @@ #include "st_context.h" -#include "st_cache.h" #include "st_atom.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "cso_cache/cso_context.h" /** @@ -155,44 +155,43 @@ translate_logicop(GLenum logicop) static void update_blend( struct st_context *st ) { - struct pipe_blend_state blend; - const struct cso_blend *cso; + struct pipe_blend_state *blend = &st->state.blend; - memset(&blend, 0, sizeof(blend)); + memset(blend, 0, sizeof(*blend)); if (st->ctx->Color.ColorLogicOpEnabled || (st->ctx->Color.BlendEnabled && st->ctx->Color.BlendEquationRGB == GL_LOGIC_OP)) { /* logicop enabled */ - blend.logicop_enable = 1; - blend.logicop_func = translate_logicop(st->ctx->Color.LogicOp); + blend->logicop_enable = 1; + blend->logicop_func = translate_logicop(st->ctx->Color.LogicOp); } else if (st->ctx->Color.BlendEnabled) { /* blending enabled */ - blend.blend_enable = 1; + blend->blend_enable = 1; - blend.rgb_func = translate_blend(st->ctx->Color.BlendEquationRGB); + blend->rgb_func = translate_blend(st->ctx->Color.BlendEquationRGB); if (st->ctx->Color.BlendEquationRGB == GL_MIN || st->ctx->Color.BlendEquationRGB == GL_MAX) { /* Min/max are special */ - blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; - blend.rgb_dst_factor = PIPE_BLENDFACTOR_ONE; + blend->rgb_src_factor = PIPE_BLENDFACTOR_ONE; + blend->rgb_dst_factor = PIPE_BLENDFACTOR_ONE; } else { - blend.rgb_src_factor = translate_blend(st->ctx->Color.BlendSrcRGB); - blend.rgb_dst_factor = translate_blend(st->ctx->Color.BlendDstRGB); + blend->rgb_src_factor = translate_blend(st->ctx->Color.BlendSrcRGB); + blend->rgb_dst_factor = translate_blend(st->ctx->Color.BlendDstRGB); } - blend.alpha_func = translate_blend(st->ctx->Color.BlendEquationA); + blend->alpha_func = translate_blend(st->ctx->Color.BlendEquationA); if (st->ctx->Color.BlendEquationA == GL_MIN || st->ctx->Color.BlendEquationA == GL_MAX) { /* Min/max are special */ - blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; - blend.alpha_dst_factor = PIPE_BLENDFACTOR_ONE; + blend->alpha_src_factor = PIPE_BLENDFACTOR_ONE; + blend->alpha_dst_factor = PIPE_BLENDFACTOR_ONE; } else { - blend.alpha_src_factor = translate_blend(st->ctx->Color.BlendSrcA); - blend.alpha_dst_factor = translate_blend(st->ctx->Color.BlendDstA); + blend->alpha_src_factor = translate_blend(st->ctx->Color.BlendSrcA); + blend->alpha_dst_factor = translate_blend(st->ctx->Color.BlendDstA); } } else { @@ -201,25 +200,18 @@ update_blend( struct st_context *st ) /* Colormask - maybe reverse these bits? */ if (st->ctx->Color.ColorMask[0]) - blend.colormask |= PIPE_MASK_R; + blend->colormask |= PIPE_MASK_R; if (st->ctx->Color.ColorMask[1]) - blend.colormask |= PIPE_MASK_G; + blend->colormask |= PIPE_MASK_G; if (st->ctx->Color.ColorMask[2]) - blend.colormask |= PIPE_MASK_B; + blend->colormask |= PIPE_MASK_B; if (st->ctx->Color.ColorMask[3]) - blend.colormask |= PIPE_MASK_A; + blend->colormask |= PIPE_MASK_A; if (st->ctx->Color.DitherFlag) - blend.dither = 1; + blend->dither = 1; - cso = st_cached_blend_state(st, &blend); - - if (st->state.blend != cso) { - /* state has changed */ - st->state.blend = cso; - /* bind new state */ - st->pipe->bind_blend_state(st->pipe, cso->data); - } + cso_set_blend(st->cso_context, blend); if (memcmp(st->ctx->Color.BlendColor, &st->state.blend_color, 4 * sizeof(GLfloat)) != 0) { /* state has changed */ diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index 7aecdbfbcc..827ad3b548 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -34,10 +34,10 @@ #include "st_context.h" -#include "st_cache.h" #include "st_atom.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "cso_cache/cso_context.h" /** @@ -93,53 +93,47 @@ gl_stencil_op_to_pipe(GLenum func) static void update_depth_stencil_alpha(struct st_context *st) { - struct pipe_depth_stencil_alpha_state depth_stencil; - const struct cso_depth_stencil_alpha *cso; + struct pipe_depth_stencil_alpha_state *dsa = &st->state.depth_stencil; - memset(&depth_stencil, 0, sizeof(depth_stencil)); + memset(dsa, 0, sizeof(*dsa)); - depth_stencil.depth.enabled = st->ctx->Depth.Test; - depth_stencil.depth.writemask = st->ctx->Depth.Mask; - depth_stencil.depth.func = st_compare_func_to_pipe(st->ctx->Depth.Func); + dsa->depth.enabled = st->ctx->Depth.Test; + dsa->depth.writemask = st->ctx->Depth.Mask; + dsa->depth.func = st_compare_func_to_pipe(st->ctx->Depth.Func); if (st->ctx->Query.CurrentOcclusionObject && st->ctx->Query.CurrentOcclusionObject->Active) - depth_stencil.depth.occlusion_count = 1; + dsa->depth.occlusion_count = 1; if (st->ctx->Stencil.Enabled) { - depth_stencil.stencil[0].enabled = 1; - depth_stencil.stencil[0].func = st_compare_func_to_pipe(st->ctx->Stencil.Function[0]); - depth_stencil.stencil[0].fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[0]); - depth_stencil.stencil[0].zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[0]); - depth_stencil.stencil[0].zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[0]); - depth_stencil.stencil[0].ref_value = st->ctx->Stencil.Ref[0] & 0xff; - depth_stencil.stencil[0].value_mask = st->ctx->Stencil.ValueMask[0] & 0xff; - depth_stencil.stencil[0].write_mask = st->ctx->Stencil.WriteMask[0] & 0xff; + dsa->stencil[0].enabled = 1; + dsa->stencil[0].func = st_compare_func_to_pipe(st->ctx->Stencil.Function[0]); + dsa->stencil[0].fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[0]); + dsa->stencil[0].zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[0]); + dsa->stencil[0].zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[0]); + dsa->stencil[0].ref_value = st->ctx->Stencil.Ref[0] & 0xff; + dsa->stencil[0].value_mask = st->ctx->Stencil.ValueMask[0] & 0xff; + dsa->stencil[0].write_mask = st->ctx->Stencil.WriteMask[0] & 0xff; if (st->ctx->Stencil.TestTwoSide) { - depth_stencil.stencil[1].enabled = 1; - depth_stencil.stencil[1].func = st_compare_func_to_pipe(st->ctx->Stencil.Function[1]); - depth_stencil.stencil[1].fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[1]); - depth_stencil.stencil[1].zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[1]); - depth_stencil.stencil[1].zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[1]); - depth_stencil.stencil[1].ref_value = st->ctx->Stencil.Ref[1] & 0xff; - depth_stencil.stencil[1].value_mask = st->ctx->Stencil.ValueMask[1] & 0xff; - depth_stencil.stencil[1].write_mask = st->ctx->Stencil.WriteMask[1] & 0xff; + dsa->stencil[1].enabled = 1; + dsa->stencil[1].func = st_compare_func_to_pipe(st->ctx->Stencil.Function[1]); + dsa->stencil[1].fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[1]); + dsa->stencil[1].zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[1]); + dsa->stencil[1].zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[1]); + dsa->stencil[1].ref_value = st->ctx->Stencil.Ref[1] & 0xff; + dsa->stencil[1].value_mask = st->ctx->Stencil.ValueMask[1] & 0xff; + dsa->stencil[1].write_mask = st->ctx->Stencil.WriteMask[1] & 0xff; } } if (st->ctx->Color.AlphaEnabled) { - depth_stencil.alpha.enabled = 1; - depth_stencil.alpha.func = st_compare_func_to_pipe(st->ctx->Color.AlphaFunc); - depth_stencil.alpha.ref = st->ctx->Color.AlphaRef; + dsa->alpha.enabled = 1; + dsa->alpha.func = st_compare_func_to_pipe(st->ctx->Color.AlphaFunc); + dsa->alpha.ref = st->ctx->Color.AlphaRef; } - cso = st_cached_depth_stencil_alpha_state(st, &depth_stencil); - if (st->state.depth_stencil != cso) { - /* state has changed */ - st->state.depth_stencil = cso; - st->pipe->bind_depth_stencil_alpha_state(st->pipe, cso->data); /* bind new state */ - } + cso_set_depth_stencil_alpha(st->cso_context, dsa); } diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index 229839d8b2..77cef9236b 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -32,10 +32,11 @@ #include "main/macros.h" #include "st_context.h" -#include "st_cache.h" +#include "st_atom.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "st_atom.h" +#include "cso_cache/cso_context.h" + static GLuint translate_fill( GLenum mode ) { @@ -72,22 +73,21 @@ static GLboolean get_offset_flag( GLuint fill_mode, static void update_raster_state( struct st_context *st ) { GLcontext *ctx = st->ctx; - struct pipe_rasterizer_state raster; - const struct cso_rasterizer *cso; + struct pipe_rasterizer_state *raster = &st->state.rasterizer; const struct gl_vertex_program *vertProg = ctx->VertexProgram._Current; uint i; - memset(&raster, 0, sizeof(raster)); + memset(raster, 0, sizeof(*raster)); - raster.origin_lower_left = 1; /* Always true for OpenGL */ + raster->origin_lower_left = 1; /* Always true for OpenGL */ /* _NEW_POLYGON, _NEW_BUFFERS */ { if (ctx->Polygon.FrontFace == GL_CCW) - raster.front_winding = PIPE_WINDING_CCW; + raster->front_winding = PIPE_WINDING_CCW; else - raster.front_winding = PIPE_WINDING_CW; + raster->front_winding = PIPE_WINDING_CW; /* XXX * I think the intention here is that user-created framebuffer objects @@ -96,13 +96,13 @@ static void update_raster_state( struct st_context *st ) * But this is an implementation/driver-specific artifact - remove... */ if (ctx->DrawBuffer && ctx->DrawBuffer->Name != 0) - raster.front_winding ^= PIPE_WINDING_BOTH; + raster->front_winding ^= PIPE_WINDING_BOTH; } /* _NEW_LIGHT */ if (ctx->Light.ShadeModel == GL_FLAT) - raster.flatshade = 1; + raster->flatshade = 1; /* _NEW_LIGHT | _NEW_PROGRAM * @@ -113,28 +113,28 @@ static void update_raster_state( struct st_context *st ) if (ctx->VertexProgram._Current) { if (ctx->VertexProgram._Enabled) { /* user-defined program */ - raster.light_twoside = ctx->VertexProgram.TwoSideEnabled; + raster->light_twoside = ctx->VertexProgram.TwoSideEnabled; } else { /* TNL-generated program */ - raster.light_twoside = ctx->Light.Enabled && ctx->Light.Model.TwoSide; + raster->light_twoside = ctx->Light.Enabled && ctx->Light.Model.TwoSide; } } else if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) { - raster.light_twoside = 1; + raster->light_twoside = 1; } /* _NEW_POLYGON */ if (ctx->Polygon.CullFlag) { if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) { - raster.cull_mode = PIPE_WINDING_BOTH; + raster->cull_mode = PIPE_WINDING_BOTH; } else if (ctx->Polygon.CullFaceMode == GL_FRONT) { - raster.cull_mode = raster.front_winding; + raster->cull_mode = raster->front_winding; } else { - raster.cull_mode = raster.front_winding ^ PIPE_WINDING_BOTH; + raster->cull_mode = raster->front_winding ^ PIPE_WINDING_BOTH; } } @@ -144,23 +144,23 @@ static void update_raster_state( struct st_context *st ) GLuint fill_front = translate_fill( ctx->Polygon.FrontMode ); GLuint fill_back = translate_fill( ctx->Polygon.BackMode ); - if (raster.front_winding == PIPE_WINDING_CW) { - raster.fill_cw = fill_front; - raster.fill_ccw = fill_back; + if (raster->front_winding == PIPE_WINDING_CW) { + raster->fill_cw = fill_front; + raster->fill_ccw = fill_back; } else { - raster.fill_cw = fill_back; - raster.fill_ccw = fill_front; + raster->fill_cw = fill_back; + raster->fill_ccw = fill_front; } /* Simplify when culling is active: */ - if (raster.cull_mode & PIPE_WINDING_CW) { - raster.fill_cw = raster.fill_ccw; + if (raster->cull_mode & PIPE_WINDING_CW) { + raster->fill_cw = raster->fill_ccw; } - if (raster.cull_mode & PIPE_WINDING_CCW) { - raster.fill_ccw = raster.fill_cw; + if (raster->cull_mode & PIPE_WINDING_CCW) { + raster->fill_ccw = raster->fill_cw; } } @@ -168,95 +168,91 @@ static void update_raster_state( struct st_context *st ) */ if (ctx->Polygon.OffsetUnits != 0.0 || ctx->Polygon.OffsetFactor != 0.0) { - raster.offset_cw = get_offset_flag( raster.fill_cw, &ctx->Polygon ); - raster.offset_ccw = get_offset_flag( raster.fill_ccw, &ctx->Polygon ); - raster.offset_units = ctx->Polygon.OffsetUnits; - raster.offset_scale = ctx->Polygon.OffsetFactor; + raster->offset_cw = get_offset_flag( raster->fill_cw, &ctx->Polygon ); + raster->offset_ccw = get_offset_flag( raster->fill_ccw, &ctx->Polygon ); + raster->offset_units = ctx->Polygon.OffsetUnits; + raster->offset_scale = ctx->Polygon.OffsetFactor; } if (ctx->Polygon.SmoothFlag) - raster.poly_smooth = 1; + raster->poly_smooth = 1; if (ctx->Polygon.StippleFlag) - raster.poly_stipple_enable = 1; + raster->poly_stipple_enable = 1; /* _NEW_BUFFERS, _NEW_POLYGON */ - if (raster.fill_cw != PIPE_POLYGON_MODE_FILL || - raster.fill_ccw != PIPE_POLYGON_MODE_FILL) + if (raster->fill_cw != PIPE_POLYGON_MODE_FILL || + raster->fill_ccw != PIPE_POLYGON_MODE_FILL) { GLfloat mrd = (ctx->DrawBuffer ? ctx->DrawBuffer->_MRD : 1.0); - raster.offset_units = ctx->Polygon.OffsetFactor * mrd; - raster.offset_scale = (ctx->Polygon.OffsetUnits * mrd * + raster->offset_units = ctx->Polygon.OffsetFactor * mrd; + raster->offset_scale = (ctx->Polygon.OffsetUnits * mrd * st->polygon_offset_scale); } /* _NEW_POINT */ - raster.point_size = ctx->Point.Size; - raster.point_smooth = ctx->Point.SmoothFlag; - raster.point_sprite = ctx->Point.PointSprite; + raster->point_size = ctx->Point.Size; + raster->point_smooth = ctx->Point.SmoothFlag; + raster->point_sprite = ctx->Point.PointSprite; for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { if (ctx->Point.CoordReplace[i]) { if (ctx->Point.SpriteOrigin == GL_UPPER_LEFT) - raster.sprite_coord_mode[i] = PIPE_SPRITE_COORD_UPPER_LEFT; + raster->sprite_coord_mode[i] = PIPE_SPRITE_COORD_UPPER_LEFT; else - raster.sprite_coord_mode[i] = PIPE_SPRITE_COORD_LOWER_LEFT; + raster->sprite_coord_mode[i] = PIPE_SPRITE_COORD_LOWER_LEFT; } else { - raster.sprite_coord_mode[i] = PIPE_SPRITE_COORD_NONE; + raster->sprite_coord_mode[i] = PIPE_SPRITE_COORD_NONE; } } if (vertProg) { if (vertProg->Base.Id == 0) { if (vertProg->Base.OutputsWritten & (1 << VERT_RESULT_PSIZ)) { /* generated program which emits point size */ - raster.point_size_per_vertex = TRUE; + raster->point_size_per_vertex = TRUE; } } else if (ctx->VertexProgram.PointSizeEnabled) { /* user-defined program and GL_VERTEX_PROGRAM_POINT_SIZE set */ - raster.point_size_per_vertex = ctx->VertexProgram.PointSizeEnabled; + raster->point_size_per_vertex = ctx->VertexProgram.PointSizeEnabled; } } /* _NEW_LINE */ - raster.line_smooth = ctx->Line.SmoothFlag; + raster->line_smooth = ctx->Line.SmoothFlag; if (ctx->Line.SmoothFlag) { - raster.line_width = CLAMP(ctx->Line.Width, + raster->line_width = CLAMP(ctx->Line.Width, ctx->Const.MinLineWidthAA, ctx->Const.MaxLineWidthAA); } else { - raster.line_width = CLAMP(ctx->Line.Width, + raster->line_width = CLAMP(ctx->Line.Width, ctx->Const.MinLineWidth, ctx->Const.MaxLineWidth); } - raster.line_stipple_enable = ctx->Line.StippleFlag; - raster.line_stipple_pattern = ctx->Line.StipplePattern; + raster->line_stipple_enable = ctx->Line.StippleFlag; + raster->line_stipple_pattern = ctx->Line.StipplePattern; /* GL stipple factor is in [1,256], remap to [0, 255] here */ - raster.line_stipple_factor = ctx->Line.StippleFactor - 1; + raster->line_stipple_factor = ctx->Line.StippleFactor - 1; /* _NEW_MULTISAMPLE */ if (ctx->Multisample.Enabled) - raster.multisample = 1; + raster->multisample = 1; /* _NEW_SCISSOR */ if (ctx->Scissor.Enabled) - raster.scissor = 1; + raster->scissor = 1; - cso = st_cached_rasterizer_state(st, &raster); - if (st->state.rasterizer != cso) { - st->state.rasterizer = cso; - st->pipe->bind_rasterizer_state(st->pipe, cso->data); - } + cso_set_rasterizer(st->cso_context, raster); } const struct st_tracked_state st_update_rasterizer = { diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 1000f98ffc..1babba9b4f 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -33,11 +33,11 @@ #include "st_context.h" -#include "st_cache.h" #include "st_atom.h" #include "st_program.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "cso_cache/cso_context.h" /** @@ -124,9 +124,9 @@ update_samplers(struct st_context *st) /* loop over sampler units (aka tex image units) */ for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) { - struct pipe_sampler_state sampler; + struct pipe_sampler_state *sampler = st->state.samplers + su; - memset(&sampler, 0, sizeof(sampler)); + memset(sampler, 0, sizeof(*sampler)); if (fs->Base.Base.SamplersUsed & (1 << su)) { GLuint texUnit = fs->Base.Base.SamplerUnits[su]; @@ -135,37 +135,37 @@ update_samplers(struct st_context *st) assert(texobj); - sampler.wrap_s = gl_wrap_to_sp(texobj->WrapS); - sampler.wrap_t = gl_wrap_to_sp(texobj->WrapT); - sampler.wrap_r = gl_wrap_to_sp(texobj->WrapR); + sampler->wrap_s = gl_wrap_to_sp(texobj->WrapS); + sampler->wrap_t = gl_wrap_to_sp(texobj->WrapT); + sampler->wrap_r = gl_wrap_to_sp(texobj->WrapR); - sampler.min_img_filter = gl_filter_to_img_filter(texobj->MinFilter); - sampler.min_mip_filter = gl_filter_to_mip_filter(texobj->MinFilter); - sampler.mag_img_filter = gl_filter_to_img_filter(texobj->MagFilter); + sampler->min_img_filter = gl_filter_to_img_filter(texobj->MinFilter); + sampler->min_mip_filter = gl_filter_to_mip_filter(texobj->MinFilter); + sampler->mag_img_filter = gl_filter_to_img_filter(texobj->MagFilter); if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB) - sampler.normalized_coords = 1; + sampler->normalized_coords = 1; - sampler.lod_bias = st->ctx->Texture.Unit[su].LodBias; + sampler->lod_bias = st->ctx->Texture.Unit[su].LodBias; #if 1 - sampler.min_lod = (texobj->MinLod) < 0.0 ? 0.0 : texobj->MinLod; - sampler.max_lod = texobj->MaxLod; + sampler->min_lod = (texobj->MinLod) < 0.0 ? 0.0 : texobj->MinLod; + sampler->max_lod = texobj->MaxLod; #else /* min/max lod should really be as follows (untested). * Also, calculate_first_last_level() needs to be overhauled * since today's hardware had real support for LOD clamping. */ - sampler.min_lod = MAX2(texobj->BaseLevel, texobj->MinLod); - sampler.max_lod = MIN2(texobj->MaxLevel, texobj->MaxLod); + sampler->min_lod = MAX2(texobj->BaseLevel, texobj->MinLod); + sampler->max_lod = MIN2(texobj->MaxLevel, texobj->MaxLod); #endif - sampler.max_anisotropy = texobj->MaxAnisotropy; + sampler->max_anisotropy = texobj->MaxAnisotropy; /* only care about ARB_shadow, not SGI shadow */ if (texobj->CompareMode == GL_COMPARE_R_TO_TEXTURE) { - sampler.compare = 1; - sampler.compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE; - sampler.compare_func + sampler->compare = 1; + sampler->compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE; + sampler->compare_func = st_compare_func_to_pipe(texobj->CompareFunc); } @@ -174,11 +174,10 @@ update_samplers(struct st_context *st) /* XXX more sampler state here */ } - st->state.sampler[su] = st_cached_sampler_state(st, &sampler)->data; + cso_single_sampler(st->cso_context, su, sampler); } - st->pipe->bind_sampler_states(st->pipe, st->state.num_samplers, - st->state.sampler); + cso_single_sampler_done(st->cso_context); } diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 10c131d554..0726688493 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -43,10 +43,9 @@ #include "pipe/p_context.h" #include "pipe/p_shader_tokens.h" -#include "cso_cache/cso_cache.h" +#include "cso_cache/cso_context.h" #include "st_context.h" -#include "st_cache.h" #include "st_atom.h" #include "st_program.h" #include "st_atom_shader.h" @@ -70,9 +69,6 @@ struct translated_vertex_program /** Maps VERT_RESULT_x to slot */ GLuint output_to_slot[VERT_RESULT_MAX]; - /** The program in TGSI format */ - struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; - /** Pointer to the translated vertex program */ struct st_vertex_program *vp; @@ -158,7 +154,7 @@ find_translated_vp(struct st_context *st, /* * Translate fragment program if needed. */ - if (!stfp->cso) { + if (!stfp->state.tokens) { GLuint inAttr, numIn = 0; for (inAttr = 0; inAttr < FRAG_ATTRIB_MAX; inAttr++) { @@ -175,11 +171,7 @@ find_translated_vp(struct st_context *st, assert(stfp->Base.Base.NumInstructions > 1); - (void) st_translate_fragment_program(st, stfp, - stfp->input_to_slot, - stfp->tokens, - ST_MAX_SHADER_TOKENS); - assert(stfp->cso); + st_translate_fragment_program(st, stfp, stfp->input_to_slot); } @@ -261,12 +253,8 @@ find_translated_vp(struct st_context *st, assert(stvp->Base.Base.NumInstructions > 1); - st_translate_vertex_program(st, stvp, - xvp->output_to_slot, - xvp->tokens, - ST_MAX_SHADER_TOKENS); + st_translate_vertex_program(st, stvp, xvp->output_to_slot); - assert(stvp->cso); xvp->vp = stvp; /* translated VP is up to date now */ @@ -296,12 +284,10 @@ update_linkage( struct st_context *st ) xvp = find_translated_vp(st, stvp, stfp); st->vp = stvp; - st->state.vs = xvp->vp; - st->pipe->bind_vs_state(st->pipe, st->state.vs->cso->data); - st->fp = stfp; - st->state.fs = stfp->cso; - st->pipe->bind_fs_state(st->pipe, st->state.fs->data); + + st->pipe->bind_vs_state(st->pipe, stvp->driver_shader); + st->pipe->bind_fs_state(st->pipe, stfp->driver_shader); st->vertex_result_to_slot = xvp->output_to_slot; } diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 663c4f205d..f1fddc4e02 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -35,7 +35,6 @@ #include "main/macros.h" #include "st_context.h" -#include "st_cache.h" #include "st_cb_accum.h" #include "st_cb_fbo.h" #include "st_draw.h" diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index e712fd84cd..eae40f2a4f 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -35,7 +35,6 @@ #include "main/macros.h" #include "shader/prog_instruction.h" #include "st_atom.h" -#include "st_cache.h" #include "st_context.h" #include "st_cb_accum.h" #include "st_cb_clear.h" @@ -50,6 +49,8 @@ #include "pipe/p_defines.h" #include "pipe/p_winsys.h" +#include "cso_cache/cso_context.h" + @@ -157,8 +158,7 @@ make_frag_shader(struct st_context *st) p->OutputsWritten = (1 << FRAG_RESULT_COLR); stfp = (struct st_fragment_program *) p; - st_translate_fragment_program(st, stfp, NULL, - stfp->tokens, ST_MAX_SHADER_TOKENS); + st_translate_fragment_program(st, stfp, NULL); return stfp; } @@ -206,9 +206,10 @@ make_vertex_shader(struct st_context *st) (1 << VERT_RESULT_HPOS)); stvp = (struct st_vertex_program *) p; - st_translate_vertex_program(st, stvp, NULL, - stvp->tokens, ST_MAX_SHADER_TOKENS); + st_translate_vertex_program(st, stvp, NULL); +#if 0 assert(stvp->cso); +#endif return stvp; } @@ -284,7 +285,6 @@ clear_with_quad(GLcontext *ctx, /* blend state: RGBA masking */ { struct pipe_blend_state blend; - const struct cso_blend *cso; memset(&blend, 0, sizeof(blend)); if (color) { if (ctx->Color.ColorMask[0]) @@ -298,14 +298,12 @@ clear_with_quad(GLcontext *ctx, if (st->ctx->Color.DitherFlag) blend.dither = 1; } - cso = st_cached_blend_state(st, &blend); - pipe->bind_blend_state(pipe, cso->data); + cso_set_blend(st->cso_context, &blend); } /* depth_stencil state: always pass/set to ref value */ { struct pipe_depth_stencil_alpha_state depth_stencil; - const struct cso_depth_stencil_alpha *cso; memset(&depth_stencil, 0, sizeof(depth_stencil)); if (depth) { depth_stencil.depth.enabled = 1; @@ -323,14 +321,13 @@ clear_with_quad(GLcontext *ctx, depth_stencil.stencil[0].value_mask = 0xff; depth_stencil.stencil[0].write_mask = ctx->Stencil.WriteMask[0] & 0xff; } - cso = st_cached_depth_stencil_alpha_state(st, &depth_stencil); - pipe->bind_depth_stencil_alpha_state(pipe, cso->data); + + cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil); } /* rasterizer state: nothing */ { struct pipe_rasterizer_state raster; - const struct cso_rasterizer *cso; memset(&raster, 0, sizeof(raster)); #if 0 /* don't do per-pixel scissor; we'll just draw a PIPE_PRIM_QUAD @@ -339,8 +336,7 @@ clear_with_quad(GLcontext *ctx, if (ctx->Scissor.Enabled) raster.scissor = 1; #endif - cso = st_cached_rasterizer_state(st, &raster); - pipe->bind_rasterizer_state(pipe, cso->data); + cso_set_rasterizer(st->cso_context, &raster); } /* fragment shader state: color pass-through program */ @@ -349,7 +345,7 @@ clear_with_quad(GLcontext *ctx, if (!stfp) { stfp = make_frag_shader(st); } - pipe->bind_fs_state(pipe, stfp->cso->data); + pipe->bind_fs_state(pipe, stfp->driver_shader); } /* vertex shader state: color/position pass-through */ @@ -358,7 +354,7 @@ clear_with_quad(GLcontext *ctx, if (!stvp) { stvp = make_vertex_shader(st); } - pipe->bind_vs_state(pipe, stvp->cso->data); + pipe->bind_vs_state(pipe, stvp->driver_shader); } /* viewport state: viewport matching window dims */ @@ -380,16 +376,19 @@ clear_with_quad(GLcontext *ctx, /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); +#if 0 + /* Can't depend on old state objects still existing -- may have + * been deleted to make room in the hash, etc. (Should get + * fixed...) + */ + st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); +#else /* Restore pipe state */ - pipe->bind_blend_state(pipe, st->state.blend->data); - pipe->bind_depth_stencil_alpha_state(pipe, st->state.depth_stencil->data); - pipe->bind_fs_state(pipe, st->state.fs->data); - pipe->bind_vs_state(pipe, st->state.vs->cso->data); - pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); + cso_set_rasterizer(st->cso_context, &st->state.rasterizer); + pipe->bind_fs_state(pipe, st->fp->driver_shader); + pipe->bind_vs_state(pipe, st->vp->driver_shader); +#endif pipe->set_viewport_state(pipe, &st->state.viewport); - /* OR: - st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); - */ } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index dee4c4132a..18ec9645c4 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -41,7 +41,6 @@ #include "st_context.h" #include "st_atom.h" #include "st_atom_constbuf.h" -#include "st_cache.h" #include "st_draw.h" #include "st_program.h" #include "st_cb_drawpixels.h" @@ -58,6 +57,7 @@ #include "pipe/p_winsys.h" #include "util/p_tile.h" #include "shader/prog_instruction.h" +#include "cso_cache/cso_context.h" /** @@ -159,8 +159,7 @@ make_bitmap_fragment_program(GLcontext *ctx) stfp = (struct st_fragment_program *) p; stfp->Base.UsesKill = GL_TRUE; - st_translate_fragment_program(ctx->st, stfp, NULL, - stfp->tokens, ST_MAX_SHADER_TOKENS); + st_translate_fragment_program(ctx->st, stfp, NULL); return stfp; } @@ -204,8 +203,7 @@ combined_bitmap_fragment_program(GLcontext *ctx) #endif /* translate to TGSI tokens */ - st_translate_fragment_program(st, stfp, NULL, - stfp->tokens, ST_MAX_SHADER_TOKENS); + st_translate_fragment_program(st, stfp, NULL); /* save new program, update serial numbers */ st->bitmap.user_prog_sn = st->fp->serialNo; @@ -266,8 +264,7 @@ combined_drawpix_fragment_program(GLcontext *ctx) #endif /* translate to TGSI tokens */ - st_translate_fragment_program(st, stfp, NULL, - stfp->tokens, ST_MAX_SHADER_TOKENS); + st_translate_fragment_program(st, stfp, NULL); /* save new program, update serial numbers */ st->pixel_xfer.xfer_prog_sn = st->pixel_xfer.program->serialNo; @@ -343,8 +340,7 @@ make_fragment_shader_z(struct st_context *st) p->OutputsWritten = (1 << FRAG_RESULT_COLR) | (1 << FRAG_RESULT_DEPR); stfp = (struct st_fragment_program *) p; - st_translate_fragment_program(st, stfp, NULL, - stfp->tokens, ST_MAX_SHADER_TOKENS); + st_translate_fragment_program(st, stfp, NULL); return stfp; } @@ -421,8 +417,7 @@ st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor) } stvp = (struct st_vertex_program *) p; - st_translate_vertex_program(st, stvp, NULL, - stvp->tokens, ST_MAX_SHADER_TOKENS); + st_translate_vertex_program(st, stvp, NULL); progs[passColor] = stvp; @@ -641,7 +636,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, const GLfloat *color, GLboolean invertTex) { + struct st_context *st = ctx->st; struct pipe_context *pipe = ctx->st->pipe; + struct cso_context *cso = ctx->st->cso_context; GLfloat x0, y0, x1, y1; GLuint maxSize; @@ -656,24 +653,23 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* setup state: just scissor */ { struct pipe_rasterizer_state setup; - const struct cso_rasterizer *cso; memset(&setup, 0, sizeof(setup)); if (ctx->Scissor.Enabled) setup.scissor = 1; - cso = st_cached_rasterizer_state(ctx->st, &setup); - pipe->bind_rasterizer_state(pipe, cso->data); + + cso_set_rasterizer(cso, &setup); } /* fragment shader state: TEX lookup program */ - pipe->bind_fs_state(pipe, stfp->cso->data); + pipe->bind_fs_state(pipe, stfp->driver_shader); /* vertex shader state: position + texcoord pass-through */ - pipe->bind_vs_state(pipe, stvp->cso->data); + pipe->bind_vs_state(pipe, stvp->driver_shader); + /* texture sampling state: */ { struct pipe_sampler_state sampler; - const struct cso_sampler *cso; memset(&sampler, 0, sizeof(sampler)); sampler.wrap_s = PIPE_TEX_WRAP_CLAMP; sampler.wrap_t = PIPE_TEX_WRAP_CLAMP; @@ -682,8 +678,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; sampler.normalized_coords = 1; - cso = st_cached_sampler_state(ctx->st, &sampler); - pipe->bind_sampler_states(pipe, 1, (void**)&cso->data); + + cso_single_sampler(cso, 0, &sampler); + cso_single_sampler_done(cso); } /* viewport state: viewport matching window dims */ @@ -723,14 +720,25 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, draw_quad(ctx, x0, y0, z, x1, y1, invertTex); /* restore GL state */ - pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer->data); - pipe->bind_fs_state(pipe, ctx->st->state.fs->data); - pipe->bind_vs_state(pipe, ctx->st->state.vs->cso->data); pipe->set_sampler_textures(pipe, ctx->st->state.num_textures, ctx->st->state.sampler_texture); - pipe->bind_sampler_states(pipe, ctx->st->state.num_samplers, - ctx->st->state.sampler); + pipe->set_viewport_state(pipe, &ctx->st->state.viewport); + +#if 0 + /* Can't depend on old state objects still existing -- may have + * been deleted to make room in the hash, etc. (Should get + * fixed...) + */ + st_invalidate_state(ctx, _NEW_COLOR | _NEW_TEXTURE); +#else + /* restore state */ + pipe->bind_fs_state(pipe, st->fp->driver_shader); + pipe->bind_vs_state(pipe, st->vp->driver_shader); + cso_set_rasterizer(cso, &st->state.rasterizer); + cso_set_samplers(cso, PIPE_MAX_SAMPLERS, + (const struct pipe_sampler_state **) st->state.sampler_list); +#endif } @@ -798,10 +806,10 @@ compatible_formats(GLenum format, GLenum type, enum pipe_format pipeFormat) static GLboolean any_fragment_ops(const struct st_context *st) { - if (st->state.depth_stencil->state.alpha.enabled || - st->state.blend->state.blend_enable || - st->state.blend->state.logicop_enable || - st->state.depth_stencil->state.depth.enabled) + if (st->state.depth_stencil.alpha.enabled || + st->state.depth_stencil.depth.enabled || + st->state.blend.blend_enable || + st->state.blend.logicop_enable) /* XXX more checks */ return GL_TRUE; else diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 61d4f4c41c..4dc76f19b1 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -168,11 +168,13 @@ static void st_program_string_notify( GLcontext *ctx, stfp->serialNo++; +#if 0 if (stfp->cso) { /* free the TGSI code */ // cso_delete(stfp->vs); stfp->cso = NULL; } +#endif stfp->param_state = stfp->Base.Base.Parameters->StateFlags; @@ -184,13 +186,14 @@ static void st_program_string_notify( GLcontext *ctx, stvp->serialNo++; +#if 0 if (stvp->cso) { /* free the CSO data */ st->pipe->delete_vs_state(st->pipe, stvp->cso->data); FREE((void *) stvp->cso); stvp->cso = NULL; } - +#endif if (stvp->draw_shader) { draw_delete_vertex_shader(st->draw, stvp->draw_shader); stvp->draw_shader = NULL; diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 09e389f9dc..5458ab420e 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -56,6 +56,7 @@ #include "pipe/p_inlines.h" #include "draw/draw_context.h" #include "cso_cache/cso_cache.h" +#include "cso_cache/cso_context.h" /** @@ -78,6 +79,7 @@ void st_invalidate_state(GLcontext * ctx, GLuint new_state) static struct st_context * st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) { + uint i; struct st_context *st = CALLOC_STRUCT( st_context ); ctx->st = st; @@ -93,12 +95,15 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st->dirty.mesa = ~0; st->dirty.st = ~0; - st->cache = cso_cache_create(); + st->cso_context = cso_create_context(pipe); st_init_atoms( st ); st_init_draw( st ); st_init_generate_mipmap(st); + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) + st->state.sampler_list[i] = &st->state.samplers[i]; + /* we want all vertex data to be placed in buffer objects */ vbo_use_buffer_objects(ctx); @@ -149,7 +154,7 @@ static void st_destroy_context_priv( struct st_context *st ) _vbo_DestroyContext(st->ctx); - cso_cache_delete( st->cache ); + cso_destroy_context(st->cso_context); _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 897a5109b7..e81aebba3d 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -74,14 +74,11 @@ struct st_context * Other state is just parameter values. */ struct { - const struct cso_alpha_test *alpha_test; - const struct cso_blend *blend; - void *sampler[PIPE_MAX_SAMPLERS]; - const struct cso_depth_stencil_alpha *depth_stencil; - const struct cso_rasterizer *rasterizer; - const struct cso_fragment_shader *fs; - struct st_vertex_program *vs; - + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state depth_stencil; + struct pipe_rasterizer_state rasterizer; + struct pipe_sampler_state samplers[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_state *sampler_list[PIPE_MAX_SAMPLERS]; struct pipe_blend_color blend_color; struct pipe_clip_state clip; struct pipe_constant_buffer constants[2]; @@ -151,6 +148,10 @@ struct st_context /** For gen/render mipmap feature */ struct { + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state depthstencil; + struct pipe_rasterizer_state rasterizer; + void *blend_cso; void *depthstencil_cso; void *rasterizer_cso; @@ -158,7 +159,7 @@ struct st_context struct st_vertex_program *stvp; } gen_mipmap; - struct cso_cache *cache; + struct cso_context *cso_context; }; diff --git a/src/mesa/state_tracker/st_debug.c b/src/mesa/state_tracker/st_debug.c index 5888bcb98a..9c13010da8 100644 --- a/src/mesa/state_tracker/st_debug.c +++ b/src/mesa/state_tracker/st_debug.c @@ -53,15 +53,15 @@ st_print_current(void) int i; printf("Vertex Transform Inputs:\n"); - for (i = 0; i < st->state.vs->cso->state.num_inputs; i++) { + for (i = 0; i < st->vp->state.num_inputs; i++) { printf(" Slot %d: VERT_ATTRIB_%d\n", i, st->vp->index_to_input[i]); } - tgsi_dump( st->state.vs->cso->state.tokens, 0 ); + tgsi_dump( st->vp->state.tokens, 0 ); if (st->vp->Base.Base.Parameters) _mesa_print_parameter_list(st->vp->Base.Base.Parameters); - tgsi_dump( st->state.fs->state.tokens, 0 ); + tgsi_dump( st->fp->state.tokens, 0 ); if (st->fp->Base.Base.Parameters) _mesa_print_parameter_list(st->fp->Base.Base.Parameters); } diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 1c0fa8c6aa..98504e46c1 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -36,7 +36,6 @@ #include "vbo/vbo.h" #include "st_atom.h" -#include "st_cache.h" #include "st_context.h" #include "st_cb_bufferobjects.h" #include "st_draw.h" @@ -219,7 +218,7 @@ st_draw_vbo(GLcontext *ctx, /* must get these after state validation! */ vp = ctx->st->vp; - vs = &ctx->st->state.vs->cso->state; + vs = &ctx->st->vp->state; /* loop over TGSI shader inputs to determine vertex buffer * and attribute info @@ -481,10 +480,10 @@ st_feedback_draw_vbo(GLcontext *ctx, /* must get these after state validation! */ vp = ctx->st->vp; - vs = &ctx->st->state.vs->cso->state; + vs = &st->vp->state; - if (!st->state.vs->draw_shader) { - st->state.vs->draw_shader = draw_create_vertex_shader(draw, vs); + if (!st->vp->draw_shader) { + st->vp->draw_shader = draw_create_vertex_shader(draw, vs); } /* @@ -496,8 +495,8 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(draw); draw_set_viewport_state(draw, &st->state.viewport); draw_set_clip_state(draw, &st->state.clip); - draw_set_rasterizer_state(draw, &st->state.rasterizer->state); - draw_bind_vertex_shader(draw, st->state.vs->draw_shader); + draw_set_rasterizer_state(draw, &st->state.rasterizer); + draw_bind_vertex_shader(draw, st->vp->draw_shader); set_feedback_vertex_format(ctx); /* loop over TGSI shader inputs to determine vertex buffer diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 3723e26d45..9c4e1032ef 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -38,6 +38,7 @@ #include "pipe/p_inlines.h" #include "pipe/p_winsys.h" #include "cso_cache/cso_cache.h" +#include "cso_cache/cso_context.h" #include "st_context.h" #include "st_draw.h" @@ -89,8 +90,7 @@ make_tex_fragment_program(GLcontext *ctx) stfp = (struct st_fragment_program *) p; - st_translate_fragment_program(ctx->st, stfp, NULL, - stfp->tokens, ST_MAX_SHADER_TOKENS); + st_translate_fragment_program(ctx->st, stfp, NULL); return stfp; } @@ -118,6 +118,7 @@ st_init_generate_mipmap(struct st_context *st) blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; blend.colormask = PIPE_MASK_RGBA; + st->gen_mipmap.blend = blend; st->gen_mipmap.blend_cso = pipe->create_blend_state(pipe, &blend); memset(&depthstencil, 0, sizeof(depthstencil)); @@ -257,14 +258,14 @@ st_render_mipmap(struct st_context *st, sampler.normalized_coords = 1; - /* bind CSOs */ - pipe->bind_blend_state(pipe, st->gen_mipmap.blend_cso); - pipe->bind_depth_stencil_alpha_state(pipe, st->gen_mipmap.depthstencil_cso); - pipe->bind_rasterizer_state(pipe, st->gen_mipmap.rasterizer_cso); + /* bind state */ + cso_set_blend(st->cso_context, &st->gen_mipmap.blend); + cso_set_depth_stencil_alpha(st->cso_context, &st->gen_mipmap.depthstencil); + cso_set_rasterizer(st->cso_context, &st->gen_mipmap.rasterizer); /* bind shaders */ - pipe->bind_fs_state(pipe, st->gen_mipmap.stfp->cso->data); - pipe->bind_vs_state(pipe, st->gen_mipmap.stvp->cso->data); + pipe->bind_fs_state(pipe, st->gen_mipmap.stfp->driver_shader); + pipe->bind_vs_state(pipe, st->gen_mipmap.stvp->driver_shader); /* * XXX for small mipmap levels, it may be faster to use the software @@ -304,17 +305,18 @@ st_render_mipmap(struct st_context *st, /*pt->first_level = first_level_save;*/ /* restore pipe state */ - if (st->state.rasterizer) - pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); - if (st->state.fs) - pipe->bind_fs_state(pipe, st->state.fs->data); - if (st->state.vs) - pipe->bind_vs_state(pipe, st->state.vs->cso->data); - pipe->bind_sampler_states(pipe, st->state.num_samplers, - st->state.sampler); +#if 0 + cso_set_rasterizer(st->cso_context, &st->state.rasterizer); + cso_set_samplers(st->cso_context, st->state.samplers_list); + pipe->bind_fs_state(pipe, st->fp->shader_program); + pipe->bind_vs_state(pipe, st->vp->shader_program); pipe->set_sampler_textures(pipe, st->state.num_textures, st->state.sampler_texture); pipe->set_viewport_state(pipe, &st->state.viewport); +#else + /* XXX is this sufficient? */ + st_invalidate_state(st->ctx, _NEW_COLOR | _NEW_TEXTURE); +#endif return TRUE; } diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index 97206752af..9446b012ad 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -683,8 +683,9 @@ find_temporaries(const struct gl_program *program, * \param tokens array to store translated tokens in * \param maxTokens size of the tokens array * + * \return number of tokens placed in 'tokens' buffer, or zero if error */ -GLboolean +GLuint tgsi_translate_mesa_program( uint procType, const struct gl_program *program, @@ -918,6 +919,6 @@ tgsi_translate_mesa_program( maxTokens - ti ); } - return GL_TRUE; + return ti; } diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.h b/src/mesa/state_tracker/st_mesa_to_tgsi.h index 3ababf1339..63fc855b53 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.h +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.h @@ -39,7 +39,7 @@ extern "C" { struct tgsi_token; struct gl_program; -GLboolean +GLuint tgsi_translate_mesa_program( uint procType, const struct gl_program *program, diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index aa252c845a..0f8784e132 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -42,15 +42,29 @@ #include "tgsi/util/tgsi_dump.h" #include "st_context.h" -#include "st_cache.h" #include "st_atom.h" #include "st_program.h" #include "st_mesa_to_tgsi.h" +#include "cso_cache/cso_context.h" #define TGSI_DEBUG 0 +/** XXX we should use the version of this from p_util.h but including + * that header causes symbol collisions. + */ +static INLINE void * +mem_dup(const void *src, uint size) +{ + void *dup = MALLOC(size); + if (dup) + memcpy(dup, src, size); + return dup; +} + + + /** * Translate a Mesa vertex shader into a TGSI shader. * \param outputMapping to map vertex program output registers to TGSI @@ -61,15 +75,15 @@ void st_translate_vertex_program(struct st_context *st, struct st_vertex_program *stvp, - const GLuint outputMapping[], - struct tgsi_token *tokensOut, - GLuint maxTokens) + const GLuint outputMapping[]) { + struct pipe_context *pipe = st->pipe; + struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; GLuint defaultOutputMapping[VERT_RESULT_MAX]; struct pipe_shader_state vs; - const struct cso_vertex_shader *cso; GLuint attr, i; GLuint num_generic = 0; + GLuint num_tokens; memset(&vs, 0, sizeof(vs)); @@ -240,7 +254,7 @@ st_translate_vertex_program(struct st_context *st, /* XXX: fix static allocation of tokens: */ - tgsi_translate_mesa_program( TGSI_PROCESSOR_VERTEX, + num_tokens = tgsi_translate_mesa_program( TGSI_PROCESSOR_VERTEX, &stvp->Base.Base, /* inputs */ vs.num_inputs, @@ -252,20 +266,21 @@ st_translate_vertex_program(struct st_context *st, vs.num_outputs, outputMapping, vs.output_semantic_name, - vs.output_semantic_index, + vs.output_semantic_index, /* tokenized result */ - tokensOut, maxTokens); + tokens, ST_MAX_SHADER_TOKENS); - vs.tokens = tokensOut; + vs.tokens = (struct tgsi_token *) + mem_dup(tokens, num_tokens * sizeof(tokens[0])); - cso = st_cached_vs_state(st, &vs); - stvp->cso = cso; + stvp->state = vs; /* struct copy */ + stvp->driver_shader = pipe->create_vs_state(pipe, &vs); if (0) _mesa_print_program(&stvp->Base.Base); if (TGSI_DEBUG) - tgsi_dump( tokensOut, 0 ); + tgsi_dump( vs.tokens, 0 ); } @@ -280,10 +295,10 @@ st_translate_vertex_program(struct st_context *st, const struct cso_fragment_shader * st_translate_fragment_program(struct st_context *st, struct st_fragment_program *stfp, - const GLuint inputMapping[], - struct tgsi_token *tokensOut, - GLuint maxTokens) + const GLuint inputMapping[]) { + struct pipe_context *pipe = st->pipe; + struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; GLuint outputMapping[FRAG_RESULT_MAX]; GLuint defaultInputMapping[FRAG_ATTRIB_MAX]; struct pipe_shader_state fs; @@ -293,6 +308,7 @@ st_translate_fragment_program(struct st_context *st, const GLbitfield inputsRead = stfp->Base.Base.InputsRead; GLuint vslot = 0; GLuint num_generic = 0; + GLuint num_tokens; memset(&fs, 0, sizeof(fs)); @@ -401,7 +417,7 @@ st_translate_fragment_program(struct st_context *st, /* XXX: fix static allocation of tokens: */ - tgsi_translate_mesa_program( TGSI_PROCESSOR_FRAGMENT, + num_tokens = tgsi_translate_mesa_program( TGSI_PROCESSOR_FRAGMENT, &stfp->Base.Base, /* inputs */ fs.num_inputs, @@ -415,18 +431,19 @@ st_translate_fragment_program(struct st_context *st, fs.output_semantic_name, fs.output_semantic_index, /* tokenized result */ - tokensOut, maxTokens); + tokens, ST_MAX_SHADER_TOKENS); - fs.tokens = tokensOut; + fs.tokens = (struct tgsi_token *) + mem_dup(tokens, num_tokens * sizeof(tokens[0])); - cso = st_cached_fs_state(st, &fs); - stfp->cso = cso; + stfp->state = fs; /* struct copy */ + stfp->driver_shader = pipe->create_fs_state(pipe, &fs); if (0) _mesa_print_program(&stfp->Base.Base); if (TGSI_DEBUG) - tgsi_dump( tokensOut, 0/*TGSI_DUMP_VERBOSE*/ ); + tgsi_dump( fs.tokens, 0/*TGSI_DUMP_VERBOSE*/ ); return cso; } diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 31558af6ce..78786dcbb6 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -60,11 +60,8 @@ struct st_fragment_program /** map FP input back to VP output */ GLuint input_map[PIPE_MAX_SHADER_INPUTS]; - /** The program in TGSI format */ - struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; - - /** Pointer to the corresponding cached shader */ - const struct cso_fragment_shader *cso; + struct pipe_shader_state state; + struct pipe_shader_state *driver_shader; GLuint param_state; @@ -88,11 +85,8 @@ struct st_vertex_program /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */ GLuint index_to_input[PIPE_MAX_SHADER_INPUTS]; - /** The program in TGSI format */ - struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; - - /** Pointer to the corresponding cached shader */ - const struct cso_vertex_shader *cso; + struct pipe_shader_state state; + struct pipe_shader_state *driver_shader; /** For using our private draw module (glRasterPos) */ struct draw_vertex_shader *draw_shader; @@ -122,16 +116,12 @@ st_vertex_program( struct gl_vertex_program *vp ) extern const struct cso_fragment_shader * st_translate_fragment_program(struct st_context *st, struct st_fragment_program *fp, - const GLuint inputMapping[], - struct tgsi_token *tokens, - GLuint maxTokens); + const GLuint inputMapping[]); extern void st_translate_vertex_program(struct st_context *st, struct st_vertex_program *vp, - const GLuint vert_output_to_slot[], - struct tgsi_token *tokens, - GLuint maxTokens); + const GLuint vert_output_to_slot[]); #endif -- cgit v1.2.3 From d91e62e9c6ff81c91b83af883281c1e205c6bf35 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 12 Mar 2008 18:24:46 -0600 Subject: gallium: in clear_stencil_buffer() check surface format to determine stencil clear value ... as we do for the Z and Z+stencil cases --- src/mesa/state_tracker/st_cb_clear.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index eae40f2a4f..cc8a136292 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -544,6 +544,15 @@ clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) /* simple clear of whole buffer */ GLuint clearValue = ctx->Stencil.Clear; + + switch (strb->surface->format) { + case PIPE_FORMAT_S8Z24_UNORM: + clearValue <<= 24; + break; + default: + ; /* no-op, stencil value is in least significant bits */ + } + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } } -- cgit v1.2.3 From 3e625ce18e35b2b0343962f93480abf4bf9b188a Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 13 Mar 2008 15:07:14 -0600 Subject: gallium: add some temporary code for testing draw module vertex passthrough Set TEST_DRAW_PASSTHROUGH=1, run progs/trivial/clear-scissor --- src/mesa/state_tracker/st_cb_clear.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index cc8a136292..4fe6195a07 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -52,7 +52,8 @@ #include "cso_cache/cso_context.h" - +/* XXX for testing draw module vertex passthrough: */ +#define TEST_DRAW_PASSTHROUGH 0 static GLuint @@ -229,6 +230,12 @@ draw_quad(GLcontext *ctx, GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */ GLuint i; +#if TEST_DRAW_PASSTHROUGH + /* invert Y coords (may be off by one pixel) */ + y0 = ctx->DrawBuffer->Height - y0; + y1 = ctx->DrawBuffer->Height - y1; +#endif + /* positions */ verts[0][0][0] = x0; verts[0][0][1] = y0; @@ -335,6 +342,10 @@ clear_with_quad(GLcontext *ctx, */ if (ctx->Scissor.Enabled) raster.scissor = 1; +#endif +#if TEST_DRAW_PASSTHROUGH + raster.bypass_clipping = 1; + raster.bypass_vs = 1; #endif cso_set_rasterizer(st->cso_context, &raster); } @@ -348,6 +359,7 @@ clear_with_quad(GLcontext *ctx, pipe->bind_fs_state(pipe, stfp->driver_shader); } +#if !TEST_DRAW_PASSTHROUGH /* vertex shader state: color/position pass-through */ { static struct st_vertex_program *stvp = NULL; @@ -356,7 +368,9 @@ clear_with_quad(GLcontext *ctx, } pipe->bind_vs_state(pipe, stvp->driver_shader); } +#endif +#if !TEST_DRAW_PASSTHROUGH /* viewport state: viewport matching window dims */ { const float width = ctx->DrawBuffer->Width; @@ -372,6 +386,7 @@ clear_with_quad(GLcontext *ctx, vp.translate[3] = 0.0; pipe->set_viewport_state(pipe, &vp); } +#endif /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); -- cgit v1.2.3 From 5bae5871f03c96eb173cb55d7e8a846a2c4bd4a0 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 13 Mar 2008 17:06:13 -0600 Subject: gallium: for TEST_DRAW_PASSTHROUGH, pass inClipCoords=FALSE to st_draw_vertices() When pass-through mode is fully supported we'll clean this up more. --- src/mesa/state_tracker/st_cb_clear.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 4fe6195a07..5865071439 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -259,7 +259,13 @@ draw_quad(GLcontext *ctx, verts[i][1][3] = color[3]; } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, GL_FALSE); + st_draw_vertices(ctx, PIPE_PRIM_POLYGON, 4, (float *) verts, 2, +#if TEST_DRAW_PASSTHROUGH + GL_TRUE +#else + GL_FALSE +#endif + ); } -- cgit v1.2.3 From f1cfb1e3676fc9e1fea6698ed5e8e79d2b094dae Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 18 Mar 2008 09:23:35 -0600 Subject: gallium: use new color packing utility functions --- src/mesa/state_tracker/st_cb_clear.c | 61 ++++-------------------------------- 1 file changed, 6 insertions(+), 55 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 5865071439..8223784d2e 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -48,6 +48,7 @@ #include "pipe/p_state.h" #include "pipe/p_defines.h" #include "pipe/p_winsys.h" +#include "util/u_pack_color.h" #include "cso_cache/cso_context.h" @@ -56,55 +57,6 @@ #define TEST_DRAW_PASSTHROUGH 0 -static GLuint -color_value(enum pipe_format pipeFormat, const GLfloat color[4]) -{ - GLubyte r, g, b, a; - - UNCLAMPED_FLOAT_TO_UBYTE(r, color[0]); - UNCLAMPED_FLOAT_TO_UBYTE(g, color[1]); - UNCLAMPED_FLOAT_TO_UBYTE(b, color[2]); - UNCLAMPED_FLOAT_TO_UBYTE(a, color[3]); - - switch (pipeFormat) { - case PIPE_FORMAT_R8G8B8A8_UNORM: - return (r << 24) | (g << 16) | (b << 8) | a; - case PIPE_FORMAT_A8R8G8B8_UNORM: - return (a << 24) | (r << 16) | (g << 8) | b; - case PIPE_FORMAT_B8G8R8A8_UNORM: - return (b << 24) | (g << 16) | (r << 8) | a; - case PIPE_FORMAT_R5G6B5_UNORM: - return ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); - default: - assert(0); - return 0; - } -} - - -static uint -depth_value(enum pipe_format pipeFormat, GLfloat value) -{ - switch (pipeFormat) { - case PIPE_FORMAT_Z16_UNORM: - return (uint) (value * 0xffff); - case PIPE_FORMAT_Z32_UNORM: - /* special-case to avoid overflow */ - if (value == 1.0) - return 0xffffffff; - else - return (uint) (value * 0xffffffff); - case PIPE_FORMAT_S8Z24_UNORM: - return (uint) (value * 0xffffff); - case PIPE_FORMAT_Z24S8_UNORM: - return ((uint) (value * 0xffffff)) << 8; - default: - assert(0); - return 0; - } -} - - static GLboolean is_depth_stencil_format(enum pipe_format pipeFormat) { @@ -518,7 +470,6 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) - static void clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { @@ -527,10 +478,10 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE); } else { - struct st_renderbuffer *strb = st_renderbuffer(rb); - /* clear whole buffer w/out masking */ - uint clearValue = color_value(strb->surface->format, ctx->Color.ClearColor); + struct st_renderbuffer *strb = st_renderbuffer(rb); + uint clearValue; + util_pack_color(ctx->Color.ClearColor, strb->surface->format, &clearValue); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } } @@ -547,7 +498,7 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) struct st_renderbuffer *strb = st_renderbuffer(rb); /* simple clear of whole buffer */ - uint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); + uint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } } @@ -591,7 +542,7 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) struct st_renderbuffer *strb = st_renderbuffer(rb); /* clear whole buffer w/out masking */ - GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); + GLuint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear); switch (strb->surface->format) { case PIPE_FORMAT_S8Z24_UNORM: -- cgit v1.2.3 From bab9209e12ec16ef3b33d46be8e6154f8c8f182d Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 18 Mar 2008 15:15:02 -0600 Subject: gallium: restore additional state after clearing with quad --- src/mesa/state_tracker/st_cb_clear.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 8223784d2e..693cddedf7 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -357,6 +357,8 @@ clear_with_quad(GLcontext *ctx, st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); #else /* Restore pipe state */ + cso_set_blend(st->cso_context, &st->state.blend); + cso_set_depth_stencil_alpha(st->cso_context, &st->state.depth_stencil); cso_set_rasterizer(st->cso_context, &st->state.rasterizer); pipe->bind_fs_state(pipe, st->fp->driver_shader); pipe->bind_vs_state(pipe, st->vp->driver_shader); -- cgit v1.2.3 From 7d95efde0a0e13e13c59444703bc47eb13926385 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 19 Mar 2008 11:12:48 -0600 Subject: gallium: implement CSO save/restore functions for use by meta operations (blit, gen-mipmaps, quad-clear, etc) Also, additional cso_set_*() functions for viewport, framebuffer, blend color, etc. state. --- src/gallium/auxiliary/cso_cache/cso_context.c | 202 +++++++++++++++++++++++--- src/gallium/auxiliary/cso_cache/cso_context.h | 53 +++++-- src/gallium/auxiliary/util/u_blit.c | 125 ++++++++-------- src/gallium/auxiliary/util/u_blit.h | 5 +- src/gallium/auxiliary/util/u_gen_mipmap.c | 116 ++++++++------- src/gallium/auxiliary/util/u_gen_mipmap.h | 6 +- src/mesa/state_tracker/st_atom_blend.c | 12 +- src/mesa/state_tracker/st_atom_framebuffer.c | 9 +- src/mesa/state_tracker/st_atom_viewport.c | 26 ++-- src/mesa/state_tracker/st_cb_blit.c | 17 +-- src/mesa/state_tracker/st_cb_clear.c | 35 ++--- src/mesa/state_tracker/st_cb_drawpixels.c | 25 ++-- src/mesa/state_tracker/st_context.h | 1 - src/mesa/state_tracker/st_gen_mipmap.c | 20 +-- 14 files changed, 408 insertions(+), 244 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 294ac82281..53d05ae6ce 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -52,11 +52,27 @@ struct cso_context { void *samplers[PIPE_MAX_SAMPLERS]; unsigned nr_samplers; - void *blend; - void *depth_stencil; - void *rasterizer; - void *fragment_shader; - void *vertex_shader; + void *samplers_saved[PIPE_MAX_SAMPLERS]; + unsigned nr_samplers_saved; + + struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + uint nr_textures; + + struct pipe_texture *textures_saved[PIPE_MAX_SAMPLERS]; + uint nr_textures_saved; + + /** Current and saved state. + * The saved state is used as a 1-deep stack. + */ + void *blend, *blend_saved; + void *depth_stencil, *depth_stencil_saved; + void *rasterizer, *rasterizer_saved; + void *fragment_shader, *fragment_shader_saved; + void *vertex_shader, *vertex_shader_saved; + + struct pipe_framebuffer_state fb, fb_saved; + struct pipe_viewport_state vp, vp_saved; + struct pipe_blend_color blend_color; }; @@ -149,12 +165,23 @@ void cso_set_blend(struct cso_context *ctx, } } -void cso_unset_blend(struct cso_context *ctx) +void cso_save_blend(struct cso_context *ctx) +{ + assert(!ctx->blend_saved); + ctx->blend_saved = ctx->blend; +} + +void cso_restore_blend(struct cso_context *ctx) { - ctx->blend = NULL; + if (ctx->blend != ctx->blend_saved) { + ctx->blend = ctx->blend_saved; + ctx->pipe->bind_blend_state(ctx->pipe, ctx->blend_saved); + } + ctx->blend_saved = NULL; } + void cso_single_sampler(struct cso_context *ctx, unsigned idx, const struct pipe_sampler_state *templ) @@ -226,13 +253,48 @@ void cso_set_samplers( struct cso_context *ctx, cso_single_sampler_done( ctx ); } -void cso_unset_samplers( struct cso_context *ctx ) +void cso_save_samplers(struct cso_context *ctx) +{ + ctx->nr_samplers_saved = ctx->nr_samplers; + memcpy(ctx->samplers_saved, ctx->samplers, sizeof(ctx->samplers)); +} + +void cso_restore_samplers(struct cso_context *ctx) +{ + cso_set_samplers(ctx, ctx->nr_samplers_saved, + (const struct pipe_sampler_state **) ctx->samplers_saved); +} + + +void cso_set_sampler_textures( struct cso_context *ctx, + uint count, + struct pipe_texture **textures ) { uint i; - for (i = 0; i < ctx->nr_samplers; i++) - ctx->samplers[i] = NULL; + + ctx->nr_textures = count; + + for (i = 0; i < count; i++) + ctx->textures[i] = textures[i]; + for ( ; i < PIPE_MAX_SAMPLERS; i++) + ctx->textures[i] = NULL; + + ctx->pipe->set_sampler_textures(ctx->pipe, count, textures); } +void cso_save_sampler_textures( struct cso_context *ctx ) +{ + ctx->nr_textures_saved = ctx->nr_textures; + memcpy(ctx->textures_saved, ctx->textures, sizeof(ctx->textures)); +} + +void cso_restore_sampler_textures( struct cso_context *ctx ) +{ + cso_set_sampler_textures(ctx, ctx->nr_textures_saved, ctx->textures_saved); + ctx->nr_textures_saved = 0; +} + + void cso_set_depth_stencil_alpha(struct cso_context *ctx, @@ -267,15 +329,25 @@ void cso_set_depth_stencil_alpha(struct cso_context *ctx, } } -void cso_unset_depth_stencil_alpha(struct cso_context *ctx) +void cso_save_depth_stencil_alpha(struct cso_context *ctx) { - ctx->depth_stencil = NULL; + assert(!ctx->depth_stencil_saved); + ctx->depth_stencil_saved = ctx->depth_stencil; +} + +void cso_restore_depth_stencil_alpha(struct cso_context *ctx) +{ + if (ctx->depth_stencil != ctx->depth_stencil_saved) { + ctx->depth_stencil = ctx->depth_stencil_saved; + ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe, ctx->depth_stencil_saved); + } + ctx->depth_stencil_saved = NULL; } void cso_set_rasterizer(struct cso_context *ctx, - const struct pipe_rasterizer_state *templ) + const struct pipe_rasterizer_state *templ) { unsigned hash_key = cso_construct_key((void*)templ, sizeof(struct pipe_rasterizer_state)); @@ -305,11 +377,20 @@ void cso_set_rasterizer(struct cso_context *ctx, } } -void cso_unset_rasterizer(struct cso_context *ctx) +void cso_save_rasterizer(struct cso_context *ctx) { - ctx->rasterizer = NULL; + assert(!ctx->rasterizer_saved); + ctx->rasterizer_saved = ctx->rasterizer; } +void cso_restore_rasterizer(struct cso_context *ctx) +{ + if (ctx->rasterizer != ctx->rasterizer_saved) { + ctx->rasterizer = ctx->rasterizer_saved; + ctx->pipe->bind_rasterizer_state(ctx->pipe, ctx->rasterizer_saved); + } + ctx->rasterizer_saved = NULL; +} void cso_set_fragment_shader(struct cso_context *ctx, @@ -343,11 +424,23 @@ void cso_set_fragment_shader(struct cso_context *ctx, } } -void cso_unset_fragment_shader(struct cso_context *ctx) +void cso_save_fragment_shader(struct cso_context *ctx) { - ctx->fragment_shader = NULL; + assert(!ctx->fragment_shader_saved); + ctx->fragment_shader_saved = ctx->fragment_shader; } +void cso_restore_fragment_shader(struct cso_context *ctx) +{ + assert(ctx->fragment_shader_saved); + if (ctx->fragment_shader_saved != ctx->fragment_shader) { + ctx->pipe->bind_fs_state(ctx->pipe, ctx->fragment_shader_saved); + ctx->fragment_shader = ctx->fragment_shader_saved; + } + ctx->fragment_shader_saved = NULL; +} + + void cso_set_vertex_shader(struct cso_context *ctx, const struct pipe_shader_state *templ) @@ -380,7 +473,78 @@ void cso_set_vertex_shader(struct cso_context *ctx, } } -void cso_unset_vertex_shader(struct cso_context *ctx) +void cso_save_vertex_shader(struct cso_context *ctx) { - ctx->vertex_shader = NULL; + assert(!ctx->vertex_shader_saved); + ctx->vertex_shader_saved = ctx->vertex_shader; +} + +void cso_restore_vertex_shader(struct cso_context *ctx) +{ + assert(ctx->vertex_shader_saved); + if (ctx->vertex_shader_saved != ctx->vertex_shader) { + ctx->pipe->bind_fs_state(ctx->pipe, ctx->vertex_shader_saved); + ctx->vertex_shader = ctx->vertex_shader_saved; + } + ctx->vertex_shader_saved = NULL; +} + + + +void cso_set_framebuffer(struct cso_context *ctx, + const struct pipe_framebuffer_state *fb) +{ + if (memcmp(&ctx->fb, fb, sizeof(*fb))) { + ctx->fb = *fb; + ctx->pipe->set_framebuffer_state(ctx->pipe, fb); + } +} + +void cso_save_framebuffer(struct cso_context *ctx) +{ + ctx->fb_saved = ctx->fb; +} + +void cso_restore_framebuffer(struct cso_context *ctx) +{ + if (memcmp(&ctx->fb, &ctx->fb_saved, sizeof(ctx->fb))) { + ctx->fb = ctx->fb_saved; + ctx->pipe->set_framebuffer_state(ctx->pipe, &ctx->fb); + } +} + + +void cso_set_viewport(struct cso_context *ctx, + const struct pipe_viewport_state *vp) +{ + if (memcmp(&ctx->vp, vp, sizeof(*vp))) { + ctx->vp = *vp; + ctx->pipe->set_viewport_state(ctx->pipe, vp); + } +} + +void cso_save_viewport(struct cso_context *ctx) +{ + ctx->vp_saved = ctx->vp; +} + + +void cso_restore_viewport(struct cso_context *ctx) +{ + if (memcmp(&ctx->vp, &ctx->vp_saved, sizeof(ctx->vp))) { + ctx->vp = ctx->vp_saved; + ctx->pipe->set_viewport_state(ctx->pipe, &ctx->vp); + } +} + + + + +void cso_set_blend_color(struct cso_context *ctx, + const struct pipe_blend_color *bc) +{ + if (memcmp(&ctx->blend_color, bc, sizeof(ctx->blend_color))) { + ctx->blend_color = *bc; + ctx->pipe->set_blend_color(ctx->pipe, bc); + } } diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index 6aa619abf5..665e8d9911 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -41,27 +41,36 @@ struct cso_context; struct cso_context *cso_create_context( struct pipe_context *pipe ); +void cso_destroy_context( struct cso_context *cso ); + + + void cso_set_blend( struct cso_context *cso, const struct pipe_blend_state *blend ); +void cso_save_blend(struct cso_context *cso); +void cso_restore_blend(struct cso_context *cso); + -void cso_unset_blend(struct cso_context *cso); void cso_set_depth_stencil_alpha( struct cso_context *cso, const struct pipe_depth_stencil_alpha_state *dsa ); +void cso_save_depth_stencil_alpha(struct cso_context *cso); +void cso_restore_depth_stencil_alpha(struct cso_context *cso); + -void cso_unset_depth_stencil_alpha( struct cso_context *cso ); void cso_set_rasterizer( struct cso_context *cso, const struct pipe_rasterizer_state *rasterizer ); +void cso_save_rasterizer(struct cso_context *cso); +void cso_restore_rasterizer(struct cso_context *cso); + -void cso_unset_rasterizer( struct cso_context *cso ); void cso_set_samplers( struct cso_context *cso, unsigned count, const struct pipe_sampler_state **states ); - -void cso_unset_samplers( struct cso_context *cso ); - +void cso_save_samplers(struct cso_context *cso); +void cso_restore_samplers(struct cso_context *cso); /* Alternate interface to support state trackers that like to modify * samplers one at a time: @@ -73,6 +82,15 @@ void cso_single_sampler( struct cso_context *cso, void cso_single_sampler_done( struct cso_context *cso ); + +void cso_set_sampler_textures( struct cso_context *cso, + uint count, + struct pipe_texture **textures ); +void cso_save_sampler_textures( struct cso_context *cso ); +void cso_restore_sampler_textures( struct cso_context *cso ); + + + /* These aren't really sensible -- most of the time the api provides * object semantics for shaders anyway, and the cases where it doesn't * (eg mesa's internall-generated texenv programs), it will be up to @@ -80,15 +98,32 @@ void cso_single_sampler_done( struct cso_context *cso ); */ void cso_set_fragment_shader( struct cso_context *cso, const struct pipe_shader_state *shader ); +void cso_save_fragment_shader(struct cso_context *cso); +void cso_restore_fragment_shader(struct cso_context *cso); + -void cso_unset_fragment_shader( struct cso_context *cso ); void cso_set_vertex_shader( struct cso_context *cso, const struct pipe_shader_state *shader ); +void cso_save_vertex_shader(struct cso_context *cso); +void cso_restore_vertex_shader(struct cso_context *cso); -void cso_unset_vertex_shader( struct cso_context *cso ); -void cso_destroy_context( struct cso_context *cso ); + +void cso_set_framebuffer(struct cso_context *cso, + const struct pipe_framebuffer_state *fb); +void cso_save_framebuffer(struct cso_context *cso); +void cso_restore_framebuffer(struct cso_context *cso); + + +void cso_set_viewport(struct cso_context *cso, + const struct pipe_viewport_state *vp); +void cso_save_viewport(struct cso_context *cso); +void cso_restore_viewport(struct cso_context *cso); + + +void cso_set_blend_color(struct cso_context *cso, + const struct pipe_blend_color *bc); #ifdef __cplusplus diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 4b4ab8185f..123304fe68 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -45,15 +45,18 @@ #include "util/u_blit.h" #include "util/u_simple_shaders.h" +#include "cso_cache/cso_context.h" + struct blit_state { struct pipe_context *pipe; + struct cso_context *cso; - void *blend; - void *depthstencil; - void *rasterizer; - void *samplers[2]; /* one for linear, one for nearest sampling */ + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state depthstencil; + struct pipe_rasterizer_state rasterizer; + struct pipe_sampler_state sampler; /*struct pipe_viewport_state viewport;*/ struct pipe_sampler_state *vs; @@ -66,56 +69,44 @@ struct blit_state * Intended to be created once and re-used for many blit() calls. */ struct blit_state * -util_create_blit(struct pipe_context *pipe) +util_create_blit(struct pipe_context *pipe, struct cso_context *cso) { - struct pipe_blend_state blend; - struct pipe_depth_stencil_alpha_state depthstencil; - struct pipe_rasterizer_state rasterizer; struct blit_state *ctx; - struct pipe_sampler_state sampler; ctx = CALLOC_STRUCT(blit_state); if (!ctx) return NULL; ctx->pipe = pipe; + ctx->cso = cso; - /* we don't use blending, but need to set valid values */ - memset(&blend, 0, sizeof(blend)); - blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; - blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; - blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; - blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; - blend.colormask = PIPE_MASK_RGBA; - ctx->blend = pipe->create_blend_state(pipe, &blend); + /* disabled blending/masking */ + memset(&ctx->blend, 0, sizeof(ctx->blend)); + ctx->blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; + ctx->blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; + ctx->blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; + ctx->blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; + ctx->blend.colormask = PIPE_MASK_RGBA; - /* depth/stencil/alpha */ - memset(&depthstencil, 0, sizeof(depthstencil)); - ctx->depthstencil = pipe->create_depth_stencil_alpha_state(pipe, &depthstencil); + /* no-op depth/stencil/alpha */ + memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil)); /* rasterizer */ - memset(&rasterizer, 0, sizeof(rasterizer)); - rasterizer.front_winding = PIPE_WINDING_CW; - rasterizer.cull_mode = PIPE_WINDING_NONE; - rasterizer.bypass_clipping = 1; /* bypasses viewport too */ - /*rasterizer.bypass_vs = 1;*/ - ctx->rasterizer = pipe->create_rasterizer_state(pipe, &rasterizer); + memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer)); + ctx->rasterizer.front_winding = PIPE_WINDING_CW; + ctx->rasterizer.cull_mode = PIPE_WINDING_NONE; + ctx->rasterizer.bypass_clipping = 1; /* bypasses viewport too */ + /*ctx->rasterizer.bypass_vs = 1;*/ /* samplers */ - memset(&sampler, 0, sizeof(sampler)); - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; - sampler.normalized_coords = 1; - ctx->samplers[0] = pipe->create_sampler_state(pipe, &sampler); - - sampler.min_img_filter = PIPE_TEX_MIPFILTER_LINEAR; - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR; - ctx->samplers[1] = pipe->create_sampler_state(pipe, &sampler); - + memset(&ctx->sampler, 0, sizeof(ctx->sampler)); + ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + ctx->sampler.min_img_filter = 0; /* set later */ + ctx->sampler.mag_img_filter = 0; /* set later */ + ctx->sampler.normalized_coords = 1; #if 0 /* viewport */ @@ -153,12 +144,6 @@ util_destroy_blit(struct blit_state *ctx) { struct pipe_context *pipe = ctx->pipe; - pipe->delete_blend_state(pipe, ctx->blend); - pipe->delete_depth_stencil_alpha_state(pipe, ctx->depthstencil); - pipe->delete_rasterizer_state(pipe, ctx->rasterizer); - pipe->delete_sampler_state(pipe, ctx->samplers[0]); - pipe->delete_sampler_state(pipe, ctx->samplers[1]); - pipe->delete_vs_state(pipe, ctx->vs); pipe->delete_fs_state(pipe, ctx->fs); @@ -236,17 +221,24 @@ util_blit_pixels(struct blit_state *ctx, src, srcLeft, srcTop, /* src */ srcW, srcH); /* size */ - /* drawing dest */ - memset(&fb, 0, sizeof(fb)); - fb.num_cbufs = 1; - fb.cbufs[0] = dst; - pipe->set_framebuffer_state(pipe, &fb); + /* save state (restored below) */ + cso_save_blend(ctx->cso); + cso_save_depth_stencil_alpha(ctx->cso); + cso_save_rasterizer(ctx->cso); + cso_save_samplers(ctx->cso); + cso_save_sampler_textures(ctx->cso); + cso_save_framebuffer(ctx->cso); + + /* set misc state we care about */ + cso_set_blend(ctx->cso, &ctx->blend); + cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil); + cso_set_rasterizer(ctx->cso, &ctx->rasterizer); /* sampler */ - if (filter == PIPE_TEX_MIPFILTER_NEAREST) - pipe->bind_sampler_states(pipe, 1, &ctx->samplers[0]); - else - pipe->bind_sampler_states(pipe, 1, &ctx->samplers[1]); + ctx->sampler.min_img_filter = filter; + ctx->sampler.mag_img_filter = filter; + cso_single_sampler(ctx->cso, 0, &ctx->sampler); + cso_single_sampler_done(ctx->cso); /* texture */ pipe->set_sampler_textures(pipe, 1, &tex); @@ -255,22 +247,25 @@ util_blit_pixels(struct blit_state *ctx, pipe->bind_fs_state(pipe, ctx->fs); pipe->bind_vs_state(pipe, ctx->vs); - /* misc state */ - pipe->bind_blend_state(pipe, ctx->blend); - pipe->bind_depth_stencil_alpha_state(pipe, ctx->depthstencil); - pipe->bind_rasterizer_state(pipe, ctx->rasterizer); + /* drawing dest */ + memset(&fb, 0, sizeof(fb)); + fb.num_cbufs = 1; + fb.cbufs[0] = dst; + cso_set_framebuffer(ctx->cso, &fb); /* draw quad */ util_draw_texquad(pipe, dstX0, dstY0, dstX1, dstY1, z); - /* unbind */ - pipe->set_sampler_textures(pipe, 0, NULL); - pipe->bind_sampler_states(pipe, 0, NULL); + /* restore state we changed */ + cso_restore_blend(ctx->cso); + cso_restore_depth_stencil_alpha(ctx->cso); + cso_restore_rasterizer(ctx->cso); + cso_restore_samplers(ctx->cso); + cso_restore_sampler_textures(ctx->cso); + cso_restore_framebuffer(ctx->cso); - /* free stuff */ + /* free the texture */ pipe_surface_reference(&texSurf, NULL); screen->texture_release(screen, &tex); - - /* Note: caller must restore pipe/gallium state at this time */ } diff --git a/src/gallium/auxiliary/util/u_blit.h b/src/gallium/auxiliary/util/u_blit.h index a349be99ad..61f1d9bb32 100644 --- a/src/gallium/auxiliary/util/u_blit.h +++ b/src/gallium/auxiliary/util/u_blit.h @@ -30,15 +30,16 @@ #define U_BLIT_H + struct pipe_context; struct pipe_surface; +struct cso_context; struct blit_state; - extern struct blit_state * -util_create_blit(struct pipe_context *pipe); +util_create_blit(struct pipe_context *pipe, struct cso_context *cso); extern void diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index e18f8ab72a..27141c4d13 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -49,14 +49,18 @@ #include "tgsi/util/tgsi_dump.h" #include "tgsi/util/tgsi_parse.h" +#include "cso_cache/cso_context.h" + struct gen_mipmap_state { struct pipe_context *pipe; + struct cso_context *cso; - void *blend; - void *depthstencil; - void *rasterizer; + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state depthstencil; + struct pipe_rasterizer_state rasterizer; + struct pipe_sampler_state sampler; /*struct pipe_viewport_state viewport;*/ struct pipe_sampler_state *vs; struct pipe_sampler_state *fs; @@ -675,11 +679,9 @@ fallback_gen_mipmap(struct gen_mipmap_state *ctx, * generate a mipmap. */ struct gen_mipmap_state * -util_create_gen_mipmap(struct pipe_context *pipe) +util_create_gen_mipmap(struct pipe_context *pipe, + struct cso_context *cso) { - struct pipe_blend_state blend; - struct pipe_depth_stencil_alpha_state depthstencil; - struct pipe_rasterizer_state rasterizer; struct gen_mipmap_state *ctx; ctx = CALLOC_STRUCT(gen_mipmap_state); @@ -687,27 +689,36 @@ util_create_gen_mipmap(struct pipe_context *pipe) return NULL; ctx->pipe = pipe; + ctx->cso = cso; - /* we don't use blending, but need to set valid values */ - memset(&blend, 0, sizeof(blend)); - blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; - blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; - blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; - blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; - blend.colormask = PIPE_MASK_RGBA; - ctx->blend = pipe->create_blend_state(pipe, &blend); + /* disabled blending/masking */ + memset(&ctx->blend, 0, sizeof(ctx->blend)); + ctx->blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; + ctx->blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; + ctx->blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; + ctx->blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; + ctx->blend.colormask = PIPE_MASK_RGBA; - /* depth/stencil/alpha */ - memset(&depthstencil, 0, sizeof(depthstencil)); - ctx->depthstencil = pipe->create_depth_stencil_alpha_state(pipe, &depthstencil); + /* no-op depth/stencil/alpha */ + memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil)); /* rasterizer */ - memset(&rasterizer, 0, sizeof(rasterizer)); - rasterizer.front_winding = PIPE_WINDING_CW; - rasterizer.cull_mode = PIPE_WINDING_NONE; - rasterizer.bypass_clipping = 1; /* bypasses viewport too */ - //rasterizer.bypass_vs = 1; - ctx->rasterizer = pipe->create_rasterizer_state(pipe, &rasterizer); + memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer)); + ctx->rasterizer.front_winding = PIPE_WINDING_CW; + ctx->rasterizer.cull_mode = PIPE_WINDING_NONE; + ctx->rasterizer.bypass_clipping = 1; /* bypasses viewport too */ + /*ctx->rasterizer.bypass_vs = 1;*/ + + /* sampler state */ + memset(&ctx->sampler, 0, sizeof(ctx->sampler)); + ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; + ctx->sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR; + ctx->sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR; + ctx->sampler.normalized_coords = 1; + #if 0 /* viewport */ @@ -745,9 +756,6 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx) { struct pipe_context *pipe = ctx->pipe; - pipe->delete_blend_state(pipe, ctx->blend); - pipe->delete_depth_stencil_alpha_state(pipe, ctx->depthstencil); - pipe->delete_rasterizer_state(pipe, ctx->rasterizer); pipe->delete_vs_state(pipe, ctx->vs); pipe->delete_fs_state(pipe, ctx->fs); @@ -792,8 +800,6 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_framebuffer_state fb; - struct pipe_sampler_state sampler; - void *sampler_cso; uint dstLevel; uint zslice = 0; @@ -803,30 +809,29 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, return; } - /* init framebuffer state */ - memset(&fb, 0, sizeof(fb)); - fb.num_cbufs = 1; - - /* sampler state */ - memset(&sampler, 0, sizeof(sampler)); - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; - sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR; - sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR; - sampler.normalized_coords = 1; + /* save state (restored below) */ + cso_save_blend(ctx->cso); + cso_save_depth_stencil_alpha(ctx->cso); + cso_save_rasterizer(ctx->cso); + cso_save_samplers(ctx->cso); + cso_save_sampler_textures(ctx->cso); + cso_save_framebuffer(ctx->cso); /* bind our state */ - pipe->bind_blend_state(pipe, ctx->blend); - pipe->bind_depth_stencil_alpha_state(pipe, ctx->depthstencil); - pipe->bind_rasterizer_state(pipe, ctx->rasterizer); + cso_set_blend(ctx->cso, &ctx->blend); + cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil); + cso_set_rasterizer(ctx->cso, &ctx->rasterizer); + pipe->bind_vs_state(pipe, ctx->vs); pipe->bind_fs_state(pipe, ctx->fs); #if 0 pipe->set_viewport_state(pipe, &ctx->viewport); #endif + /* init framebuffer state */ + memset(&fb, 0, sizeof(fb)); + fb.num_cbufs = 1; + /* * XXX for small mipmap levels, it may be faster to use the software * fallback path... @@ -838,7 +843,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, * Setup framebuffer / dest surface */ fb.cbufs[0] = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); - pipe->set_framebuffer_state(pipe, &fb); + cso_set_framebuffer(ctx->cso, &fb); /* * Setup sampler state @@ -847,11 +852,10 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, * has trouble with min clamping so we also set the lod_bias to * try to work around that. */ - sampler.min_lod = sampler.max_lod = (float) srcLevel; - sampler.lod_bias = (float) srcLevel; - sampler_cso = pipe->create_sampler_state(pipe, &sampler); - pipe->bind_sampler_states(pipe, 1, &sampler_cso); - + ctx->sampler.min_lod = ctx->sampler.max_lod = (float) srcLevel; + ctx->sampler.lod_bias = (float) srcLevel; + cso_single_sampler(ctx->cso, 0, &ctx->sampler); + cso_single_sampler_done(ctx->cso); #if 0 simple_viewport(pipe, pt->width[dstLevel], pt->height[dstLevel]); #endif @@ -869,9 +873,13 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, pipe->flush(pipe, PIPE_FLUSH_WAIT); /*pipe->texture_update(pipe, pt); not really needed */ - - pipe->delete_sampler_state(pipe, sampler_cso); } - /* Note: caller must restore pipe/gallium state at this time */ + /* restore state we changed */ + cso_restore_blend(ctx->cso); + cso_restore_depth_stencil_alpha(ctx->cso); + cso_restore_rasterizer(ctx->cso); + cso_restore_samplers(ctx->cso); + cso_restore_sampler_textures(ctx->cso); + cso_restore_framebuffer(ctx->cso); } diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.h b/src/gallium/auxiliary/util/u_gen_mipmap.h index 80496140a2..eeabf3bf07 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.h +++ b/src/gallium/auxiliary/util/u_gen_mipmap.h @@ -31,11 +31,15 @@ #include "pipe/p_state.h" +struct pipe_context; +struct pipe_texture; +struct cso_context; + struct gen_mipmap_state; extern struct gen_mipmap_state * -util_create_gen_mipmap(struct pipe_context *pipe); +util_create_gen_mipmap(struct pipe_context *pipe, struct cso_context *cso); extern void diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c index 6c13fc8141..2a0e92245c 100644 --- a/src/mesa/state_tracker/st_atom_blend.c +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -39,6 +39,7 @@ #include "pipe/p_defines.h" #include "cso_cache/cso_context.h" +#include "main/macros.h" /** * Convert GLenum blend tokens to pipe tokens. @@ -213,13 +214,10 @@ update_blend( struct st_context *st ) cso_set_blend(st->cso_context, blend); - if (memcmp(st->ctx->Color.BlendColor, &st->state.blend_color, 4 * sizeof(GLfloat)) != 0) { - /* state has changed */ - st->state.blend_color.color[0] = st->ctx->Color.BlendColor[0]; - st->state.blend_color.color[1] = st->ctx->Color.BlendColor[1]; - st->state.blend_color.color[2] = st->ctx->Color.BlendColor[2]; - st->state.blend_color.color[3] = st->ctx->Color.BlendColor[3]; - st->pipe->set_blend_color(st->pipe, (struct pipe_blend_color *) st->ctx->Color.BlendColor); + { + struct pipe_blend_color bc; + COPY_4FV(bc.color, st->ctx->Color.BlendColor); + cso_set_blend_color(st->cso_context, &bc); } } diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index 3e58d49f1f..c8fa0cbdfb 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -35,6 +35,7 @@ #include "st_atom.h" #include "st_cb_fbo.h" #include "pipe/p_context.h" +#include "cso_cache/cso_context.h" /** @@ -76,13 +77,7 @@ update_framebuffer_state( struct st_context *st ) } } - /* XXX: The memcmp is insufficient for eliminating redundant state changes, - * but we should probably do more work here to that end. - */ - if (1 /*memcmp(&framebuffer, &st->state.framebuffer, sizeof(framebuffer)) != 0*/) { - st->state.framebuffer = framebuffer; - st->pipe->set_framebuffer_state( st->pipe, &framebuffer ); - } + cso_set_framebuffer(st->cso_context, &framebuffer); } diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c index 147aa3c51a..eb3f62cfbe 100644 --- a/src/mesa/state_tracker/st_atom_viewport.c +++ b/src/mesa/state_tracker/st_atom_viewport.c @@ -29,9 +29,9 @@ #include "context.h" #include "colormac.h" #include "st_context.h" -#include "pipe/p_context.h" #include "st_atom.h" - +#include "pipe/p_context.h" +#include "cso_cache/cso_context.h" /** * Update the viewport transformation matrix. Depends on: @@ -65,22 +65,18 @@ update_viewport( struct st_context *st ) 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 pipe_viewport_state vp; - vp.scale[0] = half_width; - vp.scale[1] = half_height * yScale; - vp.scale[2] = half_depth; - vp.scale[3] = 1.0; + st->state.viewport.scale[0] = half_width; + st->state.viewport.scale[1] = half_height * yScale; + st->state.viewport.scale[2] = half_depth; + st->state.viewport.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; + st->state.viewport.translate[0] = half_width + x; + st->state.viewport.translate[1] = (half_height + y) * yScale + yBias; + st->state.viewport.translate[2] = half_depth + z; + st->state.viewport.translate[3] = 0.0; - if (memcmp(&vp, &st->state.viewport, sizeof(vp)) != 0) { - st->state.viewport = vp; - st->pipe->set_viewport_state(st->pipe, &vp); - } + cso_set_viewport(st->cso_context, &st->state.viewport); } } diff --git a/src/mesa/state_tracker/st_cb_blit.c b/src/mesa/state_tracker/st_cb_blit.c index dfa79c975c..64314a5078 100644 --- a/src/mesa/state_tracker/st_cb_blit.c +++ b/src/mesa/state_tracker/st_cb_blit.c @@ -52,7 +52,7 @@ void st_init_blit(struct st_context *st) { - st->blit = util_create_blit(st->pipe); + st->blit = util_create_blit(st->pipe, st->cso_context); } @@ -98,22 +98,9 @@ st_BlitFramebuffer(GLcontext *ctx, } -#if 0 - /* XXX is this sufficient? */ - st_invalidate_state(ctx, _NEW_COLOR | _NEW_TEXTURE); -#else - /* need to "unset" cso state because we went behind the back of the cso - * tracker. Without unset, the _set_ calls would be no-ops. - */ - cso_unset_blend(st->cso_context); - cso_unset_depth_stencil_alpha(st->cso_context); - cso_unset_rasterizer(st->cso_context); - cso_set_blend(st->cso_context, &st->state.blend); - cso_set_depth_stencil_alpha(st->cso_context, &st->state.depth_stencil); - cso_set_rasterizer(st->cso_context, &st->state.rasterizer); + /* shaders don't go through CSO yet */ pipe->bind_fs_state(pipe, st->fp->driver_shader); pipe->bind_vs_state(pipe, st->vp->driver_shader); -#endif } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 693cddedf7..c23938dc68 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -247,10 +247,19 @@ clear_with_quad(GLcontext *ctx, x1, y1); */ + cso_save_blend(st->cso_context); + cso_save_depth_stencil_alpha(st->cso_context); + cso_save_rasterizer(st->cso_context); + cso_save_viewport(st->cso_context); + /* blend state: RGBA masking */ { struct pipe_blend_state blend; memset(&blend, 0, sizeof(blend)); + blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; + blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; if (color) { if (ctx->Color.ColorMask[0]) blend.colormask |= PIPE_MASK_R; @@ -294,13 +303,6 @@ clear_with_quad(GLcontext *ctx, { struct pipe_rasterizer_state raster; memset(&raster, 0, sizeof(raster)); -#if 0 - /* don't do per-pixel scissor; we'll just draw a PIPE_PRIM_QUAD - * that matches the scissor bounds. - */ - if (ctx->Scissor.Enabled) - raster.scissor = 1; -#endif #if TEST_DRAW_PASSTHROUGH raster.bypass_clipping = 1; raster.bypass_vs = 1; @@ -342,28 +344,21 @@ clear_with_quad(GLcontext *ctx, vp.translate[1] = 0.5 * height; vp.translate[2] = 0.0; vp.translate[3] = 0.0; - pipe->set_viewport_state(pipe, &vp); + cso_set_viewport(st->cso_context, &vp); } #endif /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); -#if 0 - /* Can't depend on old state objects still existing -- may have - * been deleted to make room in the hash, etc. (Should get - * fixed...) - */ - st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL); -#else /* Restore pipe state */ - cso_set_blend(st->cso_context, &st->state.blend); - cso_set_depth_stencil_alpha(st->cso_context, &st->state.depth_stencil); - cso_set_rasterizer(st->cso_context, &st->state.rasterizer); + cso_restore_blend(st->cso_context); + cso_restore_depth_stencil_alpha(st->cso_context); + cso_restore_rasterizer(st->cso_context); + cso_restore_viewport(st->cso_context); + /* these don't go through cso yet */ pipe->bind_fs_state(pipe, st->fp->driver_shader); pipe->bind_vs_state(pipe, st->vp->driver_shader); -#endif - pipe->set_viewport_state(pipe, &st->state.viewport); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 18ec9645c4..33d34445ee 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -650,6 +650,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, assert(width <= maxSize); assert(height <= maxSize); + cso_save_rasterizer(cso); + cso_save_viewport(cso); + /* setup state: just scissor */ { struct pipe_rasterizer_state setup; @@ -696,7 +699,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, vp.translate[1] = 0.5 * height; vp.translate[2] = 0.0; vp.translate[3] = 0.0; - pipe->set_viewport_state(pipe, &vp); + cso_set_viewport(cso, &vp); } /* texture state: */ @@ -719,26 +722,18 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, else draw_quad(ctx, x0, y0, z, x1, y1, invertTex); - /* restore GL state */ - pipe->set_sampler_textures(pipe, ctx->st->state.num_textures, - ctx->st->state.sampler_texture); - - pipe->set_viewport_state(pipe, &ctx->st->state.viewport); - -#if 0 - /* Can't depend on old state objects still existing -- may have - * been deleted to make room in the hash, etc. (Should get - * fixed...) - */ - st_invalidate_state(ctx, _NEW_COLOR | _NEW_TEXTURE); -#else /* restore state */ + cso_restore_rasterizer(cso); + cso_restore_viewport(cso); + /* shaders don't go through cso yet */ pipe->bind_fs_state(pipe, st->fp->driver_shader); pipe->bind_vs_state(pipe, st->vp->driver_shader); + cso_set_rasterizer(cso, &st->state.rasterizer); cso_set_samplers(cso, PIPE_MAX_SAMPLERS, (const struct pipe_sampler_state **) st->state.sampler_list); -#endif + pipe->set_sampler_textures(pipe, ctx->st->state.num_textures, + ctx->st->state.sampler_texture); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 63150dbeaf..ca8307c4ba 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -82,7 +82,6 @@ struct st_context struct pipe_rasterizer_state rasterizer; struct pipe_sampler_state samplers[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state *sampler_list[PIPE_MAX_SAMPLERS]; - struct pipe_blend_color blend_color; struct pipe_clip_state clip; struct pipe_constant_buffer constants[2]; struct pipe_framebuffer_state framebuffer; diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 6c3afca1ba..61e1d9621c 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -59,7 +59,7 @@ void st_init_generate_mipmap(struct st_context *st) { - st->gen_mipmap = util_create_gen_mipmap(st->pipe); + st->gen_mipmap = util_create_gen_mipmap(st->pipe, st->cso_context); } @@ -94,19 +94,11 @@ st_render_mipmap(struct st_context *st, util_gen_mipmap(st->gen_mipmap, pt, face, baseLevel, lastLevel); - /* restore pipe state */ -#if 0 - cso_set_rasterizer(st->cso_context, &st->state.rasterizer); - cso_set_samplers(st->cso_context, st->state.samplers_list); - pipe->bind_fs_state(pipe, st->fp->shader_program); - pipe->bind_vs_state(pipe, st->vp->shader_program); - pipe->set_sampler_textures(pipe, st->state.num_textures, - st->state.sampler_texture); - pipe->set_viewport_state(pipe, &st->state.viewport); -#else - /* XXX is this sufficient? */ - st_invalidate_state(st->ctx, _NEW_COLOR | _NEW_TEXTURE); -#endif + /* shaders don't go through CSO yet */ + if (st->fp) + pipe->bind_fs_state(pipe, st->fp->driver_shader); + if (st->vp) + pipe->bind_vs_state(pipe, st->vp->driver_shader); return TRUE; } -- cgit v1.2.3 From 85e4ec6d118e340eaccd176aa622221642a2e754 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 20 Mar 2008 09:13:51 -0600 Subject: gallium: use the utility pasthrough shaders This avoids the Mesa->TGSI translation step. --- src/mesa/state_tracker/st_cb_clear.c | 137 +++++++---------------------------- src/mesa/state_tracker/st_cb_clear.h | 4 + src/mesa/state_tracker/st_context.c | 1 + src/mesa/state_tracker/st_context.h | 7 ++ 4 files changed, 39 insertions(+), 110 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index c23938dc68..8cc02f63bb 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -49,6 +49,7 @@ #include "pipe/p_defines.h" #include "pipe/p_winsys.h" #include "util/u_pack_color.h" +#include "util/u_simple_shaders.h" #include "cso_cache/cso_context.h" @@ -57,6 +58,20 @@ #define TEST_DRAW_PASSTHROUGH 0 +void +st_destroy_clear(struct st_context *st) +{ + if (st->clear.fs) { + st->pipe->delete_fs_state(st->pipe, st->clear.fs); + st->clear.fs = NULL; + } + if (st->clear.vs) { + st->pipe->delete_vs_state(st->pipe, st->clear.vs); + st->clear.vs = NULL; + } +} + + static GLboolean is_depth_stencil_format(enum pipe_format pipeFormat) { @@ -71,104 +86,6 @@ is_depth_stencil_format(enum pipe_format pipeFormat) -/** - * Create a simple fragment shader that just passes through the fragment color. - */ -static struct st_fragment_program * -make_frag_shader(struct st_context *st) -{ - GLcontext *ctx = st->ctx; - struct st_fragment_program *stfp; - struct gl_program *p; - GLuint interpMode[16]; - GLuint i; - - /* XXX temporary */ - for (i = 0; i < 16; i++) - interpMode[i] = TGSI_INTERPOLATE_LINEAR; - - p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); - if (!p) - return NULL; - - p->NumInstructions = 2; - p->Instructions = _mesa_alloc_instructions(2); - if (!p->Instructions) { - ctx->Driver.DeleteProgram(ctx, p); - return NULL; - } - _mesa_init_instructions(p->Instructions, 2); - /* MOV result.color, fragment.color; */ - p->Instructions[0].Opcode = OPCODE_MOV; - p->Instructions[0].DstReg.File = PROGRAM_OUTPUT; - p->Instructions[0].DstReg.Index = FRAG_RESULT_COLR; - p->Instructions[0].SrcReg[0].File = PROGRAM_INPUT; - p->Instructions[0].SrcReg[0].Index = FRAG_ATTRIB_COL0; - /* END; */ - p->Instructions[1].Opcode = OPCODE_END; - - p->InputsRead = FRAG_BIT_COL0; - p->OutputsWritten = (1 << FRAG_RESULT_COLR); - - stfp = (struct st_fragment_program *) p; - st_translate_fragment_program(st, stfp, NULL); - - return stfp; -} - - -/** - * Create a simple vertex shader that just passes through the - * vertex position and color. - */ -static struct st_vertex_program * -make_vertex_shader(struct st_context *st) -{ - GLcontext *ctx = st->ctx; - struct st_vertex_program *stvp; - struct gl_program *p; - - p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); - if (!p) - return NULL; - - p->NumInstructions = 3; - p->Instructions = _mesa_alloc_instructions(3); - if (!p->Instructions) { - ctx->Driver.DeleteProgram(ctx, p); - return NULL; - } - _mesa_init_instructions(p->Instructions, 3); - /* MOV result.pos, vertex.pos; */ - p->Instructions[0].Opcode = OPCODE_MOV; - p->Instructions[0].DstReg.File = PROGRAM_OUTPUT; - p->Instructions[0].DstReg.Index = VERT_RESULT_HPOS; - p->Instructions[0].SrcReg[0].File = PROGRAM_INPUT; - p->Instructions[0].SrcReg[0].Index = VERT_ATTRIB_POS; - /* MOV result.color, vertex.color; */ - p->Instructions[1].Opcode = OPCODE_MOV; - p->Instructions[1].DstReg.File = PROGRAM_OUTPUT; - p->Instructions[1].DstReg.Index = VERT_RESULT_COL0; - p->Instructions[1].SrcReg[0].File = PROGRAM_INPUT; - p->Instructions[1].SrcReg[0].Index = VERT_ATTRIB_COLOR0; - /* END; */ - p->Instructions[2].Opcode = OPCODE_END; - - p->InputsRead = VERT_BIT_POS | VERT_BIT_COLOR0; - p->OutputsWritten = ((1 << VERT_RESULT_COL0) | - (1 << VERT_RESULT_HPOS)); - - stvp = (struct st_vertex_program *) p; - st_translate_vertex_program(st, stvp, NULL); -#if 0 - assert(stvp->cso); -#endif - - return stvp; -} - - - /** * Draw a screen-aligned quadrilateral. * Coords are window coords with y=0=bottom. These coords will be transformed @@ -311,23 +228,23 @@ clear_with_quad(GLcontext *ctx, } /* fragment shader state: color pass-through program */ - { - static struct st_fragment_program *stfp = NULL; - if (!stfp) { - stfp = make_frag_shader(st); - } - pipe->bind_fs_state(pipe, stfp->driver_shader); + if (!st->clear.fs) { + st->clear.fs = util_make_fragment_passthrough_shader(pipe); } + pipe->bind_fs_state(pipe, st->clear.fs); + #if !TEST_DRAW_PASSTHROUGH /* vertex shader state: color/position pass-through */ - { - static struct st_vertex_program *stvp = NULL; - if (!stvp) { - stvp = make_vertex_shader(st); - } - pipe->bind_vs_state(pipe, stvp->driver_shader); + if (!st->clear.vs) { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_COLOR }; + const uint semantic_indexes[] = { 0, 0 }; + st->clear.vs = util_make_vertex_passthrough_shader(pipe, 2, + semantic_names, + semantic_indexes); } + pipe->bind_vs_state(pipe, st->clear.vs); #endif #if !TEST_DRAW_PASSTHROUGH diff --git a/src/mesa/state_tracker/st_cb_clear.h b/src/mesa/state_tracker/st_cb_clear.h index c715e56bd5..dfa4033faa 100644 --- a/src/mesa/state_tracker/st_cb_clear.h +++ b/src/mesa/state_tracker/st_cb_clear.h @@ -30,6 +30,10 @@ #define ST_CB_CLEAR_H +extern void +st_destroy_clear(struct st_context *st); + + extern void st_init_clear_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index e1fc885e0e..b1681be2eb 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -155,6 +155,7 @@ static void st_destroy_context_priv( struct st_context *st ) st_destroy_draw( st ); st_destroy_generate_mipmap(st); st_destroy_blit(st); + st_destroy_clear(st); _vbo_DestroyContext(st->ctx); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index ca8307c4ba..8058086d87 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -142,12 +142,19 @@ struct st_context GLuint combined_prog_sn; } pixel_xfer; + /** for glBitmap */ struct { struct st_fragment_program *program; /**< bitmap tex/kil program */ GLuint user_prog_sn; /**< user fragment program serial no. */ struct st_fragment_program *combined_prog; } bitmap; + /** for glClear */ + struct { + void *vs; + void *fs; + } clear; + struct gen_mipmap_state *gen_mipmap; struct blit_state *blit; -- cgit v1.2.3 From e1406c8d2366dccac0037e5329217d1c8c265eaf Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 20 Mar 2008 10:46:44 -0600 Subject: gallium: create one vertex buffer and re-use, also enable bypass_clipping Quad clears should be a little more efficient now. --- src/mesa/state_tracker/st_cb_clear.c | 76 +++++++++++++++++++++--------------- src/mesa/state_tracker/st_context.h | 2 + 2 files changed, 47 insertions(+), 31 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 8cc02f63bb..dc0d87acd3 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -50,25 +50,33 @@ #include "pipe/p_winsys.h" #include "util/u_pack_color.h" #include "util/u_simple_shaders.h" +#include "util/u_draw_quad.h" #include "cso_cache/cso_context.h" /* XXX for testing draw module vertex passthrough: */ +/* XXX this hack is broken now */ #define TEST_DRAW_PASSTHROUGH 0 void st_destroy_clear(struct st_context *st) { + struct pipe_context *pipe = st->pipe; + if (st->clear.fs) { - st->pipe->delete_fs_state(st->pipe, st->clear.fs); + pipe->delete_fs_state(pipe, st->clear.fs); st->clear.fs = NULL; } if (st->clear.vs) { - st->pipe->delete_vs_state(st->pipe, st->clear.vs); + pipe->delete_vs_state(pipe, st->clear.vs); st->clear.vs = NULL; } + if (st->clear.vbuf) { + pipe->winsys->buffer_destroy(pipe->winsys, st->clear.vbuf); + st->clear.vbuf = NULL; + } } @@ -96,45 +104,51 @@ draw_quad(GLcontext *ctx, float x0, float y0, float x1, float y1, GLfloat z, const GLfloat color[4]) { - GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */ + struct st_context *st = ctx->st; + struct pipe_context *pipe = st->pipe; GLuint i; + void *buf; -#if TEST_DRAW_PASSTHROUGH - /* invert Y coords (may be off by one pixel) */ - y0 = ctx->DrawBuffer->Height - y0; - y1 = ctx->DrawBuffer->Height - y1; -#endif + if (!st->clear.vbuf) { + st->clear.vbuf = pipe->winsys->buffer_create(pipe->winsys, 32, + PIPE_BUFFER_USAGE_VERTEX, + sizeof(st->clear.vertices)); + } /* positions */ - verts[0][0][0] = x0; - verts[0][0][1] = y0; + st->clear.vertices[0][0][0] = x0; + st->clear.vertices[0][0][1] = y0; - verts[1][0][0] = x1; - verts[1][0][1] = y0; + st->clear.vertices[1][0][0] = x1; + st->clear.vertices[1][0][1] = y0; - verts[2][0][0] = x1; - verts[2][0][1] = y1; + st->clear.vertices[2][0][0] = x1; + st->clear.vertices[2][0][1] = y1; - verts[3][0][0] = x0; - verts[3][0][1] = y1; + st->clear.vertices[3][0][0] = x0; + st->clear.vertices[3][0][1] = y1; /* same for all verts: */ for (i = 0; i < 4; i++) { - verts[i][0][2] = z; - verts[i][0][3] = 1.0; - verts[i][1][0] = color[0]; - verts[i][1][1] = color[1]; - verts[i][1][2] = color[2]; - verts[i][1][3] = color[3]; + st->clear.vertices[i][0][2] = z; + st->clear.vertices[i][0][3] = 1.0; + st->clear.vertices[i][1][0] = color[0]; + st->clear.vertices[i][1][1] = color[1]; + st->clear.vertices[i][1][2] = color[2]; + st->clear.vertices[i][1][3] = color[3]; } - st_draw_vertices(ctx, PIPE_PRIM_POLYGON, 4, (float *) verts, 2, -#if TEST_DRAW_PASSTHROUGH - GL_TRUE -#else - GL_FALSE -#endif - ); + /* put vertex data into vbuf */ + buf = pipe->winsys->buffer_map(pipe->winsys, st->clear.vbuf, + PIPE_BUFFER_USAGE_CPU_WRITE); + memcpy(buf, st->clear.vertices, sizeof(st->clear.vertices)); + pipe->winsys->buffer_unmap(pipe->winsys, st->clear.vbuf); + + /* draw */ + util_draw_vertex_buffer(pipe, st->clear.vbuf, + PIPE_PRIM_TRIANGLE_FAN, + 4, /* verts */ + 2); /* attribs/vert */ } @@ -216,12 +230,12 @@ clear_with_quad(GLcontext *ctx, cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil); } - /* rasterizer state: nothing */ + /* rasterizer state: bypass clipping */ { struct pipe_rasterizer_state raster; memset(&raster, 0, sizeof(raster)); -#if TEST_DRAW_PASSTHROUGH raster.bypass_clipping = 1; +#if TEST_DRAW_PASSTHROUGH raster.bypass_vs = 1; #endif cso_set_rasterizer(st->cso_context, &raster); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 8058086d87..2563c7fed0 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -153,6 +153,8 @@ struct st_context struct { void *vs; void *fs; + float vertices[4][2][4]; /**< vertex pos + color */ + struct pipe_buffer *vbuf; } clear; struct gen_mipmap_state *gen_mipmap; -- cgit v1.2.3 From c2044eaca96abfae153651ec609b5af2fd0b6fb0 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 20 Mar 2008 14:17:06 -0600 Subject: gallium: in clear_with_quad() check fb orientation, invert Y if needed --- src/mesa/state_tracker/st_cb_clear.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index dc0d87acd3..5ca15df602 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -165,9 +165,17 @@ clear_with_quad(GLcontext *ctx, struct st_context *st = ctx->st; struct pipe_context *pipe = st->pipe; const GLfloat x0 = ctx->DrawBuffer->_Xmin; - const GLfloat y0 = ctx->DrawBuffer->_Ymin; const GLfloat x1 = ctx->DrawBuffer->_Xmax; - const GLfloat y1 = ctx->DrawBuffer->_Ymax; + GLfloat y0, y1; + + if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { + y0 = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymax; + y1 = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymin; + } + else { + y0 = ctx->DrawBuffer->_Ymin; + y1 = ctx->DrawBuffer->_Ymax; + } /* printf("%s %s%s%s %f,%f %f,%f\n", __FUNCTION__, -- cgit v1.2.3 From 6f8286163c79a8187c2912a9b673a6f11f4f60c6 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 27 Mar 2008 15:42:52 -0600 Subject: gallium: Update calls to the simple shader functions --- src/mesa/state_tracker/st_cb_bitmap.c | 4 +++- src/mesa/state_tracker/st_cb_clear.c | 5 +++-- src/mesa/state_tracker/st_context.h | 3 +++ 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 0291b03143..64b1882424 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -487,13 +487,15 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const uint semantic_indexes[] = { 0, 0, 0 }; st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, semantic_names, - semantic_indexes); + semantic_indexes, + &st->bitmap.vert_shader); } st_validate_state(st); pt = make_bitmap_texture(ctx, width, height, unpack, bitmap); if (pt) { + assert(pt->target == PIPE_TEXTURE_2D); draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2], width, height, pt, stfp); diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 5ca15df602..ec8d3e1022 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -251,7 +251,7 @@ clear_with_quad(GLcontext *ctx, /* fragment shader state: color pass-through program */ if (!st->clear.fs) { - st->clear.fs = util_make_fragment_passthrough_shader(pipe); + st->clear.fs = util_make_fragment_passthrough_shader(pipe, &st->clear.frag_shader); } pipe->bind_fs_state(pipe, st->clear.fs); @@ -264,7 +264,8 @@ clear_with_quad(GLcontext *ctx, const uint semantic_indexes[] = { 0, 0 }; st->clear.vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names, - semantic_indexes); + semantic_indexes, + &st->clear.vert_shader); } pipe->bind_vs_state(pipe, st->clear.vs); #endif diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 2d37086799..f235c194b7 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -147,6 +147,7 @@ struct st_context struct st_fragment_program *program; /**< bitmap tex/kil program */ GLuint user_prog_sn; /**< user fragment program serial no. */ struct st_fragment_program *combined_prog; + struct pipe_shader_state vert_shader; void *vs; float vertices[4][3][4]; /**< vertex pos + color + texcoord */ struct pipe_buffer *vbuf; @@ -154,6 +155,8 @@ struct st_context /** for glClear */ struct { + struct pipe_shader_state vert_shader; + struct pipe_shader_state frag_shader; void *vs; void *fs; float vertices[4][2][4]; /**< vertex pos + color */ -- cgit v1.2.3 From 4f67a3f7d3bdeaa8d16d877ce9b277c97bd2f6b4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 3 Apr 2008 12:42:26 -0600 Subject: gallium: use identity viewport fix broken clear_with_quad() path Since bypass_clipping is set and we're specifying quad vertexes in window coords, setup identity viewport. --- src/mesa/state_tracker/st_cb_clear.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index ec8d3e1022..0c6f77bc82 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -271,17 +271,15 @@ clear_with_quad(GLcontext *ctx, #endif #if !TEST_DRAW_PASSTHROUGH - /* viewport state: viewport matching window dims */ + /* viewport state: identity since we're drawing in window coords */ { - const float width = ctx->DrawBuffer->Width; - const float height = ctx->DrawBuffer->Height; struct pipe_viewport_state vp; - vp.scale[0] = 0.5 * width; - vp.scale[1] = -0.5 * height; + vp.scale[0] = 1.0; + vp.scale[1] = 1.0; vp.scale[2] = 1.0; vp.scale[3] = 1.0; - vp.translate[0] = 0.5 * width; - vp.translate[1] = 0.5 * height; + vp.translate[0] = 0.0; + vp.translate[1] = 0.0; vp.translate[2] = 0.0; vp.translate[3] = 0.0; cso_set_viewport(st->cso_context, &vp); -- cgit v1.2.3 From c4f8c8b304a47b2490fe5b1d133e314b045854df Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 3 Apr 2008 12:44:58 -0600 Subject: gallium: remove the temporary/test TEST_DRAW_PASSTHROUGH code --- src/mesa/state_tracker/st_cb_clear.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 0c6f77bc82..041b9be2cc 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -55,11 +55,6 @@ #include "cso_cache/cso_context.h" -/* XXX for testing draw module vertex passthrough: */ -/* XXX this hack is broken now */ -#define TEST_DRAW_PASSTHROUGH 0 - - void st_destroy_clear(struct st_context *st) { @@ -243,9 +238,6 @@ clear_with_quad(GLcontext *ctx, struct pipe_rasterizer_state raster; memset(&raster, 0, sizeof(raster)); raster.bypass_clipping = 1; -#if TEST_DRAW_PASSTHROUGH - raster.bypass_vs = 1; -#endif cso_set_rasterizer(st->cso_context, &raster); } @@ -256,7 +248,6 @@ clear_with_quad(GLcontext *ctx, pipe->bind_fs_state(pipe, st->clear.fs); -#if !TEST_DRAW_PASSTHROUGH /* vertex shader state: color/position pass-through */ if (!st->clear.vs) { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, @@ -268,9 +259,7 @@ clear_with_quad(GLcontext *ctx, &st->clear.vert_shader); } pipe->bind_vs_state(pipe, st->clear.vs); -#endif -#if !TEST_DRAW_PASSTHROUGH /* viewport state: identity since we're drawing in window coords */ { struct pipe_viewport_state vp; @@ -284,7 +273,6 @@ clear_with_quad(GLcontext *ctx, vp.translate[3] = 0.0; cso_set_viewport(st->cso_context, &vp); } -#endif /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); -- cgit v1.2.3 From ce5c867cbb17b2444ebc3db5c6a03cee5e2edb8a Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 3 Apr 2008 12:54:32 -0600 Subject: gallium: streamline viewport/raster/shader state for clearing with quads Move init of these items to new st_init_clear(). --- src/mesa/state_tracker/st_cb_clear.c | 75 ++++++++++++++++++------------------ src/mesa/state_tracker/st_cb_clear.h | 4 ++ src/mesa/state_tracker/st_context.c | 1 + src/mesa/state_tracker/st_context.h | 2 + 4 files changed, 45 insertions(+), 37 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 041b9be2cc..b5e737e0d1 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -55,6 +55,42 @@ #include "cso_cache/cso_context.h" +void +st_init_clear(struct st_context *st) +{ + struct pipe_context *pipe = st->pipe; + + /* rasterizer state: bypass clipping */ + memset(&st->clear.raster, 0, sizeof(st->clear.raster)); + st->clear.raster.bypass_clipping = 1; + + /* viewport state: identity since we're drawing in window coords */ + st->clear.viewport.scale[0] = 1.0; + st->clear.viewport.scale[1] = 1.0; + st->clear.viewport.scale[2] = 1.0; + st->clear.viewport.scale[3] = 1.0; + st->clear.viewport.translate[0] = 0.0; + st->clear.viewport.translate[1] = 0.0; + st->clear.viewport.translate[2] = 0.0; + st->clear.viewport.translate[3] = 0.0; + + /* fragment shader state: color pass-through program */ + st->clear.fs = + util_make_fragment_passthrough_shader(pipe, &st->clear.frag_shader); + + /* vertex shader state: color/position pass-through */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_COLOR }; + const uint semantic_indexes[] = { 0, 0 }; + st->clear.vs = util_make_vertex_passthrough_shader(pipe, 2, + semantic_names, + semantic_indexes, + &st->clear.vert_shader); + } +} + + void st_destroy_clear(struct st_context *st) { @@ -233,47 +269,12 @@ clear_with_quad(GLcontext *ctx, cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil); } - /* rasterizer state: bypass clipping */ - { - struct pipe_rasterizer_state raster; - memset(&raster, 0, sizeof(raster)); - raster.bypass_clipping = 1; - cso_set_rasterizer(st->cso_context, &raster); - } + cso_set_rasterizer(st->cso_context, &st->clear.raster); + cso_set_viewport(st->cso_context, &st->clear.viewport); - /* fragment shader state: color pass-through program */ - if (!st->clear.fs) { - st->clear.fs = util_make_fragment_passthrough_shader(pipe, &st->clear.frag_shader); - } pipe->bind_fs_state(pipe, st->clear.fs); - - - /* vertex shader state: color/position pass-through */ - if (!st->clear.vs) { - const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, - TGSI_SEMANTIC_COLOR }; - const uint semantic_indexes[] = { 0, 0 }; - st->clear.vs = util_make_vertex_passthrough_shader(pipe, 2, - semantic_names, - semantic_indexes, - &st->clear.vert_shader); - } pipe->bind_vs_state(pipe, st->clear.vs); - /* viewport state: identity since we're drawing in window coords */ - { - struct pipe_viewport_state vp; - vp.scale[0] = 1.0; - vp.scale[1] = 1.0; - vp.scale[2] = 1.0; - vp.scale[3] = 1.0; - vp.translate[0] = 0.0; - vp.translate[1] = 0.0; - vp.translate[2] = 0.0; - vp.translate[3] = 0.0; - cso_set_viewport(st->cso_context, &vp); - } - /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); diff --git a/src/mesa/state_tracker/st_cb_clear.h b/src/mesa/state_tracker/st_cb_clear.h index dfa4033faa..f49387747d 100644 --- a/src/mesa/state_tracker/st_cb_clear.h +++ b/src/mesa/state_tracker/st_cb_clear.h @@ -30,6 +30,10 @@ #define ST_CB_CLEAR_H +extern void +st_init_clear(struct st_context *st); + + extern void st_destroy_clear(struct st_context *st); diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index a20195f2de..7511c28074 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -110,6 +110,7 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st_init_atoms( st ); st_init_bitmap(st); + st_init_clear(st); st_init_draw( st ); st_init_generate_mipmap(st); st_init_blit(st); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 44705bc89a..bcebbd4943 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -161,6 +161,8 @@ struct st_context struct { struct pipe_shader_state vert_shader; struct pipe_shader_state frag_shader; + struct pipe_rasterizer_state raster; + struct pipe_viewport_state viewport; void *vs; void *fs; float vertices[4][2][4]; /**< vertex pos + color */ -- cgit v1.2.3 From 124e1345c9ba4abe17bb04b8781ec0fe803eda7b Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 3 Apr 2008 13:16:37 -0600 Subject: gallium: set rasterizer.gl_rasterization_rules = 1 in a few more places --- src/mesa/state_tracker/st_cb_bitmap.c | 1 + src/mesa/state_tracker/st_cb_clear.c | 1 + 2 files changed, 2 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 975a55d6dc..0872f2bd28 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -754,6 +754,7 @@ st_init_bitmap(struct st_context *st) /* init baseline rasterizer state once */ memset(&st->bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer)); + st->bitmap.rasterizer.gl_rasterization_rules = 1; st->bitmap.rasterizer.bypass_vs = 1; init_bitmap_cache(st); diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index b5e737e0d1..fa9f986f11 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -62,6 +62,7 @@ st_init_clear(struct st_context *st) /* rasterizer state: bypass clipping */ memset(&st->clear.raster, 0, sizeof(st->clear.raster)); + st->clear.raster.gl_rasterization_rules = 1; st->clear.raster.bypass_clipping = 1; /* viewport state: identity since we're drawing in window coords */ -- cgit v1.2.3 From 073d9a28c2dc955956c940be6fcc4b3ab354cc6c Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Fri, 18 Apr 2008 13:38:06 +0100 Subject: gallium: Always pass colour clear value to driver as A8R8G8B8. --- src/mesa/state_tracker/st_cb_clear.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index fa9f986f11..6469511c6f 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -406,7 +406,7 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) /* clear whole buffer w/out masking */ struct st_renderbuffer *strb = st_renderbuffer(rb); uint clearValue; - util_pack_color(ctx->Color.ClearColor, strb->surface->format, &clearValue); + util_pack_color(ctx->Color.ClearColor, PIPE_FORMAT_A8R8G8B8_UNORM, &clearValue); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } } -- cgit v1.2.3 From 65efe807b9067aa07b382e3c4d9cea6222c5fc6b Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Mon, 21 Apr 2008 17:51:39 +0100 Subject: gallium: Use CSO cache for shaders. --- src/mesa/state_tracker/st_atom_shader.c | 4 ++-- src/mesa/state_tracker/st_cb_bitmap.c | 11 ++++++----- src/mesa/state_tracker/st_cb_blit.c | 5 ----- src/mesa/state_tracker/st_cb_clear.c | 12 ++++++------ src/mesa/state_tracker/st_cb_drawpixels.c | 12 ++++++------ src/mesa/state_tracker/st_gen_mipmap.c | 6 ------ 6 files changed, 20 insertions(+), 30 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index ec39026eb3..4a641a4a73 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -273,8 +273,8 @@ update_linkage( struct st_context *st ) st->vp = stvp; st->fp = stfp; - st->pipe->bind_vs_state(st->pipe, stvp->driver_shader); - st->pipe->bind_fs_state(st->pipe, stfp->driver_shader); + cso_set_vertex_shader(st->cso_context, stvp->driver_shader); + cso_set_fragment_shader(st->cso_context, stfp->driver_shader); st->vertex_result_to_slot = xvp->output_to_slot; } diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 505a13cc2b..1b863143e0 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -438,16 +438,18 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_save_samplers(cso); cso_save_sampler_textures(cso); cso_save_viewport(cso); + cso_save_fragment_shader(cso); + cso_save_vertex_shader(cso); /* rasterizer state: just scissor */ st->bitmap.rasterizer.scissor = ctx->Scissor.Enabled; cso_set_rasterizer(cso, &st->bitmap.rasterizer); /* fragment shader state: TEX lookup program */ - pipe->bind_fs_state(pipe, stfp->driver_shader); + cso_set_fragment_shader(cso, stfp->driver_shader); /* vertex shader state: position + texcoord pass-through */ - pipe->bind_vs_state(pipe, st->bitmap.vs); + cso_set_vertex_shader(cso, st->bitmap.vs); /* sampler / texture state */ cso_single_sampler(cso, 0, &st->bitmap.sampler); @@ -488,9 +490,8 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_restore_samplers(cso); cso_restore_sampler_textures(cso); cso_restore_viewport(cso); - /* shaders don't go through cso yet */ - pipe->bind_fs_state(pipe, st->fp->driver_shader); - pipe->bind_vs_state(pipe, st->vp->driver_shader); + cso_save_fragment_shader(cso); + cso_save_vertex_shader(cso); } diff --git a/src/mesa/state_tracker/st_cb_blit.c b/src/mesa/state_tracker/st_cb_blit.c index 63211d8b66..0533d9460f 100644 --- a/src/mesa/state_tracker/st_cb_blit.c +++ b/src/mesa/state_tracker/st_cb_blit.c @@ -71,7 +71,6 @@ st_BlitFramebuffer(GLcontext *ctx, GLbitfield mask, GLenum filter) { struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; const uint pFilter = ((filter == GL_NEAREST) ? PIPE_TEX_MIPFILTER_NEAREST @@ -100,10 +99,6 @@ st_BlitFramebuffer(GLcontext *ctx, 0.0, pFilter); } - - /* shaders don't go through CSO yet */ - pipe->bind_fs_state(pipe, st->fp->driver_shader); - pipe->bind_vs_state(pipe, st->vp->driver_shader); } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 6469511c6f..bb27faad21 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -195,7 +195,6 @@ clear_with_quad(GLcontext *ctx, GLboolean color, GLboolean depth, GLboolean stencil) { struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; const GLfloat x0 = ctx->DrawBuffer->_Xmin; const GLfloat x1 = ctx->DrawBuffer->_Xmax; GLfloat y0, y1; @@ -222,6 +221,8 @@ clear_with_quad(GLcontext *ctx, cso_save_depth_stencil_alpha(st->cso_context); cso_save_rasterizer(st->cso_context); cso_save_viewport(st->cso_context); + cso_save_fragment_shader(st->cso_context); + cso_save_vertex_shader(st->cso_context); /* blend state: RGBA masking */ { @@ -273,8 +274,8 @@ clear_with_quad(GLcontext *ctx, cso_set_rasterizer(st->cso_context, &st->clear.raster); cso_set_viewport(st->cso_context, &st->clear.viewport); - pipe->bind_fs_state(pipe, st->clear.fs); - pipe->bind_vs_state(pipe, st->clear.vs); + cso_set_fragment_shader(st->cso_context, st->clear.fs); + cso_set_vertex_shader(st->cso_context, st->clear.vs); /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); @@ -284,9 +285,8 @@ clear_with_quad(GLcontext *ctx, cso_restore_depth_stencil_alpha(st->cso_context); cso_restore_rasterizer(st->cso_context); cso_restore_viewport(st->cso_context); - /* these don't go through cso yet */ - pipe->bind_fs_state(pipe, st->fp->driver_shader); - pipe->bind_vs_state(pipe, st->vp->driver_shader); + cso_restore_fragment_shader(st->cso_context); + cso_restore_vertex_shader(st->cso_context); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 5fb27857a7..75261c3350 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -532,6 +532,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_save_viewport(cso); cso_save_samplers(cso); cso_save_sampler_textures(cso); + cso_save_fragment_shader(cso); + cso_save_vertex_shader(cso); /* rasterizer state: just scissor */ { @@ -543,10 +545,10 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, } /* fragment shader state: TEX lookup program */ - pipe->bind_fs_state(pipe, stfp->driver_shader); + cso_set_fragment_shader(cso, stfp->driver_shader); /* vertex shader state: position + texcoord pass-through */ - pipe->bind_vs_state(pipe, stvp->driver_shader); + cso_set_vertex_shader(cso, stvp->driver_shader); /* texture sampling state: */ @@ -615,10 +617,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_restore_viewport(cso); cso_restore_samplers(cso); cso_restore_sampler_textures(cso); - - /* shaders don't go through cso yet */ - pipe->bind_fs_state(pipe, st->fp->driver_shader); - pipe->bind_vs_state(pipe, st->vp->driver_shader); + cso_restore_fragment_shader(cso); + cso_restore_vertex_shader(cso); } diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index a931911227..da9ec12a4d 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -95,12 +95,6 @@ st_render_mipmap(struct st_context *st, util_gen_mipmap(st->gen_mipmap, pt, face, baseLevel, lastLevel, PIPE_TEX_FILTER_LINEAR); - /* shaders don't go through CSO yet */ - if (st->fp) - pipe->bind_fs_state(pipe, st->fp->driver_shader); - if (st->vp) - pipe->bind_vs_state(pipe, st->vp->driver_shader); - return TRUE; } -- cgit v1.2.3 From 01dfa6cde157321f565bab949f23f367ed20fa0e Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 21 Apr 2008 20:26:19 +0100 Subject: use cso fs/vs handle functions --- src/gallium/auxiliary/util/u_blit.c | 4 ++-- src/gallium/auxiliary/util/u_gen_mipmap.c | 4 ++-- src/mesa/state_tracker/st_atom_shader.c | 4 ++-- src/mesa/state_tracker/st_cb_bitmap.c | 4 ++-- src/mesa/state_tracker/st_cb_clear.c | 4 ++-- src/mesa/state_tracker/st_cb_drawpixels.c | 4 ++-- src/mesa/state_tracker/st_program.h | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index be5e83e834..0938b03820 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -318,8 +318,8 @@ util_blit_pixels(struct blit_state *ctx, cso_set_sampler_textures(ctx->cso, 1, &tex); /* shaders */ - cso_set_fragment_shader(ctx->cso, ctx->fs); - cso_set_vertex_shader(ctx->cso, ctx->vs); + cso_set_fragment_shader_handle(ctx->cso, ctx->fs); + cso_set_vertex_shader_handle(ctx->cso, ctx->vs); /* drawing dest */ memset(&fb, 0, sizeof(fb)); diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index f0c4063b28..9822a25ca6 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -888,8 +888,8 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil); cso_set_rasterizer(ctx->cso, &ctx->rasterizer); - cso_set_fragment_shader(ctx->cso, ctx->fs); - cso_set_vertex_shader(ctx->cso, ctx->vs); + cso_set_fragment_shader_handle(ctx->cso, ctx->fs); + cso_set_vertex_shader_handle(ctx->cso, ctx->vs); #if 0 cso_set_viewport(ctx->cso, &ctx->viewport); #endif diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 4a641a4a73..3f5ec71112 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -273,8 +273,8 @@ update_linkage( struct st_context *st ) st->vp = stvp; st->fp = stfp; - cso_set_vertex_shader(st->cso_context, stvp->driver_shader); - cso_set_fragment_shader(st->cso_context, stfp->driver_shader); + cso_set_vertex_shader_handle(st->cso_context, stvp->driver_shader); + cso_set_fragment_shader_handle(st->cso_context, stfp->driver_shader); st->vertex_result_to_slot = xvp->output_to_slot; } diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 1b863143e0..71a848ea54 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -446,10 +446,10 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_set_rasterizer(cso, &st->bitmap.rasterizer); /* fragment shader state: TEX lookup program */ - cso_set_fragment_shader(cso, stfp->driver_shader); + cso_set_fragment_shader_handle(cso, stfp->driver_shader); /* vertex shader state: position + texcoord pass-through */ - cso_set_vertex_shader(cso, st->bitmap.vs); + cso_set_vertex_shader_handle(cso, st->bitmap.vs); /* sampler / texture state */ cso_single_sampler(cso, 0, &st->bitmap.sampler); diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index bb27faad21..dac346a06c 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -274,8 +274,8 @@ clear_with_quad(GLcontext *ctx, cso_set_rasterizer(st->cso_context, &st->clear.raster); cso_set_viewport(st->cso_context, &st->clear.viewport); - cso_set_fragment_shader(st->cso_context, st->clear.fs); - cso_set_vertex_shader(st->cso_context, st->clear.vs); + cso_set_fragment_shader_handle(st->cso_context, st->clear.fs); + cso_set_vertex_shader_handle(st->cso_context, st->clear.vs); /* draw quad matching scissor rect (XXX verify coord round-off) */ draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 75261c3350..3921500659 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -545,10 +545,10 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, } /* fragment shader state: TEX lookup program */ - cso_set_fragment_shader(cso, stfp->driver_shader); + cso_set_fragment_shader_handle(cso, stfp->driver_shader); /* vertex shader state: position + texcoord pass-through */ - cso_set_vertex_shader(cso, stvp->driver_shader); + cso_set_vertex_shader_handle(cso, stvp->driver_shader); /* texture sampling state: */ diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 63d6590540..dced31e88e 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -61,7 +61,7 @@ struct st_fragment_program GLuint input_map[PIPE_MAX_SHADER_INPUTS]; struct pipe_shader_state state; - struct pipe_shader_state *driver_shader; + void *driver_shader; GLuint param_state; @@ -88,7 +88,7 @@ struct st_vertex_program GLuint num_inputs; struct pipe_shader_state state; - struct pipe_shader_state *driver_shader; + void *driver_shader; /** For using our private draw module (glRasterPos) */ struct draw_vertex_shader *draw_shader; -- cgit v1.2.3 From a770d40c3d4977e2c134661b5d8facaea446b6ea Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 24 Apr 2008 12:11:24 -0600 Subject: gallium: use cso_destroy_vertex/fragment_shader() functions Also, rearrange the st_destroy_context() code a bit to prevent some invalid/NULL ptr derefs during tear-down. --- src/mesa/state_tracker/st_cb_bitmap.c | 2 +- src/mesa/state_tracker/st_cb_clear.c | 4 ++-- src/mesa/state_tracker/st_cb_program.c | 12 +++++------- src/mesa/state_tracker/st_context.c | 11 +++++++++-- src/mesa/state_tracker/st_program.c | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 7752b40e8b..e7f6ff66b5 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -803,7 +803,7 @@ st_destroy_bitmap(struct st_context *st) } #endif if (st->bitmap.vs) { - pipe->delete_vs_state(pipe, st->bitmap.vs); + cso_delete_vertex_shader(st->cso_context, st->bitmap.vs); st->bitmap.vs = NULL; } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index dac346a06c..95a5fb8db4 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -98,11 +98,11 @@ st_destroy_clear(struct st_context *st) struct pipe_context *pipe = st->pipe; if (st->clear.fs) { - pipe->delete_fs_state(pipe, st->clear.fs); + cso_delete_fragment_shader(st->cso_context, st->clear.fs); st->clear.fs = NULL; } if (st->clear.vs) { - pipe->delete_vs_state(pipe, st->clear.vs); + cso_delete_vertex_shader(st->cso_context, st->clear.vs); st->clear.vs = NULL; } if (st->clear.vbuf) { diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 67f8b1f8eb..a293ec3f0b 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -39,7 +39,7 @@ #include "shader/programopt.h" #include "shader/shader_api.h" -#include "cso_cache/cso_cache.h" +#include "cso_cache/cso_context.h" #include "draw/draw_context.h" #include "st_context.h" @@ -127,7 +127,6 @@ void st_delete_program(GLcontext *ctx, struct gl_program *prog) { struct st_context *st = st_context(ctx); - struct pipe_context *pipe = st->pipe; switch( prog->Target ) { case GL_VERTEX_PROGRAM_ARB: @@ -135,7 +134,7 @@ st_delete_program(GLcontext *ctx, struct gl_program *prog) struct st_vertex_program *stvp = (struct st_vertex_program *) prog; if (stvp->driver_shader) { - pipe->delete_vs_state(pipe, stvp->driver_shader); + cso_delete_vertex_shader(st->cso_context, stvp->driver_shader); stvp->driver_shader = NULL; } @@ -150,7 +149,7 @@ st_delete_program(GLcontext *ctx, struct gl_program *prog) struct st_fragment_program *stfp = (struct st_fragment_program *) prog; if (stfp->driver_shader) { - pipe->delete_fs_state(pipe, stfp->driver_shader); + cso_delete_fragment_shader(st->cso_context, stfp->driver_shader); stfp->driver_shader = NULL; } @@ -187,7 +186,6 @@ static void st_program_string_notify( GLcontext *ctx, struct gl_program *prog ) { struct st_context *st = st_context(ctx); - struct pipe_context *pipe = st->pipe; if (target == GL_FRAGMENT_PROGRAM_ARB) { struct st_fragment_program *stfp = (struct st_fragment_program *) prog; @@ -195,7 +193,7 @@ static void st_program_string_notify( GLcontext *ctx, stfp->serialNo++; if (stfp->driver_shader) { - pipe->delete_fs_state(pipe, stfp->driver_shader); + cso_delete_fragment_shader(st->cso_context, stfp->driver_shader); stfp->driver_shader = NULL; } @@ -215,7 +213,7 @@ static void st_program_string_notify( GLcontext *ctx, stvp->serialNo++; if (stvp->driver_shader) { - pipe->delete_vs_state(pipe, stvp->driver_shader); + cso_delete_vertex_shader(st->cso_context, stvp->driver_shader); stvp->driver_shader = NULL; } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index dadc524b51..8a30871fa0 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -176,22 +176,29 @@ static void st_destroy_context_priv( struct st_context *st ) } } - st->pipe->destroy( st->pipe ); free( st ); } void st_destroy_context( struct st_context *st ) { + struct pipe_context *pipe = st->pipe; + struct cso_context *cso = st->cso_context; GLcontext *ctx = st->ctx; /* need to unbind and destroy CSO objects before anything else */ - cso_destroy_context(st->cso_context); + cso_release_all(st->cso_context); _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache); _mesa_free_context_data(ctx); + st_destroy_context_priv(st); + + cso_destroy_context(cso); + + pipe->destroy( pipe ); + free(ctx); } diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 3648ded8a1..d450c30694 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -270,7 +270,7 @@ st_translate_vertex_program(struct st_context *st, stvp->state.tokens = NULL; } if (stvp->driver_shader) { - pipe->delete_vs_state(pipe, stvp->driver_shader); + cso_delete_vertex_shader(st->cso_context, stvp->driver_shader); stvp->driver_shader = NULL; } -- cgit v1.2.3 From 99fba5466bfd14c4e052041c0571821be529e762 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 30 Apr 2008 10:43:59 -0600 Subject: gallium: use new buffer wrapper functions in p_inlines.h This allows us to remove most of the direct references to winsys in the state tracker. --- src/mesa/state_tracker/st_atom_constbuf.c | 14 ++++---- src/mesa/state_tracker/st_cb_bitmap.c | 13 +++---- src/mesa/state_tracker/st_cb_bufferobjects.c | 22 +++++------- src/mesa/state_tracker/st_cb_clear.c | 14 ++++---- src/mesa/state_tracker/st_cb_drawpixels.c | 13 +++---- src/mesa/state_tracker/st_cb_fbo.c | 2 +- src/mesa/state_tracker/st_context.c | 4 +-- src/mesa/state_tracker/st_draw.c | 54 ++++++++++++---------------- src/mesa/state_tracker/st_gen_mipmap.c | 14 ++++---- src/mesa/state_tracker/st_texture.c | 1 - 10 files changed, 62 insertions(+), 89 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index 03093579e1..2b659aebbc 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -36,7 +36,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "pipe/p_winsys.h" #include "pipe/p_inlines.h" #include "st_context.h" @@ -54,7 +53,7 @@ void st_upload_constants( struct st_context *st, struct gl_program_parameter_list *params, unsigned id) { - struct pipe_winsys *ws = st->pipe->winsys; + struct pipe_context *pipe = st->pipe; struct pipe_constant_buffer *cbuf = &st->state.constants[id]; assert(id == PIPE_SHADER_VERTEX || id == PIPE_SHADER_FRAGMENT); @@ -74,8 +73,8 @@ void st_upload_constants( struct st_context *st, /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_buffer_reference( ws, &cbuf->buffer, NULL ); - cbuf->buffer = ws->buffer_create( ws, 1, PIPE_BUFFER_USAGE_CONSTANT, + pipe_reference_buffer(pipe, &cbuf->buffer, NULL ); + cbuf->buffer = pipe_buffer_create(pipe, 1, PIPE_BUFFER_USAGE_CONSTANT, paramBytes ); if (0) @@ -87,9 +86,10 @@ void st_upload_constants( struct st_context *st, /* load Mesa constants into the constant buffer */ if (cbuf->buffer) { - memcpy(ws->buffer_map(ws, cbuf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE), - params->ParameterValues, paramBytes); - ws->buffer_unmap(ws, cbuf->buffer); + void *map = pipe_buffer_map(pipe, cbuf->buffer, + PIPE_BUFFER_USAGE_CPU_WRITE); + memcpy(map, params->ParameterValues, paramBytes); + pipe_buffer_unmap(pipe, cbuf->buffer); } cbuf->size = paramBytes; diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index d73cd4abfa..f0a3b75357 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -50,7 +50,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" -#include "pipe/p_winsys.h" #include "util/p_tile.h" #include "util/u_draw_quad.h" #include "util/u_simple_shaders.h" @@ -372,9 +371,8 @@ setup_bitmap_vertex_data(struct st_context *st, void *buf; if (!st->bitmap.vbuf) { - st->bitmap.vbuf = pipe->winsys->buffer_create(pipe->winsys, 32, - PIPE_BUFFER_USAGE_VERTEX, - sizeof(st->bitmap.vertices)); + st->bitmap.vbuf = pipe_buffer_create(pipe, 32, PIPE_BUFFER_USAGE_VERTEX, + sizeof(st->bitmap.vertices)); } /* Positions are in clip coords since we need to do clipping in case @@ -413,10 +411,9 @@ setup_bitmap_vertex_data(struct st_context *st, } /* put vertex data into vbuf */ - buf = pipe->winsys->buffer_map(pipe->winsys, st->bitmap.vbuf, - PIPE_BUFFER_USAGE_CPU_WRITE); + buf = pipe_buffer_map(pipe, st->bitmap.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(buf, st->bitmap.vertices, sizeof(st->bitmap.vertices)); - pipe->winsys->buffer_unmap(pipe->winsys, st->bitmap.vbuf); + pipe_buffer_unmap(pipe, st->bitmap.vbuf); } @@ -761,7 +758,7 @@ st_destroy_bitmap(struct st_context *st) } if (st->bitmap.vbuf) { - pipe->winsys->buffer_destroy(pipe->winsys, st->bitmap.vbuf); + pipe_buffer_destroy(pipe, st->bitmap.vbuf); st->bitmap.vbuf = NULL; } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index fa1254ff7c..af79aefa96 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -35,7 +35,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "pipe/p_winsys.h" #include "pipe/p_inlines.h" @@ -79,7 +78,7 @@ st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj) struct st_buffer_object *st_obj = st_buffer_object(obj); if (st_obj->buffer) - pipe_buffer_reference(pipe->winsys, &st_obj->buffer, NULL); + pipe_reference_buffer(pipe, &st_obj->buffer, NULL); free(st_obj); } @@ -106,10 +105,9 @@ st_bufferobj_subdata(GLcontext *ctx, if (offset >= st_obj->size || size > (st_obj->size - offset)) return; - map = pipe->winsys->buffer_map(pipe->winsys, st_obj->buffer, - PIPE_BUFFER_USAGE_CPU_WRITE); + map = pipe_buffer_map(pipe, st_obj->buffer, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(map + offset, data, size); - pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer); + pipe_buffer_unmap(pipe, st_obj->buffer); } @@ -130,10 +128,9 @@ st_bufferobj_get_subdata(GLcontext *ctx, if (offset >= st_obj->size || size > (st_obj->size - offset)) return; - map = pipe->winsys->buffer_map(pipe->winsys, st_obj->buffer, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe, st_obj->buffer, PIPE_BUFFER_USAGE_CPU_READ); memcpy(data, map + offset, size); - pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer); + pipe_buffer_unmap(pipe, st_obj->buffer); } @@ -174,10 +171,9 @@ st_bufferobj_data(GLcontext *ctx, buffer_usage = 0; } - pipe_buffer_reference( pipe->winsys, &st_obj->buffer, NULL ); + pipe_reference_buffer( pipe, &st_obj->buffer, NULL ); - st_obj->buffer = pipe->winsys->buffer_create( pipe->winsys, 32, buffer_usage, - size ); + st_obj->buffer = pipe_buffer_create( pipe, 32, buffer_usage, size ); st_obj->size = size; @@ -211,7 +207,7 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, break; } - obj->Pointer = pipe->winsys->buffer_map(pipe->winsys, st_obj->buffer, flags); + obj->Pointer = pipe_buffer_map(pipe, st_obj->buffer, flags); return obj->Pointer; } @@ -225,7 +221,7 @@ st_bufferobj_unmap(GLcontext *ctx, GLenum target, struct gl_buffer_object *obj) struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); - pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer); + pipe_buffer_unmap(pipe, st_obj->buffer); obj->Pointer = NULL; return GL_TRUE; } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 95a5fb8db4..fe979f10bd 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -45,9 +45,9 @@ #include "st_mesa_to_tgsi.h" #include "pipe/p_context.h" +#include "pipe/p_inlines.h" #include "pipe/p_state.h" #include "pipe/p_defines.h" -#include "pipe/p_winsys.h" #include "util/u_pack_color.h" #include "util/u_simple_shaders.h" #include "util/u_draw_quad.h" @@ -106,7 +106,7 @@ st_destroy_clear(struct st_context *st) st->clear.vs = NULL; } if (st->clear.vbuf) { - pipe->winsys->buffer_destroy(pipe->winsys, st->clear.vbuf); + pipe_buffer_destroy(pipe, st->clear.vbuf); st->clear.vbuf = NULL; } } @@ -142,9 +142,8 @@ draw_quad(GLcontext *ctx, void *buf; if (!st->clear.vbuf) { - st->clear.vbuf = pipe->winsys->buffer_create(pipe->winsys, 32, - PIPE_BUFFER_USAGE_VERTEX, - sizeof(st->clear.vertices)); + st->clear.vbuf = pipe_buffer_create(pipe, 32, PIPE_BUFFER_USAGE_VERTEX, + sizeof(st->clear.vertices)); } /* positions */ @@ -171,10 +170,9 @@ draw_quad(GLcontext *ctx, } /* put vertex data into vbuf */ - buf = pipe->winsys->buffer_map(pipe->winsys, st->clear.vbuf, - PIPE_BUFFER_USAGE_CPU_WRITE); + buf = pipe_buffer_map(pipe, st->clear.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(buf, st->clear.vertices, sizeof(st->clear.vertices)); - pipe->winsys->buffer_unmap(pipe->winsys, st->clear.vbuf); + pipe_buffer_unmap(pipe, st->clear.vbuf); /* draw */ util_draw_vertex_buffer(pipe, st->clear.vbuf, diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 7597ea323c..65bfd6cfcc 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -55,7 +55,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" -#include "pipe/p_winsys.h" #include "util/p_tile.h" #include "util/u_draw_quad.h" #include "shader/prog_instruction.h" @@ -483,20 +482,18 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, ubyte *map; /* allocate/load buffer object with vertex data */ - buf = pipe->winsys->buffer_create(pipe->winsys, 32, - PIPE_BUFFER_USAGE_VERTEX, - sizeof(verts)); - map = pipe->winsys->buffer_map(pipe->winsys, buf, - PIPE_BUFFER_USAGE_CPU_WRITE); + buf = pipe_buffer_create(pipe,32, PIPE_BUFFER_USAGE_VERTEX, + sizeof(verts)); + map = pipe_buffer_map(pipe, buf, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(map, verts, sizeof(verts)); - pipe->winsys->buffer_unmap(pipe->winsys, buf); + pipe_buffer_unmap(pipe, buf); util_draw_vertex_buffer(pipe, buf, PIPE_PRIM_QUADS, 4, /* verts */ 3); /* attribs/vert */ - pipe->winsys->buffer_destroy(pipe->winsys, buf); + pipe_buffer_destroy(pipe, buf); } } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 2d741d9390..fc8a5ea7f6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -105,7 +105,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, } else if (strb->surface->buffer) { /* release/discard the old surface buffer */ - pipe_buffer_reference(pipe->winsys, &strb->surface->buffer, NULL); + pipe_reference_buffer(pipe, &strb->surface->buffer, NULL); } /* Determine surface format here */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 8a30871fa0..c900064f2b 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -55,7 +55,6 @@ #include "st_gen_mipmap.h" #include "st_program.h" #include "pipe/p_context.h" -#include "pipe/p_winsys.h" #include "pipe/p_inlines.h" #include "draw/draw_context.h" #include "cso_cache/cso_cache.h" @@ -157,7 +156,6 @@ struct st_context *st_create_context(struct pipe_context *pipe, static void st_destroy_context_priv( struct st_context *st ) { - struct pipe_winsys *ws = st->pipe->winsys; uint i; draw_destroy(st->draw); @@ -172,7 +170,7 @@ static void st_destroy_context_priv( struct st_context *st ) for (i = 0; i < Elements(st->state.constants); i++) { if (st->state.constants[i].buffer) { - pipe_buffer_reference(ws, &st->state.constants[i].buffer, NULL); + pipe_reference_buffer(st->pipe, &st->state.constants[i].buffer, NULL); } } diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 6c20120ac7..0fe4d198bd 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -43,7 +43,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "pipe/p_winsys.h" #include "pipe/p_inlines.h" #include "draw/draw_private.h" @@ -219,8 +218,7 @@ setup_edgeflags(GLcontext *ctx, GLenum primMode, GLint start, GLint count, if (!vec) return NULL; - map = pipe->winsys->buffer_map(pipe->winsys, stobj->buffer, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe, stobj->buffer, PIPE_BUFFER_USAGE_CPU_READ); map = ADD_POINTERS(map, array->Ptr); for (i = 0; i < count; i++) { @@ -230,7 +228,7 @@ setup_edgeflags(GLcontext *ctx, GLenum primMode, GLint start, GLint count, map += array->StrideB; } - pipe->winsys->buffer_unmap(pipe->winsys, stobj->buffer); + pipe_buffer_unmap(pipe, stobj->buffer); pipe->set_edgeflags(pipe, vec); @@ -260,7 +258,6 @@ st_draw_vbo(GLcontext *ctx, GLuint max_index) { struct pipe_context *pipe = ctx->st->pipe; - struct pipe_winsys *winsys = pipe->winsys; const struct st_vertex_program *vp; const struct pipe_shader_state *vs; struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS]; @@ -292,7 +289,7 @@ st_draw_vbo(GLcontext *ctx, assert(stobj->buffer); vbuffer[attr].buffer = NULL; - pipe_buffer_reference(winsys, &vbuffer[attr].buffer, stobj->buffer); + pipe_reference_buffer(pipe, &vbuffer[attr].buffer, stobj->buffer); vbuffer[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; assert(velements[attr].src_offset <= 2048); /* 11-bit field */ @@ -310,9 +307,8 @@ st_draw_vbo(GLcontext *ctx, /* wrap user data */ vbuffer[attr].buffer - = winsys->user_buffer_create(winsys, - (void *) arrays[mesaAttr]->Ptr, - bytes); + = pipe_user_buffer_create(pipe, (void *) arrays[mesaAttr]->Ptr, + bytes); vbuffer[attr].buffer_offset = 0; velements[attr].src_offset = 0; } @@ -358,14 +354,13 @@ st_draw_vbo(GLcontext *ctx, if (bufobj && bufobj->Name) { /* elements/indexes are in a real VBO */ struct st_buffer_object *stobj = st_buffer_object(bufobj); - pipe_buffer_reference(winsys, &indexBuf, stobj->buffer); + pipe_reference_buffer(pipe, &indexBuf, stobj->buffer); indexOffset = (unsigned) ib->ptr / indexSize; } else { /* element/indicies are in user space memory */ - indexBuf = winsys->user_buffer_create(winsys, - (void *) ib->ptr, - ib->count * indexSize); + indexBuf = pipe_user_buffer_create(pipe, (void *) ib->ptr, + ib->count * indexSize); indexOffset = 0; } @@ -380,7 +375,7 @@ st_draw_vbo(GLcontext *ctx, prims[i].start + indexOffset, prims[i].count); } - pipe_buffer_reference(winsys, &indexBuf, NULL); + pipe_reference_buffer(pipe, &indexBuf, NULL); } else { /* non-indexed */ @@ -396,7 +391,7 @@ st_draw_vbo(GLcontext *ctx, /* unreference buffers (frees wrapped user-space buffer objects) */ for (attr = 0; attr < vp->num_inputs; attr++) { - pipe_buffer_reference(winsys, &vbuffer[attr].buffer, NULL); + pipe_reference_buffer(pipe, &vbuffer[attr].buffer, NULL); assert(!vbuffer[attr].buffer); } pipe->set_vertex_buffers(pipe, vp->num_inputs, vbuffer); @@ -458,7 +453,6 @@ st_feedback_draw_vbo(GLcontext *ctx, struct st_context *st = ctx->st; struct pipe_context *pipe = st->pipe; struct draw_context *draw = st->draw; - struct pipe_winsys *winsys = pipe->winsys; const struct st_vertex_program *vp; const struct pipe_shader_state *vs; struct pipe_buffer *index_buffer_handle = 0; @@ -509,7 +503,7 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(stobj->buffer); vbuffers[attr].buffer = NULL; - pipe_buffer_reference(winsys, &vbuffers[attr].buffer, stobj->buffer); + pipe_reference_buffer(pipe, &vbuffers[attr].buffer, stobj->buffer); vbuffers[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; } @@ -521,9 +515,8 @@ st_feedback_draw_vbo(GLcontext *ctx, /* wrap user data */ vbuffers[attr].buffer - = winsys->user_buffer_create(winsys, - (void *) arrays[mesaAttr]->Ptr, - bytes); + = pipe_user_buffer_create(pipe, (void *) arrays[mesaAttr]->Ptr, + bytes); vbuffers[attr].buffer_offset = 0; velements[attr].src_offset = 0; } @@ -544,9 +537,8 @@ st_feedback_draw_vbo(GLcontext *ctx, #endif /* map the attrib buffer */ - map = pipe->winsys->buffer_map(pipe->winsys, - vbuffers[attr].buffer, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe, vbuffers[attr].buffer, + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_vertex_buffer(draw, attr, map); } @@ -572,9 +564,8 @@ st_feedback_draw_vbo(GLcontext *ctx, return; } - map = pipe->winsys->buffer_map(pipe->winsys, - index_buffer_handle, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe, index_buffer_handle, + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_element_buffer(draw, indexSize, map); } else { @@ -584,7 +575,7 @@ st_feedback_draw_vbo(GLcontext *ctx, /* map constant buffers */ - mapped_constants = winsys->buffer_map(winsys, + mapped_constants = pipe_buffer_map(pipe, st->state.constants[PIPE_SHADER_VERTEX].buffer, PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_constant_buffer(st->draw, mapped_constants); @@ -597,21 +588,20 @@ st_feedback_draw_vbo(GLcontext *ctx, /* unmap constant buffers */ - winsys->buffer_unmap(winsys, st->state.constants[PIPE_SHADER_VERTEX].buffer); + pipe_buffer_unmap(pipe, st->state.constants[PIPE_SHADER_VERTEX].buffer); /* * unmap vertex/index buffers */ for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { if (draw->pt.vertex_buffer[i].buffer) { - pipe->winsys->buffer_unmap(pipe->winsys, - draw->pt.vertex_buffer[i].buffer); - pipe_buffer_reference(winsys, &draw->pt.vertex_buffer[i].buffer, NULL); + pipe_buffer_unmap(pipe, draw->pt.vertex_buffer[i].buffer); + pipe_reference_buffer(pipe, &draw->pt.vertex_buffer[i].buffer, NULL); draw_set_mapped_vertex_buffer(draw, i, NULL); } } if (ib) { - pipe->winsys->buffer_unmap(pipe->winsys, index_buffer_handle); + pipe_buffer_unmap(pipe, index_buffer_handle); draw_set_mapped_element_buffer(draw, 0, NULL); } } diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index da9ec12a4d..1a0e19c2f9 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -36,7 +36,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" -#include "pipe/p_winsys.h" #include "util/u_gen_mipmap.h" #include "cso_cache/cso_cache.h" @@ -105,7 +104,6 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, { struct pipe_context *pipe = ctx->st->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_winsys *ws = pipe->winsys; struct pipe_texture *pt = st_get_texobj_texture(texObj); const uint baseLevel = texObj->BaseLevel; const uint lastLevel = pt->last_level; @@ -128,11 +126,11 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice); dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); - srcData = (ubyte *) ws->buffer_map(ws, srcSurf->buffer, - PIPE_BUFFER_USAGE_CPU_READ) + srcData = (ubyte *) pipe_buffer_map(pipe, srcSurf->buffer, + PIPE_BUFFER_USAGE_CPU_READ) + srcSurf->offset; - dstData = (ubyte *) ws->buffer_map(ws, dstSurf->buffer, - PIPE_BUFFER_USAGE_CPU_WRITE) + dstData = (ubyte *) pipe_buffer_map(pipe, dstSurf->buffer, + PIPE_BUFFER_USAGE_CPU_WRITE) + dstSurf->offset; _mesa_generate_mipmap_level(target, datatype, comps, @@ -144,8 +142,8 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, dstSurf->pitch * dstSurf->cpp, /* stride in bytes */ dstData); - ws->buffer_unmap(ws, srcSurf->buffer); - ws->buffer_unmap(ws, dstSurf->buffer); + pipe_buffer_unmap(pipe, srcSurf->buffer); + pipe_buffer_unmap(pipe, dstSurf->buffer); pipe_surface_reference(&srcSurf, NULL); pipe_surface_reference(&dstSurf, NULL); diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 66d81e2b95..f68bef1207 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -38,7 +38,6 @@ #include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_inlines.h" -#include "pipe/p_winsys.h" #define DBG if(0) printf -- cgit v1.2.3 From 54507125e735ffa595e252282eaabf38095c21e1 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Fri, 2 May 2008 10:08:03 +0000 Subject: Some changed for non-C99 compilers --- src/mesa/state_tracker/st_atom_blend.c | 15 +++++--------- src/mesa/state_tracker/st_atom_clip.c | 15 +++++--------- src/mesa/state_tracker/st_atom_constbuf.c | 20 +++++++++--------- src/mesa/state_tracker/st_atom_depth.c | 10 ++++----- src/mesa/state_tracker/st_atom_fixedfunction.c | 10 ++++----- src/mesa/state_tracker/st_atom_framebuffer.c | 10 ++++----- src/mesa/state_tracker/st_atom_pixeltransfer.c | 10 ++++----- src/mesa/state_tracker/st_atom_rasterizer.c | 12 +++++------ src/mesa/state_tracker/st_atom_sampler.c | 15 +++++--------- src/mesa/state_tracker/st_atom_scissor.c | 15 +++++--------- src/mesa/state_tracker/st_atom_shader.c | 10 ++++----- src/mesa/state_tracker/st_atom_stipple.c | 10 ++++----- src/mesa/state_tracker/st_atom_texture.c | 15 +++++--------- src/mesa/state_tracker/st_atom_viewport.c | 10 ++++----- src/mesa/state_tracker/st_cb_clear.c | 2 +- src/mesa/state_tracker/st_draw.c | 5 +++-- src/mesa/state_tracker/st_extensions.c | 28 +++++++++++++------------- 17 files changed, 94 insertions(+), 118 deletions(-) mode change 100644 => 100755 src/mesa/state_tracker/st_atom_blend.c mode change 100644 => 100755 src/mesa/state_tracker/st_atom_clip.c mode change 100644 => 100755 src/mesa/state_tracker/st_atom_constbuf.c (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c old mode 100644 new mode 100755 index 2a0e92245c..35c09c3e08 --- a/src/mesa/state_tracker/st_atom_blend.c +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -223,15 +223,10 @@ update_blend( struct st_context *st ) const struct st_tracked_state st_update_blend = { - .name = "st_update_blend", - .dirty = { - .mesa = (_NEW_COLOR), /* XXX _NEW_BLEND someday? */ - .st = 0, + "st_update_blend", /* name */ + { /* dirty */ + (_NEW_COLOR), /* XXX _NEW_BLEND someday? */ /* mesa */ + 0, /* st */ }, - .update = update_blend + update_blend, /* update */ }; - - - - - diff --git a/src/mesa/state_tracker/st_atom_clip.c b/src/mesa/state_tracker/st_atom_clip.c old mode 100644 new mode 100755 index a6f0568660..23d709b814 --- a/src/mesa/state_tracker/st_atom_clip.c +++ b/src/mesa/state_tracker/st_atom_clip.c @@ -62,15 +62,10 @@ static void update_clip( struct st_context *st ) const struct st_tracked_state st_update_clip = { - .name = "st_update_clip", - .dirty = { - .mesa = (_NEW_TRANSFORM), - .st = 0, + "st_update_clip", /* name */ + { /* dirty */ + (_NEW_TRANSFORM), /* mesa */ + 0, /* st */ }, - .update = update_clip + update_clip /* update */ }; - - - - - diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c old mode 100644 new mode 100755 index 2b659aebbc..2856e0f0e0 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -113,12 +113,12 @@ static void update_vs_constants(struct st_context *st ) } const struct st_tracked_state st_update_vs_constants = { - .name = "st_update_vs_constants", - .dirty = { - .mesa = 0, /* set dynamically above */ - .st = ST_NEW_VERTEX_PROGRAM, + "st_update_vs_constants", /* name */ + { /* dirty */ + 0, /* set dynamically above */ /* mesa */ + ST_NEW_VERTEX_PROGRAM, /* st */ }, - .update = update_vs_constants + update_vs_constants /* update */ }; /* Fragment shader: @@ -132,11 +132,11 @@ static void update_fs_constants(struct st_context *st ) } const struct st_tracked_state st_update_fs_constants = { - .name = "st_update_fs_constants", - .dirty = { - .mesa = 0, /* set dynamically above */ - .st = ST_NEW_FRAGMENT_PROGRAM, + "st_update_fs_constants", /* name */ + { /* dirty */ + 0, /* set dynamically above */ /* mesa */ + ST_NEW_FRAGMENT_PROGRAM, /* st */ }, - .update = update_fs_constants + update_fs_constants /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index ef467582c0..0e791ceb20 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -142,10 +142,10 @@ update_depth_stencil_alpha(struct st_context *st) const struct st_tracked_state st_update_depth_stencil_alpha = { - .name = "st_update_depth_stencil", - .dirty = { - .mesa = (_NEW_DEPTH|_NEW_STENCIL|_NEW_COLOR), - .st = 0, + "st_update_depth_stencil", /* name */ + { /* dirty */ + (_NEW_DEPTH|_NEW_STENCIL|_NEW_COLOR), /* mesa */ + 0, /* st */ }, - .update = update_depth_stencil_alpha + update_depth_stencil_alpha /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_fixedfunction.c b/src/mesa/state_tracker/st_atom_fixedfunction.c index 3f137e1633..165567af70 100644 --- a/src/mesa/state_tracker/st_atom_fixedfunction.c +++ b/src/mesa/state_tracker/st_atom_fixedfunction.c @@ -55,12 +55,12 @@ static void update_tnl( struct st_context *st ) const struct st_tracked_state st_update_tnl = { - .name = "st_update_tnl", - .dirty = { - .mesa = TNL_FIXED_FUNCTION_STATE_FLAGS, - .st = 0 + "st_update_tnl", /* name */ + { /* dirty */ + TNL_FIXED_FUNCTION_STATE_FLAGS, /* mesa */ + 0 /* st */ }, - .update = update_tnl + update_tnl /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index 14eeb58cc1..0a6974d8a7 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -96,11 +96,11 @@ update_framebuffer_state( struct st_context *st ) const struct st_tracked_state st_update_framebuffer = { - .name = "st_update_framebuffer", - .dirty = { - .mesa = _NEW_BUFFERS, - .st = 0, + "st_update_framebuffer", /* name */ + { /* dirty */ + _NEW_BUFFERS, /* mesa */ + 0, /* st */ }, - .update = update_framebuffer_state + update_framebuffer_state /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 76356bbad7..999c148449 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -463,10 +463,10 @@ update_pixel_transfer(struct st_context *st) const struct st_tracked_state st_update_pixel_transfer = { - .name = "st_update_pixel_transfer", - .dirty = { - .mesa = _NEW_PIXEL | _NEW_COLOR_MATRIX, - .st = 0, + "st_update_pixel_transfer", /* name */ + { /* dirty */ + _NEW_PIXEL | _NEW_COLOR_MATRIX, /* mesa */ + 0, /* st */ }, - .update = update_pixel_transfer + update_pixel_transfer /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index bb14cf9045..87a91d56d0 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -267,11 +267,11 @@ static void update_raster_state( struct st_context *st ) } const struct st_tracked_state st_update_rasterizer = { - .name = "st_update_rasterizer", - .dirty = { - .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_LINE | _NEW_SCISSOR | - _NEW_POINT | _NEW_BUFFERS | _NEW_MULTISAMPLE), - .st = 0, + "st_update_rasterizer", /* name */ + { /* dirty */ + (_NEW_LIGHT | _NEW_POLYGON | _NEW_LINE | _NEW_SCISSOR | /* mesa */ + _NEW_POINT | _NEW_BUFFERS | _NEW_MULTISAMPLE), + 0, /* st */ }, - .update = update_raster_state + update_raster_state /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 0237da3693..7515bb30cc 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -185,15 +185,10 @@ update_samplers(struct st_context *st) const struct st_tracked_state st_update_sampler = { - .name = "st_update_sampler", - .dirty = { - .mesa = _NEW_TEXTURE, - .st = 0, + "st_update_sampler", /* name */ + { /* dirty */ + _NEW_TEXTURE, /* mesa */ + 0, /* st */ }, - .update = update_samplers + update_samplers /* update */ }; - - - - - diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c index 59601e91a1..f5db492403 100644 --- a/src/mesa/state_tracker/st_atom_scissor.c +++ b/src/mesa/state_tracker/st_atom_scissor.c @@ -83,15 +83,10 @@ update_scissor( struct st_context *st ) const struct st_tracked_state st_update_scissor = { - .name = "st_update_scissor", - .dirty = { - .mesa = (_NEW_SCISSOR | _NEW_BUFFERS), - .st = 0, + "st_update_scissor", /* name */ + { /* dirty */ + (_NEW_SCISSOR | _NEW_BUFFERS), /* mesa */ + 0, /* st */ }, - .update = update_scissor + update_scissor /* update */ }; - - - - - diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 3f5ec71112..652500f52a 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -281,10 +281,10 @@ update_linkage( struct st_context *st ) const struct st_tracked_state st_update_shader = { - .name = "st_update_shader", - .dirty = { - .mesa = 0, - .st = ST_NEW_VERTEX_PROGRAM | ST_NEW_FRAGMENT_PROGRAM + "st_update_shader", /* name */ + { /* dirty */ + 0, /* mesa */ + ST_NEW_VERTEX_PROGRAM | ST_NEW_FRAGMENT_PROGRAM /* st */ }, - .update = update_linkage + update_linkage /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_stipple.c b/src/mesa/state_tracker/st_atom_stipple.c index c91214059a..f395930ab4 100644 --- a/src/mesa/state_tracker/st_atom_stipple.c +++ b/src/mesa/state_tracker/st_atom_stipple.c @@ -54,10 +54,10 @@ update_stipple( struct st_context *st ) const struct st_tracked_state st_update_polygon_stipple = { - .name = "st_update_polygon_stipple", - .dirty = { - .mesa = (_NEW_POLYGONSTIPPLE), - .st = 0, + "st_update_polygon_stipple", /* name */ + { /* dirty */ + (_NEW_POLYGONSTIPPLE), /* mesa */ + 0, /* st */ }, - .update = update_stipple + update_stipple /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index d15da5895a..f42b2f8d66 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -111,15 +111,10 @@ update_textures(struct st_context *st) const struct st_tracked_state st_update_texture = { - .name = "st_update_texture", - .dirty = { - .mesa = _NEW_TEXTURE, - .st = ST_NEW_FRAGMENT_PROGRAM, + "st_update_texture", /* name */ + { /* dirty */ + _NEW_TEXTURE, /* mesa */ + ST_NEW_FRAGMENT_PROGRAM, /* st */ }, - .update = update_textures + update_textures /* update */ }; - - - - - diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c index eb3f62cfbe..4b51521470 100644 --- a/src/mesa/state_tracker/st_atom_viewport.c +++ b/src/mesa/state_tracker/st_atom_viewport.c @@ -82,10 +82,10 @@ update_viewport( struct st_context *st ) const struct st_tracked_state st_update_viewport = { - .name = "st_update_viewport", - .dirty = { - .mesa = _NEW_BUFFERS | _NEW_VIEWPORT, - .st = 0, + "st_update_viewport", /* name */ + { /* dirty */ + _NEW_BUFFERS | _NEW_VIEWPORT, /* mesa */ + 0, /* st */ }, - .update = update_viewport + update_viewport /* update */ }; diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index fe979f10bd..b7d7204633 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -34,8 +34,8 @@ #include "main/glheader.h" #include "main/macros.h" #include "shader/prog_instruction.h" -#include "st_atom.h" #include "st_context.h" +#include "st_atom.h" #include "st_cb_accum.h" #include "st_cb_clear.h" #include "st_cb_fbo.h" diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 0fe4d198bd..a3bffbfc95 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -35,8 +35,8 @@ #include "vbo/vbo.h" -#include "st_atom.h" #include "st_context.h" +#include "st_atom.h" #include "st_cb_bufferobjects.h" #include "st_draw.h" #include "st_program.h" @@ -549,9 +549,10 @@ st_feedback_draw_vbo(GLcontext *ctx, unsigned indexSize; struct gl_buffer_object *bufobj = ib->obj; struct st_buffer_object *stobj = st_buffer_object(bufobj); - index_buffer_handle = stobj->buffer; void *map; + index_buffer_handle = stobj->buffer; + switch (ib->type) { case GL_UNSIGNED_INT: indexSize = 4; diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 260a2efe88..6f94ba39ae 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -38,17 +38,17 @@ #include "st_extensions.h" -static int min(int a, int b) +static int _min(int a, int b) { return (a < b) ? a : b; } -static int max(int a, int b) +static int _max(int a, int b) { return (a > b) ? a : b; } -static int clamp(int a, int min, int max) +static int _clamp(int a, int min, int max) { if (a < min) return min; @@ -69,42 +69,42 @@ void st_init_limits(struct st_context *st) struct gl_constants *c = &st->ctx->Const; c->MaxTextureLevels - = min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS), + = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS), MAX_TEXTURE_LEVELS); c->Max3DTextureLevels - = min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS), + = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS), MAX_3D_TEXTURE_LEVELS); c->MaxCubeTextureLevels - = min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS), + = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS), MAX_CUBE_TEXTURE_LEVELS); c->MaxTextureRectSize - = min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE); + = _min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE); c->MaxTextureUnits = c->MaxTextureImageUnits = c->MaxTextureCoordUnits - = min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS), + = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS), MAX_TEXTURE_IMAGE_UNITS); c->MaxDrawBuffers - = clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS), + = _clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS), 1, MAX_DRAW_BUFFERS); c->MaxLineWidth - = max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH)); + = _max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH)); c->MaxLineWidthAA - = max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH_AA)); + = _max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH_AA)); c->MaxPointSize - = max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH)); + = _max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH)); c->MaxPointSizeAA - = max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH_AA)); + = _max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH_AA)); c->MaxTextureMaxAnisotropy - = max(2.0, screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_ANISOTROPY)); + = _max(2.0, screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_ANISOTROPY)); c->MaxTextureLodBias = screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_LOD_BIAS); -- cgit v1.2.3 From 4b4ac9ed3497d0cbf58311b83ed4a08a98bb854c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 20 May 2008 13:48:34 -0600 Subject: gallium: fix mem leaks --- src/mesa/state_tracker/st_cb_clear.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index b7d7204633..cdfcdcee72 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -97,6 +97,16 @@ st_destroy_clear(struct st_context *st) { struct pipe_context *pipe = st->pipe; + if (st->clear.vert_shader.tokens) { + FREE((void *) st->clear.vert_shader.tokens); + st->clear.vert_shader.tokens = NULL; + } + + if (st->clear.frag_shader.tokens) { + FREE((void *) st->clear.frag_shader.tokens); + st->clear.frag_shader.tokens = NULL; + } + if (st->clear.fs) { cso_delete_fragment_shader(st->cso_context, st->clear.fs); st->clear.fs = NULL; -- cgit v1.2.3 From 6c534b830c6f5427c391c5225c34561141c201ba Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 15 Jul 2008 11:26:38 +0200 Subject: st: Silence compiler warnings on Windows. --- src/mesa/state_tracker/st_atom_framebuffer.c | 2 +- src/mesa/state_tracker/st_atom_rasterizer.c | 2 +- src/mesa/state_tracker/st_atom_viewport.c | 6 +++--- src/mesa/state_tracker/st_cb_accum.c | 2 +- src/mesa/state_tracker/st_cb_clear.c | 14 +++++++------- src/mesa/state_tracker/st_cb_drawpixels.c | 12 ++++++------ src/mesa/state_tracker/st_cb_rasterpos.c | 2 +- src/mesa/state_tracker/st_cb_texture.c | 8 ++++---- 8 files changed, 24 insertions(+), 24 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index d46c3ee16c..80df3b0506 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -59,7 +59,7 @@ update_renderbuffer_surface(struct st_context *st, strb->surface->texture != texture || strb->surface->width != rtt_width || strb->surface->height != rtt_height) { - int level; + GLuint level; /* find matching mipmap level size */ for (level = 0; level <= texture->last_level; level++) { if (texture->width[level] == rtt_width && diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index ff40bb4312..9f4e1c1c69 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -188,7 +188,7 @@ static void update_raster_state( struct st_context *st ) { GLfloat mrd = (ctx->DrawBuffer ? ctx->DrawBuffer->_MRD : - 1.0); + 1.0f); raster->offset_units = ctx->Polygon.OffsetFactor * mrd; raster->offset_scale = (ctx->Polygon.OffsetUnits * mrd * diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c index b105909e96..8b9f1abda4 100644 --- a/src/mesa/state_tracker/st_atom_viewport.c +++ b/src/mesa/state_tracker/st_atom_viewport.c @@ -62,9 +62,9 @@ update_viewport( struct st_context *st ) GLfloat x = (GLfloat)ctx->Viewport.X; GLfloat y = (GLfloat)ctx->Viewport.Y; GLfloat z = ctx->Viewport.Near; - GLfloat half_width = (GLfloat)ctx->Viewport.Width / 2.0; - GLfloat half_height = (GLfloat)ctx->Viewport.Height / 2.0; - GLfloat half_depth = (GLfloat)(ctx->Viewport.Far - ctx->Viewport.Near) / 2.0; + GLfloat half_width = (GLfloat)ctx->Viewport.Width / 2.0f; + GLfloat half_height = (GLfloat)ctx->Viewport.Height / 2.0f; + GLfloat half_depth = (GLfloat)(ctx->Viewport.Far - ctx->Viewport.Near) / 2.0f; st->state.viewport.scale[0] = half_width; st->state.viewport.scale[1] = half_height * yScale; diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index c0e8c6bf33..a992e08ff6 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -290,7 +290,7 @@ accum_return(GLcontext *ctx, GLfloat value, for (ch = 0; ch < 4; ch++) { if (colormask[ch]) { GLfloat val = abuf[i * 4 + ch] * value; - abuf[i * 4 + ch] = CLAMP(val, 0.0, 1.0); + abuf[i * 4 + ch] = CLAMP(val, 0.0f, 1.0f); } else { abuf[i * 4 + ch] = cbuf[i * 4 + ch]; diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index cdfcdcee72..e475f022d3 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -203,17 +203,17 @@ clear_with_quad(GLcontext *ctx, GLboolean color, GLboolean depth, GLboolean stencil) { struct st_context *st = ctx->st; - const GLfloat x0 = ctx->DrawBuffer->_Xmin; - const GLfloat x1 = ctx->DrawBuffer->_Xmax; + const GLfloat x0 = (GLfloat) ctx->DrawBuffer->_Xmin; + const GLfloat x1 = (GLfloat) ctx->DrawBuffer->_Xmax; GLfloat y0, y1; if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { - y0 = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymax; - y1 = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymin; + y0 = (GLfloat) (ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymax); + y1 = (GLfloat) (ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymin); } else { - y0 = ctx->DrawBuffer->_Ymin; - y1 = ctx->DrawBuffer->_Ymax; + y0 = (GLfloat) ctx->DrawBuffer->_Ymin; + y1 = (GLfloat) ctx->DrawBuffer->_Ymax; } /* @@ -286,7 +286,7 @@ clear_with_quad(GLcontext *ctx, cso_set_vertex_shader_handle(st->cso_context, st->clear.vs); /* draw quad matching scissor rect (XXX verify coord round-off) */ - draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); + draw_quad(ctx, x0, y0, x1, y1, (GLfloat) ctx->Depth.Clear, ctx->Color.ClearColor); /* Restore pipe state */ cso_restore_blend(st->cso_context); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 6b0137dcf8..2ebfcaf82b 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -423,8 +423,8 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, /* setup vertex data */ { const struct gl_framebuffer *fb = st->ctx->DrawBuffer; - const GLfloat fb_width = fb->Width; - const GLfloat fb_height = fb->Height; + const GLfloat fb_width = (GLfloat) fb->Width; + const GLfloat fb_height = (GLfloat) fb->Height; const GLfloat clip_x0 = x0 / fb_width * 2.0f - 1.0f; const GLfloat clip_y0 = y0 / fb_height * 2.0f - 1.0f; const GLfloat clip_x1 = x1 / fb_width * 2.0f - 1.0f; @@ -571,8 +571,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* viewport state: viewport matching window dims */ { - const float width = ctx->DrawBuffer->Width; - const float height = ctx->DrawBuffer->Height; + const float width = (float) ctx->DrawBuffer->Width; + const float height = (float) ctx->DrawBuffer->Height; struct pipe_viewport_state vp; vp.scale[0] = 0.5f * width; vp.scale[1] = -0.5f * height; @@ -600,9 +600,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, * Recall that these coords are transformed by the current * vertex shader and viewport transformation. */ - x0 = x; + x0 = (GLfloat) x; x1 = x + width * ctx->Pixel.ZoomX; - y0 = y; + y0 = (GLfloat) y; y1 = y + height * ctx->Pixel.ZoomY; //if(!color) draw_quad(ctx, x0, y0, z, x1, y1, color, invertTex); diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 3cb7b68bea..3b30c2a61b 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -135,7 +135,7 @@ rastpos_point(struct draw_stage *stage, struct prim_header *prim) struct rastpos_stage *rs = rastpos_stage(stage); GLcontext *ctx = rs->ctx; struct st_context *st = ctx->st; - const GLfloat height = ctx->DrawBuffer->Height; + const GLfloat height = (GLfloat) ctx->DrawBuffer->Height; const GLuint *outputMapping = st->vertex_result_to_slot; const GLfloat *pos; GLuint i; diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 73f8b8f788..de782e8232 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -285,7 +285,7 @@ guess_and_alloc_texture(struct st_context *st, assert(!stObj->pt); if (stObj->pt && - stImage->level > stObj->base.BaseLevel && + (GLint) stImage->level > stObj->base.BaseLevel && (stImage->base.Width == 1 || (stObj->base.Target != GL_TEXTURE_1D && stImage->base.Height == 1) || @@ -296,7 +296,7 @@ guess_and_alloc_texture(struct st_context *st, /* If this image disrespects BaseLevel, allocate from level zero. * Usually BaseLevel == 0, so it's unlikely to happen. */ - if (stImage->level < stObj->base.BaseLevel) + if ((GLint) stImage->level < stObj->base.BaseLevel) firstLevel = 0; else firstLevel = stObj->base.BaseLevel; @@ -810,7 +810,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, texImage->Height, format, type); GLuint depth; - int i; + GLuint i; GLubyte *dest; /* Map */ @@ -1383,7 +1383,7 @@ calculate_first_last_level(struct st_texture_object *stObj) } else { firstLevel = 0; - lastLevel = MIN2(tObj->MaxLevel, tObj->Image[0][tObj->BaseLevel]->WidthLog2); + lastLevel = MIN2(tObj->MaxLevel, (int) tObj->Image[0][tObj->BaseLevel]->WidthLog2); } break; case GL_TEXTURE_RECTANGLE_NV: -- cgit v1.2.3 From f637a96e85a51a66f2c53b91118a6815bb61d6e6 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 3 Sep 2008 11:48:05 +0900 Subject: gallium: Have pipe_buffer_* receive a pipe_screen instead of a pipe_context. We want to use the pipe_buffer_* inlines everywhere, but a pipe context is not always available nor is it needed. --- src/gallium/auxiliary/util/u_draw_quad.c | 2 +- src/gallium/drivers/cell/ppu/cell_state_shader.c | 2 +- src/gallium/drivers/cell/ppu/cell_texture.c | 4 +-- src/gallium/drivers/i915simple/i915_prim_vbuf.c | 2 +- src/gallium/drivers/i915simple/i915_texture.c | 8 ++--- src/gallium/drivers/i965simple/brw_state_pool.c | 2 +- src/gallium/drivers/i965simple/brw_tex_layout.c | 4 +-- src/gallium/drivers/softpipe/sp_context.c | 2 +- src/gallium/drivers/softpipe/sp_state_fs.c | 2 +- src/gallium/drivers/softpipe/sp_texture.c | 6 ++-- src/gallium/include/pipe/p_inlines.h | 28 +++++++-------- src/gallium/state_trackers/python/p_context.i | 2 +- src/gallium/state_trackers/python/st_device.c | 2 +- .../state_trackers/python/st_softpipe_winsys.c | 2 +- src/gallium/winsys/drm/intel/dri/intel_screen.c | 2 +- src/gallium/winsys/egl_xlib/sw_winsys.c | 2 +- src/gallium/winsys/gdi/wmesa.c | 2 +- src/gallium/winsys/xlib/xm_winsys.c | 2 +- src/gallium/winsys/xlib/xm_winsys_aub.c | 2 +- src/mesa/state_tracker/st_atom_constbuf.c | 8 ++--- src/mesa/state_tracker/st_cb_bitmap.c | 8 ++--- src/mesa/state_tracker/st_cb_bufferobjects.c | 18 +++++----- src/mesa/state_tracker/st_cb_clear.c | 8 ++--- src/mesa/state_tracker/st_cb_drawpixels.c | 8 ++--- src/mesa/state_tracker/st_context.c | 2 +- src/mesa/state_tracker/st_draw.c | 40 +++++++++++----------- src/mesa/state_tracker/st_gen_mipmap.c | 8 ++--- 27 files changed, 89 insertions(+), 89 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/gallium/auxiliary/util/u_draw_quad.c b/src/gallium/auxiliary/util/u_draw_quad.c index bf143815d8..d643ee9ab7 100644 --- a/src/gallium/auxiliary/util/u_draw_quad.c +++ b/src/gallium/auxiliary/util/u_draw_quad.c @@ -127,6 +127,6 @@ util_draw_texquad(struct pipe_context *pipe, util_draw_vertex_buffer(pipe, vbuf, PIPE_PRIM_TRIANGLE_FAN, 4, 2); } - pipe_buffer_reference(pipe->winsys, &vbuf, NULL); + pipe_buffer_reference(pipe->screen, &vbuf, NULL); } } diff --git a/src/gallium/drivers/cell/ppu/cell_state_shader.c b/src/gallium/drivers/cell/ppu/cell_state_shader.c index 86bcad05e9..3d1b887da9 100644 --- a/src/gallium/drivers/cell/ppu/cell_state_shader.c +++ b/src/gallium/drivers/cell/ppu/cell_state_shader.c @@ -166,7 +166,7 @@ cell_set_constant_buffer(struct pipe_context *pipe, assert(index == 0); /* note: reference counting */ - pipe_buffer_reference(ws, + winsys_buffer_reference(ws, &cell->constants[shader].buffer, buf->buffer); cell->constants[shader].size = buf->size; diff --git a/src/gallium/drivers/cell/ppu/cell_texture.c b/src/gallium/drivers/cell/ppu/cell_texture.c index 5a0942bbd6..5c01aa21b8 100644 --- a/src/gallium/drivers/cell/ppu/cell_texture.c +++ b/src/gallium/drivers/cell/ppu/cell_texture.c @@ -130,7 +130,7 @@ cell_texture_release_screen(struct pipe_screen *screen, DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); */ - pipe_buffer_reference(screen->winsys, &spt->buffer, NULL); + pipe_buffer_reference(screen, &spt->buffer, NULL); FREE(spt); } @@ -161,7 +161,7 @@ cell_get_tex_surface_screen(struct pipe_screen *screen, if (ps) { assert(ps->refcount); assert(ps->winsys); - pipe_buffer_reference(ws, &ps->buffer, spt->buffer); + winsys_buffer_reference(ws, &ps->buffer, spt->buffer); ps->format = pt->format; ps->block = pt->block; ps->width = pt->width[level]; diff --git a/src/gallium/drivers/i915simple/i915_prim_vbuf.c b/src/gallium/drivers/i915simple/i915_prim_vbuf.c index e4ece55098..9397a2ca1a 100644 --- a/src/gallium/drivers/i915simple/i915_prim_vbuf.c +++ b/src/gallium/drivers/i915simple/i915_prim_vbuf.c @@ -124,7 +124,7 @@ i915_vbuf_render_allocate_vertices( struct vbuf_render *render, if (i915_render->vbo_size > size + i915_render->vbo_offset && !i915->vbo_flushed) { } else { i915->vbo_flushed = 0; - pipe_buffer_reference(winsys, &i915_render->vbo, NULL); + winsys_buffer_reference(winsys, &i915_render->vbo, NULL); } if (!i915_render->vbo) { diff --git a/src/gallium/drivers/i915simple/i915_texture.c b/src/gallium/drivers/i915simple/i915_texture.c index a853a5a3f6..bd87217063 100644 --- a/src/gallium/drivers/i915simple/i915_texture.c +++ b/src/gallium/drivers/i915simple/i915_texture.c @@ -645,7 +645,7 @@ i915_texture_release(struct pipe_screen *screen, DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); */ - pipe_buffer_reference(screen->winsys, &tex->buffer, NULL); + pipe_buffer_reference(screen, &tex->buffer, NULL); for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) if (tex->image_offset[i]) @@ -684,7 +684,7 @@ i915_get_tex_surface(struct pipe_screen *screen, ps->refcount = 1; ps->winsys = ws; pipe_texture_reference(&ps->texture, pt); - pipe_buffer_reference(ws, &ps->buffer, tex->buffer); + pipe_buffer_reference(screen, &ps->buffer, tex->buffer); ps->format = pt->format; ps->width = pt->width[level]; ps->height = pt->height[level]; @@ -728,7 +728,7 @@ i915_texture_blanket(struct pipe_screen * screen, i915_miptree_set_level_info(tex, 0, 1, base->width[0], base->height[0], 1); i915_miptree_set_image_offset(tex, 0, 0, 0, 0); - pipe_buffer_reference(screen->winsys, &tex->buffer, buffer); + pipe_buffer_reference(screen, &tex->buffer, buffer); return &tex->base; } @@ -756,7 +756,7 @@ i915_tex_surface_release(struct pipe_screen *screen, } pipe_texture_reference(&surf->texture, NULL); - pipe_buffer_reference(screen->winsys, &surf->buffer, NULL); + pipe_buffer_reference(screen, &surf->buffer, NULL); FREE(surf); } diff --git a/src/gallium/drivers/i965simple/brw_state_pool.c b/src/gallium/drivers/i965simple/brw_state_pool.c index 78d4c0e411..d0dc1ef74d 100644 --- a/src/gallium/drivers/i965simple/brw_state_pool.c +++ b/src/gallium/drivers/i965simple/brw_state_pool.c @@ -103,7 +103,7 @@ static void brw_destroy_pool( struct brw_context *brw, { struct brw_mem_pool *pool = &brw->pool[pool_id]; - pipe_buffer_reference( pool->brw->pipe.winsys, + winsys_buffer_reference( pool->brw->pipe.winsys, &pool->buffer, NULL ); } diff --git a/src/gallium/drivers/i965simple/brw_tex_layout.c b/src/gallium/drivers/i965simple/brw_tex_layout.c index 05eda9d1f2..cc0c665e02 100644 --- a/src/gallium/drivers/i965simple/brw_tex_layout.c +++ b/src/gallium/drivers/i965simple/brw_tex_layout.c @@ -330,7 +330,7 @@ brw_texture_release_screen(struct pipe_screen *screen, DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); */ - pipe_buffer_reference(ws, &tex->buffer, NULL); + winsys_buffer_reference(ws, &tex->buffer, NULL); for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) if (tex->image_offset[i]) @@ -369,7 +369,7 @@ brw_get_tex_surface_screen(struct pipe_screen *screen, if (ps) { assert(ps->format); assert(ps->refcount); - pipe_buffer_reference(ws, &ps->buffer, tex->buffer); + winsys_buffer_reference(ws, &ps->buffer, tex->buffer); ps->format = pt->format; ps->width = pt->width[level]; ps->height = pt->height[level]; diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index dda90f760a..6f12390cf7 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -113,7 +113,7 @@ static void softpipe_destroy( struct pipe_context *pipe ) for (i = 0; i < Elements(softpipe->constants); i++) { if (softpipe->constants[i].buffer) { - pipe_buffer_reference(ws, &softpipe->constants[i].buffer, NULL); + winsys_buffer_reference(ws, &softpipe->constants[i].buffer, NULL); } } diff --git a/src/gallium/drivers/softpipe/sp_state_fs.c b/src/gallium/drivers/softpipe/sp_state_fs.c index 1be461b3a4..e5b609cf6c 100644 --- a/src/gallium/drivers/softpipe/sp_state_fs.c +++ b/src/gallium/drivers/softpipe/sp_state_fs.c @@ -152,7 +152,7 @@ softpipe_set_constant_buffer(struct pipe_context *pipe, assert(index == 0); /* note: reference counting */ - pipe_buffer_reference(ws, + winsys_buffer_reference(ws, &softpipe->constants[shader].buffer, buf ? buf->buffer : NULL); softpipe->constants[shader].size = buf ? buf->size : 0; diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 3a737d6f72..c283e3e410 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -192,7 +192,7 @@ softpipe_texture_blanket(struct pipe_screen * screen, spt->base.nblocksy[0] = pf_get_nblocksy(&spt->base.block, spt->base.height[0]); spt->stride[0] = stride[0]; - pipe_buffer_reference(screen->winsys, &spt->buffer, buffer); + pipe_buffer_reference(screen, &spt->buffer, buffer); return &spt->base; } @@ -208,7 +208,7 @@ softpipe_texture_release(struct pipe_screen *screen, if (--(*pt)->refcount <= 0) { struct softpipe_texture *spt = softpipe_texture(*pt); - pipe_buffer_reference(screen->winsys, &spt->buffer, NULL); + pipe_buffer_reference(screen, &spt->buffer, NULL); FREE(spt); } *pt = NULL; @@ -231,7 +231,7 @@ softpipe_get_tex_surface(struct pipe_screen *screen, if (ps) { assert(ps->refcount); assert(ps->winsys); - pipe_buffer_reference(ws, &ps->buffer, spt->buffer); + pipe_buffer_reference(screen, &ps->buffer, spt->buffer); ps->format = pt->format; ps->block = pt->block; ps->width = pt->width[level]; diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h index 1e4b98edb4..d70de8e301 100644 --- a/src/gallium/include/pipe/p_inlines.h +++ b/src/gallium/include/pipe/p_inlines.h @@ -109,7 +109,7 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) /* XXX: thread safety issues! */ static INLINE void -pipe_buffer_reference(struct pipe_winsys *winsys, +winsys_buffer_reference(struct pipe_winsys *winsys, struct pipe_buffer **ptr, struct pipe_buffer *buf) { @@ -164,48 +164,48 @@ pipe_texture_release(struct pipe_texture **ptr) */ static INLINE struct pipe_buffer * -pipe_buffer_create( struct pipe_context *pipe, +pipe_buffer_create( struct pipe_screen *screen, unsigned alignment, unsigned usage, unsigned size ) { - return pipe->winsys->buffer_create(pipe->winsys, alignment, usage, size); + return screen->winsys->buffer_create(screen->winsys, alignment, usage, size); } static INLINE struct pipe_buffer * -pipe_user_buffer_create( struct pipe_context *pipe, void *ptr, unsigned size ) +pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size ) { - return pipe->winsys->user_buffer_create(pipe->winsys, ptr, size); + return screen->winsys->user_buffer_create(screen->winsys, ptr, size); } static INLINE void -pipe_buffer_destroy( struct pipe_context *pipe, struct pipe_buffer *buf ) +pipe_buffer_destroy( struct pipe_screen *screen, struct pipe_buffer *buf ) { - pipe->winsys->buffer_destroy(pipe->winsys, buf); + screen->winsys->buffer_destroy(screen->winsys, buf); } static INLINE void * -pipe_buffer_map(struct pipe_context *pipe, +pipe_buffer_map(struct pipe_screen *screen, struct pipe_buffer *buf, unsigned usage) { - return pipe->winsys->buffer_map(pipe->winsys, buf, usage); + return screen->winsys->buffer_map(screen->winsys, buf, usage); } static INLINE void -pipe_buffer_unmap(struct pipe_context *pipe, +pipe_buffer_unmap(struct pipe_screen *screen, struct pipe_buffer *buf) { - pipe->winsys->buffer_unmap(pipe->winsys, buf); + screen->winsys->buffer_unmap(screen->winsys, buf); } /* XXX when we're using this everywhere, get rid of - * pipe_buffer_reference() above. + * winsys_buffer_reference() above. */ static INLINE void -pipe_reference_buffer(struct pipe_context *pipe, +pipe_buffer_reference(struct pipe_screen *screen, struct pipe_buffer **ptr, struct pipe_buffer *buf) { - pipe_buffer_reference(pipe->winsys, ptr, buf); + winsys_buffer_reference(screen->winsys, ptr, buf); } diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index 0b2621f7c3..231e07cd63 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -248,7 +248,7 @@ struct st_context { util_draw_vertex_buffer(pipe, vbuf, prim, num_verts, num_attribs); error2: - pipe_buffer_reference(pipe->winsys, &vbuf, NULL); + pipe_buffer_reference(pipe->screen, &vbuf, NULL); error1: ; } diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index f71d85dd9b..bd71755f0b 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -293,7 +293,7 @@ st_buffer_destroy(struct st_buffer *st_buf) { if(st_buf) { struct pipe_winsys *winsys = st_buf->st_dev->screen->winsys; - pipe_buffer_reference(winsys, &st_buf->buffer, NULL); + pipe_buffer_reference(pipe->screen, &st_buf->buffer, NULL); FREE(st_buf); } } diff --git a/src/gallium/state_trackers/python/st_softpipe_winsys.c b/src/gallium/state_trackers/python/st_softpipe_winsys.c index 2d4f5434b3..f62113a469 100644 --- a/src/gallium/state_trackers/python/st_softpipe_winsys.c +++ b/src/gallium/state_trackers/python/st_softpipe_winsys.c @@ -221,7 +221,7 @@ st_softpipe_surface_release(struct pipe_winsys *winsys, surf->refcount--; if (surf->refcount == 0) { if (surf->buffer) - pipe_buffer_reference(winsys, &surf->buffer, NULL); + winsys_buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; diff --git a/src/gallium/winsys/drm/intel/dri/intel_screen.c b/src/gallium/winsys/drm/intel/dri/intel_screen.c index 46d4861e77..3a486481f5 100644 --- a/src/gallium/winsys/drm/intel/dri/intel_screen.c +++ b/src/gallium/winsys/drm/intel/dri/intel_screen.c @@ -83,7 +83,7 @@ intelCreateSurface(struct intel_screen *intelScreen, struct pipe_winsys *winsys, buffer); /* Unref the buffer we don't need it anyways */ - pipe_buffer_reference(screen->winsys, &buffer, NULL); + pipe_buffer_reference(screen, &buffer, NULL); surface = screen->get_tex_surface(screen, texture, diff --git a/src/gallium/winsys/egl_xlib/sw_winsys.c b/src/gallium/winsys/egl_xlib/sw_winsys.c index ae81d7f801..2fd190da52 100644 --- a/src/gallium/winsys/egl_xlib/sw_winsys.c +++ b/src/gallium/winsys/egl_xlib/sw_winsys.c @@ -216,7 +216,7 @@ surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) surf->refcount--; if (surf->refcount == 0) { if (surf->buffer) - pipe_buffer_reference(winsys, &surf->buffer, NULL); + winsys_buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; diff --git a/src/gallium/winsys/gdi/wmesa.c b/src/gallium/winsys/gdi/wmesa.c index 730fb1b541..ed3dd2b927 100644 --- a/src/gallium/winsys/gdi/wmesa.c +++ b/src/gallium/winsys/gdi/wmesa.c @@ -463,7 +463,7 @@ wm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) surf->refcount--; if (surf->refcount == 0) { if (surf->buffer) - pipe_buffer_reference(winsys, &surf->buffer, NULL); + winsys_buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; diff --git a/src/gallium/winsys/xlib/xm_winsys.c b/src/gallium/winsys/xlib/xm_winsys.c index 68ead7f528..70f01e0ef8 100644 --- a/src/gallium/winsys/xlib/xm_winsys.c +++ b/src/gallium/winsys/xlib/xm_winsys.c @@ -543,7 +543,7 @@ xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) surf->refcount--; if (surf->refcount == 0) { if (surf->buffer) - pipe_buffer_reference(winsys, &surf->buffer, NULL); + winsys_buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; diff --git a/src/gallium/winsys/xlib/xm_winsys_aub.c b/src/gallium/winsys/xlib/xm_winsys_aub.c index 35c4ebc4ba..b7c10b6bca 100644 --- a/src/gallium/winsys/xlib/xm_winsys_aub.c +++ b/src/gallium/winsys/xlib/xm_winsys_aub.c @@ -308,7 +308,7 @@ aub_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) surf->refcount--; if (surf->refcount == 0) { if (surf->buffer) - pipe_buffer_reference(winsys, &surf->buffer, NULL); + winsys_buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index d3aadf5074..d02e51cb9a 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -73,8 +73,8 @@ void st_upload_constants( struct st_context *st, /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_reference_buffer(pipe, &cbuf->buffer, NULL ); - cbuf->buffer = pipe_buffer_create(pipe, 16, PIPE_BUFFER_USAGE_CONSTANT, + pipe_buffer_reference(pipe->screen, &cbuf->buffer, NULL ); + cbuf->buffer = pipe_buffer_create(pipe->screen, 16, PIPE_BUFFER_USAGE_CONSTANT, paramBytes ); if (0) @@ -86,10 +86,10 @@ void st_upload_constants( struct st_context *st, /* load Mesa constants into the constant buffer */ if (cbuf->buffer) { - void *map = pipe_buffer_map(pipe, cbuf->buffer, + void *map = pipe_buffer_map(pipe->screen, cbuf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(map, params->ParameterValues, paramBytes); - pipe_buffer_unmap(pipe, cbuf->buffer); + pipe_buffer_unmap(pipe->screen, cbuf->buffer); } cbuf->size = paramBytes; diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index a0c305d66f..694104f9cf 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -378,7 +378,7 @@ setup_bitmap_vertex_data(struct st_context *st, void *buf; if (!st->bitmap.vbuf) { - st->bitmap.vbuf = pipe_buffer_create(pipe, 32, PIPE_BUFFER_USAGE_VERTEX, + st->bitmap.vbuf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX, sizeof(st->bitmap.vertices)); } @@ -418,9 +418,9 @@ setup_bitmap_vertex_data(struct st_context *st, } /* put vertex data into vbuf */ - buf = pipe_buffer_map(pipe, st->bitmap.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); + buf = pipe_buffer_map(pipe->screen, st->bitmap.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(buf, st->bitmap.vertices, sizeof(st->bitmap.vertices)); - pipe_buffer_unmap(pipe, st->bitmap.vbuf); + pipe_buffer_unmap(pipe->screen, st->bitmap.vbuf); } @@ -779,7 +779,7 @@ st_destroy_bitmap(struct st_context *st) } if (st->bitmap.vbuf) { - pipe_buffer_destroy(pipe, st->bitmap.vbuf); + pipe_buffer_destroy(pipe->screen, st->bitmap.vbuf); st->bitmap.vbuf = NULL; } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index af79aefa96..07fa2afce0 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -78,7 +78,7 @@ st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj) struct st_buffer_object *st_obj = st_buffer_object(obj); if (st_obj->buffer) - pipe_reference_buffer(pipe, &st_obj->buffer, NULL); + pipe_buffer_reference(pipe->screen, &st_obj->buffer, NULL); free(st_obj); } @@ -105,9 +105,9 @@ st_bufferobj_subdata(GLcontext *ctx, if (offset >= st_obj->size || size > (st_obj->size - offset)) return; - map = pipe_buffer_map(pipe, st_obj->buffer, PIPE_BUFFER_USAGE_CPU_WRITE); + map = pipe_buffer_map(pipe->screen, st_obj->buffer, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(map + offset, data, size); - pipe_buffer_unmap(pipe, st_obj->buffer); + pipe_buffer_unmap(pipe->screen, st_obj->buffer); } @@ -128,9 +128,9 @@ st_bufferobj_get_subdata(GLcontext *ctx, if (offset >= st_obj->size || size > (st_obj->size - offset)) return; - map = pipe_buffer_map(pipe, st_obj->buffer, PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe->screen, st_obj->buffer, PIPE_BUFFER_USAGE_CPU_READ); memcpy(data, map + offset, size); - pipe_buffer_unmap(pipe, st_obj->buffer); + pipe_buffer_unmap(pipe->screen, st_obj->buffer); } @@ -171,9 +171,9 @@ st_bufferobj_data(GLcontext *ctx, buffer_usage = 0; } - pipe_reference_buffer( pipe, &st_obj->buffer, NULL ); + pipe_buffer_reference( pipe->screen, &st_obj->buffer, NULL ); - st_obj->buffer = pipe_buffer_create( pipe, 32, buffer_usage, size ); + st_obj->buffer = pipe_buffer_create( pipe->screen, 32, buffer_usage, size ); st_obj->size = size; @@ -207,7 +207,7 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, break; } - obj->Pointer = pipe_buffer_map(pipe, st_obj->buffer, flags); + obj->Pointer = pipe_buffer_map(pipe->screen, st_obj->buffer, flags); return obj->Pointer; } @@ -221,7 +221,7 @@ st_bufferobj_unmap(GLcontext *ctx, GLenum target, struct gl_buffer_object *obj) struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); - pipe_buffer_unmap(pipe, st_obj->buffer); + pipe_buffer_unmap(pipe->screen, st_obj->buffer); obj->Pointer = NULL; return GL_TRUE; } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index e475f022d3..013b9a9c9c 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -116,7 +116,7 @@ st_destroy_clear(struct st_context *st) st->clear.vs = NULL; } if (st->clear.vbuf) { - pipe_buffer_destroy(pipe, st->clear.vbuf); + pipe_buffer_destroy(pipe->screen, st->clear.vbuf); st->clear.vbuf = NULL; } } @@ -152,7 +152,7 @@ draw_quad(GLcontext *ctx, void *buf; if (!st->clear.vbuf) { - st->clear.vbuf = pipe_buffer_create(pipe, 32, PIPE_BUFFER_USAGE_VERTEX, + st->clear.vbuf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX, sizeof(st->clear.vertices)); } @@ -180,9 +180,9 @@ draw_quad(GLcontext *ctx, } /* put vertex data into vbuf */ - buf = pipe_buffer_map(pipe, st->clear.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); + buf = pipe_buffer_map(pipe->screen, st->clear.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(buf, st->clear.vertices, sizeof(st->clear.vertices)); - pipe_buffer_unmap(pipe, st->clear.vbuf); + pipe_buffer_unmap(pipe->screen, st->clear.vbuf); /* draw */ util_draw_vertex_buffer(pipe, st->clear.vbuf, diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 4ec7c752df..00bbcae32a 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -487,17 +487,17 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, ubyte *map; /* allocate/load buffer object with vertex data */ - buf = pipe_buffer_create(pipe, 32, PIPE_BUFFER_USAGE_VERTEX, + buf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX, sizeof(verts)); - map = pipe_buffer_map(pipe, buf, PIPE_BUFFER_USAGE_CPU_WRITE); + map = pipe_buffer_map(pipe->screen, buf, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(map, verts, sizeof(verts)); - pipe_buffer_unmap(pipe, buf); + pipe_buffer_unmap(pipe->screen, buf); util_draw_vertex_buffer(pipe, buf, PIPE_PRIM_QUADS, 4, /* verts */ 3); /* attribs/vert */ - pipe_buffer_reference(pipe->winsys, &buf, NULL); + pipe_buffer_reference(pipe->screen, &buf, NULL); } } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 83b0be06da..08d4db7f7f 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -196,7 +196,7 @@ static void st_destroy_context_priv( struct st_context *st ) for (i = 0; i < Elements(st->state.constants); i++) { if (st->state.constants[i].buffer) { - pipe_reference_buffer(st->pipe, &st->state.constants[i].buffer, NULL); + pipe_buffer_reference(st->pipe->screen, &st->state.constants[i].buffer, NULL); } } diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 2c80701186..bdf8648ef7 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -229,7 +229,7 @@ setup_edgeflags(GLcontext *ctx, GLenum primMode, GLint start, GLint count, if (!vec) return NULL; - map = pipe_buffer_map(pipe, stobj->buffer, PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe->screen, stobj->buffer, PIPE_BUFFER_USAGE_CPU_READ); map = ADD_POINTERS(map, array->Ptr); for (i = 0; i < count; i++) { @@ -239,7 +239,7 @@ setup_edgeflags(GLcontext *ctx, GLenum primMode, GLint start, GLint count, map += array->StrideB; } - pipe_buffer_unmap(pipe, stobj->buffer); + pipe_buffer_unmap(pipe->screen, stobj->buffer); pipe->set_edgeflags(pipe, vec); @@ -373,13 +373,13 @@ setup_interleaved_attribs(GLcontext *ctx, get_user_arrays_bounds(vp, arrays, max_index, &low, &high); /*printf("user buffer range: %p %p %d\n", low, high, high-low);*/ vbuffer->buffer = - pipe_user_buffer_create(pipe, (void *) low, high - low); + pipe_user_buffer_create(pipe->screen, (void *) low, high - low); vbuffer->buffer_offset = 0; offset0 = low; } else { vbuffer->buffer = NULL; - pipe_reference_buffer(pipe, &vbuffer->buffer, stobj->buffer); + pipe_buffer_reference(pipe->screen, &vbuffer->buffer, stobj->buffer); vbuffer->buffer_offset = (unsigned) arrays[mesaAttr]->Ptr; offset0 = arrays[mesaAttr]->Ptr; } @@ -432,7 +432,7 @@ setup_non_interleaved_attribs(GLcontext *ctx, /*printf("stobj %u = %p\n", attr, (void*) stobj);*/ vbuffer[attr].buffer = NULL; - pipe_reference_buffer(pipe, &vbuffer[attr].buffer, stobj->buffer); + pipe_buffer_reference(pipe->screen, &vbuffer[attr].buffer, stobj->buffer); vbuffer[attr].buffer_offset = (unsigned) arrays[mesaAttr]->Ptr; velements[attr].src_offset = 0; } @@ -451,13 +451,13 @@ setup_non_interleaved_attribs(GLcontext *ctx, bytes = arrays[mesaAttr]->Size * _mesa_sizeof_type(arrays[mesaAttr]->Type); } - vbuffer[attr].buffer = pipe_user_buffer_create(pipe, + vbuffer[attr].buffer = pipe_user_buffer_create(pipe->screen, (void *) arrays[mesaAttr]->Ptr, bytes); } else { /* no array, use ctx->Current.Attrib[] value */ bytes = sizeof(ctx->Current.Attrib[0]); - vbuffer[attr].buffer = pipe_user_buffer_create(pipe, + vbuffer[attr].buffer = pipe_user_buffer_create(pipe->screen, (void *) ctx->Current.Attrib[mesaAttr], bytes); stride = 0; } @@ -581,12 +581,12 @@ st_draw_vbo(GLcontext *ctx, if (bufobj && bufobj->Name) { /* elements/indexes are in a real VBO */ struct st_buffer_object *stobj = st_buffer_object(bufobj); - pipe_reference_buffer(pipe, &indexBuf, stobj->buffer); + pipe_buffer_reference(pipe->screen, &indexBuf, stobj->buffer); indexOffset = (unsigned) ib->ptr / indexSize; } else { /* element/indicies are in user space memory */ - indexBuf = pipe_user_buffer_create(pipe, (void *) ib->ptr, + indexBuf = pipe_user_buffer_create(pipe->screen, (void *) ib->ptr, ib->count * indexSize); indexOffset = 0; } @@ -621,7 +621,7 @@ st_draw_vbo(GLcontext *ctx, } } - pipe_reference_buffer(pipe, &indexBuf, NULL); + pipe_buffer_reference(pipe->screen, &indexBuf, NULL); } else { /* non-indexed */ @@ -637,7 +637,7 @@ st_draw_vbo(GLcontext *ctx, /* unreference buffers (frees wrapped user-space buffer objects) */ for (attr = 0; attr < num_vbuffers; attr++) { - pipe_reference_buffer(pipe, &vbuffer[attr].buffer, NULL); + pipe_buffer_reference(pipe->screen, &vbuffer[attr].buffer, NULL); assert(!vbuffer[attr].buffer); } pipe->set_vertex_buffers(pipe, vp->num_inputs, vbuffer); @@ -750,7 +750,7 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(stobj->buffer); vbuffers[attr].buffer = NULL; - pipe_reference_buffer(pipe, &vbuffers[attr].buffer, stobj->buffer); + pipe_buffer_reference(pipe->screen, &vbuffers[attr].buffer, stobj->buffer); vbuffers[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; } @@ -762,7 +762,7 @@ st_feedback_draw_vbo(GLcontext *ctx, /* wrap user data */ vbuffers[attr].buffer - = pipe_user_buffer_create(pipe, (void *) arrays[mesaAttr]->Ptr, + = pipe_user_buffer_create(pipe->screen, (void *) arrays[mesaAttr]->Ptr, bytes); vbuffers[attr].buffer_offset = 0; velements[attr].src_offset = 0; @@ -784,7 +784,7 @@ st_feedback_draw_vbo(GLcontext *ctx, #endif /* map the attrib buffer */ - map = pipe_buffer_map(pipe, vbuffers[attr].buffer, + map = pipe_buffer_map(pipe->screen, vbuffers[attr].buffer, PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_vertex_buffer(draw, attr, map); } @@ -812,7 +812,7 @@ st_feedback_draw_vbo(GLcontext *ctx, return; } - map = pipe_buffer_map(pipe, index_buffer_handle, + map = pipe_buffer_map(pipe->screen, index_buffer_handle, PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_element_buffer(draw, indexSize, map); } @@ -823,7 +823,7 @@ st_feedback_draw_vbo(GLcontext *ctx, /* map constant buffers */ - mapped_constants = pipe_buffer_map(pipe, + mapped_constants = pipe_buffer_map(pipe->screen, st->state.constants[PIPE_SHADER_VERTEX].buffer, PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_constant_buffer(st->draw, mapped_constants, @@ -837,20 +837,20 @@ st_feedback_draw_vbo(GLcontext *ctx, /* unmap constant buffers */ - pipe_buffer_unmap(pipe, st->state.constants[PIPE_SHADER_VERTEX].buffer); + pipe_buffer_unmap(pipe->screen, st->state.constants[PIPE_SHADER_VERTEX].buffer); /* * unmap vertex/index buffers */ for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { if (draw->pt.vertex_buffer[i].buffer) { - pipe_buffer_unmap(pipe, draw->pt.vertex_buffer[i].buffer); - pipe_reference_buffer(pipe, &draw->pt.vertex_buffer[i].buffer, NULL); + pipe_buffer_unmap(pipe->screen, draw->pt.vertex_buffer[i].buffer); + pipe_buffer_reference(pipe->screen, &draw->pt.vertex_buffer[i].buffer, NULL); draw_set_mapped_vertex_buffer(draw, i, NULL); } } if (ib) { - pipe_buffer_unmap(pipe, index_buffer_handle); + pipe_buffer_unmap(pipe->screen, index_buffer_handle); draw_set_mapped_element_buffer(draw, 0, NULL); } } diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 6db9bc0dd5..b9d114b1c9 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -128,10 +128,10 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice, PIPE_BUFFER_USAGE_CPU_WRITE); - srcData = (ubyte *) pipe_buffer_map(pipe, srcSurf->buffer, + srcData = (ubyte *) pipe_buffer_map(pipe->screen, srcSurf->buffer, PIPE_BUFFER_USAGE_CPU_READ) + srcSurf->offset; - dstData = (ubyte *) pipe_buffer_map(pipe, dstSurf->buffer, + dstData = (ubyte *) pipe_buffer_map(pipe->screen, dstSurf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE) + dstSurf->offset; @@ -144,8 +144,8 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, dstSurf->stride, /* stride in bytes */ dstData); - pipe_buffer_unmap(pipe, srcSurf->buffer); - pipe_buffer_unmap(pipe, dstSurf->buffer); + pipe_buffer_unmap(pipe->screen, srcSurf->buffer); + pipe_buffer_unmap(pipe->screen, dstSurf->buffer); pipe_surface_reference(&srcSurf, NULL); pipe_surface_reference(&dstSurf, NULL); -- cgit v1.2.3 From 79200c908790238374c6059b9f781c9873584d95 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 5 Sep 2008 10:10:55 -0600 Subject: gallium: document that clear color is intentionally always PIPE_FORMAT_A8R8G8B8_UNORM --- src/mesa/state_tracker/st_cb_clear.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 013b9a9c9c..47ad3c2bc1 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -414,6 +414,9 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) /* clear whole buffer w/out masking */ struct st_renderbuffer *strb = st_renderbuffer(rb); uint clearValue; + /* NOTE: we always pass the clear color as PIPE_FORMAT_A8R8G8B8_UNORM + * at this time! + */ util_pack_color(ctx->Color.ClearColor, PIPE_FORMAT_A8R8G8B8_UNORM, &clearValue); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } -- cgit v1.2.3 From 6c6c2f1d23b02491c60e0cbce6815b468ff14c08 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Oct 2008 09:55:54 -0600 Subject: gallium: add some checks for null surface pointers in state tracker Fixes some segfaults in low memory situations. --- src/mesa/state_tracker/st_atom_framebuffer.c | 8 ++++---- src/mesa/state_tracker/st_cb_clear.c | 26 +++++++++++++++++++------- src/mesa/state_tracker/st_framebuffer.c | 3 ++- 3 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index 80df3b0506..2916886610 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -118,9 +118,10 @@ update_framebuffer_state( struct st_context *st ) update_renderbuffer_surface(st, strb); } - assert(strb->surface); - framebuffer->cbufs[framebuffer->num_cbufs] = strb->surface; - framebuffer->num_cbufs++; + if (strb->surface) { + framebuffer->cbufs[framebuffer->num_cbufs] = strb->surface; + framebuffer->num_cbufs++; + } } } @@ -132,7 +133,6 @@ update_framebuffer_state( struct st_context *st ) update_renderbuffer_surface(st, strb); } - assert(strb->surface); framebuffer->zsbuf = strb->surface; } else { diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 47ad3c2bc1..bc3055c3fd 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -406,13 +406,17 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + + if (!strb->surface) + return; + if (check_clear_color_with_quad( ctx, rb )) { /* masking or scissoring */ clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE); } else { /* clear whole buffer w/out masking */ - struct st_renderbuffer *strb = st_renderbuffer(rb); uint clearValue; /* NOTE: we always pass the clear color as PIPE_FORMAT_A8R8G8B8_UNORM * at this time! @@ -426,13 +430,16 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + + if (!strb->surface) + return; + if (check_clear_depth_with_quad(ctx, rb)) { /* scissoring or we have a combined depth/stencil buffer */ clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE); } else { - struct st_renderbuffer *strb = st_renderbuffer(rb); - /* simple clear of whole buffer */ uint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); @@ -443,13 +450,16 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + + if (!strb->surface) + return; + if (check_clear_stencil_with_quad(ctx, rb)) { /* masking or scissoring or combined depth/stencil buffer */ clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE); } else { - struct st_renderbuffer *strb = st_renderbuffer(rb); - /* simple clear of whole buffer */ GLuint clearValue = ctx->Stencil.Clear; @@ -469,14 +479,16 @@ clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + + if (!strb->surface) + return; if (check_clear_depth_stencil_with_quad(ctx, rb)) { /* masking or scissoring */ clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE); } else { - struct st_renderbuffer *strb = st_renderbuffer(rb); - /* clear whole buffer w/out masking */ GLuint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear); diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index ec8928f200..6ee1777fb7 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -289,7 +289,8 @@ st_notify_swapbuffers_complete(struct st_framebuffer *stfb) for (i = 0; i < BUFFER_COUNT; i++) { if (stfb->Base.Attachment[i].Renderbuffer) { strb = st_renderbuffer(stfb->Base.Attachment[i].Renderbuffer); - strb->surface->status = PIPE_SURFACE_STATUS_UNDEFINED; + if (strb->surface) + strb->surface->status = PIPE_SURFACE_STATUS_UNDEFINED; } } } -- cgit v1.2.3 From 1c6fe6564be28ac3e72fa8e6b1616ae0e22a7bc7 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 30 Oct 2008 16:47:20 +0900 Subject: softpipe: Don't call pipe_buffer_destroy directly. Use pipe_buffer_reference instead. --- src/mesa/state_tracker/st_cb_bitmap.c | 2 +- src/mesa/state_tracker/st_cb_clear.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 694104f9cf..3d508227e1 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -779,7 +779,7 @@ st_destroy_bitmap(struct st_context *st) } if (st->bitmap.vbuf) { - pipe_buffer_destroy(pipe->screen, st->bitmap.vbuf); + pipe_buffer_reference(pipe->screen, &st->bitmap.vbuf, NULL); st->bitmap.vbuf = NULL; } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 47ad3c2bc1..ee282e8e20 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -116,7 +116,7 @@ st_destroy_clear(struct st_context *st) st->clear.vs = NULL; } if (st->clear.vbuf) { - pipe_buffer_destroy(pipe->screen, st->clear.vbuf); + pipe_buffer_reference(pipe->screen, &st->clear.vbuf, NULL); st->clear.vbuf = NULL; } } -- cgit v1.2.3 From d2c2e9316d043ab584794a3524f22776deb4c777 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 12 Dec 2008 16:46:34 +0000 Subject: gallium: avoid mapping same vertex buffer in subsequent frames Quite a few util modules were maintaining a single vertex buffer over multiple frames, and potentially reusing it in subsequent frames. Unfortunately that would force us into syncrhonous rendering as the buffer manager would be forced to wait for the previous rendering to complete prior to allowing the map. This resolves that issue, but requires the state tracker to issue a few new flush() calls at the end of each frame. --- src/gallium/auxiliary/util/u_blit.c | 88 ++++++++++++++++++++++--------- src/gallium/auxiliary/util/u_blit.h | 4 ++ src/gallium/auxiliary/util/u_draw_quad.c | 5 +- src/gallium/auxiliary/util/u_draw_quad.h | 2 +- src/gallium/auxiliary/util/u_gen_mipmap.c | 51 +++++++++++++++--- src/gallium/auxiliary/util/u_gen_mipmap.h | 5 ++ src/mesa/state_tracker/st_cb_accum.c | 3 +- src/mesa/state_tracker/st_cb_bitmap.c | 60 +++++++++++++++------ src/mesa/state_tracker/st_cb_bitmap.h | 6 +++ src/mesa/state_tracker/st_cb_clear.c | 31 +++++++++-- src/mesa/state_tracker/st_cb_clear.h | 3 ++ src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_cb_fbo.c | 2 +- src/mesa/state_tracker/st_cb_flush.c | 11 +++- src/mesa/state_tracker/st_cb_readpixels.c | 4 +- src/mesa/state_tracker/st_context.h | 2 + 16 files changed, 219 insertions(+), 60 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index d28201ac8d..2cef3338b5 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -66,6 +66,8 @@ struct blit_state void *fs; struct pipe_buffer *vbuf; /**< quad vertices */ + unsigned vbuf_slot; + float vertices[4][2][4]; /**< vertex/texcoords for quad */ }; @@ -138,17 +140,7 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso) /* fragment shader */ ctx->fs = util_make_fragment_tex_shader(pipe, &ctx->frag_shader); - - ctx->vbuf = pipe_buffer_create(pipe->screen, - 32, - PIPE_BUFFER_USAGE_VERTEX, - sizeof(ctx->vertices)); - if (!ctx->vbuf) { - FREE(ctx); - ctx->pipe->delete_fs_state(ctx->pipe, ctx->fs); - ctx->pipe->delete_vs_state(ctx->pipe, ctx->vs); - return NULL; - } + ctx->vbuf = NULL; /* init vertex data that doesn't change */ for (i = 0; i < 4; i++) { @@ -181,15 +173,35 @@ util_destroy_blit(struct blit_state *ctx) } +static unsigned get_next_slot( struct blit_state *ctx ) +{ + const unsigned max_slots = 4096 / sizeof ctx->vertices; + + if (ctx->vbuf_slot >= max_slots) + util_blit_flush( ctx ); + + if (!ctx->vbuf) { + ctx->vbuf = pipe_buffer_create(ctx->pipe->screen, + 32, + PIPE_BUFFER_USAGE_VERTEX, + max_slots * sizeof ctx->vertices); + } + + return ctx->vbuf_slot++ * sizeof ctx->vertices; +} + + + /** * Setup vertex data for the textured quad we'll draw. * Note: y=0=top */ -static void +static unsigned setup_vertex_data(struct blit_state *ctx, float x0, float y0, float x1, float y1, float z) { void *buf; + unsigned offset; ctx->vertices[0][0][0] = x0; ctx->vertices[0][0][1] = y0; @@ -215,12 +227,16 @@ setup_vertex_data(struct blit_state *ctx, ctx->vertices[3][1][0] = 0.0f; ctx->vertices[3][1][1] = 1.0f; + offset = get_next_slot( ctx ); + buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); - memcpy(buf, ctx->vertices, sizeof(ctx->vertices)); + memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices)); pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf); + + return offset; } @@ -228,13 +244,14 @@ setup_vertex_data(struct blit_state *ctx, * Setup vertex data for the textured quad we'll draw. * Note: y=0=top */ -static void +static unsigned setup_vertex_data_tex(struct blit_state *ctx, float x0, float y0, float x1, float y1, float s0, float t0, float s1, float t1, float z) { void *buf; + unsigned offset; ctx->vertices[0][0][0] = x0; ctx->vertices[0][0][1] = y0; @@ -260,12 +277,16 @@ setup_vertex_data_tex(struct blit_state *ctx, ctx->vertices[3][1][0] = s0; ctx->vertices[3][1][1] = t1; + offset = get_next_slot( ctx ); + buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); - memcpy(buf, ctx->vertices, sizeof(ctx->vertices)); + memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices)); pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf); + + return offset; } /** * Copy pixel block from src surface to dst surface. @@ -291,6 +312,7 @@ util_blit_pixels(struct blit_state *ctx, const int srcH = abs(srcY1 - srcY0); const int srcLeft = MIN2(srcX0, srcX1); const int srcTop = MIN2(srcY0, srcY1); + unsigned offset; assert(filter == PIPE_TEX_MIPFILTER_NEAREST || filter == PIPE_TEX_MIPFILTER_LINEAR); @@ -398,11 +420,11 @@ util_blit_pixels(struct blit_state *ctx, cso_set_framebuffer(ctx->cso, &fb); /* draw quad */ - setup_vertex_data(ctx, - (float) dstX0, (float) dstY0, - (float) dstX1, (float) dstY1, z); + offset = setup_vertex_data(ctx, + (float) dstX0, (float) dstY0, + (float) dstX1, (float) dstY1, z); - util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, + util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, offset, PIPE_PRIM_TRIANGLE_FAN, 4, /* verts */ 2); /* attribs/vert */ @@ -421,6 +443,18 @@ util_blit_pixels(struct blit_state *ctx, screen->texture_release(screen, &tex); } + +/* Release vertex buffer at end of frame to avoid synchronous + * rendering. + */ +void util_blit_flush( struct blit_state *ctx ) +{ + pipe_buffer_reference(ctx->pipe->screen, &ctx->vbuf, NULL); + ctx->vbuf_slot = 0; +} + + + /** * Copy pixel block from src texture to dst surface. * Overlapping regions are acceptable. @@ -442,6 +476,7 @@ util_blit_pixels_tex(struct blit_state *ctx, struct pipe_screen *screen = pipe->screen; struct pipe_framebuffer_state fb; float s0, t0, s1, t1; + unsigned offset; assert(filter == PIPE_TEX_MIPFILTER_NEAREST || filter == PIPE_TEX_MIPFILTER_LINEAR); @@ -496,13 +531,14 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_set_framebuffer(ctx->cso, &fb); /* draw quad */ - setup_vertex_data_tex(ctx, - (float) dstX0, (float) dstY0, - (float) dstX1, (float) dstY1, - s0, t0, s1, t1, - z); - - util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, + offset = setup_vertex_data_tex(ctx, + (float) dstX0, (float) dstY0, + (float) dstX1, (float) dstY1, + s0, t0, s1, t1, + z); + + util_draw_vertex_buffer(ctx->pipe, + ctx->vbuf, offset, PIPE_PRIM_TRIANGLE_FAN, 4, /* verts */ 2); /* attribs/vert */ diff --git a/src/gallium/auxiliary/util/u_blit.h b/src/gallium/auxiliary/util/u_blit.h index 308075698f..c35beceda8 100644 --- a/src/gallium/auxiliary/util/u_blit.h +++ b/src/gallium/auxiliary/util/u_blit.h @@ -70,6 +70,10 @@ util_blit_pixels_tex(struct blit_state *ctx, int dstX1, int dstY1, float z, uint filter); +/* Call at end of frame to avoid synchronous rendering. + */ +extern void +util_blit_flush( struct blit_state *ctx ); #ifdef __cplusplus } diff --git a/src/gallium/auxiliary/util/u_draw_quad.c b/src/gallium/auxiliary/util/u_draw_quad.c index 8ecae71b64..d7bb74b87b 100644 --- a/src/gallium/auxiliary/util/u_draw_quad.c +++ b/src/gallium/auxiliary/util/u_draw_quad.c @@ -40,6 +40,7 @@ void util_draw_vertex_buffer(struct pipe_context *pipe, struct pipe_buffer *vbuf, + uint offset, uint prim_type, uint num_verts, uint num_attribs) @@ -53,7 +54,7 @@ util_draw_vertex_buffer(struct pipe_context *pipe, /* tell pipe about the vertex buffer */ vbuffer.buffer = vbuf; vbuffer.pitch = num_attribs * 4 * sizeof(float); /* vertex size */ - vbuffer.buffer_offset = 0; + vbuffer.buffer_offset = offset; pipe->set_vertex_buffers(pipe, 1, &vbuffer); /* tell pipe about the vertex attributes */ @@ -124,7 +125,7 @@ util_draw_texquad(struct pipe_context *pipe, v[29] = 1.0; pipe_buffer_unmap(pipe->screen, vbuf); - util_draw_vertex_buffer(pipe, vbuf, PIPE_PRIM_TRIANGLE_FAN, 4, 2); + util_draw_vertex_buffer(pipe, vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, 2); } pipe_buffer_reference(pipe->screen, &vbuf, NULL); diff --git a/src/gallium/auxiliary/util/u_draw_quad.h b/src/gallium/auxiliary/util/u_draw_quad.h index ec4862ead3..00d3f5b715 100644 --- a/src/gallium/auxiliary/util/u_draw_quad.h +++ b/src/gallium/auxiliary/util/u_draw_quad.h @@ -37,7 +37,7 @@ struct pipe_buffer; extern void util_draw_vertex_buffer(struct pipe_context *pipe, - struct pipe_buffer *vbuf, + struct pipe_buffer *vbuf, uint offset, uint num_attribs, uint num_verts, uint prim_type); diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 9d305ad763..5f395ec6e9 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -69,6 +69,8 @@ struct gen_mipmap_state void *fs; struct pipe_buffer *vbuf; /**< quad vertices */ + unsigned vbuf_slot; + float vertices[4][2][4]; /**< vertex/texcoords for quad */ }; @@ -779,10 +781,28 @@ util_create_gen_mipmap(struct pipe_context *pipe, } -static void +static unsigned get_next_slot( struct gen_mipmap_state *ctx ) +{ + const unsigned max_slots = 4096 / sizeof ctx->vertices; + + if (ctx->vbuf_slot >= max_slots) + util_gen_mipmap_flush( ctx ); + + if (!ctx->vbuf) { + ctx->vbuf = pipe_buffer_create(ctx->pipe->screen, + 32, + PIPE_BUFFER_USAGE_VERTEX, + max_slots * sizeof ctx->vertices); + } + + return ctx->vbuf_slot++ * sizeof ctx->vertices; +} + +static unsigned set_vertex_data(struct gen_mipmap_state *ctx, float width, float height) { void *buf; + unsigned offset; ctx->vertices[0][0][0] = 0.0f; /*x*/ ctx->vertices[0][0][1] = 0.0f; /*y*/ @@ -804,12 +824,16 @@ set_vertex_data(struct gen_mipmap_state *ctx, float width, float height) ctx->vertices[3][1][0] = 0.0f; ctx->vertices[3][1][1] = 1.0f; + offset = get_next_slot( ctx ); + buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); - memcpy(buf, ctx->vertices, sizeof(ctx->vertices)); + memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices)); pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf); + + return offset; } @@ -834,6 +858,17 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx) } + +/* Release vertex buffer at end of frame to avoid synchronous + * rendering. + */ +void util_gen_mipmap_flush( struct gen_mipmap_state *ctx ) +{ + pipe_buffer_reference(ctx->pipe->screen, &ctx->vbuf, NULL); + ctx->vbuf_slot = 0; +} + + /** * Generate mipmap images. It's assumed all needed texture memory is * already allocated. @@ -855,6 +890,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, struct pipe_framebuffer_state fb; uint dstLevel; uint zslice = 0; + uint offset; /* check if we can render in the texture's format */ if (!screen->is_format_supported(screen, pt->format, PIPE_TEXTURE_2D, @@ -925,10 +961,13 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, cso_set_sampler_textures(ctx->cso, 1, &pt); /* quad coords in window coords (bypassing clipping, viewport mapping) */ - set_vertex_data(ctx, - (float) pt->width[dstLevel], - (float) pt->height[dstLevel]); - util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, + offset = set_vertex_data(ctx, + (float) pt->width[dstLevel], + (float) pt->height[dstLevel]); + + util_draw_vertex_buffer(ctx->pipe, + ctx->vbuf, + offset, PIPE_PRIM_TRIANGLE_FAN, 4, /* verts */ 2); /* attribs/vert */ diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.h b/src/gallium/auxiliary/util/u_gen_mipmap.h index 3277024f07..54608f9466 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.h +++ b/src/gallium/auxiliary/util/u_gen_mipmap.h @@ -50,6 +50,11 @@ util_create_gen_mipmap(struct pipe_context *pipe, struct cso_context *cso); extern void util_destroy_gen_mipmap(struct gen_mipmap_state *ctx); +/* Release vertex buffer at end of frame to avoid synchronous + * rendering. + */ +extern void +util_gen_mipmap_flush( struct gen_mipmap_state *ctx ); extern void diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index cf3a99e7e9..a4e72b48ed 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -38,6 +38,7 @@ #include "st_cb_accum.h" #include "st_cb_fbo.h" #include "st_draw.h" +#include "st_public.h" #include "st_format.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -324,7 +325,7 @@ st_Accum(GLcontext *ctx, GLenum op, GLfloat value) const GLint height = ctx->DrawBuffer->_Ymax - ypos; /* make sure color bufs aren't cached */ - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + st_flush( st, PIPE_FLUSH_RENDER_CACHE, NULL ); switch (op) { case GL_ADD: diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 73645201cc..bc05ca6a2f 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -349,8 +349,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, return pt; } - -static void +static GLuint setup_bitmap_vertex_data(struct st_context *st, int x, int y, int width, int height, float z, const float color[4]) @@ -369,12 +368,18 @@ setup_bitmap_vertex_data(struct st_context *st, const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0); const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0); const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0); + const GLuint max_slots = 4096 / sizeof(st->bitmap.vertices); GLuint i; - void *buf; + + if (st->bitmap.vbuf_slot >= max_slots) { + pipe_buffer_reference(pipe->screen, &st->bitmap.vbuf, NULL); + st->bitmap.vbuf_slot = 0; + } if (!st->bitmap.vbuf) { - st->bitmap.vbuf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX, - sizeof(st->bitmap.vertices)); + st->bitmap.vbuf = pipe_buffer_create(pipe->screen, 32, + PIPE_BUFFER_USAGE_VERTEX, + max_slots * sizeof(st->bitmap.vertices)); } /* Positions are in clip coords since we need to do clipping in case @@ -413,9 +418,19 @@ setup_bitmap_vertex_data(struct st_context *st, } /* put vertex data into vbuf */ - buf = pipe_buffer_map(pipe->screen, st->bitmap.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); - memcpy(buf, st->bitmap.vertices, sizeof(st->bitmap.vertices)); - pipe_buffer_unmap(pipe->screen, st->bitmap.vbuf); + { + char *buf = pipe_buffer_map(pipe->screen, + st->bitmap.vbuf, + PIPE_BUFFER_USAGE_CPU_WRITE); + + memcpy(buf + st->bitmap.vbuf_slot * sizeof st->bitmap.vertices, + st->bitmap.vertices, + sizeof st->bitmap.vertices); + + pipe_buffer_unmap(pipe->screen, st->bitmap.vbuf); + } + + return st->bitmap.vbuf_slot++ * sizeof st->bitmap.vertices; } @@ -434,6 +449,7 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, struct cso_context *cso = ctx->st->cso_context; struct st_fragment_program *stfp; GLuint maxSize; + GLuint offset; stfp = combined_bitmap_fragment_program(ctx); @@ -518,11 +534,11 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, } /* draw textured quad */ - setup_bitmap_vertex_data(st, x, y, width, height, - ctx->Current.RasterPos[2], - color); + offset = setup_bitmap_vertex_data(st, x, y, width, height, + ctx->Current.RasterPos[2], + color); - util_draw_vertex_buffer(pipe, st->bitmap.vbuf, + util_draw_vertex_buffer(pipe, st->bitmap.vbuf, offset, PIPE_PRIM_TRIANGLE_FAN, 4, /* verts */ 3); /* attribs/vert */ @@ -592,12 +608,12 @@ st_flush_bitmap_cache(struct st_context *st) struct pipe_screen *screen = pipe->screen; assert(cache->xmin <= cache->xmax); - /* - printf("flush size %d x %d at %d, %d\n", + +/* printf("flush size %d x %d at %d, %d\n", cache->xmax - cache->xmin, cache->ymax - cache->ymin, cache->xpos, cache->ypos); - */ +*/ /* The texture surface has been mapped until now. * So unmap and release the texture surface before drawing. @@ -623,6 +639,20 @@ st_flush_bitmap_cache(struct st_context *st) } } +/* Flush bitmap cache and release vertex buffer. + */ +void +st_flush_bitmap( struct st_context *st ) +{ + st_flush_bitmap_cache(st); + + /* Release vertex buffer to avoid synchronous rendering if we were + * to map it in the next frame. + */ + pipe_buffer_reference(st->pipe->screen, &st->bitmap.vbuf, NULL); + st->bitmap.vbuf_slot = 0; +} + /** * Try to accumulate this glBitmap call in the bitmap cache. diff --git a/src/mesa/state_tracker/st_cb_bitmap.h b/src/mesa/state_tracker/st_cb_bitmap.h index aae11d34c9..81cf61981d 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.h +++ b/src/mesa/state_tracker/st_cb_bitmap.h @@ -42,5 +42,11 @@ st_destroy_bitmap(struct st_context *st); extern void st_flush_bitmap_cache(struct st_context *st); +/* Flush bitmap cache and release vertex buffer. Needed at end of + * frame to avoid synchronous rendering. + */ +extern void +st_flush_bitmap(struct st_context *st); + #endif /* ST_CB_BITMAP_H */ diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index bc3055c3fd..b6cea16163 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -148,12 +148,18 @@ draw_quad(GLcontext *ctx, { struct st_context *st = ctx->st; struct pipe_context *pipe = st->pipe; + const GLuint max_slots = 1024 / sizeof(st->clear.vertices); GLuint i; void *buf; + if (st->clear.vbuf_slot >= max_slots) { + pipe_buffer_reference(pipe->screen, &st->clear.vbuf, NULL); + st->clear.vbuf_slot = 0; + } + if (!st->clear.vbuf) { st->clear.vbuf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX, - sizeof(st->clear.vertices)); + max_slots * sizeof(st->clear.vertices)); } /* positions */ @@ -181,14 +187,23 @@ draw_quad(GLcontext *ctx, /* put vertex data into vbuf */ buf = pipe_buffer_map(pipe->screen, st->clear.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); - memcpy(buf, st->clear.vertices, sizeof(st->clear.vertices)); + + memcpy((char *)buf + st->clear.vbuf_slot * sizeof(st->clear.vertices), + st->clear.vertices, + sizeof(st->clear.vertices)); + pipe_buffer_unmap(pipe->screen, st->clear.vbuf); /* draw */ - util_draw_vertex_buffer(pipe, st->clear.vbuf, + util_draw_vertex_buffer(pipe, + st->clear.vbuf, + st->clear.vbuf_slot * sizeof(st->clear.vertices), PIPE_PRIM_TRIANGLE_FAN, 4, /* verts */ 2); /* attribs/vert */ + + /* Increment slot */ + st->clear.vbuf_slot++; } @@ -508,6 +523,16 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) } +void st_flush_clear( struct st_context *st ) +{ + /* Release vertex buffer to avoid synchronous rendering if we were + * to map it in the next frame. + */ + pipe_buffer_reference(st->pipe->screen, &st->clear.vbuf, NULL); + st->clear.vbuf_slot = 0; +} + + /** * Called via ctx->Driver.Clear() diff --git a/src/mesa/state_tracker/st_cb_clear.h b/src/mesa/state_tracker/st_cb_clear.h index f49387747d..bc035ac25c 100644 --- a/src/mesa/state_tracker/st_cb_clear.h +++ b/src/mesa/state_tracker/st_cb_clear.h @@ -37,6 +37,9 @@ st_init_clear(struct st_context *st); extern void st_destroy_clear(struct st_context *st); +extern void +st_flush_clear(struct st_context *st); + extern void st_init_clear_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 5b24b9f068..32bf21411d 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -494,7 +494,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, memcpy(map, verts, sizeof(verts)); pipe_buffer_unmap(pipe->screen, buf); - util_draw_vertex_buffer(pipe, buf, + util_draw_vertex_buffer(pipe, buf, 0, PIPE_PRIM_QUADS, 4, /* verts */ 3); /* attribs/vert */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 00076f61e0..eece7dee11 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -426,7 +426,7 @@ st_finish_render_texture(GLcontext *ctx, if (!strb) return; - ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + st_flush( ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL ); if (strb->surface) screen->tex_surface_release( screen, &strb->surface ); diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c index cc40467941..072f2e92ad 100644 --- a/src/mesa/state_tracker/st_cb_flush.c +++ b/src/mesa/state_tracker/st_cb_flush.c @@ -37,11 +37,14 @@ #include "st_context.h" #include "st_cb_bitmap.h" #include "st_cb_flush.h" +#include "st_cb_clear.h" #include "st_cb_fbo.h" #include "st_public.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_winsys.h" +#include "util/u_gen_mipmap.h" +#include "util/u_blit.h" static INLINE GLboolean @@ -78,7 +81,13 @@ void st_flush( struct st_context *st, uint pipeFlushFlags, { FLUSH_VERTICES(st->ctx, 0); - st_flush_bitmap_cache(st); + /* Release any vertex buffers that might potentially be accessed in + * successive frames: + */ + st_flush_bitmap(st); + st_flush_clear(st); + util_blit_flush(st->blit); + util_gen_mipmap_flush(st->gen_mipmap); st->pipe->flush( st->pipe, pipeFlushFlags, fence ); } diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index c801532788..646eaff190 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -317,10 +317,8 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (!dest) return; - st_flush_bitmap_cache(ctx->st); - /* make sure rendering has completed */ - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); if (format == GL_STENCIL_INDEX) { st_read_stencil_pixels(ctx, x, y, width, height, type, pack, dest); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 5bcb87ce20..695ac4a96f 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -154,6 +154,7 @@ struct st_context void *vs; float vertices[4][3][4]; /**< vertex pos + color + texcoord */ struct pipe_buffer *vbuf; + unsigned vbuf_slot; /* next free slot in vbuf */ struct bitmap_cache *cache; } bitmap; @@ -173,6 +174,7 @@ struct st_context void *fs; float vertices[4][2][4]; /**< vertex pos + color */ struct pipe_buffer *vbuf; + unsigned vbuf_slot; } clear; void *passthrough_fs; /**< simple pass-through frag shader */ -- cgit v1.2.3 From a7e72231e3c76a9410d192441da309002ea6422d Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 26 Jan 2009 14:37:21 -0500 Subject: gallium: standardize naming of masks --- src/gallium/drivers/cell/ppu/cell_gen_fragment.c | 42 +++++++++++----------- .../drivers/cell/ppu/cell_state_per_fragment.c | 16 ++++----- src/gallium/drivers/i915simple/i915_state.c | 8 ++--- src/gallium/drivers/i965simple/brw_cc.c | 12 +++---- src/gallium/drivers/i965simple/brw_wm.c | 4 +-- src/gallium/drivers/nv10/nv10_state.c | 4 +-- src/gallium/drivers/nv20/nv20_state.c | 4 +-- src/gallium/drivers/nv30/nv30_state.c | 8 ++--- src/gallium/drivers/nv40/nv40_state.c | 8 ++--- src/gallium/drivers/nv50/nv50_state.c | 8 ++--- src/gallium/drivers/softpipe/sp_quad_stencil.c | 4 +-- src/gallium/drivers/trace/tr_state.c | 4 +-- src/gallium/include/pipe/p_state.h | 6 ++-- src/gallium/state_trackers/g3dvl/vl_context.c | 4 +-- src/mesa/state_tracker/st_atom_depth.c | 8 ++--- src/mesa/state_tracker/st_cb_clear.c | 4 +-- 16 files changed, 72 insertions(+), 72 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_clear.c') diff --git a/src/gallium/drivers/cell/ppu/cell_gen_fragment.c b/src/gallium/drivers/cell/ppu/cell_gen_fragment.c index 0ea8f017ef..9bdc71b676 100644 --- a/src/gallium/drivers/cell/ppu/cell_gen_fragment.c +++ b/src/gallium/drivers/cell/ppu/cell_gen_fragment.c @@ -1187,7 +1187,7 @@ gen_stencil_test(struct spe_function *f, */ switch (state->func) { case PIPE_FUNC_EQUAL: - if (state->value_mask == stencil_max_value) { + if (state->valuemask == stencil_max_value) { /* stencil_pass = fragment_mask & (s == reference) */ spe_compare_equal_uint(f, stencil_pass_reg, fbS_reg, state->ref_value); spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); @@ -1195,16 +1195,16 @@ gen_stencil_test(struct spe_function *f, else { /* stencil_pass = fragment_mask & ((s&mask) == (reference&mask)) */ uint tmp_masked_stencil = spe_allocate_available_register(f); - spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->value_mask); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); spe_compare_equal_uint(f, stencil_pass_reg, tmp_masked_stencil, - state->value_mask & state->ref_value); + state->valuemask & state->ref_value); spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); spe_release_register(f, tmp_masked_stencil); } break; case PIPE_FUNC_NOTEQUAL: - if (state->value_mask == stencil_max_value) { + if (state->valuemask == stencil_max_value) { /* stencil_pass = fragment_mask & ~(s == reference) */ spe_compare_equal_uint(f, stencil_pass_reg, fbS_reg, state->ref_value); spe_andc(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); @@ -1212,16 +1212,16 @@ gen_stencil_test(struct spe_function *f, else { /* stencil_pass = fragment_mask & ~((s&mask) == (reference&mask)) */ int tmp_masked_stencil = spe_allocate_available_register(f); - spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->value_mask); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); spe_compare_equal_uint(f, stencil_pass_reg, tmp_masked_stencil, - state->value_mask & state->ref_value); + state->valuemask & state->ref_value); spe_andc(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); spe_release_register(f, tmp_masked_stencil); } break; case PIPE_FUNC_LESS: - if (state->value_mask == stencil_max_value) { + if (state->valuemask == stencil_max_value) { /* stencil_pass = fragment_mask & (reference < s) */ spe_compare_greater_uint(f, stencil_pass_reg, fbS_reg, state->ref_value); spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); @@ -1229,16 +1229,16 @@ gen_stencil_test(struct spe_function *f, else { /* stencil_pass = fragment_mask & ((reference&mask) < (s & mask)) */ int tmp_masked_stencil = spe_allocate_available_register(f); - spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->value_mask); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); spe_compare_greater_uint(f, stencil_pass_reg, tmp_masked_stencil, - state->value_mask & state->ref_value); + state->valuemask & state->ref_value); spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); spe_release_register(f, tmp_masked_stencil); } break; case PIPE_FUNC_GREATER: - if (state->value_mask == stencil_max_value) { + if (state->valuemask == stencil_max_value) { /* stencil_pass = fragment_mask & (reference > s) */ /* There's no convenient Compare Less Than Immediate instruction, so * we'll have to do this one the harder way, by loading a register and @@ -1255,8 +1255,8 @@ gen_stencil_test(struct spe_function *f, /* stencil_pass = fragment_mask & ((reference&mask) > (s&mask)) */ int tmp_reg = spe_allocate_available_register(f); int tmp_masked_stencil = spe_allocate_available_register(f); - spe_load_uint(f, tmp_reg, state->value_mask & state->ref_value); - spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->value_mask); + spe_load_uint(f, tmp_reg, state->valuemask & state->ref_value); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); spe_clgt(f, stencil_pass_reg, tmp_reg, tmp_masked_stencil); spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); spe_release_register(f, tmp_reg); @@ -1265,7 +1265,7 @@ gen_stencil_test(struct spe_function *f, break; case PIPE_FUNC_GEQUAL: - if (state->value_mask == stencil_max_value) { + if (state->valuemask == stencil_max_value) { /* stencil_pass = fragment_mask & (reference >= s) * = fragment_mask & ~(s > reference) */ spe_compare_greater_uint(f, stencil_pass_reg, fbS_reg, @@ -1275,16 +1275,16 @@ gen_stencil_test(struct spe_function *f, else { /* stencil_pass = fragment_mask & ~((s&mask) > (reference&mask)) */ int tmp_masked_stencil = spe_allocate_available_register(f); - spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->value_mask); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); spe_compare_greater_uint(f, stencil_pass_reg, tmp_masked_stencil, - state->value_mask & state->ref_value); + state->valuemask & state->ref_value); spe_andc(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); spe_release_register(f, tmp_masked_stencil); } break; case PIPE_FUNC_LEQUAL: - if (state->value_mask == stencil_max_value) { + if (state->valuemask == stencil_max_value) { /* stencil_pass = fragment_mask & (reference <= s) ] * = fragment_mask & ~(reference > s) */ /* As above, we have to do this by loading a register */ @@ -1298,8 +1298,8 @@ gen_stencil_test(struct spe_function *f, /* stencil_pass = fragment_mask & ~((reference&mask) > (s&mask)) */ int tmp_reg = spe_allocate_available_register(f); int tmp_masked_stencil = spe_allocate_available_register(f); - spe_load_uint(f, tmp_reg, state->ref_value & state->value_mask); - spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->value_mask); + spe_load_uint(f, tmp_reg, state->ref_value & state->valuemask); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); spe_clgt(f, stencil_pass_reg, tmp_reg, tmp_masked_stencil); spe_andc(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); spe_release_register(f, tmp_reg); @@ -1600,14 +1600,14 @@ gen_stencil_depth_test(struct spe_function *f, need_to_calculate_stencil_values = FALSE; need_to_writemask_stencil_values = FALSE; } - else if (stencil->write_mask == 0x0) { + else if (stencil->writemask == 0x0) { /* All changes are writemasked out, so no need to calculate * what those changes might be, and no need to write anything back. */ need_to_calculate_stencil_values = FALSE; need_to_writemask_stencil_values = FALSE; } - else if (stencil->write_mask == 0xff) { + else if (stencil->writemask == 0xff) { /* Still trivial, but a little less so. We need to write the stencil * values, but we don't need to mask them. */ @@ -1627,7 +1627,7 @@ gen_stencil_depth_test(struct spe_function *f, */ spe_comment(f, 0, "Computing stencil writemask"); stencil_writemask_reg = spe_allocate_available_register(f); - spe_load_uint(f, stencil_writemask_reg, dsa->stencil[facing].write_mask); + spe_load_uint(f, stencil_writemask_reg, dsa->stencil[facing].writemask); } /* At least one-sided stenciling must be on. Generate code that diff --git a/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c b/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c index 78cb446c14..d97c22b2ef 100644 --- a/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c +++ b/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c @@ -297,7 +297,7 @@ emit_stencil_test(struct pipe_depth_stencil_alpha_state *dsa, int face_stencil = spe_allocate_available_register(f); int stencil_src = stencil; const unsigned ref = (dsa->stencil[face].ref_value - & dsa->stencil[face].value_mask); + & dsa->stencil[face].valuemask); boolean complement = FALSE; int stored; int tmp = spe_allocate_available_register(f); @@ -305,9 +305,9 @@ emit_stencil_test(struct pipe_depth_stencil_alpha_state *dsa, if ((dsa->stencil[face].func != PIPE_FUNC_NEVER) && (dsa->stencil[face].func != PIPE_FUNC_ALWAYS) - && (dsa->stencil[face].value_mask != 0x0ff)) { + && (dsa->stencil[face].valuemask != 0x0ff)) { stored = spe_allocate_available_register(f); - spe_andi(f, stored, stencil, dsa->stencil[face].value_mask); + spe_andi(f, stored, stencil, dsa->stencil[face].valuemask); } else { stored = stencil; } @@ -395,7 +395,7 @@ emit_stencil_test(struct pipe_depth_stencil_alpha_state *dsa, * - For depth-pass if the stencil test is NEVER * - Any of the 3 conditions if the operation is KEEP */ - if (dsa->stencil[face].write_mask != 0) { + if (dsa->stencil[face].writemask != 0) { if ((dsa->stencil[face].func != PIPE_FUNC_ALWAYS) && (dsa->stencil[face].fail_op != PIPE_STENCIL_OP_KEEP)) { if (complement) { @@ -449,10 +449,10 @@ emit_stencil_test(struct pipe_depth_stencil_alpha_state *dsa, */ if (stencil_src == stencil) { spe_release_register(f, face_stencil); - } else if (dsa->stencil[face].write_mask != 0x0ff) { + } else if (dsa->stencil[face].writemask != 0x0ff) { int tmp = spe_allocate_available_register(f); - spe_il(f, tmp, dsa->stencil[face].write_mask); + spe_il(f, tmp, dsa->stencil[face].writemask); spe_selb(f, stencil_src, stencil, stencil_src, tmp); spe_release_register(f, tmp); @@ -580,8 +580,8 @@ cell_generate_depth_stencil_test(struct cell_depth_stencil_alpha_state *cdsa) dsa->stencil[i].zpass_op); printf("# ref value / value mask / write mask: %02x %02x %02x\n", dsa->stencil[i].ref_value, - dsa->stencil[i].value_mask, - dsa->stencil[i].write_mask); + dsa->stencil[i].valuemask, + dsa->stencil[i].writemask); } printf("\t.text\n"); diff --git a/src/gallium/drivers/i915simple/i915_state.c b/src/gallium/drivers/i915simple/i915_state.c index d2487d8277..92365f6a7a 100644 --- a/src/gallium/drivers/i915simple/i915_state.c +++ b/src/gallium/drivers/i915simple/i915_state.c @@ -318,8 +318,8 @@ i915_create_depth_stencil_state(struct pipe_context *pipe, struct i915_depth_stencil_state *cso = CALLOC_STRUCT( i915_depth_stencil_state ); { - int testmask = depth_stencil->stencil[0].value_mask & 0xff; - int writemask = depth_stencil->stencil[0].write_mask & 0xff; + int testmask = depth_stencil->stencil[0].valuemask & 0xff; + int writemask = depth_stencil->stencil[0].writemask & 0xff; cso->stencil_modes4 |= (_3DSTATE_MODES_4_CMD | ENABLE_STENCIL_TEST_MASK | @@ -350,8 +350,8 @@ i915_create_depth_stencil_state(struct pipe_context *pipe, int dfop = i915_translate_stencil_op(depth_stencil->stencil[1].zfail_op); int dpop = i915_translate_stencil_op(depth_stencil->stencil[1].zpass_op); int ref = depth_stencil->stencil[1].ref_value & 0xff; - int tmask = depth_stencil->stencil[1].value_mask & 0xff; - int wmask = depth_stencil->stencil[1].write_mask & 0xff; + int tmask = depth_stencil->stencil[1].valuemask & 0xff; + int wmask = depth_stencil->stencil[1].writemask & 0xff; cso->bfo[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | BFO_ENABLE_STENCIL_FUNCS | diff --git a/src/gallium/drivers/i965simple/brw_cc.c b/src/gallium/drivers/i965simple/brw_cc.c index 79d4150383..6191e73d12 100644 --- a/src/gallium/drivers/i965simple/brw_cc.c +++ b/src/gallium/drivers/i965simple/brw_cc.c @@ -166,8 +166,8 @@ static void upload_cc_unit( struct brw_context *brw ) cc.cc0.stencil_pass_depth_pass_op = brw_translate_stencil_op( brw->attribs.DepthStencil->stencil[0].zpass_op); cc.cc1.stencil_ref = brw->attribs.DepthStencil->stencil[0].ref_value; - cc.cc1.stencil_write_mask = brw->attribs.DepthStencil->stencil[0].write_mask; - cc.cc1.stencil_test_mask = brw->attribs.DepthStencil->stencil[0].value_mask; + cc.cc1.stencil_write_mask = brw->attribs.DepthStencil->stencil[0].writemask; + cc.cc1.stencil_test_mask = brw->attribs.DepthStencil->stencil[0].valuemask; if (brw->attribs.DepthStencil->stencil[1].enabled) { cc.cc0.bf_stencil_enable = brw->attribs.DepthStencil->stencil[1].enabled; @@ -180,14 +180,14 @@ static void upload_cc_unit( struct brw_context *brw ) cc.cc0.bf_stencil_pass_depth_pass_op = brw_translate_stencil_op( brw->attribs.DepthStencil->stencil[1].zpass_op); cc.cc1.bf_stencil_ref = brw->attribs.DepthStencil->stencil[1].ref_value; - cc.cc2.bf_stencil_write_mask = brw->attribs.DepthStencil->stencil[1].write_mask; - cc.cc2.bf_stencil_test_mask = brw->attribs.DepthStencil->stencil[1].value_mask; + cc.cc2.bf_stencil_write_mask = brw->attribs.DepthStencil->stencil[1].writemask; + cc.cc2.bf_stencil_test_mask = brw->attribs.DepthStencil->stencil[1].valuemask; } /* Not really sure about this: */ - if (brw->attribs.DepthStencil->stencil[0].write_mask || - brw->attribs.DepthStencil->stencil[1].write_mask) + if (brw->attribs.DepthStencil->stencil[0].writemask || + brw->attribs.DepthStencil->stencil[1].writemask) cc.cc0.stencil_write_enable = 1; } diff --git a/src/gallium/drivers/i965simple/brw_wm.c b/src/gallium/drivers/i965simple/brw_wm.c index 8de565b96c..10161f2d2f 100644 --- a/src/gallium/drivers/i965simple/brw_wm.c +++ b/src/gallium/drivers/i965simple/brw_wm.c @@ -111,8 +111,8 @@ static void brw_wm_populate_key( struct brw_context *brw, if (brw->attribs.DepthStencil->stencil[0].enabled) { lookup |= IZ_STENCIL_TEST_ENABLE_BIT; - if (brw->attribs.DepthStencil->stencil[0].write_mask || - brw->attribs.DepthStencil->stencil[1].write_mask) + if (brw->attribs.DepthStencil->stencil[0].writemask || + brw->attribs.DepthStencil->stencil[1].writemask) lookup |= IZ_STENCIL_WRITE_ENABLE_BIT; } diff --git a/src/gallium/drivers/nv10/nv10_state.c b/src/gallium/drivers/nv10/nv10_state.c index d2375aa2f6..e401b3590e 100644 --- a/src/gallium/drivers/nv10/nv10_state.c +++ b/src/gallium/drivers/nv10/nv10_state.c @@ -342,10 +342,10 @@ nv10_depth_stencil_alpha_state_create(struct pipe_context *pipe, hw->depth.test_enable = cso->depth.enabled ? 1 : 0; hw->stencil.enable = cso->stencil[0].enabled ? 1 : 0; - hw->stencil.wmask = cso->stencil[0].write_mask; + hw->stencil.wmask = cso->stencil[0].writemask; hw->stencil.func = nvgl_comparison_op(cso->stencil[0].func); hw->stencil.ref = cso->stencil[0].ref_value; - hw->stencil.vmask = cso->stencil[0].value_mask; + hw->stencil.vmask = cso->stencil[0].valuemask; hw->stencil.fail = nvgl_stencil_op(cso->stencil[0].fail_op); hw->stencil.zfail = nvgl_stencil_op(cso->stencil[0].zfail_op); hw->stencil.zpass = nvgl_stencil_op(cso->stencil[0].zpass_op); diff --git a/src/gallium/drivers/nv20/nv20_state.c b/src/gallium/drivers/nv20/nv20_state.c index 21bde5b81f..8eb2bee93d 100644 --- a/src/gallium/drivers/nv20/nv20_state.c +++ b/src/gallium/drivers/nv20/nv20_state.c @@ -335,10 +335,10 @@ nv20_depth_stencil_alpha_state_create(struct pipe_context *pipe, hw->depth.test_enable = cso->depth.enabled ? 1 : 0; hw->stencil.enable = cso->stencil[0].enabled ? 1 : 0; - hw->stencil.wmask = cso->stencil[0].write_mask; + hw->stencil.wmask = cso->stencil[0].writemask; hw->stencil.func = nvgl_comparison_op(cso->stencil[0].func); hw->stencil.ref = cso->stencil[0].ref_value; - hw->stencil.vmask = cso->stencil[0].value_mask; + hw->stencil.vmask = cso->stencil[0].valuemask; hw->stencil.fail = nvgl_stencil_op(cso->stencil[0].fail_op); hw->stencil.zfail = nvgl_stencil_op(cso->stencil[0].zfail_op); hw->stencil.zpass = nvgl_stencil_op(cso->stencil[0].zpass_op); diff --git a/src/gallium/drivers/nv30/nv30_state.c b/src/gallium/drivers/nv30/nv30_state.c index 47e1a625af..2ae66e7085 100644 --- a/src/gallium/drivers/nv30/nv30_state.c +++ b/src/gallium/drivers/nv30/nv30_state.c @@ -449,10 +449,10 @@ nv30_depth_stencil_alpha_state_create(struct pipe_context *pipe, if (cso->stencil[0].enabled) { so_method(so, rankine, NV34TCL_STENCIL_FRONT_ENABLE, 8); so_data (so, cso->stencil[0].enabled ? 1 : 0); - so_data (so, cso->stencil[0].write_mask); + so_data (so, cso->stencil[0].writemask); so_data (so, nvgl_comparison_op(cso->stencil[0].func)); so_data (so, cso->stencil[0].ref_value); - so_data (so, cso->stencil[0].value_mask); + so_data (so, cso->stencil[0].valuemask); so_data (so, nvgl_stencil_op(cso->stencil[0].fail_op)); so_data (so, nvgl_stencil_op(cso->stencil[0].zfail_op)); so_data (so, nvgl_stencil_op(cso->stencil[0].zpass_op)); @@ -464,10 +464,10 @@ nv30_depth_stencil_alpha_state_create(struct pipe_context *pipe, if (cso->stencil[1].enabled) { so_method(so, rankine, NV34TCL_STENCIL_BACK_ENABLE, 8); so_data (so, cso->stencil[1].enabled ? 1 : 0); - so_data (so, cso->stencil[1].write_mask); + so_data (so, cso->stencil[1].writemask); so_data (so, nvgl_comparison_op(cso->stencil[1].func)); so_data (so, cso->stencil[1].ref_value); - so_data (so, cso->stencil[1].value_mask); + so_data (so, cso->stencil[1].valuemask); so_data (so, nvgl_stencil_op(cso->stencil[1].fail_op)); so_data (so, nvgl_stencil_op(cso->stencil[1].zfail_op)); so_data (so, nvgl_stencil_op(cso->stencil[1].zpass_op)); diff --git a/src/gallium/drivers/nv40/nv40_state.c b/src/gallium/drivers/nv40/nv40_state.c index 255c4b294d..34d109f9af 100644 --- a/src/gallium/drivers/nv40/nv40_state.c +++ b/src/gallium/drivers/nv40/nv40_state.c @@ -459,10 +459,10 @@ nv40_depth_stencil_alpha_state_create(struct pipe_context *pipe, if (cso->stencil[0].enabled) { so_method(so, curie, NV40TCL_STENCIL_FRONT_ENABLE, 8); so_data (so, cso->stencil[0].enabled ? 1 : 0); - so_data (so, cso->stencil[0].write_mask); + so_data (so, cso->stencil[0].writemask); so_data (so, nvgl_comparison_op(cso->stencil[0].func)); so_data (so, cso->stencil[0].ref_value); - so_data (so, cso->stencil[0].value_mask); + so_data (so, cso->stencil[0].valuemask); so_data (so, nvgl_stencil_op(cso->stencil[0].fail_op)); so_data (so, nvgl_stencil_op(cso->stencil[0].zfail_op)); so_data (so, nvgl_stencil_op(cso->stencil[0].zpass_op)); @@ -474,10 +474,10 @@ nv40_depth_stencil_alpha_state_create(struct pipe_context *pipe, if (cso->stencil[1].enabled) { so_method(so, curie, NV40TCL_STENCIL_BACK_ENABLE, 8); so_data (so, cso->stencil[1].enabled ? 1 : 0); - so_data (so, cso->stencil[1].write_mask); + so_data (so, cso->stencil[1].writemask); so_data (so, nvgl_comparison_op(cso->stencil[1].func)); so_data (so, cso->stencil[1].ref_value); - so_data (so, cso->stencil[1].value_mask); + so_data (so, cso->stencil[1].valuemask); so_data (so, nvgl_stencil_op(cso->stencil[1].fail_op)); so_data (so, nvgl_stencil_op(cso->stencil[1].zfail_op)); so_data (so, nvgl_stencil_op(cso->stencil[1].zpass_op)); diff --git a/src/gallium/drivers/nv50/nv50_state.c b/src/gallium/drivers/nv50/nv50_state.c index 38c1d938b8..ac236db298 100644 --- a/src/gallium/drivers/nv50/nv50_state.c +++ b/src/gallium/drivers/nv50/nv50_state.c @@ -403,8 +403,8 @@ nv50_depth_stencil_alpha_state_create(struct pipe_context *pipe, so_data (so, nvgl_comparison_op(cso->stencil[0].func)); so_method(so, tesla, NV50TCL_STENCIL_BACK_FUNC_REF, 3); so_data (so, cso->stencil[0].ref_value); - so_data (so, cso->stencil[0].write_mask); - so_data (so, cso->stencil[0].value_mask); + so_data (so, cso->stencil[0].writemask); + so_data (so, cso->stencil[0].valuemask); } else { so_method(so, tesla, NV50TCL_STENCIL_BACK_ENABLE, 1); so_data (so, 0); @@ -418,8 +418,8 @@ nv50_depth_stencil_alpha_state_create(struct pipe_context *pipe, so_data (so, nvgl_stencil_op(cso->stencil[1].zpass_op)); so_data (so, nvgl_comparison_op(cso->stencil[1].func)); so_data (so, cso->stencil[1].ref_value); - so_data (so, cso->stencil[1].write_mask); - so_data (so, cso->stencil[1].value_mask); + so_data (so, cso->stencil[1].writemask); + so_data (so, cso->stencil[1].valuemask); } else { so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 1); so_data (so, 0); diff --git a/src/gallium/drivers/softpipe/sp_quad_stencil.c b/src/gallium/drivers/softpipe/sp_quad_stencil.c index abb5487748..7495515764 100644 --- a/src/gallium/drivers/softpipe/sp_quad_stencil.c +++ b/src/gallium/drivers/softpipe/sp_quad_stencil.c @@ -222,8 +222,8 @@ stencil_test_quad(struct quad_stage *qs, struct quad_header *quad) zFailOp = softpipe->depth_stencil->stencil[face].zfail_op; zPassOp = softpipe->depth_stencil->stencil[face].zpass_op; ref = softpipe->depth_stencil->stencil[face].ref_value; - wrtMask = softpipe->depth_stencil->stencil[face].write_mask; - valMask = softpipe->depth_stencil->stencil[face].value_mask; + wrtMask = softpipe->depth_stencil->stencil[face].writemask; + valMask = softpipe->depth_stencil->stencil[face].valuemask; assert(ps); /* shouldn't get here if there's no stencil buffer */ diff --git a/src/gallium/drivers/trace/tr_state.c b/src/gallium/drivers/trace/tr_state.c index 546231612f..8b147a8d37 100644 --- a/src/gallium/drivers/trace/tr_state.c +++ b/src/gallium/drivers/trace/tr_state.c @@ -281,8 +281,8 @@ void trace_dump_depth_stencil_alpha_state(const struct pipe_depth_stencil_alpha_ trace_dump_member(uint, &state->stencil[i], zpass_op); trace_dump_member(uint, &state->stencil[i], zfail_op); trace_dump_member(uint, &state->stencil[i], ref_value); - trace_dump_member(uint, &state->stencil[i], value_mask); - trace_dump_member(uint, &state->stencil[i], write_mask); + trace_dump_member(uint, &state->stencil[i], valuemask); + trace_dump_member(uint, &state->stencil[i], writemask); trace_dump_struct_end(); trace_dump_elem_end(); } diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 46f62abf3f..0a0ca770da 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -188,9 +188,9 @@ struct pipe_stencil_state unsigned fail_op:3; /**< PIPE_STENCIL_OP_x */ unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */ unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */ - ubyte ref_value; - ubyte value_mask; - ubyte write_mask; + ubyte ref_value; + ubyte valuemask; + ubyte writemask; }; diff --git a/src/gallium/state_trackers/g3dvl/vl_context.c b/src/gallium/state_trackers/g3dvl/vl_context.c index fbea1363d8..c4c4e23c15 100644 --- a/src/gallium/state_trackers/g3dvl/vl_context.c +++ b/src/gallium/state_trackers/g3dvl/vl_context.c @@ -81,8 +81,8 @@ static int vlInitCommon(struct vlContext *context) dsa.stencil[i].zpass_op = PIPE_STENCIL_OP_KEEP; dsa.stencil[i].zfail_op = PIPE_STENCIL_OP_KEEP; dsa.stencil[i].ref_value = 0; - dsa.stencil[i].value_mask = 0; - dsa.stencil[i].write_mask = 0; + dsa.stencil[i].valuemask = 0; + dsa.stencil[i].writemask = 0; } dsa.alpha.enabled = 0; dsa.alpha.func = PIPE_FUNC_ALWAYS; diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index 0e791ceb20..8b5f22d0ef 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -112,8 +112,8 @@ update_depth_stencil_alpha(struct st_context *st) dsa->stencil[0].zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[0]); dsa->stencil[0].zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[0]); dsa->stencil[0].ref_value = st->ctx->Stencil.Ref[0] & 0xff; - dsa->stencil[0].value_mask = st->ctx->Stencil.ValueMask[0] & 0xff; - dsa->stencil[0].write_mask = st->ctx->Stencil.WriteMask[0] & 0xff; + dsa->stencil[0].valuemask = st->ctx->Stencil.ValueMask[0] & 0xff; + dsa->stencil[0].writemask = st->ctx->Stencil.WriteMask[0] & 0xff; if (st->ctx->Stencil._TestTwoSide) { dsa->stencil[1].enabled = 1; @@ -122,8 +122,8 @@ update_depth_stencil_alpha(struct st_context *st) dsa->stencil[1].zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[1]); dsa->stencil[1].zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[1]); dsa->stencil[1].ref_value = st->ctx->Stencil.Ref[1] & 0xff; - dsa->stencil[1].value_mask = st->ctx->Stencil.ValueMask[1] & 0xff; - dsa->stencil[1].write_mask = st->ctx->Stencil.WriteMask[1] & 0xff; + dsa->stencil[1].valuemask = st->ctx->Stencil.ValueMask[1] & 0xff; + dsa->stencil[1].writemask = st->ctx->Stencil.WriteMask[1] & 0xff; } else { dsa->stencil[1] = dsa->stencil[0]; diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index fca1107d72..668c3f9ebf 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -287,8 +287,8 @@ clear_with_quad(GLcontext *ctx, depth_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE; depth_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE; depth_stencil.stencil[0].ref_value = ctx->Stencil.Clear; - depth_stencil.stencil[0].value_mask = 0xff; - depth_stencil.stencil[0].write_mask = ctx->Stencil.WriteMask[0] & 0xff; + depth_stencil.stencil[0].valuemask = 0xff; + depth_stencil.stencil[0].writemask = ctx->Stencil.WriteMask[0] & 0xff; } cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil); -- cgit v1.2.3