2 /**************************************************************************
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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 TUNGSTEN GRAPHICS 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.
27 **************************************************************************/
29 #include "main/mtypes.h"
31 #include "main/texobj.h"
32 #include "main/texstore.h"
33 #include "main/texcompress.h"
34 #include "main/enums.h"
36 #include "intel_context.h"
37 #include "intel_tex.h"
38 #include "intel_mipmap_tree.h"
39 #include "intel_blit.h"
41 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
44 intel_blit_texsubimage(struct gl_context
* ctx
,
45 GLenum target
, GLint level
,
46 GLint xoffset
, GLint yoffset
,
47 GLint width
, GLint height
,
48 GLenum format
, GLenum type
, const void *pixels
,
49 const struct gl_pixelstore_attrib
*packing
,
50 struct gl_texture_object
*texObj
,
51 struct gl_texture_image
*texImage
)
53 struct intel_context
*intel
= intel_context(ctx
);
54 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
55 GLuint dstRowStride
= 0;
56 drm_intel_bo
*temp_bo
= NULL
;
57 unsigned int blit_x
= 0, blit_y
= 0;
59 uint32_t tiling_mode
= I915_TILING_NONE
;
62 /* Try to do a blit upload of the subimage if the texture is
68 /* The blitter can't handle Y tiling */
69 if (intelImage
->mt
->region
->tiling
== I915_TILING_Y
)
72 if (target
!= GL_TEXTURE_2D
)
75 /* On gen6, it's probably not worth swapping to the blit ring to do
76 * this because of all the overhead involved.
81 if (!drm_intel_bo_busy(intelImage
->mt
->region
->bo
))
84 DBG("BLT subimage %s target %s level %d offset %d,%d %dx%d\n",
86 _mesa_lookup_enum_by_nr(target
),
87 level
, xoffset
, yoffset
, width
, height
);
89 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1,
90 format
, type
, pixels
, packing
,
95 temp_bo
= drm_intel_bo_alloc_tiled(intel
->bufmgr
,
102 if (temp_bo
== NULL
) {
103 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "intelTexSubImage");
107 if (drm_intel_gem_bo_map_gtt(temp_bo
)) {
108 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "intelTexSubImage");
112 dstMap
= temp_bo
->virtual;
113 dstRowStride
= pitch
;
115 intel_miptree_get_image_offset(intelImage
->mt
, level
,
116 intelImage
->base
.Base
.Face
, 0,
123 if (!_mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
129 format
, type
, pixels
, packing
)) {
130 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "intelTexSubImage");
134 unsigned int dst_pitch
= intelImage
->mt
->region
->pitch
*
137 drm_intel_gem_bo_unmap_gtt(temp_bo
);
139 ret
= intelEmitCopyBlit(intel
,
141 dstRowStride
/ intelImage
->mt
->cpp
,
142 temp_bo
, 0, GL_FALSE
,
143 dst_pitch
/ intelImage
->mt
->cpp
,
144 intelImage
->mt
->region
->bo
, 0,
145 intelImage
->mt
->region
->tiling
,
146 0, 0, blit_x
, blit_y
, width
, height
,
150 drm_intel_bo_unreference(temp_bo
);
151 _mesa_unmap_teximage_pbo(ctx
, packing
);
157 intelTexSubImage2D(struct gl_context
* ctx
,
160 GLint xoffset
, GLint yoffset
,
161 GLsizei width
, GLsizei height
,
162 GLenum format
, GLenum type
,
163 const GLvoid
* pixels
,
164 const struct gl_pixelstore_attrib
*packing
,
165 struct gl_texture_object
*texObj
,
166 struct gl_texture_image
*texImage
)
168 if (!intel_blit_texsubimage(ctx
, target
, level
,
171 format
, type
, pixels
, packing
,
173 _mesa_store_texsubimage2d(ctx
, target
, level
,
176 format
, type
, pixels
,
177 packing
, texObj
, texImage
);
182 intelInitTextureSubImageFuncs(struct dd_function_table
*functions
)
184 functions
->TexSubImage2D
= intelTexSubImage2D
;