From 70b1ff9ff39ca29bdbd25b31ebb183eea683d625 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 16 Jul 2008 14:11:45 +0900 Subject: [PATCH] python: Expand the texture test suit to cover one YUV and one DXT format. --- .../state_trackers/python/tests/base.py | 6 ++- .../state_trackers/python/tests/data.py | 31 +++++++++----- .../state_trackers/python/tests/texture.py | 40 +++++++++++++------ 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/src/gallium/state_trackers/python/tests/base.py b/src/gallium/state_trackers/python/tests/base.py index d5d6114a45d..d83abdfa765 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 2287884285e..3c1cda59d74 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 6a5ffb38b95..7812d8aebf5 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__': -- 2.30.2