Просмотр исходного кода

fragment program writing to result.depth.z was broken

tags/mesa_6_4
Brian Paul 20 лет назад
Родитель
Сommit
ea9ed5849f
2 измененных файлов: 31 добавлений и 15 удалений
  1. 13
    2
      src/mesa/swrast/s_nvfragprog.c
  2. 18
    13
      src/mesa/swrast/s_span.c

+ 13
- 2
src/mesa/swrast/s_nvfragprog.c Просмотреть файл

@@ -1388,6 +1388,7 @@ init_machine( GLcontext *ctx, struct fp_machine *machine,
/* Load input registers */
if (inputsRead & (1 << FRAG_ATTRIB_WPOS)) {
GLfloat *wpos = machine->Inputs[FRAG_ATTRIB_WPOS];
ASSERT(span->arrayMask & SPAN_Z);
wpos[0] = (GLfloat) span->x + col;
wpos[1] = (GLfloat) span->y;
wpos[2] = (GLfloat) span->array->z[col] / ctx->DrawBuffer->_DepthMaxF;
@@ -1395,6 +1396,7 @@ init_machine( GLcontext *ctx, struct fp_machine *machine,
}
if (inputsRead & (1 << FRAG_ATTRIB_COL0)) {
GLfloat *col0 = machine->Inputs[FRAG_ATTRIB_COL0];
ASSERT(span->arrayMask & SPAN_RGBA);
col0[0] = CHAN_TO_FLOAT(span->array->rgba[col][RCOMP]);
col0[1] = CHAN_TO_FLOAT(span->array->rgba[col][GCOMP]);
col0[2] = CHAN_TO_FLOAT(span->array->rgba[col][BCOMP]);
@@ -1409,6 +1411,7 @@ init_machine( GLcontext *ctx, struct fp_machine *machine,
}
if (inputsRead & (1 << FRAG_ATTRIB_FOGC)) {
GLfloat *fogc = machine->Inputs[FRAG_ATTRIB_FOGC];
ASSERT(span->arrayMask & SPAN_FOG);
fogc[0] = span->array->fog[col];
fogc[1] = 0.0F;
fogc[2] = 0.0F;
@@ -1477,11 +1480,19 @@ _swrast_exec_fragment_program( GLcontext *ctx, struct sw_span *span )
UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][ACOMP], colOut[3]);
}
/* depth value */
if (program->OutputsWritten & (1 << FRAG_OUTPUT_DEPR))
span->array->z[i] = IROUND(ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_DEPR][0] * ctx->DrawBuffer->_DepthMaxF);
if (program->OutputsWritten & (1 << FRAG_OUTPUT_DEPR)) {
const GLfloat depth
= ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_DEPR][2];
span->array->z[i] = IROUND(depth * ctx->DrawBuffer->_DepthMaxF);
}
}
}

if (program->OutputsWritten & (1 << FRAG_OUTPUT_DEPR)) {
span->interpMask &= ~SPAN_Z;
span->arrayMask |= SPAN_Z;
}

ctx->_CurrentProgram = 0;
}


+ 18
- 13
src/mesa/swrast/s_span.c Просмотреть файл

@@ -328,6 +328,7 @@ _swrast_span_interpolate_z( const GLcontext *ctx, struct sw_span *span )
zval += span->zStep;
}
}
span->interpMask &= ~SPAN_Z;
span->arrayMask |= SPAN_Z;
}

@@ -1106,6 +1107,9 @@ _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span)
SWcontext *swrast = SWRAST_CONTEXT(ctx);
const GLuint origInterpMask = span->interpMask;
const GLuint origArrayMask = span->arrayMask;
const GLboolean deferredTexture = !(ctx->Color.AlphaEnabled ||
ctx->FragmentProgram._Active ||
ctx->ATIFragmentShader._Enabled);

ASSERT(span->primitive == GL_POINT || span->primitive == GL_LINE ||
span->primitive == GL_POLYGON || span->primitive == GL_BITMAP);
@@ -1160,14 +1164,12 @@ _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span)
interpolate_texcoords(ctx, span);
}

/* If the alpha test is enabled, we have to compute the fragment colors
* at this point and do the alpha test.
* Else, if alpha test is not enabled, we'll try to defer fragment
* color computation (by interpolation, texture mapping, fragment program)
* until after the Z/stencil tests in the hope that many fragments will
* get culled, leaving less work to do.
/* 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
* actually need.
*/
if (ctx->Color.AlphaEnabled) {
if (!deferredTexture) {
/* Now we need the rgba array, fill it in if needed */
if ((span->interpMask & SPAN_RGBA) && (span->arrayMask & SPAN_RGBA) == 0)
interpolate_colors(ctx, span);
@@ -1179,9 +1181,12 @@ _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span)
interpolate_fog(ctx, span);

/* Compute fragment colors with fragment program or texture lookups */
if (ctx->FragmentProgram._Active)
/* XXX interpolate depth values here??? */
if (ctx->FragmentProgram._Active) {
/* frag prog may need Z values */
if (span->interpMask & SPAN_Z)
_swrast_span_interpolate_z(ctx, span);
_swrast_exec_fragment_program( ctx, span );
}
else if (ctx->ATIFragmentShader._Enabled)
_swrast_exec_fragment_shader( ctx, span );
else if (ctx->Texture._EnabledUnits && (span->arrayMask & SPAN_TEXTURE))
@@ -1242,11 +1247,11 @@ _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span)
return;
}

/* If the alpha test isn't enabled, we're able to defer computing fragment
* colors (by interpolation, texturing, fragment program) until now.
* Hopefully, Z/stencil tests culled many of the fragments!
/* If we were able to defer fragment color computation to now, there's
* a good chance that many fragments will have already been killed by
* Z/stencil testing.
*/
if (!ctx->Color.AlphaEnabled) {
if (deferredTexture) {
/* Now we need the rgba array, fill it in if needed */
if ((span->interpMask & SPAN_RGBA) && (span->arrayMask & SPAN_RGBA) == 0)
interpolate_colors(ctx, span);

Загрузка…
Отмена
Сохранить