radeon&r200: Add support for ARB_sampler_objects

Preparation for the mandatory support of ARB_sampler_objects. I have tested
this patch with rv280 only.

Signed-off-by: Pauli Nieminen <pauli.nieminen@linux.intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
Pauli Nieminen 2012-06-12 21:38:52 +03:00 committed by Eric Anholt
parent 10169e7adc
commit 6f6bd8aedc
10 changed files with 67 additions and 39 deletions

View File

@ -41,6 +41,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/simple_list.h"
#include "main/teximage.h"
#include "main/texobj.h"
#include "main/samplerobj.h"
#include "radeon_mipmap_tree.h"
#include "r200_context.h"
@ -360,12 +361,21 @@ static void r200TexEnv( struct gl_context *ctx, GLenum target,
}
}
void r200TexUpdateParameters(struct gl_context *ctx, GLuint unit)
{
struct gl_sampler_object *samp = _mesa_get_samplerobj(ctx, unit);
radeonTexObj* t = radeon_tex_obj(ctx->Texture.Unit[unit]._Current);
r200SetTexMaxAnisotropy(t , samp->MaxAnisotropy);
r200SetTexFilter(t, samp->MinFilter, samp->MagFilter);
r200SetTexWrap(t, samp->WrapS, samp->WrapT, samp->WrapR);
r200SetTexBorderColor(t, samp->BorderColor.f);
}
/**
* Changes variables and flags for a state update, which will happen at the
* next UpdateTextureState
*/
static void r200TexParameter( struct gl_context *ctx, GLenum target,
struct gl_texture_object *texObj,
GLenum pname, const GLfloat *params )
@ -382,20 +392,10 @@ static void r200TexParameter( struct gl_context *ctx, GLenum target,
case GL_TEXTURE_MIN_FILTER:
case GL_TEXTURE_MAG_FILTER:
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
r200SetTexMaxAnisotropy( t, texObj->Sampler.MaxAnisotropy );
r200SetTexFilter( t, texObj->Sampler.MinFilter, texObj->Sampler.MagFilter );
break;
case GL_TEXTURE_WRAP_S:
case GL_TEXTURE_WRAP_T:
case GL_TEXTURE_WRAP_R:
r200SetTexWrap( t, texObj->Sampler.WrapS, texObj->Sampler.WrapT, texObj->Sampler.WrapR );
break;
case GL_TEXTURE_BORDER_COLOR:
r200SetTexBorderColor( t, texObj->Sampler.BorderColor.f );
break;
case GL_TEXTURE_BASE_LEVEL:
case GL_TEXTURE_MAX_LEVEL:
case GL_TEXTURE_MIN_LOD:
@ -489,6 +489,16 @@ static struct gl_texture_object *r200NewTextureObject(struct gl_context * ctx,
return &t->base;
}
static struct gl_sampler_object *
r200NewSamplerObject(struct gl_context *ctx, GLuint name)
{
r200ContextPtr rmesa = R200_CONTEXT(ctx);
struct gl_sampler_object *samp = _mesa_new_sampler_object(ctx, name);
if (samp)
samp->MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy;
return samp;
}
void r200InitTextureFuncs( radeonContextPtr radeon, struct dd_function_table *functions )
@ -506,4 +516,5 @@ void r200InitTextureFuncs( radeonContextPtr radeon, struct dd_function_table *fu
functions->TexEnv = r200TexEnv;
functions->TexParameter = r200TexParameter;
functions->TexGen = r200TexGen;
functions->NewSamplerObject = r200NewSamplerObject;
}

View File

@ -48,6 +48,7 @@ extern void r200DestroyTexObj( r200ContextPtr rmesa, radeonTexObjPtr t );
extern void r200InitTextureFuncs( radeonContextPtr radeon, struct dd_function_table *functions );
extern void r200UpdateFragmentShader( struct gl_context *ctx );
extern void r200TexUpdateParameters(struct gl_context *ctx, GLuint unit);
extern void set_re_cntl_d3d( struct gl_context *ctx, int unit, GLboolean use_d3d );

View File

@ -1500,7 +1500,7 @@ static GLboolean r200_validate_texture(struct gl_context *ctx, struct gl_texture
r200ContextPtr rmesa = R200_CONTEXT(ctx);
radeonTexObj *t = radeon_tex_obj(texObj);
if (!radeon_validate_texture_miptree(ctx, texObj))
if (!radeon_validate_texture_miptree(ctx, _mesa_get_samplerobj(ctx, unit), texObj))
return GL_FALSE;
r200_validate_texgen(ctx, unit);
@ -1522,6 +1522,7 @@ static GLboolean r200_validate_texture(struct gl_context *ctx, struct gl_texture
rmesa->hw.vtx.cmd[VTX_TCL_OUTPUT_VTXFMT_1] |= 4 << (unit * 3);
rmesa->recheck_texgen[unit] = GL_TRUE;
r200TexUpdateParameters(ctx, unit);
import_tex_obj_state( rmesa, unit, t );
if (rmesa->recheck_texgen[unit]) {

View File

@ -249,7 +249,7 @@ void radeon_miptree_unreference(radeon_mipmap_tree **ptr)
* @param[out] pminLod minimal LOD
* @param[out] pmaxLod maximal LOD
*/
static void calculate_min_max_lod(struct gl_texture_object *tObj,
static void calculate_min_max_lod(struct gl_sampler_object *samp, struct gl_texture_object *tObj,
unsigned *pminLod, unsigned *pmaxLod)
{
int minLod, maxLod;
@ -260,15 +260,15 @@ static void calculate_min_max_lod(struct gl_texture_object *tObj,
case GL_TEXTURE_2D:
case GL_TEXTURE_3D:
case GL_TEXTURE_CUBE_MAP:
if (tObj->Sampler.MinFilter == GL_NEAREST || tObj->Sampler.MinFilter == GL_LINEAR) {
if (samp->MinFilter == GL_NEAREST || samp->MinFilter == GL_LINEAR) {
/* GL_NEAREST and GL_LINEAR only care about GL_TEXTURE_BASE_LEVEL.
*/
minLod = maxLod = tObj->BaseLevel;
} else {
minLod = tObj->BaseLevel + (GLint)(tObj->Sampler.MinLod);
minLod = tObj->BaseLevel + (GLint)(samp->MinLod);
minLod = MAX2(minLod, tObj->BaseLevel);
minLod = MIN2(minLod, tObj->MaxLevel);
maxLod = tObj->BaseLevel + (GLint)(tObj->Sampler.MaxLod + 0.5);
maxLod = tObj->BaseLevel + (GLint)(samp->MaxLod + 0.5);
maxLod = MIN2(maxLod, tObj->MaxLevel);
maxLod = MIN2(maxLod, tObj->Image[0][minLod]->MaxLog2 + minLod);
maxLod = MAX2(maxLod, minLod); /* need at least one level */
@ -536,17 +536,19 @@ static radeon_mipmap_tree * get_biggest_matching_miptree(radeonTexObj *texObj,
* If individual images are stored in different mipmap trees
* use the mipmap tree that has the most of the correct data.
*/
int radeon_validate_texture_miptree(struct gl_context * ctx, struct gl_texture_object *texObj)
int radeon_validate_texture_miptree(struct gl_context * ctx,
struct gl_sampler_object *samp,
struct gl_texture_object *texObj)
{
radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
radeonTexObj *t = radeon_tex_obj(texObj);
radeon_mipmap_tree *dst_miptree;
if (t->validated || t->image_override) {
if (samp == &texObj->Sampler && (t->validated || t->image_override)) {
return GL_TRUE;
}
calculate_min_max_lod(&t->base, &t->minLod, &t->maxLod);
calculate_min_max_lod(samp, &t->base, &t->minLod, &t->maxLod);
radeon_print(RADEON_TEXTURE, RADEON_NORMAL,
"%s: Validating texture %p now, minLod = %d, maxLod = %d\n",

View File

@ -43,6 +43,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/glheader.h"
#include "main/texformat.h"
#include "main/renderbuffer.h"
#include "main/samplerobj.h"
#include "swrast/swrast.h"
#include "swrast/s_renderbuffer.h"
@ -124,7 +125,8 @@ static void radeonSpanRenderStart(struct gl_context * ctx)
for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
if (ctx->Texture.Unit[i]._ReallyEnabled) {
radeon_validate_texture_miptree(ctx, ctx->Texture.Unit[i]._Current);
radeon_validate_texture_miptree(ctx, _mesa_get_samplerobj(ctx, i),
ctx->Texture.Unit[i]._Current);
radeon_swrast_map_texture_images(ctx, ctx->Texture.Unit[i]._Current);
}
}

View File

@ -312,6 +312,17 @@ static void radeonTexEnv( struct gl_context *ctx, GLenum target,
}
}
void radeonTexUpdateParameters(struct gl_context *ctx, GLuint unit)
{
struct gl_sampler_object *samp = _mesa_get_samplerobj(ctx, unit);
radeonTexObj* t = radeon_tex_obj(ctx->Texture.Unit[unit]._Current);
radeonSetTexMaxAnisotropy(t , samp->MaxAnisotropy);
radeonSetTexFilter(t, samp->MinFilter, samp->MagFilter);
radeonSetTexWrap(t, samp->WrapS, samp->WrapT);
radeonSetTexBorderColor(t, samp->BorderColor.f);
}
/**
* Changes variables and flags for a state update, which will happen at the
@ -328,22 +339,6 @@ static void radeonTexParameter( struct gl_context *ctx, GLenum target,
_mesa_lookup_enum_by_nr( pname ) );
switch ( pname ) {
case GL_TEXTURE_MIN_FILTER:
case GL_TEXTURE_MAG_FILTER:
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
radeonSetTexMaxAnisotropy( t, texObj->Sampler.MaxAnisotropy );
radeonSetTexFilter( t, texObj->Sampler.MinFilter, texObj->Sampler.MagFilter );
break;
case GL_TEXTURE_WRAP_S:
case GL_TEXTURE_WRAP_T:
radeonSetTexWrap( t, texObj->Sampler.WrapS, texObj->Sampler.WrapT );
break;
case GL_TEXTURE_BORDER_COLOR:
radeonSetTexBorderColor( t, texObj->Sampler.BorderColor.f );
break;
case GL_TEXTURE_BASE_LEVEL:
case GL_TEXTURE_MAX_LEVEL:
case GL_TEXTURE_MIN_LOD:
@ -433,6 +428,16 @@ radeonNewTextureObject( struct gl_context *ctx, GLuint name, GLenum target )
}
static struct gl_sampler_object *
radeonNewSamplerObject(struct gl_context *ctx, GLuint name)
{
r100ContextPtr rmesa = R100_CONTEXT(ctx);
struct gl_sampler_object *samp = _mesa_new_sampler_object(ctx, name);
if (samp)
samp->MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy;
return samp;
}
void radeonInitTextureFuncs( radeonContextPtr radeon, struct dd_function_table *functions )
{
@ -445,4 +450,5 @@ void radeonInitTextureFuncs( radeonContextPtr radeon, struct dd_function_table *
functions->TexEnv = radeonTexEnv;
functions->TexParameter = radeonTexParameter;
functions->TexGen = radeonTexGen;
functions->NewSamplerObject = radeonNewSamplerObject;
}

View File

@ -47,6 +47,7 @@ extern int radeonUploadTexImages( r100ContextPtr rmesa, radeonTexObjPtr t,
GLuint face );
extern void radeonDestroyTexObj( r100ContextPtr rmesa, radeonTexObjPtr t );
extern void radeonTexUpdateParameters(struct gl_context *ctx, GLuint unit);
extern void radeonInitTextureFuncs( radeonContextPtr radeon, struct dd_function_table *functions );

View File

@ -72,7 +72,7 @@ do_copy_texsubimage(struct gl_context *ctx,
}
if (!timg->mt) {
radeon_validate_texture_miptree(ctx, &tobj->base);
radeon_validate_texture_miptree(ctx, &tobj->base.Sampler, &tobj->base);
}
assert(rrb->bo);

View File

@ -42,6 +42,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/texstate.h"
#include "main/texobj.h"
#include "main/enums.h"
#include "main/samplerobj.h"
#include "radeon_context.h"
#include "radeon_mipmap_tree.h"
@ -1057,7 +1058,7 @@ static GLboolean radeon_validate_texture(struct gl_context *ctx, struct gl_textu
radeonTexObj *t = radeon_tex_obj(texObj);
int ret;
if (!radeon_validate_texture_miptree(ctx, texObj))
if (!radeon_validate_texture_miptree(ctx, _mesa_get_samplerobj(ctx, unit), texObj))
return GL_FALSE;
ret = setup_hardware_state(rmesa, t, unit);
@ -1076,6 +1077,7 @@ static GLboolean radeon_validate_texture(struct gl_context *ctx, struct gl_textu
rmesa->recheck_texgen[unit] = GL_TRUE;
radeonTexUpdateParameters(ctx, unit);
import_tex_obj_state( rmesa, unit, t );
if (rmesa->recheck_texgen[unit]) {

View File

@ -49,7 +49,9 @@ void radeonFreeTextureImageBuffer(struct gl_context *ctx, struct gl_texture_imag
void radeon_teximage_map(radeon_texture_image *image, GLboolean write_enable);
void radeon_teximage_unmap(radeon_texture_image *image);
int radeon_validate_texture_miptree(struct gl_context * ctx, struct gl_texture_object *texObj);
int radeon_validate_texture_miptree(struct gl_context * ctx,
struct gl_sampler_object *samp,
struct gl_texture_object *texObj);
void radeon_swrast_map_texture_images(struct gl_context *ctx, struct gl_texture_object *texObj);