From 8b5fce6bcc88cd9dd321f0db95c1714e5e5e85a1 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 19 Apr 2007 14:24:10 -0600 Subject: Put gl_program_machine into swrast structure rather than using a local variable. Basically an easy way to make sure the memory gets initialized once (to zero) to avoid lots of valgrind warnings. --- src/mesa/swrast/s_fragprog.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/mesa/swrast/s_fragprog.c') diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index 7f7c0d6db52..1b5f20d42d6 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -25,7 +25,6 @@ #include "glheader.h" #include "colormac.h" #include "context.h" -#include "prog_execute.h" #include "prog_instruction.h" #include "s_fragprog.h" @@ -105,7 +104,7 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine, if (ctx->FragmentProgram.CallbackEnabled) inputsRead = ~0; - if (program->Base.Target == GL_FRAGMENT_PROGRAM_NV) { + if (1/*program->Base.Target == GL_FRAGMENT_PROGRAM_NV*/) { /* Clear temporary registers (undefined for ARB_f_p) */ _mesa_bzero(machine->Temporaries, MAX_PROGRAM_TEMPS * 4 * sizeof(GLfloat)); @@ -142,19 +141,19 @@ run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end) SWcontext *swrast = SWRAST_CONTEXT(ctx); const struct gl_fragment_program *program = ctx->FragmentProgram._Current; const GLbitfield outputsWritten = program->Base.OutputsWritten; - struct gl_program_machine machine; + struct gl_program_machine *machine = &swrast->FragProgMachine; GLuint i; for (i = start; i < end; i++) { if (span->array->mask[i]) { - init_machine(ctx, &machine, program, span, i); + init_machine(ctx, machine, program, span, i); - if (_mesa_execute_program(ctx, &program->Base, &machine)) { + if (_mesa_execute_program(ctx, &program->Base, machine)) { /* Store result color */ if (outputsWritten & (1 << FRAG_RESULT_COLR)) { COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0][i], - machine.Outputs[FRAG_RESULT_COLR]); + machine->Outputs[FRAG_RESULT_COLR]); } else { /* Multiple drawbuffers / render targets @@ -165,14 +164,14 @@ run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end) for (output = 0; output < swrast->_NumColorOutputs; output++) { if (outputsWritten & (1 << (FRAG_RESULT_DATA0 + output))) { COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0+output][i], - machine.Outputs[FRAG_RESULT_DATA0 + output]); + machine->Outputs[FRAG_RESULT_DATA0 + output]); } } } /* Store result depth/z */ if (outputsWritten & (1 << FRAG_RESULT_DEPR)) { - const GLfloat depth = machine.Outputs[FRAG_RESULT_DEPR][2]; + const GLfloat depth = machine->Outputs[FRAG_RESULT_DEPR][2]; if (depth <= 0.0) span->array->z[i] = 0; else if (depth >= 1.0) -- cgit v1.2.3 From ced6f76404ff1a6713c85edff17551f82c33cc24 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 20 Apr 2007 08:21:49 -0600 Subject: undo a test/debug change --- src/mesa/swrast/s_fragprog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/swrast/s_fragprog.c') diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index 1b5f20d42d6..882fec29efe 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -104,7 +104,7 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine, if (ctx->FragmentProgram.CallbackEnabled) inputsRead = ~0; - if (1/*program->Base.Target == GL_FRAGMENT_PROGRAM_NV*/) { + if (program->Base.Target == GL_FRAGMENT_PROGRAM_NV) { /* Clear temporary registers (undefined for ARB_f_p) */ _mesa_bzero(machine->Temporaries, MAX_PROGRAM_TEMPS * 4 * sizeof(GLfloat)); -- cgit v1.2.3 From af0ae93863b4c876e70efa4e7406f04a3409f135 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 28 Apr 2007 08:51:23 -0600 Subject: only load front/back face attrib if using a shader (bug 10788) --- src/mesa/swrast/s_fragprog.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/mesa/swrast/s_fragprog.c') diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index 882fec29efe..09493873aa2 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -113,8 +113,10 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine, /* Setup pointer to input attributes */ machine->Attribs = span->array->attribs; - /* Store front/back facing value in register FOGC.Y */ - machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = (GLfloat) ctx->_Facing; + if (ctx->Shader.CurrentProgram) { + /* Store front/back facing value in register FOGC.Y */ + machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = (GLfloat) ctx->_Facing; + } machine->CurElement = col; -- cgit v1.2.3 From 60d136f63c5a5a18b12952ec8e8532cbce086a4d Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 2 May 2007 18:45:44 -0600 Subject: changes to get DDX/DDY working again --- src/mesa/swrast/s_fragprog.c | 4 ++++ src/mesa/swrast/s_span.c | 4 ++++ src/mesa/tnl/t_vb_program.c | 2 ++ 3 files changed, 10 insertions(+) (limited to 'src/mesa/swrast/s_fragprog.c') diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index 09493873aa2..b1501221cad 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -113,6 +113,10 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine, /* Setup pointer to input attributes */ machine->Attribs = span->array->attribs; + machine->DerivX = (GLfloat (*)[4]) span->attrStepX; + machine->DerivY = (GLfloat (*)[4]) span->attrStepY; + machine->NumDeriv = FRAG_ATTRIB_MAX; + if (ctx->Shader.CurrentProgram) { /* Store front/back facing value in register FOGC.Y */ machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = (GLfloat) ctx->_Facing; diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index 0b17791567a..097d2c7b51c 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -1357,7 +1357,11 @@ shade_texture_span(GLcontext *ctx, SWspan *span) if ((inputsRead >= FRAG_BIT_VAR0) && (span->interpMask & SPAN_VARYING)) interpolate_varying(ctx, span); +#if 0 if (inputsRead & FRAG_BIT_WPOS) +#else + /* XXX always interpolate wpos so that DDX/DDY work */ +#endif interpolate_wpos(ctx, span); /* Run fragment program/shader now */ diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c index 81e166bde50..9961af70ce7 100644 --- a/src/mesa/tnl/t_vb_program.c +++ b/src/mesa/tnl/t_vb_program.c @@ -126,6 +126,8 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine) } } + machine->NumDeriv = 0; + /* init condition codes */ machine->CondCodes[0] = COND_EQ; machine->CondCodes[1] = COND_EQ; -- cgit v1.2.3 From eab6e1652271f46361f95e21e9e5afcb5ffa37d7 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 11 May 2007 15:12:40 -0600 Subject: remove some unneeded code in init_machine() --- src/mesa/swrast/s_fragprog.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/mesa/swrast/s_fragprog.c') diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index b1501221cad..e47dbbdaf35 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -99,11 +99,6 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine, const struct gl_fragment_program *program, const SWspan *span, GLuint col) { - GLuint inputsRead = program->Base.InputsRead; - - if (ctx->FragmentProgram.CallbackEnabled) - inputsRead = ~0; - if (program->Base.Target == GL_FRAGMENT_PROGRAM_NV) { /* Clear temporary registers (undefined for ARB_f_p) */ _mesa_bzero(machine->Temporaries, -- cgit v1.2.3 From 84d1b24647c0719551e8bcd5fa4601fbd3b1d555 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 7 Jun 2007 13:38:06 -0700 Subject: Fix ARB_fp spec conformance bug WRT shadow sampling. The ARB_fp (and other assembly-level fragment program specs) say that the depth comparison function is always GL_NONE in fragment program mode. --- src/mesa/main/mtypes.h | 4 ++++ src/mesa/main/texstate.c | 35 +++++++++++++++++++++++++++++++++++ src/mesa/main/texstate.h | 4 ++++ src/mesa/swrast/s_fragprog.c | 16 ++++++++++++++++ src/mesa/swrast/s_texfilter.c | 20 +------------------- 5 files changed, 60 insertions(+), 19 deletions(-) (limited to 'src/mesa/swrast/s_fragprog.c') diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 7397199a11c..6cbbf145a19 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1426,6 +1426,10 @@ struct gl_texture_object GLfloat ShadowAmbient; /**< GL_ARB_shadow_ambient */ GLenum CompareMode; /**< GL_ARB_shadow */ GLenum CompareFunc; /**< GL_ARB_shadow */ + GLenum _Function; /**< Comparison function derrived from + * \c CompareOperator, \c CompareMode, and + * \c CompareFunc. + */ GLenum DepthMode; /**< GL_ARB_depth_texture */ GLint _MaxLevel; /**< actual max mipmap level (q in the spec) */ GLfloat _MaxLambda; /**< = _MaxLevel - BaseLevel (q - b in spec) */ diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index d15af22b7db..fb024437798 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -1178,6 +1178,36 @@ _mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param ) } +/** + * Update derrived compare function state. + */ +void +_mesa_update_texture_compare_function(struct gl_texture_object *tObj, + GLboolean in_frag_prog) +{ + if (in_frag_prog) { + tObj->_Function = GL_NONE; + } + else if (tObj->CompareFlag) { + /* GL_SGIX_shadow */ + if (tObj->CompareOperator == GL_TEXTURE_LEQUAL_R_SGIX) { + tObj->_Function = GL_LEQUAL; + } + else { + ASSERT(tObj->CompareOperator == GL_TEXTURE_GEQUAL_R_SGIX); + tObj->_Function = GL_GEQUAL; + } + } + else if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) { + /* GL_ARB_shadow */ + tObj->_Function = tObj->CompareFunc; + } + else { + tObj->_Function = GL_NONE; /* pass depth through as grayscale */ + } +} + + void GLAPIENTRY _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) { @@ -1385,6 +1415,7 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) if (ctx->Extensions.SGIX_shadow) { FLUSH_VERTICES(ctx, _NEW_TEXTURE); texObj->CompareFlag = params[0] ? GL_TRUE : GL_FALSE; + _mesa_update_texture_compare_function(texObj, GL_FALSE); } else { _mesa_error(ctx, GL_INVALID_ENUM, @@ -1399,6 +1430,7 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) op == GL_TEXTURE_GEQUAL_R_SGIX) { FLUSH_VERTICES(ctx, _NEW_TEXTURE); texObj->CompareOperator = op; + _mesa_update_texture_compare_function(texObj, GL_FALSE); } else { _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param)"); @@ -1437,6 +1469,7 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) if (mode == GL_NONE || mode == GL_COMPARE_R_TO_TEXTURE_ARB) { FLUSH_VERTICES(ctx, _NEW_TEXTURE); texObj->CompareMode = mode; + _mesa_update_texture_compare_function(texObj, GL_FALSE); } else { _mesa_error(ctx, GL_INVALID_ENUM, @@ -1472,6 +1505,8 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)"); return; } + + _mesa_update_texture_compare_function(texObj, GL_FALSE); } else { _mesa_error(ctx, GL_INVALID_ENUM, diff --git a/src/mesa/main/texstate.h b/src/mesa/main/texstate.h index ca29c6a23ff..df468ecf9bd 100644 --- a/src/mesa/main/texstate.h +++ b/src/mesa/main/texstate.h @@ -41,6 +41,10 @@ _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst ); extern void _mesa_print_texunit_state( GLcontext *ctx, GLuint unit ); +extern void +_mesa_update_texture_compare_function(struct gl_texture_object *tObj, + GLboolean in_frag_prog); + /** * \name Called from API diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index e47dbbdaf35..f5ffe41fc19 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -26,6 +26,7 @@ #include "colormac.h" #include "context.h" #include "prog_instruction.h" +#include "texstate.h" #include "s_fragprog.h" #include "s_span.h" @@ -199,6 +200,7 @@ void _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span ) { const struct gl_fragment_program *program = ctx->FragmentProgram._Current; + GLuint i; /* incoming colors should be floats */ if (program->Base.InputsRead & FRAG_BIT_COL0) { @@ -207,8 +209,22 @@ _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span ) ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */ + for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { + if (ctx->Texture.Unit[i]._Current != NULL) { + _mesa_update_texture_compare_function(ctx->Texture.Unit[i]._Current, + GL_TRUE); + } + } + run_program(ctx, span, 0, span->end); + for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { + if (ctx->Texture.Unit[i]._Current != NULL) { + _mesa_update_texture_compare_function(ctx->Texture.Unit[i]._Current, + GL_FALSE); + } + } + if (program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR)) { span->interpMask &= ~SPAN_RGBA; span->arrayMask |= SPAN_RGBA; diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c index 2c8e443daf9..d4516f6faa8 100644 --- a/src/mesa/swrast/s_texfilter.c +++ b/src/mesa/swrast/s_texfilter.c @@ -2893,25 +2893,7 @@ sample_depth_texture( GLcontext *ctx, /* XXXX if tObj->MinFilter != tObj->MagFilter, we're ignoring lambda */ - /* XXX this could be precomputed and saved in the texture object */ - if (tObj->CompareFlag) { - /* GL_SGIX_shadow */ - if (tObj->CompareOperator == GL_TEXTURE_LEQUAL_R_SGIX) { - function = GL_LEQUAL; - } - else { - ASSERT(tObj->CompareOperator == GL_TEXTURE_GEQUAL_R_SGIX); - function = GL_GEQUAL; - } - } - else if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) { - /* GL_ARB_shadow */ - function = tObj->CompareFunc; - } - else { - function = GL_NONE; /* pass depth through as grayscale */ - } - + function = tObj->_Function; if (tObj->MagFilter == GL_NEAREST) { GLuint i; for (i = 0; i < n; i++) { -- cgit v1.2.3 From 7b559a91028d297b34df9ec939bd4d00fad6027c Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 7 Jun 2007 13:58:50 -0700 Subject: Add support for GL_ARB_fragment_program_shadow. --- src/mesa/main/extensions.c | 2 ++ src/mesa/main/mtypes.h | 2 ++ src/mesa/main/texstate.c | 2 ++ src/mesa/shader/arbprogparse.c | 40 +++++++++++++++++++++++++++++++++------- src/mesa/swrast/s_fragprog.c | 3 ++- 5 files changed, 41 insertions(+), 8 deletions(-) (limited to 'src/mesa/swrast/s_fragprog.c') diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index a4a6cdae366..80dce56c0c1 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -47,6 +47,7 @@ static const struct { { OFF, "GL_ARB_depth_texture", F(ARB_depth_texture) }, { OFF, "GL_ARB_draw_buffers", F(ARB_draw_buffers) }, { OFF, "GL_ARB_fragment_program", F(ARB_fragment_program) }, + { OFF, "GL_ARB_fragment_program_shadow", F(ARB_fragment_program_shadow) }, { OFF, "GL_ARB_fragment_shader", F(ARB_fragment_shader) }, { OFF, "GL_ARB_half_float_pixel", F(ARB_half_float_pixel) }, { OFF, "GL_ARB_imaging", F(ARB_imaging) }, @@ -184,6 +185,7 @@ _mesa_enable_sw_extensions(GLcontext *ctx) ctx->Extensions.ARB_draw_buffers = GL_TRUE; #if FEATURE_ARB_fragment_program ctx->Extensions.ARB_fragment_program = GL_TRUE; + ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE; #endif #if FEATURE_ARB_fragment_shader ctx->Extensions.ARB_fragment_shader = GL_TRUE; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 6cbbf145a19..49332501d27 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1903,6 +1903,7 @@ struct gl_program GLbitfield InputsRead; /**< Bitmask of which input regs are read */ GLbitfield OutputsWritten; /**< Bitmask of which output regs are written to */ GLbitfield TexturesUsed[MAX_TEXTURE_IMAGE_UNITS]; /**< TEXTURE_x_BIT bitmask */ + GLbitfield ShadowSamplers; /**< Texture units used for shadow sampling. */ /** Named parameters, constants, etc. from program text */ struct gl_program_parameter_list *Parameters; @@ -2532,6 +2533,7 @@ struct gl_extensions GLboolean ARB_depth_texture; GLboolean ARB_draw_buffers; GLboolean ARB_fragment_program; + GLboolean ARB_fragment_program_shadow; GLboolean ARB_fragment_shader; GLboolean ARB_half_float_pixel; GLboolean ARB_imaging; diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index fb024437798..18afaf4edde 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -1527,6 +1527,8 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)"); return; } + + _mesa_update_texture_compare_function(texObj, GL_FALSE); } else { _mesa_error(ctx, GL_INVALID_ENUM, diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index 9af3fd0764d..5d8f763741f 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -71,6 +71,7 @@ struct arb_program /* ARB_fragment_program specifics */ GLbitfield TexturesUsed[MAX_TEXTURE_IMAGE_UNITS]; + GLbitfield ShadowSamplers; GLuint NumAluInstructions; GLuint NumTexInstructions; GLuint NumTexIndirections; @@ -2661,6 +2662,7 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, GLuint texcoord; GLubyte instClass, type, code; GLboolean rel; + GLuint shadow_tex = 0; _mesa_init_instructions(fp, 1); @@ -2978,35 +2980,54 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, /* texTarget */ switch (*(*inst)++) { + case TEXTARGET_SHADOW1D: + shadow_tex = 1 << texcoord; + /* FALLTHROUGH */ case TEXTARGET_1D: fp->TexSrcTarget = TEXTURE_1D_INDEX; break; + case TEXTARGET_SHADOW2D: + shadow_tex = 1 << texcoord; + /* FALLTHROUGH */ case TEXTARGET_2D: fp->TexSrcTarget = TEXTURE_2D_INDEX; break; case TEXTARGET_3D: fp->TexSrcTarget = TEXTURE_3D_INDEX; break; + case TEXTARGET_SHADOWRECT: + shadow_tex = 1 << texcoord; + /* FALLTHROUGH */ case TEXTARGET_RECT: fp->TexSrcTarget = TEXTURE_RECT_INDEX; break; case TEXTARGET_CUBE: fp->TexSrcTarget = TEXTURE_CUBE_INDEX; break; - case TEXTARGET_SHADOW1D: - case TEXTARGET_SHADOW2D: case TEXTARGET_SHADOW1D_ARRAY: - case TEXTARGET_SHADOW2D_ARRAY: - case TEXTARGET_SHADOWRECT: - /* TODO ARB_fragment_program_shadow code */ - break; + shadow_tex = 1 << texcoord; + /* FALLTHROUGH */ case TEXTARGET_1D_ARRAY: fp->TexSrcTarget = TEXTURE_1D_ARRAY_INDEX; break; + case TEXTARGET_SHADOW2D_ARRAY: + shadow_tex = 1 << texcoord; + /* FALLTHROUGH */ case TEXTARGET_2D_ARRAY: fp->TexSrcTarget = TEXTURE_2D_ARRAY_INDEX; break; } + + /* Don't test the first time a particular sampler is seen. Each time + * after that, make sure the shadow state is the same. + */ + if ((_mesa_bitcount(Program->TexturesUsed[texcoord]) > 0) + && ((Program->ShadowSamplers & (1 << texcoord)) != shadow_tex)) { + program_error(ctx, Program->Position, + "texture image unit used for shadow sampling and non-shadow sampling"); + return 1; + } + Program->TexturesUsed[texcoord] |= (1 << fp->TexSrcTarget); /* Check that both "2D" and "CUBE" (for example) aren't both used */ if (_mesa_bitcount(Program->TexturesUsed[texcoord]) > 1) { @@ -3014,6 +3035,9 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, "multiple targets used on one texture image unit"); return 1; } + + + Program->ShadowSamplers |= shadow_tex; break; case OP_TEX_KIL: @@ -3604,10 +3628,10 @@ enable_parser_extensions(GLcontext *ctx, grammar id) if (ctx->Extensions.ARB_matrix_palette && !enable_ext(ctx, id, "matrix_palette")) return GL_FALSE; +#endif if (ctx->Extensions.ARB_fragment_program_shadow && !enable_ext(ctx, id, "fragment_program_shadow")) return GL_FALSE; -#endif if (ctx->Extensions.EXT_point_parameters && !enable_ext(ctx, id, "point_parameters")) return GL_FALSE; @@ -3804,6 +3828,7 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, program->HintPositionInvariant = GL_FALSE; for (a = 0; a < MAX_TEXTURE_IMAGE_UNITS; a++) program->TexturesUsed[a] = 0x0; + program->ShadowSamplers = 0x0; program->NumAluInstructions = program->NumTexInstructions = program->NumTexIndirections = 0; @@ -3884,6 +3909,7 @@ _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum target, program->Base.OutputsWritten = ap.Base.OutputsWritten; for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++) program->Base.TexturesUsed[i] = ap.TexturesUsed[i]; + program->Base.ShadowSamplers = ap.ShadowSamplers; program->FogOption = ap.FogOption; program->UsesKill = ap.UsesKill; diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index f5ffe41fc19..a36c1ba4919 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -211,8 +211,9 @@ _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span ) for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { if (ctx->Texture.Unit[i]._Current != NULL) { + const GLboolean enable_shadow = ((1 << i) & program->Base.ShadowSamplers); _mesa_update_texture_compare_function(ctx->Texture.Unit[i]._Current, - GL_TRUE); + !enable_shadow); } } -- cgit v1.2.3 From 0186f1bc8356bc3c2946d4ffcb5e6d7b61b84e02 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 11 Jun 2007 16:04:36 -0600 Subject: Temporarily disable the calls to _mesa_update_texture_compare_function(). This fixes the depth-peel regression reported by Brad King. --- src/mesa/swrast/s_fragprog.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/mesa/swrast/s_fragprog.c') diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index a36c1ba4919..1cbcde3c0ad 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -209,6 +209,7 @@ _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span ) ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */ +#if 0 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { if (ctx->Texture.Unit[i]._Current != NULL) { const GLboolean enable_shadow = ((1 << i) & program->Base.ShadowSamplers); @@ -216,15 +217,18 @@ _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span ) !enable_shadow); } } +#endif run_program(ctx, span, 0, span->end); +#if 0 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { if (ctx->Texture.Unit[i]._Current != NULL) { _mesa_update_texture_compare_function(ctx->Texture.Unit[i]._Current, GL_FALSE); } } +#endif if (program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR)) { span->interpMask &= ~SPAN_RGBA; -- cgit v1.2.3 From 0fbc4c51a07a5980956d62b3f70c46c65f6c7a57 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 11 Jun 2007 17:16:18 -0600 Subject: Rework _mesa_update_texture_compare_function() to only be called during state validation/update. Note that we're still temporarily skipping the test for an active fragment program. Need to fix shadow2D() ... --- src/mesa/main/texstate.c | 82 +++++++++++++++++++++++--------------------- src/mesa/main/texstate.h | 7 ++-- src/mesa/swrast/s_fragprog.c | 20 ----------- 3 files changed, 44 insertions(+), 65 deletions(-) (limited to 'src/mesa/swrast/s_fragprog.c') diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index ed82f8028dc..c9f8a0656e8 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -1181,39 +1181,6 @@ _mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param ) } -/** - * Update derived compare function state. - */ -void -_mesa_update_texture_compare_function(struct gl_texture_object *tObj, - GLboolean in_frag_prog) -{ - if (in_frag_prog) { - /* Texel/coordinate comparison is ignored for programs. - * See GL_ARB_fragment_program/shader spec for details. - */ - tObj->_Function = GL_NONE; - } - else if (tObj->CompareFlag) { - /* GL_SGIX_shadow */ - if (tObj->CompareOperator == GL_TEXTURE_LEQUAL_R_SGIX) { - tObj->_Function = GL_LEQUAL; - } - else { - ASSERT(tObj->CompareOperator == GL_TEXTURE_GEQUAL_R_SGIX); - tObj->_Function = GL_GEQUAL; - } - } - else if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) { - /* GL_ARB_shadow */ - tObj->_Function = tObj->CompareFunc; - } - else { - tObj->_Function = GL_NONE; /* pass depth through as grayscale */ - } -} - - void GLAPIENTRY _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) { @@ -1421,7 +1388,6 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) if (ctx->Extensions.SGIX_shadow) { FLUSH_VERTICES(ctx, _NEW_TEXTURE); texObj->CompareFlag = params[0] ? GL_TRUE : GL_FALSE; - _mesa_update_texture_compare_function(texObj, GL_FALSE); } else { _mesa_error(ctx, GL_INVALID_ENUM, @@ -1436,7 +1402,6 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) op == GL_TEXTURE_GEQUAL_R_SGIX) { FLUSH_VERTICES(ctx, _NEW_TEXTURE); texObj->CompareOperator = op; - _mesa_update_texture_compare_function(texObj, GL_FALSE); } else { _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param)"); @@ -1475,7 +1440,6 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) if (mode == GL_NONE || mode == GL_COMPARE_R_TO_TEXTURE_ARB) { FLUSH_VERTICES(ctx, _NEW_TEXTURE); texObj->CompareMode = mode; - _mesa_update_texture_compare_function(texObj, GL_FALSE); } else { _mesa_error(ctx, GL_INVALID_ENUM, @@ -1511,8 +1475,6 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)"); return; } - - _mesa_update_texture_compare_function(texObj, GL_FALSE); } else { _mesa_error(ctx, GL_INVALID_ENUM, @@ -1533,8 +1495,6 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)"); return; } - - _mesa_update_texture_compare_function(texObj, GL_FALSE); } else { _mesa_error(ctx, GL_INVALID_ENUM, @@ -2835,6 +2795,47 @@ update_texture_matrices( GLcontext *ctx ) } +/** + * Update texture object's _Function field. We need to do this + * whenever any of the texture object's shadow-related fields change + * or when we start/stop using a fragment program. + * + * This function could be expanded someday to update additional per-object + * fields that depend on assorted state changes. + */ +static void +update_texture_compare_function(GLcontext *ctx, + struct gl_texture_object *tObj) +{ + /* XXX temporarily disable this test since it breaks the GLSL + * shadow2D(), etc. functions. + */ + if (0 /*ctx->FragmentProgram._Current*/) { + /* Texel/coordinate comparison is ignored for programs. + * See GL_ARB_fragment_program/shader spec for details. + */ + tObj->_Function = GL_NONE; + } + else if (tObj->CompareFlag) { + /* GL_SGIX_shadow */ + if (tObj->CompareOperator == GL_TEXTURE_LEQUAL_R_SGIX) { + tObj->_Function = GL_LEQUAL; + } + else { + ASSERT(tObj->CompareOperator == GL_TEXTURE_GEQUAL_R_SGIX); + tObj->_Function = GL_GEQUAL; + } + } + else if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) { + /* GL_ARB_shadow */ + tObj->_Function = tObj->CompareFunc; + } + else { + tObj->_Function = GL_NONE; /* pass depth through as grayscale */ + } +} + + /** * Helper function for determining which texture object (1D, 2D, cube, etc) * should actually be used. @@ -2851,6 +2852,7 @@ texture_override(GLcontext *ctx, if (texObj->_Complete) { texUnit->_ReallyEnabled = textureBit; texUnit->_Current = texObj; + update_texture_compare_function(ctx, texObj); } } } diff --git a/src/mesa/main/texstate.h b/src/mesa/main/texstate.h index df468ecf9bd..60145691b8c 100644 --- a/src/mesa/main/texstate.h +++ b/src/mesa/main/texstate.h @@ -5,9 +5,9 @@ /* * Mesa 3-D graphics library - * Version: 6.5 + * Version: 7.1 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -41,9 +41,6 @@ _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst ); extern void _mesa_print_texunit_state( GLcontext *ctx, GLuint unit ); -extern void -_mesa_update_texture_compare_function(struct gl_texture_object *tObj, - GLboolean in_frag_prog); /** diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index 1cbcde3c0ad..923b67e78e6 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -200,7 +200,6 @@ void _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span ) { const struct gl_fragment_program *program = ctx->FragmentProgram._Current; - GLuint i; /* incoming colors should be floats */ if (program->Base.InputsRead & FRAG_BIT_COL0) { @@ -209,27 +208,8 @@ _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span ) ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */ -#if 0 - for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { - if (ctx->Texture.Unit[i]._Current != NULL) { - const GLboolean enable_shadow = ((1 << i) & program->Base.ShadowSamplers); - _mesa_update_texture_compare_function(ctx->Texture.Unit[i]._Current, - !enable_shadow); - } - } -#endif - run_program(ctx, span, 0, span->end); -#if 0 - for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { - if (ctx->Texture.Unit[i]._Current != NULL) { - _mesa_update_texture_compare_function(ctx->Texture.Unit[i]._Current, - GL_FALSE); - } - } -#endif - if (program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR)) { span->interpMask &= ~SPAN_RGBA; span->arrayMask |= SPAN_RGBA; -- cgit v1.2.3