Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2003 VMware, Inc.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28. #include "main/mtypes.h"
  29. #include "main/enums.h"
  30. #include "main/image.h"
  31. #include "main/teximage.h"
  32. #include "main/texobj.h"
  33. #include "main/texstate.h"
  34. #include "main/fbobject.h"
  35.  
  36. #include "drivers/common/meta.h"
  37.  
  38. #include "intel_screen.h"
  39. #include "intel_mipmap_tree.h"
  40. #include "intel_fbo.h"
  41. #include "intel_tex.h"
  42. #include "intel_blit.h"
  43. #include "brw_context.h"
  44.  
  45. #define FILE_DEBUG_FLAG DEBUG_TEXTURE
  46.  
  47.  
  48. static bool
  49. intel_copy_texsubimage(struct brw_context *brw,
  50.                        struct intel_texture_image *intelImage,
  51.                        GLint dstx, GLint dsty, GLint slice,
  52.                        struct intel_renderbuffer *irb,
  53.                        GLint x, GLint y, GLsizei width, GLsizei height)
  54. {
  55.    const GLenum internalFormat = intelImage->base.Base.InternalFormat;
  56.    bool ret;
  57.  
  58.    intel_prepare_render(brw);
  59.  
  60.    /* glCopyTexSubImage() can be called on a multisampled renderbuffer (if
  61.     * that renderbuffer is associated with the window system framebuffer),
  62.     * however the hardware blitter can't handle this case, so fall back to
  63.     * meta (which can, since it uses ReadPixels).
  64.     */
  65.    if (irb->Base.Base.NumSamples != 0)
  66.       return false;
  67.  
  68.    /* glCopyTexSubImage() can't be called on a multisampled texture. */
  69.    assert(intelImage->base.Base.NumSamples == 0);
  70.  
  71.    if (!intelImage->mt || !irb || !irb->mt) {
  72.       if (unlikely(INTEL_DEBUG & DEBUG_PERF))
  73.          fprintf(stderr, "%s fail %p %p (0x%08x)\n",
  74.                  __func__, intelImage->mt, irb, internalFormat);
  75.       return false;
  76.    }
  77.  
  78.    /* account for view parameters and face index */
  79.    int dst_level = intelImage->base.Base.Level +
  80.                    intelImage->base.Base.TexObject->MinLevel;
  81.    int dst_slice = slice + intelImage->base.Base.Face +
  82.                    intelImage->base.Base.TexObject->MinLayer;
  83.  
  84.    _mesa_unlock_texture(&brw->ctx, intelImage->base.Base.TexObject);
  85.  
  86.    /* blit from src buffer to texture */
  87.    ret = intel_miptree_blit(brw,
  88.                             irb->mt, irb->mt_level, irb->mt_layer,
  89.                             x, y, irb->Base.Base.Name == 0,
  90.                             intelImage->mt, dst_level, dst_slice,
  91.                             dstx, dsty, false,
  92.                             width, height, GL_COPY);
  93.  
  94.    _mesa_lock_texture(&brw->ctx, intelImage->base.Base.TexObject);
  95.  
  96.    return ret;
  97. }
  98.  
  99.  
  100. static void
  101. intelCopyTexSubImage(struct gl_context *ctx, GLuint dims,
  102.                      struct gl_texture_image *texImage,
  103.                      GLint xoffset, GLint yoffset, GLint slice,
  104.                      struct gl_renderbuffer *rb,
  105.                      GLint x, GLint y,
  106.                      GLsizei width, GLsizei height)
  107. {
  108.    struct brw_context *brw = brw_context(ctx);
  109.  
  110.    /* Try BLORP first.  It can handle almost everything. */
  111.    if (brw_blorp_copytexsubimage(brw, rb, texImage, slice, x, y,
  112.                                  xoffset, yoffset, width, height))
  113.       return;
  114.  
  115.    /* Next, try the BLT engine. */
  116.    if (intel_copy_texsubimage(brw,
  117.                               intel_texture_image(texImage),
  118.                               xoffset, yoffset, slice,
  119.                               intel_renderbuffer(rb), x, y, width, height)) {
  120.       return;
  121.    }
  122.  
  123.    /* Finally, fall back to meta.  This will likely be slow. */
  124.    perf_debug("%s - fallback to swrast\n", __func__);
  125.    _mesa_meta_CopyTexSubImage(ctx, dims, texImage,
  126.                               xoffset, yoffset, slice,
  127.                               rb, x, y, width, height);
  128. }
  129.  
  130.  
  131. void
  132. intelInitTextureCopyImageFuncs(struct dd_function_table *functions)
  133. {
  134.    functions->CopyTexSubImage = intelCopyTexSubImage;
  135. }
  136.