From: Pauli Nieminen Date: Tue, 12 Jun 2012 18:38:52 +0000 (+0300) Subject: radeon&r200: Add support for ARB_sampler_objects X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6f6bd8aedcf2b2f0e1ca9a1fa7ded1cb1f5a88ed;p=mesa.git 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 Reviewed-by: Brian Paul --- diff --git a/src/mesa/drivers/dri/r200/r200_tex.c b/src/mesa/drivers/dri/r200/r200_tex.c index fe7c977ac4e..9d52095e247 100644 --- a/src/mesa/drivers/dri/r200/r200_tex.c +++ b/src/mesa/drivers/dri/r200/r200_tex.c @@ -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; } diff --git a/src/mesa/drivers/dri/r200/r200_tex.h b/src/mesa/drivers/dri/r200/r200_tex.h index 756a128a196..725b45d04ab 100644 --- a/src/mesa/drivers/dri/r200/r200_tex.h +++ b/src/mesa/drivers/dri/r200/r200_tex.h @@ -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 ); diff --git a/src/mesa/drivers/dri/r200/r200_texstate.c b/src/mesa/drivers/dri/r200/r200_texstate.c index 19e77c57fc3..b25c6113960 100644 --- a/src/mesa/drivers/dri/r200/r200_texstate.c +++ b/src/mesa/drivers/dri/r200/r200_texstate.c @@ -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]) { diff --git a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c index 413ad83ade1..0ef6457f513 100644 --- a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c +++ b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c @@ -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", diff --git a/src/mesa/drivers/dri/radeon/radeon_span.c b/src/mesa/drivers/dri/radeon/radeon_span.c index 92f3d332a4b..0617adc5bc5 100644 --- a/src/mesa/drivers/dri/radeon/radeon_span.c +++ b/src/mesa/drivers/dri/radeon/radeon_span.c @@ -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); } } diff --git a/src/mesa/drivers/dri/radeon/radeon_tex.c b/src/mesa/drivers/dri/radeon/radeon_tex.c index 71bd464266f..fcd9a76a998 100644 --- a/src/mesa/drivers/dri/radeon/radeon_tex.c +++ b/src/mesa/drivers/dri/radeon/radeon_tex.c @@ -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; } diff --git a/src/mesa/drivers/dri/radeon/radeon_tex.h b/src/mesa/drivers/dri/radeon/radeon_tex.h index 2f0fbe1d73e..fa57c08987d 100644 --- a/src/mesa/drivers/dri/radeon/radeon_tex.h +++ b/src/mesa/drivers/dri/radeon/radeon_tex.h @@ -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 ); diff --git a/src/mesa/drivers/dri/radeon/radeon_tex_copy.c b/src/mesa/drivers/dri/radeon/radeon_tex_copy.c index 1faf9c81db9..a6c406b2bff 100644 --- a/src/mesa/drivers/dri/radeon/radeon_tex_copy.c +++ b/src/mesa/drivers/dri/radeon/radeon_tex_copy.c @@ -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); diff --git a/src/mesa/drivers/dri/radeon/radeon_texstate.c b/src/mesa/drivers/dri/radeon/radeon_texstate.c index 87f12d5179c..d2b5b755d6e 100644 --- a/src/mesa/drivers/dri/radeon/radeon_texstate.c +++ b/src/mesa/drivers/dri/radeon/radeon_texstate.c @@ -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]) { diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.h b/src/mesa/drivers/dri/radeon/radeon_texture.h index 8f9f5bd128e..abcce54806d 100644 --- a/src/mesa/drivers/dri/radeon/radeon_texture.h +++ b/src/mesa/drivers/dri/radeon/radeon_texture.h @@ -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);