• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /**************************************************************************
3  *
4  * Copyright 2003 VMware, Inc.
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sub license, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  *
27  **************************************************************************/
28 
29 #include "main/bufferobj.h"
30 #include "main/macros.h"
31 #include "main/mtypes.h"
32 #include "main/pbo.h"
33 #include "main/texobj.h"
34 #include "main/texstore.h"
35 #include "main/texcompress.h"
36 #include "main/enums.h"
37 
38 #include "intel_batchbuffer.h"
39 #include "intel_context.h"
40 #include "intel_tex.h"
41 #include "intel_mipmap_tree.h"
42 #include "intel_blit.h"
43 
44 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
45 
46 static bool
intel_blit_texsubimage(struct gl_context * ctx,struct gl_texture_image * texImage,GLint xoffset,GLint yoffset,GLint width,GLint height,GLenum format,GLenum type,const void * pixels,const struct gl_pixelstore_attrib * packing)47 intel_blit_texsubimage(struct gl_context * ctx,
48 		       struct gl_texture_image *texImage,
49 		       GLint xoffset, GLint yoffset,
50 		       GLint width, GLint height,
51 		       GLenum format, GLenum type, const void *pixels,
52 		       const struct gl_pixelstore_attrib *packing)
53 {
54    struct intel_context *intel = intel_context(ctx);
55    struct intel_texture_image *intelImage = intel_texture_image(texImage);
56 
57    /* Try to do a blit upload of the subimage if the texture is
58     * currently busy.
59     */
60    if (!intelImage->mt)
61       return false;
62 
63    /* The blitter can't handle Y tiling */
64    if (intelImage->mt->region->tiling == I915_TILING_Y)
65       return false;
66 
67    if (texImage->TexObject->Target != GL_TEXTURE_2D)
68       return false;
69 
70    if (!drm_intel_bo_busy(intelImage->mt->region->bo))
71       return false;
72 
73    DBG("BLT subimage %s target %s level %d offset %d,%d %dx%d\n",
74        __func__,
75        _mesa_enum_to_string(texImage->TexObject->Target),
76        texImage->Level, xoffset, yoffset, width, height);
77 
78    pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1,
79 					format, type, pixels, packing,
80 					"glTexSubImage");
81    if (!pixels)
82       return false;
83 
84    struct intel_mipmap_tree *temp_mt =
85       intel_miptree_create(intel, GL_TEXTURE_2D, texImage->TexFormat,
86                            0, 0,
87                            width, height, 1,
88                            false, INTEL_MIPTREE_TILING_NONE);
89    if (!temp_mt)
90       goto err;
91 
92    GLubyte *dst = intel_miptree_map_raw(intel, temp_mt);
93    if (!dst)
94       goto err;
95 
96    if (!_mesa_texstore(ctx, 2, texImage->_BaseFormat,
97 		       texImage->TexFormat,
98 		       temp_mt->region->pitch,
99 		       &dst,
100 		       width, height, 1,
101 		       format, type, pixels, packing)) {
102       _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
103    }
104 
105    intel_miptree_unmap_raw(temp_mt);
106 
107    bool ret;
108 
109    ret = intel_miptree_blit(intel,
110                             temp_mt, 0, 0,
111                             0, 0, false,
112                             intelImage->mt, texImage->Level, texImage->Face,
113                             xoffset, yoffset, false,
114                             width, height, COLOR_LOGICOP_COPY);
115    assert(ret);
116 
117    intel_miptree_release(&temp_mt);
118    _mesa_unmap_teximage_pbo(ctx, packing);
119 
120    return ret;
121 
122 err:
123    _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
124    intel_miptree_release(&temp_mt);
125    _mesa_unmap_teximage_pbo(ctx, packing);
126    return false;
127 }
128 
129 static void
intelTexSubImage(struct gl_context * ctx,GLuint dims,struct gl_texture_image * texImage,GLint xoffset,GLint yoffset,GLint zoffset,GLsizei width,GLsizei height,GLsizei depth,GLenum format,GLenum type,const GLvoid * pixels,const struct gl_pixelstore_attrib * packing)130 intelTexSubImage(struct gl_context * ctx,
131                  GLuint dims,
132                  struct gl_texture_image *texImage,
133                  GLint xoffset, GLint yoffset, GLint zoffset,
134                  GLsizei width, GLsizei height, GLsizei depth,
135                  GLenum format, GLenum type,
136                  const GLvoid * pixels,
137                  const struct gl_pixelstore_attrib *packing)
138 {
139    /* The intel_blit_texsubimage() function only handles 2D images */
140    if (dims != 2 || !intel_blit_texsubimage(ctx, texImage,
141 			       xoffset, yoffset,
142 			       width, height,
143 			       format, type, pixels, packing)) {
144       _mesa_store_texsubimage(ctx, dims, texImage,
145                               xoffset, yoffset, zoffset,
146                               width, height, depth,
147                               format, type, pixels, packing);
148    }
149 }
150 
151 void
intelInitTextureSubImageFuncs(struct dd_function_table * functions)152 intelInitTextureSubImageFuncs(struct dd_function_table *functions)
153 {
154    functions->TexSubImage = intelTexSubImage;
155 }
156