From 5cc12925089ba705e4f0af9649bc30b546d900ff Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 14 Dec 2006 14:27:05 -0700 Subject: Replace __extension__ with LONGSTRING. --- src/mesa/shader/arbprogparse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/shader') diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index 5a61f30193b..72d49093721 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -3703,7 +3703,7 @@ parse_instructions(GLcontext * ctx, const GLubyte * inst, /* XXX temporary */ -__extension__ static char core_grammar_text[] = +LONGSTRING static char core_grammar_text[] = #include "grammar_syn.h" ; -- cgit v1.2.3 From 6dd967e74ff4cb03220d5785bd583203464d299d Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Sun, 14 Jan 2007 14:49:36 +0100 Subject: mesa: Update _Current ptr along Current when a new vertex program is bind. On new vertex program bind only the Current ptr where updated to point to the new program; this could lead to _Current pointing to and out of date or even a no more existing program which in turn could lead to a segfault in some driver. To avoid this _Current ptr is updated along Current if _Current where previously pointing to the same program. --- src/mesa/shader/program.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/mesa/shader') diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index ddfad47b894..6db62f591c8 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -1947,6 +1947,8 @@ _mesa_BindProgram(GLenum target, GLuint id) /* bind newProg */ if (target == GL_VERTEX_PROGRAM_ARB) { /* == GL_VERTEX_PROGRAM_NV */ + if (ctx->VertexProgram._Current == ctx->VertexProgram.Current) + ctx->VertexProgram._Current = (struct gl_vertex_program *) newProg; ctx->VertexProgram.Current = (struct gl_vertex_program *) newProg; } else if (target == GL_FRAGMENT_PROGRAM_NV || @@ -1969,7 +1971,7 @@ _mesa_BindProgram(GLenum target, GLuint id) * \note Not compiled into display lists. * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB. */ -void GLAPIENTRY +void GLAPIENTRY _mesa_DeletePrograms(GLsizei n, const GLuint *ids) { GLint i; -- cgit v1.2.3 From a03fc8277180e2171519165a724849e2254ef0b7 Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Mon, 15 Jan 2007 21:19:52 +0100 Subject: mesa: Update _Current along Current on fragment program bound. Same as a previously committed patch for vertex program, we update fragment program ptr _Current along the Current one so that _Current can't end up pointing to a no more valid program. --- src/mesa/shader/program.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/mesa/shader') diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 6db62f591c8..8442ba3248c 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -1953,6 +1953,8 @@ _mesa_BindProgram(GLenum target, GLuint id) } else if (target == GL_FRAGMENT_PROGRAM_NV || target == GL_FRAGMENT_PROGRAM_ARB) { + if (ctx->FragmentProgram._Current == ctx->FragmentProgram.Current) + ctx->FragmentProgram._Current = (struct gl_fragment_program *) newProg; ctx->FragmentProgram.Current = (struct gl_fragment_program *) newProg; } newProg->RefCount++; -- cgit v1.2.3 From 18d1fdebebcb52e7fcf50e62c4c02862d173af51 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 23 Jan 2007 11:46:02 -0700 Subject: fixes for C++ warnings/errors --- src/mesa/drivers/x11/glxapi.c | 2 +- src/mesa/main/colortab.c | 4 ++-- src/mesa/main/dlist.c | 4 ++-- src/mesa/main/texcompress_s3tc.c | 2 +- src/mesa/main/texenvprogram.c | 5 +++-- src/mesa/main/texobj.c | 6 +++--- src/mesa/shader/arbprogram.c | 4 ++-- src/mesa/shader/program.c | 2 +- src/mesa/shader/slang/slang_execute.c | 2 +- src/mesa/swrast/s_copypix.c | 4 ++-- src/mesa/swrast/s_depth.c | 4 ++-- src/mesa/swrast/s_drawpix.c | 16 ++++++++++------ src/mesa/swrast/s_readpix.c | 23 +++++++++++++---------- src/mesa/swrast/s_span.c | 8 +++++--- src/mesa/tnl/t_array_api.c | 2 +- src/mesa/tnl/t_vb_arbprogram.c | 3 ++- 16 files changed, 51 insertions(+), 40 deletions(-) (limited to 'src/mesa/shader') diff --git a/src/mesa/drivers/x11/glxapi.c b/src/mesa/drivers/x11/glxapi.c index 7945f1c5b06..973f3940451 100644 --- a/src/mesa/drivers/x11/glxapi.c +++ b/src/mesa/drivers/x11/glxapi.c @@ -241,7 +241,7 @@ glXGetCurrentContext(void) #if defined(GLX_USE_TLS) return CurrentContext; #elif defined(THREADS) - return _glthread_GetTSD(&ContextTSD); + return (GLXContext) _glthread_GetTSD(&ContextTSD); #else return CurrentContext; #endif diff --git a/src/mesa/main/colortab.c b/src/mesa/main/colortab.c index e9349516eb8..9fb0baf4a7c 100644 --- a/src/mesa/main/colortab.c +++ b/src/mesa/main/colortab.c @@ -472,8 +472,8 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, _mesa_free_colortable_data(table); if (width > 0) { - table->TableF = _mesa_malloc(comps * width * sizeof(GLfloat)); - table->TableUB = _mesa_malloc(comps * width * sizeof(GLubyte)); + table->TableF = (GLfloat *) _mesa_malloc(comps * width * sizeof(GLfloat)); + table->TableUB = (GLubyte *) _mesa_malloc(comps * width * sizeof(GLubyte)); if (!table->TableF || !table->TableUB) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable"); diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index dca6ede6cb3..ca484034828 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -4476,7 +4476,7 @@ save_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count, ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx); if (count > 0) { - unsigned i; + GLint i; const GLfloat * p = params; for (i = 0 ; i < count ; i++) { @@ -4710,7 +4710,7 @@ save_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count, ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx); if (count > 0) { - unsigned i; + GLint i; const GLfloat * p = params; for (i = 0 ; i < count ; i++) { diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c index 99b703de4a5..c823967b7a0 100644 --- a/src/mesa/main/texcompress_s3tc.c +++ b/src/mesa/main/texcompress_s3tc.c @@ -91,7 +91,7 @@ _mesa_dlopen(const char *libname, int flags) return dlopen(libname, flags); #endif #else - return (GenericFunc) NULL; + return NULL; #endif /* USE_EXTERNAL_DXTN_LIB */ } diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c index 5329719cbbb..5038b9b0c36 100644 --- a/src/mesa/main/texenvprogram.c +++ b/src/mesa/main/texenvprogram.c @@ -1184,13 +1184,14 @@ static void cache_item( struct texenvprog_cache *cache, const struct state_key *key, void *data ) { - struct texenvprog_cache_item *c = MALLOC(sizeof(*c)); + struct texenvprog_cache_item *c + = (struct texenvprog_cache_item *) MALLOC(sizeof(*c)); c->hash = hash; c->key = _mesa_malloc(sizeof(*key)); memcpy(c->key, key, sizeof(*key)); - c->data = data; + c->data = (struct gl_fragment_program *) data; if (cache->n_items > cache->size * 1.5) { if (cache->size < 1000) diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c index 1d27cd3f7c6..3cfbfa5eb54 100644 --- a/src/mesa/main/texobj.c +++ b/src/mesa/main/texobj.c @@ -699,7 +699,7 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures) = _mesa_lookup_texture(ctx, textures[i]); if (delObj) { - GLboolean delete; + GLboolean deleted; _mesa_lock_texture(ctx, delObj); @@ -728,14 +728,14 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures) * XXX all RefCount accesses should be protected by a mutex. */ delObj->RefCount--; - delete = (delObj->RefCount == 0); + deleted = (delObj->RefCount == 0); _mesa_unlock_texture(ctx, delObj); /* We know that refcount went to zero above, so this is * the only pointer left to delObj, so we don't have to * worry about locking any more: */ - if (delete) { + if (deleted) { ASSERT(delObj->Name != 0); /* Never delete default tex objs */ ASSERT(ctx->Driver.DeleteTexture); (*ctx->Driver.DeleteTexture)(ctx, delObj); diff --git a/src/mesa/shader/arbprogram.c b/src/mesa/shader/arbprogram.c index bff80d7ee3a..91f3a5e8ee7 100644 --- a/src/mesa/shader/arbprogram.c +++ b/src/mesa/shader/arbprogram.c @@ -312,7 +312,7 @@ _mesa_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count, const GLfloat *params) { GET_CURRENT_CONTEXT(ctx); - unsigned i; + GLint i; GLfloat * dest; ASSERT_OUTSIDE_BEGIN_END(ctx); @@ -464,7 +464,7 @@ _mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count, { GET_CURRENT_CONTEXT(ctx); struct gl_program *prog; - unsigned i; + GLint i; ASSERT_OUTSIDE_BEGIN_END(ctx); FLUSH_VERTICES(ctx, _NEW_PROGRAM); diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 8442ba3248c..d301f19090a 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -1810,7 +1810,7 @@ _mesa_print_program(const struct gl_program *prog) void _mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog) { - GLint i; + GLuint i; _mesa_printf("NumInstructions=%d\n", prog->NumInstructions); _mesa_printf("NumTemporaries=%d\n", prog->NumTemporaries); diff --git a/src/mesa/shader/slang/slang_execute.c b/src/mesa/shader/slang/slang_execute.c index e469de02075..3ffa4b88bfc 100644 --- a/src/mesa/shader/slang/slang_execute.c +++ b/src/mesa/shader/slang/slang_execute.c @@ -328,7 +328,7 @@ static GLvoid ensure_infolog_created(slang_info_log ** infolog) { if (*infolog == NULL) { - *infolog = slang_alloc_malloc(sizeof(slang_info_log)); + *infolog = (slang_info_log *) slang_alloc_malloc(sizeof(slang_info_log)); if (*infolog == NULL) return; slang_info_log_construct(*infolog); diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c index 761ab724e91..7e8ebb4477c 100644 --- a/src/mesa/swrast/s_copypix.c +++ b/src/mesa/swrast/s_copypix.c @@ -860,8 +860,8 @@ fast_copy_pixels(GLcontext *ctx, } /* clipping not supported */ - if (srcX < 0 || srcX + width > srcFb->Width || - srcY < 0 || srcY + height > srcFb->Height || + if (srcX < 0 || srcX + width > (GLint) srcFb->Width || + srcY < 0 || srcY + height > (GLint) srcFb->Height || dstX < dstFb->_Xmin || dstX + width > dstFb->_Xmax || dstY < dstFb->_Ymin || dstY + height > dstFb->_Ymax) { return GL_FALSE; diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c index cb584b5de8f..408174c990f 100644 --- a/src/mesa/swrast/s_depth.c +++ b/src/mesa/swrast/s_depth.c @@ -1289,7 +1289,7 @@ _swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb, GLint dx = -x; GLint i; for (i = 0; i < dx; i++) - depth[i] = 0.0; + depth[i] = 0; x = 0; n -= dx; depth += dx; @@ -1298,7 +1298,7 @@ _swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb, GLint dx = x + n - (GLint) rb->Width; GLint i; for (i = 0; i < dx; i++) - depth[n - i - 1] = 0.0; + depth[n - i - 1] = 0; n -= dx; } if (n <= 0) { diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index bdb25583515..d945a871aed 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -110,8 +110,9 @@ fast_draw_rgba_pixels(GLcontext *ctx, GLint x, GLint y, */ if (format == GL_RGBA && type == rbType) { - const GLubyte *src = _mesa_image_address2d(&unpack, pixels, width, - height, format, type, 0, 0); + const GLubyte *src + = (const GLubyte *) _mesa_image_address2d(&unpack, pixels, width, + height, format, type, 0, 0); const GLint srcStride = _mesa_image_row_stride(&unpack, width, format, type); if (simpleZoom) { @@ -139,8 +140,9 @@ fast_draw_rgba_pixels(GLcontext *ctx, GLint x, GLint y, } if (format == GL_RGB && type == rbType) { - const GLubyte *src = _mesa_image_address2d(&unpack, pixels, width, - height, format, type, 0, 0); + const GLubyte *src + = (const GLubyte *) _mesa_image_address2d(&unpack, pixels, width, + height, format, type, 0, 0); const GLint srcStride = _mesa_image_row_stride(&unpack, width, format, type); if (simpleZoom) { @@ -640,8 +642,10 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, /* if the span is wider than MAX_WIDTH we have to do it in chunks */ while (skipPixels < width) { const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH); - const GLubyte *source = _mesa_image_address2d(unpack, pixels, - width, height, format, type, 0, skipPixels); + const GLubyte *source + = (const GLubyte *) _mesa_image_address2d(unpack, pixels, + width, height, format, + type, 0, skipPixels); GLint row; for (row = 0; row < height; row++) { diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c index 128ce0afb33..27f4736c396 100644 --- a/src/mesa/swrast/s_readpix.c +++ b/src/mesa/swrast/s_readpix.c @@ -94,8 +94,8 @@ read_depth_pixels( GLcontext *ctx, /* clipping should have been done already */ ASSERT(x >= 0); ASSERT(y >= 0); - ASSERT(x + width <= rb->Width); - ASSERT(y + height <= rb->Height); + ASSERT(x + width <= (GLint) rb->Width); + ASSERT(y + height <= (GLint) rb->Height); /* width should never be > MAX_WIDTH since we did clipping earlier */ ASSERT(width <= MAX_WIDTH); @@ -210,8 +210,8 @@ fast_read_rgba_pixels( GLcontext *ctx, ASSERT(rb->_BaseFormat == GL_RGBA || rb->_BaseFormat == GL_RGB); /* clipping should have already been done */ - ASSERT(x + width <= rb->Width); - ASSERT(y + height <= rb->Height); + ASSERT(x + width <= (GLint) rb->Width); + ASSERT(y + height <= (GLint) rb->Height); /* check for things we can't handle here */ if (transferOps || @@ -223,8 +223,9 @@ fast_read_rgba_pixels( GLcontext *ctx, if (format == GL_RGBA && rb->DataType == type) { const GLint dstStride = _mesa_image_row_stride(packing, width, format, type); - GLubyte *dest = _mesa_image_address2d(packing, pixels, width, height, - format, type, 0, 0); + GLubyte *dest + = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height, + format, type, 0, 0); GLint row; ASSERT(rb->GetRow); for (row = 0; row < height; row++) { @@ -239,8 +240,9 @@ fast_read_rgba_pixels( GLcontext *ctx, type == GL_UNSIGNED_BYTE) { const GLint dstStride = _mesa_image_row_stride(packing, width, format, type); - GLubyte *dest = _mesa_image_address2d(packing, pixels, width, height, - format, type, 0, 0); + GLubyte *dest + = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height, + format, type, 0, 0); GLint row; ASSERT(rb->GetRow); for (row = 0; row < height; row++) { @@ -396,8 +398,9 @@ read_rgba_pixels( GLcontext *ctx, = _mesa_image_row_stride(packing, width, format, type); GLfloat (*rgba)[4] = swrast->SpanArrays->color.sz4.rgba; GLint row; - GLubyte *dst = _mesa_image_address2d(packing, pixels, width, height, - format, type, 0, 0); + GLubyte *dst + = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height, + format, type, 0, 0); for (row = 0; row < height; row++, y++) { diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index c74b98facfb..cca1864ea41 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -1814,7 +1814,9 @@ _swrast_get_values(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint i, inCount = 0, inStart = 0; for (i = 0; i < count; i++) { - if (x[i] >= 0 && y[i] >= 0 && x[i] < rb->Width && y[i] < rb->Height) { + if (x[i] >= 0 && y[i] >= 0 && + x[i] < (GLint) rb->Width && + y[i] < (GLint) rb->Height) { /* inside */ if (inCount == 0) inStart = i; @@ -1848,10 +1850,10 @@ _swrast_put_row(GLcontext *ctx, struct gl_renderbuffer *rb, { GLint skip = 0; - if (y < 0 || y >= rb->Height) + if (y < 0 || (GLint) y >= rb->Height) return; /* above or below */ - if (x + (GLint) count <= 0 || x >= rb->Width) + if (x + (GLint) count <= 0 || x >= (GLint) rb->Width) return; /* entirely left or right */ if (x + count > rb->Width) { diff --git a/src/mesa/tnl/t_array_api.c b/src/mesa/tnl/t_array_api.c index 6826cf7e24c..087f6af08cb 100644 --- a/src/mesa/tnl/t_array_api.c +++ b/src/mesa/tnl/t_array_api.c @@ -298,7 +298,7 @@ _tnl_DrawRangeElements(GLenum mode, #ifdef DEBUG /* check that array indices really fall inside [start, end] range */ { - GLuint i; + GLint i; for (i = 0; i < count; i++) { if (ui_indices[i] < start || ui_indices[i] > end) { _mesa_warning(ctx, "Invalid array index in " diff --git a/src/mesa/tnl/t_vb_arbprogram.c b/src/mesa/tnl/t_vb_arbprogram.c index bf4c1d52237..524472a7772 100644 --- a/src/mesa/tnl/t_vb_arbprogram.c +++ b/src/mesa/tnl/t_vb_arbprogram.c @@ -1056,7 +1056,7 @@ static void compile_vertex_program( struct gl_vertex_program *program, { struct compilation cp; struct tnl_compiled_program *p = CALLOC_STRUCT(tnl_compiled_program); - GLuint i; + GLint i; if (program->TnlData) free_tnl_data( program ); @@ -1290,6 +1290,7 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage) call_func( p, m ); } else { + GLint j; for (j = 0; j < p->nr_instructions; j++) { union instruction inst = p->instructions[j]; opcode_func[inst.alu.opcode]( m, inst ); -- cgit v1.2.3 From 54dac2c84310536cce962101de29546d3eb80175 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Fri, 9 Feb 2007 00:36:40 +0100 Subject: optimize generated vertex programs a bit Use new internal state to avoid per-vertex normalization of static spot direction vector. Use internal state for simpler per-vertex fog computations (MAD instead of SUB/MUL for linear fog, EX2 instead of POW for EXP/EXP2 fog). Simplify point size calc (2 MADs instead of MOV, MUL, MUL, DP3), and while there fix it up (RSQ instead of RCP). All untested... --- src/mesa/main/imports.h | 8 ++++++ src/mesa/shader/arbprogparse.c | 2 +- src/mesa/shader/program.c | 30 +++++++++++++++++++++ src/mesa/shader/program.h | 2 ++ src/mesa/tnl/t_vp_build.c | 61 +++++++++++++++++++++--------------------- 5 files changed, 71 insertions(+), 32 deletions(-) (limited to 'src/mesa/shader') diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index d9885dbeec4..0633b3b8bf7 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -138,6 +138,14 @@ typedef union { GLfloat f; GLint i; } fi_type; #define M_E (2.7182818284590452354) #endif +#ifndef ONE_DIV_LN2 +#define ONE_DIV_LN2 (1.442695040888963456) +#endif + +#ifndef ONE_DIV_SQRT_LN2 +#define ONE_DIV_SQRT_LN2 (1.201122408786449815) +#endif + #ifndef FLT_MAX_EXP #define FLT_MAX_EXP 128 #endif diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index 72d49093721..b9ff08de5fc 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -4101,7 +4101,7 @@ _mesa_parse_arb_vertex_program(GLcontext *ctx, GLenum target, program->Base.Parameters = ap.Base.Parameters; #if DEBUG_VP - _mesa_printf("____________Vertex program %u __________\n", program->Base.ID); + _mesa_printf("____________Vertex program %u __________\n", program->Base.Id); _mesa_print_program(&program->Base); #endif } diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index d301f19090a..7e6cd26c55e 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -996,6 +996,30 @@ _mesa_fetch_state(GLcontext *ctx, const enum state_index state[], } break; } + case STATE_FOG_PARAMS_OPTIMIZED: + /* this makes it possible to use simpler per-vertex fog calcs. POW + (for EXP/EXP2 fog) might be more expensive than EX2 on some hw, + plus it needs another constant (e) anyway. Linear fog can now be + done with a single MAD. + linear: fogcoord * -1/(end-start) + end/(end-start) + exp: 2^-(density/ln(2) * fogcoord) + exp2: 2^-((density/(ln(2)^2) * fogcoord)^2) */ + value[0] = -1.0F / (ctx->Fog.End - ctx->Fog.Start); + value[1] = ctx->Fog.End / (ctx->Fog.End - ctx->Fog.Start); + value[2] = ctx->Fog.Density * ONE_DIV_LN2; + value[3] = ctx->Fog.Density * ONE_DIV_SQRT_LN2; + break; + case STATE_SPOT_DIR_NORMALIZED: { + /* here, state[2] is the light number */ + /* pre-normalize spot dir */ + const GLuint ln = (GLuint) state[2]; + value[0] = ctx->Light.Light[ln].EyeDirection[0]; + value[1] = ctx->Light.Light[ln].EyeDirection[1]; + value[2] = ctx->Light.Light[ln].EyeDirection[2]; + NORMALIZE_3FV(value); + value[3] = ctx->Light.Light[ln]._CosCutoff; + break; + } default: /* unknown state indexes are silently ignored * should be handled by the driver. @@ -1075,6 +1099,10 @@ make_state_flags(const GLint state[]) return _NEW_MODELVIEW; case STATE_TEXRECT_SCALE: return _NEW_TEXTURE; + case STATE_FOG_PARAMS_OPTIMIZED: + return _NEW_FOG; + case STATE_SPOT_DIR_NORMALIZED: + return _NEW_LIGHT; default: /* unknown state indexes are silently ignored and * no flag set, since it is handled by the driver. @@ -1232,6 +1260,8 @@ append_token(char *dst, enum state_index k) case STATE_INTERNAL: case STATE_NORMAL_SCALE: case STATE_POSITION_NORMALIZED: + case STATE_FOG_PARAMS_OPTIMIZED: + case STATE_SPOT_DIR_NORMALIZED: append(dst, "(internal)"); break; default: diff --git a/src/mesa/shader/program.h b/src/mesa/shader/program.h index af06c03598f..a0bde077629 100644 --- a/src/mesa/shader/program.h +++ b/src/mesa/shader/program.h @@ -190,6 +190,8 @@ enum state_index { STATE_NORMAL_SCALE, STATE_TEXRECT_SCALE, STATE_POSITION_NORMALIZED, /* normalized light position */ + STATE_FOG_PARAMS_OPTIMIZED, /* for faster fog calc */ + STATE_SPOT_DIR_NORMALIZED, /* pre-normalized spot dir */ STATE_INTERNAL_DRIVER /* first available state index for drivers (must be last) */ }; diff --git a/src/mesa/tnl/t_vp_build.c b/src/mesa/tnl/t_vp_build.c index 805d05ae728..0b6f506f4e5 100644 --- a/src/mesa/tnl/t_vp_build.c +++ b/src/mesa/tnl/t_vp_build.c @@ -806,14 +806,13 @@ static struct ureg calculate_light_attenuation( struct tnl_program *p, /* Calculate spot attenuation: */ if (!p->state->unit[i].light_spotcutoff_is_180) { - struct ureg spot_dir = register_param3(p, STATE_LIGHT, i, - STATE_SPOT_DIRECTION); + struct ureg spot_dir_norm = register_param3(p, STATE_INTERNAL, + STATE_SPOT_DIR_NORMALIZED, i); struct ureg spot = get_temp(p); struct ureg slt = get_temp(p); - - emit_normalize_vec3( p, spot, spot_dir ); /* XXX: precompute! */ - emit_op2(p, OPCODE_DP3, spot, 0, negate(VPpli), spot); - emit_op2(p, OPCODE_SLT, slt, 0, swizzle1(spot_dir,W), spot); + + emit_op2(p, OPCODE_DP3, spot, 0, negate(VPpli), spot_dir_norm); + emit_op2(p, OPCODE_SLT, slt, 0, swizzle1(spot_dir_norm,W), spot); emit_op2(p, OPCODE_POW, spot, 0, spot, swizzle1(attenuation, W)); emit_op2(p, OPCODE_MUL, att, 0, slt, spot); @@ -1103,29 +1102,26 @@ static void build_fog( struct tnl_program *p ) } if (p->state->tnl_do_vertex_fog) { - struct ureg params = register_param1(p, STATE_FOG_PARAMS); + struct ureg params = register_param1(p, STATE_FOG_PARAMS_OPTIMIZED); struct ureg tmp = get_temp(p); switch (p->state->fog_mode) { case FOG_LINEAR: { struct ureg id = get_identity_param(p); - emit_op2(p, OPCODE_SUB, tmp, 0, swizzle1(params,Z), input); - emit_op2(p, OPCODE_MUL, tmp, 0, tmp, swizzle1(params,W)); + emit_op3(p, OPCODE_MAD, tmp, 0, input, swizzle1(params,X), swizzle1(params,Y)); emit_op2(p, OPCODE_MAX, tmp, 0, tmp, swizzle1(id,X)); /* saturate */ emit_op2(p, OPCODE_MIN, fog, WRITEMASK_X, tmp, swizzle1(id,W)); break; } case FOG_EXP: emit_op1(p, OPCODE_ABS, tmp, 0, input); - emit_op2(p, OPCODE_MUL, tmp, 0, tmp, swizzle1(params,X)); - emit_op2(p, OPCODE_POW, fog, WRITEMASK_X, - register_const1f(p, M_E), negate(tmp)); + emit_op2(p, OPCODE_MUL, tmp, 0, tmp, swizzle1(params,Z)); + emit_op1(p, OPCODE_EX2, fog, WRITEMASK_X, negate(tmp)); break; case FOG_EXP2: - emit_op2(p, OPCODE_MUL, tmp, 0, input, swizzle1(params,X)); + emit_op2(p, OPCODE_MUL, tmp, 0, input, swizzle1(params,W)); emit_op2(p, OPCODE_MUL, tmp, 0, tmp, tmp); - emit_op2(p, OPCODE_POW, fog, WRITEMASK_X, - register_const1f(p, M_E), negate(tmp)); + emit_op1(p, OPCODE_EX2, fog, WRITEMASK_X, negate(tmp)); break; } @@ -1317,8 +1313,6 @@ static void build_texture_transform( struct tnl_program *p ) } -/* Seems like it could be tighter: - */ static void build_pointsize( struct tnl_program *p ) { struct ureg eye = get_eye_position(p); @@ -1327,20 +1321,25 @@ static void build_pointsize( struct tnl_program *p ) struct ureg out = register_output(p, VERT_RESULT_PSIZ); struct ureg ut = get_temp(p); - /* 1, -Z, Z * Z, 1 */ - emit_op1(p, OPCODE_MOV, ut, 0, swizzle1(get_identity_param(p), W)); - emit_op2(p, OPCODE_MUL, ut, WRITEMASK_YZ, ut, negate(swizzle1(eye, Z))); - emit_op2(p, OPCODE_MUL, ut, WRITEMASK_Z, ut, negate(swizzle1(eye, Z))); - - - /* p1 + p2 * dist + p3 * dist * dist, 0 */ - emit_op2(p, OPCODE_DP3, ut, 0, ut, state_attenuation); - - /* 1 / factor */ - emit_op1(p, OPCODE_RCP, ut, 0, ut ); - - /* out = pointSize / factor */ - emit_op2(p, OPCODE_MUL, out, WRITEMASK_X, ut, state_size); + /* p1 + dist * (p2 + dist * p3); */ + emit_op3(p, OPCODE_MAD, ut, 0, negate(swizzle1(eye, Z)), + swizzle1(state_attenuation, Z), swizzle1(state_attenuation, Y)); + emit_op3(p, OPCODE_MAD, ut, 0, negate(swizzle1(eye, Z)), + ut, swizzle1(state_attenuation, X)); + + /* 1 / sqrt(factor) */ + emit_op1(p, OPCODE_RSQ, ut, 0, ut ); + +#if 1 + /* out = pointSize / sqrt(factor) */ + emit_op2(p, OPCODE_MUL, out, WRITEMASK_X, ut, state_size); +#else + /* not sure, might make sense to do clamping here, + but it's not done in t_vb_points neither */ + emit_op2(p, OPCODE_MUL, ut, 0, ut, state_size); + emit_op2(p, OPCODE_MAX, ut, 0, ut, swizzle1(state_size, Y)); + emit_op2(p, OPCODE_MIN, out, WRITEMASK_X, ut, swizzle1(state_size, Z)); +#endif release_temp(p, ut); } -- cgit v1.2.3 From b2d30ca0cb01a80ff440a4a07b293daa16486e12 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Fri, 9 Feb 2007 19:21:29 +0100 Subject: optimize per-pixel fog program use the same internal state as for vertex fog. From the old implemenentation, this changes a SUB+MUL into a MAD for linear fog, and saves a MUL for EXP/EXP2, plus saves a (constant) parameter. While here, fix the broken (forgotten) swizzling. (untested) --- src/mesa/shader/program.c | 2 +- src/mesa/shader/programopt.c | 79 +++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 50 deletions(-) (limited to 'src/mesa/shader') diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 7e6cd26c55e..490f9194457 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -997,7 +997,7 @@ _mesa_fetch_state(GLcontext *ctx, const enum state_index state[], break; } case STATE_FOG_PARAMS_OPTIMIZED: - /* this makes it possible to use simpler per-vertex fog calcs. POW + /* for simpler per-vertex/pixel fog calcs. POW (for EXP/EXP2 fog) might be more expensive than EX2 on some hw, plus it needs another constant (e) anyway. Linear fog can now be done with a single MAD. diff --git a/src/mesa/shader/programopt.c b/src/mesa/shader/programopt.c index 783177739d1..dca44c853d8 100644 --- a/src/mesa/shader/programopt.c +++ b/src/mesa/shader/programopt.c @@ -126,16 +126,15 @@ _mesa_insert_mvp_code(GLcontext *ctx, struct gl_vertex_program *vprog) void _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog) { - static const GLint fogParamsState[] = { STATE_FOG_PARAMS, 0, 0, 0, 0 }; + static const GLint fogPStateOpt[] = { STATE_INTERNAL, + STATE_FOG_PARAMS_OPTIMIZED, 0, 0, 0 }; static const GLint fogColorState[] = { STATE_FOG_COLOR, 0, 0, 0, 0 }; struct prog_instruction *newInst, *inst; const GLuint origLen = fprog->Base.NumInstructions; - const GLuint newLen = origLen + 6; + const GLuint newLen = origLen + 5; GLuint i; - GLint fogParamsRef, fogColorRef; /* state references */ + GLint fogPRefOpt, fogColorRef; /* state references */ GLuint colorTemp, fogFactorTemp; /* temporary registerss */ - GLfloat fogVals[4]; - GLuint fogConsts; /* constant values for EXP, EXP2 mode */ if (fprog->FogOption == GL_NONE) { _mesa_problem(ctx, "_mesa_append_fog_code() called for fragment program" @@ -155,9 +154,9 @@ _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog) _mesa_memcpy(newInst, fprog->Base.Instructions, origLen * sizeof(struct prog_instruction)); - /* PARAM fogParamsRef = state.fog.params; */ - fogParamsRef - = _mesa_add_state_reference(fprog->Base.Parameters, fogParamsState); + /* PARAM fogParamsRefOpt = internal optimized fog params; */ + fogPRefOpt + = _mesa_add_state_reference(fprog->Base.Parameters, fogPStateOpt); /* PARAM fogColorRef = state.fog.color; */ fogColorRef = _mesa_add_state_reference(fprog->Base.Parameters, fogColorState); @@ -167,13 +166,6 @@ _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog) /* TEMP fogFactorTemp; */ fogFactorTemp = fprog->Base.NumTemporaries++; - /* PARAM fogVals = { 1/ln(2), 1/sqrt(ln(2), 0, 0 }; */ - fogVals[0] = 1.0 / log(2.0); - fogVals[1] = 1.0 / SQRTF(log(2.0)); - fogVals[2] = 0.0; - fogVals[3] = 0.0; - fogConsts = _mesa_add_unnamed_constant(fprog->Base.Parameters, fogVals, 4); - /* Scan program to find where result.color is written */ inst = newInst; for (i = 0; i < fprog->Base.NumInstructions; i++) { @@ -191,43 +183,39 @@ _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog) } assert(inst->Opcode == OPCODE_END); /* we'll overwrite this inst */ - _mesa_init_instructions(inst, 6); + _mesa_init_instructions(inst, 5); /* emit instructions to compute fog blending factor */ if (fprog->FogOption == GL_LINEAR) { - /* SUB fogFactorTemp.x, fogParamsRef.z, fragment.fogcoord.x; */ - inst->Opcode = OPCODE_SUB; - inst->DstReg.File = PROGRAM_TEMPORARY; - inst->DstReg.Index = fogFactorTemp; - inst->DstReg.WriteMask = WRITEMASK_X; - inst->SrcReg[0].File = PROGRAM_STATE_VAR; - inst->SrcReg[0].Index = fogParamsRef; - inst->SrcReg[0].Swizzle = SWIZZLE_Z; - inst->SrcReg[1].File = PROGRAM_INPUT; - inst->SrcReg[1].Index = FRAG_ATTRIB_FOGC; - inst++; - /* MUL fogFactorTemp.x, fogFactorTemp, fogParamsRef.w; */ - inst->Opcode = OPCODE_MUL; + /* MAD fogFactorTemp.x, fragment.fogcoord.x, fogPRefOpt.x, fogPRefOpt.y; */ + inst->Opcode = OPCODE_MAD; inst->DstReg.File = PROGRAM_TEMPORARY; inst->DstReg.Index = fogFactorTemp; inst->DstReg.WriteMask = WRITEMASK_X; - inst->SrcReg[0].File = PROGRAM_TEMPORARY; - inst->SrcReg[0].Index = fogFactorTemp; + inst->SrcReg[0].File = PROGRAM_INPUT; + inst->SrcReg[0].Index = FRAG_ATTRIB_FOGC; + inst->SrcReg[0].Swizzle = SWIZZLE_X; inst->SrcReg[1].File = PROGRAM_STATE_VAR; - inst->SrcReg[1].Index = fogParamsRef; - inst->SrcReg[1].Swizzle = SWIZZLE_W; + inst->SrcReg[1].Index = fogPRefOpt; + inst->SrcReg[1].Swizzle = SWIZZLE_X; + inst->SrcReg[2].File = PROGRAM_STATE_VAR; + inst->SrcReg[2].Index = fogPRefOpt; + inst->SrcReg[2].Swizzle = SWIZZLE_Y; inst++; } else { ASSERT(fprog->FogOption == GL_EXP || fprog->FogOption == GL_EXP2); - /* MUL fogFactorTemp.x, fogParamsRef.x, fragment.fogcoord; */ + /* fogPRefOpt.z = d/ln(2), fogPRefOpt.w = d/sqrt(ln(2) */ + /* EXP: MUL fogFactorTemp.x, fogPRefOpt.z, fragment.fogcoord.x; */ + /* EXP2: MUL fogFactorTemp.x, fogPRefOpt.w, fragment.fogcoord.x; */ inst->Opcode = OPCODE_MUL; inst->DstReg.File = PROGRAM_TEMPORARY; inst->DstReg.Index = fogFactorTemp; inst->DstReg.WriteMask = WRITEMASK_X; inst->SrcReg[0].File = PROGRAM_STATE_VAR; - inst->SrcReg[0].Index = fogParamsRef; - inst->SrcReg[0].Swizzle = SWIZZLE_X; /* X=density */ + inst->SrcReg[0].Index = fogPRefOpt; + inst->SrcReg[0].Swizzle + = (fprog->FogOption == GL_EXP) ? SWIZZLE_Z : SWIZZLE_W; inst->SrcReg[1].File = PROGRAM_INPUT; inst->SrcReg[1].Index = FRAG_ATTRIB_FOGC; inst->SrcReg[1].Swizzle = SWIZZLE_X; @@ -240,23 +228,12 @@ _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog) inst->DstReg.WriteMask = WRITEMASK_X; inst->SrcReg[0].File = PROGRAM_TEMPORARY; inst->SrcReg[0].Index = fogFactorTemp; + inst->SrcReg[0].Swizzle = SWIZZLE_X; inst->SrcReg[1].File = PROGRAM_TEMPORARY; inst->SrcReg[1].Index = fogFactorTemp; + inst->SrcReg[1].Swizzle = SWIZZLE_X; inst++; } - /* EXP: MUL fogFactorTemp.x, fogFactorTemp.x, {1/ln(2)}; */ - /* EXP2: MUL fogFactorTemp.x, fogFactorTemp.x, {1/sqrt(ln(2))}; */ - inst->Opcode = OPCODE_MUL; - inst->DstReg.File = PROGRAM_TEMPORARY; - inst->DstReg.Index = fogFactorTemp; - inst->DstReg.WriteMask = WRITEMASK_X; - inst->SrcReg[0].File = PROGRAM_TEMPORARY; - inst->SrcReg[0].Index = fogFactorTemp; - inst->SrcReg[1].File = PROGRAM_CONSTANT; - inst->SrcReg[1].Index = fogConsts; - inst->SrcReg[1].Swizzle - = (fprog->FogOption == GL_EXP) ? SWIZZLE_X : SWIZZLE_Y; - inst++; /* EX2_SAT fogFactorTemp.x, -fogFactorTemp.x; */ inst->Opcode = OPCODE_EX2; inst->DstReg.File = PROGRAM_TEMPORARY; @@ -265,6 +242,7 @@ _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog) inst->SrcReg[0].File = PROGRAM_TEMPORARY; inst->SrcReg[0].Index = fogFactorTemp; inst->SrcReg[0].NegateBase = GL_TRUE; + inst->SrcReg[0].Swizzle = SWIZZLE_X; inst->SaturateMode = SATURATE_ZERO_ONE; inst++; } @@ -279,8 +257,10 @@ _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog) = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X); inst->SrcReg[1].File = PROGRAM_TEMPORARY; inst->SrcReg[1].Index = colorTemp; + inst->SrcReg[1].Swizzle = SWIZZLE_NOOP; inst->SrcReg[2].File = PROGRAM_STATE_VAR; inst->SrcReg[2].Index = fogColorRef; + inst->SrcReg[2].Swizzle = SWIZZLE_NOOP; inst++; /* MOV result.color.w, colorTemp.x; # copy alpha */ inst->Opcode = OPCODE_MOV; @@ -289,6 +269,7 @@ _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog) inst->DstReg.WriteMask = WRITEMASK_W; inst->SrcReg[0].File = PROGRAM_TEMPORARY; inst->SrcReg[0].Index = colorTemp; + inst->SrcReg[0].Swizzle = SWIZZLE_NOOP; inst++; /* END; */ inst->Opcode = OPCODE_END; -- cgit v1.2.3