i965/vs: Move the flag for whether to use the new backend to the context.
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex_subimage.c
1
2 /**************************************************************************
3 *
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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 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.
26 *
27 **************************************************************************/
28
29 #include "main/mtypes.h"
30 #include "main/pbo.h"
31 #include "main/texobj.h"
32 #include "main/texstore.h"
33 #include "main/texcompress.h"
34 #include "main/enums.h"
35
36 #include "intel_context.h"
37 #include "intel_tex.h"
38 #include "intel_mipmap_tree.h"
39 #include "intel_blit.h"
40
41 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
42
43 static void
44 intelTexSubimage(struct gl_context * ctx,
45 GLint dims,
46 GLenum target, GLint level,
47 GLint xoffset, GLint yoffset, GLint zoffset,
48 GLint width, GLint height, GLint depth,
49 GLsizei imageSize,
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)
54 {
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;
60
61 /* Try to do a blit upload of the subimage if the texture is
62 * currently busy.
63 */
64 if (intelImage->mt &&
65 intelImage->mt->region->tiling != I915_TILING_Y &&
66 intel->gen < 6 && target == GL_TEXTURE_2D &&
67 drm_intel_bo_busy(dst_bo)) {
68 unsigned long pitch;
69 uint32_t tiling_mode = I915_TILING_NONE;
70
71 DBG("BLT subimage %s target %s level %d offset %d,%d %dx%d\n",
72 __FUNCTION__,
73 _mesa_lookup_enum_by_nr(target),
74 level, xoffset, yoffset, width, height);
75
76 pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
77 format, type, pixels, packing,
78 "glTexSubImage");
79 if (!pixels)
80 return;
81
82 temp_bo = drm_intel_bo_alloc_tiled(intel->bufmgr,
83 "subimage blit bo",
84 width, height,
85 intelImage->mt->cpp,
86 &tiling_mode,
87 &pitch,
88 0);
89 if (temp_bo == NULL) {
90 _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
91 return;
92 }
93
94 if (drm_intel_gem_bo_map_gtt(temp_bo)) {
95 _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
96 return;
97 }
98
99 texImage->Data = temp_bo->virtual;
100 texImage->ImageOffsets[0] = 0;
101 dstRowStride = pitch;
102
103 intel_miptree_get_image_offset(intelImage->mt, level,
104 intelImage->base.Face, 0,
105 &blit_x, &blit_y);
106 blit_x += xoffset;
107 blit_y += yoffset;
108 xoffset = 0;
109 yoffset = 0;
110
111 if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
112 texImage->TexFormat,
113 texImage->Data,
114 xoffset, yoffset, zoffset,
115 dstRowStride,
116 texImage->ImageOffsets,
117 width, height, depth,
118 format, type, pixels, packing)) {
119 _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
120 }
121
122 GLboolean ret;
123 unsigned int dst_pitch = intelImage->mt->region->pitch *
124 intelImage->mt->cpp;
125
126 drm_intel_gem_bo_unmap_gtt(temp_bo);
127 texImage->Data = NULL;
128
129 ret = intelEmitCopyBlit(intel,
130 intelImage->mt->cpp,
131 dstRowStride / intelImage->mt->cpp,
132 temp_bo, 0, GL_FALSE,
133 dst_pitch / intelImage->mt->cpp, dst_bo, 0,
134 intelImage->mt->region->tiling,
135 0, 0, blit_x, blit_y, width, height,
136 GL_COPY);
137 assert(ret);
138
139 drm_intel_bo_unreference(temp_bo);
140 _mesa_unmap_teximage_pbo(ctx, packing);
141 return;
142 }
143
144 _mesa_store_texsubimage3d(ctx, target, level,
145 xoffset, yoffset, zoffset,
146 width, height, depth,
147 format, type, pixels,
148 packing, texObj, texImage);
149 }
150
151
152 static void
153 intelTexSubImage3D(struct gl_context * ctx,
154 GLenum target,
155 GLint level,
156 GLint xoffset, GLint yoffset, GLint zoffset,
157 GLsizei width, GLsizei height, GLsizei depth,
158 GLenum format, GLenum type,
159 const GLvoid * pixels,
160 const struct gl_pixelstore_attrib *packing,
161 struct gl_texture_object *texObj,
162 struct gl_texture_image *texImage)
163 {
164 intelTexSubimage(ctx, 3,
165 target, level,
166 xoffset, yoffset, zoffset,
167 width, height, depth, 0,
168 format, type, pixels, packing, texObj, texImage);
169 }
170
171
172 static void
173 intelTexSubImage2D(struct gl_context * ctx,
174 GLenum target,
175 GLint level,
176 GLint xoffset, GLint yoffset,
177 GLsizei width, GLsizei height,
178 GLenum format, GLenum type,
179 const GLvoid * pixels,
180 const struct gl_pixelstore_attrib *packing,
181 struct gl_texture_object *texObj,
182 struct gl_texture_image *texImage)
183 {
184 intelTexSubimage(ctx, 2,
185 target, level,
186 xoffset, yoffset, 0,
187 width, height, 1, 0,
188 format, type, pixels, packing, texObj, texImage);
189 }
190
191
192 static void
193 intelTexSubImage1D(struct gl_context * ctx,
194 GLenum target,
195 GLint level,
196 GLint xoffset,
197 GLsizei width,
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)
203 {
204 intelTexSubimage(ctx, 1,
205 target, level,
206 xoffset, 0, 0,
207 width, 1, 1, 0,
208 format, type, pixels, packing, texObj, texImage);
209 }
210
211 void
212 intelInitTextureSubImageFuncs(struct dd_function_table *functions)
213 {
214 functions->TexSubImage1D = intelTexSubImage1D;
215 functions->TexSubImage2D = intelTexSubImage2D;
216 functions->TexSubImage3D = intelTexSubImage3D;
217 }