From 64979d618a24e8378d95944d5f1d1b5847880a48 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 14 Jul 2008 22:27:40 +0900 Subject: python: Basic test case for 2d texture. --- src/gallium/state_trackers/python/tests/texture.py | 236 +++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 src/gallium/state_trackers/python/tests/texture.py (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py new file mode 100644 index 0000000000..d0b657423e --- /dev/null +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -0,0 +1,236 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. +# All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sub license, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice (including the +# next paragraph) shall be included in all copies or substantial portions +# of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR +# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +########################################################################## + + +from gallium import * +from base import * +from data import generate_data + + +def compare_rgba(width, height, rgba1, rgba2, tol=0.01): + result = True + for y in range(0, height): + for x in range(0, width): + for ch in range(4): + offset = (y*width + x)*4 + ch + v1 = rgba1[offset] + v2 = rgba2[offset] + if abs(v1 - v2) > tol: + sys.stderr.write("x=%u, y=%u, ch=%u differ: %f vs %f\n", + x, y, ch, v1, v2) + result = False + + +class TextureTest(Test): + + def __init__(self, **kargs): + Test.__init__(self) + self.__dict__.update(kargs) + + def run(self): + dev = self.dev + + format = PIPE_FORMAT_A8R8G8B8_UNORM + #format = PIPE_FORMAT_DXT1_RGB + + if not dev.is_format_supported(format, PIPE_TEXTURE): + pass + if not dev.is_format_supported(format, PIPE_SURFACE): + pass + + ctx = dev.context_create() + + width = 256 + height = 256 + + # disabled blending/masking + blend = Blend() + blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE + blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE + blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.colormask = PIPE_MASK_RGBA + ctx.set_blend(blend) + + # no-op depth/stencil/alpha + depth_stencil_alpha = DepthStencilAlpha() + ctx.set_depth_stencil_alpha(depth_stencil_alpha) + + # rasterizer + rasterizer = Rasterizer() + rasterizer.front_winding = PIPE_WINDING_CW + rasterizer.cull_mode = PIPE_WINDING_NONE + rasterizer.bypass_clipping = 1 + #rasterizer.bypass_vs = 1 + ctx.set_rasterizer(rasterizer) + + # viewport (identity, we setup vertices in wincoords) + viewport = Viewport() + scale = FloatArray(4) + scale[0] = 1.0 + scale[1] = 1.0 + scale[2] = 1.0 + scale[3] = 1.0 + viewport.scale = scale + translate = FloatArray(4) + translate[0] = 0.0 + translate[1] = 0.0 + translate[2] = 0.0 + translate[3] = 0.0 + viewport.translate = translate + ctx.set_viewport(viewport) + + # samplers + sampler = Sampler() + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE + sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.normalized_coords = 1 + ctx.set_sampler(0, sampler) + + # texture + texture = dev.texture_create(format, + width, + height) + ctx.set_sampler_texture(0, texture) + + surface = texture.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE) + + expected_rgba = generate_data(surface) + + cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, + width, + height) + + # drawing dest + cbuf = cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_GPU_WRITE) + fb = Framebuffer() + fb.width = cbuf.width + fb.height = cbuf.height + fb.num_cbufs = 1 + fb.set_cbuf(0, cbuf) + ctx.set_framebuffer(fb) + + # vertex shader + vs = Shader(''' + VERT1.1 + DCL IN[0], POSITION, CONSTANT + DCL IN[1], GENERIC, CONSTANT + DCL OUT[0], POSITION, CONSTANT + DCL OUT[1], GENERIC, CONSTANT + 0:MOV OUT[0], IN[0] + 1:MOV OUT[1], IN[1] + 2:END + ''') + #vs.dump() + ctx.set_vertex_shader(vs) + + # fragment shader + fs = Shader(''' + FRAG1.1 + DCL IN[0], GENERIC[0], PERSPECTIVE + DCL OUT[0], COLOR, CONSTANT + DCL SAMP[0], CONSTANT + 0:TEX OUT[0], IN[0], SAMP[0], 2D + 1:END + ''') + fs.dump() + ctx.set_fragment_shader(fs) + + nverts = 4 + nattrs = 2 + verts = FloatArray(nverts * nattrs * 4) + + x = 0 + y = 0 + w = width + h = height + + verts[ 0] = x # x1 + verts[ 1] = y # y1 + verts[ 2] = 0.0 # z1 + verts[ 3] = 1.0 # w1 + verts[ 4] = 0.0 # s1 + verts[ 5] = 0.0 # t + verts[ 6] = 0.0 + verts[ 7] = 0.0 + verts[ 8] = x + w # x2 + verts[ 9] = y # y2 + verts[10] = 0.0 # z2 + verts[11] = 1.0 # w2 + verts[12] = 1.0 # s2 + verts[13] = 0.0 # t2 + verts[14] = 0.0 + verts[15] = 0.0 + verts[16] = x + w # x3 + verts[17] = y + h # y3 + verts[18] = 0.0 # z3 + verts[19] = 1.0 # w3 + verts[20] = 1.0 # s3 + verts[21] = 1.0 # t3 + verts[22] = 0.0 + verts[23] = 0.0 + verts[24] = x # x4 + verts[25] = y + h # y4 + verts[26] = 0.0 # z4 + verts[27] = 1.0 # w4 + verts[28] = 0.0 # s4 + verts[29] = 1.0 # t4 + verts[30] = 0.0 + verts[31] = 0.0 + + ctx.surface_clear(cbuf, 0x00000000) + + ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, + nverts, + nattrs, + verts) + + ctx.flush() + + rgba = FloatArray(surface.height*surface.width*4) + + cbuf.get_tile_rgba(x, y, w, h, rgba) + + compare_rgba(width, height, rgba, expected_rgba) + + #save_image("texture1.png", surface) + #save_image("texture2.png", cbuf) + + +def main(): + dev = Device(hardware = False) + test = TextureTest(dev = dev) + test.run() + + +if __name__ == '__main__': + main() -- cgit v1.2.3 From 1d03102b319f7bca2bf76c5d6e3996dc87f03634 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 15 Jul 2008 08:42:16 +0900 Subject: python: Allow hardware support. --- src/gallium/state_trackers/python/SConscript | 13 +++- src/gallium/state_trackers/python/gallium.i | 2 +- src/gallium/state_trackers/python/samples/tri.py | 2 +- src/gallium/state_trackers/python/st_device.c | 6 +- .../state_trackers/python/st_hardpipe_winsys.c | 78 ++++++++++++++++++++++ .../state_trackers/python/st_softpipe_winsys.c | 2 +- src/gallium/state_trackers/python/st_winsys.h | 4 +- src/gallium/state_trackers/python/tests/texture.py | 2 +- 8 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 src/gallium/state_trackers/python/st_hardpipe_winsys.c (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/SConscript b/src/gallium/state_trackers/python/SConscript index 687c46bfd7..b284d2020b 100644 --- a/src/gallium/state_trackers/python/SConscript +++ b/src/gallium/state_trackers/python/SConscript @@ -15,12 +15,19 @@ if 'python' in env['statetrackers']: env.Append(CPPPATH = '.') - env.SharedLibrary( - target = '_gallium', + pyst = env.ConvenienceLibrary( + target = 'pyst', source = [ 'gallium.i', 'st_device.c', 'st_softpipe_winsys.c', ], - LIBS = softpipe + auxiliaries + env['LIBS'], + ) + + env.SharedLibrary( + target = '_gallium', + source = [ + 'st_hardpipe_winsys.c', + ], + LIBS = [pyst, softpipe] + auxiliaries + env['LIBS'], ) diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index 60f8e50300..967840a063 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -100,7 +100,7 @@ struct st_context { %extend st_device { - st_device(int hardware = 0) { + st_device(int hardware = 1) { return st_device_create(hardware ? TRUE : FALSE); } diff --git a/src/gallium/state_trackers/python/samples/tri.py b/src/gallium/state_trackers/python/samples/tri.py index 7a10905ddb..f915c26215 100644 --- a/src/gallium/state_trackers/python/samples/tri.py +++ b/src/gallium/state_trackers/python/samples/tri.py @@ -185,7 +185,7 @@ def test(dev): def main(): - dev = Device(hardware = False) + dev = Device() test(dev) diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index 25b5a4fa8c..d88d2de3c6 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -82,12 +82,10 @@ st_device_create_from_st_winsys(const struct st_winsys *st_ws) struct st_device * st_device_create(boolean hardware) { -#if 0 if(hardware) - return st_device_create_from_st_winsys(&st_hardware_winsys); + return st_device_create_from_st_winsys(&st_hardpipe_winsys); else -#endif - return st_device_create_from_st_winsys(&st_software_winsys); + return st_device_create_from_st_winsys(&st_softpipe_winsys); } diff --git a/src/gallium/state_trackers/python/st_hardpipe_winsys.c b/src/gallium/state_trackers/python/st_hardpipe_winsys.c new file mode 100644 index 0000000000..33b75637b3 --- /dev/null +++ b/src/gallium/state_trackers/python/st_hardpipe_winsys.c @@ -0,0 +1,78 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Bismarck, ND., USA + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * + **************************************************************************/ + +/** + * @file + * Stub for hardware pipe driver support. + */ + + +#include "pipe/p_compiler.h" + +#include "st_winsys.h" + + +extern void init_gallium(void); + +void (*force_init_gallium_linkage)(void) = &init_gallium; + + +static void +st_hardpipe_screen_destroy(struct pipe_screen *screen) +{ + st_softpipe_winsys.screen_destroy(screen); +} + + +static struct pipe_screen * +st_hardpipe_screen_create(void) +{ + return st_softpipe_winsys.screen_create(); +} + + +static void +st_hardpipe_context_destroy(struct pipe_context *pipe) +{ + st_softpipe_winsys.context_destroy(pipe); +} + + +static struct pipe_context * +st_hardpipe_context_create(struct pipe_screen *screen) +{ + return st_softpipe_winsys.context_create(screen); +} + + +const struct st_winsys st_hardpipe_winsys = { + &st_hardpipe_screen_create, + &st_hardpipe_screen_destroy, + &st_hardpipe_context_create, + &st_hardpipe_context_destroy +}; diff --git a/src/gallium/state_trackers/python/st_softpipe_winsys.c b/src/gallium/state_trackers/python/st_softpipe_winsys.c index 964d60de1d..1fda70ca00 100644 --- a/src/gallium/state_trackers/python/st_softpipe_winsys.c +++ b/src/gallium/state_trackers/python/st_softpipe_winsys.c @@ -313,7 +313,7 @@ st_softpipe_context_create(struct pipe_screen *screen) } -const struct st_winsys st_software_winsys = { +const struct st_winsys st_softpipe_winsys = { &st_softpipe_screen_create, &st_softpipe_screen_destroy, &st_softpipe_context_create, diff --git a/src/gallium/state_trackers/python/st_winsys.h b/src/gallium/state_trackers/python/st_winsys.h index 992fc9ab4b..43db8b6bff 100644 --- a/src/gallium/state_trackers/python/st_winsys.h +++ b/src/gallium/state_trackers/python/st_winsys.h @@ -50,9 +50,9 @@ struct st_winsys }; -extern const struct st_winsys st_software_winsys; +extern const struct st_winsys st_softpipe_winsys; -extern const struct st_winsys st_hardware_winsys; +extern const struct st_winsys st_hardpipe_winsys; #endif /* ST_WINSYS_H_ */ diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index d0b657423e..ad11e8dcc9 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -227,7 +227,7 @@ class TextureTest(Test): def main(): - dev = Device(hardware = False) + dev = Device() test = TextureTest(dev = dev) test.run() -- cgit v1.2.3 From ee470020e17bc4999f3540fbad49fe645a4b914e Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 15 Jul 2008 17:14:07 +0900 Subject: python: Request/respect the texture & buffer usage flags in the examples. --- src/gallium/state_trackers/python/samples/tri.py | 81 +++++++++++++++++----- src/gallium/state_trackers/python/tests/base.py | 35 +++++++++- src/gallium/state_trackers/python/tests/texture.py | 46 ++++++------ 3 files changed, 121 insertions(+), 41 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/samples/tri.py b/src/gallium/state_trackers/python/samples/tri.py index f915c26215..e5044a0245 100644 --- a/src/gallium/state_trackers/python/samples/tri.py +++ b/src/gallium/state_trackers/python/samples/tri.py @@ -30,7 +30,7 @@ from gallium import * -def save_image(filename, surface): +def make_image(surface): pixels = FloatArray(surface.height*surface.width*4) surface.get_tile_rgba(0, 0, surface.width, surface.height, pixels) @@ -45,14 +45,38 @@ def save_image(filename, surface): offset = (y*surface.width + x)*4 r, g, b, a = [int(pixels[offset + ch]*255) for ch in range(4)] outpixels[x, y] = r, g, b + return outimage + +def save_image(filename, surface): + outimage = make_image(surface) outimage.save(filename, "PNG") +def show_image(surface): + outimage = make_image(surface) + + import Tkinter as tk + from PIL import Image, ImageTk + root = tk.Tk() + + root.title('background image') + + image1 = ImageTk.PhotoImage(outimage) + w = image1.width() + h = image1.height() + x = 100 + y = 100 + root.geometry("%dx%d+%d+%d" % (w, h, x, y)) + panel1 = tk.Label(root, image=image1) + panel1.pack(side='top', fill='both', expand='yes') + panel1.image = image1 + root.mainloop() + def test(dev): ctx = dev.context_create() - width = 256 - height = 256 + width = 255 + height = 255 # disabled blending/masking blend = Blend() @@ -72,6 +96,7 @@ def test(dev): rasterizer.front_winding = PIPE_WINDING_CW rasterizer.cull_mode = PIPE_WINDING_NONE rasterizer.bypass_clipping = 1 + rasterizer.scissor = 1 #rasterizer.bypass_vs = 1 ctx.set_rasterizer(rasterizer) @@ -102,21 +127,41 @@ def test(dev): sampler.normalized_coords = 1 ctx.set_sampler(0, sampler) - # texture - texture = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, - width, height, - usage=PIPE_TEXTURE_USAGE_RENDER_TARGET) - ctx.set_sampler_texture(0, texture) - - # drawing dest - surface = texture.get_surface(usage = PIPE_BUFFER_USAGE_GPU_WRITE) + # scissor + scissor = Scissor() + scissor.minx = 0 + scissor.miny = 0 + scissor.maxx = width + scissor.maxy = height + ctx.set_scissor(scissor) + + clip = Clip() + clip.nr = 0 + ctx.set_clip(clip) + + # framebuffer + cbuf = dev.texture_create(PIPE_FORMAT_X8R8G8B8_UNORM, + width, height, + usage=PIPE_TEXTURE_USAGE_DISPLAY_TARGET) + zbuf = dev.texture_create(PIPE_FORMAT_X8Z24_UNORM, + width, height, + usage=PIPE_TEXTURE_USAGE_DEPTH_STENCIL) + _cbuf = cbuf.get_surface(usage = PIPE_BUFFER_USAGE_GPU_READ|PIPE_BUFFER_USAGE_GPU_WRITE) + _zsbuf = zbuf.get_surface(usage = PIPE_BUFFER_USAGE_GPU_READ|PIPE_BUFFER_USAGE_GPU_WRITE) fb = Framebuffer() - fb.width = surface.width - fb.height = surface.height + fb.width = width + fb.height = height fb.num_cbufs = 1 - fb.set_cbuf(0, surface) + fb.set_cbuf(0, _cbuf) + fb.set_zsbuf(_zsbuf) ctx.set_framebuffer(fb) - + _cbuf.clear_value = 0x00000000 + _zsbuf.clear_value = 0x00ffffff + ctx.surface_clear(_cbuf, _cbuf.clear_value) + ctx.surface_clear(_zsbuf, _zsbuf.clear_value) + del _cbuf + del _zsbuf + # vertex shader vs = Shader(''' VERT1.1 @@ -171,16 +216,14 @@ def test(dev): verts[22] = 1.0 # b3 verts[23] = 1.0 # a3 - ctx.surface_clear(surface, 0x00000000) - ctx.draw_vertices(PIPE_PRIM_TRIANGLES, nverts, nattrs, verts) ctx.flush() - - save_image("tri.png", surface) + + show_image(cbuf.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE)) diff --git a/src/gallium/state_trackers/python/tests/base.py b/src/gallium/state_trackers/python/tests/base.py index 5778ad4382..185a59996e 100644 --- a/src/gallium/state_trackers/python/tests/base.py +++ b/src/gallium/state_trackers/python/tests/base.py @@ -37,7 +37,7 @@ for name, value in globals().items(): formats[value] = name -def save_image(filename, surface): +def make_image(surface): pixels = FloatArray(surface.height*surface.width*4) surface.get_tile_rgba(0, 0, surface.width, surface.height, pixels) @@ -52,8 +52,41 @@ def save_image(filename, surface): offset = (y*surface.width + x)*4 r, g, b, a = [int(pixels[offset + ch]*255) for ch in range(4)] outpixels[x, y] = r, g, b + return outimage + +def save_image(filename, surface): + outimage = make_image(surface) outimage.save(filename, "PNG") +def show_image(*surfaces): + import Tkinter as tk + from PIL import Image, ImageTk + + root = tk.Tk() + + x = 64 + y = 64 + + for i in range(len(surfaces)): + surface = surfaces[i] + outimage = make_image(surface) + + if i: + window = tk.Toplevel(root) + else: + window = root + window.title('Image %u' % (i+1)) + image1 = ImageTk.PhotoImage(outimage) + w = image1.width() + h = image1.height() + window.geometry("%dx%d+%d+%d" % (w, h, x, y)) + panel1 = tk.Label(window, image=image1) + panel1.pack(side='top', fill='both', expand='yes') + panel1.image = image1 + x += w + 2 + + root.mainloop() + class Test: diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index ad11e8dcc9..84ceebb169 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -27,13 +27,14 @@ ########################################################################## +import sys from gallium import * from base import * from data import generate_data def compare_rgba(width, height, rgba1, rgba2, tol=0.01): - result = True + errors = 0 for y in range(0, height): for x in range(0, width): for ch in range(4): @@ -41,9 +42,14 @@ def compare_rgba(width, height, rgba1, rgba2, tol=0.01): v1 = rgba1[offset] v2 = rgba2[offset] if abs(v1 - v2) > tol: - sys.stderr.write("x=%u, y=%u, ch=%u differ: %f vs %f\n", - x, y, ch, v1, v2) - result = False + if errors == 0: + sys.stderr.write("x=%u, y=%u, ch=%u differ: %f vs %f\n" % (x, y, ch, v1, v2)) + if errors == 1: + sys.stderr.write("...\n") + errors += 1 + if errors: + sys.stderr.write("%u out of %u pixels differ\n" % (errors/4, height*width)) + return errors == 0 class TextureTest(Test): @@ -65,8 +71,8 @@ class TextureTest(Test): ctx = dev.context_create() - width = 256 - height = 256 + width = 64 + height = 64 # disabled blending/masking blend = Blend() @@ -122,21 +128,21 @@ class TextureTest(Test): height) ctx.set_sampler_texture(0, texture) - surface = texture.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE) - - expected_rgba = generate_data(surface) + expected_rgba = generate_data(texture.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE)) cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, width, - height) + height, + usage = PIPE_TEXTURE_USAGE_RENDER_TARGET) # drawing dest - cbuf = cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_GPU_WRITE) + cbuf = cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_GPU_WRITE|PIPE_BUFFER_USAGE_GPU_READ) fb = Framebuffer() - fb.width = cbuf.width - fb.height = cbuf.height + fb.width = width + fb.height = height fb.num_cbufs = 1 fb.set_cbuf(0, cbuf) + ctx.surface_clear(cbuf, 0x00000000) ctx.set_framebuffer(fb) # vertex shader @@ -164,7 +170,7 @@ class TextureTest(Test): ''') fs.dump() ctx.set_fragment_shader(fs) - + nverts = 4 nattrs = 2 verts = FloatArray(nverts * nattrs * 4) @@ -207,23 +213,21 @@ class TextureTest(Test): verts[30] = 0.0 verts[31] = 0.0 - ctx.surface_clear(cbuf, 0x00000000) - ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, nverts, nattrs, verts) ctx.flush() - - rgba = FloatArray(surface.height*surface.width*4) - cbuf.get_tile_rgba(x, y, w, h, rgba) + rgba = FloatArray(height*width*4) + + cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ).get_tile_rgba(x, y, w, h, rgba) compare_rgba(width, height, rgba, expected_rgba) - #save_image("texture1.png", surface) - #save_image("texture2.png", cbuf) + show_image(texture.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ), + cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ)) def main(): -- cgit v1.2.3 From 3392bcaaa823bd791e8d7e4c5a7ce013831899bb Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 15 Jul 2008 17:57:48 +0900 Subject: python: Cleanup. --- src/gallium/state_trackers/python/samples/tri.py | 8 ------ src/gallium/state_trackers/python/tests/base.py | 31 +++++++++++----------- src/gallium/state_trackers/python/tests/texture.py | 14 +++++----- 3 files changed, 23 insertions(+), 30 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/samples/tri.py b/src/gallium/state_trackers/python/samples/tri.py index e5044a0245..3665922929 100644 --- a/src/gallium/state_trackers/python/samples/tri.py +++ b/src/gallium/state_trackers/python/samples/tri.py @@ -143,24 +143,16 @@ def test(dev): cbuf = dev.texture_create(PIPE_FORMAT_X8R8G8B8_UNORM, width, height, usage=PIPE_TEXTURE_USAGE_DISPLAY_TARGET) - zbuf = dev.texture_create(PIPE_FORMAT_X8Z24_UNORM, - width, height, - usage=PIPE_TEXTURE_USAGE_DEPTH_STENCIL) _cbuf = cbuf.get_surface(usage = PIPE_BUFFER_USAGE_GPU_READ|PIPE_BUFFER_USAGE_GPU_WRITE) - _zsbuf = zbuf.get_surface(usage = PIPE_BUFFER_USAGE_GPU_READ|PIPE_BUFFER_USAGE_GPU_WRITE) fb = Framebuffer() fb.width = width fb.height = height fb.num_cbufs = 1 fb.set_cbuf(0, _cbuf) - fb.set_zsbuf(_zsbuf) ctx.set_framebuffer(fb) _cbuf.clear_value = 0x00000000 - _zsbuf.clear_value = 0x00ffffff ctx.surface_clear(_cbuf, _cbuf.clear_value) - ctx.surface_clear(_zsbuf, _zsbuf.clear_value) del _cbuf - del _zsbuf # vertex shader vs = Shader(''' diff --git a/src/gallium/state_trackers/python/tests/base.py b/src/gallium/state_trackers/python/tests/base.py index 185a59996e..d5d6114a45 100644 --- a/src/gallium/state_trackers/python/tests/base.py +++ b/src/gallium/state_trackers/python/tests/base.py @@ -37,28 +37,25 @@ for name, value in globals().items(): formats[value] = name -def make_image(surface): - pixels = FloatArray(surface.height*surface.width*4) - surface.get_tile_rgba(0, 0, surface.width, surface.height, pixels) - +def make_image(width, height, rgba): import Image outimage = Image.new( mode='RGB', - size=(surface.width, surface.height), + size=(width, height), color=(0,0,0)) outpixels = outimage.load() - for y in range(0, surface.height): - for x in range(0, surface.width): - offset = (y*surface.width + x)*4 - r, g, b, a = [int(pixels[offset + ch]*255) for ch in range(4)] + for y in range(0, height): + for x in range(0, width): + offset = (y*width + x)*4 + r, g, b, a = [int(rgba[offset + ch]*255) for ch in range(4)] outpixels[x, y] = r, g, b return outimage -def save_image(filename, surface): - outimage = make_image(surface) +def save_image(width, height, rgba, filename): + outimage = make_image(width, height, rgba) outimage.save(filename, "PNG") -def show_image(*surfaces): +def show_image(width, height, **rgbas): import Tkinter as tk from PIL import Image, ImageTk @@ -67,15 +64,17 @@ def show_image(*surfaces): x = 64 y = 64 - for i in range(len(surfaces)): - surface = surfaces[i] - outimage = make_image(surface) + labels = rgbas.keys() + labels.sort() + for i in range(len(labels)): + label = labels[i] + outimage = make_image(width, height, rgbas[label]) if i: window = tk.Toplevel(root) else: window = root - window.title('Image %u' % (i+1)) + window.title(label) image1 = ImageTk.PhotoImage(outimage) w = image1.width() h = image1.height() diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index 84ceebb169..6a5ffb38b9 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -61,8 +61,8 @@ class TextureTest(Test): def run(self): dev = self.dev - format = PIPE_FORMAT_A8R8G8B8_UNORM - #format = PIPE_FORMAT_DXT1_RGB + #format = PIPE_FORMAT_A8R8G8B8_UNORM + format = PIPE_FORMAT_DXT1_RGB if not dev.is_format_supported(format, PIPE_TEXTURE): pass @@ -130,20 +130,21 @@ class TextureTest(Test): expected_rgba = generate_data(texture.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE)) + # framebuffer cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, width, height, usage = PIPE_TEXTURE_USAGE_RENDER_TARGET) - # drawing dest cbuf = cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_GPU_WRITE|PIPE_BUFFER_USAGE_GPU_READ) fb = Framebuffer() fb.width = width fb.height = height fb.num_cbufs = 1 fb.set_cbuf(0, cbuf) - ctx.surface_clear(cbuf, 0x00000000) ctx.set_framebuffer(fb) + ctx.surface_clear(cbuf, 0x00000000) + del fb # vertex shader vs = Shader(''' @@ -220,14 +221,15 @@ class TextureTest(Test): ctx.flush() + del ctx + rgba = FloatArray(height*width*4) cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ).get_tile_rgba(x, y, w, h, rgba) compare_rgba(width, height, rgba, expected_rgba) - show_image(texture.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ), - cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ)) + show_image(width, height, Result=rgba, Expected=expected_rgba) def main(): -- cgit v1.2.3 From 70b1ff9ff39ca29bdbd25b31ebb183eea683d625 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 16 Jul 2008 14:11:45 +0900 Subject: python: Expand the texture test suit to cover one YUV and one DXT format. --- src/gallium/state_trackers/python/tests/base.py | 6 +++- src/gallium/state_trackers/python/tests/data.py | 31 +++++++++++------ src/gallium/state_trackers/python/tests/texture.py | 40 +++++++++++++++------- 3 files changed, 53 insertions(+), 24 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/tests/base.py b/src/gallium/state_trackers/python/tests/base.py index d5d6114a45..d83abdfa76 100644 --- a/src/gallium/state_trackers/python/tests/base.py +++ b/src/gallium/state_trackers/python/tests/base.py @@ -93,6 +93,9 @@ class Test: def __init__(self): pass + def description(self): + raise NotImplementedError + def run(self): raise NotImplementedError @@ -111,7 +114,8 @@ class TestSuite(Test): def run(self): for test in self.tests: - self.test.run() + print "Running %s..." % test.description() + test.run() class TextureTemplate: diff --git a/src/gallium/state_trackers/python/tests/data.py b/src/gallium/state_trackers/python/tests/data.py index 2287884285..3c1cda59d7 100644 --- a/src/gallium/state_trackers/python/tests/data.py +++ b/src/gallium/state_trackers/python/tests/data.py @@ -211,7 +211,6 @@ dxt1_rgba = [ def generate_data_compressed(surface, blocks): - pixels, block = blocks[0] stride = surface.nblocksx*surface.block.size size = surface.nblocksy*stride @@ -219,19 +218,23 @@ def generate_data_compressed(surface, blocks): raw = ByteArray(size) rgba = FloatArray(surface.height*surface.width*4) - for y in range(0, surface.nblocksx): - for x in range(0, surface.nblocksy): + for yj in range(0, surface.nblocksy): + for xj in range(0, surface.nblocksx): + pixels, block = blocks[random.randint(0, len(blocks) - 1)] - offset = (y*surface.nblocksx + x)*surface.block.width + offset = (yj*surface.nblocksx + xj)*surface.block.size for i in range(0, surface.block.size): raw[offset + i] = block[i] - for j in range(0, surface.block.width): - for i in range(0, surface.block.height): - offset = ((y*surface.block.height + j)*surface.width + x*surface.block.width + i)*4 - pixel = pixels[j*surface.block.width + i] - for ch in range(0, 4): - rgba[offset + ch] = float(pixel[ch])/255.0 + for yi in range(0, surface.block.height): + for xi in range(0, surface.block.width): + y = yj*surface.block.height + yi + x = xj*surface.block.width + xi + if y < surface.height and x < surface.width: + offset = (y*surface.width + x)*4 + pixel = pixels[yi*surface.block.width + xi] + for ch in range(0, 4): + rgba[offset + ch] = float(pixel[ch])/255.0 surface.put_tile_raw(0, 0, surface.width, surface.height, raw, stride) @@ -252,6 +255,14 @@ def generate_data_simple(surface): surface.get_tile_rgba(0, 0, surface.width, surface.height, rgba) + if surface.format in (PIPE_FORMAT_YCBCR, PIPE_FORMAT_YCBCR_REV): + # normalize + for y in range(0, surface.height): + for x in range(0, surface.width): + for ch in range(4): + offset = (y*surface.width + x)*4 + ch + rgba[offset] = min(max(rgba[offset], 0.0), 1.0) + return rgba diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index 6a5ffb38b9..7812d8aebf 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -33,7 +33,7 @@ from base import * from data import generate_data -def compare_rgba(width, height, rgba1, rgba2, tol=0.01): +def compare_rgba(width, height, rgba1, rgba2, tol=4.0/256): errors = 0 for y in range(0, height): for x in range(0, width): @@ -58,22 +58,25 @@ class TextureTest(Test): Test.__init__(self) self.__dict__.update(kargs) + def description(self): + return "%s %ux%u" % (formats[self.format], self.width, self.height) + def run(self): dev = self.dev - #format = PIPE_FORMAT_A8R8G8B8_UNORM - format = PIPE_FORMAT_DXT1_RGB + format = self.format + width = self.width + height = self.height if not dev.is_format_supported(format, PIPE_TEXTURE): - pass + print "SKIP" + return if not dev.is_format_supported(format, PIPE_SURFACE): - pass + print "SKIP" + return ctx = dev.context_create() - width = 64 - height = 64 - # disabled blending/masking blend = Blend() blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE @@ -169,7 +172,7 @@ class TextureTest(Test): 0:TEX OUT[0], IN[0], SAMP[0], 2D 1:END ''') - fs.dump() + #fs.dump() ctx.set_fragment_shader(fs) nverts = 4 @@ -227,15 +230,26 @@ class TextureTest(Test): cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ).get_tile_rgba(x, y, w, h, rgba) - compare_rgba(width, height, rgba, expected_rgba) + if compare_rgba(width, height, rgba, expected_rgba): + print "OK" + else: + print "FAIL" - show_image(width, height, Result=rgba, Expected=expected_rgba) + show_image(width, height, Result=rgba, Expected=expected_rgba) + #save_image(width, height, rgba, "result.png") + #save_image(width, height, expected_rgba, "expected.png") + sys.exit(0) def main(): dev = Device() - test = TextureTest(dev = dev) - test.run() + suite = TestSuite() + formats = [PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_YCBCR, PIPE_FORMAT_DXT1_RGB] + sizes = [64, 32, 16, 8, 4, 2] + for format in formats: + for size in sizes: + suite.add_test(TextureTest(dev=dev, format=format, width=size, height=size)) + suite.run() if __name__ == '__main__': -- cgit v1.2.3 From 32fe752d31a07293ad68cccb2fffbbfef32ab449 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 16 Jul 2008 19:36:59 +0900 Subject: python: Test all miplevels. --- src/gallium/state_trackers/python/tests/base.py | 87 ++++++++++++++++++---- src/gallium/state_trackers/python/tests/texture.py | 72 +++++++++++------- 2 files changed, 116 insertions(+), 43 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/tests/base.py b/src/gallium/state_trackers/python/tests/base.py index d83abdfa76..c50abf7f69 100644 --- a/src/gallium/state_trackers/python/tests/base.py +++ b/src/gallium/state_trackers/python/tests/base.py @@ -27,6 +27,12 @@ ########################################################################## +"""Base classes for tests. + +Loosely inspired on Python's unittest module. +""" + + from gallium import * @@ -87,17 +93,54 @@ def show_image(width, height, **rgbas): root.mainloop() +class TestFailure(Exception): -class Test: + pass + +class TestSkip(Exception): + pass + + +class Test: + def __init__(self): pass + + def _run(self, result): + raise NotImplementedError + def run(self): + result = TestResult() + self._run(result) + result.summary() + + +class TestCase(Test): + + def __init__(self, dev, **kargs): + Test.__init__(self) + self.dev = dev + self.__dict__.update(kargs) + def description(self): raise NotImplementedError - def run(self): + def test(self): raise NotImplementedError + + def _run(self, result): + result.test_start(self) + try: + self.test() + except KeyboardInterrupt: + raise + except TestSkip: + result.test_skipped(self) + except TestFailure: + result.test_failed(self) + else: + result.test_passed(self) class TestSuite(Test): @@ -112,21 +155,35 @@ class TestSuite(Test): def add_test(self, test): self.tests.append(test) - def run(self): + def _run(self, result): for test in self.tests: - print "Running %s..." % test.description() - test.run() + test._run(result) -class TextureTemplate: +class TestResult: - def __init__(self, format=PIPE_FORMAT_R8G8B8A8_UNORM, width=1, height=1, depth=1, last_level=0, target=PIPE_TEXTURE_2D): - self.format = format - self.width = width - self.height = height - self.depth = depth - self.last_level = last_level - self.target = target - - + def __init__(self): + self.tests = 0 + self.passed = 0 + self.skipped = 0 + self.failed = 0 + + def test_start(self, test): + self.tests += 1 + print "Running %s..." % test.description() + + def test_passed(self, test): + self.passed += 1 + print "PASS" + + def test_skipped(self, test): + self.skipped += 1 + print "SKIP" + + def test_failed(self): + self.failed += 1 + print "FAIL" + def summary(self): + print "%u tests, %u passed, %u skipped, %u failed" % (self.tests, self.passed, self.skipped, self.failed) + \ No newline at end of file diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index 7812d8aebf..7c7245e65c 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -52,30 +52,39 @@ def compare_rgba(width, height, rgba1, rgba2, tol=4.0/256): return errors == 0 -class TextureTest(Test): - - def __init__(self, **kargs): - Test.__init__(self) - self.__dict__.update(kargs) +def lods(*dims): + size = max(dims) + lods = 0 + while size: + lods += 1 + size >>= 1 + return lods + + +def minify(dims, level = 1): + return [max(dim>>level, 1) for dim in dims] + +class TextureTest(TestCase): + def description(self): - return "%s %ux%u" % (formats[self.format], self.width, self.height) - - def run(self): + return "%s %ux%u level=%u" % (formats[self.format], self.width, self.height, self.level) + + def test(self): dev = self.dev format = self.format width = self.width height = self.height + level = self.level + + levels = lods(width, height) + if not dev.is_format_supported(format, PIPE_TEXTURE): - print "SKIP" - return - if not dev.is_format_supported(format, PIPE_SURFACE): - print "SKIP" - return + raise TestSkip - ctx = dev.context_create() + ctx = self.dev.context_create() # disabled blending/masking blend = Blend() @@ -123,15 +132,20 @@ class TextureTest(Test): sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST sampler.normalized_coords = 1 + sampler.min_lod = level + sampler.max_lod = level ctx.set_sampler(0, sampler) # texture texture = dev.texture_create(format, width, - height) + height, + last_level = levels - 1) ctx.set_sampler_texture(0, texture) - expected_rgba = generate_data(texture.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE)) + expected_rgba = generate_data(texture.get_surface( + usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE, + level = level)) # framebuffer cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, @@ -181,8 +195,7 @@ class TextureTest(Test): x = 0 y = 0 - w = width - h = height + w, h = minify((width, height), level) verts[ 0] = x # x1 verts[ 1] = y # y1 @@ -223,32 +236,35 @@ class TextureTest(Test): verts) ctx.flush() - - del ctx - - rgba = FloatArray(height*width*4) + + rgba = FloatArray(h*w*4) cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ).get_tile_rgba(x, y, w, h, rgba) - if compare_rgba(width, height, rgba, expected_rgba): - print "OK" - else: - print "FAIL" + if not compare_rgba(w, h, rgba, expected_rgba): - show_image(width, height, Result=rgba, Expected=expected_rgba) + show_image(w, h, Result=rgba, Expected=expected_rgba) #save_image(width, height, rgba, "result.png") #save_image(width, height, expected_rgba, "expected.png") sys.exit(0) + + raise TestFailure + + del ctx + def main(): dev = Device() suite = TestSuite() formats = [PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_YCBCR, PIPE_FORMAT_DXT1_RGB] + #formats = [PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_DXT1_RGB] sizes = [64, 32, 16, 8, 4, 2] for format in formats: for size in sizes: - suite.add_test(TextureTest(dev=dev, format=format, width=size, height=size)) + levels = lods(size) + for level in range(levels): + suite.add_test(TextureTest(dev=dev, format=format, width=size, height=size, level=level)) suite.run() -- cgit v1.2.3 From 7f32834df3c428fa283e966982926c94630b1b8e Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 16 Jul 2008 23:27:15 +0900 Subject: python/tests: Extend the texture tests to cover cube maps. --- src/gallium/state_trackers/python/tests/base.py | 8 +- src/gallium/state_trackers/python/tests/texture.py | 215 +++++++++++++++------ 2 files changed, 162 insertions(+), 61 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/tests/base.py b/src/gallium/state_trackers/python/tests/base.py index c50abf7f69..8477aa5fc9 100644 --- a/src/gallium/state_trackers/python/tests/base.py +++ b/src/gallium/state_trackers/python/tests/base.py @@ -53,7 +53,7 @@ def make_image(width, height, rgba): for y in range(0, height): for x in range(0, width): offset = (y*width + x)*4 - r, g, b, a = [int(rgba[offset + ch]*255) for ch in range(4)] + r, g, b, a = [int(min(max(rgba[offset + ch], 0.0), 1.0)*255) for ch in range(4)] outpixels[x, y] = r, g, b return outimage @@ -167,6 +167,7 @@ class TestResult: self.passed = 0 self.skipped = 0 self.failed = 0 + self.failed_descriptions = [] def test_start(self, test): self.tests += 1 @@ -180,10 +181,13 @@ class TestResult: self.skipped += 1 print "SKIP" - def test_failed(self): + def test_failed(self, test): self.failed += 1 + self.failed_descriptions.append(test.description()) print "FAIL" def summary(self): print "%u tests, %u passed, %u skipped, %u failed" % (self.tests, self.passed, self.skipped, self.failed) + for description in self.failed_descriptions: + print " %s" % description \ No newline at end of file diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index 7c7245e65c..448bdbcd3e 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -33,10 +33,11 @@ from base import * from data import generate_data -def compare_rgba(width, height, rgba1, rgba2, tol=4.0/256): +def compare_rgba(width, height, rgba1, rgba2, tol=4.0/256, ratio=0.85): errors = 0 for y in range(0, height): for x in range(0, width): + differs = 0 for ch in range(4): offset = (y*width + x)*4 + ch v1 = rgba1[offset] @@ -44,12 +45,14 @@ def compare_rgba(width, height, rgba1, rgba2, tol=4.0/256): if abs(v1 - v2) > tol: if errors == 0: sys.stderr.write("x=%u, y=%u, ch=%u differ: %f vs %f\n" % (x, y, ch, v1, v2)) - if errors == 1: + if errors == 1 and ch == 0: sys.stderr.write("...\n") - errors += 1 + differs = 1 + errors += differs + total = height*width if errors: - sys.stderr.write("%u out of %u pixels differ\n" % (errors/4, height*width)) - return errors == 0 + sys.stderr.write("%u out of %u pixels differ\n" % (errors, total)) + return float(total - errors)/float(total) >= ratio def lods(*dims): @@ -65,22 +68,87 @@ def minify(dims, level = 1): return [max(dim>>level, 1) for dim in dims] +def tex_coords(texture, face, level, zslice): + st = [ + [0.0, 0.0], + [1.0, 0.0], + [1.0, 1.0], + [0.0, 1.0], + ] + + if texture.target == PIPE_TEXTURE_2D: + return [[s, t, 0.0] for s, t in st] + elif texture.target == PIPE_TEXTURE_3D: + assert 0 + elif texture.target == PIPE_TEXTURE_CUBE: + result = [] + for s, t in st: + # See http://developer.nvidia.com/object/cube_map_ogl_tutorial.html + sc = 2.0*s - 1.0 + tc = 2.0*t - 1.0 + if face == PIPE_TEX_FACE_POS_X: + rx = 1.0 + ry = -tc + rz = -sc + if face == PIPE_TEX_FACE_NEG_X: + rx = -1.0 + ry = -tc + rz = sc + if face == PIPE_TEX_FACE_POS_Y: + rx = sc + ry = 1.0 + rz = tc + if face == PIPE_TEX_FACE_NEG_Y: + rx = sc + ry = -1.0 + rz = -tc + if face == PIPE_TEX_FACE_POS_Z: + rx = sc + ry = -tc + rz = 1.0 + if face == PIPE_TEX_FACE_NEG_Z: + rx = -sc + ry = -tc + rz = -1.0 + result.append([rx, ry, rz]) + return result + + class TextureTest(TestCase): def description(self): - return "%s %ux%u level=%u" % (formats[self.format], self.width, self.height, self.level) + target = { + PIPE_TEXTURE_1D: "1d", + PIPE_TEXTURE_2D: "2d", + PIPE_TEXTURE_3D: "3d", + PIPE_TEXTURE_CUBE: "cube", + }[self.target] + format = formats[self.format] + if self.target == PIPE_TEXTURE_CUBE: + face = { + PIPE_TEX_FACE_POS_X: "+x", + PIPE_TEX_FACE_NEG_X: "-x", + PIPE_TEX_FACE_POS_Y: "+y", + PIPE_TEX_FACE_NEG_Y: "-y", + PIPE_TEX_FACE_POS_Z: "+z", + PIPE_TEX_FACE_NEG_Z: "-z", + }[self.face] + else: + face = "" + return "%s %s %ux%u %s level=%u" % (target, format, self.width, self.height, face, self.level) def test(self): dev = self.dev + target = self.target format = self.format width = self.width height = self.height level = self.level + face = self.face levels = lods(width, height) - if not dev.is_format_supported(format, PIPE_TEXTURE): raise TestSkip @@ -128,23 +196,25 @@ class TextureTest(TestCase): sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST sampler.normalized_coords = 1 - sampler.min_lod = level - sampler.max_lod = level + sampler.min_lod = 0 + sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1 ctx.set_sampler(0, sampler) # texture - texture = dev.texture_create(format, - width, - height, + texture = dev.texture_create(target=target, + format=format, + width=width, + height=height, last_level = levels - 1) ctx.set_sampler_texture(0, texture) expected_rgba = generate_data(texture.get_surface( usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE, + face = face, level = level)) # framebuffer @@ -178,14 +248,20 @@ class TextureTest(TestCase): ctx.set_vertex_shader(vs) # fragment shader + op = { + PIPE_TEXTURE_1D: "1D", + PIPE_TEXTURE_2D: "2D", + PIPE_TEXTURE_3D: "3D", + PIPE_TEXTURE_CUBE: "CUBE", + }[target] fs = Shader(''' FRAG1.1 - DCL IN[0], GENERIC[0], PERSPECTIVE + DCL IN[0], GENERIC[0], LINEAR DCL OUT[0], COLOR, CONSTANT DCL SAMP[0], CONSTANT - 0:TEX OUT[0], IN[0], SAMP[0], 2D + 0:TEX OUT[0], IN[0], SAMP[0], %s 1:END - ''') + ''' % op) #fs.dump() ctx.set_fragment_shader(fs) @@ -197,38 +273,25 @@ class TextureTest(TestCase): y = 0 w, h = minify((width, height), level) - verts[ 0] = x # x1 - verts[ 1] = y # y1 - verts[ 2] = 0.0 # z1 - verts[ 3] = 1.0 # w1 - verts[ 4] = 0.0 # s1 - verts[ 5] = 0.0 # t - verts[ 6] = 0.0 - verts[ 7] = 0.0 - verts[ 8] = x + w # x2 - verts[ 9] = y # y2 - verts[10] = 0.0 # z2 - verts[11] = 1.0 # w2 - verts[12] = 1.0 # s2 - verts[13] = 0.0 # t2 - verts[14] = 0.0 - verts[15] = 0.0 - verts[16] = x + w # x3 - verts[17] = y + h # y3 - verts[18] = 0.0 # z3 - verts[19] = 1.0 # w3 - verts[20] = 1.0 # s3 - verts[21] = 1.0 # t3 - verts[22] = 0.0 - verts[23] = 0.0 - verts[24] = x # x4 - verts[25] = y + h # y4 - verts[26] = 0.0 # z4 - verts[27] = 1.0 # w4 - verts[28] = 0.0 # s4 - verts[29] = 1.0 # t4 - verts[30] = 0.0 - verts[31] = 0.0 + pos = [ + [x, y], + [x+w, y], + [x+w, y+h], + [x, y+h], + ] + + tex = tex_coords(texture, face, level, zslice=0) + + for i in range(0, 4): + j = 8*i + verts[j + 0] = pos[i][0] # x + verts[j + 1] = pos[i][1] # y + verts[j + 2] = 0.0 # z + verts[j + 3] = 1.0 # w + verts[j + 4] = tex[i][0] # s + verts[j + 5] = tex[i][1] # r + verts[j + 6] = tex[i][2] # q + verts[j + 7] = 1.0 ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, nverts, @@ -243,10 +306,10 @@ class TextureTest(TestCase): if not compare_rgba(w, h, rgba, expected_rgba): - show_image(w, h, Result=rgba, Expected=expected_rgba) - #save_image(width, height, rgba, "result.png") - #save_image(width, height, expected_rgba, "expected.png") - sys.exit(0) + #show_image(w, h, Result=rgba, Expected=expected_rgba) + #save_image(w, h, rgba, "result.png") + #save_image(w, h, expected_rgba, "expected.png") + #sys.exit(0) raise TestFailure @@ -257,14 +320,48 @@ class TextureTest(TestCase): def main(): dev = Device() suite = TestSuite() - formats = [PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_YCBCR, PIPE_FORMAT_DXT1_RGB] - #formats = [PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_DXT1_RGB] + + targets = [] + targets += [PIPE_TEXTURE_2D] + targets += [PIPE_TEXTURE_CUBE] + + formats = [] + formats += [PIPE_FORMAT_A8R8G8B8_UNORM] + formats += [PIPE_FORMAT_R5G6B5_UNORM] + formats += [PIPE_FORMAT_L8_UNORM] + formats += [PIPE_FORMAT_YCBCR] + formats += [PIPE_FORMAT_DXT1_RGB] + sizes = [64, 32, 16, 8, 4, 2] - for format in formats: - for size in sizes: - levels = lods(size) - for level in range(levels): - suite.add_test(TextureTest(dev=dev, format=format, width=size, height=size, level=level)) + #sizes = [16] + + for target in targets: + for format in formats: + for size in sizes: + if target == PIPE_TEXTURE_CUBE: + faces = [ + PIPE_TEX_FACE_POS_X, + PIPE_TEX_FACE_NEG_X, + PIPE_TEX_FACE_POS_Y, + PIPE_TEX_FACE_NEG_Y, + PIPE_TEX_FACE_POS_Z, + PIPE_TEX_FACE_NEG_Z, + ] + else: + faces = [0] + for face in faces: + levels = lods(size) + for level in range(levels): + test = TextureTest( + dev=dev, + target=target, + format=format, + width=size, + height=size, + face=face, + level=level, + ) + suite.add_test(test) suite.run() -- cgit v1.2.3 From f610deed37dc09922eaef1c55e3d4afe8aaa7327 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 17 Jul 2008 08:21:58 +0900 Subject: python/tests: Cover all last_level combinations. --- src/gallium/state_trackers/python/tests/texture.py | 43 +++++++++++++--------- 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index 448bdbcd3e..edaa2b8b26 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -135,7 +135,11 @@ class TextureTest(TestCase): }[self.face] else: face = "" - return "%s %s %ux%u %s level=%u" % (target, format, self.width, self.height, face, self.level) + return "%s %s %ux%u last_level=%u %s level=%u" % ( + target, format, + self.width, self.height, + self.last_level, face, self.level, + ) def test(self): dev = self.dev @@ -144,11 +148,10 @@ class TextureTest(TestCase): format = self.format width = self.width height = self.height + last_level = self.last_level level = self.level face = self.face - levels = lods(width, height) - if not dev.is_format_supported(format, PIPE_TEXTURE): raise TestSkip @@ -209,14 +212,15 @@ class TextureTest(TestCase): format=format, width=width, height=height, - last_level = levels - 1) - ctx.set_sampler_texture(0, texture) + last_level = last_level) expected_rgba = generate_data(texture.get_surface( usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE, face = face, level = level)) + ctx.set_sampler_texture(0, texture) + # framebuffer cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, width, @@ -332,8 +336,8 @@ def main(): formats += [PIPE_FORMAT_YCBCR] formats += [PIPE_FORMAT_DXT1_RGB] - sizes = [64, 32, 16, 8, 4, 2] - #sizes = [16] + sizes = [64, 32, 16, 8, 4, 2, 1] + #sizes = [64] for target in targets: for format in formats: @@ -347,21 +351,24 @@ def main(): PIPE_TEX_FACE_POS_Z, PIPE_TEX_FACE_NEG_Z, ] + #faces = [PIPE_TEX_FACE_NEG_X] else: faces = [0] for face in faces: levels = lods(size) - for level in range(levels): - test = TextureTest( - dev=dev, - target=target, - format=format, - width=size, - height=size, - face=face, - level=level, - ) - suite.add_test(test) + for last_level in range(levels): + for level in range(0, last_level + 1): + test = TextureTest( + dev=dev, + target=target, + format=format, + width=size, + height=size, + face=face, + last_level = last_level, + level=level, + ) + suite.add_test(test) suite.run() -- cgit v1.2.3 From d398e1360d5c1c0f44a4ba9cd167c39a29ce8254 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 17 Jul 2008 10:27:10 +0900 Subject: python: Reimplement tile comparison in C to speed up tests. --- src/gallium/state_trackers/python/gallium.i | 48 ++++++++++++++++++---- src/gallium/state_trackers/python/tests/texture.py | 20 +++++---- 2 files changed, 53 insertions(+), 15 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index fe0afb18a9..1c207a41b9 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -425,23 +425,23 @@ error1: void unmap( void ); void - get_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, unsigned char *p, unsigned stride) { - pipe_get_tile_raw($self, x, y, w, h, p, stride); + get_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, unsigned char *raw, unsigned stride) { + pipe_get_tile_raw($self, x, y, w, h, raw, stride); } void - put_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, const unsigned char *p, unsigned stride) { - pipe_put_tile_raw($self, x, y, w, h, p, stride); + put_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, const unsigned char *raw, unsigned stride) { + pipe_put_tile_raw($self, x, y, w, h, raw, stride); } void - get_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, float *p) { - pipe_get_tile_rgba($self, x, y, w, h, p); + get_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) { + pipe_get_tile_rgba($self, x, y, w, h, rgba); } void - put_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *p) { - pipe_put_tile_rgba($self, x, y, w, h, p); + put_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba) { + pipe_put_tile_rgba($self, x, y, w, h, rgba); } void @@ -454,6 +454,38 @@ error1: pipe_put_tile_z($self, x, y, w, h, z); } + unsigned + compare_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0) + { + float *rgba2; + const float *p1; + const float *p2; + unsigned i, j, n; + + rgba2 = MALLOC(h*w*4*sizeof(float)); + if(!rgba2) + return ~0; + + pipe_get_tile_rgba($self, x, y, w, h, rgba2); + + p1 = rgba; + p2 = rgba2; + n = 0; + for(i = h*w; i; --i) { + unsigned differs = 0; + for(j = 4; j; --j) { + float delta = *p2++ - *p1++; + if (delta < -tol || delta > tol) + differs = 1; + } + n += differs; + } + + FREE(rgba2); + + return n; + } + }; diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index edaa2b8b26..3d76953126 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -304,15 +304,21 @@ class TextureTest(TestCase): ctx.flush() - rgba = FloatArray(h*w*4) - - cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ).get_tile_rgba(x, y, w, h, rgba) + cbuf = cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ) + + total = h*w + different = cbuf.compare_tile_rgba(x, y, w, h, expected_rgba, tol=4.0/256) + if different: + sys.stderr.write("%u out of %u pixels differ\n" % (different, total)) - if not compare_rgba(w, h, rgba, expected_rgba): + if float(total - different)/float(total) < 0.85: - #show_image(w, h, Result=rgba, Expected=expected_rgba) - #save_image(w, h, rgba, "result.png") - #save_image(w, h, expected_rgba, "expected.png") + if 0: + rgba = FloatArray(h*w*4) + cbuf.get_tile_rgba(x, y, w, h, rgba) + show_image(w, h, Result=rgba, Expected=expected_rgba) + save_image(w, h, rgba, "result.png") + save_image(w, h, expected_rgba, "expected.png") #sys.exit(0) raise TestFailure -- cgit v1.2.3 From e74f94b39ac47a319ee21c526315fb6fbc1513de Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 18 Jul 2008 01:08:06 +0900 Subject: python: Reimplement the generation of random texture samples in C. --- src/gallium/state_trackers/python/SConscript | 1 + src/gallium/state_trackers/python/gallium.i | 6 + src/gallium/state_trackers/python/st_sample.c | 548 +++++++++++++++++++++ src/gallium/state_trackers/python/st_sample.h | 47 ++ src/gallium/state_trackers/python/tests/data.py | 285 ----------- src/gallium/state_trackers/python/tests/texture.py | 29 +- 6 files changed, 606 insertions(+), 310 deletions(-) create mode 100644 src/gallium/state_trackers/python/st_sample.c create mode 100644 src/gallium/state_trackers/python/st_sample.h delete mode 100644 src/gallium/state_trackers/python/tests/data.py (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/SConscript b/src/gallium/state_trackers/python/SConscript index b284d2020b..973d96d55a 100644 --- a/src/gallium/state_trackers/python/SConscript +++ b/src/gallium/state_trackers/python/SConscript @@ -20,6 +20,7 @@ if 'python' in env['statetrackers']: source = [ 'gallium.i', 'st_device.c', + 'st_sample.c', 'st_softpipe_winsys.c', ], ) diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index 1c207a41b9..d5b24b04ff 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -51,6 +51,7 @@ #include "tgsi/util/tgsi_dump.h" #include "st_device.h" +#include "st_sample.h" %} @@ -454,6 +455,11 @@ error1: pipe_put_tile_z($self, x, y, w, h, z); } + void + sample_rgba(float *rgba) { + st_sample_surface($self, rgba); + } + unsigned compare_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0) { diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c new file mode 100644 index 0000000000..b47c7be293 --- /dev/null +++ b/src/gallium/state_trackers/python/st_sample.c @@ -0,0 +1,548 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "pipe/p_util.h" +#include "pipe/p_inlines.h" +#include "util/p_tile.h" + +#include "st_sample.h" + + +/** + * Use our own pseudo random generator to ensure consistent runs among + * multiple runs and platforms. + * + * @sa http://en.wikipedia.org/wiki/Linear_congruential_generator + */ +static uint32_t st_random(void) { + static uint64_t seed = UINT64_C(0xbb9a063afb0a739d); + + seed = UINT64_C(134775813) * seed + UINT64_C(1); + + return (uint16_t)(seed >> 32); +} + + +/** + * We don't want to include the patent-encumbered DXT code here, so instead + * we store several uncompressed/compressed data pairs for hardware testing + * purposes. + */ +struct dxt_data +{ + uint8_t rgba[16*4]; + uint8_t raw[16]; +}; + + +static const struct dxt_data +dxt1_rgb_data[] = { + { + { + 0x99, 0xb0, 0x8e, 0xff, + 0x5d, 0x62, 0x89, 0xff, + 0x99, 0xb0, 0x8e, 0xff, + 0x99, 0xb0, 0x8e, 0xff, + 0xd6, 0xff, 0x94, 0xff, + 0x5d, 0x62, 0x89, 0xff, + 0x99, 0xb0, 0x8e, 0xff, + 0xd6, 0xff, 0x94, 0xff, + 0x5d, 0x62, 0x89, 0xff, + 0x5d, 0x62, 0x89, 0xff, + 0x99, 0xb0, 0x8e, 0xff, + 0x21, 0x14, 0x84, 0xff, + 0x5d, 0x62, 0x89, 0xff, + 0x21, 0x14, 0x84, 0xff, + 0x21, 0x14, 0x84, 0xff, + 0x99, 0xb0, 0x8e, 0xff + }, + {0xf2, 0xd7, 0xb0, 0x20, 0xae, 0x2c, 0x6f, 0x97} + }, + { + { + 0xb5, 0xcf, 0x9c, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0x21, 0x08, 0x6b, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0x52, 0x4a, 0x7b, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0xb5, 0xcf, 0x9c, 0xff, + 0x21, 0x08, 0x6b, 0xff, + 0xb5, 0xcf, 0x9c, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0x52, 0x4a, 0x7b, 0xff, + 0xb5, 0xcf, 0x9c, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0x52, 0x4a, 0x7b, 0xff, + 0x83, 0x8c, 0x8b, 0xff + }, + {0x73, 0xb6, 0x4d, 0x20, 0x98, 0x2b, 0xe1, 0xb8} + }, + { + { + 0x00, 0x2c, 0xff, 0xff, + 0x94, 0x8d, 0x7b, 0xff, + 0x4a, 0x5c, 0xbd, 0xff, + 0x4a, 0x5c, 0xbd, 0xff, + 0x4a, 0x5c, 0xbd, 0xff, + 0x94, 0x8d, 0x7b, 0xff, + 0x94, 0x8d, 0x7b, 0xff, + 0x94, 0x8d, 0x7b, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0x94, 0x8d, 0x7b, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0x94, 0x8d, 0x7b, 0xff + }, + {0xe7, 0xdd, 0x7f, 0x01, 0xf9, 0xab, 0x08, 0x80} + }, + { + { + 0x6b, 0x24, 0x21, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x8b, 0x7a, 0x99, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x6b, 0x24, 0x21, 0xff, + 0x8b, 0x7a, 0x99, 0xff, + 0x9c, 0xa6, 0xd6, 0xff, + 0x6b, 0x24, 0x21, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x8b, 0x7a, 0x99, 0xff, + 0x6b, 0x24, 0x21, 0xff, + 0x8b, 0x7a, 0x99, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x9c, 0xa6, 0xd6, 0xff + }, + {0x3a, 0x9d, 0x24, 0x69, 0xbd, 0x9f, 0xb4, 0x39} + } +}; + + +static const struct dxt_data +dxt1_rgba_data[] = { + { + { + 0x00, 0x00, 0x00, 0x00, + 0x4e, 0xaa, 0x90, 0xff, + 0x4e, 0xaa, 0x90, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x4e, 0xaa, 0x90, 0xff, + 0x29, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x4e, 0xaa, 0x90, 0xff, + 0x73, 0x55, 0x21, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x4e, 0xaa, 0x90, 0xff, + 0x4e, 0xaa, 0x90, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x4e, 0xaa, 0x90, 0xff + }, + {0xff, 0x2f, 0xa4, 0x72, 0xeb, 0xb2, 0xbd, 0xbe} + }, + { + { + 0xb5, 0xe3, 0x63, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x6b, 0x24, 0x84, 0xff, + 0xb5, 0xe3, 0x63, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0xb5, 0xe3, 0x63, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x6b, 0x24, 0x84, 0xff, + 0x6b, 0x24, 0x84, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0xb5, 0xe3, 0x63, 0xff, + 0x90, 0x83, 0x73, 0xff, + 0xb5, 0xe3, 0x63, 0xff + }, + {0x30, 0x69, 0x0c, 0xb7, 0x4d, 0xf7, 0x0f, 0x67} + }, + { + { + 0x00, 0x00, 0x00, 0x00, + 0xc6, 0x86, 0x8c, 0xff, + 0xc6, 0x86, 0x8c, 0xff, + 0x21, 0x65, 0x42, 0xff, + 0x21, 0x65, 0x42, 0xff, + 0x21, 0x65, 0x42, 0xff, + 0x21, 0x65, 0x42, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x21, 0x65, 0x42, 0xff, + 0xc6, 0x86, 0x8c, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0xc6, 0x86, 0x8c, 0xff + }, + {0x28, 0x23, 0x31, 0xc4, 0x17, 0xc0, 0xd3, 0x7f} + }, + { + { + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0xc6, 0xe3, 0x9c, 0xff, + 0x7b, 0x1c, 0x52, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x7b, 0x1c, 0x52, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x7b, 0x1c, 0x52, 0xff, + 0xa0, 0x7f, 0x77, 0xff, + 0xc6, 0xe3, 0x9c, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0xa0, 0x7f, 0x77, 0xff + }, + {0xea, 0x78, 0x13, 0xc7, 0x7f, 0xfc, 0x33, 0xb6} + }, +}; + + +static const struct dxt_data +dxt3_rgba_data[] = { + { + { + 0x6d, 0xc6, 0x96, 0x77, + 0x6d, 0xc6, 0x96, 0xee, + 0x6d, 0xc6, 0x96, 0xaa, + 0x8c, 0xff, 0xb5, 0x44, + 0x6d, 0xc6, 0x96, 0xff, + 0x6d, 0xc6, 0x96, 0x88, + 0x31, 0x55, 0x5a, 0x66, + 0x6d, 0xc6, 0x96, 0x99, + 0x31, 0x55, 0x5a, 0xbb, + 0x31, 0x55, 0x5a, 0x55, + 0x31, 0x55, 0x5a, 0x11, + 0x6d, 0xc6, 0x96, 0xcc, + 0x6d, 0xc6, 0x96, 0xcc, + 0x6d, 0xc6, 0x96, 0x11, + 0x31, 0x55, 0x5a, 0x44, + 0x31, 0x55, 0x5a, 0x88 + }, + {0xe7, 0x4a, 0x8f, 0x96, 0x5b, 0xc1, 0x1c, 0x84, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a} + }, + { + { + 0xad, 0xeb, 0x73, 0x99, + 0x97, 0xaa, 0x86, 0x66, + 0x6b, 0x28, 0xad, 0x99, + 0xad, 0xeb, 0x73, 0x99, + 0x6b, 0x28, 0xad, 0x22, + 0xad, 0xeb, 0x73, 0xff, + 0x97, 0xaa, 0x86, 0x55, + 0x6b, 0x28, 0xad, 0x55, + 0x6b, 0x28, 0xad, 0x44, + 0xad, 0xeb, 0x73, 0x33, + 0x6b, 0x28, 0xad, 0xee, + 0x6b, 0x28, 0xad, 0x99, + 0x97, 0xaa, 0x86, 0x66, + 0xad, 0xeb, 0x73, 0xbb, + 0x97, 0xaa, 0x86, 0x99, + 0xad, 0xeb, 0x73, 0xbb + }, + {0x69, 0x99, 0xf2, 0x55, 0x34, 0x9e, 0xb6, 0xb9, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22} + }, + { + { + 0x63, 0xd7, 0xd6, 0x00, + 0x57, 0x62, 0x5d, 0xdd, + 0x57, 0x62, 0x5d, 0xcc, + 0x57, 0x62, 0x5d, 0xbb, + 0x52, 0x28, 0x21, 0xaa, + 0x57, 0x62, 0x5d, 0xcc, + 0x57, 0x62, 0x5d, 0xcc, + 0x57, 0x62, 0x5d, 0x66, + 0x57, 0x62, 0x5d, 0x22, + 0x57, 0x62, 0x5d, 0xdd, + 0x63, 0xd7, 0xd6, 0xee, + 0x57, 0x62, 0x5d, 0x33, + 0x63, 0xd7, 0xd6, 0x55, + 0x52, 0x28, 0x21, 0x55, + 0x57, 0x62, 0x5d, 0x11, + 0x5d, 0x9c, 0x99, 0xee + }, + {0xd0, 0xbc, 0xca, 0x6c, 0xd2, 0x3e, 0x55, 0xe1, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4} + }, + { + { + 0x94, 0x6f, 0x60, 0x22, + 0x94, 0x6f, 0x60, 0x22, + 0xc5, 0xab, 0x76, 0x11, + 0xc5, 0xab, 0x76, 0xee, + 0x63, 0x34, 0x4a, 0xdd, + 0x63, 0x34, 0x4a, 0x33, + 0x94, 0x6f, 0x60, 0x77, + 0xf7, 0xe7, 0x8c, 0x00, + 0x94, 0x6f, 0x60, 0x33, + 0x63, 0x34, 0x4a, 0xaa, + 0x94, 0x6f, 0x60, 0x77, + 0x63, 0x34, 0x4a, 0xcc, + 0x94, 0x6f, 0x60, 0xaa, + 0xf7, 0xe7, 0x8c, 0x99, + 0x63, 0x34, 0x4a, 0x44, + 0xc5, 0xab, 0x76, 0xaa + }, + {0x22, 0xe1, 0x3d, 0x07, 0xa3, 0xc7, 0x9a, 0xa4, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93} + }, +}; + + +static const struct dxt_data +dxt5_rgba_data[] = { + { + { + 0x6d, 0xc6, 0x96, 0x74, + 0x6d, 0xc6, 0x96, 0xf8, + 0x6d, 0xc6, 0x96, 0xb6, + 0x8c, 0xff, 0xb5, 0x53, + 0x6d, 0xc6, 0x96, 0xf8, + 0x6d, 0xc6, 0x96, 0x95, + 0x31, 0x55, 0x5a, 0x53, + 0x6d, 0xc6, 0x96, 0x95, + 0x31, 0x55, 0x5a, 0xb6, + 0x31, 0x55, 0x5a, 0x53, + 0x31, 0x55, 0x5a, 0x11, + 0x6d, 0xc6, 0x96, 0xd7, + 0x6d, 0xc6, 0x96, 0xb6, + 0x6d, 0xc6, 0x96, 0x11, + 0x31, 0x55, 0x5a, 0x32, + 0x31, 0x55, 0x5a, 0x95 + }, + {0xf8, 0x11, 0xc5, 0x0c, 0x9a, 0x73, 0xb4, 0x9c, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a} + }, + { + { + 0xad, 0xeb, 0x73, 0xa1, + 0x97, 0xaa, 0x86, 0x65, + 0x6b, 0x28, 0xad, 0xa1, + 0xad, 0xeb, 0x73, 0xa1, + 0x6b, 0x28, 0xad, 0x2a, + 0xad, 0xeb, 0x73, 0xfb, + 0x97, 0xaa, 0x86, 0x47, + 0x6b, 0x28, 0xad, 0x65, + 0x6b, 0x28, 0xad, 0x47, + 0xad, 0xeb, 0x73, 0x47, + 0x6b, 0x28, 0xad, 0xdd, + 0x6b, 0x28, 0xad, 0xa1, + 0x97, 0xaa, 0x86, 0x65, + 0xad, 0xeb, 0x73, 0xbf, + 0x97, 0xaa, 0x86, 0xa1, + 0xad, 0xeb, 0x73, 0xbf + }, + {0xfb, 0x2a, 0x34, 0x19, 0xdc, 0xbf, 0xe8, 0x71, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22} + }, + { + { + 0x63, 0xd7, 0xd6, 0x00, + 0x57, 0x62, 0x5d, 0xf5, + 0x57, 0x62, 0x5d, 0xd2, + 0x57, 0x62, 0x5d, 0xaf, + 0x52, 0x28, 0x21, 0xaf, + 0x57, 0x62, 0x5d, 0xd2, + 0x57, 0x62, 0x5d, 0xd2, + 0x57, 0x62, 0x5d, 0x69, + 0x57, 0x62, 0x5d, 0x23, + 0x57, 0x62, 0x5d, 0xd2, + 0x63, 0xd7, 0xd6, 0xf5, + 0x57, 0x62, 0x5d, 0x46, + 0x63, 0xd7, 0xd6, 0x46, + 0x52, 0x28, 0x21, 0x69, + 0x57, 0x62, 0x5d, 0x23, + 0x5d, 0x9c, 0x99, 0xf5 + }, + {0xf5, 0x00, 0x81, 0x36, 0xa9, 0x17, 0xec, 0x1e, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4} + }, + { + { + 0x94, 0x6f, 0x60, 0x25, + 0x94, 0x6f, 0x60, 0x25, + 0xc5, 0xab, 0x76, 0x05, + 0xc5, 0xab, 0x76, 0xe8, + 0x63, 0x34, 0x4a, 0xe8, + 0x63, 0x34, 0x4a, 0x25, + 0x94, 0x6f, 0x60, 0x86, + 0xf7, 0xe7, 0x8c, 0x05, + 0x94, 0x6f, 0x60, 0x25, + 0x63, 0x34, 0x4a, 0xa7, + 0x94, 0x6f, 0x60, 0x66, + 0x63, 0x34, 0x4a, 0xc7, + 0x94, 0x6f, 0x60, 0xa7, + 0xf7, 0xe7, 0x8c, 0xa7, + 0x63, 0x34, 0x4a, 0x45, + 0xc5, 0xab, 0x76, 0xa7 + }, + {0xe8, 0x05, 0x7f, 0x80, 0x33, 0x5f, 0xb5, 0x79, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93} + }, +}; + + +static INLINE void +st_sample_dxt_pixel_block(enum pipe_format format, + const struct pipe_format_block *block, + uint8_t *raw, + float *rgba, unsigned rgba_stride, + unsigned w, unsigned h) +{ + const struct dxt_data *data; + unsigned n; + unsigned i; + unsigned x, y, ch; + + switch(format) { + case PIPE_FORMAT_DXT1_RGB: + data = dxt1_rgb_data; + n = sizeof(dxt1_rgb_data)/sizeof(dxt1_rgb_data[0]); + break; + case PIPE_FORMAT_DXT1_RGBA: + data = dxt1_rgba_data; + n = sizeof(dxt1_rgba_data)/sizeof(dxt1_rgba_data[0]); + break; + case PIPE_FORMAT_DXT3_RGBA: + data = dxt3_rgba_data; + n = sizeof(dxt3_rgba_data)/sizeof(dxt3_rgba_data[0]); + break; + case PIPE_FORMAT_DXT5_RGBA: + data = dxt5_rgba_data; + n = sizeof(dxt5_rgba_data)/sizeof(dxt5_rgba_data[0]); + break; + default: + assert(0); + } + + i = st_random() % n; + + for(y = 0; y < h; ++y) + for(x = 0; x < w; ++x) + for(ch = 0; ch < 4; ++ch) + rgba[y*rgba_stride + x*4 + ch] = (float)(data[i].rgba[y*4*4 + x*4 + ch])/255.0f; + + memcpy(raw, data[i].raw, block->size); +} + + +static INLINE void +st_sample_generic_pixel_block(enum pipe_format format, + const struct pipe_format_block *block, + uint8_t *raw, + float *rgba, unsigned rgba_stride, + unsigned w, unsigned h) +{ + unsigned i; + unsigned x, y, ch; + + for(i = 0; i < block->size; ++i) + raw[i] = (uint8_t)st_random(); + + + pipe_tile_raw_to_rgba(format, + raw, + w, h, + rgba, rgba_stride); + + if(format == PIPE_FORMAT_YCBCR || format == PIPE_FORMAT_YCBCR_REV) { + for(y = 0; y < h; ++y) { + for(x = 0; x < w; ++x) { + for(ch = 0; ch < 4; ++ch) { + unsigned offset = y*rgba_stride + x*4 + ch; + rgba[offset] = CLAMP(rgba[offset], 0.0f, 1.0f); + } + } + } + } +} + + +/** + * Randomly sample pixels. + */ +void +st_sample_pixel_block(enum pipe_format format, + const struct pipe_format_block *block, + void *raw, + float *rgba, unsigned rgba_stride, + unsigned w, unsigned h) +{ + switch(format) { + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT5_RGBA: + st_sample_dxt_pixel_block(format, block, raw, rgba, rgba_stride, w, h); + break; + + default: + st_sample_generic_pixel_block(format, block, raw, rgba, rgba_stride, w, h); + break; + } +} + + +void +st_sample_surface(struct pipe_surface *surface, float *rgba) +{ + const struct pipe_format_block *block = &surface->block; + unsigned rgba_stride = surface->width*4; + void *raw; + unsigned x, y; + + raw = pipe_surface_map(surface, PIPE_BUFFER_USAGE_CPU_READ); + if(!raw) + return; + + for (y = 0; y < surface->nblocksy; ++y) { + for(x = 0; x < surface->nblocksx; ++x) { + st_sample_pixel_block(surface->format, + block, + (uint8_t*)raw + y*surface->stride + x*block->size, + rgba + y*block->height*rgba_stride + x*block->width*4, + rgba_stride, + MIN2(block->width, surface->width - x*block->width), + MIN2(block->height, surface->height - y*block->height)); + } + } + + pipe_surface_unmap(surface); +} diff --git a/src/gallium/state_trackers/python/st_sample.h b/src/gallium/state_trackers/python/st_sample.h new file mode 100644 index 0000000000..ff04a12613 --- /dev/null +++ b/src/gallium/state_trackers/python/st_sample.h @@ -0,0 +1,47 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef ST_SAMPLE_H_ +#define ST_SAMPLE_H_ + + +#include "pipe/p_format.h" + + +void +st_sample_pixel_block(enum pipe_format format, + const struct pipe_format_block *block, + void *raw, + float *rgba, unsigned rgba_stride, + unsigned w, unsigned h); + +void +st_sample_surface(struct pipe_surface *surface, float *rgba); + + +#endif /* ST_SAMPLE_H_ */ diff --git a/src/gallium/state_trackers/python/tests/data.py b/src/gallium/state_trackers/python/tests/data.py deleted file mode 100644 index 3c1cda59d7..0000000000 --- a/src/gallium/state_trackers/python/tests/data.py +++ /dev/null @@ -1,285 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# All Rights Reserved. -# -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sub license, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice (including the -# next paragraph) shall be included in all copies or substantial portions -# of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR -# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# -########################################################################## - -"""Texture data generation for use in testing.""" - - -import random - -from gallium import * - - -dxt1_rgb_data = [ - ( - [ - [0x99, 0xb0, 0x8e, 0xff], - [0x5d, 0x62, 0x89, 0xff], - [0x99, 0xb0, 0x8e, 0xff], - [0x99, 0xb0, 0x8e, 0xff], - [0xd6, 0xff, 0x94, 0xff], - [0x5d, 0x62, 0x89, 0xff], - [0x99, 0xb0, 0x8e, 0xff], - [0xd6, 0xff, 0x94, 0xff], - [0x5d, 0x62, 0x89, 0xff], - [0x5d, 0x62, 0x89, 0xff], - [0x99, 0xb0, 0x8e, 0xff], - [0x21, 0x14, 0x84, 0xff], - [0x5d, 0x62, 0x89, 0xff], - [0x21, 0x14, 0x84, 0xff], - [0x21, 0x14, 0x84, 0xff], - [0x99, 0xb0, 0x8e, 0xff], - ], - [0xf2, 0xd7, 0xb0, 0x20, 0xae, 0x2c, 0x6f, 0x97], - ), - ( - [ - [0xb5, 0xcf, 0x9c, 0xff], - [0x83, 0x8c, 0x8b, 0xff], - [0x21, 0x08, 0x6b, 0xff], - [0x83, 0x8c, 0x8b, 0xff], - [0x52, 0x4a, 0x7b, 0xff], - [0x83, 0x8c, 0x8b, 0xff], - [0x83, 0x8c, 0x8b, 0xff], - [0xb5, 0xcf, 0x9c, 0xff], - [0x21, 0x08, 0x6b, 0xff], - [0xb5, 0xcf, 0x9c, 0xff], - [0x83, 0x8c, 0x8b, 0xff], - [0x52, 0x4a, 0x7b, 0xff], - [0xb5, 0xcf, 0x9c, 0xff], - [0x83, 0x8c, 0x8b, 0xff], - [0x52, 0x4a, 0x7b, 0xff], - [0x83, 0x8c, 0x8b, 0xff], - ], - [0x73, 0xb6, 0x4d, 0x20, 0x98, 0x2b, 0xe1, 0xb8], - ), - ( - [ - [0x00, 0x2c, 0xff, 0xff], - [0x94, 0x8d, 0x7b, 0xff], - [0x4a, 0x5c, 0xbd, 0xff], - [0x4a, 0x5c, 0xbd, 0xff], - [0x4a, 0x5c, 0xbd, 0xff], - [0x94, 0x8d, 0x7b, 0xff], - [0x94, 0x8d, 0x7b, 0xff], - [0x94, 0x8d, 0x7b, 0xff], - [0xde, 0xbe, 0x39, 0xff], - [0x94, 0x8d, 0x7b, 0xff], - [0xde, 0xbe, 0x39, 0xff], - [0xde, 0xbe, 0x39, 0xff], - [0xde, 0xbe, 0x39, 0xff], - [0xde, 0xbe, 0x39, 0xff], - [0xde, 0xbe, 0x39, 0xff], - [0x94, 0x8d, 0x7b, 0xff], - ], - [0xe7, 0xdd, 0x7f, 0x01, 0xf9, 0xab, 0x08, 0x80], - ), - ( - [ - [0x6b, 0x24, 0x21, 0xff], - [0x7b, 0x4f, 0x5d, 0xff], - [0x7b, 0x4f, 0x5d, 0xff], - [0x8b, 0x7a, 0x99, 0xff], - [0x7b, 0x4f, 0x5d, 0xff], - [0x7b, 0x4f, 0x5d, 0xff], - [0x6b, 0x24, 0x21, 0xff], - [0x8b, 0x7a, 0x99, 0xff], - [0x9c, 0xa6, 0xd6, 0xff], - [0x6b, 0x24, 0x21, 0xff], - [0x7b, 0x4f, 0x5d, 0xff], - [0x8b, 0x7a, 0x99, 0xff], - [0x6b, 0x24, 0x21, 0xff], - [0x8b, 0x7a, 0x99, 0xff], - [0x7b, 0x4f, 0x5d, 0xff], - [0x9c, 0xa6, 0xd6, 0xff], - ], - [0x3a, 0x9d, 0x24, 0x69, 0xbd, 0x9f, 0xb4, 0x39], - ), -] - -dxt1_rgba = [ - ( - [ - [0x00, 0x00, 0x00, 0x00], - [0x4e, 0xaa, 0x90, 0xff], - [0x4e, 0xaa, 0x90, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0x4e, 0xaa, 0x90, 0xff], - [0x29, 0xff, 0xff, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0x4e, 0xaa, 0x90, 0xff], - [0x73, 0x55, 0x21, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x4e, 0xaa, 0x90, 0xff], - [0x4e, 0xaa, 0x90, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x4e, 0xaa, 0x90, 0xff], - ], - [0xff, 0x2f, 0xa4, 0x72, 0xeb, 0xb2, 0xbd, 0xbe], - ), - ( - [ - [0xb5, 0xe3, 0x63, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0x6b, 0x24, 0x84, 0xff], - [0xb5, 0xe3, 0x63, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0xb5, 0xe3, 0x63, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x6b, 0x24, 0x84, 0xff], - [0x6b, 0x24, 0x84, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0xb5, 0xe3, 0x63, 0xff], - [0x90, 0x83, 0x73, 0xff], - [0xb5, 0xe3, 0x63, 0xff], - ], - [0x30, 0x69, 0x0c, 0xb7, 0x4d, 0xf7, 0x0f, 0x67], - ), - ( - [ - [0x00, 0x00, 0x00, 0x00], - [0xc6, 0x86, 0x8c, 0xff], - [0xc6, 0x86, 0x8c, 0xff], - [0x21, 0x65, 0x42, 0xff], - [0x21, 0x65, 0x42, 0xff], - [0x21, 0x65, 0x42, 0xff], - [0x21, 0x65, 0x42, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x21, 0x65, 0x42, 0xff], - [0xc6, 0x86, 0x8c, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0xc6, 0x86, 0x8c, 0xff], - ], - [0x28, 0x23, 0x31, 0xc4, 0x17, 0xc0, 0xd3, 0x7f], - ), - ( - [ - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0xc6, 0xe3, 0x9c, 0xff], - [0x7b, 0x1c, 0x52, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00], - [0x7b, 0x1c, 0x52, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0x7b, 0x1c, 0x52, 0xff], - [0xa0, 0x7f, 0x77, 0xff], - [0xc6, 0xe3, 0x9c, 0xff], - [0x00, 0x00, 0x00, 0x00], - [0xa0, 0x7f, 0x77, 0xff], - ], - [0xea, 0x78, 0x13, 0xc7, 0x7f, 0xfc, 0x33, 0xb6], - ), -] - - - -def generate_data_compressed(surface, blocks): - - stride = surface.nblocksx*surface.block.size - size = surface.nblocksy*stride - - raw = ByteArray(size) - rgba = FloatArray(surface.height*surface.width*4) - - for yj in range(0, surface.nblocksy): - for xj in range(0, surface.nblocksx): - pixels, block = blocks[random.randint(0, len(blocks) - 1)] - - offset = (yj*surface.nblocksx + xj)*surface.block.size - for i in range(0, surface.block.size): - raw[offset + i] = block[i] - - for yi in range(0, surface.block.height): - for xi in range(0, surface.block.width): - y = yj*surface.block.height + yi - x = xj*surface.block.width + xi - if y < surface.height and x < surface.width: - offset = (y*surface.width + x)*4 - pixel = pixels[yi*surface.block.width + xi] - for ch in range(0, 4): - rgba[offset + ch] = float(pixel[ch])/255.0 - - surface.put_tile_raw(0, 0, surface.width, surface.height, raw, stride) - - return rgba - - -def generate_data_simple(surface): - stride = surface.nblocksx*surface.block.size - size = surface.nblocksy*stride - - raw = ByteArray(size) - rgba = FloatArray(surface.height*surface.width*4) - - for i in range(0, size): - raw[i] = random.randint(0, 255) - - surface.put_tile_raw(0, 0, surface.width, surface.height, raw, stride) - - surface.get_tile_rgba(0, 0, surface.width, surface.height, rgba) - - if surface.format in (PIPE_FORMAT_YCBCR, PIPE_FORMAT_YCBCR_REV): - # normalize - for y in range(0, surface.height): - for x in range(0, surface.width): - for ch in range(4): - offset = (y*surface.width + x)*4 + ch - rgba[offset] = min(max(rgba[offset], 0.0), 1.0) - - return rgba - - -def generate_data(surface): - width = surface.width - height = surface.height - - if surface.format == PIPE_FORMAT_DXT1_RGB: - return generate_data_compressed(surface, dxt1_rgb_data) - if surface.format == PIPE_FORMAT_DXT1_RGBA: - return generate_data_compressed(surface, dxt1_rgba_data) - if surface.format == PIPE_FORMAT_DXT3_RGBA: - assert 0 - if surface.format == PIPE_FORMAT_DXT5_RGBA: - assert 0 - - return generate_data_simple(surface) - - - diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index 3d76953126..2c9231349f 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -30,29 +30,6 @@ import sys from gallium import * from base import * -from data import generate_data - - -def compare_rgba(width, height, rgba1, rgba2, tol=4.0/256, ratio=0.85): - errors = 0 - for y in range(0, height): - for x in range(0, width): - differs = 0 - for ch in range(4): - offset = (y*width + x)*4 + ch - v1 = rgba1[offset] - v2 = rgba2[offset] - if abs(v1 - v2) > tol: - if errors == 0: - sys.stderr.write("x=%u, y=%u, ch=%u differ: %f vs %f\n" % (x, y, ch, v1, v2)) - if errors == 1 and ch == 0: - sys.stderr.write("...\n") - differs = 1 - errors += differs - total = height*width - if errors: - sys.stderr.write("%u out of %u pixels differ\n" % (errors, total)) - return float(total - errors)/float(total) >= ratio def lods(*dims): @@ -214,10 +191,12 @@ class TextureTest(TestCase): height=height, last_level = last_level) - expected_rgba = generate_data(texture.get_surface( + expected_rgba = FloatArray(height*width*4) + texture.get_surface( usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE, face = face, - level = level)) + level = level, + ).sample_rgba(expected_rgba) ctx.set_sampler_texture(0, texture) -- cgit v1.2.3 From 3ca935d9efaef4dd9746d3b2207e329b77bb1018 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 18 Jul 2008 10:12:07 +0900 Subject: python/tests: Extend the texture tests to cover volumes. --- src/gallium/state_trackers/python/tests/texture.py | 65 ++++++++++++++-------- 1 file changed, 43 insertions(+), 22 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index 2c9231349f..16ad78c8aa 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -56,7 +56,12 @@ def tex_coords(texture, face, level, zslice): if texture.target == PIPE_TEXTURE_2D: return [[s, t, 0.0] for s, t in st] elif texture.target == PIPE_TEXTURE_3D: - assert 0 + depth = texture.get_depth(level) + if depth > 1: + r = float(zslice)/float(depth - 1) + else: + r = 0.0 + return [[s, t, r] for s, t in st] elif texture.target == PIPE_TEXTURE_CUBE: result = [] for s, t in st: @@ -112,10 +117,10 @@ class TextureTest(TestCase): }[self.face] else: face = "" - return "%s %s %ux%u last_level=%u %s level=%u" % ( + return "%s %s %ux%ux%u last_level=%u face=%s level=%u zslice=%u" % ( target, format, - self.width, self.height, - self.last_level, face, self.level, + self.width, self.height, self.depth, self.last_level, + face, self.level, self.zslice, ) def test(self): @@ -125,9 +130,11 @@ class TextureTest(TestCase): format = self.format width = self.width height = self.height + depth = self.depth last_level = self.last_level - level = self.level face = self.face + level = self.level + zslice = self.zslice if not dev.is_format_supported(format, PIPE_TEXTURE): raise TestSkip @@ -185,17 +192,21 @@ class TextureTest(TestCase): ctx.set_sampler(0, sampler) # texture - texture = dev.texture_create(target=target, - format=format, - width=width, - height=height, - last_level = last_level) + texture = dev.texture_create( + target = target, + format = format, + width = width, + height = height, + depth = depth, + last_level = last_level, + ) expected_rgba = FloatArray(height*width*4) texture.get_surface( usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE, face = face, level = level, + zslice = zslice, ).sample_rgba(expected_rgba) ctx.set_sampler_texture(0, texture) @@ -263,7 +274,7 @@ class TextureTest(TestCase): [x, y+h], ] - tex = tex_coords(texture, face, level, zslice=0) + tex = tex_coords(texture, face, level, zslice) for i in range(0, 4): j = 8*i @@ -313,6 +324,7 @@ def main(): targets = [] targets += [PIPE_TEXTURE_2D] targets += [PIPE_TEXTURE_CUBE] + targets += [PIPE_TEXTURE_3D] formats = [] formats += [PIPE_FORMAT_A8R8G8B8_UNORM] @@ -322,7 +334,9 @@ def main(): formats += [PIPE_FORMAT_DXT1_RGB] sizes = [64, 32, 16, 8, 4, 2, 1] + #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] #sizes = [64] + #sizes = [63] for target in targets: for format in formats: @@ -339,21 +353,28 @@ def main(): #faces = [PIPE_TEX_FACE_NEG_X] else: faces = [0] + if target == PIPE_TEXTURE_3D: + depth = size + else: + depth = 1 for face in faces: levels = lods(size) for last_level in range(levels): for level in range(0, last_level + 1): - test = TextureTest( - dev=dev, - target=target, - format=format, - width=size, - height=size, - face=face, - last_level = last_level, - level=level, - ) - suite.add_test(test) + for zslice in range(0, depth >> level): + test = TextureTest( + dev = dev, + target = target, + format = format, + width = size, + height = size, + depth = depth, + last_level = last_level, + face = face, + level = level, + zslice = zslice, + ) + suite.add_test(test) suite.run() -- cgit v1.2.3 From 8aafc03b260ab8923f1b373f7effa75bcdb40a72 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Sat, 19 Jul 2008 12:04:37 +0900 Subject: gallium: Finer grained is_format_supported. --- src/gallium/auxiliary/util/u_blit.c | 12 ++- src/gallium/auxiliary/util/u_gen_mipmap.c | 3 +- src/gallium/drivers/cell/ppu/cell_screen.c | 24 ++--- src/gallium/drivers/i915simple/i915_screen.c | 18 ++-- src/gallium/drivers/i965simple/brw_screen.c | 5 +- src/gallium/drivers/softpipe/sp_screen.c | 26 +++--- src/gallium/include/pipe/p_defines.h | 7 +- src/gallium/include/pipe/p_screen.h | 9 +- src/gallium/state_trackers/python/gallium.i | 15 ++- src/gallium/state_trackers/python/samples/tri.py | 8 +- src/gallium/state_trackers/python/tests/texture.py | 13 ++- src/mesa/state_tracker/st_atom_pixeltransfer.c | 2 +- src/mesa/state_tracker/st_cb_bitmap.c | 3 +- src/mesa/state_tracker/st_cb_drawpixels.c | 9 +- src/mesa/state_tracker/st_cb_texture.c | 8 +- src/mesa/state_tracker/st_extensions.c | 14 ++- src/mesa/state_tracker/st_format.c | 101 +++++++++++---------- src/mesa/state_tracker/st_format.h | 2 +- src/mesa/state_tracker/st_gen_mipmap.c | 3 +- src/mesa/state_tracker/st_texture.c | 3 +- 20 files changed, 158 insertions(+), 127 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 3dc9fdd11e..ae087df4cf 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -307,8 +307,10 @@ util_blit_pixels(struct blit_state *ctx, dstY1 = tmp; } - assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE)); - assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE)); + assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)); + assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)); if(dst->format == src->format && (dstX1 - dstX0) == srcW && (dstY1 - dstY0) == srcH) { /* FIXME: this will most surely fail for overlapping rectangles */ @@ -319,7 +321,8 @@ util_blit_pixels(struct blit_state *ctx, return; } - assert(screen->is_format_supported(screen, dst->format, PIPE_SURFACE)); + assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)); /* * XXX for now we're always creating a temporary texture. @@ -449,7 +452,8 @@ util_blit_pixels_tex(struct blit_state *ctx, t0 = srcY0 / (float)tex->height[0]; t1 = srcY1 / (float)tex->height[0]; - assert(screen->is_format_supported(screen, dst->format, PIPE_SURFACE)); + assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)); /* save state (restored below) */ cso_save_blend(ctx->cso); diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 5313a8008a..4999822068 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -858,7 +858,8 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, uint zslice = 0; /* check if we can render in the texture's format */ - if (!screen->is_format_supported(screen, pt->format, PIPE_SURFACE)) { + if (!screen->is_format_supported(screen, pt->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel); return; } diff --git a/src/gallium/drivers/cell/ppu/cell_screen.c b/src/gallium/drivers/cell/ppu/cell_screen.c index 5198b51441..cf9b68b695 100644 --- a/src/gallium/drivers/cell/ppu/cell_screen.c +++ b/src/gallium/drivers/cell/ppu/cell_screen.c @@ -115,23 +115,17 @@ cell_get_paramf(struct pipe_screen *screen, int param) static boolean cell_is_format_supported( struct pipe_screen *screen, - enum pipe_format format, uint type ) + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { - switch (type) { - case PIPE_TEXTURE: - /* cell supports most texture formats, XXX for now anyway */ - if (format == PIPE_FORMAT_DXT5_RGBA || - format == PIPE_FORMAT_R8G8B8A8_SRGB) - return FALSE; - else - return TRUE; - case PIPE_SURFACE: - /* cell supports all (off-screen) surface formats, XXX for now */ - return TRUE; - default: - assert(0); + /* cell supports most formats, XXX for now anyway */ + if (format == PIPE_FORMAT_DXT5_RGBA || + format == PIPE_FORMAT_R8G8B8A8_SRGB) return FALSE; - } + else + return TRUE; } diff --git a/src/gallium/drivers/i915simple/i915_screen.c b/src/gallium/drivers/i915simple/i915_screen.c index ba8f183bdf..4b1b8af7da 100644 --- a/src/gallium/drivers/i915simple/i915_screen.c +++ b/src/gallium/drivers/i915simple/i915_screen.c @@ -148,7 +148,10 @@ i915_get_paramf(struct pipe_screen *screen, int param) static boolean i915_is_format_supported( struct pipe_screen *screen, - enum pipe_format format, uint type ) + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { static const enum pipe_format tex_supported[] = { PIPE_FORMAT_R8G8B8A8_UNORM, @@ -173,17 +176,10 @@ i915_is_format_supported( struct pipe_screen *screen, const enum pipe_format *list; uint i; - switch (type) { - case PIPE_TEXTURE: - list = tex_supported; - break; - case PIPE_SURFACE: + if(tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) list = surface_supported; - break; - default: - assert(0); - return FALSE; - } + else + list = tex_supported; for (i = 0; list[i] != PIPE_FORMAT_NONE; i++) { if (list[i] == format) diff --git a/src/gallium/drivers/i965simple/brw_screen.c b/src/gallium/drivers/i965simple/brw_screen.c index b700f7e4f5..6d8f24d1c4 100644 --- a/src/gallium/drivers/i965simple/brw_screen.c +++ b/src/gallium/drivers/i965simple/brw_screen.c @@ -136,7 +136,10 @@ brw_get_paramf(struct pipe_screen *screen, int param) static boolean brw_is_format_supported( struct pipe_screen *screen, - enum pipe_format format, uint type ) + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { #if 0 /* XXX: This is broken -- rewrite if still needed. */ diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c index f6193bfaf9..3f9d4b0ed3 100644 --- a/src/gallium/drivers/softpipe/sp_screen.c +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -115,23 +115,19 @@ softpipe_get_paramf(struct pipe_screen *screen, int param) */ static boolean softpipe_is_format_supported( struct pipe_screen *screen, - enum pipe_format format, uint type ) + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { - switch (type) { - case PIPE_TEXTURE: - case PIPE_SURFACE: - switch(format) { - case PIPE_FORMAT_DXT1_RGB: - case PIPE_FORMAT_DXT1_RGBA: - case PIPE_FORMAT_DXT3_RGBA: - case PIPE_FORMAT_DXT5_RGBA: - return FALSE; - default: - return TRUE; - } - default: - assert(0); + switch(format) { + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT5_RGBA: return FALSE; + default: + return TRUE; } } diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index bc4d7c845a..b1d100ef53 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -172,11 +172,8 @@ enum pipe_texture_target { #define PIPE_TEXTURE_USAGE_DEPTH_STENCIL 0x8 #define PIPE_TEXTURE_USAGE_SAMPLER 0x10 -/** - * Surfaces, textures, etc. (others may be added) - */ -#define PIPE_TEXTURE 1 -#define PIPE_SURFACE 2 /**< user-created surfaces */ +#define PIPE_TEXTURE_GEOM_NON_SQUARE 0x1 +#define PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO 0x2 /** diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index cc8430dae1..b15affef7a 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -77,11 +77,14 @@ struct pipe_screen { /** * Check if the given pipe_format is supported as a texture or * drawing surface. - * \param type one of PIPE_TEXTURE, PIPE_SURFACE + * \param tex_usage bitmask of PIPE_TEXTURE_USAGE_* + * \param flags bitmask of PIPE_TEXTURE_GEOM_* */ boolean (*is_format_supported)( struct pipe_screen *, - enum pipe_format format, - uint type ); + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ); /** * Create a new texture object, using the given template info. diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index c08ac87aca..8d8b762ea5 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -158,8 +158,15 @@ struct st_context { * drawing surface. * \param type one of PIPE_TEXTURE, PIPE_SURFACE */ - int is_format_supported( enum pipe_format format, unsigned type ) { - return $self->screen->is_format_supported( $self->screen, format, type); + int is_format_supported( enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { + return $self->screen->is_format_supported( $self->screen, + format, + target, + tex_usage, + geom_flags ); } struct st_context * @@ -175,7 +182,7 @@ struct st_context { unsigned depth = 1, unsigned last_level = 0, enum pipe_texture_target target = PIPE_TEXTURE_2D, - unsigned usage = 0 + unsigned tex_usage = 0 ) { struct pipe_texture templat; memset(&templat, 0, sizeof(templat)); @@ -186,7 +193,7 @@ struct st_context { templat.depth[0] = depth; templat.last_level = last_level; templat.target = target; - templat.tex_usage = usage; + templat.tex_usage = tex_usage; return $self->screen->texture_create($self->screen, &templat); } diff --git a/src/gallium/state_trackers/python/samples/tri.py b/src/gallium/state_trackers/python/samples/tri.py index 3665922929..1271c67627 100644 --- a/src/gallium/state_trackers/python/samples/tri.py +++ b/src/gallium/state_trackers/python/samples/tri.py @@ -140,9 +140,11 @@ def test(dev): ctx.set_clip(clip) # framebuffer - cbuf = dev.texture_create(PIPE_FORMAT_X8R8G8B8_UNORM, - width, height, - usage=PIPE_TEXTURE_USAGE_DISPLAY_TARGET) + cbuf = dev.texture_create( + PIPE_FORMAT_X8R8G8B8_UNORM, + width, height, + tex_usage=PIPE_TEXTURE_USAGE_DISPLAY_TARGET, + ) _cbuf = cbuf.get_surface(usage = PIPE_BUFFER_USAGE_GPU_READ|PIPE_BUFFER_USAGE_GPU_WRITE) fb = Framebuffer() fb.width = width diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index 16ad78c8aa..b2ca9f416f 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -136,7 +136,7 @@ class TextureTest(TestCase): level = self.level zslice = self.zslice - if not dev.is_format_supported(format, PIPE_TEXTURE): + if not dev.is_format_supported(format, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER, 0): raise TestSkip ctx = self.dev.context_create() @@ -199,6 +199,7 @@ class TextureTest(TestCase): height = height, depth = depth, last_level = last_level, + tex_usage = PIPE_TEXTURE_USAGE_SAMPLER, ) expected_rgba = FloatArray(height*width*4) @@ -212,10 +213,12 @@ class TextureTest(TestCase): ctx.set_sampler_texture(0, texture) # framebuffer - cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, - width, - height, - usage = PIPE_TEXTURE_USAGE_RENDER_TARGET) + cbuf_tex = dev.texture_create( + PIPE_FORMAT_A8R8G8B8_UNORM, + width, + height, + tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, + ) cbuf = cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_GPU_WRITE|PIPE_BUFFER_USAGE_GPU_READ) fb = Framebuffer() diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index e4de875e8c..a357b71677 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -122,7 +122,7 @@ create_color_map_texture(GLcontext *ctx) const uint texSize = 256; /* simple, and usually perfect */ /* find an RGBA texture format */ - format = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE); + format = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER); /* create texture for color map/table */ pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index de86832342..d5696a909f 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -746,7 +746,8 @@ st_init_bitmap(struct st_context *st) st->bitmap.rasterizer.bypass_vs = 1; /* find a usable texture format */ - if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, PIPE_TEXTURE)) { + if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)) { st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM; } else { diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 2ebfcaf82b..db0c9fbd09 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -995,18 +995,21 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, srcFormat = rbRead->texture->format; - if (screen->is_format_supported(screen, srcFormat, PIPE_TEXTURE)) { + if (screen->is_format_supported(screen, srcFormat, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)) { texFormat = srcFormat; } else { /* srcFormat can't be used as a texture format */ if (type == GL_DEPTH) { - texFormat = st_choose_format(pipe, GL_DEPTH_COMPONENT, PIPE_TEXTURE); + texFormat = st_choose_format(pipe, GL_DEPTH_COMPONENT, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_DEPTH_STENCIL); assert(texFormat != PIPE_FORMAT_NONE); /* XXX no depth texture formats??? */ } else { /* default color format */ - texFormat = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE); + texFormat = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER); assert(texFormat != PIPE_FORMAT_NONE); } } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index de782e8232..1f94a0b9ef 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1210,9 +1210,13 @@ do_copy_texsubimage(GLcontext *ctx, use_fallback = GL_FALSE; } else if (screen->is_format_supported(screen, strb->surface->format, - PIPE_TEXTURE) && + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, + 0) && screen->is_format_supported(screen, dest_surface->format, - PIPE_SURFACE)) { + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, + 0)) { boolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP); int srcY0, srcY1; if (do_flip) { diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index d804d2b453..cacf972a1b 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -213,18 +213,24 @@ void st_init_extensions(struct st_context *st) } if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SRGB, - PIPE_TEXTURE)) { + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)) { ctx->Extensions.EXT_texture_sRGB = GL_TRUE; } #if 01 if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA, - PIPE_TEXTURE)) { + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)) { ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE; } #endif - if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR, PIPE_TEXTURE) || - screen->is_format_supported(screen, PIPE_FORMAT_YCBCR_REV, PIPE_TEXTURE)) { + if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0) || + screen->is_format_supported(screen, PIPE_FORMAT_YCBCR_REV, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)) { ctx->Extensions.MESA_ycbcr_texture = GL_TRUE; } diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 50a06868df..b6d97ef659 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -281,7 +281,10 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat) * Find an RGBA format supported by the context/winsys. */ static enum pipe_format -default_rgba_format(struct pipe_screen *screen, uint type) +default_rgba_format(struct pipe_screen *screen, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags) { static const enum pipe_format colorFormats[] = { PIPE_FORMAT_A8R8G8B8_UNORM, @@ -291,7 +294,7 @@ default_rgba_format(struct pipe_screen *screen, uint type) }; uint i; for (i = 0; i < Elements(colorFormats); i++) { - if (screen->is_format_supported( screen, colorFormats[i], type )) { + if (screen->is_format_supported( screen, colorFormats[i], target, tex_usage, geom_flags )) { return colorFormats[i]; } } @@ -303,13 +306,16 @@ default_rgba_format(struct pipe_screen *screen, uint type) * Search list of formats for first RGBA format with >8 bits/channel. */ static enum pipe_format -default_deep_rgba_format(struct pipe_screen *screen, uint type) +default_deep_rgba_format(struct pipe_screen *screen, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags) { - if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM, type)) { + if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM, target, tex_usage, geom_flags)) { return PIPE_FORMAT_R16G16B16A16_SNORM; } - if (type == PIPE_TEXTURE) - return default_rgba_format(screen, type); + if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) + return default_rgba_format(screen, target, tex_usage, geom_flags); else return PIPE_FORMAT_NONE; } @@ -319,7 +325,10 @@ default_deep_rgba_format(struct pipe_screen *screen, uint type) * Find an Z format supported by the context/winsys. */ static enum pipe_format -default_depth_format(struct pipe_screen *screen, uint type) +default_depth_format(struct pipe_screen *screen, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags) { static const enum pipe_format zFormats[] = { PIPE_FORMAT_Z16_UNORM, @@ -329,7 +338,7 @@ default_depth_format(struct pipe_screen *screen, uint type) }; uint i; for (i = 0; i < Elements(zFormats); i++) { - if (screen->is_format_supported( screen, zFormats[i], type )) { + if (screen->is_format_supported( screen, zFormats[i], target, tex_usage, geom_flags )) { return zFormats[i]; } } @@ -343,12 +352,10 @@ default_depth_format(struct pipe_screen *screen, uint type) */ enum pipe_format st_choose_format(struct pipe_context *pipe, GLint internalFormat, - uint surfType) + enum pipe_texture_target target, unsigned tex_usage) { struct pipe_screen *screen = pipe->screen; - - assert(surfType == PIPE_SURFACE || - surfType == PIPE_TEXTURE); + unsigned geom_flags = 0; switch (internalFormat) { case 4: @@ -360,38 +367,38 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_RGBA16: - if (surfType == PIPE_SURFACE) - return default_deep_rgba_format( screen, surfType ); + if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) + return default_deep_rgba_format( screen, target, tex_usage, geom_flags ); else - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_RGBA4: case GL_RGBA2: - if (screen->is_format_supported( screen, PIPE_FORMAT_A4R4G4B4_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A4R4G4B4_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_A4R4G4B4_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_RGB5_A1: - if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_A1R5G5B5_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_RGB5: case GL_RGB4: case GL_R3_G3_B2: - if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_A1R5G5B5_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_R5G6B5_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_R5G6B5_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_R5G6B5_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_ALPHA: case GL_ALPHA4: @@ -399,9 +406,9 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, case GL_ALPHA12: case GL_ALPHA16: case GL_COMPRESSED_ALPHA: - if (screen->is_format_supported( screen, PIPE_FORMAT_A8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_A8_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case 1: case GL_LUMINANCE: @@ -410,9 +417,9 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, case GL_LUMINANCE12: case GL_LUMINANCE16: case GL_COMPRESSED_LUMINANCE: - if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_L8_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case 2: case GL_LUMINANCE_ALPHA: @@ -423,9 +430,9 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, case GL_LUMINANCE12_ALPHA12: case GL_LUMINANCE16_ALPHA16: case GL_COMPRESSED_LUMINANCE_ALPHA: - if (screen->is_format_supported( screen, PIPE_FORMAT_A8L8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A8L8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_A8L8_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_INTENSITY: case GL_INTENSITY4: @@ -433,17 +440,17 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, case GL_INTENSITY12: case GL_INTENSITY16: case GL_COMPRESSED_INTENSITY: - if (screen->is_format_supported( screen, PIPE_FORMAT_I8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_I8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_I8_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_YCBCR_MESA: if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR, - PIPE_TEXTURE)) { + target, tex_usage, geom_flags)) { return PIPE_FORMAT_YCBCR; } if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR_REV, - PIPE_TEXTURE)) { + target, tex_usage, geom_flags)) { return PIPE_FORMAT_YCBCR_REV; } return PIPE_FORMAT_NONE; @@ -472,40 +479,40 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, #endif case GL_DEPTH_COMPONENT16: - if (screen->is_format_supported( screen, PIPE_FORMAT_Z16_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_Z16_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_Z16_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT24: - if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_S8Z24_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_Z24S8_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT32: - if (screen->is_format_supported( screen, PIPE_FORMAT_Z32_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_Z32_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_Z32_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT: - return default_depth_format( screen, surfType ); + return default_depth_format( screen, target, tex_usage, geom_flags ); case GL_STENCIL_INDEX: case GL_STENCIL_INDEX1_EXT: case GL_STENCIL_INDEX4_EXT: case GL_STENCIL_INDEX8_EXT: case GL_STENCIL_INDEX16_EXT: - if (screen->is_format_supported( screen, PIPE_FORMAT_S8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_S8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_S8_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_S8Z24_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_Z24S8_UNORM; return PIPE_FORMAT_NONE; case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: - if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_S8Z24_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_Z24S8_UNORM; return PIPE_FORMAT_NONE; @@ -521,7 +528,8 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, enum pipe_format st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) { - return st_choose_format(pipe, internalFormat, PIPE_SURFACE); + return st_choose_format(pipe, internalFormat, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET); } @@ -587,7 +595,8 @@ st_ChooseTextureFormat(GLcontext *ctx, GLint internalFormat, (void) format; (void) type; - pFormat = st_choose_format(ctx->st->pipe, internalFormat, PIPE_TEXTURE); + pFormat = st_choose_format(ctx->st->pipe, internalFormat, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER); if (pFormat == PIPE_FORMAT_NONE) return NULL; diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h index ff0fd042db..3f5ac3201b 100644 --- a/src/mesa/state_tracker/st_format.h +++ b/src/mesa/state_tracker/st_format.h @@ -65,7 +65,7 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat); extern enum pipe_format st_choose_format(struct pipe_context *pipe, GLint internalFormat, - uint surfType); + enum pipe_texture_target target, unsigned tex_usage); extern enum pipe_format st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat); diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 2fc00df429..6db9bc0dd5 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -86,7 +86,8 @@ st_render_mipmap(struct st_context *st, assert(target != GL_TEXTURE_3D); /* not done yet */ /* check if we can render in the texture's format */ - if (!screen->is_format_supported(screen, pt->format, PIPE_SURFACE)) { + if (!screen->is_format_supported(screen, pt->format, target, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { return FALSE; } diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 8222826e7a..3e5054ecd2 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -88,7 +88,8 @@ st_texture_create(struct st_context *st, _mesa_lookup_enum_by_nr(format), last_level); assert(format); - assert(screen->is_format_supported(screen, format, PIPE_TEXTURE)); + assert(screen->is_format_supported(screen, format, target, + PIPE_TEXTURE_USAGE_SAMPLER, 0)); memset(&pt, 0, sizeof(pt)); pt.target = target; -- cgit v1.2.3 From b1d6ff1afd3ec8460f746c76764dc89f9cd70556 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Sat, 19 Jul 2008 12:30:54 +0900 Subject: python/tests: Specify the right texture target when querying formats. --- src/gallium/state_trackers/python/tests/texture.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index b2ca9f416f..861070c8d2 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -136,7 +136,7 @@ class TextureTest(TestCase): level = self.level zslice = self.zslice - if not dev.is_format_supported(format, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER, 0): + if not dev.is_format_supported(format, target, PIPE_TEXTURE_USAGE_SAMPLER, 0): raise TestSkip ctx = self.dev.context_create() @@ -364,7 +364,8 @@ def main(): levels = lods(size) for last_level in range(levels): for level in range(0, last_level + 1): - for zslice in range(0, depth >> level): + zslice = 0 + while zslice < depth >> level: test = TextureTest( dev = dev, target = target, @@ -378,6 +379,7 @@ def main(): zslice = zslice, ) suite.add_test(test) + zslice = (zslice + 1)*2 - 1 suite.run() -- cgit v1.2.3 From 5853b6c2fe10223738a15d294e2a1605ec076953 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Sun, 20 Jul 2008 09:28:27 +0900 Subject: python/tests: Check support for non-pot/non-square textures. --- src/gallium/state_trackers/python/tests/texture.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/gallium/state_trackers/python/tests/texture.py') diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index 861070c8d2..880a61306c 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -94,7 +94,10 @@ def tex_coords(texture, face, level, zslice): rz = -1.0 result.append([rx, ry, rz]) return result - + +def is_pot(n): + return n & (n - 1) == 0 + class TextureTest(TestCase): @@ -136,7 +139,14 @@ class TextureTest(TestCase): level = self.level zslice = self.zslice - if not dev.is_format_supported(format, target, PIPE_TEXTURE_USAGE_SAMPLER, 0): + tex_usage = PIPE_TEXTURE_USAGE_SAMPLER + geom_flags = 0 + if width != height: + geom_flags |= PIPE_TEXTURE_GEOM_NON_SQUARE + if not is_pot(width) or not is_pot(height) or not is_pot(depth): + geom_flags |= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO + + if not dev.is_format_supported(format, target, tex_usage, geom_flags): raise TestSkip ctx = self.dev.context_create() @@ -199,7 +209,7 @@ class TextureTest(TestCase): height = height, depth = depth, last_level = last_level, - tex_usage = PIPE_TEXTURE_USAGE_SAMPLER, + tex_usage = tex_usage, ) expected_rgba = FloatArray(height*width*4) -- cgit v1.2.3