2 ##########################################################################
4 # Copyright 2009 VMware, Inc.
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:
15 # The above copyright notice and this permission notice (including the
16 # next paragraph) shall be included in all copies or substantial portions
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.
27 ##########################################################################
46 class TextureTest(TestCase
):
69 last_level
= self
.last_level
74 bind
= PIPE_BIND_SAMPLER_VIEW
76 if not dev
.is_format_supported(format
, target
, bind
, geom_flags
):
79 if not dev
.is_format_supported(format
, target
, bind
, geom_flags
):
83 dst_texture
= dev
.resource_create(
89 last_level
= last_level
,
93 dst_surface
= dst_texture
.get_surface(face
= face
, level
= level
, zslice
= zslice
)
95 src_texture
= dev
.resource_create(
98 width
= dst_surface
.width
,
99 height
= dst_surface
.height
,
102 bind
= PIPE_BIND_SAMPLER_VIEW
,
105 src_surface
= src_texture
.get_surface()
107 w
= dst_surface
.width
108 h
= dst_surface
.height
110 stride
= util_format_get_stride(format
, w
)
111 size
= util_format_get_nblocksy(format
, h
) * stride
112 src_raw
= os
.urandom(size
)
114 ctx
.surface_write_raw(src_surface
, 0, 0, w
, h
, src_raw
, stride
)
116 ctx
.surface_copy(dst_surface
, 0, 0,
117 src_surface
, 0, 0, w
, h
)
119 dst_raw
= ctx
.surface_read_raw(dst_surface
, 0, 0, w
, h
)
121 if dst_raw
!= src_raw
:
127 ctx
= dev
.context_create()
136 sizes
= [64, 32, 16, 8, 4, 2, 1]
137 #sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
156 format
= random
.choice(formats
.keys())
157 if not util_format_is_depth_or_stencil(format
):
158 is_depth_or_stencil
= util_format_is_depth_or_stencil(format
)
160 if is_depth_or_stencil
:
161 target
= PIPE_TEXTURE_2D
163 target
= random
.choice(targets
)
165 size
= random
.choice(sizes
)
167 if target
== PIPE_TEXTURE_3D
:
172 if target
== PIPE_TEXTURE_CUBE
:
173 face
= random
.choice(faces
)
175 face
= PIPE_TEX_FACE_POS_X
178 last_level
= random
.randint(0, levels
- 1)
179 level
= random
.randint(0, last_level
)
180 zslice
= random
.randint(0, max(depth
>> level
, 1) - 1)
190 last_level
= last_level
,
199 if __name__
== '__main__':