i965: Use unreachable() instead of unconditional assert().
[mesa.git] / src / mesa / drivers / dri / i965 / intel_tex_copy.c
1 /**************************************************************************
2 *
3 * Copyright 2003 VMware, Inc.
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 VMWARE 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_mipmap_tree.h"
39 #include "intel_fbo.h"
40 #include "intel_tex.h"
41 #include "intel_blit.h"
42 #include "brw_context.h"
43
44 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
45
46
47 static bool
48 intel_copy_texsubimage(struct brw_context *brw,
49 struct intel_texture_image *intelImage,
50 GLint dstx, GLint dsty, GLint slice,
51 struct intel_renderbuffer *irb,
52 GLint x, GLint y, GLsizei width, GLsizei height)
53 {
54 const GLenum internalFormat = intelImage->base.Base.InternalFormat;
55
56 intel_prepare_render(brw);
57
58 /* glCopyTexSubImage() can be called on a multisampled renderbuffer (if
59 * that renderbuffer is associated with the window system framebuffer),
60 * however the hardware blitter can't handle this case, so fall back to
61 * meta (which can, since it uses ReadPixels).
62 */
63 if (irb->Base.Base.NumSamples != 0)
64 return false;
65
66 /* glCopyTexSubImage() can't be called on a multisampled texture. */
67 assert(intelImage->base.Base.NumSamples == 0);
68
69 if (!intelImage->mt || !irb || !irb->mt) {
70 if (unlikely(INTEL_DEBUG & DEBUG_PERF))
71 fprintf(stderr, "%s fail %p %p (0x%08x)\n",
72 __FUNCTION__, intelImage->mt, irb, internalFormat);
73 return false;
74 }
75
76 /* account for view parameters and face index */
77 int dst_level = intelImage->base.Base.Level +
78 intelImage->base.Base.TexObject->MinLevel;
79 int dst_slice = slice + intelImage->base.Base.Face +
80 intelImage->base.Base.TexObject->MinLayer;
81
82 /* blit from src buffer to texture */
83 if (!intel_miptree_blit(brw,
84 irb->mt, irb->mt_level, irb->mt_layer,
85 x, y, irb->Base.Base.Name == 0,
86 intelImage->mt, dst_level, dst_slice,
87 dstx, dsty, false,
88 width, height, GL_COPY)) {
89 return false;
90 }
91
92 return true;
93 }
94
95
96 static void
97 intelCopyTexSubImage(struct gl_context *ctx, GLuint dims,
98 struct gl_texture_image *texImage,
99 GLint xoffset, GLint yoffset, GLint slice,
100 struct gl_renderbuffer *rb,
101 GLint x, GLint y,
102 GLsizei width, GLsizei height)
103 {
104 struct brw_context *brw = brw_context(ctx);
105
106 /* Try BLORP first. It can handle almost everything. */
107 if (brw_blorp_copytexsubimage(brw, rb, texImage, slice, x, y,
108 xoffset, yoffset, width, height))
109 return;
110
111 /* Next, try the BLT engine. */
112 if (intel_copy_texsubimage(brw,
113 intel_texture_image(texImage),
114 xoffset, yoffset, slice,
115 intel_renderbuffer(rb), x, y, width, height)) {
116 return;
117 }
118
119 /* Finally, fall back to meta. This will likely be slow. */
120 perf_debug("%s - fallback to swrast\n", __FUNCTION__);
121 _mesa_meta_CopyTexSubImage(ctx, dims, texImage,
122 xoffset, yoffset, slice,
123 rb, x, y, width, height);
124 }
125
126
127 void
128 intelInitTextureCopyImageFuncs(struct dd_function_table *functions)
129 {
130 functions->CopyTexSubImage = intelCopyTexSubImage;
131 }