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"
30 #include "main/texobj.h"
31 #include "main/texstore.h"
32 #include "main/texcompress.h"
33 #include "main/enums.h"
35 #include "intel_context.h"
36 #include "intel_tex.h"
37 #include "intel_mipmap_tree.h"
38 #include "intel_blit.h"
40 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
43 intelTexSubimage(GLcontext
* ctx
,
45 GLenum target
, GLint level
,
46 GLint xoffset
, GLint yoffset
, GLint zoffset
,
47 GLint width
, GLint height
, GLint depth
,
49 GLenum format
, GLenum type
, const void *pixels
,
50 const struct gl_pixelstore_attrib
*packing
,
51 struct gl_texture_object
*texObj
,
52 struct gl_texture_image
*texImage
,
55 struct intel_context
*intel
= intel_context(ctx
);
56 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
57 GLuint dstRowStride
= 0;
58 drm_intel_bo
*temp_bo
= NULL
, *dst_bo
= NULL
;
59 unsigned int blit_x
= 0, blit_y
= 0;
61 DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__
,
62 _mesa_lookup_enum_by_nr(target
),
63 level
, xoffset
, yoffset
, width
, height
);
68 pixels
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
,
70 "glCompressedTexImage");
72 pixels
= _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
73 format
, type
, pixels
, packing
,
78 intel_prepare_render(intel
);
80 /* Map buffer if necessary. Need to lock to prevent other contexts
81 * from uploading the buffer under us.
84 dst_bo
= intel_region_buffer(intel
, intelImage
->mt
->region
,
88 intelImage
->mt
->region
->tiling
!= I915_TILING_Y
&&
89 intel
->gen
< 6 && target
== GL_TEXTURE_2D
&&
90 drm_intel_bo_busy(dst_bo
))
93 uint32_t tiling_mode
= I915_TILING_NONE
;
94 temp_bo
= drm_intel_bo_alloc_tiled(intel
->bufmgr
,
101 drm_intel_gem_bo_map_gtt(temp_bo
);
102 texImage
->Data
= temp_bo
->virtual;
103 texImage
->ImageOffsets
[0] = 0;
104 dstRowStride
= pitch
;
106 intel_miptree_get_image_offset(intelImage
->mt
, level
,
114 texImage
->Data
= intel_miptree_image_map(intel
,
119 texImage
->ImageOffsets
);
122 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
124 _mesa_format_row_stride(texImage
->TexFormat
, width
);
128 dstRowStride
= texImage
->RowStride
* _mesa_get_format_bytes(texImage
->TexFormat
);
132 assert(dstRowStride
);
135 if (intelImage
->mt
) {
136 struct intel_region
*dst
= intelImage
->mt
->region
;
138 _mesa_copy_rect(texImage
->Data
, dst
->cpp
, dst
->pitch
,
139 xoffset
, yoffset
/ 4,
140 (width
+ 3) & ~3, (height
+ 3) / 4,
141 pixels
, (width
+ 3) & ~3, 0, 0);
144 memcpy(texImage
->Data
, pixels
, imageSize
);
148 if (!_mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
151 xoffset
, yoffset
, zoffset
,
153 texImage
->ImageOffsets
,
154 width
, height
, depth
,
155 format
, type
, pixels
, packing
)) {
156 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "intelTexSubImage");
161 unsigned int dst_pitch
= intelImage
->mt
->region
->pitch
*
164 drm_intel_gem_bo_unmap_gtt(temp_bo
);
165 texImage
->Data
= NULL
;
167 ret
= intelEmitCopyBlit(intel
,
169 dstRowStride
/ intelImage
->mt
->cpp
,
170 temp_bo
, 0, GL_FALSE
,
171 dst_pitch
/ intelImage
->mt
->cpp
, dst_bo
, 0,
172 intelImage
->mt
->region
->tiling
,
173 0, 0, blit_x
, blit_y
, width
, height
,
179 _mesa_unmap_teximage_pbo(ctx
, packing
);
182 drm_intel_bo_unreference(temp_bo
);
184 } else if (intelImage
->mt
) {
185 intel_miptree_image_unmap(intel
, intelImage
->mt
);
186 texImage
->Data
= NULL
;
192 intelTexSubImage3D(GLcontext
* ctx
,
195 GLint xoffset
, GLint yoffset
, GLint zoffset
,
196 GLsizei width
, GLsizei height
, GLsizei depth
,
197 GLenum format
, GLenum type
,
198 const GLvoid
* pixels
,
199 const struct gl_pixelstore_attrib
*packing
,
200 struct gl_texture_object
*texObj
,
201 struct gl_texture_image
*texImage
)
203 intelTexSubimage(ctx
, 3,
205 xoffset
, yoffset
, zoffset
,
206 width
, height
, depth
, 0,
207 format
, type
, pixels
, packing
, texObj
, texImage
, GL_FALSE
);
212 intelTexSubImage2D(GLcontext
* ctx
,
215 GLint xoffset
, GLint yoffset
,
216 GLsizei width
, GLsizei height
,
217 GLenum format
, GLenum type
,
218 const GLvoid
* pixels
,
219 const struct gl_pixelstore_attrib
*packing
,
220 struct gl_texture_object
*texObj
,
221 struct gl_texture_image
*texImage
)
223 intelTexSubimage(ctx
, 2,
227 format
, type
, pixels
, packing
, texObj
, texImage
, GL_FALSE
);
232 intelTexSubImage1D(GLcontext
* ctx
,
237 GLenum format
, GLenum type
,
238 const GLvoid
* pixels
,
239 const struct gl_pixelstore_attrib
*packing
,
240 struct gl_texture_object
*texObj
,
241 struct gl_texture_image
*texImage
)
243 intelTexSubimage(ctx
, 1,
247 format
, type
, pixels
, packing
, texObj
, texImage
, GL_FALSE
);
251 intelCompressedTexSubImage2D(GLcontext
* ctx
,
254 GLint xoffset
, GLint yoffset
,
255 GLsizei width
, GLsizei height
,
256 GLenum format
, GLsizei imageSize
,
257 const GLvoid
* pixels
,
258 struct gl_texture_object
*texObj
,
259 struct gl_texture_image
*texImage
)
261 intelTexSubimage(ctx
, 2,
264 width
, height
, 1, imageSize
,
265 format
, 0, pixels
, &ctx
->Unpack
, texObj
, texImage
, GL_TRUE
);
271 intelInitTextureSubImageFuncs(struct dd_function_table
*functions
)
273 functions
->TexSubImage1D
= intelTexSubImage1D
;
274 functions
->TexSubImage2D
= intelTexSubImage2D
;
275 functions
->TexSubImage3D
= intelTexSubImage3D
;
276 functions
->CompressedTexSubImage2D
= intelCompressedTexSubImage2D
;