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 intelTexSubimage(struct gl_context
* ctx
,
46 GLenum target
, GLint level
,
47 GLint xoffset
, GLint yoffset
, GLint zoffset
,
48 GLint width
, GLint height
, GLint depth
,
50 GLenum format
, GLenum type
, const void *pixels
,
51 const struct gl_pixelstore_attrib
*packing
,
52 struct gl_texture_object
*texObj
,
53 struct gl_texture_image
*texImage
,
56 struct intel_context
*intel
= intel_context(ctx
);
57 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
58 GLuint dstRowStride
= 0;
59 drm_intel_bo
*temp_bo
= NULL
, *dst_bo
= NULL
;
60 unsigned int blit_x
= 0, blit_y
= 0;
62 DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__
,
63 _mesa_lookup_enum_by_nr(target
),
64 level
, xoffset
, yoffset
, width
, height
);
69 pixels
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
,
71 "glCompressedTexImage");
73 pixels
= _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
74 format
, type
, pixels
, packing
,
79 intel_prepare_render(intel
);
81 /* Map buffer if necessary. Need to lock to prevent other contexts
82 * from uploading the buffer under us.
85 dst_bo
= intel_region_buffer(intel
, intelImage
->mt
->region
,
89 intelImage
->mt
->region
->tiling
!= I915_TILING_Y
&&
90 intel
->gen
< 6 && target
== GL_TEXTURE_2D
&&
91 drm_intel_bo_busy(dst_bo
))
94 uint32_t tiling_mode
= I915_TILING_NONE
;
95 temp_bo
= drm_intel_bo_alloc_tiled(intel
->bufmgr
,
102 drm_intel_gem_bo_map_gtt(temp_bo
);
103 texImage
->Data
= temp_bo
->virtual;
104 texImage
->ImageOffsets
[0] = 0;
105 dstRowStride
= pitch
;
107 intel_miptree_get_image_offset(intelImage
->mt
, level
,
115 texImage
->Data
= intel_miptree_image_map(intel
,
120 texImage
->ImageOffsets
);
123 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
125 _mesa_format_row_stride(texImage
->TexFormat
, width
);
129 dstRowStride
= texImage
->RowStride
* _mesa_get_format_bytes(texImage
->TexFormat
);
133 assert(dstRowStride
);
136 if (intelImage
->mt
) {
137 struct intel_region
*dst
= intelImage
->mt
->region
;
139 _mesa_copy_rect(texImage
->Data
, dst
->cpp
, dst
->pitch
,
140 xoffset
, yoffset
/ 4,
141 (width
+ 3) & ~3, (height
+ 3) / 4,
142 pixels
, (width
+ 3) & ~3, 0, 0);
145 memcpy(texImage
->Data
, pixels
, imageSize
);
149 if (!_mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
152 xoffset
, yoffset
, zoffset
,
154 texImage
->ImageOffsets
,
155 width
, height
, depth
,
156 format
, type
, pixels
, packing
)) {
157 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "intelTexSubImage");
162 unsigned int dst_pitch
= intelImage
->mt
->region
->pitch
*
165 drm_intel_gem_bo_unmap_gtt(temp_bo
);
166 texImage
->Data
= NULL
;
168 ret
= intelEmitCopyBlit(intel
,
170 dstRowStride
/ intelImage
->mt
->cpp
,
171 temp_bo
, 0, GL_FALSE
,
172 dst_pitch
/ intelImage
->mt
->cpp
, dst_bo
, 0,
173 intelImage
->mt
->region
->tiling
,
174 0, 0, blit_x
, blit_y
, width
, height
,
180 _mesa_unmap_teximage_pbo(ctx
, packing
);
183 drm_intel_bo_unreference(temp_bo
);
185 } else if (intelImage
->mt
) {
186 intel_miptree_image_unmap(intel
, intelImage
->mt
);
187 texImage
->Data
= NULL
;
193 intelTexSubImage3D(struct gl_context
* ctx
,
196 GLint xoffset
, GLint yoffset
, GLint zoffset
,
197 GLsizei width
, GLsizei height
, GLsizei depth
,
198 GLenum format
, GLenum type
,
199 const GLvoid
* pixels
,
200 const struct gl_pixelstore_attrib
*packing
,
201 struct gl_texture_object
*texObj
,
202 struct gl_texture_image
*texImage
)
204 intelTexSubimage(ctx
, 3,
206 xoffset
, yoffset
, zoffset
,
207 width
, height
, depth
, 0,
208 format
, type
, pixels
, packing
, texObj
, texImage
, GL_FALSE
);
213 intelTexSubImage2D(struct gl_context
* ctx
,
216 GLint xoffset
, GLint yoffset
,
217 GLsizei width
, GLsizei height
,
218 GLenum format
, GLenum type
,
219 const GLvoid
* pixels
,
220 const struct gl_pixelstore_attrib
*packing
,
221 struct gl_texture_object
*texObj
,
222 struct gl_texture_image
*texImage
)
224 intelTexSubimage(ctx
, 2,
228 format
, type
, pixels
, packing
, texObj
, texImage
, GL_FALSE
);
233 intelTexSubImage1D(struct gl_context
* ctx
,
238 GLenum format
, GLenum type
,
239 const GLvoid
* pixels
,
240 const struct gl_pixelstore_attrib
*packing
,
241 struct gl_texture_object
*texObj
,
242 struct gl_texture_image
*texImage
)
244 intelTexSubimage(ctx
, 1,
248 format
, type
, pixels
, packing
, texObj
, texImage
, GL_FALSE
);
252 intelCompressedTexSubImage2D(struct gl_context
* ctx
,
255 GLint xoffset
, GLint yoffset
,
256 GLsizei width
, GLsizei height
,
257 GLenum format
, GLsizei imageSize
,
258 const GLvoid
* pixels
,
259 struct gl_texture_object
*texObj
,
260 struct gl_texture_image
*texImage
)
262 intelTexSubimage(ctx
, 2,
265 width
, height
, 1, imageSize
,
266 format
, 0, pixels
, &ctx
->Unpack
, texObj
, texImage
, GL_TRUE
);
272 intelInitTextureSubImageFuncs(struct dd_function_table
*functions
)
274 functions
->TexSubImage1D
= intelTexSubImage1D
;
275 functions
->TexSubImage2D
= intelTexSubImage2D
;
276 functions
->TexSubImage3D
= intelTexSubImage3D
;
277 functions
->CompressedTexSubImage2D
= intelCompressedTexSubImage2D
;