2 * Copyright 2003 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "main/mtypes.h"
27 #include "main/enums.h"
28 #include "main/image.h"
29 #include "main/teximage.h"
30 #include "main/texobj.h"
31 #include "main/texstate.h"
32 #include "main/fbobject.h"
34 #include "drivers/common/meta.h"
36 #include "intel_screen.h"
37 #include "intel_mipmap_tree.h"
38 #include "intel_fbo.h"
39 #include "intel_tex.h"
40 #include "intel_blit.h"
41 #include "brw_context.h"
43 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
47 intel_copy_texsubimage(struct brw_context
*brw
,
48 struct intel_texture_image
*intelImage
,
49 GLint dstx
, GLint dsty
, GLint slice
,
50 struct intel_renderbuffer
*irb
,
51 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
53 const GLenum internalFormat
= intelImage
->base
.Base
.InternalFormat
;
56 /* No pixel transfer operations (zoom, bias, mapping), just a blit */
57 if (brw
->ctx
._ImageTransferState
)
60 intel_prepare_render(brw
);
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).
67 if (irb
->Base
.Base
.NumSamples
!= 0)
70 /* glCopyTexSubImage() can't be called on a multisampled texture. */
71 assert(intelImage
->base
.Base
.NumSamples
== 0);
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 __func__
, intelImage
->mt
, irb
, internalFormat
);
80 /* account for view parameters and face index */
81 int dst_level
= intelImage
->base
.Base
.Level
+
82 intelImage
->base
.Base
.TexObject
->MinLevel
;
83 int dst_slice
= slice
+ intelImage
->base
.Base
.Face
+
84 intelImage
->base
.Base
.TexObject
->MinLayer
;
86 _mesa_unlock_texture(&brw
->ctx
, intelImage
->base
.Base
.TexObject
);
88 /* blit from src buffer to texture */
89 ret
= intel_miptree_blit(brw
,
90 irb
->mt
, irb
->mt_level
, irb
->mt_layer
,
91 x
, y
, irb
->Base
.Base
.Name
== 0,
92 intelImage
->mt
, dst_level
, dst_slice
,
94 width
, height
, GL_COPY
);
96 _mesa_lock_texture(&brw
->ctx
, intelImage
->base
.Base
.TexObject
);
103 intelCopyTexSubImage(struct gl_context
*ctx
, GLuint dims
,
104 struct gl_texture_image
*texImage
,
105 GLint xoffset
, GLint yoffset
, GLint slice
,
106 struct gl_renderbuffer
*rb
,
108 GLsizei width
, GLsizei height
)
110 struct brw_context
*brw
= brw_context(ctx
);
112 /* Try BLORP first. It can handle almost everything. */
113 if (brw_blorp_copytexsubimage(brw
, rb
, texImage
, slice
, x
, y
,
114 xoffset
, yoffset
, width
, height
))
117 /* Next, try the BLT engine. */
118 if (intel_copy_texsubimage(brw
,
119 intel_texture_image(texImage
),
120 xoffset
, yoffset
, slice
,
121 intel_renderbuffer(rb
), x
, y
, width
, height
)) {
125 /* Finally, fall back to meta. This will likely be slow. */
126 perf_debug("%s - fallback to swrast\n", __func__
);
127 _mesa_meta_CopyTexSubImage(ctx
, dims
, texImage
,
128 xoffset
, yoffset
, slice
,
129 rb
, x
, y
, width
, height
);
134 intelInitTextureCopyImageFuncs(struct dd_function_table
*functions
)
136 functions
->CopyTexSubImage
= intelCopyTexSubImage
;