X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fswrast%2Fs_fragprog.c;h=12bcda311b98b1291175b882097da296ccd87bd6;hb=cebc62f1060c815e3b5a1bd3728c3d909db3d2b8;hp=144f78b024acf4b2452de10653bc67fd4907c307;hpb=ad935c3f4708417641dd3c257912ccce11485acc;p=mesa.git diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index 144f78b024a..12bcda311b9 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 7.0.3 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. * @@ -17,26 +16,41 @@ * 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. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. */ #include "main/glheader.h" #include "main/colormac.h" -#include "main/context.h" -#include "main/texstate.h" -#include "shader/prog_instruction.h" +#include "main/samplerobj.h" +#include "main/teximage.h" +#include "program/prog_instruction.h" +#include "s_context.h" #include "s_fragprog.h" #include "s_span.h" +/** + * \brief Should swrast use a fragment program? + * + * \return true if the current fragment program exists and is not the fixed + * function fragment program + */ +GLboolean +_swrast_use_fragment_program(struct gl_context *ctx) +{ + struct gl_fragment_program *fp = ctx->FragmentProgram._Current; + return fp && !(fp == ctx->FragmentProgram._TexEnvProgram + && fp->Base.NumInstructions == 0); +} /** * Apply texture object's swizzle (X/Y/Z/W/0/1) to incoming 'texel' * and return results in 'colorOut'. */ -static INLINE void +static inline void swizzle_texel(const GLfloat texel[4], GLfloat colorOut[4], GLuint swizzle) { if (swizzle == SWIZZLE_NOOP) { @@ -63,7 +77,7 @@ swizzle_texel(const GLfloat texel[4], GLfloat colorOut[4], GLuint swizzle) * Called via machine->FetchTexelLod() */ static void -fetch_texel_lod( GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda, +fetch_texel_lod( struct gl_context *ctx, const GLfloat texcoord[4], GLfloat lambda, GLuint unit, GLfloat color[4] ) { const struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current; @@ -71,11 +85,12 @@ fetch_texel_lod( GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda, if (texObj) { SWcontext *swrast = SWRAST_CONTEXT(ctx); GLfloat rgba[4]; + const struct gl_sampler_object *samp = _mesa_get_samplerobj(ctx, unit); - lambda = CLAMP(lambda, texObj->MinLod, texObj->MaxLod); + lambda = CLAMP(lambda, samp->MinLod, samp->MaxLod); - swrast->TextureSample[unit](ctx, texObj, 1, - (const GLfloat (*)[4]) texcoord, + swrast->TextureSample[unit](ctx, samp, ctx->Texture.Unit[unit]._Current, + 1, (const GLfloat (*)[4]) texcoord, &lambda, &rgba); swizzle_texel(rgba, color, texObj->_Swizzle); } @@ -89,20 +104,25 @@ fetch_texel_lod( GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda, * Fetch a texel with the given partial derivatives to compute a level * of detail in the mipmap. * Called via machine->FetchTexelDeriv() + * \param lodBias the lod bias which may be specified by a TXB instruction, + * otherwise zero. */ static void -fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4], +fetch_texel_deriv( struct gl_context *ctx, const GLfloat texcoord[4], const GLfloat texdx[4], const GLfloat texdy[4], GLfloat lodBias, GLuint unit, GLfloat color[4] ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); - const struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current; + const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; + const struct gl_texture_object *texObj = texUnit->_Current; if (texObj) { - const struct gl_texture_image *texImg = - texObj->Image[0][texObj->BaseLevel]; - const GLfloat texW = (GLfloat) texImg->WidthScale; - const GLfloat texH = (GLfloat) texImg->HeightScale; + const struct gl_texture_image *texImg = _mesa_base_tex_image(texObj); + const struct swrast_texture_image *swImg = + swrast_texture_image_const(texImg); + const struct gl_sampler_object *samp = _mesa_get_samplerobj(ctx, unit); + const GLfloat texW = (GLfloat) swImg->WidthScale; + const GLfloat texH = (GLfloat) swImg->HeightScale; GLfloat lambda; GLfloat rgba[4]; @@ -111,12 +131,14 @@ fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4], texdx[3], texdy[3], /* dq/dx, dq/dy */ texW, texH, texcoord[0], texcoord[1], texcoord[3], - 1.0F / texcoord[3]) + lodBias; + 1.0F / texcoord[3]); + + lambda += lodBias + texUnit->LodBias + samp->LodBias; - lambda = CLAMP(lambda, texObj->MinLod, texObj->MaxLod); + lambda = CLAMP(lambda, samp->MinLod, samp->MaxLod); - swrast->TextureSample[unit](ctx, texObj, 1, - (const GLfloat (*)[4]) texcoord, + swrast->TextureSample[unit](ctx, samp, ctx->Texture.Unit[unit]._Current, + 1, (const GLfloat (*)[4]) texcoord, &lambda, &rgba); swizzle_texel(rgba, color, texObj->_Swizzle); } @@ -136,14 +158,18 @@ fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4], * \param col which element (column) of the span we'll operate on */ static void -init_machine(GLcontext *ctx, struct gl_program_machine *machine, +init_machine(struct gl_context *ctx, struct gl_program_machine *machine, const struct gl_fragment_program *program, const SWspan *span, GLuint col) { - 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)); + GLfloat *wpos = span->array->attribs[VARYING_SLOT_POS][col]; + + /* ARB_fragment_coord_conventions */ + if (program->OriginUpperLeft) + wpos[1] = ctx->DrawBuffer->Height - 1 - wpos[1]; + if (!program->PixelCenterInteger) { + wpos[0] += 0.5F; + wpos[1] += 0.5F; } /* Setup pointer to input attributes */ @@ -151,15 +177,14 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine, machine->DerivX = (GLfloat (*)[4]) span->attrStepX; machine->DerivY = (GLfloat (*)[4]) span->attrStepY; - machine->NumDeriv = FRAG_ATTRIB_MAX; + machine->NumDeriv = VARYING_SLOT_MAX; machine->Samplers = program->Base.SamplerUnits; /* if running a GLSL program (not ARB_fragment_program) */ - if (ctx->Shader.CurrentProgram) { - /* Store front/back facing value in register FOGC.Y */ - machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = 1.0 - span->facing; - /* Note FOGC.ZW is gl_PointCoord if drawing a sprite */ + if (ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT]) { + /* Store front/back facing value */ + machine->Attribs[VARYING_SLOT_FACE][col][0] = 1.0F - span->facing; } machine->CurElement = col; @@ -182,11 +207,11 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine, * Run fragment program on the pixels in span from 'start' to 'end' - 1. */ static void -run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end) +run_program(struct gl_context *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; + const GLbitfield64 outputsWritten = program->Base.OutputsWritten; struct gl_program_machine *machine = &swrast->FragProgMachine; GLuint i; @@ -197,8 +222,8 @@ run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end) if (_mesa_execute_program(ctx, &program->Base, machine)) { /* Store result color */ - if (outputsWritten & (1 << FRAG_RESULT_COLOR)) { - COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0][i], + if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_COLOR)) { + COPY_4V(span->array->attribs[VARYING_SLOT_COL0][i], machine->Outputs[FRAG_RESULT_COLOR]); } else { @@ -208,22 +233,23 @@ run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end) */ GLuint buf; for (buf = 0; buf < ctx->DrawBuffer->_NumColorDrawBuffers; buf++) { - if (outputsWritten & (1 << (FRAG_RESULT_DATA0 + buf))) { - COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0 + buf][i], + if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DATA0 + buf)) { + COPY_4V(span->array->attribs[VARYING_SLOT_COL0 + buf][i], machine->Outputs[FRAG_RESULT_DATA0 + buf]); } } } /* Store result depth/z */ - if (outputsWritten & (1 << FRAG_RESULT_DEPTH)) { + if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) { const GLfloat depth = machine->Outputs[FRAG_RESULT_DEPTH][2]; if (depth <= 0.0) span->array->z[i] = 0; else if (depth >= 1.0) span->array->z[i] = ctx->DrawBuffer->_DepthMax; else - span->array->z[i] = IROUND(depth * ctx->DrawBuffer->_DepthMaxF); + span->array->z[i] = + (GLuint) (depth * ctx->DrawBuffer->_DepthMaxF + 0.5F); } } else { @@ -241,23 +267,23 @@ run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end) * in the given span. */ void -_swrast_exec_fragment_program( GLcontext *ctx, SWspan *span ) +_swrast_exec_fragment_program( struct gl_context *ctx, SWspan *span ) { const struct gl_fragment_program *program = ctx->FragmentProgram._Current; /* incoming colors should be floats */ - if (program->Base.InputsRead & FRAG_BIT_COL0) { - ASSERT(span->array->ChanType == GL_FLOAT); + if (program->Base.InputsRead & VARYING_BIT_COL0) { + assert(span->array->ChanType == GL_FLOAT); } run_program(ctx, span, 0, span->end); - if (program->Base.OutputsWritten & (1 << FRAG_RESULT_COLOR)) { + if (program->Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_COLOR)) { span->interpMask &= ~SPAN_RGBA; span->arrayMask |= SPAN_RGBA; } - if (program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPTH)) { + if (program->Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) { span->interpMask &= ~SPAN_Z; span->arrayMask |= SPAN_Z; }