From bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4d Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 11 Apr 2006 11:41:11 +0000 Subject: [PATCH] More GLSL code: - use macros to access and modify render inputs bit-field; - un-alias generic vertex attributes for ARB vertex calls; - use MAX_VERTEX_PROGRAM_ATTRIBS (NV code) or MAX_VERTEX_ATTRIBS (ARB code) in place of VERT_ATTRIB_MAX; - define VERT_ATTRIB_GENERIC0..15 for un-aliased vertex attributes for ARB_vertex_shader; - fix generic attribute index range check in arbprogparse.c; - interface GLSL varyings between vertex and fragment shader; - use 64-bit optimised bitset (bitset.h) for render inputs; --- src/mesa/drivers/dri/i915/i830_context.h | 2 +- src/mesa/drivers/dri/i915/i830_vtbl.c | 45 ++-- src/mesa/drivers/dri/i915/i915_texprog.c | 21 +- src/mesa/drivers/dri/r128/r128_context.c | 2 +- src/mesa/drivers/dri/r128/r128_context.h | 2 +- src/mesa/drivers/dri/r128/r128_lock.c | 2 +- src/mesa/drivers/dri/r128/r128_tris.c | 25 ++- src/mesa/drivers/dri/r200/r200_context.h | 2 +- src/mesa/drivers/dri/r200/r200_swtcl.c | 31 +-- src/mesa/drivers/dri/r300/r300_context.h | 2 +- src/mesa/drivers/dri/r300/r300_maos.c | 50 ++--- src/mesa/drivers/dri/r300/r300_state.c | 31 ++- src/mesa/drivers/dri/radeon/radeon_context.h | 2 +- src/mesa/drivers/dri/radeon/radeon_swtcl.c | 31 +-- src/mesa/drivers/dri/savage/savagetris.c | 42 ++-- src/mesa/drivers/dri/sis/sis_context.h | 2 +- src/mesa/drivers/dri/sis/sis_tris.c | 19 +- src/mesa/drivers/dri/unichrome/via_tris.c | 27 ++- src/mesa/main/api_noop.c | 53 +++-- src/mesa/main/bitset.h | 194 ++++++++++------- src/mesa/main/dlist.c | 48 ++--- src/mesa/main/mtypes.h | 44 +++- src/mesa/main/state.c | 17 +- src/mesa/main/varray.c | 6 +- src/mesa/shader/arbprogparse.c | 4 +- src/mesa/shader/arbprogram.c | 9 +- src/mesa/shader/nvvertexec.c | 4 +- src/mesa/swrast/s_arbshader.c | 208 ++++++++++--------- src/mesa/swrast/s_context.h | 7 +- src/mesa/swrast/s_span.c | 70 +++++-- src/mesa/swrast/s_tritemp.h | 66 +++++- src/mesa/swrast/swrast.h | 3 +- src/mesa/swrast_setup/ss_context.c | 76 ++++--- src/mesa/swrast_setup/ss_context.h | 7 +- src/mesa/tnl/t_context.c | 35 ++-- src/mesa/tnl/t_context.h | 160 ++++++-------- src/mesa/tnl/t_save_api.c | 32 +-- src/mesa/tnl/t_vb_arbshader.c | 23 ++ src/mesa/tnl/t_vtx_generic.c | 61 ++++-- 39 files changed, 882 insertions(+), 583 deletions(-) diff --git a/src/mesa/drivers/dri/i915/i830_context.h b/src/mesa/drivers/dri/i915/i830_context.h index 5bdcc21c5ab..d5811e6c349 100644 --- a/src/mesa/drivers/dri/i915/i830_context.h +++ b/src/mesa/drivers/dri/i915/i830_context.h @@ -118,7 +118,7 @@ struct i830_context { struct intel_context intel; - GLuint last_index; + DECLARE_RENDERINPUTS(last_index_bitset); struct i830_hw_state meta, initial, state, *current; }; diff --git a/src/mesa/drivers/dri/i915/i830_vtbl.c b/src/mesa/drivers/dri/i915/i830_vtbl.c index e8913e8063c..9e71b111091 100644 --- a/src/mesa/drivers/dri/i915/i830_vtbl.c +++ b/src/mesa/drivers/dri/i915/i830_vtbl.c @@ -65,11 +65,13 @@ static void i830_render_start( intelContextPtr intel ) i830ContextPtr i830 = I830_CONTEXT(intel); TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); GLuint v0 = _3DSTATE_VFT0_CMD; GLuint v2 = _3DSTATE_VFT1_CMD; GLuint mcsb1 = 0; + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); + /* Important: */ VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; @@ -78,7 +80,7 @@ static void i830_render_start( intelContextPtr intel ) /* EMIT_ATTR's must be in order as they tell t_vertex.c how to * build up a hardware vertex. */ - if (index & _TNL_BITS_TEX_ANY) { + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, VFT0_XYZW ); intel->coloroffset = 4; } @@ -87,36 +89,37 @@ static void i830_render_start( intelContextPtr intel ) intel->coloroffset = 3; } - if (index & _TNL_BIT_POINTSIZE) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_POINTSIZE )) { EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, VFT0_POINT_WIDTH ); } EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, VFT0_DIFFUSE ); intel->specoffset = 0; - if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { - if (index & _TNL_BIT_COLOR1) { - intel->specoffset = intel->coloroffset + 1; - EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VFT0_SPEC ); + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) || + RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { + intel->specoffset = intel->coloroffset + 1; + EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VFT0_SPEC ); } - else - EMIT_PAD( 3 ); - - if (index & _TNL_BIT_FOG) - EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, VFT0_SPEC ); else - EMIT_PAD( 1 ); + EMIT_PAD( 3 ); + + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) + EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, VFT0_SPEC ); + else + EMIT_PAD( 1 ); } - if (index & _TNL_BITS_TEX_ANY) { + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { int i, count = 0; for (i = 0; i < I830_TEX_UNITS; i++) { - if (index & _TNL_BIT_TEX(i)) { - GLuint sz = VB->TexCoordPtr[i]->size; - GLuint emit; - GLuint mcs = (i830->state.Tex[i][I830_TEXREG_MCS] & - ~TEXCOORDTYPE_MASK); + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(i) )) { + GLuint sz = VB->TexCoordPtr[i]->size; + GLuint emit; + GLuint mcs = (i830->state.Tex[i][I830_TEXREG_MCS] & + ~TEXCOORDTYPE_MASK); switch (sz) { case 1: @@ -162,7 +165,7 @@ static void i830_render_start( intelContextPtr intel ) if (v0 != i830->state.Ctx[I830_CTXREG_VF] || v2 != i830->state.Ctx[I830_CTXREG_VF2] || mcsb1 != i830->state.Ctx[I830_CTXREG_MCSB1] || - index != i830->last_index) { + !RENDERINPUTS_EQUAL( index_bitset, i830->last_index_bitset )) { I830_STATECHANGE( i830, I830_UPLOAD_CTX ); @@ -180,7 +183,7 @@ static void i830_render_start( intelContextPtr intel ) i830->state.Ctx[I830_CTXREG_VF] = v0; i830->state.Ctx[I830_CTXREG_VF2] = v2; i830->state.Ctx[I830_CTXREG_MCSB1] = mcsb1; - i830->last_index = index; + RENDERINPUTS_COPY( i830->last_index_bitset, index_bitset ); assert(i830_check_vertex_size( intel, intel->vertex_size )); } diff --git a/src/mesa/drivers/dri/i915/i915_texprog.c b/src/mesa/drivers/dri/i915/i915_texprog.c index 74ece96f8b7..4fbce34ba21 100644 --- a/src/mesa/drivers/dri/i915/i915_texprog.c +++ b/src/mesa/drivers/dri/i915/i915_texprog.c @@ -576,11 +576,13 @@ void i915ValidateTextureProgram( i915ContextPtr i915 ) GLcontext *ctx = &intel->ctx; TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); int i, offset; GLuint s4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_VFMT_MASK; GLuint s2 = S2_TEXCOORD_NONE; + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); + /* Important: */ VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; @@ -591,9 +593,9 @@ void i915ValidateTextureProgram( i915ContextPtr i915 ) if (i915->vertex_fog == I915_FOG_PIXEL) { EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, S4_VFMT_XYZW, 16 ); - index &= ~_TNL_BIT_FOG; + RENDERINPUTS_CLEAR( index_bitset, _TNL_ATTRIB_FOG ); } - else if (index & _TNL_BITS_TEX_ANY) { + else if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, S4_VFMT_XYZW, 16 ); } else { @@ -601,29 +603,30 @@ void i915ValidateTextureProgram( i915ContextPtr i915 ) } /* How undefined is undefined? */ - if (index & _TNL_BIT_POINTSIZE) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_POINTSIZE )) { EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, S4_VFMT_POINT_WIDTH, 4 ); } intel->coloroffset = offset / 4; EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, S4_VFMT_COLOR, 4 ); - if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { - if (index & _TNL_BIT_COLOR1) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) || + RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { intel->specoffset = offset / 4; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, S4_VFMT_SPEC_FOG, 3 ); } else EMIT_PAD( 3 ); - if (index & _TNL_BIT_FOG) + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, S4_VFMT_SPEC_FOG, 1 ); else EMIT_PAD( 1 ); } - if (index & _TNL_BITS_TEX_ANY) { + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { for (i = 0; i < 8; i++) { - if (index & _TNL_BIT_TEX(i)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(i) )) { int sz = VB->TexCoordPtr[i]->size; s2 &= ~S2_TEXCOORD_FMT(i, S2_TEXCOORD_FMT0_MASK); diff --git a/src/mesa/drivers/dri/r128/r128_context.c b/src/mesa/drivers/dri/r128/r128_context.c index 6194d128f4b..2f30bd253bf 100644 --- a/src/mesa/drivers/dri/r128/r128_context.c +++ b/src/mesa/drivers/dri/r128/r128_context.c @@ -190,7 +190,7 @@ GLboolean r128CreateContext( const __GLcontextModes *glVisual, rmesa->RenderIndex = -1; /* Impossible value */ rmesa->vert_buf = NULL; rmesa->num_verts = 0; - rmesa->tnl_state = ~0; + RENDERINPUTS_ONES( rmesa->tnl_state_bitset ); /* Set the maximum texture size small enough that we can guarentee that * all texture units can bind a maximal texture and have them both in diff --git a/src/mesa/drivers/dri/r128/r128_context.h b/src/mesa/drivers/dri/r128/r128_context.h index b3552ac7639..c51dd7fa58d 100644 --- a/src/mesa/drivers/dri/r128/r128_context.h +++ b/src/mesa/drivers/dri/r128/r128_context.h @@ -130,7 +130,7 @@ struct r128_context { char *verts; /* points to tnl->clipspace.vertex_buf */ GLuint num_verts; int coloroffset, specoffset; - int tnl_state; /* tnl->render_inputs for this _tnl_install_attrs */ + DECLARE_RENDERINPUTS(tnl_state_bitset); /* tnl->render_inputs for this _tnl_install_attrs */ GLuint NewGLState; GLuint Fallback; diff --git a/src/mesa/drivers/dri/r128/r128_lock.c b/src/mesa/drivers/dri/r128/r128_lock.c index ef67bc6a43a..393dd1ed74c 100644 --- a/src/mesa/drivers/dri/r128/r128_lock.c +++ b/src/mesa/drivers/dri/r128/r128_lock.c @@ -89,7 +89,7 @@ void r128GetLock( r128ContextPtr rmesa, GLuint flags ) driUpdateFramebufferSize(rmesa->glCtx, dPriv); rmesa->lastStamp = dPriv->lastStamp; rmesa->new_state |= R128_NEW_CLIP; - rmesa->tnl_state = ~0; + RENDERINPUTS_ONES( rmesa->tnl_state_bitset ); } rmesa->dirty |= R128_UPLOAD_CONTEXT | R128_UPLOAD_CLIPRECTS; diff --git a/src/mesa/drivers/dri/r128/r128_tris.c b/src/mesa/drivers/dri/r128/r128_tris.c index 64f54682b6e..46315225165 100644 --- a/src/mesa/drivers/dri/r128/r128_tris.c +++ b/src/mesa/drivers/dri/r128/r128_tris.c @@ -564,11 +564,13 @@ static void r128RenderStart( GLcontext *ctx ) r128ContextPtr rmesa = R128_CONTEXT(ctx); TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); GLuint vc_frmt = 0; GLboolean fallback_projtex = GL_FALSE; GLuint offset = 0; + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); + /* Important: */ VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; rmesa->vertex_attr_count = 0; @@ -577,7 +579,7 @@ static void r128RenderStart( GLcontext *ctx ) /* EMIT_ATTR's must be in order as they tell t_vertex.c how to * build up a hardware vertex. */ - if ( index & _TNL_BITS_TEX_ANY ) + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, R128_CCE_VC_FRMT_RHW, 16 ); else EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, 0, 12 ); @@ -591,28 +593,29 @@ static void r128RenderStart( GLcontext *ctx ) R128_CCE_VC_FRMT_DIFFUSE_ARGB, 4 ); #endif - if ( index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG) ) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) || + RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { #if MESA_LITTLE_ENDIAN - if ( index & _TNL_BIT_COLOR1) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { rmesa->specoffset = offset; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, R128_CCE_VC_FRMT_SPEC_FRGB, 3 ); } else EMIT_PAD( 3 ); - if (index & _TNL_BIT_FOG) + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, R128_CCE_VC_FRMT_SPEC_FRGB, 1 ); else EMIT_PAD( 1 ); #else - if (index & _TNL_BIT_FOG) + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, R128_CCE_VC_FRMT_SPEC_FRGB, 1 ); else EMIT_PAD( 1 ); - if ( index & _TNL_BIT_COLOR1) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { rmesa->specoffset = offset; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_RGB, R128_CCE_VC_FRMT_SPEC_FRGB, 3 ); @@ -621,12 +624,12 @@ static void r128RenderStart( GLcontext *ctx ) #endif } - if ( index & _TNL_BIT_TEX(rmesa->tmu_source[0]) ) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(rmesa->tmu_source[0]) )) { if ( VB->TexCoordPtr[rmesa->tmu_source[0]]->size > 2 ) fallback_projtex = GL_TRUE; EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_2F, R128_CCE_VC_FRMT_S_T, 8 ); } - if ( index & _TNL_BIT_TEX(rmesa->tmu_source[1]) ) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(rmesa->tmu_source[1]) )) { if ( VB->TexCoordPtr[rmesa->tmu_source[1]]->size > 2 ) fallback_projtex = GL_TRUE; EMIT_ATTR( _TNL_ATTRIB_TEX1, EMIT_2F, R128_CCE_VC_FRMT_S2_T2, 8 ); @@ -638,7 +641,7 @@ static void r128RenderStart( GLcontext *ctx ) /* Only need to change the vertex emit code if there has been a * statechange to a TNL index. */ - if ( index != rmesa->tnl_state ) { + if (!RENDERINPUTS_EQUAL( index_bitset, rmesa->tnl_state_bitset )) { FLUSH_BATCH( rmesa ); rmesa->dirty |= R128_UPLOAD_CONTEXT; @@ -763,7 +766,7 @@ void r128InitTriFuncs( GLcontext *ctx ) _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12, (6 + 2 * ctx->Const.MaxTextureUnits) * sizeof(GLfloat) ); rmesa->verts = (char *)tnl->clipspace.vertex_buf; - rmesa->tnl_state = -1; + RENDERINPUTS_ONES( rmesa->tnl_state_bitset ); rmesa->NewGLState |= _R128_NEW_RENDER_STATE; } diff --git a/src/mesa/drivers/dri/r200/r200_context.h b/src/mesa/drivers/dri/r200/r200_context.h index faf1b96a2b8..f6709d3d7fd 100644 --- a/src/mesa/drivers/dri/r200/r200_context.h +++ b/src/mesa/drivers/dri/r200/r200_context.h @@ -897,7 +897,7 @@ struct r200_context { GLuint TclFallback; GLuint Fallback; GLuint NewGLState; - GLuint tnl_index; /* index of bits for last tnl_install_attrs */ + DECLARE_RENDERINPUTS(tnl_index_bitset); /* index of bits for last tnl_install_attrs */ /* Vertex buffers */ diff --git a/src/mesa/drivers/dri/r200/r200_swtcl.c b/src/mesa/drivers/dri/r200/r200_swtcl.c index 7ab3f7cd032..aa78f382868 100644 --- a/src/mesa/drivers/dri/r200/r200_swtcl.c +++ b/src/mesa/drivers/dri/r200/r200_swtcl.c @@ -85,11 +85,12 @@ static void r200SetVertexFormat( GLcontext *ctx ) r200ContextPtr rmesa = R200_CONTEXT( ctx ); TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); int fmt_0 = 0; int fmt_1 = 0; int offset = 0; + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); /* Important: */ @@ -106,7 +107,8 @@ static void r200SetVertexFormat( GLcontext *ctx ) /* EMIT_ATTR's must be in order as they tell t_vertex.c how to * build up a hardware vertex. */ - if ( !rmesa->swtcl.needproj || (index & _TNL_BITS_TEX_ANY)) { /* need w coord for projected textures */ + if ( !rmesa->swtcl.needproj || + RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { /* need w coord for projected textures */ EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F, R200_VTX_XY | R200_VTX_Z0 | R200_VTX_W0 ); offset = 4; } @@ -124,10 +126,11 @@ static void r200SetVertexFormat( GLcontext *ctx ) offset += 1; rmesa->swtcl.specoffset = 0; - if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) || + RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { #if MESA_LITTLE_ENDIAN - if (index & _TNL_BIT_COLOR1) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { rmesa->swtcl.specoffset = offset; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_RGB, (R200_VTX_PK_RGBA << R200_VTX_COLOR_1_SHIFT) ); } @@ -135,21 +138,21 @@ static void r200SetVertexFormat( GLcontext *ctx ) EMIT_PAD( 3 ); } - if (index & _TNL_BIT_FOG) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, (R200_VTX_PK_RGBA << R200_VTX_COLOR_1_SHIFT) ); } else { EMIT_PAD( 1 ); } #else - if (index & _TNL_BIT_FOG) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, (R200_VTX_PK_RGBA << R200_VTX_COLOR_1_SHIFT) ); } else { EMIT_PAD( 1 ); } - if (index & _TNL_BIT_COLOR1) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { rmesa->swtcl.specoffset = offset; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, (R200_VTX_PK_RGBA << R200_VTX_COLOR_1_SHIFT) ); } @@ -159,11 +162,11 @@ static void r200SetVertexFormat( GLcontext *ctx ) #endif } - if (index & _TNL_BITS_TEX_ANY) { + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { int i; for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { - if (index & _TNL_BIT_TEX(i)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(i) )) { GLuint sz = VB->TexCoordPtr[i]->size; fmt_1 |= sz << (3 * i); @@ -179,7 +182,7 @@ static void r200SetVertexFormat( GLcontext *ctx ) rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] |= R200_FOG_USE_SPEC_ALPHA; } - if ( rmesa->tnl_index != index || + if (!RENDERINPUTS_EQUAL( rmesa->tnl_index_bitset, index_bitset ) || (rmesa->hw.vtx.cmd[VTX_VTXFMT_0] != fmt_0) || (rmesa->hw.vtx.cmd[VTX_VTXFMT_1] != fmt_1) ) { R200_NEWPRIM(rmesa); @@ -193,7 +196,7 @@ static void r200SetVertexFormat( GLcontext *ctx ) rmesa->swtcl.vertex_attr_count, NULL, 0 ); rmesa->swtcl.vertex_size /= 4; - rmesa->tnl_index = index; + RENDERINPUTS_COPY( rmesa->tnl_index_bitset, index_bitset ); } } @@ -235,12 +238,12 @@ void r200ChooseVertexState( GLcontext *ctx ) /* HW perspective divide is a win, but tiny vertex formats are a * bigger one. */ - if ( ((tnl->render_inputs & _TNL_BITS_TEX_ANY) == 0) + if (!RENDERINPUTS_TEST_RANGE( tnl->render_inputs_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX ) || (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) { rmesa->swtcl.needproj = GL_TRUE; vte |= R200_VTX_XY_FMT | R200_VTX_Z_FMT; vte &= ~R200_VTX_W0_FMT; - if (tnl->render_inputs & _TNL_BITS_TEX_ANY) { + if (RENDERINPUTS_TEST_RANGE( tnl->render_inputs_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { vap &= ~R200_VAP_FORCE_W_TO_ONE; } else { @@ -719,7 +722,7 @@ void r200Fallback( GLcontext *ctx, GLuint bit, GLboolean mode ) */ _tnl_invalidate_vertex_state( ctx, ~0 ); _tnl_invalidate_vertices( ctx, ~0 ); - rmesa->tnl_index = 0; + RENDERINPUTS_ZERO( rmesa->tnl_index_bitset ); r200ChooseVertexState( ctx ); r200ChooseRenderState( ctx ); } diff --git a/src/mesa/drivers/dri/r300/r300_context.h b/src/mesa/drivers/dri/r300/r300_context.h index 449459b5b10..7504bd894ab 100644 --- a/src/mesa/drivers/dri/r300/r300_context.h +++ b/src/mesa/drivers/dri/r300/r300_context.h @@ -776,7 +776,7 @@ struct r300_state { GLuint *Elts; struct r300_dma_region elt_dma; - GLuint render_inputs; /* actual render inputs that R300 was configured for. + DECLARE_RENDERINPUTS(render_inputs_bitset); /* actual render inputs that R300 was configured for. They are the same as tnl->render_inputs for fixed pipeline */ struct { diff --git a/src/mesa/drivers/dri/r300/r300_maos.c b/src/mesa/drivers/dri/r300/r300_maos.c index 1aa005c7207..290ffb44eab 100644 --- a/src/mesa/drivers/dri/r300/r300_maos.c +++ b/src/mesa/drivers/dri/r300/r300_maos.c @@ -268,8 +268,10 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd) GLuint vic_1 = 0; /* R300_VAP_INPUT_CNTL_1 */ GLuint aa_vap_reg = 0; /* VAP register assignment */ GLuint i; - GLuint inputs = 0; - + DECLARE_RENDERINPUTS(inputs_bitset); + + RENDERINPUTS_ZERO( inputs_bitset ); + #define CONFIGURE_AOS(r, f, v, sz, cn) { \ if (RADEON_DEBUG & DEBUG_STATE) \ fprintf(stderr, "Enabling "#v "\n"); \ @@ -300,23 +302,23 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd) GLuint InputsRead = CURRENT_VERTEX_SHADER(ctx)->Base.InputsRead; struct r300_vertex_program *prog=(struct r300_vertex_program *)CURRENT_VERTEX_SHADER(ctx); if (InputsRead & (1<state.aos[nr++].aos_reg = prog->inputs[VERT_ATTRIB_POS]; } if (InputsRead & (1<state.aos[nr++].aos_reg = prog->inputs[VERT_ATTRIB_NORMAL]; } if (InputsRead & (1<state.aos[nr++].aos_reg = prog->inputs[VERT_ATTRIB_COLOR0]; } if (InputsRead & (1<state.aos[nr++].aos_reg = prog->inputs[VERT_ATTRIB_COLOR1]; } if (InputsRead & (1<state.aos[nr++].aos_reg = prog->inputs[VERT_ATTRIB_FOG]; } if(ctx->Const.MaxTextureUnits > 8) { /* Not sure if this can even happen... */ @@ -325,17 +327,17 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd) } for (i=0;iConst.MaxTextureUnits;i++) { if (InputsRead & (1<<(VERT_ATTRIB_TEX0+i))) { - inputs |= _TNL_BIT_TEX0<state.aos[nr++].aos_reg = prog->inputs[VERT_ATTRIB_TEX0+i]; } } nr = 0; } else { - inputs = TNL_CONTEXT(ctx)->render_inputs; + RENDERINPUTS_COPY( inputs_bitset, TNL_CONTEXT(ctx)->render_inputs_bitset ); } - rmesa->state.render_inputs = inputs; + RENDERINPUTS_COPY( rmesa->state.render_inputs_bitset, inputs_bitset ); - if (inputs & _TNL_BIT_POS) { + if (RENDERINPUTS_TEST( inputs_bitset, _TNL_ATTRIB_POS )) { CONFIGURE_AOS(i_coords, AOS_FORMAT_FLOAT, VB->AttribPtr[VERT_ATTRIB_POS], immd ? 4 : VB->AttribPtr[VERT_ATTRIB_POS].size, @@ -344,7 +346,7 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd) vic_1 |= R300_INPUT_CNTL_POS; } - if (inputs & _TNL_BIT_NORMAL) { + if (RENDERINPUTS_TEST( inputs_bitset, _TNL_ATTRIB_NORMAL )) { CONFIGURE_AOS(i_normal, AOS_FORMAT_FLOAT, VB->AttribPtr[VERT_ATTRIB_NORMAL], immd ? 4 : VB->AttribPtr[VERT_ATTRIB_NORMAL].size, @@ -353,7 +355,7 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd) vic_1 |= R300_INPUT_CNTL_NORMAL; } - if (inputs & _TNL_BIT_COLOR0) { + if (RENDERINPUTS_TEST( inputs_bitset, _TNL_ATTRIB_COLOR0 )) { int emitsize=4; if (!immd) { @@ -376,7 +378,7 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd) vic_1 |= R300_INPUT_CNTL_COLOR; } - if (inputs & _TNL_BIT_COLOR1) { + if (RENDERINPUTS_TEST( inputs_bitset, _TNL_ATTRIB_COLOR1 )) { int emitsize=4; if (!immd) { @@ -398,7 +400,7 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd) } #if 0 - if (inputs & _TNL_BIT_FOG) { + if (RENDERINPUTS_TEST( inputs_bitset, _TNL_ATTRIB_FOG )) { CONFIGURE_AOS( AOS_FORMAT_FLOAT, VB->FogCoordPtr, immd ? 4 : VB->FogCoordPtr->size, @@ -408,7 +410,7 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd) r300->state.texture.tc_count = 0; for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { - if (inputs & (_TNL_BIT_TEX0 << i)) { + if (RENDERINPUTS_TEST( inputs_bitset, _TNL_ATTRIB_TEX(i) )) { CONFIGURE_AOS(i_tex[i], AOS_FORMAT_FLOAT, VB->AttribPtr[VERT_ATTRIB_TEX0+i], immd ? 4 : VB->AttribPtr[VERT_ATTRIB_TEX0+i].size, @@ -531,17 +533,17 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd) #if 0 r300->hw.vic.cmd[R300_VIC_CNTL_1]=0; - if(r300->state.render_inputs & _TNL_BIT_POS) + if(RENDERINPUTS_TEST( r300->state.render_inputs_bitset, _TNL_ATTRIB_POS )) r300->hw.vic.cmd[R300_VIC_CNTL_1]|=R300_INPUT_CNTL_POS; - if(r300->state.render_inputs & _TNL_BIT_NORMAL) + if(RENDERINPUTS_TEST( r300->state.render_inputs_bitset, _TNL_ATTRIB_NORMAL )) r300->hw.vic.cmd[R300_VIC_CNTL_1]|=R300_INPUT_CNTL_NORMAL; - if(r300->state.render_inputs & _TNL_BIT_COLOR0) + if(RENDERINPUTS_TEST( r300->state.render_inputs_bitset, _TNL_ATTRIB_COLOR0 )) r300->hw.vic.cmd[R300_VIC_CNTL_1]|=R300_INPUT_CNTL_COLOR; for(i=0;i < ctx->Const.MaxTextureUnits;i++) - if(r300->state.render_inputs & (_TNL_BIT_TEX0<state.render_inputs_bitset, _TNL_ATTRIB_TEX(i) )) r300->hw.vic.cmd[R300_VIC_CNTL_1]|=(R300_INPUT_CNTL_TC0<hw.vof.cmd[R300_VOF_CNTL_1] |= (4<<(3*i)); } else { - if(inputs & _TNL_BIT_POS) + if(RENDERINPUTS_TEST( inputs_bitset, _TNL_ATTRIB_POS )) r300->hw.vof.cmd[R300_VOF_CNTL_0] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT; - if(inputs & _TNL_BIT_COLOR0) + if(RENDERINPUTS_TEST( inputs_bitset, _TNL_ATTRIB_COLOR0 )) r300->hw.vof.cmd[R300_VOF_CNTL_0] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_PRESENT; - if(inputs & _TNL_BIT_COLOR1) + if(RENDERINPUTS_TEST( inputs_bitset, _TNL_ATTRIB_COLOR1 )) r300->hw.vof.cmd[R300_VOF_CNTL_0] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT; for(i=0;i < ctx->Const.MaxTextureUnits;i++) - if(inputs & (_TNL_BIT_TEX0<hw.vof.cmd[R300_VOF_CNTL_1]|=(4<<(3*i)); } diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c index 56052d64d26..bb0cb78382b 100644 --- a/src/mesa/drivers/dri/r300/r300_state.c +++ b/src/mesa/drivers/dri/r300/r300_state.c @@ -1270,6 +1270,19 @@ void r300_setup_textures(GLcontext *ctx) fprintf(stderr, "TX_ENABLE: %08x last_hw_tmu=%d\n", r300->hw.txe.cmd[R300_TXE_ENABLE], last_hw_tmu); } +union r300_outputs_written { + GLuint vp_outputs; /* hw_tcl_on */ + DECLARE_RENDERINPUTS(index_bitset); /* !hw_tcl_on */ +}; + +static GLboolean r300_outputs_written_test (r300_outputs_written *ow, GLuint vp_result, + GLuint tnl_attrib) +{ + if (hw_tcl_on) + return ow->vp_outputs & (1 << vp_result); + return RENDERINPUTS_TEST( ow->index_bitset, tnl_attrib ); +} + void r300_setup_rs_unit(GLcontext *ctx) { r300ContextPtr r300 = R300_CONTEXT(ctx); @@ -1284,16 +1297,16 @@ void r300_setup_rs_unit(GLcontext *ctx) 0x00, 0x00 }; - GLuint OutputsWritten; + union r300_outputs_written OutputsWritten; GLuint InputsRead; int fp_reg, high_rr; int in_texcoords, col_interp_nr; int i; if(hw_tcl_on) - OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->Base.OutputsWritten; + OutputsWritten.vp_outputs = CURRENT_VERTEX_SHADER(ctx)->Base.OutputsWritten; else - OutputsWritten = r300->state.render_inputs; + RENDERINPUTS_COPY( OutputsWritten.index_bitset, r300->state.render_inputs_bitset ); if (ctx->FragmentProgram._Current) InputsRead = ctx->FragmentProgram._Current->Base.InputsRead; @@ -1324,7 +1337,7 @@ void r300_setup_rs_unit(GLcontext *ctx) | (fp_reg << R300_RS_ROUTE_DEST_SHIFT); high_rr = fp_reg; - if (!(OutputsWritten & (hw_tcl_on ? (1 << (VERT_RESULT_TEX0+i)) : (_TNL_BIT_TEX0<Base); @@ -1334,12 +1347,12 @@ void r300_setup_rs_unit(GLcontext *ctx) fp_reg++; } /* Need to count all coords enabled at vof */ - if (OutputsWritten & (hw_tcl_on ? (1 << (VERT_RESULT_TEX0+i)) : (_TNL_BIT_TEX0<Base); @@ -1355,7 +1368,7 @@ void r300_setup_rs_unit(GLcontext *ctx) out: if (InputsRead & FRAG_BIT_COL1) { - if (!(OutputsWritten & (hw_tcl_on ? (1<state.render_inputs & _TNL_BIT_COLOR1) { + if (RENDERINPUTS_TEST( r300->state.render_inputs_bitset, _TNL_ATTRIB_COLOR1 )) { WRITE_OP( EASY_VSF_OP(MUL, o_reg++, ALL, RESULT), VSF_REG(r300->state.vap_reg.i_color[1]), @@ -1526,7 +1539,7 @@ static void r300GenerateSimpleVertexShader(r300ContextPtr r300) /* Pass through texture coordinates, if any */ for(i=0;i < r300->radeon.glCtx->Const.MaxTextureUnits;i++) - if(r300->state.render_inputs & (_TNL_BIT_TEX0<state.render_inputs_bitset, _TNL_ATTRIB_TEX(i) )){ // fprintf(stderr, "i_tex[%d]=%d\n", i, r300->state.vap_reg.i_tex[i]); WRITE_OP( EASY_VSF_OP(MUL, o_reg++ /* 2+i */, ALL, RESULT), diff --git a/src/mesa/drivers/dri/radeon/radeon_context.h b/src/mesa/drivers/dri/radeon/radeon_context.h index 9abd8667308..9902e60c595 100644 --- a/src/mesa/drivers/dri/radeon/radeon_context.h +++ b/src/mesa/drivers/dri/radeon/radeon_context.h @@ -735,7 +735,7 @@ struct radeon_context { GLuint TclFallback; GLuint Fallback; GLuint NewGLState; - GLuint tnl_index; /* index of bits for last tnl_install_attrs */ + DECLARE_RENDERINPUTS(tnl_index_bitset); /* index of bits for last tnl_install_attrs */ /* Vertex buffers */ diff --git a/src/mesa/drivers/dri/radeon/radeon_swtcl.c b/src/mesa/drivers/dri/radeon/radeon_swtcl.c index 9924931e1a2..4d5bbbd1f18 100644 --- a/src/mesa/drivers/dri/radeon/radeon_swtcl.c +++ b/src/mesa/drivers/dri/radeon/radeon_swtcl.c @@ -92,10 +92,11 @@ static void radeonSetVertexFormat( GLcontext *ctx ) radeonContextPtr rmesa = RADEON_CONTEXT( ctx ); TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); int fmt_0 = 0; int offset = 0; + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); /* Important: */ @@ -113,7 +114,7 @@ static void radeonSetVertexFormat( GLcontext *ctx ) * build up a hardware vertex. */ if ( !rmesa->swtcl.needproj || - (index & _TNL_BITS_TEX_ANY)) { /* for projtex */ + RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { /* for projtex */ EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F, RADEON_CP_VC_FRMT_XY | RADEON_CP_VC_FRMT_Z | RADEON_CP_VC_FRMT_W0 ); offset = 4; @@ -135,10 +136,11 @@ static void radeonSetVertexFormat( GLcontext *ctx ) offset += 1; rmesa->swtcl.specoffset = 0; - if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) || + RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { #if MESA_LITTLE_ENDIAN - if (index & _TNL_BIT_COLOR1) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { rmesa->swtcl.specoffset = offset; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_RGB, RADEON_CP_VC_FRMT_PKSPEC ); @@ -147,7 +149,7 @@ static void radeonSetVertexFormat( GLcontext *ctx ) EMIT_PAD( 3 ); } - if (index & _TNL_BIT_FOG) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, RADEON_CP_VC_FRMT_PKSPEC ); } @@ -155,7 +157,7 @@ static void radeonSetVertexFormat( GLcontext *ctx ) EMIT_PAD( 1 ); } #else - if (index & _TNL_BIT_FOG) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, RADEON_CP_VC_FRMT_PKSPEC ); } @@ -163,7 +165,7 @@ static void radeonSetVertexFormat( GLcontext *ctx ) EMIT_PAD( 1 ); } - if (index & _TNL_BIT_COLOR1) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { rmesa->swtcl.specoffset = offset; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, RADEON_CP_VC_FRMT_PKSPEC ); @@ -174,11 +176,11 @@ static void radeonSetVertexFormat( GLcontext *ctx ) #endif } - if (index & _TNL_BITS_TEX_ANY) { + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { int i; for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { - if (index & _TNL_BIT_TEX(i)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(i) )) { GLuint sz = VB->TexCoordPtr[i]->size; switch (sz) { @@ -204,7 +206,7 @@ static void radeonSetVertexFormat( GLcontext *ctx ) } } - if ( rmesa->tnl_index != index || + if (!RENDERINPUTS_EQUAL( rmesa->tnl_index_bitset, index_bitset ) || fmt_0 != rmesa->swtcl.vertex_format) { RADEON_NEWPRIM(rmesa); rmesa->swtcl.vertex_format = fmt_0; @@ -214,7 +216,7 @@ static void radeonSetVertexFormat( GLcontext *ctx ) rmesa->swtcl.vertex_attr_count, NULL, 0 ); rmesa->swtcl.vertex_size /= 4; - rmesa->tnl_index = index; + RENDERINPUTS_COPY( rmesa->tnl_index_bitset, index_bitset ); if (RADEON_DEBUG & DEBUG_VERTS) fprintf( stderr, "%s: vertex_size= %d floats\n", __FUNCTION__, rmesa->swtcl.vertex_size); @@ -257,8 +259,9 @@ void radeonChooseVertexState( GLcontext *ctx ) * bigger one. */ - if ( ((tnl->render_inputs & (_TNL_BITS_TEX_ANY|_TNL_BIT_COLOR1) ) == 0) - || (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) { + if ((!RENDERINPUTS_TEST_RANGE( tnl->render_inputs_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX ) && + !RENDERINPUTS_TEST( tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR1 )) + || (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) { rmesa->swtcl.needproj = GL_TRUE; se_coord_fmt = (RADEON_VTX_XY_PRE_MULT_1_OVER_W0 | RADEON_VTX_Z_PRE_MULT_1_OVER_W0 | @@ -938,7 +941,7 @@ void radeonFallback( GLcontext *ctx, GLuint bit, GLboolean mode ) */ _tnl_invalidate_vertex_state( ctx, ~0 ); _tnl_invalidate_vertices( ctx, ~0 ); - rmesa->tnl_index = 0; + RENDERINPUTS_ZERO( rmesa->tnl_index_bitset ); radeonChooseVertexState( ctx ); radeonChooseRenderState( ctx ); } diff --git a/src/mesa/drivers/dri/savage/savagetris.c b/src/mesa/drivers/dri/savage/savagetris.c index 18470401372..3dd821a4d39 100644 --- a/src/mesa/drivers/dri/savage/savagetris.c +++ b/src/mesa/drivers/dri/savage/savagetris.c @@ -867,15 +867,17 @@ static GLboolean savageCheckPTexHack( GLcontext *ctx ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); - if (index & _TNL_BIT_TEX(0) && VB->TexCoordPtr[0]->size == 4) { - if ((index & _TNL_BITS_TEX_ANY) == _TNL_BIT_TEX(0)) + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); + + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX0 ) && VB->TexCoordPtr[0]->size == 4) { + if (!RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_ATTRIB_TEX1, _TNL_LAST_TEX )) return GL_TRUE; /* apply ptex hack */ else FALLBACK(ctx, SAVAGE_FALLBACK_PROJ_TEXTURE, GL_TRUE); } - if ((index & _TNL_BIT_TEX(1)) && VB->TexCoordPtr[1]->size == 4) + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX1 ) && VB->TexCoordPtr[1]->size == 4) FALLBACK(ctx, SAVAGE_FALLBACK_PROJ_TEXTURE, GL_TRUE); return GL_FALSE; /* don't apply ptex hack */ @@ -929,10 +931,11 @@ static __inline__ GLuint savageChooseVertexFormat_s3d( GLcontext *ctx ) savageContextPtr imesa = SAVAGE_CONTEXT(ctx); TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); GLuint setupIndex = SAVAGE_EMIT_XYZ; GLubyte skip; + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); imesa->vertex_attr_count = 0; skip = SAVAGE_SKIP_ALL_S3D; @@ -941,7 +944,7 @@ static __inline__ GLuint savageChooseVertexFormat_s3d( GLcontext *ctx ) /* EMIT_ATTR's must be in order as they tell t_vertex.c how to * build up a hardware vertex. */ - if ((index & _TNL_BITS_TEX_ANY) || !(ctx->_TriangleCaps & DD_FLATSHADE)) + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX ) || !(ctx->_TriangleCaps & DD_FLATSHADE)) EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, SAVAGE_EMIT_W, SAVAGE_SKIP_W ); else { EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, 0, 0 ); @@ -952,17 +955,17 @@ static __inline__ GLuint savageChooseVertexFormat_s3d( GLcontext *ctx ) /* t_context.c always includes a diffuse color */ EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, SAVAGE_EMIT_C0, SAVAGE_SKIP_C0 ); - if ((index & _TNL_BIT_COLOR1)) + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, SAVAGE_EMIT_C1, SAVAGE_SKIP_C1 ); else EMIT_PAD( 3 ); - if ((index & _TNL_BIT_FOG)) + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, SAVAGE_EMIT_FOG, SAVAGE_SKIP_C1 ); else EMIT_PAD( 1 ); skip &= ~SAVAGE_SKIP_C1; - if (index & _TNL_BIT_TEX(0)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX0 )) { if (imesa->ptexHack) EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_3F_XYW, SAVAGE_EMIT_STQ0, SAVAGE_SKIP_ST0); else if (VB->TexCoordPtr[0]->size == 4) @@ -991,28 +994,27 @@ static __inline__ GLuint savageChooseVertexFormat_s4( GLcontext *ctx ) savageContextPtr imesa = SAVAGE_CONTEXT(ctx); TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); GLuint setupIndex = SAVAGE_EMIT_XYZ; GLubyte skip; GLuint size, mask; + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); skip = SAVAGE_SKIP_ALL_S4; skip &= ~SAVAGE_SKIP_Z; /* all mesa vertices have a z coordinate */ - if ((index & _TNL_BITS_TEX_ANY) || !(ctx->_TriangleCaps & DD_FLATSHADE)) + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX ) || !(ctx->_TriangleCaps & DD_FLATSHADE)) NEED_ATTR( SAVAGE_EMIT_W, SAVAGE_SKIP_W ); /* t_context.c always includes a diffuse color */ NEED_ATTR( SAVAGE_EMIT_C0, SAVAGE_SKIP_C0 ); - - if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { - if ((index & _TNL_BIT_COLOR1)) - NEED_ATTR( SAVAGE_EMIT_C1, SAVAGE_SKIP_C1 ); - if ((index & _TNL_BIT_FOG)) - NEED_ATTR( SAVAGE_EMIT_FOG, SAVAGE_SKIP_C1 ); - } - if (index & _TNL_BIT_TEX(0)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) + NEED_ATTR( SAVAGE_EMIT_C1, SAVAGE_SKIP_C1 ); + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) + NEED_ATTR( SAVAGE_EMIT_FOG, SAVAGE_SKIP_C1 ); + + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX0 )) { if (imesa->ptexHack) NEED_ATTR( SAVAGE_EMIT_STQ0, SAVAGE_SKIP_ST0); else if (VB->TexCoordPtr[0]->size == 4) @@ -1024,7 +1026,7 @@ static __inline__ GLuint savageChooseVertexFormat_s4( GLcontext *ctx ) else NEED_ATTR( SAVAGE_EMIT_S0, SAVAGE_SKIP_S0 ); } - if (index & _TNL_BIT_TEX(1)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX1 )) { if (VB->TexCoordPtr[1]->size == 4) /* projective textures are not supported by the hardware */ assert (0); /* should be caught by savageCheckPTexHack */ diff --git a/src/mesa/drivers/dri/sis/sis_context.h b/src/mesa/drivers/dri/sis/sis_context.h index ead4a26678e..c349bf96ed2 100644 --- a/src/mesa/drivers/dri/sis/sis_context.h +++ b/src/mesa/drivers/dri/sis/sis_context.h @@ -332,7 +332,7 @@ struct sis_context GLint drawableID; GLint GlobalFlag; - GLuint last_tcl_state; + DECLARE_RENDERINPUTS(last_tcl_state_bitset); /* Stereo */ GLboolean useStereo; diff --git a/src/mesa/drivers/dri/sis/sis_tris.c b/src/mesa/drivers/dri/sis/sis_tris.c index 24f6cb9aa87..a0e39dcd3c9 100644 --- a/src/mesa/drivers/dri/sis/sis_tris.c +++ b/src/mesa/drivers/dri/sis/sis_tris.c @@ -842,10 +842,12 @@ static void sisRenderStart( GLcontext *ctx ) TNLcontext *tnl = TNL_CONTEXT(ctx); sisContextPtr smesa = SIS_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); GLuint AGPParseSet = smesa->AGPParseSet; GLboolean tex_fallback = GL_FALSE; + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); + if (ctx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT && smesa->driDrawable->numClipRects != 0) { @@ -869,7 +871,7 @@ static void sisRenderStart( GLcontext *ctx ) AGPParseSet &= ~(MASK_VertexDWSize | MASK_VertexDataFormat); AGPParseSet |= SiS_PS_HAS_XYZ | SiS_PS_HAS_DIFFUSE; - if (index & _TNL_BITS_TEX_ANY) { + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { EMIT_ATTR(_TNL_ATTRIB_POS, EMIT_4F_VIEWPORT); AGPParseSet |= SiS_PS_HAS_W; smesa->coloroffset = 4; @@ -881,17 +883,18 @@ static void sisRenderStart( GLcontext *ctx ) EMIT_ATTR(_TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA); smesa->specoffset = 0; - if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) || + RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { AGPParseSet |= SiS_PS_HAS_SPECULAR; - if (index & _TNL_BIT_COLOR1) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { EMIT_ATTR(_TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR); smesa->specoffset = smesa->coloroffset + 1; } else { EMIT_PAD(3); } - if (index & _TNL_BIT_FOG) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { EMIT_ATTR(_TNL_ATTRIB_FOG, EMIT_1UB_1F); } else { EMIT_PAD(1); @@ -899,14 +902,14 @@ static void sisRenderStart( GLcontext *ctx ) } /* projective textures are not supported by the hardware */ - if (index & _TNL_BIT_TEX(0)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX0 )) { if (VB->TexCoordPtr[0]->size > 2) tex_fallback = GL_TRUE; EMIT_ATTR(_TNL_ATTRIB_TEX0, EMIT_2F); AGPParseSet |= SiS_PS_HAS_UV0; } /* Will only hit tex1 on SiS300 */ - if (index & _TNL_BIT_TEX(1)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX1 )) { if (VB->TexCoordPtr[1]->size > 2) tex_fallback = GL_TRUE; EMIT_ATTR(_TNL_ATTRIB_TEX1, EMIT_2F); @@ -914,7 +917,7 @@ static void sisRenderStart( GLcontext *ctx ) } FALLBACK(smesa, SIS_FALLBACK_TEXTURE, tex_fallback); - if (smesa->last_tcl_state != index) { + if (!RENDERINPUTS_EQUAL( smesa->last_tcl_state_bitset, index_bitset )) { smesa->AGPParseSet = AGPParseSet; smesa->vertex_size = _tnl_install_attrs( ctx, smesa->vertex_attrs, diff --git a/src/mesa/drivers/dri/unichrome/via_tris.c b/src/mesa/drivers/dri/unichrome/via_tris.c index 9cb88ae2399..4cc7942b1b6 100644 --- a/src/mesa/drivers/dri/unichrome/via_tris.c +++ b/src/mesa/drivers/dri/unichrome/via_tris.c @@ -744,16 +744,18 @@ static void viaChooseVertexState( GLcontext *ctx ) { struct via_context *vmesa = VIA_CONTEXT(ctx); TNLcontext *tnl = TNL_CONTEXT(ctx); - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); GLuint regCmdB = HC_HVPMSK_X | HC_HVPMSK_Y | HC_HVPMSK_Z; GLuint setupIndex = 0; + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); vmesa->vertex_attr_count = 0; /* EMIT_ATTR's must be in order as they tell t_vertex.c how to * build up a hardware vertex. */ - if (index & (_TNL_BITS_TEX_ANY|_TNL_BIT_FOG)) { + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX ) || + RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, VIA_EMIT_W, HC_HVPMSK_W ); vmesa->coloroffset = 4; } @@ -767,8 +769,9 @@ static void viaChooseVertexState( GLcontext *ctx ) HC_HVPMSK_Cd ); vmesa->specoffset = 0; - if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { - if ((index & _TNL_BIT_COLOR1)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) || + RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { vmesa->specoffset = vmesa->coloroffset + 1; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VIA_EMIT_SPEC, HC_HVPMSK_Cs ); @@ -776,13 +779,13 @@ static void viaChooseVertexState( GLcontext *ctx ) else EMIT_PAD( 3 ); - if ((index & _TNL_BIT_FOG)) + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, VIA_EMIT_FOG, HC_HVPMSK_Cs ); else EMIT_PAD( 1 ); } - if (index & _TNL_BIT_TEX(0)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX0 )) { if (vmesa->ptexHack) EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_3F_XYW, VIA_EMIT_PTEX0, (HC_HVPMSK_S | HC_HVPMSK_T) ); @@ -791,7 +794,7 @@ static void viaChooseVertexState( GLcontext *ctx ) (HC_HVPMSK_S | HC_HVPMSK_T) ); } - if (index & _TNL_BIT_TEX(1)) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX1 )) { EMIT_ATTR( _TNL_ATTRIB_TEX1, EMIT_2F, VIA_EMIT_TEX1, (HC_HVPMSK_S | HC_HVPMSK_T) ); } @@ -824,17 +827,19 @@ static GLboolean viaCheckPTexHack( GLcontext *ctx ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint index = tnl->render_inputs; + DECLARE_RENDERINPUTS(index_bitset); GLboolean fallback = GL_FALSE; GLboolean ptexHack = GL_FALSE; - if (index & _TNL_BIT_TEX(0) && VB->TexCoordPtr[0]->size == 4) { - if ((index & _TNL_BITS_TEX_ANY) == _TNL_BIT_TEX(0)) + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); + + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX0 ) && VB->TexCoordPtr[0]->size == 4) { + if (!RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_ATTRIB_TEX1, _TNL_LAST_TEX )) ptexHack = GL_TRUE; else fallback = GL_TRUE; } - if ((index & _TNL_BIT_TEX(1)) && VB->TexCoordPtr[1]->size == 4) + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX1 ) && VB->TexCoordPtr[1]->size == 4) fallback = GL_TRUE; FALLBACK(VIA_CONTEXT(ctx), VIA_FALLBACK_PROJ_TEXTURE, fallback); diff --git a/src/mesa/main/api_noop.c b/src/mesa/main/api_noop.c index af7e1f9ac70..acb93415143 100644 --- a/src/mesa/main/api_noop.c +++ b/src/mesa/main/api_noop.c @@ -2,7 +2,7 @@ * Mesa 3-D graphics library * Version: 6.5 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -391,7 +391,7 @@ void GLAPIENTRY _mesa_noop_TexCoord4fv( const GLfloat *v ) void GLAPIENTRY _mesa_noop_VertexAttrib1fNV( GLuint index, GLfloat x ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) { ASSIGN_4V(ctx->Current.Attrib[index], x, 0, 0, 1); } else @@ -401,7 +401,7 @@ void GLAPIENTRY _mesa_noop_VertexAttrib1fNV( GLuint index, GLfloat x ) void GLAPIENTRY _mesa_noop_VertexAttrib1fvNV( GLuint index, const GLfloat *v ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) { ASSIGN_4V(ctx->Current.Attrib[index], v[0], 0, 0, 1); } else @@ -411,7 +411,7 @@ void GLAPIENTRY _mesa_noop_VertexAttrib1fvNV( GLuint index, const GLfloat *v ) void GLAPIENTRY _mesa_noop_VertexAttrib2fNV( GLuint index, GLfloat x, GLfloat y ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) { ASSIGN_4V(ctx->Current.Attrib[index], x, y, 0, 1); } else @@ -421,7 +421,7 @@ void GLAPIENTRY _mesa_noop_VertexAttrib2fNV( GLuint index, GLfloat x, GLfloat y void GLAPIENTRY _mesa_noop_VertexAttrib2fvNV( GLuint index, const GLfloat *v ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) { ASSIGN_4V(ctx->Current.Attrib[index], v[0], v[1], 0, 1); } else @@ -432,7 +432,7 @@ void GLAPIENTRY _mesa_noop_VertexAttrib3fNV( GLuint index, GLfloat x, GLfloat y, GLfloat z ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) { ASSIGN_4V(ctx->Current.Attrib[index], x, y, z, 1); } else @@ -442,7 +442,7 @@ void GLAPIENTRY _mesa_noop_VertexAttrib3fNV( GLuint index, GLfloat x, void GLAPIENTRY _mesa_noop_VertexAttrib3fvNV( GLuint index, const GLfloat *v ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) { ASSIGN_4V(ctx->Current.Attrib[index], v[0], v[1], v[2], 1); } else @@ -453,7 +453,7 @@ void GLAPIENTRY _mesa_noop_VertexAttrib4fNV( GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) { ASSIGN_4V(ctx->Current.Attrib[index], x, y, z, w); } else @@ -463,7 +463,7 @@ void GLAPIENTRY _mesa_noop_VertexAttrib4fNV( GLuint index, GLfloat x, void GLAPIENTRY _mesa_noop_VertexAttrib4fvNV( GLuint index, const GLfloat *v ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) { ASSIGN_4V(ctx->Current.Attrib[index], v[0], v[1], v[2], v[3]); } else @@ -471,15 +471,12 @@ void GLAPIENTRY _mesa_noop_VertexAttrib4fvNV( GLuint index, const GLfloat *v ) } -/* - * XXX Un-alias attribs here - */ void GLAPIENTRY _mesa_noop_VertexAttrib1fARB( GLuint index, GLfloat x ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { - ASSIGN_4V(ctx->Current.Attrib[index], x, 0, 0, 1); + if (index < MAX_VERTEX_ATTRIBS) { + ASSIGN_4V(ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index], x, 0, 0, 1); } else _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttrib1fARB" ); @@ -488,8 +485,8 @@ void GLAPIENTRY _mesa_noop_VertexAttrib1fARB( GLuint index, GLfloat x ) void GLAPIENTRY _mesa_noop_VertexAttrib1fvARB( GLuint index, const GLfloat *v ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { - ASSIGN_4V(ctx->Current.Attrib[index], v[0], 0, 0, 1); + if (index < MAX_VERTEX_ATTRIBS) { + ASSIGN_4V(ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index], v[0], 0, 0, 1); } else _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttrib1fvARB" ); @@ -498,8 +495,8 @@ void GLAPIENTRY _mesa_noop_VertexAttrib1fvARB( GLuint index, const GLfloat *v ) void GLAPIENTRY _mesa_noop_VertexAttrib2fARB( GLuint index, GLfloat x, GLfloat y ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { - ASSIGN_4V(ctx->Current.Attrib[index], x, y, 0, 1); + if (index < MAX_VERTEX_ATTRIBS) { + ASSIGN_4V(ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index], x, y, 0, 1); } else _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttrib2fARB" ); @@ -508,8 +505,8 @@ void GLAPIENTRY _mesa_noop_VertexAttrib2fARB( GLuint index, GLfloat x, GLfloat y void GLAPIENTRY _mesa_noop_VertexAttrib2fvARB( GLuint index, const GLfloat *v ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { - ASSIGN_4V(ctx->Current.Attrib[index], v[0], v[1], 0, 1); + if (index < MAX_VERTEX_ATTRIBS) { + ASSIGN_4V(ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index], v[0], v[1], 0, 1); } else _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttrib2fvARB" ); @@ -519,8 +516,8 @@ void GLAPIENTRY _mesa_noop_VertexAttrib3fARB( GLuint index, GLfloat x, GLfloat y, GLfloat z ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { - ASSIGN_4V(ctx->Current.Attrib[index], x, y, z, 1); + if (index < MAX_VERTEX_ATTRIBS) { + ASSIGN_4V(ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index], x, y, z, 1); } else _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttrib3fARB" ); @@ -529,8 +526,8 @@ void GLAPIENTRY _mesa_noop_VertexAttrib3fARB( GLuint index, GLfloat x, void GLAPIENTRY _mesa_noop_VertexAttrib3fvARB( GLuint index, const GLfloat *v ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { - ASSIGN_4V(ctx->Current.Attrib[index], v[0], v[1], v[2], 1); + if (index < MAX_VERTEX_ATTRIBS) { + ASSIGN_4V(ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index], v[0], v[1], v[2], 1); } else _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttrib3fvARB" ); @@ -540,8 +537,8 @@ void GLAPIENTRY _mesa_noop_VertexAttrib4fARB( GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { - ASSIGN_4V(ctx->Current.Attrib[index], x, y, z, w); + if (index < MAX_VERTEX_ATTRIBS) { + ASSIGN_4V(ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index], x, y, z, w); } else _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttrib4fARB" ); @@ -550,8 +547,8 @@ void GLAPIENTRY _mesa_noop_VertexAttrib4fARB( GLuint index, GLfloat x, void GLAPIENTRY _mesa_noop_VertexAttrib4fvARB( GLuint index, const GLfloat *v ) { GET_CURRENT_CONTEXT(ctx); - if (index < VERT_ATTRIB_MAX) { - ASSIGN_4V(ctx->Current.Attrib[index], v[0], v[1], v[2], v[3]); + if (index < MAX_VERTEX_ATTRIBS) { + ASSIGN_4V(ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index], v[0], v[1], v[2], v[3]); } else _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttrib4fvARB" ); diff --git a/src/mesa/main/bitset.h b/src/mesa/main/bitset.h index 1fd548bfda9..8bd4526cb6f 100644 --- a/src/mesa/main/bitset.h +++ b/src/mesa/main/bitset.h @@ -1,72 +1,122 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5 - * - * Copyright (C) 2006 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. - */ - -/** - * \file bitset.h - * \brief Bitset of arbitrary size definitions. - * \author Michal Krol - */ - -#define BITSET_WORD GLuint -#define BITSET_WORDBITS (sizeof (BITSET_WORD) * 8) - -/* bitset declarations - */ -#define BITSET_DECLARE(name, size) \ - BITSET_WORD name[((size) + BITSET_WORDBITS - 1) / BITSET_WORDBITS] - -/* bitset operations - */ -#define BITSET_COPY(x, y) _mesa_memcpy( (x), (y), sizeof (x) ) -#define BITSET_EQUAL(x, y) (_mesa_memcmp( (x), (y), sizeof (x) ) == 0) -#define BITSET_ZERO(x) _mesa_memset( (x), 0, sizeof (x) ) -#define BITSET_ONES(x) _mesa_memset( (x), 0xff, sizeof (x) ) - -#define BITSET_BITWORD(b) ((b) / BITSET_WORDBITS) -#define BITSET_BIT(b) (1 << ((b) % BITSET_WORDBITS)) - -/* single bit operations - */ -#define BITSET_TEST(x, b) ((x)[BITSET_BITWORD(b)] & BITSET_BIT(b)) -#define BITSET_SET(x, b) ((x)[BITSET_BITWORD(b)] |= BITSET_BIT(b)) -#define BITSET_CLEAR(x, b) ((x)[BITSET_BITWORD(b)] &= ~BITSET_BIT(b)) - -#define BITSET_MASK(b) ((b) == BITSET_WORDBITS ? ~0 : BITSET_BIT(b) - 1) -#define BITSET_RANGE(b, e) (BITSET_MASK((e) + 1) & ~BITSET_MASK(b)) - -/* bit range operations - */ -#define BITSET_TEST_RANGE(x, b, e) \ - (BITSET_BITWORD(b) == BITSET_BITWORD(e) ? \ - ((x)[BITSET_BITWORD(b)] & BITSET_RANGE(b, e)) : \ - (assert (!"BITSET_TEST_RANGE: bit range crosses word boundary"), 0)) -#define BITSET_SET_RANGE(x, b, e) \ - (BITSET_BITWORD(b) == BITSET_BITWORD(e) ? \ - ((x)[BITSET_BITWORD(b)] |= BITSET_RANGE(b, e)) : \ - (assert (!"BITSET_SET_RANGE: bit range crosses word boundary"), 0)) -#define BITSET_CLEAR_RANGE(x, b, e) \ - (BITSET_BITWORD(b) == BITSET_BITWORD(e) ? \ - ((x)[BITSET_BITWORD(b)] &= ~BITSET_RANGE(b, e)) : \ - (assert (!"BITSET_CLEAR_RANGE: bit range crosses word boundary"), 0)) - +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 2006 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. + */ + +/** + * \file bitset.h + * \brief Bitset of arbitrary size definitions. + * \author Michal Krol + */ + +/**************************************************************************** + * generic bitset implementation + */ + +#define BITSET_WORD GLuint +#define BITSET_WORDBITS (sizeof (BITSET_WORD) * 8) + +/* bitset declarations + */ +#define BITSET_DECLARE(name, size) \ + BITSET_WORD name[((size) + BITSET_WORDBITS - 1) / BITSET_WORDBITS] + +/* bitset operations + */ +#define BITSET_COPY(x, y) _mesa_memcpy( (x), (y), sizeof (x) ) +#define BITSET_EQUAL(x, y) (_mesa_memcmp( (x), (y), sizeof (x) ) == 0) +#define BITSET_ZERO(x) _mesa_memset( (x), 0, sizeof (x) ) +#define BITSET_ONES(x) _mesa_memset( (x), 0xff, sizeof (x) ) + +#define BITSET_BITWORD(b) ((b) / BITSET_WORDBITS) +#define BITSET_BIT(b) (1 << ((b) % BITSET_WORDBITS)) + +/* single bit operations + */ +#define BITSET_TEST(x, b) ((x)[BITSET_BITWORD(b)] & BITSET_BIT(b)) +#define BITSET_SET(x, b) ((x)[BITSET_BITWORD(b)] |= BITSET_BIT(b)) +#define BITSET_CLEAR(x, b) ((x)[BITSET_BITWORD(b)] &= ~BITSET_BIT(b)) + +#define BITSET_MASK(b) ((b) == BITSET_WORDBITS ? ~0 : BITSET_BIT(b) - 1) +#define BITSET_RANGE(b, e) (BITSET_MASK((e) + 1) & ~BITSET_MASK(b)) + +/* bit range operations + */ +#define BITSET_TEST_RANGE(x, b, e) \ + (BITSET_BITWORD(b) == BITSET_BITWORD(e) ? \ + ((x)[BITSET_BITWORD(b)] & BITSET_RANGE(b, e)) : \ + (assert (!"BITSET_TEST_RANGE: bit range crosses word boundary"), 0)) +#define BITSET_SET_RANGE(x, b, e) \ + (BITSET_BITWORD(b) == BITSET_BITWORD(e) ? \ + ((x)[BITSET_BITWORD(b)] |= BITSET_RANGE(b, e)) : \ + (assert (!"BITSET_SET_RANGE: bit range crosses word boundary"), 0)) +#define BITSET_CLEAR_RANGE(x, b, e) \ + (BITSET_BITWORD(b) == BITSET_BITWORD(e) ? \ + ((x)[BITSET_BITWORD(b)] &= ~BITSET_RANGE(b, e)) : \ + (assert (!"BITSET_CLEAR_RANGE: bit range crosses word boundary"), 0)) + +/**************************************************************************** + * 64-bit bitset implementation + */ + +#define BITSET64_WORD GLuint +#define BITSET64_WORDBITS (sizeof (BITSET64_WORD) * 8) + +/* bitset declarations + */ +#define BITSET64_DECLARE(name, size) \ + GLuint name[2] + +/* bitset operations + */ +#define BITSET64_COPY(x, y) do { (x)[0] = (y)[0]; (x)[1] = (y)[1]; } while (0) +#define BITSET64_EQUAL(x, y) ( (x)[0] == (y)[0] && (x)[1] == (y)[1] ) +#define BITSET64_ZERO(x) do { (x)[0] = 0; (x)[1] = 0; } while (0) +#define BITSET64_ONES(x) do { (x)[0] = 0xFF; (x)[1] = 0xFF; } while (0) + +#define BITSET64_BITWORD(b) ((b) / BITSET64_WORDBITS) +#define BITSET64_BIT(b) (1 << ((b) % BITSET64_WORDBITS)) + +/* single bit operations + */ +#define BITSET64_TEST(x, b) ((x)[BITSET64_BITWORD(b)] & BITSET64_BIT(b)) +#define BITSET64_SET(x, b) ((x)[BITSET64_BITWORD(b)] |= BITSET64_BIT(b)) +#define BITSET64_CLEAR(x, b) ((x)[BITSET64_BITWORD(b)] &= ~BITSET64_BIT(b)) + +#define BITSET64_MASK(b) ((b) == BITSET64_WORDBITS ? ~0 : BITSET64_BIT(b) - 1) +#define BITSET64_RANGE(b, e) (BITSET64_MASK((e) + 1) & ~BITSET64_MASK(b)) + +/* bit range operations + */ +#define BITSET64_TEST_RANGE(x, b, e) \ + (BITSET64_BITWORD(b) == BITSET64_BITWORD(e) ? \ + ((x)[BITSET64_BITWORD(b)] & BITSET64_RANGE(b, e)) : \ + (assert (!"BITSET64_TEST_RANGE: bit range crosses word boundary"), 0)) +#define BITSET64_SET_RANGE(x, b, e) \ + (BITSET64_BITWORD(b) == BITSET64_BITWORD(e) ? \ + ((x)[BITSET64_BITWORD(b)] |= BITSET64_RANGE(b, e)) : \ + (assert (!"BITSET64_SET_RANGE: bit range crosses word boundary"), 0)) +#define BITSET64_CLEAR_RANGE(x, b, e) \ + (BITSET64_BITWORD(b) == BITSET64_BITWORD(e) ? \ + ((x)[BITSET64_BITWORD(b)] &= ~BITSET64_RANGE(b, e)) : \ + (assert (!"BITSET64_CLEAR_RANGE: bit range crosses word boundary"), 0)) + diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index dba2008ef73..4fe1bfddcc9 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -4777,7 +4777,7 @@ save_Attr1fNV(GLenum attr, GLfloat x) n[2].f = x; } - ASSERT(attr < VERT_ATTRIB_MAX); + ASSERT(attr < MAX_VERTEX_PROGRAM_ATTRIBS); ctx->ListState.ActiveAttribSize[attr] = 1; ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, 0, 0, 1); @@ -4799,7 +4799,7 @@ save_Attr2fNV(GLenum attr, GLfloat x, GLfloat y) n[3].f = y; } - ASSERT(attr < VERT_ATTRIB_MAX); + ASSERT(attr < MAX_VERTEX_PROGRAM_ATTRIBS); ctx->ListState.ActiveAttribSize[attr] = 2; ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, 0, 1); @@ -4822,7 +4822,7 @@ save_Attr3fNV(GLenum attr, GLfloat x, GLfloat y, GLfloat z) n[4].f = z; } - ASSERT(attr < VERT_ATTRIB_MAX); + ASSERT(attr < MAX_VERTEX_PROGRAM_ATTRIBS); ctx->ListState.ActiveAttribSize[attr] = 3; ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, 1); @@ -4846,7 +4846,7 @@ save_Attr4fNV(GLenum attr, GLfloat x, GLfloat y, GLfloat z, GLfloat w) n[5].f = w; } - ASSERT(attr < VERT_ATTRIB_MAX); + ASSERT(attr < MAX_VERTEX_PROGRAM_ATTRIBS); ctx->ListState.ActiveAttribSize[attr] = 4; ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, w); @@ -4868,7 +4868,7 @@ save_Attr1fARB(GLenum attr, GLfloat x) n[2].f = x; } - ASSERT(attr < VERT_ATTRIB_MAX); + ASSERT(attr < MAX_VERTEX_ATTRIBS); ctx->ListState.ActiveAttribSize[attr] = 1; ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, 0, 0, 1); @@ -4890,7 +4890,7 @@ save_Attr2fARB(GLenum attr, GLfloat x, GLfloat y) n[3].f = y; } - ASSERT(attr < VERT_ATTRIB_MAX); + ASSERT(attr < MAX_VERTEX_ATTRIBS); ctx->ListState.ActiveAttribSize[attr] = 2; ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, 0, 1); @@ -4913,7 +4913,7 @@ save_Attr3fARB(GLenum attr, GLfloat x, GLfloat y, GLfloat z) n[4].f = z; } - ASSERT(attr < VERT_ATTRIB_MAX); + ASSERT(attr < MAX_VERTEX_ATTRIBS); ctx->ListState.ActiveAttribSize[attr] = 3; ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, 1); @@ -4937,7 +4937,7 @@ save_Attr4fARB(GLenum attr, GLfloat x, GLfloat y, GLfloat z, GLfloat w) n[5].f = w; } - ASSERT(attr < VERT_ATTRIB_MAX); + ASSERT(attr < MAX_VERTEX_ATTRIBS); ctx->ListState.ActiveAttribSize[attr] = 4; ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, w); @@ -5432,7 +5432,7 @@ index_error(void) static void GLAPIENTRY save_VertexAttrib1fNV(GLuint index, GLfloat x) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) save_Attr1fNV(index, x); else index_error(); @@ -5441,7 +5441,7 @@ save_VertexAttrib1fNV(GLuint index, GLfloat x) static void GLAPIENTRY save_VertexAttrib1fvNV(GLuint index, const GLfloat * v) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) save_Attr1fNV(index, v[0]); else index_error(); @@ -5450,7 +5450,7 @@ save_VertexAttrib1fvNV(GLuint index, const GLfloat * v) static void GLAPIENTRY save_VertexAttrib2fNV(GLuint index, GLfloat x, GLfloat y) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) save_Attr2fNV(index, x, y); else index_error(); @@ -5459,7 +5459,7 @@ save_VertexAttrib2fNV(GLuint index, GLfloat x, GLfloat y) static void GLAPIENTRY save_VertexAttrib2fvNV(GLuint index, const GLfloat * v) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) save_Attr2fNV(index, v[0], v[1]); else index_error(); @@ -5468,7 +5468,7 @@ save_VertexAttrib2fvNV(GLuint index, const GLfloat * v) static void GLAPIENTRY save_VertexAttrib3fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) save_Attr3fNV(index, x, y, z); else index_error(); @@ -5477,7 +5477,7 @@ save_VertexAttrib3fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z) static void GLAPIENTRY save_VertexAttrib3fvNV(GLuint index, const GLfloat * v) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) save_Attr3fNV(index, v[0], v[1], v[2]); else index_error(); @@ -5487,7 +5487,7 @@ static void GLAPIENTRY save_VertexAttrib4fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) save_Attr4fNV(index, x, y, z, w); else index_error(); @@ -5496,7 +5496,7 @@ save_VertexAttrib4fNV(GLuint index, GLfloat x, GLfloat y, static void GLAPIENTRY save_VertexAttrib4fvNV(GLuint index, const GLfloat * v) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) save_Attr4fNV(index, v[0], v[1], v[2], v[3]); else index_error(); @@ -5508,7 +5508,7 @@ save_VertexAttrib4fvNV(GLuint index, const GLfloat * v) static void GLAPIENTRY save_VertexAttrib1fARB(GLuint index, GLfloat x) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) save_Attr1fARB(index, x); else index_error(); @@ -5517,7 +5517,7 @@ save_VertexAttrib1fARB(GLuint index, GLfloat x) static void GLAPIENTRY save_VertexAttrib1fvARB(GLuint index, const GLfloat * v) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) save_Attr1fARB(index, v[0]); else index_error(); @@ -5526,7 +5526,7 @@ save_VertexAttrib1fvARB(GLuint index, const GLfloat * v) static void GLAPIENTRY save_VertexAttrib2fARB(GLuint index, GLfloat x, GLfloat y) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) save_Attr2fARB(index, x, y); else index_error(); @@ -5535,7 +5535,7 @@ save_VertexAttrib2fARB(GLuint index, GLfloat x, GLfloat y) static void GLAPIENTRY save_VertexAttrib2fvARB(GLuint index, const GLfloat * v) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) save_Attr2fARB(index, v[0], v[1]); else index_error(); @@ -5544,7 +5544,7 @@ save_VertexAttrib2fvARB(GLuint index, const GLfloat * v) static void GLAPIENTRY save_VertexAttrib3fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) save_Attr3fARB(index, x, y, z); else index_error(); @@ -5553,7 +5553,7 @@ save_VertexAttrib3fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z) static void GLAPIENTRY save_VertexAttrib3fvARB(GLuint index, const GLfloat * v) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) save_Attr3fARB(index, v[0], v[1], v[2]); else index_error(); @@ -5563,7 +5563,7 @@ static void GLAPIENTRY save_VertexAttrib4fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) save_Attr4fARB(index, x, y, z, w); else index_error(); @@ -5572,7 +5572,7 @@ save_VertexAttrib4fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z, static void GLAPIENTRY save_VertexAttrib4fvARB(GLuint index, const GLfloat * v) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) save_Attr4fARB(index, v[0], v[1], v[2], v[3]); else index_error(); diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 7876cff2ed5..c443411b629 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -41,6 +41,7 @@ #include "glapitable.h" #include "glthread.h" #include "math/m_matrix.h" /* GLmatrix */ +#include "bitset.h" /** @@ -155,7 +156,19 @@ enum VERT_ATTRIB_GENERIC1 = 17, VERT_ATTRIB_GENERIC2 = 18, VERT_ATTRIB_GENERIC3 = 19, - VERT_ATTRIB_MAX = 16 /* XXX not counting generic attribs yet */ + VERT_ATTRIB_GENERIC4 = 20, + VERT_ATTRIB_GENERIC5 = 21, + VERT_ATTRIB_GENERIC6 = 22, + VERT_ATTRIB_GENERIC7 = 23, + VERT_ATTRIB_GENERIC8 = 24, + VERT_ATTRIB_GENERIC9 = 25, + VERT_ATTRIB_GENERIC10 = 26, + VERT_ATTRIB_GENERIC11 = 27, + VERT_ATTRIB_GENERIC12 = 28, + VERT_ATTRIB_GENERIC13 = 29, + VERT_ATTRIB_GENERIC14 = 30, + VERT_ATTRIB_GENERIC15 = 31, + VERT_ATTRIB_MAX = 32 }; /** @@ -183,11 +196,40 @@ enum #define VERT_BIT_GENERIC1 (1 << VERT_ATTRIB_GENERIC1) #define VERT_BIT_GENERIC2 (1 << VERT_ATTRIB_GENERIC2) #define VERT_BIT_GENERIC3 (1 << VERT_ATTRIB_GENERIC3) +#define VERT_BIT_GENERIC4 (1 << VERT_ATTRIB_GENERIC4) +#define VERT_BIT_GENERIC5 (1 << VERT_ATTRIB_GENERIC5) +#define VERT_BIT_GENERIC6 (1 << VERT_ATTRIB_GENERIC6) +#define VERT_BIT_GENERIC7 (1 << VERT_ATTRIB_GENERIC7) +#define VERT_BIT_GENERIC8 (1 << VERT_ATTRIB_GENERIC8) +#define VERT_BIT_GENERIC9 (1 << VERT_ATTRIB_GENERIC9) +#define VERT_BIT_GENERIC10 (1 << VERT_ATTRIB_GENERIC10) +#define VERT_BIT_GENERIC11 (1 << VERT_ATTRIB_GENERIC11) +#define VERT_BIT_GENERIC12 (1 << VERT_ATTRIB_GENERIC12) +#define VERT_BIT_GENERIC13 (1 << VERT_ATTRIB_GENERIC13) +#define VERT_BIT_GENERIC14 (1 << VERT_ATTRIB_GENERIC14) +#define VERT_BIT_GENERIC15 (1 << VERT_ATTRIB_GENERIC15) #define VERT_BIT_TEX(u) (1 << (VERT_ATTRIB_TEX0 + (u))) #define VERT_BIT_GENERIC(g) (1 << (VERT_ATTRIB_GENERIC0 + (g))) /*@}*/ +/** + * GLSL allows shader writers to allocate vertex result attributes (varyings) in + * single float component granularity. This is in contrast to vertex / fragment + * programs, where result attributes (actually texcoords) were allocated + * in 4-component vectors of floats granularity. + * For performance reasons, it would be optimal to stick with this scheme on a scalar + * processor. Varyings will likely be allocated as 3-component vectors, so statistically + * we win 2 floats. + * The constant VARYINGS_PER_VECTOR tells us how much of float components we pack into + * one result vector. For scalar processor it would be 1, for vector processor - 4. + * + * NOTE: Currently we pack varyings into vertex attributes. + */ +#define VARYINGS_PER_VECTOR 2 +#define VARYING_EMIT_STYLE EMIT_2F +#define MAX_VARYING_VECTORS ((MAX_VARYING_FLOATS + VARYINGS_PER_VECTOR - 1) / VARYINGS_PER_VECTOR) + /** * Indexes for vertex program result attributes */ diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index 7e452bdfd7f..761a45f2bd8 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -820,7 +820,11 @@ update_arrays( GLcontext *ctx ) /* find min of _MaxElement values for all enabled arrays */ /* 0 */ - if (ctx->VertexProgram._Enabled + if (ctx->ShaderObjects._VertexShaderPresent + && ctx->Array.VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled) { + min = ctx->Array.VertexAttrib[VERT_ATTRIB_GENERIC0]._MaxElement; + } + else if (ctx->VertexProgram._Enabled && ctx->Array.VertexAttrib[VERT_ATTRIB_POS].Enabled) { min = ctx->Array.VertexAttrib[VERT_ATTRIB_POS]._MaxElement; } @@ -888,7 +892,7 @@ update_arrays( GLcontext *ctx ) } /* 8..15 */ - for (i = VERT_ATTRIB_TEX0; i < VERT_ATTRIB_MAX; i++) { + for (i = VERT_ATTRIB_TEX0; i <= VERT_ATTRIB_TEX7; i++) { if (ctx->VertexProgram._Enabled && ctx->Array.VertexAttrib[i].Enabled) { min = MIN2(min, ctx->Array.VertexAttrib[i]._MaxElement); @@ -899,6 +903,15 @@ update_arrays( GLcontext *ctx ) } } + /* 16..31 */ + if (ctx->ShaderObjects._VertexShaderPresent) { + for (i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++) { + if (ctx->Array.VertexAttrib[i].Enabled) { + min = MIN2(min, ctx->Array.VertexAttrib[i]._MaxElement); + } + } + } + if (ctx->Array.Index.Enabled) { min = MIN2(min, ctx->Array.Index._MaxElement); } diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index cf64fb23df7..9f8dc766c9d 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.1 + * Version: 6.5 * - * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -441,7 +441,7 @@ _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type, GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); - if (index >= VERT_ATTRIB_MAX) { + if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) { _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)"); return; } diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index a7068e6dbcf..f8809c576f9 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -2,7 +2,7 @@ * Mesa 3-D graphics library * Version: 6.5 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -856,7 +856,7 @@ parse_generic_attrib_num(GLcontext *ctx, GLubyte ** inst, { GLint i = parse_integer(inst, Program); - if ((i < 0) || (i > MAX_VERTEX_PROGRAM_ATTRIBS)) + if ((i < 0) || (i >= MAX_VERTEX_PROGRAM_ATTRIBS)) { _mesa_set_program_error (ctx, Program->Position, "Invalid generic vertex attribute index"); diff --git a/src/mesa/shader/arbprogram.c b/src/mesa/shader/arbprogram.c index a7b26e72b58..9cc5488b2b1 100644 --- a/src/mesa/shader/arbprogram.c +++ b/src/mesa/shader/arbprogram.c @@ -2,7 +2,7 @@ * Mesa 3-D graphics library * Version: 6.5 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -123,11 +123,8 @@ _mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params) params[0] = ctx->Array.VertexAttrib[index].Normalized; break; case GL_CURRENT_VERTEX_ATTRIB_ARB: - FLUSH_CURRENT(ctx, 0); - /* XXX should read: - COPY_4V(params, ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index]); - */ - COPY_4V(params, ctx->Current.Attrib[index]); + FLUSH_CURRENT(ctx, 0); + COPY_4V(params, ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index]); break; case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB: if (!ctx->Extensions.ARB_vertex_buffer_object) { diff --git a/src/mesa/shader/nvvertexec.c b/src/mesa/shader/nvvertexec.c index 0e0e459b289..fc5837812e2 100644 --- a/src/mesa/shader/nvvertexec.c +++ b/src/mesa/shader/nvvertexec.c @@ -2,7 +2,7 @@ * Mesa 3-D graphics library * Version: 6.5 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -51,7 +51,7 @@ _mesa_init_vp_per_vertex_registers(GLcontext *ctx) { /* Input registers get initialized from the current vertex attribs */ MEMCPY(ctx->VertexProgram.Inputs, ctx->Current.Attrib, - VERT_ATTRIB_MAX * 4 * sizeof(GLfloat)); + MAX_VERTEX_PROGRAM_ATTRIBS * 4 * sizeof(GLfloat)); if (ctx->VertexProgram.Current->IsNVProgram) { GLuint i; diff --git a/src/mesa/swrast/s_arbshader.c b/src/mesa/swrast/s_arbshader.c index ba146dd1bb9..9cd96c5a366 100644 --- a/src/mesa/swrast/s_arbshader.c +++ b/src/mesa/swrast/s_arbshader.c @@ -1,99 +1,109 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5 - * - * Copyright (C) 2006 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. - * - * Authors: - * Michal Krol - */ - -#include "glheader.h" -#include "context.h" -#include "colormac.h" -#include "s_arbshader.h" -#include "s_context.h" -#include "shaderobjects.h" -#include "shaderobjects_3dlabs.h" -#include "slang_utility.h" -#include "slang_link.h" - -void _swrast_exec_arbshader (GLcontext *ctx, struct sw_span *span) -{ - struct gl2_program_intf **pro; - GLuint i; - - if (!ctx->ShaderObjects._FragmentShaderPresent) - return; - pro = ctx->ShaderObjects.CurrentProgram; - if (!ctx->ShaderObjects._VertexShaderPresent) - (**pro).UpdateFixedUniforms (pro); - - for (i = span->start; i < span->end; i++) - { - /* only run shader on active fragments */ - if (span->array->mask[i]) { - GLfloat vec[4]; - GLuint j; - GLboolean discard; - - vec[0] = (GLfloat) span->x + i; - vec[1] = (GLfloat) span->y; - vec[2] = (GLfloat) span->array->z[i] / ctx->DrawBuffer->_DepthMaxF; - vec[3] = span->w + span->dwdx * i; - (**pro).UpdateFixedVarying (pro, SLANG_FRAGMENT_FIXED_FRAGCOORD, vec, 0, - 4 * sizeof (GLfloat), GL_TRUE); - vec[0] = CHAN_TO_FLOAT(span->array->rgba[i][RCOMP]); - vec[1] = CHAN_TO_FLOAT(span->array->rgba[i][GCOMP]); - vec[2] = CHAN_TO_FLOAT(span->array->rgba[i][BCOMP]); - vec[3] = CHAN_TO_FLOAT(span->array->rgba[i][ACOMP]); - (**pro).UpdateFixedVarying (pro, SLANG_FRAGMENT_FIXED_COLOR, vec, 0, 4 * sizeof (GLfloat), - GL_TRUE); - for (j = 0; j < ctx->Const.MaxTextureCoordUnits; j++) - { - vec[0] = span->array->texcoords[j][i][0]; - vec[1] = span->array->texcoords[j][i][1]; - vec[2] = span->array->texcoords[j][i][2]; - vec[3] = span->array->texcoords[j][i][3]; - (**pro).UpdateFixedVarying (pro, SLANG_FRAGMENT_FIXED_TEXCOORD, vec, j, - 4 * sizeof (GLfloat), GL_TRUE); - } - - _slang_exec_fragment_shader (pro); - - _slang_fetch_discard (pro, &discard); - if (discard) - { - span->array->mask[i] = GL_FALSE; - span->writeAll = GL_FALSE; - } - else - { - (**pro).UpdateFixedVarying (pro, SLANG_FRAGMENT_FIXED_FRAGCOLOR, vec, 0, - 4 * sizeof (GLfloat), GL_FALSE); - UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][RCOMP], vec[0]); - UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][GCOMP], vec[1]); - UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][BCOMP], vec[2]); - UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][ACOMP], vec[3]); - } - } - } -} - +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 2006 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. + * + * Authors: + * Michal Krol + */ + +#include "glheader.h" +#include "context.h" +#include "colormac.h" +#include "s_arbshader.h" +#include "s_context.h" +#include "shaderobjects.h" +#include "shaderobjects_3dlabs.h" +#include "slang_utility.h" +#include "slang_link.h" + +void _swrast_exec_arbshader (GLcontext *ctx, struct sw_span *span) +{ + struct gl2_program_intf **pro; + GLuint i; + + if (!ctx->ShaderObjects._FragmentShaderPresent) + return; + pro = ctx->ShaderObjects.CurrentProgram; + if (!ctx->ShaderObjects._VertexShaderPresent) + (**pro).UpdateFixedUniforms (pro); + + for (i = span->start; i < span->end; i++) + { + /* only run shader on active fragments */ + if (span->array->mask[i]) { + GLfloat vec[4]; + GLuint j; + GLboolean discard; + + vec[0] = (GLfloat) span->x + i; + vec[1] = (GLfloat) span->y; + vec[2] = (GLfloat) span->array->z[i] / ctx->DrawBuffer->_DepthMaxF; + vec[3] = span->w + span->dwdx * i; + (**pro).UpdateFixedVarying (pro, SLANG_FRAGMENT_FIXED_FRAGCOORD, vec, 0, + 4 * sizeof (GLfloat), GL_TRUE); + vec[0] = CHAN_TO_FLOAT(span->array->rgba[i][RCOMP]); + vec[1] = CHAN_TO_FLOAT(span->array->rgba[i][GCOMP]); + vec[2] = CHAN_TO_FLOAT(span->array->rgba[i][BCOMP]); + vec[3] = CHAN_TO_FLOAT(span->array->rgba[i][ACOMP]); + (**pro).UpdateFixedVarying (pro, SLANG_FRAGMENT_FIXED_COLOR, vec, 0, 4 * sizeof (GLfloat), + GL_TRUE); + for (j = 0; j < ctx->Const.MaxTextureCoordUnits; j++) + { + vec[0] = span->array->texcoords[j][i][0]; + vec[1] = span->array->texcoords[j][i][1]; + vec[2] = span->array->texcoords[j][i][2]; + vec[3] = span->array->texcoords[j][i][3]; + (**pro).UpdateFixedVarying (pro, SLANG_FRAGMENT_FIXED_TEXCOORD, vec, j, + 4 * sizeof (GLfloat), GL_TRUE); + } + for (j = 0; j < MAX_VARYING_VECTORS; j++) + { + GLuint k; + + for (k = 0; k < VARYINGS_PER_VECTOR; k++) + { + (**pro).UpdateVarying (pro, j * VARYINGS_PER_VECTOR + k, + &span->array->varying[i][j][k], GL_FALSE); + } + } + + _slang_exec_fragment_shader (pro); + + _slang_fetch_discard (pro, &discard); + if (discard) + { + span->array->mask[i] = GL_FALSE; + span->writeAll = GL_FALSE; + } + else + { + (**pro).UpdateFixedVarying (pro, SLANG_FRAGMENT_FIXED_FRAGCOLOR, vec, 0, + 4 * sizeof (GLfloat), GL_FALSE); + UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][RCOMP], vec[0]); + UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][GCOMP], vec[1]); + UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][BCOMP], vec[2]); + UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][ACOMP], vec[3]); + } + } + } +} + diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index 5d9a35043be..3c5a4c32228 100644 --- a/src/mesa/swrast/s_context.h +++ b/src/mesa/swrast/s_context.h @@ -2,7 +2,7 @@ * Mesa 3-D graphics library * Version: 6.5 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -66,6 +66,7 @@ #define SPAN_FLAT 0x400 /**< flat shading? */ #define SPAN_XY 0x800 #define SPAN_MASK 0x1000 +#define SPAN_VARYING 0x2000 /*@}*/ @@ -90,6 +91,7 @@ struct span_arrays { GLfloat texcoords[MAX_TEXTURE_COORD_UNITS][MAX_WIDTH][4]; GLfloat lambda[MAX_TEXTURE_COORD_UNITS][MAX_WIDTH]; GLfloat coverage[MAX_WIDTH]; + GLfloat varying[MAX_WIDTH][MAX_VARYING_VECTORS][VARYINGS_PER_VECTOR]; /** This mask indicates which fragments are alive or culled */ GLubyte mask[MAX_WIDTH]; @@ -167,6 +169,9 @@ struct sw_span { GLfloat texStepX[MAX_TEXTURE_COORD_UNITS][4]; GLfloat texStepY[MAX_TEXTURE_COORD_UNITS][4]; GLfixed intTex[2], intTexStep[2]; /* s, t only */ + GLfloat var[MAX_VARYING_VECTORS][VARYINGS_PER_VECTOR]; + GLfloat varStepX[MAX_VARYING_VECTORS][VARYINGS_PER_VECTOR]; + GLfloat varStepY[MAX_VARYING_VECTORS][VARYINGS_PER_VECTOR]; /* partial derivatives wrt X and Y. */ GLfloat dzdx, dzdy; diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index 02901a7ed94..11457723b09 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -37,7 +37,7 @@ #include "imports.h" #include "s_atifragshader.h" -#include "s_alpha.h" +#include "s_alpha.h" #include "s_arbshader.h" #include "s_blend.h" #include "s_context.h" @@ -434,7 +434,8 @@ interpolate_texcoords(GLcontext *ctx, struct sw_span *span) GLfloat r = span->tex[u][2]; GLfloat q = span->tex[u][3]; GLuint i; - if (ctx->FragmentProgram._Active || ctx->ATIFragmentShader._Enabled) { + if (ctx->FragmentProgram._Active || ctx->ATIFragmentShader._Enabled || + ctx->ShaderObjects._FragmentShaderPresent) { /* do perspective correction but don't divide s, t, r by q */ const GLfloat dwdx = span->dwdx; GLfloat w = span->w; @@ -485,7 +486,8 @@ interpolate_texcoords(GLcontext *ctx, struct sw_span *span) GLfloat r = span->tex[u][2]; GLfloat q = span->tex[u][3]; GLuint i; - if (ctx->FragmentProgram._Active || ctx->ATIFragmentShader._Enabled) { + if (ctx->FragmentProgram._Active || ctx->ATIFragmentShader._Enabled || + ctx->ShaderObjects._FragmentShaderPresent) { /* do perspective correction but don't divide s, t, r by q */ const GLfloat dwdx = span->dwdx; GLfloat w = span->w; @@ -568,7 +570,8 @@ interpolate_texcoords(GLcontext *ctx, struct sw_span *span) GLfloat r = span->tex[0][2]; GLfloat q = span->tex[0][3]; GLuint i; - if (ctx->FragmentProgram._Active || ctx->ATIFragmentShader._Enabled) { + if (ctx->FragmentProgram._Active || ctx->ATIFragmentShader._Enabled || + ctx->ShaderObjects._FragmentShaderPresent) { /* do perspective correction but don't divide s, t, r by q */ const GLfloat dwdx = span->dwdx; GLfloat w = span->w; @@ -619,7 +622,8 @@ interpolate_texcoords(GLcontext *ctx, struct sw_span *span) GLfloat r = span->tex[0][2]; GLfloat q = span->tex[0][3]; GLuint i; - if (ctx->FragmentProgram._Active || ctx->ATIFragmentShader._Enabled) { + if (ctx->FragmentProgram._Active || ctx->ATIFragmentShader._Enabled || + ctx->ShaderObjects._FragmentShaderPresent) { /* do perspective correction but don't divide s, t, r by q */ const GLfloat dwdx = span->dwdx; GLfloat w = span->w; @@ -667,6 +671,38 @@ interpolate_texcoords(GLcontext *ctx, struct sw_span *span) } +/** + * Fill in the span.varying array from the interpolation values. + */ +static void +interpolate_varying(GLcontext *ctx, struct sw_span *span) +{ + GLuint i, j; + + ASSERT(span->interpMask & SPAN_VARYING); + ASSERT(!(span->arrayMask & SPAN_VARYING)); + + span->arrayMask |= SPAN_VARYING; + + for (i = 0; i < MAX_VARYING_VECTORS; i++) { + for (j = 0; j < VARYINGS_PER_VECTOR; j++) { + const GLfloat dvdx = span->varStepX[i][j]; + GLfloat v = span->var[i][j]; + const GLfloat dwdx = span->dwdx; + GLfloat w = span->w; + GLuint k; + + for (k = 0; k < span->end; k++) { + GLfloat invW = 1.0f / w; + span->array->varying[k][i][j] = v * invW; + v += dvdx; + w += dwdx; + } + } + } +} + + /** * Apply the current polygon stipple pattern to a span of pixels. */ @@ -1139,6 +1175,10 @@ _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span) interpolate_texcoords(ctx, span); } + if (ctx->ShaderObjects._FragmentShaderPresent) { + interpolate_varying(ctx, span); + } + /* This is the normal place to compute the resulting fragment color/Z. * As an optimization, we try to defer this until after Z/stencil * testing in order to try to avoid computing colors that we won't @@ -1155,11 +1195,11 @@ _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span) if (span->interpMask & SPAN_FOG) interpolate_fog(ctx, span); - /* Compute fragment colors with fragment program or texture lookups */ - if (ctx->ShaderObjects._FragmentShaderPresent) { - if (span->interpMask & SPAN_Z) - _swrast_span_interpolate_z (ctx, span); - _swrast_exec_arbshader (ctx, span); + /* Compute fragment colors with fragment program or texture lookups */ + if (ctx->ShaderObjects._FragmentShaderPresent) { + if (span->interpMask & SPAN_Z) + _swrast_span_interpolate_z (ctx, span); + _swrast_exec_arbshader (ctx, span); } else if (ctx->FragmentProgram._Active) { /* frag prog may need Z values */ @@ -1240,11 +1280,11 @@ _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span) if (span->interpMask & SPAN_FOG) interpolate_fog(ctx, span); - if (ctx->ShaderObjects._FragmentShaderPresent) { - if (span->interpMask & SPAN_Z) - _swrast_span_interpolate_z (ctx, span); - _swrast_exec_arbshader (ctx, span); - } + if (ctx->ShaderObjects._FragmentShaderPresent) { + if (span->interpMask & SPAN_Z) + _swrast_span_interpolate_z (ctx, span); + _swrast_exec_arbshader (ctx, span); + } else if (ctx->FragmentProgram._Active) _swrast_exec_fragment_program( ctx, span ); else if (ctx->ATIFragmentShader._Enabled) diff --git a/src/mesa/swrast/s_tritemp.h b/src/mesa/swrast/s_tritemp.h index 7f581561ec5..29a7a94da15 100644 --- a/src/mesa/swrast/s_tritemp.h +++ b/src/mesa/swrast/s_tritemp.h @@ -28,7 +28,7 @@ * This file is #include'd to generate custom triangle rasterizers. * * The following macros may be defined to indicate what auxillary information - * must be interplated across the triangle: + * must be interpolated across the triangle: * INTERP_Z - if defined, interpolate vertex Z values * INTERP_W - if defined, interpolate vertex W values * INTERP_FOG - if defined, interpolate fog values @@ -41,6 +41,7 @@ * INTERP_TEX - if defined, interpolate set 0 float STRQ texcoords * NOTE: OpenGL STRQ = Mesa STUV (R was taken for red) * INTERP_MULTITEX - if defined, interpolate N units of STRQ texcoords + * INTERP_VARYING - if defined, interpolate M floats of GLSL varyings * * When one can directly address pixels in the color buffer the following * macros can be defined and used to compute pixel addresses during @@ -142,6 +143,20 @@ +#ifdef INTERP_VARYING +#define VARYING_LOOP(CODE)\ + {\ + GLuint iv, ic;\ + for (iv = 0; iv < MAX_VARYING_VECTORS; iv++) {\ + for (ic = 0; ic < VARYINGS_PER_VECTOR; ic++) {\ + CODE\ + }\ + }\ + } +#endif + + + /* * Some code we unfortunately need to prevent negative interpolated colors. */ @@ -648,6 +663,19 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, ) } #endif +#ifdef INTERP_VARYING + span.interpMask |= SPAN_VARYING; + { + /* win[3] is 1/W */ + const GLfloat wMax = vMax->win[3], wMin = vMin->win[3], wMid = vMid->win[3]; + VARYING_LOOP( + GLfloat eMaj_dvar = vMax->attribute[iv][ic] * wMax - vMin->attribute[iv][ic] * wMin; + GLfloat eBot_dvar = vMid->attribute[iv][ic] * wMid - vMin->attribute[iv][ic] * wMin; + span.varStepX[iv][ic] = oneOverArea * (eMaj_dvar * eBot.dy - eMaj.dy * eBot_dvar); + span.varStepY[iv][ic] = oneOverArea * (eMaj.dx * eBot_dvar - eMaj_dvar * eBot.dx); + ) + } +#endif /* * We always sample at pixel centers. However, we avoid @@ -751,6 +779,11 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, GLfloat duOuter[MAX_TEXTURE_COORD_UNITS], duInner[MAX_TEXTURE_COORD_UNITS]; GLfloat dvOuter[MAX_TEXTURE_COORD_UNITS], dvInner[MAX_TEXTURE_COORD_UNITS]; #endif +#ifdef INTERP_VARYING + GLfloat varLeft[MAX_VARYING_VECTORS][VARYINGS_PER_VECTOR]; + GLfloat dvarOuter[MAX_VARYING_VECTORS][VARYINGS_PER_VECTOR]; + GLfloat dvarInner[MAX_VARYING_VECTORS][VARYINGS_PER_VECTOR]; +#endif for (subTriangle=0; subTriangle<=1; subTriangle++) { EdgeT *eLeft, *eRight; @@ -1023,6 +1056,15 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, duOuter[u] = span.texStepY[u][2] + dxOuter * span.texStepX[u][2]; dvOuter[u] = span.texStepY[u][3] + dxOuter * span.texStepX[u][3]; ) +#endif +#ifdef INTERP_VARYING + VARYING_LOOP( + const GLfloat invW = vLower->win[3]; + const GLfloat var0 = vLower->attribute[iv][ic] * invW; + varLeft[iv][ic] = var0 + (span.varStepX[iv][ic] * adjx + + span.varStepY[iv][ic] * adjy) * (1.0f / FIXED_SCALE); + dvarOuter[iv][ic] = span.varStepY[iv][ic] + dxOuter * span.varStepX[iv][ic]; + ) #endif } /*if setupLeft*/ @@ -1086,6 +1128,11 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, dvInner[u] = dvOuter[u] + span.texStepX[u][3]; ) #endif +#ifdef INTERP_VARYING + VARYING_LOOP( + dvarInner[iv][ic] = dvarOuter[iv][ic] + span.varStepX[iv][ic]; + ) +#endif while (lines > 0) { /* initialize the span interpolants to the leftmost value */ @@ -1135,6 +1182,11 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, span.tex[u][3] = vLeft[u]; ) #endif +#ifdef INTERP_VARYING + VARYING_LOOP( + span.var[iv][ic] = varLeft[iv][ic]; + ) +#endif /* This is where we actually generate fragments */ /* XXX the test for span.y > 0 _shouldn't_ be needed but @@ -1222,6 +1274,11 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, uLeft[u] += duOuter[u]; vLeft[u] += dvOuter[u]; ) +#endif +#ifdef INTERP_VARYING + VARYING_LOOP( + varLeft[iv][ic] += dvarOuter[iv][ic]; + ) #endif } else { @@ -1267,6 +1324,11 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, uLeft[u] += duInner[u]; vLeft[u] += dvInner[u]; ) +#endif +#ifdef INTERP_VARYING + VARYING_LOOP( + varLeft[iv][ic] += dvarInner[iv][ic]; + ) #endif } } /*while lines>0*/ @@ -1299,7 +1361,9 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, #undef INTERP_INT_TEX #undef INTERP_TEX #undef INTERP_MULTITEX +#undef INTERP_VARYING #undef TEX_UNIT_LOOP +#undef VARYING_LOOP #undef S_SCALE #undef T_SCALE diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h index 4422195a524..2a212342539 100644 --- a/src/mesa/swrast/swrast.h +++ b/src/mesa/swrast/swrast.h @@ -2,7 +2,7 @@ * Mesa 3-D graphics library * Version: 6.5 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -73,6 +73,7 @@ typedef struct { GLfloat fog; GLfloat index; GLfloat pointSize; + GLfloat attribute[MAX_VERTEX_ATTRIBS][4]; } SWvertex; diff --git a/src/mesa/swrast_setup/ss_context.c b/src/mesa/swrast_setup/ss_context.c index c63646ca977..7b25d14a0ca 100644 --- a/src/mesa/swrast_setup/ss_context.c +++ b/src/mesa/swrast_setup/ss_context.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.1 + * Version: 6.5 * - * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -93,7 +93,6 @@ do { \ e++; \ } while (0) - /* * We patch this function into tnl->Driver.Render.Start. * It's called when we start rendering a vertex buffer. @@ -119,43 +118,52 @@ _swsetup_RenderStart( GLcontext *ctx ) VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; - if (tnl->render_inputs != swsetup->last_index) { - GLuint index = tnl->render_inputs; + if (!RENDERINPUTS_EQUAL(tnl->render_inputs_bitset, swsetup->last_index_bitset)) { + DECLARE_RENDERINPUTS(index_bitset); struct tnl_attr_map map[_TNL_ATTRIB_MAX]; int i, e = 0; + RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); + EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, win ); - - if (index & _TNL_BIT_COLOR0) - EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4CHAN_4F_RGBA, color ); - - if (index & _TNL_BIT_COLOR1) - EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4CHAN_4F_RGBA, specular); - - if (index & _TNL_BIT_FOG) - EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1F, fog); - - if (index & _TNL_BITS_TEX_ANY) { - for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { - if (index & _TNL_BIT_TEX(i)) { - EMIT_ATTR( _TNL_ATTRIB_TEX0+i, EMIT_4F, texcoord[i] ); - } - } + + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR0 )) + EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4CHAN_4F_RGBA, color ); + + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) + EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4CHAN_4F_RGBA, specular); + + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) + EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1F, fog); + + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { + for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(i) )) { + EMIT_ATTR( _TNL_ATTRIB_TEX(i), EMIT_4F, texcoord[i] ); + } + } } - - if (index & _TNL_BIT_INDEX) - EMIT_ATTR( _TNL_ATTRIB_INDEX, EMIT_1F, index ); - - if (index & _TNL_BIT_POINTSIZE) - EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, pointSize ); - + + if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_ATTRIBUTE, _TNL_LAST_ATTRIBUTE )) { + for (i = 0; i < MAX_VERTEX_ATTRIBS; i++) { + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_ATTRIBUTE(i) )) { + EMIT_ATTR( _TNL_ATTRIB_ATTRIBUTE(i), VARYING_EMIT_STYLE, attribute[i] ); + } + } + } + + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_INDEX )) + EMIT_ATTR( _TNL_ATTRIB_INDEX, EMIT_1F, index ); + + if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_POINTSIZE )) + EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, pointSize ); + _tnl_install_attrs( ctx, map, e, - ctx->Viewport._WindowMap.m, - sizeof(SWvertex) ); - - swsetup->last_index = index; - } + ctx->Viewport._WindowMap.m, + sizeof(SWvertex) ); + RENDERINPUTS_COPY( swsetup->last_index_bitset, index_bitset ); + } } /* @@ -205,7 +213,7 @@ _swsetup_Wakeup( GLcontext *ctx ) _swsetup_InvalidateState( ctx, ~0 ); swsetup->verts = (SWvertex *)tnl->clipspace.vertex_buf; - swsetup->last_index = 0; + RENDERINPUTS_ZERO( swsetup->last_index_bitset ); } diff --git a/src/mesa/swrast_setup/ss_context.h b/src/mesa/swrast_setup/ss_context.h index 2c6e4faf3da..e5d890447a7 100644 --- a/src/mesa/swrast_setup/ss_context.h +++ b/src/mesa/swrast_setup/ss_context.h @@ -1,9 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 4.1 + * Version: 6.5 * - * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -32,11 +32,12 @@ #include "mtypes.h" #include "swrast/swrast.h" #include "swrast_setup.h" +#include "tnl/t_context.h" typedef struct { GLuint NewState; GLenum render_prim; - GLuint last_index; + DECLARE_RENDERINPUTS(last_index_bitset); SWvertex *verts; } SScontext; diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c index d9777bfe6d7..ad972fa7b7c 100644 --- a/src/mesa/tnl/t_context.c +++ b/src/mesa/tnl/t_context.c @@ -2,7 +2,7 @@ * Mesa 3-D graphics library * Version: 6.5 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -170,32 +170,43 @@ _tnl_InvalidateState( GLcontext *ctx, GLuint new_state ) /* Calculate tnl->render_inputs: */ if (ctx->Visual.rgbMode) { - tnl->render_inputs = (_TNL_BIT_POS| - _TNL_BIT_COLOR0| - (ctx->Texture._EnabledCoordUnits << _TNL_ATTRIB_TEX0)); + GLuint i; + + RENDERINPUTS_ZERO( tnl->render_inputs_bitset ); + RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_POS ); + RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR0 ); + for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { + if (ctx->Texture._EnabledCoordUnits & (1 << i)) { + RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_TEX(i) ); + } + } if (NEED_SECONDARY_COLOR(ctx)) - tnl->render_inputs |= _TNL_BIT_COLOR1; + RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR1 ); } else { - tnl->render_inputs |= (_TNL_BIT_POS|_TNL_BIT_INDEX); + RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_POS ); + RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_INDEX ); } - + if (ctx->Fog.Enabled || (ctx->FragmentProgram._Active && - ctx->FragmentProgram._Current->FogOption != GL_NONE)) - tnl->render_inputs |= _TNL_BIT_FOG; + ctx->FragmentProgram._Current->FogOption != GL_NONE)) + RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_FOG ); if (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL) - tnl->render_inputs |= _TNL_BIT_EDGEFLAG; + RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_EDGEFLAG ); if (ctx->RenderMode == GL_FEEDBACK) - tnl->render_inputs |= _TNL_BIT_TEX0; + RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_TEX0 ); if (ctx->Point._Attenuated || (ctx->VertexProgram._Enabled && ctx->VertexProgram.PointSizeEnabled)) - tnl->render_inputs |= _TNL_BIT_POINTSIZE; + RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_POINTSIZE ); + + if (ctx->ShaderObjects._VertexShaderPresent || ctx->ShaderObjects._FragmentShaderPresent) + RENDERINPUTS_SET_RANGE( tnl->render_inputs_bitset, _TNL_FIRST_ATTRIBUTE, _TNL_LAST_ATTRIBUTE ); } diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h index 753f59257a0..7a0ca6f411f 100644 --- a/src/mesa/tnl/t_context.h +++ b/src/mesa/tnl/t_context.h @@ -2,7 +2,7 @@ * mesa 3-D graphics library * Version: 6.5 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 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"), @@ -92,6 +92,12 @@ * number of bits allocated for these numbers in places like vertex * program instruction formats and register layouts. */ +/* The bit space exhaustion is a fact now, done by _TNL_ATTRIB_ATTRIBUTE* for + * GLSL vertex shader which cannot be aliased with conventional vertex attribs. + * Compacting _TNL_ATTRIB_MAT_* attribs would not work, they would not give + * as many free bits (11 plus already 1 free bit) as _TNL_ATTRIB_ATTRIBUTE* + * attribs want (16). + */ enum { _TNL_ATTRIB_POS = 0, _TNL_ATTRIB_WEIGHT = 1, @@ -109,98 +115,56 @@ enum { _TNL_ATTRIB_TEX5 = 13, _TNL_ATTRIB_TEX6 = 14, _TNL_ATTRIB_TEX7 = 15, - _TNL_ATTRIB_MAT_FRONT_AMBIENT = 16, - _TNL_ATTRIB_MAT_BACK_AMBIENT = 17, - _TNL_ATTRIB_MAT_FRONT_DIFFUSE = 18, - _TNL_ATTRIB_MAT_BACK_DIFFUSE = 19, - _TNL_ATTRIB_MAT_FRONT_SPECULAR = 20, - _TNL_ATTRIB_MAT_BACK_SPECULAR = 21, - _TNL_ATTRIB_MAT_FRONT_EMISSION = 22, - _TNL_ATTRIB_MAT_BACK_EMISSION = 23, - _TNL_ATTRIB_MAT_FRONT_SHININESS = 24, - _TNL_ATTRIB_MAT_BACK_SHININESS = 25, - _TNL_ATTRIB_MAT_FRONT_INDEXES = 26, - _TNL_ATTRIB_MAT_BACK_INDEXES = 27, - _TNL_ATTRIB_INDEX = 28, - _TNL_ATTRIB_EDGEFLAG = 29, - _TNL_ATTRIB_POINTSIZE = 30, - _TNL_ATTRIB_MAX = 31 + _TNL_ATTRIB_ATTRIBUTE0 = 16, + _TNL_ATTRIB_ATTRIBUTE1 = 17, + _TNL_ATTRIB_ATTRIBUTE2 = 18, + _TNL_ATTRIB_ATTRIBUTE3 = 19, + _TNL_ATTRIB_ATTRIBUTE4 = 20, + _TNL_ATTRIB_ATTRIBUTE5 = 21, + _TNL_ATTRIB_ATTRIBUTE6 = 22, + _TNL_ATTRIB_ATTRIBUTE7 = 23, + _TNL_ATTRIB_ATTRIBUTE8 = 24, + _TNL_ATTRIB_ATTRIBUTE9 = 25, + _TNL_ATTRIB_ATTRIBUTE10 = 26, + _TNL_ATTRIB_ATTRIBUTE11 = 27, + _TNL_ATTRIB_ATTRIBUTE12 = 28, + _TNL_ATTRIB_ATTRIBUTE13 = 29, + _TNL_ATTRIB_ATTRIBUTE14 = 30, + _TNL_ATTRIB_ATTRIBUTE15 = 31, + _TNL_ATTRIB_MAT_FRONT_AMBIENT = 32, + _TNL_ATTRIB_MAT_BACK_AMBIENT = 33, + _TNL_ATTRIB_MAT_FRONT_DIFFUSE = 34, + _TNL_ATTRIB_MAT_BACK_DIFFUSE = 35, + _TNL_ATTRIB_MAT_FRONT_SPECULAR = 36, + _TNL_ATTRIB_MAT_BACK_SPECULAR = 37, + _TNL_ATTRIB_MAT_FRONT_EMISSION = 38, + _TNL_ATTRIB_MAT_BACK_EMISSION = 39, + _TNL_ATTRIB_MAT_FRONT_SHININESS = 40, + _TNL_ATTRIB_MAT_BACK_SHININESS = 41, + _TNL_ATTRIB_MAT_FRONT_INDEXES = 42, + _TNL_ATTRIB_MAT_BACK_INDEXES = 43, + _TNL_ATTRIB_INDEX = 44, + _TNL_ATTRIB_EDGEFLAG = 45, + _TNL_ATTRIB_POINTSIZE = 46, + _TNL_ATTRIB_MAX = 47 } ; -/* Will probably have to revise this scheme fairly shortly, eg. by - * compacting all the MAT flags down to one bit, or by using two - * dwords to store the flags. +#define _TNL_ATTRIB_TEX(u) (_TNL_ATTRIB_TEX0 + (u)) +#define _TNL_ATTRIB_ATTRIBUTE(n) (_TNL_ATTRIB_ATTRIBUTE0 + (n)) + +/* Define bit ranges instead of bit masks. */ -#define _TNL_BIT_POS (1<<0) -#define _TNL_BIT_WEIGHT (1<<1) -#define _TNL_BIT_NORMAL (1<<2) -#define _TNL_BIT_COLOR0 (1<<3) -#define _TNL_BIT_COLOR1 (1<<4) -#define _TNL_BIT_FOG (1<<5) -#define _TNL_BIT_SIX (1<<6) -#define _TNL_BIT_SEVEN (1<<7) -#define _TNL_BIT_TEX0 (1<<8) -#define _TNL_BIT_TEX1 (1<<9) -#define _TNL_BIT_TEX2 (1<<10) -#define _TNL_BIT_TEX3 (1<<11) -#define _TNL_BIT_TEX4 (1<<12) -#define _TNL_BIT_TEX5 (1<<13) -#define _TNL_BIT_TEX6 (1<<14) -#define _TNL_BIT_TEX7 (1<<15) -#define _TNL_BIT_MAT_FRONT_AMBIENT (1<<16) -#define _TNL_BIT_MAT_BACK_AMBIENT (1<<17) -#define _TNL_BIT_MAT_FRONT_DIFFUSE (1<<18) -#define _TNL_BIT_MAT_BACK_DIFFUSE (1<<19) -#define _TNL_BIT_MAT_FRONT_SPECULAR (1<<20) -#define _TNL_BIT_MAT_BACK_SPECULAR (1<<21) -#define _TNL_BIT_MAT_FRONT_EMISSION (1<<22) -#define _TNL_BIT_MAT_BACK_EMISSION (1<<23) -#define _TNL_BIT_MAT_FRONT_SHININESS (1<<24) -#define _TNL_BIT_MAT_BACK_SHININESS (1<<25) -#define _TNL_BIT_MAT_FRONT_INDEXES (1<<26) -#define _TNL_BIT_MAT_BACK_INDEXES (1<<27) -#define _TNL_BIT_INDEX (1<<28) -#define _TNL_BIT_EDGEFLAG (1<<29) -#define _TNL_BIT_POINTSIZE (1<<30) - -#define _TNL_BIT_TEX(u) (1 << (_TNL_ATTRIB_TEX0 + (u))) - - - -#define _TNL_BITS_MAT_ANY (_TNL_BIT_MAT_FRONT_AMBIENT | \ - _TNL_BIT_MAT_BACK_AMBIENT | \ - _TNL_BIT_MAT_FRONT_DIFFUSE | \ - _TNL_BIT_MAT_BACK_DIFFUSE | \ - _TNL_BIT_MAT_FRONT_SPECULAR | \ - _TNL_BIT_MAT_BACK_SPECULAR | \ - _TNL_BIT_MAT_FRONT_EMISSION | \ - _TNL_BIT_MAT_BACK_EMISSION | \ - _TNL_BIT_MAT_FRONT_SHININESS | \ - _TNL_BIT_MAT_BACK_SHININESS | \ - _TNL_BIT_MAT_FRONT_INDEXES | \ - _TNL_BIT_MAT_BACK_INDEXES) - - -#define _TNL_BITS_TEX_ANY (_TNL_BIT_TEX0 | \ - _TNL_BIT_TEX1 | \ - _TNL_BIT_TEX2 | \ - _TNL_BIT_TEX3 | \ - _TNL_BIT_TEX4 | \ - _TNL_BIT_TEX5 | \ - _TNL_BIT_TEX6 | \ - _TNL_BIT_TEX7) - - -#define _TNL_BITS_PROG_ANY (_TNL_BIT_POS | \ - _TNL_BIT_WEIGHT | \ - _TNL_BIT_NORMAL | \ - _TNL_BIT_COLOR0 | \ - _TNL_BIT_COLOR1 | \ - _TNL_BIT_FOG | \ - _TNL_BIT_SIX | \ - _TNL_BIT_SEVEN | \ - _TNL_BITS_TEX_ANY) +#define _TNL_FIRST_PROG _TNL_ATTRIB_WEIGHT +#define _TNL_LAST_PROG _TNL_ATTRIB_TEX7 + +#define _TNL_FIRST_TEX _TNL_ATTRIB_TEX0 +#define _TNL_LAST_TEX _TNL_ATTRIB_TEX7 + +#define _TNL_FIRST_ATTRIBUTE _TNL_ATTRIB_ATTRIBUTE0 +#define _TNL_LAST_ATTRIBUTE _TNL_ATTRIB_ATTRIBUTE15 +#define _TNL_FIRST_MAT _TNL_ATTRIB_MAT_FRONT_AMBIENT +#define _TNL_LAST_MAT _TNL_ATTRIB_MAT_BACK_INDEXES #define PRIM_BEGIN 0x10 @@ -444,6 +408,7 @@ struct vertex_buffer GLvector4f *SecondaryColorPtr[2]; /* _TNL_BIT_COLOR1 */ GLvector4f *PointSizePtr; /* _TNL_BIT_POS */ GLvector4f *FogCoordPtr; /* _TNL_BIT_FOG */ + GLvector4f *VaryingPtr[MAX_VARYING_VECTORS]; struct tnl_prim *Primitive; GLuint PrimitiveCount; @@ -730,7 +695,20 @@ struct tnl_device_driver */ } Render; }; - + + +#define DECLARE_RENDERINPUTS(name) BITSET64_DECLARE(name, _TNL_ATTRIB_MAX) +#define RENDERINPUTS_COPY BITSET64_COPY +#define RENDERINPUTS_EQUAL BITSET64_EQUAL +#define RENDERINPUTS_ZERO BITSET64_ZERO +#define RENDERINPUTS_ONES BITSET64_ONES +#define RENDERINPUTS_TEST BITSET64_TEST +#define RENDERINPUTS_SET BITSET64_SET +#define RENDERINPUTS_CLEAR BITSET64_CLEAR +#define RENDERINPUTS_TEST_RANGE BITSET64_TEST_RANGE +#define RENDERINPUTS_SET_RANGE BITSET64_SET_RANGE +#define RENDERINPUTS_CLEAR_RANGE BITSET64_CLEAR_RANGE + /** * Context state for T&L context. @@ -783,7 +761,7 @@ typedef struct */ GLboolean DiscardPrimitive; - GLuint render_inputs; + DECLARE_RENDERINPUTS(render_inputs_bitset); GLvertexformat exec_vtxfmt; GLvertexformat save_vtxfmt; diff --git a/src/mesa/tnl/t_save_api.c b/src/mesa/tnl/t_save_api.c index 9788468d508..5765652b7e0 100644 --- a/src/mesa/tnl/t_save_api.c +++ b/src/mesa/tnl/t_save_api.c @@ -936,7 +936,7 @@ static void GLAPIENTRY _save_MultiTexCoord4fv( GLenum target, const GLfloat *v ) static void GLAPIENTRY _save_VertexAttrib1fNV( GLuint index, GLfloat x ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) DISPATCH_ATTR1F( index, x ); else enum_error(); @@ -944,7 +944,7 @@ static void GLAPIENTRY _save_VertexAttrib1fNV( GLuint index, GLfloat x ) static void GLAPIENTRY _save_VertexAttrib1fvNV( GLuint index, const GLfloat *v ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) DISPATCH_ATTR1FV( index, v ); else enum_error(); @@ -952,7 +952,7 @@ static void GLAPIENTRY _save_VertexAttrib1fvNV( GLuint index, const GLfloat *v ) static void GLAPIENTRY _save_VertexAttrib2fNV( GLuint index, GLfloat x, GLfloat y ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) DISPATCH_ATTR2F( index, x, y ); else enum_error(); @@ -960,7 +960,7 @@ static void GLAPIENTRY _save_VertexAttrib2fNV( GLuint index, GLfloat x, GLfloat static void GLAPIENTRY _save_VertexAttrib2fvNV( GLuint index, const GLfloat *v ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) DISPATCH_ATTR2FV( index, v ); else enum_error(); @@ -969,7 +969,7 @@ static void GLAPIENTRY _save_VertexAttrib2fvNV( GLuint index, const GLfloat *v ) static void GLAPIENTRY _save_VertexAttrib3fNV( GLuint index, GLfloat x, GLfloat y, GLfloat z ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) DISPATCH_ATTR3F( index, x, y, z ); else enum_error(); @@ -977,7 +977,7 @@ static void GLAPIENTRY _save_VertexAttrib3fNV( GLuint index, GLfloat x, GLfloat static void GLAPIENTRY _save_VertexAttrib3fvNV( GLuint index, const GLfloat *v ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) DISPATCH_ATTR3FV( index, v ); else enum_error(); @@ -986,7 +986,7 @@ static void GLAPIENTRY _save_VertexAttrib3fvNV( GLuint index, const GLfloat *v ) static void GLAPIENTRY _save_VertexAttrib4fNV( GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) DISPATCH_ATTR4F( index, x, y, z, w ); else enum_error(); @@ -994,7 +994,7 @@ static void GLAPIENTRY _save_VertexAttrib4fNV( GLuint index, GLfloat x, GLfloat static void GLAPIENTRY _save_VertexAttrib4fvNV( GLuint index, const GLfloat *v ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_PROGRAM_ATTRIBS) DISPATCH_ATTR4FV( index, v ); else enum_error(); @@ -1004,7 +1004,7 @@ static void GLAPIENTRY _save_VertexAttrib4fvNV( GLuint index, const GLfloat *v ) static void GLAPIENTRY _save_VertexAttrib1fARB( GLuint index, GLfloat x ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) DISPATCH_ATTR1F( index, x ); else enum_error(); @@ -1013,7 +1013,7 @@ _save_VertexAttrib1fARB( GLuint index, GLfloat x ) static void GLAPIENTRY _save_VertexAttrib1fvARB( GLuint index, const GLfloat *v ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) DISPATCH_ATTR1FV( index, v ); else enum_error(); @@ -1022,7 +1022,7 @@ _save_VertexAttrib1fvARB( GLuint index, const GLfloat *v ) static void GLAPIENTRY _save_VertexAttrib2fARB( GLuint index, GLfloat x, GLfloat y ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) DISPATCH_ATTR2F( index, x, y ); else enum_error(); @@ -1031,7 +1031,7 @@ _save_VertexAttrib2fARB( GLuint index, GLfloat x, GLfloat y ) static void GLAPIENTRY _save_VertexAttrib2fvARB( GLuint index, const GLfloat *v ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) DISPATCH_ATTR2FV( index, v ); else enum_error(); @@ -1040,7 +1040,7 @@ _save_VertexAttrib2fvARB( GLuint index, const GLfloat *v ) static void GLAPIENTRY _save_VertexAttrib3fARB( GLuint index, GLfloat x, GLfloat y, GLfloat z ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) DISPATCH_ATTR3F( index, x, y, z ); else enum_error(); @@ -1049,7 +1049,7 @@ _save_VertexAttrib3fARB( GLuint index, GLfloat x, GLfloat y, GLfloat z ) static void GLAPIENTRY _save_VertexAttrib3fvARB( GLuint index, const GLfloat *v ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) DISPATCH_ATTR3FV( index, v ); else enum_error(); @@ -1058,7 +1058,7 @@ _save_VertexAttrib3fvARB( GLuint index, const GLfloat *v ) static void GLAPIENTRY _save_VertexAttrib4fARB( GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) DISPATCH_ATTR4F( index, x, y, z, w ); else enum_error(); @@ -1067,7 +1067,7 @@ _save_VertexAttrib4fARB( GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat static void GLAPIENTRY _save_VertexAttrib4fvARB( GLuint index, const GLfloat *v ) { - if (index < VERT_ATTRIB_MAX) + if (index < MAX_VERTEX_ATTRIBS) DISPATCH_ATTR4FV( index, v ); else enum_error(); diff --git a/src/mesa/tnl/t_vb_arbshader.c b/src/mesa/tnl/t_vb_arbshader.c index 88d7f6ac8cc..b1d024e0cca 100644 --- a/src/mesa/tnl/t_vb_arbshader.c +++ b/src/mesa/tnl/t_vb_arbshader.c @@ -37,6 +37,7 @@ typedef struct { GLvector4f outputs[VERT_RESULT_MAX]; + GLvector4f varyings[MAX_VARYING_VECTORS]; GLvector4f ndc_coords; GLubyte *clipmask; GLubyte ormask; @@ -63,6 +64,11 @@ static GLboolean construct_arb_vertex_shader (GLcontext *ctx, struct tnl_pipelin _mesa_vector4f_alloc (&store->outputs[i], 0, size, 32); store->outputs[i].size = 4; } + for (i = 0; i < MAX_VARYING_VECTORS; i++) + { + _mesa_vector4f_alloc (&store->varyings[i], 0, size, 32); + store->varyings[i].size = 4; + } _mesa_vector4f_alloc (&store->ndc_coords, 0, size, 32); store->clipmask = (GLubyte *) ALIGN_MALLOC (size, 32); @@ -79,6 +85,8 @@ static void destruct_arb_vertex_shader (struct tnl_pipeline_stage *stage) for (i = 0; i < VERT_RESULT_MAX; i++) _mesa_vector4f_free (&store->outputs[i]); + for (i = 0; i < MAX_VARYING_VECTORS; i++) + _mesa_vector4f_free (&store->varyings[i]); _mesa_vector4f_free (&store->ndc_coords); ALIGN_FREE (store->clipmask); @@ -206,6 +214,17 @@ static GLboolean run_arb_vertex_shader (GLcontext *ctx, struct tnl_pipeline_stag fetch_output_vec4 (pro, SLANG_VERTEX_FIXED_BACKCOLOR, VERT_RESULT_BFC0, i, 0, store); fetch_output_vec4 (pro, SLANG_VERTEX_FIXED_BACKSECONDARYCOLOR, VERT_RESULT_BFC1, i, 0, store); /* XXX: fetch output SLANG_VERTEX_FIXED_CLIPVERTEX */ + + for (j = 0; j < MAX_VARYING_VECTORS; j++) + { + GLuint k; + + for (k = 0; k < VARYINGS_PER_VECTOR; k++) + { + (**pro).UpdateVarying (pro, j * VARYINGS_PER_VECTOR + k, + &store->varyings[j].data[i][k], GL_TRUE); + } + } } vb->ClipPtr = &store->outputs[VERT_RESULT_HPOS]; @@ -218,6 +237,8 @@ static GLboolean run_arb_vertex_shader (GLcontext *ctx, struct tnl_pipeline_stag vb->SecondaryColorPtr[1] = &store->outputs[VERT_RESULT_BFC1]; vb->FogCoordPtr = &store->outputs[VERT_RESULT_FOGC]; vb->PointSizePtr = &store->outputs[VERT_RESULT_PSIZ]; + for (i = 0; i < MAX_VARYING_VECTORS; i++) + vb->VaryingPtr[i] = &store->varyings[i]; vb->AttribPtr[VERT_ATTRIB_COLOR0] = vb->ColorPtr[0]; vb->AttribPtr[VERT_ATTRIB_COLOR1] = vb->SecondaryColorPtr[0]; @@ -225,6 +246,8 @@ static GLboolean run_arb_vertex_shader (GLcontext *ctx, struct tnl_pipeline_stag for (i = 0; i < ctx->Const.MaxTextureUnits; i++) vb->AttribPtr[VERT_ATTRIB_TEX0 + i] = vb->TexCoordPtr[i]; vb->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &store->outputs[VERT_RESULT_PSIZ]; + for (i = 0; i < MAX_VARYING_VECTORS; i++) + vb->AttribPtr[_TNL_ATTRIB_ATTRIBUTE0 + i] = vb->VaryingPtr[i]; store->ormask = 0; store->andmask = CLIP_FRUSTUM_BITS; diff --git a/src/mesa/tnl/t_vtx_generic.c b/src/mesa/tnl/t_vtx_generic.c index 0422fcd45dc..d59ce90c6d7 100644 --- a/src/mesa/tnl/t_vtx_generic.c +++ b/src/mesa/tnl/t_vtx_generic.c @@ -364,42 +364,42 @@ static void GLAPIENTRY _tnl_MultiTexCoord4fv( GLenum target, static void GLAPIENTRY _tnl_VertexAttrib1fNV( GLuint index, GLfloat x ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) index = ERROR_ATTRIB; DISPATCH_ATTR1F( index, x ); } static void GLAPIENTRY _tnl_VertexAttrib1fvNV( GLuint index, const GLfloat *v ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) index = ERROR_ATTRIB; DISPATCH_ATTR1FV( index, v ); } static void GLAPIENTRY _tnl_VertexAttrib2fNV( GLuint index, GLfloat x, GLfloat y ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) index = ERROR_ATTRIB; DISPATCH_ATTR2F( index, x, y ); } static void GLAPIENTRY _tnl_VertexAttrib2fvNV( GLuint index, const GLfloat *v ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) index = ERROR_ATTRIB; DISPATCH_ATTR2FV( index, v ); } static void GLAPIENTRY _tnl_VertexAttrib3fNV( GLuint index, GLfloat x, GLfloat y, GLfloat z ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) index = ERROR_ATTRIB; DISPATCH_ATTR3F( index, x, y, z ); } static void GLAPIENTRY _tnl_VertexAttrib3fvNV( GLuint index, const GLfloat *v ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) index = ERROR_ATTRIB; DISPATCH_ATTR3FV( index, v ); } @@ -407,60 +407,73 @@ static void GLAPIENTRY _tnl_VertexAttrib4fNV( GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) index = ERROR_ATTRIB; DISPATCH_ATTR4F( index, x, y, z, w ); } static void GLAPIENTRY _tnl_VertexAttrib4fvNV( GLuint index, const GLfloat *v ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) index = ERROR_ATTRIB; DISPATCH_ATTR4FV( index, v ); } - -/* - * XXX adjust index - */ - static void GLAPIENTRY _tnl_VertexAttrib1fARB( GLuint index, GLfloat x ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_ATTRIBS) + index = ERROR_ATTRIB; + else + index += VERT_ATTRIB_GENERIC0; DISPATCH_ATTR1F( index, x ); } static void GLAPIENTRY _tnl_VertexAttrib1fvARB( GLuint index, const GLfloat *v ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_ATTRIBS) + index = ERROR_ATTRIB; + else + index += VERT_ATTRIB_GENERIC0; DISPATCH_ATTR1FV( index, v ); } static void GLAPIENTRY _tnl_VertexAttrib2fARB( GLuint index, GLfloat x, GLfloat y ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_ATTRIBS) + index = ERROR_ATTRIB; + else + index += VERT_ATTRIB_GENERIC0; DISPATCH_ATTR2F( index, x, y ); } static void GLAPIENTRY _tnl_VertexAttrib2fvARB( GLuint index, const GLfloat *v ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_ATTRIBS) + index = ERROR_ATTRIB; + else + index += VERT_ATTRIB_GENERIC0; DISPATCH_ATTR2FV( index, v ); } static void GLAPIENTRY _tnl_VertexAttrib3fARB( GLuint index, GLfloat x, GLfloat y, GLfloat z ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_ATTRIBS) + index = ERROR_ATTRIB; + else + index += VERT_ATTRIB_GENERIC0; DISPATCH_ATTR3F( index, x, y, z ); } static void GLAPIENTRY _tnl_VertexAttrib3fvARB( GLuint index, const GLfloat *v ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_ATTRIBS) + index = ERROR_ATTRIB; + else + index += VERT_ATTRIB_GENERIC0; DISPATCH_ATTR3FV( index, v ); } @@ -468,14 +481,20 @@ static void GLAPIENTRY _tnl_VertexAttrib4fARB( GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_ATTRIBS) + index = ERROR_ATTRIB; + else + index += VERT_ATTRIB_GENERIC0; DISPATCH_ATTR4F( index, x, y, z, w ); } static void GLAPIENTRY _tnl_VertexAttrib4fvARB( GLuint index, const GLfloat *v ) { - if (index >= VERT_ATTRIB_MAX) index = ERROR_ATTRIB; + if (index >= MAX_VERTEX_ATTRIBS) + index = ERROR_ATTRIB; + else + index += VERT_ATTRIB_GENERIC0; DISPATCH_ATTR4FV( index, v ); } -- 2.30.2