2 ##########################################################################
4 # Copyright 2009 VMware, Inc.
5 # Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
8 # Permission is hereby granted, free of charge, to any person obtaining a
9 # copy of this software and associated documentation files (the
10 # "Software"), to deal in the Software without restriction, including
11 # without limitation the rights to use, copy, modify, merge, publish,
12 # distribute, sub license, and/or sell copies of the Software, and to
13 # permit persons to whom the Software is furnished to do so, subject to
14 # the following conditions:
16 # The above copyright notice and this permission notice (including the
17 # next paragraph) shall be included in all copies or substantial portions
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 # IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
24 # ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 ##########################################################################
44 def minify(dims
, level
= 1):
45 return [max(dim
>>level
, 1) for dim
in dims
]
48 def tex_coords(texture
, face
, level
, zslice
):
56 if texture
.target
== PIPE_TEXTURE_2D
:
57 return [[s
, t
, 0.0] for s
, t
in st
]
58 elif texture
.target
== PIPE_TEXTURE_3D
:
59 depth
= texture
.get_depth(level
)
61 r
= float(zslice
)/float(depth
- 1)
64 return [[s
, t
, r
] for s
, t
in st
]
65 elif texture
.target
== PIPE_TEXTURE_CUBE
:
68 # See http://developer.nvidia.com/object/cube_map_ogl_tutorial.html
71 if face
== PIPE_TEX_FACE_POS_X
:
75 if face
== PIPE_TEX_FACE_NEG_X
:
79 if face
== PIPE_TEX_FACE_POS_Y
:
83 if face
== PIPE_TEX_FACE_NEG_Y
:
87 if face
== PIPE_TEX_FACE_POS_Z
:
91 if face
== PIPE_TEX_FACE_NEG_Z
:
95 result
.append([rx
, ry
, rz
])
99 return n
& (n
- 1) == 0
102 class TextureColorSampleTest(TestCase
):
124 last_level
= self
.last_level
129 tex_usage
= PIPE_TEXTURE_USAGE_SAMPLER
132 geom_flags |
= PIPE_TEXTURE_GEOM_NON_SQUARE
133 if not is_pot(width
) or not is_pot(height
) or not is_pot(depth
):
134 geom_flags |
= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO
136 if not dev
.is_format_supported(format
, target
, tex_usage
, geom_flags
):
139 ctx
= self
.dev
.context_create()
141 # disabled blending/masking
143 blend
.rt
[0].rgb_src_factor
= PIPE_BLENDFACTOR_ONE
144 blend
.rt
[0].alpha_src_factor
= PIPE_BLENDFACTOR_ONE
145 blend
.rt
[0].rgb_dst_factor
= PIPE_BLENDFACTOR_ZERO
146 blend
.rt
[0].alpha_dst_factor
= PIPE_BLENDFACTOR_ZERO
147 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
150 # no-op depth/stencil/alpha
151 depth_stencil_alpha
= DepthStencilAlpha()
152 ctx
.set_depth_stencil_alpha(depth_stencil_alpha
)
155 rasterizer
= Rasterizer()
156 rasterizer
.front_winding
= PIPE_WINDING_CW
157 rasterizer
.cull_mode
= PIPE_WINDING_NONE
158 rasterizer
.bypass_vs_clip_and_viewport
= 1
159 ctx
.set_rasterizer(rasterizer
)
163 sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
164 sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
165 sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
166 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NEAREST
167 sampler
.min_img_filter
= PIPE_TEX_MIPFILTER_NEAREST
168 sampler
.mag_img_filter
= PIPE_TEX_MIPFILTER_NEAREST
169 sampler
.normalized_coords
= 1
171 sampler
.max_lod
= PIPE_MAX_TEXTURE_LEVELS
- 1
172 ctx
.set_fragment_sampler(0, sampler
)
175 texture
= dev
.texture_create(
181 last_level
= last_level
,
182 tex_usage
= tex_usage
,
185 expected_rgba
= FloatArray(height
*width
*4)
190 ).sample_rgba(expected_rgba
)
192 ctx
.set_fragment_sampler_texture(0, texture
)
195 cbuf_tex
= dev
.texture_create(
196 PIPE_FORMAT_B8G8R8A8_UNORM
,
199 tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
,
202 cbuf
= cbuf_tex
.get_surface()
208 ctx
.set_framebuffer(fb
)
209 rgba
= FloatArray(4);
214 ctx
.clear(PIPE_CLEAR_COLOR
, rgba
, 0.0, 0)
220 DCL IN[0], POSITION, CONSTANT
221 DCL IN[1], GENERIC, CONSTANT
222 DCL OUT[0], POSITION, CONSTANT
223 DCL OUT[1], GENERIC, CONSTANT
229 ctx
.set_vertex_shader(vs
)
233 PIPE_TEXTURE_1D
: "1D",
234 PIPE_TEXTURE_2D
: "2D",
235 PIPE_TEXTURE_3D
: "3D",
236 PIPE_TEXTURE_CUBE
: "CUBE",
240 DCL IN[0], GENERIC[0], LINEAR
241 DCL OUT[0], COLOR, CONSTANT
242 DCL SAMP[0], CONSTANT
243 0:TEX OUT[0], IN[0], SAMP[0], %s
247 ctx
.set_fragment_shader(fs
)
251 verts
= FloatArray(nverts
* nattrs
* 4)
255 w
, h
= minify((width
, height
), level
)
264 tex
= tex_coords(texture
, face
, level
, zslice
)
266 for i
in range(0, 4):
268 verts
[j
+ 0] = pos
[i
][0] # x
269 verts
[j
+ 1] = pos
[i
][1] # y
270 verts
[j
+ 2] = 0.0 # z
271 verts
[j
+ 3] = 1.0 # w
272 verts
[j
+ 4] = tex
[i
][0] # s
273 verts
[j
+ 5] = tex
[i
][1] # r
274 verts
[j
+ 6] = tex
[i
][2] # q
277 ctx
.draw_vertices(PIPE_PRIM_TRIANGLE_FAN
,
284 cbuf
= cbuf_tex
.get_surface()
286 self
.assert_rgba(cbuf
, x
, y
, w
, h
, expected_rgba
, 4.0/256, 0.85)
289 class TextureDepthSampleTest(TestCase
):
311 last_level
= self
.last_level
316 tex_usage
= PIPE_TEXTURE_USAGE_SAMPLER
319 geom_flags |
= PIPE_TEXTURE_GEOM_NON_SQUARE
320 if not is_pot(width
) or not is_pot(height
) or not is_pot(depth
):
321 geom_flags |
= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO
323 if not dev
.is_format_supported(format
, target
, tex_usage
, geom_flags
):
326 ctx
= self
.dev
.context_create()
328 # disabled blending/masking
330 blend
.rt
[0].rgb_src_factor
= PIPE_BLENDFACTOR_ONE
331 blend
.rt
[0].alpha_src_factor
= PIPE_BLENDFACTOR_ONE
332 blend
.rt
[0].rgb_dst_factor
= PIPE_BLENDFACTOR_ZERO
333 blend
.rt
[0].alpha_dst_factor
= PIPE_BLENDFACTOR_ZERO
334 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
337 # depth/stencil/alpha
338 depth_stencil_alpha
= DepthStencilAlpha()
339 depth_stencil_alpha
.depth
.enabled
= 1
340 depth_stencil_alpha
.depth
.writemask
= 1
341 depth_stencil_alpha
.depth
.func
= PIPE_FUNC_LESS
342 ctx
.set_depth_stencil_alpha(depth_stencil_alpha
)
345 rasterizer
= Rasterizer()
346 rasterizer
.front_winding
= PIPE_WINDING_CW
347 rasterizer
.cull_mode
= PIPE_WINDING_NONE
348 rasterizer
.bypass_vs_clip_and_viewport
= 1
349 ctx
.set_rasterizer(rasterizer
)
353 sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
354 sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
355 sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
356 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NEAREST
357 sampler
.min_img_filter
= PIPE_TEX_MIPFILTER_NEAREST
358 sampler
.mag_img_filter
= PIPE_TEX_MIPFILTER_NEAREST
359 sampler
.normalized_coords
= 1
361 sampler
.max_lod
= PIPE_MAX_TEXTURE_LEVELS
- 1
362 ctx
.set_fragment_sampler(0, sampler
)
365 texture
= dev
.texture_create(
371 last_level
= last_level
,
372 tex_usage
= tex_usage
,
375 expected_rgba
= FloatArray(height
*width
*4)
380 ).sample_rgba(expected_rgba
)
382 ctx
.set_fragment_sampler_texture(0, texture
)
385 cbuf_tex
= dev
.texture_create(
386 PIPE_FORMAT_B8G8R8A8_UNORM
,
389 tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
,
392 zsbuf_tex
= dev
.texture_create(
393 PIPE_FORMAT_X8Z24_UNORM
,
396 tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
,
399 cbuf
= cbuf_tex
.get_surface()
400 zsbuf
= zsbuf_tex
.get_surface()
407 ctx
.set_framebuffer(fb
)
408 rgba
= FloatArray(4);
413 ctx
.clear(PIPE_CLEAR_DEPTHSTENCIL
, rgba
, 1.0, 0)
419 DCL IN[0], POSITION, CONSTANT
420 DCL IN[1], GENERIC, CONSTANT
421 DCL OUT[0], POSITION, CONSTANT
422 DCL OUT[1], GENERIC, CONSTANT
428 ctx
.set_vertex_shader(vs
)
432 PIPE_TEXTURE_1D
: "1D",
433 PIPE_TEXTURE_2D
: "2D",
434 PIPE_TEXTURE_3D
: "3D",
435 PIPE_TEXTURE_CUBE
: "CUBE",
439 DCL IN[0], GENERIC[0], LINEAR
440 DCL SAMP[0], CONSTANT
441 DCL OUT[0].z, POSITION
442 0:TEX OUT[0].z, IN[0], SAMP[0], %s
446 ctx
.set_fragment_shader(fs
)
450 verts
= FloatArray(nverts
* nattrs
* 4)
454 w
, h
= minify((width
, height
), level
)
463 tex
= tex_coords(texture
, face
, level
, zslice
)
465 for i
in range(0, 4):
467 verts
[j
+ 0] = pos
[i
][0] # x
468 verts
[j
+ 1] = pos
[i
][1] # y
469 verts
[j
+ 2] = 0.0 # z
470 verts
[j
+ 3] = 1.0 # w
471 verts
[j
+ 4] = tex
[i
][0] # s
472 verts
[j
+ 5] = tex
[i
][1] # r
473 verts
[j
+ 6] = tex
[i
][2] # q
476 ctx
.draw_vertices(PIPE_PRIM_TRIANGLE_FAN
,
483 zsbuf
= zsbuf_tex
.get_surface()
485 self
.assert_rgba(zsbuf
, x
, y
, w
, h
, expected_rgba
, 4.0/256, 0.85)
501 PIPE_FORMAT_B8G8R8A8_UNORM
,
502 PIPE_FORMAT_B8G8R8X8_UNORM
,
503 #PIPE_FORMAT_B8G8R8A8_SRGB,
504 PIPE_FORMAT_B5G6R5_UNORM
,
505 PIPE_FORMAT_B5G5R5A1_UNORM
,
506 PIPE_FORMAT_B4G4R4A4_UNORM
,
507 PIPE_FORMAT_A8_UNORM
,
508 PIPE_FORMAT_L8_UNORM
,
510 PIPE_FORMAT_DXT1_RGB
,
511 #PIPE_FORMAT_DXT1_RGBA,
512 #PIPE_FORMAT_DXT3_RGBA,
513 #PIPE_FORMAT_DXT5_RGBA,
517 PIPE_FORMAT_Z32_UNORM
,
518 PIPE_FORMAT_S8Z24_UNORM
,
519 PIPE_FORMAT_X8Z24_UNORM
,
520 PIPE_FORMAT_Z16_UNORM
,
523 sizes
= [64, 32, 16, 8, 4, 2, 1]
524 #sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
537 for format
in color_formats
:
538 for target
in targets
:
540 if target
== PIPE_TEXTURE_3D
:
545 if target
!= PIPE_TEXTURE_CUBE
and face
:
548 for last_level
in range(levels
):
549 for level
in range(0, last_level
+ 1):
551 while zslice
< depth
>> level
:
552 test
= TextureColorSampleTest(
559 last_level
= last_level
,
565 zslice
= (zslice
+ 1)*2 - 1
566 for format
in depth_formats
:
567 target
= PIPE_TEXTURE_2D
574 test
= TextureDepthSampleTest(
581 last_level
= last_level
,
590 if __name__
== '__main__':