Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / mesa / drivers / dri / r600 / r600_tex.c
index 6d531bf0f938b1eb29f63d26f82bab2c7bb4d41d..d6a58f410cccc3d44816cff0775a8bdf8d275e82 100644 (file)
@@ -40,20 +40,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/image.h"
 #include "main/mipmap.h"
 #include "main/simple_list.h"
-#include "main/texformat.h"
 #include "main/texstore.h"
-#include "main/teximage.h"
 #include "main/texobj.h"
 
 #include "texmem.h"
 
 #include "r600_context.h"
-#include "r700_state.h"
 #include "radeon_mipmap_tree.h"
 #include "r600_tex.h"
 
-#include "xmlpool.h"
-
 
 static unsigned int translate_wrap_mode(GLenum wrapmode)
 {
@@ -67,7 +62,7 @@ static unsigned int translate_wrap_mode(GLenum wrapmode)
        case GL_MIRROR_CLAMP_TO_EDGE_EXT: return SQ_TEX_MIRROR_ONCE_LAST_TEXEL;
        case GL_MIRROR_CLAMP_TO_BORDER_EXT: return SQ_TEX_MIRROR_ONCE_BORDER;
        default:
-               _mesa_problem(NULL, "bad wrap mode in %s", __FUNCTION__);
+               radeon_error("bad wrap mode in %s", __FUNCTION__);
                return 0;
        }
 }
@@ -167,9 +162,9 @@ static void r600SetTexDefaultState(radeonTexObjPtr t)
 }
 
 
+#if 0
 static GLuint aniso_filter(GLfloat anisotropy)
 {
-#if 0
        if (anisotropy >= 16.0) {
                return R300_TX_MAX_ANISO_16_TO_1;
        } else if (anisotropy >= 8.0) {
@@ -181,9 +176,9 @@ static GLuint aniso_filter(GLfloat anisotropy)
        } else {
                return R300_TX_MAX_ANISO_1_TO_1;
        }
-#endif
        return 0;
 }
+#endif
 
 /**
  * Set the texture magnification and minification modes.
@@ -208,8 +203,7 @@ static void r600SetTexFilter(radeonTexObjPtr t, GLenum minf, GLenum magf, GLfloa
                        | R300_TX_MIN_FILTER_ANISO
                        | R300_TX_MIN_FILTER_MIP_LINEAR
                        | aniso_filter(anisotropy);*/
-               if (RADEON_DEBUG & DEBUG_TEXTURE)
-                       fprintf(stderr, "Using maximum anisotropy of %f\n", anisotropy);
+               radeon_print(RADEON_TEXTURE, RADEON_NORMAL, "Using maximum anisotropy of %f\n", anisotropy);
                return;
        }
 
@@ -282,16 +276,16 @@ static void r600SetTexBorderColor(radeonTexObjPtr t, const GLfloat color[4])
  * next UpdateTextureState
  */
 
-static void r600TexParameter(GLcontext * ctx, GLenum target,
+static void r600TexParameter(struct gl_context * ctx, GLenum target,
                             struct gl_texture_object *texObj,
                             GLenum pname, const GLfloat * params)
 {
        radeonTexObj* t = radeon_tex_obj(texObj);
+       GLenum baseFormat;
 
-       if (RADEON_DEBUG & (DEBUG_STATE | DEBUG_TEXTURE)) {
-               fprintf(stderr, "%s( %s )\n", __FUNCTION__,
+       radeon_print(RADEON_STATE | RADEON_TEXTURE, RADEON_VERBOSE,
+                       "%s( %s )\n", __FUNCTION__,
                        _mesa_lookup_enum_by_nr(pname));
-       }
 
        switch (pname) {
        case GL_TEXTURE_MIN_FILTER:
@@ -307,30 +301,22 @@ static void r600TexParameter(GLcontext * ctx, GLenum target,
                break;
 
        case GL_TEXTURE_BORDER_COLOR:
-               r600SetTexBorderColor(t, texObj->BorderColor);
+               r600SetTexBorderColor(t, texObj->BorderColor.f);
                break;
 
        case GL_TEXTURE_BASE_LEVEL:
        case GL_TEXTURE_MAX_LEVEL:
        case GL_TEXTURE_MIN_LOD:
        case GL_TEXTURE_MAX_LOD:
-               /* This isn't the most efficient solution but there doesn't appear to
-                * be a nice alternative.  Since there's no LOD clamping,
-                * we just have to rely on loading the right subset of mipmap levels
-                * to simulate a clamped LOD.
-                */
-               if (t->mt) {
-                       radeon_miptree_unreference(t->mt);
-                       t->mt = 0;
-                       t->validated = GL_FALSE;
-               }
+               t->validated = GL_FALSE;
                break;
 
        case GL_DEPTH_TEXTURE_MODE:
                if (!texObj->Image[0][texObj->BaseLevel])
                        return;
-               if (texObj->Image[0][texObj->BaseLevel]->TexFormat->BaseFormat
-                   == GL_DEPTH_COMPONENT) {
+               baseFormat = texObj->Image[0][texObj->BaseLevel]->_BaseFormat;
+               if (baseFormat == GL_DEPTH_COMPONENT ||
+                   baseFormat == GL_DEPTH_STENCIL) {
                        r600SetDepthTexMode(texObj);
                        break;
                } else {
@@ -346,16 +332,15 @@ static void r600TexParameter(GLcontext * ctx, GLenum target,
        }
 }
 
-static void r600DeleteTexture(GLcontext * ctx, struct gl_texture_object *texObj)
+static void r600DeleteTexture(struct gl_context * ctx, struct gl_texture_object *texObj)
 {
        context_t* rmesa = R700_CONTEXT(ctx);
        radeonTexObj* t = radeon_tex_obj(texObj);
 
-       if (RADEON_DEBUG & (DEBUG_STATE | DEBUG_TEXTURE)) {
-               fprintf(stderr, "%s( %p (target = %s) )\n", __FUNCTION__,
+       radeon_print(RADEON_STATE | RADEON_TEXTURE, RADEON_NORMAL,
+               "%s( %p (target = %s) )\n", __FUNCTION__,
                        (void *)texObj,
                        _mesa_lookup_enum_by_nr(texObj->Target));
-       }
 
        if (rmesa) {
                int i;
@@ -371,10 +356,8 @@ static void r600DeleteTexture(GLcontext * ctx, struct gl_texture_object *texObj)
                t->bo = NULL;
        }
 
-       if (t->mt) {
-               radeon_miptree_unreference(t->mt);
-               t->mt = 0;
-       }
+       radeon_miptree_unreference(&t->mt);
+
        _mesa_delete_texture_object(ctx, texObj);
 }
 
@@ -385,7 +368,7 @@ static void r600DeleteTexture(GLcontext * ctx, struct gl_texture_object *texObj)
  * allocate the default texture objects.
  * Fixup MaxAnisotropy according to user preference.
  */
-static struct gl_texture_object *r600NewTextureObject(GLcontext * ctx,
+static struct gl_texture_object *r600NewTextureObject(struct gl_context * ctx,
                                                      GLuint name,
                                                      GLenum target)
 {
@@ -393,10 +376,9 @@ static struct gl_texture_object *r600NewTextureObject(GLcontext * ctx,
        radeonTexObj* t = CALLOC_STRUCT(radeon_tex_obj);
 
 
-       if (RADEON_DEBUG & (DEBUG_STATE | DEBUG_TEXTURE)) {
-               fprintf(stderr, "%s( %p (target = %s) )\n", __FUNCTION__,
+       radeon_print(RADEON_STATE | RADEON_TEXTURE, RADEON_NORMAL,
+               "%s( %p (target = %s) )\n", __FUNCTION__,
                        t, _mesa_lookup_enum_by_nr(target));
-       }
 
        _mesa_initialize_texture_object(&t->base, name, target);
        t->base.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy;
@@ -405,12 +387,60 @@ static struct gl_texture_object *r600NewTextureObject(GLcontext * ctx,
        r600SetTexDefaultState(t);
        r600UpdateTexWrap(t);
        r600SetTexFilter(t, t->base.MinFilter, t->base.MagFilter, t->base.MaxAnisotropy);
-       r600SetTexBorderColor(t, t->base.BorderColor);
+       r600SetTexBorderColor(t, t->base.BorderColor.f);
 
        return &t->base;
 }
 
-void r600InitTextureFuncs(struct dd_function_table *functions)
+unsigned r600IsFormatRenderable(gl_format mesa_format)
+{
+       switch (mesa_format) {
+       case MESA_FORMAT_RGBA8888:
+       case MESA_FORMAT_SIGNED_RGBA8888:
+       case MESA_FORMAT_RGBA8888_REV:
+       case MESA_FORMAT_SIGNED_RGBA8888_REV:
+       case MESA_FORMAT_ARGB8888:
+       case MESA_FORMAT_XRGB8888:
+       case MESA_FORMAT_ARGB8888_REV:
+       case MESA_FORMAT_XRGB8888_REV:
+       case MESA_FORMAT_RGB565:
+       case MESA_FORMAT_RGB565_REV:
+       case MESA_FORMAT_ARGB4444:
+       case MESA_FORMAT_ARGB4444_REV:
+       case MESA_FORMAT_ARGB1555:
+       case MESA_FORMAT_ARGB1555_REV:
+       case MESA_FORMAT_AL88:
+       case MESA_FORMAT_AL88_REV:
+       case MESA_FORMAT_RGB332:
+       case MESA_FORMAT_A8:
+       case MESA_FORMAT_I8:
+       case MESA_FORMAT_CI8:
+       case MESA_FORMAT_L8:
+       case MESA_FORMAT_RGBA_FLOAT32:
+       case MESA_FORMAT_RGBA_FLOAT16:
+       case MESA_FORMAT_ALPHA_FLOAT32:
+       case MESA_FORMAT_ALPHA_FLOAT16:
+       case MESA_FORMAT_LUMINANCE_FLOAT32:
+       case MESA_FORMAT_LUMINANCE_FLOAT16:
+       case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
+       case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
+       case MESA_FORMAT_INTENSITY_FLOAT32: /* X, X, X, X */
+       case MESA_FORMAT_INTENSITY_FLOAT16: /* X, X, X, X */
+       case MESA_FORMAT_X8_Z24:
+       case MESA_FORMAT_S8_Z24:
+       case MESA_FORMAT_Z24_S8:
+       case MESA_FORMAT_Z16:
+       case MESA_FORMAT_Z32:
+       case MESA_FORMAT_SARGB8:
+       case MESA_FORMAT_SLA8:
+       case MESA_FORMAT_SL8:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+void r600InitTextureFuncs(radeonContextPtr radeon, struct dd_function_table *functions)
 {
        /* Note: we only plug in the functions we implement in the driver
         * since _mesa_init_driver_functions() was already called.
@@ -438,6 +468,11 @@ void r600InitTextureFuncs(struct dd_function_table *functions)
        functions->CompressedTexImage2D = radeonCompressedTexImage2D;
        functions->CompressedTexSubImage2D = radeonCompressedTexSubImage2D;
 
+       if (radeon->radeonScreen->kernel_mm) {
+               functions->CopyTexImage2D = radeonCopyTexImage2D;
+               functions->CopyTexSubImage2D = radeonCopyTexSubImage2D;
+       }
+
        functions->GenerateMipmap = radeonGenerateMipmap;
 
        driInitTextureFormats();