i965: Move the remaining intel code to the i965 directory.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_tex_copy.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "main/mtypes.h"
29 #include "main/enums.h"
30 #include "main/image.h"
31 #include "main/teximage.h"
32 #include "main/texstate.h"
33 #include "main/fbobject.h"
34
35 #include "drivers/common/meta.h"
36
37 #include "intel_screen.h"
38 #include "intel_context.h"
39 #include "intel_mipmap_tree.h"
40 #include "intel_regions.h"
41 #include "intel_fbo.h"
42 #include "intel_tex.h"
43 #include "intel_blit.h"
44 #ifndef I915
45 #include "brw_context.h"
46 #endif
47
48 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
49
50
51 static bool
52 intel_copy_texsubimage(struct intel_context *intel,
53 struct intel_texture_image *intelImage,
54 GLint dstx, GLint dsty, GLint slice,
55 struct intel_renderbuffer *irb,
56 GLint x, GLint y, GLsizei width, GLsizei height)
57 {
58 const GLenum internalFormat = intelImage->base.Base.InternalFormat;
59
60 intel_prepare_render(intel);
61
62 /* glCopyTexSubImage() can be called on a multisampled renderbuffer (if
63 * that renderbuffer is associated with the window system framebuffer),
64 * however the hardware blitter can't handle this case, so fall back to
65 * meta (which can, since it uses ReadPixels).
66 */
67 if (irb->Base.Base.NumSamples != 0)
68 return false;
69
70 /* glCopyTexSubImage() can't be called on a multisampled texture. */
71 assert(intelImage->base.Base.NumSamples == 0);
72
73 if (!intelImage->mt || !irb || !irb->mt) {
74 if (unlikely(INTEL_DEBUG & DEBUG_PERF))
75 fprintf(stderr, "%s fail %p %p (0x%08x)\n",
76 __FUNCTION__, intelImage->mt, irb, internalFormat);
77 return false;
78 }
79
80 /* blit from src buffer to texture */
81 if (!intel_miptree_blit(intel,
82 irb->mt, irb->mt_level, irb->mt_layer,
83 x, y, irb->Base.Base.Name == 0,
84 intelImage->mt, intelImage->base.Base.Level,
85 intelImage->base.Base.Face + slice,
86 dstx, dsty, false,
87 width, height, GL_COPY)) {
88 return false;
89 }
90
91 return true;
92 }
93
94
95 static void
96 intelCopyTexSubImage(struct gl_context *ctx, GLuint dims,
97 struct gl_texture_image *texImage,
98 GLint xoffset, GLint yoffset, GLint slice,
99 struct gl_renderbuffer *rb,
100 GLint x, GLint y,
101 GLsizei width, GLsizei height)
102 {
103 struct intel_context *intel = intel_context(ctx);
104
105 #ifndef I915
106 /* Try BLORP first. It can handle almost everything. */
107 if (brw_blorp_copytexsubimage(intel, rb, texImage, slice, x, y,
108 xoffset, yoffset, width, height))
109 return;
110 #endif
111
112 /* Next, try the BLT engine. */
113 if (intel_copy_texsubimage(intel,
114 intel_texture_image(texImage),
115 xoffset, yoffset, slice,
116 intel_renderbuffer(rb), x, y, width, height)) {
117 return;
118 }
119
120 /* Finally, fall back to meta. This will likely be slow. */
121 perf_debug("%s - fallback to swrast\n", __FUNCTION__);
122 _mesa_meta_CopyTexSubImage(ctx, dims, texImage,
123 xoffset, yoffset, slice,
124 rb, x, y, width, height);
125 }
126
127
128 void
129 intelInitTextureCopyImageFuncs(struct dd_function_table *functions)
130 {
131 functions->CopyTexSubImage = intelCopyTexSubImage;
132 }