From 4002b75e6267ecd0f9e3093e221e34ed5c8485d4 Mon Sep 17 00:00:00 2001 From: Nicolai Haehnle Date: Mon, 30 Jun 2008 00:44:26 +0200 Subject: [PATCH] r300: Cleanup LodBias support . There is both a per-texture unit and a per-texture object (at least for OpenGL 1.4); this should now be supported properly. . The LOD bias calculation in r300_state has been simplified and corrected (need to multiply by 32 instead of 31, and ensure clamping) . do not clamp LOD bias in TexEnv, as that behaviour conflicts with what the spec says . set Const.MaxTextureLodBias properly . remove the no_neg_lod_bias property; if somebody can explain what it's good for, we can add it back in, but according to Google, nobody seems to use it . removed some dead code and unused variables --- src/mesa/drivers/dri/r300/r300_context.c | 1 + src/mesa/drivers/dri/r300/r300_context.h | 5 +- src/mesa/drivers/dri/r300/r300_state.c | 28 ++++--- src/mesa/drivers/dri/r300/r300_tex.c | 91 --------------------- src/mesa/drivers/dri/radeon/radeon_screen.c | 15 ++-- 5 files changed, 25 insertions(+), 115 deletions(-) diff --git a/src/mesa/drivers/dri/r300/r300_context.c b/src/mesa/drivers/dri/r300/r300_context.c index 063d4e575ef..44c368030f6 100644 --- a/src/mesa/drivers/dri/r300/r300_context.c +++ b/src/mesa/drivers/dri/r300/r300_context.c @@ -279,6 +279,7 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual, MIN2(ctx->Const.MaxTextureImageUnits, ctx->Const.MaxTextureCoordUnits); ctx->Const.MaxTextureMaxAnisotropy = 16.0; + ctx->Const.MaxTextureLodBias = 16.0; if (screen->chip_family >= CHIP_FAMILY_RV515) { ctx->Const.MaxTextureLevels = 13; diff --git a/src/mesa/drivers/dri/r300/r300_context.h b/src/mesa/drivers/dri/r300/r300_context.h index 285b2ad6fd6..a24ab0cad76 100644 --- a/src/mesa/drivers/dri/r300/r300_context.h +++ b/src/mesa/drivers/dri/r300/r300_context.h @@ -806,10 +806,10 @@ struct r500_fragment_program { GLcontext *ctx; GLboolean translated; GLboolean error; - + struct r500_fragment_program_external_state state; struct r500_fragment_program_code code; - + GLboolean writes_depth; GLuint optimization; @@ -925,7 +925,6 @@ struct r300_context { driTextureObject swapped; int texture_depth; float initialMaxAnisotropy; - float LODBias; /* Clientdata textures; */ diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c index 00351014af3..9e4cc777a98 100644 --- a/src/mesa/drivers/dri/r300/r300_state.c +++ b/src/mesa/drivers/dri/r300/r300_state.c @@ -1381,16 +1381,14 @@ static void r500SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings) } } -static GLuint r300CalculateTexLodBias(GLfloat bias) +static GLuint translate_lod_bias(GLfloat bias) { - GLuint b; - b = (unsigned int)fabsf(ceilf(bias*31)); - if (signbit(bias)) { - b ^= 0x3ff; /* 10 bits */ - } - b <<= 3; - b &= R300_LOD_BIAS_MASK; - return b; + GLint b = (int)(bias*32); + if (b >= (1 << 9)) + b = (1 << 9)-1; + else if (b < -(1 << 9)) + b = -(1 << 9); + return ((GLuint)b) << R300_LOD_BIAS_SHIFT; } static void r300SetupTextures(GLcontext * ctx) @@ -1456,10 +1454,14 @@ static void r300SetupTextures(GLcontext * ctx) r300->hw.tex.filter.cmd[R300_TEX_VALUE_0 + hw_tmu] = gen_fixed_filter(t->filter) | (hw_tmu << 28); - /* Make LOD bias a bit more per-tex and less per-everything. */ - t->filter_1 &= ~R300_LOD_BIAS_MASK; - t->filter_1 |= r300CalculateTexLodBias(ctx->Texture.Unit[i].LodBias); - r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] = t->filter_1; + /* Note: There is a LOD bias per texture unit and a LOD bias + * per texture object. We add them here to get the correct behaviour. + * (The per-texture object LOD bias was introduced in OpenGL 1.4 + * and is not present in the EXT_texture_object extension). + */ + r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] = + t->filter_1 | + translate_lod_bias(ctx->Texture.Unit[i].LodBias + t->base.tObj->LodBias); r300->hw.tex.size.cmd[R300_TEX_VALUE_0 + hw_tmu] = t->size; r300->hw.tex.format.cmd[R300_TEX_VALUE_0 + diff --git a/src/mesa/drivers/dri/r300/r300_tex.c b/src/mesa/drivers/dri/r300/r300_tex.c index 4ed71777d39..c8f02c4ef5b 100644 --- a/src/mesa/drivers/dri/r300/r300_tex.c +++ b/src/mesa/drivers/dri/r300/r300_tex.c @@ -175,20 +175,6 @@ static void r300SetTexBorderColor(r300TexObjPtr t, GLubyte c[4]) t->pp_border_color = PACK_COLOR_8888(c[3], c[0], c[1], c[2]); } -static void r300SetTexLodBias(r300TexObjPtr t, GLfloat bias) -{ - GLuint b; - b = (unsigned int)fabsf(ceilf(bias*31)); - if (signbit(bias)) { - b ^= 0x3ff; /* 10 bits */ - } - b <<= 3; - b &= R300_LOD_BIAS_MASK; - - t->filter_1 &= ~R300_LOD_BIAS_MASK; - t->filter_1 |= b; -} - /** * Allocate space for and load the mesa images into the texture memory block. * This will happen before drawing with a new texture, or drawing with a @@ -912,78 +898,6 @@ r300TexSubImage3D(GLcontext * ctx, GLenum target, GLint level, t->dirty_images[0] |= (1 << level); } -/* This feels like a prime target for code reuse, so I'm putting it here - * instead of inlining it in TexEnv. */ -static GLenum r300TexUnitTarget(struct gl_texture_unit *unit) { - if (unit->_ReallyEnabled & (TEXTURE_RECT_BIT)) { - return GL_TEXTURE_RECTANGLE_NV; - } else if (unit->_ReallyEnabled & (TEXTURE_1D_BIT)) { - return GL_TEXTURE_1D; - } else if (unit->_ReallyEnabled & (TEXTURE_2D_BIT)) { - return GL_TEXTURE_2D; - } else if (unit->_ReallyEnabled & (TEXTURE_3D_BIT)) { - return GL_TEXTURE_3D; - } else if (unit->_ReallyEnabled & (TEXTURE_CUBE_BIT)) { - return GL_TEXTURE_CUBE_MAP; - } - if (unit->Enabled & (TEXTURE_RECT_BIT)) { - return GL_TEXTURE_RECTANGLE_NV; - } else if (unit->Enabled & (TEXTURE_1D_BIT)) { - return GL_TEXTURE_1D; - } else if (unit->Enabled & (TEXTURE_2D_BIT)) { - return GL_TEXTURE_2D; - } else if (unit->Enabled & (TEXTURE_3D_BIT)) { - return GL_TEXTURE_3D; - } else if (unit->Enabled & (TEXTURE_CUBE_BIT)) { - return GL_TEXTURE_CUBE_MAP; - } - return 0; -} - -static void r300TexEnv(GLcontext * ctx, GLenum target, - GLenum pname, const GLfloat * param) -{ - r300ContextPtr rmesa = R300_CONTEXT(ctx); - if (RADEON_DEBUG & DEBUG_STATE) { - fprintf(stderr, "%s( %s )\n", - __FUNCTION__, _mesa_lookup_enum_by_nr(pname)); - } - - /* This is incorrect: Need to maintain this data for each of - * GL_TEXTURE_{123}D, GL_TEXTURE_RECTANGLE_NV, etc, and switch - * between them according to _ReallyEnabled. - */ - switch (pname) { - case GL_TEXTURE_LOD_BIAS_EXT: { - GLfloat bias, min; - - /* The R300's LOD bias is a signed 2's complement value with a - * range of -16.0 <= bias < 16.0. - * - * NOTE: Add a small bias to the bias for conform mipsel.c test. - */ - bias = *param + .01; - min = driQueryOptionb(&rmesa->radeon.optionCache, - "no_neg_lod_bias") ? 0.0 : -16.0; - bias = CLAMP(bias, min, 16.0); - - /* There's probably a magic Mesa method for finding the REAL - * texture unit. I don't know it, though. */ - if (!(ctx->Texture._EnabledUnits & (1 << ctx->Texture.CurrentUnit))) { - break; - } - - /* Save our newly clamped LOD bias. */ - ctx->Texture.Unit[ctx->Texture.CurrentUnit].LodBias = bias; - - break; - } - - default: - return; - } -} - /** * Changes variables and flags for a state update, which will happen at the * next UpdateTextureState @@ -1106,10 +1020,6 @@ static struct gl_texture_object *r300NewTextureObject(GLcontext * ctx, return NULL; obj->MaxAnisotropy = rmesa->initialMaxAnisotropy; - /* Attempt to fill LOD bias, if previously set. - * Should start at 0.0, which won't affect the HW. */ - obj->LodBias = rmesa->LODBias; - r300AllocTexObj(obj); return obj; } @@ -1131,7 +1041,6 @@ void r300InitTextureFuncs(struct dd_function_table *functions) functions->DeleteTexture = r300DeleteTexture; functions->IsTextureResident = driIsTextureResident; - functions->TexEnv = r300TexEnv; functions->TexParameter = r300TexParameter; functions->CompressedTexImage2D = r300CompressedTexImage2D; diff --git a/src/mesa/drivers/dri/radeon/radeon_screen.c b/src/mesa/drivers/dri/radeon/radeon_screen.c index b647cffa0e7..02152499c4e 100644 --- a/src/mesa/drivers/dri/radeon/radeon_screen.c +++ b/src/mesa/drivers/dri/radeon/radeon_screen.c @@ -194,8 +194,7 @@ DRI_CONF_BEGIN DRI_CONF_SECTION_QUALITY DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB) DRI_CONF_DEF_MAX_ANISOTROPY(1.0, "1.0,2.0,4.0,8.0,16.0") - DRI_CONF_NO_NEG_LOD_BIAS(false) - DRI_CONF_FORCE_S3TC_ENABLE(false) + DRI_CONF_FORCE_S3TC_ENABLE(false) DRI_CONF_DISABLE_S3TC(false) DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER) DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC) @@ -206,7 +205,7 @@ DRI_CONF_BEGIN DRI_CONF_NO_RAST(false) DRI_CONF_SECTION_END DRI_CONF_END; -static const GLuint __driNConfigOptions = 18; +static const GLuint __driNConfigOptions = 17; #ifndef RADEON_DEBUG int RADEON_DEBUG = 0; @@ -244,10 +243,10 @@ radeonGetParam(int fd, int param, void *value) { int ret; drm_radeon_getparam_t gp; - + gp.param = param; gp.value = value; - + ret = drmCommandWriteRead( fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp)); return ret; } @@ -280,7 +279,7 @@ radeonFillInModes( __DRIscreenPrivate *psp, depth_bits_array[0] = depth_bits; depth_bits_array[1] = depth_bits; - + /* Just like with the accumulation buffer, always provide some modes * with a stencil buffer. It will be a sw fallback, but some apps won't * care about that. @@ -384,7 +383,7 @@ radeonCreateScreen( __DRIscreenPrivate *sPriv ) int ret; ret = radeonGetParam( sPriv->fd, RADEON_PARAM_GART_BUFFER_OFFSET, &screen->gart_buffer_offset); - + if (ret) { FREE( screen ); fprintf(stderr, "drm_radeon_getparam_t (RADEON_PARAM_GART_BUFFER_OFFSET): %d\n", ret); @@ -1133,7 +1132,7 @@ static void radeonDestroyContext(__DRIcontextPrivate * driContextPriv) /** * This is the driver specific part of the createNewScreen entry point. - * + * * \todo maybe fold this into intelInitDriver * * \return the __GLcontextModes supported by this driver -- 2.30.2