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 ##########################################################################
43 class TextureTest(TestCase
):
65 last_level
= self
.last_level
71 dst_texture
= dev
.resource_create(
77 last_level
= last_level
,
78 bind
= PIPE_BIND_RENDER_TARGET
,
80 if dst_texture
is None:
83 dst_surface
= dst_texture
.get_surface(face
= face
, level
= level
, zslice
= zslice
)
85 ref_texture
= dev
.resource_create(
88 width
= dst_surface
.width
,
89 height
= dst_surface
.height
,
92 bind
= PIPE_BIND_SAMPLER_VIEW
,
95 ref_surface
= ref_texture
.get_surface()
97 src_texture
= dev
.resource_create(
99 format
= PIPE_FORMAT_B8G8R8A8_UNORM
,
100 width
= dst_surface
.width
,
101 height
= dst_surface
.height
,
104 bind
= PIPE_BIND_SAMPLER_VIEW
,
107 src_surface
= src_texture
.get_surface()
109 expected_rgba
= FloatArray(height
*width
*4)
110 ref_surface
.sample_rgba(expected_rgba
)
112 src_surface
.put_tile_rgba(0, 0, src_surface
.width
, src_surface
.height
, expected_rgba
)
114 ctx
= self
.dev
.context_create()
116 # disabled blending/masking
118 blend
.rt
[0].rgb_src_factor
= PIPE_BLENDFACTOR_ONE
119 blend
.rt
[0].alpha_src_factor
= PIPE_BLENDFACTOR_ONE
120 blend
.rt
[0].rgb_dst_factor
= PIPE_BLENDFACTOR_ZERO
121 blend
.rt
[0].alpha_dst_factor
= PIPE_BLENDFACTOR_ZERO
122 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
125 # no-op depth/stencil/alpha
126 depth_stencil_alpha
= DepthStencilAlpha()
127 ctx
.set_depth_stencil_alpha(depth_stencil_alpha
)
130 rasterizer
= Rasterizer()
131 rasterizer
.front_winding
= PIPE_WINDING_CW
132 rasterizer
.cull_mode
= PIPE_WINDING_NONE
133 rasterizer
.bypass_vs_clip_and_viewport
= 1
134 ctx
.set_rasterizer(rasterizer
)
138 sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
139 sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
140 sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
141 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NEAREST
142 sampler
.min_img_filter
= PIPE_TEX_MIPFILTER_NEAREST
143 sampler
.mag_img_filter
= PIPE_TEX_MIPFILTER_NEAREST
144 sampler
.normalized_coords
= 1
146 sampler
.max_lod
= PIPE_MAX_TEXTURE_LEVELS
- 1
147 ctx
.set_fragment_sampler(0, sampler
)
148 ctx
.set_fragment_sampler_texture(0, src_texture
)
151 cbuf_tex
= dev
.resource_create(
152 PIPE_FORMAT_B8G8R8A8_UNORM
,
155 bind
= PIPE_BIND_RENDER_TARGET
,
159 fb
.width
= dst_surface
.width
160 fb
.height
= dst_surface
.height
162 fb
.set_cbuf(0, dst_surface
)
163 ctx
.set_framebuffer(fb
)
164 rgba
= FloatArray(4);
169 ctx
.clear(PIPE_CLEAR_COLOR
, rgba
, 0.0, 0)
175 DCL IN[0], POSITION, CONSTANT
176 DCL IN[1], GENERIC, CONSTANT
177 DCL OUT[0], POSITION, CONSTANT
178 DCL OUT[1], GENERIC, CONSTANT
184 ctx
.set_vertex_shader(vs
)
189 DCL IN[0], GENERIC[0], LINEAR
190 DCL OUT[0], COLOR, CONSTANT
191 DCL SAMP[0], CONSTANT
192 0:TEX OUT[0], IN[0], SAMP[0], 2D
196 ctx
.set_fragment_shader(fs
)
200 verts
= FloatArray(nverts
* nattrs
* 4)
204 w
= dst_surface
.width
205 h
= dst_surface
.height
221 for i
in range(0, 4):
223 verts
[j
+ 0] = pos
[i
][0] # x
224 verts
[j
+ 1] = pos
[i
][1] # y
225 verts
[j
+ 2] = 0.0 # z
226 verts
[j
+ 3] = 1.0 # w
227 verts
[j
+ 4] = tex
[i
][0] # s
228 verts
[j
+ 5] = tex
[i
][1] # r
232 ctx
.draw_vertices(PIPE_PRIM_TRIANGLE_FAN
,
239 self
.assert_rgba(dst_surface
, x
, y
, w
, h
, expected_rgba
, 4.0/256, 0.85)
254 PIPE_FORMAT_B8G8R8A8_UNORM
,
255 PIPE_FORMAT_B8G8R8X8_UNORM
,
256 #PIPE_FORMAT_B8G8R8A8_SRGB,
257 PIPE_FORMAT_B5G6R5_UNORM
,
258 PIPE_FORMAT_B5G5R5A1_UNORM
,
259 PIPE_FORMAT_B4G4R4A4_UNORM
,
260 #PIPE_FORMAT_Z32_UNORM,
261 #PIPE_FORMAT_S8_USCALED_Z24_UNORM,
262 #PIPE_FORMAT_X8Z24_UNORM,
263 #PIPE_FORMAT_Z16_UNORM,
264 #PIPE_FORMAT_S8_USCALED,
265 PIPE_FORMAT_A8_UNORM
,
266 PIPE_FORMAT_L8_UNORM
,
267 #PIPE_FORMAT_DXT1_RGB,
268 #PIPE_FORMAT_DXT1_RGBA,
269 #PIPE_FORMAT_DXT3_RGBA,
270 #PIPE_FORMAT_DXT5_RGBA,
273 sizes
= [64, 32, 16, 8, 4, 2, 1]
274 #sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
287 for target
in targets
:
288 for format
in formats
:
290 if target
== PIPE_TEXTURE_3D
:
295 if target
!= PIPE_TEXTURE_CUBE
and face
:
298 for last_level
in range(levels
):
299 for level
in range(0, last_level
+ 1):
301 while zslice
< depth
>> level
:
309 last_level
= last_level
,
315 zslice
= (zslice
+ 1)*2 - 1
319 if __name__
== '__main__':