DRI2: report swap events correctly in direct rendered case
[mesa.git] / progs / gallium / python / tests / surface_copy.py
1 #!/usr/bin/env python
2 ##########################################################################
3 #
4 # Copyright 2009 VMware, Inc.
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 VMWARE 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
30 from gallium import *
31 from base import *
32
33
34 def lods(*dims):
35 size = max(dims)
36 lods = 0
37 while size:
38 lods += 1
39 size >>= 1
40 return lods
41
42
43 class TextureTest(TestCase):
44
45 tags = (
46 'target',
47 'format',
48 'width',
49 'height',
50 'depth',
51 'last_level',
52 'face',
53 'level',
54 'zslice',
55 )
56
57 def test(self):
58 dev = self.dev
59
60 target = self.target
61 format = self.format
62 width = self.width
63 height = self.height
64 depth = self.depth
65 last_level = self.last_level
66 face = self.face
67 level = self.level
68 zslice = self.zslice
69
70 # textures
71 dst_texture = dev.texture_create(
72 target = target,
73 format = format,
74 width = width,
75 height = height,
76 depth = depth,
77 last_level = last_level,
78 tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET,
79 )
80 if dst_texture is None:
81 raise TestSkip
82
83 dst_surface = dst_texture.get_surface(face = face, level = level, zslice = zslice)
84
85 src_texture = dev.texture_create(
86 target = target,
87 format = format,
88 width = dst_surface.width,
89 height = dst_surface.height,
90 depth = 1,
91 last_level = 0,
92 tex_usage = PIPE_TEXTURE_USAGE_SAMPLER,
93 )
94
95 src_surface = src_texture.get_surface()
96
97 x = 0
98 y = 0
99 w = dst_surface.width
100 h = dst_surface.height
101
102 # ???
103 stride = pf_get_stride(texture->format, w)
104 size = pf_get_nblocksy(texture->format) * stride
105 src_raw = os.urandom(size)
106
107 src_surface.put_tile_raw(0, 0, w, h, src_raw, stride)
108
109 ctx = self.dev.context_create()
110
111 ctx.surface_copy(dst_surface, 0, 0,
112 src_surface, 0, 0, w, h)
113
114 ctx.flush()
115
116 dst_raw = dst_surface.get_tile_raw(0, 0, w, h)
117
118 if dst_raw != src_raw:
119 raise TestFailure
120
121
122
123 def main():
124 dev = Device()
125 suite = TestSuite()
126
127 targets = [
128 PIPE_TEXTURE_2D,
129 PIPE_TEXTURE_CUBE,
130 #PIPE_TEXTURE_3D,
131 ]
132
133 formats = [
134 PIPE_FORMAT_B8G8R8A8_UNORM,
135 PIPE_FORMAT_B8G8R8X8_UNORM,
136 PIPE_FORMAT_B8G8R8A8_SRGB,
137 PIPE_FORMAT_B5G6R5_UNORM,
138 PIPE_FORMAT_B5G5R5A1_UNORM,
139 PIPE_FORMAT_B4G4R4A4_UNORM,
140 PIPE_FORMAT_Z32_UNORM,
141 PIPE_FORMAT_S8Z24_UNORM,
142 PIPE_FORMAT_X8Z24_UNORM,
143 PIPE_FORMAT_Z16_UNORM,
144 PIPE_FORMAT_S8_UNORM,
145 PIPE_FORMAT_A8_UNORM,
146 PIPE_FORMAT_L8_UNORM,
147 PIPE_FORMAT_DXT1_RGB,
148 PIPE_FORMAT_DXT1_RGBA,
149 PIPE_FORMAT_DXT3_RGBA,
150 PIPE_FORMAT_DXT5_RGBA,
151 ]
152
153 sizes = [64, 32, 16, 8, 4, 2, 1]
154 #sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
155 #sizes = [64]
156 #sizes = [63]
157
158 faces = [
159 PIPE_TEX_FACE_POS_X,
160 PIPE_TEX_FACE_NEG_X,
161 PIPE_TEX_FACE_POS_Y,
162 PIPE_TEX_FACE_NEG_Y,
163 PIPE_TEX_FACE_POS_Z,
164 PIPE_TEX_FACE_NEG_Z,
165 ]
166
167 for target in targets:
168 for format in formats:
169 for size in sizes:
170 if target == PIPE_TEXTURE_3D:
171 depth = size
172 else:
173 depth = 1
174 for face in faces:
175 if target != PIPE_TEXTURE_CUBE and face:
176 continue
177 levels = lods(size)
178 for last_level in range(levels):
179 for level in range(0, last_level + 1):
180 zslice = 0
181 while zslice < depth >> level:
182 test = TextureTest(
183 dev = dev,
184 target = target,
185 format = format,
186 width = size,
187 height = size,
188 depth = depth,
189 last_level = last_level,
190 face = face,
191 level = level,
192 zslice = zslice,
193 )
194 suite.add_test(test)
195 zslice = (zslice + 1)*2 - 1
196 suite.run()
197
198
199 if __name__ == '__main__':
200 main()