r200: use common glCopyTex(Sub)Image code
authorMaciej Cencora <m.cencora@gmail.com>
Tue, 19 Jan 2010 22:20:44 +0000 (23:20 +0100)
committerMaciej Cencora <m.cencora@gmail.com>
Tue, 19 Jan 2010 22:38:35 +0000 (23:38 +0100)
src/mesa/drivers/dri/r200/Makefile
src/mesa/drivers/dri/r200/r200_blit.c
src/mesa/drivers/dri/r200/r200_blit.h
src/mesa/drivers/dri/r200/r200_context.c
src/mesa/drivers/dri/r200/r200_tex.c
src/mesa/drivers/dri/r200/r200_tex.h
src/mesa/drivers/dri/r200/r200_texcopy.c [deleted file]

index 2155ece21640df0a2d1063a0c97f15f8f1ec04b2..ca33faff87f51da760ea6beae7df1e98b3a3caef 100644 (file)
@@ -29,8 +29,8 @@ RADEON_COMMON_SOURCES = \
        radeon_mipmap_tree.c \
        radeon_queryobj.c \
        radeon_span.c \
-       radeon_texture.c
-
+       radeon_texture.c \
+       radeon_tex_copy.c
 
 DRIVER_SOURCES = r200_context.c \
                 r200_ioctl.c \
@@ -47,7 +47,6 @@ DRIVER_SOURCES = r200_context.c \
                 r200_fragshader.c \
                 r200_vertprog.c \
                 r200_blit.c \
-                r200_texcopy.c \
                 radeon_screen.c \
                 $(EGL_SOURCES) \
                 $(RADEON_COMMON_SOURCES) \
index 081218b3a5d4ac3568992c458b911ea2e00385a8..212258436329421ccf21b28f7a15d6736e0808a8 100644 (file)
@@ -311,27 +311,29 @@ static inline void emit_draw_packet(struct r200_context *r200,
  * @param[in] height region height
  * @param[in] flip_y set if y coords of the source image need to be flipped
  */
-GLboolean r200_blit(struct r200_context *r200,
-                    struct radeon_bo *src_bo,
-                    intptr_t src_offset,
-                    gl_format src_mesaformat,
-                    unsigned src_pitch,
-                    unsigned src_width,
-                    unsigned src_height,
-                    unsigned src_x_offset,
-                    unsigned src_y_offset,
-                    struct radeon_bo *dst_bo,
-                    intptr_t dst_offset,
-                    gl_format dst_mesaformat,
-                    unsigned dst_pitch,
-                    unsigned dst_width,
-                    unsigned dst_height,
-                    unsigned dst_x_offset,
-                    unsigned dst_y_offset,
-                    unsigned reg_width,
-                    unsigned reg_height,
-                    unsigned flip_y)
+unsigned r200_blit(GLcontext *ctx,
+                   struct radeon_bo *src_bo,
+                   intptr_t src_offset,
+                   gl_format src_mesaformat,
+                   unsigned src_pitch,
+                   unsigned src_width,
+                   unsigned src_height,
+                   unsigned src_x_offset,
+                   unsigned src_y_offset,
+                   struct radeon_bo *dst_bo,
+                   intptr_t dst_offset,
+                   gl_format dst_mesaformat,
+                   unsigned dst_pitch,
+                   unsigned dst_width,
+                   unsigned dst_height,
+                   unsigned dst_x_offset,
+                   unsigned dst_y_offset,
+                   unsigned reg_width,
+                   unsigned reg_height,
+                   unsigned flip_y)
 {
+    struct r200_context *r200 = R200_CONTEXT(ctx);
+
     if (!is_blit_supported(dst_mesaformat))
         return GL_FALSE;
 
@@ -396,7 +398,7 @@ GLboolean r200_blit(struct r200_context *r200,
                      reg_width, reg_height,
                      flip_y);
 
-    radeonFlush(r200->radeon.glCtx);
+    radeonFlush(ctx);
 
     return GL_TRUE;
 }
index 2d0e893623ffdb81cf2457d814f1826fc317da86..38487266ae1ff08cd535f1e8aa6f0e5c8a0801c5 100644 (file)
 
 void r200_blit_init(struct r200_context *r200);
 
-GLboolean r200_blit(struct r200_context *r200,
-                    struct radeon_bo *src_bo,
-                    intptr_t src_offset,
-                    gl_format src_mesaformat,
-                    unsigned src_pitch,
-                    unsigned src_width,
-                    unsigned src_height,
-                    unsigned src_x_offset,
-                    unsigned src_y_offset,
-                    struct radeon_bo *dst_bo,
-                    intptr_t dst_offset,
-                    gl_format dst_mesaformat,
-                    unsigned dst_pitch,
-                    unsigned dst_width,
-                    unsigned dst_height,
-                    unsigned dst_x_offset,
-                    unsigned dst_y_offset,
-                    unsigned width,
-                    unsigned height,
-                    unsigned flip_y);
+unsigned r200_blit(GLcontext *ctx,
+                   struct radeon_bo *src_bo,
+                   intptr_t src_offset,
+                   gl_format src_mesaformat,
+                   unsigned src_pitch,
+                   unsigned src_width,
+                   unsigned src_height,
+                   unsigned src_x_offset,
+                   unsigned src_y_offset,
+                   struct radeon_bo *dst_bo,
+                   intptr_t dst_offset,
+                   gl_format dst_mesaformat,
+                   unsigned dst_pitch,
+                   unsigned dst_width,
+                   unsigned dst_height,
+                   unsigned dst_x_offset,
+                   unsigned dst_y_offset,
+                   unsigned width,
+                   unsigned height,
+                   unsigned flip_y);
 
 #endif // R200_BLIT_H
index 217004c26507aa6c0281c5f17dd1b480bf60edc1..3d6d0f5ec0dd17854ed83da84acb9769f0d75d2e 100644 (file)
@@ -61,6 +61,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "r200_maos.h"
 #include "r200_vertprog.h"
 #include "radeon_queryobj.h"
+#include "r200_blit.h"
 
 #include "radeon_span.h"
 
@@ -268,6 +269,7 @@ static void r200_init_vtbl(radeonContextPtr radeon)
    radeon->vtbl.fallback = r200Fallback;
    radeon->vtbl.update_scissor = r200_vtbl_update_scissor;
    radeon->vtbl.emit_query_finish = r200_emit_query_finish;
+   radeon->vtbl.blit = r200_blit;
 }
 
 
@@ -327,7 +329,7 @@ GLboolean r200CreateContext( const __GLcontextModes *glVisual,
    r200InitDriverFuncs(&functions);
    r200InitIoctlFuncs(&functions);
    r200InitStateFuncs(&functions);
-   r200InitTextureFuncs(&functions);
+   r200InitTextureFuncs(&rmesa->radeon, &functions);
    r200InitShaderFuncs(&functions);
    radeonInitQueryObjFunctions(&functions);
 
index 5b87ba6ccdf39e888e973a120995436828511e4d..0916df6476576eaa6e7a6231b86c5bf2fde4251e 100644 (file)
@@ -477,7 +477,7 @@ static struct gl_texture_object *r200NewTextureObject(GLcontext * ctx,
 
 
 
-void r200InitTextureFuncs( struct dd_function_table *functions )
+void r200InitTextureFuncs( 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.
@@ -511,6 +511,11 @@ void r200InitTextureFuncs( 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;
 
    functions->NewTextureImage = radeonNewTextureImage;
index e122de6e5edd7665df7a3d23001c2db12c866070..1a1e7038df62be18d88974916da7bd2456613dfc 100644 (file)
@@ -48,7 +48,7 @@ extern int r200UploadTexImages( r200ContextPtr rmesa, radeonTexObjPtr t, GLuint
 
 extern void r200DestroyTexObj( r200ContextPtr rmesa, radeonTexObjPtr t );
 
-extern void r200InitTextureFuncs( struct dd_function_table *functions );
+extern void r200InitTextureFuncs( radeonContextPtr radeon, struct dd_function_table *functions );
 
 extern void r200UpdateFragmentShader( GLcontext *ctx );
 
diff --git a/src/mesa/drivers/dri/r200/r200_texcopy.c b/src/mesa/drivers/dri/r200/r200_texcopy.c
deleted file mode 100644 (file)
index cdb6cd7..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (C) 2009 Maciej Cencora <m.cencora@gmail.com>
- *
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "radeon_common.h"
-#include "r200_context.h"
-
-#include "main/image.h"
-#include "main/teximage.h"
-#include "main/texstate.h"
-#include "drivers/common/meta.h"
-
-#include "radeon_mipmap_tree.h"
-#include "r200_blit.h"
-#include <main/debug.h>
-
-// TODO:
-// need to pass correct pitch for small dst textures!
-static GLboolean
-do_copy_texsubimage(GLcontext *ctx,
-                    GLenum target, GLint level,
-                    struct radeon_tex_obj *tobj,
-                    radeon_texture_image *timg,
-                    GLint dstx, GLint dsty,
-                    GLint x, GLint y,
-                    GLsizei width, GLsizei height)
-{
-    struct r200_context *r200 = R200_CONTEXT(ctx);
-    struct radeon_renderbuffer *rrb;
-
-    if (_mesa_get_format_bits(timg->base.TexFormat, GL_DEPTH_BITS) > 0) {
-        rrb = radeon_get_depthbuffer(&r200->radeon);
-    } else {
-        rrb = radeon_get_colorbuffer(&r200->radeon);
-    }
-
-    if (!timg->mt) {
-        radeon_validate_texture_miptree(ctx, &tobj->base);
-    }
-
-    assert(rrb && rrb->bo);
-    assert(timg->mt->bo);
-    assert(timg->base.Width >= dstx + width);
-    assert(timg->base.Height >= dsty + height);
-
-    intptr_t src_offset = rrb->draw_offset;
-    intptr_t dst_offset = radeon_miptree_image_offset(timg->mt, _mesa_tex_target_to_face(target), level);
-
-    if (src_offset % 32 || dst_offset % 32) {
-        return GL_FALSE;
-    }
-
-    if (0) {
-        fprintf(stderr, "%s: copying to face %d, level %d\n",
-                __FUNCTION__, _mesa_tex_target_to_face(target), level);
-        fprintf(stderr, "to: x %d, y %d, offset %d\n", dstx, dsty, (uint32_t) dst_offset);
-        fprintf(stderr, "from (%dx%d) width %d, height %d, offset %d, pitch %d\n",
-                x, y, rrb->base.Width, rrb->base.Height, (uint32_t) src_offset, rrb->pitch/rrb->cpp);
-        fprintf(stderr, "src size %d, dst size %d\n", rrb->bo->size, timg->mt->bo->size);
-
-    }
-
-    /* blit from src buffer to texture */
-    return r200_blit(r200, rrb->bo, src_offset, rrb->base.Format, rrb->pitch,
-                     rrb->base.Width, rrb->base.Height, x, y,
-                     timg->mt->bo, dst_offset, timg->base.TexFormat,
-                     timg->base.Width, timg->base.Width, timg->base.Height,
-                     dstx, dsty, width, height, 1);
-}
-
-static void
-r200CopyTexImage2D(GLcontext *ctx, GLenum target, GLint level,
-                   GLenum internalFormat,
-                   GLint x, GLint y, GLsizei width, GLsizei height,
-                   GLint border)
-{
-    struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
-    struct gl_texture_object *texObj =
-        _mesa_select_tex_object(ctx, texUnit, target);
-    struct gl_texture_image *texImage =
-        _mesa_select_tex_image(ctx, texObj, target, level);
-    int srcx, srcy, dstx, dsty;
-
-    if (border)
-        goto fail;
-
-    /* Setup or redefine the texture object, mipmap tree and texture
-     * image.  Don't populate yet.
-     */
-    ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
-                           width, height, border,
-                           GL_RGBA, GL_UNSIGNED_BYTE, NULL,
-                           &ctx->DefaultPacking, texObj, texImage);
-
-    srcx = x;
-    srcy = y;
-    dstx = 0;
-    dsty = 0;
-    if (!_mesa_clip_copytexsubimage(ctx,
-                                    &dstx, &dsty,
-                                    &srcx, &srcy,
-                                    &width, &height)) {
-        return;
-    }
-
-    if (!do_copy_texsubimage(ctx, target, level,
-                             radeon_tex_obj(texObj), (radeon_texture_image *)texImage,
-                             0, 0, x, y, width, height)) {
-        goto fail;
-    }
-
-    return;
-
-fail:
-    _mesa_meta_CopyTexImage2D(ctx, target, level, internalFormat, x, y,
-                              width, height, border);
-}
-
-static void
-r200CopyTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
-                      GLint xoffset, GLint yoffset,
-                      GLint x, GLint y,
-                      GLsizei width, GLsizei height)
-{
-    struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
-    struct gl_texture_object *texObj = _mesa_select_tex_object(ctx, texUnit, target);
-    struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texObj, target, level);
-
-    if (!do_copy_texsubimage(ctx, target, level,
-                             radeon_tex_obj(texObj), (radeon_texture_image *)texImage,
-                             xoffset, yoffset, x, y, width, height)) {
-
-       //DEBUG_FALLBACKS
-
-        _mesa_meta_CopyTexSubImage2D(ctx, target, level,
-                                     xoffset, yoffset, x, y, width, height);
-    }
-}
-
-
-void r200_init_texcopy_functions(struct dd_function_table *table)
-{
-    table->CopyTexImage2D = r200CopyTexImage2D;
-    table->CopyTexSubImage2D = r200CopyTexSubImage2D;
-}