From 6393cda6766b707ef01e925d378239a66d143ae0 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 14 Jun 2007 18:11:48 +0100 Subject: Renamed softpipe directories and files to something less confusing. softpipe/state_tracker --> state_tracker/ softpipe/ --> pipe/ softpipe/generic --> pipe/softpipe/ I don't think pipe is a great name, but I disliked all the others too. Luckily it's fairly easy to rename with git, so this can be revisited later. --- src/mesa/state_tracker/st_context.h | 111 ++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/mesa/state_tracker/st_context.h (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h new file mode 100644 index 0000000000..317d377371 --- /dev/null +++ b/src/mesa/state_tracker/st_context.h @@ -0,0 +1,111 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef ST_CONTEXT_H +#define ST_CONTEXT_H + +#include "mtypes.h" +#include "softpipe/sp_state.h" + + +struct st_context; +struct st_region; +struct st_texture_object; +struct st_texture_image; +struct st_fragment_program; + +#define ST_NEW_MESA 0x1 /* Mesa state has changed */ +#define ST_NEW_FRAGMENT_PROGRAM 0x2 + +struct st_state_flags { + GLuint mesa; + GLuint st; +}; + +struct st_tracked_state { + struct st_state_flags dirty; + void (*update)( struct st_context *st ); +}; + + + + +struct st_context +{ + GLcontext *ctx; + + struct softpipe_context *softpipe; + + /* Eventually will use a cache to feed the softpipe with + * create/bind/delete calls to constant state objects. Not yet + * though, we just shove random objects across the interface. + */ + struct { + struct softpipe_viewport viewport; + struct softpipe_setup_state setup; + struct softpipe_fs_state fs; + struct softpipe_blend_state blend; + struct softpipe_surface cbuf; + struct softpipe_clip_state clip; + struct softpipe_depth_state depth; + struct softpipe_scissor_rect scissor; + struct softpipe_poly_stipple poly_stipple; + struct softpipe_stencil_state stencil; + } state; + + struct { + struct st_tracked_state tracked_state; + } constants; + + struct { + struct gl_fragment_program *fragment_program; + } cb; + + /* State to be validated: + */ + struct st_tracked_state **atoms; + GLuint nr_atoms; + + struct st_state_flags dirty; + + /* Counter to track program string changes: + */ + GLuint program_id; + + GLfloat polygon_offset_scale; /* ?? */ +}; + + +/* Need this so that we can implement Mesa callbacks in this module. + */ +static INLINE struct st_context *st_context(GLcontext *ctx) +{ + return ctx->st; +} + + +#endif -- cgit v1.2.3 From 943964a1e5bad86bdceb0a06d60fb3b302ebce6a Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 14 Jun 2007 18:23:43 +0100 Subject: Rename directories again?! Some git wierdness going on. --- src/mesa/drivers/x11/xm_api.c | 6 +- src/mesa/drivers/x11/xm_dd.c | 4 +- src/mesa/pipe/p_context.h | 54 +- src/mesa/pipe/p_defines.h | 164 +++--- src/mesa/pipe/p_state.h | 62 +-- src/mesa/pipe/softpipe/g_context.c | 135 ----- src/mesa/pipe/softpipe/g_context.h | 149 ----- src/mesa/pipe/softpipe/g_draw.c | 696 ----------------------- src/mesa/pipe/softpipe/g_draw.h | 56 -- src/mesa/pipe/softpipe/g_headers.h | 116 ---- src/mesa/pipe/softpipe/g_prim.h | 90 --- src/mesa/pipe/softpipe/g_prim_clip.c | 429 --------------- src/mesa/pipe/softpipe/g_prim_cull.c | 119 ---- src/mesa/pipe/softpipe/g_prim_flatshade.c | 149 ----- src/mesa/pipe/softpipe/g_prim_offset.c | 157 ------ src/mesa/pipe/softpipe/g_prim_setup.c | 888 ------------------------------ src/mesa/pipe/softpipe/g_prim_setup.h | 121 ---- src/mesa/pipe/softpipe/g_prim_twoside.c | 149 ----- src/mesa/pipe/softpipe/g_prim_unfilled.c | 165 ------ src/mesa/pipe/softpipe/g_state.h | 61 -- src/mesa/pipe/softpipe/g_state_clip.c | 69 --- src/mesa/pipe/softpipe/g_state_derived.c | 136 ----- src/mesa/pipe/softpipe/g_state_fs.c | 50 -- src/mesa/pipe/softpipe/g_state_setup.c | 122 ---- src/mesa/pipe/softpipe/g_state_surface.c | 53 -- src/mesa/pipe/softpipe/g_surface.c | 153 ----- src/mesa/pipe/softpipe/g_surface.h | 115 ---- src/mesa/pipe/softpipe/g_tile.h | 42 -- src/mesa/pipe/softpipe/g_tile_fs.c | 203 ------- src/mesa/pipe/softpipe/g_tile_output.c | 92 ---- src/mesa/sources | 63 ++- src/mesa/state_tracker/st_atom_blend.c | 92 ++-- src/mesa/state_tracker/st_atom_cbuf.c | 6 +- src/mesa/state_tracker/st_atom_clip.c | 8 +- src/mesa/state_tracker/st_atom_depth.c | 26 +- src/mesa/state_tracker/st_atom_fs.c | 6 +- src/mesa/state_tracker/st_atom_scissor.c | 6 +- src/mesa/state_tracker/st_atom_setup.c | 6 +- src/mesa/state_tracker/st_atom_stencil.c | 44 +- src/mesa/state_tracker/st_atom_viewport.c | 6 +- src/mesa/state_tracker/st_context.c | 8 +- src/mesa/state_tracker/st_context.h | 26 +- src/mesa/state_tracker/st_draw.c | 8 +- src/mesa/state_tracker/st_public.h | 4 +- 44 files changed, 302 insertions(+), 4812 deletions(-) delete mode 100644 src/mesa/pipe/softpipe/g_context.c delete mode 100644 src/mesa/pipe/softpipe/g_context.h delete mode 100644 src/mesa/pipe/softpipe/g_draw.c delete mode 100644 src/mesa/pipe/softpipe/g_draw.h delete mode 100644 src/mesa/pipe/softpipe/g_headers.h delete mode 100644 src/mesa/pipe/softpipe/g_prim.h delete mode 100644 src/mesa/pipe/softpipe/g_prim_clip.c delete mode 100644 src/mesa/pipe/softpipe/g_prim_cull.c delete mode 100644 src/mesa/pipe/softpipe/g_prim_flatshade.c delete mode 100644 src/mesa/pipe/softpipe/g_prim_offset.c delete mode 100644 src/mesa/pipe/softpipe/g_prim_setup.c delete mode 100644 src/mesa/pipe/softpipe/g_prim_setup.h delete mode 100644 src/mesa/pipe/softpipe/g_prim_twoside.c delete mode 100644 src/mesa/pipe/softpipe/g_prim_unfilled.c delete mode 100644 src/mesa/pipe/softpipe/g_state.h delete mode 100644 src/mesa/pipe/softpipe/g_state_clip.c delete mode 100644 src/mesa/pipe/softpipe/g_state_derived.c delete mode 100644 src/mesa/pipe/softpipe/g_state_fs.c delete mode 100644 src/mesa/pipe/softpipe/g_state_setup.c delete mode 100644 src/mesa/pipe/softpipe/g_state_surface.c delete mode 100644 src/mesa/pipe/softpipe/g_surface.c delete mode 100644 src/mesa/pipe/softpipe/g_surface.h delete mode 100644 src/mesa/pipe/softpipe/g_tile.h delete mode 100644 src/mesa/pipe/softpipe/g_tile_fs.c delete mode 100644 src/mesa/pipe/softpipe/g_tile_output.c (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index af1a169a76..396a0923e9 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -80,8 +80,8 @@ #include "tnl/t_pipeline.h" #include "drivers/common/driverfuncs.h" -#include "softpipe/state_tracker/st_public.h" -#include "softpipe/generic/g_context.h" +#include "state_tracker/st_public.h" +#include "pipe/softpipe/sp_context.h" /** * Global X driver lock @@ -1561,7 +1561,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) st_create_context( mesaCtx, - generic_create() ); + softpipe_create() ); return c; } diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c index 63e7115e80..eb59d1d05e 100644 --- a/src/mesa/drivers/x11/xm_dd.c +++ b/src/mesa/drivers/x11/xm_dd.c @@ -53,8 +53,8 @@ #include "tnl/tnl.h" #include "tnl/t_context.h" -#include "softpipe/generic/g_context.h" -#include "softpipe/state_tracker/st_public.h" +#include "pipe/softpipe/sp_context.h" +#include "state_tracker/st_public.h" /* diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 716ddd27a9..dc7a80744a 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -25,12 +25,14 @@ * **************************************************************************/ -#ifndef SP_CONTEXT_H -#define SP_CONTEXT_H +#ifndef PIPE_CONTEXT_H +#define PIPE_CONTEXT_H #include "mtypes.h" -extern struct softpipe_context *generic_create( void ); +/* Kludge: + */ +extern struct pipe_context *softpipe_create( void ); /* Drawing currently kludged up via the existing tnl/ module. */ @@ -41,48 +43,48 @@ struct vertex_buffer; * Software pipeline rendering context. Basically a collection of * state setting functions, plus VBO drawing entrypoint. */ -struct softpipe_context { +struct pipe_context { - void (*destroy)( struct softpipe_context * ); + void (*destroy)( struct pipe_context * ); /* * Drawing */ - void (*draw_vb)( struct softpipe_context *softpipe, + void (*draw_vb)( struct pipe_context *pipe, struct vertex_buffer *VB ); /* * State functions */ - void (*set_blend_state)( struct softpipe_context *, - const struct softpipe_blend_state * ); + void (*set_blend_state)( struct pipe_context *, + const struct pipe_blend_state * ); - void (*set_cbuf_state)( struct softpipe_context *, - const struct softpipe_surface * ); + void (*set_cbuf_state)( struct pipe_context *, + const struct pipe_surface * ); - void (*set_clip_state)( struct softpipe_context *, - const struct softpipe_clip_state * ); + void (*set_clip_state)( struct pipe_context *, + const struct pipe_clip_state * ); - void (*set_depth_state)( struct softpipe_context *, - const struct softpipe_depth_state * ); + void (*set_depth_state)( struct pipe_context *, + const struct pipe_depth_state * ); - void (*set_fs_state)( struct softpipe_context *, - const struct softpipe_fs_state * ); + void (*set_fs_state)( struct pipe_context *, + const struct pipe_fs_state * ); - void (*set_polygon_stipple)( struct softpipe_context *, - const struct softpipe_poly_stipple * ); + void (*set_polygon_stipple)( struct pipe_context *, + const struct pipe_poly_stipple * ); - void (*set_setup_state)( struct softpipe_context *, - const struct softpipe_setup_state * ); + void (*set_setup_state)( struct pipe_context *, + const struct pipe_setup_state * ); - void (*set_scissor_rect)( struct softpipe_context *, - const struct softpipe_scissor_rect * ); + void (*set_scissor_rect)( struct pipe_context *, + const struct pipe_scissor_rect * ); - void (*set_stencil_state)( struct softpipe_context *, - const struct softpipe_stencil_state * ); + void (*set_stencil_state)( struct pipe_context *, + const struct pipe_stencil_state * ); - void (*set_viewport)( struct softpipe_context *, - const struct softpipe_viewport * ); + void (*set_viewport)( struct pipe_context *, + const struct pipe_viewport * ); }; diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h index c381865dab..1ca717e7ec 100644 --- a/src/mesa/pipe/p_defines.h +++ b/src/mesa/pipe/p_defines.h @@ -25,97 +25,97 @@ * **************************************************************************/ -#ifndef SP_DEFINES_H -#define SP_DEFINES_H +#ifndef PIPE_DEFINES_H +#define PIPE_DEFINES_H -#define SP_BLENDFACTOR_ONE 0x1 -#define SP_BLENDFACTOR_SRC_COLOR 0x2 -#define SP_BLENDFACTOR_SRC_ALPHA 0x3 -#define SP_BLENDFACTOR_DST_ALPHA 0x4 -#define SP_BLENDFACTOR_DST_COLOR 0x5 -#define SP_BLENDFACTOR_SRC_ALPHA_SATURATE 0x6 -#define SP_BLENDFACTOR_CONST_COLOR 0x7 -#define SP_BLENDFACTOR_CONST_ALPHA 0x8 -#define SP_BLENDFACTOR_SRC1_COLOR 0x9 -#define SP_BLENDFACTOR_SRC1_ALPHA 0x0A -#define SP_BLENDFACTOR_ZERO 0x11 -#define SP_BLENDFACTOR_INV_SRC_COLOR 0x12 -#define SP_BLENDFACTOR_INV_SRC_ALPHA 0x13 -#define SP_BLENDFACTOR_INV_DST_ALPHA 0x14 -#define SP_BLENDFACTOR_INV_DST_COLOR 0x15 -#define SP_BLENDFACTOR_INV_CONST_COLOR 0x17 -#define SP_BLENDFACTOR_INV_CONST_ALPHA 0x18 -#define SP_BLENDFACTOR_INV_SRC1_COLOR 0x19 -#define SP_BLENDFACTOR_INV_SRC1_ALPHA 0x1A +#define PIPE_BLENDFACTOR_ONE 0x1 +#define PIPE_BLENDFACTOR_SRC_COLOR 0x2 +#define PIPE_BLENDFACTOR_SRC_ALPHA 0x3 +#define PIPE_BLENDFACTOR_DST_ALPHA 0x4 +#define PIPE_BLENDFACTOR_DST_COLOR 0x5 +#define PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE 0x6 +#define PIPE_BLENDFACTOR_CONST_COLOR 0x7 +#define PIPE_BLENDFACTOR_CONST_ALPHA 0x8 +#define PIPE_BLENDFACTOR_SRC1_COLOR 0x9 +#define PIPE_BLENDFACTOR_SRC1_ALPHA 0x0A +#define PIPE_BLENDFACTOR_ZERO 0x11 +#define PIPE_BLENDFACTOR_INV_SRC_COLOR 0x12 +#define PIPE_BLENDFACTOR_INV_SRC_ALPHA 0x13 +#define PIPE_BLENDFACTOR_INV_DST_ALPHA 0x14 +#define PIPE_BLENDFACTOR_INV_DST_COLOR 0x15 +#define PIPE_BLENDFACTOR_INV_CONST_COLOR 0x17 +#define PIPE_BLENDFACTOR_INV_CONST_ALPHA 0x18 +#define PIPE_BLENDFACTOR_INV_SRC1_COLOR 0x19 +#define PIPE_BLENDFACTOR_INV_SRC1_ALPHA 0x1A -#define SP_BLEND_ADD 0 -#define SP_BLEND_SUBTRACT 1 -#define SP_BLEND_REVERSE_SUBTRACT 2 -#define SP_BLEND_MIN 3 -#define SP_BLEND_MAX 4 +#define PIPE_BLEND_ADD 0 +#define PIPE_BLEND_SUBTRACT 1 +#define PIPE_BLEND_REVERSE_SUBTRACT 2 +#define PIPE_BLEND_MIN 3 +#define PIPE_BLEND_MAX 4 -#define SP_LOGICOP_CLEAR 0 -#define SP_LOGICOP_NOR 1 -#define SP_LOGICOP_AND_INVERTED 2 -#define SP_LOGICOP_COPY_INVERTED 3 -#define SP_LOGICOP_AND_REVERSE 4 -#define SP_LOGICOP_INVERT 5 -#define SP_LOGICOP_XOR 6 -#define SP_LOGICOP_NAND 7 -#define SP_LOGICOP_AND 8 -#define SP_LOGICOP_EQUIV 9 -#define SP_LOGICOP_NOOP 10 -#define SP_LOGICOP_OR_INVERTED 11 -#define SP_LOGICOP_COPY 12 -#define SP_LOGICOP_OR_REVERSE 13 -#define SP_LOGICOP_OR 14 -#define SP_LOGICOP_SET 15 +#define PIPE_LOGICOP_CLEAR 0 +#define PIPE_LOGICOP_NOR 1 +#define PIPE_LOGICOP_AND_INVERTED 2 +#define PIPE_LOGICOP_COPY_INVERTED 3 +#define PIPE_LOGICOP_AND_REVERSE 4 +#define PIPE_LOGICOP_INVERT 5 +#define PIPE_LOGICOP_XOR 6 +#define PIPE_LOGICOP_NAND 7 +#define PIPE_LOGICOP_AND 8 +#define PIPE_LOGICOP_EQUIV 9 +#define PIPE_LOGICOP_NOOP 10 +#define PIPE_LOGICOP_OR_INVERTED 11 +#define PIPE_LOGICOP_COPY 12 +#define PIPE_LOGICOP_OR_REVERSE 13 +#define PIPE_LOGICOP_OR 14 +#define PIPE_LOGICOP_SET 15 -#define SP_STENCIL_FUNC_NEVER 0 -#define SP_STENCIL_FUNC_LESS 1 -#define SP_STENCIL_FUNC_EQUAL 2 -#define SP_STENCIL_FUNC_LEQUAL 3 -#define SP_STENCIL_FUNC_GREATER 4 -#define SP_STENCIL_FUNC_NOTEQUAL 5 -#define SP_STENCIL_FUNC_GEQUAL 6 -#define SP_STENCIL_FUNC_ALWAYS 7 +#define PIPE_STENCIL_FUNC_NEVER 0 +#define PIPE_STENCIL_FUNC_LESS 1 +#define PIPE_STENCIL_FUNC_EQUAL 2 +#define PIPE_STENCIL_FUNC_LEQUAL 3 +#define PIPE_STENCIL_FUNC_GREATER 4 +#define PIPE_STENCIL_FUNC_NOTEQUAL 5 +#define PIPE_STENCIL_FUNC_GEQUAL 6 +#define PIPE_STENCIL_FUNC_ALWAYS 7 -#define SP_STENCIL_OP_KEEP 0 -#define SP_STENCIL_OP_ZERO 1 -#define SP_STENCIL_OP_REPLACE 2 -#define SP_STENCIL_OP_INCR 3 -#define SP_STENCIL_OP_DECR 4 -#define SP_STENCIL_OP_INCR_WRAP 5 -#define SP_STENCIL_OP_DECR_WRAP 6 -#define SP_STENCIL_OP_INVERT 7 +#define PIPE_STENCIL_OP_KEEP 0 +#define PIPE_STENCIL_OP_ZERO 1 +#define PIPE_STENCIL_OP_REPLACE 2 +#define PIPE_STENCIL_OP_INCR 3 +#define PIPE_STENCIL_OP_DECR 4 +#define PIPE_STENCIL_OP_INCR_WRAP 5 +#define PIPE_STENCIL_OP_DECR_WRAP 6 +#define PIPE_STENCIL_OP_INVERT 7 /* Note: same as stencil funcs. Also used for shadow/depth compare */ -#define SP_DEPTH_FUNC_NEVER 0 -#define SP_DEPTH_FUNC_LESS 1 -#define SP_DEPTH_FUNC_EQUAL 2 -#define SP_DEPTH_FUNC_LEQUAL 3 -#define SP_DEPTH_FUNC_GREATER 4 -#define SP_DEPTH_FUNC_NOTEQUAL 5 -#define SP_DEPTH_FUNC_GEQUAL 6 -#define SP_DEPTH_FUNC_ALWAYS 7 +#define PIPE_DEPTH_FUNC_NEVER 0 +#define PIPE_DEPTH_FUNC_LESS 1 +#define PIPE_DEPTH_FUNC_EQUAL 2 +#define PIPE_DEPTH_FUNC_LEQUAL 3 +#define PIPE_DEPTH_FUNC_GREATER 4 +#define PIPE_DEPTH_FUNC_NOTEQUAL 5 +#define PIPE_DEPTH_FUNC_GEQUAL 6 +#define PIPE_DEPTH_FUNC_ALWAYS 7 -#define SP_TEX_WRAP_REPEAT 0 -#define SP_TEX_WRAP_CLAMP 1 -#define SP_TEX_WRAP_CLAMP_TO_EDGE 2 -#define SP_TEX_WRAP_CLAMP_TO_BORDER 3 -#define SP_TEX_WRAP_MIRROR_REPEAT 4 -#define SP_TEX_WRAP_MIRROR_CLAMP 5 -#define SP_TEX_WRAP_MIRROR_CLAMP_TO_EDGE 6 -#define SP_TEX_WRAP_MIRROR_CLAMP_TO_BORDER 7 +#define PIPE_TEX_WRAP_REPEAT 0 +#define PIPE_TEX_WRAP_CLAMP 1 +#define PIPE_TEX_WRAP_CLAMP_TO_EDGE 2 +#define PIPE_TEX_WRAP_CLAMP_TO_BORDER 3 +#define PIPE_TEX_WRAP_MIRROR_REPEAT 4 +#define PIPE_TEX_WRAP_MIRROR_CLAMP 5 +#define PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE 6 +#define PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER 7 -#define SP_TEX_FILTER_NEAREST 0 -#define SP_TEX_FILTER_LINEAR 1 -#define SP_TEX_FILTER_NEAREST_MIPMAP_NEAREST 2 -#define SP_TEX_FILTER_NEAREST_MIPMAP_LINEAR 3 -#define SP_TEX_FILTER_LINEAR_MIPMAP_NEAREST 4 -#define SP_TEX_FILTER_LINEAR_MIPMAP_LINEAR 5 +#define PIPE_TEX_FILTER_NEAREST 0 +#define PIPE_TEX_FILTER_LINEAR 1 +#define PIPE_TEX_FILTER_NEAREST_MIPMAP_NEAREST 2 +#define PIPE_TEX_FILTER_NEAREST_MIPMAP_LINEAR 3 +#define PIPE_TEX_FILTER_LINEAR_MIPMAP_NEAREST 4 +#define PIPE_TEX_FILTER_LINEAR_MIPMAP_LINEAR 5 -#define SP_TEX_COMPARE_NONE 0 -#define SP_TEX_COMPARE_R_TO_TEXTURE 1 +#define PIPE_TEX_COMPARE_NONE 0 +#define PIPE_TEX_COMPARE_R_TO_TEXTURE 1 #endif diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 150fa9fcad..7264f253d9 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -25,8 +25,8 @@ * **************************************************************************/ -#ifndef SP_STATE_H -#define SP_STATE_H +#ifndef PIPE_STATE_H +#define PIPE_STATE_H #include "mtypes.h" #include "vf/vf.h" @@ -40,7 +40,7 @@ #define FILL_LINE 2 #define FILL_TRI 3 -struct softpipe_setup_state { +struct pipe_setup_state { GLuint flatshade:1; GLuint light_twoside:1; @@ -63,17 +63,17 @@ struct softpipe_setup_state { GLfloat offset_scale; }; -struct softpipe_poly_stipple { +struct pipe_poly_stipple { GLuint stipple[32]; }; -struct softpipe_viewport { +struct pipe_viewport { GLfloat scale[4]; GLfloat translate[4]; }; -struct softpipe_scissor_rect { +struct pipe_scissor_rect { GLshort minx; GLshort miny; GLshort maxx; @@ -81,26 +81,26 @@ struct softpipe_scissor_rect { }; -#define SP_MAX_CLIP_PLANES 6 +#define PIPE_MAX_CLIP_PLANES 6 -struct softpipe_clip_state { - GLfloat ucp[SP_MAX_CLIP_PLANES][4]; +struct pipe_clip_state { + GLfloat ucp[PIPE_MAX_CLIP_PLANES][4]; GLuint nr; }; -struct softpipe_fs_state { +struct pipe_fs_state { struct gl_fragment_program *fp; }; -#define SP_MAX_CONSTANT 32 +#define PIPE_MAX_CONSTANT 32 -struct softpipe_constant_buffer { - GLfloat constant[SP_MAX_CONSTANT][4]; +struct pipe_constant_buffer { + GLfloat constant[PIPE_MAX_CONSTANT][4]; GLuint nr_constants; }; -struct softpipe_depth_state +struct pipe_depth_state { GLuint enabled:1; /**< depth test enabled? */ GLuint writemask:1; /**< allow depth buffer writes? */ @@ -109,7 +109,7 @@ struct softpipe_depth_state }; -struct softpipe_blend_state { +struct pipe_blend_state { GLuint blend_enable:1; GLuint rgb_func:3; @@ -124,17 +124,17 @@ struct softpipe_blend_state { GLuint logicop_func:4; }; -struct softpipe_blend_color { +struct pipe_blend_color { GLfloat color[4]; }; -struct softpipe_stencil_state { +struct pipe_stencil_state { GLuint front_enabled:1; - GLuint front_func:3; /**< SP_STENCIL_FUNC_x */ - GLuint front_fail_op:3; /**< SP_STENCIL_OP_x */ - GLuint front_zpass_op:3; /**< SP_STENCIL_OP_x */ - GLuint front_zfail_op:3; /**< SP_STENCIL_OP_x */ + GLuint front_func:3; /**< PIPE_STENCIL_FUNC_x */ + GLuint front_fail_op:3; /**< PIPE_STENCIL_OP_x */ + GLuint front_zpass_op:3; /**< PIPE_STENCIL_OP_x */ + GLuint front_zfail_op:3; /**< PIPE_STENCIL_OP_x */ GLuint back_enabled:1; GLuint back_func:3; GLuint back_fail_op:3; @@ -147,9 +147,9 @@ struct softpipe_stencil_state { }; -/* This will change for hardware softpipes... +/* This will change for hardware pipes... */ -struct softpipe_surface { +struct pipe_surface { GLubyte *ptr; GLint stride; GLuint cpp; @@ -160,13 +160,13 @@ struct softpipe_surface { /** * Texture sampler state. */ -struct softpipe_sampler_state +struct pipe_sampler_state { - GLuint wrap_s:3; /**< SP_TEX_WRAP_x */ - GLuint wrap_t:3; /**< SP_TEX_WRAP_x */ - GLuint wrap_r:3; /**< SP_TEX_WRAP_x */ - GLuint min_filter:3; /**< SP_TEX_FILTER_x */ - GLuint mag_filter:1; /**< SP_TEX_FILTER_LINEAR or _NEAREST */ + GLuint wrap_s:3; /**< PIPE_TEX_WRAP_x */ + GLuint wrap_t:3; /**< PIPE_TEX_WRAP_x */ + GLuint wrap_r:3; /**< PIPE_TEX_WRAP_x */ + GLuint min_filter:3; /**< PIPE_TEX_FILTER_x */ + GLuint mag_filter:1; /**< PIPE_TEX_FILTER_LINEAR or _NEAREST */ GLfloat min_lod; GLfloat max_lod; GLfloat lod_bias; @@ -176,8 +176,8 @@ struct softpipe_sampler_state #endif GLfloat max_anisotropy; GLuint compare:1; /**< shadow/depth compare enabled? */ - GLenum compare_mode:1; /**< SP_TEX_COMPARE_x */ - GLenum compare_func:3; /**< SP_DEPTH_FUNC_x */ + GLenum compare_mode:1; /**< PIPE_TEX_COMPARE_x */ + GLenum compare_func:3; /**< PIPE_DEPTH_FUNC_x */ GLfloat shadow_ambient; /**< shadow test fail color/intensity */ }; diff --git a/src/mesa/pipe/softpipe/g_context.c b/src/mesa/pipe/softpipe/g_context.c deleted file mode 100644 index c3329b5c7d..0000000000 --- a/src/mesa/pipe/softpipe/g_context.c +++ /dev/null @@ -1,135 +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. - * - **************************************************************************/ - -/* Author: - * Keith Whitwell - */ - -#include "imports.h" -#include "macros.h" - -#include "tnl/t_context.h" -#include "vf/vf.h" - -#include "g_context.h" -#include "g_prim.h" -#include "g_state.h" -#include "g_draw.h" - -static void generic_destroy( struct softpipe_context *softpipe ) -{ - struct generic_context *generic = generic_context( softpipe ); - - draw_destroy( generic->draw ); - - FREE( generic ); -} - - -static void generic_draw_vb( struct softpipe_context *softpipe, - struct vertex_buffer *VB ) -{ - struct generic_context *generic = generic_context( softpipe ); - - if (generic->dirty) - generic_update_derived( generic ); - - draw_vb( generic->draw, VB ); -} - -struct softpipe_context *generic_create( void ) -{ - struct generic_context *generic = CALLOC_STRUCT(generic_context); - - generic->softpipe.destroy = generic_destroy; - generic->softpipe.set_clip_state = generic_set_clip_state; - generic->softpipe.set_viewport = generic_set_viewport; - generic->softpipe.set_setup_state = generic_set_setup_state; - generic->softpipe.set_scissor_rect = generic_set_scissor_rect; - generic->softpipe.set_fs_state = generic_set_fs_state; - generic->softpipe.set_polygon_stipple = generic_set_polygon_stipple; - generic->softpipe.set_cbuf_state = generic_set_cbuf_state; - generic->softpipe.draw_vb = generic_draw_vb; - - - - generic->prim.setup = prim_setup( generic ); - generic->prim.unfilled = prim_unfilled( generic ); - generic->prim.twoside = prim_twoside( generic ); - generic->prim.offset = prim_offset( generic ); - generic->prim.clip = prim_clip( generic ); - generic->prim.flatshade = prim_flatshade( generic ); - generic->prim.cull = prim_cull( generic ); - - - generic->draw = draw_create( generic ); - - ASSIGN_4V( generic->plane[0], -1, 0, 0, 1 ); - ASSIGN_4V( generic->plane[1], 1, 0, 0, 1 ); - ASSIGN_4V( generic->plane[2], 0, -1, 0, 1 ); - ASSIGN_4V( generic->plane[3], 0, 1, 0, 1 ); - ASSIGN_4V( generic->plane[4], 0, 0, 1, 1 ); /* yes these are correct */ - ASSIGN_4V( generic->plane[5], 0, 0, -1, 1 ); /* mesa's a bit wonky */ - generic->nr_planes = 6; - - return &generic->softpipe; -} - - - - - - -#define MAX_VERTEX_SIZE ((2 + FRAG_ATTRIB_MAX) * 4 * sizeof(GLfloat)) - -void prim_alloc_tmps( struct prim_stage *stage, GLuint nr ) -{ - stage->nr_tmps = nr; - - if (nr) { - GLubyte *store = MALLOC(MAX_VERTEX_SIZE * nr); - GLuint i; - - stage->tmp = MALLOC(sizeof(struct vertex_header *) * nr); - - for (i = 0; i < nr; i++) - stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE); - } -} - -void prim_free_tmps( struct prim_stage *stage ) -{ - if (stage->tmp) { - FREE(stage->tmp[0]); - FREE(stage->tmp); - } -} - - - - - diff --git a/src/mesa/pipe/softpipe/g_context.h b/src/mesa/pipe/softpipe/g_context.h deleted file mode 100644 index 24d467f2c3..0000000000 --- a/src/mesa/pipe/softpipe/g_context.h +++ /dev/null @@ -1,149 +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 - */ - -#ifndef G_CONTEXT_H -#define G_CONTEXT_H - -#include "glheader.h" - -#include "softpipe/sp_state.h" -#include "softpipe/sp_context.h" - - - -struct generic_surface; -struct draw_context; -struct prim_stage; - - -enum interp_mode { - INTERP_CONSTANT, - INTERP_LINEAR, - INTERP_PERSPECTIVE -}; - - -#define G_NEW_VIEWPORT 0x1 -#define G_NEW_SETUP 0x2 -#define G_NEW_FS 0x4 -#define G_NEW_BLEND 0x8 -#define G_NEW_CBUF 0x10 -#define G_NEW_CLIP 0x20 -#define G_NEW_SCISSOR 0x40 -#define G_NEW_STIPPLE 0x80 - - - -struct generic_context { - struct softpipe_context softpipe; - - - /* The most recent drawing state as set by the driver: - */ - struct softpipe_viewport viewport; - struct softpipe_setup_state setup; - struct softpipe_fs_state fs; - struct softpipe_blend_state blend; - struct softpipe_surface cbuf; - struct softpipe_clip_state clip; - struct softpipe_scissor_rect scissor; - struct softpipe_poly_stipple poly_stipple; - GLuint dirty; - - - /* Cbuf derived state??? - */ - struct generic_surface *cbuf_surface; - - /* Clip derived state: - */ - GLfloat plane[12][4]; - GLuint nr_planes; - - /* Setup derived state. TODO: this should be passed in the program - * tokens as parameters to DECL instructions. - * - * For now we just set colors to CONST on flatshade, textures to - * perspective always and everything else to linear. - */ - enum interp_mode interp[VF_ATTRIB_MAX]; - - - /* FS + setup derived state: - */ - GLuint fp_attr_to_slot[VF_ATTRIB_MAX]; - GLuint vf_attr_to_slot[VF_ATTRIB_MAX]; - GLuint nr_attrs; - GLuint nr_frag_attrs; - GLuint attr_mask; - - GLboolean need_z; - GLboolean need_w; - - /* Stipple derived state: - */ - GLubyte stipple_masks[16][16]; - - - /* The software clipper/setup engine. - */ - struct { - struct prim_stage *setup; - struct prim_stage *unfilled; - struct prim_stage *twoside; - struct prim_stage *clip; - struct prim_stage *flatshade; - struct prim_stage *offset; - struct prim_stage *cull; - - struct prim_stage *first; - - GLenum prim; - GLuint vertex_size; - } prim; - - /* Temp kludge: - */ - struct draw_context *draw; -}; - - - - -static INLINE struct generic_context * -generic_context( struct softpipe_context *softpipe ) -{ - return (struct generic_context *)softpipe; -} - - - - -#endif diff --git a/src/mesa/pipe/softpipe/g_draw.c b/src/mesa/pipe/softpipe/g_draw.c deleted file mode 100644 index 4e094c21a0..0000000000 --- a/src/mesa/pipe/softpipe/g_draw.c +++ /dev/null @@ -1,696 +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 - */ - -#include "imports.h" - -#include "tnl/t_context.h" - -#include "g_context.h" -#include "g_prim.h" -#include "g_headers.h" -#include "g_draw.h" - -/* This file is a temporary set of hooks to allow us to use the tnl/ - * and vf/ modules until we have replacements in softpipe. - */ - - -struct draw_context -{ - struct generic_context *generic; - - struct vf_attr_map attrs[VF_ATTRIB_MAX]; - GLuint nr_attrs; - GLuint vertex_size; - struct vertex_fetch *vf; - - GLubyte *verts; - GLuint nr_vertices; - GLboolean in_vb; - - GLenum prim; - - /* Helper for tnl: - */ - GLvector4f header; -}; - - -static struct vertex_header *get_vertex( struct draw_context *pipe, - GLuint i ) -{ - return (struct vertex_header *)(pipe->verts + i * pipe->vertex_size); -} - - - -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->generic->prim.first->begin( draw->generic->prim.first ); -} - -static void draw_set_prim( struct draw_context *draw, - GLenum prim ) -{ - draw->prim = prim; - - /* Not done yet - need to force edgeflags to 1 in strip/fan - * primitives. - */ -#if 0 - switch (prim) { - case GL_TRIANGLES: - case GL_POLYGON: - case GL_QUADS: - case GL_QUAD_STRIP: /* yes, we need this */ - respect_edgeflags( pipe, GL_TRUE ); - break; - - default: - respect_edgeflags( pipe, GL_FALSE ); - break; - } -#endif -} - - - -static void do_quad( struct prim_stage *first, - struct vertex_header *v0, - struct vertex_header *v1, - struct vertex_header *v2, - struct vertex_header *v3 ) -{ - struct prim_header prim; - - { - GLuint tmp = v1->edgeflag; - v1->edgeflag = 0; - - prim.v[0] = v0; - prim.v[1] = v1; - prim.v[2] = v3; - first->tri( first, &prim ); - - v1->edgeflag = tmp; - } - - { - GLuint tmp = v3->edgeflag; - v3->edgeflag = 0; - - prim.v[0] = v1; - prim.v[1] = v2; - prim.v[2] = v3; - first->tri( first, &prim ); - - v3->edgeflag = tmp; - } -} - - - - -static void draw_indexed_prim( struct draw_context *draw, - const GLuint *elts, - GLuint count ) -{ - struct prim_stage * const first = draw->generic->prim.first; - struct prim_header prim; - GLuint i; - - prim.det = 0; /* valid from cull stage onwards */ - prim.v[0] = 0; - prim.v[1] = 0; - prim.v[2] = 0; - - switch (draw->prim) { - case GL_POINTS: - for (i = 0; i < count; i ++) { - prim.v[0] = get_vertex( draw, elts[i] ); - - first->point( first, &prim ); - } - break; - - case GL_LINES: - for (i = 0; i+1 < count; i += 2) { - prim.v[0] = get_vertex( draw, elts[i + 0] ); - prim.v[1] = get_vertex( draw, elts[i + 1] ); - - first->line( first, &prim ); - } - break; - - case GL_LINE_LOOP: - if (count >= 2) { - for (i = 1; i < count; i++) { - prim.v[0] = get_vertex( draw, elts[i-1] ); - prim.v[1] = get_vertex( draw, elts[i] ); - first->line( first, &prim ); - } - - prim.v[0] = get_vertex( draw, elts[count-1] ); - prim.v[1] = get_vertex( draw, elts[0] ); - first->line( first, &prim ); - } - break; - - case GL_LINE_STRIP: - /* I'm guessing it will be necessary to have something like a - * render->reset_line_stipple() method to properly support - * splitting strips into primitives like this. Alternately we - * could just scan ahead to find individual clipped lines and - * otherwise leave the strip intact - that might be better, but - * require more complex code here. - */ - if (count >= 2) { - prim.v[0] = 0; - prim.v[1] = get_vertex( draw, elts[0] ); - - for (i = 1; i < count; i++) { - prim.v[0] = prim.v[1]; - prim.v[1] = get_vertex( draw, elts[i] ); - - first->line( first, &prim ); - } - } - break; - - case GL_TRIANGLES: - for (i = 0; i+2 < count; i += 3) { - prim.v[0] = get_vertex( draw, elts[i + 0] ); - prim.v[1] = get_vertex( draw, elts[i + 1] ); - prim.v[2] = get_vertex( draw, elts[i + 2] ); - - first->tri( first, &prim ); - } - break; - - case GL_TRIANGLE_STRIP: - for (i = 0; i+2 < count; i++) { - if (i & 1) { - prim.v[0] = get_vertex( draw, elts[i + 1] ); - prim.v[1] = get_vertex( draw, elts[i + 0] ); - prim.v[2] = get_vertex( draw, elts[i + 2] ); - } - else { - prim.v[0] = get_vertex( draw, elts[i + 0] ); - prim.v[1] = get_vertex( draw, elts[i + 1] ); - prim.v[2] = get_vertex( draw, elts[i + 2] ); - } - - first->tri( first, &prim ); - } - break; - - case GL_TRIANGLE_FAN: - if (count >= 3) { - prim.v[0] = get_vertex( draw, elts[0] ); - prim.v[1] = 0; - prim.v[2] = get_vertex( draw, elts[1] ); - - for (i = 0; i+2 < count; i++) { - prim.v[1] = prim.v[2]; - prim.v[2] = get_vertex( draw, elts[i+2] ); - - first->tri( first, &prim ); - } - } - break; - - case GL_QUADS: - for (i = 0; i+3 < count; i += 4) { - do_quad( first, - get_vertex( draw, elts[i + 0] ), - get_vertex( draw, elts[i + 1] ), - get_vertex( draw, elts[i + 2] ), - get_vertex( draw, elts[i + 3] )); - } - break; - - case GL_QUAD_STRIP: - for (i = 0; i+3 < count; i += 2) { - do_quad( first, - get_vertex( draw, elts[i + 2] ), - get_vertex( draw, elts[i + 0] ), - get_vertex( draw, elts[i + 1] ), - get_vertex( draw, elts[i + 3] )); - } - break; - - - case GL_POLYGON: - if (count >= 3) { - prim.v[0] = 0; - prim.v[1] = get_vertex( draw, elts[1] ); - prim.v[2] = get_vertex( draw, elts[0] ); - - for (i = 0; i+2 < count; i++) { - prim.v[0] = prim.v[1]; - prim.v[1] = get_vertex( draw, elts[i+2] ); - - first->tri( first, &prim ); - } - } - break; - - default: - assert(0); - break; - } -} - -static void draw_prim( struct draw_context *draw, - GLuint start, - GLuint count ) -{ - struct prim_stage * const first = draw->generic->prim.first; - struct prim_header prim; - GLuint i; - -// _mesa_printf("%s (%d) %d/%d\n", __FUNCTION__, draw->prim, start, count ); - - prim.det = 0; /* valid from cull stage onwards */ - prim.v[0] = 0; - prim.v[1] = 0; - prim.v[2] = 0; - - switch (draw->prim) { - case GL_POINTS: - for (i = 0; i < count; i ++) { - prim.v[0] = get_vertex( draw, start + i ); - first->point( first, &prim ); - } - break; - - case GL_LINES: - for (i = 0; i+1 < count; i += 2) { - prim.v[0] = get_vertex( draw, start + i + 0 ); - prim.v[1] = get_vertex( draw, start + i + 1 ); - - first->line( first, &prim ); - } - break; - - case GL_LINE_LOOP: - if (count >= 2) { - for (i = 1; i < count; i++) { - prim.v[0] = get_vertex( draw, start + i - 1 ); - prim.v[1] = get_vertex( draw, start + i ); - first->line( first, &prim ); - } - - prim.v[0] = get_vertex( draw, start + count - 1 ); - prim.v[1] = get_vertex( draw, start + 0 ); - first->line( first, &prim ); - } - break; - - case GL_LINE_STRIP: - if (count >= 2) { - prim.v[0] = 0; - prim.v[1] = get_vertex( draw, start + 0 ); - - for (i = 1; i < count; i++) { - prim.v[0] = prim.v[1]; - prim.v[1] = get_vertex( draw, start + i ); - - first->line( first, &prim ); - } - } - break; - - case GL_TRIANGLES: - for (i = 0; i+2 < count; i += 3) { - prim.v[0] = get_vertex( draw, start + i + 0 ); - prim.v[1] = get_vertex( draw, start + i + 1 ); - prim.v[2] = get_vertex( draw, start + i + 2 ); - - first->tri( first, &prim ); - } - break; - - case GL_TRIANGLE_STRIP: - for (i = 0; i+2 < count; i++) { - if (i & 1) { - prim.v[0] = get_vertex( draw, start + i + 1 ); - prim.v[1] = get_vertex( draw, start + i + 0 ); - prim.v[2] = get_vertex( draw, start + i + 2 ); - } - else { - prim.v[0] = get_vertex( draw, start + i + 0 ); - prim.v[1] = get_vertex( draw, start + i + 1 ); - prim.v[2] = get_vertex( draw, start + i + 2 ); - } - - first->tri( first, &prim ); - } - break; - - case GL_TRIANGLE_FAN: - if (count >= 3) { - prim.v[0] = get_vertex( draw, start + 0 ); - prim.v[1] = 0; - prim.v[2] = get_vertex( draw, start + 1 ); - - for (i = 0; i+2 < count; i++) { - prim.v[1] = prim.v[2]; - prim.v[2] = get_vertex( draw, start + i + 2 ); - - first->tri( first, &prim ); - } - } - break; - - - case GL_QUADS: - for (i = 0; i+3 < count; i += 4) { - do_quad( first, - get_vertex( draw, start + i + 0 ), - get_vertex( draw, start + i + 1 ), - get_vertex( draw, start + i + 2 ), - get_vertex( draw, start + i + 3 )); - } - break; - - case GL_QUAD_STRIP: - for (i = 0; i+3 < count; i += 2) { - do_quad( first, - get_vertex( draw, start + i + 2 ), - get_vertex( draw, start + i + 0 ), - get_vertex( draw, start + i + 1 ), - get_vertex( draw, start + i + 3 )); - } - break; - - case GL_POLYGON: - if (count >= 3) { - prim.v[0] = 0; - prim.v[1] = get_vertex( draw, start + 1 ); - prim.v[2] = get_vertex( draw, start + 0 ); - - for (i = 0; i+2 < count; i++) { - prim.v[0] = prim.v[1]; - prim.v[1] = get_vertex( draw, start + i + 2 ); - - first->tri( first, &prim ); - } - } - break; - - default: - assert(0); - break; - } -} - - -static void draw_release_vertices( struct draw_context *draw ) -{ - draw->generic->prim.first->end( draw->generic->prim.first ); - - FREE(draw->verts); - draw->verts = NULL; -} - - -struct header_dword { - GLuint clipmask:12; - GLuint edgeflag:1; - GLuint pad:19; -}; - - -static void -build_vertex_headers( struct draw_context *draw, - struct vertex_buffer *VB ) -{ - if (draw->header.storage == NULL) { - draw->header.stride = sizeof(GLfloat); - draw->header.size = 1; - draw->header.storage = ALIGN_MALLOC( VB->Size * sizeof(GLfloat), 32 ); - draw->header.data = draw->header.storage; - draw->header.count = 0; - draw->header.flags = VEC_SIZE_1 | VEC_MALLOC; - } - - /* Build vertex header attribute. - * - */ - - { - GLuint i; - struct header_dword *header = (struct header_dword *)draw->header.storage; - - /* yes its a hack - */ - assert(sizeof(*header) == sizeof(GLfloat)); - - draw->header.count = VB->Count; - - if (VB->EdgeFlag) { - for (i = 0; i < VB->Count; i++) { - header[i].clipmask = VB->ClipMask[i]; - header[i].edgeflag = VB->EdgeFlag[i]; - header[i].pad = 0; - } - } - else if (VB->ClipOrMask) { - for (i = 0; i < VB->Count; i++) { - header[i].clipmask = VB->ClipMask[i]; - header[i].edgeflag = 0; - header[i].pad = 0; - } - } - else { - for (i = 0; i < VB->Count; i++) { - header[i].clipmask = 0; - header[i].edgeflag = 0; - header[i].pad = 0; - } - } - } - - VB->AttribPtr[VF_ATTRIB_VERTEX_HEADER] = &draw->header; -} - - - - - -static GLuint draw_prim_info(GLenum mode, GLuint *first, GLuint *incr) -{ - switch (mode) { - case GL_POINTS: - *first = 1; - *incr = 1; - return 0; - case GL_LINES: - *first = 2; - *incr = 2; - return 0; - case GL_LINE_STRIP: - *first = 2; - *incr = 1; - return 0; - case GL_LINE_LOOP: - *first = 2; - *incr = 1; - return 1; - case GL_TRIANGLES: - *first = 3; - *incr = 3; - return 0; - case GL_TRIANGLE_STRIP: - *first = 3; - *incr = 1; - return 0; - case GL_TRIANGLE_FAN: - case GL_POLYGON: - *first = 3; - *incr = 1; - return 1; - case GL_QUADS: - *first = 4; - *incr = 4; - return 0; - case GL_QUAD_STRIP: - *first = 4; - *incr = 2; - return 0; - default: - assert(0); - *first = 1; - *incr = 1; - return 0; - } -} - - -static GLuint trim( GLuint count, GLuint first, GLuint incr ) -{ - if (count < first) - return 0; - else - return count - (count - first) % incr; -} - - -/* This is a hack & will all go away. - */ -void draw_vb(struct draw_context *draw, - struct vertex_buffer *VB ) -{ - GLuint i; - - VB->AttribPtr[VF_ATTRIB_POS] = VB->NdcPtr; - VB->AttribPtr[VF_ATTRIB_BFC0] = VB->ColorPtr[1]; - VB->AttribPtr[VF_ATTRIB_BFC1] = VB->SecondaryColorPtr[1]; - VB->AttribPtr[VF_ATTRIB_CLIP_POS] = VB->ClipPtr; - - /* Build vertex headers: - */ - build_vertex_headers( draw, VB ); - - draw->in_vb = 1; - - /* Allocate the vertices: - */ - draw_allocate_vertices( draw, VB->Count ); - - /* Bind the vb outputs: - */ - vf_set_sources( draw->vf, VB->AttribPtr, 0 ); - - /* Build the hardware or prim-pipe vertices: - */ - vf_emit_vertices( draw->vf, VB->Count, draw->verts ); - - - for (i = 0; i < VB->PrimitiveCount; i++) { - - GLenum mode = VB->Primitive[i].mode; - GLuint start = VB->Primitive[i].start; - GLuint length, first, incr; - - /* Trim the primitive down to a legal size. - */ - draw_prim_info( mode, &first, &incr ); - length = trim( VB->Primitive[i].count, first, incr ); - - if (!length) - continue; - - if (draw->prim != mode) - draw_set_prim( draw, mode ); - - if (VB->Elts) { - draw_indexed_prim( draw, - VB->Elts + start, - length ); - } - else { - draw_prim( draw, - start, - length ); - } - } - - draw_release_vertices( draw ); - draw->verts = NULL; - draw->in_vb = 0; -} - -void draw_set_viewport( struct draw_context *draw, - const GLfloat *scale, - const GLfloat *translate ) -{ - assert(!draw->in_vb); - vf_set_vp_scale_translate( draw->vf, scale, translate ); -} - - - -struct draw_context *draw_create( struct generic_context *generic ) -{ - struct draw_context *draw = CALLOC_STRUCT( draw_context ); - draw->generic = generic; - draw->vf = vf_create( GL_TRUE ); - - return draw; -} - - -void draw_destroy( struct draw_context *draw ) -{ - if (draw->header.storage) - ALIGN_FREE( draw->header.storage ); - - vf_destroy( draw->vf ); - - FREE( draw ); -} - -#define EMIT_ATTR( ATTR, STYLE ) \ -do { \ - draw->attrs[draw->nr_attrs].attrib = ATTR; \ - draw->attrs[draw->nr_attrs].format = STYLE; \ - draw->nr_attrs++; \ -} while (0) - - -void draw_set_vertex_attributes( struct draw_context *draw, - const GLuint *attrs, - GLuint nr_attrs ) -{ - GLuint i; - - draw->nr_attrs = 0; - - EMIT_ATTR(VF_ATTRIB_VERTEX_HEADER, EMIT_1F); - EMIT_ATTR(VF_ATTRIB_CLIP_POS, EMIT_4F); - - assert(attrs[0] == VF_ATTRIB_POS); - EMIT_ATTR(attrs[0], EMIT_4F_VIEWPORT); - - for (i = 1; i < nr_attrs; i++) - EMIT_ATTR(attrs[i], EMIT_4F); - - draw->vertex_size = vf_set_vertex_attributes( draw->vf, draw->attrs, draw->nr_attrs, 0 ); -} - - diff --git a/src/mesa/pipe/softpipe/g_draw.h b/src/mesa/pipe/softpipe/g_draw.h deleted file mode 100644 index 78c93b4df7..0000000000 --- a/src/mesa/pipe/softpipe/g_draw.h +++ /dev/null @@ -1,56 +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 - */ - -#ifndef G_DRAW_H -#define G_DRAW_H - -#include "glheader.h" -#include "softpipe/sp_state.h" - - -struct draw_context; - -struct draw_context *draw_create( struct generic_context *generic ); - -void draw_destroy( struct draw_context *draw ); - -void draw_set_viewport( struct draw_context *draw, - const GLfloat *scale, - const GLfloat *translate ); - -void draw_set_vertex_attributes( struct draw_context *draw, - const GLuint *attrs, - GLuint nr_attrs ); - -void draw_vb(struct draw_context *draw, - struct vertex_buffer *VB ); - -#endif diff --git a/src/mesa/pipe/softpipe/g_headers.h b/src/mesa/pipe/softpipe/g_headers.h deleted file mode 100644 index 96ff52a453..0000000000 --- a/src/mesa/pipe/softpipe/g_headers.h +++ /dev/null @@ -1,116 +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 - */ -#ifndef G_HEADERS_H -#define G_HEADERS_H - -#define PRIM_POINT 1 -#define PRIM_LINE 2 -#define PRIM_TRI 3 - -struct prim_header { - GLfloat det; - struct vertex_header *v[3]; -}; - -/* Carry some useful information around with the vertices in the prim - * pipe. - */ -struct vertex_header { - GLuint clipmask:12; - GLuint edgeflag:1; - GLuint pad:19; - - GLfloat clip[4]; - - GLfloat data[][4]; /* Note variable size */ -}; - - - - - -/* The rasterizer generates 2x2 quads of fragment and feeds them to - * the current fp_machine (see below). - */ -#define QUAD_BOTTOM_LEFT 0 -#define QUAD_BOTTOM_RIGHT 1 -#define QUAD_TOP_LEFT 2 -#define QUAD_TOP_RIGHT 3 -#define QUAD_SIZE (2*2) - -#define MASK_BOTTOM_LEFT 0x1 -#define MASK_BOTTOM_RIGHT 0x2 -#define MASK_TOP_LEFT 0x4 -#define MASK_TOP_RIGHT 0x8 -#define MASK_ALL 0xf - - -#define NUM_CHANNELS 4 /* avoid confusion between 4 pixels and 4 channels */ - - -struct setup_coefficient { - GLfloat a0[NUM_CHANNELS]; /* in an xyzw layout */ - GLfloat dadx[NUM_CHANNELS]; - GLfloat dady[NUM_CHANNELS]; -}; - - - -/* Encodes everything we need to know about a 2x2 pixel block. Uses - * "Channel-Serial" or "SoA" layout. - * - * Will expand to include non-attribute things like AA coverage and - * maybe prefetched depth from the depth buffer. - */ -struct quad_header { - GLint x0; - GLint y0; - GLuint mask; - GLuint facing; /**< Front or back facing? */ - - struct { - GLfloat color[4][QUAD_SIZE]; /* rrrr, gggg, bbbb, aaaa */ - GLfloat depth[QUAD_SIZE]; - } outputs; - - const struct setup_coefficient *coef; - - const enum interp_mode *interp; /* XXX: this information should be - * encoded in fragment program DECL - * statements. */ - - GLuint nr_attrs; -}; - - - - - -#endif diff --git a/src/mesa/pipe/softpipe/g_prim.h b/src/mesa/pipe/softpipe/g_prim.h deleted file mode 100644 index e3b2c5ea2f..0000000000 --- a/src/mesa/pipe/softpipe/g_prim.h +++ /dev/null @@ -1,90 +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 - */ - -#ifndef G_PRIM_H -#define G_PRIM_H - -#include "glheader.h" -#include "g_headers.h" - -struct generic_context; - -struct prim_stage *prim_setup( struct generic_context *context ); -struct prim_stage *prim_unfilled( struct generic_context *context ); -struct prim_stage *prim_twoside( struct generic_context *context ); -struct prim_stage *prim_offset( struct generic_context *context ); -struct prim_stage *prim_clip( struct generic_context *context ); -struct prim_stage *prim_flatshade( struct generic_context *context ); -struct prim_stage *prim_cull( struct generic_context *context ); - - -/* Internal structs and helpers for the primitive clip/setup pipeline: - */ -struct prim_stage { - struct generic_context *generic; - - struct prim_stage *next; - - struct vertex_header **tmp; - GLuint nr_tmps; - - void (*begin)( struct prim_stage * ); - - void (*point)( struct prim_stage *, - struct prim_header * ); - - void (*line)( struct prim_stage *, - struct prim_header * ); - - void (*tri)( struct prim_stage *, - struct prim_header * ); - - void (*end)( struct prim_stage * ); -}; - - - -/* Get a writeable copy of a vertex: - */ -static INLINE struct vertex_header * -dup_vert( struct prim_stage *stage, - const struct vertex_header *vert, - GLuint idx ) -{ - struct vertex_header *tmp = stage->tmp[idx]; - memcpy(tmp, vert, stage->generic->prim.vertex_size ); - return tmp; -} - -void prim_free_tmps( struct prim_stage *stage ); -void prim_alloc_tmps( struct prim_stage *stage, GLuint nr ); - - -#endif diff --git a/src/mesa/pipe/softpipe/g_prim_clip.c b/src/mesa/pipe/softpipe/g_prim_clip.c deleted file mode 100644 index 742def9c7d..0000000000 --- a/src/mesa/pipe/softpipe/g_prim_clip.c +++ /dev/null @@ -1,429 +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 - */ - -#include "imports.h" -#include "macros.h" - -#include "g_context.h" -#include "g_prim.h" - -struct clipper { - struct prim_stage stage; - - GLuint active_user_planes; -}; - -/* This is a bit confusing: - */ -static INLINE struct clipper *clipper_stage( struct prim_stage *stage ) -{ - return (struct clipper *)stage; -} - - -#define LINTERP(T, OUT, IN) ((OUT) + (T) * ((IN) - (OUT))) - - -/* All attributes are float[4], so this is easy: - */ -static void interp_attr( GLfloat *fdst, - GLfloat t, - const GLfloat *fin, - const GLfloat *fout ) -{ - fdst[0] = LINTERP( t, fout[0], fin[0] ); - fdst[1] = LINTERP( t, fout[1], fin[1] ); - fdst[2] = LINTERP( t, fout[2], fin[2] ); - fdst[3] = LINTERP( t, fout[3], fin[3] ); -} - - - - -/* Interpolate between two vertices to produce a third. - */ -static void interp( struct clipper *clip, - struct vertex_header *dst, - GLfloat t, - const struct vertex_header *out, - const struct vertex_header *in ) -{ - const GLuint nr_attrs = clip->stage.generic->nr_attrs; - GLuint j; - - /* Vertex header. - */ - { - dst->clipmask = 0; - dst->edgeflag = 0; - dst->pad = 0; - } - - /* Clip coordinates: interpolate normally - */ - { - interp_attr(dst->clip, t, in->clip, out->clip); - } - - /* Do the projective divide and insert window coordinates: - */ - { - const GLfloat *pos = dst->clip; - const GLfloat *scale = clip->stage.generic->viewport.scale; - const GLfloat *trans = clip->stage.generic->viewport.translate; - GLfloat oow; - - oow = 1.0 / pos[3]; - - dst->data[0][0] = pos[0] * oow * scale[0] + trans[0]; - dst->data[0][1] = pos[1] * oow * scale[1] + trans[1]; - dst->data[0][2] = pos[2] * oow * scale[2] + trans[2]; - dst->data[0][3] = oow; - } - - - /* Other attributes - */ - for (j = 1; j < nr_attrs-1; j++) { - interp_attr(dst->data[j], t, in->data[j], out->data[j]); - } -} - - -#define CLIP_USER_BIT 0x40 -#define CLIP_CULL_BIT 0x80 - - -static INLINE GLfloat dot4( const GLfloat *a, - const GLfloat *b ) -{ - GLfloat result = (a[0]*b[0] + - a[1]*b[1] + - a[2]*b[2] + - a[3]*b[3]); - - return result; -} - - -#if 0 -static INLINE void do_tri( struct prim_stage *next, - struct prim_header *header ) -{ - GLuint i; - for (i = 0; i < 3; i++) { - GLfloat *ndc = header->v[i]->data[0]; - _mesa_printf("ndc %f %f %f\n", ndc[0], ndc[1], ndc[2]); - assert(ndc[0] >= -1 && ndc[0] <= 641); - assert(ndc[1] >= 30 && ndc[1] <= 481); - } - _mesa_printf("\n"); - next->tri(next, header); -} -#endif - - -static void emit_poly( struct prim_stage *stage, - struct vertex_header **inlist, - GLuint n ) -{ - struct prim_header header; - GLuint i; - - for (i = 2; i < n; i++) { - header.v[0] = inlist[0]; - header.v[1] = inlist[i-1]; - header.v[2] = inlist[i]; - - { - GLuint tmp0 = header.v[0]->edgeflag; - GLuint tmp2 = header.v[2]->edgeflag; - - if (i != 2) header.v[0]->edgeflag = 0; - if (i != n-1) header.v[2]->edgeflag = 0; - - stage->next->tri( stage->next, &header ); - - header.v[0]->edgeflag = tmp0; - header.v[2]->edgeflag = tmp2; - } - } -} - - -#if 0 -static void emit_poly( struct prim_stage *stage ) -{ - GLuint i; - - for (i = 2; i < n; i++) { - header->v[0] = inlist[0]; - header->v[1] = inlist[i-1]; - header->v[2] = inlist[i]; - - stage->next->tri( stage->next, header ); - } -} -#endif - - -/* Clip a triangle against the viewport and user clip planes. - */ -static void -do_clip_tri( struct prim_stage *stage, - struct prim_header *header, - GLuint clipmask ) -{ - struct clipper *clipper = clipper_stage( stage ); - struct vertex_header *a[MAX_CLIPPED_VERTICES]; - struct vertex_header *b[MAX_CLIPPED_VERTICES]; - struct vertex_header **inlist = a; - struct vertex_header **outlist = b; - GLuint tmpnr = 0; - GLuint n = 3; - GLuint i; - - inlist[0] = header->v[0]; - inlist[1] = header->v[1]; - inlist[2] = header->v[2]; - - /* XXX: Note stupid hack to deal with tnl's 8-bit clipmask. Remove - * this once we correctly use 16bit masks for userclip planes. - */ - clipmask &= ~CLIP_CULL_BIT; - if (clipmask & CLIP_USER_BIT) { - clipmask &= ~CLIP_USER_BIT; - clipmask |= clipper->active_user_planes; - } - - while (clipmask && n >= 3) { - GLuint plane_idx = ffs(clipmask)-1; - const GLfloat *plane = clipper->stage.generic->plane[plane_idx]; - struct vertex_header *vert_prev = inlist[0]; - GLfloat dp_prev = dot4( vert_prev->clip, plane ); - GLuint outcount = 0; - - clipmask &= ~(1<clip, plane ); - - if (!IS_NEGATIVE(dp_prev)) { - outlist[outcount++] = vert_prev; - } - - if (DIFFERENT_SIGNS(dp, dp_prev)) { - struct vertex_header *new_vert = clipper->stage.tmp[tmpnr++]; - outlist[outcount++] = new_vert; - - if (IS_NEGATIVE(dp)) { - /* Going out of bounds. Avoid division by zero as we - * know dp != dp_prev from DIFFERENT_SIGNS, above. - */ - GLfloat t = dp / (dp - dp_prev); - interp( clipper, new_vert, t, vert, vert_prev ); - - /* Force edgeflag true in this case: - */ - new_vert->edgeflag = 1; - } else { - /* Coming back in. - */ - GLfloat t = dp_prev / (dp_prev - dp); - interp( clipper, new_vert, t, vert_prev, vert ); - - /* Copy starting vert's edgeflag: - */ - new_vert->edgeflag = vert_prev->edgeflag; - } - } - - vert_prev = vert; - dp_prev = dp; - } - - { - struct vertex_header **tmp = inlist; - inlist = outlist; - outlist = tmp; - n = outcount; - } - } - - /* Emit the polygon as triangles to the setup stage: - */ - if (n >= 3) - emit_poly( stage, inlist, n ); -} - - -/* Clip a line against the viewport and user clip planes. - */ -static void -do_clip_line( struct prim_stage *stage, - struct prim_header *header, - GLuint clipmask ) -{ - struct clipper *clipper = clipper_stage( stage ); - struct vertex_header *v0 = header->v[0]; - struct vertex_header *v1 = header->v[1]; - const GLfloat *pos0 = v0->clip; - const GLfloat *pos1 = v1->clip; - GLfloat t0 = 0; - GLfloat t1 = 0; - - /* XXX: Note stupid hack to deal with tnl's 8-bit clipmask. Remove - * this once we correctly use 16bit masks for userclip planes. - */ - clipmask &= ~CLIP_CULL_BIT; - if (clipmask & CLIP_USER_BIT) { - clipmask &= ~CLIP_USER_BIT; - clipmask |= clipper->active_user_planes; - } - - while (clipmask) { - GLuint plane_idx = ffs(clipmask)-1; - const GLfloat *plane = clipper->stage.generic->plane[plane_idx]; - - clipmask &= ~(1< t1) t1 = t; - } - - if (dp0 < 0) { - GLfloat t = dp0 / (dp0 - dp1); - if (t > t0) t0 = t; - } - - if (t0 + t1 >= 1.0) - return; /* discard */ - } - - if (v0->clipmask) { - interp( clipper, stage->tmp[0], t0, v0, v1 ); - header->v[0] = stage->tmp[0]; - } - - if (v1->clipmask) { - interp( clipper, stage->tmp[1], t1, v1, v0 ); - header->v[1] = stage->tmp[1]; - } - - stage->next->line( stage->next, header ); -} - - - -static void clip_begin( struct prim_stage *stage ) -{ - struct clipper *clipper = clipper_stage(stage); - GLuint nr = stage->generic->nr_planes; - - /* Hacky bitmask to use when we hit CLIP_USER_BIT: - */ - clipper->active_user_planes = ((1<next->begin( stage->next ); -} - -static void -clip_point( struct prim_stage *stage, - struct prim_header *header ) -{ - if (header->v[0]->clipmask == 0) - stage->next->point( stage->next, header ); -} - - -static void -clip_line( struct prim_stage *stage, - struct prim_header *header ) -{ - GLuint clipmask = (header->v[0]->clipmask | - header->v[1]->clipmask); - - if (clipmask == 0) { - stage->next->line( stage->next, header ); - } - else if ((header->v[0]->clipmask & - header->v[1]->clipmask) == 0) { - do_clip_line(stage, header, clipmask); - } -} - - -static void -clip_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - GLuint clipmask = (header->v[0]->clipmask | - header->v[1]->clipmask | - header->v[2]->clipmask); - - if (clipmask == 0) { - stage->next->tri( stage->next, header ); - } - else if ((header->v[0]->clipmask & - header->v[1]->clipmask & - header->v[2]->clipmask) == 0) { - do_clip_tri(stage, header, clipmask); - } -} - -static void clip_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - - -struct prim_stage *prim_clip( struct generic_context *generic ) -{ - struct clipper *clipper = CALLOC_STRUCT(clipper); - - prim_alloc_tmps( &clipper->stage, MAX_CLIPPED_VERTICES ); - - clipper->stage.generic = generic; - clipper->stage.begin = clip_begin; - clipper->stage.point = clip_point; - clipper->stage.line = clip_line; - clipper->stage.tri = clip_tri; - clipper->stage.end = clip_end; - - return &clipper->stage; -} diff --git a/src/mesa/pipe/softpipe/g_prim_cull.c b/src/mesa/pipe/softpipe/g_prim_cull.c deleted file mode 100644 index 633fbcc492..0000000000 --- a/src/mesa/pipe/softpipe/g_prim_cull.c +++ /dev/null @@ -1,119 +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 - */ -#include "imports.h" - -#include "g_context.h" -#include "g_prim.h" - - - -struct cull_stage { - struct prim_stage stage; - GLuint mode; -}; - - - -static INLINE struct cull_stage *cull_stage( struct prim_stage *stage ) -{ - return (struct cull_stage *)stage; -} - - -static void cull_begin( struct prim_stage *stage ) -{ - struct cull_stage *cull = cull_stage(stage); - - cull->mode = stage->generic->setup.cull_mode; - - stage->next->begin( stage->next ); -} - - -static void cull_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - /* Window coords: */ - GLfloat *v0 = (GLfloat *)&(header->v[0]->data[0]); - GLfloat *v1 = (GLfloat *)&(header->v[1]->data[0]); - GLfloat *v2 = (GLfloat *)&(header->v[2]->data[0]); - - GLfloat ex = v0[0] - v2[0]; - GLfloat ey = v0[1] - v2[1]; - GLfloat fx = v1[0] - v2[0]; - GLfloat fy = v1[1] - v2[1]; - - header->det = ex * fy - ey * fx; - - _mesa_printf("%s %f\n", __FUNCTION__, header->det ); - - if (header->det != 0) { - GLuint mode = (header->det < 0) ? WINDING_CW : WINDING_CCW; - - if ((mode & cull_stage(stage)->mode) == 0) - stage->next->tri( stage->next, header ); - } -} - - -static void cull_line( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->line( stage->next, header ); -} - - -static void cull_point( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->point( stage->next, header ); -} - -static void cull_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - -struct prim_stage *prim_cull( struct generic_context *generic ) -{ - struct cull_stage *cull = CALLOC_STRUCT(cull_stage); - - prim_alloc_tmps( &cull->stage, 0 ); - - cull->stage.generic = generic; - cull->stage.next = NULL; - cull->stage.begin = cull_begin; - cull->stage.point = cull_point; - cull->stage.line = cull_line; - cull->stage.tri = cull_tri; - cull->stage.end = cull_end; - - return &cull->stage; -} diff --git a/src/mesa/pipe/softpipe/g_prim_flatshade.c b/src/mesa/pipe/softpipe/g_prim_flatshade.c deleted file mode 100644 index 1974a64fa8..0000000000 --- a/src/mesa/pipe/softpipe/g_prim_flatshade.c +++ /dev/null @@ -1,149 +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 - */ -#include "imports.h" - -#include "g_context.h" -#include "g_prim.h" - - -struct flatshade_stage { - struct prim_stage stage; - - const GLuint *lookup; -}; - - - -static INLINE struct flatshade_stage *flatshade_stage( struct prim_stage *stage ) -{ - return (struct flatshade_stage *)stage; -} - - -static void flatshade_begin( struct prim_stage *stage ) -{ - stage->next->begin( stage->next ); -} - - - -static INLINE void copy_attr( GLuint attr, - struct vertex_header *dst, - const struct vertex_header *src ) -{ - if (attr) { - memcpy( dst->data[attr], - src->data[attr], - sizeof(src->data[0]) ); - } -} - -static void copy_colors( struct prim_stage *stage, - struct vertex_header *dst, - const struct vertex_header *src ) -{ - struct flatshade_stage *flatshade = flatshade_stage(stage); - const GLuint *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 ); -} - - - -/* Flatshade tri. Required for clipping and when unfilled tris are - * active, otherwise handled by hardware. - */ -static void flatshade_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - struct prim_header tmp; - - tmp.det = header->det; - tmp.v[0] = dup_vert(stage, header->v[0], 0); - tmp.v[1] = dup_vert(stage, header->v[1], 1); - tmp.v[2] = header->v[2]; - - copy_colors(stage, tmp.v[0], tmp.v[2]); - copy_colors(stage, tmp.v[1], tmp.v[2]); - - stage->next->tri( stage->next, &tmp ); -} - - -/* Flatshade line. Required for clipping. - */ -static void flatshade_line( struct prim_stage *stage, - struct prim_header *header ) -{ - struct prim_header tmp; - - tmp.v[0] = dup_vert(stage, header->v[0], 0); - tmp.v[1] = header->v[1]; - - copy_colors(stage, tmp.v[0], tmp.v[1]); - - stage->next->line( stage->next, &tmp ); -} - - -static void flatshade_point( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->point( stage->next, header ); -} - -static void flatshade_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - -struct prim_stage *prim_flatshade( struct generic_context *generic ) -{ - struct flatshade_stage *flatshade = CALLOC_STRUCT(flatshade_stage); - - prim_alloc_tmps( &flatshade->stage, 2 ); - - flatshade->stage.generic = generic; - flatshade->stage.next = NULL; - flatshade->stage.begin = flatshade_begin; - flatshade->stage.point = flatshade_point; - flatshade->stage.line = flatshade_line; - flatshade->stage.tri = flatshade_tri; - flatshade->stage.end = flatshade_end; - - flatshade->lookup = generic->vf_attr_to_slot; - - return &flatshade->stage; -} - - diff --git a/src/mesa/pipe/softpipe/g_prim_offset.c b/src/mesa/pipe/softpipe/g_prim_offset.c deleted file mode 100644 index 801ce9a441..0000000000 --- a/src/mesa/pipe/softpipe/g_prim_offset.c +++ /dev/null @@ -1,157 +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 - */ -#include "imports.h" -#include "macros.h" - -#include "g_context.h" -#include "g_prim.h" - - - -struct offset_stage { - struct prim_stage stage; - - GLuint hw_data_offset; - - GLfloat scale; - GLfloat units; -}; - - - -static INLINE struct offset_stage *offset_stage( struct prim_stage *stage ) -{ - return (struct offset_stage *)stage; -} - - -static void offset_begin( struct prim_stage *stage ) -{ - struct offset_stage *offset = offset_stage(stage); - - offset->units = stage->generic->setup.offset_units; - offset->scale = stage->generic->setup.offset_scale; - - stage->next->begin( stage->next ); -} - - -/* Offset tri. Some hardware can handle this, but not usually when - * doing unfilled rendering. - */ -static void do_offset_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - struct offset_stage *offset = offset_stage(stage); - GLfloat inv_det = 1.0 / header->det; - - /* Window coords: - */ - GLfloat *v0 = (GLfloat *)&(header->v[0]->data[0]); - GLfloat *v1 = (GLfloat *)&(header->v[1]->data[0]); - GLfloat *v2 = (GLfloat *)&(header->v[2]->data[0]); - - GLfloat ex = v0[0] - v2[2]; - GLfloat fx = v1[0] - v2[2]; - GLfloat ey = v0[1] - v2[2]; - GLfloat fy = v1[1] - v2[2]; - GLfloat ez = v0[2] - v2[2]; - GLfloat fz = v1[2] - v2[2]; - - GLfloat a = ey*fz - ez*fy; - GLfloat b = ez*fx - ex*fz; - - GLfloat ac = a * inv_det; - GLfloat bc = b * inv_det; - GLfloat zoffset; - - if ( ac < 0.0f ) ac = -ac; - if ( bc < 0.0f ) bc = -bc; - - zoffset = offset->units + MAX2( ac, bc ) * offset->scale; - - v0[2] += zoffset; - v1[2] += zoffset; - v2[2] += zoffset; - - stage->next->tri( stage->next, header ); -} - - -static void offset_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - struct prim_header tmp; - - tmp.det = header->det; - tmp.v[0] = dup_vert(stage, header->v[0], 0); - tmp.v[1] = dup_vert(stage, header->v[1], 1); - tmp.v[2] = dup_vert(stage, header->v[2], 2); - - do_offset_tri( stage->next, &tmp ); -} - - - -static void offset_line( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->line( stage->next, header ); -} - - -static void offset_point( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->point( stage->next, header ); -} - - -static void offset_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - -struct prim_stage *prim_offset( struct generic_context *generic ) -{ - struct offset_stage *offset = CALLOC_STRUCT(offset_stage); - - prim_alloc_tmps( &offset->stage, 3 ); - - offset->stage.generic = generic; - offset->stage.next = NULL; - offset->stage.begin = offset_begin; - offset->stage.point = offset_point; - offset->stage.line = offset_line; - offset->stage.tri = offset_tri; - offset->stage.end = offset_end; - - return &offset->stage; -} diff --git a/src/mesa/pipe/softpipe/g_prim_setup.c b/src/mesa/pipe/softpipe/g_prim_setup.c deleted file mode 100644 index 41e1381a60..0000000000 --- a/src/mesa/pipe/softpipe/g_prim_setup.c +++ /dev/null @@ -1,888 +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 - */ - -#include "imports.h" -#include "macros.h" - -#include "g_context.h" -#include "g_prim.h" -#include "g_tile.h" - - -/** - * Triangle edge info - */ -struct edge { - GLfloat dx; /* X(v1) - X(v0), used only during setup */ - GLfloat dy; /* Y(v1) - Y(v0), used only during setup */ - GLfloat dxdy; /* dx/dy */ - GLfloat sx; /* first sample point x coord */ - GLfloat sy; - GLint lines; /* number of lines on this edge */ -}; - - -/** - * Triangle setup info (derived from prim_stage). - * Also used for line drawing (taking some liberties). - */ -struct setup_stage { - struct prim_stage stage; /**< This must be first */ - - /* Vertices are just an array of floats making up each attribute in - * turn. Currently fixed at 4 floats, but should change in time. - * Codegen will help cope with this. - */ - const struct vertex_header *vmax; - const struct vertex_header *vmid; - const struct vertex_header *vmin; - const struct vertex_header *vprovoke; - - struct edge ebot; - struct edge etop; - struct edge emaj; - - GLfloat oneoverarea; - - struct setup_coefficient coef[FRAG_ATTRIB_MAX]; - struct quad_header quad; - - struct { - GLint left[2]; /**< [0] = row0, [1] = row1 */ - GLint right[2]; - GLint y; - GLuint y_flags; - GLuint mask; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */ - } span; -}; - - - -/** - * Basically a cast wrapper. - */ -static inline struct setup_stage *setup_stage( struct prim_stage *stage ) -{ - return (struct setup_stage *)stage; -} - - -/** - * Given an X or Y coordinate, return the block/quad coordinate that it - * belongs to. - */ -static inline GLint block( GLint x ) -{ - return x & ~1; -} - - - -static void setup_begin( struct prim_stage *stage ) -{ - setup_stage(stage)->quad.nr_attrs = stage->generic->nr_frag_attrs; -} - - -/** - * Run shader on a quad/block. - */ -static void run_shader_block( struct setup_stage *setup, - GLint x, GLint y, GLuint mask ) -{ - setup->quad.x0 = x; - setup->quad.y0 = y; - setup->quad.mask = mask; - - quad_shade( setup->stage.generic, &setup->quad ); -} - - -/** - * Compute mask which indicates which pixels in the 2x2 quad are actually inside - * the triangle's bounds. - * - * this is pretty nasty... may need to rework flush_spans again to - * fix it, if possible. - */ -static GLuint calculate_mask( struct setup_stage *setup, - GLint x ) -{ - GLuint mask = 0; - - if (x >= setup->span.left[0] && x < setup->span.right[0]) - mask |= MASK_BOTTOM_LEFT; - - if (x >= setup->span.left[1] && x < setup->span.right[1]) - mask |= MASK_TOP_LEFT; - - if (x+1 >= setup->span.left[0] && x+1 < setup->span.right[0]) - mask |= MASK_BOTTOM_RIGHT; - - if (x+1 >= setup->span.left[1] && x+1 < setup->span.right[1]) - mask |= MASK_TOP_RIGHT; - - return mask; -} - - -/** - * Render a horizontal span of quads - */ -static void flush_spans( struct setup_stage *setup ) -{ - GLint minleft, maxright; - GLint x; - - switch (setup->span.y_flags) { - case 3: - minleft = MIN2(setup->span.left[0], setup->span.left[1]); - maxright = MAX2(setup->span.right[0], setup->span.right[1]); - break; - - case 1: - minleft = setup->span.left[0]; - maxright = setup->span.right[0]; - break; - - case 2: - minleft = setup->span.left[1]; - maxright = setup->span.right[1]; - break; - - default: - return; - } - - - for (x = block(minleft); x <= block(maxright); ) - { - run_shader_block( setup, x, - setup->span.y, - calculate_mask( setup, x ) ); - x += 2; - } - - setup->span.y = 0; - setup->span.y_flags = 0; - setup->span.right[0] = 0; - setup->span.right[1] = 0; -} - - -static GLboolean setup_sort_vertices( struct setup_stage *setup, - const struct prim_header *prim ) -{ - const struct vertex_header *v0 = prim->v[0]; - const struct vertex_header *v1 = prim->v[1]; - const struct vertex_header *v2 = prim->v[2]; - - setup->vprovoke = v2; - - /* determine bottom to top order of vertices */ - { - GLfloat y0 = v0->data[0][1]; - GLfloat y1 = v1->data[0][1]; - GLfloat y2 = v2->data[0][1]; - if (y0 <= y1) { - if (y1 <= y2) { - /* y0<=y1<=y2 */ - setup->vmin = v0; - setup->vmid = v1; - setup->vmax = v2; - } - else if (y2 <= y0) { - /* y2<=y0<=y1 */ - setup->vmin = v2; - setup->vmid = v0; - setup->vmax = v1; - } - else { - /* y0<=y2<=y1 */ - setup->vmin = v0; - setup->vmid = v2; - setup->vmax = v1; - } - } - else { - if (y0 <= y2) { - /* y1<=y0<=y2 */ - setup->vmin = v1; - setup->vmid = v0; - setup->vmax = v2; - } - else if (y2 <= y1) { - /* y2<=y1<=y0 */ - setup->vmin = v2; - setup->vmid = v1; - setup->vmax = v0; - } - else { - /* y1<=y2<=y0 */ - setup->vmin = v1; - setup->vmid = v2; - setup->vmax = v0; - } - } - } - - setup->ebot.dx = setup->vmid->data[0][0] - setup->vmin->data[0][0]; - setup->ebot.dy = setup->vmid->data[0][1] - setup->vmin->data[0][1]; - setup->emaj.dx = setup->vmax->data[0][0] - setup->vmin->data[0][0]; - setup->emaj.dy = setup->vmax->data[0][1] - setup->vmin->data[0][1]; - setup->etop.dx = setup->vmax->data[0][0] - setup->vmid->data[0][0]; - setup->etop.dy = setup->vmax->data[0][1] - setup->vmid->data[0][1]; - - /* xxx: may need to adjust this sign according to the if-tree - * above: - * - * XXX: this is like 'det', but calculated from screen coords?? - */ - { - const GLfloat area = (setup->emaj.dx * setup->ebot.dy - - setup->ebot.dx * setup->emaj.dy); - - setup->oneoverarea = 1.0 / area; - } - - /* XXX need to know if this is a front or back-facing triangle: - * - the GLSL gl_FrontFacing fragment attribute (bool) - * - two-sided stencil test - */ - setup->quad.facing = 0; - - _mesa_printf("%s one-over-area %f\n", __FUNCTION__, setup->oneoverarea ); - - - return GL_TRUE; -} - - -/** - * Compute a0 for a constant-valued coefficient (GL_FLAT shading). - */ -static void const_coeff( struct setup_stage *setup, - GLuint slot, - GLuint i ) -{ - setup->coef[slot].dadx[i] = 0; - setup->coef[slot].dady[i] = 0; - - /* need provoking vertex info! - */ - setup->coef[slot].a0[i] = setup->vprovoke->data[slot][i]; -} - - -/** - * Compute a0, dadx and dady for a linearly interpolated coefficient, - * for a triangle. - */ -static void tri_linear_coeff( struct setup_stage *setup, - GLuint slot, - GLuint i) -{ - GLfloat botda = setup->vmid->data[slot][i] - setup->vmin->data[slot][i]; - GLfloat majda = setup->vmax->data[slot][i] - setup->vmin->data[slot][i]; - GLfloat a = setup->ebot.dy * majda - botda * setup->emaj.dy; - GLfloat b = setup->emaj.dx * botda - majda * setup->ebot.dx; - - setup->coef[slot].dadx[i] = a * setup->oneoverarea; - setup->coef[slot].dady[i] = b * setup->oneoverarea; - - /* calculate a0 as the value which would be sampled for the - * fragment at (0,0), taking into account that we want to sample at - * pixel centers, in other words (0.5, 0.5). - * - * this is neat but unfortunately not a good way to do things for - * triangles with very large values of dadx or dady as it will - * result in the subtraction and re-addition from a0 of a very - * large number, which means we'll end up loosing a lot of the - * fractional bits and precision from a0. the way to fix this is - * to define a0 as the sample at a pixel center somewhere near vmin - * instead - i'll switch to this later. - */ - setup->coef[slot].a0[i] = (setup->vmin->data[slot][i] - - (setup->coef[slot].dadx[i] * (setup->vmin->data[0][0] - 0.5) + - setup->coef[slot].dady[i] * (setup->vmin->data[0][1] - 0.5))); - - _mesa_printf("attr[%d].%c: %f dx:%f dy:%f\n", - slot, "xyzw"[i], - setup->coef[slot].a0[i], - setup->coef[slot].dadx[i], - setup->coef[slot].dady[i]); -} - - -/** - * Compute a0, dadx and dady for a perspective-corrected interpolant, - * for a triangle. - */ -static void tri_persp_coeff( struct setup_stage *setup, - GLuint slot, - GLuint i ) -{ - /* premultiply by 1/w: - */ - GLfloat mina = setup->vmin->data[slot][i] * setup->vmin->data[0][3]; - GLfloat mida = setup->vmid->data[slot][i] * setup->vmid->data[0][3]; - GLfloat maxa = setup->vmax->data[slot][i] * setup->vmax->data[0][3]; - - GLfloat botda = mida - mina; - GLfloat majda = maxa - mina; - GLfloat a = setup->ebot.dy * majda - botda * setup->emaj.dy; - GLfloat b = setup->emaj.dx * botda - majda * setup->ebot.dx; - - setup->coef[slot].dadx[i] = a * setup->oneoverarea; - setup->coef[slot].dady[i] = b * setup->oneoverarea; - setup->coef[slot].a0[i] = (mina - - (setup->coef[slot].dadx[i] * (setup->vmin->data[0][0] - 0.5) + - setup->coef[slot].dady[i] * (setup->vmin->data[0][1] - 0.5))); -} - - - -/** - * Compute the setup->coef[] array dadx, dady, a0 values. - * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized. - */ -static void setup_tri_coefficients( struct setup_stage *setup ) -{ - const enum interp_mode *interp = setup->stage.generic->interp; - GLuint slot, j; - - /* z and w are done by linear interpolation: - */ - tri_linear_coeff(setup, 0, 2); - tri_linear_coeff(setup, 0, 3); - - /* setup interpolation for all the remaining attributes: - */ - for (slot = 1; slot < setup->quad.nr_attrs; slot++) { - switch (interp[slot]) { - case INTERP_CONSTANT: - for (j = 0; j < NUM_CHANNELS; j++) - const_coeff(setup, slot, j); - break; - - case INTERP_LINEAR: - for (j = 0; j < NUM_CHANNELS; j++) - tri_linear_coeff(setup, slot, j); - break; - - case INTERP_PERSPECTIVE: - for (j = 0; j < NUM_CHANNELS; j++) - tri_persp_coeff(setup, slot, j); - break; - } - } -} - - - -static void setup_tri_edges( struct setup_stage *setup ) -{ - GLfloat vmin_x = setup->vmin->data[0][0] + 0.5; - GLfloat vmid_x = setup->vmid->data[0][0] + 0.5; - - GLfloat vmin_y = setup->vmin->data[0][1] - 0.5; - GLfloat vmid_y = setup->vmid->data[0][1] - 0.5; - GLfloat vmax_y = setup->vmax->data[0][1] - 0.5; - - setup->emaj.sy = ceilf(vmin_y); - setup->emaj.lines = (GLint) ceilf(vmax_y - setup->emaj.sy); - setup->emaj.dxdy = setup->emaj.dx / setup->emaj.dy; - setup->emaj.sx = vmin_x + (setup->emaj.sy - vmin_y) * setup->emaj.dxdy; - - setup->etop.sy = ceilf(vmid_y); - setup->etop.lines = (GLint) ceilf(vmax_y - setup->etop.sy); - setup->etop.dxdy = setup->etop.dx / setup->etop.dy; - setup->etop.sx = vmid_x + (setup->etop.sy - vmid_y) * setup->etop.dxdy; - - setup->ebot.sy = ceilf(vmin_y); - setup->ebot.lines = (GLint) ceilf(vmid_y - setup->ebot.sy); - setup->ebot.dxdy = setup->ebot.dx / setup->ebot.dy; - setup->ebot.sx = vmin_x + (setup->ebot.sy - vmin_y) * setup->ebot.dxdy; -} - - -/** - * Render the upper or lower half of a triangle. - * Scissoring is applied here too. - */ -static void subtriangle( struct setup_stage *setup, - struct edge *eleft, - struct edge *eright, - GLuint lines ) -{ - GLint y, start_y, finish_y; - GLint sy = (GLint)eleft->sy; - - assert((GLint)eleft->sy == (GLint) eright->sy); - assert((GLint)eleft->sy >= 0); /* catch bug in x64? */ - - /* scissor y: - */ - if (setup->stage.generic->setup.scissor) { - start_y = sy; - finish_y = start_y + lines; - - if (start_y < setup->stage.generic->scissor.miny) - start_y = setup->stage.generic->scissor.miny; - - if (finish_y > setup->stage.generic->scissor.maxy) - finish_y = setup->stage.generic->scissor.maxy; - - start_y -= sy; - finish_y -= sy; - } - else { - start_y = 0; - finish_y = lines; - } - - _mesa_printf("%s %d %d\n", __FUNCTION__, start_y, finish_y); - - for (y = start_y; y < finish_y; y++) { - - /* avoid accumulating adds as floats don't have the precision to - * accurately iterate large triangle edges that way. luckily we - * can just multiply these days. - * - * this is all drowned out by the attribute interpolation anyway. - */ - GLint left = (GLint)(eleft->sx + y * eleft->dxdy); - GLint right = (GLint)(eright->sx + y * eright->dxdy); - - /* scissor x: - */ - if (setup->stage.generic->setup.scissor) { - if (left < setup->stage.generic->scissor.minx) - left = setup->stage.generic->scissor.minx; - - if (right > setup->stage.generic->scissor.maxx) - right = setup->stage.generic->scissor.maxx; - } - - if (left < right) { - GLint _y = sy+y; - if (block(_y) != setup->span.y) { - flush_spans(setup); - setup->span.y = block(_y); - } - - setup->span.left[_y&1] = left; - setup->span.right[_y&1] = right; - setup->span.y_flags |= 1<<(_y&1); - } - } - - - /* save the values so that emaj can be restarted: - */ - eleft->sx += lines * eleft->dxdy; - eright->sx += lines * eright->dxdy; - eleft->sy += lines; - eright->sy += lines; -} - - -/** - * Do setup for triangle rasterization, then render the triangle. - */ -static void setup_tri( struct prim_stage *stage, - struct prim_header *prim ) -{ - struct setup_stage *setup = setup_stage( stage ); - - _mesa_printf("%s\n", __FUNCTION__ ); - - setup_sort_vertices( setup, prim ); - setup_tri_coefficients( setup ); - setup_tri_edges( setup ); - - setup->span.y = 0; - setup->span.y_flags = 0; - setup->span.right[0] = 0; - setup->span.right[1] = 0; -// setup->span.z_mode = tri_z_mode( setup->ctx ); - -// init_constant_attribs( setup ); - - if (setup->oneoverarea < 0.0) { - /* emaj on left: - */ - subtriangle( setup, &setup->emaj, &setup->ebot, setup->ebot.lines ); - subtriangle( setup, &setup->emaj, &setup->etop, setup->etop.lines ); - } - else { - /* emaj on right: - */ - subtriangle( setup, &setup->ebot, &setup->emaj, setup->ebot.lines ); - subtriangle( setup, &setup->etop, &setup->emaj, setup->etop.lines ); - } - - flush_spans( setup ); -} - - - -/** - * Compute a0, dadx and dady for a linearly interpolated coefficient, - * for a line. - */ -static void -line_linear_coeff(struct setup_stage *setup, GLuint slot, GLuint i) -{ - const GLfloat dz = setup->vmax->data[slot][i] - setup->vmin->data[slot][i]; - const GLfloat dadx = dz * setup->emaj.dx * setup->oneoverarea; - const GLfloat dady = dz * setup->emaj.dy * setup->oneoverarea; - setup->coef[slot].dadx[i] = dadx; - setup->coef[slot].dady[i] = dady; - setup->coef[slot].a0[i] - = (setup->vmin->data[slot][i] - - (dadx * (setup->vmin->data[0][0] - 0.5) + - dady * (setup->vmin->data[0][1] - 0.5))); -} - - -/** - * Compute a0, dadx and dady for a perspective-corrected interpolant, - * for a line. - */ -static void -line_persp_coeff(struct setup_stage *setup, GLuint slot, GLuint i) -{ - /* XXX to do */ - line_linear_coeff(setup, slot, i); /* XXX temporary */ -} - - -/** - * Compute the setup->coef[] array dadx, dady, a0 values. - * Must be called after setup->vmin,vmax are initialized. - */ -static INLINE void -setup_line_coefficients(struct setup_stage *setup, struct prim_header *prim) -{ - const enum interp_mode *interp = setup->stage.generic->interp; - GLuint slot, j; - - /* use setup->vmin, vmax to point to vertices */ - setup->vprovoke = prim->v[1]; - setup->vmin = prim->v[0]; - setup->vmax = prim->v[1]; - - setup->emaj.dx = setup->vmax->data[0][0] - setup->vmin->data[0][0]; - setup->emaj.dy = setup->vmax->data[0][1] - setup->vmin->data[0][1]; - /* NOTE: this is not really 1/area */ - setup->oneoverarea = 1.0 / (setup->emaj.dx * setup->emaj.dx + - setup->emaj.dy * setup->emaj.dy); - - /* z and w are done by linear interpolation: - */ - line_linear_coeff(setup, 0, 2); - line_linear_coeff(setup, 0, 3); - - /* setup interpolation for all the remaining attributes: - */ - for (slot = 1; slot < setup->quad.nr_attrs; slot++) { - switch (interp[slot]) { - case INTERP_CONSTANT: - for (j = 0; j < NUM_CHANNELS; j++) - const_coeff(setup, slot, j); - break; - - case INTERP_LINEAR: - for (j = 0; j < NUM_CHANNELS; j++) - line_linear_coeff(setup, slot, j); - break; - - case INTERP_PERSPECTIVE: - for (j = 0; j < NUM_CHANNELS; j++) - line_persp_coeff(setup, slot, j); - break; - } - } -} - - -/** - * Plot a pixel in a line segment. - */ -static INLINE void -plot(struct setup_stage *setup, GLint x, GLint y) -{ - const GLint iy = y & 1; - const GLint ix = x & 1; - const GLint quadX = x - ix; - const GLint quadY = y - iy; - const GLint mask = (1 << ix) << (2 * iy); - - if (quadX != setup->quad.x0 || - quadY != setup->quad.y0) - { - /* flush prev quad, start new quad */ - - if (setup->quad.x0 != -1) - quad_shade(setup->stage.generic, &setup->quad); - - setup->quad.x0 = quadX; - setup->quad.y0 = quadY; - setup->quad.mask = 0x0; - } - - setup->quad.mask |= mask; -} - - - -/** - * Do setup for line rasterization, then render the line. - * XXX single-pixel width, no stipple, etc - * XXX no scissoring yet. - */ -static void -setup_line(struct prim_stage *stage, struct prim_header *prim) -{ - const struct vertex_header *v0 = prim->v[0]; - const struct vertex_header *v1 = prim->v[1]; - struct setup_stage *setup = setup_stage( stage ); - - GLint x0 = (GLint) v0->data[0][0]; - GLint x1 = (GLint) v1->data[0][0]; - GLint y0 = (GLint) v0->data[0][1]; - GLint y1 = (GLint) v1->data[0][1]; - GLint dx = x1 - x0; - GLint dy = y1 - y0; - GLint xstep, ystep; - - if (dx == 0 && dy == 0) - return; - - setup_line_coefficients(setup, prim); - - if (dx < 0) { - dx = -dx; /* make positive */ - xstep = -1; - } - else { - xstep = 1; - } - - if (dy < 0) { - dy = -dy; /* make positive */ - ystep = -1; - } - else { - ystep = 1; - } - - assert(dx >= 0); - assert(dy >= 0); - - setup->quad.x0 = setup->quad.y0 = -1; - setup->quad.mask = 0x0; - - if (dx > dy) { - /*** X-major line ***/ - GLint i; - const GLint errorInc = dy + dy; - GLint error = errorInc - dx; - const GLint errorDec = error - dx; - - for (i = 0; i < dx; i++) { - plot(setup, x0, y0); - - x0 += xstep; - if (error < 0) { - error += errorInc; - } - else { - error += errorDec; - y0 += ystep; - } - } - } - else { - /*** Y-major line ***/ - GLint i; - const GLint errorInc = dx + dx; - GLint error = errorInc - dy; - const GLint errorDec = error - dy; - - for (i = 0; i < dy; i++) { - plot(setup, x0, y0); - - y0 += ystep; - - if (error < 0) { - error += errorInc; - } - else { - error += errorDec; - x0 += xstep; - } - } - } - - /* draw final quad */ - if (setup->quad.mask) { - quad_shade(setup->stage.generic, &setup->quad); - } -} - - -/** - * Do setup for point rasterization, then render the point. - * Round or square points... - * XXX could optimize a lot for 1-pixel points. - */ -static void -setup_point(struct prim_stage *stage, struct prim_header *prim) -{ - struct setup_stage *setup = setup_stage( stage ); - GLfloat halfSize = 7.3; /*XXX this is a vertex attrib */ - GLfloat halfSizeSquared = halfSize * halfSize; - const struct vertex_header *v0 = prim->v[0]; - const GLfloat x = v0->data[FRAG_ATTRIB_WPOS][0]; - const GLfloat y = v0->data[FRAG_ATTRIB_WPOS][1]; - const GLint ixmin = block((GLint) (x - halfSize)); - const GLint ixmax = block((GLint) (x + halfSize)); - const GLint iymin = block((GLint) (y - halfSize)); - const GLint iymax = block((GLint) (y + halfSize)); - GLboolean round = GL_TRUE; - GLint ix, iy; - GLuint slot, j; - - /* For points, all interpolants are constant-valued. - * However, for point sprites, we'll need to setup texcoords appropriately. - * XXX: which coefficients are the texcoords??? - * We may do point sprites as textured quads... - * - * KW: We don't know which coefficients are texcoords - ultimately - * the choice of what interpolation mode to use for each attribute - * should be determined by the fragment program, using - * per-attribute declaration statements that include interpolation - * mode as a parameter. So either the fragment program will have - * to be adjusted for pointsprite vs normal point behaviour, or - * otherwise a special interpolation mode will have to be defined - * which matches the required behaviour for point sprites. But - - * the latter is not a feature of normal hardware, and as such - * probably should be ruled out on that basis. - */ - setup->vprovoke = prim->v[0]; - const_coeff(setup, 0, 2); - const_coeff(setup, 0, 3); - for (slot = 1; slot < setup->quad.nr_attrs; slot++) { - for (j = 0; j < NUM_CHANNELS; j++) - const_coeff(setup, slot, j); - } - - /* XXX need to clip against scissor bounds too */ - - for (iy = iymin; iy <= iymax; iy += 2) { - for (ix = ixmin; ix <= ixmax; ix += 2) { - - if (round) { - /* rounded points */ - /* XXX for GL_SMOOTH, need to compute per-fragment coverage too */ - GLfloat dx, dy; - - setup->quad.mask = 0x0; - - dx = (ix + 0.5) - x; - dy = (iy + 0.5) - y; - if (dx * dx + dy * dy <= halfSizeSquared) - setup->quad.mask |= MASK_BOTTOM_LEFT; - - dx = (ix + 1.5) - x; - dy = (iy + 0.5) - y; - if (dx * dx + dy * dy <= halfSizeSquared) - setup->quad.mask |= MASK_BOTTOM_RIGHT; - - dx = (ix + 0.5) - x; - dy = (iy + 1.5) - y; - if (dx * dx + dy * dy <= halfSizeSquared) - setup->quad.mask |= MASK_TOP_LEFT; - - dx = (ix + 1.5) - x; - dy = (iy + 1.5) - y; - if (dx * dx + dy * dy <= halfSizeSquared) - setup->quad.mask |= MASK_TOP_RIGHT; - } - else { - /* square points */ - setup->quad.mask = 0xf; - - if (ix + 0.5 < x - halfSize) - setup->quad.mask &= (MASK_BOTTOM_RIGHT | MASK_TOP_RIGHT); - - if (ix + 1.5 > x + halfSize) - setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_TOP_LEFT); - - if (iy + 0.5 < y - halfSize) - setup->quad.mask &= (MASK_TOP_LEFT | MASK_TOP_RIGHT); - - if (iy + 1.5 > y + halfSize) - setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_BOTTOM_RIGHT); - } - - if (setup->quad.mask) { - setup->quad.x0 = ix; - setup->quad.y0 = iy; - quad_shade( setup->stage.generic, &setup->quad ); - } - } - } -} - - - -static void setup_end( struct prim_stage *stage ) -{ -} - - -struct prim_stage *prim_setup( struct generic_context *generic ) -{ - struct setup_stage *setup = CALLOC_STRUCT(setup_stage); - - setup->stage.generic = generic; - setup->stage.begin = setup_begin; - setup->stage.point = setup_point; - setup->stage.line = setup_line; - setup->stage.tri = setup_tri; - setup->stage.end = setup_end; - - setup->quad.coef = setup->coef; - - return &setup->stage; -} diff --git a/src/mesa/pipe/softpipe/g_prim_setup.h b/src/mesa/pipe/softpipe/g_prim_setup.h deleted file mode 100644 index 40a70c543e..0000000000 --- a/src/mesa/pipe/softpipe/g_prim_setup.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5 - * - * Copyright (C) 1999-2005 Brian Paul 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, sublicense, - * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL 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 S_TRI_H -#define S_TRI_H - -/* Vertices are just an array of floats, with all the attributes - * packed. We currently assume a layout like: - * - * attr[0][0..3] - window position - * attr[1..n][0..3] - remaining attributes. - * - * Attributes are assumed to be 4 floats wide but are packed so that - * all the enabled attributes run contiguously. - */ - -#include "glheader.h" -#include "imports.h" -#include "s_tri_public.h" -#include "s_context.h" - - - -struct tri_context; -struct fp_context; -struct be_context; - -/* Note the rasterizer does not take a GLcontext argument. This is - * deliberate. - */ -struct tri_context *tri_create_context( GLcontext *ctx ); - -void tri_destroy_context( struct tri_context *tri ); - -void tri_set_fp_context( struct tri_context *tri, - struct fp_context *fp, - void (*fp_run)( struct fp_context *fp, - const struct fp_inputs *, - struct fp_outputs * )); - - -void tri_set_be_context( struct tri_context *tri, - struct be_context *be, - void (*be_run)( struct be_context *be, - const struct fp_outputs * )); - -void tri_set_attribs( struct tri_context *tri, - const struct attr_info *info, - GLuint nr_attrib ); - -void tri_set_backface( struct tri_context *tri, - GLfloat backface ); - -void tri_set_scissor( struct tri_context *tri, - GLint x, - GLint y, - GLuint width, - GLuint height, - GLboolean enabled ); - -void tri_set_stipple( struct tri_context *tri, - const GLuint *pattern, - GLboolean enabled ); - -/* Unfilled triangles will be handled elsewhere (higher in the - * pipeline), as will things like stipple (lower in the pipeline). - */ - -void tri_triangle( struct tri_context *tri, - const struct vertex *v0, - const struct vertex *v1, - const struct vertex *v2 ); - -/* TODO: rasterize_line, rasterize_point?? - * How will linestipple work? - */ - - -#ifdef SETUP_PRIVATE - - - - - - -GLboolean tri_setup( struct tri_context *tri, - const struct vertex *v0, - const struct vertex *v1, - const struct vertex *v2 ); - -void tri_rasterize( struct tri_context *tri ); -void tri_rasterize_spans( struct tri_context *tri ); - - - - - - -#endif -#endif diff --git a/src/mesa/pipe/softpipe/g_prim_twoside.c b/src/mesa/pipe/softpipe/g_prim_twoside.c deleted file mode 100644 index 334ae2f537..0000000000 --- a/src/mesa/pipe/softpipe/g_prim_twoside.c +++ /dev/null @@ -1,149 +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 - */ -#include "imports.h" -#include "g_context.h" -#include "g_prim.h" - - -struct twoside_stage { - struct prim_stage stage; - - GLfloat facing; - const GLuint *lookup; -}; - - -static INLINE struct twoside_stage *twoside_stage( struct prim_stage *stage ) -{ - return (struct twoside_stage *)stage; -} - - -static void twoside_begin( struct prim_stage *stage ) -{ - struct twoside_stage *twoside = twoside_stage(stage); - - twoside->facing = (stage->generic->setup.front_winding == WINDING_CW) ? -1 : 1; - - stage->next->begin( stage->next ); -} - - -static INLINE void copy_color( GLuint attr_dst, - GLuint attr_src, - struct vertex_header *v ) -{ - if (attr_dst && attr_src) { - memcpy( v->data[attr_dst], - v->data[attr_src], - sizeof(v->data[0]) ); - } -} - - -static struct vertex_header *copy_bfc( struct twoside_stage *twoside, - const struct vertex_header *v, - GLuint idx ) -{ - struct vertex_header *tmp = dup_vert( &twoside->stage, v, idx ); - - copy_color( twoside->lookup[VF_ATTRIB_COLOR0], - twoside->lookup[VF_ATTRIB_BFC0], - tmp ); - - copy_color( twoside->lookup[VF_ATTRIB_COLOR1], - twoside->lookup[VF_ATTRIB_BFC1], - tmp ); - - return tmp; -} - - -/* Twoside tri: - */ -static void twoside_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - struct twoside_stage *twoside = twoside_stage(stage); - - if (header->det * twoside->facing < 0) { - struct prim_header tmp; - - tmp.det = header->det; - tmp.v[0] = copy_bfc(twoside, header->v[0], 0); - tmp.v[1] = copy_bfc(twoside, header->v[1], 1); - tmp.v[2] = copy_bfc(twoside, header->v[2], 2); - - stage->next->tri( stage->next, &tmp ); - } - else { - stage->next->tri( stage->next, header ); - } -} - - -static void twoside_line( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->line( stage->next, header ); -} - - -static void twoside_point( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->point( stage->next, header ); -} - -static void twoside_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - - - -struct prim_stage *prim_twoside( struct generic_context *generic ) -{ - struct twoside_stage *twoside = CALLOC_STRUCT(twoside_stage); - - prim_alloc_tmps( &twoside->stage, 3 ); - - twoside->stage.generic = generic; - twoside->stage.next = NULL; - twoside->stage.begin = twoside_begin; - twoside->stage.point = twoside_point; - twoside->stage.line = twoside_line; - twoside->stage.tri = twoside_tri; - twoside->stage.end = twoside_end; - - twoside->lookup = generic->vf_attr_to_slot; - - return &twoside->stage; -} diff --git a/src/mesa/pipe/softpipe/g_prim_unfilled.c b/src/mesa/pipe/softpipe/g_prim_unfilled.c deleted file mode 100644 index 7c6ee79f92..0000000000 --- a/src/mesa/pipe/softpipe/g_prim_unfilled.c +++ /dev/null @@ -1,165 +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 - */ -#include "imports.h" - -#include "g_context.h" -#include "g_prim.h" - - - -struct unfilled_stage { - struct prim_stage stage; - - GLuint mode[2]; -}; - - -static INLINE struct unfilled_stage *unfilled_stage( struct prim_stage *stage ) -{ - return (struct unfilled_stage *)stage; -} - - -static void unfilled_begin( struct prim_stage *stage ) -{ - struct unfilled_stage *unfilled = unfilled_stage(stage); - - unfilled->mode[0] = stage->generic->setup.fill_ccw; - unfilled->mode[1] = stage->generic->setup.fill_cw; - - stage->next->begin( stage->next ); -} - -static void point( struct prim_stage *stage, - struct vertex_header *v0 ) -{ - struct prim_header tmp; - tmp.v[0] = v0; - stage->next->point( stage->next, &tmp ); -} - -static void line( struct prim_stage *stage, - struct vertex_header *v0, - struct vertex_header *v1 ) -{ - struct prim_header tmp; - tmp.v[0] = v0; - tmp.v[1] = v1; - stage->next->line( stage->next, &tmp ); -} - - -static void points( struct prim_stage *stage, - struct prim_header *header ) -{ - struct vertex_header *v0 = header->v[0]; - struct vertex_header *v1 = header->v[1]; - struct vertex_header *v2 = header->v[2]; - - if (v0->edgeflag) point( stage, v0 ); - if (v1->edgeflag) point( stage, v1 ); - if (v2->edgeflag) point( stage, v2 ); -} - -static void lines( struct prim_stage *stage, - struct prim_header *header ) -{ - struct vertex_header *v0 = header->v[0]; - struct vertex_header *v1 = header->v[1]; - struct vertex_header *v2 = header->v[2]; - - if (v0->edgeflag) line( stage, v0, v1 ); - if (v1->edgeflag) line( stage, v1, v2 ); - if (v2->edgeflag) line( stage, v2, v0 ); -} - - -/* Unfilled tri: - * - * Note edgeflags in the vertex struct is not sufficient as we will - * need to manipulate them when decomposing primitives??? - */ -static void unfilled_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - struct unfilled_stage *unfilled = unfilled_stage(stage); - GLuint mode = unfilled->mode[header->det < 0]; - - switch (mode) { - case FILL_TRI: - stage->next->tri( stage->next, header ); - break; - - case FILL_LINE: - lines( stage, header ); - break; - - case GL_POINT: - points( stage, header ); - break; - } -} - -static void unfilled_line( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->line( stage->next, header ); -} - - -static void unfilled_point( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->point( stage->next, header ); -} - - -static void unfilled_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - -struct prim_stage *prim_unfilled( struct generic_context *generic ) -{ - struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage); - - prim_alloc_tmps( &unfilled->stage, 0 ); - - unfilled->stage.generic = generic; - unfilled->stage.next = NULL; - unfilled->stage.tmp = NULL; - unfilled->stage.begin = unfilled_begin; - unfilled->stage.point = unfilled_point; - unfilled->stage.line = unfilled_line; - unfilled->stage.tri = unfilled_tri; - unfilled->stage.end = unfilled_end; - - return &unfilled->stage; -} diff --git a/src/mesa/pipe/softpipe/g_state.h b/src/mesa/pipe/softpipe/g_state.h deleted file mode 100644 index 5077d37ab7..0000000000 --- a/src/mesa/pipe/softpipe/g_state.h +++ /dev/null @@ -1,61 +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 - */ - -#ifndef PRIM_H -#define PRIM_H - -#include "glheader.h" -#include "softpipe/sp_state.h" - - -void generic_set_clip_state( struct softpipe_context *, - const struct softpipe_clip_state * ); - -void generic_set_viewport( struct softpipe_context *, - const struct softpipe_viewport * ); - -void generic_set_setup_state( struct softpipe_context *, - const struct softpipe_setup_state * ); - -void generic_set_scissor_rect( struct softpipe_context *, - const struct softpipe_scissor_rect * ); - -void generic_set_fs_state( struct softpipe_context *, - const struct softpipe_fs_state * ); - -void generic_set_polygon_stipple( struct softpipe_context *, - const struct softpipe_poly_stipple * ); - -void generic_set_cbuf_state( struct softpipe_context *, - const struct softpipe_surface * ); - -void generic_update_derived( struct generic_context *generic ); - -#endif diff --git a/src/mesa/pipe/softpipe/g_state_clip.c b/src/mesa/pipe/softpipe/g_state_clip.c deleted file mode 100644 index b90034e11e..0000000000 --- a/src/mesa/pipe/softpipe/g_state_clip.c +++ /dev/null @@ -1,69 +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 - */ -#include "imports.h" - -#include "g_context.h" -#include "g_state.h" -#include "g_draw.h" - - - -void generic_set_clip_state( struct softpipe_context *softpipe, - const struct softpipe_clip_state *clip ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy(&generic->plane[6], clip->ucp, clip->nr * sizeof(clip->ucp[0])); - - generic->nr_planes = 6 + clip->nr; - generic->dirty |= G_NEW_CLIP; -} - - - -/* Called when driver state tracker notices changes to the viewport - * matrix: - */ -void generic_set_viewport( struct softpipe_context *softpipe, - const struct softpipe_viewport *viewport ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy(&generic->viewport, viewport, sizeof(viewport)); - - /* Using tnl/ and vf/ modules is temporary while getting started. - * Full softpipe will have vertex shader, vertex fetch of its own. - */ - draw_set_viewport( generic->draw, viewport->scale, viewport->translate ); - generic->dirty |= G_NEW_VIEWPORT; -} - - - diff --git a/src/mesa/pipe/softpipe/g_state_derived.c b/src/mesa/pipe/softpipe/g_state_derived.c deleted file mode 100644 index 678825afe1..0000000000 --- a/src/mesa/pipe/softpipe/g_state_derived.c +++ /dev/null @@ -1,136 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "glheader.h" -#include "macros.h" -#include "enums.h" -#include "program.h" - -#include "g_context.h" -#include "g_draw.h" -#include "g_state.h" - -#define EMIT_ATTR( ATTR, FRAG_ATTR, INTERP ) \ -do { \ - slot_to_vf_attr[generic->nr_attrs] = ATTR; \ - generic->vf_attr_to_slot[ATTR] = generic->nr_attrs; \ - generic->fp_attr_to_slot[FRAG_ATTR] = generic->nr_attrs; \ - generic->interp[generic->nr_attrs] = INTERP; \ - generic->nr_attrs++; \ - attr_mask |= (1<fs.fp; - const GLuint inputsRead = fp->Base.InputsRead; - GLuint slot_to_vf_attr[VF_ATTRIB_MAX]; - GLuint attr_mask = 0; - GLuint i; - - generic->nr_attrs = 0; - memset(slot_to_vf_attr, 0, sizeof(slot_to_vf_attr)); - - memset(generic->fp_attr_to_slot, 0, sizeof(generic->vf_attr_to_slot)); - memset(generic->vf_attr_to_slot, 0, sizeof(generic->fp_attr_to_slot)); - - /* TODO - Figure out if we need to do perspective divide, etc. - */ - EMIT_ATTR(VF_ATTRIB_POS, FRAG_ATTRIB_WPOS, 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++) { - if (inputsRead & (i << i)) { - EMIT_ATTR(frag_to_vf[i], i, INTERP_LINEAR); - } - } - - for (i = FRAG_ATTRIB_TEX0; i < FRAG_ATTRIB_MAX; i++) { - if (inputsRead & (i << i)) { - EMIT_ATTR(frag_to_vf[i], i, INTERP_PERSPECTIVE); - } - } - - generic->nr_frag_attrs = generic->nr_attrs; - - /* Additional attributes required for setup: Just twosided - * lighting. Edgeflag is dealt with specially by setting bits in - * the vertex header. - */ - if (generic->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 & FRAG_BIT_COL1) { - EMIT_ATTR(VF_ATTRIB_BFC1, FRAG_ATTRIB_MAX, 0); /* XXX: discard after setup */ - } - } - - if (attr_mask != generic->attr_mask) { - generic->attr_mask = attr_mask; - - draw_set_vertex_attributes( generic->draw, - slot_to_vf_attr, - generic->nr_attrs ); - } -} - - -/* Hopefully this will remain quite simple, otherwise need to pull in - * something like the state tracker mechanism. - */ -void generic_update_derived( struct generic_context *generic ) -{ - if (generic->dirty & (G_NEW_SETUP | G_NEW_FS)) - calculate_vertex_layout( generic ); - - generic->dirty = 0; -} diff --git a/src/mesa/pipe/softpipe/g_state_fs.c b/src/mesa/pipe/softpipe/g_state_fs.c deleted file mode 100644 index 8a430c0c65..0000000000 --- a/src/mesa/pipe/softpipe/g_state_fs.c +++ /dev/null @@ -1,50 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "g_context.h" -#include "g_state.h" - - - -void generic_set_fs_state( struct softpipe_context *softpipe, - const struct softpipe_fs_state *fs ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy(&generic->fs, fs, sizeof(*fs)); - - generic->dirty |= G_NEW_FS; -} - - - - - - - - - diff --git a/src/mesa/pipe/softpipe/g_state_setup.c b/src/mesa/pipe/softpipe/g_state_setup.c deleted file mode 100644 index 2a5176c5a1..0000000000 --- a/src/mesa/pipe/softpipe/g_state_setup.c +++ /dev/null @@ -1,122 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "g_context.h" -#include "g_state.h" -#include "g_prim.h" - - - - -static void validate_prim_pipe( struct generic_context *generic ) -{ - struct prim_stage *next = generic->prim.setup; - - /* TODO: make the current primitive part of the state and build - * shorter pipelines for lines & points. - */ - if (generic->setup.fill_cw != FILL_TRI || - generic->setup.fill_ccw != FILL_TRI) { - - generic->prim.unfilled->next = next; - next = generic->prim.unfilled; - } - - if (generic->setup.offset_cw || - generic->setup.offset_ccw) { - generic->prim.offset->next = next; - next = generic->prim.offset; - } - - if (generic->setup.light_twoside) { - generic->prim.twoside->next = next; - next = generic->prim.twoside; - } - - /* Always run the cull stage as we calculate determinant there - * also. Fix this.. - */ - { - generic->prim.cull->next = next; - next = generic->prim.cull; - } - - - /* Clip stage - */ - { - generic->prim.clip->next = next; - next = generic->prim.clip; - } - - /* Do software flatshading prior to clipping. XXX: should only do - * this for clipped primitives, ie it is a part of the clip - * routine. - */ - if (generic->setup.flatshade) { - generic->prim.flatshade->next = next; - next = generic->prim.flatshade; - } - - - generic->prim.first = next; -} - - - - -void generic_set_setup_state( struct softpipe_context *softpipe, - const struct softpipe_setup_state *setup ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy( &generic->setup, setup, sizeof(*setup) ); - - validate_prim_pipe( generic ); - generic->dirty |= G_NEW_SETUP; -} - - - -void generic_set_scissor_rect( struct softpipe_context *softpipe, - const struct softpipe_scissor_rect *scissor ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy( &generic->scissor, scissor, sizeof(*scissor) ); - generic->dirty |= G_NEW_SCISSOR; -} - - -void generic_set_polygon_stipple( struct softpipe_context *softpipe, - const struct softpipe_poly_stipple *stipple ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy( &generic->poly_stipple, stipple, sizeof(*stipple) ); - generic->dirty |= G_NEW_STIPPLE; -} diff --git a/src/mesa/pipe/softpipe/g_state_surface.c b/src/mesa/pipe/softpipe/g_state_surface.c deleted file mode 100644 index c791ce4640..0000000000 --- a/src/mesa/pipe/softpipe/g_state_surface.c +++ /dev/null @@ -1,53 +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 - */ -#include "imports.h" - -#include "g_context.h" -#include "g_state.h" -#include "g_surface.h" - - -/* This is all a total hack. - */ -void generic_set_cbuf_state( struct softpipe_context *softpipe, - const struct softpipe_surface *surface ) -{ - struct generic_context *generic = generic_context(softpipe); - - if (generic->cbuf_surface == NULL) { - generic->cbuf_surface = CALLOC_STRUCT(generic_surface); - generic->cbuf_surface->type = &gs_rgba8; - } - - generic->cbuf_surface->surface = *surface; - generic->dirty |= G_NEW_CBUF; -} - - diff --git a/src/mesa/pipe/softpipe/g_surface.c b/src/mesa/pipe/softpipe/g_surface.c deleted file mode 100644 index 2df30cde70..0000000000 --- a/src/mesa/pipe/softpipe/g_surface.c +++ /dev/null @@ -1,153 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "g_context.h" -#include "g_state.h" -#include "g_surface.h" -#include "g_headers.h" - -static void rgba8_read_quad_f( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - rgba[k][0] = ptr[0] * (1.0 / 255.0); - rgba[k][1] = ptr[1] * (1.0 / 255.0); - rgba[k][2] = ptr[2] * (1.0 / 255.0); - rgba[k][3] = ptr[3] * (1.0 / 255.0); - } - } -} - -static void rgba8_read_quad_f_swz( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - rrrr[0][k] = ptr[0] * (1.0 / 255.0); - rrrr[1][k] = ptr[1] * (1.0 / 255.0); - rrrr[2][k] = ptr[2] * (1.0 / 255.0); - rrrr[3][k] = ptr[3] * (1.0 / 255.0); - } - } -} - -static void rgba8_write_quad_f( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - ptr[0] = rgba[k][0] * 255.0; - ptr[1] = rgba[k][1] * 255.0; - ptr[2] = rgba[k][2] * 255.0; - ptr[3] = rgba[k][3] * 255.0; - } - } -} - -static void rgba8_write_quad_f_swz( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - ptr[0] = rrrr[0][k] * 255.0; - ptr[1] = rrrr[1][k] * 255.0; - ptr[2] = rrrr[2][k] * 255.0; - ptr[3] = rrrr[3][k] * 255.0; - } - } -} - - - - -static void rgba8_read_quad_ub( struct generic_surface *gs, - GLint x, GLint y, - GLubyte (*rgba)[NUM_CHANNELS] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - rgba[k][0] = ptr[0]; - rgba[k][1] = ptr[1]; - rgba[k][2] = ptr[2]; - rgba[k][3] = ptr[3]; - } - } -} - - -static void rgba8_write_quad_ub( struct generic_surface *gs, - GLint x, GLint y, - GLubyte (*rgba)[NUM_CHANNELS] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - ptr[0] = rgba[k][0]; - ptr[1] = rgba[k][1]; - ptr[2] = rgba[k][2]; - ptr[3] = rgba[k][3]; - } - } -} - - - - -struct generic_surface_type gs_rgba8 = { - G_SURFACE_RGBA_8888, - rgba8_read_quad_f, - rgba8_read_quad_f_swz, - rgba8_read_quad_ub, - rgba8_write_quad_f, - rgba8_write_quad_f_swz, - rgba8_write_quad_ub, -}; - - - diff --git a/src/mesa/pipe/softpipe/g_surface.h b/src/mesa/pipe/softpipe/g_surface.h deleted file mode 100644 index 23c28f0bb4..0000000000 --- a/src/mesa/pipe/softpipe/g_surface.h +++ /dev/null @@ -1,115 +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 - */ - -#ifndef G_SURFACE_H -#define G_SURFACE_H - -#include "glheader.h" -#include "g_headers.h" - -struct generic_surface; - -#define G_SURFACE_RGBA_8888 0x1 - -/* Internal structs and helpers for the primitive clip/setup pipeline: - */ -struct generic_surface_type { - - GLuint format; - - void (*read_quad_f)( struct generic_surface *, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ); - - void (*read_quad_f_swz)( struct generic_surface *, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ); - - void (*read_quad_ub)( struct generic_surface *, - GLint x, GLint y, - GLubyte (*rgba)[NUM_CHANNELS] ); - - - void (*write_quad_f)( struct generic_surface *, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ); - - void (*write_quad_f_swz)( struct generic_surface *, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ); - - - void (*write_quad_ub)( struct generic_surface *, - GLint x, GLint y, - GLubyte (*rgba)[NUM_CHANNELS] ); - - -}; - - -struct generic_surface { - struct generic_surface_type *type; - struct softpipe_surface surface; -}; - - -static INLINE void gs_read_quad_f( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ) -{ - gs->type->read_quad_f(gs, x, y, rgba); -} - -static INLINE void gs_read_quad_f_swz( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ) -{ - gs->type->read_quad_f_swz(gs, x, y, rrrr); -} - -static INLINE void gs_write_quad_f( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ) -{ - gs->type->write_quad_f(gs, x, y, rgba); -} - -static INLINE void gs_write_quad_f_swz( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ) -{ - gs->type->write_quad_f_swz(gs, x, y, rrrr); -} - -/* Like this, or hidden? - */ -struct generic_surface_type gs_rgba8; - -#endif diff --git a/src/mesa/pipe/softpipe/g_tile.h b/src/mesa/pipe/softpipe/g_tile.h deleted file mode 100644 index 6ae5212356..0000000000 --- a/src/mesa/pipe/softpipe/g_tile.h +++ /dev/null @@ -1,42 +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 - */ -#ifndef G_TILE_H -#define G_TILE_H - -struct generic_context; -struct quad_header; - -void quad_shade( struct generic_context *generic, - struct quad_header *quad ); - -void quad_output( struct generic_context *generic, - struct quad_header *quad ); - -#endif diff --git a/src/mesa/pipe/softpipe/g_tile_fs.c b/src/mesa/pipe/softpipe/g_tile_fs.c deleted file mode 100644 index 4c5e6efaed..0000000000 --- a/src/mesa/pipe/softpipe/g_tile_fs.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5 - * - * Copyright (C) 1999-2005 Brian Paul 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, sublicense, - * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL 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. - */ - -/* Vertices are just an array of floats, with all the attributes - * packed. We currently assume a layout like: - * - * attr[0][0..3] - window position - * attr[1..n][0..3] - remaining attributes. - * - * Attributes are assumed to be 4 floats wide but are packed so that - * all the enabled attributes run contiguously. - */ - -#include "glheader.h" -#include "g_context.h" -#include "g_headers.h" -#include "g_tile.h" - -struct exec_machine { - const struct setup_coefficient *coef; - - GLfloat attr[FRAG_ATTRIB_MAX][4][QUAD_SIZE]; -}; - - -/** - * Compute quad's attributes values, as constants (GL_FLAT shading). - */ -static INLINE void cinterp( struct exec_machine *exec, - GLuint attrib, - GLuint i ) -{ - GLuint j; - - for (j = 0; j < QUAD_SIZE; j++) { - exec->attr[attrib][i][j] = exec->coef[attrib].a0[i]; - } -} - - -/** - * Compute quad's attribute values by linear interpolation. - * - * Push into the fp: - * - * INPUT[attr] = MAD COEF_A0[attr], COEF_DADX[attr], INPUT_WPOS.xxxx - * INPUT[attr] = MAD INPUT[attr], COEF_DADY[attr], INPUT_WPOS.yyyy - */ -static INLINE void linterp( struct exec_machine *exec, - GLuint attrib, - GLuint i ) -{ - GLuint j; - - for (j = 0; j < QUAD_SIZE; j++) { - const GLfloat x = exec->attr[FRAG_ATTRIB_WPOS][0][j]; - const GLfloat y = exec->attr[FRAG_ATTRIB_WPOS][1][j]; - exec->attr[attrib][i][j] = (exec->coef[attrib].a0[i] + - exec->coef[attrib].dadx[i] * x + - exec->coef[attrib].dady[i] * y); - } -} - - -/** - * Compute quad's attribute values by linear interpolation with - * perspective correction. - * - * Push into the fp: - * - * INPUT[attr] = MAD COEF_A0[attr], COEF_DADX[attr], INPUT_WPOS.xxxx - * INPUT[attr] = MAD INPUT[attr], COEF_DADY[attr], INPUT_WPOS.yyyy - * INPUT[attr] = MUL INPUT[attr], INPUT_WPOS.wwww - * - * (Or should that be 1/w ???) - */ -static INLINE void pinterp( struct exec_machine *exec, - GLuint attrib, - GLuint i ) -{ - GLuint j; - - for (j = 0; j < QUAD_SIZE; j++) { - const GLfloat x = exec->attr[FRAG_ATTRIB_WPOS][0][j]; - const GLfloat y = exec->attr[FRAG_ATTRIB_WPOS][1][j]; - const GLfloat invW = exec->attr[FRAG_ATTRIB_WPOS][3][j]; - exec->attr[attrib][i][j] = ((exec->coef[attrib].a0[i] + - exec->coef[attrib].dadx[i] * x + - exec->coef[attrib].dady[i] * y) * invW); - } -} - - - -/* This should be done by the fragment shader execution unit (code - * generated from the decl instructions). Do it here for now. - */ -void quad_shade( struct generic_context *generic, - struct quad_header *quad ) -{ - struct exec_machine exec; - GLfloat fx = quad->x0; - GLfloat fy = quad->y0; - GLuint i, j; - - exec.coef = quad->coef; - - /* Position: - */ - exec.attr[FRAG_ATTRIB_WPOS][0][0] = fx; - exec.attr[FRAG_ATTRIB_WPOS][0][1] = fx + 1.0; - exec.attr[FRAG_ATTRIB_WPOS][0][2] = fx; - exec.attr[FRAG_ATTRIB_WPOS][0][3] = fx + 1.0; - - exec.attr[FRAG_ATTRIB_WPOS][1][0] = fy; - exec.attr[FRAG_ATTRIB_WPOS][1][1] = fy; - exec.attr[FRAG_ATTRIB_WPOS][1][2] = fy + 1.0; - exec.attr[FRAG_ATTRIB_WPOS][1][3] = fy + 1.0; - - /* Z and W are done by linear interpolation: - * XXX we'll probably have to use integers for Z - */ - if (generic->need_z) { - linterp(&exec, 0, 2); - } - - if (generic->need_w) { - linterp(&exec, 0, 3); -// invert(&exec, 0, 3); - } - - /* Interpolate all the remaining attributes. This will get pushed - * into the fragment program's responsibilities at some point. - */ - for (i = 1; i < quad->nr_attrs; i++) { -#if 1 - for (j = 0; j < NUM_CHANNELS; j++) - linterp(&exec, i, j); -#else - switch (quad->interp[i]) { - case INTERP_CONSTANT: - for (j = 0; j < NUM_CHANNELS; j++) - cinterp(&exec, i, j); - break; - - case INTERP_LINEAR: - for (j = 0; j < NUM_CHANNELS; j++) - linterp(&exec, i, j); - break; - - case INTERP_PERSPECTIVE: - for (j = 0; j < NUM_CHANNELS; j++) - pinterp(&exec, i, j); - break; - } -#endif - } - -#if 0 - generic->run_fs( tri->fp, quad, &tri->outputs ); -#else - { - GLuint attr = generic->fp_attr_to_slot[FRAG_ATTRIB_COL0]; - assert(attr); - - memcpy(quad->outputs.color, - exec.attr[attr], - sizeof(quad->outputs.color)); - } -#endif - - - if (quad->mask) - quad_output( generic, quad ); -} - - - - - - - diff --git a/src/mesa/pipe/softpipe/g_tile_output.c b/src/mesa/pipe/softpipe/g_tile_output.c deleted file mode 100644 index 058ca30193..0000000000 --- a/src/mesa/pipe/softpipe/g_tile_output.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5 - * - * Copyright (C) 1999-2005 Brian Paul 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, sublicense, - * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL 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. - */ - -/* Vertices are just an array of floats, with all the attributes - * packed. We currently assume a layout like: - * - * attr[0][0..3] - window position - * attr[1..n][0..3] - remaining attributes. - * - * Attributes are assumed to be 4 floats wide but are packed so that - * all the enabled attributes run contiguously. - */ - -#include "glheader.h" -#include "g_context.h" -#include "g_headers.h" -#include "g_surface.h" -#include "g_tile.h" - - -static void mask_copy( GLfloat (*dest)[4], - GLfloat (*src)[4], - GLuint mask ) -{ - GLuint i, j; - - for (i = 0; i < 4; i++) { - if (mask & (1<mask != MASK_ALL) - { - GLfloat tmp[4][QUAD_SIZE]; - - /* Yes, we'll probably have a masked write as well, but this is - * how blend will be done at least. - */ - gs_read_quad_f_swz( generic->cbuf_surface, - quad->x0, - quad->y0, - tmp ); - - mask_copy( tmp, quad->outputs.color, quad->mask ); - - gs_write_quad_f_swz( generic->cbuf_surface, - quad->x0, - quad->y0, - tmp ); - } - else - { - gs_write_quad_f_swz( generic->cbuf_surface, - quad->x0, - quad->y0, - quad->outputs.color ); - } -} diff --git a/src/mesa/sources b/src/mesa/sources index eda3ef7beb..af8d678878 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -155,36 +155,38 @@ VF_SOURCES = \ vf/vf_sse.c SOFTPIPE_SOURCES = \ - softpipe/generic/g_context.c \ - softpipe/generic/g_draw.c \ - softpipe/generic/g_prim_clip.c \ - softpipe/generic/g_prim_cull.c \ - softpipe/generic/g_prim_flatshade.c \ - softpipe/generic/g_prim_offset.c \ - softpipe/generic/g_prim_setup.c \ - softpipe/generic/g_prim_twoside.c \ - softpipe/generic/g_prim_unfilled.c \ - softpipe/generic/g_state_clip.c \ - softpipe/generic/g_state_derived.c \ - softpipe/generic/g_state_fs.c \ - softpipe/generic/g_state_setup.c \ - softpipe/generic/g_state_surface.c \ - softpipe/generic/g_surface.c \ - softpipe/generic/g_tile_fs.c \ - softpipe/generic/g_tile_output.c \ - softpipe/state_tracker/st_atom.c \ - softpipe/state_tracker/st_atom_blend.c \ - softpipe/state_tracker/st_atom_cbuf.c \ - softpipe/state_tracker/st_atom_clip.c \ - softpipe/state_tracker/st_atom_depth.c \ - softpipe/state_tracker/st_atom_fs.c \ - softpipe/state_tracker/st_atom_scissor.c \ - softpipe/state_tracker/st_atom_stencil.c \ - softpipe/state_tracker/st_atom_setup.c \ - softpipe/state_tracker/st_atom_viewport.c \ - softpipe/state_tracker/st_cb_program.c \ - softpipe/state_tracker/st_draw.c \ - softpipe/state_tracker/st_context.c + pipe/softpipe/sp_context.c \ + pipe/softpipe/sp_draw.c \ + pipe/softpipe/sp_prim_clip.c \ + pipe/softpipe/sp_prim_cull.c \ + pipe/softpipe/sp_prim_flatshade.c \ + pipe/softpipe/sp_prim_offset.c \ + pipe/softpipe/sp_prim_setup.c \ + pipe/softpipe/sp_prim_twoside.c \ + pipe/softpipe/sp_prim_unfilled.c \ + pipe/softpipe/sp_state_clip.c \ + pipe/softpipe/sp_state_derived.c \ + pipe/softpipe/sp_state_fs.c \ + pipe/softpipe/sp_state_setup.c \ + pipe/softpipe/sp_state_surface.c \ + pipe/softpipe/sp_surface.c \ + pipe/softpipe/sp_tile_fs.c \ + pipe/softpipe/sp_tile_output.c + +STATETRACKER_SOURCES = \ + state_tracker/st_atom.c \ + state_tracker/st_atom_blend.c \ + state_tracker/st_atom_cbuf.c \ + state_tracker/st_atom_clip.c \ + state_tracker/st_atom_depth.c \ + state_tracker/st_atom_fs.c \ + state_tracker/st_atom_scissor.c \ + state_tracker/st_atom_stencil.c \ + state_tracker/st_atom_setup.c \ + state_tracker/st_atom_viewport.c \ + state_tracker/st_cb_program.c \ + state_tracker/st_draw.c \ + state_tracker/st_context.c @@ -334,6 +336,7 @@ SOLO_SOURCES = \ $(VBO_SOURCES) \ $(VF_SOURCES) \ $(SOFTPIPE_SOURCES) \ + $(STATETRACKER_SOURCES) \ $(TNL_SOURCES) \ $(SHADER_SOURCES) \ $(SWRAST_SOURCES) \ diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c index eabb9172ba..03fbd290e0 100644 --- a/src/mesa/state_tracker/st_atom_blend.c +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -34,12 +34,12 @@ #include "st_context.h" #include "st_atom.h" -#include "softpipe/sp_context.h" -#include "softpipe/sp_defines.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" /** - * Convert GLenum blend tokens to softpipe tokens. + * Convert GLenum blend tokens to pipe tokens. * Both blend factors and blend funcs are accepted. */ static GLuint @@ -48,54 +48,54 @@ gl_blend_to_sp(GLenum blend) switch (blend) { /* blend functions */ case GL_FUNC_ADD: - return SP_BLEND_ADD; + return PIPE_BLEND_ADD; case GL_FUNC_SUBTRACT: - return SP_BLEND_SUBTRACT; + return PIPE_BLEND_SUBTRACT; case GL_FUNC_REVERSE_SUBTRACT: - return SP_BLEND_REVERSE_SUBTRACT; + return PIPE_BLEND_REVERSE_SUBTRACT; case GL_MIN: - return SP_BLEND_MIN; + return PIPE_BLEND_MIN; case GL_MAX: - return SP_BLEND_MAX; + return PIPE_BLEND_MAX; /* blend factors */ case GL_ONE: - return SP_BLENDFACTOR_ONE; + return PIPE_BLENDFACTOR_ONE; case GL_SRC_COLOR: - return SP_BLENDFACTOR_SRC_COLOR; + return PIPE_BLENDFACTOR_SRC_COLOR; case GL_SRC_ALPHA: - return SP_BLENDFACTOR_SRC_ALPHA; + return PIPE_BLENDFACTOR_SRC_ALPHA; case GL_DST_ALPHA: - return SP_BLENDFACTOR_DST_ALPHA; + return PIPE_BLENDFACTOR_DST_ALPHA; case GL_DST_COLOR: - return SP_BLENDFACTOR_DST_COLOR; + return PIPE_BLENDFACTOR_DST_COLOR; case GL_SRC_ALPHA_SATURATE: - return SP_BLENDFACTOR_SRC_ALPHA_SATURATE; + return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE; case GL_CONSTANT_COLOR: - return SP_BLENDFACTOR_CONST_COLOR; + return PIPE_BLENDFACTOR_CONST_COLOR; case GL_CONSTANT_ALPHA: - return SP_BLENDFACTOR_CONST_ALPHA; + return PIPE_BLENDFACTOR_CONST_ALPHA; /* - return SP_BLENDFACTOR_SRC1_COLOR; - return SP_BLENDFACTOR_SRC1_ALPHA; + return PIPE_BLENDFACTOR_SRC1_COLOR; + return PIPE_BLENDFACTOR_SRC1_ALPHA; */ case GL_ZERO: - return SP_BLENDFACTOR_ZERO; + return PIPE_BLENDFACTOR_ZERO; case GL_ONE_MINUS_SRC_COLOR: - return SP_BLENDFACTOR_INV_SRC_COLOR; + return PIPE_BLENDFACTOR_INV_SRC_COLOR; case GL_ONE_MINUS_SRC_ALPHA: - return SP_BLENDFACTOR_INV_SRC_ALPHA; + return PIPE_BLENDFACTOR_INV_SRC_ALPHA; case GL_ONE_MINUS_DST_COLOR: - return SP_BLENDFACTOR_INV_DST_ALPHA; + return PIPE_BLENDFACTOR_INV_DST_ALPHA; case GL_ONE_MINUS_DST_ALPHA: - return SP_BLENDFACTOR_INV_DST_COLOR; + return PIPE_BLENDFACTOR_INV_DST_COLOR; case GL_ONE_MINUS_CONSTANT_COLOR: - return SP_BLENDFACTOR_INV_CONST_COLOR; + return PIPE_BLENDFACTOR_INV_CONST_COLOR; case GL_ONE_MINUS_CONSTANT_ALPHA: - return SP_BLENDFACTOR_INV_CONST_ALPHA; + return PIPE_BLENDFACTOR_INV_CONST_ALPHA; /* - return SP_BLENDFACTOR_INV_SRC1_COLOR; - return SP_BLENDFACTOR_INV_SRC1_ALPHA; + return PIPE_BLENDFACTOR_INV_SRC1_COLOR; + return PIPE_BLENDFACTOR_INV_SRC1_ALPHA; */ default: assert("invalid GL token in gl_blend_to_sp()" == NULL); @@ -105,44 +105,44 @@ gl_blend_to_sp(GLenum blend) /** - * Convert GLenum logicop tokens to softpipe tokens. + * Convert GLenum logicop tokens to pipe tokens. */ static GLuint gl_logicop_to_sp(GLenum logicop) { switch (logicop) { case GL_CLEAR: - return SP_LOGICOP_CLEAR; + return PIPE_LOGICOP_CLEAR; case GL_NOR: - return SP_LOGICOP_NOR; + return PIPE_LOGICOP_NOR; case GL_AND_INVERTED: - return SP_LOGICOP_AND_INVERTED; + return PIPE_LOGICOP_AND_INVERTED; case GL_COPY_INVERTED: - return SP_LOGICOP_COPY_INVERTED; + return PIPE_LOGICOP_COPY_INVERTED; case GL_AND_REVERSE: - return SP_LOGICOP_AND_REVERSE; + return PIPE_LOGICOP_AND_REVERSE; case GL_INVERT: - return SP_LOGICOP_INVERT; + return PIPE_LOGICOP_INVERT; case GL_XOR: - return SP_LOGICOP_XOR; + return PIPE_LOGICOP_XOR; case GL_NAND: - return SP_LOGICOP_NAND; + return PIPE_LOGICOP_NAND; case GL_AND: - return SP_LOGICOP_AND; + return PIPE_LOGICOP_AND; case GL_EQUIV: - return SP_LOGICOP_EQUIV; + return PIPE_LOGICOP_EQUIV; case GL_NOOP: - return SP_LOGICOP_NOOP; + return PIPE_LOGICOP_NOOP; case GL_OR_INVERTED: - return SP_LOGICOP_OR_INVERTED; + return PIPE_LOGICOP_OR_INVERTED; case GL_COPY: - return SP_LOGICOP_COPY; + return PIPE_LOGICOP_COPY; case GL_OR_REVERSE: - return SP_LOGICOP_OR_REVERSE; + return PIPE_LOGICOP_OR_REVERSE; case GL_OR: - return SP_LOGICOP_OR; + return PIPE_LOGICOP_OR; case GL_SET: - return SP_LOGICOP_SET; + return PIPE_LOGICOP_SET; default: assert("invalid GL token in gl_logicop_to_sp()" == NULL); return 0; @@ -153,7 +153,7 @@ gl_logicop_to_sp(GLenum logicop) static void update_blend( struct st_context *st ) { - struct softpipe_blend_state blend; + struct pipe_blend_state blend; memset(&blend, 0, sizeof(blend)); @@ -183,7 +183,7 @@ update_blend( struct st_context *st ) if (memcmp(&blend, &st->state.blend, sizeof(blend)) != 0) { /* state has changed */ st->state.blend = blend; /* struct copy */ - st->softpipe->set_blend_state(st->softpipe, &blend); /* set new state */ + st->pipe->set_blend_state(st->pipe, &blend); /* set new state */ } } diff --git a/src/mesa/state_tracker/st_atom_cbuf.c b/src/mesa/state_tracker/st_atom_cbuf.c index cd707ec5ef..0f90aa7646 100644 --- a/src/mesa/state_tracker/st_atom_cbuf.c +++ b/src/mesa/state_tracker/st_atom_cbuf.c @@ -31,7 +31,7 @@ */ #include "st_context.h" -#include "softpipe/sp_context.h" +#include "pipe/p_context.h" #include "st_atom.h" extern GLboolean xmesa_get_cbuf_details( GLcontext *ctx, @@ -45,7 +45,7 @@ extern GLboolean xmesa_get_cbuf_details( GLcontext *ctx, */ static void update_cbuf_state( struct st_context *st ) { - struct softpipe_surface cbuf; + struct pipe_surface cbuf; GLboolean ok; ok = xmesa_get_cbuf_details( st->ctx, @@ -58,7 +58,7 @@ static void update_cbuf_state( struct st_context *st ) if (memcmp(&cbuf, &st->state.cbuf, sizeof(cbuf)) != 0) { st->state.cbuf = cbuf; - st->softpipe->set_cbuf_state( st->softpipe, &cbuf ); + st->pipe->set_cbuf_state( st->pipe, &cbuf ); } } diff --git a/src/mesa/state_tracker/st_atom_clip.c b/src/mesa/state_tracker/st_atom_clip.c index 710d6ffc84..8ccad637d5 100644 --- a/src/mesa/state_tracker/st_atom_clip.c +++ b/src/mesa/state_tracker/st_atom_clip.c @@ -32,7 +32,7 @@ #include "st_context.h" -#include "softpipe/sp_context.h" +#include "pipe/p_context.h" #include "st_atom.h" @@ -40,12 +40,12 @@ */ static void update_clip( struct st_context *st ) { - struct softpipe_clip_state clip; + struct pipe_clip_state clip; GLuint i; memset(&clip, 0, sizeof(clip)); - for (i = 0; i < SP_MAX_CLIP_PLANES; i++) { + for (i = 0; i < PIPE_MAX_CLIP_PLANES; i++) { if (st->ctx->Transform.ClipPlanesEnabled & (1 << i)) { memcpy(clip.ucp[clip.nr], st->ctx->Transform._ClipUserPlane[i], @@ -56,7 +56,7 @@ static void update_clip( struct st_context *st ) if (memcmp(&clip, &st->state.clip, sizeof(clip)) != 0) { st->state.clip = clip; - st->softpipe->set_clip_state(st->softpipe, &clip); + st->pipe->set_clip_state(st->pipe, &clip); } } diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index 5532abc8fd..4c891e6e54 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -34,25 +34,25 @@ #include "st_context.h" #include "st_atom.h" -#include "softpipe/sp_context.h" -#include "softpipe/sp_defines.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" /** - * Convert GLenum depth func tokens to softpipe tokens. + * Convert GLenum depth func tokens to pipe tokens. */ static GLuint gl_depth_func_to_sp(GLenum func) { /* Same values, just biased */ - assert(SP_DEPTH_FUNC_NEVER == GL_NEVER - GL_NEVER); - assert(SP_DEPTH_FUNC_LESS == GL_LESS - GL_NEVER); - assert(SP_DEPTH_FUNC_EQUAL == GL_EQUAL - GL_NEVER); - assert(SP_DEPTH_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); - assert(SP_DEPTH_FUNC_GREATER == GL_GREATER - GL_NEVER); - assert(SP_DEPTH_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); - assert(SP_DEPTH_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); - assert(SP_DEPTH_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); + assert(PIPE_DEPTH_FUNC_NEVER == GL_NEVER - GL_NEVER); + assert(PIPE_DEPTH_FUNC_LESS == GL_LESS - GL_NEVER); + assert(PIPE_DEPTH_FUNC_EQUAL == GL_EQUAL - GL_NEVER); + assert(PIPE_DEPTH_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); + assert(PIPE_DEPTH_FUNC_GREATER == GL_GREATER - GL_NEVER); + assert(PIPE_DEPTH_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); + assert(PIPE_DEPTH_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); + assert(PIPE_DEPTH_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); assert(func >= GL_NEVER); assert(func <= GL_ALWAYS); return func - GL_NEVER; @@ -62,7 +62,7 @@ gl_depth_func_to_sp(GLenum func) static void update_depth( struct st_context *st ) { - struct softpipe_depth_state depth; + struct pipe_depth_state depth; memset(&depth, 0, sizeof(depth)); @@ -74,7 +74,7 @@ update_depth( struct st_context *st ) if (memcmp(&depth, &st->state.depth, sizeof(depth)) != 0) { /* state has changed */ st->state.depth = depth; /* struct copy */ - st->softpipe->set_depth_state(st->softpipe, &depth); /* set new state */ + st->pipe->set_depth_state(st->pipe, &depth); /* set new state */ } } diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index ca109d2d34..9c6bc1ce2a 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -30,19 +30,19 @@ */ #include "st_context.h" -#include "softpipe/sp_context.h" +#include "pipe/p_context.h" #include "st_atom.h" static void update_fs( struct st_context *st ) { - struct softpipe_fs_state fs; + struct pipe_fs_state fs; fs.fp = st->ctx->FragmentProgram._Current; if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0) { st->state.fs = fs; - st->softpipe->set_fs_state(st->softpipe, &fs); + st->pipe->set_fs_state(st->pipe, &fs); } } diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c index 105c2a6dd9..75bead388f 100644 --- a/src/mesa/state_tracker/st_atom_scissor.c +++ b/src/mesa/state_tracker/st_atom_scissor.c @@ -32,7 +32,7 @@ #include "st_context.h" -#include "softpipe/sp_context.h" +#include "pipe/p_context.h" #include "st_atom.h" @@ -42,7 +42,7 @@ static void update_scissor( struct st_context *st ) { - struct softpipe_scissor_rect scissor; + struct pipe_scissor_rect scissor; const struct gl_framebuffer *fb = st->ctx->DrawBuffer; scissor.minx = 0; @@ -69,7 +69,7 @@ update_scissor( struct st_context *st ) if (memcmp(&scissor, &st->state.scissor, sizeof(scissor)) != 0) { /* state has changed */ st->state.scissor = scissor; /* struct copy */ - st->softpipe->set_scissor_rect(st->softpipe, &scissor); /* activate */ + st->pipe->set_scissor_rect(st->pipe, &scissor); /* activate */ } } diff --git a/src/mesa/state_tracker/st_atom_setup.c b/src/mesa/state_tracker/st_atom_setup.c index 2a582ea36c..d88d403c1d 100644 --- a/src/mesa/state_tracker/st_atom_setup.c +++ b/src/mesa/state_tracker/st_atom_setup.c @@ -32,7 +32,7 @@ #include "st_context.h" -#include "softpipe/sp_context.h" +#include "pipe/p_context.h" #include "st_atom.h" static GLuint translate_fill( GLenum mode ) @@ -60,7 +60,7 @@ static GLboolean get_offset_flag( GLuint fill_mode, static void update_setup_state( struct st_context *st ) { GLcontext *ctx = st->ctx; - struct softpipe_setup_state setup; + struct pipe_setup_state setup; memset(&setup, 0, sizeof(setup)); @@ -162,7 +162,7 @@ static void update_setup_state( struct st_context *st ) if (memcmp(&setup, &st->state.setup, sizeof(setup)) != 0) { st->state.setup = setup; - st->softpipe->set_setup_state( st->softpipe, &setup ); + st->pipe->set_setup_state( st->pipe, &setup ); } } diff --git a/src/mesa/state_tracker/st_atom_stencil.c b/src/mesa/state_tracker/st_atom_stencil.c index 32610c3d24..b9f24f49e6 100644 --- a/src/mesa/state_tracker/st_atom_stencil.c +++ b/src/mesa/state_tracker/st_atom_stencil.c @@ -34,25 +34,25 @@ #include "st_context.h" #include "st_atom.h" -#include "softpipe/sp_context.h" -#include "softpipe/sp_defines.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" /** - * Convert GLenum stencil func tokens to softpipe tokens. + * Convert GLenum stencil func tokens to pipe tokens. */ static GLuint gl_stencil_func_to_sp(GLenum func) { /* Same values, just biased */ - assert(SP_STENCIL_FUNC_NEVER == GL_NEVER - GL_NEVER); - assert(SP_STENCIL_FUNC_LESS == GL_LESS - GL_NEVER); - assert(SP_STENCIL_FUNC_EQUAL == GL_EQUAL - GL_NEVER); - assert(SP_STENCIL_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); - assert(SP_STENCIL_FUNC_GREATER == GL_GREATER - GL_NEVER); - assert(SP_STENCIL_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); - assert(SP_STENCIL_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); - assert(SP_STENCIL_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); + assert(PIPE_STENCIL_FUNC_NEVER == GL_NEVER - GL_NEVER); + assert(PIPE_STENCIL_FUNC_LESS == GL_LESS - GL_NEVER); + assert(PIPE_STENCIL_FUNC_EQUAL == GL_EQUAL - GL_NEVER); + assert(PIPE_STENCIL_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); + assert(PIPE_STENCIL_FUNC_GREATER == GL_GREATER - GL_NEVER); + assert(PIPE_STENCIL_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); + assert(PIPE_STENCIL_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); + assert(PIPE_STENCIL_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); assert(func >= GL_NEVER); assert(func <= GL_ALWAYS); return func - GL_NEVER; @@ -60,28 +60,28 @@ gl_stencil_func_to_sp(GLenum func) /** - * Convert GLenum stencil op tokens to softpipe tokens. + * Convert GLenum stencil op tokens to pipe tokens. */ static GLuint gl_stencil_op_to_sp(GLenum func) { switch (func) { case GL_KEEP: - return SP_STENCIL_OP_KEEP; + return PIPE_STENCIL_OP_KEEP; case GL_ZERO: - return SP_STENCIL_OP_ZERO; + return PIPE_STENCIL_OP_ZERO; case GL_REPLACE: - return SP_STENCIL_OP_REPLACE; + return PIPE_STENCIL_OP_REPLACE; case GL_INCR: - return SP_STENCIL_OP_INCR; + return PIPE_STENCIL_OP_INCR; case GL_DECR: - return SP_STENCIL_OP_DECR; + return PIPE_STENCIL_OP_DECR; case GL_INCR_WRAP: - return SP_STENCIL_OP_INCR_WRAP; + return PIPE_STENCIL_OP_INCR_WRAP; case GL_DECR_WRAP: - return SP_STENCIL_OP_DECR_WRAP; + return PIPE_STENCIL_OP_DECR_WRAP; case GL_INVERT: - return SP_STENCIL_OP_INVERT; + return PIPE_STENCIL_OP_INVERT; default: assert("invalid GL token in gl_stencil_op_to_sp()" == NULL); return 0; @@ -92,7 +92,7 @@ gl_stencil_op_to_sp(GLenum func) static void update_stencil( struct st_context *st ) { - struct softpipe_stencil_state stencil; + struct pipe_stencil_state stencil; memset(&stencil, 0, sizeof(stencil)); @@ -121,7 +121,7 @@ update_stencil( struct st_context *st ) if (memcmp(&stencil, &st->state.stencil, sizeof(stencil)) != 0) { /* state has changed */ st->state.stencil = stencil; /* struct copy */ - st->softpipe->set_stencil_state(st->softpipe, &stencil); /* set new state */ + st->pipe->set_stencil_state(st->pipe, &stencil); /* set new state */ } } diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c index af896e2e31..765bcf3647 100644 --- a/src/mesa/state_tracker/st_atom_viewport.c +++ b/src/mesa/state_tracker/st_atom_viewport.c @@ -29,7 +29,7 @@ #include "context.h" #include "colormac.h" #include "st_context.h" -#include "softpipe/sp_context.h" +#include "pipe/p_context.h" #include "st_atom.h" @@ -88,7 +88,7 @@ static void update_viewport( struct st_context *st ) GLfloat half_height = ctx->Viewport.Height / 2.0; GLfloat half_depth = (ctx->Viewport.Far - ctx->Viewport.Near) / 2.0; - struct softpipe_viewport vp; + struct pipe_viewport vp; vp.scale[0] = half_width; vp.scale[1] = half_height * yScale; @@ -102,7 +102,7 @@ static void update_viewport( struct st_context *st ) if (memcmp(&vp, &st->state.viewport, sizeof(vp)) != 0) { st->state.viewport = vp; - st->softpipe->set_viewport(st->softpipe, &vp); + st->pipe->set_viewport(st->pipe, &vp); } } } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 8a06dd88df..6308e81a61 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -31,7 +31,7 @@ #include "st_atom.h" #include "st_draw.h" #include "st_program.h" -#include "softpipe/sp_context.h" +#include "pipe/p_context.h" void st_invalidate_state(GLcontext * ctx, GLuint new_state) { @@ -43,14 +43,14 @@ void st_invalidate_state(GLcontext * ctx, GLuint new_state) struct st_context *st_create_context( GLcontext *ctx, - struct softpipe_context *softpipe ) + struct pipe_context *pipe ) { struct st_context *st = CALLOC_STRUCT( st_context ); ctx->st = st; st->ctx = ctx; - st->softpipe = softpipe; + st->pipe = pipe; st->dirty.mesa = ~0; st->dirty.st = ~0; @@ -68,7 +68,7 @@ void st_destroy_context( struct st_context *st ) st_destroy_atoms( st ); st_destroy_draw( st ); st_destroy_cb_program( st ); - st->softpipe->destroy( st->softpipe ); + 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 317d377371..6d9460e2f0 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -29,7 +29,7 @@ #define ST_CONTEXT_H #include "mtypes.h" -#include "softpipe/sp_state.h" +#include "pipe/p_state.h" struct st_context; @@ -58,23 +58,23 @@ struct st_context { GLcontext *ctx; - struct softpipe_context *softpipe; + struct pipe_context *pipe; - /* Eventually will use a cache to feed the softpipe with + /* Eventually will use a cache to feed the pipe with * create/bind/delete calls to constant state objects. Not yet * though, we just shove random objects across the interface. */ struct { - struct softpipe_viewport viewport; - struct softpipe_setup_state setup; - struct softpipe_fs_state fs; - struct softpipe_blend_state blend; - struct softpipe_surface cbuf; - struct softpipe_clip_state clip; - struct softpipe_depth_state depth; - struct softpipe_scissor_rect scissor; - struct softpipe_poly_stipple poly_stipple; - struct softpipe_stencil_state stencil; + struct pipe_viewport viewport; + struct pipe_setup_state setup; + struct pipe_fs_state fs; + struct pipe_blend_state blend; + struct pipe_surface cbuf; + struct pipe_clip_state clip; + struct pipe_depth_state depth; + struct pipe_scissor_rect scissor; + struct pipe_poly_stipple poly_stipple; + struct pipe_stencil_state stencil; } state; struct { diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 12646402ee..4db8189988 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -38,7 +38,7 @@ #include "st_context.h" #include "st_atom.h" #include "st_draw.h" -#include "softpipe/sp_context.h" +#include "pipe/p_context.h" /* * TNL stage which feedsinto the above. @@ -52,13 +52,13 @@ static GLboolean draw( GLcontext * ctx, struct tnl_pipeline_stage *stage ) struct st_context *st = st_context(ctx); struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - /* Validate driver and softpipe state: + /* Validate driver and pipe state: */ st_validate_state( st ); /* Call into the new draw code to handle the VB: */ - st->softpipe->draw_vb( st->softpipe, VB ); + st->pipe->draw_vb( st->pipe, VB ); /* Finished */ @@ -84,7 +84,7 @@ static const struct tnl_pipeline_stage *intel_pipeline[] = { &_tnl_texture_transform_stage, &_tnl_point_attenuation_stage, &_tnl_vertex_program_stage, - &st_draw, /* ADD: escape to softpipe */ + &st_draw, /* ADD: escape to pipe */ 0, }; diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index 8241dbd52d..3191549a2f 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -31,10 +31,10 @@ #include "mtypes.h" struct st_context; -struct softpipe_context; +struct pipe_context; struct st_context *st_create_context( GLcontext *ctx, - struct softpipe_context *softpipe); + struct pipe_context *pipe); void st_destroy_context( struct st_context *st ); -- cgit v1.2.3 From 8f6b6eed35832733674372dea7bd5ce69a965c4e Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 15 Jun 2007 09:51:53 -0600 Subject: initial framebuffer state --- src/mesa/pipe/p_context.h | 3 +++ src/mesa/pipe/p_state.h | 15 ++++++++++++++- src/mesa/pipe/softpipe/sp_context.h | 1 + src/mesa/sources | 1 + src/mesa/state_tracker/st_context.h | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index dc7a80744a..5c9b9b14fe 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -59,6 +59,9 @@ struct pipe_context { void (*set_blend_state)( struct pipe_context *, const struct pipe_blend_state * ); + void (*set_framebuffer_state)( struct pipe_context *, + const struct pipe_framebuffer_state * ); + void (*set_cbuf_state)( struct pipe_context *, const struct pipe_surface * ); diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 7264f253d9..dba1e11715 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -149,7 +149,9 @@ struct pipe_stencil_state { /* This will change for hardware pipes... */ -struct pipe_surface { +struct pipe_surface +{ + GLuint width, height; GLubyte *ptr; GLint stride; GLuint cpp; @@ -157,6 +159,17 @@ struct pipe_surface { }; +struct pipe_framebuffer_state +{ + GLuint num_cbufs; /**< Number of color bufs to draw to */ + struct pipe_surface *cbufs[4]; /**< OpenGL can write to as many as + 4 color buffers at once */ + struct pipe_surface *zbuf; /**< Z buffer */ + struct pipe_surface *sbuf; /**< Stencil buffer */ + struct pipe_surface *abuf; /**< Accum buffer */ +}; + + /** * Texture sampler state. */ diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index da6c17aaf6..9050b59f77 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -67,6 +67,7 @@ struct softpipe_context { /* The most recent drawing state as set by the driver: */ + struct pipe_framebuffer_state framebuffer; struct pipe_viewport viewport; struct pipe_setup_state setup; struct pipe_fs_state fs; diff --git a/src/mesa/sources b/src/mesa/sources index af8d678878..1aef2f76eb 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -180,6 +180,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_clip.c \ state_tracker/st_atom_depth.c \ state_tracker/st_atom_fs.c \ + state_tracker/st_atom_framebuffer.c \ state_tracker/st_atom_scissor.c \ state_tracker/st_atom_stencil.c \ state_tracker/st_atom_setup.c \ diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 6d9460e2f0..b43fc0925b 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -65,6 +65,7 @@ struct st_context * though, we just shove random objects across the interface. */ struct { + struct pipe_framebuffer_state framebuffer; struct pipe_viewport viewport; struct pipe_setup_state setup; struct pipe_fs_state fs; -- cgit v1.2.3 From 493f7b5f3ae2eb64eaa65e24e79a7a071c359b81 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 18 Jun 2007 17:54:38 -0600 Subject: Added alpha test state. --- src/mesa/pipe/p_context.h | 9 ++- src/mesa/pipe/p_state.h | 25 ++++---- src/mesa/pipe/softpipe/sp_context.h | 2 + src/mesa/sources | 2 + src/mesa/state_tracker/st_atom_alphatest.c | 94 ++++++++++++++++++++++++++++++ src/mesa/state_tracker/st_context.h | 1 + 6 files changed, 120 insertions(+), 13 deletions(-) create mode 100644 src/mesa/state_tracker/st_atom_alphatest.c (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 5c9b9b14fe..f7374a8380 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -56,12 +56,12 @@ struct pipe_context { /* * State functions */ + 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_framebuffer_state)( struct pipe_context *, - const struct pipe_framebuffer_state * ); - void (*set_cbuf_state)( struct pipe_context *, const struct pipe_surface * ); @@ -71,6 +71,9 @@ struct pipe_context { void (*set_depth_state)( struct pipe_context *, const struct pipe_depth_state * ); + void (*set_framebuffer_state)( struct pipe_context *, + const struct pipe_framebuffer_state * ); + void (*set_fs_state)( struct pipe_context *, const struct pipe_fs_state * ); diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index dba1e11715..71f1e99964 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -104,34 +104,39 @@ struct pipe_depth_state { GLuint enabled:1; /**< depth test enabled? */ GLuint writemask:1; /**< allow depth buffer writes? */ - GLuint func:3; /**< depth test func */ + GLuint func:3; /**< depth test func (PIPE_FUNC_x) */ GLfloat clear; /**< Clear value in [0,1] (XXX correct place?) */ }; +struct pipe_alpha_test_state { + GLuint enable:1; + GLuint func:3; /**< PIPE_FUNC_x */ + GLfloat ref; /**< reference value */ +}; -struct pipe_blend_state { - GLuint blend_enable:1; +struct pipe_blend_state { + GLuint blend_enable:1; - GLuint rgb_func:3; - GLuint rgb_src_factor:5; - GLuint rgb_dst_factor:5; + GLuint rgb_func:3; + GLuint rgb_src_factor:5; + GLuint rgb_dst_factor:5; GLuint alpha_func:3; GLuint alpha_src_factor:5; GLuint alpha_dst_factor:5; - GLuint logicop_enable:1; + GLuint logicop_enable:1; GLuint logicop_func:4; }; struct pipe_blend_color { - GLfloat color[4]; + GLfloat color[4]; }; struct pipe_stencil_state { GLuint front_enabled:1; - GLuint front_func:3; /**< PIPE_STENCIL_FUNC_x */ + GLuint front_func:3; /**< PIPE_FUNC_x */ GLuint front_fail_op:3; /**< PIPE_STENCIL_OP_x */ GLuint front_zpass_op:3; /**< PIPE_STENCIL_OP_x */ GLuint front_zfail_op:3; /**< PIPE_STENCIL_OP_x */ @@ -190,7 +195,7 @@ struct pipe_sampler_state GLfloat max_anisotropy; GLuint compare:1; /**< shadow/depth compare enabled? */ GLenum compare_mode:1; /**< PIPE_TEX_COMPARE_x */ - GLenum compare_func:3; /**< PIPE_DEPTH_FUNC_x */ + GLenum compare_func:3; /**< PIPE_FUNC_x */ GLfloat shadow_ambient; /**< shadow test fail color/intensity */ }; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index f2ebc4272a..efe453ea2c 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -59,6 +59,7 @@ enum interp_mode { #define G_NEW_SCISSOR 0x40 #define G_NEW_STIPPLE 0x80 #define G_NEW_FRAMEBUFFER 0x100 +#define G_NEW_ALPHA_TEST 0x200 struct softpipe_context { @@ -72,6 +73,7 @@ struct softpipe_context { struct pipe_setup_state setup; struct pipe_fs_state fs; struct pipe_blend_state blend; + struct pipe_alpha_test_state alpha_test; struct pipe_surface cbuf; struct pipe_clip_state clip; struct pipe_scissor_rect scissor; diff --git a/src/mesa/sources b/src/mesa/sources index 1aef2f76eb..d07d4dabe8 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -175,6 +175,7 @@ SOFTPIPE_SOURCES = \ STATETRACKER_SOURCES = \ state_tracker/st_atom.c \ + state_tracker/st_atom_alphatest.c \ state_tracker/st_atom_blend.c \ state_tracker/st_atom_cbuf.c \ state_tracker/st_atom_clip.c \ @@ -291,6 +292,7 @@ X11_DRIVER_SOURCES = \ drivers/x11/xm_glide.c \ drivers/x11/xm_line.c \ drivers/x11/xm_span.c \ + drivers/x11/xm_surface.c \ drivers/x11/xm_tri.c OSMESA_DRIVER_SOURCES = \ diff --git a/src/mesa/state_tracker/st_atom_alphatest.c b/src/mesa/state_tracker/st_atom_alphatest.c new file mode 100644 index 0000000000..b7cc0d70a9 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_alphatest.c @@ -0,0 +1,94 @@ +/************************************************************************** + * + * 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_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; + + memset(&alpha, 0, sizeof(alpha)); + + if (st->ctx->Color.AlphaEnabled) { + alpha.enable = 1; + 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) { + /* state has changed */ + st->state.alpha_test = alpha; /* struct copy */ + st->pipe->set_alpha_test_state(st->pipe, &alpha); /* set new state */ + } +} + + +const struct st_tracked_state st_update_alpha_test = { + .dirty = { + .mesa = (_NEW_COLOR), + .st = 0, + }, + .update = update_alpha_test +}; + + + + + diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index b43fc0925b..d98dd3aada 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -69,6 +69,7 @@ struct st_context struct pipe_viewport viewport; struct pipe_setup_state setup; struct pipe_fs_state fs; + struct pipe_alpha_test_state alpha_test; struct pipe_blend_state blend; struct pipe_surface cbuf; struct pipe_clip_state clip; -- cgit v1.2.3 From 6cb2d0cb71d2019bd2c941a8c042e56275b22c1c Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 19 Jun 2007 19:52:25 -0600 Subject: hook up point state --- src/mesa/pipe/p_context.h | 3 + src/mesa/pipe/softpipe/sp_context.c | 1 + src/mesa/pipe/softpipe/sp_context.h | 3 + src/mesa/pipe/softpipe/sp_prim_setup.c | 131 ++++++++++++++++++-------------- src/mesa/pipe/softpipe/sp_state.h | 3 + src/mesa/pipe/softpipe/sp_state_point.c | 47 ++++++++++++ src/mesa/sources | 2 + src/mesa/state_tracker/st_atom.c | 1 + src/mesa/state_tracker/st_atom.h | 1 + src/mesa/state_tracker/st_atom_point.c | 70 +++++++++++++++++ src/mesa/state_tracker/st_context.h | 2 +- 11 files changed, 204 insertions(+), 60 deletions(-) create mode 100644 src/mesa/pipe/softpipe/sp_state_point.c create mode 100644 src/mesa/state_tracker/st_atom_point.c (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index f7374a8380..3e0c61eda2 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -71,6 +71,9 @@ struct pipe_context { void (*set_depth_state)( struct pipe_context *, const struct pipe_depth_state * ); + void (*set_point_state)( struct pipe_context *, + const struct pipe_point_state * ); + void (*set_framebuffer_state)( struct pipe_context *, const struct pipe_framebuffer_state * ); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 018f67302d..e0acf4177b 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -68,6 +68,7 @@ struct pipe_context *softpipe_create( void ) softpipe->pipe.destroy = softpipe_destroy; softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.set_clip_state = softpipe_set_clip_state; + softpipe->pipe.set_point_state = softpipe_set_point_state; softpipe->pipe.set_viewport = softpipe_set_viewport; softpipe->pipe.set_setup_state = softpipe_set_setup_state; softpipe->pipe.set_scissor_rect = softpipe_set_scissor_rect; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index a873301368..43cb6f3f0b 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -54,11 +54,13 @@ enum interp_mode { #define G_NEW_SETUP 0x2 #define G_NEW_FS 0x4 #define G_NEW_BLEND 0x8 +#define G_NEW_POINT 0x10 #define G_NEW_CLIP 0x20 #define G_NEW_SCISSOR 0x40 #define G_NEW_STIPPLE 0x80 #define G_NEW_FRAMEBUFFER 0x100 #define G_NEW_ALPHA_TEST 0x200 +#define G_NEW_DEPTH_TEST 0x400 struct softpipe_context { @@ -74,6 +76,7 @@ struct softpipe_context { struct pipe_blend_state blend; struct pipe_alpha_test_state alpha_test; struct pipe_clip_state clip; + struct pipe_point_state point; struct pipe_scissor_rect scissor; struct pipe_poly_stipple poly_stipple; GLuint dirty; diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index a1addc4ee1..8ef0fcbf9c 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -769,17 +769,12 @@ static void setup_point(struct prim_stage *stage, struct prim_header *prim) { struct setup_stage *setup = setup_stage( stage ); - GLfloat halfSize = 7.3; /*XXX this is a vertex attrib */ - GLfloat halfSizeSquared = halfSize * halfSize; + /*XXX this should be a vertex attrib! */ + GLfloat halfSize = 0.5 * setup->stage.softpipe->point.size; + GLboolean round = setup->stage.softpipe->point.smooth; const struct vertex_header *v0 = prim->v[0]; const GLfloat x = v0->data[FRAG_ATTRIB_WPOS][0]; const GLfloat y = v0->data[FRAG_ATTRIB_WPOS][1]; - const GLint ixmin = block((GLint) (x - halfSize)); - const GLint ixmax = block((GLint) (x + halfSize)); - const GLint iymin = block((GLint) (y - halfSize)); - const GLint iymax = block((GLint) (y + halfSize)); - GLboolean round = GL_TRUE; - GLint ix, iy; GLuint slot, j; /* For points, all interpolants are constant-valued. @@ -808,57 +803,75 @@ setup_point(struct prim_stage *stage, struct prim_header *prim) /* XXX need to clip against scissor bounds too */ - for (iy = iymin; iy <= iymax; iy += 2) { - for (ix = ixmin; ix <= ixmax; ix += 2) { - - if (round) { - /* rounded points */ - /* XXX for GL_SMOOTH, need to compute per-fragment coverage too */ - GLfloat dx, dy; - - setup->quad.mask = 0x0; - - dx = (ix + 0.5) - x; - dy = (iy + 0.5) - y; - if (dx * dx + dy * dy <= halfSizeSquared) - setup->quad.mask |= MASK_BOTTOM_LEFT; - - dx = (ix + 1.5) - x; - dy = (iy + 0.5) - y; - if (dx * dx + dy * dy <= halfSizeSquared) - setup->quad.mask |= MASK_BOTTOM_RIGHT; - - dx = (ix + 0.5) - x; - dy = (iy + 1.5) - y; - if (dx * dx + dy * dy <= halfSizeSquared) - setup->quad.mask |= MASK_TOP_LEFT; - - dx = (ix + 1.5) - x; - dy = (iy + 1.5) - y; - if (dx * dx + dy * dy <= halfSizeSquared) - setup->quad.mask |= MASK_TOP_RIGHT; - } - else { - /* square points */ - setup->quad.mask = 0xf; - - if (ix + 0.5 < x - halfSize) - setup->quad.mask &= (MASK_BOTTOM_RIGHT | MASK_TOP_RIGHT); - - if (ix + 1.5 > x + halfSize) - setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_TOP_LEFT); - - if (iy + 0.5 < y - halfSize) - setup->quad.mask &= (MASK_TOP_LEFT | MASK_TOP_RIGHT); - - if (iy + 1.5 > y + halfSize) - setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_BOTTOM_RIGHT); - } - - if (setup->quad.mask) { - setup->quad.x0 = ix; - setup->quad.y0 = iy; - quad_shade( setup->stage.softpipe, &setup->quad ); + if (halfSize <= 0.5 && !round) { + /* special case for 1-pixel points */ + const GLint ix = ((GLint) x) & 1; + const GLint iy = ((GLint) y) & 1; + setup->quad.x0 = x - ix; + setup->quad.y0 = y - iy; + setup->quad.mask = (1 << ix) << (2 * iy); + quad_shade(setup->stage.softpipe, &setup->quad); + } + else { + const GLint ixmin = block((GLint) (x - halfSize)); + const GLint ixmax = block((GLint) (x + halfSize)); + const GLint iymin = block((GLint) (y - halfSize)); + const GLint iymax = block((GLint) (y + halfSize)); + GLfloat halfSizeSquared = halfSize * halfSize; + GLint ix, iy; + + for (iy = iymin; iy <= iymax; iy += 2) { + for (ix = ixmin; ix <= ixmax; ix += 2) { + + if (round) { + /* rounded points */ + /* XXX for GL_SMOOTH, need to compute per-fragment coverage too */ + GLfloat dx, dy; + + setup->quad.mask = 0x0; + + dx = (ix + 0.5) - x; + dy = (iy + 0.5) - y; + if (dx * dx + dy * dy <= halfSizeSquared) + setup->quad.mask |= MASK_BOTTOM_LEFT; + + dx = (ix + 1.5) - x; + dy = (iy + 0.5) - y; + if (dx * dx + dy * dy <= halfSizeSquared) + setup->quad.mask |= MASK_BOTTOM_RIGHT; + + dx = (ix + 0.5) - x; + dy = (iy + 1.5) - y; + if (dx * dx + dy * dy <= halfSizeSquared) + setup->quad.mask |= MASK_TOP_LEFT; + + dx = (ix + 1.5) - x; + dy = (iy + 1.5) - y; + if (dx * dx + dy * dy <= halfSizeSquared) + setup->quad.mask |= MASK_TOP_RIGHT; + } + else { + /* square points */ + setup->quad.mask = 0xf; + + if (ix + 0.5 < x - halfSize) + setup->quad.mask &= (MASK_BOTTOM_RIGHT | MASK_TOP_RIGHT); + + if (ix + 1.5 > x + halfSize) + setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_TOP_LEFT); + + if (iy + 0.5 < y - halfSize) + setup->quad.mask &= (MASK_TOP_LEFT | MASK_TOP_RIGHT); + + if (iy + 1.5 > y + halfSize) + setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_BOTTOM_RIGHT); + } + + if (setup->quad.mask) { + setup->quad.x0 = ix; + setup->quad.y0 = iy; + quad_shade( setup->stage.softpipe, &setup->quad ); + } } } } diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 5002ce88fc..4d18e80b38 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -53,6 +53,9 @@ void softpipe_set_scissor_rect( struct pipe_context *, void softpipe_set_fs_state( struct pipe_context *, const struct pipe_fs_state * ); +void softpipe_set_point_state( struct pipe_context *, + const struct pipe_point_state * ); + void softpipe_set_polygon_stipple( struct pipe_context *, const struct pipe_poly_stipple * ); diff --git a/src/mesa/pipe/softpipe/sp_state_point.c b/src/mesa/pipe/softpipe/sp_state_point.c new file mode 100644 index 0000000000..566b33e696 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_state_point.c @@ -0,0 +1,47 @@ +/************************************************************************** + * + * 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 + */ +#include "imports.h" + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_draw.h" + + + +void softpipe_set_point_state( struct pipe_context *pipe, + const struct pipe_point_state *point ) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + softpipe->point = *point; + + softpipe->dirty |= G_NEW_POINT; +} + diff --git a/src/mesa/sources b/src/mesa/sources index eb67dd9f7b..0bf7dbceb3 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -167,6 +167,7 @@ SOFTPIPE_SOURCES = \ pipe/softpipe/sp_state_clip.c \ pipe/softpipe/sp_state_derived.c \ pipe/softpipe/sp_state_fs.c \ + pipe/softpipe/sp_state_point.c \ pipe/softpipe/sp_state_setup.c \ pipe/softpipe/sp_state_surface.c \ pipe/softpipe/sp_tile_fs.c \ @@ -180,6 +181,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_depth.c \ state_tracker/st_atom_fs.c \ state_tracker/st_atom_framebuffer.c \ + state_tracker/st_atom_point.c \ state_tracker/st_atom_scissor.c \ state_tracker/st_atom_stencil.c \ state_tracker/st_atom_setup.c \ diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 228e7889b7..8ac435041d 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -45,6 +45,7 @@ static const struct st_tracked_state *atoms[] = &st_update_framebuffer, &st_update_clip, &st_update_fs, + &st_update_point, &st_update_setup, &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 8a75c9c6d5..56c33f3076 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -48,6 +48,7 @@ const struct st_tracked_state st_update_framebuffer; const struct st_tracked_state st_update_clip; const struct st_tracked_state st_update_depth; const struct st_tracked_state st_update_fs; +const struct st_tracked_state st_update_point; const struct st_tracked_state st_update_setup; const struct st_tracked_state st_update_viewport; const struct st_tracked_state st_update_constants; diff --git a/src/mesa/state_tracker/st_atom_point.c b/src/mesa/state_tracker/st_atom_point.c new file mode 100644 index 0000000000..7299142932 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_point.c @@ -0,0 +1,70 @@ +/************************************************************************** + * + * 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" + + +static void +update_point( struct st_context *st ) +{ + struct pipe_point_state point; + + memset(&point, 0, sizeof(point)); + + point.smooth = st->ctx->Point.SmoothFlag; + point.size = st->ctx->Point.Size; + point.min_size = st->ctx->Point.MinSize; + point.max_size = st->ctx->Point.MaxSize; + point.attenuation[0] = st->ctx->Point.Params[0]; + point.attenuation[1] = st->ctx->Point.Params[1]; + point.attenuation[2] = st->ctx->Point.Params[2]; + + if (memcmp(&point, &st->state.point, sizeof(point)) != 0) { + /* state has changed */ + st->state.point = point; /* struct copy */ + st->pipe->set_point_state(st->pipe, &point); /* set new state */ + } +} + + +const struct st_tracked_state st_update_point = { + .dirty = { + .mesa = (_NEW_POINT), + .st = 0, + }, + .update = update_point +}; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index d98dd3aada..94388f1aee 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -71,9 +71,9 @@ struct st_context struct pipe_fs_state fs; struct pipe_alpha_test_state alpha_test; struct pipe_blend_state blend; - struct pipe_surface cbuf; struct pipe_clip_state clip; struct pipe_depth_state depth; + struct pipe_point_state point; struct pipe_scissor_rect scissor; struct pipe_poly_stipple poly_stipple; struct pipe_stencil_state stencil; -- cgit v1.2.3 From 73f96c51052bf5233191d852ef463462306bf1d5 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 20 Jun 2007 08:47:09 -0600 Subject: Initial work for glClear(), clear color state. --- src/mesa/pipe/p_context.h | 10 +++-- src/mesa/pipe/p_state.h | 5 +++ src/mesa/pipe/softpipe/sp_clear.c | 47 +++++++++++++++++++++ src/mesa/pipe/softpipe/sp_clear.h | 43 +++++++++++++++++++ src/mesa/pipe/softpipe/sp_context.c | 4 +- src/mesa/pipe/softpipe/sp_context.h | 1 + src/mesa/pipe/softpipe/sp_state.h | 3 ++ src/mesa/pipe/softpipe/sp_state_surface.c | 15 ++++++- src/mesa/sources | 2 + src/mesa/state_tracker/st_atom.c | 1 + src/mesa/state_tracker/st_atom.h | 1 + src/mesa/state_tracker/st_atom_clear_color.c | 62 ++++++++++++++++++++++++++++ src/mesa/state_tracker/st_context.h | 1 + 13 files changed, 189 insertions(+), 6 deletions(-) create mode 100644 src/mesa/pipe/softpipe/sp_clear.c create mode 100644 src/mesa/pipe/softpipe/sp_clear.h create mode 100644 src/mesa/state_tracker/st_atom_clear_color.c (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 3e0c61eda2..32444343be 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -53,6 +53,10 @@ struct pipe_context { void (*draw_vb)( struct pipe_context *pipe, struct vertex_buffer *VB ); + /** Clear framebuffer */ + void (*clear)(struct pipe_context *pipe, GLboolean color, GLboolean depth, + GLboolean stencil, GLboolean accum); + /* * State functions */ @@ -62,12 +66,12 @@ struct pipe_context { void (*set_blend_state)( struct pipe_context *, const struct pipe_blend_state * ); - void (*set_cbuf_state)( struct pipe_context *, - const struct pipe_surface * ); - void (*set_clip_state)( struct pipe_context *, const struct pipe_clip_state * ); + void (*set_clear_color_state)( struct pipe_context *, + const struct pipe_clear_color_state * ); + void (*set_depth_state)( struct pipe_context *, const struct pipe_depth_state * ); diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index c88c0de6ad..c4bf0d2195 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -133,6 +133,11 @@ struct pipe_blend_color { GLfloat color[4]; }; +struct pipe_clear_color_state +{ + GLfloat color[4]; +}; + struct pipe_line_state { GLuint smooth:1; diff --git a/src/mesa/pipe/softpipe/sp_clear.c b/src/mesa/pipe/softpipe/sp_clear.c new file mode 100644 index 0000000000..c7fbca4229 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_clear.c @@ -0,0 +1,47 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Brian Paul + */ + + +#include "sp_clear.h" + + +void +softpipe_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, + GLboolean stencil, GLboolean accum) +{ + /* validate state (scissor)? */ + + if (color) { + } + if (depth) { + } + +} diff --git a/src/mesa/pipe/softpipe/sp_clear.h b/src/mesa/pipe/softpipe/sp_clear.h new file mode 100644 index 0000000000..f9db99dd32 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_clear.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. + * + **************************************************************************/ + +/* Author: + * Brian Paul + */ + +#ifndef SP_CLEAR_H +#define SP_CLEAR_H + +#include "pipe/p_state.h" +struct pipe_context; + +extern void +softpipe_clear(struct pipe_context *pipe, GLboolean color, GLboolean depth, + GLboolean stencil, GLboolean accum); + + +#endif /* SP_CLEAR_H */ diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index e0acf4177b..7ab65162bd 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -36,6 +36,7 @@ #include "vf/vf.h" #include "sp_context.h" +#include "sp_clear.h" #include "sp_prim.h" #include "sp_state.h" #include "sp_draw.h" @@ -68,6 +69,7 @@ struct pipe_context *softpipe_create( void ) softpipe->pipe.destroy = softpipe_destroy; softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.set_clip_state = softpipe_set_clip_state; + softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state; softpipe->pipe.set_point_state = softpipe_set_point_state; softpipe->pipe.set_viewport = softpipe_set_viewport; softpipe->pipe.set_setup_state = softpipe_set_setup_state; @@ -75,7 +77,7 @@ struct pipe_context *softpipe_create( void ) softpipe->pipe.set_fs_state = softpipe_set_fs_state; softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; softpipe->pipe.draw_vb = softpipe_draw_vb; - + softpipe->pipe.clear = softpipe_clear; softpipe->prim.setup = prim_setup( softpipe ); diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 43cb6f3f0b..0a183ea385 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -76,6 +76,7 @@ struct softpipe_context { struct pipe_blend_state blend; struct pipe_alpha_test_state alpha_test; struct pipe_clip_state clip; + struct pipe_clear_color_state clear_color; struct pipe_point_state point; struct pipe_scissor_rect scissor; struct pipe_poly_stipple poly_stipple; diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 4d18e80b38..bc5a3512ae 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -38,6 +38,9 @@ void softpipe_set_framebuffer_state( struct pipe_context *, const struct pipe_framebuffer_state * ); +void softpipe_set_clear_color_state( struct pipe_context *, + const struct pipe_clear_color_state * ); + void softpipe_set_clip_state( struct pipe_context *, const struct pipe_clip_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_surface.c b/src/mesa/pipe/softpipe/sp_state_surface.c index 99332fdd52..4d27814e1b 100644 --- a/src/mesa/pipe/softpipe/sp_state_surface.c +++ b/src/mesa/pipe/softpipe/sp_state_surface.c @@ -37,8 +37,9 @@ /* * XXX this might get moved someday */ -void softpipe_set_framebuffer_state( struct pipe_context *pipe, - const struct pipe_framebuffer_state *fb ) +void +softpipe_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) { struct softpipe_context *softpipe = softpipe_context(pipe); @@ -48,3 +49,13 @@ void softpipe_set_framebuffer_state( struct pipe_context *pipe, } + + +void +softpipe_set_clear_color_state(struct pipe_context *pipe, + const struct pipe_clear_color_state *clear) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + softpipe->clear_color = *clear; /* struct copy */ +} diff --git a/src/mesa/sources b/src/mesa/sources index 0bf7dbceb3..97801648c4 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -155,6 +155,7 @@ VF_SOURCES = \ vf/vf_sse.c SOFTPIPE_SOURCES = \ + pipe/softpipe/sp_clear.c \ pipe/softpipe/sp_context.c \ pipe/softpipe/sp_draw.c \ pipe/softpipe/sp_prim_clip.c \ @@ -177,6 +178,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom.c \ state_tracker/st_atom_alphatest.c \ state_tracker/st_atom_blend.c \ + state_tracker/st_atom_clear_color.c \ state_tracker/st_atom_clip.c \ state_tracker/st_atom_depth.c \ state_tracker/st_atom_fs.c \ diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 8ac435041d..e1d187f2db 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -43,6 +43,7 @@ static const struct st_tracked_state *atoms[] = { &st_update_framebuffer, + &st_update_clear_color, &st_update_clip, &st_update_fs, &st_update_point, diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 56c33f3076..8c1219fefd 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -46,6 +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_clear_color; const struct st_tracked_state st_update_depth; const struct st_tracked_state st_update_fs; const struct st_tracked_state st_update_point; diff --git a/src/mesa/state_tracker/st_atom_clear_color.c b/src/mesa/state_tracker/st_atom_clear_color.c new file mode 100644 index 0000000000..adf730cd8c --- /dev/null +++ b/src/mesa/state_tracker/st_atom_clear_color.c @@ -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: + * Keith Whitwell + * Brian Paul + */ + +#include "st_context.h" +#include "st_atom.h" +#include "pipe/p_context.h" + + +static void +update_clear_color_state( struct st_context *st ) +{ + struct pipe_clear_color_state clear; + + clear.color[0] = st->ctx->Color.ClearColor[0]; + clear.color[1] = st->ctx->Color.ClearColor[1]; + clear.color[2] = st->ctx->Color.ClearColor[2]; + clear.color[3] = st->ctx->Color.ClearColor[3]; + + if (memcmp(&clear, &st->state.clear_color, sizeof(clear)) != 0) { + st->state.clear_color = clear; + st->pipe->set_clear_color_state( st->pipe, &clear ); + } +} + + +const struct st_tracked_state st_update_clear_color = { + .dirty = { + .mesa = _NEW_COLOR, + .st = 0, + }, + .update = update_clear_color_state +}; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 94388f1aee..0f1fa2327b 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -71,6 +71,7 @@ struct st_context struct pipe_fs_state fs; struct pipe_alpha_test_state alpha_test; struct pipe_blend_state blend; + struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; struct pipe_depth_state depth; struct pipe_point_state point; -- cgit v1.2.3 From 13682d959ddacde1ce65843aa8c5b43dc9017b32 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 22 Jun 2007 13:08:49 -0600 Subject: more texture sampler work --- src/mesa/pipe/p_context.h | 4 + src/mesa/pipe/p_state.h | 15 ++-- src/mesa/pipe/softpipe/sp_context.c | 1 + src/mesa/pipe/softpipe/sp_context.h | 2 + src/mesa/pipe/softpipe/sp_state.h | 4 + src/mesa/pipe/softpipe/sp_state_sampler.c | 49 +++++++++++ src/mesa/sources | 2 + src/mesa/state_tracker/st_atom_sampler.c | 135 ++++++++++++++++++++++++++++++ src/mesa/state_tracker/st_context.h | 1 + 9 files changed, 208 insertions(+), 5 deletions(-) create mode 100644 src/mesa/pipe/softpipe/sp_state_sampler.c create mode 100644 src/mesa/state_tracker/st_atom_sampler.c (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 32444343be..7e68699d3e 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -96,6 +96,10 @@ struct pipe_context { void (*set_stencil_state)( struct pipe_context *, const struct pipe_stencil_state * ); + void (*set_sampler_state)( struct pipe_context *, + GLuint unit, + const struct pipe_sampler_state * ); + void (*set_viewport)( struct pipe_context *, const struct pipe_viewport * ); }; diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index d1e387ce43..f3723eb87e 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -41,6 +41,16 @@ #include "mtypes.h" + +/** + * Implementation limits + */ +#define PIPE_MAX_SAMPLERS 8 +#define PIPE_MAX_CLIP_PLANES 6 +#define PIPE_MAX_CONSTANT 32 + + + /** * Primitive (point/line/tri) setup info */ @@ -84,9 +94,6 @@ struct pipe_scissor_rect { GLshort maxy; }; - -#define PIPE_MAX_CLIP_PLANES 6 - struct pipe_clip_state { GLfloat ucp[PIPE_MAX_CLIP_PLANES][4]; GLuint nr; @@ -96,8 +103,6 @@ struct pipe_fs_state { struct gl_fragment_program *fp; }; -#define PIPE_MAX_CONSTANT 32 - struct pipe_constant_buffer { GLfloat constant[PIPE_MAX_CONSTANT][4]; GLuint nr_constants; diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index f27d2dd8bc..07b529fc6e 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -76,6 +76,7 @@ struct pipe_context *softpipe_create( void ) softpipe->pipe.set_scissor_rect = softpipe_set_scissor_rect; softpipe->pipe.set_fs_state = softpipe_set_fs_state; softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; + softpipe->pipe.set_sampler_state = softpipe_set_sampler_state; softpipe->pipe.draw_vb = softpipe_draw_vb; softpipe->pipe.clear = softpipe_clear; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 329544eb74..d8c0de0ad1 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -62,6 +62,7 @@ enum interp_mode { #define G_NEW_FRAMEBUFFER 0x100 #define G_NEW_ALPHA_TEST 0x200 #define G_NEW_DEPTH_TEST 0x400 +#define G_NEW_SAMPLER 0x800 #define PIPE_ATTRIB_MAX 32 @@ -84,6 +85,7 @@ struct softpipe_context { struct pipe_point_state point; struct pipe_scissor_rect scissor; struct pipe_poly_stipple poly_stipple; + struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; GLuint dirty; /* Clip derived state: diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 6253b9c9e5..faaa043a56 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -59,6 +59,10 @@ void softpipe_set_viewport( struct pipe_context *, void softpipe_set_setup_state( struct pipe_context *, const struct pipe_setup_state * ); +void softpipe_set_sampler_state( struct pipe_context *, + GLuint unit, + const struct pipe_sampler_state * ); + void softpipe_set_scissor_rect( struct pipe_context *, const struct pipe_scissor_rect * ); diff --git a/src/mesa/pipe/softpipe/sp_state_sampler.c b/src/mesa/pipe/softpipe/sp_state_sampler.c new file mode 100644 index 0000000000..6b422acfb6 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_state_sampler.c @@ -0,0 +1,49 @@ +/************************************************************************** + * + * 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: + * Brian Paul + */ +#include "imports.h" + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_draw.h" + + + +void +softpipe_set_sampler_state(struct pipe_context *pipe, + GLuint unit, + const struct pipe_sampler_state *sampler) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + softpipe->sampler[unit] = *sampler; + + softpipe->dirty |= G_NEW_SAMPLER; +} diff --git a/src/mesa/sources b/src/mesa/sources index fd84ed5826..3887e9f3c2 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -177,6 +177,7 @@ SOFTPIPE_SOURCES = \ pipe/softpipe/sp_state_fs.c \ pipe/softpipe/sp_state_point.c \ pipe/softpipe/sp_state_setup.c \ + pipe/softpipe/sp_state_sampler.c \ pipe/softpipe/sp_state_surface.c STATETRACKER_SOURCES = \ @@ -189,6 +190,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_fs.c \ state_tracker/st_atom_framebuffer.c \ state_tracker/st_atom_point.c \ + state_tracker/st_atom_sampler.c \ state_tracker/st_atom_scissor.c \ state_tracker/st_atom_stencil.c \ state_tracker/st_atom_setup.c \ diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c new file mode 100644 index 0000000000..1aa9da8484 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -0,0 +1,135 @@ +/************************************************************************** + * + * 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 texcoord wrap tokens to pipe tokens. + */ +static GLuint +gl_wrap_to_sp(GLenum wrap) +{ + switch (wrap) { + case GL_REPEAT: + return PIPE_TEX_WRAP_REPEAT; + case GL_CLAMP: + return PIPE_TEX_WRAP_CLAMP; + case GL_CLAMP_TO_EDGE: + return PIPE_TEX_WRAP_CLAMP_TO_EDGE; + case GL_CLAMP_TO_BORDER: + return PIPE_TEX_WRAP_CLAMP_TO_BORDER; + case GL_MIRRORED_REPEAT: + return PIPE_TEX_WRAP_MIRROR_REPEAT; + case GL_MIRROR_CLAMP_EXT: + return PIPE_TEX_WRAP_MIRROR_CLAMP; + case GL_MIRROR_CLAMP_TO_EDGE_EXT: + return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE; + case GL_MIRROR_CLAMP_TO_BORDER_EXT: + return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER; + default: + abort(); + return 0; + } +} + + +static GLuint +gl_filter_to_sp(GLenum filter) +{ + switch (filter) { + case GL_NEAREST: + return PIPE_TEX_FILTER_NEAREST; + case GL_LINEAR: + return PIPE_TEX_FILTER_LINEAR; + case GL_NEAREST_MIPMAP_NEAREST: + return PIPE_TEX_FILTER_NEAREST_MIPMAP_NEAREST; + case GL_NEAREST_MIPMAP_LINEAR: + return PIPE_TEX_FILTER_NEAREST_MIPMAP_LINEAR; + case GL_LINEAR_MIPMAP_NEAREST: + return PIPE_TEX_FILTER_LINEAR_MIPMAP_NEAREST; + case GL_LINEAR_MIPMAP_LINEAR: + return PIPE_TEX_FILTER_LINEAR_MIPMAP_LINEAR; + default: + abort(); + return 0; + } +} + + +static void +update_samplers(struct st_context *st) +{ + GLuint u; + + for (u = 0; u < st->ctx->Const.MaxTextureImageUnits; u++) { + const struct gl_texture_object *texobj + = st->ctx->Texture.Unit[u]._Current; + struct pipe_sampler_state sampler; + + memset(&sampler, 0, sizeof(sampler)); + + 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_filter = gl_filter_to_sp(texobj->MinFilter); + sampler.mag_filter = gl_filter_to_sp(texobj->MagFilter); + + /* XXX more sampler state here */ + + if (memcmp(&sampler, &st->state.sampler[u], sizeof(sampler)) != 0) { + /* state has changed */ + st->state.sampler[u] = sampler; + st->pipe->set_sampler_state(st->pipe, u, &sampler); + } + } +} + + +const struct st_tracked_state st_update_sampler = { + .dirty = { + .mesa = _NEW_TEXTURE, + .st = 0, + }, + .update = update_samplers +}; + + + + + diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 0f1fa2327b..582d586a73 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -75,6 +75,7 @@ struct st_context struct pipe_clip_state clip; struct pipe_depth_state depth; struct pipe_point_state point; + struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; struct pipe_scissor_rect scissor; struct pipe_poly_stipple poly_stipple; struct pipe_stencil_state stencil; -- cgit v1.2.3 From 1be17dc446aa6b0770d76a3eccf79d0faf6608c0 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 26 Jun 2007 17:35:24 -0600 Subject: consolidate point/line state into pipe_setup_state --- src/mesa/pipe/p_context.h | 3 --- src/mesa/pipe/p_state.h | 31 +++++++++++-------------------- src/mesa/pipe/softpipe/sp_context.c | 1 - src/mesa/pipe/softpipe/sp_context.h | 1 - src/mesa/pipe/softpipe/sp_prim_setup.c | 4 ++-- src/mesa/pipe/softpipe/sp_state.h | 3 --- src/mesa/sources | 6 ++---- src/mesa/state_tracker/st_atom.c | 1 - src/mesa/state_tracker/st_atom.h | 1 - src/mesa/state_tracker/st_atom_setup.c | 28 +++++++++++++++++++++------- src/mesa/state_tracker/st_context.h | 1 - 11 files changed, 36 insertions(+), 44 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index d9546a24d2..93dbbe6ab7 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -75,9 +75,6 @@ struct pipe_context { void (*set_depth_state)( struct pipe_context *, const struct pipe_depth_state * ); - void (*set_point_state)( struct pipe_context *, - const struct pipe_point_state * ); - void (*set_framebuffer_state)( struct pipe_context *, const struct pipe_framebuffer_state * ); diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 3e3da7cce6..e0fa4d54c3 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -70,9 +70,19 @@ struct pipe_setup_state GLuint offset_ccw:1; GLuint scissor:1; - GLuint poly_stipple:1; + GLuint poly_smooth:1; + GLuint poly_stipple_enable:1; + + GLuint line_smooth:1; + GLuint line_stipple_enable:1; + + GLuint point_smooth:1; + GLubyte line_stipple_factor; /**< [1..255] only */ + GLushort line_stipple_pattern; + GLfloat line_width; + GLfloat point_size; /**< used when no per-vertex size */ GLfloat offset_units; GLfloat offset_scale; }; @@ -147,25 +157,6 @@ struct pipe_clear_color_state GLfloat color[4]; }; -/** XXXX probably merge into pipe_setup_state */ -struct pipe_line_state -{ - GLuint smooth:1; - GLuint stipple:1; - GLushort stipple_pattern; - GLint stipple_factor; - GLfloat width; -}; - -/** XXXX probably merge into pipe_setup_state */ -struct pipe_point_state -{ - GLuint smooth:1; - GLfloat size; - GLfloat min_size, max_size; - GLfloat attenuation[3]; -}; - struct pipe_stencil_state { GLuint front_enabled:1; GLuint front_func:3; /**< PIPE_FUNC_x */ diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 0d00c7eb6c..7a0aad0973 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -70,7 +70,6 @@ struct pipe_context *softpipe_create( void ) softpipe->pipe.set_clip_state = softpipe_set_clip_state; softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state; softpipe->pipe.set_depth_state = softpipe_set_depth_test_state; - softpipe->pipe.set_point_state = softpipe_set_point_state; softpipe->pipe.set_viewport = softpipe_set_viewport; softpipe->pipe.set_setup_state = softpipe_set_setup_state; softpipe->pipe.set_scissor_rect = softpipe_set_scissor_rect; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 7c816dbc1a..c38102e2fd 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -83,7 +83,6 @@ struct softpipe_context { struct pipe_clip_state clip; struct pipe_clear_color_state clear_color; struct pipe_depth_state depth_test; - struct pipe_point_state point; struct pipe_scissor_rect scissor; struct pipe_poly_stipple poly_stipple; struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index a559b31a52..3f4602feb0 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -782,8 +782,8 @@ setup_point(struct prim_stage *stage, struct prim_header *prim) { struct setup_stage *setup = setup_stage( stage ); /*XXX this should be a vertex attrib! */ - GLfloat halfSize = 0.5 * setup->stage.softpipe->point.size; - GLboolean round = setup->stage.softpipe->point.smooth; + GLfloat halfSize = 0.5 * setup->stage.softpipe->setup.point_size; + GLboolean round = setup->stage.softpipe->setup.point_smooth; const struct vertex_header *v0 = prim->v[0]; const GLfloat x = v0->data[FRAG_ATTRIB_WPOS][0]; const GLfloat y = v0->data[FRAG_ATTRIB_WPOS][1]; diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 735d039748..4086c16bcc 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -73,9 +73,6 @@ void softpipe_set_scissor_rect( struct pipe_context *, void softpipe_set_fs_state( struct pipe_context *, const struct pipe_fs_state * ); -void softpipe_set_point_state( struct pipe_context *, - const struct pipe_point_state * ); - void softpipe_set_polygon_stipple( struct pipe_context *, const struct pipe_poly_stipple * ); diff --git a/src/mesa/sources b/src/mesa/sources index 3887e9f3c2..c0c4b35355 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -175,9 +175,8 @@ SOFTPIPE_SOURCES = \ pipe/softpipe/sp_state_clip.c \ pipe/softpipe/sp_state_derived.c \ pipe/softpipe/sp_state_fs.c \ - pipe/softpipe/sp_state_point.c \ - pipe/softpipe/sp_state_setup.c \ pipe/softpipe/sp_state_sampler.c \ + pipe/softpipe/sp_state_setup.c \ pipe/softpipe/sp_state_surface.c STATETRACKER_SOURCES = \ @@ -189,11 +188,10 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_depth.c \ state_tracker/st_atom_fs.c \ state_tracker/st_atom_framebuffer.c \ - state_tracker/st_atom_point.c \ state_tracker/st_atom_sampler.c \ state_tracker/st_atom_scissor.c \ - state_tracker/st_atom_stencil.c \ state_tracker/st_atom_setup.c \ + state_tracker/st_atom_stencil.c \ state_tracker/st_atom_viewport.c \ state_tracker/st_cb_program.c \ state_tracker/st_draw.c \ diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 5fcd9d7af5..88c6c776a3 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -47,7 +47,6 @@ static const struct st_tracked_state *atoms[] = &st_update_depth, &st_update_clip, &st_update_fs, - &st_update_point, &st_update_setup, &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 8c1219fefd..7ea3301ea5 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -49,7 +49,6 @@ 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_fs; -const struct st_tracked_state st_update_point; const struct st_tracked_state st_update_setup; const struct st_tracked_state st_update_viewport; const struct st_tracked_state st_update_constants; diff --git a/src/mesa/state_tracker/st_atom_setup.c b/src/mesa/state_tracker/st_atom_setup.c index fcda2b3a41..23adf0b7c8 100644 --- a/src/mesa/state_tracker/st_atom_setup.c +++ b/src/mesa/state_tracker/st_atom_setup.c @@ -101,12 +101,6 @@ static void update_setup_state( struct st_context *st ) ctx->Light.Model.TwoSide) setup.light_twoside = 1; - if (ctx->Polygon.SmoothFlag) - setup.poly_smooth = 1; - - if (ctx->Polygon.StippleFlag) - setup.poly_stipple = 1; - /* _NEW_POLYGON */ if (ctx->Polygon.CullFlag) { @@ -158,6 +152,12 @@ static void update_setup_state( struct st_context *st ) if (setup.fill_ccw != PIPE_POLYGON_MODE_FILL) setup.offset_ccw = get_offset_flag( setup.fill_ccw, &ctx->Polygon ); + if (ctx->Polygon.SmoothFlag) + setup.poly_smooth = 1; + + if (ctx->Polygon.StippleFlag) + setup.poly_stipple_enable = 1; + /* _NEW_BUFFERS, _NEW_POLYGON */ @@ -173,6 +173,19 @@ static void update_setup_state( struct st_context *st ) st->polygon_offset_scale); } + /* _NEW_POINT + */ + setup.point_size = ctx->Point.Size; + setup.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; + setup.line_stipple_factor = ctx->Line.StippleFactor; + if (memcmp(&setup, &st->state.setup, sizeof(setup)) != 0) { st->state.setup = setup; @@ -182,7 +195,8 @@ static void update_setup_state( struct st_context *st ) const struct st_tracked_state st_update_setup = { .dirty = { - .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_BUFFERS), + .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_LINE | + _NEW_POINT | _NEW_BUFFERS), .st = 0, }, .update = update_setup_state diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 582d586a73..48ea7f12ee 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -74,7 +74,6 @@ struct st_context struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; struct pipe_depth_state depth; - struct pipe_point_state point; struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; struct pipe_scissor_rect scissor; struct pipe_poly_stipple poly_stipple; -- cgit v1.2.3 From ea92566ed9cabf5eb5d0993b39c4372d5bfcf3f1 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 2 Jul 2007 15:32:12 -0600 Subject: rename a few structs (use _state suffix consistantly), reorder/sort fields in some structs --- src/mesa/pipe/p_context.h | 8 ++++---- src/mesa/pipe/p_state.h | 4 ++-- src/mesa/pipe/softpipe/sp_context.c | 4 ++-- src/mesa/pipe/softpipe/sp_context.h | 16 ++++++++-------- src/mesa/pipe/softpipe/sp_state.h | 8 ++++---- src/mesa/pipe/softpipe/sp_state_clip.c | 4 ++-- src/mesa/pipe/softpipe/sp_state_setup.c | 4 ++-- src/mesa/state_tracker/st_atom_scissor.c | 4 ++-- src/mesa/state_tracker/st_atom_viewport.c | 4 ++-- src/mesa/state_tracker/st_context.h | 16 ++++++++-------- 10 files changed, 36 insertions(+), 36 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 93dbbe6ab7..b87c42844c 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -87,8 +87,8 @@ struct pipe_context { void (*set_setup_state)( struct pipe_context *, const struct pipe_setup_state * ); - void (*set_scissor_rect)( struct pipe_context *, - const struct pipe_scissor_rect * ); + void (*set_scissor_state)( struct pipe_context *, + const struct pipe_scissor_state * ); void (*set_stencil_state)( struct pipe_context *, const struct pipe_stencil_state * ); @@ -101,8 +101,8 @@ struct pipe_context { GLuint unit, struct pipe_texture_object * ); - void (*set_viewport)( struct pipe_context *, - const struct pipe_viewport * ); + void (*set_viewport_state)( struct pipe_context *, + const struct pipe_viewport_state * ); }; diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 66a53483a3..7f9a6d12de 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -100,12 +100,12 @@ struct pipe_poly_stipple { }; -struct pipe_viewport { +struct pipe_viewport_state { GLfloat scale[4]; GLfloat translate[4]; }; -struct pipe_scissor_rect { +struct pipe_scissor_state { GLshort minx; GLshort miny; GLshort maxx; diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 7a0aad0973..5bd652f3a3 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -70,9 +70,9 @@ struct pipe_context *softpipe_create( void ) softpipe->pipe.set_clip_state = softpipe_set_clip_state; softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state; softpipe->pipe.set_depth_state = softpipe_set_depth_test_state; - softpipe->pipe.set_viewport = softpipe_set_viewport; + softpipe->pipe.set_viewport_state = softpipe_set_viewport_state; softpipe->pipe.set_setup_state = softpipe_set_setup_state; - softpipe->pipe.set_scissor_rect = softpipe_set_scissor_rect; + softpipe->pipe.set_scissor_state = softpipe_set_scissor_state; softpipe->pipe.set_fs_state = softpipe_set_fs_state; softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; softpipe->pipe.set_sampler_state = softpipe_set_sampler_state; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 7ba78b8090..a8c952591e 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -74,19 +74,19 @@ struct softpipe_context { /* The most recent drawing state as set by the driver: */ - struct pipe_framebuffer_state framebuffer; - struct pipe_viewport viewport; - struct pipe_setup_state setup; - struct pipe_fs_state fs; - struct pipe_blend_state blend; struct pipe_alpha_test_state alpha_test; - struct pipe_clip_state clip; - struct pipe_clear_color_state clear_color; + struct pipe_blend_state blend; + struct pipe_clear_color_state clear_color; + struct pipe_clip_state clip; struct pipe_depth_state depth_test; - struct pipe_scissor_rect scissor; + struct pipe_framebuffer_state framebuffer; + struct pipe_fs_state fs; struct pipe_poly_stipple poly_stipple; + struct pipe_scissor_state scissor; struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; + struct pipe_setup_state setup; struct pipe_texture_object *texture[PIPE_MAX_SAMPLERS]; + struct pipe_viewport_state viewport; GLuint dirty; /* Clip derived state: diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 4086c16bcc..60c24885e4 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -53,8 +53,8 @@ void softpipe_set_clip_state( struct pipe_context *, void softpipe_set_depth_test_state( struct pipe_context *, const struct pipe_depth_state * ); -void softpipe_set_viewport( struct pipe_context *, - const struct pipe_viewport * ); +void softpipe_set_viewport_state( struct pipe_context *, + const struct pipe_viewport_state * ); void softpipe_set_setup_state( struct pipe_context *, const struct pipe_setup_state * ); @@ -67,8 +67,8 @@ void softpipe_set_texture_state( struct pipe_context *, GLuint unit, struct pipe_texture_object * ); -void softpipe_set_scissor_rect( struct pipe_context *, - const struct pipe_scissor_rect * ); +void softpipe_set_scissor_state( struct pipe_context *, + const struct pipe_scissor_state * ); void softpipe_set_fs_state( struct pipe_context *, const struct pipe_fs_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_clip.c b/src/mesa/pipe/softpipe/sp_state_clip.c index 4b83f2b07e..c907550019 100644 --- a/src/mesa/pipe/softpipe/sp_state_clip.c +++ b/src/mesa/pipe/softpipe/sp_state_clip.c @@ -51,8 +51,8 @@ void softpipe_set_clip_state( struct pipe_context *pipe, /* Called when driver state tracker notices changes to the viewport * matrix: */ -void softpipe_set_viewport( struct pipe_context *pipe, - const struct pipe_viewport *viewport ) +void softpipe_set_viewport_state( struct pipe_context *pipe, + const struct pipe_viewport_state *viewport ) { struct softpipe_context *softpipe = softpipe_context(pipe); diff --git a/src/mesa/pipe/softpipe/sp_state_setup.c b/src/mesa/pipe/softpipe/sp_state_setup.c index a249ceb992..55803aeac5 100644 --- a/src/mesa/pipe/softpipe/sp_state_setup.c +++ b/src/mesa/pipe/softpipe/sp_state_setup.c @@ -103,8 +103,8 @@ void softpipe_set_setup_state( struct pipe_context *pipe, -void softpipe_set_scissor_rect( struct pipe_context *pipe, - const struct pipe_scissor_rect *scissor ) +void softpipe_set_scissor_state( struct pipe_context *pipe, + const struct pipe_scissor_state *scissor ) { struct softpipe_context *softpipe = softpipe_context(pipe); diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c index 75bead388f..05a9f3eed1 100644 --- a/src/mesa/state_tracker/st_atom_scissor.c +++ b/src/mesa/state_tracker/st_atom_scissor.c @@ -42,7 +42,7 @@ static void update_scissor( struct st_context *st ) { - struct pipe_scissor_rect scissor; + struct pipe_scissor_state scissor; const struct gl_framebuffer *fb = st->ctx->DrawBuffer; scissor.minx = 0; @@ -69,7 +69,7 @@ update_scissor( struct st_context *st ) if (memcmp(&scissor, &st->state.scissor, sizeof(scissor)) != 0) { /* state has changed */ st->state.scissor = scissor; /* struct copy */ - st->pipe->set_scissor_rect(st->pipe, &scissor); /* activate */ + st->pipe->set_scissor_state(st->pipe, &scissor); /* activate */ } } diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c index 765bcf3647..ac91f628aa 100644 --- a/src/mesa/state_tracker/st_atom_viewport.c +++ b/src/mesa/state_tracker/st_atom_viewport.c @@ -88,7 +88,7 @@ static void update_viewport( struct st_context *st ) GLfloat half_height = ctx->Viewport.Height / 2.0; GLfloat half_depth = (ctx->Viewport.Far - ctx->Viewport.Near) / 2.0; - struct pipe_viewport vp; + struct pipe_viewport_state vp; vp.scale[0] = half_width; vp.scale[1] = half_height * yScale; @@ -102,7 +102,7 @@ static void update_viewport( struct st_context *st ) if (memcmp(&vp, &st->state.viewport, sizeof(vp)) != 0) { st->state.viewport = vp; - st->pipe->set_viewport(st->pipe, &vp); + st->pipe->set_viewport_state(st->pipe, &vp); } } } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 48ea7f12ee..3b47785a9a 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -65,19 +65,19 @@ struct st_context * though, we just shove random objects across the interface. */ struct { - struct pipe_framebuffer_state framebuffer; - struct pipe_viewport viewport; - struct pipe_setup_state setup; - struct pipe_fs_state fs; struct pipe_alpha_test_state alpha_test; struct pipe_blend_state blend; struct pipe_clear_color_state clear_color; - struct pipe_clip_state clip; - struct pipe_depth_state depth; - struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; - struct pipe_scissor_rect scissor; + struct pipe_clip_state clip; + struct pipe_depth_state depth; + struct pipe_framebuffer_state framebuffer; + struct pipe_fs_state fs; 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_stencil_state stencil; + struct pipe_viewport_state viewport; } state; struct { -- cgit v1.2.3 From 284efcfc27aaeb447e0898ae3342e9fee20c584a Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 3 Jul 2007 17:19:30 -0600 Subject: hook in state tracking for blend color --- src/mesa/pipe/p_context.h | 3 +++ src/mesa/pipe/softpipe/sp_context.c | 1 + src/mesa/pipe/softpipe/sp_state.h | 3 +++ src/mesa/pipe/softpipe/sp_state_blend.c | 11 +++++++++++ src/mesa/state_tracker/st_atom_blend.c | 9 +++++++++ src/mesa/state_tracker/st_context.h | 1 + 6 files changed, 28 insertions(+) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index b87c42844c..e4115226e7 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -66,6 +66,9 @@ struct pipe_context { void (*set_blend_state)( struct pipe_context *, const struct pipe_blend_state * ); + void (*set_blend_color)( struct pipe_context *, + const struct pipe_blend_color * ); + void (*set_clip_state)( struct pipe_context *, const struct pipe_clip_state * ); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 5bd652f3a3..6bd1d9f16e 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -67,6 +67,7 @@ struct pipe_context *softpipe_create( void ) softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state; softpipe->pipe.set_blend_state = softpipe_set_blend_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_depth_state = softpipe_set_depth_test_state; diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 60c24885e4..38a212b79a 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -44,6 +44,9 @@ void softpipe_set_alpha_test_state( struct pipe_context *, 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 ); + void softpipe_set_clear_color_state( struct pipe_context *, const struct pipe_clear_color_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_blend.c b/src/mesa/pipe/softpipe/sp_state_blend.c index c364d8a319..6ca42e8a01 100644 --- a/src/mesa/pipe/softpipe/sp_state_blend.c +++ b/src/mesa/pipe/softpipe/sp_state_blend.c @@ -46,6 +46,17 @@ void softpipe_set_blend_state( struct pipe_context *pipe, } +void softpipe_set_blend_color( struct pipe_context *pipe, + const struct pipe_blend_color *blend_color ) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + softpipe->blend_color = *blend_color; + + softpipe->dirty |= G_NEW_BLEND; +} + + /** XXX move someday? Or consolidate all these simple state setters * into one file. */ diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c index e0215c9eef..3e5410cfab 100644 --- a/src/mesa/state_tracker/st_atom_blend.c +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -201,6 +201,15 @@ update_blend( struct st_context *st ) st->state.blend = blend; /* struct copy */ st->pipe->set_blend_state(st->pipe, &blend); /* set new state */ } + + 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); + } } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 3b47785a9a..c1d868604c 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -67,6 +67,7 @@ struct st_context struct { 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; struct pipe_depth_state depth; -- cgit v1.2.3 From 4824c342c864e870251a7d343c95e51274e50d23 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 19 Jul 2007 20:24:55 +0100 Subject: Trigger tgsi compilation for fragment programs. Not sure the generated program looks correct though... --- src/mesa/pipe/p_state.h | 5 ++- src/mesa/pipe/softpipe/sp_state_derived.c | 4 +-- src/mesa/pipe/tgsi/core/tgsi_dump.c | 4 +++ src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h | 2 ++ src/mesa/sources | 1 + src/mesa/state_tracker/st_atom.c | 1 + src/mesa/state_tracker/st_atom.h | 1 + src/mesa/state_tracker/st_atom_fs.c | 27 ++++++++++++-- src/mesa/state_tracker/st_atom_vs.c | 49 +++++++++++++++++++++++++ src/mesa/state_tracker/st_cb_program.c | 59 ++++++++++++++----------------- src/mesa/state_tracker/st_context.h | 1 + src/mesa/state_tracker/st_program.h | 38 +++++++++++++++++++- 12 files changed, 152 insertions(+), 40 deletions(-) create mode 100644 src/mesa/state_tracker/st_atom_vs.c (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index fd5e7ad3af..e3f62a80ad 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -121,8 +121,11 @@ struct pipe_clip_state { GLuint nr; }; + struct pipe_fs_state { - struct gl_fragment_program *fp; + GLuint inputs_read; /* FRAG_ATTRIB_* */ + const struct tgsi_token *tokens; + }; struct pipe_constant_buffer { diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index 18dfb50e38..fcdedb54a9 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -28,7 +28,6 @@ #include "main/glheader.h" #include "main/macros.h" #include "main/enums.h" -#include "shader/program.h" #include "vf/vf.h" #include "pipe/draw/draw_context.h" @@ -68,8 +67,7 @@ static const GLuint frag_to_vf[FRAG_ATTRIB_MAX] = */ static void calculate_vertex_layout( struct softpipe_context *softpipe ) { - struct gl_fragment_program *fp = softpipe->fs.fp; - const GLuint inputsRead = fp->Base.InputsRead; + const GLuint inputsRead = softpipe->fs.inputs_read; GLuint slot_to_vf_attr[VF_ATTRIB_MAX]; GLbitfield attr_mask = 0x0; GLuint i; diff --git a/src/mesa/pipe/tgsi/core/tgsi_dump.c b/src/mesa/pipe/tgsi/core/tgsi_dump.c index fecb246ab1..0345fd93f7 100644 --- a/src/mesa/pipe/tgsi/core/tgsi_dump.c +++ b/src/mesa/pipe/tgsi/core/tgsi_dump.c @@ -400,12 +400,16 @@ tgsi_dump( GLuint deflt = !(flags & TGSI_DUMP_NO_DEFAULT); { +#if 0 static GLuint counter = 0; char buffer[64]; sprintf( buffer, "sbir-dump-%.4u.txt", counter++ ); dump.file = fopen( buffer, "wt" ); +#else + dump.file = stderr; dump.tabs = 0; +#endif } tgsi_parse_init( &parse, tokens ); diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h index 4c1141e579..9256318997 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h @@ -5,6 +5,8 @@ extern "C" { #endif // defined __cplusplus +struct tgsi_token; + GLboolean tgsi_mesa_compile_fp_program( const struct gl_fragment_program *program, diff --git a/src/mesa/sources b/src/mesa/sources index a76e41bdda..a589ae4373 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -206,6 +206,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_clip.c \ state_tracker/st_atom_depth.c \ state_tracker/st_atom_fs.c \ + state_tracker/st_atom_vs.c \ state_tracker/st_atom_framebuffer.c \ state_tracker/st_atom_sampler.c \ state_tracker/st_atom_scissor.c \ diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index dfebfb4768..85c99bc182 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -46,6 +46,7 @@ static const struct st_tracked_state *atoms[] = &st_update_clear_color, &st_update_depth, &st_update_clip, + &st_update_vs, &st_update_fs, &st_update_setup, &st_update_polygon_stipple, diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index a56483ac39..1b70e27933 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -49,6 +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; 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_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 9c6bc1ce2a..6fa4f53c73 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -32,15 +32,38 @@ #include "st_context.h" #include "pipe/p_context.h" #include "st_atom.h" +#include "st_program.h" +#include "pipe/tgsi/mesa/mesa_to_tgsi.h" +#include "pipe/tgsi/core/tgsi_dump.h" + +static void compile_fs( struct st_context *st, + struct st_fragment_program *fs ) +{ + /* XXX: fix static allocation of tokens: + */ + tgsi_mesa_compile_fp_program( &fs->Base, fs->tokens, ST_FP_MAX_TOKENS ); + + tgsi_dump( fs->tokens, TGSI_DUMP_VERBOSE ); +} static void update_fs( struct st_context *st ) { struct pipe_fs_state fs; + struct st_fragment_program *fp = st_fragment_program(st->ctx->FragmentProgram._Current); + + memset( &fs, 0, sizeof(fs) ); - fs.fp = st->ctx->FragmentProgram._Current; + if (fp->dirty) + compile_fs( st, fp ); + + fs.inputs_read = fp->Base.Base.InputsRead; + fs.tokens = &fp->tokens[0]; - if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0) { + if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0 || + fp->dirty) + { + fp->dirty = 0; st->state.fs = fs; st->pipe->set_fs_state(st->pipe, &fs); } diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c new file mode 100644 index 0000000000..6a26bfdd19 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -0,0 +1,49 @@ +/************************************************************************** + * + * 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 + */ + +#include "st_context.h" +#include "pipe/p_context.h" +#include "st_atom.h" + + + +static void update_vs( struct st_context *st ) +{ +} + + +const struct st_tracked_state st_update_vs = { + .dirty = { + .mesa = 0, + .st = ST_NEW_VERTEX_PROGRAM, + }, + .update = update_vs +}; diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 327b627722..18061ca69c 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -52,6 +52,7 @@ static void st_bind_program( GLcontext *ctx, switch (target) { case GL_VERTEX_PROGRAM_ARB: + st->dirty.st |= ST_NEW_VERTEX_PROGRAM; break; case GL_FRAGMENT_PROGRAM_ARB: st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; @@ -66,16 +67,23 @@ static struct gl_program *st_new_program( GLcontext *ctx, struct st_context *st = st_context(ctx); switch (target) { - case GL_VERTEX_PROGRAM_ARB: - return _mesa_init_vertex_program(ctx, - CALLOC_STRUCT(gl_vertex_program), - target, - id); + case GL_VERTEX_PROGRAM_ARB: { + struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program); + + prog->id = st->program_id++; + prog->dirty = 1; + + return _mesa_init_vertex_program( ctx, + &prog->Base, + target, + id ); + } case GL_FRAGMENT_PROGRAM_ARB: { struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program); prog->id = st->program_id++; + prog->dirty = 1; return _mesa_init_fragment_program( ctx, &prog->Base, @@ -106,40 +114,25 @@ static void st_program_string_notify( GLcontext *ctx, GLenum target, struct gl_program *prog ) { - if (target == GL_FRAGMENT_PROGRAM_ARB) { - struct st_context *st = st_context(ctx); + struct st_context *st = st_context(ctx); - if (prog == &st->ctx->FragmentProgram._Current->Base) - { - struct st_fragment_program *p = - (struct st_fragment_program *) prog; + if (target == GL_FRAGMENT_PROGRAM_ARB) { + struct st_fragment_program *p = (struct st_fragment_program *)prog; + if (prog == &ctx->FragmentProgram._Current->Base) st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; - p->id = st->program_id++; -#if 0 - p->param_state = p->Base.Base.Parameters->StateFlags; - p->translated = 0; -#endif - - /* Gack! do this in the compiler: - */ - if (p->Base.FogOption) { - /* add extra instructions to do fog, then turn off FogOption field */ - _mesa_append_fog_code(ctx, &p->Base); - p->Base.FogOption = GL_NONE; - } - - /* XXX: Not hooked-up yet. */ - { - struct tgsi_token tokens[1024]; - - tgsi_mesa_compile_fp_program( prog, tokens, 1024 ); - tgsi_dump( tokens, TGSI_DUMP_VERBOSE ); - } - } + p->id = st->program_id++; + p->param_state = p->Base.Base.Parameters->StateFlags; } else if (target == GL_VERTEX_PROGRAM_ARB) { + struct st_vertex_program *p = (struct st_vertex_program *)prog; + + if (prog == &ctx->VertexProgram._Current->Base) + st->dirty.st |= ST_NEW_VERTEX_PROGRAM; + + p->id = st->program_id++; + p->param_state = p->Base.Base.Parameters->StateFlags; /* Also tell tnl about it: */ diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index c1d868604c..ef3cdb3b09 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; #define ST_NEW_MESA 0x1 /* Mesa state has changed */ #define ST_NEW_FRAGMENT_PROGRAM 0x2 +#define ST_NEW_VERTEX_PROGRAM 0x4 struct st_state_flags { GLuint mesa; diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index a47059d7a6..b28887946d 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -34,6 +34,12 @@ #ifndef ST_PROGRAM_H #define ST_PROGRAM_H +#include "mtypes.h" +#include "pipe/tgsi/core/tgsi_token.h" + +#define ST_FP_MAX_TOKENS 1024 + + struct st_fragment_program { struct gl_fragment_program Base; @@ -43,6 +49,11 @@ struct st_fragment_program * ProgramStringNotify changes. */ + + struct tgsi_token tokens[ST_FP_MAX_TOKENS]; + GLboolean dirty; + + #if 0 GLfloat (*cbuffer)[4]; GLuint nr_constants; @@ -56,13 +67,38 @@ struct st_fragment_program const GLfloat *values; /* Pointer to tracked values */ } *param; GLuint nr_params; +#endif GLuint param_state; -#endif }; +struct st_vertex_program +{ + struct gl_vertex_program Base; + GLboolean error; /* If program is malformed for any reason. */ + + GLuint id; /* String id, for tracking + * ProgramStringNotify changes. + */ + + GLboolean dirty; + GLuint param_state; +}; + void st_init_cb_program( struct st_context *st ); void st_destroy_cb_program( struct st_context *st ); +static inline struct st_fragment_program * +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 ) +{ + return (struct st_vertex_program *)vp; +} + #endif -- 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_context.h') 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 5c2c05600081f811e001a81a600778de0fcab85d Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 10 Aug 2007 12:57:14 +0100 Subject: Handle glFlush/glFinish through the state tracker. --- src/mesa/drivers/dri/intel_winsys/intel_context.c | 46 ------------ .../dri/intel_winsys/intel_pipe_i915simple.c | 14 +++- .../drivers/dri/intel_winsys/intel_pipe_softpipe.c | 31 +++++++++ src/mesa/pipe/i915simple/i915_flush.c | 5 +- src/mesa/pipe/i915simple/i915_winsys.h | 6 ++ src/mesa/pipe/p_context.h | 6 +- src/mesa/pipe/softpipe/sp_context.c | 2 +- src/mesa/pipe/softpipe/sp_flush.c | 19 ++++- src/mesa/pipe/softpipe/sp_flush.h | 2 +- src/mesa/pipe/softpipe/sp_winsys.h | 12 +++- src/mesa/sources | 1 + src/mesa/state_tracker/st_cb_flush.c | 81 ++++++++++++++++++++++ src/mesa/state_tracker/st_cb_flush.h | 38 ++++++++++ src/mesa/state_tracker/st_context.c | 2 + src/mesa/state_tracker/st_context.h | 4 ++ 15 files changed, 212 insertions(+), 57 deletions(-) create mode 100644 src/mesa/state_tracker/st_cb_flush.c create mode 100644 src/mesa/state_tracker/st_cb_flush.h (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_context.c b/src/mesa/drivers/dri/intel_winsys/intel_context.c index 1032fc2d0f..a1746e0965 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_context.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_context.c @@ -240,51 +240,7 @@ intelFlush(GLcontext * ctx) } -/** - * Check if we need to rotate/warp the front color buffer to the - * rotated screen. We generally need to do this when we get a glFlush - * or glFinish after drawing to the front color buffer. - * If no rotation, just copy the private fake front buffer to the real one. - */ -static void -intelCheckFrontUpdate(GLcontext * ctx) -{ - struct intel_context *intel = intel_context(ctx); - /* rely on _ColorDrawBufferMask being kept up to date by mesa - even for window-fbos. */ - /* not sure. Might need that for all masks including - BUFFER_BIT_FRONT_LEFT maybe? */ - if (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] == - BUFFER_BIT_FRONT_LEFT) { - __DRIdrawablePrivate *dPriv = intel->driDrawable; - intelCopyBuffer(dPriv, NULL); - } -} - -/** - * Called via glFlush. - */ -static void -intelglFlush(GLcontext * ctx) -{ - intelFlush(ctx); - intelCheckFrontUpdate(ctx); -} - -void -intelFinish(GLcontext * ctx) -{ - struct intel_context *intel = intel_context(ctx); - intelFlush(ctx); - if (intel->batch->last_fence) { - driFenceFinish(intel->batch->last_fence, - 0, GL_FALSE); - driFenceUnReference(intel->batch->last_fence); - intel->batch->last_fence = NULL; - } - intelCheckFrontUpdate(ctx); -} static void @@ -292,8 +248,6 @@ intelInitDriverFunctions(struct dd_function_table *functions) { _mesa_init_driver_functions(functions); - functions->Flush = intelglFlush; - functions->Finish = intelFinish; functions->GetString = intelGetString; functions->UpdateState = intelInvalidateState; diff --git a/src/mesa/drivers/dri/intel_winsys/intel_pipe_i915simple.c b/src/mesa/drivers/dri/intel_winsys/intel_pipe_i915simple.c index c0e8c2349c..d78d81aa1c 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_pipe_i915simple.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_pipe_i915simple.c @@ -37,6 +37,7 @@ #include "intel_context.h" #include "intel_batchbuffer.h" #include "intel_pipe.h" +#include "intel_blit.h" #include "pipe/i915simple/i915_winsys.h" @@ -171,7 +172,7 @@ static unsigned *intel_i915_batch_start( struct i915_winsys *sws, if (intel_batchbuffer_space( intel->batch ) >= dwords * 4) { /* XXX: Hmm, the driver can't really do much with this pointer: */ - return intel->batch->ptr; + return (unsigned *)intel->batch->ptr; } else return NULL; @@ -242,6 +243,16 @@ static void intel_i915_printf( struct i915_winsys *sws, } +static void +intel_i915_flush_frontbuffer( struct i915_winsys *sws ) +{ + struct intel_context *intel = intel_i915_winsys(sws)->intel; + __DRIdrawablePrivate *dPriv = intel->driDrawable; + + intelCopyBuffer(dPriv, NULL); +} + + struct pipe_context * intel_create_i915simple( struct intel_context *intel ) { @@ -264,6 +275,7 @@ intel_create_i915simple( struct intel_context *intel ) iws->winsys.batch_reloc = intel_i915_batch_reloc; iws->winsys.batch_flush = intel_i915_batch_flush; iws->winsys.batch_wait_idle = intel_i915_batch_wait_idle; + iws->winsys.flush_frontbuffer = intel_i915_flush_frontbuffer; iws->intel = intel; /* Create the i915simple context: diff --git a/src/mesa/drivers/dri/intel_winsys/intel_pipe_softpipe.c b/src/mesa/drivers/dri/intel_winsys/intel_pipe_softpipe.c index 06db5c9f43..439bb372e1 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_pipe_softpipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_pipe_softpipe.c @@ -36,6 +36,8 @@ #include "intel_context.h" #include "intel_pipe.h" +#include "intel_batchbuffer.h" +#include "intel_blit.h" #include "pipe/softpipe/sp_winsys.h" #include "pipe/p_defines.h" @@ -175,6 +177,33 @@ intel_supported_formats(struct pipe_context *pipe, GLuint *numFormats) } +static void intel_wait_idle( struct softpipe_winsys *sws ) +{ + struct intel_context *intel = intel_softpipe_winsys(sws)->intel; + + if (intel->batch->last_fence) { + driFenceFinish(intel->batch->last_fence, + DRM_FENCE_TYPE_EXE | DRM_I915_FENCE_TYPE_RW, GL_FALSE); + driFenceUnReference(intel->batch->last_fence); + intel->batch->last_fence = NULL; + } +} + + +/* The state tracker (should!) keep track of whether the fake + * frontbuffer has been touched by any rendering since the last time + * we copied its contents to the real frontbuffer. Our task is easy: + */ +static void +intel_flush_frontbuffer( struct softpipe_winsys *sws ) +{ + struct intel_context *intel = intel_softpipe_winsys(sws)->intel; + __DRIdrawablePrivate *dPriv = intel->driDrawable; + + intelCopyBuffer(dPriv, NULL); +} + + struct pipe_context * intel_create_softpipe( struct intel_context *intel ) @@ -197,6 +226,8 @@ intel_create_softpipe( struct intel_context *intel ) isws->sws.buffer_data = intel_buffer_data; isws->sws.buffer_subdata = intel_buffer_subdata; isws->sws.buffer_get_subdata = intel_buffer_get_subdata; + isws->sws.flush_frontbuffer = intel_flush_frontbuffer; + isws->sws.wait_idle = intel_wait_idle; isws->intel = intel; /* Create the softpipe context: diff --git a/src/mesa/pipe/i915simple/i915_flush.c b/src/mesa/pipe/i915simple/i915_flush.c index 1cf945e9a2..8af4ce770c 100644 --- a/src/mesa/pipe/i915simple/i915_flush.c +++ b/src/mesa/pipe/i915simple/i915_flush.c @@ -66,11 +66,10 @@ static void i915_flush( struct pipe_context *pipe, FLUSH_BATCH(); } -static void i915_finish(struct pipe_context *pipe) +static void i915_wait_idle(struct pipe_context *pipe) { struct i915_context *i915 = i915_context(pipe); - i915_flush( pipe, 0 ); i915->winsys->batch_wait_idle( i915->winsys ); } @@ -78,5 +77,5 @@ static void i915_finish(struct pipe_context *pipe) void i915_init_flush_functions( struct i915_context *i915 ) { i915->pipe.flush = i915_flush; - i915->pipe.finish = i915_finish; + i915->pipe.wait_idle = i915_wait_idle; } diff --git a/src/mesa/pipe/i915simple/i915_winsys.h b/src/mesa/pipe/i915simple/i915_winsys.h index 9802148aa1..a3dadbfd3d 100644 --- a/src/mesa/pipe/i915simple/i915_winsys.h +++ b/src/mesa/pipe/i915simple/i915_winsys.h @@ -50,6 +50,12 @@ struct pipe_buffer_handle; struct i915_winsys { + /* Do any special operations to ensure frontbuffer contents are + * displayed, eg copy fake frontbuffer. + */ + void (*flush_frontbuffer)( struct i915_winsys *sws ); + + /* debug output */ void (*printf)( struct i915_winsys *sws, diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 7eb492816b..533840c555 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -220,10 +220,14 @@ struct pipe_context { struct pipe_mipmap_tree *mt ); + /* Simple flush/finish support: + */ void (*flush)( struct pipe_context *pipe, unsigned flags ); - void (*finish)( struct pipe_context *pipe ); + void (*wait_idle)( struct pipe_context *pipe ); + + void (*flush_frontbuffer)( struct pipe_context *pipe ); }; diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 0794d9a888..db572f169d 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -221,7 +221,7 @@ struct pipe_context *softpipe_create( struct softpipe_winsys *sws ) softpipe->pipe.draw_vertices = softpipe_draw_vertices; softpipe->pipe.clear = softpipe_clear; softpipe->pipe.flush = softpipe_flush; - softpipe->pipe.finish = softpipe_finish; + softpipe->pipe.wait_idle = softpipe_wait_idle; softpipe->pipe.reset_occlusion_counter = softpipe_reset_occlusion_counter; softpipe->pipe.get_occlusion_counter = softpipe_get_occlusion_counter; diff --git a/src/mesa/pipe/softpipe/sp_flush.c b/src/mesa/pipe/softpipe/sp_flush.c index aa609469a6..a0bce200ed 100644 --- a/src/mesa/pipe/softpipe/sp_flush.c +++ b/src/mesa/pipe/softpipe/sp_flush.c @@ -33,6 +33,7 @@ #include "pipe/p_defines.h" #include "sp_flush.h" #include "sp_context.h" +#include "sp_winsys.h" /* There will be actual work to do here. In future we may want a * fence-like interface instead of finish, and perhaps flush will take @@ -49,9 +50,21 @@ softpipe_flush( struct pipe_context *pipe, } void -softpipe_finish(struct pipe_context *pipe) +softpipe_wait_idle(struct pipe_context *pipe) { - /* Just calls into flush() + /* Nothing to do. + * XXX: What about swapbuffers. + * XXX: Even more so - what about fake frontbuffer copies?? */ - softpipe_flush( pipe, 0 ); + struct softpipe_context *softpipe = softpipe_context(pipe); + softpipe->winsys->wait_idle( softpipe->winsys ); +} + + +void +softpipe_flush_frontbuffer( struct pipe_context *pipe ) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + softpipe->winsys->flush_frontbuffer( softpipe->winsys ); } diff --git a/src/mesa/pipe/softpipe/sp_flush.h b/src/mesa/pipe/softpipe/sp_flush.h index 5e204f87a5..03c0010623 100644 --- a/src/mesa/pipe/softpipe/sp_flush.h +++ b/src/mesa/pipe/softpipe/sp_flush.h @@ -30,7 +30,7 @@ struct pipe_context; -void softpipe_finish(struct pipe_context *pipe); void softpipe_flush(struct pipe_context *pipe, unsigned flags ); +void softpipe_wait_idle(struct pipe_context *pipe); #endif diff --git a/src/mesa/pipe/softpipe/sp_winsys.h b/src/mesa/pipe/softpipe/sp_winsys.h index 6f6d0f2446..73b0659067 100644 --- a/src/mesa/pipe/softpipe/sp_winsys.h +++ b/src/mesa/pipe/softpipe/sp_winsys.h @@ -50,9 +50,19 @@ struct pipe_buffer_handle; struct softpipe_winsys { + /* Do any special operations to ensure frontbuffer contents are + * displayed, eg copy fake frontbuffer. + */ + void (*flush_frontbuffer)( struct softpipe_winsys *sws ); + + /* Wait for any hw swapbuffers, etc. to finish: + */ + void (*wait_idle)( struct softpipe_winsys *sws ); + /* debug output */ - void (*printf)( const char *, ... ); + void (*printf)( struct softpipe_winsys *sws, + const char *, ... ); /* The buffer manager is modeled after the dri_bugmgr interface, diff --git a/src/mesa/sources b/src/mesa/sources index 54a0978715..a2b9fed82b 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -194,6 +194,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_viewport.c \ state_tracker/st_cb_bufferobjects.c \ state_tracker/st_cb_clear.c \ + state_tracker/st_cb_flush.c \ state_tracker/st_cb_drawpixels.c \ state_tracker/st_cb_fbo.c \ state_tracker/st_cb_program.c \ diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c new file mode 100644 index 0000000000..a6a8f8d90f --- /dev/null +++ b/src/mesa/state_tracker/st_cb_flush.c @@ -0,0 +1,81 @@ +/************************************************************************** + * + * 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 "main/glheader.h" +#include "main/macros.h" +#include "st_context.h" +#include "st_cb_flush.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" + + +static void st_flush(GLcontext *ctx) +{ + struct st_context *st = ctx->st; + + /* If there has been no rendering to the frontbuffer, consider + * short-circuiting this, or perhaps pass an "optional" flag down + * to the driver so that it can make the decision. + */ + st->pipe->flush( st->pipe, 0 ); + + + /* XXX: temporary hack. This flag should only be set if we do any + * rendering to the front buffer. + */ + st->flags.frontbuffer_dirty = (ctx->DrawBuffer->_ColorDrawBufferMask[0] == + BUFFER_BIT_FRONT_LEFT); + + + if (st->flags.frontbuffer_dirty) { + /* Hook for copying "fake" frontbuffer if necessary: + */ + st->pipe->flush_frontbuffer( st->pipe ); + st->flags.frontbuffer_dirty = 0; + } +} + +static void st_finish(GLcontext *ctx) +{ + struct st_context *st = ctx->st; + + st_flush( ctx ); + st->pipe->wait_idle( st->pipe ); +} + + +void st_init_flush_functions(struct dd_function_table *functions) +{ + functions->Flush = st_flush; + functions->Finish = st_finish; +} diff --git a/src/mesa/state_tracker/st_cb_flush.h b/src/mesa/state_tracker/st_cb_flush.h new file mode 100644 index 0000000000..29ceab3a56 --- /dev/null +++ b/src/mesa/state_tracker/st_cb_flush.h @@ -0,0 +1,38 @@ +/************************************************************************** + * + * 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_CB_CLEAR_H +#define ST_CB_CLEAR_H + + +extern void +st_init_flush_functions(struct dd_function_table *functions); + + +#endif /* ST_CB_CLEAR_H */ + diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 80935442ae..2bdcc6caf3 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -34,6 +34,7 @@ #include "st_cb_fbo.h" #include "st_cb_readpixels.h" #include "st_cb_texture.h" +#include "st_cb_flush.h" #include "st_atom.h" #include "st_draw.h" #include "st_program.h" @@ -109,4 +110,5 @@ void st_init_driver_functions(struct dd_function_table *functions) st_init_program_functions(functions); st_init_readpixels_functions(functions); st_init_texture_functions(functions); + st_init_flush_functions(functions); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index fe73630c75..88e2701fc3 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -90,6 +90,10 @@ struct st_context struct gl_fragment_program *fragment_program; } cb; + struct { + GLuint frontbuffer_dirty:1; + } flags; + /* State to be validated: */ struct st_tracked_state **atoms; -- cgit v1.2.3 From 39407fd85467141fceafbedf52d9e55e008eb011 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 10 Aug 2007 16:42:26 +0100 Subject: Move string functions to state_tracker, add queries to pipe, winsys. --- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 7 ++ src/mesa/pipe/i915simple/Makefile | 1 + src/mesa/pipe/i915simple/i915_context.c | 15 +--- src/mesa/pipe/i915simple/i915_context.h | 2 + src/mesa/pipe/i915simple/i915_reg.h | 9 +++ src/mesa/pipe/i915simple/i915_strings.c | 83 +++++++++++++++++++++ src/mesa/pipe/p_context.h | 7 ++ src/mesa/pipe/p_winsys.h | 4 + src/mesa/pipe/softpipe/sp_context.c | 12 +++ src/mesa/sources | 1 + src/mesa/state_tracker/st_cb_strings.c | 86 ++++++++++++++++++++++ src/mesa/state_tracker/st_cb_strings.h | 38 ++++++++++ src/mesa/state_tracker/st_context.c | 2 + src/mesa/state_tracker/st_context.h | 2 + 14 files changed, 258 insertions(+), 11 deletions(-) create mode 100644 src/mesa/pipe/i915simple/i915_strings.c create mode 100644 src/mesa/state_tracker/st_cb_strings.c create mode 100644 src/mesa/state_tracker/st_cb_strings.h (limited to 'src/mesa/state_tracker/st_context.h') 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 015d8fc2bb..eb64f5aa20 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -185,6 +185,12 @@ intel_printf( struct pipe_winsys *sws, const char *fmtString, ... ) va_end( args ); } +static const char * +intel_get_name( struct pipe_winsys *sws ) +{ + return "Intel/DRI/ttm"; +} + struct pipe_winsys * intel_create_pipe_winsys( struct intel_context *intel ) @@ -209,6 +215,7 @@ intel_create_pipe_winsys( struct intel_context *intel ) iws->winsys.flush_frontbuffer = intel_flush_frontbuffer; iws->winsys.wait_idle = intel_wait_idle; iws->winsys.printf = intel_printf; + iws->winsys.get_name = intel_get_name; iws->intel = intel; return &iws->winsys; diff --git a/src/mesa/pipe/i915simple/Makefile b/src/mesa/pipe/i915simple/Makefile index 28fe70d069..9a0d40a8d4 100644 --- a/src/mesa/pipe/i915simple/Makefile +++ b/src/mesa/pipe/i915simple/Makefile @@ -19,6 +19,7 @@ DRIVER_SOURCES = \ i915_state_derived.c \ i915_state_emit.c \ i915_state_fragprog.c \ + i915_strings.c \ i915_prim_emit.c \ i915_tex_layout.c \ i915_surface.c diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index d9fbada1ff..199352cd70 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -31,20 +31,12 @@ #include "i915_state.h" #include "i915_batch.h" #include "i915_tex_layout.h" +#include "i915_reg.h" #include "pipe/draw/draw_context.h" #include "pipe/p_defines.h" #include "pipe/p_winsys.h" -#define PCI_CHIP_I915_G 0x2582 -#define PCI_CHIP_I915_GM 0x2592 -#define PCI_CHIP_I945_G 0x2772 -#define PCI_CHIP_I945_GM 0x27A2 -#define PCI_CHIP_I945_GME 0x27AE -#define PCI_CHIP_G33_G 0x29C2 -#define PCI_CHIP_Q35_G 0x29B2 -#define PCI_CHIP_Q33_G 0x29D2 - /** * Return list of supported surface/texture formats. @@ -190,8 +182,6 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys, struct i915_context *i915; unsigned is_i945 = 0; - /* TODO: Push this down into the pipe driver: - */ switch (pci_id) { case PCI_CHIP_I915_G: case PCI_CHIP_I915_GM: @@ -241,7 +231,10 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys, i915_init_surface_functions(i915); i915_init_state_functions(i915); i915_init_flush_functions(i915); + i915_init_string_functions(i915); + i915->pci_id = pci_id; + i915->flags.is_i945 = is_i945; if (i915->flags.is_i945) i915->pipe.mipmap_tree_layout = i945_miptree_layout; diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index 7a73a8d8d0..93b5e2546c 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -121,6 +121,7 @@ struct i915_context GLuint hardware_dirty; GLuint debug; + GLuint pci_id; struct { unsigned is_i945:1; @@ -188,6 +189,7 @@ void i915_init_region_functions( struct i915_context *i915 ); void i915_init_surface_functions( struct i915_context *i915 ); void i915_init_state_functions( struct i915_context *i915 ); void i915_init_flush_functions( struct i915_context *i915 ); +void i915_init_string_functions( struct i915_context *i915 ); diff --git a/src/mesa/pipe/i915simple/i915_reg.h b/src/mesa/pipe/i915simple/i915_reg.h index 0776b75ef9..f4070ef93e 100644 --- a/src/mesa/pipe/i915simple/i915_reg.h +++ b/src/mesa/pipe/i915simple/i915_reg.h @@ -961,5 +961,14 @@ #define BLENDFACT_INV_CONST_ALPHA 0x0f #define BLENDFACT_MASK 0x0f +#define PCI_CHIP_I915_G 0x2582 +#define PCI_CHIP_I915_GM 0x2592 +#define PCI_CHIP_I945_G 0x2772 +#define PCI_CHIP_I945_GM 0x27A2 +#define PCI_CHIP_I945_GME 0x27AE +#define PCI_CHIP_G33_G 0x29C2 +#define PCI_CHIP_Q35_G 0x29B2 +#define PCI_CHIP_Q33_G 0x29D2 + #endif diff --git a/src/mesa/pipe/i915simple/i915_strings.c b/src/mesa/pipe/i915simple/i915_strings.c new file mode 100644 index 0000000000..a9b0bfc7c2 --- /dev/null +++ b/src/mesa/pipe/i915simple/i915_strings.c @@ -0,0 +1,83 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "i915_context.h" +#include "i915_reg.h" + + +static const char *i915_get_vendor( struct pipe_context *pipe ) +{ + return "Tungsten Graphics, Inc."; +} + + +static const char *i915_get_name( struct pipe_context *pipe ) +{ + static char buffer[128]; + const char *chipset; + + switch (i915_context(pipe)->pci_id) { + case PCI_CHIP_I915_G: + chipset = "915G"; + break; + case PCI_CHIP_I915_GM: + chipset = "915GM"; + break; + case PCI_CHIP_I945_G: + chipset = "945G"; + break; + case PCI_CHIP_I945_GM: + chipset = "945GM"; + break; + case PCI_CHIP_I945_GME: + chipset = "945GME"; + break; + case PCI_CHIP_G33_G: + chipset = "G33"; + break; + case PCI_CHIP_Q35_G: + chipset = "Q35"; + break; + case PCI_CHIP_Q33_G: + chipset = "Q33"; + break; + default: + chipset = "unknown"; + break; + } + + snprintf(buffer, sizeof(buffer), "pipe/i915 (chipset: %s)", chipset); + return buffer; +} + + +void +i915_init_string_functions(struct i915_context *i915) +{ + i915->pipe.get_name = i915_get_name; + i915->pipe.get_vendor = i915_get_vendor; +} diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index b303cee5cc..84557b9a4a 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -51,12 +51,19 @@ struct pipe_context { */ const GLuint *(*supported_formats)(struct pipe_context *pipe, GLuint *numFormats); + void (*max_texture_size)(struct pipe_context *pipe, GLuint textureType, /* PIPE_TEXTURE_x */ GLuint *maxWidth, GLuint *maxHeight, GLuint *maxDepth); + const char *(*get_name)( struct pipe_context *pipe ); + + const char *(*get_vendor)( struct pipe_context *pipe ); + + + /* * Drawing */ diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index c455ebdbbe..b7495a205f 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -107,6 +107,10 @@ struct pipe_winsys { */ void (*wait_idle)( struct pipe_winsys *sws ); + /* Queries: + */ + const char *(*get_name)( struct pipe_winsys *sws ); + }; diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index b35bd66081..d67ad2c01d 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -224,6 +224,16 @@ static GLuint softpipe_get_occlusion_counter(struct pipe_context *pipe) return softpipe->occlusion_counter; } +static const char *softpipe_get_name( struct pipe_context *pipe ) +{ + return "softpipe"; +} + +static const char *softpipe_get_vendor( struct pipe_context *pipe ) +{ + return "Tungsten Graphics, Inc."; +} + struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, struct softpipe_winsys *softpipe_winsys ) @@ -259,6 +269,8 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.flush = softpipe_flush; softpipe->pipe.reset_occlusion_counter = softpipe_reset_occlusion_counter; softpipe->pipe.get_occlusion_counter = softpipe_get_occlusion_counter; + softpipe->pipe.get_name = softpipe_get_name; + softpipe->pipe.get_vendor = softpipe_get_vendor; /* textures */ softpipe->pipe.mipmap_tree_layout = softpipe_mipmap_tree_layout; diff --git a/src/mesa/sources b/src/mesa/sources index a2b9fed82b..c94cd3de26 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -199,6 +199,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_cb_fbo.c \ state_tracker/st_cb_program.c \ state_tracker/st_cb_readpixels.c \ + state_tracker/st_cb_strings.c \ state_tracker/st_cb_texture.c \ state_tracker/st_context.c \ state_tracker/st_draw.c \ diff --git a/src/mesa/state_tracker/st_cb_strings.c b/src/mesa/state_tracker/st_cb_strings.c new file mode 100644 index 0000000000..ac1a8b1422 --- /dev/null +++ b/src/mesa/state_tracker/st_cb_strings.c @@ -0,0 +1,86 @@ +/************************************************************************** + * + * 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 "main/glheader.h" +#include "main/macros.h" +#include "main/version.h" +#include "pipe/p_context.h" +#include "pipe/p_winsys.h" +#include "st_context.h" +#include "st_cb_strings.h" + +#define ST_VERSION_STRING "0.1" + +static const GLubyte * +st_get_string(GLcontext * ctx, GLenum name) +{ + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; + static char buffer[128]; + + + switch (name) { + case GL_VENDOR: { + const char *vendor = pipe->get_vendor( pipe ); + const char *tungsten = "Tungsten Graphics, Inc."; + + /* Tungsten developed the state_tracker module (and much of + * Mesa), but the driver itself may come from elsewhere. The + * additional string allows "and XyzCorp" to reflect this. + */ + if (vendor && strcmp(vendor, tungsten) != 0) + snprintf(buffer, sizeof(buffer), "%s and %s", tungsten, vendor); + else + snprintf(buffer, sizeof(buffer), "%s", tungsten); + + return (GLubyte *) buffer; + break; + } + + case GL_RENDERER: + snprintf(buffer, sizeof(buffer), "TG3D, %s on %s", + pipe->get_name( pipe ), + pipe->winsys->get_name( pipe->winsys )); + + return (GLubyte *) buffer; + + default: + return NULL; + } +} + + +void st_init_string_functions(struct dd_function_table *functions) +{ + functions->GetString = st_get_string; +} diff --git a/src/mesa/state_tracker/st_cb_strings.h b/src/mesa/state_tracker/st_cb_strings.h new file mode 100644 index 0000000000..3b765aaa59 --- /dev/null +++ b/src/mesa/state_tracker/st_cb_strings.h @@ -0,0 +1,38 @@ +/************************************************************************** + * + * 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_CB_STRINGS_H +#define ST_CB_STRINGS_H + + +extern void +st_init_string_functions(struct dd_function_table *functions); + + +#endif /* ST_CB_CLEAR_H */ + diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 2bdcc6caf3..7bb9cbda45 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -35,6 +35,7 @@ #include "st_cb_readpixels.h" #include "st_cb_texture.h" #include "st_cb_flush.h" +#include "st_cb_strings.h" #include "st_atom.h" #include "st_draw.h" #include "st_program.h" @@ -111,4 +112,5 @@ void st_init_driver_functions(struct dd_function_table *functions) st_init_readpixels_functions(functions); st_init_texture_functions(functions); st_init_flush_functions(functions); + st_init_string_functions(functions); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 88e2701fc3..8ce85cddaa 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -116,4 +116,6 @@ static INLINE struct st_context *st_context(GLcontext *ctx) extern void st_init_driver_functions(struct dd_function_table *functions); + + #endif -- cgit v1.2.3 From 8cc668a4a8d67af21af6883e18fe7423f28999f9 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 13 Aug 2007 15:20:08 -0600 Subject: fix some issues with texture/mipmap_tree state tracking --- src/mesa/state_tracker/st_atom_texture.c | 9 +++++---- src/mesa/state_tracker/st_cb_drawpixels.c | 4 ++-- src/mesa/state_tracker/st_context.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index eeaf68b001..bafd38695f 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -51,8 +51,8 @@ update_textures(struct st_context *st) for (u = 0; u < st->ctx->Const.MaxTextureImageUnits; u++) { struct gl_texture_object *texObj = st->ctx->Texture.Unit[u]._Current; + struct pipe_mipmap_tree *mt; if (texObj) { - struct pipe_mipmap_tree *mt; GLboolean flush, retval; retval = st_finalize_mipmap_tree(st->ctx, st->pipe, u, &flush); @@ -60,12 +60,13 @@ update_textures(struct st_context *st) retval, flush); mt = st_get_texobj_mipmap_tree(texObj); - - st->pipe->set_texture_state(st->pipe, u, mt); } else { - st->pipe->set_texture_state(st->pipe, u, NULL); + mt = NULL; } + + st->state.texture[u] = mt; + st->pipe->set_texture_state(st->pipe, u, mt); } } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index cdb9ebc3ff..7a89e853ee 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -315,8 +315,8 @@ 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); - /* XXX FIX: pipe->set_texture_state(pipe, unit, ???); */ - pipe->set_sampler_state(pipe, unit, &ctx->st->state.sampler[0]); + pipe->set_texture_state(pipe, unit, ctx->st->state.texture[unit]); + pipe->set_sampler_state(pipe, unit, &ctx->st->state.sampler[unit]); free_mipmap_tree(pipe, mt); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 8ce85cddaa..8d82d53133 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -79,6 +79,7 @@ struct st_context 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; } state; -- cgit v1.2.3 From 4698483f849ba8dfde20a5d649f1ea099291f241 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 13 Aug 2007 18:16:11 -0600 Subject: Added st_fb_orientation() function to determine the up/down orientation of the framebuffer. --- src/mesa/state_tracker/st_atom_viewport.c | 14 +++----------- src/mesa/state_tracker/st_cb_readpixels.c | 16 ++++++++++++---- src/mesa/state_tracker/st_context.h | 27 +++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 15 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c index 1307cbb6d2..a70f4c7434 100644 --- a/src/mesa/state_tracker/st_atom_viewport.c +++ b/src/mesa/state_tracker/st_atom_viewport.c @@ -39,27 +39,19 @@ * - depthrange * - window pos/size or FBO size */ -static void update_viewport( struct st_context *st ) +static void +update_viewport( struct st_context *st ) { GLcontext *ctx = st->ctx; GLfloat yScale, yBias; - /* Negate Y scale to flip image vertically. - * The NDC Y coords prior to viewport transformation are in the range - * [y=-1=bottom, y=1=top] - * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where H - * is the window height. - * Use the viewport transformation to invert Y. - */ - /* _NEW_BUFFERS */ - if (ctx->DrawBuffer) { + if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { yScale = -1; yBias = ctx->DrawBuffer->Height ; } else { - /* we won't be rendering anything */ yScale = 1.0; yBias = 0.0; } diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 22abc104e2..98604e5b6b 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -60,7 +60,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, struct pipe_context *pipe = ctx->st->pipe; GLfloat temp[MAX_WIDTH][4]; const GLbitfield transferOps = ctx->_ImageTransferState; - GLint i, yInv, dfStride; + GLint i, yStep, dfStride; GLfloat *df; struct st_renderbuffer *strb; struct gl_pixelstore_attrib clippedPacking = *pack; @@ -104,11 +104,19 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, dfStride = 0; } + /* determine bottom-to-top vs. top-to-bottom order */ + if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { + y = strb->Base.Height - 1 - y; + yStep = -1; + } + else { + yStep = 1; + } + /* Do a row at a time to flip image data vertically */ - yInv = strb->Base.Height - 1 - y; for (i = 0; i < height; i++) { - strb->surface->get_tile(strb->surface, x, yInv, width, 1, df); - yInv--; + strb->surface->get_tile(strb->surface, x, y, width, 1, df); + y += yStep; df += dfStride; if (!dfStride) { /* convert GLfloat to user's format/type */ diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 8d82d53133..13843d9b7f 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -118,5 +118,32 @@ extern void st_init_driver_functions(struct dd_function_table *functions); +#define Y_0_TOP 1 +#define Y_0_BOTTOM 2 + +static INLINE GLuint +st_fb_orientation(const struct gl_framebuffer *fb) +{ + if (fb && fb->Name == 0) { + /* Drawing into a window (on-screen buffer). + * + * Negate Y scale to flip image vertically. + * The NDC Y coords prior to viewport transformation are in the range + * [y=-1=bottom, y=1=top] + * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where + * H is the window height. + * Use the viewport transformation to invert Y. + */ + return Y_0_TOP; + } + else { + /* Drawing into user-created FBO (very likely a texture). + * + * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering. + */ + return Y_0_BOTTOM; + } +} + #endif -- 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_context.h') 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 1f026d98dd77b6d26cc76946d92f69a9e6091b8e Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 18 Aug 2007 16:05:49 +0100 Subject: Create a default vertex attribute buffer which mirrors ctx->Current.Attrrib[] Used when the vertex shader references attributes which aren't present in VBOs. --- src/mesa/state_tracker/st_context.h | 2 + src/mesa/state_tracker/st_draw.c | 113 +++++++++++++++++++++++++++--------- 2 files changed, 88 insertions(+), 27 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 25ed20a5f8..35774a790e 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -104,6 +104,8 @@ struct st_context struct st_state_flags dirty; GLfloat polygon_offset_scale; /* ?? */ + + struct pipe_buffer_handle *default_attrib_buffer; }; diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 425076d653..db24b24fa7 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -44,6 +44,7 @@ #include "st_cb_bufferobjects.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_winsys.h" #include "vbo/vbo_context.h" @@ -52,7 +53,7 @@ * bypassing the T&L module. This only works with VBO-based demos, * such as progs/test/bufferobj.c */ -#define USE_NEW_DRAW 0 +#define USE_NEW_DRAW 01 /* @@ -134,6 +135,38 @@ pipe_vertex_format(GLenum format, GLuint size) +/** + * The default attribute buffer is basically a copy of the + * ctx->Current.Attrib[] array. It's used when the vertex program + * references an attribute for which we don't have a VBO/array. + */ +static void +create_default_attribs_buffer(struct st_context *st) +{ + struct pipe_context *pipe = st->pipe; + st->default_attrib_buffer = pipe->winsys->buffer_create( pipe->winsys, 32 ); +} + + +static void +destroy_default_attribs_buffer(struct st_context *st) +{ + struct pipe_context *pipe = st->pipe; + pipe->winsys->buffer_unreference(pipe->winsys, &st->default_attrib_buffer); +} + + +static void +update_default_attribs_buffer(GLcontext *ctx) +{ + struct pipe_context *pipe = ctx->st->pipe; + struct pipe_buffer_handle *buf = ctx->st->default_attrib_buffer; + const unsigned size = sizeof(ctx->Current.Attrib); + const void *data = ctx->Current.Attrib; + pipe->winsys->buffer_data(pipe->winsys, buf, size, data); +} + + /** * This function gets plugged into the VBO module and is called when * we have something to render. @@ -150,41 +183,66 @@ draw_vbo(GLcontext *ctx, { struct pipe_context *pipe = ctx->st->pipe; GLuint attr, i; + GLbitfield attrsNeeded; + const unsigned attr0_offset = (unsigned) arrays[0]->Ptr; st_validate_state(ctx->st); + update_default_attribs_buffer(ctx); + /* this must be after state validation */ + attrsNeeded = ctx->st->state.vs.inputs_read; /* tell pipe about the vertex array element/attributes */ for (attr = 0; attr < 16; attr++) { - struct gl_buffer_object *bufobj = arrays[attr]->BufferObj; struct pipe_vertex_buffer vbuffer; struct pipe_vertex_element velement; - if (bufobj && bufobj->Name) { - struct st_buffer_object *stobj = st_buffer_object(bufobj); - - assert(stobj->buffer); - - vbuffer.pitch = arrays[attr]->StrideB; /* in bytes */ - vbuffer.max_index = 0; - vbuffer.buffer = stobj->buffer; - vbuffer.buffer_offset = 0; - - /* Recall that for VBOs, the gl_client_array->Ptr field is - * really an offset from the start of the VBO, not a pointer. - */ - velement.src_offset = (unsigned) arrays[attr]->Ptr; - velement.vertex_buffer_index = attr; - velement.dst_offset = 0; - velement.src_format = pipe_vertex_format(arrays[attr]->Type, - arrays[attr]->Size); + vbuffer.buffer = NULL; + vbuffer.pitch = 0; + velement.src_offset = 0; + velement.vertex_buffer_index = 0; + velement.src_format = 0; + + if (attrsNeeded & (1 << attr)) { + struct gl_buffer_object *bufobj = arrays[attr]->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[attr]->Ptr; + + assert(stobj->buffer); + + vbuffer.buffer = stobj->buffer; + vbuffer.buffer_offset = attr0_offset; /* in bytes */ + vbuffer.pitch = arrays[attr]->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[attr]->Type, + arrays[attr]->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; + } } - else { - /* vertex attribute data is not an a real buffer! */ - /* XXX we'll want to handle that someday... */ - vbuffer.buffer = NULL; - } + if (attr == 0) + assert(vbuffer.buffer); pipe->set_vertex_buffer(pipe, attr, &vbuffer); pipe->set_vertex_element(pipe, attr, &velement); @@ -209,6 +267,8 @@ void st_init_draw( struct st_context *st ) #if USE_NEW_DRAW struct vbo_context *vbo = (struct vbo_context *) ctx->swtnl_im; + create_default_attribs_buffer(st); + assert(vbo); assert(vbo->draw_prims); vbo->draw_prims = draw_vbo; @@ -224,8 +284,7 @@ void st_init_draw( struct st_context *st ) void st_destroy_draw( struct st_context *st ) { - /* Nothing to do. - */ + destroy_default_attribs_buffer(st); } -- 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_context.h') 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 fa8cbc45e883762f3c3f1f11497a035c217f8d65 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 22 Aug 2007 18:35:50 -0600 Subject: Need to store vendor and renderer strings in the context. As it was, we always returned the same pointer. So glxinfo, which calls glGetString() before printing anything, was printing the same string for both vendor and renderer. --- src/mesa/state_tracker/st_cb_strings.c | 14 ++++++-------- src/mesa/state_tracker/st_context.h | 3 +++ 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_cb_strings.c b/src/mesa/state_tracker/st_cb_strings.c index ac1a8b1422..776f518e2b 100644 --- a/src/mesa/state_tracker/st_cb_strings.c +++ b/src/mesa/state_tracker/st_cb_strings.c @@ -46,8 +46,6 @@ st_get_string(GLcontext * ctx, GLenum name) { struct st_context *st = st_context(ctx); struct pipe_context *pipe = st->pipe; - static char buffer[128]; - switch (name) { case GL_VENDOR: { @@ -59,20 +57,20 @@ st_get_string(GLcontext * ctx, GLenum name) * additional string allows "and XyzCorp" to reflect this. */ if (vendor && strcmp(vendor, tungsten) != 0) - snprintf(buffer, sizeof(buffer), "%s and %s", tungsten, vendor); + snprintf(st->vendor, sizeof(st->vendor), + "%s and %s", tungsten, vendor); else - snprintf(buffer, sizeof(buffer), "%s", tungsten); + snprintf(st->vendor, sizeof(st->vendor), "%s", tungsten); - return (GLubyte *) buffer; - break; + return (GLubyte *) st->vendor; } case GL_RENDERER: - snprintf(buffer, sizeof(buffer), "TG3D, %s on %s", + snprintf(st->renderer, sizeof(st->renderer), "TG3D, %s on %s", pipe->get_name( pipe ), pipe->winsys->get_name( pipe->winsys )); - return (GLubyte *) buffer; + return (GLubyte *) st->renderer; default: return NULL; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 38d6a3ed86..13ea28237c 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -97,6 +97,9 @@ struct st_context GLuint frontbuffer_dirty:1; } flags; + char vendor[100]; + char renderer[100]; + /* State to be validated: */ struct st_tracked_state **atoms; -- cgit v1.2.3 From 07d97e80e616d9fdc437d3b41055c347d5c54932 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 24 Aug 2007 18:30:00 +0100 Subject: checkpoint in constant tracking rework --- src/mesa/sources | 6 +- src/mesa/state_tracker/st_atom.c | 51 ++++++++++---- src/mesa/state_tracker/st_atom.h | 3 +- src/mesa/state_tracker/st_atom_cbuf.c | 72 ------------------- src/mesa/state_tracker/st_atom_fs.c | 84 ++++++++-------------- src/mesa/state_tracker/st_atom_vs.c | 124 ++++++++++----------------------- src/mesa/state_tracker/st_cb_program.c | 16 ++++- src/mesa/state_tracker/st_context.h | 5 +- src/mesa/state_tracker/st_program.h | 20 +----- src/mesa/tnl/t_vp_build.h | 7 ++ 10 files changed, 134 insertions(+), 254 deletions(-) delete mode 100644 src/mesa/state_tracker/st_atom_cbuf.c (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/sources b/src/mesa/sources index 61a8d580ad..53969774f9 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -186,10 +186,11 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_blend.c \ state_tracker/st_atom_clear_color.c \ state_tracker/st_atom_clip.c \ + state_tracker/st_atom_constbuf.c \ state_tracker/st_atom_depth.c \ - state_tracker/st_atom_fs.c \ - state_tracker/st_atom_vs.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_setup.c \ @@ -197,6 +198,7 @@ STATETRACKER_SOURCES = \ 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 \ diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index d67291e50b..99fcbdfda7 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -29,8 +29,10 @@ #include "glheader.h" #include "context.h" +#include "pipe/p_defines.h" #include "st_context.h" #include "st_atom.h" +#include "st_program.h" @@ -46,9 +48,11 @@ static const struct st_tracked_state *atoms[] = &st_update_clear_color, &st_update_depth, &st_update_clip, + &st_update_tnl, &st_update_vs, &st_update_fs, + &st_update_setup, &st_update_polygon_stipple, &st_update_viewport, @@ -57,8 +61,8 @@ static const struct st_tracked_state *atoms[] = &st_update_stencil, &st_update_sampler, &st_update_texture, - /* will be patched out at runtime */ -/* &st_update_constants */ + &st_update_vs_constants, + &st_update_fs_constants, }; @@ -72,13 +76,17 @@ void st_init_atoms( struct st_context *st ) /* Patch in a pointer to the dynamic state atom: */ - for (i = 0; i < st->nr_atoms; i++) - if (st->atoms[i] == &st_update_constants) - st->atoms[i] = &st->constants.tracked_state; + for (i = 0; i < st->nr_atoms; i++) { + if (st->atoms[i] == &st_update_vs_constants) { + st->atoms[i] = &st->constants.tracked_state[PIPE_SHADER_VERTEX]; + st->atoms[i][0] = st_update_vs_constants; + } - memcpy(&st->constants.tracked_state, - &st_update_constants, - sizeof(st_update_constants)); + if (st->atoms[i] == &st_update_fs_constants) { + st->atoms[i] = &st->constants.tracked_state[PIPE_SHADER_FRAGMENT]; + st->atoms[i][0] = st_update_fs_constants; + } + } } @@ -118,6 +126,21 @@ static void xor_states( struct st_state_flags *result, } +/* Too complex to figure out, just check every time: + */ +static void check_program_state( struct st_context *st ) +{ + GLcontext *ctx = st->ctx; + + if (ctx->VertexProgram._Current != &st->vp->Base) + st->dirty.st |= ST_NEW_VERTEX_PROGRAM; + + if (ctx->FragmentProgram._Current != &st->fp->Base) + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; + +} + + /*********************************************************************** * Update all derived state: */ @@ -127,6 +150,8 @@ void st_validate_state( struct st_context *st ) struct st_state_flags *state = &st->dirty; GLuint i; + check_program_state( st ); + if (state->st == 0) return; @@ -142,10 +167,12 @@ void st_validate_state( struct st_context *st ) for (i = 0; i < st->nr_atoms; i++) { const struct st_tracked_state *atom = st->atoms[i]; struct st_state_flags generated; - - assert(atom->dirty.mesa || - atom->dirty.st); - assert(atom->update); + + if (!(atom->dirty.mesa || atom->dirty.st) || + !atom->update) { + _mesa_printf("malformed atom %d\n", i); + assert(0); + } if (check_state(state, &atom->dirty)) { st->atoms[i]->update( st ); diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 51da489f6d..447430bfef 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -54,12 +54,13 @@ const struct st_tracked_state st_update_vs; const struct st_tracked_state st_update_setup; const struct st_tracked_state st_update_polygon_stipple; const struct st_tracked_state st_update_viewport; -const struct st_tracked_state st_update_constants; 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; +const struct st_tracked_state st_update_vs_constants; #endif diff --git a/src/mesa/state_tracker/st_atom_cbuf.c b/src/mesa/state_tracker/st_atom_cbuf.c deleted file mode 100644 index 0f90aa7646..0000000000 --- a/src/mesa/state_tracker/st_atom_cbuf.c +++ /dev/null @@ -1,72 +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 - */ - -#include "st_context.h" -#include "pipe/p_context.h" -#include "st_atom.h" - -extern GLboolean xmesa_get_cbuf_details( GLcontext *ctx, - void **ptr, - GLuint *cpp, - GLint *stride, - GLuint *format ); - - -/* This is a hack to work with the X11 driver as a test harness - */ -static void update_cbuf_state( struct st_context *st ) -{ - struct pipe_surface cbuf; - GLboolean ok; - - ok = xmesa_get_cbuf_details( st->ctx, - (void **)&cbuf.ptr, - &cbuf.cpp, - &cbuf.stride, - &cbuf.format ); - - assert(ok); - - if (memcmp(&cbuf, &st->state.cbuf, sizeof(cbuf)) != 0) { - st->state.cbuf = cbuf; - st->pipe->set_cbuf_state( st->pipe, &cbuf ); - } -} - -const struct st_tracked_state st_update_cbuf = { - .dirty = { - .mesa = _NEW_BUFFERS, - .st = 0, - }, - .update = update_cbuf_state -}; - diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index a164ded184..f706761198 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -43,92 +43,64 @@ #define TGSI_DEBUG 0 -static void compile_fs( struct st_context *st, - struct st_fragment_program *fs ) +static void compile_fs( struct st_context *st ) { + struct st_fragment_program *fp = st->fp; + /* XXX: fix static allocation of tokens: */ - tgsi_mesa_compile_fp_program( &fs->Base, fs->tokens, ST_FP_MAX_TOKENS ); - - if (TGSI_DEBUG) - tgsi_dump( fs->tokens, TGSI_DUMP_VERBOSE ); -} - - -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]; + tgsi_mesa_compile_fp_program( &fp->Base, fp->tokens, ST_FP_MAX_TOKENS ); - if (!cbuf->buffer) - cbuf->buffer = ws->buffer_create(ws, 1); + fp->fs.inputs_read + = tgsi_mesa_translate_vertex_input_mask(fp->Base.Base.InputsRead); + fp->fs.outputs_written + = tgsi_mesa_translate_vertex_output_mask(fp->Base.Base.OutputsWritten); + fp->fs.tokens = &fp->tokens[0]; - /* load Mesa constants into the constant buffer */ - if (paramBytes) - ws->buffer_data(ws, cbuf->buffer, paramBytes, params->ParameterValues); - - cbuf->size = paramBytes; + if (TGSI_DEBUG) + tgsi_dump( fp->tokens, TGSI_DUMP_VERBOSE ); - st->pipe->set_constant_buffer(st->pipe, PIPE_SHADER_FRAGMENT, 0, cbuf); + fp->dirty = 0; } + 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 */ + /* find active shader and params. Changes to this Mesa state + * should be covered by ST_NEW_FRAGMENT_PROGRAM, thanks to the + * logic in st_cb_program.c + */ if (st->ctx->Shader.CurrentProgram && st->ctx->Shader.CurrentProgram->LinkStatus && st->ctx->Shader.CurrentProgram->FragmentProgram) { struct gl_fragment_program *f = st->ctx->Shader.CurrentProgram->FragmentProgram; fp = st_fragment_program(f); - params = f->Base.Parameters; } - else if (st->ctx->FragmentProgram._Current) { + else { + assert(st->ctx->FragmentProgram._Current); fp = st_fragment_program(st->ctx->FragmentProgram._Current); - params = st->ctx->FragmentProgram._Current->Base.Parameters; - } - - /* update constants */ - if (fp && params) { - _mesa_load_state_parameters(st->ctx, params); - 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 - = 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 || - fp->dirty) - { - fp->dirty = 0; - st->state.fs = fs; - st->pipe->set_fs_state(st->pipe, &fs); + if (st->fp != fp || fp->dirty) { + st->fp = fp; + + if (fp->dirty) + compile_fs( st ); + + st->state.fs = fp->fs; + st->pipe->set_fs_state(st->pipe, &st->state.fs); } } const struct st_tracked_state st_update_fs = { .dirty = { - .mesa = _NEW_PROGRAM, + .mesa = 0, .st = ST_NEW_FRAGMENT_PROGRAM, }, .update = update_fs diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index b2d25fa993..ab7e2ae4be 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -45,108 +45,79 @@ #include "st_program.h" -#define TGSI_DEBUG 0 +#define TGSI_DEBUG 1 -static void compile_vs( struct st_context *st, - struct st_vertex_program *vs ) + + + +/* translate shader to TGSI format +*/ +static void compile_vs( struct st_context *st ) { + struct st_vertex_program *vp = st->vp; + /* XXX: fix static allocation of tokens: */ - tgsi_mesa_compile_vp_program( &vs->Base, vs->tokens, ST_FP_MAX_TOKENS ); + tgsi_mesa_compile_vp_program( &vp->Base, vp->tokens, ST_FP_MAX_TOKENS ); + + vp->vs.inputs_read + = tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead); + vp->vs.outputs_written + = tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten); + vp->vs.tokens = &vp->tokens[0]; if (TGSI_DEBUG) - tgsi_dump( vs->tokens, TGSI_DUMP_VERBOSE ); + tgsi_dump( vp->tokens, 0 ); #if defined(USE_X86_ASM) || defined(SLANG_X86) tgsi_emit_sse2( - vs->tokens, - &vs->sse2_program ); + vp->vs.tokens, + &vp->vs.sse2_program ); #endif -} - - -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); + vp->dirty = 0; } + 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; + struct st_vertex_program *vp; - /* find active shader and params */ + /* find active shader and params -- Should be covered by + * ST_NEW_VERTEX_PROGRAM + */ 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) { + else { + assert(st->ctx->VertexProgram._Current); vp = st_vertex_program(st->ctx->VertexProgram._Current); - params = st->ctx->VertexProgram._Current->Base.Parameters; } - /* update constants */ - if (vp && params) { - _mesa_load_state_parameters(st->ctx, params); - /*_mesa_print_parameter_list(params);*/ - update_vs_constants(st, params); - } + if (st->vp != vp || vp->dirty) { + st->vp = vp; - /* translate shader to TGSI format */ - if (vp->dirty) - compile_vs( st, vp ); - - /* update pipe state */ - memset( &vs, 0, sizeof(vs) ); - vs.inputs_read - = tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead); - vs.outputs_written - = tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten); - vs.tokens = &vp->tokens[0]; + if (vp->dirty) + compile_vs( st ); #if defined(USE_X86_ASM) || defined(SLANG_X86) - vs.executable = (void *) x86_get_func( &vp->sse2_program ); + vs.executable = (void *) x86_get_func( &vp->sse2_program ); #endif - 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); + st->state.vs = st->vp->vs; + st->pipe->set_vs_state(st->pipe, &st->state.vs); } } const struct st_tracked_state st_update_vs = { .dirty = { - .mesa = (_NEW_PROGRAM | - _NEW_MODELVIEW | - _NEW_PROJECTION | - _NEW_LIGHT), /*XXX MORE?*/ + .mesa = 0, .st = ST_NEW_VERTEX_PROGRAM, }, .update = update_vs @@ -155,28 +126,3 @@ const struct st_tracked_state st_update_vs = { - -/** - * When TnL state has changed, need to generate new vertex program. - * This should be done before updating the vertes shader (vs) state. - */ -static void update_tnl( struct st_context *st ) -{ - uint before = st->ctx->NewState; - if (st->ctx->VertexProgram._MaintainTnlProgram) - _tnl_UpdateFixedFunctionProgram( st->ctx ); - assert(before == st->ctx->NewState); -} - - -const struct st_tracked_state st_update_tnl = { - .dirty = { - .mesa = (_NEW_PROGRAM | - _NEW_LIGHT | - _NEW_TEXTURE | - _NEW_TRANSFORM | - _NEW_LIGHT), /* XXX more? */ - .st = 0 - }, - .update = update_tnl -}; diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index b84f552404..b9c19bdd3e 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -64,6 +64,17 @@ static void st_bind_program( GLcontext *ctx, } } +static void st_use_program( GLcontext *ctx, + GLuint program ) +{ + struct st_context *st = st_context(ctx); + + st->dirty.st |= ST_NEW_VERTEX_PROGRAM; + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; +} + + + static struct gl_program *st_new_program( GLcontext *ctx, GLenum target, GLuint id ) @@ -132,6 +143,7 @@ static GLboolean st_is_program_native( GLcontext *ctx, return GL_TRUE; } + static void st_program_string_notify( GLcontext *ctx, GLenum target, struct gl_program *prog ) @@ -166,10 +178,8 @@ static void st_program_string_notify( GLcontext *ctx, void st_init_program_functions(struct dd_function_table *functions) { -#if 0 - assert(functions->ProgramStringNotify == _tnl_program_string); -#endif functions->BindProgram = st_bind_program; + functions->UseProgram = st_use_program; functions->NewProgram = st_new_program; functions->DeleteProgram = st_delete_program; functions->IsProgramNative = st_is_program_native; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 13ea28237c..9e8015d4c7 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -86,7 +86,7 @@ struct st_context } state; struct { - struct st_tracked_state tracked_state; + struct st_tracked_state tracked_state[2]; } constants; struct { @@ -109,6 +109,9 @@ struct st_context GLfloat polygon_offset_scale; /* ?? */ + struct st_vertex_program *vp; + struct st_fragment_program *fp; + struct pipe_buffer_handle *default_attrib_buffer; }; diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 883953399c..7a91983ce9 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -54,21 +54,7 @@ struct st_fragment_program struct tgsi_token tokens[ST_FP_MAX_TOKENS]; GLboolean dirty; -#if 0 - GLfloat (*cbuffer)[4]; - GLuint nr_constants; - - /* Translate all the parameters, etc, into a constant buffer which - * we update on state changes. - */ - struct - { - GLuint reg; /* Constant idx */ - const GLfloat *values; /* Pointer to tracked values */ - } *param; - GLuint nr_params; -#endif - + struct pipe_shader_state fs; GLuint param_state; }; @@ -89,9 +75,7 @@ struct st_vertex_program struct x86_function sse2_program; #endif -#if 0 - struct pipe_constant_buffer constants; -#endif + struct pipe_shader_state vs; GLuint param_state; }; diff --git a/src/mesa/tnl/t_vp_build.h b/src/mesa/tnl/t_vp_build.h index 4a98fff026..5e22fcf8c4 100644 --- a/src/mesa/tnl/t_vp_build.h +++ b/src/mesa/tnl/t_vp_build.h @@ -28,6 +28,13 @@ #include "mtypes.h" +#define TNL_FIXED_FUNCTION_STATE_FLAGS (_NEW_PROGRAM | \ + _NEW_LIGHT | \ + _NEW_TEXTURE | \ + _NEW_TRANSFORM | \ + _NEW_FOG | \ + _NEW_POINT) + extern void _tnl_UpdateFixedFunctionProgram( GLcontext *ctx ); extern void _tnl_ProgramCacheInit( GLcontext *ctx ); -- cgit v1.2.3 From 4185da4681405f3cc4d0cc601d428f2f44d0dda8 Mon Sep 17 00:00:00 2001 From: keithw Date: Sat, 25 Aug 2007 22:00:36 +0100 Subject: add names to tracked state atoms to improve debug --- src/mesa/state_tracker/st_atom.c | 9 ++++++++- src/mesa/state_tracker/st_atom_alphatest.c | 1 + src/mesa/state_tracker/st_atom_blend.c | 1 + src/mesa/state_tracker/st_atom_clear_color.c | 1 + src/mesa/state_tracker/st_atom_clip.c | 1 + src/mesa/state_tracker/st_atom_depth.c | 1 + src/mesa/state_tracker/st_atom_framebuffer.c | 1 + src/mesa/state_tracker/st_atom_fs.c | 1 + src/mesa/state_tracker/st_atom_sampler.c | 1 + src/mesa/state_tracker/st_atom_scissor.c | 1 + src/mesa/state_tracker/st_atom_setup.c | 1 + src/mesa/state_tracker/st_atom_stencil.c | 1 + src/mesa/state_tracker/st_atom_stipple.c | 1 + src/mesa/state_tracker/st_atom_texture.c | 1 + src/mesa/state_tracker/st_atom_viewport.c | 1 + src/mesa/state_tracker/st_atom_vs.c | 1 + src/mesa/state_tracker/st_context.h | 1 + 17 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 99fcbdfda7..66ab5d7c3a 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -155,6 +155,8 @@ void st_validate_state( struct st_context *st ) if (state->st == 0) return; +// _mesa_printf("%s %x/%x\n", __FUNCTION__, state->mesa, state->st); + if (1) { /* Debug version which enforces various sanity checks on the * state flags which are generated and checked to help ensure @@ -168,14 +170,17 @@ void st_validate_state( struct st_context *st ) const struct st_tracked_state *atom = st->atoms[i]; struct st_state_flags generated; +// _mesa_printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st); + if (!(atom->dirty.mesa || atom->dirty.st) || !atom->update) { - _mesa_printf("malformed atom %d\n", i); + _mesa_printf("malformed atom %s\n", atom->name); assert(0); } if (check_state(state, &atom->dirty)) { st->atoms[i]->update( st ); +// _mesa_printf("after: %x\n", atom->dirty.mesa); } accumulate_state(&examined, &atom->dirty); @@ -188,6 +193,8 @@ void st_validate_state( struct st_context *st ) assert(!check_state(&examined, &generated)); prev = *state; } +// _mesa_printf("\n"); + } else { const GLuint nr = st->nr_atoms; diff --git a/src/mesa/state_tracker/st_atom_alphatest.c b/src/mesa/state_tracker/st_atom_alphatest.c index 1e2e449795..4378154053 100644 --- a/src/mesa/state_tracker/st_atom_alphatest.c +++ b/src/mesa/state_tracker/st_atom_alphatest.c @@ -81,6 +81,7 @@ update_alpha_test( struct st_context *st ) const struct st_tracked_state st_update_alpha_test = { + .name = "st_update_alpha_test", .dirty = { .mesa = (_NEW_COLOR), .st = 0, diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c index 256f13471a..afd21a6141 100644 --- a/src/mesa/state_tracker/st_atom_blend.c +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -227,6 +227,7 @@ 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, diff --git a/src/mesa/state_tracker/st_atom_clear_color.c b/src/mesa/state_tracker/st_atom_clear_color.c index adf730cd8c..ce3431c5d3 100644 --- a/src/mesa/state_tracker/st_atom_clear_color.c +++ b/src/mesa/state_tracker/st_atom_clear_color.c @@ -54,6 +54,7 @@ update_clear_color_state( struct st_context *st ) const struct st_tracked_state st_update_clear_color = { + .name = "st_update_clear_color", .dirty = { .mesa = _NEW_COLOR, .st = 0, diff --git a/src/mesa/state_tracker/st_atom_clip.c b/src/mesa/state_tracker/st_atom_clip.c index 8ccad637d5..a6f0568660 100644 --- a/src/mesa/state_tracker/st_atom_clip.c +++ b/src/mesa/state_tracker/st_atom_clip.c @@ -62,6 +62,7 @@ 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, diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index 7fc51953dc..df05c79e36 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -84,6 +84,7 @@ update_depth( struct st_context *st ) const struct st_tracked_state st_update_depth = { + .name = "st_update_depth", .dirty = { .mesa = (_NEW_DEPTH), .st = 0, diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index f054eb8f21..3c4b37e7c5 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -82,6 +82,7 @@ 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, diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index f706761198..767816bf23 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -99,6 +99,7 @@ static void update_fs( struct st_context *st ) const struct st_tracked_state st_update_fs = { + .name = "st_update_fs", .dirty = { .mesa = 0, .st = ST_NEW_FRAGMENT_PROGRAM, diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 7d568baf9e..d65565f991 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -152,6 +152,7 @@ update_samplers(struct st_context *st) const struct st_tracked_state st_update_sampler = { + .name = "st_update_sampler", .dirty = { .mesa = _NEW_TEXTURE, .st = 0, diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c index 2bf633828e..59601e91a1 100644 --- a/src/mesa/state_tracker/st_atom_scissor.c +++ b/src/mesa/state_tracker/st_atom_scissor.c @@ -83,6 +83,7 @@ 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, diff --git a/src/mesa/state_tracker/st_atom_setup.c b/src/mesa/state_tracker/st_atom_setup.c index 3eac2588df..09d921560d 100644 --- a/src/mesa/state_tracker/st_atom_setup.c +++ b/src/mesa/state_tracker/st_atom_setup.c @@ -211,6 +211,7 @@ static void update_setup_state( struct st_context *st ) } const struct st_tracked_state st_update_setup = { + .name = "st_update_setup", .dirty = { .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_LINE | _NEW_SCISSOR | _NEW_POINT | _NEW_BUFFERS | _NEW_MULTISAMPLE), diff --git a/src/mesa/state_tracker/st_atom_stencil.c b/src/mesa/state_tracker/st_atom_stencil.c index d037335e9e..b8aec0b3b6 100644 --- a/src/mesa/state_tracker/st_atom_stencil.c +++ b/src/mesa/state_tracker/st_atom_stencil.c @@ -127,6 +127,7 @@ update_stencil( struct st_context *st ) const struct st_tracked_state st_update_stencil = { + .name = "st_update_stencil", .dirty = { .mesa = (_NEW_STENCIL), .st = 0, diff --git a/src/mesa/state_tracker/st_atom_stipple.c b/src/mesa/state_tracker/st_atom_stipple.c index dd04d2158c..c91214059a 100644 --- a/src/mesa/state_tracker/st_atom_stipple.c +++ b/src/mesa/state_tracker/st_atom_stipple.c @@ -54,6 +54,7 @@ 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, diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index bafd38695f..7970bcf2b8 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -72,6 +72,7 @@ update_textures(struct st_context *st) const struct st_tracked_state st_update_texture = { + .name = "st_update_texture", .dirty = { .mesa = _NEW_TEXTURE, .st = 0, diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c index a70f4c7434..147aa3c51a 100644 --- a/src/mesa/state_tracker/st_atom_viewport.c +++ b/src/mesa/state_tracker/st_atom_viewport.c @@ -86,6 +86,7 @@ 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, diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index ab7e2ae4be..a1e6117bde 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -116,6 +116,7 @@ static void update_vs( struct st_context *st ) const struct st_tracked_state st_update_vs = { + .name = "st_update_vs", .dirty = { .mesa = 0, .st = ST_NEW_VERTEX_PROGRAM, diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 9e8015d4c7..cb34994d77 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -48,6 +48,7 @@ struct st_state_flags { }; struct st_tracked_state { + const char *name; struct st_state_flags dirty; void (*update)( struct st_context *st ); }; -- cgit v1.2.3 From bee148cb7d5c974a1b5534a0307b2c082eea27e2 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 10 Sep 2007 16:28:27 -0600 Subject: plug in rasterpos/feedback code --- src/mesa/state_tracker/st_context.c | 2 ++ src/mesa/state_tracker/st_context.h | 1 + 2 files changed, 3 insertions(+) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 42263cab64..e66e65e2dd 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -34,6 +34,7 @@ #include "st_cb_drawpixels.h" #include "st_cb_fbo.h" #include "st_cb_queryobj.h" +#include "st_cb_rasterpos.h" #include "st_cb_readpixels.h" #include "st_cb_texture.h" #include "st_cb_flush.h" @@ -121,6 +122,7 @@ void st_init_driver_functions(struct dd_function_table *functions) st_init_fbo_functions(functions); st_init_program_functions(functions); st_init_query_functions(functions); + st_init_rasterpos_functions(functions); st_init_readpixels_functions(functions); st_init_texture_functions(functions); st_init_flush_functions(functions); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index cb34994d77..98b78af7c5 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -74,6 +74,7 @@ struct st_context 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]; struct pipe_poly_stipple poly_stipple; -- cgit v1.2.3 From b4bacd1fca336f043d1ee3c3a346fbd42a3b02eb Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 17 Sep 2007 14:24:11 -0600 Subject: Plug in selection/feedback code. Not quite finished yet. Selection/feedback are done with a private instance of the 'draw' module in the state tracker. Not quite all the draw context's state is set yet, namely vertex format info. Hold off on that for a bit... --- src/mesa/sources | 1 + src/mesa/state_tracker/st_context.c | 6 ++ src/mesa/state_tracker/st_context.h | 7 ++ src/mesa/state_tracker/st_draw.c | 180 ++++++++++++++++++++++++++++++++++-- src/mesa/state_tracker/st_draw.h | 20 ++++ 5 files changed, 205 insertions(+), 9 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/sources b/src/mesa/sources index a672ad2fcf..ec561294c5 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -210,6 +210,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_cb_flush.c \ state_tracker/st_cb_drawpixels.c \ state_tracker/st_cb_fbo.c \ + state_tracker/st_cb_feedback.c \ state_tracker/st_cb_program.c \ state_tracker/st_cb_queryobj.c \ state_tracker/st_cb_rasterpos.c \ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index e66e65e2dd..6ab643f1fe 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -33,6 +33,7 @@ #include "st_cb_clear.h" #include "st_cb_drawpixels.h" #include "st_cb_fbo.h" +#include "st_cb_feedback.h" #include "st_cb_queryobj.h" #include "st_cb_rasterpos.h" #include "st_cb_readpixels.h" @@ -43,6 +44,7 @@ #include "st_draw.h" #include "st_program.h" #include "pipe/p_context.h" +#include "pipe/draw/draw_context.h" void st_invalidate_state(GLcontext * ctx, GLuint new_state) @@ -64,6 +66,8 @@ struct st_context *st_create_context( GLcontext *ctx, st->ctx = ctx; st->pipe = pipe; + st->draw = draw_create(); /* for selection/feedback */ + st->dirty.mesa = ~0; st->dirty.st = ~0; @@ -97,6 +101,7 @@ struct st_context *st_create_context( GLcontext *ctx, void st_destroy_context( struct st_context *st ) { + draw_destroy(st->draw); st_destroy_atoms( st ); st_destroy_draw( st ); @@ -120,6 +125,7 @@ void st_init_driver_functions(struct dd_function_table *functions) st_init_clear_functions(functions); st_init_drawpixels_functions(functions); st_init_fbo_functions(functions); + st_init_feedback_functions(functions); st_init_program_functions(functions); st_init_query_functions(functions); st_init_rasterpos_functions(functions); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 98b78af7c5..56cae7d973 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -37,6 +37,9 @@ struct st_region; struct st_texture_object; struct st_texture_image; struct st_fragment_program; +struct draw_context; +struct draw_stage; + #define ST_NEW_MESA 0x1 /* Mesa state has changed */ #define ST_NEW_FRAGMENT_PROGRAM 0x2 @@ -62,6 +65,10 @@ struct st_context struct pipe_context *pipe; + struct draw_context *draw; /**< For selection/feedback */ + struct draw_stage *feedback_stage; /**< For FL_FEEDBACK rendermode */ + struct draw_stage *selection_stage; /**< For GL_SELECT rendermode */ + /* Eventually will use a cache to feed the pipe with * create/bind/delete calls to constant state objects. Not yet * though, we just shove random objects across the interface. diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 1facc14ccd..69f4b7fa5b 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -46,6 +46,8 @@ #include "pipe/p_winsys.h" #include "pipe/tgsi/exec/tgsi_attribs.h" +#include "pipe/draw/draw_private.h" +#include "pipe/draw/draw_context.h" static GLuint @@ -173,14 +175,14 @@ update_default_attribs_buffer(GLcontext *ctx) * we have something to render. * Basically, translate the information into the format expected by pipe. */ -static void -draw_vbo(GLcontext *ctx, - const struct gl_client_array **arrays, - const struct _mesa_prim *prims, - GLuint nr_prims, - const struct _mesa_index_buffer *ib, - GLuint min_index, - GLuint max_index) +void +st_draw_vbo(GLcontext *ctx, + const struct gl_client_array **arrays, + const struct _mesa_prim *prims, + GLuint nr_prims, + const struct _mesa_index_buffer *ib, + GLuint min_index, + GLuint max_index) { struct pipe_context *pipe = ctx->st->pipe; GLuint attr, i; @@ -356,6 +358,166 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, +/** + * Called by VBO to draw arrays when in selection or feedback mode. + * This is very much like the normal draw_vbo() function above. + * Look at code refactoring some day. + * Might move this into the failover module some day. + */ +void +st_feedback_draw_vbo(GLcontext *ctx, + const struct gl_client_array **arrays, + const struct _mesa_prim *prims, + GLuint nr_prims, + const struct _mesa_index_buffer *ib, + GLuint min_index, + GLuint max_index) +{ + struct st_context *st = ctx->st; + struct pipe_context *pipe = st->pipe; + struct draw_context *draw = st->draw; + GLuint attr, i; + GLbitfield attrsNeeded; + const unsigned attr0_offset = (unsigned) arrays[0]->Ptr; + struct pipe_buffer_handle *index_buffer_handle = 0; + + assert(ctx->RenderMode == GL_SELECT || + ctx->RenderMode == GL_FEEDBACK); + assert(draw); + + /* + * Set up the draw module's state. + * + * We'd like to do this less frequently, but the normal state-update + * code sends state updates to the pipe, not to our private draw module. + */ + 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_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; + + /* tell draw module about the vertex array element/attributes */ + for (attr = 0; attr < 16; attr++) { + struct pipe_vertex_buffer vbuffer; + struct pipe_vertex_element velement; + void *map; + + vbuffer.buffer = NULL; + vbuffer.pitch = 0; + velement.src_offset = 0; + 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 (attr == 0) + assert(vbuffer.buffer); + + draw_set_vertex_buffer(draw, attr, &vbuffer); + draw_set_vertex_element(draw, attr, &velement); + + /* map the attrib buffer */ + if (vbuffer.buffer) { + map = pipe->winsys->buffer_map(pipe->winsys, + vbuffer.buffer, + PIPE_BUFFER_FLAG_READ); + draw_set_mapped_vertex_buffer(draw, attr, map); + } + } + + + if (ib) { + 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; + + switch (ib->type) { + case GL_UNSIGNED_INT: + indexSize = 4; + break; + case GL_UNSIGNED_SHORT: + indexSize = 2; + break; + default: + assert(0); + } + + map = pipe->winsys->buffer_map(pipe->winsys, + index_buffer_handle, + PIPE_BUFFER_FLAG_READ); + draw_set_mapped_element_buffer(draw, indexSize, map); + } + + + /* draw here */ + for (i = 0; i < nr_prims; i++) { + draw_arrays(draw, prims[i].mode, prims[i].start, prims[i].count); + } + + + /* + * unmap vertex/index buffers + */ + for (i = 0; i < PIPE_ATTRIB_MAX; i++) { + if (draw->vertex_buffer[i].buffer) { + pipe->winsys->buffer_unmap(pipe->winsys, + draw->vertex_buffer[i].buffer); + draw_set_mapped_vertex_buffer(draw, i, NULL); + } + } + if (ib) { + pipe->winsys->buffer_unmap(pipe->winsys, index_buffer_handle); + draw_set_mapped_element_buffer(draw, 0, NULL); + } +} + /* This is all a hack to keep using tnl until we have vertex programs @@ -370,7 +532,7 @@ void st_init_draw( struct st_context *st ) assert(vbo); assert(vbo->draw_prims); - vbo->draw_prims = draw_vbo; + vbo->draw_prims = st_draw_vbo; _tnl_ProgramCacheInit( ctx ); } diff --git a/src/mesa/state_tracker/st_draw.h b/src/mesa/state_tracker/st_draw.h index 0005fbc51f..1fcd1b7e6b 100644 --- a/src/mesa/state_tracker/st_draw.h +++ b/src/mesa/state_tracker/st_draw.h @@ -34,11 +34,31 @@ #ifndef ST_DRAW_H #define ST_DRAW_H +struct _mesa_prim; +struct _mesa_index_buffer; void st_init_draw( struct st_context *st ); void st_destroy_draw( struct st_context *st ); +extern void +st_draw_vbo(GLcontext *ctx, + const struct gl_client_array **arrays, + const struct _mesa_prim *prims, + GLuint nr_prims, + const struct _mesa_index_buffer *ib, + GLuint min_index, + GLuint max_index); + +extern void +st_feedback_draw_vbo(GLcontext *ctx, + const struct gl_client_array **arrays, + const struct _mesa_prim *prims, + GLuint nr_prims, + const struct _mesa_index_buffer *ib, + GLuint min_index, + GLuint max_index); + void st_draw_vertices(GLcontext *ctx, unsigned prim, unsigned numVertex, float *verts, -- 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_context.h') 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 f117327a3f246713abfd4dc4320d4a1a7f1b811a Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 17 Sep 2007 09:47:41 -0400 Subject: Make sampler an immutable state object. Switch the sample to be an immutable state object. --- src/mesa/cso_cache/cso_cache.c | 7 +++- src/mesa/cso_cache/cso_cache.h | 2 + src/mesa/pipe/failover/fo_context.h | 2 +- src/mesa/pipe/failover/fo_state.c | 8 ++-- src/mesa/pipe/failover/fo_state_emit.c | 4 +- src/mesa/pipe/i915simple/i915_context.h | 4 +- src/mesa/pipe/i915simple/i915_state.c | 54 +++++++++++++++++---------- src/mesa/pipe/i915simple/i915_state_sampler.c | 2 +- src/mesa/pipe/p_context.h | 13 +++++-- src/mesa/pipe/softpipe/sp_context.c | 4 +- src/mesa/pipe/softpipe/sp_context.h | 4 +- src/mesa/pipe/softpipe/sp_state.h | 13 +++++-- src/mesa/pipe/softpipe/sp_state_sampler.c | 26 +++++++++++-- src/mesa/state_tracker/st_atom_sampler.c | 10 +++-- src/mesa/state_tracker/st_cache.c | 17 +++++++++ src/mesa/state_tracker/st_cache.h | 6 +++ src/mesa/state_tracker/st_cb_drawpixels.c | 6 ++- src/mesa/state_tracker/st_context.h | 4 +- 18 files changed, 133 insertions(+), 53 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/cso_cache/cso_cache.c b/src/mesa/cso_cache/cso_cache.c index 784d1f970f..61da590575 100644 --- a/src/mesa/cso_cache/cso_cache.c +++ b/src/mesa/cso_cache/cso_cache.c @@ -74,6 +74,8 @@ static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_ switch(type) { case CSO_BLEND: hash = sc->blend_hash; + case CSO_SAMPLER: + hash = sc->sampler_hash; } return hash; @@ -84,6 +86,8 @@ static int _cso_size_for_type(enum cso_cache_type type) switch(type) { case CSO_BLEND: return sizeof(struct pipe_blend_state); + case CSO_SAMPLER: + return sizeof(struct pipe_sampler_state); } return 0; } @@ -133,6 +137,7 @@ 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(); return sc; } @@ -140,8 +145,8 @@ struct cso_cache *cso_cache_create(void) void cso_cache_delete(struct cso_cache *sc) { assert(sc); - assert(sc->blend_hash); cso_hash_delete(sc->blend_hash); + cso_hash_delete(sc->sampler_hash); free(sc); } diff --git a/src/mesa/cso_cache/cso_cache.h b/src/mesa/cso_cache/cso_cache.h index c022b98d43..05a4cfcbdd 100644 --- a/src/mesa/cso_cache/cso_cache.h +++ b/src/mesa/cso_cache/cso_cache.h @@ -41,10 +41,12 @@ struct cso_hash; struct cso_cache { struct cso_hash *blend_hash; + struct cso_hash *sampler_hash; }; enum cso_cache_type { CSO_BLEND, + CSO_SAMPLER }; 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 b065aa832a..fa336193a8 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -68,6 +68,7 @@ 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]; 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_sampler_state sampler[PIPE_MAX_SAMPLERS]; struct pipe_setup_state setup; struct pipe_stencil_state stencil; 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 2357d7ef5c..f3a99e4198 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -196,16 +196,16 @@ failover_set_stencil_state(struct pipe_context *pipe, static void -failover_set_sampler_state(struct pipe_context *pipe, +failover_bind_sampler_state(struct pipe_context *pipe, unsigned unit, const struct pipe_sampler_state *sampler) { struct failover_context *failover = failover_context(pipe); - failover->sampler[unit] = *sampler; + failover->sampler[unit] = sampler; failover->dirty |= FO_NEW_SAMPLER; failover->dirty_sampler |= (1<hw->set_sampler_state( failover->hw, unit, sampler ); + failover->hw->bind_sampler_state( failover->hw, unit, sampler ); } @@ -267,6 +267,7 @@ void 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.set_alpha_test_state = failover_set_alpha_test_state; failover->pipe.set_blend_color = failover_set_blend_color; @@ -277,7 +278,6 @@ failover_init_state_functions( struct failover_context *failover ) 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_sampler_state = failover_set_sampler_state; 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; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index 77413d100b..9d462678c5 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -100,8 +100,8 @@ failover_state_emit( struct failover_context *failover ) if (failover->dirty & FO_NEW_SAMPLER) { for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { if (failover->dirty_sampler & (1<sw->set_sampler_state( failover->sw, i, - &failover->sampler[i] ); + failover->sw->bind_sampler_state( failover->sw, i, + failover->sampler[i] ); } } } diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index 215c5294fa..51baa281ec 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -123,7 +123,8 @@ struct i915_context /* The most recent drawing state as set by the driver: */ - const struct pipe_blend_state *blend; + const struct pipe_blend_state *blend; + const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; @@ -135,7 +136,6 @@ struct i915_context struct pipe_shader_state fs; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; struct pipe_setup_state setup; struct pipe_stencil_state stencil; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 478988fd4a..10060b45a4 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -42,8 +42,6 @@ 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)); @@ -62,10 +60,9 @@ static void i915_bind_blend_state( struct pipe_context *pipe, static void i915_delete_blend_state( struct pipe_context *pipe, - const struct pipe_blend_state *blend ) + const struct pipe_blend_state *blend ) { - /*struct i915_context *i915 = i915_context(pipe);*/ - free(blend); + free((void*)blend); } static void i915_set_blend_color( struct pipe_context *pipe, @@ -78,6 +75,34 @@ static void i915_set_blend_color( struct pipe_context *pipe, i915->dirty |= I915_NEW_BLEND; } +static const struct pipe_sampler_state * +i915_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + struct pipe_sampler_state *new_sampler = malloc(sizeof(struct pipe_sampler_state)); + memcpy(new_sampler, sampler, sizeof(struct pipe_sampler_state)); + + return new_sampler; +} + +static void i915_bind_sampler_state(struct pipe_context *pipe, + unsigned unit, + const struct pipe_sampler_state *sampler) +{ + struct i915_context *i915 = i915_context(pipe); + + assert(unit < PIPE_MAX_SAMPLERS); + i915->sampler[unit] = sampler; + + i915->dirty |= I915_NEW_SAMPLER; +} + +static void i915_delete_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + free((struct pipe_sampler_state*)sampler); +} + /** XXX move someday? Or consolidate all these simple state setters * into one file. @@ -189,19 +214,6 @@ static void i915_set_constant_buffer(struct pipe_context *pipe, } -static void i915_set_sampler_state(struct pipe_context *pipe, - unsigned unit, - const struct pipe_sampler_state *sampler) -{ - struct i915_context *i915 = i915_context(pipe); - - assert(unit < PIPE_MAX_SAMPLERS); - i915->sampler[unit] = *sampler; - - i915->dirty |= I915_NEW_SAMPLER; -} - - static void i915_set_texture_state(struct pipe_context *pipe, unsigned unit, struct pipe_mipmap_tree *texture) @@ -293,7 +305,6 @@ static void i915_set_vertex_buffer( struct pipe_context *pipe, /* pass-through to draw module */ draw_set_vertex_buffer(i915->draw, index, buffer); } - static void i915_set_vertex_element( struct pipe_context *pipe, unsigned index, @@ -313,6 +324,10 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.bind_blend_state = i915_bind_blend_state; i915->pipe.delete_blend_state = i915_delete_blend_state; + i915->pipe.create_sampler_state = i915_create_sampler_state; + i915->pipe.bind_sampler_state = i915_bind_sampler_state; + i915->pipe.delete_sampler_state = i915_delete_sampler_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; @@ -323,7 +338,6 @@ i915_init_state_functions( struct i915_context *i915 ) 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_sampler_state = i915_set_sampler_state; 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; diff --git a/src/mesa/pipe/i915simple/i915_state_sampler.c b/src/mesa/pipe/i915simple/i915_state_sampler.c index 7a595d1022..419a156136 100644 --- a/src/mesa/pipe/i915simple/i915_state_sampler.c +++ b/src/mesa/pipe/i915simple/i915_state_sampler.c @@ -269,7 +269,7 @@ void i915_update_samplers( struct i915_context *i915 ) if (i915->texture[unit]) { update_sampler( i915, unit, - i915->sampler + unit, /* sampler state */ + i915->sampler[unit], /* sampler state */ i915->texture[unit], /* mipmap tree */ i915->current.sampler[unit] /* the result */ ); diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index b9af69fc05..0913e49096 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -92,6 +92,15 @@ struct pipe_context { void (*delete_blend_state)(struct pipe_context *, const struct pipe_blend_state *); + const struct pipe_sampler_state * (*create_sampler_state)( + struct pipe_context *, + const struct pipe_sampler_state *); + void (*bind_sampler_state)(struct pipe_context *, + unsigned unit, + const struct pipe_sampler_state *); + void (*delete_sampler_state)(struct pipe_context *, + const struct pipe_sampler_state *); + void (*set_alpha_test_state)( struct pipe_context *, const struct pipe_alpha_test_state * ); @@ -135,10 +144,6 @@ struct pipe_context { void (*set_stencil_state)( struct pipe_context *, const struct pipe_stencil_state * ); - void (*set_sampler_state)( struct pipe_context *, - unsigned unit, - const struct pipe_sampler_state * ); - void (*set_texture_state)( struct pipe_context *, unsigned unit, struct pipe_mipmap_tree * ); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index b9c7013e9e..bab7985e8d 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -253,6 +253,9 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, 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.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.set_alpha_test_state = softpipe_set_alpha_test_state; softpipe->pipe.set_blend_color = softpipe_set_blend_color; @@ -265,7 +268,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, 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_sampler_state = softpipe_set_sampler_state; 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; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 7fecf2974a..5cee1a3cf9 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -71,7 +71,8 @@ struct softpipe_context { /* The most recent drawing state as set by the driver: */ - const struct pipe_blend_state *blend; + const struct pipe_blend_state *blend; + const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; 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_sampler_state sampler[PIPE_MAX_SAMPLERS]; struct pipe_setup_state setup; struct pipe_stencil_state stencil; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index e2b1a2a164..c8c93709db 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -41,6 +41,15 @@ void softpipe_bind_blend_state(struct pipe_context *, void softpipe_delete_blend_state(struct pipe_context *, const struct pipe_blend_state *); +const struct pipe_sampler_state * +softpipe_create_sampler_state(struct pipe_context *, + const struct pipe_sampler_state *); +void softpipe_bind_sampler_state(struct pipe_context *, + unsigned, + const struct pipe_sampler_state *); +void softpipe_delete_sampler_state(struct pipe_context *, + const struct pipe_sampler_state *); + void softpipe_set_framebuffer_state( struct pipe_context *, const struct pipe_framebuffer_state * ); @@ -81,10 +90,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_sampler_state( struct pipe_context *, - unsigned unit, - const struct pipe_sampler_state * ); - void softpipe_set_stencil_state( struct pipe_context *, const struct pipe_stencil_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_sampler.c b/src/mesa/pipe/softpipe/sp_state_sampler.c index 2e3d0c3d65..09898eb579 100644 --- a/src/mesa/pipe/softpipe/sp_state_sampler.c +++ b/src/mesa/pipe/softpipe/sp_state_sampler.c @@ -34,20 +34,38 @@ +const struct pipe_sampler_state * +softpipe_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + struct pipe_sampler_state *new_sampler = malloc(sizeof(struct pipe_sampler_state)); + memcpy(new_sampler, sampler, sizeof(struct pipe_sampler_state)); + + return new_sampler; +} + void -softpipe_set_sampler_state(struct pipe_context *pipe, - unsigned unit, - const struct pipe_sampler_state *sampler) +softpipe_bind_sampler_state(struct pipe_context *pipe, + unsigned unit, + const struct pipe_sampler_state *sampler) { struct softpipe_context *softpipe = softpipe_context(pipe); assert(unit < PIPE_MAX_SAMPLERS); - softpipe->sampler[unit] = *sampler; + softpipe->sampler[unit] = sampler; softpipe->dirty |= SP_NEW_SAMPLER; } +void +softpipe_delete_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + free((struct pipe_sampler_state*)sampler); +} + + void softpipe_set_texture_state(struct pipe_context *pipe, unsigned unit, diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index d65565f991..9a728e2d79 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.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" @@ -142,10 +143,13 @@ update_samplers(struct st_context *st) /* XXX more sampler state here */ } - if (memcmp(&sampler, &st->state.sampler[u], sizeof(sampler)) != 0) { + const struct pipe_sampler_state *cached_sampler = + st_cached_sampler_state(st, &sampler); + + if (cached_sampler == st->state.sampler[u]) { /* state has changed */ - st->state.sampler[u] = sampler; - st->pipe->set_sampler_state(st->pipe, u, &sampler); + st->state.sampler[u] = cached_sampler; + st->pipe->bind_sampler_state(st->pipe, u, cached_sampler); } } } diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index 0205b1cab3..99fb45f00a 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -59,3 +59,20 @@ struct pipe_blend_state * st_cached_blend_state( } return (struct pipe_blend_state*)(cso_hash_iter_data(iter)); } + +struct pipe_sampler_state * st_cached_sampler_state( + struct st_context *st, + const struct pipe_sampler_state *sampler) +{ + unsigned hash_key = cso_construct_key((void*)sampler, sizeof(struct pipe_sampler_state)); + struct cso_hash_iter iter = cso_find_state_template(st->cache, + hash_key, CSO_SAMPLER, + (void*)sampler); + if (cso_hash_iter_is_null(iter)) { + const struct pipe_sampler_state *created_state = st->pipe->create_sampler_state( + st->pipe, sampler); + iter = cso_insert_state(st->cache, hash_key, CSO_SAMPLER, + (void*)created_state); + } + return (struct pipe_sampler_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 29b1d00dca..927585141c 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -34,10 +34,16 @@ #define ST_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); +struct pipe_sampler_state * st_cached_sampler_state( + struct st_context *st, + const struct pipe_sampler_state *sampler); + + #endif diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index c2d231cdb5..31a37e5cd4 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -34,6 +34,7 @@ #include "st_context.h" #include "st_atom.h" +#include "st_cache.h" #include "st_draw.h" #include "st_program.h" #include "st_cb_drawpixels.h" @@ -359,7 +360,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; - pipe->set_sampler_state(pipe, unit, &sampler); + const struct pipe_sampler_state *state = st_cached_sampler_state(ctx->st, &sampler); + pipe->bind_sampler_state(pipe, unit, state); } /* viewport state: viewport matching window dims */ @@ -402,7 +404,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, 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]); + pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); free_mipmap_tree(pipe, mt); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index bd2efdb960..13526ff9e7 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -74,7 +74,8 @@ struct st_context * though, we just shove random objects across the interface. */ struct { - const struct pipe_blend_state *blend; + const struct pipe_blend_state *blend; + const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; @@ -86,7 +87,6 @@ struct st_context struct pipe_framebuffer_state framebuffer; 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; -- 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_context.h') 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_context.h') 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_context.h') 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 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_context.h') 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_context.h') 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 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_context.h') 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_context.h') 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 7a06c026ad24b74048f6d125383faf25deb1dfbb Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Thu, 20 Sep 2007 10:07:10 -0400 Subject: Fix failover state binding and convert the sampler to use the new state constant state object semantics. --- src/mesa/pipe/cso_cache/cso_cache.h | 5 +++ src/mesa/pipe/failover/fo_context.h | 12 +++--- src/mesa/pipe/failover/fo_state.c | 72 ++++++++++++++++++++++--------- src/mesa/pipe/failover/fo_state_emit.c | 2 +- src/mesa/pipe/i915simple/i915_state.c | 15 +++---- src/mesa/pipe/p_context.h | 13 +++--- src/mesa/pipe/softpipe/sp_state.h | 9 ++-- src/mesa/pipe/softpipe/sp_state_sampler.c | 18 +++----- src/mesa/state_tracker/st_atom_sampler.c | 10 ++--- src/mesa/state_tracker/st_cache.c | 22 +++++----- src/mesa/state_tracker/st_cache.h | 2 +- src/mesa/state_tracker/st_cb_drawpixels.c | 7 +-- src/mesa/state_tracker/st_context.h | 2 +- 13 files changed, 105 insertions(+), 84 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/cso_cache/cso_cache.h b/src/mesa/pipe/cso_cache/cso_cache.h index 291759d5d1..2acb58c66b 100644 --- a/src/mesa/pipe/cso_cache/cso_cache.h +++ b/src/mesa/pipe/cso_cache/cso_cache.h @@ -73,6 +73,11 @@ struct cso_vertex_shader { void *data; }; +struct cso_sampler { + struct pipe_sampler_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 7371ad4392..8a2fbe2be9 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -70,12 +70,12 @@ struct failover_context { /* The most recent drawing state as set by the driver: */ - const struct fo_state *blend; - const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; - const struct fo_state *depth_stencil; - const struct fo_state *rasterizer; - const struct fo_state *fragment_shader; - const struct fo_state *vertex_shader; + const struct fo_state *blend; + const struct fo_state *sampler[PIPE_MAX_SAMPLERS]; + const struct fo_state *depth_stencil; + const struct fo_state *rasterizer; + 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 3379f45355..ce3f0ca635 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -75,10 +75,10 @@ failover_bind_blend_state( struct pipe_context *pipe, void *blend ) { struct failover_context *failover = failover_context(pipe); - - failover->blend = (struct fo_state *)blend; + struct fo_state *state = (struct fo_state *)blend; + failover->blend = state; failover->dirty |= FO_NEW_BLEND; - failover->hw->bind_blend_state( failover->hw, blend ); + failover->hw->bind_blend_state( failover->hw, state->hw_state ); } static void @@ -146,10 +146,10 @@ failover_bind_depth_stencil_state(struct pipe_context *pipe, void *depth_stencil) { struct failover_context *failover = failover_context(pipe); - - failover->depth_stencil = (struct fo_state *)depth_stencil; + 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, depth_stencil ); + failover->hw->bind_depth_stencil_state(failover->hw, state->hw_state); } static void @@ -192,14 +192,13 @@ failover_create_fs_state(struct pipe_context *pipe, } static void -failover_bind_fs_state(struct pipe_context *pipe, - void *fs) +failover_bind_fs_state(struct pipe_context *pipe, void *fs) { struct failover_context *failover = failover_context(pipe); - - failover->fragment_shader = (struct fo_state *)fs; + struct fo_state *state = (struct fo_state*)fs; + failover->fragment_shader = state; failover->dirty |= FO_NEW_FRAGMENT_SHADER; - failover->hw->bind_fs_state(failover->hw, (struct pipe_shader_state *)fs); + failover->hw->bind_fs_state(failover->hw, state->hw_state); } static void @@ -235,9 +234,10 @@ failover_bind_vs_state(struct pipe_context *pipe, { struct failover_context *failover = failover_context(pipe); - failover->vertex_shader = (struct fo_state*)vs; + struct fo_state *state = (struct fo_state*)vs; + failover->vertex_shader = state; failover->dirty |= FO_NEW_VERTEX_SHADER; - failover->hw->bind_vs_state(failover->hw, vs); + failover->hw->bind_vs_state(failover->hw, state->hw_state); } static void @@ -284,9 +284,10 @@ failover_bind_rasterizer_state(struct pipe_context *pipe, { struct failover_context *failover = failover_context(pipe); - failover->rasterizer = (struct fo_state *)raster; + struct fo_state *state = (struct fo_state*)raster; + failover->rasterizer = state; failover->dirty |= FO_NEW_RASTERIZER; - failover->hw->bind_rasterizer_state( failover->hw, raster ); + failover->hw->bind_rasterizer_state(failover->hw, state->hw_state); } static void @@ -315,17 +316,44 @@ failover_set_scissor_state( struct pipe_context *pipe, failover->hw->set_scissor_state( failover->hw, scissor ); } + +static void * +failover_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *templ) +{ + struct fo_state *state = malloc(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_sampler_state(pipe, templ); + state->hw_state = failover->hw->create_sampler_state(pipe, templ); + + return state; +} + static void failover_bind_sampler_state(struct pipe_context *pipe, - unsigned unit, - const struct pipe_sampler_state *sampler) + unsigned unit, void *sampler) { struct failover_context *failover = failover_context(pipe); - - failover->sampler[unit] = sampler; + struct fo_state *state = (struct fo_state*)sampler; + failover->sampler[unit] = state; failover->dirty |= FO_NEW_SAMPLER; failover->dirty_sampler |= (1<hw->bind_sampler_state( failover->hw, unit, sampler ); + failover->hw->bind_sampler_state(failover->hw, unit, + state->hw_state); +} + +static void +failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) +{ + struct fo_state *state = (struct fo_state*)sampler; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_sampler_state(pipe, state->sw_state); + failover->hw->delete_sampler_state(pipe, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + free(state); } @@ -389,7 +417,9 @@ 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.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; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index da12b4e25c..c0ea681024 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -103,7 +103,7 @@ failover_state_emit( struct failover_context *failover ) for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { if (failover->dirty_sampler & (1<sw->bind_sampler_state( failover->sw, i, - failover->sampler[i] ); + failover->sampler[i]->sw_state ); } } } diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index be549ed6fd..0fb41e17ab 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -142,32 +142,27 @@ static void i915_set_blend_color( struct pipe_context *pipe, i915->dirty |= I915_NEW_BLEND; } -static const struct pipe_sampler_state * +static void * i915_create_sampler_state(struct pipe_context *pipe, const struct pipe_sampler_state *sampler) { - struct pipe_sampler_state *new_sampler = malloc(sizeof(struct pipe_sampler_state)); - memcpy(new_sampler, sampler, sizeof(struct pipe_sampler_state)); - - return new_sampler; + return 0; } static void i915_bind_sampler_state(struct pipe_context *pipe, - unsigned unit, - const struct pipe_sampler_state *sampler) + unsigned unit, void *sampler) { struct i915_context *i915 = i915_context(pipe); assert(unit < PIPE_MAX_SAMPLERS); - i915->sampler[unit] = sampler; + i915->sampler[unit] = (const struct pipe_sampler_state *)sampler; i915->dirty |= I915_NEW_SAMPLER; } static void i915_delete_sampler_state(struct pipe_context *pipe, - const struct pipe_sampler_state *sampler) + void *sampler) { - free((struct pipe_sampler_state*)sampler); } diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 84aca20c58..07ee019880 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -91,14 +91,11 @@ struct pipe_context { 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 *, - const struct pipe_sampler_state *); - void (*bind_sampler_state)(struct pipe_context *, - unsigned unit, - const struct pipe_sampler_state *); - void (*delete_sampler_state)(struct pipe_context *, - const struct pipe_sampler_state *); + 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 *(*create_rasterizer_state)(struct pipe_context *, const struct pipe_rasterizer_state *); diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 08dfe208fb..62323c41c3 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -41,14 +41,11 @@ void softpipe_bind_blend_state(struct pipe_context *, void softpipe_delete_blend_state(struct pipe_context *, void *); -const struct pipe_sampler_state * +void * softpipe_create_sampler_state(struct pipe_context *, const struct pipe_sampler_state *); -void softpipe_bind_sampler_state(struct pipe_context *, - unsigned, - const struct pipe_sampler_state *); -void softpipe_delete_sampler_state(struct pipe_context *, - const struct pipe_sampler_state *); +void softpipe_bind_sampler_state(struct pipe_context *, unsigned, void *); +void softpipe_delete_sampler_state(struct pipe_context *, void *); void * softpipe_create_depth_stencil_state(struct pipe_context *, diff --git a/src/mesa/pipe/softpipe/sp_state_sampler.c b/src/mesa/pipe/softpipe/sp_state_sampler.c index 09898eb579..ad98375735 100644 --- a/src/mesa/pipe/softpipe/sp_state_sampler.c +++ b/src/mesa/pipe/softpipe/sp_state_sampler.c @@ -32,27 +32,21 @@ #include "sp_context.h" #include "sp_state.h" - - -const struct pipe_sampler_state * +void * softpipe_create_sampler_state(struct pipe_context *pipe, const struct pipe_sampler_state *sampler) { - struct pipe_sampler_state *new_sampler = malloc(sizeof(struct pipe_sampler_state)); - memcpy(new_sampler, sampler, sizeof(struct pipe_sampler_state)); - - return new_sampler; + return 0; } void softpipe_bind_sampler_state(struct pipe_context *pipe, - unsigned unit, - const struct pipe_sampler_state *sampler) + unsigned unit, void *sampler) { struct softpipe_context *softpipe = softpipe_context(pipe); assert(unit < PIPE_MAX_SAMPLERS); - softpipe->sampler[unit] = sampler; + softpipe->sampler[unit] = (struct pipe_sampler_state *)sampler; softpipe->dirty |= SP_NEW_SAMPLER; } @@ -60,9 +54,9 @@ softpipe_bind_sampler_state(struct pipe_context *pipe, void softpipe_delete_sampler_state(struct pipe_context *pipe, - const struct pipe_sampler_state *sampler) + void *sampler) { - free((struct pipe_sampler_state*)sampler); + /* do nothing */ } diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 994d3691d8..23ccd55a05 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -123,6 +123,7 @@ update_samplers(struct st_context *st) const struct gl_texture_object *texobj = st->ctx->Texture.Unit[u]._Current; struct pipe_sampler_state sampler; + const struct cso_sampler *cso; memset(&sampler, 0, sizeof(sampler)); @@ -143,13 +144,12 @@ update_samplers(struct st_context *st) /* XXX more sampler state here */ } - const struct pipe_sampler_state *cached_sampler = - st_cached_sampler_state(st, &sampler); + cso = st_cached_sampler_state(st, &sampler); - if (cached_sampler != st->state.sampler[u]) { + if (cso != st->state.sampler[u]) { /* state has changed */ - st->state.sampler[u] = cached_sampler; - st->pipe->bind_sampler_state(st->pipe, u, cached_sampler); + st->state.sampler[u] = cso; + st->pipe->bind_sampler_state(st->pipe, u, cso->data); } } } diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index c1ec130b32..007a2311e9 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -61,21 +61,23 @@ const struct cso_blend * st_cached_blend_state(struct st_context *st, return ((struct cso_blend *)cso_hash_iter_data(iter)); } -struct pipe_sampler_state * st_cached_sampler_state( - struct st_context *st, - const struct pipe_sampler_state *sampler) +const struct cso_sampler * +st_cached_sampler_state(struct st_context *st, + const struct pipe_sampler_state *templ) { - unsigned hash_key = cso_construct_key((void*)sampler, sizeof(struct pipe_sampler_state)); + unsigned hash_key = cso_construct_key((void*)templ, sizeof(struct pipe_sampler_state)); struct cso_hash_iter iter = cso_find_state_template(st->cache, hash_key, CSO_SAMPLER, - (void*)sampler); + (void*)templ); if (cso_hash_iter_is_null(iter)) { - const struct pipe_sampler_state *created_state = st->pipe->create_sampler_state( - st->pipe, sampler); - iter = cso_insert_state(st->cache, hash_key, CSO_SAMPLER, - (void*)created_state); + struct cso_sampler *cso = malloc(sizeof(struct cso_sampler)); + memcpy(&cso->state, templ, sizeof(struct pipe_sampler_state)); + cso->data = st->pipe->create_sampler_state(st->pipe, templ); + if (!cso->data) + cso->data = &cso->state; + iter = cso_insert_state(st->cache, hash_key, CSO_SAMPLER, cso); } - return (struct pipe_sampler_state*)(cso_hash_iter_data(iter)); + return (struct cso_sampler*)(cso_hash_iter_data(iter)); } const struct cso_depth_stencil * diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index 167d9ec11a..483af6fdb4 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -43,7 +43,7 @@ const struct cso_blend * st_cached_blend_state(struct st_context *st, const struct pipe_blend_state *blend); -struct pipe_sampler_state * +const struct cso_sampler * st_cached_sampler_state(struct st_context *st, const struct pipe_sampler_state *sampler); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 95810b7baf..d814e34157 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -345,6 +345,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* texture sampling state: */ { struct pipe_sampler_state sampler; + const struct cso_sampler *cso; memset(&sampler, 0, sizeof(sampler)); sampler.wrap_s = PIPE_TEX_WRAP_REPEAT; sampler.wrap_t = PIPE_TEX_WRAP_REPEAT; @@ -352,8 +353,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; - const struct pipe_sampler_state *state = st_cached_sampler_state(ctx->st, &sampler); - pipe->bind_sampler_state(pipe, unit, state); + cso = st_cached_sampler_state(ctx->st, &sampler); + pipe->bind_sampler_state(pipe, unit, cso->data); } /* viewport state: viewport matching window dims */ @@ -396,7 +397,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, 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->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]->data); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); free_mipmap_tree(pipe, mt); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index b82cf24273..8a57227c84 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -76,7 +76,7 @@ struct st_context */ struct { const struct cso_blend *blend; - const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + 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; -- 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_context.h') 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_context.h') 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 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_context.h') 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 07f31a29b41be572c48fc1b440eaeb6a6b010cc8 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 25 Sep 2007 14:46:49 -0600 Subject: some clean-up of ST_NEW_ shader flags --- src/mesa/state_tracker/st_atom_shader.c | 2 +- src/mesa/state_tracker/st_cb_program.c | 24 ++++-------------------- src/mesa/state_tracker/st_context.h | 2 +- 3 files changed, 6 insertions(+), 22 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index f3bb9effde..383184e575 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -416,7 +416,7 @@ const struct st_tracked_state st_update_shader = { .name = "st_update_shader", .dirty = { .mesa = 0, - .st = ST_NEW_LINKAGE + .st = ST_NEW_SHADER }, .update = update_linkage }; diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index aee316df6f..f57d22652f 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -56,15 +56,7 @@ static void st_bind_program( GLcontext *ctx, { struct st_context *st = st_context(ctx); - switch (target) { - case GL_VERTEX_PROGRAM_ARB: - st->dirty.st |= ST_NEW_VERTEX_PROGRAM; - break; - case GL_FRAGMENT_PROGRAM_ARB: - st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; - break; - } - st->dirty.st |= ST_NEW_LINKAGE; + st->dirty.st |= ST_NEW_SHADER; } @@ -77,9 +69,7 @@ static void st_use_program( GLcontext *ctx, { struct st_context *st = st_context(ctx); - st->dirty.st |= ST_NEW_VERTEX_PROGRAM; - st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; - st->dirty.st |= ST_NEW_LINKAGE; + st->dirty.st |= ST_NEW_SHADER; } @@ -126,7 +116,7 @@ static struct gl_program *st_new_program( GLcontext *ctx, return _mesa_new_program(ctx, target, id); } - st->dirty.st |= ST_NEW_LINKAGE; + st->dirty.st |= ST_NEW_SHADER; } @@ -180,9 +170,6 @@ static void st_program_string_notify( GLcontext *ctx, if (target == GL_FRAGMENT_PROGRAM_ARB) { struct st_fragment_program *stfp = (struct st_fragment_program *) prog; - if (prog == &ctx->FragmentProgram._Current->Base) - st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; - stfp->serialNo++; stfp->param_state = stfp->Base.Base.Parameters->StateFlags; @@ -190,9 +177,6 @@ static void st_program_string_notify( GLcontext *ctx, else if (target == GL_VERTEX_PROGRAM_ARB) { struct st_vertex_program *stvp = (struct st_vertex_program *) prog; - if (prog == &ctx->VertexProgram._Current->Base) - st->dirty.st |= ST_NEW_VERTEX_PROGRAM; - stvp->serialNo++; stvp->param_state = stvp->Base.Base.Parameters->StateFlags; @@ -202,7 +186,7 @@ static void st_program_string_notify( GLcontext *ctx, _tnl_program_string(ctx, target, prog); } - st->dirty.st |= ST_NEW_LINKAGE; + st->dirty.st |= ST_NEW_SHADER; } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 24f0ff9aaf..da4fd0d4e4 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -45,7 +45,7 @@ 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 +#define ST_NEW_SHADER 0x8 struct st_state_flags { -- cgit v1.2.3 From a7e997cfc5d909eebbc16ba5b0362e9778f01561 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 1 Oct 2007 06:25:23 -0400 Subject: Get rid of ST_NEW_SHADER flag and the dependency on _NEW_PROGRAM which is being hit all the time. Done by Keith really. --- src/mesa/state_tracker/st_atom_shader.c | 4 ++-- src/mesa/state_tracker/st_cb_program.c | 26 ++++++++++++++++---------- src/mesa/state_tracker/st_context.h | 1 - 3 files changed, 18 insertions(+), 13 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index dc6210cd6c..919461bcb8 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -306,8 +306,8 @@ update_linkage( struct st_context *st ) const struct st_tracked_state st_update_shader = { .name = "st_update_shader", .dirty = { - .mesa = _NEW_PROGRAM, - .st = ST_NEW_SHADER + .mesa = 0, + .st = ST_NEW_VERTEX_PROGRAM | ST_NEW_FRAGMENT_PROGRAM }, .update = update_linkage }; diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 8df8b263d3..1902c8d7d6 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 "tnl/tnl.h" #include "pipe/tgsi/mesa/tgsi_mesa.h" @@ -57,7 +56,14 @@ static void st_bind_program( GLcontext *ctx, { struct st_context *st = st_context(ctx); - st->dirty.st |= ST_NEW_SHADER; + switch (target) { + case GL_VERTEX_PROGRAM_ARB: + st->dirty.st |= ST_NEW_VERTEX_PROGRAM; + break; + case GL_FRAGMENT_PROGRAM_ARB: + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; + break; + } } @@ -70,7 +76,8 @@ static void st_use_program( GLcontext *ctx, { struct st_context *st = st_context(ctx); - st->dirty.st |= ST_NEW_SHADER; + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; + st->dirty.st |= ST_NEW_VERTEX_PROGRAM; _mesa_use_program(ctx, program); } @@ -114,8 +121,6 @@ static struct gl_program *st_new_program( GLcontext *ctx, default: return _mesa_new_program(ctx, target, id); } - - st->dirty.st |= ST_NEW_SHADER; } @@ -175,6 +180,9 @@ static void st_program_string_notify( GLcontext *ctx, } stfp->param_state = stfp->Base.Base.Parameters->StateFlags; + + if (st->fp == stfp) + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; } else if (target == GL_VERTEX_PROGRAM_ARB) { struct st_vertex_program *stvp = (struct st_vertex_program *) prog; @@ -189,12 +197,10 @@ static void st_program_string_notify( GLcontext *ctx, stvp->param_state = stvp->Base.Base.Parameters->StateFlags; - /* Also tell tnl about it: - */ - _tnl_program_string(ctx, target, prog); - } + if (st->vp == stvp) + st->dirty.st |= ST_NEW_VERTEX_PROGRAM; - st->dirty.st |= ST_NEW_SHADER; + } } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index da4fd0d4e4..b4ae041d36 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -45,7 +45,6 @@ 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_SHADER 0x8 struct st_state_flags { -- cgit v1.2.3 From 0007cd7ba0a61fcbcf9c9d19e014408be25ae496 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 18 Oct 2007 15:18:55 -0600 Subject: Alternate CopyPixels path based on get/put_tile(). For some drivers (like Xlib) it's not possible to treat the front/back color buffers as pipe_regions. So pipe->region_copy() won't work. Added a new state tracker field indicating if we can use regions for colorbuffer accesses. This should probably be re-considered someday... --- src/mesa/drivers/x11/xm_api.c | 2 ++ src/mesa/state_tracker/st_cb_drawpixels.c | 42 +++++++++++++++++++++++++------ src/mesa/state_tracker/st_context.c | 1 + src/mesa/state_tracker/st_context.h | 6 +++++ 4 files changed, 43 insertions(+), 8 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index 1d3f799f36..ff83dab075 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -1603,6 +1603,8 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) mesaCtx->st->pipe->surface_alloc = xmesa_surface_alloc; mesaCtx->st->pipe->supported_formats = xmesa_supported_formats; + mesaCtx->st->haveFramebufferRegions = GL_FALSE; + /* special pipe->clear function */ mesaCtx->st->pipe->clear = xmesa_clear; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index b88b96e3b2..90f91c39b5 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -1219,14 +1219,40 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, srcy = ctx->DrawBuffer->Height - srcy - height; } - /* copy source framebuffer region into mipmap/texture */ - pipe->region_copy(pipe, - mt->region, /* dest */ - 0, /* dest_offset */ - 0, 0, /* destx/y */ - psRead->region, - 0, /* src_offset */ - srcx, srcy, width, height); + /* For some drivers (like Xlib) it's not possible to treat the + * front/back color buffers as regions (they're XImages and Pixmaps). + * So, this var tells us if we can use region_copy here... + */ + if (st->haveFramebufferRegions) { + /* copy source framebuffer region into mipmap/texture */ + pipe->region_copy(pipe, + mt->region, /* dest */ + 0, /* dest_offset */ + 0, 0, /* destx/y */ + psRead->region, + 0, /* src_offset */ + srcx, srcy, width, height); + } + else { + /* alternate path using get/put_tile() */ + struct pipe_surface *psTex; + GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); + + psTex = pipe->get_tex_surface(pipe, mt, 0, 0, 0); + + (void) pipe->region_map(pipe, psRead->region); + (void) pipe->region_map(pipe, psTex->region); + + psRead->get_tile(psRead, srcx, srcy, width, height, buf); + psTex->put_tile(psTex, 0, 0, width, height, buf); + + pipe->region_unmap(pipe, psRead->region); + pipe->region_unmap(pipe, psTex->region); + + pipe_surface_reference(&psTex, NULL); + + free(buf); + } /* draw textured quad */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 09d9b1ea3b..8ced3f504c 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -90,6 +90,7 @@ struct st_context *st_create_context( GLcontext *ctx, st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; + st->haveFramebufferRegions = GL_TRUE; #if 0 st_init_cb_clear( st ); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index b4ae041d36..bacc0b9b3f 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -111,6 +111,12 @@ struct st_context char vendor[100]; char renderer[100]; + /** Can we access the front/back color buffers as pipe_regions? + * We can't with the Xlib driver... + * This is a hack that should be fixed someday. + */ + GLboolean haveFramebufferRegions; + /* State to be validated: */ struct st_tracked_state **atoms; -- cgit v1.2.3 From cc9b4df5cbcb4e77cd5ee06e97e450fc0d78006e Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 29 Oct 2007 17:14:23 -0600 Subject: update comments, fix typo --- src/mesa/state_tracker/st_context.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index bacc0b9b3f..329599bc61 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -68,12 +68,11 @@ struct st_context struct pipe_context *pipe; struct draw_context *draw; /**< For selection/feedback */ - struct draw_stage *feedback_stage; /**< For FL_FEEDBACK rendermode */ + struct draw_stage *feedback_stage; /**< For GL_FEEDBACK rendermode */ struct draw_stage *selection_stage; /**< For GL_SELECT rendermode */ - /* Eventually will use a cache to feed the pipe with - * create/bind/delete calls to constant state objects. Not yet - * though, we just shove random objects across the interface. + /* Some state is contained in constant objects. + * Other state is just parameter values. */ struct { const struct cso_alpha_test *alpha_test; -- cgit v1.2.3 From b19a93393043371776af6d50662a3eb0a9a965ce Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 29 Oct 2007 17:32:42 -0600 Subject: comment unused 'cb' field --- src/mesa/state_tracker/st_context.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 329599bc61..ecab0e2932 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -99,6 +99,7 @@ struct st_context struct st_tracked_state tracked_state[2]; } constants; + /* XXX unused: */ struct { struct gl_fragment_program *fragment_program; } cb; -- cgit v1.2.3 From 0be546fa53753119a770d6368ced380bdf69c69b Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 30 Oct 2007 11:15:59 -0600 Subject: added pixel_transfer_program field --- src/mesa/state_tracker/st_context.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index ecab0e2932..3774a999ab 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -132,6 +132,8 @@ struct st_context struct st_vertex_program *vp; /**< Currently bound vertex program */ struct st_fragment_program *fp; /**< Currently bound fragment program */ + struct gl_fragment_program *pixel_transfer_program; + /** * Buffer object which stores the ctx->Current.Attrib[] values. * Used for vertex array drawing when we we need an attribute for -- cgit v1.2.3 From df174bdb818d4e21652d49c73ff17722e34a38b9 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 30 Oct 2007 12:24:05 -0600 Subject: added pixel_transfer_cache --- src/mesa/state_tracker/st_context.c | 4 ++++ src/mesa/state_tracker/st_context.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 8ced3f504c..e872e8b12c 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -92,6 +92,8 @@ struct st_context *st_create_context( GLcontext *ctx, st->haveFramebufferRegions = GL_TRUE; + st->pixel_transfer_cache = _mesa_new_program_cache(); + #if 0 st_init_cb_clear( st ); st_init_cb_program( st ); @@ -124,6 +126,8 @@ void st_destroy_context( struct st_context *st ) #endif cso_cache_delete( st->cache ); + _mesa_delete_program_cache(st->ctx, st->pixel_transfer_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 3774a999ab..4de70a3b2e 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -28,7 +28,8 @@ #ifndef ST_CONTEXT_H #define ST_CONTEXT_H -#include "mtypes.h" +#include "main/mtypes.h" +#include "shader/prog_cache.h" #include "pipe/p_state.h" @@ -133,6 +134,7 @@ struct st_context struct st_fragment_program *fp; /**< Currently bound fragment program */ struct gl_fragment_program *pixel_transfer_program; + struct gl_program_cache *pixel_transfer_cache; /** * Buffer object which stores the ctx->Current.Attrib[] values. -- cgit v1.2.3 From d6a739f6b0658414a81715bf690159f7cfdb4961 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 30 Oct 2007 16:13:37 -0600 Subject: Use program serial numbers to avoid re-generating fragment programs for glDrawPixels. --- src/mesa/state_tracker/st_atom_pixeltransfer.c | 14 ++++--- src/mesa/state_tracker/st_cb_drawpixels.c | 52 +++++++++++++++++--------- src/mesa/state_tracker/st_cb_program.c | 6 ++- src/mesa/state_tracker/st_context.c | 4 +- src/mesa/state_tracker/st_context.h | 10 ++++- 5 files changed, 58 insertions(+), 28 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index b190c39343..8cf340e685 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -42,6 +42,7 @@ #include "shader/prog_print.h" #include "st_context.h" +#include "st_program.h" @@ -79,8 +80,6 @@ is_identity(const GLfloat m[16]) static void make_state_key(GLcontext *ctx, struct state_key *key) { - /*GLuint i, j;*/ - memset(key, 0, sizeof(*key)); if (ctx->Pixel.RedBias != 0.0 || ctx->Pixel.RedScale != 1.0 || @@ -189,6 +188,8 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) inst[ic].SrcReg[0].Index = FRAG_RESULT_COLR; ic++; + /* XXX reimplement in terms of MUL/MAD (see t_vp_build.c) */ + /* DP4 result.color.x, tmp0, matrow0; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; @@ -268,6 +269,9 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) +/** + * Update st->pixel_xfer.program in response to new pixel-transfer state. + */ static void update_pixel_transfer(struct st_context *st) { @@ -277,14 +281,14 @@ update_pixel_transfer(struct st_context *st) make_state_key(st->ctx, &key); fp = (struct gl_fragment_program *) - _mesa_search_program_cache(st->pixel_transfer_cache, &key, sizeof(key)); + _mesa_search_program_cache(st->pixel_xfer.cache, &key, sizeof(key)); if (!fp) { fp = get_pixel_transfer_program(st->ctx, &key); - _mesa_program_cache_insert(st->ctx, st->pixel_transfer_cache, + _mesa_program_cache_insert(st->ctx, st->pixel_xfer.cache, &key, sizeof(key), &fp->Base); } - st->pixel_transfer_program = fp; + st->pixel_xfer.program = (struct st_fragment_program *) fp; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 3359338385..c74c8fa641 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -182,30 +182,48 @@ make_drawpix_fragment_shader(struct st_context *st) { GLcontext *ctx = st->ctx; struct st_fragment_program *stfp; - struct gl_program *p; - /* - * XXX Use st_program's serial numbers to determine when the - * user-provided program and pixel-transfer program to avoid - * needless combining/translation here. - */ + if (st->pixel_xfer.program->serialNo == st->pixel_xfer.xfer_prog_sn + && st->fp->serialNo == st->pixel_xfer.user_prog_sn) { + /* the pixel tranfer program has not changed and the user-defined + * shader has not changed, so re-use the combined program. + */ + stfp = st->pixel_xfer.combined_prog; + } + else { + /* Concatenate the pixel transfer program with the current user- + * defined shader. + */ + stfp = (struct st_fragment_program *) + _mesa_combine_programs(ctx, + &st->pixel_xfer.program->Base.Base, + &st->fp->Base.Base); - p = _mesa_combine_programs(ctx, - &st->pixel_transfer_program->Base, - &ctx->FragmentProgram._Current->Base); #if 0 - _mesa_print_program(p); - printf("InputsRead: 0x%x\n", p->InputsRead); - printf("OutputsWritten: 0x%x\n", p->OutputsWritten); - _mesa_print_parameter_list(p->Parameters); + { + struct gl_program *p = &stfp->Base.Base; + _mesa_print_program(p); + printf("InputsRead: 0x%x\n", p->InputsRead); + printf("OutputsWritten: 0x%x\n", p->OutputsWritten); + _mesa_print_parameter_list(p->Parameters); + } #endif - stfp = (struct st_fragment_program *) p; - st_translate_fragment_program(st, stfp, NULL, - stfp->tokens, ST_MAX_SHADER_TOKENS); + /* translate to TGSI tokens */ + st_translate_fragment_program(st, stfp, NULL, + stfp->tokens, ST_MAX_SHADER_TOKENS); + /* save new program, update serial numbers */ + st->pixel_xfer.xfer_prog_sn = st->pixel_xfer.program->serialNo; + st->pixel_xfer.user_prog_sn = st->fp->serialNo; + st->pixel_xfer.combined_prog_sn = stfp->serialNo; + st->pixel_xfer.combined_prog = stfp; + } - st_upload_constants( st, p->Parameters, PIPE_SHADER_FRAGMENT ); + /* Ideally we'd have updated the pipe constants during the normal + * st/atom mechanism. But we can't since this is specific to glDrawPixels. + */ + st_upload_constants(st, stfp->Base.Base.Parameters, PIPE_SHADER_FRAGMENT); return stfp; } diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index a330c1c922..aed6b1ee97 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -44,6 +44,8 @@ #include "st_atom_shader.h" +static GLuint SerialNo = 1; + /** * Called via ctx->Driver.BindProgram() to bind an ARB vertex or @@ -91,7 +93,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->serialNo = 1; + prog->serialNo = SerialNo++; return _mesa_init_vertex_program( ctx, &prog->Base, @@ -103,7 +105,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->serialNo = 1; + prog->serialNo = SerialNo++; return _mesa_init_fragment_program( ctx, &prog->Base, diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index e872e8b12c..c7398233d8 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -92,7 +92,7 @@ struct st_context *st_create_context( GLcontext *ctx, st->haveFramebufferRegions = GL_TRUE; - st->pixel_transfer_cache = _mesa_new_program_cache(); + st->pixel_xfer.cache = _mesa_new_program_cache(); #if 0 st_init_cb_clear( st ); @@ -126,7 +126,7 @@ void st_destroy_context( struct st_context *st ) #endif cso_cache_delete( st->cache ); - _mesa_delete_program_cache(st->ctx, st->pixel_transfer_cache); + _mesa_delete_program_cache(st->ctx, st->pixel_xfer.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 4de70a3b2e..8bbfb0d6fe 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -133,8 +133,14 @@ struct st_context struct st_vertex_program *vp; /**< Currently bound vertex program */ struct st_fragment_program *fp; /**< Currently bound fragment program */ - struct gl_fragment_program *pixel_transfer_program; - struct gl_program_cache *pixel_transfer_cache; + struct { + struct gl_program_cache *cache; + struct st_fragment_program *program; /**< cur pixel transfer prog */ + GLuint xfer_prog_sn; /**< pixel xfer program serial no. */ + GLuint user_prog_sn; /**< user fragment program serial no. */ + struct st_fragment_program *combined_prog; + GLuint combined_prog_sn; + } pixel_xfer; /** * Buffer object which stores the ctx->Current.Attrib[] values. -- cgit v1.2.3 From 520c71161ad0929a4b43e8e1e75067e10920f596 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 30 Oct 2007 18:38:32 -0600 Subject: Implement shader concatenation for glBitmap. --- src/mesa/state_tracker/st_cb_drawpixels.c | 114 ++++++++++++++++++++---------- src/mesa/state_tracker/st_context.h | 6 ++ 2 files changed, 81 insertions(+), 39 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 1864d65ee8..ffaa34d7d3 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -59,28 +59,22 @@ /** - * Create a simple fragment shader that does a TEX() instruction to get - * the fragment color. - * If bitmapMode, use KIL instruction to kill the "0-pixels". + * Make fragment program for glBitmap: + * Sample the texture and kill the fragment if the bit is 0. + * This program will be combined with the user's fragment program. */ static struct st_fragment_program * -make_bitmap_fragment_shader(struct st_context *st) +make_bitmap_fragment_program(GLcontext *ctx) { - /* only make programs once and re-use */ - static struct st_fragment_program *prog = NULL; - GLcontext *ctx = st->ctx; struct st_fragment_program *stfp; struct gl_program *p; GLuint ic = 0; - if (prog) - return prog; - p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); if (!p) return NULL; - p->NumInstructions = 6; + p->NumInstructions = 5; p->Instructions = _mesa_alloc_instructions(p->NumInstructions); if (!p->Instructions) { @@ -89,11 +83,6 @@ make_bitmap_fragment_shader(struct st_context *st) } _mesa_init_instructions(p->Instructions, p->NumInstructions); - /* - * XXX, we need to compose this fragment shader with the current - * user-provided fragment shader so the fragment program is applied - * to the fragments which aren't culled. - */ /* TEX tmp0, fragment.texcoord[0], texture[0], 2D; */ p->Instructions[ic].Opcode = OPCODE_TEX; p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY; @@ -133,34 +122,84 @@ make_bitmap_fragment_shader(struct st_context *st) p->Instructions[ic].SrcReg[0].Index = 0; ic++; - /* MOV result.color, fragment.color */ - p->Instructions[ic].Opcode = OPCODE_MOV; - p->Instructions[ic].DstReg.File = PROGRAM_OUTPUT; - p->Instructions[ic].DstReg.Index = FRAG_RESULT_COLR; - p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT; - p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_COL0; - ic++; - /* END; */ p->Instructions[ic++].Opcode = OPCODE_END; assert(ic == p->NumInstructions); - p->InputsRead = FRAG_BIT_TEX0 | FRAG_BIT_COL0; - p->OutputsWritten = (1 << FRAG_RESULT_COLR); + p->InputsRead = FRAG_BIT_TEX0; + p->OutputsWritten = 0x0; stfp = (struct st_fragment_program *) p; - st_translate_fragment_program(st, stfp, NULL, + st_translate_fragment_program(ctx->st, stfp, NULL, stfp->tokens, ST_MAX_SHADER_TOKENS); - prog = stfp; + return stfp; +} + + +/** + * Combine basic bitmap fragment program with the user-defined program. + */ +static struct st_fragment_program * +combined_bitmap_fragment_program(GLcontext *ctx) +{ + struct st_context *st = ctx->st; + struct st_fragment_program *stfp; + + if (!st->bitmap.program) { + /* create the basic bitmap fragment program */ + st->bitmap.program = make_bitmap_fragment_program(ctx); + } + + if (st->bitmap.user_prog_sn == st->fp->serialNo) { + /* re-use */ + stfp = st->bitmap.combined_prog; + } + else { + /* Concatenate the bitmap program with the current user-defined program. + */ + stfp = (struct st_fragment_program *) + _mesa_combine_programs(ctx, + &st->bitmap.program->Base.Base, + &st->fp->Base.Base); + +#if 0 + { + struct gl_program *p = &stfp->Base.Base; + printf("Combined bitmap program:\n"); + _mesa_print_program(p); + printf("InputsRead: 0x%x\n", p->InputsRead); + printf("OutputsWritten: 0x%x\n", p->OutputsWritten); + _mesa_print_parameter_list(p->Parameters); + } +#endif + + /* translate to TGSI tokens */ + st_translate_fragment_program(st, stfp, NULL, + stfp->tokens, ST_MAX_SHADER_TOKENS); + + /* save new program, update serial numbers */ + st->bitmap.user_prog_sn = st->fp->serialNo; + st->bitmap.combined_prog = stfp; + } + + /* Ideally we'd have updated the pipe constants during the normal + * st/atom mechanism. But we can't since this is specific to glBitmap. + */ + st_upload_constants(st, stfp->Base.Base.Parameters, PIPE_SHADER_FRAGMENT); return stfp; } + +/** + * Make fragment shader for glDraw/CopyPixels. This shader is made + * by combining the pixel transfer shader with the user-defined shader. + */ static struct st_fragment_program * -make_drawpix_fragment_shader(GLcontext *ctx) +combined_drawpix_fragment_program(GLcontext *ctx) { struct st_context *st = ctx->st; struct st_fragment_program *stfp; @@ -168,13 +207,13 @@ make_drawpix_fragment_shader(GLcontext *ctx) if (st->pixel_xfer.program->serialNo == st->pixel_xfer.xfer_prog_sn && st->fp->serialNo == st->pixel_xfer.user_prog_sn) { /* the pixel tranfer program has not changed and the user-defined - * shader has not changed, so re-use the combined program. + * program has not changed, so re-use the combined program. */ stfp = st->pixel_xfer.combined_prog; } else { /* Concatenate the pixel transfer program with the current user- - * defined shader. + * defined program. */ stfp = (struct st_fragment_program *) _mesa_combine_programs(ctx, @@ -241,7 +280,7 @@ make_fragment_shader_z(struct st_context *st) } _mesa_init_instructions(p->Instructions, p->NumInstructions); - /* TEX result.color, fragment.texcoord[0], texture[0], 2D; */ + /* TEX result.depth, fragment.texcoord[0], texture[0], 2D; */ p->Instructions[ic].Opcode = OPCODE_TEX; p->Instructions[ic].DstReg.File = PROGRAM_OUTPUT; p->Instructions[ic].DstReg.Index = FRAG_RESULT_DEPR; @@ -945,7 +984,7 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } else { ps = st->state.framebuffer.cbufs[0]; - stfp = make_drawpix_fragment_shader(ctx); + stfp = combined_drawpix_fragment_program(ctx); stvp = make_vertex_shader(ctx->st, GL_FALSE); color = NULL; } @@ -1122,16 +1161,13 @@ static void st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap ) { - struct st_vertex_program *stvp; struct st_fragment_program *stfp; + struct st_vertex_program *stvp; struct st_context *st = ctx->st; struct pipe_mipmap_tree *mt; - /* create the fragment program */ - stfp = make_bitmap_fragment_shader(ctx->st); - - /* and vertex program */ stvp = make_vertex_shader(ctx->st, GL_TRUE); + stfp = combined_bitmap_fragment_program(ctx); st_validate_state(st); @@ -1248,7 +1284,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, if (type == GL_COLOR) { rbRead = st_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer); color = NULL; - stfp = make_drawpix_fragment_shader(ctx); + stfp = combined_drawpix_fragment_program(ctx); stvp = make_vertex_shader(ctx->st, GL_FALSE); } else { diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 8bbfb0d6fe..7ab69df7c7 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -142,6 +142,12 @@ struct st_context GLuint combined_prog_sn; } pixel_xfer; + 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; + /** * Buffer object which stores the ctx->Current.Attrib[] values. * Used for vertex array drawing when we we need an attribute for -- cgit v1.2.3 From 794e03d3926614036d285f2033d8708c7667814a Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 2 Nov 2007 13:22:22 -0600 Subject: Introduce st_framebuffer type and st_create_framebuffer(), st_make_current() --- src/mesa/state_tracker/st_context.c | 23 +++++++++++++++++++++++ src/mesa/state_tracker/st_context.h | 10 ++++++++++ src/mesa/state_tracker/st_public.h | 8 ++++++++ 3 files changed, 41 insertions(+) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 1d129ad077..db933b86e4 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -155,6 +155,29 @@ void st_destroy_context( struct st_context *st ) } +struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual ) +{ + struct st_framebuffer *stfb + = CALLOC_STRUCT(st_framebuffer); + if (stfb) { + } + return stfb; +} + + +void st_make_current(struct st_context *st, + struct st_framebuffer *draw, + struct st_framebuffer *read) +{ + if (st) { + _mesa_make_current(st->ctx, &draw->Base, &read->Base); + } + else { + _mesa_make_current(NULL, NULL, NULL); + } +} + + void st_init_driver_functions(struct dd_function_table *functions) { diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 7ab69df7c7..9b232827f4 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -167,6 +167,16 @@ static INLINE struct st_context *st_context(GLcontext *ctx) } +/** + * Wrapper for GLframebuffer, nothing extra for now. + * This is an opaque type to the outside world. + */ +struct st_framebuffer +{ + GLframebuffer Base; +}; + + extern void st_init_driver_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index 1cc6e6e40e..94d1cdfde4 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -31,6 +31,8 @@ #include "mtypes.h" struct st_context; +struct st_framebuffer; + struct pipe_context; struct st_context *st_create_context( GLcontext *ctx, @@ -44,6 +46,12 @@ void st_destroy_context( struct st_context *st ); void st_destroy_context2( struct st_context *st ); +struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual ); + +void st_make_current(struct st_context *st, + struct st_framebuffer *draw, + struct st_framebuffer *read); + void st_invalidate_state(GLcontext * ctx, GLuint new_state); void st_flush( struct st_context *st ); -- cgit v1.2.3 From e39f1b4cbea6d41dc09430bd3d811cb7bbdea5f8 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 5 Nov 2007 15:59:55 -0700 Subject: Update xlib driver to use newer state tracker context/framebuffer functions. XMesaContext has an st_context * which contains a mesa context. --- src/mesa/drivers/dri/intel_winsys/intel_screen.c | 2 +- src/mesa/pipe/xlib/fakeglx.c | 17 ++- src/mesa/pipe/xlib/xm_api.c | 160 ++++++++++------------- src/mesa/pipe/xlib/xmesaP.h | 31 ++++- src/mesa/state_tracker/st_context.c | 7 + src/mesa/state_tracker/st_context.h | 3 +- src/mesa/state_tracker/st_framebuffer.c | 84 ++++++------ src/mesa/state_tracker/st_public.h | 9 +- 8 files changed, 170 insertions(+), 143 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_screen.c b/src/mesa/drivers/dri/intel_winsys/intel_screen.c index fa5c19ecd7..899988340e 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_screen.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_screen.c @@ -283,7 +283,7 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv, if (!intelfb) return GL_FALSE; - intelfb->stfb = st_create_framebuffer(mesaVis); + intelfb->stfb = st_create_framebuffer(mesaVis, GL_TRUE, (void*) intelfb); if (!intelfb->stfb) { free(intelfb); return GL_FALSE; diff --git a/src/mesa/pipe/xlib/fakeglx.c b/src/mesa/pipe/xlib/fakeglx.c index 7a170b4d3d..d7e7b292d1 100644 --- a/src/mesa/pipe/xlib/fakeglx.c +++ b/src/mesa/pipe/xlib/fakeglx.c @@ -51,6 +51,9 @@ #include "version.h" #include "xfonts.h" #include "xmesaP.h" +#include "state_tracker/st_context.h" +#include "state_tracker/st_public.h" + #ifdef __VMS #define _mesa_sprintf sprintf @@ -1617,7 +1620,7 @@ Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst, if (MakeCurrent_PrevContext == src) { _mesa_Flush(); } - _mesa_copy_context( &(xm_src->mesa), &(xm_dst->mesa), (GLuint) mask ); + st_copy_context_state( xm_src->st, xm_dst->st, (GLuint) mask ); } @@ -2383,16 +2386,16 @@ Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute, switch (attribute) { case GLX_WIDTH: - *value = xmbuf->mesa_buffer.Width; + *value = xmesa_buffer_width(xmbuf); break; case GLX_HEIGHT: - *value = xmbuf->mesa_buffer.Height; + *value = xmesa_buffer_width(xmbuf); break; case GLX_PRESERVED_CONTENTS: *value = True; break; case GLX_LARGEST_PBUFFER: - *value = xmbuf->mesa_buffer.Width * xmbuf->mesa_buffer.Height; + *value = xmesa_buffer_width(xmbuf) * xmesa_buffer_height(xmbuf); break; case GLX_FBCONFIG_ID: *value = xmbuf->xm_visual->visinfo->visualid; @@ -2762,13 +2765,13 @@ Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, un *value = True; break; case GLX_LARGEST_PBUFFER_SGIX: - *value = xmbuf->mesa_buffer.Width * xmbuf->mesa_buffer.Height; + *value = xmesa_buffer_width(xmbuf) * xmesa_buffer_height(xmbuf); break; case GLX_WIDTH_SGIX: - *value = xmbuf->mesa_buffer.Width; + *value = xmesa_buffer_width(xmbuf); break; case GLX_HEIGHT_SGIX: - *value = xmbuf->mesa_buffer.Height; + *value = xmesa_buffer_height(xmbuf); break; case GLX_EVENT_MASK_SGIX: *value = 0; /* XXX might be wrong */ diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c index 7f144a5d32..abd0b4f292 100644 --- a/src/mesa/pipe/xlib/xm_api.c +++ b/src/mesa/pipe/xlib/xm_api.c @@ -300,6 +300,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, XMesaVisual vis, XMesaColormap cmap) { XMesaBuffer b; + GLframebuffer *fb; ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER); @@ -312,8 +313,13 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, b->type = type; b->cmap = cmap; - _mesa_initialize_framebuffer(&b->mesa_buffer, &vis->mesa_visual); - b->mesa_buffer.Delete = xmesa_delete_framebuffer; + /* + * Create framebuffer, but we'll plug in our own renderbuffers below. + */ + b->stfb = st_create_framebuffer(&vis->mesa_visual, GL_FALSE, (void *) b); + fb = &b->stfb->Base; + + fb->Delete = xmesa_delete_framebuffer; /* * XXX we want to create surfaces for pipe, not renderbuffers for Mesa. @@ -330,8 +336,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, b->frontxrb->Parent = b; b->frontxrb->drawable = d; b->frontxrb->pixmap = (XMesaPixmap) d; - _mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_FRONT_LEFT, - &b->frontxrb->St.Base); + _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &b->frontxrb->St.Base); #if 0 /* sketch... */ { struct pipe_surface *front_surf; @@ -339,8 +344,6 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, } #endif - - /* * Back renderbuffer */ @@ -355,8 +358,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, /* determine back buffer implementation */ b->db_mode = vis->ximage_flag ? BACK_XIMAGE : BACK_PIXMAP; - _mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_BACK_LEFT, - &b->backxrb->St.Base); + _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &b->backxrb->St.Base); } /* @@ -379,34 +381,34 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, /* combined depth/stencil */ struct gl_renderbuffer *rb = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT); - _mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_DEPTH, rb); - _mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_STENCIL, rb); + _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb); + _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb); } else { if (vis->mesa_visual.depthBits > 0) { struct gl_renderbuffer *rb = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT32); - _mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_DEPTH, rb); + _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb); } if (vis->mesa_visual.stencilBits > 0) { struct gl_renderbuffer *rb = st_new_renderbuffer_fb(GL_STENCIL_INDEX8_EXT); - _mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_STENCIL, rb); + _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb); } } if (vis->mesa_visual.accumRedBits > 0) { struct gl_renderbuffer *rb = st_new_renderbuffer_fb(GL_RGBA16); - _mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_ACCUM, rb); + _mesa_add_renderbuffer(fb, BUFFER_ACCUM, rb); } /* * Other renderbuffer (depth, stencil, etc) */ - _mesa_add_soft_renderbuffers(&b->mesa_buffer, + _mesa_add_soft_renderbuffers(fb, GL_FALSE, /* color */ GL_FALSE, /*vis->mesa_visual.haveDepthBuffer,*/ GL_FALSE, /* stencil */ @@ -454,7 +456,7 @@ xmesa_free_buffer(XMesaBuffer buffer) for (b = XMesaBufferList; b; b = b->Next) { if (b == buffer) { - struct gl_framebuffer *fb = &buffer->mesa_buffer; + struct gl_framebuffer *fb = &buffer->stfb->Base; /* unlink buffer from list */ if (prev) @@ -1112,11 +1114,12 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, * Convert an RGBA color to a pixel value. */ unsigned long -xmesa_color_to_pixel(GLcontext *ctx, +xmesa_color_to_pixel(XMesaContext xmesa, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLuint pixelFormat) { - XMesaContext xmesa = XMESA_CONTEXT(ctx); + GLcontext *ctx = xmesa->st->ctx; + switch (pixelFormat) { case PF_Index: return 0; @@ -1444,9 +1447,11 @@ PUBLIC XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) { static GLboolean firstTime = GL_TRUE; + struct pipe_context *pipe; XMesaContext c; GLcontext *mesaCtx; - struct dd_function_table functions; + + (void) xmesa_init_driver_functions; if (firstTime) { _glthread_INIT_MUTEX(_xmesa_lock); @@ -1458,29 +1463,20 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) if (!c) return NULL; - mesaCtx = &(c->mesa); - - /* initialize with default driver functions, then plug in XMesa funcs */ -#if 0 - _mesa_init_driver_functions(&functions); -#else - memset(&functions, 0, sizeof(functions)); -#endif - xmesa_init_driver_functions(v, &functions); - st_init_driver_functions(&functions); + pipe = xmesa_create_softpipe( c ); - if (!_mesa_initialize_context(mesaCtx, &v->mesa_visual, - share_list ? &(share_list->mesa) : (GLcontext *) NULL, - &functions, (void *) c)) { - _mesa_free(c); - return NULL; - } + c->st = st_create_context2(pipe, &v->mesa_visual, + share_list ? share_list->st : NULL); + mesaCtx = c->st->ctx; + c->st->ctx->DriverCtx = c; +#if 00 _mesa_enable_sw_extensions(mesaCtx); _mesa_enable_1_3_extensions(mesaCtx); _mesa_enable_1_4_extensions(mesaCtx); _mesa_enable_1_5_extensions(mesaCtx); _mesa_enable_2_0_extensions(mesaCtx); +#endif #ifdef XFree86Server /* If we're running in the X server, do bounds checking to prevent @@ -1496,25 +1492,18 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) c->display = v->display; c->pixelformat = v->dithered_pf; /* Dithering is enabled by default */ - st_create_context( mesaCtx, - xmesa_create_softpipe( c ) ); - /* override these functions, as if the xlib driver were derived from * the softpipe driver. */ -#if 0 - mesaCtx->st->pipe->surface_alloc = xmesa_surface_alloc; - mesaCtx->st->pipe->is_format_supported = xmesa_is_format_supported; -#endif - mesaCtx->st->pipe->get_tile = xmesa_get_tile; - mesaCtx->st->pipe->put_tile = xmesa_put_tile; - mesaCtx->st->pipe->get_tile_rgba = xmesa_get_tile_rgba; - mesaCtx->st->pipe->put_tile_rgba = xmesa_put_tile_rgba; + pipe->get_tile = xmesa_get_tile; + pipe->put_tile = xmesa_put_tile; + pipe->get_tile_rgba = xmesa_get_tile_rgba; + pipe->put_tile_rgba = xmesa_put_tile_rgba; - mesaCtx->st->haveFramebufferRegions = GL_FALSE; + c->st->haveFramebufferRegions = GL_FALSE; /* special pipe->clear function */ - mesaCtx->st->pipe->clear = xmesa_clear; + pipe->clear = xmesa_clear; return c; } @@ -1524,10 +1513,8 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) PUBLIC void XMesaDestroyContext( XMesaContext c ) { - GLcontext *mesaCtx = &c->mesa; - - _mesa_free_context_data( mesaCtx ); - _mesa_free( c ); + st_destroy_context2(c->st); + _mesa_free(c); } @@ -1645,7 +1632,7 @@ XMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p, /* get pixmap size, update framebuffer/renderbuffer dims */ xmesa_get_window_size(v->display, b, &width, &height); - _mesa_resize_framebuffer(NULL, &(b->mesa_buffer), width, height); + _mesa_resize_framebuffer(NULL, &(b->stfb->Base), width, height); if (target == 0) { /* examine dims */ @@ -1746,12 +1733,7 @@ xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer) { GLuint width, height; xmesa_get_window_size(drawBuffer->display, drawBuffer, &width, &height); - if (drawBuffer->mesa_buffer.Width != width || - drawBuffer->mesa_buffer.Height != height) { - GLcontext *ctx = xmctx ? &xmctx->mesa : NULL; - _mesa_resize_framebuffer(ctx, &(drawBuffer->mesa_buffer), width, height); - } - drawBuffer->mesa_buffer.Initialized = GL_TRUE; /* XXX TEMPORARY? */ + st_resize_framebuffer(drawBuffer->stfb, width, height); } @@ -1775,6 +1757,8 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, if (!drawBuffer || !readBuffer) return GL_FALSE; /* must specify buffers! */ +#if 0 + /* XXX restore this optimization */ if (&(c->mesa) == _mesa_get_current_context() && c->mesa.DrawBuffer == &drawBuffer->mesa_buffer && c->mesa.ReadBuffer == &readBuffer->mesa_buffer @@ -1782,6 +1766,7 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, /* same context and buffer, do nothing */ return GL_TRUE; } +#endif c->xm_buffer = drawBuffer; @@ -1794,16 +1779,15 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, if (readBuffer != drawBuffer) xmesa_check_and_update_buffer_size(c, readBuffer); - _mesa_make_current(&(c->mesa), - &drawBuffer->mesa_buffer, - &readBuffer->mesa_buffer); + st_make_current(c->st, drawBuffer->stfb, readBuffer->stfb); +#if 0 if (c->xm_visual->mesa_visual.rgbMode) { /* * Must recompute and set these pixel values because colormap * can be different for different windows. */ - c->clearpixel = xmesa_color_to_pixel( &c->mesa, + c->clearpixel = xmesa_color_to_pixel( c, c->clearcolor[0], c->clearcolor[1], c->clearcolor[2], @@ -1811,13 +1795,14 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, c->xm_visual->undithered_pf); XMesaSetForeground(c->display, drawBuffer->cleargc, c->clearpixel); } +#endif /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */ drawBuffer->wasCurrent = GL_TRUE; } else { /* Detach */ - _mesa_make_current( NULL, NULL, NULL ); + st_make_current( NULL, NULL, NULL ); } return GL_TRUE; } @@ -1925,8 +1910,6 @@ GLboolean XMesaSetFXmode( GLint mode ) PUBLIC void XMesaSwapBuffers( XMesaBuffer b ) { - GET_CURRENT_CONTEXT(ctx); - if (!b->backxrb) { /* single buffered */ return; @@ -1935,8 +1918,7 @@ void XMesaSwapBuffers( XMesaBuffer b ) /* If we're swapping the buffer associated with the current context * we have to flush any pending rendering commands first. */ - if (ctx && ctx->DrawBuffer == &(b->mesa_buffer)) - _mesa_notifySwapBuffers(ctx); + st_notify_swapbuffers(b->stfb); if (b->db_mode) { if (b->backxrb->ximage) { @@ -1947,7 +1929,7 @@ void XMesaSwapBuffers( XMesaBuffer b ) XShmPutImage( b->xm_visual->display, b->frontxrb->drawable, b->swapgc, b->backxrb->ximage, 0, 0, - 0, 0, b->mesa_buffer.Width, b->mesa_buffer.Height, + 0, 0, xmesa_buffer_width(b), xmesa_buffer_height(b), False ); /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/ } @@ -1958,7 +1940,8 @@ void XMesaSwapBuffers( XMesaBuffer b ) XMesaPutImage( b->xm_visual->display, b->frontxrb->drawable, b->swapgc, b->backxrb->ximage, 0, 0, - 0, 0, b->mesa_buffer.Width, b->mesa_buffer.Height ); + 0, 0, + xmesa_buffer_width(b), xmesa_buffer_height(b)); /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/ } } @@ -1969,14 +1952,16 @@ void XMesaSwapBuffers( XMesaBuffer b ) b->backxrb->pixmap, /* source drawable */ b->frontxrb->drawable, /* dest. drawable */ b->swapgc, - 0, 0, b->mesa_buffer.Width, b->mesa_buffer.Height, + 0, 0, xmesa_buffer_width(b), xmesa_buffer_height(b), 0, 0 /* dest region */ ); /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/ } - if (b->swAlpha) - _mesa_copy_soft_alpha_renderbuffers(ctx, &b->mesa_buffer); + if (b->swAlpha) { + GET_CURRENT_CONTEXT(ctx); + _mesa_copy_soft_alpha_renderbuffers(ctx, &b->stfb->Base); + } } #if !defined(XFree86Server) XSync( b->xm_visual->display, False ); @@ -1990,21 +1975,18 @@ void XMesaSwapBuffers( XMesaBuffer b ) */ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) { - GET_CURRENT_CONTEXT(ctx); - - /* If we're swapping the buffer associated with the current context - * we have to flush any pending rendering commands first. - */ - if (ctx && ctx->DrawBuffer == &(b->mesa_buffer)) - _mesa_notifySwapBuffers(ctx); - if (!b->backxrb) { /* single buffered */ return; } + /* If we're swapping the buffer associated with the current context + * we have to flush any pending rendering commands first. + */ + st_notify_swapbuffers(b->stfb); + if (b->db_mode) { - int yTop = b->mesa_buffer.Height - y - height; + int yTop = xmesa_buffer_height(b) - y - height; if (b->backxrb->ximage) { /* Copy Ximage from host's memory to server's window */ #if defined(USE_XSHM) && !defined(XFree86Server) @@ -2082,7 +2064,7 @@ GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height, GLint *bytesPerValue, void **buffer ) { struct gl_renderbuffer *rb - = b->mesa_buffer.Attachment[BUFFER_DEPTH].Renderbuffer; + = b->stfb->Base.Attachment[BUFFER_DEPTH].Renderbuffer; if (!rb || !rb->Data) { *width = 0; *height = 0; @@ -2091,9 +2073,9 @@ GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height, return GL_FALSE; } else { - *width = b->mesa_buffer.Width; - *height = b->mesa_buffer.Height; - *bytesPerValue = b->mesa_buffer.Visual.depthBits <= 16 + *width = xmesa_buffer_width(b); + *height = xmesa_buffer_height(b); + *bytesPerValue = b->stfb->Base.Visual.depthBits <= 16 ? sizeof(GLushort) : sizeof(GLuint); *buffer = rb->Data; return GL_TRUE; @@ -2103,11 +2085,11 @@ GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height, void XMesaFlush( XMesaContext c ) { - if (c && c->xm_visual) { + if (c && c->display) { #ifdef XFree86Server /* NOT_NEEDED */ #else - XSync( c->xm_visual->display, False ); + XSync( c->display, False ); #endif } } @@ -2185,7 +2167,7 @@ unsigned long XMesaDitherColor( XMesaContext xmesa, GLint x, GLint y, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ) { - GLcontext *ctx = &xmesa->mesa; + GLcontext *ctx = xmesa->st->ctx; GLint r = (GLint) (red * 255.0F); GLint g = (GLint) (green * 255.0F); GLint b = (GLint) (blue * 255.0F); @@ -2311,7 +2293,7 @@ XMesaBindTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer, if (drawable->TextureFormat == GLX_TEXTURE_FORMAT_NONE_EXT) return; /* BadMatch error */ - rb = drawable->mesa_buffer.Attachment[b].Renderbuffer; + rb = drawable->stfb->Base.Attachment[b].Renderbuffer; if (!rb) { /* invalid buffer */ return; diff --git a/src/mesa/pipe/xlib/xmesaP.h b/src/mesa/pipe/xlib/xmesaP.h index 506db859bb..f1ca2a8fe8 100644 --- a/src/mesa/pipe/xlib/xmesaP.h +++ b/src/mesa/pipe/xlib/xmesaP.h @@ -33,6 +33,8 @@ #include "xm_image.h" #endif #include "state_tracker/st_cb_fbo.h" +#include "state_tracker/st_context.h" +#include "state_tracker/st_public.h" #include "pipe/softpipe/sp_context.h" #include "pipe/softpipe/sp_surface.h" @@ -116,7 +118,8 @@ struct xmesa_visual { * Basically corresponds to a GLXContext. */ struct xmesa_context { - GLcontext mesa; /* the core library context (containment) */ + struct st_context *st; + XMesaVisual xm_visual; /* Describes the buffers */ XMesaBuffer xm_buffer; /* current span/point/line/triangle buffer */ @@ -187,8 +190,8 @@ struct xmesa_renderbuffer * Basically corresponds to a GLXDrawable. */ struct xmesa_buffer { - GLframebuffer mesa_buffer; /* depth, stencil, accum, etc buffers */ - /* This MUST BE FIRST! */ + struct st_framebuffer *stfb; + GLboolean wasCurrent; /* was ever the current buffer? */ XMesaVisual xm_visual; /* the X/Mesa visual */ @@ -458,7 +461,7 @@ extern XMesaBuffer xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis); extern unsigned long -xmesa_color_to_pixel( GLcontext *ctx, +xmesa_color_to_pixel( XMesaContext xmesa, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLuint pixelFormat ); @@ -492,7 +495,7 @@ xmesa_renderbuffer(struct gl_renderbuffer *rb) static INLINE XMesaContext XMESA_CONTEXT(GLcontext *ctx) { - return (XMesaContext) ctx; + return (XMesaContext) ctx->DriverCtx; } @@ -502,9 +505,10 @@ XMESA_CONTEXT(GLcontext *ctx) * XXX should use inlined function for better type safety. */ static INLINE XMesaBuffer -XMESA_BUFFER(GLframebuffer *b) +XMESA_BUFFER(GLframebuffer *fb) { - return (XMesaBuffer) b; + struct st_framebuffer *stfb = (struct st_framebuffer *) fb; + return (XMesaBuffer) st_framebuffer_private(stfb); } @@ -564,4 +568,17 @@ xmesa_put_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, extern struct pipe_surface * xmesa_create_front_surface(XMesaVisual vis, Window win); +static INLINE GLuint +xmesa_buffer_width(XMesaBuffer b) +{ + return b->stfb->Base.Width; +} + +static INLINE GLuint +xmesa_buffer_height(XMesaBuffer b) +{ + return b->stfb->Base.Height; +} + + #endif diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index a8cc618d77..138f18aa99 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -174,6 +174,13 @@ void st_make_current(struct st_context *st, } +void st_copy_context_state(struct st_context *dst, + struct st_context *src, + uint mask) +{ + _mesa_copy_context(dst->ctx, src->ctx, mask); +} + void st_init_driver_functions(struct dd_function_table *functions) { diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 9b232827f4..30407768b9 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -168,12 +168,13 @@ static INLINE struct st_context *st_context(GLcontext *ctx) /** - * Wrapper for GLframebuffer, nothing extra for now. + * Wrapper for GLframebuffer. * This is an opaque type to the outside world. */ struct st_framebuffer { GLframebuffer Base; + void *Private; }; diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 2e7687d9c9..ec120ba39a 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -35,7 +35,9 @@ #include "st_cb_fbo.h" -struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual ) +struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, + boolean createRenderbuffers, + void *private) { struct st_framebuffer *stfb = CALLOC_STRUCT(st_framebuffer); @@ -46,46 +48,48 @@ struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual ) _mesa_initialize_framebuffer(&stfb->Base, visual); - { - /* fake frontbuffer */ - /* XXX allocation should only happen in the unusual case - it's actually needed */ - struct gl_renderbuffer *rb = st_new_renderbuffer_fb(rgbFormat); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb); + if (createRenderbuffers) { + { + /* fake frontbuffer */ + /* XXX allocation should only happen in the unusual case + it's actually needed */ + struct gl_renderbuffer *rb = st_new_renderbuffer_fb(rgbFormat); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb); + } + + if (visual->doubleBufferMode) { + struct gl_renderbuffer *rb = st_new_renderbuffer_fb(rgbFormat); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb); + } + + if (visual->depthBits == 24 && visual->stencilBits == 8) { + /* combined depth/stencil buffer */ + struct gl_renderbuffer *depthStencilRb + = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT); + /* note: bind RB to two attachment points */ + _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL,depthStencilRb); + } + else if (visual->depthBits == 16) { + /* just 16-bit depth buffer, no hw stencil */ + struct gl_renderbuffer *depthRb + = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT16); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); + } + + + /* now add any/all software-based renderbuffers we may need */ + _mesa_add_soft_renderbuffers(&stfb->Base, + GL_FALSE, /* never sw color */ + GL_FALSE, /* never sw depth */ + swStencil, visual->accumRedBits > 0, + GL_FALSE, /* never sw alpha */ + GL_FALSE /* never sw aux */ ); } - if (visual->doubleBufferMode) { - struct gl_renderbuffer *rb = st_new_renderbuffer_fb(rgbFormat); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb); - } - - if (visual->depthBits == 24 && visual->stencilBits == 8) { - /* combined depth/stencil buffer */ - struct gl_renderbuffer *depthStencilRb - = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT); - /* note: bind RB to two attachment points */ - _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL,depthStencilRb); - } - else if (visual->depthBits == 16) { - /* just 16-bit depth buffer, no hw stencil */ - struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT16); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); - } - - - /* now add any/all software-based renderbuffers we may need */ - _mesa_add_soft_renderbuffers(&stfb->Base, - GL_FALSE, /* never sw color */ - GL_FALSE, /* never sw depth */ - swStencil, visual->accumRedBits > 0, - GL_FALSE, /* never sw alpha */ - GL_FALSE /* never sw aux */ ); - - stfb->Base.Initialized = GL_TRUE; + stfb->Private = private; } return stfb; } @@ -149,3 +153,9 @@ st_notify_swapbuffers(struct st_framebuffer *stfb) } } + +void *st_framebuffer_private( struct st_framebuffer *stfb ) +{ + return stfb->Private; +} + diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index 8162ceeffa..c94e8d32c8 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -53,7 +53,12 @@ void st_destroy_context( struct st_context *st ); void st_destroy_context2( struct st_context *st ); -struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual ); +void st_copy_context_state(struct st_context *dst, struct st_context *src, + uint mask); + +struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, + GLboolean createRenderbuffers, + void *privateData); void st_resize_framebuffer( struct st_framebuffer *stfb, GLuint width, GLuint height ); @@ -61,6 +66,8 @@ void st_resize_framebuffer( struct st_framebuffer *stfb, struct pipe_surface *st_get_framebuffer_surface(struct st_framebuffer *stfb, uint surfIndex); +void *st_framebuffer_private( struct st_framebuffer *stfb ); + void st_unreference_framebuffer( struct st_framebuffer **stfb ); void st_make_current(struct st_context *st, -- cgit v1.2.3 From 9b0f71e37f2ed129997b247d58f8d5e9004f4935 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 5 Nov 2007 16:34:47 -0700 Subject: move st_invalidate_state() prototype to st_context.h --- src/mesa/state_tracker/st_context.h | 2 ++ src/mesa/state_tracker/st_public.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 30407768b9..82e133911f 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -180,6 +180,8 @@ struct st_framebuffer extern void st_init_driver_functions(struct dd_function_table *functions); +void st_invalidate_state(GLcontext * ctx, GLuint new_state); + #define Y_0_TOP 1 diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index b21a8d3886..d81cf60503 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -70,8 +70,6 @@ void st_make_current(struct st_context *st, struct st_framebuffer *draw, struct st_framebuffer *read); -void st_invalidate_state(GLcontext * ctx, GLuint new_state); - void st_flush( struct st_context *st ); void st_notify_swapbuffers(struct st_framebuffer *stfb); -- cgit v1.2.3 From aa880bdfa05d8ff2486ef8266f93dea983b7c6fd Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 16 Nov 2007 17:13:01 -0700 Subject: Reimplement glRasterPos using the private 'draw' module. --- src/mesa/state_tracker/st_cb_rasterpos.c | 440 +++++++++++-------------------- src/mesa/state_tracker/st_context.h | 3 +- 2 files changed, 160 insertions(+), 283 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 5b97c1ee34..5279cb1cd4 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -25,353 +25,229 @@ * **************************************************************************/ - /* - * Authors: - * Brian Paul - */ +/** + * glRasterPos implementation. Basically render a GL_POINT with our + * private draw module. Plug in a special "rasterpos" stage at the end + * of the 'draw' pipeline to capture the results and update the current + * raster pos attributes. + * + * Authors: + * Brian Paul + */ + #include "main/imports.h" -#include "main/feedback.h" #include "main/macros.h" #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" #include "st_draw.h" -#include "st_format.h" -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_winsys.h" +#include "pipe/draw/draw_context.h" +#include "pipe/draw/draw_private.h" #include "shader/prog_instruction.h" +#include "vbo/vbo.h" -static void -setup_vertex_attribs(GLcontext *ctx) +/** + * Our special drawing pipeline stage (replaces rasterization). + */ +struct rastpos_stage { - struct pipe_context *pipe = ctx->st->pipe; - 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 */ - { - struct pipe_vertex_buffer vbuffer; - vbuffer.buffer = ctx->st->default_attrib_buffer; - vbuffer.buffer_offset = 0; - vbuffer.pitch = 0; /* must be zero! */ - vbuffer.max_index = 1; - pipe->set_vertex_buffer(pipe, 0, &vbuffer); - } + struct draw_stage stage; /**< Base class */ + GLcontext *ctx; /**< Rendering context */ - for (slot = 0; slot < vs->state.num_inputs; slot++) { - struct pipe_vertex_element velement; - const GLuint attr = stvp->index_to_input[slot]; + /* vertex attrib info we can setup once and re-use */ + struct gl_client_array array[VERT_ATTRIB_MAX]; + const struct gl_client_array *arrays[VERT_ATTRIB_MAX]; + struct _mesa_prim prim; +}; - 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); - } -} +static INLINE struct rastpos_stage * +rastpos_stage( struct draw_stage *stage ) +{ + return (struct rastpos_stage *) stage; +} static void -setup_feedback(GLcontext *ctx) +rastpos_begin( struct draw_stage *stage ) { - struct pipe_context *pipe = ctx->st->pipe; - const struct pipe_shader_state *vs = &ctx->st->state.vs->state; - struct pipe_feedback_state feedback; - uint i; - - memset(&feedback, 0, sizeof(feedback)); - feedback.enabled = 1; - feedback.interleaved = 1; - feedback.discard = 1; - feedback.num_attribs = 0; - - /* feedback all results from vertex shader */ - for (i = 0; i < vs->num_outputs; i++) { - feedback.attrib[feedback.num_attribs] = i; - feedback.size[feedback.num_attribs] = 4; - feedback.num_attribs++; - } - - if (pipe->set_feedback_state) - pipe->set_feedback_state(pipe, &feedback); + /* no-op */ } +static void +rastpos_end( struct draw_stage *stage ) +{ + /* no-op */ +} - - - -/** - * Clip a point against the view volume. - * - * \param v vertex vector describing the point to clip. - * - * \return zero if outside view volume, or one if inside. - */ -static GLuint -viewclip_point( const GLfloat v[] ) +static void +rastpos_reset_stipple_counter( struct draw_stage *stage ) { - if ( v[0] > v[3] || v[0] < -v[3] - || v[1] > v[3] || v[1] < -v[3] - || v[2] > v[3] || v[2] < -v[3] ) { - return 0; - } - else { - return 1; - } + /* no-op */ } +static void +rastpos_tri( struct draw_stage *stage, struct prim_header *prim ) +{ + /* should never get here */ + assert(0); +} -/** - * Clip a point against the far/near Z clipping planes. - * - * \param v vertex vector describing the point to clip. - * - * \return zero if outside view volume, or one if inside. - */ -static GLuint -viewclip_point_z( const GLfloat v[] ) +static void +rastpos_line( struct draw_stage *stage, struct prim_header *prim ) { - if (v[2] > v[3] || v[2] < -v[3] ) { - return 0; - } - else { - return 1; - } + /* should never get here */ + assert(0); } /** - * Clip a point against the user clipping planes. - * - * \param ctx GL context. - * \param v vertex vector describing the point to clip. - * - * \return zero if the point was clipped, or one otherwise. + * Update a raster pos attribute from the vertex result if it's present, + * else copy the current attrib. */ -static GLuint -userclip_point( GLcontext *ctx, const GLfloat v[] ) +static void +update_attrib(GLcontext *ctx, const GLuint *outputMapping, + const struct vertex_header *vert, + GLfloat *dest, + GLuint result, GLuint defaultAttrib) { - GLuint p; - - for (p = 0; p < ctx->Const.MaxClipPlanes; p++) { - if (ctx->Transform.ClipPlanesEnabled & (1 << p)) { - GLfloat dot = v[0] * ctx->Transform._ClipUserPlane[p][0] - + v[1] * ctx->Transform._ClipUserPlane[p][1] - + v[2] * ctx->Transform._ClipUserPlane[p][2] - + v[3] * ctx->Transform._ClipUserPlane[p][3]; - if (dot < 0.0F) { - return 0; - } - } - } - - return 1; + const GLfloat *src; + const GLuint k = outputMapping[result]; + if (k != ~0) + src = vert->data[k]; + else + src = ctx->Current.Attrib[defaultAttrib]; + COPY_4V(dest, src); } /** - * Update the current raster position. - * Do clip testing, etc. here. + * Normally, this function would render a GL_POINT. */ static void -update_rasterpos(GLcontext *ctx, - const float clipPos[4], - const float color0[4], - const float color1[4], - const float *fog, - const float *tex) +rastpos_point(struct draw_stage *stage, struct prim_header *prim) { - uint i; - float d, ndc[3]; - - /* clip to view volume */ - if (ctx->Transform.RasterPositionUnclipped) { - /* GL_IBM_rasterpos_clip: only clip against Z */ - if (viewclip_point_z(clipPos) == 0) { - ctx->Current.RasterPosValid = GL_FALSE; - return; - } - } - else if (viewclip_point(clipPos) == 0) { - /* Normal OpenGL behaviour */ - ctx->Current.RasterPosValid = GL_FALSE; - return; - } - - /* clip to user clipping planes */ - if (ctx->Transform.ClipPlanesEnabled && !userclip_point(ctx, clipPos)) { - ctx->Current.RasterPosValid = GL_FALSE; - return; - } + struct rastpos_stage *rs = rastpos_stage(stage); + GLcontext *ctx = rs->ctx; + struct st_context *st = ctx->st; + const GLfloat height = ctx->DrawBuffer->Height; + const GLuint *outputMapping = st->vertex_result_to_slot; + const GLfloat *pos; + GLuint i; + + /* if we get here, we didn't get clipped */ + ctx->Current.RasterPosValid = GL_TRUE; + /* update raster pos */ + pos = prim->v[0]->data[0]; + ctx->Current.RasterPos[0] = pos[0]; + ctx->Current.RasterPos[1] = height - 1 - pos[1]; + ctx->Current.RasterPos[2] = pos[2]; + ctx->Current.RasterPos[3] = pos[3]; - /* - * update current raster position - */ - /* ndc = clip / W */ - d = (clipPos[3] == 0.0F) ? 1.0F : 1.0F / clipPos[3]; - ndc[0] = clipPos[0] * d; - ndc[1] = clipPos[1] * d; - ndc[2] = clipPos[2] * d; - /* wincoord = viewport_mapping(ndc) */ - ctx->Current.RasterPos[0] = (ndc[0] * ctx->Viewport._WindowMap.m[MAT_SX] - + ctx->Viewport._WindowMap.m[MAT_TX]); - ctx->Current.RasterPos[1] = (ndc[1] * ctx->Viewport._WindowMap.m[MAT_SY] - + ctx->Viewport._WindowMap.m[MAT_TY]); - ctx->Current.RasterPos[2] = (ndc[2] * ctx->Viewport._WindowMap.m[MAT_SZ] - + ctx->Viewport._WindowMap.m[MAT_TZ]) - / ctx->DrawBuffer->_DepthMaxF; - ctx->Current.RasterPos[3] = clipPos[3]; - - /* compute raster distance */ -#if 0 - if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) - ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0]; - else { - /* XXX we don't have an eye coord! */ - ctx->Current.RasterDistance = - SQRTF( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] ); - } -#else - ctx->Current.RasterDistance = fog[0]; -#endif - - /* colors and texcoords */ - COPY_4FV(ctx->Current.RasterColor, color0); - COPY_4FV(ctx->Current.RasterSecondaryColor, color1); - for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { - COPY_4FV(ctx->Current.RasterTexCoords + i, tex + i *4); - } + /* update other raster attribs */ + update_attrib(ctx, outputMapping, prim->v[0], + ctx->Current.RasterColor, + VERT_RESULT_COL0, VERT_ATTRIB_COLOR0); - ctx->Current.RasterPosValid = GL_TRUE; + update_attrib(ctx, outputMapping, prim->v[0], + ctx->Current.RasterSecondaryColor, + VERT_RESULT_COL1, VERT_ATTRIB_COLOR1); - if (ctx->RenderMode == GL_SELECT) { - _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] ); + for (i = 0; i < MAX_TEXTURE_UNITS; i++) { + update_attrib(ctx, outputMapping, prim->v[0], + ctx->Current.RasterTexCoords[i], + VERT_RESULT_TEX0 + i, VERT_ATTRIB_TEX0 + i); } } +/** + * Create rasterpos "drawing" stage. + */ +static struct rastpos_stage * +new_draw_rastpos_stage(GLcontext *ctx, struct draw_context *draw) +{ + struct rastpos_stage *rs = CALLOC_STRUCT(rastpos_stage); + + rs->stage.draw = draw; + rs->stage.next = NULL; + rs->stage.begin = rastpos_begin; + rs->stage.point = rastpos_point; + rs->stage.line = rastpos_line; + rs->stage.tri = rastpos_tri; + rs->stage.end = rastpos_end; + rs->stage.reset_stipple_counter = rastpos_reset_stipple_counter; + rs->ctx = ctx; + + return rs; +} + static void st_RasterPos(GLcontext *ctx, const GLfloat v[4]) { - const struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; - float *buf_map; - struct pipe_feedback_buffer fb_buf; + struct st_context *st = ctx->st; + struct draw_context *draw = st->draw; + struct rastpos_stage *rs; - st_validate_state(ctx->st); - - /* setup vertex buffers */ - setup_vertex_attribs(ctx); - - /* - * Load the default attribute buffer with current attribs. - */ - { - 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 */ - pipe->winsys->buffer_data(pipe->winsys, buf, - size, data, - PIPE_BUFFER_USAGE_VERTEX); - /* position */ - pipe->winsys->buffer_subdata(pipe->winsys, buf, - 0, /* offset */ - 4 * sizeof(float), /* size */ - v); /* data */ + if (st->rastpos_stage) { + /* get rastpos stage info */ + rs = rastpos_stage(st->rastpos_stage); } - - - /* setup feedback state */ - setup_feedback(ctx); - - /* setup vertex feedback buffer */ - { - fb_buf.size = 8 * 4 * sizeof(float); - fb_buf.buffer = pipe->winsys->buffer_create(pipe->winsys, 0); - fb_buf.start_offset = 0; - pipe->winsys->buffer_data(pipe->winsys, fb_buf.buffer, - fb_buf.size, - NULL, /* data */ - PIPE_BUFFER_USAGE_VERTEX); - if (pipe->set_feedback_buffer) - pipe->set_feedback_buffer(pipe, 0, &fb_buf); - } - - - /* draw a point */ - pipe->draw_arrays(pipe, GL_POINTS, 0, 1); - - /* get feedback */ - buf_map = (float *) pipe->winsys->buffer_map(pipe->winsys, fb_buf.buffer, - PIPE_BUFFER_FLAG_READ); - - /* extract values and update rasterpos state */ - { - const GLuint *outputMapping = st->vertex_result_to_slot; - const float *pos, *color0, *color1, *fog, *tex0; - float *buf = buf_map; - - assert(outputMapping[VERT_RESULT_HPOS] != ~0); - pos = buf; - buf += 4; - - if (outputMapping[VERT_RESULT_COL0] != ~0) { - color0 = buf; - buf += 4; - } - else { - color0 = ctx->Current.Attrib[VERT_ATTRIB_COLOR0]; + else { + /* create rastpos draw stage */ + GLuint i; + + rs = new_draw_rastpos_stage(ctx, draw); + st->rastpos_stage = &rs->stage; + + /* one-time init */ + for (i = 0; i < VERT_ATTRIB_MAX; i++) { + rs->array[i].Size = 4; + rs->array[i].Type = GL_FLOAT; + rs->array[i].Stride = 0; + rs->array[i].StrideB = 0; + rs->array[i].Ptr = (GLubyte *) ctx->Current.Attrib[i]; + rs->array[i].Enabled = GL_TRUE; + rs->array[i].Normalized = GL_TRUE; + rs->array[i].BufferObj = NULL; + rs->arrays[i] = &rs->array[i]; } - if (outputMapping[VERT_RESULT_COL1] != ~0) { - color1 = buf; - buf += 4; - } - else { - color1 = ctx->Current.Attrib[VERT_ATTRIB_COLOR1]; - } + rs->prim.mode = GL_POINTS; + rs->prim.indexed = 0; + rs->prim.begin = 1; + rs->prim.end = 1; + rs->prim.weak = 0; + rs->prim.start = 0; + rs->prim.count = 1; + } - if (outputMapping[VERT_RESULT_FOGC] != ~0) { - fog = buf; - buf += 4; - } - else { - fog = ctx->Current.Attrib[VERT_ATTRIB_FOG]; - } + /* plug our rastpos stage into the draw module */ + draw_set_rasterize_stage(st->draw, st->rastpos_stage); - if (outputMapping[VERT_RESULT_TEX0] != ~0) { - tex0 = buf; - buf += 4; - } - else { - tex0 = ctx->Current.Attrib[VERT_ATTRIB_TEX0]; - } + /* make sure everything's up to date */ + st_validate_state(ctx->st); - update_rasterpos(ctx, pos, color0, color1, fog, tex0); - } + /* This will get set only if rastpos_point(), above, gets called */ + ctx->Current.RasterPosValid = GL_FALSE; - /* free vertex feedback buffer */ - pipe->winsys->buffer_unmap(pipe->winsys, fb_buf.buffer); - pipe->winsys->buffer_reference(pipe->winsys, &fb_buf.buffer, NULL); + /* All vertex attribs but position were previously initialized above. + * Just plug in position pointer now. + */ + rs->array[0].Ptr = (GLubyte *) v; - /* restore pipe state */ - if (pipe->set_feedback_state) - pipe->set_feedback_state(pipe, &st->state.feedback); + /* draw the point */ + st_feedback_draw_vbo(ctx, rs->arrays, &rs->prim, 1, NULL, 0, 1); } + void st_init_rasterpos_functions(struct dd_function_table *functions) { functions->RasterPos = st_RasterPos; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 82e133911f..a6045230a0 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -68,9 +68,10 @@ struct st_context struct pipe_context *pipe; - struct draw_context *draw; /**< For selection/feedback */ + struct draw_context *draw; /**< For selection/feedback/rastpos only */ struct draw_stage *feedback_stage; /**< For GL_FEEDBACK rendermode */ struct draw_stage *selection_stage; /**< For GL_SELECT rendermode */ + struct draw_stage *rastpos_stage; /**< For glRasterPos */ /* Some state is contained in constant objects. * Other state is just parameter values. -- cgit v1.2.3 From 753db0d8407147393a7b0622ae3fa28f68d0353d Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Fri, 30 Nov 2007 20:48:03 +0100 Subject: Hide texture layout details from the state tracker. pipe->get_tex_surface() has to be used for access to texture image data. --- src/mesa/drivers/dri/intel_winsys/intel_screen.c | 4 +- src/mesa/pipe/failover/fo_context.c | 3 +- src/mesa/pipe/failover/fo_context.h | 2 +- src/mesa/pipe/failover/fo_state.c | 2 +- src/mesa/pipe/i915simple/Makefile | 2 +- src/mesa/pipe/i915simple/i915_context.c | 9 +- src/mesa/pipe/i915simple/i915_context.h | 30 +- src/mesa/pipe/i915simple/i915_state.c | 4 +- src/mesa/pipe/i915simple/i915_state_sampler.c | 29 +- src/mesa/pipe/i915simple/i915_surface.c | 25 +- src/mesa/pipe/i915simple/i915_tex_layout.c | 474 -------------------- src/mesa/pipe/i915simple/i915_tex_layout.h | 16 - src/mesa/pipe/i915simple/i915_texture.c | 539 +++++++++++++++++++++++ src/mesa/pipe/i915simple/i915_texture.h | 16 + src/mesa/pipe/llvm/llvm_entry.c | 2 - src/mesa/pipe/p_context.h | 11 +- src/mesa/pipe/p_inlines.h | 20 + src/mesa/pipe/p_state.h | 42 +- src/mesa/pipe/softpipe/Makefile | 2 +- src/mesa/pipe/softpipe/sp_context.c | 17 +- src/mesa/pipe/softpipe/sp_context.h | 2 +- src/mesa/pipe/softpipe/sp_quad_fs.c | 2 +- src/mesa/pipe/softpipe/sp_state.h | 31 +- src/mesa/pipe/softpipe/sp_state_fs.c | 2 + src/mesa/pipe/softpipe/sp_state_sampler.c | 4 +- src/mesa/pipe/softpipe/sp_surface.c | 25 +- src/mesa/pipe/softpipe/sp_surface.h | 2 +- src/mesa/pipe/softpipe/sp_tex_layout.c | 361 --------------- src/mesa/pipe/softpipe/sp_tex_layout.h | 16 - src/mesa/pipe/softpipe/sp_tex_sample.c | 18 +- src/mesa/pipe/softpipe/sp_texture.c | 425 ++++++++++++++++++ src/mesa/pipe/softpipe/sp_texture.h | 18 + src/mesa/pipe/softpipe/sp_tile_cache.c | 4 +- src/mesa/pipe/softpipe/sp_tile_cache.h | 2 +- src/mesa/pipe/tgsi/exec/tgsi_exec.h | 2 +- src/mesa/sources | 2 +- src/mesa/state_tracker/st_atom_texture.c | 14 +- src/mesa/state_tracker/st_cb_drawpixels.c | 214 +++------ src/mesa/state_tracker/st_cb_fbo.c | 24 +- src/mesa/state_tracker/st_cb_texture.c | 427 +++++++++--------- src/mesa/state_tracker/st_cb_texture.h | 10 +- src/mesa/state_tracker/st_context.h | 22 +- src/mesa/state_tracker/st_mipmap_tree.c | 328 -------------- src/mesa/state_tracker/st_mipmap_tree.h | 118 ----- src/mesa/state_tracker/st_texture.c | 276 ++++++++++++ src/mesa/state_tracker/st_texture.h | 109 +++++ 46 files changed, 1877 insertions(+), 1830 deletions(-) delete mode 100644 src/mesa/pipe/i915simple/i915_tex_layout.c delete mode 100644 src/mesa/pipe/i915simple/i915_tex_layout.h create mode 100644 src/mesa/pipe/i915simple/i915_texture.c create mode 100644 src/mesa/pipe/i915simple/i915_texture.h delete mode 100644 src/mesa/pipe/softpipe/sp_tex_layout.c delete mode 100644 src/mesa/pipe/softpipe/sp_tex_layout.h create mode 100644 src/mesa/pipe/softpipe/sp_texture.c create mode 100644 src/mesa/pipe/softpipe/sp_texture.h delete mode 100644 src/mesa/state_tracker/st_mipmap_tree.c delete mode 100644 src/mesa/state_tracker/st_mipmap_tree.h create mode 100644 src/mesa/state_tracker/st_texture.c create mode 100644 src/mesa/state_tracker/st_texture.h (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_screen.c b/src/mesa/drivers/dri/intel_winsys/intel_screen.c index 01460e5be3..1b520f7135 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_screen.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_screen.c @@ -328,8 +328,8 @@ intelSetTexOffset(__DRIcontext *pDRICtx, int texname, if (!stObj) return; - if (stObj->mt) - st_miptree_release(intel->st->pipe, &stObj->mt); + if (stObj->pt) + st->pipe->texture_release(intel->st->pipe, &stObj->pt); stObj->imageOverride = GL_TRUE; stObj->depthOverride = depth; diff --git a/src/mesa/pipe/failover/fo_context.c b/src/mesa/pipe/failover/fo_context.c index 0cc9cab408..a25563d451 100644 --- a/src/mesa/pipe/failover/fo_context.c +++ b/src/mesa/pipe/failover/fo_context.c @@ -145,7 +145,8 @@ struct pipe_context *failover_create( struct pipe_context *hw, failover->pipe.surface_data = hw->surface_data; failover->pipe.surface_copy = hw->surface_copy; failover->pipe.surface_fill = hw->surface_fill; - failover->pipe.mipmap_tree_layout = hw->mipmap_tree_layout; + failover->pipe.texture_create = hw->texture_create; + failover->pipe.texture_release = hw->texture_release; failover->pipe.flush = hw->flush; failover->dirty = 0; diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index 759b53ccbe..7cf18c9ec1 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -85,7 +85,7 @@ struct failover_context { struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; uint sampler_units[PIPE_MAX_SAMPLERS]; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index 2cd1a50b20..fd6137ba66 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -402,7 +402,7 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) static void failover_set_texture_state(struct pipe_context *pipe, unsigned unit, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { struct failover_context *failover = failover_context(pipe); diff --git a/src/mesa/pipe/i915simple/Makefile b/src/mesa/pipe/i915simple/Makefile index 391a084915..1223b386a3 100644 --- a/src/mesa/pipe/i915simple/Makefile +++ b/src/mesa/pipe/i915simple/Makefile @@ -22,7 +22,7 @@ DRIVER_SOURCES = \ i915_strings.c \ i915_prim_emit.c \ i915_prim_vbuf.c \ - i915_tex_layout.c \ + i915_texture.c \ i915_fpc_emit.c \ i915_fpc_translate.c \ i915_surface.c diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index a0ed3032b1..94649231cf 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -29,7 +29,7 @@ #include "i915_winsys.h" #include "i915_state.h" #include "i915_batch.h" -#include "i915_tex_layout.h" +#include "i915_texture.h" #include "i915_reg.h" #include "pipe/draw/draw_context.h" @@ -357,11 +357,8 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys, i915->pci_id = pci_id; i915->flags.is_i945 = is_i945; - if (i915->flags.is_i945) - i915->pipe.mipmap_tree_layout = i945_miptree_layout; - else - i915->pipe.mipmap_tree_layout = i915_miptree_layout; - + i915->pipe.texture_create = i915_texture_create; + i915->pipe.texture_release = i915_texture_release; i915->dirty = ~0; i915->hardware_dirty = ~0; diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index ee430ebc90..8ed3465be2 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -150,6 +150,34 @@ struct i915_alpha_test_state { unsigned LIS6; }; +struct i915_texture { + struct pipe_texture base; + + /* Derived from the above: + */ + unsigned pitch; + unsigned depth_pitch; /* per-image on i945? */ + unsigned total_height; + + unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; + + /* Explicitly store the offset of each image for each cube face or + * depth value. Pretty much have to accept that hardware formats + * are going to be so diverse that there is no unified way to + * compute the offsets of depth/cube images within a mipmap level, + * so have to store them as a lookup table: + */ + unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */ + + /* Includes image offset tables: + */ + unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS]; + + /* The data is held here: + */ + struct pipe_region *region; +}; + struct i915_context { struct pipe_context pipe; @@ -174,7 +202,7 @@ struct i915_context struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; uint sampler_units[PIPE_MAX_SAMPLERS]; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct i915_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 468d0ce91b..038fd623ea 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -525,11 +525,11 @@ static void i915_set_constant_buffer(struct pipe_context *pipe, static void i915_set_texture_state(struct pipe_context *pipe, unsigned unit, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { struct i915_context *i915 = i915_context(pipe); - i915->texture[unit] = texture; /* ptr, not struct */ + i915->texture[unit] = (struct i915_texture*)texture; /* ptr, not struct */ i915->dirty |= I915_NEW_TEXTURE; } diff --git a/src/mesa/pipe/i915simple/i915_state_sampler.c b/src/mesa/pipe/i915simple/i915_state_sampler.c index 0991e6ac0d..1816d9abdb 100644 --- a/src/mesa/pipe/i915simple/i915_state_sampler.c +++ b/src/mesa/pipe/i915simple/i915_state_sampler.c @@ -46,9 +46,11 @@ static void update_sampler(struct i915_context *i915, uint unit, const struct i915_sampler_state *sampler, - const struct pipe_mipmap_tree *mt, + const struct i915_texture *tex, unsigned state[3] ) { + const struct pipe_texture *pt = &tex->base; + /* Need to do this after updating the maps, which call the * intel_finalize_mipmap_tree and hence can update firstLevel: */ @@ -56,8 +58,8 @@ static void update_sampler(struct i915_context *i915, state[1] = sampler->state[1]; state[2] = sampler->state[2]; - if (mt->format == PIPE_FORMAT_YCBCR || - mt->format == PIPE_FORMAT_YCBCR_REV) + if (pt->format == PIPE_FORMAT_YCBCR || + pt->format == PIPE_FORMAT_YCBCR_REV) state[0] |= SS2_COLORSPACE_CONVERSION; /* 3D textures don't seem to respect the border color. @@ -75,7 +77,7 @@ static void update_sampler(struct i915_context *i915, const unsigned ws = sampler->templ->wrap_s; const unsigned wt = sampler->templ->wrap_t; const unsigned wr = sampler->templ->wrap_r; - if (mt->target == PIPE_TEXTURE_3D && + if (pt->target == PIPE_TEXTURE_3D && (sampler->templ->min_img_filter != PIPE_TEX_FILTER_NEAREST || sampler->templ->mag_img_filter != PIPE_TEX_FILTER_NEAREST) && (ws == PIPE_TEX_WRAP_CLAMP || @@ -105,13 +107,13 @@ void i915_update_samplers( struct i915_context *i915 ) i915->current.sampler_enable_flags = 0x0; for (unit = 0; unit < I915_TEX_UNITS; unit++) { - /* determine unit enable/disable by looking for a bound mipmap tree */ + /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ if (i915->texture[unit]) { update_sampler( i915, unit, i915->sampler[unit], /* sampler state */ - i915->texture[unit], /* mipmap tree */ + i915->texture[unit], /* texture */ i915->current.sampler[unit] /* the result */ ); @@ -179,18 +181,19 @@ static void i915_update_texture(struct i915_context *i915, uint unit, uint state[6]) { - const struct pipe_mipmap_tree *mt = i915->texture[unit]; + const struct i915_texture *tex = i915->texture[unit]; + const struct pipe_texture *pt = &tex->base; uint format, pitch; - const uint width = mt->width0, height = mt->height0, depth = mt->depth0; - const uint num_levels = mt->last_level - mt->first_level; + const uint width = pt->width[0], height = pt->height[0], depth = pt->depth[0]; + const uint num_levels = pt->last_level - pt->first_level; - assert(mt); + assert(tex); assert(width); assert(height); assert(depth); - format = translate_texture_format(mt->format); - pitch = mt->pitch * mt->cpp; + format = translate_texture_format(pt->format); + pitch = tex->pitch * pt->cpp; assert(format); assert(pitch); @@ -217,7 +220,7 @@ i915_update_textures(struct i915_context *i915) uint unit; for (unit = 0; unit < I915_TEX_UNITS; unit++) { - /* determine unit enable/disable by looking for a bound mipmap tree */ + /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ if (i915->texture[unit]) { i915_update_texture(i915, unit, i915->current.texbuffer[unit]); diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index e4a5de00d7..385202507d 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -187,34 +187,35 @@ i915_put_tile(struct pipe_context *pipe, */ static struct pipe_surface * i915_get_tex_surface(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice) { + struct i915_texture *tex = (struct i915_texture *)pt; struct pipe_surface *ps; unsigned offset; /* in bytes */ - offset = mt->level[level].level_offset; + offset = tex->level_offset[level]; - if (mt->target == PIPE_TEXTURE_CUBE) { - offset += mt->level[level].image_offset[face] * mt->cpp; + if (pt->target == PIPE_TEXTURE_CUBE) { + offset += tex->image_offset[level][face] * pt->cpp; } - else if (mt->target == PIPE_TEXTURE_3D) { - offset += mt->level[level].image_offset[zslice] * mt->cpp; + else if (pt->target == PIPE_TEXTURE_3D) { + offset += tex->image_offset[level][zslice] * pt->cpp; } else { assert(face == 0); assert(zslice == 0); } - ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format); + ps = pipe->winsys->surface_alloc(pipe->winsys, pt->format); if (ps) { assert(ps->format); assert(ps->refcount); - pipe_region_reference(&ps->region, mt->region); - ps->cpp = mt->cpp; - ps->width = mt->level[level].width; - ps->height = mt->level[level].height; - ps->pitch = mt->pitch; + pipe_region_reference(&ps->region, tex->region); + ps->cpp = pt->cpp; + ps->width = pt->width[level]; + ps->height = pt->height[level]; + ps->pitch = tex->pitch; ps->offset = offset; } return ps; diff --git a/src/mesa/pipe/i915simple/i915_tex_layout.c b/src/mesa/pipe/i915simple/i915_tex_layout.c deleted file mode 100644 index cb372a7170..0000000000 --- a/src/mesa/pipe/i915simple/i915_tex_layout.c +++ /dev/null @@ -1,474 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 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 - * Michel Dänzer - */ - -#include "pipe/p_state.h" -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_util.h" - -#include "i915_tex_layout.h" -#include "i915_debug.h" - - -static unsigned minify( unsigned d ) -{ - return MAX2(1, d>>1); -} - -static int align(int value, int alignment) -{ - return (value + alignment - 1) & ~(alignment - 1); -} - - -static void -i915_miptree_set_level_info(struct pipe_mipmap_tree *mt, - unsigned level, - unsigned nr_images, - unsigned x, unsigned y, unsigned w, unsigned h, unsigned d) -{ - assert(level < PIPE_MAX_TEXTURE_LEVELS); - - mt->level[level].width = w; - mt->level[level].height = h; - mt->level[level].depth = d; - mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp; - mt->level[level].nr_images = nr_images; - - /* - DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, - level, w, h, d, x, y, mt->level[level].level_offset); - */ - - /* Not sure when this would happen, but anyway: - */ - if (mt->level[level].image_offset) { - FREE(mt->level[level].image_offset); - mt->level[level].image_offset = NULL; - } - - assert(nr_images); - assert(!mt->level[level].image_offset); - - mt->level[level].image_offset = (unsigned *) MALLOC(nr_images * sizeof(unsigned)); - mt->level[level].image_offset[0] = 0; -} - - -static void -i915_miptree_set_image_offset(struct pipe_mipmap_tree *mt, - unsigned level, unsigned img, unsigned x, unsigned y) -{ - if (img == 0 && level == 0) - assert(x == 0 && y == 0); - - assert(img < mt->level[level].nr_images); - - mt->level[level].image_offset[img] = (x + y * mt->pitch); - - /* - DBG("%s level %d img %d pos %d,%d image_offset %x\n", - __FUNCTION__, level, img, x, y, mt->level[level].image_offset[img]); - */ -} - - -static void -i945_miptree_layout_2d( struct pipe_mipmap_tree *mt ) -{ - int align_h = 2, align_w = 4; - unsigned level; - unsigned x = 0; - unsigned y = 0; - unsigned width = mt->width0; - unsigned height = mt->height0; - - mt->pitch = mt->width0; - - /* May need to adjust pitch to accomodate the placement of - * the 2nd mipmap. This occurs when the alignment - * constraints of mipmap placement push the right edge of the - * 2nd mipmap out past the width of its parent. - */ - if (mt->first_level != mt->last_level) { - unsigned mip1_width = align(minify(mt->width0), align_w) - + minify(minify(mt->width0)); - - if (mip1_width > mt->width0) - mt->pitch = mip1_width; - } - - /* Pitch must be a whole number of dwords, even though we - * express it in texels. - */ - mt->pitch = align(mt->pitch * mt->cpp, 4) / mt->cpp; - mt->total_height = 0; - - for ( level = mt->first_level ; level <= mt->last_level ; level++ ) { - unsigned img_height; - - i915_miptree_set_level_info(mt, level, 1, x, y, width, height, 1); - - if (mt->compressed) - img_height = MAX2(1, height/4); - else - img_height = align(height, align_h); - - - /* Because the images are packed better, the final offset - * might not be the maximal one: - */ - mt->total_height = MAX2(mt->total_height, y + img_height); - - /* Layout_below: step right after second mipmap. - */ - if (level == mt->first_level + 1) { - x += align(width, align_w); - } - else { - y += img_height; - } - - width = minify(width); - height = minify(height); - } -} - - -static const int initial_offsets[6][2] = { - {0, 0}, - {0, 2}, - {1, 0}, - {1, 2}, - {1, 1}, - {1, 3} -}; - -static const int step_offsets[6][2] = { - {0, 2}, - {0, 2}, - {-1, 2}, - {-1, 2}, - {-1, 1}, - {-1, 1} -}; - - -boolean -i915_miptree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree * mt) -{ - unsigned level; - - switch (mt->target) { - case PIPE_TEXTURE_CUBE: { - const unsigned dim = mt->width0; - unsigned face; - unsigned lvlWidth = mt->width0, lvlHeight = mt->height0; - - assert(lvlWidth == lvlHeight); /* cubemap images are square */ - - /* double pitch for cube layouts */ - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - mt->total_height = dim * 4; - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_level_info(mt, level, 6, - 0, 0, - /*OLD: mt->pitch, mt->total_height,*/ - lvlWidth, lvlHeight, - 1); - lvlWidth /= 2; - lvlHeight /= 2; - } - - for (face = 0; face < 6; face++) { - unsigned x = initial_offsets[face][0] * dim; - unsigned y = initial_offsets[face][1] * dim; - unsigned d = dim; - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_image_offset(mt, level, face, x, y); - d >>= 1; - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - } - } - break; - } - case PIPE_TEXTURE_3D:{ - unsigned width = mt->width0; - unsigned height = mt->height0; - unsigned depth = mt->depth0; - unsigned stack_height = 0; - - /* Calculate the size of a single slice. - */ - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - - /* XXX: hardware expects/requires 9 levels at minimum. - */ - for (level = mt->first_level; level <= MAX2(8, mt->last_level); - level++) { - i915_miptree_set_level_info(mt, level, depth, 0, mt->total_height, - width, height, depth); - - - stack_height += MAX2(2, height); - - width = minify(width); - height = minify(height); - depth = minify(depth); - } - - /* Fixup depth image_offsets: - */ - depth = mt->depth0; - for (level = mt->first_level; level <= mt->last_level; level++) { - unsigned i; - for (i = 0; i < depth; i++) - i915_miptree_set_image_offset(mt, level, i, - 0, i * stack_height); - - depth = minify(depth); - } - - - /* Multiply slice size by texture depth for total size. It's - * remarkable how wasteful of memory the i915 texture layouts - * are. They are largely fixed in the i945. - */ - mt->total_height = stack_height * mt->depth0; - break; - } - - default:{ - unsigned width = mt->width0; - unsigned height = mt->height0; - unsigned img_height; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_level_info(mt, level, 1, - 0, mt->total_height, - width, height, 1); - - if (mt->compressed) - img_height = MAX2(1, height / 4); - else - img_height = (MAX2(2, height) + 1) & ~1; - - mt->total_height += img_height; - - width = minify(width); - height = minify(height); - } - break; - } - } - /* - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp); - */ - - return TRUE; -} - - -boolean -i945_miptree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree * mt) -{ - unsigned level; - - switch (mt->target) { - case PIPE_TEXTURE_CUBE:{ - const unsigned dim = mt->width0; - unsigned face; - unsigned lvlWidth = mt->width0, lvlHeight = mt->height0; - - assert(lvlWidth == lvlHeight); /* cubemap images are square */ - - /* Depending on the size of the largest images, pitch can be - * determined either by the old-style packing of cubemap faces, - * or the final row of 4x4, 2x2 and 1x1 faces below this. - */ - if (dim > 32) - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - else - mt->pitch = 14 * 8; - - mt->total_height = dim * 4 + 4; - - /* Set all the levels to effectively occupy the whole rectangular region. - */ - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_level_info(mt, level, 6, - 0, 0, - lvlWidth, lvlHeight, 1); - lvlWidth /= 2; - lvlHeight /= 2; - } - - - for (face = 0; face < 6; face++) { - unsigned x = initial_offsets[face][0] * dim; - unsigned y = initial_offsets[face][1] * dim; - unsigned d = dim; - - if (dim == 4 && face >= 4) { - y = mt->total_height - 4; - x = (face - 4) * 8; - } - else if (dim < 4 && (face > 0 || mt->first_level > 0)) { - y = mt->total_height - 4; - x = face * 8; - } - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_image_offset(mt, level, face, x, y); - - d >>= 1; - - switch (d) { - case 4: - switch (face) { - case PIPE_TEX_FACE_POS_X: - case PIPE_TEX_FACE_NEG_X: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - case PIPE_TEX_FACE_POS_Y: - case PIPE_TEX_FACE_NEG_Y: - y += 12; - x -= 8; - break; - case PIPE_TEX_FACE_POS_Z: - case PIPE_TEX_FACE_NEG_Z: - y = mt->total_height - 4; - x = (face - 4) * 8; - break; - } - - case 2: - y = mt->total_height - 4; - x = 16 + face * 8; - break; - - case 1: - x += 48; - break; - - default: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - } - } - } - break; - } - case PIPE_TEXTURE_3D:{ - unsigned width = mt->width0; - unsigned height = mt->height0; - unsigned depth = mt->depth0; - unsigned pack_x_pitch, pack_x_nr; - unsigned pack_y_pitch; - unsigned level; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - pack_y_pitch = MAX2(mt->height0, 2); - pack_x_pitch = mt->pitch; - pack_x_nr = 1; - - for (level = mt->first_level; level <= mt->last_level; level++) { - unsigned nr_images = mt->target == PIPE_TEXTURE_3D ? depth : 6; - int x = 0; - int y = 0; - unsigned q, j; - - i915_miptree_set_level_info(mt, level, nr_images, - 0, mt->total_height, - width, height, depth); - - for (q = 0; q < nr_images;) { - for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { - i915_miptree_set_image_offset(mt, level, q, x, y); - x += pack_x_pitch; - } - - x = 0; - y += pack_y_pitch; - } - - - mt->total_height += y; - - if (pack_x_pitch > 4) { - pack_x_pitch >>= 1; - pack_x_nr <<= 1; - assert(pack_x_pitch * pack_x_nr <= mt->pitch); - } - - if (pack_y_pitch > 2) { - pack_y_pitch >>= 1; - } - - width = minify(width); - height = minify(height); - depth = minify(depth); - } - break; - } - - case PIPE_TEXTURE_1D: - case PIPE_TEXTURE_2D: -// case PIPE_TEXTURE_RECTANGLE: - i945_miptree_layout_2d(mt); - break; - default: - assert(0); - return FALSE; - } - - /* - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp); - */ - - return TRUE; -} - diff --git a/src/mesa/pipe/i915simple/i915_tex_layout.h b/src/mesa/pipe/i915simple/i915_tex_layout.h deleted file mode 100644 index e033786381..0000000000 --- a/src/mesa/pipe/i915simple/i915_tex_layout.h +++ /dev/null @@ -1,16 +0,0 @@ - -#ifndef I915_TEX_LAYOUT_H -#define I915_TEX_LAYOUT_H - -struct pipe_context; -struct pipe_mipmap_tree; - - -extern boolean -i915_miptree_layout(struct pipe_context *, struct pipe_mipmap_tree *); - -extern boolean -i945_miptree_layout(struct pipe_context *, struct pipe_mipmap_tree *); - - -#endif /* I915_TEX_LAYOUT_H */ diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c new file mode 100644 index 0000000000..3bfa806d9e --- /dev/null +++ b/src/mesa/pipe/i915simple/i915_texture.c @@ -0,0 +1,539 @@ +/************************************************************************** + * + * Copyright 2006 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 + * Michel Dänzer + */ + +#include "pipe/p_state.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_util.h" +#include "pipe/p_winsys.h" + +#include "i915_context.h" +#include "i915_texture.h" +#include "i915_debug.h" + + +static unsigned minify( unsigned d ) +{ + return MAX2(1, d>>1); +} + +static int align(int value, int alignment) +{ + return (value + alignment - 1) & ~(alignment - 1); +} + + +static void +i915_miptree_set_level_info(struct i915_texture *tex, + unsigned level, + unsigned nr_images, + unsigned x, unsigned y, unsigned w, unsigned h, unsigned d) +{ + struct pipe_texture *pt = &tex->base; + + assert(level < PIPE_MAX_TEXTURE_LEVELS); + + pt->width[level] = w; + pt->height[level] = h; + pt->depth[level] = d; + + tex->level_offset[level] = (x + y * tex->pitch) * pt->cpp; + tex->nr_images[level] = nr_images; + + /* + DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, + level, w, h, d, x, y, tex->level_offset[level]); + */ + + /* Not sure when this would happen, but anyway: + */ + if (tex->image_offset[level]) { + FREE(tex->image_offset[level]); + tex->image_offset[level] = NULL; + } + + assert(nr_images); + assert(!tex->image_offset[level]); + + tex->image_offset[level] = (unsigned *) MALLOC(nr_images * sizeof(unsigned)); + tex->image_offset[level][0] = 0; +} + + +static void +i915_miptree_set_image_offset(struct i915_texture *tex, + unsigned level, unsigned img, unsigned x, unsigned y) +{ + if (img == 0 && level == 0) + assert(x == 0 && y == 0); + + assert(img < tex->nr_images[level]); + + tex->image_offset[level][img] = (x + y * tex->pitch); + + /* + DBG("%s level %d img %d pos %d,%d image_offset %x\n", + __FUNCTION__, level, img, x, y, tex->image_offset[level][img]); + */ +} + + +static void +i945_miptree_layout_2d( struct i915_texture *tex ) +{ + struct pipe_texture *pt = &tex->base; + int align_h = 2, align_w = 4; + unsigned level; + unsigned x = 0; + unsigned y = 0; + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + + tex->pitch = pt->width[0]; + + /* May need to adjust pitch to accomodate the placement of + * the 2nd mipmap. This occurs when the alignment + * constraints of mipmap placement push the right edge of the + * 2nd mipmap out past the width of its parent. + */ + if (pt->first_level != pt->last_level) { + unsigned mip1_width = align(minify(pt->width[0]), align_w) + + minify(minify(pt->width[0])); + + if (mip1_width > pt->width[0]) + tex->pitch = mip1_width; + } + + /* Pitch must be a whole number of dwords, even though we + * express it in texels. + */ + tex->pitch = align(tex->pitch * pt->cpp, 4) / pt->cpp; + tex->total_height = 0; + + for ( level = pt->first_level ; level <= pt->last_level ; level++ ) { + unsigned img_height; + + i915_miptree_set_level_info(tex, level, 1, x, y, width, height, 1); + + if (pt->compressed) + img_height = MAX2(1, height/4); + else + img_height = align(height, align_h); + + + /* Because the images are packed better, the final offset + * might not be the maximal one: + */ + tex->total_height = MAX2(tex->total_height, y + img_height); + + /* Layout_below: step right after second mipmap. + */ + if (level == pt->first_level + 1) { + x += align(width, align_w); + } + else { + y += img_height; + } + + width = minify(width); + height = minify(height); + } +} + + +static const int initial_offsets[6][2] = { + {0, 0}, + {0, 2}, + {1, 0}, + {1, 2}, + {1, 1}, + {1, 3} +}; + +static const int step_offsets[6][2] = { + {0, 2}, + {0, 2}, + {-1, 2}, + {-1, 2}, + {-1, 1}, + {-1, 1} +}; + + +static boolean +i915_miptree_layout(struct pipe_context *pipe, struct i915_texture * tex) +{ + struct pipe_texture *pt = &tex->base; + unsigned level; + + switch (pt->target) { + case PIPE_TEXTURE_CUBE: { + const unsigned dim = pt->width[0]; + unsigned face; + unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0]; + + assert(lvlWidth == lvlHeight); /* cubemap images are square */ + + /* double pitch for cube layouts */ + tex->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; + tex->total_height = dim * 4; + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_level_info(tex, level, 6, + 0, 0, + /*OLD: tex->pitch, tex->total_height,*/ + lvlWidth, lvlHeight, + 1); + lvlWidth /= 2; + lvlHeight /= 2; + } + + for (face = 0; face < 6; face++) { + unsigned x = initial_offsets[face][0] * dim; + unsigned y = initial_offsets[face][1] * dim; + unsigned d = dim; + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_image_offset(tex, level, face, x, y); + d >>= 1; + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + } + } + break; + } + case PIPE_TEXTURE_3D:{ + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned depth = pt->depth[0]; + unsigned stack_height = 0; + + /* Calculate the size of a single slice. + */ + tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + + /* XXX: hardware expects/requires 9 levels at minimum. + */ + for (level = pt->first_level; level <= MAX2(8, pt->last_level); + level++) { + i915_miptree_set_level_info(tex, level, depth, 0, tex->total_height, + width, height, depth); + + + stack_height += MAX2(2, height); + + width = minify(width); + height = minify(height); + depth = minify(depth); + } + + /* Fixup depth image_offsets: + */ + depth = pt->depth[0]; + for (level = pt->first_level; level <= pt->last_level; level++) { + unsigned i; + for (i = 0; i < depth; i++) + i915_miptree_set_image_offset(tex, level, i, + 0, i * stack_height); + + depth = minify(depth); + } + + + /* Multiply slice size by texture depth for total size. It's + * remarkable how wasteful of memory the i915 texture layouts + * are. They are largely fixed in the i945. + */ + tex->total_height = stack_height * pt->depth[0]; + break; + } + + default:{ + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned img_height; + + tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + tex->total_height = 0; + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_level_info(tex, level, 1, + 0, tex->total_height, + width, height, 1); + + if (pt->compressed) + img_height = MAX2(1, height / 4); + else + img_height = (MAX2(2, height) + 1) & ~1; + + tex->total_height += img_height; + + width = minify(width); + height = minify(height); + } + break; + } + } + /* + DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, + tex->pitch, + tex->total_height, pt->cpp, tex->pitch * tex->total_height * pt->cpp); + */ + + return TRUE; +} + + +static boolean +i945_miptree_layout(struct pipe_context *pipe, struct i915_texture * tex) +{ + struct pipe_texture *pt = &tex->base; + unsigned level; + + switch (pt->target) { + case PIPE_TEXTURE_CUBE:{ + const unsigned dim = pt->width[0]; + unsigned face; + unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0]; + + assert(lvlWidth == lvlHeight); /* cubemap images are square */ + + /* Depending on the size of the largest images, pitch can be + * determined either by the old-style packing of cubemap faces, + * or the final row of 4x4, 2x2 and 1x1 faces below this. + */ + if (dim > 32) + tex->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; + else + tex->pitch = 14 * 8; + + tex->total_height = dim * 4 + 4; + + /* Set all the levels to effectively occupy the whole rectangular region. + */ + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_level_info(tex, level, 6, + 0, 0, + lvlWidth, lvlHeight, 1); + lvlWidth /= 2; + lvlHeight /= 2; + } + + + for (face = 0; face < 6; face++) { + unsigned x = initial_offsets[face][0] * dim; + unsigned y = initial_offsets[face][1] * dim; + unsigned d = dim; + + if (dim == 4 && face >= 4) { + y = tex->total_height - 4; + x = (face - 4) * 8; + } + else if (dim < 4 && (face > 0 || pt->first_level > 0)) { + y = tex->total_height - 4; + x = face * 8; + } + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_image_offset(tex, level, face, x, y); + + d >>= 1; + + switch (d) { + case 4: + switch (face) { + case PIPE_TEX_FACE_POS_X: + case PIPE_TEX_FACE_NEG_X: + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + break; + case PIPE_TEX_FACE_POS_Y: + case PIPE_TEX_FACE_NEG_Y: + y += 12; + x -= 8; + break; + case PIPE_TEX_FACE_POS_Z: + case PIPE_TEX_FACE_NEG_Z: + y = tex->total_height - 4; + x = (face - 4) * 8; + break; + } + + case 2: + y = tex->total_height - 4; + x = 16 + face * 8; + break; + + case 1: + x += 48; + break; + + default: + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + break; + } + } + } + break; + } + case PIPE_TEXTURE_3D:{ + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned depth = pt->depth[0]; + unsigned pack_x_pitch, pack_x_nr; + unsigned pack_y_pitch; + unsigned level; + + tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + tex->total_height = 0; + + pack_y_pitch = MAX2(pt->height[0], 2); + pack_x_pitch = tex->pitch; + pack_x_nr = 1; + + for (level = pt->first_level; level <= pt->last_level; level++) { + unsigned nr_images = pt->target == PIPE_TEXTURE_3D ? depth : 6; + int x = 0; + int y = 0; + unsigned q, j; + + i915_miptree_set_level_info(tex, level, nr_images, + 0, tex->total_height, + width, height, depth); + + for (q = 0; q < nr_images;) { + for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { + i915_miptree_set_image_offset(tex, level, q, x, y); + x += pack_x_pitch; + } + + x = 0; + y += pack_y_pitch; + } + + + tex->total_height += y; + + if (pack_x_pitch > 4) { + pack_x_pitch >>= 1; + pack_x_nr <<= 1; + assert(pack_x_pitch * pack_x_nr <= tex->pitch); + } + + if (pack_y_pitch > 2) { + pack_y_pitch >>= 1; + } + + width = minify(width); + height = minify(height); + depth = minify(depth); + } + break; + } + + case PIPE_TEXTURE_1D: + case PIPE_TEXTURE_2D: +// case PIPE_TEXTURE_RECTANGLE: + i945_miptree_layout_2d(tex); + break; + default: + assert(0); + return FALSE; + } + + /* + DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, + tex->pitch, + tex->total_height, pt->cpp, tex->pitch * tex->total_height * pt->cpp); + */ + + return TRUE; +} + +void +i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) +{ + struct i915_texture *tex = REALLOC(*pt, sizeof(struct pipe_texture), + sizeof(struct i915_texture)); + + if (tex) { + struct i915_context *i915 = i915_context(pipe); + + memset(&tex->base + 1, 0, + sizeof(struct i915_texture) - sizeof(struct pipe_texture)); + + if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) : + i915_miptree_layout(pipe, tex)) { + tex->region = pipe->winsys->region_alloc(pipe->winsys, + tex->pitch * tex->base.cpp * + tex->total_height, + PIPE_SURFACE_FLAG_TEXTURE); + } + + if (!tex->region) { + FREE(tex); + tex = NULL; + } + } + + *pt = &tex->base; +} + +void +i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) +{ + if (!*pt) + return; + + /* + DBG("%s %p refcount will be %d\n", + __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); + */ + if (--(*pt)->refcount <= 0) { + struct i915_texture *tex = (struct i915_texture *)*pt; + uint i; + + /* + DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); + */ + + pipe->winsys->region_release(pipe->winsys, &tex->region); + + for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) + if (tex->image_offset[i]) + free(tex->image_offset[i]); + + free(tex); + } + *pt = NULL; +} diff --git a/src/mesa/pipe/i915simple/i915_texture.h b/src/mesa/pipe/i915simple/i915_texture.h new file mode 100644 index 0000000000..84a0502e81 --- /dev/null +++ b/src/mesa/pipe/i915simple/i915_texture.h @@ -0,0 +1,16 @@ + +#ifndef I915_TEXTURE_H +#define I915_TEXTURE_H + +struct pipe_context; +struct pipe_texture; + + +extern void +i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt); + +extern void +i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt); + + +#endif /* I915_TEXTURE_H */ diff --git a/src/mesa/pipe/llvm/llvm_entry.c b/src/mesa/pipe/llvm/llvm_entry.c index 2459d14cb8..fe32e7810d 100644 --- a/src/mesa/pipe/llvm/llvm_entry.c +++ b/src/mesa/pipe/llvm/llvm_entry.c @@ -194,7 +194,6 @@ void run_vertex_shader(float (*ainputs)[16][4], struct pipe_sampler_state; -struct pipe_mipmap_tree; struct softpipe_tile_cache; #define NUM_CHANNELS 4 /* R,G,B,A */ @@ -203,7 +202,6 @@ struct softpipe_tile_cache; struct tgsi_sampler { const struct pipe_sampler_state *state; - struct pipe_mipmap_tree *texture; /** Get samples for four fragments in a quad */ void (*get_samples)(struct tgsi_sampler *sampler, const float s[QUAD_SIZE], diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index e145b22f2f..5033209323 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -155,7 +155,7 @@ struct pipe_context { void (*set_texture_state)( struct pipe_context *, unsigned unit, - struct pipe_mipmap_tree * ); + struct pipe_texture * ); void (*set_viewport_state)( struct pipe_context *, const struct pipe_viewport_state * ); @@ -180,7 +180,7 @@ struct pipe_context { /** Get a surface which is a "view" into a texture */ struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe, - struct pipe_mipmap_tree *texture, + struct pipe_texture *texture, unsigned face, unsigned level, unsigned zslice); @@ -237,8 +237,11 @@ struct pipe_context { /* * Texture functions */ - boolean (*mipmap_tree_layout)( struct pipe_context *pipe, - struct pipe_mipmap_tree *mt ); + void (*texture_create)(struct pipe_context *pipe, + struct pipe_texture **pt); + + void (*texture_release)(struct pipe_context *pipe, + struct pipe_texture **pt); /* Flush rendering: diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index 2418d016e1..c04d46dddd 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -80,4 +80,24 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) } } + +/** + * \sa pipe_region_reference + */ +static INLINE void +pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr, + struct pipe_texture *pt) +{ + assert(ptr); + if (*ptr) { + pipe->texture_release(pipe, ptr); + assert(!*ptr); + } + if (pt) { + /* reference the new thing */ + pt->refcount++; + *ptr = pt; + } +} + #endif /* P_INLINES_H */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 642734aeb8..077a8f5a06 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -288,27 +288,11 @@ struct pipe_surface /** - * Describes the location of each texture image within a texture region. + * Texture. Represents one or several texture images on one or several mipmap + * levels. */ -struct pipe_mipmap_level -{ - unsigned level_offset; - unsigned width; - unsigned height; - unsigned depth; - unsigned nr_images; - - /* Explicitly store the offset of each image for each cube face or - * depth value. Pretty much have to accept that hardware formats - * are going to be so diverse that there is no unified way to - * compute the offsets of depth/cube images within a mipmap level, - * so have to store them as a lookup table: - */ - unsigned *image_offset; /**< array [depth] of offsets */ -}; - -struct pipe_mipmap_tree -{ +struct pipe_texture +{ /* Effectively the key: */ unsigned target; /* XXX convert to PIPE_TEXTURE_x */ @@ -318,25 +302,13 @@ struct pipe_mipmap_tree unsigned first_level; unsigned last_level; - unsigned width0, height0, depth0; /**< Level zero image dimensions */ + unsigned width[PIPE_MAX_TEXTURE_LEVELS]; + unsigned height[PIPE_MAX_TEXTURE_LEVELS]; + unsigned depth[PIPE_MAX_TEXTURE_LEVELS]; unsigned cpp; unsigned compressed:1; - /* Derived from the above: - */ - unsigned pitch; - unsigned depth_pitch; /* per-image on i945? */ - unsigned total_height; - - /* Includes image offset tables: - */ - struct pipe_mipmap_level level[PIPE_MAX_TEXTURE_LEVELS]; - - /* The data is held here: - */ - struct pipe_region *region; - /* These are also refcounted: */ unsigned refcount; diff --git a/src/mesa/pipe/softpipe/Makefile b/src/mesa/pipe/softpipe/Makefile index 59628531cc..9978884c9b 100644 --- a/src/mesa/pipe/softpipe/Makefile +++ b/src/mesa/pipe/softpipe/Makefile @@ -34,7 +34,7 @@ DRIVER_SOURCES = \ sp_state_rasterizer.c \ sp_state_surface.c \ sp_state_vertex.c \ - sp_tex_layout.c \ + sp_texture.c \ sp_tex_sample.c \ sp_tile_cache.c \ sp_surface.c diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index d5e68c189d..7a9fccce9a 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -40,7 +40,7 @@ #include "sp_state.h" #include "sp_surface.h" #include "sp_tile_cache.h" -#include "sp_tex_layout.h" +#include "sp_texture.h" #include "sp_winsys.h" @@ -98,9 +98,9 @@ softpipe_map_texture_surfaces(struct softpipe_context *sp) uint i; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct pipe_mipmap_tree *mt = sp->texture[i]; - if (mt) { - pipe->region_map(pipe, mt->region); + struct softpipe_texture *spt = sp->texture[i]; + if (spt) { + pipe->region_map(pipe, spt->region); } } } @@ -146,9 +146,9 @@ softpipe_unmap_texture_surfaces(struct softpipe_context *sp) struct pipe_context *pipe = &sp->pipe; uint i; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct pipe_mipmap_tree *mt = sp->texture[i]; - if (mt) { - pipe->region_unmap(pipe, mt->region); + struct softpipe_texture *spt = sp->texture[i]; + if (spt) { + pipe->region_unmap(pipe, spt->region); } } } @@ -351,7 +351,8 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.get_vendor = softpipe_get_vendor; /* textures */ - softpipe->pipe.mipmap_tree_layout = softpipe_mipmap_tree_layout; + softpipe->pipe.texture_create = softpipe_texture_create; + softpipe->pipe.texture_release = softpipe_texture_release; softpipe->pipe.get_tex_surface = softpipe_get_tex_surface; /* diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 872766101d..d4763a98c6 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -89,7 +89,7 @@ struct softpipe_context { struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct softpipe_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c index 24c8a44c47..7184fcda52 100644 --- a/src/mesa/pipe/softpipe/sp_quad_fs.c +++ b/src/mesa/pipe/softpipe/sp_quad_fs.c @@ -277,7 +277,7 @@ static void shade_begin(struct quad_stage *qs) /* set TGSI sampler state that varies */ for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { qss->samplers[i].state = softpipe->sampler[i]; - qss->samplers[i].texture = softpipe->texture[i]; + qss->samplers[i].texture = &softpipe->texture[i]->base; } #ifdef MESA_LLVM diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 2f096a9cc9..a543735b52 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -52,6 +52,35 @@ struct sp_fragment_shader_state { #endif }; +struct softpipe_texture +{ + struct pipe_texture base; + + /* Derived from the above: + */ + unsigned pitch; + unsigned depth_pitch; /* per-image on i945? */ + unsigned total_height; + + unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; + + /* Explicitly store the offset of each image for each cube face or + * depth value. Pretty much have to accept that hardware formats + * are going to be so diverse that there is no unified way to + * compute the offsets of depth/cube images within a mipmap level, + * so have to store them as a lookup table: + */ + unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */ + + /* Includes image offset tables: + */ + unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS]; + + /* The data is held here: + */ + struct pipe_region *region; +}; + void * softpipe_create_alpha_test_state(struct pipe_context *, const struct pipe_alpha_test_state *); @@ -125,7 +154,7 @@ void softpipe_set_scissor_state( struct pipe_context *, void softpipe_set_texture_state( struct pipe_context *, unsigned unit, - struct pipe_mipmap_tree * ); + struct pipe_texture * ); void softpipe_set_viewport_state( struct pipe_context *, const struct pipe_viewport_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c index 912f42d568..a360b4f02b 100644 --- a/src/mesa/pipe/softpipe/sp_state_fs.c +++ b/src/mesa/pipe/softpipe/sp_state_fs.c @@ -34,6 +34,8 @@ #include "pipe/draw/draw_context.h" #include "pipe/p_shader_tokens.h" #include "pipe/llvm/gallivm.h" +#include "pipe/tgsi/util/tgsi_dump.h" +#include "pipe/tgsi/exec/tgsi_sse2.h" void * softpipe_create_fs_state(struct pipe_context *pipe, diff --git a/src/mesa/pipe/softpipe/sp_state_sampler.c b/src/mesa/pipe/softpipe/sp_state_sampler.c index 246a7d6eda..e71b9159e3 100644 --- a/src/mesa/pipe/softpipe/sp_state_sampler.c +++ b/src/mesa/pipe/softpipe/sp_state_sampler.c @@ -68,12 +68,12 @@ softpipe_delete_sampler_state(struct pipe_context *pipe, void softpipe_set_texture_state(struct pipe_context *pipe, unsigned unit, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { struct softpipe_context *softpipe = softpipe_context(pipe); assert(unit < PIPE_MAX_SAMPLERS); - softpipe->texture[unit] = texture; /* ptr, not struct */ + softpipe->texture[unit] = (struct softpipe_texture *)texture; /* ptr, not struct */ sp_tile_cache_set_texture(softpipe->tex_cache[unit], texture); diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index a6ab404603..c41bbc59b9 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -565,34 +565,35 @@ z24s8_get_tile(struct pipe_surface *ps, */ struct pipe_surface * softpipe_get_tex_surface(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice) { + struct softpipe_texture *spt = (struct softpipe_texture *)pt; struct pipe_surface *ps; unsigned offset; /* in bytes */ - offset = mt->level[level].level_offset; + offset = spt->level_offset[level]; - if (mt->target == PIPE_TEXTURE_CUBE) { - offset += mt->level[level].image_offset[face] * mt->cpp; + if (pt->target == PIPE_TEXTURE_CUBE) { + offset += spt->image_offset[level][face] * pt->cpp; } - else if (mt->target == PIPE_TEXTURE_3D) { - offset += mt->level[level].image_offset[zslice] * mt->cpp; + else if (pt->target == PIPE_TEXTURE_3D) { + offset += spt->image_offset[level][zslice] * pt->cpp; } else { assert(face == 0); assert(zslice == 0); } - ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format); + ps = pipe->winsys->surface_alloc(pipe->winsys, pt->format); if (ps) { assert(ps->format); assert(ps->refcount); - pipe_region_reference(&ps->region, mt->region); - ps->cpp = mt->cpp; - ps->width = mt->level[level].width; - ps->height = mt->level[level].height; - ps->pitch = mt->pitch; + pipe_region_reference(&ps->region, spt->region); + ps->cpp = pt->cpp; + ps->width = pt->width[level]; + ps->height = pt->height[level]; + ps->pitch = spt->pitch; ps->offset = offset; } return ps; diff --git a/src/mesa/pipe/softpipe/sp_surface.h b/src/mesa/pipe/softpipe/sp_surface.h index cf87e1a92c..b652e7598e 100644 --- a/src/mesa/pipe/softpipe/sp_surface.h +++ b/src/mesa/pipe/softpipe/sp_surface.h @@ -41,7 +41,7 @@ struct softpipe_tile_cache; extern struct pipe_surface * softpipe_get_tex_surface(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice); diff --git a/src/mesa/pipe/softpipe/sp_tex_layout.c b/src/mesa/pipe/softpipe/sp_tex_layout.c deleted file mode 100644 index 8156b00301..0000000000 --- a/src/mesa/pipe/softpipe/sp_tex_layout.c +++ /dev/null @@ -1,361 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 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 - * Michel Dänzer - */ - -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_util.h" -#include "sp_tex_layout.h" - - -/* At the moment, just make softpipe use the same layout for its - * textures as the i945. Softpipe needs some sort of texture layout, - * this one was handy. May be worthwhile to simplify this code a - * little. - */ - -static unsigned minify( unsigned d ) -{ - return MAX2(1, d>>1); -} - -static int align(int value, int alignment) -{ - return (value + alignment - 1) & ~(alignment - 1); -} - - -static void -sp_miptree_set_level_info(struct pipe_mipmap_tree *mt, - unsigned level, - unsigned nr_images, - unsigned x, unsigned y, unsigned w, unsigned h, unsigned d) -{ - assert(level < PIPE_MAX_TEXTURE_LEVELS); - - mt->level[level].width = w; - mt->level[level].height = h; - mt->level[level].depth = d; - mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp; - mt->level[level].nr_images = nr_images; - - /* - DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, - level, w, h, d, x, y, mt->level[level].level_offset); - */ - - /* Not sure when this would happen, but anyway: - */ - if (mt->level[level].image_offset) { - FREE( mt->level[level].image_offset ); - mt->level[level].image_offset = NULL; - } - - assert(nr_images); - assert(!mt->level[level].image_offset); - - mt->level[level].image_offset = (unsigned *) MALLOC( nr_images * sizeof(unsigned) ); - mt->level[level].image_offset[0] = 0; -} - - -static void -sp_miptree_set_image_offset(struct pipe_mipmap_tree *mt, - unsigned level, unsigned img, unsigned x, unsigned y) -{ - if (img == 0 && level == 0) - assert(x == 0 && y == 0); - - assert(img < mt->level[level].nr_images); - - mt->level[level].image_offset[img] = (x + y * mt->pitch); - - /* - DBG("%s level %d img %d pos %d,%d image_offset %x\n", - __FUNCTION__, level, img, x, y, mt->level[level].image_offset[img]); - */ -} - - -static void -sp_miptree_layout_2d( struct pipe_mipmap_tree *mt ) -{ - int align_h = 2, align_w = 4; - unsigned level; - unsigned x = 0; - unsigned y = 0; - unsigned width = mt->width0; - unsigned height = mt->height0; - - mt->pitch = mt->width0; - /* XXX FIX THIS: - * we use alignment=64 bytes in sp_region_alloc(). If we change - * that, change this too. - */ - if (mt->pitch < 16) - mt->pitch = 16; - - /* May need to adjust pitch to accomodate the placement of - * the 2nd mipmap. This occurs when the alignment - * constraints of mipmap placement push the right edge of the - * 2nd mipmap out past the width of its parent. - */ - if (mt->first_level != mt->last_level) { - unsigned mip1_width = align(minify(mt->width0), align_w) - + minify(minify(mt->width0)); - - if (mip1_width > mt->width0) - mt->pitch = mip1_width; - } - - /* Pitch must be a whole number of dwords, even though we - * express it in texels. - */ - mt->pitch = align(mt->pitch * mt->cpp, 4) / mt->cpp; - mt->total_height = 0; - - for ( level = mt->first_level ; level <= mt->last_level ; level++ ) { - unsigned img_height; - - sp_miptree_set_level_info(mt, level, 1, x, y, width, height, 1); - - if (mt->compressed) - img_height = MAX2(1, height/4); - else - img_height = align(height, align_h); - - - /* Because the images are packed better, the final offset - * might not be the maximal one: - */ - mt->total_height = MAX2(mt->total_height, y + img_height); - - /* Layout_below: step right after second mipmap. - */ - if (level == mt->first_level + 1) { - x += align(width, align_w); - } - else { - y += img_height; - } - - width = minify(width); - height = minify(height); - } -} - - -static const int initial_offsets[6][2] = { - {0, 0}, - {0, 2}, - {1, 0}, - {1, 2}, - {1, 1}, - {1, 3} -}; - -static const int step_offsets[6][2] = { - {0, 2}, - {0, 2}, - {-1, 2}, - {-1, 2}, - {-1, 1}, - {-1, 1} -}; - - - -boolean -softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree * mt) -{ - unsigned level; - - switch (mt->target) { - case PIPE_TEXTURE_CUBE:{ - const unsigned dim = mt->width0; - unsigned face; - unsigned lvlWidth = mt->width0, lvlHeight = mt->height0; - - assert(lvlWidth == lvlHeight); /* cubemap images are square */ - - /* Depending on the size of the largest images, pitch can be - * determined either by the old-style packing of cubemap faces, - * or the final row of 4x4, 2x2 and 1x1 faces below this. - */ - if (dim > 32) - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - else - mt->pitch = 14 * 8; - - mt->total_height = dim * 4 + 4; - - /* Set all the levels to effectively occupy the whole rectangular region. - */ - for (level = mt->first_level; level <= mt->last_level; level++) { - sp_miptree_set_level_info(mt, level, 6, - 0, 0, - lvlWidth, lvlHeight, 1); - lvlWidth /= 2; - lvlHeight /= 2; - } - - - for (face = 0; face < 6; face++) { - unsigned x = initial_offsets[face][0] * dim; - unsigned y = initial_offsets[face][1] * dim; - unsigned d = dim; - - if (dim == 4 && face >= 4) { - y = mt->total_height - 4; - x = (face - 4) * 8; - } - else if (dim < 4 && (face > 0 || mt->first_level > 0)) { - y = mt->total_height - 4; - x = face * 8; - } - - for (level = mt->first_level; level <= mt->last_level; level++) { - sp_miptree_set_image_offset(mt, level, face, x, y); - - d >>= 1; - - switch (d) { - case 4: - switch (face) { - case PIPE_TEX_FACE_POS_X: - case PIPE_TEX_FACE_NEG_X: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - case PIPE_TEX_FACE_POS_Y: - case PIPE_TEX_FACE_NEG_Y: - y += 12; - x -= 8; - break; - case PIPE_TEX_FACE_POS_Z: - case PIPE_TEX_FACE_NEG_Z: - y = mt->total_height - 4; - x = (face - 4) * 8; - break; - } - - case 2: - y = mt->total_height - 4; - x = 16 + face * 8; - break; - - case 1: - x += 48; - break; - - default: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - } - } - } - break; - } - case PIPE_TEXTURE_3D:{ - unsigned width = mt->width0; - unsigned height = mt->height0; - unsigned depth = mt->depth0; - unsigned pack_x_pitch, pack_x_nr; - unsigned pack_y_pitch; - unsigned level; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - pack_y_pitch = MAX2(mt->height0, 2); - pack_x_pitch = mt->pitch; - pack_x_nr = 1; - - for (level = mt->first_level; level <= mt->last_level; level++) { - unsigned nr_images = mt->target == PIPE_TEXTURE_3D ? depth : 6; - int x = 0; - int y = 0; - unsigned q, j; - - sp_miptree_set_level_info(mt, level, nr_images, - 0, mt->total_height, - width, height, depth); - - for (q = 0; q < nr_images;) { - for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { - sp_miptree_set_image_offset(mt, level, q, x, y); - x += pack_x_pitch; - } - - x = 0; - y += pack_y_pitch; - } - - - mt->total_height += y; - - if (pack_x_pitch > 4) { - pack_x_pitch >>= 1; - pack_x_nr <<= 1; - assert(pack_x_pitch * pack_x_nr <= mt->pitch); - } - - if (pack_y_pitch > 2) { - pack_y_pitch >>= 1; - } - - width = minify(width); - height = minify(height); - depth = minify(depth); - } - break; - } - - case PIPE_TEXTURE_1D: - case PIPE_TEXTURE_2D: -// case PIPE_TEXTURE_RECTANGLE: - sp_miptree_layout_2d(mt); - break; - default: - assert(0); - break; - } - - /* - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp); - */ - - return TRUE; -} - diff --git a/src/mesa/pipe/softpipe/sp_tex_layout.h b/src/mesa/pipe/softpipe/sp_tex_layout.h deleted file mode 100644 index ea19c13b23..0000000000 --- a/src/mesa/pipe/softpipe/sp_tex_layout.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SP_TEX_LAYOUT_H -#define SP_TEX_LAYOUT_H - - -struct pipe_context; -struct pipe_mipmap_tree; - - -extern boolean -softpipe_mipmap_tree_layout(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt); - - -#endif /* SP_TEX_LAYOUT_H */ - - diff --git a/src/mesa/pipe/softpipe/sp_tex_sample.c b/src/mesa/pipe/softpipe/sp_tex_sample.c index 92958400fc..9e48ed0cd2 100644 --- a/src/mesa/pipe/softpipe/sp_tex_sample.c +++ b/src/mesa/pipe/softpipe/sp_tex_sample.c @@ -422,7 +422,7 @@ compute_lambda(struct tgsi_sampler *sampler, dsdy = FABSF(dsdy); rho = MAX2(dsdx, dsdy); if (sampler->state->normalized_coords) - rho *= sampler->texture->width0; + rho *= sampler->texture->width[0]; } if (t) { float dtdx = t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]; @@ -432,7 +432,7 @@ compute_lambda(struct tgsi_sampler *sampler, dtdy = FABSF(dtdy); max = MAX2(dtdx, dtdy); if (sampler->state->normalized_coords) - max *= sampler->texture->height0; + max *= sampler->texture->height[0]; rho = MAX2(rho, max); } if (p) { @@ -443,7 +443,7 @@ compute_lambda(struct tgsi_sampler *sampler, dpdy = FABSF(dpdy); max = MAX2(dpdx, dpdy); if (sampler->state->normalized_coords) - max *= sampler->texture->depth0; + max *= sampler->texture->depth[0]; rho = MAX2(rho, max); } @@ -620,8 +620,8 @@ sp_get_samples_2d_common(struct tgsi_sampler *sampler, &level0, &level1, &levelBlend, &imgFilter); if (sampler->state->normalized_coords) { - width = sampler->texture->level[level0].width; - height = sampler->texture->level[level0].height; + width = sampler->texture->width[level0]; + height = sampler->texture->height[level0]; } else { width = height = 1; @@ -757,9 +757,9 @@ sp_get_samples_3d(struct tgsi_sampler *sampler, &level0, &level1, &levelBlend, &imgFilter); if (sampler->state->normalized_coords) { - width = sampler->texture->level[level0].width; - height = sampler->texture->level[level0].height; - depth = sampler->texture->level[level0].depth; + width = sampler->texture->width[level0]; + height = sampler->texture->height[level0]; + depth = sampler->texture->depth[level0]; } else { width = height = depth = 1; @@ -883,7 +883,7 @@ sp_get_samples_cube(struct tgsi_sampler *sampler, /** * Called via tgsi_sampler::get_samples() * Use the sampler's state setting to get a filtered RGBA value - * from the sampler's texture (mipmap tree). + * from the sampler's texture. * * XXX we can implement many versions of this function, each * tightly coded for a specific combination of sampler state diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c new file mode 100644 index 0000000000..2f9a1e9837 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -0,0 +1,425 @@ +/************************************************************************** + * + * Copyright 2006 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 + * Michel Dänzer + */ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_util.h" +#include "pipe/p_winsys.h" + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_texture.h" + + +/* At the moment, just make softpipe use the same layout for its + * textures as the i945. Softpipe needs some sort of texture layout, + * this one was handy. May be worthwhile to simplify this code a + * little. + */ + +static unsigned minify( unsigned d ) +{ + return MAX2(1, d>>1); +} + +static int align(int value, int alignment) +{ + return (value + alignment - 1) & ~(alignment - 1); +} + + +static void +sp_miptree_set_level_info(struct softpipe_texture *spt, + unsigned level, + unsigned nr_images, + unsigned x, unsigned y, unsigned w, unsigned h, + unsigned d) +{ + struct pipe_texture *pt = &spt->base; + + assert(level < PIPE_MAX_TEXTURE_LEVELS); + + pt->width[level] = w; + pt->height[level] = h; + pt->depth[level] = d; + + spt->nr_images[level] = nr_images; + spt->level_offset[level] = (x + y * spt->pitch) * pt->cpp; + + /* + DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, + level, w, h, d, x, y, spt->level_offset[level]); + */ + + /* Not sure when this would happen, but anyway: + */ + if (spt->image_offset[level]) { + FREE( spt->image_offset[level] ); + spt->image_offset[level] = NULL; + } + + assert(nr_images); + assert(!spt->image_offset[level]); + + spt->image_offset[level] = (unsigned *) MALLOC( nr_images * sizeof(unsigned) ); + spt->image_offset[level][0] = 0; +} + + +static void +sp_miptree_set_image_offset(struct softpipe_texture *spt, + unsigned level, unsigned img, unsigned x, unsigned y) +{ + if (img == 0 && level == 0) + assert(x == 0 && y == 0); + + assert(img < spt->nr_images[level]); + + spt->image_offset[level][img] = (x + y * spt->pitch); + + /* + DBG("%s level %d img %d pos %d,%d image_offset %x\n", + __FUNCTION__, level, img, x, y, spt->image_offset[level][img]); + */ +} + + +static void +sp_miptree_layout_2d( struct softpipe_texture *spt ) +{ + struct pipe_texture *pt = &spt->base; + int align_h = 2, align_w = 4; + unsigned level; + unsigned x = 0; + unsigned y = 0; + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + + spt->pitch = pt->width[0]; + /* XXX FIX THIS: + * we use alignment=64 bytes in sp_region_alloc(). If we change + * that, change this too. + */ + if (spt->pitch < 16) + spt->pitch = 16; + + /* May need to adjust pitch to accomodate the placement of + * the 2nd mipmap. This occurs when the alignment + * constraints of mipmap placement push the right edge of the + * 2nd mipmap out past the width of its parent. + */ + if (pt->first_level != pt->last_level) { + unsigned mip1_width = align(minify(pt->width[0]), align_w) + + minify(minify(pt->width[0])); + + if (mip1_width > pt->width[0]) + spt->pitch = mip1_width; + } + + /* Pitch must be a whole number of dwords, even though we + * express it in texels. + */ + spt->pitch = align(spt->pitch * pt->cpp, 4) / pt->cpp; + spt->total_height = 0; + + for ( level = pt->first_level ; level <= pt->last_level ; level++ ) { + unsigned img_height; + + sp_miptree_set_level_info(spt, level, 1, x, y, width, height, 1); + + if (pt->compressed) + img_height = MAX2(1, height/4); + else + img_height = align(height, align_h); + + + /* Because the images are packed better, the final offset + * might not be the maximal one: + */ + spt->total_height = MAX2(spt->total_height, y + img_height); + + /* Layout_below: step right after second mipmap. + */ + if (level == pt->first_level + 1) { + x += align(width, align_w); + } + else { + y += img_height; + } + + width = minify(width); + height = minify(height); + } +} + + +static const int initial_offsets[6][2] = { + {0, 0}, + {0, 2}, + {1, 0}, + {1, 2}, + {1, 1}, + {1, 3} +}; + +static const int step_offsets[6][2] = { + {0, 2}, + {0, 2}, + {-1, 2}, + {-1, 2}, + {-1, 1}, + {-1, 1} +}; + + + +static boolean +softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct softpipe_texture * spt) +{ + struct pipe_texture *pt = &spt->base; + unsigned level; + + switch (pt->target) { + case PIPE_TEXTURE_CUBE:{ + const unsigned dim = pt->width[0]; + unsigned face; + unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0]; + + assert(lvlWidth == lvlHeight); /* cubemap images are square */ + + /* Depending on the size of the largest images, pitch can be + * determined either by the old-style packing of cubemap faces, + * or the final row of 4x4, 2x2 and 1x1 faces below this. + */ + if (dim > 32) + spt->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; + else + spt->pitch = 14 * 8; + + spt->total_height = dim * 4 + 4; + + /* Set all the levels to effectively occupy the whole rectangular region. + */ + for (level = pt->first_level; level <= pt->last_level; level++) { + sp_miptree_set_level_info(spt, level, 6, + 0, 0, + lvlWidth, lvlHeight, 1); + lvlWidth /= 2; + lvlHeight /= 2; + } + + + for (face = 0; face < 6; face++) { + unsigned x = initial_offsets[face][0] * dim; + unsigned y = initial_offsets[face][1] * dim; + unsigned d = dim; + + if (dim == 4 && face >= 4) { + y = spt->total_height - 4; + x = (face - 4) * 8; + } + else if (dim < 4 && (face > 0 || pt->first_level > 0)) { + y = spt->total_height - 4; + x = face * 8; + } + + for (level = pt->first_level; level <= pt->last_level; level++) { + sp_miptree_set_image_offset(spt, level, face, x, y); + + d >>= 1; + + switch (d) { + case 4: + switch (face) { + case PIPE_TEX_FACE_POS_X: + case PIPE_TEX_FACE_NEG_X: + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + break; + case PIPE_TEX_FACE_POS_Y: + case PIPE_TEX_FACE_NEG_Y: + y += 12; + x -= 8; + break; + case PIPE_TEX_FACE_POS_Z: + case PIPE_TEX_FACE_NEG_Z: + y = spt->total_height - 4; + x = (face - 4) * 8; + break; + } + + case 2: + y = spt->total_height - 4; + x = 16 + face * 8; + break; + + case 1: + x += 48; + break; + + default: + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + break; + } + } + } + break; + } + case PIPE_TEXTURE_3D:{ + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned depth = pt->depth[0]; + unsigned pack_x_pitch, pack_x_nr; + unsigned pack_y_pitch; + unsigned level; + + spt->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + spt->total_height = 0; + + pack_y_pitch = MAX2(pt->height[0], 2); + pack_x_pitch = spt->pitch; + pack_x_nr = 1; + + for (level = pt->first_level; level <= pt->last_level; level++) { + unsigned nr_images = pt->target == PIPE_TEXTURE_3D ? depth : 6; + int x = 0; + int y = 0; + unsigned q, j; + + sp_miptree_set_level_info(spt, level, nr_images, + 0, spt->total_height, + width, height, depth); + + for (q = 0; q < nr_images;) { + for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { + sp_miptree_set_image_offset(spt, level, q, x, y); + x += pack_x_pitch; + } + + x = 0; + y += pack_y_pitch; + } + + + spt->total_height += y; + + if (pack_x_pitch > 4) { + pack_x_pitch >>= 1; + pack_x_nr <<= 1; + assert(pack_x_pitch * pack_x_nr <= spt->pitch); + } + + if (pack_y_pitch > 2) { + pack_y_pitch >>= 1; + } + + width = minify(width); + height = minify(height); + depth = minify(depth); + } + break; + } + + case PIPE_TEXTURE_1D: + case PIPE_TEXTURE_2D: +// case PIPE_TEXTURE_RECTANGLE: + sp_miptree_layout_2d(spt); + break; + default: + assert(0); + break; + } + + /* + DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, + spt->pitch, + spt->total_height, pt->cpp, spt->pitch * spt->total_height * pt->cpp); + */ + + return TRUE; +} + +void +softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) +{ + struct softpipe_texture *spt = REALLOC(*pt, sizeof(struct pipe_texture), + sizeof(struct softpipe_texture)); + + if (spt) { + memset(&spt->base + 1, 0, + sizeof(struct softpipe_texture) - sizeof(struct pipe_texture)); + + if (softpipe_mipmap_tree_layout(pipe, spt)) { + spt->region = pipe->winsys->region_alloc(pipe->winsys, + spt->pitch * (*pt)->cpp * + spt->total_height, + PIPE_SURFACE_FLAG_TEXTURE); + } + + if (!spt->region) { + FREE(spt); + spt = NULL; + } + } + + *pt = &spt->base; +} + +void +softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) +{ + if (!*pt) + return; + + /* + DBG("%s %p refcount will be %d\n", + __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); + */ + if (--(*pt)->refcount <= 0) { + struct softpipe_texture *spt = (struct softpipe_texture *)*pt; + uint i; + + /* + DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); + */ + + pipe->winsys->region_release(pipe->winsys, &spt->region); + + for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) + if (spt->image_offset[i]) + free(spt->image_offset[i]); + + free(spt); + } + *pt = NULL; +} diff --git a/src/mesa/pipe/softpipe/sp_texture.h b/src/mesa/pipe/softpipe/sp_texture.h new file mode 100644 index 0000000000..2aca57bd1d --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_texture.h @@ -0,0 +1,18 @@ +#ifndef SP_TEXTURE_H +#define SP_TEXTURE_H + + +struct pipe_context; +struct pipe_texture; + + +extern void +softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt); + +extern void +softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt); + + +#endif /* SP_TEXTURE */ + + diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index ea0c8b8f91..62ee6a27c9 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -51,7 +51,7 @@ struct softpipe_tile_cache { struct pipe_surface *surface; /**< the surface we're caching */ - struct pipe_mipmap_tree *texture; /**< if caching a texture */ + struct pipe_texture *texture; /**< if caching a texture */ struct softpipe_cached_tile entries[NUM_ENTRIES]; uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32]; float clear_value[4]; @@ -139,7 +139,7 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc) void sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { uint i; diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.h b/src/mesa/pipe/softpipe/sp_tile_cache.h index e66fec2e20..9967aa5044 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.h +++ b/src/mesa/pipe/softpipe/sp_tile_cache.h @@ -71,7 +71,7 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc); extern void sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, - struct pipe_mipmap_tree *texture); + struct pipe_texture *texture); extern void sp_flush_tile_cache(struct softpipe_context *softpipe, diff --git a/src/mesa/pipe/tgsi/exec/tgsi_exec.h b/src/mesa/pipe/tgsi/exec/tgsi_exec.h index 1d497e97fb..2c62b30f15 100644 --- a/src/mesa/pipe/tgsi/exec/tgsi_exec.h +++ b/src/mesa/pipe/tgsi/exec/tgsi_exec.h @@ -76,7 +76,7 @@ struct softpipe_tile_cache; /**< Opaque to TGSI */ struct tgsi_sampler { const struct pipe_sampler_state *state; - struct pipe_mipmap_tree *texture; + struct pipe_texture *texture; /** Get samples for four fragments in a quad */ void (*get_samples)(struct tgsi_sampler *sampler, const float s[QUAD_SIZE], diff --git a/src/mesa/sources b/src/mesa/sources index 2df60d1996..596d3b89d5 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -236,7 +236,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_framebuffer.c \ state_tracker/st_mesa_to_tgsi.c \ state_tracker/st_program.c \ - state_tracker/st_mipmap_tree.c + state_tracker/st_texture.c SHADER_SOURCES = \ shader/arbprogparse.c \ diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index f25cfd386a..c4e5af02d5 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -51,24 +51,24 @@ update_textures(struct st_context *st) for (u = 0; u < st->ctx->Const.MaxTextureImageUnits; u++) { struct gl_texture_object *texObj = st->ctx->Texture.Unit[u]._Current; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; if (texObj) { GLboolean flush, retval; - retval = st_finalize_mipmap_tree(st->ctx, st->pipe, u, &flush); + retval = st_finalize_texture(st->ctx, st->pipe, u, &flush); #if 0 - printf("finalize_mipmap_tree returned %d, flush = %d\n", + printf("finalize_texture returned %d, flush = %d\n", retval, flush); #endif - mt = st_get_texobj_mipmap_tree(texObj); + pt = st_get_texobj_texture(texObj); } else { - mt = NULL; + pt = NULL; } - st->state.texture[u] = mt; - st->pipe->set_texture_state(st->pipe, u, mt); + st->state.texture[u] = pt; + st->pipe->set_texture_state(st->pipe, u, pt); } } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 39c0cf6b32..c28ad15b29 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -33,6 +33,7 @@ #include "main/imports.h" #include "main/image.h" #include "main/macros.h" +#include "main/texformat.h" #include "shader/program.h" #include "shader/prog_parameter.h" #include "shader/prog_print.h" @@ -50,6 +51,7 @@ #include "st_draw.h" #include "st_format.h" #include "st_mesa_to_tgsi.h" +#include "st_texture.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" @@ -440,63 +442,20 @@ _mesa_base_format(GLenum format) } - -static struct pipe_mipmap_tree * -alloc_mipmap_tree(struct st_context *st, - GLsizei width, GLsizei height, uint pipeFormat) -{ - const GLbitfield flags = PIPE_SURFACE_FLAG_TEXTURE; - struct pipe_mipmap_tree *mt; - GLuint cpp; - - mt = CALLOC_STRUCT(pipe_mipmap_tree); - if (!mt) - return NULL; - - cpp = st_sizeof_format(pipeFormat); - - mt->target = PIPE_TEXTURE_2D; - mt->internal_format = GL_RGBA; - mt->format = pipeFormat; - mt->first_level = 0; - mt->last_level = 0; - mt->width0 = width; - mt->height0 = height; - mt->depth0 = 1; - mt->cpp = cpp; - mt->compressed = 0; - mt->pitch = st->pipe->winsys->surface_pitch(st->pipe->winsys, cpp, width, - flags); - mt->region = st->pipe->winsys->region_alloc(st->pipe->winsys, - mt->pitch * cpp * height, flags); - mt->depth_pitch = 0; - mt->total_height = height; - mt->level[0].level_offset = 0; - mt->level[0].width = width; - mt->level[0].height = height; - mt->level[0].depth = 1; - mt->level[0].nr_images = 1; - mt->level[0].image_offset = NULL; - mt->refcount = 1; - - return mt; -} - - /** - * Make mipmap tree containing an image for glDrawPixels image. + * Make texture containing an image for glDrawPixels image. * If 'pixels' is NULL, leave the texture image data undefined. */ -static struct pipe_mipmap_tree * -make_mipmap_tree(struct st_context *st, - GLsizei width, GLsizei height, GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels) +static struct pipe_texture * +make_texture(struct st_context *st, + GLsizei width, GLsizei height, GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *pixels) { GLcontext *ctx = st->ctx; struct pipe_context *pipe = st->pipe; const struct gl_texture_format *mformat; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; GLuint pipeFormat, cpp; GLenum baseFormat; @@ -509,29 +468,33 @@ make_mipmap_tree(struct st_context *st, assert(pipeFormat); cpp = st_sizeof_format(pipeFormat); - mt = alloc_mipmap_tree(st, width, height, pipeFormat); - if (!mt) + pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, baseFormat, 0, 0, + width, height, 1, 0); + if (!pt) return NULL; if (unpack->BufferObj && unpack->BufferObj->Name) { /* - mt->region = buffer_object_region(unpack->BufferObj); + pt->region = buffer_object_region(unpack->BufferObj); */ printf("st_DrawPixels (sourcing from PBO not implemented yet)\n"); } { + struct pipe_surface *surface; static const GLuint dstImageOffsets = 0; GLboolean success; - GLuint pitch = mt->pitch; GLubyte *dest; const GLbitfield imageTransferStateSave = ctx->_ImageTransferState; /* we'll do pixel transfer in a fragment shader */ ctx->_ImageTransferState = 0x0; + surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); + /* map texture region */ - dest = pipe->region_map(pipe, mt->region); + (void) pipe->region_map(pipe, surface->region); + dest = surface->region->map + surface->offset; /* Put image into texture region. * Note that the image is actually going to be upside down in @@ -542,7 +505,7 @@ make_mipmap_tree(struct st_context *st, mformat, /* gl_texture_format */ dest, /* dest */ 0, 0, 0, /* dstX/Y/Zoffset */ - pitch * cpp, /* dstRowStride, bytes */ + surface->pitch * cpp, /* dstRowStride, bytes */ &dstImageOffsets, /* dstImageOffsets */ width, height, 1, /* size */ format, type, /* src format/type */ @@ -550,44 +513,15 @@ make_mipmap_tree(struct st_context *st, unpack); /* unmap */ - pipe->region_unmap(pipe, mt->region); + pipe->region_unmap(pipe, surface->region); + pipe_surface_reference(&surface, NULL); assert(success); /* restore */ ctx->_ImageTransferState = imageTransferStateSave; } -#if 0 - mt->target = PIPE_TEXTURE_2D; - mt->internal_format = GL_RGBA; - mt->format = pipeFormat; - mt->first_level = 0; - mt->last_level = 0; - mt->width0 = width; - mt->height0 = height; - mt->depth0 = 1; - mt->cpp = cpp; - mt->compressed = 0; - mt->pitch = mt->pitch; - mt->depth_pitch = 0; - mt->total_height = height; - mt->level[0].level_offset = 0; - mt->level[0].width = width; - mt->level[0].height = height; - mt->level[0].depth = 1; - mt->level[0].nr_images = 1; - mt->level[0].image_offset = NULL; - mt->refcount = 1; -#endif - return mt; -} - - -static void -free_mipmap_tree(struct pipe_context *pipe, struct pipe_mipmap_tree *mt) -{ - pipe->winsys->region_release(pipe->winsys, &mt->region); - free(mt); + return pt; } @@ -693,7 +627,7 @@ static void draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, GLsizei width, GLsizei height, GLfloat zoomX, GLfloat zoomY, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, struct st_vertex_program *stvp, struct st_fragment_program *stfp, const GLfloat *color, @@ -761,9 +695,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->set_viewport_state(pipe, &vp); } - /* mipmap tree state: */ + /* texture state: */ { - pipe->set_texture_state(pipe, unit, mt); + pipe->set_texture_state(pipe, unit, pt); } /* Compute window coords (y=0=bottom) with pixel zoom. @@ -1025,14 +959,13 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, any_pixel_transfer_ops(st) || !compatible_formats(format, type, ps->format)) { /* textured quad */ - struct pipe_mipmap_tree *mt - = make_mipmap_tree(ctx->st, width, height, format, type, - unpack, pixels); - if (mt) { + struct pipe_texture *pt + = make_texture(ctx->st, width, height, format, type, unpack, pixels); + if (pt) { draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, - mt, stvp, stfp, color, GL_FALSE); - free_mipmap_tree(st->pipe, mt); + pt, stvp, stfp, color, GL_FALSE); + st->pipe->texture_release(st->pipe, &pt); } } else { @@ -1046,26 +979,29 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /** * Create a texture which represents a bitmap image. */ -static struct pipe_mipmap_tree * +static struct pipe_texture * make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap) { struct pipe_context *pipe = ctx->st->pipe; - const uint flags = PIPE_SURFACE_FLAG_TEXTURE; + struct pipe_surface *surface; uint format = 0, cpp, comp; + GLenum internal_format; ubyte *dest; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; int row, col; /* find a texture format we know */ if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8 )) { format = PIPE_FORMAT_U_I8; + internal_format = GL_INTENSITY8; 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; + internal_format = GL_RGBA8; cpp = 4; comp = 3; /* alpha channel */ /*XXX little-endian dependency */ } @@ -1075,31 +1011,25 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, } /** - * Create a mipmap tree. + * Create a texture. */ - mt = CALLOC_STRUCT(pipe_mipmap_tree); - if (!mt) + pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, internal_format, + 0, 0, width, height, 1, 0); + if (!pt) return NULL; if (unpack->BufferObj && unpack->BufferObj->Name) { /* - mt->region = buffer_object_region(unpack->BufferObj); + pt->region = buffer_object_region(unpack->BufferObj); */ printf("st_Bitmap (sourcing from PBO not implemented yet)\n"); } - - /* allocate texture region/storage */ - mt->pitch = pipe->winsys->surface_pitch(pipe->winsys, cpp, width, flags); - mt->region = pipe->winsys->region_alloc(pipe->winsys, - mt->pitch * cpp * height, flags); + surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); /* map texture region */ - dest = pipe->region_map(pipe, mt->region); - if (!dest) { - printf("st_Bitmap region_map() failed!?!"); - return NULL; - } + (void) pipe->region_map(pipe, surface->region); + dest = surface->region->map + surface->offset; /* Put image into texture region. * Note that the image is actually going to be upside down in @@ -1109,7 +1039,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, for (row = 0; row < height; row++) { const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack, bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); - ubyte *destRow = dest + row * mt->pitch * cpp; + ubyte *destRow = dest + row * surface->pitch * cpp; if (unpack->LsbFirst) { /* Lsb first */ @@ -1158,30 +1088,13 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, } /* row */ - /* unmap */ - pipe->region_unmap(pipe, mt->region); - - mt->target = PIPE_TEXTURE_2D; - mt->internal_format = GL_RGBA; - mt->format = format; - mt->first_level = 0; - mt->last_level = 0; - mt->width0 = width; - mt->height0 = height; - mt->depth0 = 1; - mt->cpp = cpp; - mt->compressed = 0; - mt->depth_pitch = 0; - mt->total_height = height; - mt->level[0].level_offset = 0; - mt->level[0].width = width; - mt->level[0].height = height; - mt->level[0].depth = 1; - mt->level[0].nr_images = 1; - mt->level[0].image_offset = NULL; - mt->refcount = 1; - - return mt; + /* Release surface */ + pipe->region_unmap(pipe, surface->region); + pipe_surface_reference(&surface, NULL); + + pt->format = format; + + return pt; } @@ -1193,21 +1106,21 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, struct st_fragment_program *stfp; struct st_vertex_program *stvp; struct st_context *st = ctx->st; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; stvp = make_vertex_shader(ctx->st, GL_TRUE); stfp = combined_bitmap_fragment_program(ctx); st_validate_state(st); - mt = make_bitmap_texture(ctx, width, height, unpack, bitmap); - if (mt) { + pt = make_bitmap_texture(ctx, width, height, unpack, bitmap); + if (pt) { draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], width, height, 1.0, 1.0, - mt, stvp, stfp, + pt, stvp, stfp, ctx->Current.RasterColor, GL_FALSE); - free_mipmap_tree(st->pipe, mt); + st->pipe->texture_release(st->pipe, &pt); } } @@ -1296,7 +1209,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, struct st_fragment_program *stfp; struct pipe_surface *psRead; struct pipe_surface *psTex; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; GLfloat *color; uint format; @@ -1327,11 +1240,12 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, psRead = rbRead->surface; format = psRead->format; - mt = alloc_mipmap_tree(ctx->st, width, height, format); - if (!mt) + pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, + rbRead->Base.InternalFormat, 0, 0, width, height, 1, 0); + if (!pt) return; - psTex = pipe->get_tex_surface(pipe, mt, 0, 0, 0); + psTex = pipe->get_tex_surface(pipe, pt, 0, 0, 0); if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { srcy = ctx->DrawBuffer->Height - srcy - height; @@ -1368,10 +1282,10 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, /* draw textured quad */ draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2], width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, - mt, stvp, stfp, color, GL_TRUE); + pt, stvp, stfp, color, GL_TRUE); pipe_surface_reference(&psTex, NULL); - free_mipmap_tree(st->pipe, mt); + st->pipe->texture_release(st->pipe, &pt); } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 80c92e8b7a..43681b7f8a 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -286,7 +286,7 @@ st_render_texture(GLcontext *ctx, struct st_renderbuffer *strb; struct gl_renderbuffer *rb; struct pipe_context *pipe = st->pipe; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; assert(!att->Renderbuffer); @@ -302,26 +302,26 @@ st_render_texture(GLcontext *ctx, rb->AllocStorage = NULL; /* should not get called */ strb = st_renderbuffer(rb); - /* get the mipmap tree for the texture */ - mt = st_get_texobj_mipmap_tree(att->Texture); - assert(mt); - assert(mt->level[att->TextureLevel].width); + /* get the texture for the texture object */ + pt = st_get_texobj_texture(att->Texture); + assert(pt); + assert(pt->width[att->TextureLevel]); - rb->Width = mt->level[att->TextureLevel].width; - rb->Height = mt->level[att->TextureLevel].height; + rb->Width = pt->width[att->TextureLevel]; + rb->Height = pt->height[att->TextureLevel]; - /* the renderbuffer's surface is inside the mipmap_tree: */ - strb->surface = pipe->get_tex_surface(pipe, mt, + /* the renderbuffer's surface is inside the texture */ + strb->surface = pipe->get_tex_surface(pipe, pt, att->CubeMapFace, att->TextureLevel, att->Zoffset); assert(strb->surface); - init_renderbuffer_bits(strb, mt->format); + init_renderbuffer_bits(strb, pt->format); /* - printf("RENDER TO TEXTURE obj=%p mt=%p surf=%p %d x %d\n", - att->Texture, mt, strb->surface, rb->Width, rb->Height); + printf("RENDER TO TEXTURE obj=%p pt=%p surf=%p %d x %d\n", + att->Texture, pt, strb->surface, rb->Width, rb->Height); */ /* Invalidate buffer state so that the pipe's framebuffer state diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 461705119f..f45d7e4275 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -40,7 +40,7 @@ #include "state_tracker/st_cb_fbo.h" #include "state_tracker/st_cb_texture.h" #include "state_tracker/st_format.h" -#include "state_tracker/st_mipmap_tree.h" +#include "state_tracker/st_texture.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -54,8 +54,7 @@ struct st_texture_object { struct gl_texture_object base; /* The "parent" object */ - /* The mipmap tree must include at least these levels once - * validated: + /* The texture must include at least these levels once validated: */ GLuint firstLevel; GLuint lastLevel; @@ -67,7 +66,7 @@ struct st_texture_object /* On validation any active images held in main memory or in other * regions will be copied to this region and the old storage freed. */ - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; GLboolean imageOverride; GLint depthOverride; @@ -76,24 +75,6 @@ struct st_texture_object -struct st_texture_image -{ - struct gl_texture_image base; - - /* These aren't stored in gl_texture_image - */ - GLuint level; - GLuint face; - - /* If stImage->mt != NULL, image data is stored here. - * Else if stImage->base.Data != NULL, image is stored there. - * Else there is no image data. - */ - struct pipe_mipmap_tree *mt; -}; - - - static INLINE struct st_texture_object * st_texture_object(struct gl_texture_object *obj) @@ -108,11 +89,11 @@ st_texture_image(struct gl_texture_image *img) } -struct pipe_mipmap_tree * -st_get_texobj_mipmap_tree(struct gl_texture_object *texObj) +struct pipe_texture * +st_get_texobj_texture(struct gl_texture_object *texObj) { struct st_texture_object *stObj = st_texture_object(texObj); - return stObj->mt; + return stObj->pt; } @@ -174,9 +155,9 @@ st_IsTextureResident(GLcontext * ctx, struct gl_texture_object *texObj) struct st_texture_object *stObj = st_texture_object(texObj); return - stObj->mt && - stObj->mt->region && - intel_is_region_resident(intel, stObj->mt->region); + stObj->pt && + stObj->pt->region && + intel_is_region_resident(intel, stObj->pt->region); #endif return 1; } @@ -207,11 +188,10 @@ static void st_DeleteTextureObject(GLcontext *ctx, struct gl_texture_object *texObj) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_object *stObj = st_texture_object(texObj); - if (stObj->mt) - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt) + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); _mesa_delete_texture_object(ctx, texObj); } @@ -220,13 +200,12 @@ st_DeleteTextureObject(GLcontext *ctx, static void st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_image *stImage = st_texture_image(texImage); DBG("%s\n", __FUNCTION__); - if (stImage->mt) { - st_miptree_release(pipe, &stImage->mt); + if (stImage->pt) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stImage->pt); } if (texImage->Data) { @@ -287,10 +266,10 @@ do_memcpy(void *dest, const void *src, size_t n) } -/* Functions to store texture images. Where possible, mipmap_tree's +/* Functions to store texture images. Where possible, textures * will be created or further instantiated with image data, otherwise * images will be stored in malloc'd memory. A validation step is - * required to pull those images into a mipmap tree, or otherwise + * required to pull those images into a texture, or otherwise * decide a fallback is required. */ @@ -313,17 +292,16 @@ logbase2(int n) /* Otherwise, store it in memory if (Border != 0) or (any dimension == * 1). * - * Otherwise, if max_level >= level >= min_level, create tree with - * space for textures from min_level down to max_level. + * Otherwise, if max_level >= level >= min_level, create texture with + * space for images from min_level down to max_level. * - * Otherwise, create tree with space for textures from (level - * 0)..(1x1). Consider pruning this tree at a validation if the - * saving is worth it. + * Otherwise, create texture with space for images from (level 0)..(1x1). + * Consider pruning this texture at a validation if the saving is worth it. */ static void -guess_and_alloc_mipmap_tree(struct pipe_context *pipe, - struct st_texture_object *stObj, - struct st_texture_image *stImage) +guess_and_alloc_texture(struct st_context *st, + struct st_texture_object *stObj, + struct st_texture_image *stImage) { GLuint firstLevel; GLuint lastLevel; @@ -382,23 +360,20 @@ guess_and_alloc_mipmap_tree(struct pipe_context *pipe, lastLevel = firstLevel + MAX2(MAX2(l2width, l2height), l2depth); } - assert(!stObj->mt); + assert(!stObj->pt); if (stImage->base.IsCompressed) comp_byte = compressed_num_bytes(stImage->base.TexFormat->MesaFormat); - stObj->mt = st_miptree_create(pipe, + stObj->pt = st_texture_create(st, gl_target_to_pipe(stObj->base.Target), - stImage->base.InternalFormat, + st_mesa_format_to_pipe_format(stImage->base.TexFormat->MesaFormat), + stImage->base.InternalFormat, firstLevel, lastLevel, width, height, depth, - stImage->base.TexFormat->TexelBytes, comp_byte); - stObj->mt->format - = st_mesa_format_to_pipe_format(stImage->base.TexFormat->MesaFormat); - DBG("%s - success\n", __FUNCTION__); } @@ -482,11 +457,11 @@ try_pbo_upload(GLcontext *ctx, else src_stride = width; - dst_offset = st_miptree_image_offset(stImage->mt, + dst_offset = st_texture_image_offset(stImage->pt, stImage->face, stImage->level); - dst_stride = stImage->mt->pitch; + dst_stride = stImage->pt->pitch; { struct _DriBufferObject *src_buffer = @@ -495,11 +470,11 @@ try_pbo_upload(GLcontext *ctx, /* Temporary hack: cast to _DriBufferObject: */ struct _DriBufferObject *dst_buffer = - (struct _DriBufferObject *)stImage->mt->region->buffer; + (struct _DriBufferObject *)stImage->pt->region->buffer; intelEmitCopyBlit(intel, - stImage->mt->cpp, + stImage->pt->cpp, src_stride, src_buffer, src_offset, dst_stride, dst_buffer, dst_offset, 0, 0, 0, 0, width, height, @@ -540,7 +515,6 @@ st_TexImage(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage, GLsizei imageSize, int compressed) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLint postConvWidth = width; @@ -589,58 +563,58 @@ st_TexImage(GLcontext * ctx, /* Release the reference to a potentially orphaned buffer. * Release any old malloced memory. */ - if (stImage->mt) { - st_miptree_release(pipe, &stImage->mt); + if (stImage->pt) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stImage->pt); assert(!texImage->Data); } else if (texImage->Data) { _mesa_align_free(texImage->Data); } - /* If this is the only texture image in the tree, could call + /* If this is the only texture image in the texture, could call * bmBufferData with NULL data to free the old block and avoid * waiting on any outstanding fences. */ - if (stObj->mt && - stObj->mt->first_level == level && - stObj->mt->last_level == level && - stObj->mt->target != PIPE_TEXTURE_CUBE && - !st_miptree_match_image(stObj->mt, &stImage->base, + if (stObj->pt && + stObj->pt->first_level == level && + stObj->pt->last_level == level && + stObj->pt->target != PIPE_TEXTURE_CUBE && + !st_texture_match_image(stObj->pt, &stImage->base, stImage->face, stImage->level)) { DBG("release it\n"); - st_miptree_release(pipe, &stObj->mt); - assert(!stObj->mt); + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); + assert(!stObj->pt); } - if (!stObj->mt) { - guess_and_alloc_mipmap_tree(pipe, stObj, stImage); - if (!stObj->mt) { - DBG("guess_and_alloc_mipmap_tree: failed\n"); + if (!stObj->pt) { + guess_and_alloc_texture(ctx->st, stObj, stImage); + if (!stObj->pt) { + DBG("guess_and_alloc_texture: failed\n"); } } - assert(!stImage->mt); + assert(!stImage->pt); - if (stObj->mt && - st_miptree_match_image(stObj->mt, &stImage->base, + if (stObj->pt && + st_texture_match_image(stObj->pt, &stImage->base, stImage->face, stImage->level)) { - st_miptree_reference(&stImage->mt, stObj->mt); - assert(stImage->mt); + pipe_texture_reference(ctx->st->pipe, &stImage->pt, stObj->pt); + assert(stImage->pt); } - if (!stImage->mt) - DBG("XXX: Image did not fit into tree - storing in local memory!\n"); + if (!stImage->pt) + DBG("XXX: Image did not fit into texture - storing in local memory!\n"); #if 0 /* XXX FIX when st_buffer_objects are in place */ /* PBO fastpaths: */ if (dims <= 2 && - stImage->mt && + stImage->pt && intel_buffer_object(unpack->BufferObj) && check_pbo_format(internalFormat, format, - type, stImage->base.TexFormat)) { + type, texImage->TexFormat)) { DBG("trying pbo upload\n"); @@ -650,9 +624,9 @@ st_TexImage(GLcontext * ctx, * performance (in particular when pipe_region_cow() is * required). */ - if (stObj->mt == stImage->mt && - stObj->mt->first_level == level && - stObj->mt->last_level == level) { + if (stObj->pt == stImage->pt && + stObj->pt->first_level == level && + stObj->pt->last_level == level) { if (try_pbo_zcopy(intel, stImage, unpack, internalFormat, @@ -683,7 +657,7 @@ st_TexImage(GLcontext * ctx, /* intelCopyTexImage calls this function with pixels == NULL, with - * the expectation that the mipmap tree will be set up but nothing + * the expectation that the texture will be set up but nothing * more will be done. This is where those calls return: */ if (compressed) { @@ -698,13 +672,9 @@ st_TexImage(GLcontext * ctx, if (!pixels) return; - if (stImage->mt) { - texImage->Data = st_miptree_image_map(pipe, - stImage->mt, - stImage->face, - stImage->level, - &dstRowStride, - stImage->base.ImageOffsets); + if (stImage->pt) { + texImage->Data = st_texture_image_map(ctx->st, stImage, 0); + dstRowStride = stImage->surface->pitch * stImage->surface->cpp; } else { /* Allocate regular memory and store the image there temporarily. */ @@ -732,22 +702,36 @@ st_TexImage(GLcontext * ctx, if (compressed) { memcpy(texImage->Data, pixels, imageSize); } - else if (!texImage->TexFormat->StoreImage(ctx, dims, - texImage->_BaseFormat, - texImage->TexFormat, - texImage->Data, - 0, 0, 0, /* dstX/Y/Zoffset */ - dstRowStride, - texImage->ImageOffsets, - width, height, depth, - format, type, pixels, unpack)) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); + else { + GLuint srcImageStride = _mesa_image_image_stride(unpack, width, height, + format, type); + int i; + + for (i = 0; i++ < depth;) { + if (!texImage->TexFormat->StoreImage(ctx, dims, + texImage->_BaseFormat, + texImage->TexFormat, + texImage->Data, + 0, 0, 0, /* dstX/Y/Zoffset */ + dstRowStride, + texImage->ImageOffsets, + width, height, 1, + format, type, pixels, unpack)) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); + } + + if (stImage->pt && i < depth) { + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, i); + pixels += srcImageStride; + } + } } _mesa_unmap_teximage_pbo(ctx, unpack); - if (stImage->mt) { - st_miptree_image_unmap(pipe, stImage->mt); + if (stImage->pt) { + st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; } @@ -839,49 +823,58 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, /* struct intel_context *intel = intel_context(ctx); */ - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_image *stImage = st_texture_image(texImage); + GLuint dstImageStride = _mesa_image_image_stride(&ctx->Pack, texImage->Width, + texImage->Height, format, + type); + GLuint depth; + int i; /* Map */ - if (stImage->mt) { + if (stImage->pt) { /* Image is stored in hardware format in a buffer managed by the * kernel. Need to explicitly map and unmap it. */ - stImage->base.Data = - st_miptree_image_map(pipe, - stImage->mt, - stImage->face, - stImage->level, - &stImage->base.RowStride, - stImage->base.ImageOffsets); - stImage->base.RowStride /= stImage->mt->cpp; + texImage->Data = st_texture_image_map(ctx->st, stImage, 0); + texImage->RowStride = stImage->surface->pitch; } else { /* Otherwise, the image should actually be stored in - * stImage->base.Data. This is pretty confusing for + * texImage->Data. This is pretty confusing for * everybody, I'd much prefer to separate the two functions of * texImage->Data - storage for texture images in main memory * and access (ie mappings) of images. In other words, we'd * create a new texImage->Map field and leave Data simply for * storage. */ - assert(stImage->base.Data); + assert(texImage->Data); } + depth = texImage->Depth; + texImage->Depth = 1; - if (compressed) { - _mesa_get_compressed_teximage(ctx, target, level, pixels, - texObj, texImage); - } else { - _mesa_get_teximage(ctx, target, level, format, type, pixels, - texObj, texImage); + for (i = 0; i++ < depth;) { + if (compressed) { + _mesa_get_compressed_teximage(ctx, target, level, pixels, + texObj, texImage); + } else { + _mesa_get_teximage(ctx, target, level, format, type, pixels, + texObj, texImage); + } + + if (stImage->pt && i < depth) { + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, i); + pixels += dstImageStride; + } } - + + texImage->Depth = depth; /* Unmap */ - if (stImage->mt) { - st_miptree_image_unmap(pipe, stImage->mt); - stImage->base.Data = NULL; + if (stImage->pt) { + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = NULL; } } @@ -921,9 +914,11 @@ st_TexSubimage(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_image *stImage = st_texture_image(texImage); GLuint dstRowStride; + GLuint srcImageStride = _mesa_image_image_stride(packing, width, height, + format, type); + int i; DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__, _mesa_lookup_enum_by_nr(target), @@ -938,25 +933,28 @@ st_TexSubimage(GLcontext * ctx, /* Map buffer if necessary. Need to lock to prevent other contexts * from uploading the buffer under us. */ - if (stImage->mt) - texImage->Data = st_miptree_image_map(pipe, - stImage->mt, - stImage->face, - stImage->level, - &dstRowStride, - texImage->ImageOffsets); - - assert(dstRowStride); - - if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat, - texImage->TexFormat, - texImage->Data, - xoffset, yoffset, zoffset, - dstRowStride, - texImage->ImageOffsets, - width, height, depth, - format, type, pixels, packing)) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage"); + if (stImage->pt) { + texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset); + dstRowStride = stImage->surface->pitch * stImage->surface->cpp; + } + + for (i = 0; i++ < depth;) { + if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat, + texImage->TexFormat, + texImage->Data, + xoffset, yoffset, 0, + dstRowStride, + texImage->ImageOffsets, + width, height, 1, + format, type, pixels, packing)) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage"); + } + + if (stImage->pt && i < depth) { + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i); + pixels += srcImageStride; + } } #if 0 @@ -970,8 +968,8 @@ st_TexSubimage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, packing); - if (stImage->mt) { - st_miptree_image_unmap(pipe, stImage->mt); + if (stImage->pt) { + st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; } } @@ -1074,7 +1072,7 @@ fallback_copy_texsubimage(GLcontext *ctx, { struct pipe_context *pipe = ctx->st->pipe; const uint face = texture_face(target); - struct pipe_mipmap_tree *mt = stImage->mt; + struct pipe_texture *pt = stImage->pt; struct pipe_surface *src_surf, *dest_surf; GLfloat *data; GLint row, yStep; @@ -1090,7 +1088,7 @@ fallback_copy_texsubimage(GLcontext *ctx, src_surf = strb->surface; - dest_surf = pipe->get_tex_surface(pipe, mt, + dest_surf = pipe->get_tex_surface(pipe, pt, face, level, destZ); (void) pipe->region_map(pipe, dest_surf->region); @@ -1150,7 +1148,7 @@ do_copy_texsubimage(GLcontext *ctx, struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb; struct pipe_context *pipe = ctx->st->pipe; - struct pipe_region *src_region, *dest_region; + struct pipe_surface *dest_surface; uint dest_format, src_format; (void) texImage; @@ -1169,29 +1167,24 @@ do_copy_texsubimage(GLcontext *ctx, assert(strb); assert(strb->surface); - assert(stImage->mt); + assert(stImage->pt); if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { srcY = strb->Base.Height - srcY - height; } src_format = strb->surface->format; - dest_format = stImage->mt->format; + dest_format = stImage->pt->format; - src_region = strb->surface->region; - dest_region = stImage->mt->region; + dest_surface = pipe->get_tex_surface(pipe, stImage->pt, stImage->face, + stImage->level, destZ); if (src_format == dest_format && ctx->_ImageTransferState == 0x0 && - src_region && - dest_region && - strb->surface->cpp == stImage->mt->cpp) { + strb->surface->region && + dest_surface->region && + strb->surface->cpp == stImage->pt->cpp) { /* do blit-style copy */ - struct pipe_surface *dest_surface = pipe->get_tex_surface(pipe, - stImage->mt, - stImage->face, - stImage->level, - destZ); /* XXX may need to invert image depending on window * vs. user-created FBO @@ -1203,12 +1196,12 @@ do_copy_texsubimage(GLcontext *ctx, * worth it: */ intelEmitCopyBlit(intel, - stImage->mt->cpp, + stImage->pt->cpp, -src->pitch, src->buffer, src->height * src->pitch * src->cpp, - stImage->mt->pitch, - stImage->mt->region->buffer, + stImage->pt->pitch, + stImage->pt->region->buffer, dest_offset, x, y + height, dstx, dsty, width, height, GL_COPY); /* ? */ @@ -1224,8 +1217,6 @@ do_copy_texsubimage(GLcontext *ctx, /* size */ width, height); #endif - - pipe_surface_reference(&dest_surface, NULL); } else { fallback_copy_texsubimage(ctx, target, level, @@ -1234,6 +1225,7 @@ do_copy_texsubimage(GLcontext *ctx, srcX, srcY, width, height); } + pipe_surface_reference(&dest_surface, NULL); #if 0 /* GL_SGIS_generate_mipmap -- this can be accelerated now. @@ -1267,7 +1259,7 @@ st_CopyTexImage1D(GLcontext * ctx, GLenum target, GLint level, goto fail; #endif - /* Setup or redefine the texture object, mipmap tree and texture + /* Setup or redefine the texture object, texture and texture * image. Don't populate yet. */ ctx->Driver.TexImage1D(ctx, target, level, internalFormat, @@ -1299,7 +1291,7 @@ st_CopyTexImage2D(GLcontext * ctx, GLenum target, GLint level, goto fail; #endif - /* Setup or redefine the texture object, mipmap tree and texture + /* Setup or redefine the texture object, texture and texture * image. Don't populate yet. */ ctx->Driver.TexImage2D(ctx, target, level, internalFormat, @@ -1407,28 +1399,28 @@ calculate_first_last_level(struct st_texture_object *stObj) static void -copy_image_data_to_tree(struct pipe_context *pipe, - struct st_texture_object *stObj, - struct st_texture_image *stImage) +copy_image_data_to_texture(struct st_context *st, + struct st_texture_object *stObj, + struct st_texture_image *stImage) { - if (stImage->mt) { + if (stImage->pt) { /* Copy potentially with the blitter: */ - st_miptree_image_copy(pipe, - stObj->mt, /* dest miptree */ + st_texture_image_copy(st->pipe, + stObj->pt, /* dest texture */ stImage->face, stImage->level, - stImage->mt /* src miptree */ + stImage->pt /* src texture */ ); - st_miptree_release(pipe, &stImage->mt); + st->pipe->texture_release(st->pipe, &stImage->pt); } else { assert(stImage->base.Data != NULL); /* More straightforward upload. */ - st_miptree_image_data(pipe, - stObj->mt, + st_texture_image_data(st->pipe, + stObj->pt, stImage->face, stImage->level, stImage->base.Data, @@ -1439,16 +1431,16 @@ copy_image_data_to_tree(struct pipe_context *pipe, stImage->base.Data = NULL; } - st_miptree_reference(&stImage->mt, stObj->mt); + pipe_texture_reference(st->pipe, &stImage->pt, stObj->pt); } /* */ GLboolean -st_finalize_mipmap_tree(GLcontext *ctx, - struct pipe_context *pipe, GLuint unit, - GLboolean *needFlush) +st_finalize_texture(GLcontext *ctx, + struct pipe_context *pipe, GLuint unit, + GLboolean *needFlush) { struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current; struct st_texture_object *stObj = st_texture_object(tObj); @@ -1465,7 +1457,7 @@ st_finalize_mipmap_tree(GLcontext *ctx, */ assert(stObj->base._Complete); - /* What levels must the tree include at a minimum? + /* What levels must the texture include at a minimum? */ calculate_first_last_level(stObj); firstImage = @@ -1474,27 +1466,27 @@ st_finalize_mipmap_tree(GLcontext *ctx, /* Fallback case: */ if (firstImage->base.Border) { - if (stObj->mt) { - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); } return GL_FALSE; } - /* If both firstImage and stObj have a tree which can contain + /* If both firstImage and stObj point to a texture which can contain * all active images, favour firstImage. Note that because of the * completeness requirement, we know that the image dimensions * will match. */ - if (firstImage->mt && - firstImage->mt != stObj->mt && - firstImage->mt->first_level <= stObj->firstLevel && - firstImage->mt->last_level >= stObj->lastLevel) { + if (firstImage->pt && + firstImage->pt != stObj->pt && + firstImage->pt->first_level <= stObj->firstLevel && + firstImage->pt->last_level >= stObj->lastLevel) { - if (stObj->mt) - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt) + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); - st_miptree_reference(&stObj->mt, firstImage->mt); + pipe_texture_reference(ctx->st->pipe, &stObj->pt, firstImage->pt); } if (firstImage->base.IsCompressed) { @@ -1505,48 +1497,45 @@ st_finalize_mipmap_tree(GLcontext *ctx, cpp = firstImage->base.TexFormat->TexelBytes; } - /* Check tree can hold all active levels. Check tree matches + /* Check texture can hold all active levels. Check texture matches * target, imageFormat, etc. * * XXX: For some layouts (eg i945?), the test might have to be - * first_level == firstLevel, as the tree isn't valid except at the + * first_level == firstLevel, as the texture isn't valid except at the * original start level. Hope to get around this by * programming minLod, maxLod, baseLevel into the hardware and - * leaving the tree alone. + * leaving the texture alone. */ - if (stObj->mt && - (stObj->mt->target != gl_target_to_pipe(stObj->base.Target) || - stObj->mt->internal_format != firstImage->base.InternalFormat || - stObj->mt->first_level != stObj->firstLevel || - stObj->mt->last_level != stObj->lastLevel || - stObj->mt->width0 != firstImage->base.Width || - stObj->mt->height0 != firstImage->base.Height || - stObj->mt->depth0 != firstImage->base.Depth || - stObj->mt->cpp != cpp || - stObj->mt->compressed != firstImage->base.IsCompressed)) { - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt && + (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) || + stObj->pt->internal_format != firstImage->base.InternalFormat || + stObj->pt->first_level != stObj->firstLevel || + stObj->pt->last_level != stObj->lastLevel || + stObj->pt->width[0] != firstImage->base.Width || + stObj->pt->height[0] != firstImage->base.Height || + stObj->pt->depth[0] != firstImage->base.Depth || + stObj->pt->cpp != cpp || + stObj->pt->compressed != firstImage->base.IsCompressed)) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); } - /* May need to create a new tree: + /* May need to create a new texture: */ - if (!stObj->mt) { - stObj->mt = st_miptree_create(pipe, + if (!stObj->pt) { + stObj->pt = st_texture_create(ctx->st, gl_target_to_pipe(stObj->base.Target), - firstImage->base.InternalFormat, + st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat), + firstImage->base.InternalFormat, stObj->firstLevel, stObj->lastLevel, firstImage->base.Width, firstImage->base.Height, firstImage->base.Depth, - cpp, comp_byte); - - stObj->mt->format - = st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat); } - /* Pull in any images not in the object's tree: + /* Pull in any images not in the object's texture: */ nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; for (face = 0; face < nr_faces; face++) { @@ -1554,10 +1543,10 @@ st_finalize_mipmap_tree(GLcontext *ctx, struct st_texture_image *stImage = st_texture_image(stObj->base.Image[face][i]); - /* Need to import images in main memory or held in other trees. + /* Need to import images in main memory or held in other textures. */ - if (stObj->mt != stImage->mt) { - copy_image_data_to_tree(pipe, stObj, stImage); + if (stObj->pt != stImage->pt) { + copy_image_data_to_texture(ctx->st, stObj, stImage); *needFlush = GL_TRUE; } } diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h index 7a1867dc58..7f8082b029 100644 --- a/src/mesa/state_tracker/st_cb_texture.h +++ b/src/mesa/state_tracker/st_cb_texture.h @@ -2,14 +2,14 @@ #define ST_CB_TEXTURE_H -extern struct pipe_mipmap_tree * -st_get_texobj_mipmap_tree(struct gl_texture_object *texObj); +extern struct pipe_texture * +st_get_texobj_texture(struct gl_texture_object *texObj); extern GLboolean -st_finalize_mipmap_tree(GLcontext *ctx, - struct pipe_context *pipe, GLuint unit, - GLboolean *needFlush); +st_finalize_texture(GLcontext *ctx, + struct pipe_context *pipe, GLuint unit, + GLboolean *needFlush); extern void diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index a6045230a0..db97014c5a 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -36,7 +36,6 @@ struct st_context; struct st_region; struct st_texture_object; -struct st_texture_image; struct st_fragment_program; struct draw_context; struct draw_stage; @@ -61,6 +60,25 @@ struct st_tracked_state { +struct st_texture_image +{ + struct gl_texture_image base; + + /* These aren't stored in gl_texture_image + */ + GLuint level; + GLuint face; + + /* If stImage->pt != NULL, image data is stored here. + * Else if stImage->base.Data != NULL, image is stored there. + * Else there is no image data. + */ + struct pipe_texture *pt; + + struct pipe_surface *surface; +}; + + struct st_context { @@ -91,7 +109,7 @@ struct st_context struct pipe_constant_buffer constants[2]; struct pipe_feedback_state feedback; struct pipe_framebuffer_state framebuffer; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_viewport_state viewport; diff --git a/src/mesa/state_tracker/st_mipmap_tree.c b/src/mesa/state_tracker/st_mipmap_tree.c deleted file mode 100644 index 6ccf33105f..0000000000 --- a/src/mesa/state_tracker/st_mipmap_tree.c +++ /dev/null @@ -1,328 +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. - * - **************************************************************************/ - -#include "st_mipmap_tree.h" -#include "enums.h" - -#include "pipe/p_state.h" -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_util.h" -#include "pipe/p_inlines.h" -#include "pipe/p_winsys.h" - - -#define DBG if(0) printf - -#if 0 -static GLenum -target_to_target(GLenum target) -{ - switch (target) { - case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: - return GL_TEXTURE_CUBE_MAP_ARB; - default: - return target; - } -} -#endif - -struct pipe_mipmap_tree * -st_miptree_create(struct pipe_context *pipe, - unsigned target, - GLenum internal_format, - GLuint first_level, - GLuint last_level, - GLuint width0, - GLuint height0, - GLuint depth0, GLuint cpp, GLuint compress_byte) -{ - GLboolean ok; - struct pipe_mipmap_tree *mt = calloc(sizeof(*mt), 1); - GLbitfield flags = 0x0; - - assert(target <= PIPE_TEXTURE_CUBE); - - DBG("%s target %s format %s level %d..%d\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(target), - _mesa_lookup_enum_by_nr(internal_format), first_level, last_level); - - mt->target = target; - mt->internal_format = internal_format; - mt->first_level = first_level; - mt->last_level = last_level; - mt->width0 = width0; - mt->height0 = height0; - mt->depth0 = depth0; - mt->cpp = compress_byte ? compress_byte : cpp; - mt->compressed = compress_byte ? 1 : 0; - mt->refcount = 1; - - ok = pipe->mipmap_tree_layout(pipe, mt); - if (ok) { - mt->region = pipe->winsys->region_alloc(pipe->winsys, - mt->pitch * mt->cpp * - mt->total_height, flags); - } - - if (!mt->region) { - free(mt); - return NULL; - } - - return mt; -} - - -void -st_miptree_reference(struct pipe_mipmap_tree **dst, - struct pipe_mipmap_tree *src) -{ - src->refcount++; - *dst = src; - DBG("%s %p refcount now %d\n", __FUNCTION__, (void *) src, src->refcount); -} - -void -st_miptree_release(struct pipe_context *pipe, - struct pipe_mipmap_tree **mt) -{ - if (!*mt) - return; - - DBG("%s %p refcount will be %d\n", - __FUNCTION__, (void *) *mt, (*mt)->refcount - 1); - if (--(*mt)->refcount <= 0) { - GLuint i; - - DBG("%s deleting %p\n", __FUNCTION__, (void *) *mt); - - pipe->winsys->region_release(pipe->winsys, &((*mt)->region)); - - for (i = 0; i < MAX_TEXTURE_LEVELS; i++) - if ((*mt)->level[i].image_offset) - free((*mt)->level[i].image_offset); - - free(*mt); - } - *mt = NULL; -} - - - - -/* Can the image be pulled into a unified mipmap tree. This mirrors - * the completeness test in a lot of ways. - * - * Not sure whether I want to pass gl_texture_image here. - */ -GLboolean -st_miptree_match_image(struct pipe_mipmap_tree *mt, - struct gl_texture_image *image, - GLuint face, GLuint level) -{ - /* Images with borders are never pulled into mipmap trees. - */ - if (image->Border) - return GL_FALSE; - - if (image->InternalFormat != mt->internal_format || - image->IsCompressed != mt->compressed) - return GL_FALSE; - - /* Test image dimensions against the base level image adjusted for - * minification. This will also catch images not present in the - * tree, changed targets, etc. - */ - if (image->Width != mt->level[level].width || - image->Height != mt->level[level].height || - image->Depth != mt->level[level].depth) - return GL_FALSE; - - return GL_TRUE; -} - - -/* Although we use the image_offset[] array to store relative offsets - * to cube faces, Mesa doesn't know anything about this and expects - * each cube face to be treated as a separate image. - * - * These functions present that view to mesa: - */ -const GLuint * -st_miptree_depth_offsets(struct pipe_mipmap_tree *mt, GLuint level) -{ - static const GLuint zero = 0; - - if (mt->target != PIPE_TEXTURE_3D || mt->level[level].nr_images == 1) - return &zero; - else - return mt->level[level].image_offset; -} - - -/** - * Return the offset to the given mipmap texture image within the - * texture memory buffer, in bytes. - */ -GLuint -st_miptree_image_offset(const struct pipe_mipmap_tree * mt, - GLuint face, GLuint level) -{ - if (mt->target == PIPE_TEXTURE_CUBE) - return (mt->level[level].level_offset + - mt->level[level].image_offset[face] * mt->cpp); - else - return mt->level[level].level_offset; -} - - -GLuint -st_miptree_texel_offset(const struct pipe_mipmap_tree * mt, - GLuint face, GLuint level, - GLuint col, GLuint row, GLuint img) -{ - GLuint imgOffset = st_miptree_image_offset(mt, face, level); - - return imgOffset + row * (mt->pitch + col) * mt->cpp; -} - - - -/** - * Map a teximage in a mipmap tree. - * \param row_stride returns row stride in bytes - * \param image_stride returns image stride in bytes (for 3D textures). - * \return address of mapping - */ -GLubyte * -st_miptree_image_map(struct pipe_context *pipe, - struct pipe_mipmap_tree * mt, - GLuint face, - GLuint level, - GLuint * row_stride, GLuint * image_offsets) -{ - GLubyte *ptr; - DBG("%s \n", __FUNCTION__); - - if (row_stride) - *row_stride = mt->pitch * mt->cpp; - - if (image_offsets) - memcpy(image_offsets, mt->level[level].image_offset, - mt->level[level].depth * sizeof(GLuint)); - - ptr = pipe->region_map(pipe, mt->region); - - return ptr + st_miptree_image_offset(mt, face, level); -} - -void -st_miptree_image_unmap(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt) -{ - DBG("%s\n", __FUNCTION__); - pipe->region_unmap(pipe, mt->region); -} - - - -/* Upload data for a particular image. - */ -void -st_miptree_image_data(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, - GLuint level, - void *src, - GLuint src_row_pitch, GLuint src_image_pitch) -{ - GLuint depth = dst->level[level].depth; - GLuint i; - GLuint height = 0; - const GLubyte *srcUB = src; - struct pipe_surface *dst_surface; - - DBG("%s\n", __FUNCTION__); - for (i = 0; i < depth; i++) { - height = dst->level[level].height; - if(dst->compressed) - height /= 4; - - dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); - - pipe->surface_data(pipe, dst_surface, - 0, 0, /* dstx, dsty */ - srcUB, - src_row_pitch, - 0, 0, /* source x, y */ - dst->level[level].width, height); /* width, height */ - - pipe_surface_reference(&dst_surface, NULL); - - srcUB += src_image_pitch * dst->cpp; - } -} - -/* Copy mipmap image between trees - */ -void -st_miptree_image_copy(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, GLuint level, - struct pipe_mipmap_tree *src) -{ - GLuint width = src->level[level].width; - GLuint height = src->level[level].height; - GLuint depth = src->level[level].depth; - struct pipe_surface *src_surface; - struct pipe_surface *dst_surface; - GLuint i; - - if (dst->compressed) - height /= 4; - for (i = 0; i < depth; i++) { - dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); - src_surface = pipe->get_tex_surface(pipe, src, face, level, i); - - pipe->surface_copy(pipe, - dst_surface, - 0, 0, /* destX, Y */ - src_surface, - 0, 0, /* srcX, Y */ - width, height); - - pipe_surface_reference(&dst_surface, NULL); - pipe_surface_reference(&src_surface, NULL); - } - -} diff --git a/src/mesa/state_tracker/st_mipmap_tree.h b/src/mesa/state_tracker/st_mipmap_tree.h deleted file mode 100644 index 3e7fd7fa0c..0000000000 --- a/src/mesa/state_tracker/st_mipmap_tree.h +++ /dev/null @@ -1,118 +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. - * - **************************************************************************/ - -#ifndef ST_MIPMAP_TREE_H -#define ST_MIPMAP_TREE_H - - -#include "main/mtypes.h" - -struct pipe_context; -struct pipe_mipmap_tree; -struct pipe_region; - - -extern struct pipe_mipmap_tree * -st_miptree_create(struct pipe_context *pipe, - GLenum target, - GLenum internal_format, - GLuint first_level, - GLuint last_level, - GLuint width0, - GLuint height0, - GLuint depth0, - GLuint cpp, - GLuint compress_byte); - -extern void -st_miptree_reference(struct pipe_mipmap_tree **dst, - struct pipe_mipmap_tree *src); - -extern void -st_miptree_release(struct pipe_context *pipe, struct pipe_mipmap_tree **mt); - - -/* Check if an image fits an existing mipmap tree layout - */ -extern GLboolean -st_miptree_match_image(struct pipe_mipmap_tree *mt, - struct gl_texture_image *image, - GLuint face, GLuint level); - -/* Return a pointer to an image within a tree. Return image stride as - * well. - */ -extern GLubyte * -st_miptree_image_map(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, - GLuint face, GLuint level, - GLuint * row_stride, GLuint * image_stride); - -extern void -st_miptree_image_unmap(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt); - - -/* Return pointers to each 2d slice within an image. Indexed by depth - * value. - */ -extern const GLuint * -st_miptree_depth_offsets(struct pipe_mipmap_tree *mt, GLuint level); - - -/* Return the linear offset of an image relative to the start of the - * tree: - */ -extern GLuint -st_miptree_image_offset(const struct pipe_mipmap_tree *mt, - GLuint face, GLuint level); - -extern GLuint -st_miptree_texel_offset(const struct pipe_mipmap_tree * mt, - GLuint face, GLuint level, - GLuint col, GLuint row, GLuint img); - - -/* Upload an image into a tree - */ -extern void -st_miptree_image_data(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, GLuint level, void *src, - GLuint src_row_pitch, GLuint src_image_pitch); - - -/* Copy an image between two trees - */ -extern void -st_miptree_image_copy(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, GLuint level, - struct pipe_mipmap_tree *src); - - -#endif diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c new file mode 100644 index 0000000000..a5582c31c0 --- /dev/null +++ b/src/mesa/state_tracker/st_texture.c @@ -0,0 +1,276 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "st_context.h" +#include "st_format.h" +#include "st_texture.h" +#include "enums.h" + +#include "pipe/p_state.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_util.h" +#include "pipe/p_inlines.h" +#include "pipe/p_winsys.h" + + +#define DBG if(0) printf + +#if 0 +static GLenum +target_to_target(GLenum target) +{ + switch (target) { + case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: + return GL_TEXTURE_CUBE_MAP_ARB; + default: + return target; + } +} +#endif + +struct pipe_texture * +st_texture_create(struct st_context *st, + unsigned target, + unsigned format, + GLenum internal_format, + GLuint first_level, + GLuint last_level, + GLuint width0, + GLuint height0, + GLuint depth0, + GLuint compress_byte) +{ + struct pipe_texture *pt = CALLOC_STRUCT(pipe_texture); + + assert(target <= PIPE_TEXTURE_CUBE); + + DBG("%s target %s format %s level %d..%d\n", __FUNCTION__, + _mesa_lookup_enum_by_nr(target), + _mesa_lookup_enum_by_nr(internal_format), first_level, last_level); + + if (!pt) + return NULL; + + assert(format); + + pt->target = target; + pt->format = format; + pt->internal_format = internal_format; + pt->first_level = first_level; + pt->last_level = last_level; + pt->width[0] = width0; + pt->height[0] = height0; + pt->depth[0] = depth0; + pt->compressed = compress_byte ? 1 : 0; + pt->cpp = pt->compressed ? compress_byte : st_sizeof_format(format); + pt->refcount = 1; + + st->pipe->texture_create(st->pipe, &pt); + + return pt; +} + + + + +/* Can the image be pulled into a unified mipmap texture. This mirrors + * the completeness test in a lot of ways. + * + * Not sure whether I want to pass gl_texture_image here. + */ +GLboolean +st_texture_match_image(struct pipe_texture *pt, + struct gl_texture_image *image, + GLuint face, GLuint level) +{ + /* Images with borders are never pulled into mipmap textures. + */ + if (image->Border) + return GL_FALSE; + + if (image->InternalFormat != pt->internal_format || + image->IsCompressed != pt->compressed) + return GL_FALSE; + + /* Test image dimensions against the base level image adjusted for + * minification. This will also catch images not present in the + * texture, changed targets, etc. + */ + if (image->Width != pt->width[level] || + image->Height != pt->height[level] || + image->Depth != pt->depth[level]) + return GL_FALSE; + + return GL_TRUE; +} + + +#if 000 +/* Although we use the image_offset[] array to store relative offsets + * to cube faces, Mesa doesn't know anything about this and expects + * each cube face to be treated as a separate image. + * + * These functions present that view to mesa: + */ +const GLuint * +st_texture_depth_offsets(struct pipe_texture *pt, GLuint level) +{ + static const GLuint zero = 0; + + if (pt->target != PIPE_TEXTURE_3D || pt->level[level].nr_images == 1) + return &zero; + else + return pt->level[level].image_offset; +} + + +/** + * Return the offset to the given mipmap texture image within the + * texture memory buffer, in bytes. + */ +GLuint +st_texture_image_offset(const struct pipe_texture * pt, + GLuint face, GLuint level) +{ + if (pt->target == PIPE_TEXTURE_CUBE) + return (pt->level[level].level_offset + + pt->level[level].image_offset[face] * pt->cpp); + else + return pt->level[level].level_offset; +} +#endif + + +/** + * Map a teximage in a mipmap texture. + * \param row_stride returns row stride in bytes + * \param image_stride returns image stride in bytes (for 3D textures). + * \return address of mapping + */ +GLubyte * +st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, + GLuint zoffset) +{ + struct pipe_texture *pt = stImage->pt; + DBG("%s \n", __FUNCTION__); + + stImage->surface = st->pipe->get_tex_surface(st->pipe, pt, stImage->face, + stImage->level, zoffset); + + (void) st->pipe->region_map(st->pipe, stImage->surface->region); + + return stImage->surface->region->map + stImage->surface->offset; +} + +void +st_texture_image_unmap(struct st_context *st, struct st_texture_image *stImage) +{ + DBG("%s\n", __FUNCTION__); + + st->pipe->region_unmap(st->pipe, stImage->surface->region); + + pipe_surface_reference(&stImage->surface, NULL); +} + + + +/* Upload data for a particular image. + */ +void +st_texture_image_data(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, + GLuint level, + void *src, + GLuint src_row_pitch, GLuint src_image_pitch) +{ + GLuint depth = dst->depth[level]; + GLuint i; + GLuint height = 0; + const GLubyte *srcUB = src; + struct pipe_surface *dst_surface; + + DBG("%s\n", __FUNCTION__); + for (i = 0; i < depth; i++) { + height = dst->height[level]; + if(dst->compressed) + height /= 4; + + dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); + + pipe->surface_data(pipe, dst_surface, + 0, 0, /* dstx, dsty */ + srcUB, + src_row_pitch, + 0, 0, /* source x, y */ + dst->width[level], height); /* width, height */ + + pipe_surface_reference(&dst_surface, NULL); + + srcUB += src_image_pitch * dst->cpp; + } +} + +/* Copy mipmap image between textures + */ +void +st_texture_image_copy(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, GLuint level, + struct pipe_texture *src) +{ + GLuint width = src->width[level]; + GLuint height = src->height[level]; + GLuint depth = src->depth[level]; + struct pipe_surface *src_surface; + struct pipe_surface *dst_surface; + GLuint i; + + if (dst->compressed) + height /= 4; + for (i = 0; i < depth; i++) { + dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); + src_surface = pipe->get_tex_surface(pipe, src, face, level, i); + + pipe->surface_copy(pipe, + dst_surface, + 0, 0, /* destX, Y */ + src_surface, + 0, 0, /* srcX, Y */ + width, height); + + pipe_surface_reference(&dst_surface, NULL); + pipe_surface_reference(&src_surface, NULL); + } + +} diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h new file mode 100644 index 0000000000..b25e3f3f3b --- /dev/null +++ b/src/mesa/state_tracker/st_texture.h @@ -0,0 +1,109 @@ +/************************************************************************** + * + * 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_TEXTURE_H +#define ST_TEXTURE_H + + +#include "main/mtypes.h" + +struct pipe_context; +struct pipe_texture; +struct pipe_region; + + +extern struct pipe_texture * +st_texture_create(struct st_context *st, + unsigned target, + unsigned format, + GLenum internal_format, + GLuint first_level, + GLuint last_level, + GLuint width0, + GLuint height0, + GLuint depth0, + GLuint compress_byte); + + +/* Check if an image fits an existing texture + */ +extern GLboolean +st_texture_match_image(struct pipe_texture *pt, + struct gl_texture_image *image, + GLuint face, GLuint level); + +/* Return a pointer to an image within a texture. Return image stride as + * well. + */ +extern GLubyte * +st_texture_image_map(struct st_context *st, + struct st_texture_image *stImage, + GLuint zoffset); + +extern void +st_texture_image_unmap(struct st_context *st, + struct st_texture_image *stImage); + + +/* Return pointers to each 2d slice within an image. Indexed by depth + * value. + */ +extern const GLuint * +st_texture_depth_offsets(struct pipe_texture *pt, GLuint level); + + +/* Return the linear offset of an image relative to the start of its region: + */ +extern GLuint +st_texture_image_offset(const struct pipe_texture *pt, + GLuint face, GLuint level); + +extern GLuint +st_texture_texel_offset(const struct pipe_texture * pt, + GLuint face, GLuint level, + GLuint col, GLuint row, GLuint img); + + +/* Upload an image into a texture + */ +extern void +st_texture_image_data(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, GLuint level, void *src, + GLuint src_row_pitch, GLuint src_image_pitch); + + +/* Copy an image between two textures + */ +extern void +st_texture_image_copy(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, GLuint level, + struct pipe_texture *src); + + +#endif -- cgit v1.2.3 From b859cdf6f191b4d8b56537c8dc30082a7e2d94b3 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Fri, 7 Dec 2007 12:30:35 +0100 Subject: Eliminate struct pipe_region. Directly use struct pipe_buffer_handle for storage and struct pipe_surface for (un)mapping. --- .../drivers/dri/intel_winsys/intel_swapbuffers.c | 7 +- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 51 ++----------- src/mesa/pipe/failover/fo_context.c | 2 - src/mesa/pipe/i915simple/Makefile | 1 - src/mesa/pipe/i915simple/i915_context.c | 1 - src/mesa/pipe/i915simple/i915_context.h | 6 +- src/mesa/pipe/i915simple/i915_regions.c | 78 -------------------- src/mesa/pipe/i915simple/i915_state_emit.c | 6 +- src/mesa/pipe/i915simple/i915_surface.c | 35 ++++----- src/mesa/pipe/i915simple/i915_texture.c | 17 +++-- src/mesa/pipe/p_context.h | 10 +-- src/mesa/pipe/p_inlines.h | 53 +++++++------- src/mesa/pipe/p_state.h | 22 ++---- src/mesa/pipe/softpipe/Makefile | 1 - src/mesa/pipe/softpipe/sp_clear.c | 4 +- src/mesa/pipe/softpipe/sp_context.c | 84 ++++++---------------- src/mesa/pipe/softpipe/sp_draw_arrays.c | 2 - src/mesa/pipe/softpipe/sp_region.c | 79 -------------------- src/mesa/pipe/softpipe/sp_region.h | 40 ----------- src/mesa/pipe/softpipe/sp_state.h | 2 +- src/mesa/pipe/softpipe/sp_state_surface.c | 28 ++++---- src/mesa/pipe/softpipe/sp_surface.c | 61 ++++++++-------- src/mesa/pipe/softpipe/sp_texture.c | 18 +++-- src/mesa/pipe/softpipe/sp_tile_cache.c | 24 ++++++- src/mesa/pipe/softpipe/sp_tile_cache.h | 6 +- src/mesa/pipe/xlib/xm_api.c | 2 +- src/mesa/pipe/xlib/xm_buffer.c | 9 ++- src/mesa/pipe/xlib/xm_surface.c | 8 +-- src/mesa/pipe/xlib/xm_winsys.c | 50 +------------ src/mesa/state_tracker/st_cb_accum.c | 33 ++++----- src/mesa/state_tracker/st_cb_drawpixels.c | 48 ++++++------- src/mesa/state_tracker/st_cb_fbo.c | 28 ++++---- src/mesa/state_tracker/st_cb_readpixels.c | 13 ++-- src/mesa/state_tracker/st_cb_texture.c | 30 ++++---- src/mesa/state_tracker/st_context.c | 2 +- src/mesa/state_tracker/st_context.h | 5 +- src/mesa/state_tracker/st_texture.c | 9 ++- src/mesa/state_tracker/st_texture.h | 3 +- 38 files changed, 275 insertions(+), 603 deletions(-) delete mode 100644 src/mesa/pipe/i915simple/i915_regions.c delete mode 100644 src/mesa/pipe/softpipe/sp_region.c delete mode 100644 src/mesa/pipe/softpipe/sp_region.h (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c b/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c index f96209d1b0..454cd71f6c 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c @@ -88,12 +88,11 @@ intelDisplaySurface(__DRIdrawablePrivate *dPriv, const drm_clip_rect_t *pbox = dPriv->pClipRects; const int pitch = intelScreen->front.pitch / intelScreen->front.cpp; const int cpp = intelScreen->front.cpp; - const struct pipe_region *srcRegion = surf->region; const int srcpitch = surf->pitch; int BR13, CMD; int i; - ASSERT(srcRegion); + ASSERT(surf->buffer); ASSERT(surf->cpp == cpp); DBG(SWAP, "screen pitch %d src surface pitch %d\n", @@ -159,7 +158,7 @@ intelDisplaySurface(__DRIdrawablePrivate *dPriv, assert(box.x1 < box.x2); assert(box.y1 < box.y2); - /* XXX this could be done with pipe->region_copy() */ + /* XXX this could be done with pipe->surface_copy() */ BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS); OUT_BATCH(CMD); OUT_BATCH(BR13); @@ -171,7 +170,7 @@ intelDisplaySurface(__DRIdrawablePrivate *dPriv, DRM_BO_MASK_MEM | DRM_BO_FLAG_WRITE, 0); OUT_BATCH((sbox.y1 << 16) | sbox.x1); OUT_BATCH((srcpitch * cpp) & 0xffff); - OUT_RELOC(dri_bo(srcRegion->buffer), + OUT_RELOC(dri_bo(surf->buffer), DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, DRM_BO_MASK_MEM | DRM_BO_FLAG_READ, 0); 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 7b3aa99482..1b71d0ac10 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -135,13 +135,12 @@ static void intel_buffer_get_subdata(struct pipe_winsys *winsys, * for all buffers. */ static struct pipe_buffer_handle * -intel_buffer_create(struct pipe_winsys *winsys, - unsigned alignment) +intel_buffer_create(struct pipe_winsys *winsys, unsigned flags) { struct _DriBufferObject *buffer; struct intel_pipe_winsys *iws = intel_pipe_winsys(winsys); driGenBuffers( iws->regionPool, - "pipe buffer", 1, &buffer, alignment, 0, 0 ); + "pipe buffer", 1, &buffer, 64, 0, 0 ); return pipe_bo(buffer); } @@ -193,46 +192,6 @@ intel_i915_surface_pitch(struct pipe_winsys *winsys, } -static struct pipe_region * -intel_i915_region_alloc(struct pipe_winsys *winsys, - unsigned size, unsigned flags) -{ - struct pipe_region *region = calloc(sizeof(*region), 1); - const unsigned alignment = 64; - - region->refcount = 1; - - region->buffer = winsys->buffer_create( winsys, alignment ); - - winsys->buffer_data( winsys, - region->buffer, - size, - NULL, - PIPE_BUFFER_USAGE_PIXEL ); - - return region; -} - -static void -intel_i915_region_release(struct pipe_winsys *winsys, - struct pipe_region **region) -{ - if (!*region) - return; - - assert((*region)->refcount > 0); - (*region)->refcount--; - - if ((*region)->refcount == 0) { - assert((*region)->map_refcount == 0); - - winsys->buffer_reference( winsys, &((*region)->buffer), NULL ); - free(*region); - } - *region = NULL; -} - - static struct pipe_surface * intel_i915_surface_alloc(struct pipe_winsys *winsys, unsigned format) { @@ -252,8 +211,8 @@ intel_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) struct pipe_surface *surf = *s; surf->refcount--; if (surf->refcount == 0) { - if (surf->region) - winsys->region_release(winsys, &surf->region); + if (surf->buffer) + winsys->buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; @@ -300,8 +259,6 @@ intel_create_pipe_winsys( int fd ) iws->winsys.flush_frontbuffer = intel_flush_frontbuffer; iws->winsys.printf = intel_printf; iws->winsys.get_name = intel_get_name; - iws->winsys.region_alloc = intel_i915_region_alloc; - iws->winsys.region_release = intel_i915_region_release; iws->winsys.surface_pitch = intel_i915_surface_pitch; iws->winsys.surface_alloc = intel_i915_surface_alloc; iws->winsys.surface_release = intel_i915_surface_release; diff --git a/src/mesa/pipe/failover/fo_context.c b/src/mesa/pipe/failover/fo_context.c index a25563d451..a1291f583b 100644 --- a/src/mesa/pipe/failover/fo_context.c +++ b/src/mesa/pipe/failover/fo_context.c @@ -140,8 +140,6 @@ struct pipe_context *failover_create( struct pipe_context *hw, #endif failover->pipe.get_tex_surface = hw->get_tex_surface; - failover->pipe.region_map = hw->region_map; - failover->pipe.region_unmap = hw->region_unmap; failover->pipe.surface_data = hw->surface_data; failover->pipe.surface_copy = hw->surface_copy; failover->pipe.surface_fill = hw->surface_fill; diff --git a/src/mesa/pipe/i915simple/Makefile b/src/mesa/pipe/i915simple/Makefile index 1223b386a3..2f91de3afc 100644 --- a/src/mesa/pipe/i915simple/Makefile +++ b/src/mesa/pipe/i915simple/Makefile @@ -12,7 +12,6 @@ DRIVER_SOURCES = \ i915_context.c \ i915_debug.c \ i915_debug_fp.c \ - i915_regions.c \ i915_state.c \ i915_state_immediate.c \ i915_state_dynamic.c \ diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index 94649231cf..07b331c528 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -348,7 +348,6 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys, draw_set_rasterize_stage(i915->draw, i915_draw_render_stage(i915)); } - i915_init_region_functions(i915); i915_init_surface_functions(i915); i915_init_state_functions(i915); i915_init_flush_functions(i915); diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index 8ed3465be2..dbf0c885cc 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -175,7 +175,7 @@ struct i915_texture { /* The data is held here: */ - struct pipe_region *region; + struct pipe_buffer_handle *buffer; }; struct i915_context @@ -289,10 +289,10 @@ void i915_clear(struct pipe_context *pipe, struct pipe_surface *ps, /*********************************************************************** - * i915_region.c: + * i915_surface.c: */ -void i915_init_region_functions( struct i915_context *i915 ); void i915_init_surface_functions( struct i915_context *i915 ); + void i915_init_state_functions( struct i915_context *i915 ); void i915_init_flush_functions( struct i915_context *i915 ); void i915_init_string_functions( struct i915_context *i915 ); diff --git a/src/mesa/pipe/i915simple/i915_regions.c b/src/mesa/pipe/i915simple/i915_regions.c deleted file mode 100644 index 82fdec83d0..0000000000 --- a/src/mesa/pipe/i915simple/i915_regions.c +++ /dev/null @@ -1,78 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 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. - * - **************************************************************************/ - -/* Provide additional functionality on top of bufmgr buffers: - * - 2d semantics and blit operations (XXX: remove/simplify blits??) - * - refcounting of buffers for multiple images in a buffer. - * - refcounting of buffer mappings. - */ - -#include "pipe/p_defines.h" -#include "pipe/p_winsys.h" -#include "i915_context.h" - - - - -static ubyte * -i915_region_map(struct pipe_context *pipe, struct pipe_region *region) -{ - struct i915_context *i915 = i915_context( pipe ); - - if (!region->map_refcount++) { - region->map = i915->pipe.winsys->buffer_map( i915->pipe.winsys, - region->buffer, - PIPE_BUFFER_FLAG_WRITE | - PIPE_BUFFER_FLAG_READ); - } - - return region->map; -} - -static void -i915_region_unmap(struct pipe_context *pipe, struct pipe_region *region) -{ - struct i915_context *i915 = i915_context( pipe ); - - if (region->map_refcount > 0) { - assert(region->map); - if (!--region->map_refcount) { - i915->pipe.winsys->buffer_unmap( i915->pipe.winsys, - region->buffer ); - region->map = NULL; - } - } -} - - -void -i915_init_region_functions(struct i915_context *i915) -{ - i915->pipe.region_map = i915_region_map; - i915->pipe.region_unmap = i915_region_unmap; -} - diff --git a/src/mesa/pipe/i915simple/i915_state_emit.c b/src/mesa/pipe/i915simple/i915_state_emit.c index 900a91d896..eda40d7c76 100644 --- a/src/mesa/pipe/i915simple/i915_state_emit.c +++ b/src/mesa/pipe/i915simple/i915_state_emit.c @@ -220,7 +220,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) BUF_3D_PITCH(pitch) | /* pitch in bytes */ BUF_3D_USE_FENCE); - OUT_RELOC(cbuf_surface->region->buffer, + OUT_RELOC(cbuf_surface->buffer, I915_BUFFER_ACCESS_WRITE, 0); } @@ -236,7 +236,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) BUF_3D_PITCH(zpitch) | /* pitch in bytes */ BUF_3D_USE_FENCE); - OUT_RELOC(depth_surface->region->buffer, + OUT_RELOC(depth_surface->buffer, I915_BUFFER_ACCESS_WRITE, 0); } @@ -284,7 +284,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) for (unit = 0; unit < I915_TEX_UNITS; unit++) { if (enabled & (1 << unit)) { struct pipe_buffer_handle *buf = - i915->texture[unit]->region->buffer; + i915->texture[unit]->buffer; uint offset = 0; assert(buf); diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index 385202507d..ecbabe50eb 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -29,6 +29,7 @@ #include "i915_blit.h" #include "i915_state.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_inlines.h" #include "pipe/p_winsys.h" @@ -57,7 +58,7 @@ i915_get_tile_rgba(struct pipe_context *pipe, uint x, uint y, uint w, uint h, float *p) { const unsigned *src - = ((const unsigned *) (ps->region->map + ps->offset)) + = ((const unsigned *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -129,7 +130,7 @@ i915_get_tile(struct pipe_context *pipe, ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); CLIP_TILE; @@ -137,7 +138,7 @@ i915_get_tile(struct pipe_context *pipe, dst_stride = w0 * cpp; } - pSrc = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; + pSrc = ps->map + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { @@ -163,7 +164,7 @@ i915_put_tile(struct pipe_context *pipe, ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); CLIP_TILE; @@ -172,7 +173,7 @@ i915_put_tile(struct pipe_context *pipe, } pSrc = (const ubyte *) p; - pDest = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; + pDest = ps->map + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w0 * cpp); @@ -211,7 +212,7 @@ i915_get_tex_surface(struct pipe_context *pipe, if (ps) { assert(ps->format); assert(ps->refcount); - pipe_region_reference(&ps->region, tex->region); + pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, tex->buffer); ps->cpp = pt->cpp; ps->width = pt->width[level]; ps->height = pt->height[level]; @@ -274,12 +275,12 @@ i915_surface_data(struct pipe_context *pipe, const void *src, unsigned src_pitch, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - _mesa_copy_rect(pipe->region_map(pipe, dst->region) + dst->offset, + _mesa_copy_rect(pipe_surface_map(dst), dst->cpp, dst->pitch, dstx, dsty, width, height, src, src_pitch, srcx, srcy); - pipe->region_unmap(pipe, dst->region); + pipe_surface_unmap(dst); } @@ -297,23 +298,23 @@ i915_surface_copy(struct pipe_context *pipe, assert( dst->cpp == src->cpp ); if (0) { - _mesa_copy_rect(pipe->region_map(pipe, dst->region) + dst->offset, + _mesa_copy_rect(pipe_surface_map(dst), dst->cpp, dst->pitch, dstx, dsty, width, height, - pipe->region_map(pipe, src->region) + src->offset, + pipe_surface_map(src), src->pitch, srcx, srcy); - pipe->region_unmap(pipe, src->region); - pipe->region_unmap(pipe, dst->region); + pipe_surface_unmap(src); + pipe_surface_unmap(dst); } else { i915_copy_blit( i915_context(pipe), dst->cpp, - (short) src->pitch, src->region->buffer, src->offset, - (short) dst->pitch, dst->region->buffer, dst->offset, + (short) src->pitch, src->buffer, src->offset, + (short) dst->pitch, dst->buffer, dst->offset, (short) srcx, (short) srcy, (short) dstx, (short) dsty, (short) width, (short) height ); } } @@ -324,7 +325,7 @@ i915_surface_copy(struct pipe_context *pipe, static ubyte * get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) { - return dst->region->map + (y * dst->pitch + x) * dst->cpp; + return dst->map + (y * dst->pitch + x) * dst->cpp; } @@ -337,7 +338,7 @@ i915_surface_fill(struct pipe_context *pipe, if (0) { unsigned i, j; - (void)pipe->region_map(pipe, dst->region); + (void)pipe_surface_map(dst); switch (dst->cpp) { case 1: { @@ -375,7 +376,7 @@ i915_surface_fill(struct pipe_context *pipe, i915_fill_blit( i915_context(pipe), dst->cpp, (short) dst->pitch, - dst->region->buffer, dst->offset, + dst->buffer, dst->offset, (short) dstx, (short) dsty, (short) width, (short) height, value ); diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c index 3bfa806d9e..1ca2815dfb 100644 --- a/src/mesa/pipe/i915simple/i915_texture.c +++ b/src/mesa/pipe/i915simple/i915_texture.c @@ -33,6 +33,7 @@ #include "pipe/p_state.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_winsys.h" @@ -494,13 +495,17 @@ i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) : i915_miptree_layout(pipe, tex)) { - tex->region = pipe->winsys->region_alloc(pipe->winsys, - tex->pitch * tex->base.cpp * - tex->total_height, - PIPE_SURFACE_FLAG_TEXTURE); + tex->buffer = pipe->winsys->buffer_create(pipe->winsys, + PIPE_SURFACE_FLAG_TEXTURE); + + if (tex->buffer) + pipe->winsys->buffer_data(pipe->winsys, tex->buffer, + tex->pitch * tex->base.cpp * + tex->total_height, NULL, + PIPE_BUFFER_USAGE_PIXEL); } - if (!tex->region) { + if (!tex->buffer) { FREE(tex); tex = NULL; } @@ -527,7 +532,7 @@ i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); */ - pipe->winsys->region_release(pipe->winsys, &tex->region); + pipe->winsys->buffer_reference(pipe->winsys, &tex->buffer, NULL); for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) if (tex->image_offset[i]) diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 5033209323..2420d02213 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -37,7 +37,7 @@ struct pipe_state_cache; * Gallium rendering context. Basically: * - state setting functions * - VBO drawing functions - * - memory region function + * - surface functions * - device queries */ struct pipe_context { @@ -201,14 +201,6 @@ struct pipe_context { uint x, uint y, uint w, uint h, const float *p); - /* - * Memory region functions - */ - ubyte *(*region_map)(struct pipe_context *pipe, struct pipe_region *r); - - void (*region_unmap)(struct pipe_context *pipe, struct pipe_region *r); - - /* * Surface functions */ diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index c04d46dddd..1697284b04 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -29,40 +29,42 @@ #define P_INLINES_H #include "p_context.h" +#include "p_defines.h" #include "p_winsys.h" -/** - * Set 'ptr' to point to 'region' and update reference counting. - * The old thing pointed to, if any, will be unreferenced first. - * 'region' may be NULL. - */ +static INLINE ubyte * +pipe_surface_map(struct pipe_surface *surface) +{ + if (!surface->map_refcount++) { + surface->map = surface->winsys->buffer_map( surface->winsys, + surface->buffer, + PIPE_BUFFER_FLAG_WRITE | + PIPE_BUFFER_FLAG_READ ) + + surface->offset; + } + + return surface->map; +} + static INLINE void -pipe_region_reference(struct pipe_region **ptr, struct pipe_region *region) +pipe_surface_unmap(struct pipe_surface *surface) { - assert(ptr); - if (*ptr) { - /* unreference the old thing */ - struct pipe_region *oldReg = *ptr; - assert(oldReg->refcount > 0); - oldReg->refcount--; - if (oldReg->refcount == 0) { - /* free the old region */ - assert(oldReg->map_refcount == 0); - /* XXX dereference the region->buffer */ - FREE( oldReg ); + if (surface->map_refcount > 0) { + assert(surface->map); + if (!--surface->map_refcount) { + surface->winsys->buffer_unmap( surface->winsys, + surface->buffer ); + surface->map = NULL; } - *ptr = NULL; - } - if (region) { - /* reference the new thing */ - region->refcount++; - *ptr = region; } } + /** - * \sa pipe_region_reference + * Set 'ptr' to point to 'surf' and update reference counting. + * The old thing pointed to, if any, will be unreferenced first. + * 'surf' may be NULL. */ static INLINE void pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) @@ -82,7 +84,7 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) /** - * \sa pipe_region_reference + * \sa pipe_surface_reference */ static INLINE void pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr, @@ -100,4 +102,5 @@ pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr, } } + #endif /* P_INLINES_H */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 077a8f5a06..44dec9b773 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -256,32 +256,20 @@ struct pipe_sampler_state }; -/*** - *** Resource Objects - ***/ - -struct pipe_region -{ - struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ - - unsigned refcount; /**< Reference count for region */ - ubyte *map; /**< only non-NULL when region is actually mapped */ - unsigned map_refcount; /**< Reference count for mapping */ -}; - - /** - * 2D surface. This is basically a view into a pipe_region (memory buffer). + * 2D surface. This is basically a view into a memory buffer. * May be a renderbuffer, texture mipmap level, etc. */ struct pipe_surface { - struct pipe_region *region; + 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 */ unsigned cpp; /**< bytes per pixel */ unsigned width, height; unsigned pitch; /**< in pixels */ - unsigned offset; /**< offset from start of region, in bytes */ + unsigned offset; /**< offset from start of buffer, in bytes */ unsigned refcount; struct pipe_winsys *winsys; /**< winsys which owns/created the surface */ }; diff --git a/src/mesa/pipe/softpipe/Makefile b/src/mesa/pipe/softpipe/Makefile index 9978884c9b..647cc05373 100644 --- a/src/mesa/pipe/softpipe/Makefile +++ b/src/mesa/pipe/softpipe/Makefile @@ -24,7 +24,6 @@ DRIVER_SOURCES = \ sp_quad_output.c \ sp_quad_stencil.c \ sp_quad_stipple.c \ - sp_region.c \ sp_state_blend.c \ sp_state_clip.c \ sp_state_derived.c \ diff --git a/src/mesa/pipe/softpipe/sp_clear.c b/src/mesa/pipe/softpipe/sp_clear.c index a4276362b9..496b38fd5f 100644 --- a/src/mesa/pipe/softpipe/sp_clear.c +++ b/src/mesa/pipe/softpipe/sp_clear.c @@ -50,12 +50,12 @@ softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps, softpipe_update_derived(softpipe); /* not needed?? */ - if (ps == sp_tile_cache_get_surface(softpipe->zbuf_cache)) { + if (ps == sp_tile_cache_get_surface(softpipe, softpipe->zbuf_cache)) { float clear[4]; clear[0] = 1.0; /* XXX hack */ sp_tile_cache_clear(softpipe->zbuf_cache, clear); } - else if (ps == sp_tile_cache_get_surface(softpipe->cbuf_cache[0])) { + else if (ps == sp_tile_cache_get_surface(softpipe, softpipe->cbuf_cache[0])) { float clear[4]; clear[0] = 0.2f; /* XXX hack */ clear[1] = 0.2f; /* XXX hack */ diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 7a9fccce9a..f7f0316cf2 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -31,12 +31,12 @@ #include "pipe/draw/draw_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "sp_clear.h" #include "sp_context.h" #include "sp_flush.h" #include "sp_prim_setup.h" -#include "sp_region.h" #include "sp_state.h" #include "sp_surface.h" #include "sp_tile_cache.h" @@ -65,44 +65,22 @@ softpipe_is_format_supported( struct pipe_context *pipe, uint format ) void softpipe_map_surfaces(struct softpipe_context *sp) { - struct pipe_context *pipe = &sp->pipe; + struct pipe_surface *ps; unsigned i; for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - struct pipe_surface *ps = sp->framebuffer.cbufs[i]; - if (ps->region && !ps->region->map) { - pipe->region_map(pipe, ps->region); - } + ps = sp->framebuffer.cbufs[i]; + if (ps->buffer) + pipe_surface_map(ps); } - if (sp->framebuffer.zbuf) { - struct pipe_surface *ps = sp->framebuffer.zbuf; - if (ps->region && !ps->region->map) { - pipe->region_map(pipe, ps->region); - } - } - - if (sp->framebuffer.sbuf) { - struct pipe_surface *ps = sp->framebuffer.sbuf; - if (ps->region && !ps->region->map) { - pipe->region_map(pipe, ps->region); - } - } -} - + ps = sp->framebuffer.zbuf; + if (ps && ps->buffer) + pipe_surface_map(ps); -void -softpipe_map_texture_surfaces(struct softpipe_context *sp) -{ - struct pipe_context *pipe = &sp->pipe; - uint i; - - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct softpipe_texture *spt = sp->texture[i]; - if (spt) { - pipe->region_map(pipe, spt->region); - } - } + ps = sp->framebuffer.sbuf; + if (ps && ps->buffer) + pipe_surface_map(ps); } @@ -112,7 +90,7 @@ softpipe_map_texture_surfaces(struct softpipe_context *sp) void softpipe_unmap_surfaces(struct softpipe_context *sp) { - struct pipe_context *pipe = &sp->pipe; + struct pipe_surface *ps; uint i; for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) @@ -121,36 +99,18 @@ softpipe_unmap_surfaces(struct softpipe_context *sp) sp_flush_tile_cache(sp, sp->sbuf_cache); for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - struct pipe_surface *ps = sp->framebuffer.cbufs[i]; - if (ps->region) - pipe->region_unmap(pipe, ps->region); + ps = sp->framebuffer.cbufs[i]; + if (ps->map) + pipe_surface_unmap(ps); } - if (sp->framebuffer.zbuf) { - struct pipe_surface *ps = sp->framebuffer.zbuf; - if (ps->region) - pipe->region_unmap(pipe, ps->region); - } - - if (sp->framebuffer.sbuf && sp->framebuffer.sbuf != sp->framebuffer.zbuf) { - struct pipe_surface *ps = sp->framebuffer.sbuf; - if (ps->region) - pipe->region_unmap(pipe, ps->region); - } -} - + ps = sp->framebuffer.zbuf; + if (ps && ps->map) + pipe_surface_unmap(ps); -void -softpipe_unmap_texture_surfaces(struct softpipe_context *sp) -{ - struct pipe_context *pipe = &sp->pipe; - uint i; - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct softpipe_texture *spt = sp->texture[i]; - if (spt) { - pipe->region_unmap(pipe, spt->region); - } - } + ps = sp->framebuffer.sbuf; + if (ps && ps->map) + pipe_surface_unmap(ps); } @@ -403,8 +363,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, draw_set_rasterize_stage(softpipe->draw, softpipe->setup); } - - sp_init_region_functions(softpipe); sp_init_surface_functions(softpipe); return &softpipe->pipe; diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c index 8a82cdfe1a..93eb68405d 100644 --- a/src/mesa/pipe/softpipe/sp_draw_arrays.c +++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c @@ -112,7 +112,6 @@ softpipe_draw_elements(struct pipe_context *pipe, softpipe_update_derived( sp ); softpipe_map_surfaces(sp); - softpipe_map_texture_surfaces(sp); softpipe_map_constant_buffers(sp); /* @@ -184,7 +183,6 @@ softpipe_draw_elements(struct pipe_context *pipe, /* Note: leave drawing surfaces mapped */ - softpipe_unmap_texture_surfaces(sp); softpipe_unmap_constant_buffers(sp); return TRUE; diff --git a/src/mesa/pipe/softpipe/sp_region.c b/src/mesa/pipe/softpipe/sp_region.c deleted file mode 100644 index 58dc6bb96e..0000000000 --- a/src/mesa/pipe/softpipe/sp_region.c +++ /dev/null @@ -1,79 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 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. - * - **************************************************************************/ - -/* Provide additional functionality on top of bufmgr buffers: - * - 2d semantics and blit operations (XXX: remove/simplify blits??) - * - refcounting of buffers for multiple images in a buffer. - * - refcounting of buffer mappings. - */ - -#include "sp_context.h" -#include "sp_region.h" -#include "pipe/p_util.h" -#include "pipe/p_winsys.h" -#include "pipe/p_defines.h" - - - -static ubyte * -sp_region_map(struct pipe_context *pipe, struct pipe_region *region) -{ - struct softpipe_context *sp = softpipe_context( pipe ); - - if (!region->map_refcount++) { - region->map = sp->pipe.winsys->buffer_map( sp->pipe.winsys, - region->buffer, - PIPE_BUFFER_FLAG_WRITE | - PIPE_BUFFER_FLAG_READ); - } - - return region->map; -} - -static void -sp_region_unmap(struct pipe_context *pipe, struct pipe_region *region) -{ - struct softpipe_context *sp = softpipe_context( pipe ); - - if (region->map_refcount > 0) { - assert(region->map); - if (!--region->map_refcount) { - sp->pipe.winsys->buffer_unmap( sp->pipe.winsys, - region->buffer ); - region->map = NULL; - } - } -} - - -void -sp_init_region_functions(struct softpipe_context *sp) -{ - sp->pipe.region_map = sp_region_map; - sp->pipe.region_unmap = sp_region_unmap; -} - diff --git a/src/mesa/pipe/softpipe/sp_region.h b/src/mesa/pipe/softpipe/sp_region.h deleted file mode 100644 index 432746b27f..0000000000 --- a/src/mesa/pipe/softpipe/sp_region.h +++ /dev/null @@ -1,40 +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. - * - **************************************************************************/ - - -#ifndef SP_REGION_H -#define SP_REGION_H - - -struct softpipe_context; - - -extern void -sp_init_region_functions(struct softpipe_context *sp); - - -#endif /* SP_REGION_H */ diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index a543735b52..daf9955ca5 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -78,7 +78,7 @@ struct softpipe_texture /* The data is held here: */ - struct pipe_region *region; + struct pipe_buffer_handle *buffer; }; void * diff --git a/src/mesa/pipe/softpipe/sp_state_surface.c b/src/mesa/pipe/softpipe/sp_state_surface.c index d4e0bd1e15..9470ef485f 100644 --- a/src/mesa/pipe/softpipe/sp_state_surface.c +++ b/src/mesa/pipe/softpipe/sp_state_surface.c @@ -27,6 +27,8 @@ /* Authors: Keith Whitwell */ +#include "p_inlines.h" + #include "sp_context.h" #include "sp_state.h" #include "sp_surface.h" @@ -54,17 +56,17 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, sp_flush_tile_cache(sp, sp->cbuf_cache[i]); /* unmap old */ ps = sp->framebuffer.cbufs[i]; - if (ps && ps->region) - pipe->region_unmap(pipe, ps->region); + if (ps && ps->map) + pipe_surface_unmap(ps); /* map new */ ps = fb->cbufs[i]; if (ps) - pipe->region_map(pipe, ps->region); + pipe_surface_map(ps); /* assign new */ sp->framebuffer.cbufs[i] = fb->cbufs[i]; /* update cache */ - sp_tile_cache_set_surface(sp->cbuf_cache[i], ps); + sp_tile_cache_set_surface(sp, sp->cbuf_cache[i], ps); } } @@ -76,8 +78,8 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, sp_flush_tile_cache(sp, sp->zbuf_cache); /* unmap old */ ps = sp->framebuffer.zbuf; - if (ps && ps->region) - pipe->region_unmap(pipe, ps->region); + if (ps && ps->map) + pipe_surface_unmap(ps); if (sp->framebuffer.sbuf == sp->framebuffer.zbuf) { /* combined z/stencil */ sp->framebuffer.sbuf = NULL; @@ -85,12 +87,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, /* map new */ ps = fb->zbuf; if (ps) - pipe->region_map(pipe, ps->region); + pipe_surface_map(ps); /* assign new */ sp->framebuffer.zbuf = fb->zbuf; /* update cache */ - sp_tile_cache_set_surface(sp->zbuf_cache, ps); + sp_tile_cache_set_surface(sp, sp->zbuf_cache, ps); } /* XXX combined depth/stencil here */ @@ -101,12 +103,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, sp_flush_tile_cache(sp, sp->sbuf_cache_sep); /* unmap old */ ps = sp->framebuffer.sbuf; - if (ps && ps->region) - pipe->region_unmap(pipe, ps->region); + if (ps && ps->map) + pipe_surface_unmap(ps); /* map new */ ps = fb->sbuf; if (ps && fb->sbuf != fb->zbuf) - pipe->region_map(pipe, ps->region); + pipe_surface_map(ps); /* assign new */ sp->framebuffer.sbuf = fb->sbuf; @@ -114,12 +116,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, if (fb->sbuf != fb->zbuf) { /* separate stencil buf */ sp->sbuf_cache = sp->sbuf_cache_sep; - sp_tile_cache_set_surface(sp->sbuf_cache, ps); + sp_tile_cache_set_surface(sp, sp->sbuf_cache, ps); } else { /* combined depth/stencil */ sp->sbuf_cache = sp->zbuf_cache; - sp_tile_cache_set_surface(sp->sbuf_cache, ps); + sp_tile_cache_set_surface(sp, sp->sbuf_cache, ps); } } diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index c41bbc59b9..c61e0842fc 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -76,7 +76,7 @@ a8r8g8b8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const unsigned *src - = ((const unsigned *) (ps->region->map + ps->offset)) + = ((const unsigned *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -107,7 +107,7 @@ a8r8g8b8_put_tile(struct pipe_surface *ps, const float *p) { unsigned *dst - = ((unsigned *) (ps->region->map + ps->offset)) + = ((unsigned *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -140,7 +140,7 @@ b8g8r8a8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const unsigned *src - = ((const unsigned *) (ps->region->map + ps->offset)) + = ((const unsigned *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -171,7 +171,7 @@ b8g8r8a8_put_tile(struct pipe_surface *ps, const float *p) { unsigned *dst - = ((unsigned *) (ps->region->map + ps->offset)) + = ((unsigned *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -204,7 +204,7 @@ a1r5g5b5_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->region->map + ps->offset)) + = ((const ushort *) (ps->map)) + y * ps->pitch + x; unsigned i, j; @@ -235,7 +235,7 @@ z16_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->region->map + ps->offset)) + = ((const ushort *) (ps->map)) + y * ps->pitch + x; const float scale = 1.0f / 65535.0f; unsigned i, j; @@ -268,7 +268,7 @@ l8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->region->map + ps->offset)) + = ((const ubyte *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -299,7 +299,7 @@ a8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->region->map + ps->offset)) + = ((const ubyte *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -330,7 +330,7 @@ r16g16b16a16_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const short *src - = ((const short *) (ps->region->map + ps->offset)) + = ((const short *) (ps->map)) + (y * ps->pitch + x) * 4; unsigned i, j; unsigned w0 = w; @@ -362,7 +362,7 @@ r16g16b16a16_put_tile(struct pipe_surface *ps, const float *p) { short *dst - = ((short *) (ps->region->map + ps->offset)) + = ((short *) (ps->map)) + (y * ps->pitch + x) * 4; unsigned i, j; unsigned w0 = w; @@ -399,7 +399,7 @@ i8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->region->map + ps->offset)) + = ((const ubyte *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -430,7 +430,7 @@ a8_l8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->region->map + ps->offset)) + = ((const ushort *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -467,7 +467,7 @@ z32_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->region->map + ps->offset)) + = ((const uint *) (ps->map)) + y * ps->pitch + x; const double scale = 1.0 / (double) 0xffffffff; unsigned i, j; @@ -501,7 +501,7 @@ s8z24_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->region->map + ps->offset)) + = ((const uint *) (ps->map)) + y * ps->pitch + x; const double scale = 1.0 / ((1 << 24) - 1); unsigned i, j; @@ -535,7 +535,7 @@ z24s8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->region->map + ps->offset)) + = ((const uint *) (ps->map)) + y * ps->pitch + x; const double scale = 1.0 / ((1 << 24) - 1); unsigned i, j; @@ -589,7 +589,7 @@ softpipe_get_tex_surface(struct pipe_context *pipe, if (ps) { assert(ps->format); assert(ps->refcount); - pipe_region_reference(&ps->region, spt->region); + pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, spt->buffer); ps->cpp = pt->cpp; ps->width = pt->width[level]; ps->height = pt->height[level]; @@ -613,7 +613,7 @@ softpipe_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); if (dst_stride == 0) { dst_stride = w * cpp; @@ -621,7 +621,7 @@ softpipe_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, CLIP_TILE; - pSrc = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; + pSrc = ps->map + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { @@ -645,7 +645,7 @@ softpipe_put_tile(struct pipe_context *pipe, struct pipe_surface *ps, ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); if (src_stride == 0) { src_stride = w * cpp; @@ -654,7 +654,7 @@ softpipe_put_tile(struct pipe_context *pipe, struct pipe_surface *ps, CLIP_TILE; pSrc = (const ubyte *) p; - pDest = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; + pDest = ps->map + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w * cpp); @@ -817,12 +817,12 @@ sp_surface_data(struct pipe_context *pipe, const void *src, unsigned src_pitch, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - copy_rect(pipe->region_map(pipe, dst->region) + dst->offset, + copy_rect(pipe_surface_map(dst), dst->cpp, dst->pitch, dstx, dsty, width, height, src, src_pitch, srcx, srcy); - pipe->region_unmap(pipe, dst->region); + pipe_surface_unmap(dst); } /* Assumes all values are within bounds -- no checking at this level - @@ -835,29 +835,26 @@ sp_surface_copy(struct pipe_context *pipe, struct pipe_surface *src, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - ubyte *src_map, *dst_map; assert( dst->cpp == src->cpp ); - dst_map = pipe->region_map(pipe, dst->region); - src_map = pipe->region_map(pipe, src->region); - copy_rect(dst_map + dst->offset, + copy_rect(pipe_surface_map(dst), dst->cpp, dst->pitch, dstx, dsty, width, height, - src_map + src->offset, + pipe_surface_map(src), src->pitch, srcx, srcy); - pipe->region_unmap(pipe, src->region); - pipe->region_unmap(pipe, dst->region); + pipe_surface_unmap(src); + pipe_surface_unmap(dst); } static ubyte * get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) { - return dst->region->map + (y * dst->pitch + x) * dst->cpp; + return dst->map + (y * dst->pitch + x) * dst->cpp; } @@ -879,7 +876,7 @@ sp_surface_fill(struct pipe_context *pipe, assert(dst->pitch > 0); assert(width <= dst->pitch); - (void)pipe->region_map(pipe, dst->region); + (void)pipe_surface_map(dst); switch (dst->cpp) { case 1: @@ -935,7 +932,7 @@ sp_surface_fill(struct pipe_context *pipe, break; } - pipe->region_unmap( pipe, dst->region ); + pipe_surface_unmap( dst ); } diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c index 2f9a1e9837..53486f9bba 100644 --- a/src/mesa/pipe/softpipe/sp_texture.c +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -32,6 +32,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_winsys.h" @@ -380,13 +381,18 @@ softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) sizeof(struct softpipe_texture) - sizeof(struct pipe_texture)); if (softpipe_mipmap_tree_layout(pipe, spt)) { - spt->region = pipe->winsys->region_alloc(pipe->winsys, - spt->pitch * (*pt)->cpp * - spt->total_height, - PIPE_SURFACE_FLAG_TEXTURE); + spt->buffer = pipe->winsys->buffer_create(pipe->winsys, + PIPE_SURFACE_FLAG_TEXTURE); + + if (spt->buffer) { + pipe->winsys->buffer_data(pipe->winsys, spt->buffer, + spt->pitch * (*pt)->cpp * + spt->total_height, NULL, + PIPE_BUFFER_USAGE_PIXEL); + } } - if (!spt->region) { + if (!spt->buffer) { FREE(spt); spt = NULL; } @@ -413,7 +419,7 @@ softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); */ - pipe->winsys->region_release(pipe->winsys, &spt->region); + pipe->winsys->buffer_reference(pipe->winsys, &spt->buffer, NULL); for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) if (spt->image_offset[i]) diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index 62ee6a27c9..08cd39cc55 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -123,16 +123,24 @@ sp_destroy_tile_cache(struct softpipe_tile_cache *tc) void -sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, +sp_tile_cache_set_surface(struct softpipe_context *sp, + struct softpipe_tile_cache *tc, struct pipe_surface *ps) { + if (tc->surface && tc->surface->map) + pipe_surface_unmap(tc->surface); + pipe_surface_reference(&tc->surface, ps); } struct pipe_surface * -sp_tile_cache_get_surface(struct softpipe_tile_cache *tc) +sp_tile_cache_get_surface(struct softpipe_context *sp, + struct softpipe_tile_cache *tc) { + if (tc->surface && !tc->surface->map) + pipe_surface_map(tc->surface); + return tc->surface; } @@ -162,7 +170,7 @@ sp_flush_tile_cache(struct softpipe_context *softpipe, boolean is_depth_stencil; int inuse = 0, pos; - if (!ps || !ps->region || !ps->region->map) + if (!ps || !ps->buffer) return; is_depth_stencil = (ps->format == PIPE_FORMAT_S8_Z24 || @@ -367,6 +375,16 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, struct pipe_surface *ps = pipe->get_tex_surface(pipe, tc->texture, face, level, z); + if (ps != tc->surface) { + if (tc->surface && tc->surface->map) + pipe_surface_unmap(tc->surface); + + pipe_surface_reference(&tc->surface, ps); + + if (!tc->surface->map) + pipe_surface_map(tc->surface); + } + pipe->get_tile_rgba(pipe, ps, tile_x, tile_y, TILE_SIZE, TILE_SIZE, (float *) tile->data.color); diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.h b/src/mesa/pipe/softpipe/sp_tile_cache.h index 9967aa5044..de5ff2c498 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.h +++ b/src/mesa/pipe/softpipe/sp_tile_cache.h @@ -63,11 +63,13 @@ extern void sp_destroy_tile_cache(struct softpipe_tile_cache *tc); extern void -sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, +sp_tile_cache_set_surface(struct softpipe_context *sp, + struct softpipe_tile_cache *tc, struct pipe_surface *sps); extern struct pipe_surface * -sp_tile_cache_get_surface(struct softpipe_tile_cache *tc); +sp_tile_cache_get_surface(struct softpipe_context *sp, + struct softpipe_tile_cache *tc); extern void sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c index f87d72d0c8..542b4aca49 100644 --- a/src/mesa/pipe/xlib/xm_api.c +++ b/src/mesa/pipe/xlib/xm_api.c @@ -1512,7 +1512,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) pipe->get_tile_rgba = xmesa_get_tile_rgba; pipe->put_tile_rgba = xmesa_put_tile_rgba; - c->st->haveFramebufferRegions = GL_FALSE; + c->st->haveFramebufferSurfaces = GL_FALSE; /* special pipe->clear function */ pipe->clear = xmesa_clear; diff --git a/src/mesa/pipe/xlib/xm_buffer.c b/src/mesa/pipe/xlib/xm_buffer.c index 449e90184b..6fc2f4ba63 100644 --- a/src/mesa/pipe/xlib/xm_buffer.c +++ b/src/mesa/pipe/xlib/xm_buffer.c @@ -269,9 +269,8 @@ static void finish_surface_init(GLcontext *ctx, struct xmesa_renderbuffer *xrb) { struct pipe_context *pipe = ctx->st->pipe; - if (!xrb->St.surface->region) { - xrb->St.surface->region = pipe->winsys->region_alloc(pipe->winsys, 1, - 0x0); + if (!xrb->St.surface->buffer) { + xrb->St.surface->buffer = pipe->winsys->buffer_create(pipe->winsys, 0x0); } } @@ -301,7 +300,7 @@ xmesa_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->Height = height; rb->InternalFormat = internalFormat; - if (!xrb->St.surface || !xrb->St.surface->region) + if (!xrb->St.surface || !xrb->St.surface->buffer) finish_surface_init(ctx, xrb); /* surface info */ @@ -363,7 +362,7 @@ xmesa_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb, xrb->origin4 = NULL; } - if (!xrb->St.surface || !xrb->St.surface->region) + if (!xrb->St.surface || !xrb->St.surface->buffer) finish_surface_init(ctx, xrb); xrb->St.surface->width = width; diff --git a/src/mesa/pipe/xlib/xm_surface.c b/src/mesa/pipe/xlib/xm_surface.c index 58ca2e7fb3..4a54b5c7e1 100644 --- a/src/mesa/pipe/xlib/xm_surface.c +++ b/src/mesa/pipe/xlib/xm_surface.c @@ -665,12 +665,12 @@ xmesa_new_color_surface(struct pipe_winsys *winsys, GLuint pipeFormat) xms->surface.refcount = 1; xms->surface.winsys = winsys; - /* Note, the region we allocate doesn't actually have any storage + /* Note, the buffer we allocate doesn't actually have any storage * since we're drawing into an XImage or Pixmap. - * The region's size will get set in the xmesa_alloc_front/back_storage() + * The surface's size will get set in the xmesa_alloc_front/back_storage() * functions. */ - xms->surface.region = winsys->region_alloc(winsys, 1, 0x0); + xms->surface.buffer = winsys->buffer_create(winsys, 0x0); return &xms->surface; } @@ -713,7 +713,7 @@ xmesa_clear(struct pipe_context *pipe, struct pipe_surface *ps, uint value) { struct softpipe_context *sp = softpipe_context(pipe); - if (ps == sp_tile_cache_get_surface(sp->cbuf_cache[0])) { + if (ps == sp_tile_cache_get_surface(sp, sp->cbuf_cache[0])) { float clear[4]; clear[0] = 0.2; /* XXX hack */ clear[1] = 0.2; diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index 99816a811d..295174d4bb 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -186,7 +186,7 @@ xm_get_name(struct pipe_winsys *pws) static struct pipe_buffer_handle * -xm_buffer_create(struct pipe_winsys *pws, unsigned alignment) +xm_buffer_create(struct pipe_winsys *pws, unsigned flags) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); buffer->refcount = 1; @@ -228,47 +228,6 @@ xm_surface_pitch(struct pipe_winsys *winsys, unsigned cpp, unsigned width, } -static struct pipe_region * -xm_region_alloc(struct pipe_winsys *winsys, unsigned size, unsigned flags) -{ - struct pipe_region *region = CALLOC_STRUCT(pipe_region); - const unsigned alignment = 64; - - region->refcount = 1; - - assert(size > 0); - - region->buffer = winsys->buffer_create( winsys, alignment ); - - /* NULL data --> just allocate the space */ - winsys->buffer_data( winsys, - region->buffer, - size, - NULL, - PIPE_BUFFER_USAGE_PIXEL ); - return region; -} - - -static void -xm_region_release(struct pipe_winsys *winsys, struct pipe_region **region) -{ - if (!*region) - return; - - assert((*region)->refcount > 0); - (*region)->refcount--; - - if ((*region)->refcount == 0) { - assert((*region)->map_refcount == 0); - - winsys->buffer_reference( winsys, &((*region)->buffer), NULL ); - free(*region); - } - *region = NULL; -} - - /** * Called via pipe->surface_alloc() to create new surfaces (textures, * renderbuffers, etc. @@ -301,8 +260,8 @@ xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) struct pipe_surface *surf = *s; surf->refcount--; if (surf->refcount == 0) { - if (surf->region) - winsys->region_release(winsys, &surf->region); + if (surf->buffer) + winsys->buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; @@ -335,9 +294,6 @@ xmesa_get_pipe_winsys(void) ws->buffer_subdata = xm_buffer_subdata; ws->buffer_get_subdata = xm_buffer_get_subdata; - ws->region_alloc = xm_region_alloc; - ws->region_release = xm_region_release; - ws->surface_pitch = xm_surface_pitch; ws->surface_alloc = xm_surface_alloc; ws->surface_release = xm_surface_release; diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 7a245b0ed6..c8d9cba12f 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -42,6 +42,7 @@ #include "st_format.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" /** @@ -68,7 +69,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) GLfloat *accBuf; GLint i; - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(acc_ps); accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); @@ -83,7 +84,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) free(accBuf); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(acc_ps); } @@ -99,7 +100,7 @@ accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias, accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); @@ -111,7 +112,7 @@ accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias, free(accBuf); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(acc_ps); } @@ -128,8 +129,8 @@ accum_accum(struct pipe_context *pipe, GLfloat value, colorBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - colorMap = pipe->region_map(pipe, color_ps->region); - accMap = pipe->region_map(pipe, acc_ps->region); + colorMap = pipe_surface_map(color_ps); + accMap = pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf); pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); @@ -143,8 +144,8 @@ accum_accum(struct pipe_context *pipe, GLfloat value, free(colorBuf); free(accBuf); - pipe->region_unmap(pipe, color_ps->region); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(color_ps); + pipe_surface_unmap(acc_ps); } @@ -159,8 +160,8 @@ accum_load(struct pipe_context *pipe, GLfloat value, buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, color_ps->region); - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(color_ps); + (void) pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, buf); @@ -172,8 +173,8 @@ accum_load(struct pipe_context *pipe, GLfloat value, free(buf); - pipe->region_unmap(pipe, color_ps->region); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(color_ps); + pipe_surface_unmap(acc_ps); } @@ -190,8 +191,8 @@ accum_return(GLcontext *ctx, GLfloat value, abuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, color_ps->region); - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(color_ps); + (void) pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, abuf); @@ -218,8 +219,8 @@ accum_return(GLcontext *ctx, GLfloat value, if (cbuf) free(cbuf); - pipe->region_unmap(pipe, color_ps->region); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(color_ps); + pipe_surface_unmap(acc_ps); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index c28ad15b29..a61daffb20 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -492,11 +492,10 @@ make_texture(struct st_context *st, surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); - /* map texture region */ - (void) pipe->region_map(pipe, surface->region); - dest = surface->region->map + surface->offset; + /* map texture surface */ + dest = pipe_surface_map(surface); - /* Put image into texture region. + /* Put image into texture surface. * Note that the image is actually going to be upside down in * the texture. We deal with that with texcoords. */ @@ -513,7 +512,7 @@ make_texture(struct st_context *st, unpack); /* unmap */ - pipe->region_unmap(pipe, surface->region); + pipe_surface_unmap(surface); pipe_surface_reference(&surface, NULL); assert(success); @@ -852,7 +851,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, pipe->flush(pipe, 0); /* map the stencil buffer */ - stmap = pipe->region_map(pipe, ps->region); + stmap = pipe_surface_map(ps); /* if width > MAX_WIDTH, have to process image in chunks */ skipPixels = 0; @@ -909,7 +908,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } /* unmap the stencil buffer */ - pipe->region_unmap(pipe, ps->region); + pipe_surface_unmap(ps); } @@ -1027,11 +1026,10 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); - /* map texture region */ - (void) pipe->region_map(pipe, surface->region); - dest = surface->region->map + surface->offset; + /* map texture surface */ + dest = pipe_surface_map(surface); - /* Put image into texture region. + /* Put image into texture surface. * Note that the image is actually going to be upside down in * the texture. We deal with that with texcoords. */ @@ -1089,7 +1087,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, } /* row */ /* Release surface */ - pipe->region_unmap(pipe, surface->region); + pipe_surface_unmap(surface); pipe_surface_reference(&surface, NULL); pt->format = format; @@ -1130,8 +1128,6 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty) { - struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; struct st_renderbuffer *rbRead = st_renderbuffer(ctx->ReadBuffer->_StencilBuffer); struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer); struct pipe_surface *psRead = rbRead->surface; @@ -1147,8 +1143,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, } /* map the stencil buffers */ - readMap = pipe->region_map(pipe, psRead->region); - drawMap = pipe->region_map(pipe, psDraw->region); + readMap = pipe_surface_map(psRead); + drawMap = pipe_surface_map(psDraw); /* this will do stencil pixel transfer ops */ st_read_stencil_pixels(ctx, srcx, srcy, width, height, GL_UNSIGNED_BYTE, @@ -1192,8 +1188,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, free(buffer); /* unmap the stencil buffers */ - pipe->region_unmap(pipe, psRead->region); - pipe->region_unmap(pipe, psDraw->region); + pipe_surface_unmap(psRead); + pipe_surface_unmap(psDraw); } @@ -1252,11 +1248,11 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, } /* For some drivers (like Xlib) it's not possible to treat the - * front/back color buffers as regions (they're XImages and Pixmaps). - * So, this var tells us if we can use region_copy here... + * front/back color buffers as surfaces (they're XImages and Pixmaps). + * So, this var tells us if we can use surface_copy here... */ - if (st->haveFramebufferRegions) { - /* copy source framebuffer region into mipmap/texture */ + if (st->haveFramebufferSurfaces) { + /* copy source framebuffer surface into mipmap/texture */ pipe->surface_copy(pipe, psTex, /* dest */ 0, 0, /* destx/y */ @@ -1267,14 +1263,14 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, /* alternate path using get/put_tile() */ GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, psRead->region); - (void) pipe->region_map(pipe, psTex->region); + (void) pipe_surface_map(psRead); + (void) pipe_surface_map(psTex); pipe->get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf); pipe->put_tile_rgba(pipe, psTex, 0, 0, width, height, buf); - pipe->region_unmap(pipe, psRead->region); - pipe->region_unmap(pipe, psTex->region); + pipe_surface_unmap(psRead); + pipe_surface_unmap(psTex); free(buf); } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 43681b7f8a..6b9023c410 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -109,22 +109,22 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, width, flags); } - /* free old region */ - if (strb->surface->region) { - /* loop here since mapping is refcounted */ - struct pipe_region *r = strb->surface->region; - while (r->map) - pipe->region_unmap(pipe, r); - pipe->winsys->region_release(pipe->winsys, &strb->surface->region); - } - - strb->surface->region = pipe->winsys->region_alloc(pipe->winsys, - strb->surface->pitch * - cpp * height, flags); - if (!strb->surface->region) + /* loop here since mapping is refcounted */ + while (strb->surface->map) + pipe_surface_unmap(strb->surface); + if (strb->surface->buffer) + pipe->winsys->buffer_reference(pipe->winsys, &strb->surface->buffer, + NULL); + + strb->surface->buffer = pipe->winsys->buffer_create(pipe->winsys, flags); + if (!strb->surface->buffer) return GL_FALSE; /* out of memory, try s/w buffer? */ - ASSERT(strb->surface->region->buffer); + pipe->winsys->buffer_data(pipe->winsys, strb->surface->buffer, + strb->surface->pitch * cpp * height, NULL, + PIPE_BUFFER_USAGE_PIXEL); + + ASSERT(strb->surface->buffer); ASSERT(strb->surface->format); strb->Base.Width = strb->surface->width = width; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 83fe480af8..e2243e7de4 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -39,6 +39,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "st_context.h" #include "st_cb_readpixels.h" #include "st_cb_fbo.h" @@ -56,8 +57,6 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, const struct gl_pixelstore_attrib *packing, GLvoid *pixels) { - struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer); struct pipe_surface *ps = strb->surface; @@ -65,7 +64,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, GLint j; /* map the stencil buffer */ - stmap = pipe->region_map(pipe, ps->region); + stmap = pipe_surface_map(ps); /* width should never be > MAX_WIDTH since we did clipping earlier */ ASSERT(width <= MAX_WIDTH); @@ -122,7 +121,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ - pipe->region_unmap(pipe, ps->region); + pipe_surface_unmap(ps); } @@ -151,7 +150,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /* Do all needed clipping here, so that we can forget about it later */ if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) { - /* The ReadPixels region is totally outside the window bounds */ + /* The ReadPixels surface is totally outside the window bounds */ return; } @@ -180,7 +179,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (!strb) return; - pipe->region_map(pipe, strb->surface->region); + pipe_surface_map(strb->surface); if (format == GL_RGBA && type == GL_FLOAT) { /* write tile(row) directly into user's buffer */ @@ -231,7 +230,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } - pipe->region_unmap(pipe, strb->surface->region); + pipe_surface_unmap(strb->surface); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index acc97df2e7..1fcef746c1 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -64,7 +64,7 @@ struct st_texture_object GLuint textureOffset; /* On validation any active images held in main memory or in other - * regions will be copied to this region and the old storage freed. + * textures will be copied to this texture and the old storage freed. */ struct pipe_texture *pt; @@ -721,7 +721,7 @@ st_TexImage(GLcontext * ctx, } if (stImage->pt && i < depth) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = st_texture_image_map(ctx->st, stImage, i); pixels += srcImageStride; } @@ -731,7 +731,7 @@ st_TexImage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, unpack); if (stImage->pt) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = NULL; } @@ -860,7 +860,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, } if (stImage->pt && i < depth) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = st_texture_image_map(ctx->st, stImage, i); pixels += dstImageStride; } @@ -870,7 +870,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, /* Unmap */ if (stImage->pt) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = NULL; } } @@ -948,7 +948,7 @@ st_TexSubimage(GLcontext * ctx, } if (stImage->pt && i < depth) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i); pixels += srcImageStride; } @@ -966,7 +966,7 @@ st_TexSubimage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, packing); if (stImage->pt) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = NULL; } } @@ -1051,8 +1051,8 @@ texture_face(GLenum target) /** - * Do a CopyTexSubImage operation by mapping the source region and - * dest region and using get_tile()/put_tile() to access the pixels/texels. + * Do a CopyTexSubImage operation by mapping the source surface and + * dest surface and using get_tile()/put_tile() to access the pixels/texels. * * Note: srcY=0=TOP of renderbuffer */ @@ -1088,8 +1088,8 @@ fallback_copy_texsubimage(GLcontext *ctx, dest_surf = pipe->get_tex_surface(pipe, pt, face, level, destZ); - (void) pipe->region_map(pipe, dest_surf->region); - (void) pipe->region_map(pipe, src_surf->region); + (void) pipe_surface_map(dest_surf); + (void) pipe_surface_map(src_surf); /* buffer for one row */ data = (GLfloat *) malloc(width * 4 * sizeof(GLfloat)); @@ -1110,8 +1110,8 @@ fallback_copy_texsubimage(GLcontext *ctx, } - (void) pipe->region_unmap(pipe, dest_surf->region); - (void) pipe->region_unmap(pipe, src_surf->region); + (void) pipe_surface_unmap(dest_surf); + (void) pipe_surface_unmap(src_surf); free(data); } @@ -1178,8 +1178,8 @@ do_copy_texsubimage(GLcontext *ctx, if (src_format == dest_format && ctx->_ImageTransferState == 0x0 && - strb->surface->region && - dest_surface->region && + strb->surface->buffer && + dest_surface->buffer && strb->surface->cpp == stImage->pt->cpp) { /* do blit-style copy */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index a4ec3721be..abde6d64b0 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -103,7 +103,7 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; - st->haveFramebufferRegions = GL_TRUE; + st->haveFramebufferSurfaces = GL_TRUE; st->pixel_xfer.cache = _mesa_new_program_cache(); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index db97014c5a..c31b76c63f 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -34,7 +34,6 @@ struct st_context; -struct st_region; struct st_texture_object; struct st_fragment_program; struct draw_context; @@ -131,11 +130,11 @@ struct st_context char vendor[100]; char renderer[100]; - /** Can we access the front/back color buffers as pipe_regions? + /** Can we access the front/back color buffers as pipe_surfaces? * We can't with the Xlib driver... * This is a hack that should be fixed someday. */ - GLboolean haveFramebufferRegions; + GLboolean haveFramebufferSurfaces; /* State to be validated: */ diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index a5582c31c0..1ec4514873 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -33,6 +33,7 @@ #include "pipe/p_state.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_inlines.h" #include "pipe/p_winsys.h" @@ -187,17 +188,15 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, stImage->surface = st->pipe->get_tex_surface(st->pipe, pt, stImage->face, stImage->level, zoffset); - (void) st->pipe->region_map(st->pipe, stImage->surface->region); - - return stImage->surface->region->map + stImage->surface->offset; + return pipe_surface_map(stImage->surface); } void -st_texture_image_unmap(struct st_context *st, struct st_texture_image *stImage) +st_texture_image_unmap(struct st_texture_image *stImage) { DBG("%s\n", __FUNCTION__); - st->pipe->region_unmap(st->pipe, stImage->surface->region); + pipe_surface_unmap(stImage->surface); pipe_surface_reference(&stImage->surface, NULL); } diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index b25e3f3f3b..f49d91a069 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -65,8 +65,7 @@ st_texture_image_map(struct st_context *st, GLuint zoffset); extern void -st_texture_image_unmap(struct st_context *st, - struct st_texture_image *stImage); +st_texture_image_unmap(struct st_texture_image *stImage); /* Return pointers to each 2d slice within an image. Indexed by depth -- cgit v1.2.3 From 48731280d08bef51c406703e82986643e17b4757 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 11 Dec 2007 13:00:12 +0000 Subject: gallium: Remove feedback interfaces from pipe driver. Something similar will return when geometry shaders are added, but for now this interface is not required. --- src/mesa/pipe/draw/draw_context.c | 21 --- src/mesa/pipe/draw/draw_context.h | 6 - src/mesa/pipe/draw/draw_feedback.c | 253 ----------------------------- src/mesa/pipe/draw/draw_private.h | 9 - src/mesa/pipe/draw/draw_validate.c | 5 - src/mesa/pipe/i915simple/i915_context.c | 22 --- src/mesa/pipe/i915simple/i915_context.h | 4 - src/mesa/pipe/i915simple/i915_state.c | 30 ---- src/mesa/pipe/p_context.h | 9 - src/mesa/pipe/p_state.h | 22 --- src/mesa/pipe/softpipe/Makefile | 1 - src/mesa/pipe/softpipe/sp_context.c | 2 - src/mesa/pipe/softpipe/sp_context.h | 4 - src/mesa/pipe/softpipe/sp_draw_arrays.c | 22 --- src/mesa/pipe/softpipe/sp_state.h | 8 - src/mesa/pipe/softpipe/sp_state_feedback.c | 72 -------- src/mesa/sources | 1 - src/mesa/state_tracker/st_cb_rasterpos.c | 44 +++-- src/mesa/state_tracker/st_context.h | 1 - 19 files changed, 21 insertions(+), 515 deletions(-) delete mode 100644 src/mesa/pipe/draw/draw_feedback.c delete mode 100644 src/mesa/pipe/softpipe/sp_state_feedback.c (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/draw/draw_context.c b/src/mesa/pipe/draw/draw_context.c index 33727e6547..179f7ed0d6 100644 --- a/src/mesa/pipe/draw/draw_context.c +++ b/src/mesa/pipe/draw/draw_context.c @@ -55,7 +55,6 @@ struct draw_context *draw_create( void ) draw->pipeline.clip = draw_clip_stage( draw ); draw->pipeline.flatshade = draw_flatshade_stage( draw ); draw->pipeline.cull = draw_cull_stage( draw ); - draw->pipeline.feedback = draw_feedback_stage( draw ); draw->pipeline.validate = draw_validate_stage( draw ); draw->pipeline.first = draw->pipeline.validate; @@ -100,7 +99,6 @@ void draw_destroy( struct draw_context *draw ) draw->pipeline.clip->destroy( draw->pipeline.clip ); draw->pipeline.flatshade->destroy( draw->pipeline.flatshade ); draw->pipeline.cull->destroy( draw->pipeline.cull ); - draw->pipeline.feedback->destroy( draw->pipeline.feedback ); draw->pipeline.validate->destroy( draw->pipeline.validate ); if (draw->pipeline.rasterize) draw->pipeline.rasterize->destroy( draw->pipeline.rasterize ); @@ -117,13 +115,6 @@ void draw_flush( struct draw_context *draw ) } -void draw_set_feedback_state( struct draw_context *draw, - const struct pipe_feedback_state *feedback ) -{ - draw_flush( draw ); - draw->feedback = *feedback; -} - /** * Register new primitive rasterization/rendering state. @@ -223,18 +214,6 @@ draw_set_mapped_constant_buffer(struct draw_context *draw, } -void -draw_set_mapped_feedback_buffer(struct draw_context *draw, uint index, - void *buffer, uint size) -{ - draw_flush( draw ); - - assert(index < PIPE_MAX_FEEDBACK_ATTRIBS); - draw->user.feedback_buffer[index] = buffer; - draw->user.feedback_buffer_size[index] = size; /* in bytes */ -} - - diff --git a/src/mesa/pipe/draw/draw_context.h b/src/mesa/pipe/draw/draw_context.h index 8e2232244c..6dc6e4ce82 100644 --- a/src/mesa/pipe/draw/draw_context.h +++ b/src/mesa/pipe/draw/draw_context.h @@ -82,9 +82,6 @@ void draw_set_viewport_state( struct draw_context *draw, void draw_set_clip_state( struct draw_context *pipe, const struct pipe_clip_state *clip ); -void draw_set_feedback_state( struct draw_context *draw, - const struct pipe_feedback_state * ); - void draw_set_rasterizer_state( struct draw_context *draw, const struct pipe_rasterizer_state *raster ); @@ -120,9 +117,6 @@ void draw_set_mapped_vertex_buffer(struct draw_context *draw, void draw_set_mapped_constant_buffer(struct draw_context *draw, const void *buffer); -void -draw_set_mapped_feedback_buffer(struct draw_context *draw, uint index, - void *buffer, uint size); /*********************************************************************** diff --git a/src/mesa/pipe/draw/draw_feedback.c b/src/mesa/pipe/draw/draw_feedback.c deleted file mode 100644 index aea6a8184c..0000000000 --- a/src/mesa/pipe/draw/draw_feedback.c +++ /dev/null @@ -1,253 +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. - * - **************************************************************************/ - -/** - * Primitive/vertex feedback (and/or discard) stage. - * Used to implement transformation feedback/streaming and other things - * which require a post-transformed vertex position (such as rasterpos, - * selection and feedback modes). - * - * Authors: - * Brian Paul - */ - - -#include "pipe/p_util.h" -#include "draw_private.h" - - -struct feedback_stage { - struct draw_stage stage; /**< base class */ - uint num_prim_generated; /**< number of primitives received */ - uint num_prim_emitted; /**< number of primitives fed back */ - uint num_vert_emitted; /**< number of vertices fed back */ - uint max_vert_emit; /**< max number of verts we can emit */ - float *dest[PIPE_MAX_FEEDBACK_ATTRIBS]; /**< dests for vertex attribs */ -}; - - - -/** - * Check if there's space to store 'numVerts' in the feedback buffer(s). - */ -static boolean -check_space(const struct draw_stage *stage, uint numVerts) -{ - const struct feedback_stage *fs = (struct feedback_stage *) stage; - return fs->num_vert_emitted + numVerts <= fs->max_vert_emit; -} - - -/** - * Record the given vertex's attributes into the feedback buffer(s). - */ -static void -feedback_vertex(struct draw_stage *stage, const struct vertex_header *vertex) -{ - struct feedback_stage *fs = (struct feedback_stage *) stage; - const struct pipe_feedback_state *feedback = &stage->draw->feedback; - const uint select = feedback->interleaved ? 0 : 1; - uint i; - - /* - * Note: 'select' is either 0 or 1. By multiplying 'i' by 'select' - * we can either address output buffer 0 (for interleaving) or - * output buffer i (for non-interleaved). - */ - for (i = 0; i < feedback->num_attribs; i++) { - 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]; - - switch (size) { - case 4: - dest[3] = src[3]; - /* fall-through */ - case 3: - dest[2] = src[2]; - /* fall-through */ - case 2: - dest[1] = src[1]; - /* fall-through */ - case 1: - dest[0] = src[0]; - /* fall-through */ - default: - ; - } - fs->dest[i * select] += size; - } - - fs->num_vert_emitted++; -} - - -static void feedback_begin( struct draw_stage *stage ) -{ - struct feedback_stage *fs = (struct feedback_stage *) stage; - const struct pipe_feedback_state *feedback = &stage->draw->feedback; - - fs->num_prim_generated = 0; - fs->num_prim_emitted = 0; - fs->num_vert_emitted = 0; - - assert(feedback->enabled); - - /* Compute max_vert_emit, the max number of vertices we can emit. - * And, setup dest[] pointers. - */ - if (stage->draw->feedback.interleaved) { - uint i, vertex_size = 0; - /* compute size of each interleaved vertex, in floats */ - for (i = 0; i < feedback->num_attribs; i++) { - vertex_size += feedback->size[i]; - } - /* compute max number of vertices we can feedback */ - fs->max_vert_emit = stage->draw->user.feedback_buffer_size[0] - / sizeof(float) / vertex_size; - - fs->dest[0] = (float *) stage->draw->user.feedback_buffer[0]; - } - else { - uint i; - uint max = ~0; - for (i = 0; i < feedback->num_attribs; i++) { - uint n = stage->draw->user.feedback_buffer_size[i] - / sizeof(float) / feedback->size[i]; - if (n < max) - max = n; - fs->dest[i] = (float *) stage->draw->user.feedback_buffer[i]; - } - fs->max_vert_emit = max; - } - - if (!feedback->discard) - stage->next->begin( stage->next ); -} - - -static void feedback_tri( struct draw_stage *stage, - struct prim_header *header ) -{ - struct feedback_stage *fs = (struct feedback_stage *) stage; - - fs->num_prim_generated++; - - if (stage->draw->feedback.enabled && check_space(stage, 3)) { - feedback_vertex(stage, header->v[0]); - feedback_vertex(stage, header->v[1]); - feedback_vertex(stage, header->v[2]); - fs->num_prim_emitted++; - } - - if (!stage->draw->feedback.discard) - stage->next->tri( stage->next, header ); -} - - -static void feedback_line( struct draw_stage *stage, - struct prim_header *header ) -{ - struct feedback_stage *fs = (struct feedback_stage *) stage; - - fs->num_prim_generated++; - - if (stage->draw->feedback.enabled && check_space(stage, 2)) { - feedback_vertex(stage, header->v[0]); - feedback_vertex(stage, header->v[1]); - fs->num_prim_emitted++; - } - - if (!stage->draw->feedback.discard) - stage->next->line( stage->next, header ); -} - - -static void feedback_point( struct draw_stage *stage, - struct prim_header *header ) -{ - struct feedback_stage *fs = (struct feedback_stage *) stage; - - fs->num_prim_generated++; - - if (stage->draw->feedback.enabled && check_space(stage, 1)) { - feedback_vertex(stage, header->v[0]); - fs->num_prim_emitted++; - } - - if (!stage->draw->feedback.discard) - stage->next->point( stage->next, header ); -} - - -static void feedback_end( struct draw_stage *stage ) -{ - - /* XXX Unmap the vertex feedback buffers so we can write to them */ - - - if (!stage->draw->feedback.discard) - stage->next->end( stage->next ); -} - - - -static void feedback_reset_stipple_counter( struct draw_stage *stage ) -{ - if (!stage->draw->feedback.discard) - stage->next->reset_stipple_counter( stage->next ); -} - - -static void feedback_destroy( struct draw_stage *stage ) -{ - FREE( stage ); -} - - -/** - * Create feedback drawing stage. - */ -struct draw_stage *draw_feedback_stage( struct draw_context *draw ) -{ - struct feedback_stage *feedback = CALLOC_STRUCT(feedback_stage); - - feedback->stage.draw = draw; - feedback->stage.next = NULL; - feedback->stage.begin = feedback_begin; - feedback->stage.point = feedback_point; - feedback->stage.line = feedback_line; - feedback->stage.tri = feedback_tri; - feedback->stage.end = feedback_end; - feedback->stage.reset_stipple_counter = feedback_reset_stipple_counter; - feedback->stage.destroy = feedback_destroy; - - return &feedback->stage; -} - - diff --git a/src/mesa/pipe/draw/draw_private.h b/src/mesa/pipe/draw/draw_private.h index ca5ca7b3c9..5f89ac121e 100644 --- a/src/mesa/pipe/draw/draw_private.h +++ b/src/mesa/pipe/draw/draw_private.h @@ -159,7 +159,6 @@ struct draw_context struct draw_stage *validate; /* stages (in logical order) */ - struct draw_stage *feedback; struct draw_stage *flatshade; struct draw_stage *clip; struct draw_stage *cull; @@ -172,13 +171,10 @@ struct draw_context /* pipe state that we need: */ 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]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; const struct draw_vertex_shader *vertex_shader; - struct pipe_vertex_buffer feedback_buffer[PIPE_ATTRIB_MAX]; - struct pipe_vertex_element feedback_element[PIPE_ATTRIB_MAX]; /* user-space vertex data, buffers */ struct { @@ -192,10 +188,6 @@ struct draw_context /** constant buffer (for vertex shader) */ const void *constants; - - /** The vertex feedback buffer */ - void *feedback_buffer[PIPE_MAX_FEEDBACK_ATTRIBS]; - uint feedback_buffer_size[PIPE_MAX_FEEDBACK_ATTRIBS]; /* in bytes */ } user; /* Clip derived state: @@ -257,7 +249,6 @@ struct draw_context -extern struct draw_stage *draw_feedback_stage( struct draw_context *context ); extern struct draw_stage *draw_unfilled_stage( struct draw_context *context ); extern struct draw_stage *draw_twoside_stage( struct draw_context *context ); extern struct draw_stage *draw_offset_stage( struct draw_context *context ); diff --git a/src/mesa/pipe/draw/draw_validate.c b/src/mesa/pipe/draw/draw_validate.c index 8ce4a926e2..58cf340281 100644 --- a/src/mesa/pipe/draw/draw_validate.c +++ b/src/mesa/pipe/draw/draw_validate.c @@ -100,11 +100,6 @@ static void validate_begin( struct draw_stage *stage ) next = draw->pipeline.flatshade; } - if (draw->feedback.enabled || draw->feedback.discard) { - draw->pipeline.feedback->next = next; - next = draw->pipeline.feedback; - } - draw->pipeline.first = next; draw->pipeline.first->begin( draw->pipeline.first ); } diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index f505ff6ae6..d2bbeea16a 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -223,18 +223,6 @@ i915_draw_elements( struct pipe_context *pipe, draw_set_mapped_element_buffer(draw, 0, NULL); } - /* Map feedback buffers if enabled */ - if (i915->feedback.enabled) { - const uint n = i915->feedback.interleaved ? 1 : i915->feedback.num_attribs; - for (i = 0; i < n; i++) { - void *ptr = pipe->winsys->buffer_map(pipe->winsys, - i915->feedback_buffer[i].buffer, - PIPE_BUFFER_FLAG_WRITE); - draw_set_mapped_feedback_buffer(draw, i, ptr, - i915->feedback_buffer[i].size); - } - } - draw_set_mapped_constant_buffer(draw, i915->current.constants[PIPE_SHADER_VERTEX]); @@ -256,16 +244,6 @@ i915_draw_elements( struct pipe_context *pipe, draw_set_mapped_element_buffer(draw, 0, NULL); } - /* Unmap feedback buffers if enabled */ - if (i915->feedback.enabled) { - const uint n = i915->feedback.interleaved ? 1 : i915->feedback.num_attribs; - for (i = 0; i < n; i++) { - pipe->winsys->buffer_unmap(pipe->winsys, - i915->feedback_buffer[i].buffer); - draw_set_mapped_feedback_buffer(draw, i, NULL, 0); - } - } - return TRUE; } diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index dbf0c885cc..b9b67c4fcf 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -197,7 +197,6 @@ struct i915_context struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; struct pipe_constant_buffer constants[PIPE_SHADER_TYPES]; - struct pipe_feedback_state feedback; struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; @@ -206,9 +205,6 @@ struct i915_context struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; - /** Feedback buffers */ - struct pipe_feedback_buffer feedback_buffer[PIPE_MAX_FEEDBACK_ATTRIBS]; - unsigned dirty; unsigned *batch_start; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 038fd623ea..b9f257a007 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -547,34 +547,6 @@ static void i915_set_framebuffer_state(struct pipe_context *pipe, } -static void -i915_set_feedback_state(struct pipe_context *pipe, - const struct pipe_feedback_state *feedback) -{ - struct i915_context *i915 = i915_context(pipe); - i915->feedback = *feedback; - draw_set_feedback_state(i915->draw, feedback); -} - - -static void -i915_set_feedback_buffer(struct pipe_context *pipe, - unsigned index, - const struct pipe_feedback_buffer *feedback) -{ - struct i915_context *i915 = i915_context(pipe); - - assert(index < PIPE_MAX_FEEDBACK_ATTRIBS); - - /* Need to be careful with referencing */ - pipe->winsys->buffer_reference(pipe->winsys, - &i915->feedback_buffer[index].buffer, - feedback->buffer); - i915->feedback_buffer[index].size = feedback->size; - i915->feedback_buffer[index].start_offset = feedback->start_offset; -} - - static void i915_set_clear_color_state(struct pipe_context *pipe, const struct pipe_clear_color_state *clear) @@ -751,8 +723,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_feedback_state = i915_set_feedback_state; - i915->pipe.set_feedback_buffer = i915_set_feedback_buffer; i915->pipe.set_polygon_stipple = i915_set_polygon_stipple; i915->pipe.set_sampler_units = i915_set_sampler_units; diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 00379fbacf..7da4992841 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -139,9 +139,6 @@ struct pipe_context { uint shader, uint index, const struct pipe_constant_buffer *buf ); - void (*set_feedback_state)( struct pipe_context *, - const struct pipe_feedback_state *); - void (*set_framebuffer_state)( struct pipe_context *, const struct pipe_framebuffer_state * ); @@ -172,12 +169,6 @@ struct pipe_context { unsigned index, const struct pipe_vertex_element * ); - /* - * Vertex feedback - */ - void (*set_feedback_buffer)(struct pipe_context *, - unsigned index, - const struct pipe_feedback_buffer *); /** Get a surface which is a "view" into a texture */ struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe, diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 6db9bbc953..50344bea78 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -103,19 +103,6 @@ struct pipe_rasterizer_state }; -/** - * Post-transform vertex feeback - */ -struct pipe_feedback_state { - uint enabled:1; /**< enable feedback? */ - uint discard:1; /**< discard primitives? */ - uint interleaved:1; /**< interleaved output? */ - uint num_attribs; - uint attrib[PIPE_MAX_FEEDBACK_ATTRIBS]; - uint size[PIPE_MAX_FEEDBACK_ATTRIBS]; -}; - - struct pipe_poly_stipple { unsigned stipple[32]; }; @@ -336,15 +323,6 @@ struct pipe_vertex_element }; -/** - * Vertex feedback buffer - */ -struct pipe_feedback_buffer { - struct pipe_buffer_handle *buffer; - unsigned size; - unsigned start_offset; -}; - /** * Hardware queries (occlusion, transform feedback, timing, etc) diff --git a/src/mesa/pipe/softpipe/Makefile b/src/mesa/pipe/softpipe/Makefile index 647cc05373..5e6886a37e 100644 --- a/src/mesa/pipe/softpipe/Makefile +++ b/src/mesa/pipe/softpipe/Makefile @@ -27,7 +27,6 @@ DRIVER_SOURCES = \ sp_state_blend.c \ sp_state_clip.c \ sp_state_derived.c \ - sp_state_feedback.c \ sp_state_fs.c \ sp_state_sampler.c \ sp_state_rasterizer.c \ diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 8b8e04c2f9..2eab3aaabb 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -306,7 +306,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, 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_feedback_state = softpipe_set_feedback_state; softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; softpipe->pipe.set_sampler_units = softpipe_set_sampler_units; @@ -316,7 +315,6 @@ 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; - softpipe->pipe.set_feedback_buffer = softpipe_set_feedback_buffer; softpipe->pipe.draw_arrays = softpipe_draw_arrays; softpipe->pipe.draw_elements = softpipe_draw_elements; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index b97cdc52c6..1c391dcd4d 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -85,7 +85,6 @@ struct softpipe_context { struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; struct pipe_constant_buffer constants[2]; - struct pipe_feedback_state feedback; struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; @@ -117,9 +116,6 @@ struct softpipe_context { boolean need_w; /**< produce quad/fragment W values? */ int psize_slot; - /** Feedback buffers */ - struct pipe_feedback_buffer feedback_buffer[PIPE_MAX_FEEDBACK_ATTRIBS]; - #if 0 /* Stipple derived state: */ diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c index 93eb68405d..b7626f8a5f 100644 --- a/src/mesa/pipe/softpipe/sp_draw_arrays.c +++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c @@ -138,18 +138,6 @@ softpipe_draw_elements(struct pipe_context *pipe, draw_set_mapped_element_buffer(draw, 0, NULL); } - /* Map feedback buffers if enabled */ - if (sp->feedback.enabled) { - const uint n = sp->feedback.interleaved ? 1 : sp->feedback.num_attribs; - for (i = 0; i < n; i++) { - void *ptr = pipe->winsys->buffer_map(pipe->winsys, - sp->feedback_buffer[i].buffer, - PIPE_BUFFER_FLAG_WRITE); - draw_set_mapped_feedback_buffer(draw, i, ptr, - sp->feedback_buffer[i].size); - } - } - /* draw! */ draw_arrays(draw, mode, start, count); @@ -171,16 +159,6 @@ softpipe_draw_elements(struct pipe_context *pipe, draw_set_mapped_element_buffer(draw, 0, NULL); } - /* Unmap feedback buffers if enabled */ - if (sp->feedback.enabled) { - const uint n = sp->feedback.interleaved ? 1 : sp->feedback.num_attribs; - for (i = 0; i < n; i++) { - pipe->winsys->buffer_unmap(pipe->winsys, - sp->feedback_buffer[i].buffer); - draw_set_mapped_feedback_buffer(draw, i, NULL, 0); - } - } - /* Note: leave drawing surfaces mapped */ softpipe_unmap_constant_buffers(sp); diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index ea9d2e62be..f434567da5 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -102,9 +102,6 @@ void softpipe_set_constant_buffer(struct pipe_context *, uint shader, uint index, const struct pipe_constant_buffer *buf); -void softpipe_set_feedback_state( struct pipe_context *, - const struct pipe_feedback_state * ); - void *softpipe_create_fs_state(struct pipe_context *, const struct pipe_shader_state *); void softpipe_bind_fs_state(struct pipe_context *, void *); @@ -138,11 +135,6 @@ void softpipe_set_vertex_buffer(struct pipe_context *, unsigned index, const struct pipe_vertex_buffer *); -void softpipe_set_feedback_buffer(struct pipe_context *, - uint index, - const struct pipe_feedback_buffer *); - - void softpipe_update_derived( struct softpipe_context *softpipe ); diff --git a/src/mesa/pipe/softpipe/sp_state_feedback.c b/src/mesa/pipe/softpipe/sp_state_feedback.c deleted file mode 100644 index 02aaf34e75..0000000000 --- a/src/mesa/pipe/softpipe/sp_state_feedback.c +++ /dev/null @@ -1,72 +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: - * Brian Paul - */ - - -#include "sp_context.h" -#include "sp_state.h" -#include "sp_surface.h" - -#include "pipe/p_winsys.h" -#include "pipe/draw/draw_context.h" - - -void -softpipe_set_feedback_state(struct pipe_context *pipe, - const struct pipe_feedback_state *feedback) -{ - struct softpipe_context *softpipe = softpipe_context(pipe); - - softpipe->feedback = *feedback; /* struct copy */ - /* - softpipe->dirty |= SP_NEW_FEEDBACK; - */ - - draw_set_feedback_state(softpipe->draw, feedback); -} - - -void -softpipe_set_feedback_buffer(struct pipe_context *pipe, - unsigned index, - const struct pipe_feedback_buffer *feedback) -{ - struct softpipe_context *softpipe = softpipe_context(pipe); - - assert(index < PIPE_MAX_FEEDBACK_ATTRIBS); - - /* Need to be careful with referencing */ - pipe->winsys->buffer_reference(pipe->winsys, - &softpipe->feedback_buffer[index].buffer, - feedback->buffer); - softpipe->feedback_buffer[index].size = feedback->size; - softpipe->feedback_buffer[index].start_offset = feedback->start_offset; -} diff --git a/src/mesa/sources b/src/mesa/sources index c34361eaae..4a5a97b47d 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -162,7 +162,6 @@ DRAW_SOURCES = \ pipe/draw/draw_context.c\ pipe/draw/draw_cull.c \ pipe/draw/draw_debug.c \ - pipe/draw/draw_feedback.c \ pipe/draw/draw_flatshade.c \ pipe/draw/draw_offset.c \ pipe/draw/draw_prim.c \ diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 5279cb1cd4..852cff6490 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -173,6 +173,7 @@ static struct rastpos_stage * new_draw_rastpos_stage(GLcontext *ctx, struct draw_context *draw) { struct rastpos_stage *rs = CALLOC_STRUCT(rastpos_stage); + GLuint i; rs->stage.draw = draw; rs->stage.next = NULL; @@ -184,6 +185,26 @@ new_draw_rastpos_stage(GLcontext *ctx, struct draw_context *draw) rs->stage.reset_stipple_counter = rastpos_reset_stipple_counter; rs->ctx = ctx; + for (i = 0; i < VERT_ATTRIB_MAX; i++) { + rs->array[i].Size = 4; + rs->array[i].Type = GL_FLOAT; + rs->array[i].Stride = 0; + rs->array[i].StrideB = 0; + rs->array[i].Ptr = (GLubyte *) ctx->Current.Attrib[i]; + rs->array[i].Enabled = GL_TRUE; + rs->array[i].Normalized = GL_TRUE; + rs->array[i].BufferObj = NULL; + rs->arrays[i] = &rs->array[i]; + } + + rs->prim.mode = GL_POINTS; + rs->prim.indexed = 0; + rs->prim.begin = 1; + rs->prim.end = 1; + rs->prim.weak = 0; + rs->prim.start = 0; + rs->prim.count = 1; + return rs; } @@ -201,31 +222,8 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4]) } else { /* create rastpos draw stage */ - GLuint i; - rs = new_draw_rastpos_stage(ctx, draw); st->rastpos_stage = &rs->stage; - - /* one-time init */ - for (i = 0; i < VERT_ATTRIB_MAX; i++) { - rs->array[i].Size = 4; - rs->array[i].Type = GL_FLOAT; - rs->array[i].Stride = 0; - rs->array[i].StrideB = 0; - rs->array[i].Ptr = (GLubyte *) ctx->Current.Attrib[i]; - rs->array[i].Enabled = GL_TRUE; - rs->array[i].Normalized = GL_TRUE; - rs->array[i].BufferObj = NULL; - rs->arrays[i] = &rs->array[i]; - } - - rs->prim.mode = GL_POINTS; - rs->prim.indexed = 0; - rs->prim.begin = 1; - rs->prim.end = 1; - rs->prim.weak = 0; - rs->prim.start = 0; - rs->prim.count = 1; } /* plug our rastpos stage into the draw module */ diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index c31b76c63f..33aacdb6d1 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -106,7 +106,6 @@ struct st_context struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; struct pipe_constant_buffer constants[2]; - struct pipe_feedback_state feedback; struct pipe_framebuffer_state framebuffer; struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; -- cgit v1.2.3 From 94cadef31f9d4ee9fce1bfa66fabb0a403a6f049 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 11 Dec 2007 13:19:33 +0000 Subject: gallium: remove redundant clear_color state. --- src/mesa/pipe/failover/fo_context.h | 1 - src/mesa/pipe/failover/fo_state.c | 11 ----- src/mesa/pipe/failover/fo_state_emit.c | 3 -- src/mesa/pipe/i915simple/i915_context.h | 1 - src/mesa/pipe/i915simple/i915_state.c | 11 ----- src/mesa/pipe/i965simple/brw_context.h | 1 - src/mesa/pipe/i965simple/brw_state.c | 9 ---- src/mesa/pipe/p_context.h | 3 -- src/mesa/pipe/p_state.h | 5 --- src/mesa/pipe/softpipe/sp_context.c | 1 - src/mesa/pipe/softpipe/sp_context.h | 1 - src/mesa/pipe/softpipe/sp_state.h | 3 -- src/mesa/pipe/softpipe/sp_state_surface.c | 8 ---- src/mesa/sources | 1 - src/mesa/state_tracker/st_atom.c | 1 - src/mesa/state_tracker/st_atom.h | 1 - src/mesa/state_tracker/st_atom_clear_color.c | 63 ---------------------------- src/mesa/state_tracker/st_context.h | 1 - 18 files changed, 125 deletions(-) delete mode 100644 src/mesa/state_tracker/st_atom_clear_color.c (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index 7cf18c9ec1..2423eb4556 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -79,7 +79,6 @@ struct failover_context { const struct fo_state *vertex_shader; 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_poly_stipple poly_stipple; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index fd6137ba66..689d2fa3c7 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -146,16 +146,6 @@ failover_set_clip_state( struct pipe_context *pipe, failover->hw->set_clip_state( failover->hw, clip ); } -static void -failover_set_clear_color_state( struct pipe_context *pipe, - const struct pipe_clear_color_state *clear_color ) -{ - struct failover_context *failover = failover_context(pipe); - - failover->clear_color = *clear_color; - failover->dirty |= FO_NEW_CLEAR_COLOR; - failover->hw->set_clear_color_state( failover->hw, clear_color ); -} static void * failover_create_depth_stencil_state(struct pipe_context *pipe, @@ -480,7 +470,6 @@ failover_init_state_functions( struct failover_context *failover ) 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_polygon_stipple = failover_set_polygon_stipple; failover->pipe.set_sampler_units = failover_set_sampler_units; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index a3aff8abd2..612b0a6ca3 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -69,9 +69,6 @@ failover_state_emit( struct failover_context *failover ) if (failover->dirty & FO_NEW_CLIP) failover->sw->set_clip_state( failover->sw, &failover->clip ); - if (failover->dirty & FO_NEW_CLEAR_COLOR) - 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->sw_state ); diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index b9b67c4fcf..a239c8f72e 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -194,7 +194,6 @@ struct i915_context const struct pipe_shader_state *fs; 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_framebuffer_state framebuffer; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index b9f257a007..a8c6565a54 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -548,16 +548,6 @@ static void i915_set_framebuffer_state(struct pipe_context *pipe, -static void i915_set_clear_color_state(struct pipe_context *pipe, - const struct pipe_clear_color_state *clear) -{ - struct i915_context *i915 = i915_context(pipe); - - i915->clear_color = *clear; /* struct copy */ -} - - - static void i915_set_clip_state( struct pipe_context *pipe, const struct pipe_clip_state *clip ) { @@ -720,7 +710,6 @@ i915_init_state_functions( struct i915_context *i915 ) 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_framebuffer_state = i915_set_framebuffer_state; diff --git a/src/mesa/pipe/i965simple/brw_context.h b/src/mesa/pipe/i965simple/brw_context.h index 00df46e704..53f66cd6a9 100644 --- a/src/mesa/pipe/i965simple/brw_context.h +++ b/src/mesa/pipe/i965simple/brw_context.h @@ -475,7 +475,6 @@ struct brw_context struct pipe_scissor_state Scissor; struct pipe_viewport_state Viewport; struct pipe_framebuffer_state FrameBuffer; - struct pipe_clear_color_state ClearColor; const struct pipe_constant_buffer *Constants[2]; const struct brw_texture *Texture[PIPE_MAX_SAMPLERS]; diff --git a/src/mesa/pipe/i965simple/brw_state.c b/src/mesa/pipe/i965simple/brw_state.c index b50f23c1a2..7731c2e01f 100644 --- a/src/mesa/pipe/i965simple/brw_state.c +++ b/src/mesa/pipe/i965simple/brw_state.c @@ -377,14 +377,6 @@ static void brw_set_framebuffer_state(struct pipe_context *pipe, -static void brw_set_clear_color_state(struct pipe_context *pipe, - const struct pipe_clear_color_state *clear) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.ClearColor = *clear; /* struct copy */ -} - /************************************************************************ * Rasterizer state */ @@ -449,7 +441,6 @@ brw_init_state_functions( struct brw_context *brw ) brw->pipe.set_blend_color = brw_set_blend_color; brw->pipe.set_clip_state = brw_set_clip_state; - brw->pipe.set_clear_color_state = brw_set_clear_color_state; brw->pipe.set_constant_buffer = brw_set_constant_buffer; brw->pipe.set_framebuffer_state = brw_set_framebuffer_state; diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 7da4992841..6b97844445 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -132,9 +132,6 @@ struct pipe_context { void (*set_clip_state)( struct pipe_context *, const struct pipe_clip_state * ); - 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 ); diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 50344bea78..56d4f96ed7 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -200,11 +200,6 @@ struct pipe_blend_color { float color[4]; }; -struct pipe_clear_color_state -{ - float color[4]; -}; - 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 2eab3aaabb..43f23dc1e8 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -304,7 +304,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, 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_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 1c391dcd4d..45d15c720e 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -82,7 +82,6 @@ struct softpipe_context { const struct sp_vertex_shader_state *vs; 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_framebuffer_state framebuffer; diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index f434567da5..80a1cba25a 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -92,9 +92,6 @@ void softpipe_set_framebuffer_state( struct pipe_context *, void softpipe_set_blend_color( struct pipe_context *pipe, const struct pipe_blend_color *blend_color ); -void softpipe_set_clear_color_state( struct pipe_context *, - const struct pipe_clear_color_state * ); - void softpipe_set_clip_state( struct pipe_context *, const struct pipe_clip_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_surface.c b/src/mesa/pipe/softpipe/sp_state_surface.c index 30bedc74bc..ee72aaf4c5 100644 --- a/src/mesa/pipe/softpipe/sp_state_surface.c +++ b/src/mesa/pipe/softpipe/sp_state_surface.c @@ -131,11 +131,3 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, -void -softpipe_set_clear_color_state(struct pipe_context *pipe, - const struct pipe_clear_color_state *clear) -{ - struct softpipe_context *softpipe = softpipe_context(pipe); - - softpipe->clear_color = *clear; /* struct copy */ -} diff --git a/src/mesa/sources b/src/mesa/sources index 4a5a97b47d..fb059498f9 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -200,7 +200,6 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom.c \ state_tracker/st_atom_alphatest.c \ state_tracker/st_atom_blend.c \ - state_tracker/st_atom_clear_color.c \ state_tracker/st_atom_clip.c \ state_tracker/st_atom_constbuf.c \ state_tracker/st_atom_depth.c \ diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 0797ea615e..bde81edd8c 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -45,7 +45,6 @@ static const struct st_tracked_state *atoms[] = { &st_update_framebuffer, - &st_update_clear_color, &st_update_depth_stencil, &st_update_clip, diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 3c0db0db09..0114f42ba5 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -46,7 +46,6 @@ 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_stencil; const struct st_tracked_state st_update_shader; const struct st_tracked_state st_update_rasterizer; diff --git a/src/mesa/state_tracker/st_atom_clear_color.c b/src/mesa/state_tracker/st_atom_clear_color.c deleted file mode 100644 index ce3431c5d3..0000000000 --- a/src/mesa/state_tracker/st_atom_clear_color.c +++ /dev/null @@ -1,63 +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" - - -static void -update_clear_color_state( struct st_context *st ) -{ - struct pipe_clear_color_state clear; - - clear.color[0] = st->ctx->Color.ClearColor[0]; - clear.color[1] = st->ctx->Color.ClearColor[1]; - clear.color[2] = st->ctx->Color.ClearColor[2]; - clear.color[3] = st->ctx->Color.ClearColor[3]; - - if (memcmp(&clear, &st->state.clear_color, sizeof(clear)) != 0) { - st->state.clear_color = clear; - st->pipe->set_clear_color_state( st->pipe, &clear ); - } -} - - -const struct st_tracked_state st_update_clear_color = { - .name = "st_update_clear_color", - .dirty = { - .mesa = _NEW_COLOR, - .st = 0, - }, - .update = update_clear_color_state -}; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 33aacdb6d1..4855961d09 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -103,7 +103,6 @@ struct st_context const struct cso_vertex_shader *vs; 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_framebuffer_state framebuffer; -- cgit v1.2.3 From c3af68dc5022715cc8f126b7df12f3f5248aefe7 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 11 Dec 2007 14:39:37 +0000 Subject: gallium: remove set_sampler_units interface The effect of this mapping can be acheived by the state tracker and setting up the pipe texture state pointers to incorporate its affects. --- src/mesa/pipe/cell/ppu/cell_context.c | 1 - src/mesa/pipe/cell/ppu/cell_context.h | 1 - src/mesa/pipe/cell/ppu/cell_state.h | 3 --- src/mesa/pipe/cell/ppu/cell_state_sampler.c | 20 +++++------------- src/mesa/pipe/failover/fo_context.h | 1 - src/mesa/pipe/failover/fo_state.c | 23 +++++---------------- src/mesa/pipe/failover/fo_state_emit.c | 2 +- src/mesa/pipe/i915simple/i915_context.h | 1 - src/mesa/pipe/i915simple/i915_state.c | 19 +++++------------ src/mesa/pipe/i965simple/brw_state.c | 10 ++------- src/mesa/pipe/llvm/gallivm.cpp | 8 +++----- src/mesa/pipe/llvm/gallivm.h | 3 +-- src/mesa/pipe/llvm/llvm_base_shader.cpp | 2 -- src/mesa/pipe/llvm/llvm_entry.c | 3 +-- src/mesa/pipe/p_context.h | 12 +++++------ src/mesa/pipe/softpipe/sp_context.c | 3 +-- src/mesa/pipe/softpipe/sp_context.h | 1 - src/mesa/pipe/softpipe/sp_quad_fs.c | 3 +-- src/mesa/pipe/softpipe/sp_state.h | 5 +---- src/mesa/pipe/softpipe/sp_state_sampler.c | 17 +++------------ src/mesa/pipe/tgsi/exec/tgsi_exec.c | 3 +-- src/mesa/pipe/tgsi/exec/tgsi_exec.h | 1 - src/mesa/state_tracker/st_atom_sampler.c | 15 +------------- src/mesa/state_tracker/st_atom_texture.c | 32 +++++++++++++++++++---------- src/mesa/state_tracker/st_cb_drawpixels.c | 4 ++-- src/mesa/state_tracker/st_cb_texture.c | 4 ++-- src/mesa/state_tracker/st_cb_texture.h | 3 ++- src/mesa/state_tracker/st_context.h | 2 +- 28 files changed, 65 insertions(+), 137 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/cell/ppu/cell_context.c b/src/mesa/pipe/cell/ppu/cell_context.c index 68543ecf30..5534d82ccf 100644 --- a/src/mesa/pipe/cell/ppu/cell_context.c +++ b/src/mesa/pipe/cell/ppu/cell_context.c @@ -217,7 +217,6 @@ cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws) cell->pipe.set_framebuffer_state = cell_set_framebuffer_state; cell->pipe.set_polygon_stipple = cell_set_polygon_stipple; - cell->pipe.set_sampler_units = cell_set_sampler_units; cell->pipe.set_scissor_state = cell_set_scissor_state; cell->pipe.set_texture_state = cell_set_texture_state; cell->pipe.set_viewport_state = cell_set_viewport_state; diff --git a/src/mesa/pipe/cell/ppu/cell_context.h b/src/mesa/pipe/cell/ppu/cell_context.h index a64692081d..12073b93a0 100644 --- a/src/mesa/pipe/cell/ppu/cell_context.h +++ b/src/mesa/pipe/cell/ppu/cell_context.h @@ -58,7 +58,6 @@ struct cell_context struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; - uint sampler_units[PIPE_MAX_SAMPLERS]; uint dirty; /** The primitive drawing context */ diff --git a/src/mesa/pipe/cell/ppu/cell_state.h b/src/mesa/pipe/cell/ppu/cell_state.h index 033767d29b..4bad45950b 100644 --- a/src/mesa/pipe/cell/ppu/cell_state.h +++ b/src/mesa/pipe/cell/ppu/cell_state.h @@ -93,9 +93,6 @@ void cell_set_constant_buffer(struct pipe_context *pipe, void cell_set_polygon_stipple( struct pipe_context *, const struct pipe_poly_stipple * ); -void cell_set_sampler_units( struct pipe_context *, - uint numSamplers, const uint *units ); - void cell_set_scissor_state( struct pipe_context *, const struct pipe_scissor_state * ); diff --git a/src/mesa/pipe/cell/ppu/cell_state_sampler.c b/src/mesa/pipe/cell/ppu/cell_state_sampler.c index c2a180ed30..495567b16c 100644 --- a/src/mesa/pipe/cell/ppu/cell_state_sampler.c +++ b/src/mesa/pipe/cell/ppu/cell_state_sampler.c @@ -69,32 +69,22 @@ cell_delete_sampler_state(struct pipe_context *pipe, void -cell_set_texture_state(struct pipe_context *pipe, - unsigned unit, - struct pipe_texture *texture) +cell_set_sampler_texture(struct pipe_context *pipe, + unsigned sampler, + struct pipe_texture *texture) { struct cell_context *cell = cell_context(pipe); assert(unit < PIPE_MAX_SAMPLERS); #if 0 - cell->texture[unit] = cell_texture(texture); /* ptr, not struct */ - cell_tile_cache_set_texture(cell->tex_cache[unit], texture); + cell->texture[sampler] = cell_texture(texture); /* ptr, not struct */ + cell_tile_cache_set_texture(cell->tex_cache[sampler], texture); #endif cell->dirty |= CELL_NEW_TEXTURE; } -void -cell_set_sampler_units(struct pipe_context *pipe, - uint num_samplers, const uint *units ) -{ - struct cell_context *cell = cell_context(pipe); - uint i; - for (i = 0; i < num_samplers; i++) - cell->sampler_units[i] = units[i]; - cell->dirty |= CELL_NEW_SAMPLER; -} diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index 2423eb4556..f5eaa0b5fa 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -83,7 +83,6 @@ struct failover_context { struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - uint sampler_units[PIPE_MAX_SAMPLERS]; struct pipe_texture *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 689d2fa3c7..6b4f1517ac 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -284,18 +284,6 @@ failover_set_polygon_stipple( struct pipe_context *pipe, failover->hw->set_polygon_stipple( failover->hw, stipple ); } -static void -failover_set_sampler_units( struct pipe_context *pipe, - uint num_samplers, const uint *units ) -{ - struct failover_context *failover = failover_context(pipe); - uint i; - - for (i = 0; i < num_samplers; i++) - failover->sampler_units[i] = units[i]; - failover->dirty |= FO_NEW_SAMPLER; - failover->hw->set_sampler_units(failover->hw, num_samplers, units); -} static void * failover_create_rasterizer_state(struct pipe_context *pipe, @@ -390,16 +378,16 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) static void -failover_set_texture_state(struct pipe_context *pipe, - unsigned unit, - struct pipe_texture *texture) +failover_set_sampler_texture(struct pipe_context *pipe, + unsigned unit, + struct pipe_texture *texture) { struct failover_context *failover = failover_context(pipe); failover->texture[unit] = texture; failover->dirty |= FO_NEW_TEXTURE; failover->dirty_texture |= (1<hw->set_texture_state( failover->hw, unit, texture ); + failover->hw->set_sampler_texture( failover->hw, unit, texture ); } @@ -472,9 +460,8 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.set_clip_state = failover_set_clip_state; failover->pipe.set_framebuffer_state = failover_set_framebuffer_state; failover->pipe.set_polygon_stipple = failover_set_polygon_stipple; - failover->pipe.set_sampler_units = failover_set_sampler_units; failover->pipe.set_scissor_state = failover_set_scissor_state; - failover->pipe.set_texture_state = failover_set_texture_state; + failover->pipe.set_sampler_texture = failover_set_sampler_texture; failover->pipe.set_viewport_state = failover_set_viewport_state; failover->pipe.set_vertex_buffer = failover_set_vertex_buffer; failover->pipe.set_vertex_element = failover_set_vertex_element; diff --git a/src/mesa/pipe/failover/fo_state_emit.c b/src/mesa/pipe/failover/fo_state_emit.c index 612b0a6ca3..c99ecd4f8d 100644 --- a/src/mesa/pipe/failover/fo_state_emit.c +++ b/src/mesa/pipe/failover/fo_state_emit.c @@ -109,7 +109,7 @@ failover_state_emit( struct failover_context *failover ) if (failover->dirty & FO_NEW_TEXTURE) { for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { if (failover->dirty_texture & (1<sw->set_texture_state( failover->sw, i, + failover->sw->set_sampler_texture( failover->sw, i, failover->texture[i] ); } } diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index a239c8f72e..80df7f0fba 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -199,7 +199,6 @@ struct i915_context struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - uint sampler_units[PIPE_MAX_SAMPLERS]; struct i915_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index a8c6565a54..2a9a587a37 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -431,14 +431,6 @@ static void i915_set_polygon_stipple( struct pipe_context *pipe, { } -static void i915_set_sampler_units(struct pipe_context *pipe, - uint numSamplers, const uint *units) -{ - struct i915_context *i915 = i915_context(pipe); - uint i; - for (i = 0; i < numSamplers; i++) - i915->sampler_units[i] = units[i]; -} static void * i915_create_fs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) @@ -523,13 +515,13 @@ static void i915_set_constant_buffer(struct pipe_context *pipe, } -static void i915_set_texture_state(struct pipe_context *pipe, - unsigned unit, - struct pipe_texture *texture) +static void i915_set_sampler_texture(struct pipe_context *pipe, + unsigned sampler, + struct pipe_texture *texture) { struct i915_context *i915 = i915_context(pipe); - i915->texture[unit] = (struct i915_texture*)texture; /* ptr, not struct */ + i915->texture[sampler] = (struct i915_texture*)texture; /* ptr, not struct */ i915->dirty |= I915_NEW_TEXTURE; } @@ -714,9 +706,8 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.set_framebuffer_state = i915_set_framebuffer_state; i915->pipe.set_polygon_stipple = i915_set_polygon_stipple; - i915->pipe.set_sampler_units = i915_set_sampler_units; i915->pipe.set_scissor_state = i915_set_scissor_state; - i915->pipe.set_texture_state = i915_set_texture_state; + i915->pipe.set_sampler_texture = i915_set_sampler_texture; i915->pipe.set_viewport_state = i915_set_viewport_state; i915->pipe.set_vertex_buffer = i915_set_vertex_buffer; i915->pipe.set_vertex_element = i915_set_vertex_element; diff --git a/src/mesa/pipe/i965simple/brw_state.c b/src/mesa/pipe/i965simple/brw_state.c index 7731c2e01f..ff4ae7999b 100644 --- a/src/mesa/pipe/i965simple/brw_state.c +++ b/src/mesa/pipe/i965simple/brw_state.c @@ -110,11 +110,6 @@ static void brw_delete_sampler_state(struct pipe_context *pipe, } -static void brw_set_sampler_units(struct pipe_context *pipe, - uint numSamplers, const uint *units) -{ -} - /************************************************************************ * Depth stencil */ @@ -349,7 +344,7 @@ static void brw_set_constant_buffer(struct pipe_context *pipe, */ -static void brw_set_texture_state(struct pipe_context *pipe, +static void brw_set_sampler_texture(struct pipe_context *pipe, unsigned unit, struct pipe_texture *texture) { @@ -448,9 +443,8 @@ brw_init_state_functions( struct brw_context *brw ) // brw->pipe.set_feedback_buffer = brw_set_feedback_buffer; brw->pipe.set_polygon_stipple = brw_set_polygon_stipple; - brw->pipe.set_sampler_units = brw_set_sampler_units; brw->pipe.set_scissor_state = brw_set_scissor_state; - brw->pipe.set_texture_state = brw_set_texture_state; + brw->pipe.set_sampler_texture = brw_set_sampler_texture; brw->pipe.set_viewport_state = brw_set_viewport_state; brw->pipe.set_vertex_buffer = brw_set_vertex_buffer; brw->pipe.set_vertex_element = brw_set_vertex_element; diff --git a/src/mesa/pipe/llvm/gallivm.cpp b/src/mesa/pipe/llvm/gallivm.cpp index bd8bfac208..a60440022a 100644 --- a/src/mesa/pipe/llvm/gallivm.cpp +++ b/src/mesa/pipe/llvm/gallivm.cpp @@ -927,23 +927,21 @@ typedef int (*fragment_shader_runner)(float x, float y, float (*inputs)[16][4], int num_attribs, float (*consts)[4], int num_consts, - struct tgsi_sampler *samplers, - unsigned *sampler_units); + struct tgsi_sampler *samplers); int gallivm_fragment_shader_exec(struct gallivm_prog *prog, float fx, float fy, float (*dests)[16][4], float (*inputs)[16][4], float (*consts)[4], - struct tgsi_sampler *samplers, - unsigned *sampler_units) + struct tgsi_sampler *samplers) { fragment_shader_runner runner = reinterpret_cast(prog->function); assert(runner); runner(fx, fy, dests, inputs, prog->num_interp, consts, prog->num_consts, - samplers, sampler_units); + samplers); return 0; } diff --git a/src/mesa/pipe/llvm/gallivm.h b/src/mesa/pipe/llvm/gallivm.h index 6a05a55db4..fd9a11e5b6 100644 --- a/src/mesa/pipe/llvm/gallivm.h +++ b/src/mesa/pipe/llvm/gallivm.h @@ -67,8 +67,7 @@ int gallivm_fragment_shader_exec(struct gallivm_prog *prog, float (*dests)[PIPE_MAX_SHADER_INPUTS][4], float (*inputs)[PIPE_MAX_SHADER_INPUTS][4], float (*consts)[4], - struct tgsi_sampler *samplers, - unsigned *sampler_units); + struct tgsi_sampler *samplers); void gallivm_prog_inputs_interpolate(struct gallivm_prog *prog, float (*inputs)[PIPE_MAX_SHADER_INPUTS][4], const struct tgsi_interp_coef *coefs); diff --git a/src/mesa/pipe/llvm/llvm_base_shader.cpp b/src/mesa/pipe/llvm/llvm_base_shader.cpp index f141ea2da0..a703ba3862 100644 --- a/src/mesa/pipe/llvm/llvm_base_shader.cpp +++ b/src/mesa/pipe/llvm/llvm_base_shader.cpp @@ -770,8 +770,6 @@ Module* createBaseShader() { int32_num_consts_125->setName("num_consts"); Value* ptr_samplers = args++; ptr_samplers->setName("samplers"); - Value* ptr_sampler_units = args++; - ptr_sampler_units->setName("sampler_units"); BasicBlock* label_entry_126 = new BasicBlock("entry",func_run_fragment_shader,0); BasicBlock* label_forbody6_i_127 = new BasicBlock("forbody6.i",func_run_fragment_shader,0); diff --git a/src/mesa/pipe/llvm/llvm_entry.c b/src/mesa/pipe/llvm/llvm_entry.c index fe32e7810d..cbe4965ef6 100644 --- a/src/mesa/pipe/llvm/llvm_entry.c +++ b/src/mesa/pipe/llvm/llvm_entry.c @@ -219,8 +219,7 @@ int run_fragment_shader(float x, float y, int num_inputs, float (*aconsts)[4], int num_consts, - struct tgsi_sampler *samplers, - unsigned *sampler_units) + struct tgsi_sampler *samplers) { float4 inputs[4][16]; float4 consts[32]; diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 6b97844445..83b4ab07fb 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -142,15 +142,15 @@ struct pipe_context { void (*set_polygon_stipple)( struct pipe_context *, const struct pipe_poly_stipple * ); - void (*set_sampler_units)( struct pipe_context *, - uint num_samplers, const uint *units ); - void (*set_scissor_state)( struct pipe_context *, const struct pipe_scissor_state * ); - void (*set_texture_state)( struct pipe_context *, - unsigned unit, - struct pipe_texture * ); + + /* Currently a sampler is constrained to sample from a single texture: + */ + void (*set_sampler_texture)( struct pipe_context *, + unsigned sampler, + struct pipe_texture * ); void (*set_viewport_state)( struct pipe_context *, const struct pipe_viewport_state * ); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 43f23dc1e8..7d243aaabb 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -307,9 +307,8 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer; softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; - softpipe->pipe.set_sampler_units = softpipe_set_sampler_units; softpipe->pipe.set_scissor_state = softpipe_set_scissor_state; - softpipe->pipe.set_texture_state = softpipe_set_texture_state; + softpipe->pipe.set_sampler_texture = softpipe_set_sampler_texture; softpipe->pipe.set_viewport_state = softpipe_set_viewport_state; softpipe->pipe.set_vertex_buffer = softpipe_set_vertex_buffer; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 45d15c720e..afdd0ec88e 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -91,7 +91,6 @@ struct softpipe_context { struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; - uint sampler_units[PIPE_MAX_SAMPLERS]; unsigned dirty; /* diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c index 75576a9bde..9307ed233d 100644 --- a/src/mesa/pipe/softpipe/sp_quad_fs.c +++ b/src/mesa/pipe/softpipe/sp_quad_fs.c @@ -98,7 +98,6 @@ shade_quad( /* Consts does not require 16 byte alignment. */ machine->Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT]; - machine->SamplerUnits = softpipe->sampler_units; machine->InterpCoefs = quad->coef; machine->Inputs[0].xyzw[0].f[0] = fx; @@ -206,7 +205,7 @@ shade_quad_llvm(struct quad_stage *qs, /*quad->mask &=*/ gallivm_fragment_shader_exec(llvm, fx, fy, dests, inputs, softpipe->mapped_constants[PIPE_SHADER_FRAGMENT], - qss->samplers, softpipe->sampler_units); + qss->samplers); #if DLLVM printf("OUT LLVM = 1[%f %f %f %f], 2[%f %f %f %f]\n", dests[0][0][0], dests[0][0][1], dests[0][0][2], dests[0][0][3], diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 80a1cba25a..a3bd078a71 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -111,13 +111,10 @@ void softpipe_delete_vs_state(struct pipe_context *, void *); void softpipe_set_polygon_stipple( struct pipe_context *, const struct pipe_poly_stipple * ); -void softpipe_set_sampler_units( struct pipe_context *, - uint numSamplers, const uint *units ); - void softpipe_set_scissor_state( struct pipe_context *, const struct pipe_scissor_state * ); -void softpipe_set_texture_state( struct pipe_context *, +void softpipe_set_sampler_texture( struct pipe_context *, unsigned unit, struct pipe_texture * ); diff --git a/src/mesa/pipe/softpipe/sp_state_sampler.c b/src/mesa/pipe/softpipe/sp_state_sampler.c index 173901f04e..3842e71503 100644 --- a/src/mesa/pipe/softpipe/sp_state_sampler.c +++ b/src/mesa/pipe/softpipe/sp_state_sampler.c @@ -67,9 +67,9 @@ softpipe_delete_sampler_state(struct pipe_context *pipe, void -softpipe_set_texture_state(struct pipe_context *pipe, - unsigned unit, - struct pipe_texture *texture) +softpipe_set_sampler_texture(struct pipe_context *pipe, + unsigned unit, + struct pipe_texture *texture) { struct softpipe_context *softpipe = softpipe_context(pipe); @@ -82,15 +82,4 @@ softpipe_set_texture_state(struct pipe_context *pipe, } -void -softpipe_set_sampler_units(struct pipe_context *pipe, - uint num_samplers, const uint *units ) -{ - struct softpipe_context *softpipe = softpipe_context(pipe); - uint i; - for (i = 0; i < num_samplers; i++) - softpipe->sampler_units[i] = units[i]; - softpipe->dirty |= SP_NEW_SAMPLER; -} - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_exec.c b/src/mesa/pipe/tgsi/exec/tgsi_exec.c index ab83f27c1b..8636271a34 100644 --- a/src/mesa/pipe/tgsi/exec/tgsi_exec.c +++ b/src/mesa/pipe/tgsi/exec/tgsi_exec.c @@ -1217,8 +1217,7 @@ exec_tex(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst, boolean biasLod) { - const uint sampler = inst->FullSrcRegisters[1].SrcRegister.Index; - const uint unit = mach->SamplerUnits[sampler]; + const uint unit = inst->FullSrcRegisters[1].SrcRegister.Index; union tgsi_exec_channel r[8]; uint chan_index; float lodBias; diff --git a/src/mesa/pipe/tgsi/exec/tgsi_exec.h b/src/mesa/pipe/tgsi/exec/tgsi_exec.h index 2c62b30f15..e7952a08e3 100644 --- a/src/mesa/pipe/tgsi/exec/tgsi_exec.h +++ b/src/mesa/pipe/tgsi/exec/tgsi_exec.h @@ -162,7 +162,6 @@ struct tgsi_exec_machine struct tgsi_exec_vector *Temps; struct tgsi_exec_vector *Addrs; - uint *SamplerUnits; struct tgsi_sampler *Samplers; float Imms[TGSI_EXEC_NUM_IMMEDIATES][4]; diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 67a9159069..052b6dd144 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -172,26 +172,13 @@ update_samplers(struct st_context *st) st->pipe->bind_sampler_state(st->pipe, u, cso->data); } } - - - /* mapping from sampler vars to texture units */ - { - struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; - uint sample_units[PIPE_MAX_SAMPLERS]; - uint s; - for (s = 0; s < PIPE_MAX_SAMPLERS; s++) { - sample_units[s] = fprog->Base.SamplerUnits[s]; - } - - st->pipe->set_sampler_units(st->pipe, PIPE_MAX_SAMPLERS, sample_units); - } } const struct st_tracked_state st_update_sampler = { .name = "st_update_sampler", .dirty = { - .mesa = _NEW_TEXTURE | _NEW_PROGRAM, + .mesa = _NEW_TEXTURE, .st = 0, }, .update = update_samplers diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index c4e5af02d5..fb21d29c40 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -46,20 +46,24 @@ static void update_textures(struct st_context *st) { - GLuint u; + GLuint s; - for (u = 0; u < st->ctx->Const.MaxTextureImageUnits; u++) { + /* ST_NEW_FRAGMENT_PROGRAM + */ + struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; + + for (s = 0; s < st->ctx->Const.MaxTextureCoordUnits; s++) { + GLuint su = fprog->Base.SamplerUnits[s]; + struct gl_texture_object *texObj - = st->ctx->Texture.Unit[u]._Current; + = st->ctx->Texture.Unit[su]._Current; + struct pipe_texture *pt; + if (texObj) { GLboolean flush, retval; - retval = st_finalize_texture(st->ctx, st->pipe, u, &flush); -#if 0 - printf("finalize_texture returned %d, flush = %d\n", - retval, flush); -#endif + retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); pt = st_get_texobj_texture(texObj); } @@ -67,8 +71,14 @@ update_textures(struct st_context *st) pt = NULL; } - st->state.texture[u] = pt; - st->pipe->set_texture_state(st->pipe, u, pt); + /* XXX: need to ensure that textures are unbound/removed from + * this table before being deleted, otherwise the pointer + * comparison below could fail. + */ + if (st->state.sampler_texture[s] != pt) { + st->state.sampler_texture[s] = pt; + st->pipe->set_sampler_texture(st->pipe, s, pt); + } } } @@ -77,7 +87,7 @@ const struct st_tracked_state st_update_texture = { .name = "st_update_texture", .dirty = { .mesa = _NEW_TEXTURE, - .st = 0, + .st = ST_NEW_FRAGMENT_PROGRAM, }, .update = update_textures }; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 0179000353..5d4c443c01 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -697,7 +697,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* texture state: */ { - pipe->set_texture_state(pipe, unit, pt); + pipe->set_sampler_texture(pipe, unit, pt); } /* Compute window coords (y=0=bottom) with pixel zoom. @@ -719,7 +719,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, 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->set_texture_state(pipe, unit, ctx->st->state.texture[unit]); + 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_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 2c93a2f3dd..39dd21dc59 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1412,10 +1412,10 @@ copy_image_data_to_texture(struct st_context *st, */ GLboolean st_finalize_texture(GLcontext *ctx, - struct pipe_context *pipe, GLuint unit, + struct pipe_context *pipe, + struct gl_texture_object *tObj, GLboolean *needFlush) { - struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current; struct st_texture_object *stObj = st_texture_object(tObj); int comp_byte = 0; int cpp; diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h index 7f8082b029..878256ec26 100644 --- a/src/mesa/state_tracker/st_cb_texture.h +++ b/src/mesa/state_tracker/st_cb_texture.h @@ -8,7 +8,8 @@ st_get_texobj_texture(struct gl_texture_object *texObj); extern GLboolean st_finalize_texture(GLcontext *ctx, - struct pipe_context *pipe, GLuint unit, + struct pipe_context *pipe, + struct gl_texture_object *tObj, GLboolean *needFlush); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 4855961d09..87646b3c71 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -106,7 +106,7 @@ struct st_context struct pipe_clip_state clip; struct pipe_constant_buffer constants[2]; struct pipe_framebuffer_state framebuffer; - struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; + struct pipe_texture *sampler_texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_viewport_state viewport; -- 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_context.h') 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 c664302c3e34a29b4bbb02fd3789dd3f7d92849c Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 19 Dec 2007 13:45:00 -0700 Subject: Fix problem with initial viewport/scissor size. If an app never called glViewport, the viewport size was always 0 by 0 pixels. Now pass initial size to st_create_framebuffer() and initialize the viewport and scissor bounds in st_make_current(). This could also be fixed by ensuring the gl_framebuffers passed to _mesa_make_current() were initialized to the right size. But that involves allocating the renderbuffers/pipe_surfaces earlier and that runs into some other issues ATM. Also remove obsolete createRenderbuffers param to st_create_framebuffer(). --- src/mesa/drivers/dri/intel_winsys/intel_screen.c | 4 +- src/mesa/pipe/xlib/xm_api.c | 8 +- src/mesa/state_tracker/st_context.c | 14 +++ src/mesa/state_tracker/st_context.h | 1 + src/mesa/state_tracker/st_framebuffer.c | 109 +++++++++++------------ src/mesa/state_tracker/st_public.h | 2 +- 6 files changed, 79 insertions(+), 59 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_screen.c b/src/mesa/drivers/dri/intel_winsys/intel_screen.c index bce6c5699a..9e31c013a9 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_screen.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_screen.c @@ -297,10 +297,12 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv, else stencilFormat = PIPE_FORMAT_NONE; - intelfb->stfb = st_create_framebuffer(visual, GL_TRUE, + intelfb->stfb = st_create_framebuffer(visual, colorFormat, depthFormat, stencilFormat, + driDrawPriv->w, + driDrawPriv->h, (void*) intelfb); if (!intelfb->stfb) { free(intelfb); diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c index 186a712b52..ebf4c21eaf 100644 --- a/src/mesa/pipe/xlib/xm_api.c +++ b/src/mesa/pipe/xlib/xm_api.c @@ -207,7 +207,7 @@ static GLboolean window_exists( XMesaDisplay *dpy, Window win ) } static Status -get_drawable_size( XMesaDisplay *dpy, Drawable d, GLuint *width, GLuint *height ) +get_drawable_size( XMesaDisplay *dpy, Drawable d, uint *width, uint *height ) { Window root; Status stat; @@ -323,6 +323,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, XMesaBuffer b; GLframebuffer *fb; enum pipe_format colorFormat, depthFormat, stencilFormat; + uint width, height; ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER); @@ -359,11 +360,14 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, } + get_drawable_size(vis->display, d, &width, &height); + /* * Create framebuffer, but we'll plug in our own renderbuffers below. */ - b->stfb = st_create_framebuffer(&vis->mesa_visual, GL_TRUE, + b->stfb = st_create_framebuffer(&vis->mesa_visual, colorFormat, depthFormat, stencilFormat, + width, height, (void *) b); fb = &b->stfb->Base; diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 524e06fb00..1d26da474e 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -28,6 +28,8 @@ #include "main/imports.h" #include "main/context.h" #include "main/extensions.h" +#include "main/matrix.h" +#include "main/buffers.h" #include "vbo/vbo.h" #include "shader/shader_api.h" #include "st_public.h" @@ -163,7 +165,19 @@ void st_make_current(struct st_context *st, struct st_framebuffer *read) { if (st) { + GLboolean firstTime = st->ctx->FirstTimeCurrent; _mesa_make_current(st->ctx, &draw->Base, &read->Base); + /* Need to initialize viewport here since draw->Base->Width/Height + * will still be zero at this point. + * This could be improved, but would require rather extensive work + * elsewhere (allocate rb surface storage sooner) + */ + if (firstTime) { + GLuint w = draw->InitWidth, h = draw->InitHeight; + _mesa_set_viewport(st->ctx, 0, 0, w, h); + _mesa_set_scissor(st->ctx, 0, 0, w, h); + + } } else { _mesa_make_current(NULL, NULL, NULL); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index c3919d474c..0f40f3ceee 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -191,6 +191,7 @@ struct st_framebuffer { GLframebuffer Base; void *Private; + GLuint InitWidth, InitHeight; }; diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index b81a894ef1..5e0943f75c 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -37,80 +37,79 @@ struct st_framebuffer * st_create_framebuffer( const __GLcontextModes *visual, - boolean createRenderbuffers, /* XXX remove? */ enum pipe_format colorFormat, enum pipe_format depthFormat, enum pipe_format stencilFormat, + uint width, uint height, void *private) { struct st_framebuffer *stfb = CALLOC_STRUCT(st_framebuffer); if (stfb) { _mesa_initialize_framebuffer(&stfb->Base, visual); - if (createRenderbuffers) { - { - /* fake frontbuffer */ - /* XXX allocation should only happen in the unusual case - it's actually needed */ - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(colorFormat); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb); - } + { + /* fake frontbuffer */ + /* XXX allocation should only happen in the unusual case + it's actually needed */ + struct gl_renderbuffer *rb + = st_new_renderbuffer_fb(colorFormat); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb); + } - if (visual->doubleBufferMode) { - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(colorFormat); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb); - } + if (visual->doubleBufferMode) { + struct gl_renderbuffer *rb + = st_new_renderbuffer_fb(colorFormat); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb); + } + + if (visual->depthBits == 24 && visual->stencilBits == 8) { + /* combined depth/stencil buffer */ + struct gl_renderbuffer *depthStencilRb + = st_new_renderbuffer_fb(depthFormat); + /* note: bind RB to two attachment points */ + _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb); + } + else { + /* separate depth and/or stencil */ - if (visual->depthBits == 24 && visual->stencilBits == 8) { - /* combined depth/stencil buffer */ - struct gl_renderbuffer *depthStencilRb + if (visual->depthBits == 32) { + /* 32-bit depth buffer */ + struct gl_renderbuffer *depthRb = st_new_renderbuffer_fb(depthFormat); - /* note: bind RB to two attachment points */ - _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } - else { - /* separate depth and/or stencil */ - - if (visual->depthBits == 32) { - /* 32-bit depth buffer */ - struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(depthFormat); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); - } - else if (visual->depthBits == 24) { - /* 24-bit depth buffer, ignore stencil bits */ - struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(depthFormat); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); - } - else if (visual->depthBits > 0) { - /* 16-bit depth buffer */ - struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(depthFormat); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); - } - - if (visual->stencilBits > 0) { - /* 8-bit stencil */ - struct gl_renderbuffer *stencilRb - = st_new_renderbuffer_fb(stencilFormat); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb); - } + else if (visual->depthBits == 24) { + /* 24-bit depth buffer, ignore stencil bits */ + struct gl_renderbuffer *depthRb + = st_new_renderbuffer_fb(depthFormat); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); + } + else if (visual->depthBits > 0) { + /* 16-bit depth buffer */ + struct gl_renderbuffer *depthRb + = st_new_renderbuffer_fb(depthFormat); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } - if (visual->accumRedBits > 0) { - /* 16-bit/channel accum */ - struct gl_renderbuffer *accumRb - = st_new_renderbuffer_fb(PIPE_FORMAT_R16G16B16A16_SNORM); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb); + if (visual->stencilBits > 0) { + /* 8-bit stencil */ + struct gl_renderbuffer *stencilRb + = st_new_renderbuffer_fb(stencilFormat); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb); } } - stfb->Base.Initialized = GL_TRUE; + if (visual->accumRedBits > 0) { + /* 16-bit/channel accum */ + struct gl_renderbuffer *accumRb + = st_new_renderbuffer_fb(PIPE_FORMAT_R16G16B16A16_SNORM); + _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb); + } + stfb->Base.Initialized = GL_TRUE; + stfb->InitWidth = width; + stfb->InitHeight = height; stfb->Private = private; } return stfb; diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index 558b20f1e8..ed5ef1f159 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -55,10 +55,10 @@ void st_copy_context_state(struct st_context *dst, struct st_context *src, uint mask); struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, - boolean createRenderbuffers, enum pipe_format colorFormat, enum pipe_format depthFormat, enum pipe_format stencilFormat, + uint width, uint height, void *privateData); void st_resize_framebuffer( struct st_framebuffer *stfb, -- 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_context.h') 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 756d52ec12c41ee90ee9598dc9028cc134806bd2 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Fri, 25 Jan 2008 17:01:01 +0100 Subject: gallium: Simplify winsys buffer interface. The properties of a buffer represented by struct pipe_buffer_handle are now basically constant over its lifetime. The state tracker gets to deal with any more complex buffer semantics it may need to provide. --- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 82 +++++++------- src/mesa/pipe/i915simple/i915_context.c | 4 +- src/mesa/pipe/i915simple/i915_prim_vbuf.c | 8 +- src/mesa/pipe/i915simple/i915_state.c | 3 +- src/mesa/pipe/i915simple/i915_texture.c | 14 +-- src/mesa/pipe/i965simple/brw_curbe.c | 7 +- src/mesa/pipe/i965simple/brw_draw_upload.c | 6 +- src/mesa/pipe/i965simple/brw_misc_state.c | 6 +- src/mesa/pipe/i965simple/brw_state_pool.c | 10 +- src/mesa/pipe/i965simple/brw_tex_layout.c | 14 +-- src/mesa/pipe/p_defines.h | 26 ++--- src/mesa/pipe/p_inlines.h | 4 +- src/mesa/pipe/p_winsys.h | 59 +++------- src/mesa/pipe/pipebuffer/pb_buffer_handle.c | 52 +-------- src/mesa/pipe/pipebuffer/pb_buffer_handle.h | 4 +- src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c | 3 +- src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c | 4 +- src/mesa/pipe/softpipe/sp_draw_arrays.c | 6 +- src/mesa/pipe/softpipe/sp_texture.c | 9 +- src/mesa/pipe/xlib/xm_winsys.c | 69 ++---------- src/mesa/pipe/xlib/xm_winsys_aub.c | 119 +++++---------------- src/mesa/state_tracker/st_atom_constbuf.c | 16 ++- src/mesa/state_tracker/st_cb_bufferobjects.c | 106 ++++++++++-------- src/mesa/state_tracker/st_cb_bufferobjects.h | 1 + src/mesa/state_tracker/st_context.h | 7 -- src/mesa/state_tracker/st_draw.c | 45 ++------ 26 files changed, 228 insertions(+), 456 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') 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 340fa2fb85..43ed0602a4 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -70,10 +70,10 @@ static void *intel_buffer_map(struct pipe_winsys *winsys, { unsigned drm_flags = 0; - if (flags & PIPE_BUFFER_FLAG_WRITE) + if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) drm_flags |= DRM_BO_FLAG_WRITE; - if (flags & PIPE_BUFFER_FLAG_READ) + if (flags & PIPE_BUFFER_USAGE_CPU_READ) drm_flags |= DRM_BO_FLAG_READ; return driBOMap( dri_bo(buf), drm_flags, 0 ); @@ -103,50 +103,48 @@ intel_buffer_reference(struct pipe_winsys *winsys, } -/* Grabs the hardware lock! - */ -static int intel_buffer_data(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, - unsigned size, const void *data, - unsigned usage ) -{ - driBOData( dri_bo(buf), size, data, 0 ); - return 0; -} - -static int intel_buffer_subdata(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, - unsigned long offset, - unsigned long size, - const void *data) -{ - driBOSubData( dri_bo(buf), offset, size, data ); - return 0; -} - -static int intel_buffer_get_subdata(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, - unsigned long offset, - unsigned long size, - void *data) -{ - driBOGetSubData( dri_bo(buf), offset, size, data ); - return 0; -} - /* Pipe has no concept of pools. We choose the tex/region pool * for all buffers. + * Grabs the hardware lock! */ static struct pipe_buffer_handle * intel_buffer_create(struct pipe_winsys *winsys, unsigned alignment, - unsigned flags, - unsigned hint ) + unsigned usage, + unsigned size ) { struct _DriBufferObject *buffer; struct intel_pipe_winsys *iws = intel_pipe_winsys(winsys); + unsigned flags = 0; + + if (usage & (PIPE_BUFFER_USAGE_VERTEX /*| IWS_BUFFER_USAGE_LOCAL*/)) { + flags |= DRM_BO_FLAG_MEM_LOCAL | DRM_BO_FLAG_CACHED; + } else { + flags |= DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT; + } + + if (usage & PIPE_BUFFER_USAGE_GPU_READ) + flags |= DRM_BO_FLAG_READ; + + if (usage & PIPE_BUFFER_USAGE_GPU_WRITE) + flags |= DRM_BO_FLAG_WRITE; + + /* drm complains if we don't set any read/write flags. + */ + if ((flags & (DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE)) == 0) + flags |= DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE; + +#if 0 + if (flags & IWS_BUFFER_USAGE_EXE) + flags |= DRM_BO_FLAG_EXE; + + if (usage & IWS_BUFFER_USAGE_CACHED) + flags |= DRM_BO_FLAG_CACHED; +#endif + driGenBuffers( iws->regionPool, - "pipe buffer", 1, &buffer, alignment, flags, hint ); + "pipe buffer", 1, &buffer, alignment, flags, 0 ); + driBOData( buffer, size, NULL, 0 ); return pipe_bo(buffer); } @@ -219,15 +217,12 @@ intel_i915_surface_alloc_storage(struct pipe_winsys *winsys, surf->pitch = round_up(width, alignment / surf->cpp); assert(!surf->buffer); - surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0); + surf->buffer = winsys->buffer_create(winsys, alignment, + PIPE_BUFFER_USAGE_PIXEL, + surf->pitch * surf->cpp * height); if(!surf->buffer) return -1; - ret = winsys->buffer_data(winsys, - surf->buffer, - surf->pitch * surf->cpp * height, - NULL, - PIPE_BUFFER_USAGE_PIXEL); if(ret) { winsys->buffer_reference(winsys, &surf->buffer, NULL); return ret; @@ -285,9 +280,6 @@ intel_create_pipe_winsys( int fd ) iws->winsys.buffer_map = intel_buffer_map; iws->winsys.buffer_unmap = intel_buffer_unmap; iws->winsys.buffer_reference = intel_buffer_reference; - iws->winsys.buffer_data = intel_buffer_data; - iws->winsys.buffer_subdata = intel_buffer_subdata; - iws->winsys.buffer_get_subdata = intel_buffer_get_subdata; iws->winsys.flush_frontbuffer = intel_flush_frontbuffer; iws->winsys.printf = intel_printf; iws->winsys.get_name = intel_get_name; diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index 1c6b8cbb05..c2b96d2554 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -185,7 +185,7 @@ i915_draw_elements( struct pipe_context *pipe, void *buf = pipe->winsys->buffer_map(pipe->winsys, i915->vertex_buffer[i].buffer, - PIPE_BUFFER_FLAG_READ); + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_vertex_buffer(draw, i, buf); } } @@ -193,7 +193,7 @@ i915_draw_elements( struct pipe_context *pipe, if (indexBuffer) { void *mapped_indexes = pipe->winsys->buffer_map(pipe->winsys, indexBuffer, - PIPE_BUFFER_FLAG_READ); + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes); } else { diff --git a/src/mesa/pipe/i915simple/i915_prim_vbuf.c b/src/mesa/pipe/i915simple/i915_prim_vbuf.c index edc62e25e5..0887f9a1c6 100644 --- a/src/mesa/pipe/i915simple/i915_prim_vbuf.c +++ b/src/mesa/pipe/i915simple/i915_prim_vbuf.c @@ -99,16 +99,14 @@ i915_vbuf_render_allocate_vertices( struct vbuf_render *render, /* FIXME: handle failure */ assert(!i915->vbo); - i915->vbo = winsys->buffer_create(winsys, 64, 0, 0); - winsys->buffer_data( winsys, i915->vbo, - size, NULL, - I915_BUFFER_USAGE_LIT_VERTEX ); + i915->vbo = winsys->buffer_create(winsys, 64, I915_BUFFER_USAGE_LIT_VERTEX, + size); i915->dirty |= I915_NEW_VBO; return winsys->buffer_map(winsys, i915->vbo, - PIPE_BUFFER_FLAG_WRITE ); + PIPE_BUFFER_USAGE_CPU_WRITE); } diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 1190e05699..950ea52d60 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -476,7 +476,8 @@ static void i915_set_constant_buffer(struct pipe_context *pipe, { void *mapped; if (buf->size && - (mapped = ws->buffer_map(ws, buf->buffer, PIPE_BUFFER_FLAG_READ))) { + (mapped = ws->buffer_map(ws, buf->buffer, + PIPE_BUFFER_USAGE_CPU_READ))) { memcpy(i915->current.constants[shader], mapped, buf->size); ws->buffer_unmap(ws, buf->buffer); i915->current.num_user_constants[shader] diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c index 6b0a4a96f3..bf80e18233 100644 --- a/src/mesa/pipe/i915simple/i915_texture.c +++ b/src/mesa/pipe/i915simple/i915_texture.c @@ -490,15 +490,11 @@ i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) sizeof(struct i915_texture) - sizeof(struct pipe_texture)); if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) : - i915_miptree_layout(pipe, tex)) { - tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64, 0, 0); - - if (tex->buffer) - pipe->winsys->buffer_data(pipe->winsys, tex->buffer, - tex->pitch * tex->base.cpp * - tex->total_height, NULL, - PIPE_BUFFER_USAGE_PIXEL); - } + i915_miptree_layout(pipe, tex)) + tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64, + PIPE_BUFFER_USAGE_PIXEL, + tex->pitch * tex->base.cpp * + tex->total_height); if (!tex->buffer) { FREE(tex); diff --git a/src/mesa/pipe/i965simple/brw_curbe.c b/src/mesa/pipe/i965simple/brw_curbe.c index 4d79a7abe2..2733eb4e75 100644 --- a/src/mesa/pipe/i965simple/brw_curbe.c +++ b/src/mesa/pipe/i965simple/brw_curbe.c @@ -255,15 +255,12 @@ static void upload_constant_buffer(struct brw_context *brw) /* FIXME: buffer size is num_consts + num_immediates */ if (brw->vs.prog_data->num_consts) { /* map the vertex constant buffer and copy to curbe: */ - ws->buffer_map(ws, cbuffer->buffer, 0); + void *data = ws->buffer_map(ws, cbuffer->buffer, 0); /* FIXME: this is wrong. the cbuffer->size currently * represents size of consts + immediates. so if we'll * have both we'll copy over the end of the buffer * with the subsequent memcpy */ - ws->buffer_get_subdata(ws, cbuffer->buffer, - 0, - cbuffer->size, - &buf[offset]); + memcpy(&buf[offset], data, cbuffer->size); ws->buffer_unmap(ws, cbuffer->buffer); offset += cbuffer->size; } diff --git a/src/mesa/pipe/i965simple/brw_draw_upload.c b/src/mesa/pipe/i965simple/brw_draw_upload.c index 88d6c9d111..43e53914e9 100644 --- a/src/mesa/pipe/i965simple/brw_draw_upload.c +++ b/src/mesa/pipe/i965simple/brw_draw_upload.c @@ -240,7 +240,7 @@ boolean brw_upload_vertex_buffers( struct brw_context *brw ) for (i = 0; i < nr_enabled; i++) { OUT_BATCH( vbp.vb[i].vb0.dword ); - OUT_RELOC( vbp.vb[i].buffer, PIPE_BUFFER_FLAG_READ, + OUT_RELOC( vbp.vb[i].buffer, PIPE_BUFFER_USAGE_GPU_READ, vbp.vb[i].offset); OUT_BATCH( vbp.vb[i].max_index ); OUT_BATCH( vbp.vb[i].instance_data_step_rate ); @@ -290,8 +290,8 @@ boolean brw_upload_indices( struct brw_context *brw, BEGIN_BATCH(4, 0); OUT_BATCH( ib.header.dword ); - OUT_RELOC( index_buffer, PIPE_BUFFER_FLAG_READ, start); - OUT_RELOC( index_buffer, PIPE_BUFFER_FLAG_READ, start + count); + OUT_RELOC( index_buffer, PIPE_BUFFER_USAGE_GPU_READ, start); + OUT_RELOC( index_buffer, PIPE_BUFFER_USAGE_GPU_READ, start + count); OUT_BATCH( 0 ); ADVANCE_BATCH(); } diff --git a/src/mesa/pipe/i965simple/brw_misc_state.c b/src/mesa/pipe/i965simple/brw_misc_state.c index 3b7f36dd1d..925049ecc1 100644 --- a/src/mesa/pipe/i965simple/brw_misc_state.c +++ b/src/mesa/pipe/i965simple/brw_misc_state.c @@ -245,7 +245,7 @@ static void upload_depthbuffer(struct brw_context *brw) // (depth_surface->region->tiled << 27) | (BRW_SURFACE_2D << 29)); OUT_RELOC(depth_surface->buffer, - PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE, 0); + PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE, 0); OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1) | ((depth_surface->pitch - 1) << 6) | ((depth_surface->height - 1) << 19)); @@ -465,10 +465,10 @@ static void upload_state_base_address( struct brw_context *brw ) BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS); OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (6 - 2)); OUT_RELOC(brw->pool[BRW_GS_POOL].buffer, - PIPE_BUFFER_FLAG_READ, + PIPE_BUFFER_USAGE_GPU_READ, 1); /* General state base address */ OUT_RELOC(brw->pool[BRW_SS_POOL].buffer, - PIPE_BUFFER_FLAG_READ, + PIPE_BUFFER_USAGE_GPU_READ, 1); /* Surface state base address */ OUT_BATCH(1); /* Indirect object base address */ OUT_BATCH(1); /* General state upper bound */ diff --git a/src/mesa/pipe/i965simple/brw_state_pool.c b/src/mesa/pipe/i965simple/brw_state_pool.c index 78268ed8f2..2f930be837 100644 --- a/src/mesa/pipe/i965simple/brw_state_pool.c +++ b/src/mesa/pipe/i965simple/brw_state_pool.c @@ -91,13 +91,9 @@ static void brw_init_pool( struct brw_context *brw, pool->brw = brw; pool->buffer = brw->pipe.winsys->buffer_create(brw->pipe.winsys, - 4096, 0, 0); - - brw->pipe.winsys->buffer_data(brw->pipe.winsys, - pool->buffer, - size, - NULL, - 0 /* DRM_BO_FLAG_MEM_TT */); + 4096, + 0 /* DRM_BO_FLAG_MEM_TT */, + size); } static void brw_destroy_pool( struct brw_context *brw, diff --git a/src/mesa/pipe/i965simple/brw_tex_layout.c b/src/mesa/pipe/i965simple/brw_tex_layout.c index 2b2bf16f1b..eadacbf09e 100644 --- a/src/mesa/pipe/i965simple/brw_tex_layout.c +++ b/src/mesa/pipe/i965simple/brw_tex_layout.c @@ -308,15 +308,11 @@ brw_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) memset(&tex->base + 1, 0, sizeof(struct brw_texture) - sizeof(struct pipe_texture)); - if (brw_miptree_layout(pipe, tex)) { - tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64, 0, 0); - - if (tex->buffer) - pipe->winsys->buffer_data(pipe->winsys, tex->buffer, - tex->pitch * tex->base.cpp * - tex->total_height, NULL, - PIPE_BUFFER_USAGE_PIXEL); - } + if (brw_miptree_layout(pipe, tex)) + tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64, + PIPE_BUFFER_USAGE_PIXEL, + tex->pitch * tex->base.cpp * + tex->total_height); if (!tex->buffer) { FREE(tex); diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h index 50bea691e7..90eebd5e6c 100644 --- a/src/mesa/pipe/p_defines.h +++ b/src/mesa/pipe/p_defines.h @@ -177,26 +177,20 @@ enum pipe_texture_target { #define PIPE_SURFACE_STATUS_CLEAR 2 -/** - * Buffer access flags - */ -#define PIPE_BUFFER_FLAG_READ 0x1 -#define PIPE_BUFFER_FLAG_WRITE 0x2 -#define PIPE_BUFFER_FLAG_MEM_LOCAL 0x4 -#define PIPE_BUFFER_FLAG_CACHED 0x8 -#define PIPE_BUFFER_FLAG_CUSTOM (1<<16) - - - /** * Buffer usage flags */ -#define PIPE_BUFFER_USAGE_PIXEL (1 << 0) -#define PIPE_BUFFER_USAGE_VERTEX (1 << 1) -#define PIPE_BUFFER_USAGE_INDEX (1 << 2) -#define PIPE_BUFFER_USAGE_CONSTANT (1 << 3) +#define PIPE_BUFFER_USAGE_CPU_READ (1 << 0) +#define PIPE_BUFFER_USAGE_CPU_WRITE (1 << 1) +#define PIPE_BUFFER_USAGE_GPU_READ (1 << 2) +#define PIPE_BUFFER_USAGE_GPU_WRITE (1 << 3) +#define PIPE_BUFFER_USAGE_PIXEL (1 << 4) +#define PIPE_BUFFER_USAGE_VERTEX (1 << 5) +#define PIPE_BUFFER_USAGE_INDEX (1 << 6) +#define PIPE_BUFFER_USAGE_CONSTANT (1 << 7) /** Pipe driver custam usage flags should be greater or equal to this value */ -#define PIPE_BUFFER_USAGE_CUSTOM (1 << 16) +#define PIPE_BUFFER_USAGE_CUSTOM (1 << 16) + /** * Flush types: diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index 6976d087f9..8ee0820f92 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -37,8 +37,8 @@ static INLINE void * pipe_surface_map(struct pipe_surface *surface) { return (char *)surface->winsys->buffer_map( surface->winsys, surface->buffer, - PIPE_BUFFER_FLAG_WRITE | - PIPE_BUFFER_FLAG_READ ) + PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_CPU_READ ) + surface->offset; } diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 75c6dc7e85..9742f59a4d 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -1,4 +1,4 @@ -/************************************************************************** + /************************************************************************** * * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. @@ -93,17 +93,20 @@ struct pipe_winsys /** - * The buffer manager is modeled after the dri_bufmgr interface, which - * in turn is modeled after the ARB_vertex_buffer_object extension, - * but this is the subset that gallium cares about. Remember that - * gallium gets to choose the interface it needs, and the window - * systems must then implement that interface (rather than the + * Buffer management. Buffer attributes are mostly fixed over its lifetime. + * + * Remember that gallium gets to choose the interface it needs, and the + * window systems must then implement that interface (rather than the * other way around...). + * + * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This + * usage argument is only an optimization hint, not a guarantee, therefore + * proper behavior must be observed in all circumstances. */ struct pipe_buffer_handle *(*buffer_create)( struct pipe_winsys *sws, unsigned alignment, - unsigned flags, - unsigned hint ); + unsigned usage, + unsigned size ); /** Create a buffer that wraps user-space data */ struct pipe_buffer_handle *(*user_buffer_create)(struct pipe_winsys *sws, @@ -116,7 +119,7 @@ struct pipe_winsys */ void *(*buffer_map)( struct pipe_winsys *sws, struct pipe_buffer_handle *buf, - unsigned flags ); + unsigned usage ); void (*buffer_unmap)( struct pipe_winsys *sws, struct pipe_buffer_handle *buf ); @@ -126,44 +129,8 @@ struct pipe_winsys struct pipe_buffer_handle **ptr, struct pipe_buffer_handle *buf ); - /** - * Create the data store of a buffer and optionally initialize it. - * - * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This - * usage argument is only an optimization hint, not a guarantee, therefore - * proper behavior must be observed in all circumstances. - * - * Returns zero on success. - */ - int (*buffer_data)(struct pipe_winsys *sws, - struct pipe_buffer_handle *buf, - unsigned size, const void *data, - unsigned usage); - /** - * Modify some or all of the data contained in a buffer's data store. - * - * Returns zero on success. - */ - int (*buffer_subdata)(struct pipe_winsys *sws, - struct pipe_buffer_handle *buf, - unsigned long offset, - unsigned long size, - const void *data); - - /** - * Query some or all of the data contained in a buffer's data store. - * - * Returns zero on success. - */ - int (*buffer_get_subdata)(struct pipe_winsys *sws, - struct pipe_buffer_handle *buf, - unsigned long offset, - unsigned long size, - void *data); - - - /** Set ptr = buf, with reference counting */ + /** Set ptr = fence, with reference counting */ void (*fence_reference)( struct pipe_winsys *sws, struct pipe_fence_handle **ptr, struct pipe_fence_handle *fence ); diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_handle.c b/src/mesa/pipe/pipebuffer/pb_buffer_handle.c index 5a5eaee7ac..9aeff976f3 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer_handle.c +++ b/src/mesa/pipe/pipebuffer/pb_buffer_handle.c @@ -46,8 +46,8 @@ static struct pipe_buffer_handle * buffer_handle_create(struct pipe_winsys *winsys, unsigned alignment, - unsigned flags, - unsigned hint) + unsigned usage, + unsigned size) { struct pipe_buffer_handle *handle; @@ -57,8 +57,8 @@ buffer_handle_create(struct pipe_winsys *winsys, handle->refcount = 1; handle->alignment = alignment; - handle->flags = flags; - handle->hint = hint; + handle->usage = usage; + handle->size = size; handle->buf = &null_buffer; @@ -73,7 +73,7 @@ buffer_handle_create_user(struct pipe_winsys *winsys, struct pipe_buffer_handle *handle; struct pipe_buffer *buf; - handle = buffer_handle_create(winsys, 1, 0, 0); + handle = buffer_handle_create(winsys, 1, 0, size); if(!handle) return NULL; @@ -129,46 +129,6 @@ buffer_handle_reference(struct pipe_winsys *winsys, } -static int -buffer_handle_subdata(struct pipe_winsys *winsys, - struct pipe_buffer_handle *handle, - unsigned long offset, - unsigned long size, - const void *data) -{ - void *map; - assert(handle); - assert(data); - map = buffer_handle_map(winsys, handle, PIPE_BUFFER_FLAG_WRITE); - if(map) { - memcpy((char *)map + offset, data, size); - buffer_handle_unmap(winsys, handle); - return 0; - } - return -1; -} - - -static int -buffer_handle_get_subdata(struct pipe_winsys *winsys, - struct pipe_buffer_handle *handle, - unsigned long offset, - unsigned long size, - void *data) -{ - void *map; - assert(handle); - assert(data); - map = buffer_handle_map(winsys, handle, PIPE_BUFFER_FLAG_READ); - if(map) { - memcpy(data, (char *)map + offset, size); - buffer_handle_unmap(winsys, handle); - return 0; - } - return -1; -} - - void buffer_handle_init_winsys(struct pipe_winsys *winsys) { @@ -177,6 +137,4 @@ buffer_handle_init_winsys(struct pipe_winsys *winsys) winsys->buffer_map = buffer_handle_map; winsys->buffer_unmap = buffer_handle_unmap; winsys->buffer_reference = buffer_handle_reference; - winsys->buffer_subdata = buffer_handle_subdata; - winsys->buffer_get_subdata = buffer_handle_get_subdata; } diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_handle.h b/src/mesa/pipe/pipebuffer/pb_buffer_handle.h index 076eec2fdc..34133c9fba 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer_handle.h +++ b/src/mesa/pipe/pipebuffer/pb_buffer_handle.h @@ -55,8 +55,8 @@ struct pipe_buffer_handle /** Allocation characteristics */ unsigned alignment; - unsigned flags; - unsigned hint; + unsigned usage; + unsigned size; /** * The actual buffer. diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c index e9bc34b4a4..d174f24e32 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c @@ -241,7 +241,8 @@ mm_bufmgr_create_from_buffer(struct pipe_buffer *buffer, mm->buffer = buffer; mm->map = buffer_map(mm->buffer, - PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE ); + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); if(!mm->map) goto failure; diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c index ee6fa62500..e6a8c78668 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c @@ -246,8 +246,8 @@ pool_bufmgr_create(struct buffer_manager *provider, goto failure; pool->map = buffer_map(pool->buffer, - PIPE_BUFFER_FLAG_READ | - PIPE_BUFFER_FLAG_WRITE ); + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); if(!pool->map) goto failure; diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c index b7626f8a5f..8ee9177e5b 100644 --- a/src/mesa/pipe/softpipe/sp_draw_arrays.c +++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c @@ -50,7 +50,7 @@ softpipe_map_constant_buffers(struct softpipe_context *sp) 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); + PIPE_BUFFER_USAGE_CPU_READ); } draw_set_mapped_constant_buffer(sp->draw, @@ -122,7 +122,7 @@ softpipe_draw_elements(struct pipe_context *pipe, void *buf = pipe->winsys->buffer_map(pipe->winsys, sp->vertex_buffer[i].buffer, - PIPE_BUFFER_FLAG_READ); + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_vertex_buffer(draw, i, buf); } } @@ -130,7 +130,7 @@ softpipe_draw_elements(struct pipe_context *pipe, if (indexBuffer) { void *mapped_indexes = pipe->winsys->buffer_map(pipe->winsys, indexBuffer, - PIPE_BUFFER_FLAG_READ); + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes); } else { diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c index d43a6996e9..23e9c1b376 100644 --- a/src/mesa/pipe/softpipe/sp_texture.c +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -91,12 +91,9 @@ softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) softpipe_texture_layout(spt); - spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0); - - if (spt->buffer) { - pipe->winsys->buffer_data(pipe->winsys, spt->buffer, spt->buffer_size, - NULL, PIPE_BUFFER_USAGE_PIXEL); - } + spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, + PIPE_BUFFER_USAGE_PIXEL, + spt->buffer_size); if (!spt->buffer) { FREE(spt); diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index 432431aca1..cb043ef394 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -165,48 +165,6 @@ xm_buffer_reference(struct pipe_winsys *pws, } } -static int -xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, - unsigned size, const void *data, unsigned usage ) -{ - struct xm_buffer *xm_buf = xm_bo(buf); - assert(!xm_buf->userBuffer); - if (xm_buf->size != size) { - if (xm_buf->data) - align_free(xm_buf->data); - /* align to 16-byte multiple for Cell */ - xm_buf->data = align_malloc(size, 16); - xm_buf->size = size; - } - if (data) - memcpy(xm_buf->data, data, size); - return 0; -} - -static int -xm_buffer_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, - unsigned long offset, unsigned long size, const void *data) -{ - struct xm_buffer *xm_buf = xm_bo(buf); - GLubyte *b = (GLubyte *) xm_buf->data; - assert(!xm_buf->userBuffer); - assert(b); - memcpy(b + offset, data, size); - return 0; -} - -static int -xm_buffer_get_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, - unsigned long offset, unsigned long size, void *data) -{ - const struct xm_buffer *xm_buf = xm_bo(buf); - const GLubyte *b = (GLubyte *) xm_buf->data; - assert(!xm_buf->userBuffer); - assert(b); - memcpy(data, b + offset, size); - return 0; -} - /** * Display a surface that's in a tiled configuration. That is, all the @@ -317,11 +275,16 @@ xm_get_name(struct pipe_winsys *pws) static struct pipe_buffer_handle * xm_buffer_create(struct pipe_winsys *pws, unsigned alignment, - unsigned flags, - unsigned hints) + unsigned usage, + unsigned size) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); buffer->refcount = 1; + + /* align to 16-byte multiple for Cell */ + buffer->data = align_malloc(size, max(alignment, 16)); + buffer->size = size; + return pipe_bo(buffer); } @@ -359,7 +322,6 @@ xm_surface_alloc_storage(struct pipe_winsys *winsys, unsigned flags) { const unsigned alignment = 64; - int ret; surf->width = width; surf->height = height; @@ -372,19 +334,11 @@ xm_surface_alloc_storage(struct pipe_winsys *winsys, #endif assert(!surf->buffer); - surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0); + surf->buffer = winsys->buffer_create(winsys, alignment, + PIPE_BUFFER_USAGE_PIXEL, + surf->pitch * surf->cpp * height); if(!surf->buffer) return -1; - - ret = winsys->buffer_data(winsys, - surf->buffer, - surf->pitch * surf->cpp * height, - NULL, - 0); - if(ret) { - winsys->buffer_reference(winsys, &surf->buffer, NULL); - return ret; - } return 0; } @@ -454,9 +408,6 @@ xmesa_get_pipe_winsys_aub(void) ws->buffer_map = xm_buffer_map; ws->buffer_unmap = xm_buffer_unmap; ws->buffer_reference = xm_buffer_reference; - ws->buffer_data = xm_buffer_data; - ws->buffer_subdata = xm_buffer_subdata; - ws->buffer_get_subdata = xm_buffer_get_subdata; ws->surface_alloc = xm_surface_alloc; ws->surface_alloc_storage = xm_surface_alloc_storage; diff --git a/src/mesa/pipe/xlib/xm_winsys_aub.c b/src/mesa/pipe/xlib/xm_winsys_aub.c index 980c0be540..28dd07bc6e 100644 --- a/src/mesa/pipe/xlib/xm_winsys_aub.c +++ b/src/mesa/pipe/xlib/xm_winsys_aub.c @@ -101,7 +101,7 @@ static void *aub_buffer_map(struct pipe_winsys *winsys, assert(sbo->data); - if (flags & PIPE_BUFFER_FLAG_WRITE) + if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) sbo->dump_on_unmap = 1; sbo->map_count++; @@ -150,61 +150,6 @@ aub_buffer_reference(struct pipe_winsys *winsys, } -static int aub_buffer_data(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, - unsigned size, const void *data, - unsigned usage ) -{ - struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys); - struct aub_buffer *sbo = aub_bo(buf); - - /* Could reuse buffers that are not referenced in current - * batchbuffer. Can't do that atm, so always reallocate: - */ - if (1 || sbo->size < size) { - assert(iws->used + size < iws->size); - sbo->data = iws->pool + iws->used; - sbo->offset = AUB_BUF_START + iws->used; - iws->used += align(size, 4096); - } - - sbo->size = size; - - if (data != NULL) { - memcpy(sbo->data, data, size); - - brw_aub_gtt_data( iws->aubfile, - sbo->offset, - sbo->data, - sbo->size, - 0, - 0 ); - } - return 0; -} - -static int aub_buffer_subdata(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, - unsigned long offset, - unsigned long size, - const void *data) -{ - struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys); - struct aub_buffer *sbo = aub_bo(buf); - - assert(sbo->size > offset + size); - memcpy(sbo->data + offset, data, size); - - brw_aub_gtt_data( iws->aubfile, - sbo->offset + offset, - sbo->data + offset, - size, - 0, - 0 ); - return 0; -} - - void xmesa_buffer_subdata_aub(struct pipe_winsys *winsys, struct pipe_buffer_handle *buf, unsigned long offset, @@ -258,29 +203,30 @@ void xmesa_display_aub( /* struct pipe_winsys *winsys, */ -static int aub_buffer_get_subdata(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, - unsigned long offset, - unsigned long size, - void *data) -{ - struct aub_buffer *sbo = aub_bo(buf); - assert(sbo->size >= offset + size); - memcpy(data, sbo->data + offset, size); - return 0; -} - /* Pipe has no concept of pools. We choose the tex/region pool * for all buffers. */ static struct pipe_buffer_handle * aub_buffer_create(struct pipe_winsys *winsys, - unsigned alignment, - unsigned flags, - unsigned hint) + unsigned alignment, + unsigned usage, + unsigned size) { + struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys); struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer); + sbo->refcount = 1; + + /* Could reuse buffers that are not referenced in current + * batchbuffer. Can't do that atm, so always reallocate: + */ + assert(iws->used + size < iws->size); + sbo->data = iws->pool + iws->used; + sbo->offset = AUB_BUF_START + iws->used; + iws->used += align(size, 4096); + + sbo->size = size; + return pipe_bo(sbo); } @@ -288,17 +234,14 @@ aub_buffer_create(struct pipe_winsys *winsys, static struct pipe_buffer_handle * aub_user_buffer_create(struct pipe_winsys *winsys, void *ptr, unsigned bytes) { - struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer); - - sbo->refcount = 1; + struct aub_buffer *sbo; /* Lets hope this is meant for upload, not as a result! */ - aub_buffer_data( winsys, - pipe_bo(sbo), - bytes, - ptr, - 0 ); + sbo = aub_bo(aub_buffer_create( winsys, 0, 0, 0 )); + + sbo->data = ptr; + sbo->size = bytes; return pipe_bo(sbo); } @@ -345,7 +288,6 @@ aub_i915_surface_alloc_storage(struct pipe_winsys *winsys, unsigned flags) { const unsigned alignment = 64; - int ret; surf->width = width; surf->height = height; @@ -354,20 +296,12 @@ aub_i915_surface_alloc_storage(struct pipe_winsys *winsys, surf->pitch = round_up(width, alignment / surf->cpp); assert(!surf->buffer); - surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0); + surf->buffer = winsys->buffer_create(winsys, alignment, + PIPE_BUFFER_USAGE_PIXEL, + surf->pitch * surf->cpp * height); if(!surf->buffer) return -1; - ret = winsys->buffer_data(winsys, - surf->buffer, - surf->pitch * surf->cpp * height, - NULL, - 0); - if(ret) { - winsys->buffer_reference(winsys, &surf->buffer, NULL); - return ret; - } - return 0; } @@ -418,9 +352,6 @@ xmesa_create_pipe_winsys_aub( void ) iws->winsys.buffer_map = aub_buffer_map; iws->winsys.buffer_unmap = aub_buffer_unmap; iws->winsys.buffer_reference = aub_buffer_reference; - iws->winsys.buffer_data = aub_buffer_data; - iws->winsys.buffer_subdata = aub_buffer_subdata; - iws->winsys.buffer_get_subdata = aub_buffer_get_subdata; iws->winsys.flush_frontbuffer = aub_flush_frontbuffer; iws->winsys.printf = aub_printf; iws->winsys.get_name = aub_get_name; diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index 57f5ec68d2..c9d63136b5 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -69,8 +69,13 @@ void st_upload_constants( struct st_context *st, _mesa_load_state_parameters(st->ctx, params); - if (!cbuf->buffer) - cbuf->buffer = ws->buffer_create(ws, 1, 0, 0); + if (cbuf->buffer && cbuf->size != paramBytes) + ws->buffer_reference( ws, &cbuf->buffer, NULL ); + + if (!cbuf->buffer) { + cbuf->buffer = ws->buffer_create(ws, 1, PIPE_BUFFER_USAGE_CONSTANT, + paramBytes); + } if (0) { @@ -80,8 +85,11 @@ void st_upload_constants( struct st_context *st, } /* load Mesa constants into the constant buffer */ - ws->buffer_data(ws, cbuf->buffer, paramBytes, params->ParameterValues, - PIPE_BUFFER_USAGE_CONSTANT); + if (cbuf->buffer) { + memcpy(ws->buffer_map(ws, cbuf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE), + params->ParameterValues, paramBytes); + ws->buffer_unmap(ws, cbuf->buffer); + } cbuf->size = paramBytes; diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index 872248cdb5..60bd1d5f0d 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -55,7 +55,6 @@ static struct gl_buffer_object * st_bufferobj_alloc(GLcontext *ctx, GLuint name, GLenum target) { - struct st_context *st = st_context(ctx); struct st_buffer_object *st_obj = CALLOC_STRUCT(st_buffer_object); if (!st_obj) @@ -63,8 +62,6 @@ st_bufferobj_alloc(GLcontext *ctx, GLuint name, GLenum target) _mesa_initialize_buffer_object(&st_obj->Base, name, target); - st_obj->buffer = st->pipe->winsys->buffer_create( st->pipe->winsys, 32, 0, 0 ); - return &st_obj->Base; } @@ -88,6 +85,57 @@ st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj) +/** + * Replace data in a subrange of buffer object. If the data range + * specified by size + offset extends beyond the end of the buffer or + * if data is NULL, no copy is performed. + * Called via glBufferSubDataARB(). + */ +static void +st_bufferobj_subdata(GLcontext *ctx, + GLenum target, + GLintptrARB offset, + GLsizeiptrARB size, + const GLvoid * data, struct gl_buffer_object *obj) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_buffer_object *st_obj = st_buffer_object(obj); + char *map; + + 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); + memcpy(map + offset, data, size); + pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer); +} + + +/** + * Called via glGetBufferSubDataARB(). + */ +static void +st_bufferobj_get_subdata(GLcontext *ctx, + GLenum target, + GLintptrARB offset, + GLsizeiptrARB size, + GLvoid * data, struct gl_buffer_object *obj) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_buffer_object *st_obj = st_buffer_object(obj); + char *map; + + 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); + memcpy(data, map + offset, size); + pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer); +} + + /** * Allocate space for and store data in a buffer object. Any data that was * previously stored in the buffer object is lost. If data is NULL, @@ -102,7 +150,8 @@ st_bufferobj_data(GLcontext *ctx, GLenum usage, struct gl_buffer_object *obj) { - struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); unsigned buffer_usage; @@ -124,46 +173,15 @@ st_bufferobj_data(GLcontext *ctx, buffer_usage = 0; } - pipe->winsys->buffer_data( pipe->winsys, st_obj->buffer, - size, data, - buffer_usage ); -} + pipe->winsys->buffer_reference( pipe->winsys, &st_obj->buffer, NULL ); + st_obj->buffer = pipe->winsys->buffer_create( pipe->winsys, 32, buffer_usage, + size ); -/** - * Replace data in a subrange of buffer object. If the data range - * specified by size + offset extends beyond the end of the buffer or - * if data is NULL, no copy is performed. - * Called via glBufferSubDataARB(). - */ -static void -st_bufferobj_subdata(GLcontext *ctx, - GLenum target, - GLintptrARB offset, - GLsizeiptrARB size, - const GLvoid * data, 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_subdata(pipe->winsys, st_obj->buffer, offset, size, data); -} - - -/** - * Called via glGetBufferSubDataARB(). - */ -static void -st_bufferobj_get_subdata(GLcontext *ctx, - GLenum target, - GLintptrARB offset, - GLsizeiptrARB size, - GLvoid * data, struct gl_buffer_object *obj) -{ - struct pipe_context *pipe = st_context(ctx)->pipe; - struct st_buffer_object *st_obj = st_buffer_object(obj); + st_obj->size = size; - pipe->winsys->buffer_get_subdata(pipe->winsys, st_obj->buffer, offset, size, data); + if (data) + st_bufferobj_subdata(ctx, target, 0, size, data, obj); } @@ -180,15 +198,15 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, switch (access) { case GL_WRITE_ONLY: - flags = PIPE_BUFFER_FLAG_WRITE; + flags = PIPE_BUFFER_USAGE_CPU_WRITE; break; case GL_READ_ONLY: - flags = PIPE_BUFFER_FLAG_READ; + flags = PIPE_BUFFER_USAGE_CPU_READ; break; case GL_READ_WRITE: /* fall-through */ default: - flags = PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE; + flags = PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE; break; } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.h b/src/mesa/state_tracker/st_cb_bufferobjects.h index 2090a743e0..15003ae15d 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.h +++ b/src/mesa/state_tracker/st_cb_bufferobjects.h @@ -40,6 +40,7 @@ struct st_buffer_object { struct gl_buffer_object Base; struct pipe_buffer_handle *buffer; + GLsizeiptrARB size; }; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 5ae21c93f9..2b6f8743f3 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -164,13 +164,6 @@ struct st_context struct st_fragment_program *combined_prog; } bitmap; - /** - * 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_draw.c b/src/mesa/state_tracker/st_draw.c index 71acf6e862..371d4e7966 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -190,29 +190,6 @@ pipe_vertex_format(GLenum type, GLuint size, GLboolean normalized) } -/** - * The default attribute buffer is basically a copy of the - * ctx->Current.Attrib[] array. It's used when the vertex program - * references an attribute for which we don't have a VBO/array. - */ -static void -create_default_attribs_buffer(struct st_context *st) -{ - struct pipe_context *pipe = st->pipe; - /* XXX don't hardcode magic 32 here */ - st->default_attrib_buffer = pipe->winsys->buffer_create( pipe->winsys, 32, 0, 0 ); -} - - -static void -destroy_default_attribs_buffer(struct st_context *st) -{ - struct pipe_context *pipe = st->pipe; - pipe->winsys->buffer_reference(pipe->winsys, - &st->default_attrib_buffer, NULL); -} - - /** * This function gets plugged into the VBO module and is called when * we have something to render. @@ -399,10 +376,14 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, } /* XXX create one-time */ - vbuf = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0); - pipe->winsys->buffer_data(pipe->winsys, vbuf, - vertex_bytes, verts, - PIPE_BUFFER_USAGE_VERTEX); + vbuf = pipe->winsys->buffer_create(pipe->winsys, 32, + PIPE_BUFFER_USAGE_VERTEX, vertex_bytes); + assert(vbuf); + + memcpy(pipe->winsys->buffer_map(pipe->winsys, vbuf, + PIPE_BUFFER_USAGE_CPU_WRITE), + verts, vertex_bytes); + pipe->winsys->buffer_unmap(pipe->winsys, vbuf); /* tell pipe about the vertex buffer */ vbuffer.buffer = vbuf; @@ -568,7 +549,7 @@ st_feedback_draw_vbo(GLcontext *ctx, /* map the attrib buffer */ map = pipe->winsys->buffer_map(pipe->winsys, vbuffer[attr].buffer, - PIPE_BUFFER_FLAG_READ); + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_vertex_buffer(draw, attr, map); } @@ -592,7 +573,7 @@ st_feedback_draw_vbo(GLcontext *ctx, map = pipe->winsys->buffer_map(pipe->winsys, index_buffer_handle, - PIPE_BUFFER_FLAG_READ); + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_element_buffer(draw, indexSize, map); } else { @@ -604,7 +585,7 @@ st_feedback_draw_vbo(GLcontext *ctx, /* map constant buffers */ mapped_constants = winsys->buffer_map(winsys, st->state.constants[PIPE_SHADER_VERTEX].buffer, - PIPE_BUFFER_FLAG_READ); + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_constant_buffer(st->draw, mapped_constants); @@ -640,16 +621,12 @@ void st_init_draw( struct st_context *st ) { GLcontext *ctx = st->ctx; - /* actually, not used here, but elsewhere */ - create_default_attribs_buffer(st); - vbo_set_draw_func(ctx, st_draw_vbo); } void st_destroy_draw( struct st_context *st ) { - destroy_default_attribs_buffer(st); } -- cgit v1.2.3 From 4650b35846e8e87fb0d74573a5f66452bb449b4b Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 5 Feb 2008 16:32:15 -0700 Subject: gallium: add bitmap/drawpixels texcoord bias support The state tracker will call pipe->get_paramf(PIPE_CAP_BITMAP_TEXCOORD_BIAS) to get a bias factor for adjusting the texcoords used in bitmap/drawpixels. This allows us to compensate for small differences in rasterization from one device to another. --- src/mesa/pipe/p_defines.h | 2 +- src/mesa/state_tracker/st_cb_drawpixels.c | 7 +++++-- src/mesa/state_tracker/st_context.h | 2 ++ src/mesa/state_tracker/st_extensions.c | 3 +++ 4 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h index 85adf2d61d..0bf53ecb79 100644 --- a/src/mesa/pipe/p_defines.h +++ b/src/mesa/pipe/p_defines.h @@ -265,6 +265,6 @@ enum pipe_texture_target { #define PIPE_CAP_MAX_POINT_WIDTH_AA 17 #define PIPE_CAP_MAX_TEXTURE_ANISOTROPY 18 #define PIPE_CAP_MAX_TEXTURE_LOD_BIAS 19 - +#define PIPE_CAP_BITMAP_TEXCOORD_BIAS 20 #endif diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 6b44cba2e4..34d420fcff 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -581,10 +581,13 @@ draw_quad_colored(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, GLfloat x1, GLfloat y1, const GLfloat *color, GLboolean invertTex) { + GLfloat bias = ctx->st->bitmap_texcoord_bias; GLfloat verts[4][3][4]; /* four verts, three attribs, XYZW */ GLuint i; - GLfloat sLeft = 0.0, sRight = 1.0; - GLfloat tTop = invertTex, tBot = 1.0 - tTop; + GLfloat xBias = bias / (x1-x0); + GLfloat yBias = bias / (y1-y0); + GLfloat sLeft = 0.0 + xBias, sRight = 1.0 + xBias; + GLfloat tTop = invertTex - yBias, tBot = 1.0 - tTop - yBias; /* upper-left */ verts[0][0][0] = x0; /* attr[0].x */ diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 2b6f8743f3..a756055898 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -143,6 +143,8 @@ struct st_context GLfloat polygon_offset_scale; /* ?? */ + GLfloat bitmap_texcoord_bias; + /** Mapping from VERT_RESULT_x to post-transformed vertex slot */ const GLuint *vertex_result_to_slot; diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 0157bdd6b3..97d28d77c4 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -106,6 +106,9 @@ void st_init_limits(struct st_context *st) c->MaxTextureLodBias = pipe->get_paramf(pipe, PIPE_CAP_MAX_TEXTURE_LOD_BIAS); + + st->bitmap_texcoord_bias + = pipe->get_paramf(pipe, PIPE_CAP_BITMAP_TEXCOORD_BIAS); } -- cgit v1.2.3 From 6d53b8f42349c507e7184aa567a4b2a4fc7b037f Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 12 Feb 2008 16:06:51 -0700 Subject: gallium: move gen-mipmap global/static vars into st_context This fixes potential problems with multi-context programs. --- src/mesa/state_tracker/st_context.h | 9 ++++++++ src/mesa/state_tracker/st_gen_mipmap.c | 41 +++++++++++----------------------- 2 files changed, 22 insertions(+), 28 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index a756055898..59d1590f05 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -166,6 +166,15 @@ struct st_context struct st_fragment_program *combined_prog; } bitmap; + /** For gen/render mipmap feature */ + struct { + void *blend_cso; + void *depthstencil_cso; + void *rasterizer_cso; + struct st_fragment_program *stfp; + struct st_vertex_program *stvp; + } gen_mipmap; + struct cso_cache *cache; }; diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index fd7d8cefea..b4a21fd7e2 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -48,15 +48,6 @@ -static void *blend_cso = NULL; -static void *depthstencil_cso = NULL; -static void *rasterizer_cso = NULL; - -static struct st_fragment_program *stfp = NULL; -static struct st_vertex_program *stvp = NULL; - - - static struct st_fragment_program * make_tex_fragment_program(GLcontext *ctx) { @@ -119,20 +110,18 @@ st_init_generate_mipmap(struct st_context *st) struct pipe_rasterizer_state rasterizer; struct pipe_depth_stencil_alpha_state depthstencil; - assert(!blend_cso); - memset(&blend, 0, sizeof(blend)); blend.colormask = PIPE_MASK_RGBA; - blend_cso = pipe->create_blend_state(pipe, &blend); + st->gen_mipmap.blend_cso = pipe->create_blend_state(pipe, &blend); memset(&depthstencil, 0, sizeof(depthstencil)); - depthstencil_cso = pipe->create_depth_stencil_alpha_state(pipe, &depthstencil); + st->gen_mipmap.depthstencil_cso = pipe->create_depth_stencil_alpha_state(pipe, &depthstencil); memset(&rasterizer, 0, sizeof(rasterizer)); - rasterizer_cso = pipe->create_rasterizer_state(pipe, &rasterizer); + st->gen_mipmap.rasterizer_cso = pipe->create_rasterizer_state(pipe, &rasterizer); - stfp = make_tex_fragment_program(st->ctx); - stvp = st_make_passthrough_vertex_shader(st, GL_FALSE); + st->gen_mipmap.stfp = make_tex_fragment_program(st->ctx); + st->gen_mipmap.stvp = st_make_passthrough_vertex_shader(st, GL_FALSE); } @@ -141,15 +130,11 @@ st_destroy_generate_mipmpap(struct st_context *st) { struct pipe_context *pipe = st->pipe; - pipe->delete_blend_state(pipe, blend_cso); - pipe->delete_depth_stencil_alpha_state(pipe, depthstencil_cso); - pipe->delete_rasterizer_state(pipe, rasterizer_cso); + pipe->delete_blend_state(pipe, st->gen_mipmap.blend_cso); + pipe->delete_depth_stencil_alpha_state(pipe, st->gen_mipmap.depthstencil_cso); + pipe->delete_rasterizer_state(pipe, st->gen_mipmap.rasterizer_cso); /* XXX free stfp, stvp */ - - blend_cso = NULL; - depthstencil_cso = NULL; - rasterizer_cso = NULL; } @@ -263,13 +248,13 @@ st_render_mipmap(struct st_context *st, /* bind CSOs */ - pipe->bind_blend_state(pipe, blend_cso); - pipe->bind_depth_stencil_alpha_state(pipe, depthstencil_cso); - pipe->bind_rasterizer_state(pipe, rasterizer_cso); + 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 shaders */ - pipe->bind_fs_state(pipe, stfp->fs->data); - pipe->bind_vs_state(pipe, stvp->cso->data); + pipe->bind_fs_state(pipe, st->gen_mipmap.stfp->fs->data); + pipe->bind_vs_state(pipe, st->gen_mipmap.stvp->cso->data); /* * XXX for small mipmap levels, it may be faster to use the software -- cgit v1.2.3 From 58edb0683db45c449b219988a8715cf8fd69e42d Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 20 Feb 2008 11:20:25 -0700 Subject: gallium: state tracker didn't always notify drivers of texobj data changes Calling glTexSubImage() or glTexImage() to replace texture data didn't reliably cause pipe->set_sampler_texture() to get called so drivers didn't always get notified of new texture data. The st_texture_object->pt pointer doesn't always indicate changed data so added a dirtyData field. --- src/mesa/state_tracker/st_atom_texture.c | 18 ++++----- src/mesa/state_tracker/st_cb_drawpixels.c | 3 +- src/mesa/state_tracker/st_cb_fbo.c | 1 + src/mesa/state_tracker/st_cb_texture.c | 42 ++++---------------- src/mesa/state_tracker/st_cb_texture.h | 32 ++++++++++++++-- src/mesa/state_tracker/st_context.h | 22 +---------- src/mesa/state_tracker/st_gen_mipmap.c | 4 +- src/mesa/state_tracker/st_texture.h | 64 +++++++++++++++++++++++++++++++ 8 files changed, 115 insertions(+), 71 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 2a836d630b..9fead7e314 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -34,6 +34,7 @@ #include "st_context.h" #include "st_atom.h" +#include "st_texture.h" #include "st_cb_texture.h" #include "pipe/p_context.h" @@ -53,27 +54,26 @@ update_textures(struct st_context *st) for (unit = 0; unit < st->ctx->Const.MaxTextureCoordUnits; unit++) { const GLuint su = fprog->Base.SamplerUnits[unit]; struct gl_texture_object *texObj = st->ctx->Texture.Unit[su]._Current; - struct pipe_texture *pt; + struct st_texture_object *stObj = st_texture_object(texObj); if (texObj) { GLboolean flush, retval; retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); /* XXX retval indicates whether there's a texture border */ - - pt = st_get_texobj_texture(texObj); - } - else { - pt = NULL; } /* XXX: need to ensure that textures are unbound/removed from * this table before being deleted, otherwise the pointer * comparison below could fail. */ - if (st->state.sampler_texture[unit] != pt) { - st->state.sampler_texture[unit] = pt; - st->pipe->set_sampler_texture(st->pipe, unit, pt); + if (st->state.sampler_texture[unit] != stObj || + (stObj && stObj->dirtyData)) { + struct pipe_texture *pt = st_get_stobj_texture(stObj); + st->state.sampler_texture[unit] = stObj; + st->pipe->set_sampler_texture(st->pipe, unit, pt); + if (stObj) + stObj->dirtyData = GL_FALSE; } } } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index e2d4e06da1..585cae3743 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -726,7 +726,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, 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_texture(pipe, unit, ctx->st->state.sampler_texture[unit]); + pipe->set_sampler_texture(pipe, unit, + st_get_stobj_texture(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_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 4341623267..781425b546 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -48,6 +48,7 @@ #include "st_cb_texture.h" #include "st_format.h" #include "st_public.h" +#include "st_texture.h" diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 03dbb30b0f..7226b0dd98 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -53,33 +53,6 @@ #define DBG if (0) printf -struct st_texture_object -{ - struct gl_texture_object base; /* The "parent" object */ - - /* The texture must include at levels [0..lastLevel] once validated: - */ - GLuint lastLevel; - - /* On validation any active images held in main memory or in other - * textures will be copied to this texture and the old storage freed. - */ - struct pipe_texture *pt; - - GLboolean imageOverride; - GLint depthOverride; - GLuint pitchOverride; -}; - - - -static INLINE struct st_texture_object * -st_texture_object(struct gl_texture_object *obj) -{ - return (struct st_texture_object *) obj; -} - - static INLINE struct st_texture_image * st_texture_image(struct gl_texture_image *img) { @@ -87,14 +60,6 @@ st_texture_image(struct gl_texture_image *img) } -struct pipe_texture * -st_get_texobj_texture(struct gl_texture_object *texObj) -{ - struct st_texture_object *stObj = st_texture_object(texObj); - return stObj->pt; -} - - static enum pipe_texture_target gl_target_to_pipe(GLenum target) { @@ -725,6 +690,9 @@ st_TexImage(GLcontext * ctx, texImage->Data = NULL; } + /* flag data as dirty */ + stObj->dirtyData = GL_TRUE; + #if 01 if (level == texObj->BaseLevel && texObj->GenerateMipmap) { ctx->Driver.GenerateMipmap(ctx, target, texObj); @@ -900,6 +868,7 @@ st_TexSubimage(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { + struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLuint dstRowStride; GLuint srcImageStride = _mesa_image_image_stride(packing, width, height, @@ -961,6 +930,9 @@ st_TexSubimage(GLcontext * ctx, st_texture_image_unmap(stImage); texImage->Data = NULL; } + + /* flag data as dirty */ + stObj->dirtyData = GL_TRUE; } diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h index 878256ec26..843745fcd6 100644 --- a/src/mesa/state_tracker/st_cb_texture.h +++ b/src/mesa/state_tracker/st_cb_texture.h @@ -1,9 +1,33 @@ -#ifndef ST_CB_TEXTURE_H -#define ST_CB_TEXTURE_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. + * + **************************************************************************/ -extern struct pipe_texture * -st_get_texobj_texture(struct gl_texture_object *texObj); +#ifndef ST_CB_TEXTURE_H +#define ST_CB_TEXTURE_H extern GLboolean diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 59d1590f05..5be4769be4 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -59,26 +59,6 @@ struct st_tracked_state { -struct st_texture_image -{ - struct gl_texture_image base; - - /* These aren't stored in gl_texture_image - */ - GLuint level; - GLuint face; - - /* If stImage->pt != NULL, image data is stored here. - * Else if stImage->base.Data != NULL, image is stored there. - * Else there is no image data. - */ - struct pipe_texture *pt; - - struct pipe_surface *surface; -}; - - - struct st_context { GLcontext *ctx; @@ -106,7 +86,7 @@ struct st_context struct pipe_clip_state clip; struct pipe_constant_buffer constants[2]; struct pipe_framebuffer_state framebuffer; - struct pipe_texture *sampler_texture[PIPE_MAX_SAMPLERS]; + struct st_texture_object *sampler_texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_viewport_state viewport; diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 6c09b86033..a0b4b973aa 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -43,6 +43,7 @@ #include "st_draw.h" #include "st_gen_mipmap.h" #include "st_program.h" +#include "st_texture.h" #include "st_cb_drawpixels.h" #include "st_cb_texture.h" @@ -302,7 +303,8 @@ st_render_mipmap(struct st_context *st, pipe->bind_vs_state(pipe, st->state.vs->cso->data); if (st->state.sampler[0]) pipe->bind_sampler_state(pipe, 0, st->state.sampler[0]->data); - pipe->set_sampler_texture(pipe, 0, st->state.sampler_texture[0]); + pipe->set_sampler_texture(pipe, 0, + st_get_stobj_texture(st->state.sampler_texture[0])); pipe->set_viewport_state(pipe, &st->state.viewport); return TRUE; diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index 72324cd9ab..78f5f451ed 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -35,6 +35,70 @@ struct pipe_context; struct pipe_texture; +struct st_texture_image +{ + struct gl_texture_image base; + + /* These aren't stored in gl_texture_image + */ + GLuint level; + GLuint face; + + /* If stImage->pt != NULL, image data is stored here. + * Else if stImage->base.Data != NULL, image is stored there. + * Else there is no image data. + */ + struct pipe_texture *pt; + + struct pipe_surface *surface; +}; + + + +struct st_texture_object +{ + struct gl_texture_object base; /* The "parent" object */ + + /* The texture must include at levels [0..lastLevel] once validated: + */ + GLuint lastLevel; + + /* On validation any active images held in main memory or in other + * textures will be copied to this texture and the old storage freed. + */ + struct pipe_texture *pt; + + GLboolean imageOverride; + GLint depthOverride; + GLuint pitchOverride; + + GLboolean dirtyData; +}; + + +static INLINE struct st_texture_object * +st_texture_object(struct gl_texture_object *obj) +{ + return (struct st_texture_object *) obj; +} + + +static INLINE struct pipe_texture * +st_get_texobj_texture(struct gl_texture_object *texObj) +{ + struct st_texture_object *stObj = st_texture_object(texObj); + return stObj ? stObj->pt : NULL; +} + + +static INLINE struct pipe_texture * +st_get_stobj_texture(struct st_texture_object *stObj) +{ + return stObj ? stObj->pt : NULL; +} + + + extern struct pipe_texture * st_texture_create(struct st_context *st, enum pipe_texture_target target, -- cgit v1.2.3 From 07d6347e8a51fc7bbd5c586a5739f17c68c5eafd Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 29 Feb 2008 16:16:16 -0700 Subject: gallium: change st->state.sampler_texture[] to store pipe_texture pointers This is a better fix for the previous check-in. Fixes texadd.c conform test, and probably other bugs. --- src/mesa/state_tracker/st_atom_texture.c | 14 ++++++-------- src/mesa/state_tracker/st_cb_drawpixels.c | 3 +-- src/mesa/state_tracker/st_context.h | 2 +- src/mesa/state_tracker/st_gen_mipmap.c | 3 +-- 4 files changed, 9 insertions(+), 13 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 0e1c396aeb..697d2cdfb4 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -55,6 +55,7 @@ update_textures(struct st_context *st) const GLuint su = fprog->Base.SamplerUnits[unit]; struct gl_texture_object *texObj = st->ctx->Texture.Unit[su]._Current; struct st_texture_object *stObj = st_texture_object(texObj); + struct pipe_texture *pt; if (texObj) { GLboolean flush, retval; @@ -67,18 +68,15 @@ update_textures(struct st_context *st) * this table before being deleted, otherwise the pointer * comparison below could fail. */ - if (st->state.sampler_texture[unit] != stObj || - (stObj && stObj->dirtyData)) { - /* should really test if the bound 'pt' is changing */ - struct pipe_texture *pt = st_get_stobj_texture(stObj); - st->state.sampler_texture[unit] = stObj; + + pt = st_get_stobj_texture(stObj); + + if (st->state.sampler_texture[unit] != pt) { + st->state.sampler_texture[unit] = pt; st->pipe->set_sampler_texture(st->pipe, unit, pt); } - stObj = st->state.sampler_texture[unit]; - if (stObj && stObj->dirtyData) { - struct pipe_texture *pt = st_get_stobj_texture(stObj); st->pipe->texture_update(st->pipe, pt); stObj->dirtyData = GL_FALSE; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index de99882ab7..65c9fda9cb 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -727,8 +727,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, 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_texture(pipe, unit, - st_get_stobj_texture(ctx->st->state.sampler_texture[unit])); + 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_context.h b/src/mesa/state_tracker/st_context.h index 5be4769be4..1fbf9721e7 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -86,7 +86,7 @@ struct st_context struct pipe_clip_state clip; struct pipe_constant_buffer constants[2]; struct pipe_framebuffer_state framebuffer; - struct st_texture_object *sampler_texture[PIPE_MAX_SAMPLERS]; + struct pipe_texture *sampler_texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_viewport_state viewport; diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 243dc0b1d0..841d77abbc 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -312,8 +312,7 @@ st_render_mipmap(struct st_context *st, pipe->bind_vs_state(pipe, st->state.vs->cso->data); if (st->state.sampler[0]) pipe->bind_sampler_state(pipe, 0, st->state.sampler[0]->data); - pipe->set_sampler_texture(pipe, 0, - st_get_stobj_texture(st->state.sampler_texture[0])); + pipe->set_sampler_texture(pipe, 0, st->state.sampler_texture[0]); pipe->set_viewport_state(pipe, &st->state.viewport); return TRUE; -- cgit v1.2.3 From 4528287e040415c2071012d02f20979ff995c754 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Wed, 5 Mar 2008 10:50:14 +0100 Subject: gallium: michel's patch to rework texture/sampler binding interface Bind all the samplers/textures at once rather than piecemeal. This is easier for drivers to understand. --- src/gallium/auxiliary/draw/draw_aaline.c | 54 +- src/gallium/auxiliary/draw/draw_pstipple.c | 51 +- src/gallium/drivers/failover/fo_context.h | 7 +- src/gallium/drivers/failover/fo_state.c | 59 +- src/gallium/drivers/failover/fo_state_emit.c | 18 +- src/gallium/drivers/i915simple/i915_context.h | 675 +++++----- src/gallium/drivers/i915simple/i915_state.c | 46 +- src/gallium/drivers/i915simple/i915_state_emit.c | 6 - .../drivers/i915simple/i915_state_sampler.c | 6 +- src/gallium/drivers/i965simple/brw_context.h | 1365 ++++++++++---------- src/gallium/drivers/i965simple/brw_state.c | 896 ++++++------- .../drivers/i965simple/brw_wm_sampler_state.c | 3 +- .../drivers/i965simple/brw_wm_surface_state.c | 2 +- src/gallium/drivers/softpipe/sp_context.c | 486 +++---- src/gallium/drivers/softpipe/sp_context.h | 3 + src/gallium/drivers/softpipe/sp_quad_fs.c | 417 +++--- src/gallium/drivers/softpipe/sp_state.h | 390 +++--- src/gallium/drivers/softpipe/sp_state_sampler.c | 56 +- src/gallium/drivers/softpipe/sp_texture.c | 404 +++--- src/gallium/include/pipe/p_context.h | 8 +- src/mesa/state_tracker/st_atom_sampler.c | 16 +- src/mesa/state_tracker/st_atom_texture.c | 15 +- src/mesa/state_tracker/st_cb_drawpixels.c | 11 +- src/mesa/state_tracker/st_context.h | 5 +- src/mesa/state_tracker/st_gen_mipmap.c | 11 +- 25 files changed, 2561 insertions(+), 2449 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/gallium/auxiliary/draw/draw_aaline.c b/src/gallium/auxiliary/draw/draw_aaline.c index 7660e56fe6..3ec73b0800 100644 --- a/src/gallium/auxiliary/draw/draw_aaline.c +++ b/src/gallium/auxiliary/draw/draw_aaline.c @@ -78,7 +78,8 @@ struct aaline_stage void *sampler_cso; struct pipe_texture *texture; - uint sampler_unit; + uint num_samplers; + uint num_textures; /* @@ -98,11 +99,10 @@ struct aaline_stage void (*driver_bind_fs_state)(struct pipe_context *, void *); void (*driver_delete_fs_state)(struct pipe_context *, void *); - void (*driver_bind_sampler_state)(struct pipe_context *, unsigned, void *); - - void (*driver_set_sampler_texture)(struct pipe_context *, - unsigned sampler, - struct pipe_texture *); + void (*driver_bind_sampler_states)(struct pipe_context *, unsigned, + void **); + void (*driver_set_sampler_textures)(struct pipe_context *, unsigned, + struct pipe_texture **); struct pipe_context *pipe; }; @@ -607,6 +607,7 @@ aaline_first_line(struct draw_stage *stage, struct prim_header *header) auto struct aaline_stage *aaline = aaline_stage(stage); struct draw_context *draw = stage->draw; struct pipe_context *pipe = aaline->pipe; + uint num = MAX2(aaline->num_textures, aaline->num_samplers); assert(draw->rasterizer->line_smooth); @@ -624,8 +625,11 @@ aaline_first_line(struct draw_stage *stage, struct prim_header *header) */ bind_aaline_fragment_shader(aaline); - aaline->driver_bind_sampler_state(pipe, aaline->sampler_unit, aaline->sampler_cso); - aaline->driver_set_sampler_texture(pipe, aaline->sampler_unit, aaline->texture); + aaline->state.sampler[num] = aaline->sampler_cso; + aaline->state.texture[num] = aaline->texture; + + aaline->driver_bind_sampler_states(pipe, num + 1, aaline->state.sampler); + aaline->driver_set_sampler_textures(pipe, num + 1, aaline->state.texture); /* now really draw first line */ stage->line = aaline_line; @@ -647,10 +651,10 @@ aaline_flush(struct draw_stage *stage, unsigned flags) aaline->driver_bind_fs_state(pipe, aaline->fs->driver_fs); /* XXX restore original texture, sampler state */ - aaline->driver_bind_sampler_state(pipe, aaline->sampler_unit, - aaline->state.sampler[aaline->sampler_unit]); - aaline->driver_set_sampler_texture(pipe, aaline->sampler_unit, - aaline->state.texture[aaline->sampler_unit]); + aaline->driver_bind_sampler_states(pipe, aaline->num_samplers, + aaline->state.sampler); + aaline->driver_set_sampler_textures(pipe, aaline->num_textures, + aaline->state.texture); draw->extra_vp_outputs.slot = 0; } @@ -745,26 +749,28 @@ aaline_delete_fs_state(struct pipe_context *pipe, void *fs) static void -aaline_bind_sampler_state(struct pipe_context *pipe, - unsigned unit, void *sampler) +aaline_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) { struct aaline_stage *aaline = aaline_stage_from_pipe(pipe); /* save current */ - aaline->state.sampler[unit] = sampler; + memcpy(aaline->state.sampler, sampler, num * sizeof(void *)); + aaline->num_samplers = num; /* pass-through */ - aaline->driver_bind_sampler_state(aaline->pipe, unit, sampler); + aaline->driver_bind_sampler_states(aaline->pipe, num, sampler); } static void -aaline_set_sampler_texture(struct pipe_context *pipe, - unsigned sampler, struct pipe_texture *texture) +aaline_set_sampler_textures(struct pipe_context *pipe, + unsigned num, struct pipe_texture **texture) { struct aaline_stage *aaline = aaline_stage_from_pipe(pipe); /* save current */ - aaline->state.texture[sampler] = texture; + memcpy(aaline->state.texture, texture, num * sizeof(struct pipe_texture *)); + aaline->num_textures = num; /* pass-through */ - aaline->driver_set_sampler_texture(aaline->pipe, sampler, texture); + aaline->driver_set_sampler_textures(aaline->pipe, num, texture); } @@ -798,14 +804,14 @@ draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe) aaline->driver_bind_fs_state = pipe->bind_fs_state; aaline->driver_delete_fs_state = pipe->delete_fs_state; - aaline->driver_bind_sampler_state = pipe->bind_sampler_state; - aaline->driver_set_sampler_texture = pipe->set_sampler_texture; + aaline->driver_bind_sampler_states = pipe->bind_sampler_states; + aaline->driver_set_sampler_textures = pipe->set_sampler_textures; /* override the driver's functions */ pipe->create_fs_state = aaline_create_fs_state; pipe->bind_fs_state = aaline_bind_fs_state; pipe->delete_fs_state = aaline_delete_fs_state; - pipe->bind_sampler_state = aaline_bind_sampler_state; - pipe->set_sampler_texture = aaline_set_sampler_texture; + pipe->bind_sampler_states = aaline_bind_sampler_states; + pipe->set_sampler_textures = aaline_set_sampler_textures; } diff --git a/src/gallium/auxiliary/draw/draw_pstipple.c b/src/gallium/auxiliary/draw/draw_pstipple.c index 2cfeb813b3..894b136f2c 100644 --- a/src/gallium/auxiliary/draw/draw_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pstipple.c @@ -68,7 +68,8 @@ struct pstip_stage void *sampler_cso; struct pipe_texture *texture; - uint sampler_unit; + uint num_samplers; + uint num_textures; /* * Currently bound state @@ -88,11 +89,10 @@ struct pstip_stage void (*driver_bind_fs_state)(struct pipe_context *, void *); void (*driver_delete_fs_state)(struct pipe_context *, void *); - void (*driver_bind_sampler_state)(struct pipe_context *, unsigned, void *); + void (*driver_bind_sampler_states)(struct pipe_context *, unsigned, void **); - void (*driver_set_sampler_texture)(struct pipe_context *, - unsigned sampler, - struct pipe_texture *); + void (*driver_set_sampler_textures)(struct pipe_context *, unsigned, + struct pipe_texture **); void (*driver_set_polygon_stipple)(struct pipe_context *, const struct pipe_poly_stipple *); @@ -328,8 +328,6 @@ generate_pstip_fs(struct pstip_stage *pstip) tgsi_dump(pstip_fs.tokens, 0); #endif - pstip->sampler_unit = transform.maxSampler + 1; - #if 1 /* XXX remove */ if (transform.wincoordInput < 0) { pstip_fs.input_semantic_name[pstip_fs.num_inputs] = TGSI_SEMANTIC_POSITION; @@ -486,6 +484,7 @@ pstip_first_tri(struct draw_stage *stage, struct prim_header *header) struct pstip_stage *pstip = pstip_stage(stage); struct draw_context *draw = stage->draw; struct pipe_context *pipe = pstip->pipe; + uint num = MAX2(pstip->num_textures, pstip->num_samplers); assert(draw->rasterizer->poly_stipple_enable); @@ -494,8 +493,8 @@ pstip_first_tri(struct draw_stage *stage, struct prim_header *header) */ bind_pstip_fragment_shader(pstip); - pstip->driver_bind_sampler_state(pipe, pstip->sampler_unit, pstip->sampler_cso); - pstip->driver_set_sampler_texture(pipe, pstip->sampler_unit, pstip->texture); + pstip->driver_bind_sampler_states(pipe, num + 1, pstip->state.sampler); + pstip->driver_set_sampler_textures(pipe, num + 1, pstip->state.texture); /* now really draw first line */ stage->tri = passthrough_tri; @@ -517,10 +516,10 @@ pstip_flush(struct draw_stage *stage, unsigned flags) pstip->driver_bind_fs_state(pipe, pstip->fs->driver_fs); /* XXX restore original texture, sampler state */ - pstip->driver_bind_sampler_state(pipe, pstip->sampler_unit, - pstip->state.sampler[pstip->sampler_unit]); - pstip->driver_set_sampler_texture(pipe, pstip->sampler_unit, - pstip->state.texture[pstip->sampler_unit]); + pstip->driver_bind_sampler_states(pipe, pstip->num_samplers, + pstip->state.sampler); + pstip->driver_set_sampler_textures(pipe, pstip->num_textures, + pstip->state.texture); } @@ -613,26 +612,28 @@ pstip_delete_fs_state(struct pipe_context *pipe, void *fs) static void -pstip_bind_sampler_state(struct pipe_context *pipe, - unsigned unit, void *sampler) +pstip_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) { struct pstip_stage *pstip = pstip_stage_from_pipe(pipe); /* save current */ - pstip->state.sampler[unit] = sampler; + memcpy(pstip->state.sampler, sampler, num * sizeof(void *)); + pstip->num_samplers = num; /* pass-through */ - pstip->driver_bind_sampler_state(pstip->pipe, unit, sampler); + pstip->driver_bind_sampler_states(pstip->pipe, num, sampler); } static void -pstip_set_sampler_texture(struct pipe_context *pipe, - unsigned sampler, struct pipe_texture *texture) +pstip_set_sampler_textures(struct pipe_context *pipe, + unsigned num, struct pipe_texture **texture) { struct pstip_stage *pstip = pstip_stage_from_pipe(pipe); /* save current */ - pstip->state.texture[sampler] = texture; + memcpy(pstip->state.texture, texture, num * sizeof(struct pipe_texture *)); + pstip->num_textures = num; /* pass-through */ - pstip->driver_set_sampler_texture(pstip->pipe, sampler, texture); + pstip->driver_set_sampler_textures(pstip->pipe, num, texture); } @@ -682,8 +683,8 @@ draw_install_pstipple_stage(struct draw_context *draw, pstip->driver_bind_fs_state = pipe->bind_fs_state; pstip->driver_delete_fs_state = pipe->delete_fs_state; - pstip->driver_bind_sampler_state = pipe->bind_sampler_state; - pstip->driver_set_sampler_texture = pipe->set_sampler_texture; + pstip->driver_bind_sampler_states = pipe->bind_sampler_states; + pstip->driver_set_sampler_textures = pipe->set_sampler_textures; pstip->driver_set_polygon_stipple = pipe->set_polygon_stipple; /* override the driver's functions */ @@ -691,7 +692,7 @@ draw_install_pstipple_stage(struct draw_context *draw, pipe->bind_fs_state = pstip_bind_fs_state; pipe->delete_fs_state = pstip_delete_fs_state; - pipe->bind_sampler_state = pstip_bind_sampler_state; - pipe->set_sampler_texture = pstip_set_sampler_texture; + pipe->bind_sampler_states = pstip_bind_sampler_states; + pipe->set_sampler_textures = pstip_set_sampler_textures; pipe->set_polygon_stipple = pstip_set_polygon_stipple; } diff --git a/src/gallium/drivers/failover/fo_context.h b/src/gallium/drivers/failover/fo_context.h index 1dc87291c9..8f3ad3ee79 100644 --- a/src/gallium/drivers/failover/fo_context.h +++ b/src/gallium/drivers/failover/fo_context.h @@ -87,12 +87,15 @@ struct failover_context { struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; + void *sw_sampler_state[PIPE_MAX_SAMPLERS]; + void *hw_sampler_state[PIPE_MAX_SAMPLERS]; + unsigned dirty; - unsigned dirty_sampler; - unsigned dirty_texture; unsigned dirty_vertex_buffer; unsigned dirty_vertex_element; + unsigned num_samplers; + unsigned num_textures; unsigned mode; struct pipe_context *hw; diff --git a/src/gallium/drivers/failover/fo_state.c b/src/gallium/drivers/failover/fo_state.c index 0fc5568da1..11eec2714e 100644 --- a/src/gallium/drivers/failover/fo_state.c +++ b/src/gallium/drivers/failover/fo_state.c @@ -28,6 +28,8 @@ /* Authors: Keith Whitwell */ +#include "pipe/p_inlines.h" + #include "fo_context.h" @@ -322,18 +324,27 @@ failover_create_sampler_state(struct pipe_context *pipe, } static void -failover_bind_sampler_state(struct pipe_context *pipe, - unsigned unit, void *sampler) +failover_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) { struct failover_context *failover = failover_context(pipe); struct fo_state *state = (struct fo_state*)sampler; - failover->sampler[unit] = state; + uint i; + assert(num <= PIPE_MAX_SAMPLERS); + /* Check for no-op */ + if (num == failover->num_samplers && + !memcmp(failover->sampler, sampler, num * sizeof(void *))) + return; + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + failover->sw_sampler_state[i] = i < num ? state[i].sw_state : NULL; + failover->hw_sampler_state[i] = i < num ? state[i].hw_state : NULL; + } failover->dirty |= FO_NEW_SAMPLER; - failover->dirty_sampler |= (1<sw->bind_sampler_state(failover->sw, unit, - state->sw_state); - failover->hw->bind_sampler_state(failover->hw, unit, - state->hw_state); + failover->num_samplers = num; + failover->sw->bind_sampler_states(failover->sw, num, + failover->sw_sampler_state); + failover->hw->bind_sampler_states(failover->hw, num, + failover->hw_sampler_state); } static void @@ -351,17 +362,29 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) static void -failover_set_sampler_texture(struct pipe_context *pipe, - unsigned unit, - struct pipe_texture *texture) +failover_set_sampler_textures(struct pipe_context *pipe, + unsigned num, + struct pipe_texture **texture) { struct failover_context *failover = failover_context(pipe); - - failover->texture[unit] = texture; + uint i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == failover->num_textures && + !memcmp(failover->texture, texture, num * sizeof(struct pipe_texture *))) + return; + for (i = 0; i < num; i++) + pipe_texture_reference((struct pipe_texture **) &failover->texture[i], + texture[i]); + for (i = num; i < failover->num_textures; i++) + pipe_texture_reference((struct pipe_texture **) &failover->texture[i], + NULL); failover->dirty |= FO_NEW_TEXTURE; - failover->dirty_texture |= (1<sw->set_sampler_texture( failover->sw, unit, texture ); - failover->hw->set_sampler_texture( failover->hw, unit, texture ); + failover->num_textures = num; + failover->sw->set_sampler_textures( failover->sw, num, texture ); + failover->hw->set_sampler_textures( failover->hw, num, texture ); } @@ -429,7 +452,7 @@ 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.create_sampler_state = failover_create_sampler_state; - failover->pipe.bind_sampler_state = failover_bind_sampler_state; + failover->pipe.bind_sampler_states = failover_bind_sampler_states; failover->pipe.delete_sampler_state = failover_delete_sampler_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; @@ -449,7 +472,7 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.set_framebuffer_state = failover_set_framebuffer_state; failover->pipe.set_polygon_stipple = failover_set_polygon_stipple; failover->pipe.set_scissor_state = failover_set_scissor_state; - failover->pipe.set_sampler_texture = failover_set_sampler_texture; + failover->pipe.set_sampler_textures = failover_set_sampler_textures; failover->pipe.set_viewport_state = failover_set_viewport_state; failover->pipe.set_vertex_buffer = failover_set_vertex_buffer; failover->pipe.set_vertex_element = failover_set_vertex_element; diff --git a/src/gallium/drivers/failover/fo_state_emit.c b/src/gallium/drivers/failover/fo_state_emit.c index c663dd4947..3de931e04e 100644 --- a/src/gallium/drivers/failover/fo_state_emit.c +++ b/src/gallium/drivers/failover/fo_state_emit.c @@ -94,21 +94,13 @@ failover_state_emit( struct failover_context *failover ) failover->sw->set_viewport_state( failover->sw, &failover->viewport ); if (failover->dirty & FO_NEW_SAMPLER) { - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - if (failover->dirty_sampler & (1<sw->bind_sampler_state( failover->sw, i, - failover->sampler[i]->sw_state ); - } - } + failover->sw->bind_sampler_states( failover->sw, failover->num_samplers, + failover->sw_sampler_state ); } if (failover->dirty & FO_NEW_TEXTURE) { - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - if (failover->dirty_texture & (1<sw->set_sampler_texture( failover->sw, i, - failover->texture[i] ); - } - } + failover->sw->set_sampler_textures( failover->sw, failover->num_textures, + failover->texture ); } if (failover->dirty & FO_NEW_VERTEX_BUFFER) { @@ -132,6 +124,4 @@ failover_state_emit( struct failover_context *failover ) failover->dirty = 0; failover->dirty_vertex_element = 0; failover->dirty_vertex_buffer = 0; - failover->dirty_texture = 0; - failover->dirty_sampler = 0; } diff --git a/src/gallium/drivers/i915simple/i915_context.h b/src/gallium/drivers/i915simple/i915_context.h index 6401112f83..746f18ba38 100644 --- a/src/gallium/drivers/i915simple/i915_context.h +++ b/src/gallium/drivers/i915simple/i915_context.h @@ -1,336 +1,339 @@ - /************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef I915_CONTEXT_H -#define I915_CONTEXT_H - - -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_state.h" - -#include "draw/draw_vertex.h" - -#include "tgsi/util/tgsi_scan.h" - - -#define I915_TEX_UNITS 8 - -#define I915_DYNAMIC_MODES4 0 -#define I915_DYNAMIC_DEPTHSCALE_0 1 /* just the header */ -#define I915_DYNAMIC_DEPTHSCALE_1 2 -#define I915_DYNAMIC_IAB 3 -#define I915_DYNAMIC_BC_0 4 /* just the header */ -#define I915_DYNAMIC_BC_1 5 -#define I915_DYNAMIC_BFO_0 6 -#define I915_DYNAMIC_BFO_1 7 -#define I915_DYNAMIC_STP_0 8 -#define I915_DYNAMIC_STP_1 9 -#define I915_DYNAMIC_SC_ENA_0 10 -#define I915_DYNAMIC_SC_RECT_0 11 -#define I915_DYNAMIC_SC_RECT_1 12 -#define I915_DYNAMIC_SC_RECT_2 13 -#define I915_MAX_DYNAMIC 14 - - -#define I915_IMMEDIATE_S0 0 -#define I915_IMMEDIATE_S1 1 -#define I915_IMMEDIATE_S2 2 -#define I915_IMMEDIATE_S3 3 -#define I915_IMMEDIATE_S4 4 -#define I915_IMMEDIATE_S5 5 -#define I915_IMMEDIATE_S6 6 -#define I915_IMMEDIATE_S7 7 -#define I915_MAX_IMMEDIATE 8 - -/* These must mach the order of LI0_STATE_* bits, as they will be used - * to generate hardware packets: - */ -#define I915_CACHE_STATIC 0 -#define I915_CACHE_DYNAMIC 1 /* handled specially */ -#define I915_CACHE_SAMPLER 2 -#define I915_CACHE_MAP 3 -#define I915_CACHE_PROGRAM 4 -#define I915_CACHE_CONSTANTS 5 -#define I915_MAX_CACHE 6 - -#define I915_MAX_CONSTANT 32 - - -/** See constant_flags[] below */ -#define I915_CONSTFLAG_USER 0x1f - - -/** - * Subclass of pipe_shader_state - */ -struct i915_fragment_shader -{ - struct pipe_shader_state state; - - struct tgsi_shader_info info; - - uint *program; - uint program_len; - - /** - * constants introduced during translation. - * These are placed at the end of the constant buffer and grow toward - * the beginning (eg: slot 31, 30 29, ...) - * User-provided constants start at 0. - * This allows both types of constants to co-exist (until there's too many) - * and doesn't require regenerating/changing the fragment program to - * shuffle constants around. - */ - uint num_constants; - float constants[I915_MAX_CONSTANT][4]; - - /** - * Status of each constant - * if I915_CONSTFLAG_PARAM, the value must be taken from the corresponding - * slot of the user's constant buffer. (set by pipe->set_constant_buffer()) - * Else, the bitmask indicates which components are occupied by immediates. - */ - ubyte constant_flags[I915_MAX_CONSTANT]; -}; - - -struct i915_cache_context; - -/* Use to calculate differences between state emitted to hardware and - * current driver-calculated state. - */ -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]; - - /* texture sampler state */ - unsigned sampler[I915_TEX_UNITS][3]; - unsigned sampler_enable_flags; - unsigned sampler_enable_nr; - - /* texture image buffers */ - unsigned texbuffer[I915_TEX_UNITS][2]; - - /** Describes the current hardware vertex layout */ - struct vertex_info vertex_info; - - unsigned id; /* track lost context events */ -}; - -struct i915_blend_state { - unsigned iab; - unsigned modes4; - unsigned LIS5; - unsigned LIS6; -}; - -struct i915_depth_stencil_state { - unsigned stencil_modes4; - unsigned bfo[2]; - unsigned stencil_LIS5; - unsigned depth_LIS6; -}; - -struct i915_rasterizer_state { - int light_twoside : 1; - unsigned st; - enum interp_mode color_interp; - - unsigned LIS4; - unsigned LIS7; - unsigned sc[1]; - - const struct pipe_rasterizer_state *templ; - - union { float f; unsigned u; } ds[2]; -}; - -struct i915_sampler_state { - unsigned state[3]; - const struct pipe_sampler_state *templ; -}; - - -struct i915_texture { - struct pipe_texture base; - - /* Derived from the above: - */ - unsigned pitch; - unsigned depth_pitch; /* per-image on i945? */ - unsigned total_height; - - unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; - - /* Explicitly store the offset of each image for each cube face or - * depth value. Pretty much have to accept that hardware formats - * are going to be so diverse that there is no unified way to - * compute the offsets of depth/cube images within a mipmap level, - * so have to store them as a lookup table: - */ - unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */ - - /* Includes image offset tables: - */ - unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS]; - - /* The data is held here: - */ - struct pipe_buffer *buffer; -}; - -struct i915_context -{ - struct pipe_context pipe; - struct i915_winsys *winsys; - struct draw_context *draw; - - /* The most recent drawing state as set by the driver: - */ - 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; - - struct i915_fragment_shader *fs; - - struct pipe_blend_color blend_color; - struct pipe_clip_state clip; - struct pipe_constant_buffer constants[PIPE_SHADER_TYPES]; - struct pipe_framebuffer_state framebuffer; - struct pipe_poly_stipple poly_stipple; - struct pipe_scissor_state scissor; - struct i915_texture *texture[PIPE_MAX_SAMPLERS]; - struct pipe_viewport_state viewport; - struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; - - unsigned dirty; - - unsigned *batch_start; - - /** Vertex buffer */ - struct pipe_buffer *vbo; - - struct i915_state current; - unsigned hardware_dirty; - - unsigned debug; -}; - -/* A flag for each state_tracker state object: - */ -#define I915_NEW_VIEWPORT 0x1 -#define I915_NEW_RASTERIZER 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_STENCIL 0x200 -#define I915_NEW_SAMPLER 0x400 -#define I915_NEW_TEXTURE 0x800 -#define I915_NEW_CONSTANTS 0x1000 -#define I915_NEW_VBO 0x2000 -#define I915_NEW_VS 0x4000 - - -/* Driver's internally generated state flags: - */ -#define I915_NEW_VERTEX_FORMAT 0x10000 - - -/* Dirty flags for hardware emit - */ -#define I915_HW_STATIC (1<set_constant_buffer()) + * Else, the bitmask indicates which components are occupied by immediates. + */ + ubyte constant_flags[I915_MAX_CONSTANT]; +}; + + +struct i915_cache_context; + +/* Use to calculate differences between state emitted to hardware and + * current driver-calculated state. + */ +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]; + + /* texture sampler state */ + unsigned sampler[I915_TEX_UNITS][3]; + unsigned sampler_enable_flags; + unsigned sampler_enable_nr; + + /* texture image buffers */ + unsigned texbuffer[I915_TEX_UNITS][2]; + + /** Describes the current hardware vertex layout */ + struct vertex_info vertex_info; + + unsigned id; /* track lost context events */ +}; + +struct i915_blend_state { + unsigned iab; + unsigned modes4; + unsigned LIS5; + unsigned LIS6; +}; + +struct i915_depth_stencil_state { + unsigned stencil_modes4; + unsigned bfo[2]; + unsigned stencil_LIS5; + unsigned depth_LIS6; +}; + +struct i915_rasterizer_state { + int light_twoside : 1; + unsigned st; + enum interp_mode color_interp; + + unsigned LIS4; + unsigned LIS7; + unsigned sc[1]; + + const struct pipe_rasterizer_state *templ; + + union { float f; unsigned u; } ds[2]; +}; + +struct i915_sampler_state { + unsigned state[3]; + const struct pipe_sampler_state *templ; +}; + + +struct i915_texture { + struct pipe_texture base; + + /* Derived from the above: + */ + unsigned pitch; + unsigned depth_pitch; /* per-image on i945? */ + unsigned total_height; + + unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; + + /* Explicitly store the offset of each image for each cube face or + * depth value. Pretty much have to accept that hardware formats + * are going to be so diverse that there is no unified way to + * compute the offsets of depth/cube images within a mipmap level, + * so have to store them as a lookup table: + */ + unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */ + + /* Includes image offset tables: + */ + unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS]; + + /* The data is held here: + */ + struct pipe_buffer *buffer; +}; + +struct i915_context +{ + struct pipe_context pipe; + struct i915_winsys *winsys; + struct draw_context *draw; + + /* The most recent drawing state as set by the driver: + */ + 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; + + struct i915_fragment_shader *fs; + + struct pipe_blend_color blend_color; + struct pipe_clip_state clip; + struct pipe_constant_buffer constants[PIPE_SHADER_TYPES]; + struct pipe_framebuffer_state framebuffer; + struct pipe_poly_stipple poly_stipple; + struct pipe_scissor_state scissor; + struct i915_texture *texture[PIPE_MAX_SAMPLERS]; + struct pipe_viewport_state viewport; + struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; + + unsigned dirty; + + unsigned num_samplers; + unsigned num_textures; + + unsigned *batch_start; + + /** Vertex buffer */ + struct pipe_buffer *vbo; + + struct i915_state current; + unsigned hardware_dirty; + + unsigned debug; +}; + +/* A flag for each state_tracker state object: + */ +#define I915_NEW_VIEWPORT 0x1 +#define I915_NEW_RASTERIZER 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_STENCIL 0x200 +#define I915_NEW_SAMPLER 0x400 +#define I915_NEW_TEXTURE 0x800 +#define I915_NEW_CONSTANTS 0x1000 +#define I915_NEW_VBO 0x2000 +#define I915_NEW_VS 0x4000 + + +/* Driver's internally generated state flags: + */ +#define I915_NEW_VERTEX_FORMAT 0x10000 + + +/* Dirty flags for hardware emit + */ +#define I915_HW_STATIC (1<sampler[unit] = (const struct i915_sampler_state*)sampler; + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == i915->num_samplers && + !memcmp(i915->sampler, sampler, num * sizeof(void *))) + return; + + memcpy(i915->sampler, sampler, num * sizeof(void *)); + memset(&i915->sampler[num], 0, (PIPE_MAX_SAMPLERS - num) * sizeof(void *)); + + i915->num_samplers = num; i915->dirty |= I915_NEW_SAMPLER; } @@ -526,14 +535,29 @@ static void i915_set_constant_buffer(struct pipe_context *pipe, } -static void i915_set_sampler_texture(struct pipe_context *pipe, - unsigned sampler, - struct pipe_texture *texture) +static void i915_set_sampler_textures(struct pipe_context *pipe, + unsigned num, + struct pipe_texture **texture) { struct i915_context *i915 = i915_context(pipe); + uint i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == i915->num_textures && + !memcmp(i915->texture, texture, num * sizeof(struct pipe_texture *))) + return; + + for (i = 0; i < num; i++) + pipe_texture_reference((struct pipe_texture **) &i915->texture[i], + texture[i]); + + for (i = num; i < i915->num_textures; i++) + pipe_texture_reference((struct pipe_texture **) &i915->texture[i], + NULL); - pipe_texture_reference((struct pipe_texture **) &i915->texture[sampler], - texture); + i915->num_textures = num; i915->dirty |= I915_NEW_TEXTURE; } @@ -691,7 +715,7 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.delete_blend_state = i915_delete_blend_state; i915->pipe.create_sampler_state = i915_create_sampler_state; - i915->pipe.bind_sampler_state = i915_bind_sampler_state; + i915->pipe.bind_sampler_states = i915_bind_sampler_states; i915->pipe.delete_sampler_state = i915_delete_sampler_state; i915->pipe.create_depth_stencil_alpha_state = i915_create_depth_stencil_state; @@ -715,7 +739,7 @@ i915_init_state_functions( struct i915_context *i915 ) i915->pipe.set_polygon_stipple = i915_set_polygon_stipple; i915->pipe.set_scissor_state = i915_set_scissor_state; - i915->pipe.set_sampler_texture = i915_set_sampler_texture; + i915->pipe.set_sampler_textures = i915_set_sampler_textures; i915->pipe.set_viewport_state = i915_set_viewport_state; i915->pipe.set_vertex_buffer = i915_set_vertex_buffer; i915->pipe.set_vertex_element = i915_set_vertex_element; diff --git a/src/gallium/drivers/i915simple/i915_state_emit.c b/src/gallium/drivers/i915simple/i915_state_emit.c index 6bbaac4e34..a7498d22b7 100644 --- a/src/gallium/drivers/i915simple/i915_state_emit.c +++ b/src/gallium/drivers/i915simple/i915_state_emit.c @@ -267,12 +267,6 @@ i915_emit_hardware_state(struct i915_context *i915 ) /* 2 + I915_TEX_UNITS*3 dwords, I915_TEX_UNITS relocs */ if (i915->hardware_dirty & (I915_HW_MAP | I915_HW_SAMPLER)) { - /* XXX: we were refering to sampler state - * (current.sampler_enable_nr) below, but only checking - * I915_HW_MAP above. Should probably calculate the enabled - * flags separately - but there will be further rework of - * state so perhaps not necessary yet. - */ const uint nr = i915->current.sampler_enable_nr; if (nr) { const uint enabled = i915->current.sampler_enable_flags; diff --git a/src/gallium/drivers/i915simple/i915_state_sampler.c b/src/gallium/drivers/i915simple/i915_state_sampler.c index 9c1a5bbbd6..9dbb1b1b23 100644 --- a/src/gallium/drivers/i915simple/i915_state_sampler.c +++ b/src/gallium/drivers/i915simple/i915_state_sampler.c @@ -106,7 +106,8 @@ void i915_update_samplers( struct i915_context *i915 ) i915->current.sampler_enable_nr = 0; i915->current.sampler_enable_flags = 0x0; - for (unit = 0; unit < I915_TEX_UNITS; unit++) { + for (unit = 0; unit < i915->num_textures && unit < i915->num_samplers; + unit++) { /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ if (i915->texture[unit]) { @@ -219,7 +220,8 @@ i915_update_textures(struct i915_context *i915) { uint unit; - for (unit = 0; unit < I915_TEX_UNITS; unit++) { + for (unit = 0; unit < i915->num_textures && unit < i915->num_samplers; + unit++) { /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ if (i915->texture[unit]) { diff --git a/src/gallium/drivers/i965simple/brw_context.h b/src/gallium/drivers/i965simple/brw_context.h index 4da3a8cffc..b83a13c3b6 100644 --- a/src/gallium/drivers/i965simple/brw_context.h +++ b/src/gallium/drivers/i965simple/brw_context.h @@ -1,681 +1,684 @@ -/* - Copyright (C) Intel Corp. 2006. All Rights Reserved. - Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to - develop this 3D driver. - - 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, sublicense, 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 NONINFRINGEMENT. - IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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 - */ - - -#ifndef BRWCONTEXT_INC -#define BRWCONTEXT_INC - - -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_state.h" - -#include "tgsi/util/tgsi_scan.h" - -#include "brw_structs.h" -#include "brw_winsys.h" - - -/* Glossary: - * - * URB - uniform resource buffer. A mid-sized buffer which is - * partitioned between the fixed function units and used for passing - * values (vertices, primitives, constants) between them. - * - * CURBE - constant URB entry. An urb region (entry) used to hold - * constant values which the fixed function units can be instructed to - * preload into the GRF when spawining a thread. - * - * VUE - vertex URB entry. An urb entry holding a vertex and usually - * a vertex header. The header contains control information and - * things like primitive type, Begin/end flags and clip codes. - * - * PUE - primitive URB entry. An urb entry produced by the setup (SF) - * unit holding rasterization and interpolation parameters. - * - * GRF - general register file. One of several register files - * addressable by programmed threads. The inputs (r0, payload, curbe, - * urb) of the thread are preloaded to this area before the thread is - * spawned. The registers are individually 8 dwords wide and suitable - * for general usage. Registers holding thread input values are not - * special and may be overwritten. - * - * MRF - message register file. Threads communicate (and terminate) - * by sending messages. Message parameters are placed in contigous - * MRF registers. All program output is via these messages. URB - * entries are populated by sending a message to the shared URB - * function containing the new data, together with a control word, - * often an unmodified copy of R0. - * - * R0 - GRF register 0. Typically holds control information used when - * sending messages to other threads. - * - * EU or GEN4 EU: The name of the programmable subsystem of the - * i965 hardware. Threads are executed by the EU, the registers - * described above are part of the EU architecture. - * - * Fixed function units: - * - * CS - Command streamer. Notional first unit, little software - * interaction. Holds the URB entries used for constant data, ie the - * CURBEs. - * - * VF/VS - Vertex Fetch / Vertex Shader. The fixed function part of - * this unit is responsible for pulling vertices out of vertex buffers - * in vram and injecting them into the processing pipe as VUEs. If - * enabled, it first passes them to a VS thread which is a good place - * for the driver to implement any active vertex shader. - * - * GS - Geometry Shader. This corresponds to a new DX10 concept. If - * enabled, incoming strips etc are passed to GS threads in individual - * line/triangle/point units. The GS thread may perform arbitary - * computation and emit whatever primtives with whatever vertices it - * chooses. This makes GS an excellent place to implement GL's - * unfilled polygon modes, though of course it is capable of much - * more. Additionally, GS is used to translate away primitives not - * handled by latter units, including Quads and Lineloops. - * - * CS - Clipper. Mesa's clipping algorithms are imported to run on - * this unit. The fixed function part performs cliptesting against - * the 6 fixed clipplanes and makes descisions on whether or not the - * incoming primitive needs to be passed to a thread for clipping. - * User clip planes are handled via cooperation with the VS thread. - * - * SF - Strips Fans or Setup: Triangles are prepared for - * rasterization. Interpolation coefficients are calculated. - * Flatshading and two-side lighting usually performed here. - * - * WM - Windower. Interpolation of vertex attributes performed here. - * Fragment shader implemented here. SIMD aspects of EU taken full - * advantage of, as pixels are processed in blocks of 16. - * - * CC - Color Calculator. No EU threads associated with this unit. - * Handles blending and (presumably) depth and stencil testing. - */ - -#define BRW_MAX_CURBE (32*16) - -struct brw_context; -struct brw_winsys; - - -/* Raised when we receive new state across the pipe interface: - */ -#define BRW_NEW_VIEWPORT 0x1 -#define BRW_NEW_RASTERIZER 0x2 -#define BRW_NEW_FS 0x4 -#define BRW_NEW_BLEND 0x8 -#define BRW_NEW_CLIP 0x10 -#define BRW_NEW_SCISSOR 0x20 -#define BRW_NEW_STIPPLE 0x40 -#define BRW_NEW_FRAMEBUFFER 0x80 -#define BRW_NEW_ALPHA_TEST 0x100 -#define BRW_NEW_DEPTH_STENCIL 0x200 -#define BRW_NEW_SAMPLER 0x400 -#define BRW_NEW_TEXTURE 0x800 -#define BRW_NEW_CONSTANTS 0x1000 -#define BRW_NEW_VBO 0x2000 -#define BRW_NEW_VS 0x4000 - -/* Raised for other internal events: - */ -#define BRW_NEW_URB_FENCE 0x10000 -#define BRW_NEW_PSP 0x20000 -#define BRW_NEW_CURBE_OFFSETS 0x40000 -#define BRW_NEW_REDUCED_PRIMITIVE 0x80000 -#define BRW_NEW_PRIMITIVE 0x100000 -#define BRW_NEW_SCENE 0x200000 -#define BRW_NEW_SF_LINKAGE 0x400000 - -extern int BRW_DEBUG; - -#define DEBUG_TEXTURE 0x1 -#define DEBUG_STATE 0x2 -#define DEBUG_IOCTL 0x4 -#define DEBUG_PRIMS 0x8 -#define DEBUG_VERTS 0x10 -#define DEBUG_FALLBACKS 0x20 -#define DEBUG_VERBOSE 0x40 -#define DEBUG_DRI 0x80 -#define DEBUG_DMA 0x100 -#define DEBUG_SANITY 0x200 -#define DEBUG_SYNC 0x400 -#define DEBUG_SLEEP 0x800 -#define DEBUG_PIXEL 0x1000 -#define DEBUG_STATS 0x2000 -#define DEBUG_TILE 0x4000 -#define DEBUG_SINGLE_THREAD 0x8000 -#define DEBUG_WM 0x10000 -#define DEBUG_URB 0x20000 -#define DEBUG_VS 0x40000 -#define DEBUG_BATCH 0x80000 -#define DEBUG_BUFMGR 0x100000 -#define DEBUG_BLIT 0x200000 -#define DEBUG_REGION 0x400000 -#define DEBUG_MIPTREE 0x800000 - -#define DBG(...) do { \ - if (BRW_DEBUG & FILE_DEBUG_FLAG) \ - brw->pipe.winsys->printf(brw->pipe.winsys, __VA_ARGS__); \ -} while(0) - -#define PRINT(...) do { \ - brw->pipe.winsys->printf(brw->pipe.winsys, __VA_ARGS__); \ -} while(0) - -struct brw_state_flags { - unsigned cache; - unsigned brw; -}; - - -struct brw_vertex_program { - struct pipe_shader_state program; - struct tgsi_shader_info info; - int id; -}; - - -struct brw_fragment_program { - struct pipe_shader_state program; - struct tgsi_shader_info info; - - boolean UsesDepth; /* XXX add this to tgsi_shader_info? */ - int id; -}; - - -struct pipe_setup_linkage { - struct { - unsigned vp_output:5; - unsigned interp_mode:4; - unsigned bf_vp_output:5; - } fp_input[PIPE_MAX_SHADER_INPUTS]; - - unsigned fp_input_count:5; - unsigned max_vp_output:5; -}; - - - -struct brw_texture { - struct pipe_texture base; - - /* Derived from the above: - */ - unsigned pitch; - unsigned depth_pitch; /* per-image on i945? */ - unsigned total_height; - - unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; - - /* Explicitly store the offset of each image for each cube face or - * depth value. Pretty much have to accept that hardware formats - * are going to be so diverse that there is no unified way to - * compute the offsets of depth/cube images within a mipmap level, - * so have to store them as a lookup table: - */ - unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */ - - /* Includes image offset tables: - */ - unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS]; - - /* The data is held here: - */ - struct pipe_buffer *buffer; -}; - -/* Data about a particular attempt to compile a program. Note that - * there can be many of these, each in a different GL state - * corresponding to a different brw_wm_prog_key struct, with different - * compiled programs: - */ -/* Data about a particular attempt to compile a program. Note that - * there can be many of these, each in a different GL state - * corresponding to a different brw_wm_prog_key struct, with different - * compiled programs: - */ - -struct brw_wm_prog_data { - unsigned curb_read_length; - unsigned urb_read_length; - - unsigned first_curbe_grf; - unsigned total_grf; - unsigned total_scratch; - - /* Internally generated constants for the CURBE. These are loaded - * ahead of the data from the constant buffer. - */ - const float internal_const[8]; - unsigned nr_internal_consts; - unsigned max_const; - - boolean error; -}; - -struct brw_sf_prog_data { - unsigned urb_read_length; - unsigned total_grf; - - /* Each vertex may have upto 12 attributes, 4 components each, - * except WPOS which requires only 2. (11*4 + 2) == 44 ==> 11 - * rows. - * - * Actually we use 4 for each, so call it 12 rows. - */ - unsigned urb_entry_size; -}; - -struct brw_clip_prog_data { - unsigned curb_read_length; /* user planes? */ - unsigned clip_mode; - unsigned urb_read_length; - unsigned total_grf; -}; - -struct brw_gs_prog_data { - unsigned urb_read_length; - unsigned total_grf; -}; - -struct brw_vs_prog_data { - unsigned curb_read_length; - unsigned urb_read_length; - unsigned total_grf; - unsigned outputs_written; - - unsigned inputs_read; - - unsigned max_const; - - float imm_buf[PIPE_MAX_CONSTANT][4]; - unsigned num_imm; - unsigned num_consts; - - /* Used for calculating urb partitions: - */ - unsigned urb_entry_size; -}; - - -#define BRW_MAX_TEX_UNIT 8 -#define BRW_WM_MAX_SURF BRW_MAX_TEX_UNIT + 1 - -/* Create a fixed sized struct for caching binding tables: - */ -struct brw_surface_binding_table { - unsigned surf_ss_offset[BRW_WM_MAX_SURF]; -}; - - -struct brw_cache; - -struct brw_mem_pool { - struct pipe_buffer *buffer; - - unsigned size; - unsigned offset; /* offset of first free byte */ - - struct brw_context *brw; -}; - -struct brw_cache_item { - unsigned hash; - unsigned key_size; /* for variable-sized keys */ - const void *key; - - unsigned offset; /* offset within pool's buffer */ - unsigned data_size; - - struct brw_cache_item *next; -}; - - - -struct brw_cache { - unsigned id; - - const char *name; - - struct brw_context *brw; - struct brw_mem_pool *pool; - - struct brw_cache_item **items; - unsigned size, n_items; - - unsigned key_size; /* for fixed-size keys */ - unsigned aux_size; - - unsigned last_addr; /* offset of active item */ -}; - - - - -/* Considered adding a member to this struct to document which flags - * an update might raise so that ordering of the state atoms can be - * checked or derived at runtime. Dropped the idea in favor of having - * a debug mode where the state is monitored for flags which are - * raised that have already been tested against. - */ -struct brw_tracked_state { - struct brw_state_flags dirty; - void (*update)( struct brw_context *brw ); -}; - - -/* Flags for brw->state.cache. - */ -#define CACHE_NEW_CC_VP (1< 32. Wouldn't life - * be easier if C allowed arrays of packed elements? - */ -#define ATTRIB_BIT_DWORDS ((PIPE_ATTRIB_MAX+31)/32) - - - - -struct brw_vertex_info { - unsigned varying; /* varying:1[PIPE_ATTRIB_MAX] */ - unsigned sizes[ATTRIB_BIT_DWORDS * 2]; /* sizes:2[PIPE_ATTRIB_MAX] */ -}; - - - - - -struct brw_context -{ - struct pipe_context pipe; - struct brw_winsys *winsys; - - unsigned primitive; - unsigned reduced_primitive; - - boolean emit_state_always; - - struct { - struct brw_state_flags dirty; - } state; - - - struct { - const struct pipe_blend_state *Blend; - 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]; - const struct brw_vertex_program *VertexProgram; - const struct brw_fragment_program *FragmentProgram; - - struct pipe_clip_state Clip; - struct pipe_blend_color BlendColor; - struct pipe_scissor_state Scissor; - struct pipe_viewport_state Viewport; - struct pipe_framebuffer_state FrameBuffer; - - const struct pipe_constant_buffer *Constants[2]; - const struct brw_texture *Texture[PIPE_MAX_SAMPLERS]; - } attribs; - - struct brw_mem_pool pool[BRW_MAX_POOL]; - struct brw_cache cache[BRW_MAX_CACHE]; - struct brw_cached_batch_item *cached_batch_items; - - struct { - - /* Arrays with buffer objects to copy non-bufferobj arrays into - * for upload: - */ - const struct pipe_vertex_buffer *vbo_array[PIPE_ATTRIB_MAX]; - - struct brw_vertex_element_state inputs[PIPE_ATTRIB_MAX]; - -#define BRW_NR_UPLOAD_BUFS 17 -#define BRW_UPLOAD_INIT_SIZE (128*1024) - - /* Summary of size and varying of active arrays, so we can check - * for changes to this state: - */ - struct brw_vertex_info info; - } vb; - - - unsigned hardware_dirty; - unsigned dirty; - unsigned pci_id; - /* BRW_NEW_URB_ALLOCATIONS: - */ - struct { - unsigned vsize; /* vertex size plus header in urb registers */ - unsigned csize; /* constant buffer size in urb registers */ - unsigned sfsize; /* setup data size in urb registers */ - - boolean constrained; - - unsigned nr_vs_entries; - unsigned nr_gs_entries; - unsigned nr_clip_entries; - unsigned nr_sf_entries; - unsigned nr_cs_entries; - -/* unsigned vs_size; */ -/* unsigned gs_size; */ -/* unsigned clip_size; */ -/* unsigned sf_size; */ -/* unsigned cs_size; */ - - unsigned vs_start; - unsigned gs_start; - unsigned clip_start; - unsigned sf_start; - unsigned cs_start; - } urb; - - - /* BRW_NEW_CURBE_OFFSETS: - */ - struct { - unsigned wm_start; - unsigned wm_size; - unsigned clip_start; - unsigned clip_size; - unsigned vs_start; - unsigned vs_size; - unsigned total_size; - - unsigned gs_offset; - - float *last_buf; - unsigned last_bufsz; - } curbe; - - struct { - struct brw_vs_prog_data *prog_data; - - unsigned prog_gs_offset; - unsigned state_gs_offset; - } vs; - - struct { - struct brw_gs_prog_data *prog_data; - - boolean prog_active; - unsigned prog_gs_offset; - unsigned state_gs_offset; - } gs; - - struct { - struct brw_clip_prog_data *prog_data; - - unsigned prog_gs_offset; - unsigned vp_gs_offset; - unsigned state_gs_offset; - } clip; - - - struct { - struct brw_sf_prog_data *prog_data; - - struct pipe_setup_linkage linkage; - - unsigned prog_gs_offset; - unsigned vp_gs_offset; - unsigned state_gs_offset; - } sf; - - struct { - struct brw_wm_prog_data *prog_data; - -// struct brw_wm_compiler *compile_data; - - - /** - * Array of sampler state uploaded at sampler_gs_offset of BRW_SAMPLER - * cache - */ - struct brw_sampler_state sampler[BRW_MAX_TEX_UNIT]; - - unsigned render_surf; - unsigned nr_surfaces; - - unsigned max_threads; - struct pipe_buffer *scratch_buffer; - unsigned scratch_buffer_size; - - unsigned sampler_count; - unsigned sampler_gs_offset; - - struct brw_surface_binding_table bind; - unsigned bind_ss_offset; - - unsigned prog_gs_offset; - unsigned state_gs_offset; - } wm; - - - struct { - unsigned vp_gs_offset; - unsigned state_gs_offset; - } cc; - - - /* Used to give every program string a unique id - */ - unsigned program_id; -}; - - -#define BRW_PACKCOLOR8888(r,g,b,a) ((r<<24) | (g<<16) | (b<<8) | a) - - -/*====================================================================== - * brw_vtbl.c - */ -void brw_do_flush( struct brw_context *brw, - unsigned flags ); - - -/*====================================================================== - * brw_state.c - */ -void brw_validate_state(struct brw_context *brw); -void brw_init_state(struct brw_context *brw); -void brw_destroy_state(struct brw_context *brw); - - -/*====================================================================== - * brw_tex.c - */ -void brwUpdateTextureState( struct brw_context *brw ); - - -/* brw_urb.c - */ -void brw_upload_urb_fence(struct brw_context *brw); - -void brw_upload_constant_buffer_state(struct brw_context *brw); - -void brw_init_surface_functions(struct brw_context *brw); -void brw_init_state_functions(struct brw_context *brw); -void brw_init_flush_functions(struct brw_context *brw); -void brw_init_string_functions(struct brw_context *brw); - -/*====================================================================== - * Inline conversion functions. These are better-typed than the - * macros used previously: - */ -static inline struct brw_context * -brw_context( struct pipe_context *ctx ) -{ - return (struct brw_context *)ctx; -} - -#endif - +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + 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, sublicense, 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 NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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 + */ + + +#ifndef BRWCONTEXT_INC +#define BRWCONTEXT_INC + + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" + +#include "tgsi/util/tgsi_scan.h" + +#include "brw_structs.h" +#include "brw_winsys.h" + + +/* Glossary: + * + * URB - uniform resource buffer. A mid-sized buffer which is + * partitioned between the fixed function units and used for passing + * values (vertices, primitives, constants) between them. + * + * CURBE - constant URB entry. An urb region (entry) used to hold + * constant values which the fixed function units can be instructed to + * preload into the GRF when spawining a thread. + * + * VUE - vertex URB entry. An urb entry holding a vertex and usually + * a vertex header. The header contains control information and + * things like primitive type, Begin/end flags and clip codes. + * + * PUE - primitive URB entry. An urb entry produced by the setup (SF) + * unit holding rasterization and interpolation parameters. + * + * GRF - general register file. One of several register files + * addressable by programmed threads. The inputs (r0, payload, curbe, + * urb) of the thread are preloaded to this area before the thread is + * spawned. The registers are individually 8 dwords wide and suitable + * for general usage. Registers holding thread input values are not + * special and may be overwritten. + * + * MRF - message register file. Threads communicate (and terminate) + * by sending messages. Message parameters are placed in contigous + * MRF registers. All program output is via these messages. URB + * entries are populated by sending a message to the shared URB + * function containing the new data, together with a control word, + * often an unmodified copy of R0. + * + * R0 - GRF register 0. Typically holds control information used when + * sending messages to other threads. + * + * EU or GEN4 EU: The name of the programmable subsystem of the + * i965 hardware. Threads are executed by the EU, the registers + * described above are part of the EU architecture. + * + * Fixed function units: + * + * CS - Command streamer. Notional first unit, little software + * interaction. Holds the URB entries used for constant data, ie the + * CURBEs. + * + * VF/VS - Vertex Fetch / Vertex Shader. The fixed function part of + * this unit is responsible for pulling vertices out of vertex buffers + * in vram and injecting them into the processing pipe as VUEs. If + * enabled, it first passes them to a VS thread which is a good place + * for the driver to implement any active vertex shader. + * + * GS - Geometry Shader. This corresponds to a new DX10 concept. If + * enabled, incoming strips etc are passed to GS threads in individual + * line/triangle/point units. The GS thread may perform arbitary + * computation and emit whatever primtives with whatever vertices it + * chooses. This makes GS an excellent place to implement GL's + * unfilled polygon modes, though of course it is capable of much + * more. Additionally, GS is used to translate away primitives not + * handled by latter units, including Quads and Lineloops. + * + * CS - Clipper. Mesa's clipping algorithms are imported to run on + * this unit. The fixed function part performs cliptesting against + * the 6 fixed clipplanes and makes descisions on whether or not the + * incoming primitive needs to be passed to a thread for clipping. + * User clip planes are handled via cooperation with the VS thread. + * + * SF - Strips Fans or Setup: Triangles are prepared for + * rasterization. Interpolation coefficients are calculated. + * Flatshading and two-side lighting usually performed here. + * + * WM - Windower. Interpolation of vertex attributes performed here. + * Fragment shader implemented here. SIMD aspects of EU taken full + * advantage of, as pixels are processed in blocks of 16. + * + * CC - Color Calculator. No EU threads associated with this unit. + * Handles blending and (presumably) depth and stencil testing. + */ + +#define BRW_MAX_CURBE (32*16) + +struct brw_context; +struct brw_winsys; + + +/* Raised when we receive new state across the pipe interface: + */ +#define BRW_NEW_VIEWPORT 0x1 +#define BRW_NEW_RASTERIZER 0x2 +#define BRW_NEW_FS 0x4 +#define BRW_NEW_BLEND 0x8 +#define BRW_NEW_CLIP 0x10 +#define BRW_NEW_SCISSOR 0x20 +#define BRW_NEW_STIPPLE 0x40 +#define BRW_NEW_FRAMEBUFFER 0x80 +#define BRW_NEW_ALPHA_TEST 0x100 +#define BRW_NEW_DEPTH_STENCIL 0x200 +#define BRW_NEW_SAMPLER 0x400 +#define BRW_NEW_TEXTURE 0x800 +#define BRW_NEW_CONSTANTS 0x1000 +#define BRW_NEW_VBO 0x2000 +#define BRW_NEW_VS 0x4000 + +/* Raised for other internal events: + */ +#define BRW_NEW_URB_FENCE 0x10000 +#define BRW_NEW_PSP 0x20000 +#define BRW_NEW_CURBE_OFFSETS 0x40000 +#define BRW_NEW_REDUCED_PRIMITIVE 0x80000 +#define BRW_NEW_PRIMITIVE 0x100000 +#define BRW_NEW_SCENE 0x200000 +#define BRW_NEW_SF_LINKAGE 0x400000 + +extern int BRW_DEBUG; + +#define DEBUG_TEXTURE 0x1 +#define DEBUG_STATE 0x2 +#define DEBUG_IOCTL 0x4 +#define DEBUG_PRIMS 0x8 +#define DEBUG_VERTS 0x10 +#define DEBUG_FALLBACKS 0x20 +#define DEBUG_VERBOSE 0x40 +#define DEBUG_DRI 0x80 +#define DEBUG_DMA 0x100 +#define DEBUG_SANITY 0x200 +#define DEBUG_SYNC 0x400 +#define DEBUG_SLEEP 0x800 +#define DEBUG_PIXEL 0x1000 +#define DEBUG_STATS 0x2000 +#define DEBUG_TILE 0x4000 +#define DEBUG_SINGLE_THREAD 0x8000 +#define DEBUG_WM 0x10000 +#define DEBUG_URB 0x20000 +#define DEBUG_VS 0x40000 +#define DEBUG_BATCH 0x80000 +#define DEBUG_BUFMGR 0x100000 +#define DEBUG_BLIT 0x200000 +#define DEBUG_REGION 0x400000 +#define DEBUG_MIPTREE 0x800000 + +#define DBG(...) do { \ + if (BRW_DEBUG & FILE_DEBUG_FLAG) \ + brw->pipe.winsys->printf(brw->pipe.winsys, __VA_ARGS__); \ +} while(0) + +#define PRINT(...) do { \ + brw->pipe.winsys->printf(brw->pipe.winsys, __VA_ARGS__); \ +} while(0) + +struct brw_state_flags { + unsigned cache; + unsigned brw; +}; + + +struct brw_vertex_program { + struct pipe_shader_state program; + struct tgsi_shader_info info; + int id; +}; + + +struct brw_fragment_program { + struct pipe_shader_state program; + struct tgsi_shader_info info; + + boolean UsesDepth; /* XXX add this to tgsi_shader_info? */ + int id; +}; + + +struct pipe_setup_linkage { + struct { + unsigned vp_output:5; + unsigned interp_mode:4; + unsigned bf_vp_output:5; + } fp_input[PIPE_MAX_SHADER_INPUTS]; + + unsigned fp_input_count:5; + unsigned max_vp_output:5; +}; + + + +struct brw_texture { + struct pipe_texture base; + + /* Derived from the above: + */ + unsigned pitch; + unsigned depth_pitch; /* per-image on i945? */ + unsigned total_height; + + unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; + + /* Explicitly store the offset of each image for each cube face or + * depth value. Pretty much have to accept that hardware formats + * are going to be so diverse that there is no unified way to + * compute the offsets of depth/cube images within a mipmap level, + * so have to store them as a lookup table: + */ + unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */ + + /* Includes image offset tables: + */ + unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS]; + + /* The data is held here: + */ + struct pipe_buffer *buffer; +}; + +/* Data about a particular attempt to compile a program. Note that + * there can be many of these, each in a different GL state + * corresponding to a different brw_wm_prog_key struct, with different + * compiled programs: + */ +/* Data about a particular attempt to compile a program. Note that + * there can be many of these, each in a different GL state + * corresponding to a different brw_wm_prog_key struct, with different + * compiled programs: + */ + +struct brw_wm_prog_data { + unsigned curb_read_length; + unsigned urb_read_length; + + unsigned first_curbe_grf; + unsigned total_grf; + unsigned total_scratch; + + /* Internally generated constants for the CURBE. These are loaded + * ahead of the data from the constant buffer. + */ + const float internal_const[8]; + unsigned nr_internal_consts; + unsigned max_const; + + boolean error; +}; + +struct brw_sf_prog_data { + unsigned urb_read_length; + unsigned total_grf; + + /* Each vertex may have upto 12 attributes, 4 components each, + * except WPOS which requires only 2. (11*4 + 2) == 44 ==> 11 + * rows. + * + * Actually we use 4 for each, so call it 12 rows. + */ + unsigned urb_entry_size; +}; + +struct brw_clip_prog_data { + unsigned curb_read_length; /* user planes? */ + unsigned clip_mode; + unsigned urb_read_length; + unsigned total_grf; +}; + +struct brw_gs_prog_data { + unsigned urb_read_length; + unsigned total_grf; +}; + +struct brw_vs_prog_data { + unsigned curb_read_length; + unsigned urb_read_length; + unsigned total_grf; + unsigned outputs_written; + + unsigned inputs_read; + + unsigned max_const; + + float imm_buf[PIPE_MAX_CONSTANT][4]; + unsigned num_imm; + unsigned num_consts; + + /* Used for calculating urb partitions: + */ + unsigned urb_entry_size; +}; + + +#define BRW_MAX_TEX_UNIT 8 +#define BRW_WM_MAX_SURF BRW_MAX_TEX_UNIT + 1 + +/* Create a fixed sized struct for caching binding tables: + */ +struct brw_surface_binding_table { + unsigned surf_ss_offset[BRW_WM_MAX_SURF]; +}; + + +struct brw_cache; + +struct brw_mem_pool { + struct pipe_buffer *buffer; + + unsigned size; + unsigned offset; /* offset of first free byte */ + + struct brw_context *brw; +}; + +struct brw_cache_item { + unsigned hash; + unsigned key_size; /* for variable-sized keys */ + const void *key; + + unsigned offset; /* offset within pool's buffer */ + unsigned data_size; + + struct brw_cache_item *next; +}; + + + +struct brw_cache { + unsigned id; + + const char *name; + + struct brw_context *brw; + struct brw_mem_pool *pool; + + struct brw_cache_item **items; + unsigned size, n_items; + + unsigned key_size; /* for fixed-size keys */ + unsigned aux_size; + + unsigned last_addr; /* offset of active item */ +}; + + + + +/* Considered adding a member to this struct to document which flags + * an update might raise so that ordering of the state atoms can be + * checked or derived at runtime. Dropped the idea in favor of having + * a debug mode where the state is monitored for flags which are + * raised that have already been tested against. + */ +struct brw_tracked_state { + struct brw_state_flags dirty; + void (*update)( struct brw_context *brw ); +}; + + +/* Flags for brw->state.cache. + */ +#define CACHE_NEW_CC_VP (1< 32. Wouldn't life + * be easier if C allowed arrays of packed elements? + */ +#define ATTRIB_BIT_DWORDS ((PIPE_ATTRIB_MAX+31)/32) + + + + +struct brw_vertex_info { + unsigned varying; /* varying:1[PIPE_ATTRIB_MAX] */ + unsigned sizes[ATTRIB_BIT_DWORDS * 2]; /* sizes:2[PIPE_ATTRIB_MAX] */ +}; + + + + + +struct brw_context +{ + struct pipe_context pipe; + struct brw_winsys *winsys; + + unsigned primitive; + unsigned reduced_primitive; + + boolean emit_state_always; + + struct { + struct brw_state_flags dirty; + } state; + + + struct { + const struct pipe_blend_state *Blend; + 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]; + const struct brw_vertex_program *VertexProgram; + const struct brw_fragment_program *FragmentProgram; + + struct pipe_clip_state Clip; + struct pipe_blend_color BlendColor; + struct pipe_scissor_state Scissor; + struct pipe_viewport_state Viewport; + struct pipe_framebuffer_state FrameBuffer; + + const struct pipe_constant_buffer *Constants[2]; + const struct brw_texture *Texture[PIPE_MAX_SAMPLERS]; + } attribs; + + unsigned num_samplers; + unsigned num_textures; + + struct brw_mem_pool pool[BRW_MAX_POOL]; + struct brw_cache cache[BRW_MAX_CACHE]; + struct brw_cached_batch_item *cached_batch_items; + + struct { + + /* Arrays with buffer objects to copy non-bufferobj arrays into + * for upload: + */ + const struct pipe_vertex_buffer *vbo_array[PIPE_ATTRIB_MAX]; + + struct brw_vertex_element_state inputs[PIPE_ATTRIB_MAX]; + +#define BRW_NR_UPLOAD_BUFS 17 +#define BRW_UPLOAD_INIT_SIZE (128*1024) + + /* Summary of size and varying of active arrays, so we can check + * for changes to this state: + */ + struct brw_vertex_info info; + } vb; + + + unsigned hardware_dirty; + unsigned dirty; + unsigned pci_id; + /* BRW_NEW_URB_ALLOCATIONS: + */ + struct { + unsigned vsize; /* vertex size plus header in urb registers */ + unsigned csize; /* constant buffer size in urb registers */ + unsigned sfsize; /* setup data size in urb registers */ + + boolean constrained; + + unsigned nr_vs_entries; + unsigned nr_gs_entries; + unsigned nr_clip_entries; + unsigned nr_sf_entries; + unsigned nr_cs_entries; + +/* unsigned vs_size; */ +/* unsigned gs_size; */ +/* unsigned clip_size; */ +/* unsigned sf_size; */ +/* unsigned cs_size; */ + + unsigned vs_start; + unsigned gs_start; + unsigned clip_start; + unsigned sf_start; + unsigned cs_start; + } urb; + + + /* BRW_NEW_CURBE_OFFSETS: + */ + struct { + unsigned wm_start; + unsigned wm_size; + unsigned clip_start; + unsigned clip_size; + unsigned vs_start; + unsigned vs_size; + unsigned total_size; + + unsigned gs_offset; + + float *last_buf; + unsigned last_bufsz; + } curbe; + + struct { + struct brw_vs_prog_data *prog_data; + + unsigned prog_gs_offset; + unsigned state_gs_offset; + } vs; + + struct { + struct brw_gs_prog_data *prog_data; + + boolean prog_active; + unsigned prog_gs_offset; + unsigned state_gs_offset; + } gs; + + struct { + struct brw_clip_prog_data *prog_data; + + unsigned prog_gs_offset; + unsigned vp_gs_offset; + unsigned state_gs_offset; + } clip; + + + struct { + struct brw_sf_prog_data *prog_data; + + struct pipe_setup_linkage linkage; + + unsigned prog_gs_offset; + unsigned vp_gs_offset; + unsigned state_gs_offset; + } sf; + + struct { + struct brw_wm_prog_data *prog_data; + +// struct brw_wm_compiler *compile_data; + + + /** + * Array of sampler state uploaded at sampler_gs_offset of BRW_SAMPLER + * cache + */ + struct brw_sampler_state sampler[BRW_MAX_TEX_UNIT]; + + unsigned render_surf; + unsigned nr_surfaces; + + unsigned max_threads; + struct pipe_buffer *scratch_buffer; + unsigned scratch_buffer_size; + + unsigned sampler_count; + unsigned sampler_gs_offset; + + struct brw_surface_binding_table bind; + unsigned bind_ss_offset; + + unsigned prog_gs_offset; + unsigned state_gs_offset; + } wm; + + + struct { + unsigned vp_gs_offset; + unsigned state_gs_offset; + } cc; + + + /* Used to give every program string a unique id + */ + unsigned program_id; +}; + + +#define BRW_PACKCOLOR8888(r,g,b,a) ((r<<24) | (g<<16) | (b<<8) | a) + + +/*====================================================================== + * brw_vtbl.c + */ +void brw_do_flush( struct brw_context *brw, + unsigned flags ); + + +/*====================================================================== + * brw_state.c + */ +void brw_validate_state(struct brw_context *brw); +void brw_init_state(struct brw_context *brw); +void brw_destroy_state(struct brw_context *brw); + + +/*====================================================================== + * brw_tex.c + */ +void brwUpdateTextureState( struct brw_context *brw ); + + +/* brw_urb.c + */ +void brw_upload_urb_fence(struct brw_context *brw); + +void brw_upload_constant_buffer_state(struct brw_context *brw); + +void brw_init_surface_functions(struct brw_context *brw); +void brw_init_state_functions(struct brw_context *brw); +void brw_init_flush_functions(struct brw_context *brw); +void brw_init_string_functions(struct brw_context *brw); + +/*====================================================================== + * Inline conversion functions. These are better-typed than the + * macros used previously: + */ +static inline struct brw_context * +brw_context( struct pipe_context *ctx ) +{ + return (struct brw_context *)ctx; +} + +#endif + diff --git a/src/gallium/drivers/i965simple/brw_state.c b/src/gallium/drivers/i965simple/brw_state.c index 6744a8aa4f..f5efe9fc06 100644 --- a/src/gallium/drivers/i965simple/brw_state.c +++ b/src/gallium/drivers/i965simple/brw_state.c @@ -1,434 +1,462 @@ -/************************************************************************** - * - * 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 - * Keith Whitwell - */ - - -#include "pipe/p_winsys.h" -#include "pipe/p_util.h" -#include "pipe/p_inlines.h" -#include "pipe/p_shader_tokens.h" -#include "tgsi/util/tgsi_dump.h" - -#include "brw_context.h" -#include "brw_defines.h" -#include "brw_state.h" -#include "brw_draw.h" - - -#define DUP( TYPE, VAL ) \ -do { \ - struct TYPE *x = malloc(sizeof(*x)); \ - memcpy(x, VAL, sizeof(*x) ); \ - return x; \ -} while (0) - -/************************************************************************ - * Blend - */ -static void * -brw_create_blend_state(struct pipe_context *pipe, - const struct pipe_blend_state *blend) -{ - DUP( pipe_blend_state, blend ); -} - -static void brw_bind_blend_state(struct pipe_context *pipe, - void *blend) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.Blend = (struct pipe_blend_state*)blend; - brw->state.dirty.brw |= BRW_NEW_BLEND; -} - - -static void brw_delete_blend_state(struct pipe_context *pipe, void *blend) -{ - free(blend); -} - -static void brw_set_blend_color( struct pipe_context *pipe, - const struct pipe_blend_color *blend_color ) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.BlendColor = *blend_color; - - brw->state.dirty.brw |= BRW_NEW_BLEND; -} - -/************************************************************************ - * Sampler - */ - -static void * -brw_create_sampler_state(struct pipe_context *pipe, - const struct pipe_sampler_state *sampler) -{ - DUP( pipe_sampler_state, sampler ); -} - -static void brw_bind_sampler_state(struct pipe_context *pipe, - unsigned unit, void *sampler) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.Samplers[unit] = sampler; - brw->state.dirty.brw |= BRW_NEW_SAMPLER; -} - -static void brw_delete_sampler_state(struct pipe_context *pipe, - void *sampler) -{ - free(sampler); -} - - -/************************************************************************ - * Depth stencil - */ - -static void * -brw_create_depth_stencil_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_alpha_state *depth_stencil) -{ - DUP( pipe_depth_stencil_alpha_state, depth_stencil ); -} - -static void brw_bind_depth_stencil_state(struct pipe_context *pipe, - void *depth_stencil) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.DepthStencil = (const struct pipe_depth_stencil_alpha_state *)depth_stencil; - - brw->state.dirty.brw |= BRW_NEW_DEPTH_STENCIL; -} - -static void brw_delete_depth_stencil_state(struct pipe_context *pipe, - void *depth_stencil) -{ - free(depth_stencil); -} - -/************************************************************************ - * Scissor - */ -static void brw_set_scissor_state( struct pipe_context *pipe, - const struct pipe_scissor_state *scissor ) -{ - struct brw_context *brw = brw_context(pipe); - - memcpy( &brw->attribs.Scissor, scissor, sizeof(*scissor) ); - brw->state.dirty.brw |= BRW_NEW_SCISSOR; -} - - -/************************************************************************ - * Stipple - */ - -static void brw_set_polygon_stipple( struct pipe_context *pipe, - const struct pipe_poly_stipple *stipple ) -{ -} - - -/************************************************************************ - * Fragment shader - */ - -static void * brw_create_fs_state(struct pipe_context *pipe, - const struct pipe_shader_state *shader) -{ - struct brw_fragment_program *brw_fp = CALLOC_STRUCT(brw_fragment_program); - - /* XXX: Do I have to duplicate the tokens as well?? - */ - brw_fp->program = *shader; - brw_fp->id = brw_context(pipe)->program_id++; - - tgsi_scan_shader(shader->tokens, &brw_fp->info); - -#if 0 - brw_shader_info(shader->tokens, - &brw_fp->info2); -#endif - - tgsi_dump(shader->tokens, 0); - - - return (void *)brw_fp; -} - -static void brw_bind_fs_state(struct pipe_context *pipe, void *shader) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.FragmentProgram = (struct brw_fragment_program *)shader; - brw->state.dirty.brw |= BRW_NEW_FS; -} - -static void brw_delete_fs_state(struct pipe_context *pipe, void *shader) -{ - FREE(shader); -} - - -/************************************************************************ - * Vertex shader and other TNL state - */ - -static void *brw_create_vs_state(struct pipe_context *pipe, - const struct pipe_shader_state *shader) -{ - struct brw_vertex_program *brw_vp = CALLOC_STRUCT(brw_vertex_program); - - /* XXX: Do I have to duplicate the tokens as well?? - */ - brw_vp->program = *shader; - brw_vp->id = brw_context(pipe)->program_id++; - - tgsi_scan_shader(shader->tokens, &brw_vp->info); - -#if 0 - brw_shader_info(shader->tokens, - &brw_vp->info2); -#endif - tgsi_dump(shader->tokens, 0); - - return (void *)brw_vp; -} - -static void brw_bind_vs_state(struct pipe_context *pipe, void *vs) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.VertexProgram = (struct brw_vertex_program *)vs; - brw->state.dirty.brw |= BRW_NEW_VS; - - debug_printf("YYYYYYYYYYYYY BINDING VERTEX SHADER\n"); -} - -static void brw_delete_vs_state(struct pipe_context *pipe, void *shader) -{ - FREE(shader); -} - - -static void brw_set_clip_state( struct pipe_context *pipe, - const struct pipe_clip_state *clip ) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.Clip = *clip; -} - - -static void brw_set_viewport_state( struct pipe_context *pipe, - const struct pipe_viewport_state *viewport ) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.Viewport = *viewport; /* struct copy */ - brw->state.dirty.brw |= BRW_NEW_VIEWPORT; - - /* pass the viewport info to the draw module */ - //draw_set_viewport_state(brw->draw, viewport); -} - - -static void brw_set_vertex_buffer( struct pipe_context *pipe, - unsigned index, - const struct pipe_vertex_buffer *buffer ) -{ - struct brw_context *brw = brw_context(pipe); - brw->vb.vbo_array[index] = buffer; -} - -static void brw_set_vertex_element(struct pipe_context *pipe, - unsigned index, - const struct pipe_vertex_element *element) -{ - /* flush ? */ - struct brw_context *brw = brw_context(pipe); - - assert(index < PIPE_ATTRIB_MAX); - struct brw_vertex_element_state el; - memset(&el, 0, sizeof(el)); - - el.ve0.src_offset = element->src_offset; - el.ve0.src_format = brw_translate_surface_format(element->src_format); - el.ve0.valid = 1; - el.ve0.vertex_buffer_index = element->vertex_buffer_index; - - el.ve1.dst_offset = index * 4; - - el.ve1.vfcomponent3 = BRW_VFCOMPONENT_STORE_SRC; - el.ve1.vfcomponent2 = BRW_VFCOMPONENT_STORE_SRC; - el.ve1.vfcomponent1 = BRW_VFCOMPONENT_STORE_SRC; - el.ve1.vfcomponent0 = BRW_VFCOMPONENT_STORE_SRC; - - switch (element->nr_components) { - case 1: el.ve1.vfcomponent1 = BRW_VFCOMPONENT_STORE_0; - case 2: el.ve1.vfcomponent2 = BRW_VFCOMPONENT_STORE_0; - case 3: el.ve1.vfcomponent3 = BRW_VFCOMPONENT_STORE_1_FLT; - break; - } - - brw->vb.inputs[index] = el; -} - - - -/************************************************************************ - * Constant buffers - */ - -static void brw_set_constant_buffer(struct pipe_context *pipe, - uint shader, uint index, - const struct pipe_constant_buffer *buf) -{ - struct brw_context *brw = brw_context(pipe); - - assert(buf == 0 || index == 0); - - brw->attribs.Constants[shader] = buf; - brw->state.dirty.brw |= BRW_NEW_CONSTANTS; -} - - -/************************************************************************ - * Texture surfaces - */ - - -static void brw_set_sampler_texture(struct pipe_context *pipe, - unsigned unit, - struct pipe_texture *texture) -{ - struct brw_context *brw = brw_context(pipe); - - pipe_texture_reference((struct pipe_texture **) &brw->attribs.Texture[unit], - texture); - - brw->state.dirty.brw |= BRW_NEW_TEXTURE; -} - - -/************************************************************************ - * Render targets, etc - */ - -static void brw_set_framebuffer_state(struct pipe_context *pipe, - const struct pipe_framebuffer_state *fb) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.FrameBuffer = *fb; /* struct copy */ - - brw->state.dirty.brw |= BRW_NEW_FRAMEBUFFER; -} - - - -/************************************************************************ - * Rasterizer state - */ - -static void * -brw_create_rasterizer_state(struct pipe_context *pipe, - const struct pipe_rasterizer_state *rasterizer) -{ - DUP(pipe_rasterizer_state, rasterizer); -} - -static void brw_bind_rasterizer_state( struct pipe_context *pipe, - void *setup ) -{ - struct brw_context *brw = brw_context(pipe); - - brw->attribs.Raster = (struct pipe_rasterizer_state *)setup; - - /* Also pass-through to draw module: - */ - //draw_set_rasterizer_state(brw->draw, setup); - - brw->state.dirty.brw |= BRW_NEW_RASTERIZER; -} - -static void brw_delete_rasterizer_state(struct pipe_context *pipe, - void *setup) -{ - free(setup); -} - - - -void -brw_init_state_functions( struct brw_context *brw ) -{ - 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; - - brw->pipe.create_sampler_state = brw_create_sampler_state; - brw->pipe.bind_sampler_state = brw_bind_sampler_state; - brw->pipe.delete_sampler_state = brw_delete_sampler_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; - brw->pipe.delete_rasterizer_state = brw_delete_rasterizer_state; - brw->pipe.create_fs_state = brw_create_fs_state; - brw->pipe.bind_fs_state = brw_bind_fs_state; - brw->pipe.delete_fs_state = brw_delete_fs_state; - brw->pipe.create_vs_state = brw_create_vs_state; - brw->pipe.bind_vs_state = brw_bind_vs_state; - brw->pipe.delete_vs_state = brw_delete_vs_state; - - brw->pipe.set_blend_color = brw_set_blend_color; - brw->pipe.set_clip_state = brw_set_clip_state; - brw->pipe.set_constant_buffer = brw_set_constant_buffer; - brw->pipe.set_framebuffer_state = brw_set_framebuffer_state; - -// brw->pipe.set_feedback_state = brw_set_feedback_state; -// brw->pipe.set_feedback_buffer = brw_set_feedback_buffer; - - brw->pipe.set_polygon_stipple = brw_set_polygon_stipple; - brw->pipe.set_scissor_state = brw_set_scissor_state; - brw->pipe.set_sampler_texture = brw_set_sampler_texture; - brw->pipe.set_viewport_state = brw_set_viewport_state; - brw->pipe.set_vertex_buffer = brw_set_vertex_buffer; - brw->pipe.set_vertex_element = brw_set_vertex_element; -} +/************************************************************************** + * + * 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 + * Keith Whitwell + */ + + +#include "pipe/p_winsys.h" +#include "pipe/p_util.h" +#include "pipe/p_inlines.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi/util/tgsi_dump.h" + +#include "brw_context.h" +#include "brw_defines.h" +#include "brw_state.h" +#include "brw_draw.h" + + +#define DUP( TYPE, VAL ) \ +do { \ + struct TYPE *x = malloc(sizeof(*x)); \ + memcpy(x, VAL, sizeof(*x) ); \ + return x; \ +} while (0) + +/************************************************************************ + * Blend + */ +static void * +brw_create_blend_state(struct pipe_context *pipe, + const struct pipe_blend_state *blend) +{ + DUP( pipe_blend_state, blend ); +} + +static void brw_bind_blend_state(struct pipe_context *pipe, + void *blend) +{ + struct brw_context *brw = brw_context(pipe); + + brw->attribs.Blend = (struct pipe_blend_state*)blend; + brw->state.dirty.brw |= BRW_NEW_BLEND; +} + + +static void brw_delete_blend_state(struct pipe_context *pipe, void *blend) +{ + free(blend); +} + +static void brw_set_blend_color( struct pipe_context *pipe, + const struct pipe_blend_color *blend_color ) +{ + struct brw_context *brw = brw_context(pipe); + + brw->attribs.BlendColor = *blend_color; + + brw->state.dirty.brw |= BRW_NEW_BLEND; +} + +/************************************************************************ + * Sampler + */ + +static void * +brw_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + DUP( pipe_sampler_state, sampler ); +} + +static void brw_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) +{ + struct brw_context *brw = brw_context(pipe); + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == brw->num_samplers && + !memcmp(brw->attribs.Samplers, sampler, num * sizeof(void *))) + return; + + memcpy(brw->attribs.Samplers, sampler, num * sizeof(void *)); + memset(&brw->attribs.Samplers[num], 0, (PIPE_MAX_SAMPLERS - num) * + sizeof(void *)); + + brw->num_samplers = num; + + brw->state.dirty.brw |= BRW_NEW_SAMPLER; +} + +static void brw_delete_sampler_state(struct pipe_context *pipe, + void *sampler) +{ + free(sampler); +} + + +/************************************************************************ + * Depth stencil + */ + +static void * +brw_create_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_alpha_state *depth_stencil) +{ + DUP( pipe_depth_stencil_alpha_state, depth_stencil ); +} + +static void brw_bind_depth_stencil_state(struct pipe_context *pipe, + void *depth_stencil) +{ + struct brw_context *brw = brw_context(pipe); + + brw->attribs.DepthStencil = (const struct pipe_depth_stencil_alpha_state *)depth_stencil; + + brw->state.dirty.brw |= BRW_NEW_DEPTH_STENCIL; +} + +static void brw_delete_depth_stencil_state(struct pipe_context *pipe, + void *depth_stencil) +{ + free(depth_stencil); +} + +/************************************************************************ + * Scissor + */ +static void brw_set_scissor_state( struct pipe_context *pipe, + const struct pipe_scissor_state *scissor ) +{ + struct brw_context *brw = brw_context(pipe); + + memcpy( &brw->attribs.Scissor, scissor, sizeof(*scissor) ); + brw->state.dirty.brw |= BRW_NEW_SCISSOR; +} + + +/************************************************************************ + * Stipple + */ + +static void brw_set_polygon_stipple( struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple ) +{ +} + + +/************************************************************************ + * Fragment shader + */ + +static void * brw_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *shader) +{ + struct brw_fragment_program *brw_fp = CALLOC_STRUCT(brw_fragment_program); + + /* XXX: Do I have to duplicate the tokens as well?? + */ + brw_fp->program = *shader; + brw_fp->id = brw_context(pipe)->program_id++; + + tgsi_scan_shader(shader->tokens, &brw_fp->info); + +#if 0 + brw_shader_info(shader->tokens, + &brw_fp->info2); +#endif + + tgsi_dump(shader->tokens, 0); + + + return (void *)brw_fp; +} + +static void brw_bind_fs_state(struct pipe_context *pipe, void *shader) +{ + struct brw_context *brw = brw_context(pipe); + + brw->attribs.FragmentProgram = (struct brw_fragment_program *)shader; + brw->state.dirty.brw |= BRW_NEW_FS; +} + +static void brw_delete_fs_state(struct pipe_context *pipe, void *shader) +{ + FREE(shader); +} + + +/************************************************************************ + * Vertex shader and other TNL state + */ + +static void *brw_create_vs_state(struct pipe_context *pipe, + const struct pipe_shader_state *shader) +{ + struct brw_vertex_program *brw_vp = CALLOC_STRUCT(brw_vertex_program); + + /* XXX: Do I have to duplicate the tokens as well?? + */ + brw_vp->program = *shader; + brw_vp->id = brw_context(pipe)->program_id++; + + tgsi_scan_shader(shader->tokens, &brw_vp->info); + +#if 0 + brw_shader_info(shader->tokens, + &brw_vp->info2); +#endif + tgsi_dump(shader->tokens, 0); + + return (void *)brw_vp; +} + +static void brw_bind_vs_state(struct pipe_context *pipe, void *vs) +{ + struct brw_context *brw = brw_context(pipe); + + brw->attribs.VertexProgram = (struct brw_vertex_program *)vs; + brw->state.dirty.brw |= BRW_NEW_VS; + + debug_printf("YYYYYYYYYYYYY BINDING VERTEX SHADER\n"); +} + +static void brw_delete_vs_state(struct pipe_context *pipe, void *shader) +{ + FREE(shader); +} + + +static void brw_set_clip_state( struct pipe_context *pipe, + const struct pipe_clip_state *clip ) +{ + struct brw_context *brw = brw_context(pipe); + + brw->attribs.Clip = *clip; +} + + +static void brw_set_viewport_state( struct pipe_context *pipe, + const struct pipe_viewport_state *viewport ) +{ + struct brw_context *brw = brw_context(pipe); + + brw->attribs.Viewport = *viewport; /* struct copy */ + brw->state.dirty.brw |= BRW_NEW_VIEWPORT; + + /* pass the viewport info to the draw module */ + //draw_set_viewport_state(brw->draw, viewport); +} + + +static void brw_set_vertex_buffer( struct pipe_context *pipe, + unsigned index, + const struct pipe_vertex_buffer *buffer ) +{ + struct brw_context *brw = brw_context(pipe); + brw->vb.vbo_array[index] = buffer; +} + +static void brw_set_vertex_element(struct pipe_context *pipe, + unsigned index, + const struct pipe_vertex_element *element) +{ + /* flush ? */ + struct brw_context *brw = brw_context(pipe); + + assert(index < PIPE_ATTRIB_MAX); + struct brw_vertex_element_state el; + memset(&el, 0, sizeof(el)); + + el.ve0.src_offset = element->src_offset; + el.ve0.src_format = brw_translate_surface_format(element->src_format); + el.ve0.valid = 1; + el.ve0.vertex_buffer_index = element->vertex_buffer_index; + + el.ve1.dst_offset = index * 4; + + el.ve1.vfcomponent3 = BRW_VFCOMPONENT_STORE_SRC; + el.ve1.vfcomponent2 = BRW_VFCOMPONENT_STORE_SRC; + el.ve1.vfcomponent1 = BRW_VFCOMPONENT_STORE_SRC; + el.ve1.vfcomponent0 = BRW_VFCOMPONENT_STORE_SRC; + + switch (element->nr_components) { + case 1: el.ve1.vfcomponent1 = BRW_VFCOMPONENT_STORE_0; + case 2: el.ve1.vfcomponent2 = BRW_VFCOMPONENT_STORE_0; + case 3: el.ve1.vfcomponent3 = BRW_VFCOMPONENT_STORE_1_FLT; + break; + } + + brw->vb.inputs[index] = el; +} + + + +/************************************************************************ + * Constant buffers + */ + +static void brw_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + const struct pipe_constant_buffer *buf) +{ + struct brw_context *brw = brw_context(pipe); + + assert(buf == 0 || index == 0); + + brw->attribs.Constants[shader] = buf; + brw->state.dirty.brw |= BRW_NEW_CONSTANTS; +} + + +/************************************************************************ + * Texture surfaces + */ + + +static void brw_set_sampler_textures(struct pipe_context *pipe, + unsigned num, + struct pipe_texture **texture) +{ + struct brw_context *brw = brw_context(pipe); + uint i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == brw->num_textures && + !memcmp(brw->attribs.Texture, texture, num * + sizeof(struct pipe_texture *))) + return; + + for (i = 0; i < num; i++) + pipe_texture_reference((struct pipe_texture **) &brw->attribs.Texture[i], + texture[i]); + + for (i = num; i < brw->num_textures; i++) + pipe_texture_reference((struct pipe_texture **) &brw->attribs.Texture[i], + NULL); + + brw->num_textures = num; + + brw->state.dirty.brw |= BRW_NEW_TEXTURE; +} + + +/************************************************************************ + * Render targets, etc + */ + +static void brw_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) +{ + struct brw_context *brw = brw_context(pipe); + + brw->attribs.FrameBuffer = *fb; /* struct copy */ + + brw->state.dirty.brw |= BRW_NEW_FRAMEBUFFER; +} + + + +/************************************************************************ + * Rasterizer state + */ + +static void * +brw_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *rasterizer) +{ + DUP(pipe_rasterizer_state, rasterizer); +} + +static void brw_bind_rasterizer_state( struct pipe_context *pipe, + void *setup ) +{ + struct brw_context *brw = brw_context(pipe); + + brw->attribs.Raster = (struct pipe_rasterizer_state *)setup; + + /* Also pass-through to draw module: + */ + //draw_set_rasterizer_state(brw->draw, setup); + + brw->state.dirty.brw |= BRW_NEW_RASTERIZER; +} + +static void brw_delete_rasterizer_state(struct pipe_context *pipe, + void *setup) +{ + free(setup); +} + + + +void +brw_init_state_functions( struct brw_context *brw ) +{ + 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; + + brw->pipe.create_sampler_state = brw_create_sampler_state; + brw->pipe.bind_sampler_states = brw_bind_sampler_states; + brw->pipe.delete_sampler_state = brw_delete_sampler_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; + brw->pipe.delete_rasterizer_state = brw_delete_rasterizer_state; + brw->pipe.create_fs_state = brw_create_fs_state; + brw->pipe.bind_fs_state = brw_bind_fs_state; + brw->pipe.delete_fs_state = brw_delete_fs_state; + brw->pipe.create_vs_state = brw_create_vs_state; + brw->pipe.bind_vs_state = brw_bind_vs_state; + brw->pipe.delete_vs_state = brw_delete_vs_state; + + brw->pipe.set_blend_color = brw_set_blend_color; + brw->pipe.set_clip_state = brw_set_clip_state; + brw->pipe.set_constant_buffer = brw_set_constant_buffer; + brw->pipe.set_framebuffer_state = brw_set_framebuffer_state; + +// brw->pipe.set_feedback_state = brw_set_feedback_state; +// brw->pipe.set_feedback_buffer = brw_set_feedback_buffer; + + brw->pipe.set_polygon_stipple = brw_set_polygon_stipple; + brw->pipe.set_scissor_state = brw_set_scissor_state; + brw->pipe.set_sampler_textures = brw_set_sampler_textures; + brw->pipe.set_viewport_state = brw_set_viewport_state; + brw->pipe.set_vertex_buffer = brw_set_vertex_buffer; + brw->pipe.set_vertex_element = brw_set_vertex_element; +} diff --git a/src/gallium/drivers/i965simple/brw_wm_sampler_state.c b/src/gallium/drivers/i965simple/brw_wm_sampler_state.c index de42ffc5b1..ff5ba7e7c7 100644 --- a/src/gallium/drivers/i965simple/brw_wm_sampler_state.c +++ b/src/gallium/drivers/i965simple/brw_wm_sampler_state.c @@ -235,7 +235,8 @@ static void upload_wm_samplers(struct brw_context *brw) unsigned sampler_count = 0; /* BRW_NEW_SAMPLER */ - for (unit = 0; unit < BRW_MAX_TEX_UNIT; unit++) { + for (unit = 0; unit < brw->num_textures && unit < brw->num_samplers; + unit++) { /* determine unit enable/disable by looking for a bound texture */ if (brw->attribs.Texture[unit]) { const struct pipe_sampler_state *sampler = brw->attribs.Samplers[unit]; diff --git a/src/gallium/drivers/i965simple/brw_wm_surface_state.c b/src/gallium/drivers/i965simple/brw_wm_surface_state.c index d16d919bce..853c743ccf 100644 --- a/src/gallium/drivers/i965simple/brw_wm_surface_state.c +++ b/src/gallium/drivers/i965simple/brw_wm_surface_state.c @@ -237,7 +237,7 @@ static void upload_wm_surfaces(struct brw_context *brw ) /* BRW_NEW_TEXTURE */ - for (i = 0; i < BRW_MAX_TEX_UNIT; i++) { + for (i = 0; i < brw->num_textures && i < brw->num_samplers; i++) { const struct brw_texture *texUnit = brw->attribs.Texture[i]; if (texUnit && diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index fa16ed94e8..316ae552b8 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -1,243 +1,243 @@ -/************************************************************************** - * - * 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: - * Keith Whitwell - */ - -#include "draw/draw_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_inlines.h" -#include "pipe/p_util.h" -#include "sp_clear.h" -#include "sp_context.h" -#include "sp_flush.h" -#include "sp_prim_setup.h" -#include "sp_prim_vbuf.h" -#include "sp_state.h" -#include "sp_surface.h" -#include "sp_tile_cache.h" -#include "sp_texture.h" -#include "sp_winsys.h" -#include "sp_query.h" - - - -/** - * Map any drawing surfaces which aren't already mapped - */ -void -softpipe_map_surfaces(struct softpipe_context *sp) -{ - unsigned i; - - for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - sp_tile_cache_map_surfaces(sp->cbuf_cache[i]); - } - - sp_tile_cache_map_surfaces(sp->zsbuf_cache); -} - - -/** - * Unmap any mapped drawing surfaces - */ -void -softpipe_unmap_surfaces(struct softpipe_context *sp) -{ - uint i; - - for (i = 0; i < sp->framebuffer.num_cbufs; i++) - sp_flush_tile_cache(sp, sp->cbuf_cache[i]); - sp_flush_tile_cache(sp, sp->zsbuf_cache); - - for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - sp_tile_cache_unmap_surfaces(sp->cbuf_cache[i]); - } - sp_tile_cache_unmap_surfaces(sp->zsbuf_cache); -} - - -static void softpipe_destroy( struct pipe_context *pipe ) -{ - struct softpipe_context *softpipe = softpipe_context( pipe ); - struct pipe_winsys *ws = pipe->winsys; - uint i; - - draw_destroy( softpipe->draw ); - - softpipe->quad.polygon_stipple->destroy( softpipe->quad.polygon_stipple ); - softpipe->quad.earlyz->destroy( softpipe->quad.earlyz ); - softpipe->quad.shade->destroy( softpipe->quad.shade ); - softpipe->quad.alpha_test->destroy( softpipe->quad.alpha_test ); - softpipe->quad.depth_test->destroy( softpipe->quad.depth_test ); - softpipe->quad.stencil_test->destroy( softpipe->quad.stencil_test ); - softpipe->quad.occlusion->destroy( softpipe->quad.occlusion ); - softpipe->quad.coverage->destroy( softpipe->quad.coverage ); - softpipe->quad.bufloop->destroy( softpipe->quad.bufloop ); - softpipe->quad.blend->destroy( softpipe->quad.blend ); - softpipe->quad.colormask->destroy( softpipe->quad.colormask ); - softpipe->quad.output->destroy( softpipe->quad.output ); - - for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) - sp_destroy_tile_cache(softpipe->cbuf_cache[i]); - sp_destroy_tile_cache(softpipe->zsbuf_cache); - - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) - sp_destroy_tile_cache(softpipe->tex_cache[i]); - - for (i = 0; i < Elements(softpipe->constants); i++) { - if (softpipe->constants[i].buffer) { - pipe_buffer_reference(ws, &softpipe->constants[i].buffer, NULL); - } - } - - FREE( softpipe ); -} - - -struct pipe_context * -softpipe_create( struct pipe_screen *screen, - struct pipe_winsys *pipe_winsys, - struct softpipe_winsys *softpipe_winsys ) -{ - struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context); - uint i; - -#if defined(__i386__) || defined(__386__) - softpipe->use_sse = GETENV( "GALLIUM_NOSSE" ) == NULL; -#else - softpipe->use_sse = FALSE; -#endif - - softpipe->dump_fs = GETENV( "GALLIUM_DUMP_FS" ) != NULL; - - softpipe->pipe.winsys = pipe_winsys; - softpipe->pipe.screen = screen; - softpipe->pipe.destroy = softpipe_destroy; - - /* 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.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_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; - softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state; - - softpipe->pipe.create_fs_state = softpipe_create_fs_state; - softpipe->pipe.bind_fs_state = softpipe_bind_fs_state; - softpipe->pipe.delete_fs_state = softpipe_delete_fs_state; - - softpipe->pipe.create_vs_state = softpipe_create_vs_state; - softpipe->pipe.bind_vs_state = softpipe_bind_vs_state; - softpipe->pipe.delete_vs_state = softpipe_delete_vs_state; - - softpipe->pipe.set_blend_color = softpipe_set_blend_color; - softpipe->pipe.set_clip_state = softpipe_set_clip_state; - softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer; - softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; - softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; - softpipe->pipe.set_scissor_state = softpipe_set_scissor_state; - softpipe->pipe.set_sampler_texture = softpipe_set_sampler_texture; - softpipe->pipe.set_viewport_state = softpipe_set_viewport_state; - - softpipe->pipe.set_vertex_buffer = softpipe_set_vertex_buffer; - softpipe->pipe.set_vertex_element = softpipe_set_vertex_element; - - softpipe->pipe.draw_arrays = softpipe_draw_arrays; - softpipe->pipe.draw_elements = softpipe_draw_elements; - - softpipe->pipe.clear = softpipe_clear; - softpipe->pipe.flush = softpipe_flush; - - softpipe_init_query_funcs( softpipe ); - softpipe_init_texture_funcs( softpipe ); - - /* - * Alloc caches for accessing drawing surfaces and textures. - * Must be before quad stage setup! - */ - for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) - softpipe->cbuf_cache[i] = sp_create_tile_cache(); - softpipe->zsbuf_cache = sp_create_tile_cache(); - - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) - softpipe->tex_cache[i] = sp_create_tile_cache(); - - - /* setup quad rendering stages */ - softpipe->quad.polygon_stipple = sp_quad_polygon_stipple_stage(softpipe); - softpipe->quad.earlyz = sp_quad_earlyz_stage(softpipe); - softpipe->quad.shade = sp_quad_shade_stage(softpipe); - softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe); - softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe); - softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe); - softpipe->quad.occlusion = sp_quad_occlusion_stage(softpipe); - softpipe->quad.coverage = sp_quad_coverage_stage(softpipe); - softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe); - softpipe->quad.blend = sp_quad_blend_stage(softpipe); - softpipe->quad.colormask = sp_quad_colormask_stage(softpipe); - softpipe->quad.output = sp_quad_output_stage(softpipe); - - softpipe->winsys = softpipe_winsys; - - /* - * Create drawing context and plug our rendering stage into it. - */ - softpipe->draw = draw_create(); - assert(softpipe->draw); - softpipe->setup = sp_draw_render_stage(softpipe); - - if (GETENV( "SP_VBUF" ) != NULL) { - sp_init_vbuf(softpipe); - } - else { - draw_set_rasterize_stage(softpipe->draw, softpipe->setup); - } - - /* plug in AA line/point stages */ - draw_install_aaline_stage(softpipe->draw, &softpipe->pipe); - draw_install_aapoint_stage(softpipe->draw, &softpipe->pipe); - -#if USE_DRAW_STAGE_PSTIPPLE - /* Do polygon stipple w/ texture map + frag prog? */ - draw_install_pstipple_stage(softpipe->draw, &softpipe->pipe); -#endif - - sp_init_surface_functions(softpipe); - - return &softpipe->pipe; -} +/************************************************************************** + * + * 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: + * Keith Whitwell + */ + +#include "draw/draw_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_inlines.h" +#include "pipe/p_util.h" +#include "sp_clear.h" +#include "sp_context.h" +#include "sp_flush.h" +#include "sp_prim_setup.h" +#include "sp_prim_vbuf.h" +#include "sp_state.h" +#include "sp_surface.h" +#include "sp_tile_cache.h" +#include "sp_texture.h" +#include "sp_winsys.h" +#include "sp_query.h" + + + +/** + * Map any drawing surfaces which aren't already mapped + */ +void +softpipe_map_surfaces(struct softpipe_context *sp) +{ + unsigned i; + + for (i = 0; i < sp->framebuffer.num_cbufs; i++) { + sp_tile_cache_map_surfaces(sp->cbuf_cache[i]); + } + + sp_tile_cache_map_surfaces(sp->zsbuf_cache); +} + + +/** + * Unmap any mapped drawing surfaces + */ +void +softpipe_unmap_surfaces(struct softpipe_context *sp) +{ + uint i; + + for (i = 0; i < sp->framebuffer.num_cbufs; i++) + sp_flush_tile_cache(sp, sp->cbuf_cache[i]); + sp_flush_tile_cache(sp, sp->zsbuf_cache); + + for (i = 0; i < sp->framebuffer.num_cbufs; i++) { + sp_tile_cache_unmap_surfaces(sp->cbuf_cache[i]); + } + sp_tile_cache_unmap_surfaces(sp->zsbuf_cache); +} + + +static void softpipe_destroy( struct pipe_context *pipe ) +{ + struct softpipe_context *softpipe = softpipe_context( pipe ); + struct pipe_winsys *ws = pipe->winsys; + uint i; + + draw_destroy( softpipe->draw ); + + softpipe->quad.polygon_stipple->destroy( softpipe->quad.polygon_stipple ); + softpipe->quad.earlyz->destroy( softpipe->quad.earlyz ); + softpipe->quad.shade->destroy( softpipe->quad.shade ); + softpipe->quad.alpha_test->destroy( softpipe->quad.alpha_test ); + softpipe->quad.depth_test->destroy( softpipe->quad.depth_test ); + softpipe->quad.stencil_test->destroy( softpipe->quad.stencil_test ); + softpipe->quad.occlusion->destroy( softpipe->quad.occlusion ); + softpipe->quad.coverage->destroy( softpipe->quad.coverage ); + softpipe->quad.bufloop->destroy( softpipe->quad.bufloop ); + softpipe->quad.blend->destroy( softpipe->quad.blend ); + softpipe->quad.colormask->destroy( softpipe->quad.colormask ); + softpipe->quad.output->destroy( softpipe->quad.output ); + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) + sp_destroy_tile_cache(softpipe->cbuf_cache[i]); + sp_destroy_tile_cache(softpipe->zsbuf_cache); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) + sp_destroy_tile_cache(softpipe->tex_cache[i]); + + for (i = 0; i < Elements(softpipe->constants); i++) { + if (softpipe->constants[i].buffer) { + pipe_buffer_reference(ws, &softpipe->constants[i].buffer, NULL); + } + } + + FREE( softpipe ); +} + + +struct pipe_context * +softpipe_create( struct pipe_screen *screen, + struct pipe_winsys *pipe_winsys, + struct softpipe_winsys *softpipe_winsys ) +{ + struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context); + uint i; + +#if defined(__i386__) || defined(__386__) + softpipe->use_sse = GETENV( "GALLIUM_NOSSE" ) == NULL; +#else + softpipe->use_sse = FALSE; +#endif + + softpipe->dump_fs = GETENV( "GALLIUM_DUMP_FS" ) != NULL; + + softpipe->pipe.winsys = pipe_winsys; + softpipe->pipe.screen = screen; + softpipe->pipe.destroy = softpipe_destroy; + + /* 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.create_sampler_state = softpipe_create_sampler_state; + softpipe->pipe.bind_sampler_states = softpipe_bind_sampler_states; + softpipe->pipe.delete_sampler_state = softpipe_delete_sampler_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; + softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state; + + softpipe->pipe.create_fs_state = softpipe_create_fs_state; + softpipe->pipe.bind_fs_state = softpipe_bind_fs_state; + softpipe->pipe.delete_fs_state = softpipe_delete_fs_state; + + softpipe->pipe.create_vs_state = softpipe_create_vs_state; + softpipe->pipe.bind_vs_state = softpipe_bind_vs_state; + softpipe->pipe.delete_vs_state = softpipe_delete_vs_state; + + softpipe->pipe.set_blend_color = softpipe_set_blend_color; + softpipe->pipe.set_clip_state = softpipe_set_clip_state; + softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer; + softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; + softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; + softpipe->pipe.set_scissor_state = softpipe_set_scissor_state; + softpipe->pipe.set_sampler_textures = softpipe_set_sampler_textures; + softpipe->pipe.set_viewport_state = softpipe_set_viewport_state; + + softpipe->pipe.set_vertex_buffer = softpipe_set_vertex_buffer; + softpipe->pipe.set_vertex_element = softpipe_set_vertex_element; + + softpipe->pipe.draw_arrays = softpipe_draw_arrays; + softpipe->pipe.draw_elements = softpipe_draw_elements; + + softpipe->pipe.clear = softpipe_clear; + softpipe->pipe.flush = softpipe_flush; + + softpipe_init_query_funcs( softpipe ); + softpipe_init_texture_funcs( softpipe ); + + /* + * Alloc caches for accessing drawing surfaces and textures. + * Must be before quad stage setup! + */ + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) + softpipe->cbuf_cache[i] = sp_create_tile_cache(); + softpipe->zsbuf_cache = sp_create_tile_cache(); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) + softpipe->tex_cache[i] = sp_create_tile_cache(); + + + /* setup quad rendering stages */ + softpipe->quad.polygon_stipple = sp_quad_polygon_stipple_stage(softpipe); + softpipe->quad.earlyz = sp_quad_earlyz_stage(softpipe); + softpipe->quad.shade = sp_quad_shade_stage(softpipe); + softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe); + softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe); + softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe); + softpipe->quad.occlusion = sp_quad_occlusion_stage(softpipe); + softpipe->quad.coverage = sp_quad_coverage_stage(softpipe); + softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe); + softpipe->quad.blend = sp_quad_blend_stage(softpipe); + softpipe->quad.colormask = sp_quad_colormask_stage(softpipe); + softpipe->quad.output = sp_quad_output_stage(softpipe); + + softpipe->winsys = softpipe_winsys; + + /* + * Create drawing context and plug our rendering stage into it. + */ + softpipe->draw = draw_create(); + assert(softpipe->draw); + softpipe->setup = sp_draw_render_stage(softpipe); + + if (GETENV( "SP_VBUF" ) != NULL) { + sp_init_vbuf(softpipe); + } + else { + draw_set_rasterize_stage(softpipe->draw, softpipe->setup); + } + + /* plug in AA line/point stages */ + draw_install_aaline_stage(softpipe->draw, &softpipe->pipe); + draw_install_aapoint_stage(softpipe->draw, &softpipe->pipe); + +#if USE_DRAW_STAGE_PSTIPPLE + /* Do polygon stipple w/ texture map + frag prog? */ + draw_install_pstipple_stage(softpipe->draw, &softpipe->pipe); +#endif + + sp_init_surface_functions(softpipe); + + return &softpipe->pipe; +} diff --git a/src/gallium/drivers/softpipe/sp_context.h b/src/gallium/drivers/softpipe/sp_context.h index feeafc7084..19e6cfaf02 100644 --- a/src/gallium/drivers/softpipe/sp_context.h +++ b/src/gallium/drivers/softpipe/sp_context.h @@ -81,6 +81,9 @@ struct softpipe_context { struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; unsigned dirty; + unsigned num_samplers; + unsigned num_textures; + /* Counter for occlusion queries. Note this supports overlapping * queries. */ diff --git a/src/gallium/drivers/softpipe/sp_quad_fs.c b/src/gallium/drivers/softpipe/sp_quad_fs.c index 1fbb2e38c4..9198198db3 100644 --- a/src/gallium/drivers/softpipe/sp_quad_fs.c +++ b/src/gallium/drivers/softpipe/sp_quad_fs.c @@ -1,208 +1,209 @@ -/************************************************************************** - * - * 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. - * - **************************************************************************/ - -/* Vertices are just an array of floats, with all the attributes - * packed. We currently assume a layout like: - * - * attr[0][0..3] - window position - * attr[1..n][0..3] - remaining attributes. - * - * Attributes are assumed to be 4 floats wide but are packed so that - * all the enabled attributes run contiguously. - */ - -#include "pipe/p_util.h" -#include "pipe/p_defines.h" -#include "pipe/p_shader_tokens.h" - -#include "sp_context.h" -#include "sp_state.h" -#include "sp_headers.h" -#include "sp_quad.h" -#include "sp_texture.h" -#include "sp_tex_sample.h" - - -struct quad_shade_stage -{ - struct quad_stage stage; - struct tgsi_sampler samplers[PIPE_MAX_SAMPLERS]; - struct tgsi_exec_machine machine; - struct tgsi_exec_vector *inputs, *outputs; - int colorOutSlot, depthOutSlot; -}; - - -/** cast wrapper */ -static INLINE struct quad_shade_stage * -quad_shade_stage(struct quad_stage *qs) -{ - return (struct quad_shade_stage *) qs; -} - - - -/** - * Execute fragment shader for the four fragments in the quad. - */ -static void -shade_quad( - struct quad_stage *qs, - struct quad_header *quad ) -{ - struct quad_shade_stage *qss = quad_shade_stage( qs ); - struct softpipe_context *softpipe = qs->softpipe; - struct tgsi_exec_machine *machine = &qss->machine; - - /* Consts do not require 16 byte alignment. */ - machine->Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT]; - - machine->InterpCoefs = quad->coef; - - /* run shader */ - quad->mask &= softpipe->fs->run( softpipe->fs, - &qss->machine, - quad ); - - /* store result color */ - if (qss->colorOutSlot >= 0) { - /* XXX need to handle multiple color outputs someday */ - assert(qss->stage.softpipe->fs->info.output_semantic_name[qss->colorOutSlot] - == TGSI_SEMANTIC_COLOR); - memcpy( - quad->outputs.color, - &machine->Outputs[qss->colorOutSlot].xyzw[0].f[0], - sizeof( quad->outputs.color ) ); - } - - /* - * XXX the following code for updating quad->outputs.depth - * isn't really needed if we did early z testing. - */ - - /* store result Z */ - if (qss->depthOutSlot >= 0) { - /* output[slot] is new Z */ - uint i; - for (i = 0; i < 4; i++) { - quad->outputs.depth[i] = machine->Outputs[0].xyzw[2].f[i]; - } - } - else { - /* copy input Z (which was interpolated by the executor) to output Z */ - uint i; - for (i = 0; i < 4; i++) { - quad->outputs.depth[i] = machine->Inputs[0].xyzw[2].f[i]; - /* XXX not sure the above line is always correct. The following - * might be better: - quad->outputs.depth[i] = machine->QuadPos.xyzw[2].f[i]; - */ - } - } - - /* shader may cull fragments */ - if( quad->mask ) { - qs->next->run( qs->next, quad ); - } -} - -/** - * Per-primitive (or per-begin?) setup - */ -static void shade_begin(struct quad_stage *qs) -{ - struct quad_shade_stage *qss = quad_shade_stage(qs); - struct softpipe_context *softpipe = qs->softpipe; - unsigned i; - - /* set TGSI sampler state that varies */ - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - qss->samplers[i].state = softpipe->sampler[i]; - qss->samplers[i].texture = softpipe->texture[i]; - } - - /* find output slots for depth, color */ - qss->colorOutSlot = -1; - qss->depthOutSlot = -1; - for (i = 0; i < qss->stage.softpipe->fs->info.num_outputs; i++) { - switch (qss->stage.softpipe->fs->info.output_semantic_name[i]) { - case TGSI_SEMANTIC_POSITION: - qss->depthOutSlot = i; - break; - case TGSI_SEMANTIC_COLOR: - qss->colorOutSlot = i; - break; - } - } - - softpipe->fs->prepare( softpipe->fs, - &qss->machine, - qss->samplers ); - - qs->next->begin(qs->next); -} - - -static void shade_destroy(struct quad_stage *qs) -{ - struct quad_shade_stage *qss = (struct quad_shade_stage *) qs; - - tgsi_exec_machine_free_data(&qss->machine); - FREE( qss->inputs ); - FREE( qss->outputs ); - FREE( qs ); -} - - -struct quad_stage *sp_quad_shade_stage( struct softpipe_context *softpipe ) -{ - struct quad_shade_stage *qss = CALLOC_STRUCT(quad_shade_stage); - uint i; - - /* allocate storage for program inputs/outputs, aligned to 16 bytes */ - qss->inputs = MALLOC(PIPE_ATTRIB_MAX * sizeof(*qss->inputs) + 16); - qss->outputs = MALLOC(PIPE_ATTRIB_MAX * sizeof(*qss->outputs) + 16); - qss->machine.Inputs = align16(qss->inputs); - qss->machine.Outputs = align16(qss->outputs); - - qss->stage.softpipe = softpipe; - qss->stage.begin = shade_begin; - qss->stage.run = shade_quad; - qss->stage.destroy = shade_destroy; - - /* set TGSI sampler state that's constant */ - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - assert(softpipe->tex_cache[i]); - qss->samplers[i].get_samples = sp_get_samples; - qss->samplers[i].pipe = &softpipe->pipe; - qss->samplers[i].cache = softpipe->tex_cache[i]; - } - - tgsi_exec_machine_init( &qss->machine ); - - return &qss->stage; -} +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/* Vertices are just an array of floats, with all the attributes + * packed. We currently assume a layout like: + * + * attr[0][0..3] - window position + * attr[1..n][0..3] - remaining attributes. + * + * Attributes are assumed to be 4 floats wide but are packed so that + * all the enabled attributes run contiguously. + */ + +#include "pipe/p_util.h" +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_headers.h" +#include "sp_quad.h" +#include "sp_texture.h" +#include "sp_tex_sample.h" + + +struct quad_shade_stage +{ + struct quad_stage stage; + struct tgsi_sampler samplers[PIPE_MAX_SAMPLERS]; + struct tgsi_exec_machine machine; + struct tgsi_exec_vector *inputs, *outputs; + int colorOutSlot, depthOutSlot; +}; + + +/** cast wrapper */ +static INLINE struct quad_shade_stage * +quad_shade_stage(struct quad_stage *qs) +{ + return (struct quad_shade_stage *) qs; +} + + + +/** + * Execute fragment shader for the four fragments in the quad. + */ +static void +shade_quad( + struct quad_stage *qs, + struct quad_header *quad ) +{ + struct quad_shade_stage *qss = quad_shade_stage( qs ); + struct softpipe_context *softpipe = qs->softpipe; + struct tgsi_exec_machine *machine = &qss->machine; + + /* Consts do not require 16 byte alignment. */ + machine->Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT]; + + machine->InterpCoefs = quad->coef; + + /* run shader */ + quad->mask &= softpipe->fs->run( softpipe->fs, + &qss->machine, + quad ); + + /* store result color */ + if (qss->colorOutSlot >= 0) { + /* XXX need to handle multiple color outputs someday */ + assert(qss->stage.softpipe->fs->info.output_semantic_name[qss->colorOutSlot] + == TGSI_SEMANTIC_COLOR); + memcpy( + quad->outputs.color, + &machine->Outputs[qss->colorOutSlot].xyzw[0].f[0], + sizeof( quad->outputs.color ) ); + } + + /* + * XXX the following code for updating quad->outputs.depth + * isn't really needed if we did early z testing. + */ + + /* store result Z */ + if (qss->depthOutSlot >= 0) { + /* output[slot] is new Z */ + uint i; + for (i = 0; i < 4; i++) { + quad->outputs.depth[i] = machine->Outputs[0].xyzw[2].f[i]; + } + } + else { + /* copy input Z (which was interpolated by the executor) to output Z */ + uint i; + for (i = 0; i < 4; i++) { + quad->outputs.depth[i] = machine->Inputs[0].xyzw[2].f[i]; + /* XXX not sure the above line is always correct. The following + * might be better: + quad->outputs.depth[i] = machine->QuadPos.xyzw[2].f[i]; + */ + } + } + + /* shader may cull fragments */ + if( quad->mask ) { + qs->next->run( qs->next, quad ); + } +} + +/** + * Per-primitive (or per-begin?) setup + */ +static void shade_begin(struct quad_stage *qs) +{ + struct quad_shade_stage *qss = quad_shade_stage(qs); + struct softpipe_context *softpipe = qs->softpipe; + unsigned i; + unsigned num = MAX2(softpipe->num_textures, softpipe->num_samplers); + + /* set TGSI sampler state that varies */ + for (i = 0; i < num; i++) { + qss->samplers[i].state = softpipe->sampler[i]; + qss->samplers[i].texture = softpipe->texture[i]; + } + + /* find output slots for depth, color */ + qss->colorOutSlot = -1; + qss->depthOutSlot = -1; + for (i = 0; i < qss->stage.softpipe->fs->info.num_outputs; i++) { + switch (qss->stage.softpipe->fs->info.output_semantic_name[i]) { + case TGSI_SEMANTIC_POSITION: + qss->depthOutSlot = i; + break; + case TGSI_SEMANTIC_COLOR: + qss->colorOutSlot = i; + break; + } + } + + softpipe->fs->prepare( softpipe->fs, + &qss->machine, + qss->samplers ); + + qs->next->begin(qs->next); +} + + +static void shade_destroy(struct quad_stage *qs) +{ + struct quad_shade_stage *qss = (struct quad_shade_stage *) qs; + + tgsi_exec_machine_free_data(&qss->machine); + FREE( qss->inputs ); + FREE( qss->outputs ); + FREE( qs ); +} + + +struct quad_stage *sp_quad_shade_stage( struct softpipe_context *softpipe ) +{ + struct quad_shade_stage *qss = CALLOC_STRUCT(quad_shade_stage); + uint i; + + /* allocate storage for program inputs/outputs, aligned to 16 bytes */ + qss->inputs = MALLOC(PIPE_ATTRIB_MAX * sizeof(*qss->inputs) + 16); + qss->outputs = MALLOC(PIPE_ATTRIB_MAX * sizeof(*qss->outputs) + 16); + qss->machine.Inputs = align16(qss->inputs); + qss->machine.Outputs = align16(qss->outputs); + + qss->stage.softpipe = softpipe; + qss->stage.begin = shade_begin; + qss->stage.run = shade_quad; + qss->stage.destroy = shade_destroy; + + /* set TGSI sampler state that's constant */ + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + assert(softpipe->tex_cache[i]); + qss->samplers[i].get_samples = sp_get_samples; + qss->samplers[i].pipe = &softpipe->pipe; + qss->samplers[i].cache = softpipe->tex_cache[i]; + } + + tgsi_exec_machine_init( &qss->machine ); + + return &qss->stage; +} diff --git a/src/gallium/drivers/softpipe/sp_state.h b/src/gallium/drivers/softpipe/sp_state.h index 3943d4ed2b..45d159143f 100644 --- a/src/gallium/drivers/softpipe/sp_state.h +++ b/src/gallium/drivers/softpipe/sp_state.h @@ -1,195 +1,195 @@ -/************************************************************************** - * - * 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 - */ - -#ifndef SP_STATE_H -#define SP_STATE_H - -#include "pipe/p_state.h" -#include "tgsi/util/tgsi_scan.h" - - -#define SP_NEW_VIEWPORT 0x1 -#define SP_NEW_RASTERIZER 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_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_QUERY 0x4000 - - -struct tgsi_sampler; -struct tgsi_exec_machine; - - -/** Subclass of pipe_shader_state (though it doesn't really need to be). - * - * This is starting to look an awful lot like a quad pipeline stage... - */ -struct sp_fragment_shader { - struct pipe_shader_state shader; - - struct tgsi_shader_info info; - - void (*prepare)( const struct sp_fragment_shader *shader, - struct tgsi_exec_machine *machine, - struct tgsi_sampler *samplers); - - /* Run the shader - this interface will get cleaned up in the - * future: - */ - unsigned (*run)( const struct sp_fragment_shader *shader, - struct tgsi_exec_machine *machine, - struct quad_header *quad ); - - - void (*delete)( struct sp_fragment_shader * ); -}; - -struct vertex_info; - -/** Subclass of pipe_shader_state */ -struct sp_vertex_shader { - struct pipe_shader_state shader; - struct draw_vertex_shader *draw_data; -}; - - - -void * -softpipe_create_blend_state(struct pipe_context *, - const struct pipe_blend_state *); -void softpipe_bind_blend_state(struct pipe_context *, - void *); -void softpipe_delete_blend_state(struct pipe_context *, - void *); - -void * -softpipe_create_sampler_state(struct pipe_context *, - const struct pipe_sampler_state *); -void softpipe_bind_sampler_state(struct pipe_context *, unsigned, void *); -void softpipe_delete_sampler_state(struct pipe_context *, void *); - -void * -softpipe_create_depth_stencil_state(struct pipe_context *, - 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 *); - -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_set_framebuffer_state( struct pipe_context *, - const struct pipe_framebuffer_state * ); - -void softpipe_set_blend_color( struct pipe_context *pipe, - const struct pipe_blend_color *blend_color ); - -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_create_fs_state(struct pipe_context *, - const struct pipe_shader_state *); -void softpipe_bind_fs_state(struct pipe_context *, void *); -void softpipe_delete_fs_state(struct pipe_context *, void *); -void *softpipe_create_vs_state(struct pipe_context *, - const struct pipe_shader_state *); -void softpipe_bind_vs_state(struct pipe_context *, void *); -void softpipe_delete_vs_state(struct pipe_context *, void *); - -void softpipe_set_polygon_stipple( struct pipe_context *, - const struct pipe_poly_stipple * ); - -void softpipe_set_scissor_state( struct pipe_context *, - const struct pipe_scissor_state * ); - -void softpipe_set_sampler_texture( struct pipe_context *, - unsigned unit, - struct pipe_texture * ); - -void softpipe_set_viewport_state( struct pipe_context *, - const struct pipe_viewport_state * ); - -void softpipe_set_vertex_element(struct pipe_context *, - unsigned index, - const struct pipe_vertex_element *); - -void softpipe_set_vertex_buffer(struct pipe_context *, - unsigned index, - const struct pipe_vertex_buffer *); - - -void softpipe_update_derived( struct softpipe_context *softpipe ); - - -boolean softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode, - unsigned start, unsigned count); - -boolean softpipe_draw_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, - unsigned indexSize, - unsigned mode, unsigned start, unsigned count); - - -void -softpipe_map_surfaces(struct softpipe_context *sp); - -void -softpipe_unmap_surfaces(struct softpipe_context *sp); - -void -softpipe_map_texture_surfaces(struct softpipe_context *sp); - -void -softpipe_unmap_texture_surfaces(struct softpipe_context *sp); - - -struct vertex_info * -softpipe_get_vertex_info(struct softpipe_context *softpipe); - -struct vertex_info * -softpipe_get_vbuf_vertex_info(struct softpipe_context *softpipe); - - -#endif +/************************************************************************** + * + * 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 + */ + +#ifndef SP_STATE_H +#define SP_STATE_H + +#include "pipe/p_state.h" +#include "tgsi/util/tgsi_scan.h" + + +#define SP_NEW_VIEWPORT 0x1 +#define SP_NEW_RASTERIZER 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_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_QUERY 0x4000 + + +struct tgsi_sampler; +struct tgsi_exec_machine; + + +/** Subclass of pipe_shader_state (though it doesn't really need to be). + * + * This is starting to look an awful lot like a quad pipeline stage... + */ +struct sp_fragment_shader { + struct pipe_shader_state shader; + + struct tgsi_shader_info info; + + void (*prepare)( const struct sp_fragment_shader *shader, + struct tgsi_exec_machine *machine, + struct tgsi_sampler *samplers); + + /* Run the shader - this interface will get cleaned up in the + * future: + */ + unsigned (*run)( const struct sp_fragment_shader *shader, + struct tgsi_exec_machine *machine, + struct quad_header *quad ); + + + void (*delete)( struct sp_fragment_shader * ); +}; + +struct vertex_info; + +/** Subclass of pipe_shader_state */ +struct sp_vertex_shader { + struct pipe_shader_state shader; + struct draw_vertex_shader *draw_data; +}; + + + +void * +softpipe_create_blend_state(struct pipe_context *, + const struct pipe_blend_state *); +void softpipe_bind_blend_state(struct pipe_context *, + void *); +void softpipe_delete_blend_state(struct pipe_context *, + void *); + +void * +softpipe_create_sampler_state(struct pipe_context *, + const struct pipe_sampler_state *); +void softpipe_bind_sampler_states(struct pipe_context *, unsigned, void **); +void softpipe_delete_sampler_state(struct pipe_context *, void *); + +void * +softpipe_create_depth_stencil_state(struct pipe_context *, + 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 *); + +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_set_framebuffer_state( struct pipe_context *, + const struct pipe_framebuffer_state * ); + +void softpipe_set_blend_color( struct pipe_context *pipe, + const struct pipe_blend_color *blend_color ); + +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_create_fs_state(struct pipe_context *, + const struct pipe_shader_state *); +void softpipe_bind_fs_state(struct pipe_context *, void *); +void softpipe_delete_fs_state(struct pipe_context *, void *); +void *softpipe_create_vs_state(struct pipe_context *, + const struct pipe_shader_state *); +void softpipe_bind_vs_state(struct pipe_context *, void *); +void softpipe_delete_vs_state(struct pipe_context *, void *); + +void softpipe_set_polygon_stipple( struct pipe_context *, + const struct pipe_poly_stipple * ); + +void softpipe_set_scissor_state( struct pipe_context *, + const struct pipe_scissor_state * ); + +void softpipe_set_sampler_textures( struct pipe_context *, + unsigned num, + struct pipe_texture ** ); + +void softpipe_set_viewport_state( struct pipe_context *, + const struct pipe_viewport_state * ); + +void softpipe_set_vertex_element(struct pipe_context *, + unsigned index, + const struct pipe_vertex_element *); + +void softpipe_set_vertex_buffer(struct pipe_context *, + unsigned index, + const struct pipe_vertex_buffer *); + + +void softpipe_update_derived( struct softpipe_context *softpipe ); + + +boolean softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode, + unsigned start, unsigned count); + +boolean softpipe_draw_elements(struct pipe_context *pipe, + struct pipe_buffer *indexBuffer, + unsigned indexSize, + unsigned mode, unsigned start, unsigned count); + + +void +softpipe_map_surfaces(struct softpipe_context *sp); + +void +softpipe_unmap_surfaces(struct softpipe_context *sp); + +void +softpipe_map_texture_surfaces(struct softpipe_context *sp); + +void +softpipe_unmap_texture_surfaces(struct softpipe_context *sp); + + +struct vertex_info * +softpipe_get_vertex_info(struct softpipe_context *softpipe); + +struct vertex_info * +softpipe_get_vbuf_vertex_info(struct softpipe_context *softpipe); + + +#endif diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c index 1d6dd17d1d..7cf85b9207 100644 --- a/src/gallium/drivers/softpipe/sp_state_sampler.c +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -50,45 +50,67 @@ softpipe_create_sampler_state(struct pipe_context *pipe, return mem_dup(sampler, sizeof(*sampler)); } + void -softpipe_bind_sampler_state(struct pipe_context *pipe, - unsigned unit, void *sampler) +softpipe_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) { struct softpipe_context *softpipe = softpipe_context(pipe); + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == softpipe->num_samplers && + !memcmp(softpipe->sampler, sampler, num * sizeof(void *))) + return; + draw_flush(softpipe->draw); - assert(unit < PIPE_MAX_SAMPLERS); - softpipe->sampler[unit] = (struct pipe_sampler_state *)sampler; + memcpy(softpipe->sampler, sampler, num * sizeof(void *)); + memset(&softpipe->sampler[num], 0, (PIPE_MAX_SAMPLERS - num) * + sizeof(void *)); + + softpipe->num_samplers = num; softpipe->dirty |= SP_NEW_SAMPLER; } void -softpipe_delete_sampler_state(struct pipe_context *pipe, - void *sampler) +softpipe_set_sampler_textures(struct pipe_context *pipe, + unsigned num, struct pipe_texture **texture) { - FREE( sampler ); -} + struct softpipe_context *softpipe = softpipe_context(pipe); + uint i; + assert(num <= PIPE_MAX_SAMPLERS); -void -softpipe_set_sampler_texture(struct pipe_context *pipe, - unsigned unit, - struct pipe_texture *texture) -{ - struct softpipe_context *softpipe = softpipe_context(pipe); + /* Check for no-op */ + if (num == softpipe->num_textures && + !memcmp(softpipe->texture, texture, num * sizeof(struct pipe_texture *))) + return; draw_flush(softpipe->draw); - assert(unit < PIPE_MAX_SAMPLERS); - pipe_texture_reference(&softpipe->texture[unit], texture); + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + struct pipe_texture *tex = i < num ? texture[i] : NULL; + + pipe_texture_reference(&softpipe->texture[i], tex); + sp_tile_cache_set_texture(pipe, softpipe->tex_cache[i], tex); + } - sp_tile_cache_set_texture(pipe, softpipe->tex_cache[unit], texture); + softpipe->num_textures = num; softpipe->dirty |= SP_NEW_TEXTURE; } +void +softpipe_delete_sampler_state(struct pipe_context *pipe, + void *sampler) +{ + FREE( sampler ); +} + + diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index c605ed925b..bbf2d80308 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -1,202 +1,202 @@ -/************************************************************************** - * - * Copyright 2006 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 - * Michel Dänzer - */ - -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_inlines.h" -#include "pipe/p_util.h" -#include "pipe/p_winsys.h" - -#include "sp_context.h" -#include "sp_state.h" -#include "sp_texture.h" -#include "sp_tile_cache.h" - - -/* Simple, maximally packed layout. - */ - -static unsigned minify( unsigned d ) -{ - return MAX2(1, d>>1); -} - - -static void -softpipe_texture_layout(struct softpipe_texture * spt) -{ - struct pipe_texture *pt = &spt->base; - unsigned level; - unsigned width = pt->width[0]; - unsigned height = pt->height[0]; - unsigned depth = pt->depth[0]; - - spt->buffer_size = 0; - - for (level = 0; level <= pt->last_level; level++) { - pt->width[level] = width; - pt->height[level] = height; - pt->depth[level] = depth; - - spt->level_offset[level] = spt->buffer_size; - - spt->buffer_size += ((pt->compressed) ? MAX2(1, height/4) : height) * - ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) * - width * pt->cpp; - - width = minify(width); - height = minify(height); - depth = minify(depth); - } -} - - -static struct pipe_texture * -softpipe_texture_create_screen(struct pipe_screen *screen, - const struct pipe_texture *templat) -{ - struct pipe_winsys *ws = screen->winsys; - struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture); - if (!spt) - return NULL; - - spt->base = *templat; - spt->base.refcount = 1; - spt->base.screen = screen; - - softpipe_texture_layout(spt); - - spt->buffer = ws->buffer_create(ws, 32, - PIPE_BUFFER_USAGE_PIXEL, - spt->buffer_size); - if (!spt->buffer) { - FREE(spt); - return NULL; - } - - assert(spt->base.refcount == 1); - - return &spt->base; -} - - -static void -softpipe_texture_release_screen(struct pipe_screen *screen, - struct pipe_texture **pt) -{ - if (!*pt) - return; - - /* - DBG("%s %p refcount will be %d\n", - __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); - */ - if (--(*pt)->refcount <= 0) { - struct softpipe_texture *spt = softpipe_texture(*pt); - - /* - DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); - */ - - pipe_buffer_reference(screen->winsys, &spt->buffer, NULL); - - FREE(spt); - } - *pt = NULL; -} - - -static struct pipe_surface * -softpipe_get_tex_surface_screen(struct pipe_screen *screen, - struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice) -{ - struct pipe_winsys *ws = screen->winsys; - struct softpipe_texture *spt = softpipe_texture(pt); - struct pipe_surface *ps; - - assert(level <= pt->last_level); - - ps = ws->surface_alloc(ws); - if (ps) { - assert(ps->refcount); - assert(ps->winsys); - pipe_buffer_reference(ws, &ps->buffer, spt->buffer); - ps->format = pt->format; - ps->cpp = pt->cpp; - ps->width = pt->width[level]; - ps->height = pt->height[level]; - ps->pitch = ps->width; - ps->offset = spt->level_offset[level]; - - if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) { - ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) * - (pt->compressed ? ps->height/4 : ps->height) * - ps->width * ps->cpp; - } - else { - assert(face == 0); - assert(zslice == 0); - } - } - return ps; -} - - -static void -softpipe_texture_update(struct pipe_context *pipe, - struct pipe_texture *texture) -{ - struct softpipe_context *softpipe = softpipe_context(pipe); - uint unit; - for (unit = 0; unit < PIPE_MAX_SAMPLERS; unit++) { - if (softpipe->texture[unit] == texture) { - sp_flush_tile_cache(softpipe, softpipe->tex_cache[unit]); - } - } -} - - -void -softpipe_init_texture_funcs( struct softpipe_context *softpipe ) -{ - softpipe->pipe.texture_update = softpipe_texture_update; -} - - -void -softpipe_init_screen_texture_funcs(struct pipe_screen *screen) -{ - screen->texture_create = softpipe_texture_create_screen; - screen->texture_release = softpipe_texture_release_screen; - screen->get_tex_surface = softpipe_get_tex_surface_screen; -} +/************************************************************************** + * + * Copyright 2006 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 + * Michel Dänzer + */ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_inlines.h" +#include "pipe/p_util.h" +#include "pipe/p_winsys.h" + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_texture.h" +#include "sp_tile_cache.h" + + +/* Simple, maximally packed layout. + */ + +static unsigned minify( unsigned d ) +{ + return MAX2(1, d>>1); +} + + +static void +softpipe_texture_layout(struct softpipe_texture * spt) +{ + struct pipe_texture *pt = &spt->base; + unsigned level; + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned depth = pt->depth[0]; + + spt->buffer_size = 0; + + for (level = 0; level <= pt->last_level; level++) { + pt->width[level] = width; + pt->height[level] = height; + pt->depth[level] = depth; + + spt->level_offset[level] = spt->buffer_size; + + spt->buffer_size += ((pt->compressed) ? MAX2(1, height/4) : height) * + ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) * + width * pt->cpp; + + width = minify(width); + height = minify(height); + depth = minify(depth); + } +} + + +static struct pipe_texture * +softpipe_texture_create_screen(struct pipe_screen *screen, + const struct pipe_texture *templat) +{ + struct pipe_winsys *ws = screen->winsys; + struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture); + if (!spt) + return NULL; + + spt->base = *templat; + spt->base.refcount = 1; + spt->base.screen = screen; + + softpipe_texture_layout(spt); + + spt->buffer = ws->buffer_create(ws, 32, + PIPE_BUFFER_USAGE_PIXEL, + spt->buffer_size); + if (!spt->buffer) { + FREE(spt); + return NULL; + } + + assert(spt->base.refcount == 1); + + return &spt->base; +} + + +static void +softpipe_texture_release_screen(struct pipe_screen *screen, + struct pipe_texture **pt) +{ + if (!*pt) + return; + + /* + DBG("%s %p refcount will be %d\n", + __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); + */ + if (--(*pt)->refcount <= 0) { + struct softpipe_texture *spt = softpipe_texture(*pt); + + /* + DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); + */ + + pipe_buffer_reference(screen->winsys, &spt->buffer, NULL); + + FREE(spt); + } + *pt = NULL; +} + + +static struct pipe_surface * +softpipe_get_tex_surface_screen(struct pipe_screen *screen, + struct pipe_texture *pt, + unsigned face, unsigned level, unsigned zslice) +{ + struct pipe_winsys *ws = screen->winsys; + struct softpipe_texture *spt = softpipe_texture(pt); + struct pipe_surface *ps; + + assert(level <= pt->last_level); + + ps = ws->surface_alloc(ws); + if (ps) { + assert(ps->refcount); + assert(ps->winsys); + pipe_buffer_reference(ws, &ps->buffer, spt->buffer); + ps->format = pt->format; + ps->cpp = pt->cpp; + ps->width = pt->width[level]; + ps->height = pt->height[level]; + ps->pitch = ps->width; + ps->offset = spt->level_offset[level]; + + if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) { + ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) * + (pt->compressed ? ps->height/4 : ps->height) * + ps->width * ps->cpp; + } + else { + assert(face == 0); + assert(zslice == 0); + } + } + return ps; +} + + +static void +softpipe_texture_update(struct pipe_context *pipe, + struct pipe_texture *texture) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + uint unit; + for (unit = 0; unit < softpipe->num_textures; unit++) { + if (softpipe->texture[unit] == texture) { + sp_flush_tile_cache(softpipe, softpipe->tex_cache[unit]); + } + } +} + + +void +softpipe_init_texture_funcs( struct softpipe_context *softpipe ) +{ + softpipe->pipe.texture_update = softpipe_texture_update; +} + + +void +softpipe_init_screen_texture_funcs(struct pipe_screen *screen) +{ + screen->texture_create = softpipe_texture_create_screen; + screen->texture_release = softpipe_texture_release_screen; + screen->get_tex_surface = softpipe_get_tex_surface_screen; +} diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index 1501b52f3e..b64948f0f3 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -100,7 +100,7 @@ struct pipe_context { void * (*create_sampler_state)(struct pipe_context *, const struct pipe_sampler_state *); - void (*bind_sampler_state)(struct pipe_context *, unsigned unit, void *); + void (*bind_sampler_states)(struct pipe_context *, unsigned num, void **); void (*delete_sampler_state)(struct pipe_context *, void *); void * (*create_rasterizer_state)(struct pipe_context *, @@ -148,9 +148,9 @@ struct pipe_context { /* Currently a sampler is constrained to sample from a single texture: */ - void (*set_sampler_texture)( struct pipe_context *, - unsigned sampler, - struct pipe_texture * ); + void (*set_sampler_textures)( struct pipe_context *, + unsigned num, + struct pipe_texture ** ); void (*set_viewport_state)( struct pipe_context *, const struct pipe_viewport_state * ); diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 92263cb688..1000f98ffc 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -120,10 +120,11 @@ update_samplers(struct st_context *st) const struct st_fragment_program *fs = st->fp; GLuint su; + st->state.num_samplers = 0; + /* loop over sampler units (aka tex image units) */ for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) { struct pipe_sampler_state sampler; - const struct cso_sampler *cso; memset(&sampler, 0, sizeof(sampler)); @@ -168,17 +169,16 @@ update_samplers(struct st_context *st) = st_compare_func_to_pipe(texobj->CompareFunc); } + st->state.num_samplers = su + 1; + /* XXX more sampler state here */ } - cso = st_cached_sampler_state(st, &sampler); - - if (cso != st->state.sampler[su]) { - /* state has changed */ - st->state.sampler[su] = cso; - st->pipe->bind_sampler_state(st->pipe, su, cso->data); - } + st->state.sampler[su] = st_cached_sampler_state(st, &sampler)->data; } + + st->pipe->bind_sampler_states(st->pipe, st->state.num_samplers, + st->state.sampler); } diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 697d2cdfb4..e53a897637 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -37,6 +37,7 @@ #include "st_texture.h" #include "st_cb_texture.h" #include "pipe/p_context.h" +#include "pipe/p_inlines.h" /** @@ -51,6 +52,8 @@ update_textures(struct st_context *st) struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; GLuint unit; + st->state.num_textures = 0; + for (unit = 0; unit < st->ctx->Const.MaxTextureCoordUnits; unit++) { const GLuint su = fprog->Base.SamplerUnits[unit]; struct gl_texture_object *texObj = st->ctx->Texture.Unit[su]._Current; @@ -62,6 +65,8 @@ update_textures(struct st_context *st) retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); /* XXX retval indicates whether there's a texture border */ + + st->state.num_textures = unit + 1; } /* XXX: need to ensure that textures are unbound/removed from @@ -70,18 +75,16 @@ update_textures(struct st_context *st) */ pt = st_get_stobj_texture(stObj); - - if (st->state.sampler_texture[unit] != pt) { - st->state.sampler_texture[unit] = pt; - st->pipe->set_sampler_texture(st->pipe, unit, pt); - } + pipe_texture_reference(&st->state.sampler_texture[unit], pt); if (stObj && stObj->dirtyData) { st->pipe->texture_update(st->pipe, pt); stObj->dirtyData = GL_FALSE; } - } + + st->pipe->set_sampler_textures(st->pipe, st->state.num_textures, + st->state.sampler_texture); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 65c9fda9cb..dee4c4132a 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -641,7 +641,6 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, const GLfloat *color, GLboolean invertTex) { - const GLuint unit = 0; struct pipe_context *pipe = ctx->st->pipe; GLfloat x0, y0, x1, y1; GLuint maxSize; @@ -684,7 +683,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; sampler.normalized_coords = 1; cso = st_cached_sampler_state(ctx->st, &sampler); - pipe->bind_sampler_state(pipe, unit, cso->data); + pipe->bind_sampler_states(pipe, 1, (void**)&cso->data); } /* viewport state: viewport matching window dims */ @@ -705,7 +704,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* texture state: */ { - pipe->set_sampler_texture(pipe, unit, pt); + pipe->set_sampler_textures(pipe, 1, &pt); } /* Compute window coords (y=0=bottom) with pixel zoom. @@ -727,8 +726,10 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, 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_texture(pipe, unit, ctx->st->state.sampler_texture[unit]); - pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]->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); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 1fbf9721e7..897a5109b7 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -76,7 +76,7 @@ struct st_context struct { const struct cso_alpha_test *alpha_test; const struct cso_blend *blend; - const struct cso_sampler *sampler[PIPE_MAX_SAMPLERS]; + void *sampler[PIPE_MAX_SAMPLERS]; const struct cso_depth_stencil_alpha *depth_stencil; const struct cso_rasterizer *rasterizer; const struct cso_fragment_shader *fs; @@ -90,6 +90,9 @@ struct st_context struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_viewport_state viewport; + + GLuint num_samplers; + GLuint num_textures; } state; struct { diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 841d77abbc..3723e26d45 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -284,7 +284,7 @@ st_render_mipmap(struct st_context *st, */ sampler.min_lod = sampler.max_lod = srcLevel; sampler_cso = pipe->create_sampler_state(pipe, &sampler); - pipe->bind_sampler_state(pipe, 0, sampler_cso); + pipe->bind_sampler_states(pipe, 1, &sampler_cso); simple_viewport(pipe, pt->width[dstLevel], pt->height[dstLevel]); @@ -293,7 +293,7 @@ st_render_mipmap(struct st_context *st, * the right mipmap level. */ /*pt->first_level = srcLevel;*/ - pipe->set_sampler_texture(pipe, 0, pt); + pipe->set_sampler_textures(pipe, 1, &pt); draw_quad(st->ctx); @@ -310,9 +310,10 @@ st_render_mipmap(struct st_context *st, pipe->bind_fs_state(pipe, st->state.fs->data); if (st->state.vs) pipe->bind_vs_state(pipe, st->state.vs->cso->data); - if (st->state.sampler[0]) - pipe->bind_sampler_state(pipe, 0, st->state.sampler[0]->data); - pipe->set_sampler_texture(pipe, 0, st->state.sampler_texture[0]); + pipe->bind_sampler_states(pipe, st->state.num_samplers, + st->state.sampler); + pipe->set_sampler_textures(pipe, st->state.num_textures, + st->state.sampler_texture); pipe->set_viewport_state(pipe, &st->state.viewport); return 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_context.h') 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 088c6404fcae07dec6dcf16d2cb0777aa7b446ad Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 17 Mar 2008 15:48:13 -0600 Subject: gallium: use new gallium utility code for generating mipmaps --- src/mesa/state_tracker/st_context.h | 13 +- src/mesa/state_tracker/st_gen_mipmap.c | 225 +-------------------------------- 2 files changed, 8 insertions(+), 230 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index e81aebba3d..09bab7bfb1 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -146,18 +146,7 @@ struct st_context struct st_fragment_program *combined_prog; } bitmap; - /** 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; - struct st_fragment_program *stfp; - struct st_vertex_program *stvp; - } gen_mipmap; + struct gen_mipmap_state *gen_mipmap; struct cso_context *cso_context; }; diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index e878925990..5f09d9bb06 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -37,6 +37,8 @@ #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" #include "cso_cache/cso_context.h" @@ -49,55 +51,6 @@ #include "st_cb_texture.h" - -static struct st_fragment_program * -make_tex_fragment_program(GLcontext *ctx) -{ - struct st_fragment_program *stfp; - struct gl_program *p; - GLuint ic = 0; - - p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); - if (!p) - return NULL; - - p->NumInstructions = 2; - - p->Instructions = _mesa_alloc_instructions(p->NumInstructions); - if (!p->Instructions) { - ctx->Driver.DeleteProgram(ctx, p); - return NULL; - } - _mesa_init_instructions(p->Instructions, p->NumInstructions); - - /* TEX result.color, fragment.texcoord[0], texture[0], 2D; */ - p->Instructions[ic].Opcode = OPCODE_TEX; - p->Instructions[ic].DstReg.File = PROGRAM_OUTPUT; - p->Instructions[ic].DstReg.Index = FRAG_RESULT_COLR; - p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT; - p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0; - p->Instructions[ic].TexSrcUnit = 0; - p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX; - ic++; - - /* END; */ - p->Instructions[ic++].Opcode = OPCODE_END; - - assert(ic == p->NumInstructions); - - p->InputsRead = FRAG_BIT_TEX0; - p->OutputsWritten = (1 << FRAG_RESULT_COLR); - - stfp = (struct st_fragment_program *) p; - - st_translate_fragment_program(ctx->st, stfp, NULL); - - return stfp; -} - - - - /** * one-time init for generate mipmap * XXX Note: there may be other times we need no-op/simple state like this. @@ -106,117 +59,18 @@ make_tex_fragment_program(GLcontext *ctx) void st_init_generate_mipmap(struct st_context *st) { - struct pipe_context *pipe = st->pipe; - struct pipe_blend_state blend; - struct pipe_rasterizer_state rasterizer; - struct pipe_depth_stencil_alpha_state depthstencil; - - /* 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; - st->gen_mipmap.blend = blend; - st->gen_mipmap.blend_cso = pipe->create_blend_state(pipe, &blend); - - memset(&depthstencil, 0, sizeof(depthstencil)); - st->gen_mipmap.depthstencil_cso = pipe->create_depth_stencil_alpha_state(pipe, &depthstencil); - - /* Note: we're assuming zero is valid for all non-specified fields */ - memset(&rasterizer, 0, sizeof(rasterizer)); - rasterizer.front_winding = PIPE_WINDING_CW; - rasterizer.cull_mode = PIPE_WINDING_NONE; - st->gen_mipmap.rasterizer_cso = pipe->create_rasterizer_state(pipe, &rasterizer); - - st->gen_mipmap.stfp = make_tex_fragment_program(st->ctx); - st->gen_mipmap.stvp = st_make_passthrough_vertex_shader(st, GL_FALSE); + st->gen_mipmap = util_create_gen_mipmap(st->pipe); } void st_destroy_generate_mipmpap(struct st_context *st) { - struct pipe_context *pipe = st->pipe; - - pipe->delete_blend_state(pipe, st->gen_mipmap.blend_cso); - pipe->delete_depth_stencil_alpha_state(pipe, st->gen_mipmap.depthstencil_cso); - pipe->delete_rasterizer_state(pipe, st->gen_mipmap.rasterizer_cso); - - /* XXX free stfp, stvp */ + util_destroy_gen_mipmap(st->gen_mipmap); + st->gen_mipmap = NULL; } -static void -simple_viewport(struct pipe_context *pipe, uint width, uint height) -{ - struct pipe_viewport_state vp; - - vp.scale[0] = 0.5 * width; - vp.scale[1] = -0.5 * height; - 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.0; - vp.translate[3] = 0.0; - - pipe->set_viewport_state(pipe, &vp); -} - - - -/* - * Draw simple [-1,1]x[-1,1] quad - */ -static void -draw_quad(GLcontext *ctx) -{ - GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */ - GLuint i; - GLfloat sLeft = 0.0, sRight = 1.0; - GLfloat tTop = 1.0, tBot = 0.0; - GLfloat x0 = -1.0, x1 = 1.0; - GLfloat y0 = -1.0, y1 = 1.0; - - /* upper-left */ - verts[0][0][0] = x0; /* attr[0].x */ - verts[0][0][1] = y0; /* attr[0].y */ - verts[0][1][0] = sLeft; /* attr[1].s */ - verts[0][1][1] = tTop; /* attr[1].t */ - - /* upper-right */ - verts[1][0][0] = x1; - verts[1][0][1] = y0; - verts[1][1][0] = sRight; - verts[1][1][1] = tTop; - - /* lower-right */ - verts[2][0][0] = x1; - verts[2][0][1] = y1; - verts[2][1][0] = sRight; - verts[2][1][1] = tBot; - - /* lower-left */ - verts[3][0][0] = x0; - verts[3][0][1] = y1; - verts[3][1][0] = sLeft; - verts[3][1][1] = tBot; - - /* same for all verts: */ - for (i = 0; i < 4; i++) { - verts[i][0][2] = 0.0; /*Z*/ - verts[i][0][3] = 1.0; /*W*/ - verts[i][1][2] = 0.0; /*R*/ - verts[i][1][3] = 1.0; /*Q*/ - } - - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, GL_TRUE); -} - - - /** * Generate mipmap levels using hardware rendering. * \return TRUE if successful, FALSE if not possible @@ -229,12 +83,7 @@ st_render_mipmap(struct st_context *st, { struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_framebuffer_state fb; - struct pipe_sampler_state sampler; - void *sampler_cso; - const uint face = _mesa_tex_target_to_face(target), zslice = 0; - /*const uint first_level_save = pt->first_level;*/ - uint dstLevel; + const uint face = _mesa_tex_target_to_face(target); assert(target != GL_TEXTURE_3D); /* not done yet */ @@ -243,67 +92,7 @@ st_render_mipmap(struct st_context *st, return FALSE; } - /* 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; - - - /* 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->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 - * fallback path... - */ - for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { - const uint srcLevel = dstLevel - 1; - - /* - * Setup framebuffer / dest surface - */ - fb.cbufs[0] = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); - pipe->set_framebuffer_state(pipe, &fb); - - /* - * Setup sampler state - * Note: we should only have to set the min/max LOD clamps to ensure - * we grab texels from the right mipmap level. But some hardware - * has trouble with min clamping so we also set the lod_bias to - * try to work around that. - */ - sampler.min_lod = sampler.max_lod = srcLevel; - sampler.lod_bias = srcLevel; - sampler_cso = pipe->create_sampler_state(pipe, &sampler); - pipe->bind_sampler_states(pipe, 1, &sampler_cso); - - simple_viewport(pipe, pt->width[dstLevel], pt->height[dstLevel]); - - pipe->set_sampler_textures(pipe, 1, &pt); - - draw_quad(st->ctx); - - pipe->flush(pipe, PIPE_FLUSH_WAIT); - - /*pipe->texture_update(pipe, pt); not really needed */ - - pipe->delete_sampler_state(pipe, sampler_cso); - } + util_gen_mipmap(st->gen_mipmap, pt, face, baseLevel, lastLevel); /* restore pipe state */ #if 0 -- cgit v1.2.3 From 0df877a0ee68359d106ba84e3dd3b7c42ae20d5a Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 18 Mar 2008 17:16:23 -0600 Subject: gallium: plug in and init GL_EXT_framebuffer_blit function/extension --- src/mesa/state_tracker/st_context.c | 5 +++++ src/mesa/state_tracker/st_context.h | 4 ++++ src/mesa/state_tracker/st_extensions.c | 1 + 3 files changed, 10 insertions(+) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 5458ab420e..e1fc885e0e 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -36,6 +36,7 @@ #include "st_context.h" #include "st_cb_accum.h" #include "st_cb_bufferobjects.h" +#include "st_cb_blit.h" #include "st_cb_clear.h" #include "st_cb_drawpixels.h" #include "st_cb_fbo.h" @@ -100,6 +101,7 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st_init_atoms( st ); st_init_draw( st ); st_init_generate_mipmap(st); + st_init_blit(st); for (i = 0; i < PIPE_MAX_SAMPLERS; i++) st->state.sampler_list[i] = &st->state.samplers[i]; @@ -151,6 +153,8 @@ static void st_destroy_context_priv( struct st_context *st ) draw_destroy(st->draw); st_destroy_atoms( st ); st_destroy_draw( st ); + st_destroy_generate_mipmap(st); + st_destroy_blit(st); _vbo_DestroyContext(st->ctx); @@ -217,6 +221,7 @@ void st_init_driver_functions(struct dd_function_table *functions) st_init_accum_functions(functions); st_init_bufferobject_functions(functions); + st_init_blit_functions(functions); st_init_clear_functions(functions); st_init_drawpixels_functions(functions); st_init_fbo_functions(functions); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 09bab7bfb1..63150dbeaf 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -40,6 +40,9 @@ struct draw_context; struct draw_stage; struct cso_cache; struct cso_blend; +struct gen_mipmap_state; +struct blit_state; + #define ST_NEW_MESA 0x1 /* Mesa state has changed */ #define ST_NEW_FRAGMENT_PROGRAM 0x2 @@ -147,6 +150,7 @@ struct st_context } bitmap; struct gen_mipmap_state *gen_mipmap; + struct blit_state *blit; struct cso_context *cso_context; }; diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 99d2a5fb9e..0962b5f74c 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -143,6 +143,7 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.EXT_blend_logic_op = GL_TRUE; ctx->Extensions.EXT_blend_minmax = GL_TRUE; ctx->Extensions.EXT_blend_subtract = GL_TRUE; + ctx->Extensions.EXT_framebuffer_blit = GL_TRUE; ctx->Extensions.EXT_framebuffer_object = GL_TRUE; ctx->Extensions.EXT_fog_coord = GL_TRUE; ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE; -- 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_context.h') 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_context.h') 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_context.h') 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 f6cd3778c54c0329c3f497a7368a158087d653d3 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 20 Mar 2008 14:50:17 -0600 Subject: gallium: glBitmap code now separe from glDraw/CopyPixels code Also, glBitmap now re-uses the vertex buffer to avoid frequent allocations/ deallocations. And, use u_simple_shaders utility code. --- src/mesa/sources | 1 + src/mesa/state_tracker/st_cb_drawpixels.c | 295 +----------------------------- src/mesa/state_tracker/st_cb_drawpixels.h | 4 - src/mesa/state_tracker/st_context.c | 7 +- src/mesa/state_tracker/st_context.h | 3 + 5 files changed, 16 insertions(+), 294 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/sources b/src/mesa/sources index 287af7121a..d109dce5bc 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -172,6 +172,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_texture.c \ state_tracker/st_atom_viewport.c \ state_tracker/st_cb_accum.c \ + state_tracker/st_cb_bitmap.c \ state_tracker/st_cb_blit.c \ state_tracker/st_cb_bufferobjects.c \ state_tracker/st_cb_clear.c \ diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 99d5e3e848..b4cd93cd54 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -56,6 +56,7 @@ #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" #include "cso_cache/cso_context.h" @@ -85,140 +86,6 @@ is_passthrough_program(const struct gl_fragment_program *prog) } -/** - * Make fragment program for glBitmap: - * Sample the texture and kill the fragment if the bit is 0. - * This program will be combined with the user's fragment program. - */ -static struct st_fragment_program * -make_bitmap_fragment_program(GLcontext *ctx) -{ - struct st_fragment_program *stfp; - struct gl_program *p; - GLuint ic = 0; - - p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); - if (!p) - return NULL; - - p->NumInstructions = 5; - - p->Instructions = _mesa_alloc_instructions(p->NumInstructions); - if (!p->Instructions) { - ctx->Driver.DeleteProgram(ctx, p); - return NULL; - } - _mesa_init_instructions(p->Instructions, p->NumInstructions); - - /* TEX tmp0, fragment.texcoord[0], texture[0], 2D; */ - p->Instructions[ic].Opcode = OPCODE_TEX; - p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY; - p->Instructions[ic].DstReg.Index = 0; - p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT; - p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0; - p->Instructions[ic].TexSrcUnit = 0; - p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX; - ic++; - - /* SWZ tmp0.x, tmp0.x, 1111; # tmp0.x = 1.0 */ - p->Instructions[ic].Opcode = OPCODE_SWZ; - p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY; - p->Instructions[ic].DstReg.Index = 0; - p->Instructions[ic].DstReg.WriteMask = WRITEMASK_X; - p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - p->Instructions[ic].SrcReg[0].Index = 0; - p->Instructions[ic].SrcReg[0].Swizzle - = MAKE_SWIZZLE4(SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE ); - ic++; - - /* SUB tmp0, tmp0.wwww, tmp0.xxxx; # tmp0.w -= 1 */ - p->Instructions[ic].Opcode = OPCODE_SUB; - p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY; - p->Instructions[ic].DstReg.Index = 0; - p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - p->Instructions[ic].SrcReg[0].Index = 0; - p->Instructions[ic].SrcReg[0].Swizzle = SWIZZLE_WWWW; - p->Instructions[ic].SrcReg[1].File = PROGRAM_TEMPORARY; - p->Instructions[ic].SrcReg[1].Index = 0; - p->Instructions[ic].SrcReg[1].Swizzle = SWIZZLE_XXXX; /* 1.0 */ - ic++; - - /* KIL if tmp0 < 0 */ - p->Instructions[ic].Opcode = OPCODE_KIL; - p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - p->Instructions[ic].SrcReg[0].Index = 0; - ic++; - - /* END; */ - p->Instructions[ic++].Opcode = OPCODE_END; - - assert(ic == p->NumInstructions); - - p->InputsRead = FRAG_BIT_TEX0; - p->OutputsWritten = 0x0; - - stfp = (struct st_fragment_program *) p; - stfp->Base.UsesKill = GL_TRUE; - st_translate_fragment_program(ctx->st, stfp, NULL); - - return stfp; -} - - -/** - * Combine basic bitmap fragment program with the user-defined program. - */ -static struct st_fragment_program * -combined_bitmap_fragment_program(GLcontext *ctx) -{ - struct st_context *st = ctx->st; - struct st_fragment_program *stfp; - - if (!st->bitmap.program) { - /* create the basic bitmap fragment program */ - st->bitmap.program = make_bitmap_fragment_program(ctx); - } - - if (st->bitmap.user_prog_sn == st->fp->serialNo) { - /* re-use */ - stfp = st->bitmap.combined_prog; - } - else { - /* Concatenate the bitmap program with the current user-defined program. - */ - stfp = (struct st_fragment_program *) - _mesa_combine_programs(ctx, - &st->bitmap.program->Base.Base, - &st->fp->Base.Base); - -#if 0 - { - struct gl_program *p = &stfp->Base.Base; - printf("Combined bitmap program:\n"); - _mesa_print_program(p); - printf("InputsRead: 0x%x\n", p->InputsRead); - printf("OutputsWritten: 0x%x\n", p->OutputsWritten); - _mesa_print_parameter_list(p->Parameters); - } -#endif - - /* translate to TGSI tokens */ - st_translate_fragment_program(st, stfp, NULL); - - /* save new program, update serial numbers */ - st->bitmap.user_prog_sn = st->fp->serialNo; - st->bitmap.combined_prog = stfp; - } - - /* Ideally we'd have updated the pipe constants during the normal - * st/atom mechanism. But we can't since this is specific to glBitmap. - */ - st_upload_constants(st, stfp->Base.Base.Parameters, PIPE_SHADER_FRAGMENT); - - return stfp; -} - - /** * Make fragment shader for glDraw/CopyPixels. This shader is made @@ -351,7 +218,7 @@ 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). */ -struct st_vertex_program * +static struct st_vertex_program * st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor) { /* only make programs once and re-use */ @@ -655,14 +522,14 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_save_rasterizer(cso); cso_save_viewport(cso); - /* setup state: just scissor */ + /* rasterizer state: just scissor */ { - struct pipe_rasterizer_state setup; - memset(&setup, 0, sizeof(setup)); + struct pipe_rasterizer_state rasterizer; + memset(&rasterizer, 0, sizeof(rasterizer)); if (ctx->Scissor.Enabled) - setup.scissor = 1; + rasterizer.scissor = 1; - cso_set_rasterizer(cso, &setup); + cso_set_rasterizer(cso, &rasterizer); } /* fragment shader state: TEX lookup program */ @@ -990,153 +857,6 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, -/** - * Create a texture which represents a bitmap image. - */ -static struct pipe_texture * -make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, - const struct gl_pixelstore_attrib *unpack, - const GLubyte *bitmap) -{ - struct pipe_context *pipe = ctx->st->pipe; - struct pipe_screen *screen = pipe->screen; - struct pipe_surface *surface; - uint format = 0, cpp, comp; - ubyte *dest; - struct pipe_texture *pt; - int row, col; - - /* find a texture format we know */ - if (screen->is_format_supported( screen, PIPE_FORMAT_U_I8, PIPE_TEXTURE )) { - format = PIPE_FORMAT_U_I8; - cpp = 1; - comp = 0; - } - else if (screen->is_format_supported( screen, PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_TEXTURE )) { - format = PIPE_FORMAT_A8R8G8B8_UNORM; - cpp = 4; - comp = 3; /* alpha channel */ /*XXX little-endian dependency */ - } - else { - /* XXX support more formats */ - assert( 0 ); - } - - /** - * Create a texture. - */ - pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, width, height, - 1, 0); - if (!pt) - return NULL; - - if (unpack->BufferObj && unpack->BufferObj->Name) { - /* - pt->region = buffer_object_region(unpack->BufferObj); - */ - printf("st_Bitmap (sourcing from PBO not implemented yet)\n"); - } - - surface = screen->get_tex_surface(screen, pt, 0, 0, 0); - - /* map texture surface */ - dest = pipe_surface_map(surface); - - /* Put image into texture surface. - * Note that the image is actually going to be upside down in - * the texture. We deal with that with texcoords. - */ - - for (row = 0; row < height; row++) { - const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack, - bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); - ubyte *destRow = dest + row * surface->pitch * cpp; - - if (unpack->LsbFirst) { - /* Lsb first */ - GLubyte mask = 1U << (unpack->SkipPixels & 0x7); - for (col = 0; col < width; col++) { - - /* set texel to 255 if bit is set */ - destRow[comp] = (*src & mask) ? 255 : 0; - destRow += cpp; - - if (mask == 128U) { - src++; - mask = 1U; - } - else { - mask = mask << 1; - } - } - - /* get ready for next row */ - if (mask != 1) - src++; - } - else { - /* Msb first */ - GLubyte mask = 128U >> (unpack->SkipPixels & 0x7); - for (col = 0; col < width; col++) { - - /* set texel to 255 if bit is set */ - destRow[comp] =(*src & mask) ? 255 : 0; - destRow += cpp; - - if (mask == 1U) { - src++; - mask = 128U; - } - else { - mask = mask >> 1; - } - } - - /* get ready for next row */ - if (mask != 128) - src++; - } - - } /* row */ - - /* Release surface */ - pipe_surface_unmap(surface); - pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, pt, 0, 0x1); - - pt->format = format; - - return pt; -} - - - -static void -st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, - const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap ) -{ - struct st_fragment_program *stfp; - struct st_vertex_program *stvp; - struct st_context *st = ctx->st; - struct pipe_texture *pt; - - stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE); - stfp = combined_bitmap_fragment_program(ctx); - - st_validate_state(st); - - pt = make_bitmap_texture(ctx, width, height, unpack, bitmap); - if (pt) { - draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], - width, height, 1.0, 1.0, - pt, stvp, stfp, - ctx->Current.RasterColor, GL_FALSE); - - pipe_texture_reference(&pt, NULL); - } -} - - static void copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, @@ -1337,5 +1057,4 @@ void st_init_drawpixels_functions(struct dd_function_table *functions) { functions->DrawPixels = st_DrawPixels; functions->CopyPixels = st_CopyPixels; - functions->Bitmap = st_Bitmap; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.h b/src/mesa/state_tracker/st_cb_drawpixels.h index b8b906f06b..71ba487020 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.h +++ b/src/mesa/state_tracker/st_cb_drawpixels.h @@ -30,10 +30,6 @@ #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_context.c b/src/mesa/state_tracker/st_context.c index b1681be2eb..d9e8722976 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -35,8 +35,9 @@ #include "st_public.h" #include "st_context.h" #include "st_cb_accum.h" -#include "st_cb_bufferobjects.h" +#include "st_cb_bitmap.h" #include "st_cb_blit.h" +#include "st_cb_bufferobjects.h" #include "st_cb_clear.h" #include "st_cb_drawpixels.h" #include "st_cb_fbo.h" @@ -154,6 +155,7 @@ static void st_destroy_context_priv( struct st_context *st ) st_destroy_atoms( st ); st_destroy_draw( st ); st_destroy_generate_mipmap(st); + st_destroy_bitmap(st); st_destroy_blit(st); st_destroy_clear(st); @@ -221,8 +223,9 @@ void st_init_driver_functions(struct dd_function_table *functions) _mesa_init_glsl_driver_functions(functions); st_init_accum_functions(functions); - st_init_bufferobject_functions(functions); + st_init_bitmap_functions(functions); st_init_blit_functions(functions); + st_init_bufferobject_functions(functions); st_init_clear_functions(functions); st_init_drawpixels_functions(functions); st_init_fbo_functions(functions); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 2563c7fed0..2d37086799 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -147,6 +147,9 @@ 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; + void *vs; + float vertices[4][3][4]; /**< vertex pos + color + texcoord */ + struct pipe_buffer *vbuf; } bitmap; /** for glClear */ -- 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_context.h') 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 c62b197b528293abb56b099503344e3cdd7d6c40 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 28 Mar 2008 14:53:47 -0600 Subject: gallium: implement a glBitmap cache The bitmap cache attempts to accumulate a series of glBitmap calls in a buffer to effectively render a whole bunch of bitmaps at once. The cache can be disabled, if needed, by setting UseBitmapCache=GL_FALSE. --- src/mesa/state_tracker/st_atom.c | 3 + src/mesa/state_tracker/st_cb_bitmap.c | 234 ++++++++++++++++++++++++++++++++-- src/mesa/state_tracker/st_cb_bitmap.h | 5 + src/mesa/state_tracker/st_cb_flush.c | 3 + src/mesa/state_tracker/st_context.c | 1 + src/mesa/state_tracker/st_context.h | 2 + 6 files changed, 236 insertions(+), 12 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 0e22a2fa6e..40e4142631 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -32,6 +32,7 @@ #include "pipe/p_defines.h" #include "st_context.h" #include "st_atom.h" +#include "st_cb_bitmap.h" #include "st_program.h" @@ -147,6 +148,8 @@ void st_validate_state( struct st_context *st ) struct st_state_flags *state = &st->dirty; GLuint i; + st_flush_bitmap_cache(st); + check_program_state( st ); if (state->st == 0) diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 64b1882424..e46dcbf661 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -59,6 +59,31 @@ +/** + * The bitmap cache attempts to accumulate multiple glBitmap calls in a + * buffer which is then rendered en mass upon a flush, state change, etc. + * A wide, short buffer is used to target the common case of a series + * of glBitmap calls being used to draw text. + */ +static GLboolean UseBitmapCache = 0*GL_TRUE; + + +#define BITMAP_CACHE_WIDTH 512 +#define BITMAP_CACHE_HEIGHT 32 + +struct bitmap_cache +{ + /** An I8 texture image: */ + GLubyte buffer[BITMAP_CACHE_HEIGHT][BITMAP_CACHE_WIDTH]; + GLboolean empty; + /** Window pos to render the cached image */ + GLint xpos, ypos; + struct pipe_texture *texture; +}; + + + + /** * Make fragment program for glBitmap: * Sample the texture and kill the fragment if the bit is 0. @@ -390,16 +415,18 @@ setup_bitmap_vertex_data(struct st_context *st, static void draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, GLsizei width, GLsizei height, - struct pipe_texture *pt, - struct st_fragment_program *stfp) + struct pipe_texture *pt) { struct st_context *st = ctx->st; struct pipe_context *pipe = ctx->st->pipe; struct cso_context *cso = ctx->st->cso_context; + struct st_fragment_program *stfp; GLuint maxSize; + stfp = combined_bitmap_fragment_program(ctx); + /* limit checks */ - /* XXX if DrawPixels image is larger than max texture size, break + /* XXX if the bitmap is larger than the max texture size, break * it up into chunks. */ maxSize = 1 << (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1); @@ -467,18 +494,185 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, +static void +init_bitmap_cache(struct st_context *st) +{ + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; + enum pipe_format format; + + st->bitmap.cache = CALLOC_STRUCT(bitmap_cache); + if (!st->bitmap.cache) + return; + + /* find a usable texture format */ + if (screen->is_format_supported(screen, PIPE_FORMAT_U_I8, PIPE_TEXTURE)) { + format = PIPE_FORMAT_U_I8; + } + else { + /* XXX support more formats */ + assert(0); + } + + st->bitmap.cache->texture + = st_texture_create(st, PIPE_TEXTURE_2D, format, 0, + BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT, 1, 0); + if (!st->bitmap.cache->texture) { + FREE(st->bitmap.cache); + st->bitmap.cache = NULL; + return; + } + + st->bitmap.cache->empty = GL_TRUE; +} + + +/** + * If there's anything in the bitmap cache, draw/flush it now. + */ +void +st_flush_bitmap_cache(struct st_context *st) +{ + if (!st->bitmap.cache->empty) { + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_surface *surf; + void *dest; + + /* update the texture map image */ + surf = screen->get_tex_surface(screen, st->bitmap.cache->texture, 0, 0, 0); + dest = pipe_surface_map(surf); + memcpy(dest, st->bitmap.cache->buffer, sizeof(st->bitmap.cache->buffer)); + pipe_surface_unmap(surf); + pipe_surface_reference(&surf, NULL); + + pipe->texture_update(pipe, st->bitmap.cache->texture, 0, 0x1); + + draw_bitmap_quad(st->ctx, + st->bitmap.cache->xpos, + st->bitmap.cache->ypos, + st->ctx->Current.RasterPos[2], + BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT, + st->bitmap.cache->texture); + + memset(st->bitmap.cache->buffer, 0, sizeof(st->bitmap.cache->buffer)); + st->bitmap.cache->empty = GL_TRUE; + } +} + + +/** + * Try to accumulate this glBitmap call in the bitmap cache. + * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc. + */ +static GLboolean +accum_bitmap(struct st_context *st, + GLint x, GLint y, GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap ) +{ + int row, col; + int px = -999, py; + + if (width > BITMAP_CACHE_WIDTH || + height > BITMAP_CACHE_HEIGHT) + return GL_FALSE; /* too big to cache */ + + if (!st->bitmap.cache->empty) { + px = x - st->bitmap.cache->xpos; /* pos in buffer */ + py = y - st->bitmap.cache->ypos; + if (px < 0 || px + width > BITMAP_CACHE_WIDTH || + py < 0 || py + height > BITMAP_CACHE_HEIGHT) { + /* This bitmap would extend beyond cache bounds, + * so flush and continue. + */ + st_flush_bitmap_cache(st); + } + } + + if (st->bitmap.cache->empty) { + /* Initialize. Center bitmap vertically in the buffer. */ + px = 0; + py = (BITMAP_CACHE_HEIGHT - height) / 2; + st->bitmap.cache->xpos = x; + st->bitmap.cache->ypos = y - py; + st->bitmap.cache->empty = GL_FALSE; + } + + assert(px != -999); + + /* XXX try to combine this code with code in make_bitmap_texture() */ +#define SET_PIXEL(COL, ROW) \ + st->bitmap.cache->buffer[py + (ROW)][px + (COL)] = 0xff; + + for (row = 0; row < height; row++) { + const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack, + bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); + + if (unpack->LsbFirst) { + /* Lsb first */ + GLubyte mask = 1U << (unpack->SkipPixels & 0x7); + for (col = 0; col < width; col++) { + + if (*src & mask) { + SET_PIXEL(col, row); + } + + if (mask == 128U) { + src++; + mask = 1U; + } + else { + mask = mask << 1; + } + } + + /* get ready for next row */ + if (mask != 1) + src++; + } + else { + /* Msb first */ + GLubyte mask = 128U >> (unpack->SkipPixels & 0x7); + for (col = 0; col < width; col++) { + + if (*src & mask) { + SET_PIXEL(col, row); + } + + if (mask == 1U) { + src++; + mask = 128U; + } + else { + mask = mask >> 1; + } + } + + /* get ready for next row */ + if (mask != 128) + src++; + } + + } /* row */ + + return GL_TRUE; /* accumulated */ +} + + + +/** + * Called via ctx->Driver.Bitmap() + */ static void st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap ) { - struct st_fragment_program *stfp; struct st_context *st = ctx->st; struct pipe_texture *pt; st_validate_state(st); - stfp = combined_bitmap_fragment_program(ctx); - if (!st->bitmap.vs) { /* create pass-through vertex shader now */ const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, @@ -491,26 +685,36 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, &st->bitmap.vert_shader); } - st_validate_state(st); + if (UseBitmapCache && accum_bitmap(st, x, y, width, height, unpack, bitmap)) + return; 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); + width, height, pt); pipe_texture_reference(&pt, NULL); } } - -void st_init_bitmap_functions(struct dd_function_table *functions) +/** Per-context init */ +void +st_init_bitmap_functions(struct dd_function_table *functions) { functions->Bitmap = st_Bitmap; } +/** Per-context init */ +void +st_init_bitmap(struct st_context *st) +{ + init_bitmap_cache(st); +} + + +/** Per-context tear-down */ void st_destroy_bitmap(struct st_context *st) { @@ -528,9 +732,15 @@ st_destroy_bitmap(struct st_context *st) pipe->delete_vs_state(pipe, st->bitmap.vs); st->bitmap.vs = NULL; } + if (st->bitmap.vbuf) { pipe->winsys->buffer_destroy(pipe->winsys, st->bitmap.vbuf); st->bitmap.vbuf = NULL; } -} + if (st->bitmap.cache) { + pipe_texture_release(&st->bitmap.cache->texture); + FREE(st->bitmap.cache); + st->bitmap.cache = NULL; + } +} diff --git a/src/mesa/state_tracker/st_cb_bitmap.h b/src/mesa/state_tracker/st_cb_bitmap.h index ac19e0ebb1..aae11d34c9 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.h +++ b/src/mesa/state_tracker/st_cb_bitmap.h @@ -33,9 +33,14 @@ extern void st_init_bitmap_functions(struct dd_function_table *functions); +extern void +st_init_bitmap(struct st_context *st); extern void st_destroy_bitmap(struct st_context *st); +extern void +st_flush_bitmap_cache(struct st_context *st); + #endif /* ST_CB_BITMAP_H */ diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c index a536a059bd..e321b401e2 100644 --- a/src/mesa/state_tracker/st_cb_flush.c +++ b/src/mesa/state_tracker/st_cb_flush.c @@ -35,6 +35,7 @@ #include "main/macros.h" #include "main/context.h" #include "st_context.h" +#include "st_cb_bitmap.h" #include "st_cb_flush.h" #include "st_cb_fbo.h" #include "st_public.h" @@ -48,6 +49,8 @@ void st_flush( struct st_context *st, uint pipeFlushFlags, { FLUSH_VERTICES(st->ctx, 0); + st_flush_bitmap_cache(st); + st->pipe->flush( st->pipe, pipeFlushFlags, fence ); } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 726e06d7c2..a20195f2de 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -109,6 +109,7 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st->cso_context = cso_create_context(pipe); st_init_atoms( st ); + st_init_bitmap(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 f235c194b7..85e3d47e1a 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -42,6 +42,7 @@ struct cso_cache; struct cso_blend; struct gen_mipmap_state; struct blit_state; +struct bitmap_cache; #define ST_NEW_MESA 0x1 /* Mesa state has changed */ @@ -151,6 +152,7 @@ struct st_context void *vs; float vertices[4][3][4]; /**< vertex pos + color + texcoord */ struct pipe_buffer *vbuf; + struct bitmap_cache *cache; } bitmap; /** for glClear */ -- cgit v1.2.3 From e66cb602b79f52bd1f01b1c3f7af039eeff283a6 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 31 Mar 2008 12:18:20 -0600 Subject: gallium: turn on clipping for bitmaps Bitmaps can extend beyond window edges so we need to clip. Also, move some state atom vars to st_context to be a bit more efficient. --- src/mesa/state_tracker/st_cb_bitmap.c | 94 +++++++++++++++++++++-------------- src/mesa/state_tracker/st_context.h | 2 + 2 files changed, 60 insertions(+), 36 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index ec56b25f7c..0cc910a67f 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -350,16 +350,21 @@ setup_bitmap_vertex_data(struct st_context *st, { struct pipe_context *pipe = st->pipe; const struct gl_framebuffer *fb = st->ctx->DrawBuffer; - const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP); + const GLfloat fb_width = fb->Width; + const GLfloat fb_height = fb->Height; const GLfloat x0 = x; const GLfloat x1 = x + width; - const GLfloat y0 = invert ? ((int) fb->Height - y - height) : y; - const GLfloat y1 = invert ? (y0 + height) : y + height; + const GLfloat y0 = y; + const GLfloat y1 = y + height; const GLfloat bias = st->bitmap_texcoord_bias; const GLfloat xBias = bias / (x1-x0); const GLfloat yBias = bias / (y1-y0); const GLfloat sLeft = 0.0 + xBias, sRight = 1.0 + xBias; - const GLfloat tTop = 1.0 - yBias, tBot = 1.0 - tTop - yBias; + const GLfloat tTop = yBias, tBot = 1.0 - tTop - yBias; + const GLfloat clip_x0 = x0 / fb_width * 2.0 - 1.0; + const GLfloat clip_y0 = y0 / fb_height * 2.0 - 1.0; + const GLfloat clip_x1 = x1 / fb_width * 2.0 - 1.0; + const GLfloat clip_y1 = y1 / fb_height * 2.0 - 1.0; GLuint i; void *buf; @@ -369,24 +374,26 @@ setup_bitmap_vertex_data(struct st_context *st, sizeof(st->bitmap.vertices)); } - /* positions, texcoords */ - st->bitmap.vertices[0][0][0] = x0; - st->bitmap.vertices[0][0][1] = y0; + /* Positions are in clip coords since we need to do clipping in case + * the bitmap quad goes beyond the window bounds. + */ + st->bitmap.vertices[0][0][0] = clip_x0; + st->bitmap.vertices[0][0][1] = clip_y0; st->bitmap.vertices[0][2][0] = sLeft; st->bitmap.vertices[0][2][1] = tTop; - st->bitmap.vertices[1][0][0] = x1; - st->bitmap.vertices[1][0][1] = y0; + st->bitmap.vertices[1][0][0] = clip_x1; + st->bitmap.vertices[1][0][1] = clip_y0; st->bitmap.vertices[1][2][0] = sRight; st->bitmap.vertices[1][2][1] = tTop; - st->bitmap.vertices[2][0][0] = x1; - st->bitmap.vertices[2][0][1] = y1; + st->bitmap.vertices[2][0][0] = clip_x1; + st->bitmap.vertices[2][0][1] = clip_y1; st->bitmap.vertices[2][2][0] = sRight; st->bitmap.vertices[2][2][1] = tBot; - st->bitmap.vertices[3][0][0] = x0; - st->bitmap.vertices[3][0][1] = y1; + st->bitmap.vertices[3][0][0] = clip_x0; + st->bitmap.vertices[3][0][1] = clip_y1; st->bitmap.vertices[3][2][0] = sLeft; st->bitmap.vertices[3][2][1] = tBot; @@ -437,17 +444,11 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_save_rasterizer(cso); cso_save_samplers(cso); + cso_save_viewport(cso); /* rasterizer state: just scissor */ - { - struct pipe_rasterizer_state rasterizer; - memset(&rasterizer, 0, sizeof(rasterizer)); - if (ctx->Scissor.Enabled) - rasterizer.scissor = 1; - rasterizer.bypass_clipping = 1; - - cso_set_rasterizer(cso, &rasterizer); - } + 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); @@ -456,21 +457,26 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->bind_vs_state(pipe, st->bitmap.vs); /* sampler / texture state */ + cso_single_sampler(cso, 0, &st->bitmap.sampler); + cso_single_sampler_done(cso); + pipe->set_sampler_textures(pipe, 1, &pt); + + /* viewport state: viewport matching window dims */ { - struct pipe_sampler_state sampler; - memset(&sampler, 0, sizeof(sampler)); - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP; - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP; - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP; - sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; - sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; - sampler.normalized_coords = 1; - - cso_single_sampler(cso, 0, &sampler); - cso_single_sampler_done(cso); - - pipe->set_sampler_textures(pipe, 1, &pt); + const struct gl_framebuffer *fb = st->ctx->DrawBuffer; + const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP); + const float width = fb->Width; + const float height = fb->Height; + struct pipe_viewport_state vp; + vp.scale[0] = 0.5 * width; + vp.scale[1] = height * (invert ? -0.5 : 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.0; + vp.translate[3] = 0.0; + cso_set_viewport(cso, &vp); } /* draw textured quad */ @@ -487,6 +493,7 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* restore state */ cso_restore_rasterizer(cso); cso_restore_samplers(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); @@ -742,6 +749,21 @@ st_init_bitmap_functions(struct dd_function_table *functions) void st_init_bitmap(struct st_context *st) { + struct pipe_sampler_state *sampler = &st->bitmap.sampler; + + /* init sampler state once */ + memset(sampler, 0, sizeof(*sampler)); + sampler->wrap_s = PIPE_TEX_WRAP_CLAMP; + sampler->wrap_t = PIPE_TEX_WRAP_CLAMP; + sampler->wrap_r = PIPE_TEX_WRAP_CLAMP; + sampler->min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler->min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler->mag_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler->normalized_coords = 1; + + /* init scissor state once */ + memset(&st->bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer)); + init_bitmap_cache(st); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 85e3d47e1a..44705bc89a 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -148,6 +148,8 @@ 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_rasterizer_state rasterizer; + struct pipe_sampler_state sampler; struct pipe_shader_state vert_shader; void *vs; float vertices[4][3][4]; /**< vertex pos + color + texcoord */ -- 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_context.h') 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 a52faa9325db178601811f4bdad6d9747de5f238 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 9 Apr 2008 16:09:46 -0600 Subject: gallium: remove unneeded st->haveFramebufferSurfaces field. --- src/gallium/winsys/xlib/xm_api.c | 3 --- src/mesa/state_tracker/st_cb_drawpixels.c | 6 +----- src/mesa/state_tracker/st_context.c | 2 -- src/mesa/state_tracker/st_context.h | 6 ------ 4 files changed, 1 insertion(+), 16 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/gallium/winsys/xlib/xm_api.c b/src/gallium/winsys/xlib/xm_api.c index a82d3c990e..0c248344b1 100644 --- a/src/gallium/winsys/xlib/xm_api.c +++ b/src/gallium/winsys/xlib/xm_api.c @@ -814,9 +814,6 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) mesaCtx->Const.CheckArrayBounds = GL_TRUE; #endif - /* finish up xmesa context initializations */ - c->st->haveFramebufferSurfaces = GL_TRUE; - return c; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index c57e05312a..b1affc4a91 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -1017,11 +1017,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, srcy = ctx->DrawBuffer->Height - srcy - height; } - /* For some drivers (like Xlib) it's not possible to treat the - * front/back color buffers as surfaces (they're XImages and Pixmaps). - * So, this var tells us if we can use surface_copy here... - */ - if (st->haveFramebufferSurfaces && srcFormat == texFormat) { + if (srcFormat == texFormat) { /* copy source framebuffer surface into mipmap/texture */ pipe->surface_copy(pipe, FALSE, diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 7511c28074..154327239d 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -128,8 +128,6 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; - st->haveFramebufferSurfaces = GL_TRUE; - st->pixel_xfer.cache = _mesa_new_program_cache(); /* GL limits and extensions */ diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index bcebbd4943..212687cf4a 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -111,12 +111,6 @@ struct st_context char vendor[100]; char renderer[100]; - /** Can we access the front/back color buffers as pipe_surfaces? - * We can't with the Xlib driver... - * This is a hack that should be fixed someday. - */ - GLboolean haveFramebufferSurfaces; - /* State to be validated: */ struct st_tracked_state **atoms; -- cgit v1.2.3 From 311e40268414649f047ee177ba22a17a2d437843 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 9 Apr 2008 18:39:51 -0600 Subject: gallium: more elaborate tracking of front color buffer state This fixes the case where the app calls SwapBuffers then calls glReadPixels to read the front color buffer. We now keep track of when the front buffer is a _logically_ copy of the back buffer (after SwapBuffers) and read from the back color buffer instead of the front. --- src/mesa/state_tracker/st_atom_framebuffer.c | 8 +++++++ src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_cb_flush.c | 27 ++++------------------- src/mesa/state_tracker/st_cb_readpixels.c | 33 ++++++++++++++++++++++++++-- src/mesa/state_tracker/st_cb_readpixels.h | 3 +++ src/mesa/state_tracker/st_context.h | 9 +++++--- src/mesa/state_tracker/st_framebuffer.c | 1 + 7 files changed, 54 insertions(+), 29 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index 02573af8f0..8a95096ec9 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -81,6 +81,14 @@ update_framebuffer_state( struct st_context *st ) } cso_set_framebuffer(st->cso_context, framebuffer); + + if (fb->_ColorDrawBufferMask[0] & BUFFER_BIT_FRONT_LEFT) { + if (st->frontbuffer_status == FRONT_STATUS_COPY_OF_BACK) { + /* XXX copy back buf to front? */ + } + /* we're assuming we'll really draw to the front buffer */ + st->frontbuffer_status = FRONT_STATUS_DIRTY; + } } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index b1affc4a91..5f8c90cbba 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -961,7 +961,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, } if (type == GL_COLOR) { - rbRead = st_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer); + rbRead = st_get_color_read_renderbuffer(ctx); color = NULL; stfp = combined_drawpix_fragment_program(ctx); stvp = st_make_passthrough_vertex_shader(ctx->st, GL_FALSE); diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c index 1bcd1b4cd9..1b3402cee2 100644 --- a/src/mesa/state_tracker/st_cb_flush.c +++ b/src/mesa/state_tracker/st_cb_flush.c @@ -44,30 +44,10 @@ #include "pipe/p_winsys.h" -static GLboolean +static INLINE GLboolean is_front_buffer_dirty(struct st_context *st) { - GLframebuffer *fb = st->ctx->DrawBuffer; - - if (!fb) - return GL_FALSE; - - /* XXX: temporary hack. This flag should only be set if we do any - * rendering to the front buffer. - * - * Further more, the scissor rectangle could be tracked to - * construct a dirty region of the front buffer, to avoid - * situations where it must be copied repeatedly. - * - * In the extreme case, some kind of timer could be set up to allow - * coalescing of multiple flushes to the frontbuffer, which can be - * quite a performance drain if there are a sufficient number of - * them. - */ - st->flags.frontbuffer_dirty - = (fb->_ColorDrawBufferMask[0] & BUFFER_BIT_FRONT_LEFT); - - return st->flags.frontbuffer_dirty; + return st->frontbuffer_status == FRONT_STATUS_DIRTY; } @@ -86,7 +66,8 @@ display_front_buffer(struct st_context *st) */ st->pipe->winsys->flush_frontbuffer( st->pipe->winsys, front_surf, st->pipe->priv ); - st->flags.frontbuffer_dirty = 0; + + st->frontbuffer_status = FRONT_STATUS_UNDEFINED; } diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 2bcc8c99fb..29a06ffaa9 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -128,6 +128,34 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } +/** + * Return renderbuffer to use for reading color pixels for glRead/CopyPixel + * commands. + * Special care is needed for the front buffer. + */ +struct st_renderbuffer * +st_get_color_read_renderbuffer(GLcontext *ctx) +{ + struct gl_framebuffer *fb = ctx->ReadBuffer; + struct st_renderbuffer *strb = + st_renderbuffer(fb->_ColorReadBuffer); + struct st_renderbuffer *front = + st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); + + if (strb == front + && ctx->st->frontbuffer_status == FRONT_STATUS_COPY_OF_BACK) { + /* reading from front color buffer, which is a logical copy of the + * back color buffer. + */ + struct st_renderbuffer *back = + st_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer); + strb = back; + } + + return strb; +} + + /** * Do glReadPixels by getting rows from the framebuffer surface with * get_tile(). Convert to requested format/type with Mesa image routines. @@ -173,12 +201,13 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, strb = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer); } else { - strb = st_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer); + /* Read color buffer */ + strb = st_get_color_read_renderbuffer(ctx); } + if (!strb) return; - if (format == GL_RGBA && type == GL_FLOAT) { /* write tile(row) directly into user's buffer */ df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width, diff --git a/src/mesa/state_tracker/st_cb_readpixels.h b/src/mesa/state_tracker/st_cb_readpixels.h index 79acdad88e..9e151be51f 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.h +++ b/src/mesa/state_tracker/st_cb_readpixels.h @@ -29,6 +29,9 @@ #ifndef ST_CB_READPIXELS_H #define ST_CB_READPIXELS_H +extern struct st_renderbuffer * +st_get_color_read_renderbuffer(GLcontext *ctx); + extern void st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum type, diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 212687cf4a..d89e54c43c 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -45,6 +45,11 @@ struct blit_state; struct bitmap_cache; +#define FRONT_STATUS_UNDEFINED 0 +#define FRONT_STATUS_DIRTY 1 +#define FRONT_STATUS_COPY_OF_BACK 2 + + #define ST_NEW_MESA 0x1 /* Mesa state has changed */ #define ST_NEW_FRAGMENT_PROGRAM 0x2 #define ST_NEW_VERTEX_PROGRAM 0x4 @@ -104,9 +109,7 @@ struct st_context struct gl_fragment_program *fragment_program; } cb; - struct { - GLuint frontbuffer_dirty:1; - } flags; + GLuint frontbuffer_status; /**< one of FRONT_STATUS_ */ char vendor[100]; char renderer[100]; diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index ea09d9234c..47466c97d8 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -188,6 +188,7 @@ st_notify_swapbuffers(struct st_framebuffer *stfb) st_flush( ctx->st, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_SWAPBUFFERS, NULL ); + ctx->st->frontbuffer_status = FRONT_STATUS_COPY_OF_BACK; } } -- cgit v1.2.3 From 4b822a101680532ce6df52904af91194b78a16ba Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 16 Apr 2008 16:52:12 -0600 Subject: gallium: implement RGBA pixel maps in the pixel transfer fragment program --- src/mesa/state_tracker/st_atom_pixeltransfer.c | 136 ++++++++++++++++++++++++- src/mesa/state_tracker/st_cb_drawpixels.c | 13 ++- src/mesa/state_tracker/st_context.h | 2 + 3 files changed, 146 insertions(+), 5 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index efb92b735e..76356bbad7 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -42,8 +42,14 @@ #include "shader/prog_print.h" #include "st_context.h" +#include "st_format.h" #include "st_program.h" +#include "st_texture.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_inlines.h" +#include "util/u_pack_color.h" struct state_key @@ -51,6 +57,7 @@ struct state_key GLuint scaleAndBias:1; GLuint colorMatrix:1; GLuint colorMatrixPostScaleBias:1; + GLuint pixelMaps:1; #if 0 GLfloat Maps[3][256][4]; @@ -101,6 +108,69 @@ make_state_key(GLcontext *ctx, struct state_key *key) !TEST_EQ_4V(ctx->Pixel.PostColorMatrixBias, zero)) { key->colorMatrixPostScaleBias = 1; } + + key->pixelMaps = ctx->Pixel.MapColorFlag; +} + + +static struct pipe_texture * +create_color_map_texture(GLcontext *ctx) +{ + struct pipe_context *pipe = ctx->st->pipe; + struct pipe_texture *pt; + enum pipe_format format; + const uint texSize = 256; /* simple, and usually perfect */ + + /* find an RGBA texture format */ + format = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE); + + /* create texture for color map/table */ + pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, + texSize, texSize, 1, 0); + return pt; +} + + +/** + * Update the pixelmap texture with the contents of the R/G/B/A pixel maps. + */ +static void +load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) +{ + struct pipe_context *pipe = ctx->st->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_surface *surface; + const GLuint rSize = ctx->PixelMaps.RtoR.Size; + const GLuint gSize = ctx->PixelMaps.GtoG.Size; + const GLuint bSize = ctx->PixelMaps.BtoB.Size; + const GLuint aSize = ctx->PixelMaps.AtoA.Size; + const uint texSize = pt->width[0]; + uint *dest; + uint i, j; + + surface = screen->get_tex_surface(screen, pt, 0, 0, 0); + dest = (uint *) pipe_surface_map(surface); + + /* Pack four 1D maps into a 2D texture: + * R map is placed horizontally, indexed by S, in channel 0 + * G map is placed vertically, indexed by T, in channel 1 + * B map is placed horizontally, indexed by S, in channel 2 + * A map is placed vertically, indexed by T, in channel 3 + */ + for (i = 0; i < texSize; i++) { + for (j = 0; j < texSize; j++) { + int k = (i * texSize + j); + ubyte r = ctx->PixelMaps.RtoR.Map8[j * rSize / texSize]; + ubyte g = ctx->PixelMaps.GtoG.Map8[i * gSize / texSize]; + ubyte b = ctx->PixelMaps.BtoB.Map8[j * bSize / texSize]; + ubyte a = ctx->PixelMaps.AtoA.Map8[i * aSize / texSize]; + util_pack_color_ub(r, g, b, a, pt->format, dest + k); + } + } + + pipe_surface_unmap(surface); + pipe_surface_reference(&surface, NULL); + pipe->texture_update(pipe, pt, 0, 0x1); } @@ -113,6 +183,7 @@ make_state_key(GLcontext *ctx, struct state_key *key) static struct gl_fragment_program * get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) { + struct st_context *st = ctx->st; struct prog_instruction inst[MAX_INST]; struct gl_program_parameter_list *params; struct gl_fragment_program *fp; @@ -126,7 +197,10 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) params = _mesa_new_parameter_list(); - /* TEX colorTemp, fragment.texcoord[0], texture[0], 2D; */ + /* + * Get initial pixel color from the texture. + * TEX colorTemp, fragment.texcoord[0], texture[0], 2D; + */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_TEX; inst[ic].DstReg.File = PROGRAM_TEMPORARY; @@ -140,7 +214,6 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) fp->Base.OutputsWritten = (1 << FRAG_RESULT_COLR); fp->Base.SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */ - /* MAD colorTemp, colorTemp, scale, bias; */ if (key->scaleAndBias) { static const gl_state_index scale_state[STATE_LENGTH] = { STATE_INTERNAL, STATE_PT_SCALE, 0, 0, 0 }; @@ -161,6 +234,7 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) scale_p = _mesa_add_state_reference(params, scale_state); bias_p = _mesa_add_state_reference(params, bias_state); + /* MAD colorTemp, colorTemp, scale, bias; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_MAD; inst[ic].DstReg.File = PROGRAM_TEMPORARY; @@ -174,6 +248,56 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) ic++; } + if (key->pixelMaps) { + const GLuint temp = 1; + + /* create the colormap/texture now if not already done */ + if (!st->pixel_xfer.pixelmap_texture) { + st->pixel_xfer.pixelmap_texture = create_color_map_texture(ctx); + } + + /* with a little effort, we can do four pixel map look-ups with + * two TEX instructions: + */ + + /* TEX temp.rg, colorTemp.rgba, texture[1], 2D; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_TEX; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = temp; + inst[ic].DstReg.WriteMask = WRITEMASK_XY; /* write R,G */ + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = colorTemp; + inst[ic].TexSrcUnit = 1; + inst[ic].TexSrcTarget = TEXTURE_2D_INDEX; + ic++; + + /* TEX temp.ba, colorTemp.baba, texture[1], 2D; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_TEX; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = temp; + inst[ic].DstReg.WriteMask = WRITEMASK_ZW; /* write B,A */ + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = colorTemp; + inst[ic].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_W, + SWIZZLE_Z, SWIZZLE_W); + inst[ic].TexSrcUnit = 1; + inst[ic].TexSrcTarget = TEXTURE_2D_INDEX; + ic++; + + /* MOV colorTemp, temp; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_MOV; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = colorTemp; + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = temp; + ic++; + + fp->Base.SamplersUsed |= (1 << 1); /* sampler 1 is used */ + } + if (key->colorMatrix) { static const gl_state_index row0_state[STATE_LENGTH] = { STATE_COLOR_MATRIX, 0, 0, 0, 0 }; @@ -190,8 +314,6 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) GLint row3_p = _mesa_add_state_reference(params, row3_state); const GLuint temp = 1; - /* XXX reimplement in terms of MUL/MAD (see t_vp_build.c) */ - /* DP4 temp.x, colorTemp, matrow0; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; @@ -316,6 +438,7 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) static void update_pixel_transfer(struct st_context *st) { + GLcontext *ctx = st->ctx; struct state_key key; struct gl_fragment_program *fp; @@ -329,6 +452,11 @@ update_pixel_transfer(struct st_context *st) &key, sizeof(key), &fp->Base); } + if (ctx->Pixel.MapColorFlag) { + load_color_map_texture(ctx, st->pixel_xfer.pixelmap_texture); + } + st->pixel_xfer.pixelmap_enabled = ctx->Pixel.MapColorFlag; + st->pixel_xfer.program = (struct st_fragment_program *) fp; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 5f8c90cbba..67f468c689 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -562,6 +562,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, sampler.normalized_coords = 1; cso_single_sampler(cso, 0, &sampler); + if (st->pixel_xfer.pixelmap_enabled) { + cso_single_sampler(cso, 1, &sampler); + } cso_single_sampler_done(cso); } @@ -582,7 +585,15 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, } /* texture state: */ - pipe->set_sampler_textures(pipe, 1, &pt); + if (st->pixel_xfer.pixelmap_enabled) { + struct pipe_texture *textures[2]; + textures[0] = pt; + textures[1] = st->pixel_xfer.pixelmap_texture; + pipe->set_sampler_textures(pipe, 2, textures); + } + else { + pipe->set_sampler_textures(pipe, 1, &pt); + } /* Compute window coords (y=0=bottom) with pixel zoom. * Recall that these coords are transformed by the current diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index d89e54c43c..ae1ba41d4f 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -138,6 +138,8 @@ struct st_context GLuint user_prog_sn; /**< user fragment program serial no. */ struct st_fragment_program *combined_prog; GLuint combined_prog_sn; + struct pipe_texture *pixelmap_texture; + boolean pixelmap_enabled; /**< use the pixelmap texture? */ } pixel_xfer; /** for glBitmap */ -- cgit v1.2.3 From 33f3938d2d6340b31d758c96bd35f858c6c8267d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 22 Apr 2008 18:38:37 -0600 Subject: gallium: fix some bitmap frag shader issues If texturing happens to be enabled when glBitmap() is called, need to be careful about choosing a sampler unit, etc. --- src/mesa/state_tracker/st_cb_bitmap.c | 85 +++++++++++++++++++++------------- src/mesa/state_tracker/st_cb_program.c | 4 ++ src/mesa/state_tracker/st_context.h | 3 -- src/mesa/state_tracker/st_program.h | 4 ++ 4 files changed, 62 insertions(+), 34 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 701d1e397e..7752b40e8b 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -105,7 +105,7 @@ struct bitmap_cache * This program will be combined with the user's fragment program. */ static struct st_fragment_program * -make_bitmap_fragment_program(GLcontext *ctx) +make_bitmap_fragment_program(GLcontext *ctx, GLuint samplerIndex) { struct st_fragment_program *stfp; struct gl_program *p; @@ -130,7 +130,7 @@ make_bitmap_fragment_program(GLcontext *ctx) p->Instructions[ic].DstReg.Index = 0; p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT; p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0; - p->Instructions[ic].TexSrcUnit = 0; + p->Instructions[ic].TexSrcUnit = samplerIndex; p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX; ic++; @@ -148,7 +148,7 @@ make_bitmap_fragment_program(GLcontext *ctx) p->InputsRead = FRAG_BIT_TEX0; p->OutputsWritten = 0x0; - p->SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */ + p->SamplersUsed = (1 << samplerIndex); stfp = (struct st_fragment_program *) p; stfp->Base.UsesKill = GL_TRUE; @@ -158,6 +158,19 @@ make_bitmap_fragment_program(GLcontext *ctx) } +static int +find_free_bit(uint bitfield) +{ + int i; + for (i = 0; i < 32; i++) { + if ((bitfield & (1 << i)) == 0) { + return i; + } + } + return -1; +} + + /** * Combine basic bitmap fragment program with the user-defined program. */ @@ -165,28 +178,26 @@ static struct st_fragment_program * combined_bitmap_fragment_program(GLcontext *ctx) { struct st_context *st = ctx->st; - struct st_fragment_program *stfp; - - if (!st->bitmap.program) { - /* create the basic bitmap fragment program */ - st->bitmap.program = make_bitmap_fragment_program(ctx); - } + struct st_fragment_program *stfp = st->fp; - if (st->bitmap.user_prog_sn == st->fp->serialNo) { - /* re-use */ - stfp = st->bitmap.combined_prog; - } - else { - /* Concatenate the bitmap program with the current user-defined program. + if (!stfp->bitmap_program) { + /* + * Generate new program which is the user-defined program prefixed + * with the bitmap sampler/kill instructions. */ - stfp = (struct st_fragment_program *) - _mesa_combine_programs(ctx, - &st->bitmap.program->Base.Base, - &st->fp->Base.Base); + struct st_fragment_program *bitmap_prog; + uint sampler; + sampler = find_free_bit(st->fp->Base.Base.SamplersUsed); + bitmap_prog = make_bitmap_fragment_program(ctx, sampler); + + stfp->bitmap_program = (struct st_fragment_program *) + _mesa_combine_programs(ctx, + &bitmap_prog->Base.Base, &stfp->Base.Base); + stfp->bitmap_program->bitmap_sampler = sampler; #if 0 { - struct gl_program *p = &stfp->Base.Base; + struct gl_program *p = &stfp->bitmap_program->Base.Base; printf("Combined bitmap program:\n"); _mesa_print_program(p); printf("InputsRead: 0x%x\n", p->InputsRead); @@ -196,11 +207,7 @@ combined_bitmap_fragment_program(GLcontext *ctx) #endif /* translate to TGSI tokens */ - st_translate_fragment_program(st, stfp, NULL); - - /* save new program, update serial numbers */ - st->bitmap.user_prog_sn = st->fp->serialNo; - st->bitmap.combined_prog = stfp; + st_translate_fragment_program(st, stfp->bitmap_program, NULL); } /* Ideally we'd have updated the pipe constants during the normal @@ -208,7 +215,7 @@ combined_bitmap_fragment_program(GLcontext *ctx) */ st_upload_constants(st, stfp->Base.Base.Parameters, PIPE_SHADER_FRAGMENT); - return stfp; + return stfp->bitmap_program; } @@ -451,10 +458,25 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* vertex shader state: position + texcoord pass-through */ cso_set_vertex_shader_handle(cso, st->bitmap.vs); - /* sampler / texture state */ - cso_single_sampler(cso, 0, &st->bitmap.sampler); - cso_single_sampler_done(cso); - pipe->set_sampler_textures(pipe, 1, &pt); + /* user samplers, plus our bitmap sampler */ + { + struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; + uint num = MAX2(stfp->bitmap_sampler + 1, st->state.num_samplers); + uint i; + for (i = 0; i < st->state.num_samplers; i++) { + samplers[i] = &st->state.samplers[i]; + } + samplers[stfp->bitmap_sampler] = &st->bitmap.sampler; + cso_set_samplers(cso, num, (const struct pipe_sampler_state **) samplers); } + + /* user textures, plus the bitmap texture */ + { + struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + uint num = MAX2(stfp->bitmap_sampler + 1, st->state.num_textures); + memcpy(textures, st->state.sampler_texture, sizeof(textures)); + textures[stfp->bitmap_sampler] = pt; + cso_set_sampler_textures(cso, num, textures); + } /* viewport state: viewport matching window dims */ { @@ -771,6 +793,7 @@ st_destroy_bitmap(struct st_context *st) { struct pipe_context *pipe = st->pipe; +#if 0 if (st->bitmap.combined_prog) { st_delete_program(st->ctx, &st->bitmap.combined_prog->Base.Base); } @@ -778,7 +801,7 @@ st_destroy_bitmap(struct st_context *st) if (st->bitmap.program) { st_delete_program(st->ctx, &st->bitmap.program->Base.Base); } - +#endif if (st->bitmap.vs) { pipe->delete_vs_state(pipe, st->bitmap.vs); st->bitmap.vs = NULL; diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 003ec0d2b7..67f8b1f8eb 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -159,6 +159,10 @@ st_delete_program(GLcontext *ctx, struct gl_program *prog) stfp->state.tokens = NULL; } + if (stfp->bitmap_program) { + st_delete_program(ctx, &stfp->bitmap_program->Base.Base); + } + st_free_translated_vertex_programs(st, stfp->vertex_programs); } break; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index ae1ba41d4f..2851770d4c 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -144,9 +144,6 @@ struct st_context /** 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; struct pipe_rasterizer_state rasterizer; struct pipe_sampler_state sampler; struct pipe_shader_state vert_shader; diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index e58b8a1851..1a2062131d 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -69,6 +69,10 @@ struct st_fragment_program * outputs match this fragment program's inputs. */ struct translated_vertex_program *vertex_programs; + + /** Program prefixed with glBitmap prologue */ + struct st_fragment_program *bitmap_program; + uint bitmap_sampler; }; -- cgit v1.2.3 From 332b77b852905224741084c5a4f5d2f4625dd119 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 25 Apr 2008 15:23:21 -0600 Subject: gallium: use simple color pass-through fragment shader if textures don't exist If we run out of texture memory we may not have the texture needed by the fragment shader. If this happens, plug in a color passthrough shader. So instead of crashing, we just don't see the texture. GL_OUT_OF_MEMORY is raised, of course. --- src/mesa/state_tracker/st_atom_texture.c | 30 ++++++++++++++++++++++++++++-- src/mesa/state_tracker/st_context.h | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 01c07dc26d..d15da5895a 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -38,6 +38,23 @@ #include "st_cb_texture.h" #include "pipe/p_context.h" #include "pipe/p_inlines.h" +#include "cso_cache/cso_context.h" +#include "util/u_simple_shaders.h" + + +static void * +get_passthrough_fs(struct st_context *st) +{ + struct pipe_shader_state shader; + + if (!st->passthrough_fs) { + st->passthrough_fs = + util_make_fragment_passthrough_shader(st->pipe, &shader); + free((void *) shader.tokens); + } + + return st->passthrough_fs; +} /** @@ -49,6 +66,7 @@ update_textures(struct st_context *st) { struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; GLuint su; + GLboolean missing_textures = GL_FALSE; st->state.num_textures = 0; @@ -67,6 +85,7 @@ update_textures(struct st_context *st) retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); if (!retval) { /* out of mem */ + missing_textures = GL_TRUE; continue; } @@ -79,8 +98,15 @@ update_textures(struct st_context *st) pipe_texture_reference(&st->state.sampler_texture[su], pt); } - st->pipe->set_sampler_textures(st->pipe, st->state.num_textures, - st->state.sampler_texture); + cso_set_sampler_textures(st->cso_context, + st->state.num_textures, + st->state.sampler_texture); + + if (missing_textures) { + /* use a pass-through frag shader that uses no textures */ + void *fs = get_passthrough_fs(st); + cso_set_fragment_shader_handle(st->cso_context, fs); + } } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 2851770d4c..7e933a2b10 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -165,6 +165,8 @@ struct st_context struct pipe_buffer *vbuf; } clear; + void *passthrough_fs; /**< simple pass-through frag shader */ + struct gen_mipmap_state *gen_mipmap; struct blit_state *blit; -- cgit v1.2.3 From 1cf164142768d8338527ee8cab8dee83af82af0b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 25 Apr 2008 16:12:11 -0600 Subject: gallium: remove unneeded st->bitmap_texcoord_bias --- src/mesa/state_tracker/st_cb_bitmap.c | 7 ++----- src/mesa/state_tracker/st_cb_drawpixels.c | 7 ++----- src/mesa/state_tracker/st_context.h | 2 -- src/mesa/state_tracker/st_extensions.c | 6 ++---- 4 files changed, 6 insertions(+), 16 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 507ace27c7..6c2d9a4b89 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -355,11 +355,8 @@ setup_bitmap_vertex_data(struct st_context *st, const GLfloat x1 = x + width; const GLfloat y0 = y; const GLfloat y1 = y + height; - const GLfloat bias = 0.0 * st->bitmap_texcoord_bias; /* XXX remove */ - const GLfloat xBias = bias / (x1-x0); - const GLfloat yBias = bias / (y1-y0); - const GLfloat sLeft = 0.0 + xBias, sRight = 1.0 + xBias; - const GLfloat tTop = yBias, tBot = 1.0 - tTop - yBias; + const GLfloat sLeft = 0.0F, sRight = 1.0F; + const GLfloat tTop = 0.0, tBot = 1.0 - tTop; const GLfloat clip_x0 = x0 / fb_width * 2.0 - 1.0; const GLfloat clip_y0 = y0 / fb_height * 2.0 - 1.0; const GLfloat clip_x1 = x1 / fb_width * 2.0 - 1.0; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index cdfa041d15..047ea3816b 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -425,11 +425,8 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, const GLfloat clip_y0 = y0 / fb_height * 2.0 - 1.0; const GLfloat clip_x1 = x1 / fb_width * 2.0 - 1.0; const GLfloat clip_y1 = y1 / fb_height * 2.0 - 1.0; - GLfloat bias = ctx->st->bitmap_texcoord_bias; - GLfloat xBias = 0*bias / (x1-x0); - GLfloat yBias = 0*bias / (y1-y0); - GLfloat sLeft = 0.0 + xBias, sRight = 1.0 + xBias; - GLfloat tTop = invertTex - yBias, tBot = 1.0 - tTop - yBias; + const GLfloat sLeft = 0.0F, sRight = 1.0F; + const GLfloat tTop = invertTex, tBot = 1.0 - tTop; GLuint tex, i; /* upper-left */ diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 7e933a2b10..80a71d1766 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -123,8 +123,6 @@ struct st_context GLfloat polygon_offset_scale; /* ?? */ - GLfloat bitmap_texcoord_bias; - /** Mapping from VERT_RESULT_x to post-transformed vertex slot */ const GLuint *vertex_result_to_slot; diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index f2d40e84b3..260a2efe88 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -109,9 +109,6 @@ void st_init_limits(struct st_context *st) c->MaxTextureLodBias = screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_LOD_BIAS); - st->bitmap_texcoord_bias - = screen->get_paramf(screen, PIPE_CAP_BITMAP_TEXCOORD_BIAS); - c->MaxDrawBuffers = CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS), 1, MAX_DRAW_BUFFERS); @@ -220,11 +217,12 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.EXT_texture_sRGB = GL_TRUE; } +#if 01 if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA, PIPE_TEXTURE)) { ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE; } - +#endif if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR, PIPE_TEXTURE) || screen->is_format_supported(screen, PIPE_FORMAT_YCBCR_REV, PIPE_TEXTURE)) { ctx->Extensions.MESA_ycbcr_texture = GL_TRUE; -- cgit v1.2.3 From eefb9d3b51e40867ac3fee43b6496a62b1888b3c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 30 Apr 2008 09:41:55 -0600 Subject: gallium: simplify texture format selection --- src/mesa/state_tracker/st_cb_bitmap.c | 57 +++++++++++------------------------ src/mesa/state_tracker/st_context.h | 1 + 2 files changed, 18 insertions(+), 40 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 836758a336..45842fe231 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -230,27 +230,10 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, struct pipe_context *pipe = ctx->st->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_surface *surface; - uint format = 0, cpp, comp; ubyte *dest; struct pipe_texture *pt; int row, col; - /* find a texture format we know */ - if (screen->is_format_supported( screen, PIPE_FORMAT_U_I8, PIPE_TEXTURE )) { - format = PIPE_FORMAT_U_I8; - cpp = 1; - comp = 0; - } - else if (screen->is_format_supported( screen, PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_TEXTURE )) { - format = PIPE_FORMAT_A8R8G8B8_UNORM; - cpp = 4; - comp = 3; /* alpha channel */ /*XXX little-endian dependency */ - } - else { - /* XXX support more formats */ - assert( 0 ); - } - /* PBO source... */ bitmap = _mesa_map_bitmap_pbo(ctx, unpack, bitmap); if (!bitmap) { @@ -260,8 +243,8 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, /** * Create texture to hold bitmap pattern. */ - pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, width, height, - 1, 0); + pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, ctx->st->bitmap.tex_format, + 0, width, height, 1, 0); if (!pt) { _mesa_unmap_bitmap_pbo(ctx, unpack); return NULL; @@ -280,7 +263,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, for (row = 0; row < height; row++) { const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack, bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); - ubyte *destRow = dest + row * surface->pitch * cpp; + ubyte *destRow = dest + row * surface->pitch; if (unpack->LsbFirst) { /* Lsb first */ @@ -288,8 +271,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, for (col = 0; col < width; col++) { /* set texel to 255 if bit is set */ - destRow[comp] = (*src & mask) ? 0x0 : 0xff; - destRow += cpp; + destRow[col] = (*src & mask) ? 0x0 : 0xff; if (mask == 128U) { src++; @@ -310,8 +292,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, for (col = 0; col < width; col++) { /* set texel to 255 if bit is set */ - destRow[comp] =(*src & mask) ? 0x0 : 0xff; - destRow += cpp; + destRow[col] =(*src & mask) ? 0x0 : 0xff; if (mask == 1U) { src++; @@ -336,8 +317,6 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, pipe_surface_reference(&surface, NULL); pipe->texture_update(pipe, pt, 0, 0x1); - pt->format = format; - return pt; } @@ -530,25 +509,12 @@ reset_cache(struct st_context *st) static void init_bitmap_cache(struct st_context *st) { - struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; - enum pipe_format format; - st->bitmap.cache = CALLOC_STRUCT(bitmap_cache); if (!st->bitmap.cache) return; - /* find a usable texture format */ - if (screen->is_format_supported(screen, PIPE_FORMAT_U_I8, PIPE_TEXTURE)) { - format = PIPE_FORMAT_U_I8; - } - else { - /* XXX support more formats */ - assert(0); - } - st->bitmap.cache->texture - = st_texture_create(st, PIPE_TEXTURE_2D, format, 0, + = st_texture_create(st, PIPE_TEXTURE_2D, st->bitmap.tex_format, 0, BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT, 1, 0); if (!st->bitmap.cache->texture) { FREE(st->bitmap.cache); @@ -768,6 +734,8 @@ void st_init_bitmap(struct st_context *st) { struct pipe_sampler_state *sampler = &st->bitmap.sampler; + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; /* init sampler state once */ memset(sampler, 0, sizeof(*sampler)); @@ -784,6 +752,15 @@ st_init_bitmap(struct st_context *st) st->bitmap.rasterizer.gl_rasterization_rules = 1; st->bitmap.rasterizer.bypass_vs = 1; + /* find a usable texture format */ + if (screen->is_format_supported(screen, PIPE_FORMAT_U_I8, PIPE_TEXTURE)) { + st->bitmap.tex_format = PIPE_FORMAT_U_I8; + } + else { + /* XXX support more formats */ + assert(0); + } + init_bitmap_cache(st); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 80a71d1766..1ca779d0a9 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -145,6 +145,7 @@ struct st_context struct pipe_rasterizer_state rasterizer; struct pipe_sampler_state sampler; struct pipe_shader_state vert_shader; + enum pipe_format tex_format; void *vs; float vertices[4][3][4]; /**< vertex pos + color + texcoord */ struct pipe_buffer *vbuf; -- cgit v1.2.3 From 1a82d9648b3db780e58e4966924157542d148c58 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 7 May 2008 16:44:33 -0600 Subject: gallium: fix some render to texture bugs Before, we were sometimes rendering into a stale texture because st_finalize_texture() would discard the old texture and create a new one. Moved st_update_framebuffer atom after texture validation so that we can create a new renderbuffer surface if the texture changes. Also, split texture validation into two parts: finalize_textures and update_textures. Do finalize_textures first to avoid getting into the situtation where we're doing a pipe->surface_copy() mid-way through state validation. Some debug code still in place, but disabled... --- src/mesa/state_tracker/st_atom.c | 3 +- src/mesa/state_tracker/st_atom.h | 1 + src/mesa/state_tracker/st_atom_framebuffer.c | 60 ++++++++++++++++++++- src/mesa/state_tracker/st_atom_shader.c | 26 ++++++++- src/mesa/state_tracker/st_atom_texture.c | 80 +++++++++++++++++----------- src/mesa/state_tracker/st_cb_fbo.c | 34 +++++++++--- src/mesa/state_tracker/st_cb_fbo.h | 3 ++ src/mesa/state_tracker/st_cb_readpixels.c | 2 + src/mesa/state_tracker/st_cb_texture.c | 1 + src/mesa/state_tracker/st_context.h | 3 ++ src/mesa/state_tracker/st_texture.c | 16 ++++++ 11 files changed, 189 insertions(+), 40 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 18063adc79..ecfd117918 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -45,10 +45,10 @@ */ static const struct st_tracked_state *atoms[] = { - &st_update_framebuffer, &st_update_depth_stencil_alpha, &st_update_clip, + &st_finalize_textures, &st_update_shader, &st_update_rasterizer, @@ -58,6 +58,7 @@ static const struct st_tracked_state *atoms[] = &st_update_blend, &st_update_sampler, &st_update_texture, + &st_update_framebuffer, &st_update_vs_constants, &st_update_fs_constants, &st_update_pixel_transfer diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index c6c6eba812..c7cffd85c8 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -55,6 +55,7 @@ extern const struct st_tracked_state st_update_scissor; extern const struct st_tracked_state st_update_blend; extern const struct st_tracked_state st_update_sampler; extern const struct st_tracked_state st_update_texture; +extern const struct st_tracked_state st_finalize_textures; extern const struct st_tracked_state st_update_fs_constants; extern const struct st_tracked_state st_update_vs_constants; extern const struct st_tracked_state st_update_pixel_transfer; diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index 0a6974d8a7..c9a30e44b2 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -34,13 +34,60 @@ #include "st_context.h" #include "st_atom.h" #include "st_cb_fbo.h" +#include "st_texture.h" #include "pipe/p_context.h" +#include "pipe/p_inlines.h" #include "cso_cache/cso_context.h" + +/** + * When doing GL render to texture, we have to be sure that finalize_texture() + * didn't yank out the pipe_texture that we earlier created a surface for. + * Check for that here and create a new surface if needed. + */ +static void +update_renderbuffer_surface(struct st_context *st, + struct st_renderbuffer *strb) +{ + struct pipe_screen *screen = st->pipe->screen; + struct pipe_texture *texture = strb->rtt->pt; + int rtt_width = strb->Base.Width; + int rtt_height = strb->Base.Height; + + if (!strb->surface || + strb->surface->texture != texture || + strb->surface->width != rtt_width || + strb->surface->height != rtt_height) { + int level; + /* find matching mipmap level size */ + for (level = 0; level <= texture->last_level; level++) { + if (texture->width[level] == rtt_width && + texture->height[level] == rtt_height) { + + pipe_surface_reference(&strb->surface, NULL); + + strb->surface = screen->get_tex_surface(screen, + texture, + strb->rtt_face, + level, + strb->rtt_slice, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); +#if 0 + printf("-- alloc new surface %d x %d into tex %p\n", + strb->surface->width, strb->surface->height, + texture); +#endif + break; + } + } + } +} + + /** * Update framebuffer state (color, depth, stencil, etc. buffers) - * XXX someday: separate draw/read buffers. */ static void update_framebuffer_state( struct st_context *st ) @@ -55,6 +102,8 @@ update_framebuffer_state( struct st_context *st ) framebuffer->width = fb->Width; framebuffer->height = fb->Height; + /*printf("------ fb size %d x %d\n", fb->Width, fb->Height);*/ + /* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state * to determine which surfaces to draw to */ @@ -62,6 +111,13 @@ update_framebuffer_state( struct st_context *st ) for (j = 0; j < MAX_DRAW_BUFFERS; j++) { for (i = 0; i < fb->_NumColorDrawBuffers[j]; i++) { strb = st_renderbuffer(fb->_ColorDrawBuffers[j][i]); + + /*printf("--------- framebuffer surface rtt %p\n", strb->rtt);*/ + if (strb->rtt) { + /* rendering to a GL texture, may have to update surface */ + update_renderbuffer_surface(st, strb); + } + assert(strb->surface); framebuffer->cbufs[framebuffer->num_cbufs] = strb->surface; framebuffer->num_cbufs++; @@ -99,7 +155,7 @@ const struct st_tracked_state st_update_framebuffer = { "st_update_framebuffer", /* name */ { /* dirty */ _NEW_BUFFERS, /* mesa */ - 0, /* st */ + ST_NEW_FRAMEBUFFER, /* st */ }, update_framebuffer_state /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 7745591afb..8839ab380f 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -44,6 +44,8 @@ #include "pipe/p_context.h" #include "pipe/p_shader_tokens.h" +#include "util/u_simple_shaders.h" + #include "cso_cache/cso_context.h" #include "st_context.h" @@ -252,6 +254,20 @@ st_free_translated_vertex_programs(struct st_context *st, } +static void * +get_passthrough_fs(struct st_context *st) +{ + struct pipe_shader_state shader; + + if (!st->passthrough_fs) { + st->passthrough_fs = + util_make_fragment_passthrough_shader(st->pipe, &shader); + free((void *) shader.tokens); + } + + return st->passthrough_fs; +} + static void update_linkage( struct st_context *st ) @@ -277,7 +293,15 @@ update_linkage( struct st_context *st ) st_reference_fragprog(st, &st->fp, stfp); cso_set_vertex_shader_handle(st->cso_context, stvp->driver_shader); - cso_set_fragment_shader_handle(st->cso_context, stfp->driver_shader); + + if (st->missing_textures) { + /* use a pass-through frag shader that uses no textures */ + void *fs = get_passthrough_fs(st); + cso_set_fragment_shader_handle(st->cso_context, fs); + } + else { + 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_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 767654f3d0..1ec671ed48 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -39,34 +39,13 @@ #include "pipe/p_context.h" #include "pipe/p_inlines.h" #include "cso_cache/cso_context.h" -#include "util/u_simple_shaders.h" -static void * -get_passthrough_fs(struct st_context *st) -{ - struct pipe_shader_state shader; - - if (!st->passthrough_fs) { - st->passthrough_fs = - util_make_fragment_passthrough_shader(st->pipe, &shader); - free((void *) shader.tokens); - } - - return st->passthrough_fs; -} - - -/** - * XXX This needs some work yet.... - * Need to "upload" texture images at appropriate times. - */ static void update_textures(struct st_context *st) { struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; GLuint su; - GLboolean missing_textures = GL_FALSE; st->state.num_textures = 0; @@ -85,13 +64,11 @@ update_textures(struct st_context *st) retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); if (!retval) { /* out of mem */ - missing_textures = GL_TRUE; + /* missing texture */ continue; } st->state.num_textures = su + 1; - - stObj->teximage_realloc = TRUE; } pt = st_get_stobj_texture(stObj); @@ -103,12 +80,6 @@ update_textures(struct st_context *st) cso_set_sampler_textures(st->cso_context, st->state.num_textures, st->state.sampler_texture); - - if (missing_textures) { - /* use a pass-through frag shader that uses no textures */ - void *fs = get_passthrough_fs(st); - cso_set_fragment_shader_handle(st->cso_context, fs); - } } @@ -120,3 +91,52 @@ const struct st_tracked_state st_update_texture = { }, update_textures /* update */ }; + + + + +static void +finalize_textures(struct st_context *st) +{ + struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; + const GLboolean prev_missing_textures = st->missing_textures; + GLuint su; + + st->missing_textures = GL_FALSE; + + for (su = 0; su < st->ctx->Const.MaxTextureCoordUnits; su++) { + if (fprog->Base.SamplersUsed & (1 << su)) { + const GLuint texUnit = fprog->Base.SamplerUnits[su]; + struct gl_texture_object *texObj + = st->ctx->Texture.Unit[texUnit]._Current; + struct st_texture_object *stObj = st_texture_object(texObj); + + if (texObj) { + GLboolean flush, retval; + + retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); + if (!retval) { + /* out of mem */ + st->missing_textures = GL_TRUE; + continue; + } + + stObj->teximage_realloc = TRUE; + } + } + } + + if (prev_missing_textures != st->missing_textures) + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; +} + + + +const struct st_tracked_state st_finalize_textures = { + "st_finalize_textures", /* name */ + { /* dirty */ + _NEW_TEXTURE, /* mesa */ + 0, /* st */ + }, + finalize_textures /* update */ +}; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 747d4905e6..2368c31f4b 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -358,6 +358,10 @@ st_render_texture(GLcontext *ctx, struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_texture *pt; + struct st_texture_object *stObj; + const struct gl_texture_image *texImage = + att->Texture->Image[att->CubeMapFace][att->TextureLevel]; + assert(!att->Renderbuffer); @@ -374,27 +378,42 @@ st_render_texture(GLcontext *ctx, strb = st_renderbuffer(rb); /* get the texture for the texture object */ + stObj = st_texture_object(att->Texture); + + /* point renderbuffer at texobject */ + strb->rtt = stObj; + strb->rtt_level = att->TextureLevel; + strb->rtt_face = att->CubeMapFace; + strb->rtt_slice = att->Zoffset; + + rb->Width = texImage->Width2; + rb->Height = texImage->Height2; + /*printf("***** render to texture level %d: %d x %d\n", att->TextureLevel, rb->Width, rb->Height);*/ + pt = st_get_texobj_texture(att->Texture); assert(pt); - assert(pt->width[att->TextureLevel]); - - rb->Width = pt->width[att->TextureLevel]; - rb->Height = pt->height[att->TextureLevel]; + /*printf("***** pipe texture %d x %d\n", pt->width[0], pt->height[0]);*/ pipe_texture_reference( &strb->texture, pt ); + pipe_surface_reference(&strb->surface, NULL); + +#if 0 /* the renderbuffer's surface is inside the texture */ strb->surface = screen->get_tex_surface(screen, pt, att->CubeMapFace, - att->TextureLevel, + att->TextureLevel /*- att->Texture->BaseLevel*/, att->Zoffset, PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE); + printf("***** surface size: %d x %d\n", strb->surface->width, strb->surface->height); + assert(strb->surface); assert(screen->is_format_supported(screen, strb->surface->format, PIPE_TEXTURE)); assert(screen->is_format_supported(screen, strb->surface->format, PIPE_SURFACE)); init_renderbuffer_bits(strb, pt->format); +#endif /* printf("RENDER TO TEXTURE obj=%p pt=%p surf=%p %d x %d\n", @@ -424,7 +443,10 @@ st_finish_render_texture(GLcontext *ctx, ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); - screen->tex_surface_release( screen, &strb->surface ); + if (strb->surface) + screen->tex_surface_release( screen, &strb->surface ); + + strb->rtt = NULL; /* printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index f9cec91314..87b0734a0c 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -44,6 +44,9 @@ struct st_renderbuffer struct pipe_texture *texture; struct pipe_surface *surface; /* temporary view into texture */ enum pipe_format format; /** preferred format, or PIPE_FORMAT_NONE */ + + struct st_texture_object *rtt; /**< GL render to texture's texture */ + int rtt_level, rtt_face, rtt_slice; }; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 0b2b9d544d..3615fafc0a 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -183,6 +183,8 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, struct gl_pixelstore_attrib clippedPacking = *pack; struct pipe_surface *surf; + assert(ctx->ReadBuffer->Width > 0); + /* XXX convolution not done yet */ assert((transferOps & IMAGE_CONVOLUTION_BIT) == 0); diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 3206215b2e..3468b5f2a1 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1496,6 +1496,7 @@ st_finalize_texture(GLcontext *ctx, stObj->pt->cpp != cpp || stObj->pt->compressed != firstImage->base.IsCompressed) { pipe_texture_release(&stObj->pt); + ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER; } } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 1ca779d0a9..69be4ebdd0 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -53,6 +53,7 @@ struct bitmap_cache; #define ST_NEW_MESA 0x1 /* Mesa state has changed */ #define ST_NEW_FRAGMENT_PROGRAM 0x2 #define ST_NEW_VERTEX_PROGRAM 0x4 +#define ST_NEW_FRAMEBUFFER 0x8 struct st_state_flags { @@ -121,6 +122,8 @@ struct st_context struct st_state_flags dirty; + GLboolean missing_textures; + GLfloat polygon_offset_scale; /* ?? */ /** Mapping from VERT_RESULT_x to post-transformed vertex slot */ diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 2b3742d4e5..d0f56c9717 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -315,6 +315,22 @@ st_texture_image_copy(struct pipe_context *pipe, assert(src->width[srcLevel] == width); assert(src->height[srcLevel] == height); +#if 0 + { + src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i, + PIPE_BUFFER_USAGE_CPU_READ); + ubyte *map = screen->surface_map(screen, src_surface, PIPE_BUFFER_USAGE_CPU_READ); + map += src_surface->width * src_surface->height * 4 / 2; + printf("%s center pixel: %d %d %d %d (pt %p[%d] -> %p[%d])\n", + __FUNCTION__, + map[0], map[1], map[2], map[3], + src, srcLevel, dst, dstLevel); + + screen->surface_unmap(screen, src_surface); + pipe_surface_reference(&src_surface, NULL); + } +#endif + dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i, PIPE_BUFFER_USAGE_GPU_WRITE); -- cgit v1.2.3 From 5c431c22227fdc552b34a5feabf1d339dcfe9848 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 20 May 2008 13:38:45 -0600 Subject: gallium: clean-up glDraw/CopyPixels shaders when destroying context --- src/mesa/state_tracker/st_cb_drawpixels.c | 39 +++++++++++++++++++++---------- src/mesa/state_tracker/st_cb_drawpixels.h | 3 +++ src/mesa/state_tracker/st_context.c | 1 + src/mesa/state_tracker/st_context.h | 6 +++++ 4 files changed, 37 insertions(+), 12 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 56b949cf96..fbbe8d2d64 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -164,14 +164,16 @@ static struct st_fragment_program * make_fragment_shader_z(struct st_context *st) { GLcontext *ctx = st->ctx; - /* only make programs once and re-use */ - static struct st_fragment_program *stfp = NULL; struct gl_program *p; GLuint ic = 0; - if (stfp) - return stfp; + if (st->drawpix.z_shader) { + return st->drawpix.z_shader; + } + /* + * Create shader now + */ p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); if (!p) return NULL; @@ -213,10 +215,10 @@ make_fragment_shader_z(struct st_context *st) p->OutputsWritten = (1 << FRAG_RESULT_COLR) | (1 << FRAG_RESULT_DEPR); p->SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */ - stfp = (struct st_fragment_program *) p; - st_translate_fragment_program(st, stfp, NULL); + st->drawpix.z_shader = (struct st_fragment_program *) p; + st_translate_fragment_program(st, st->drawpix.z_shader, NULL); - return stfp; + return st->drawpix.z_shader; } @@ -228,16 +230,17 @@ make_fragment_shader_z(struct st_context *st) static 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 }; GLcontext *ctx = st->ctx; struct st_vertex_program *stvp; struct gl_program *p; GLuint ic = 0; - if (progs[passColor]) - return progs[passColor]; + if (st->drawpix.vert_shaders[passColor]) + return st->drawpix.vert_shaders[passColor]; + /* + * Create shader now + */ p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); if (!p) return NULL; @@ -293,7 +296,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); - progs[passColor] = stvp; + st->drawpix.vert_shaders[passColor] = stvp; return stvp; } @@ -1042,3 +1045,15 @@ void st_init_drawpixels_functions(struct dd_function_table *functions) functions->DrawPixels = st_DrawPixels; functions->CopyPixels = st_CopyPixels; } + + +void +st_destroy_drawpix(struct st_context *st) +{ + st_reference_fragprog(st, &st->drawpix.z_shader, NULL); + st_reference_fragprog(st, &st->pixel_xfer.combined_prog, NULL); + st_reference_vertprog(st, &st->drawpix.vert_shaders[0], NULL); + st_reference_vertprog(st, &st->drawpix.vert_shaders[1], NULL); +} + + diff --git a/src/mesa/state_tracker/st_cb_drawpixels.h b/src/mesa/state_tracker/st_cb_drawpixels.h index 71ba487020..26fe864d18 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.h +++ b/src/mesa/state_tracker/st_cb_drawpixels.h @@ -32,5 +32,8 @@ extern void st_init_drawpixels_functions(struct dd_function_table *functions); +extern void +st_destroy_drawpix(struct st_context *st); + #endif /* ST_CB_DRAWPIXELS_H */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index fb397ea510..b407fd884b 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -168,6 +168,7 @@ static void st_destroy_context_priv( struct st_context *st ) st_destroy_bitmap(st); st_destroy_blit(st); st_destroy_clear(st); + st_destroy_drawpix(st); _vbo_DestroyContext(st->ctx); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 1ca779d0a9..46c16e45e6 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -152,6 +152,12 @@ struct st_context struct bitmap_cache *cache; } bitmap; + /** for glDraw/CopyPixels */ + struct { + struct st_fragment_program *z_shader; + struct st_vertex_program *vert_shaders[2]; + } drawpix; + /** for glClear */ struct { struct pipe_shader_state vert_shader; -- cgit v1.2.3 From 8f6d9e12be0be086ca2aab0b56dff8d2181addd9 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 14 Aug 2008 15:38:09 -0600 Subject: gallium: use a default texture in update_textures(), update_samplers() when needed The default texture is used when the current fragment shader has texture sample instructions but the user has not provided/bound a texture. --- src/mesa/state_tracker/st_atom_sampler.c | 12 ++++++---- src/mesa/state_tracker/st_atom_texture.c | 34 ++++++++++++++++++--------- src/mesa/state_tracker/st_cb_texture.c | 40 ++++++++++++++++++++++++++++++++ src/mesa/state_tracker/st_cb_texture.h | 4 ++++ src/mesa/state_tracker/st_context.c | 5 ++++ src/mesa/state_tracker/st_context.h | 2 ++ 6 files changed, 82 insertions(+), 15 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 3ba6a971f6..cef61fb55c 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -35,6 +35,7 @@ #include "main/macros.h" #include "st_context.h" +#include "st_cb_texture.h" #include "st_atom.h" #include "st_program.h" #include "pipe/p_context.h" @@ -125,6 +126,8 @@ update_samplers(struct st_context *st) st->state.num_samplers = 0; + /*printf("%s samplers used = 0x%x\n", __FUNCTION__, fs->Base.Base.SamplersUsed);*/ + /* loop over sampler units (aka tex image units) */ for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) { struct pipe_sampler_state *sampler = st->state.samplers + su; @@ -136,8 +139,9 @@ update_samplers(struct st_context *st) const struct gl_texture_object *texobj = st->ctx->Texture.Unit[texUnit]._Current; - if (!texobj) - continue; + if (!texobj) { + texobj = st_get_default_texture(st); + } sampler->wrap_s = gl_wrap_to_sp(texobj->WrapS); sampler->wrap_t = gl_wrap_to_sp(texobj->WrapT); @@ -184,11 +188,11 @@ update_samplers(struct st_context *st) st->state.num_samplers = su + 1; - /* XXX more sampler state here */ - + /*printf("%s su=%u non-null\n", __FUNCTION__, su);*/ cso_single_sampler(st->cso_context, su, sampler); } else { + /*printf("%s su=%u null\n", __FUNCTION__, su);*/ cso_single_sampler(st->cso_context, su, NULL); } } diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 1ec671ed48..fb03766ff5 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -49,6 +49,8 @@ update_textures(struct st_context *st) st->state.num_textures = 0; + /*printf("%s samplers used = 0x%x\n", __FUNCTION__, fprog->Base.SamplersUsed);*/ + for (su = 0; su < st->ctx->Const.MaxTextureCoordUnits; su++) { struct pipe_texture *pt = NULL; @@ -56,24 +58,34 @@ update_textures(struct st_context *st) const GLuint texUnit = fprog->Base.SamplerUnits[su]; struct gl_texture_object *texObj = st->ctx->Texture.Unit[texUnit]._Current; - struct st_texture_object *stObj = st_texture_object(texObj); - - if (texObj) { - GLboolean flush, retval; + struct st_texture_object *stObj; + GLboolean flush, retval; - retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); - if (!retval) { - /* out of mem */ - /* missing texture */ - continue; - } + if (!texObj) { + texObj = st_get_default_texture(st); + } + stObj = st_texture_object(texObj); - st->state.num_textures = su + 1; + retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); + if (!retval) { + /* out of mem */ + continue; } + st->state.num_textures = su + 1; + pt = st_get_stobj_texture(stObj); } + /* + if (pt) { + printf("%s su=%u non-null\n", __FUNCTION__, su); + } + else { + printf("%s su=%u null\n", __FUNCTION__, su); + } + */ + pipe_texture_reference(&st->state.sampler_texture[su], pt); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index fceb260d70..f291531f81 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1461,6 +1461,46 @@ st_finalize_texture(GLcontext *ctx, } +/** + * Returns pointer to a default/dummy texture. + * This is typically used when the current shader has tex/sample instructions + * but the user has not provided a (any) texture(s). + */ +struct gl_texture_object * +st_get_default_texture(struct st_context *st) +{ + if (!st->default_texture) { + static const GLenum target = GL_TEXTURE_2D; + GLubyte pixels[16][16][4]; + struct gl_texture_object *texObj; + struct gl_texture_image *texImg; + + texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target); + + texImg = _mesa_get_tex_image(st->ctx, texObj, target, 0); + + _mesa_init_teximage_fields(st->ctx, target, texImg, + 16, 16, 1, 0, /* w, h, d, border */ + GL_RGBA); + + st_TexImage(st->ctx, 2, target, + 0, GL_RGBA, /* level, intformat */ + 16, 16, 1, 0, /* w, h, d, border */ + GL_RGBA, GL_UNSIGNED_BYTE, pixels, + &st->ctx->DefaultPacking, + texObj, texImg, + 0, 0); + + texObj->MinFilter = GL_NEAREST; + texObj->MagFilter = GL_NEAREST; + texObj->_Complete = GL_TRUE; + + st->default_texture = texObj; + } + return st->default_texture; +} + + void st_init_texture_functions(struct dd_function_table *functions) { diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h index 843745fcd6..f1fe0339cd 100644 --- a/src/mesa/state_tracker/st_cb_texture.h +++ b/src/mesa/state_tracker/st_cb_texture.h @@ -37,6 +37,10 @@ st_finalize_texture(GLcontext *ctx, GLboolean *needFlush); +extern struct gl_texture_object * +st_get_default_texture(struct st_context *st); + + extern void st_init_texture_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 6e4a376d44..d014ace59f 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -199,6 +199,11 @@ static void st_destroy_context_priv( struct st_context *st ) } } + if (st->default_texture) { + st->ctx->Driver.DeleteTexture(st->ctx, st->default_texture); + st->default_texture = NULL; + } + free( st ); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 96333902a9..4314d9af5c 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -132,6 +132,8 @@ struct st_context struct st_vertex_program *vp; /**< Currently bound vertex program */ struct st_fragment_program *fp; /**< Currently bound fragment program */ + struct gl_texture_object *default_texture; + struct { struct gl_program_cache *cache; struct st_fragment_program *program; /**< cur pixel transfer prog */ -- cgit v1.2.3 From 1a820f52f6fa125786538c1adf2aa350e66b8c1e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 17 Sep 2008 14:32:33 -0600 Subject: gallium: clean-up/fix msaa override in state tracker --- src/mesa/state_tracker/st_atom_rasterizer.c | 2 +- src/mesa/state_tracker/st_context.c | 15 +++++++++++++++ src/mesa/state_tracker/st_context.h | 6 ++++++ src/mesa/state_tracker/st_framebuffer.c | 11 +++++------ 4 files changed, 27 insertions(+), 7 deletions(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index e286dc5116..fc47896c24 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -254,7 +254,7 @@ static void update_raster_state( struct st_context *st ) raster->line_stipple_factor = ctx->Line.StippleFactor - 1; /* _NEW_MULTISAMPLE */ - if (ctx->Multisample._Enabled) + if (ctx->Multisample._Enabled || st->force_msaa) raster->multisample = 1; /* _NEW_SCISSOR */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 534c7c12ac..cca808d328 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -88,6 +88,19 @@ void st_invalidate_state(GLcontext * ctx, GLuint new_state) } +/** + * Check for multisample env var override. + */ +int +st_get_msaa(void) +{ + const char *msaa = _mesa_getenv("__GL_FSAA_MODE"); + if (msaa) + return atoi(msaa); + return 0; +} + + static struct st_context * st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) { @@ -141,6 +154,8 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st->pixel_xfer.cache = _mesa_new_program_cache(); + st->force_msaa = st_get_msaa(); + /* GL limits and extensions */ st_init_limits(st); st_init_extensions(st); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 4314d9af5c..1d1aca3111 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -181,6 +181,8 @@ struct st_context struct blit_state *blit; struct cso_context *cso_context; + + int force_msaa; }; @@ -238,4 +240,8 @@ st_fb_orientation(const struct gl_framebuffer *fb) } +extern int +st_get_msaa(void); + + #endif diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 0f4a03fa48..ec8928f200 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -51,13 +51,12 @@ st_create_framebuffer( const __GLcontextModes *visual, { struct st_framebuffer *stfb = CALLOC_STRUCT(st_framebuffer); if (stfb) { - int samples = 0; - const char *msaa_override = _mesa_getenv("__GL_FSAA_MODE"); + int samples = st_get_msaa(); + + if (visual->sampleBuffers) + samples = visual->samples; + _mesa_initialize_framebuffer(&stfb->Base, visual); - if (visual->sampleBuffers) samples = visual->samples; - if (msaa_override) { - samples = _mesa_atoi(msaa_override); - } { /* fake frontbuffer */ -- cgit v1.2.3 From 281055987a535d7fa226cfbd9e1acb7777b2b3dd Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 26 Nov 2008 07:06:14 -0700 Subject: gallium: replace 2 with PIPE_SHADER_TYPES --- src/mesa/state_tracker/st_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_context.h') diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 1d1aca3111..5bcb87ce20 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -102,7 +102,7 @@ struct st_context } state; struct { - struct st_tracked_state tracked_state[2]; + struct st_tracked_state tracked_state[PIPE_SHADER_TYPES]; } constants; /* XXX unused: */ -- 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_context.h') 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