radeon: emit scissor when using cs path
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_texture.c
index 63680b495c92cbbe2b566163ddbdcf808d2832e0..35ed54243116fe512afb7017c0e679e939408312 100644 (file)
@@ -131,6 +131,25 @@ void radeon_teximage_unmap(radeon_texture_image *image)
        }
 }
 
+static void map_override(GLcontext *ctx, radeonTexObj *t)
+{
+       radeon_texture_image *img = get_radeon_texture_image(t->base.Image[0][0]);
+
+       radeon_bo_map(t->bo, GL_FALSE);
+
+       img->base.Data = t->bo->ptr;
+       _mesa_set_fetch_functions(&img->base, 2);
+}
+
+static void unmap_override(GLcontext *ctx, radeonTexObj *t)
+{
+       radeon_texture_image *img = get_radeon_texture_image(t->base.Image[0][0]);
+
+       radeon_bo_unmap(t->bo);
+
+       img->base.Data = NULL;
+}
+
 /**
  * Map a validated texture for reading during software rendering.
  */
@@ -139,9 +158,15 @@ void radeonMapTexture(GLcontext *ctx, struct gl_texture_object *texObj)
        radeonTexObj* t = radeon_tex_obj(texObj);
        int face, level;
 
+       if (!radeon_validate_texture_miptree(ctx, texObj))
+         return;
+
        /* for r100 3D sw fallbacks don't have mt */
+       if (t->image_override && t->bo)
+               map_override(ctx, t);
+
        if (!t->mt)
-         return;
+               return;
 
        radeon_bo_map(t->mt->bo, GL_FALSE);
        for(face = 0; face < t->mt->faces; ++face) {
@@ -155,6 +180,8 @@ void radeonUnmapTexture(GLcontext *ctx, struct gl_texture_object *texObj)
        radeonTexObj* t = radeon_tex_obj(texObj);
        int face, level;
 
+       if (t->image_override && t->bo)
+               unmap_override(ctx, t);
        /* for r100 3D sw fallbacks don't have mt */
        if (!t->mt)
          return;
@@ -230,13 +257,13 @@ void radeonGenerateMipmap(GLcontext* ctx, GLenum target, struct gl_texture_objec
 /* try to find a format which will only need a memcopy */
 static const struct gl_texture_format *radeonChoose8888TexFormat(radeonContextPtr rmesa,
                                                                 GLenum srcFormat,
-                                                                GLenum srcType)
+                                                                GLenum srcType, GLboolean fbo)
 {
        const GLuint ui = 1;
        const GLubyte littleEndian = *((const GLubyte *)&ui);
 
        /* r100 can only do this */
-       if (IS_R100_CLASS(rmesa->radeonScreen))
+       if (IS_R100_CLASS(rmesa->radeonScreen) || fbo)
          return _dri_texformat_argb8888;
 
        if ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
@@ -249,6 +276,8 @@ static const struct gl_texture_format *radeonChoose8888TexFormat(radeonContextPt
                   (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
                   (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && !littleEndian)) {
                return &_mesa_texformat_rgba8888_rev;
+       } else if (IS_R200_CLASS(rmesa->radeonScreen)) {
+               return _dri_texformat_argb8888;
        } else if (srcFormat == GL_BGRA && ((srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
                                            srcType == GL_UNSIGNED_INT_8_8_8_8)) {
                return &_mesa_texformat_argb8888_rev;
@@ -259,10 +288,19 @@ static const struct gl_texture_format *radeonChoose8888TexFormat(radeonContextPt
                return _dri_texformat_argb8888;
 }
 
-const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
+const struct gl_texture_format *radeonChooseTextureFormat_mesa(GLcontext * ctx,
                                                          GLint internalFormat,
                                                          GLenum format,
                                                          GLenum type)
+{
+       return radeonChooseTextureFormat(ctx, internalFormat, format,
+                                        type, 0);
+}
+
+const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
+                                                         GLint internalFormat,
+                                                         GLenum format,
+                                                         GLenum type, GLboolean fbo)
 {
        radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
        const GLboolean do32bpt =
@@ -294,7 +332,7 @@ const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
                case GL_UNSIGNED_SHORT_1_5_5_5_REV:
                        return _dri_texformat_argb1555;
                default:
-                       return do32bpt ? radeonChoose8888TexFormat(rmesa, format, type) :
+                       return do32bpt ? radeonChoose8888TexFormat(rmesa, format, type, fbo) :
                            _dri_texformat_argb4444;
                }
 
@@ -321,7 +359,7 @@ const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
        case GL_RGBA12:
        case GL_RGBA16:
                return !force16bpt ?
-                       radeonChoose8888TexFormat(rmesa, format,type) :
+                       radeonChoose8888TexFormat(rmesa, format, type, fbo) :
                        _dri_texformat_argb4444;
 
        case GL_RGBA4:
@@ -349,8 +387,12 @@ const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
        case GL_ALPHA12:
        case GL_ALPHA16:
        case GL_COMPRESSED_ALPHA:
-               return _dri_texformat_a8;
-
+               /* r200: can't use a8 format since interpreting hw I8 as a8 would result
+                  in wrong rgb values (same as alpha value instead of 0). */
+               if (IS_R200_CLASS(rmesa->radeonScreen))
+                       return _dri_texformat_al88;
+               else
+                       return _dri_texformat_a8;
        case 1:
        case GL_LUMINANCE:
        case GL_LUMINANCE4:
@@ -431,25 +473,13 @@ const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
        case GL_DEPTH_COMPONENT16:
        case GL_DEPTH_COMPONENT24:
        case GL_DEPTH_COMPONENT32:
-#if 0
-               switch (type) {
-               case GL_UNSIGNED_BYTE:
-               case GL_UNSIGNED_SHORT:
-                       return &_mesa_texformat_z16;
-               case GL_UNSIGNED_INT:
-                       return &_mesa_texformat_z32;
-               case GL_UNSIGNED_INT_24_8_EXT:
-               default:
-                       return &_mesa_texformat_z24_s8;
-               }
-#else
-               return &_mesa_texformat_z16;
-#endif
-
+       case GL_DEPTH_STENCIL_EXT:
+       case GL_DEPTH24_STENCIL8_EXT:
+               return &_mesa_texformat_s8_z24;
        default:
                _mesa_problem(ctx,
-                             "unexpected internalFormat 0x%x in r300ChooseTextureFormat",
-                             (int)internalFormat);
+                             "unexpected internalFormat 0x%x in %s",
+                             (int)internalFormat, __func__);
                return NULL;
        }
 
@@ -489,7 +519,7 @@ static void radeon_teximage(
        }
 
        /* Choose and fill in the texture format for this image */
-       texImage->TexFormat = radeonChooseTextureFormat(ctx, internalFormat, format, type);
+       texImage->TexFormat = radeonChooseTextureFormat(ctx, internalFormat, format, type, 0);
        _mesa_set_fetch_functions(texImage, dims);
 
        if (texImage->TexFormat->TexelBytes == 0) {