i965/miptree: Replace is_lossless_compressed with mt->aux_usage checks
[mesa.git] / src / mesa / drivers / dri / i965 / intel_copy_image.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2014 Intel Corporation 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 "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Jason Ekstrand <jason.ekstrand@intel.com>
26 */
27
28 #include "brw_blorp.h"
29 #include "intel_fbo.h"
30 #include "intel_tex.h"
31 #include "intel_blit.h"
32 #include "intel_mipmap_tree.h"
33 #include "main/formats.h"
34 #include "main/teximage.h"
35 #include "drivers/common/meta.h"
36
37 static void
38 copy_miptrees(struct brw_context *brw,
39 struct intel_mipmap_tree *src_mt,
40 int src_x, int src_y, int src_z, unsigned src_level,
41 struct intel_mipmap_tree *dst_mt,
42 int dst_x, int dst_y, int dst_z, unsigned dst_level,
43 int src_width, int src_height)
44 {
45 if (brw->gen <= 5) {
46 /* On gen4-5, try BLT first.
47 *
48 * Gen4-5 have a single ring for both 3D and BLT operations, so there's
49 * no inter-ring synchronization issues like on Gen6+. It is apparently
50 * faster than using the 3D pipeline. Original Gen4 also has to rebase
51 * and copy miptree slices in order to render to unaligned locations.
52 */
53 if (intel_miptree_copy(brw, src_mt, src_level, src_z, src_x, src_y,
54 dst_mt, dst_level, dst_z, dst_x, dst_y,
55 src_width, src_height))
56 return;
57 }
58
59 brw_blorp_copy_miptrees(brw,
60 src_mt, src_level, src_z,
61 dst_mt, dst_level, dst_z,
62 src_x, src_y, dst_x, dst_y,
63 src_width, src_height);
64 }
65
66 static void
67 intel_copy_image_sub_data(struct gl_context *ctx,
68 struct gl_texture_image *src_image,
69 struct gl_renderbuffer *src_renderbuffer,
70 int src_x, int src_y, int src_z,
71 struct gl_texture_image *dst_image,
72 struct gl_renderbuffer *dst_renderbuffer,
73 int dst_x, int dst_y, int dst_z,
74 int src_width, int src_height)
75 {
76 struct brw_context *brw = brw_context(ctx);
77 struct intel_mipmap_tree *src_mt, *dst_mt;
78 unsigned src_level, dst_level;
79
80 if (src_image) {
81 src_mt = intel_texture_image(src_image)->mt;
82 src_level = src_image->Level + src_image->TexObject->MinLevel;
83
84 /* Cube maps actually have different images per face */
85 if (src_image->TexObject->Target == GL_TEXTURE_CUBE_MAP)
86 src_z = src_image->Face;
87
88 src_z += src_image->TexObject->MinLayer;
89 } else {
90 assert(src_renderbuffer);
91 src_mt = intel_renderbuffer(src_renderbuffer)->mt;
92 src_image = src_renderbuffer->TexImage;
93 src_level = 0;
94 }
95
96 if (dst_image) {
97 dst_mt = intel_texture_image(dst_image)->mt;
98
99 dst_level = dst_image->Level + dst_image->TexObject->MinLevel;
100
101 /* Cube maps actually have different images per face */
102 if (dst_image->TexObject->Target == GL_TEXTURE_CUBE_MAP)
103 dst_z = dst_image->Face;
104
105 dst_z += dst_image->TexObject->MinLayer;
106 } else {
107 assert(dst_renderbuffer);
108 dst_mt = intel_renderbuffer(dst_renderbuffer)->mt;
109 dst_image = dst_renderbuffer->TexImage;
110 dst_level = 0;
111 }
112
113 copy_miptrees(brw, src_mt, src_x, src_y, src_z, src_level,
114 dst_mt, dst_x, dst_y, dst_z, dst_level,
115 src_width, src_height);
116
117 /* CopyImage only works for equal formats, texture view equivalence
118 * classes, and a couple special cases for compressed textures.
119 *
120 * Notably, GL_DEPTH_STENCIL does not appear in any equivalence
121 * classes, so we know the formats must be the same, and thus both
122 * will either have stencil, or not. They can't be mismatched.
123 */
124 assert((src_mt->stencil_mt != NULL) == (dst_mt->stencil_mt != NULL));
125
126 if (dst_mt->stencil_mt) {
127 copy_miptrees(brw, src_mt->stencil_mt, src_x, src_y, src_z, src_level,
128 dst_mt->stencil_mt, dst_x, dst_y, dst_z, dst_level,
129 src_width, src_height);
130 }
131 }
132
133 void
134 intelInitCopyImageFuncs(struct dd_function_table *functions)
135 {
136 functions->CopyImageSubData = intel_copy_image_sub_data;
137 }