python: Expand the texture test suit to cover one YUV and one DXT format.

This commit is contained in:
José Fonseca
2008-07-16 14:11:45 +09:00
parent 61c4de53c3
commit 70b1ff9ff3
3 changed files with 53 additions and 24 deletions

View File

@@ -93,6 +93,9 @@ class Test:
def __init__(self): def __init__(self):
pass pass
def description(self):
raise NotImplementedError
def run(self): def run(self):
raise NotImplementedError raise NotImplementedError
@@ -111,7 +114,8 @@ class TestSuite(Test):
def run(self): def run(self):
for test in self.tests: for test in self.tests:
self.test.run() print "Running %s..." % test.description()
test.run()
class TextureTemplate: class TextureTemplate:

View File

@@ -211,7 +211,6 @@ dxt1_rgba = [
def generate_data_compressed(surface, blocks): def generate_data_compressed(surface, blocks):
pixels, block = blocks[0]
stride = surface.nblocksx*surface.block.size stride = surface.nblocksx*surface.block.size
size = surface.nblocksy*stride size = surface.nblocksy*stride
@@ -219,17 +218,21 @@ def generate_data_compressed(surface, blocks):
raw = ByteArray(size) raw = ByteArray(size)
rgba = FloatArray(surface.height*surface.width*4) rgba = FloatArray(surface.height*surface.width*4)
for y in range(0, surface.nblocksx): for yj in range(0, surface.nblocksy):
for x 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): for i in range(0, surface.block.size):
raw[offset + i] = block[i] raw[offset + i] = block[i]
for j in range(0, surface.block.width): for yi in range(0, surface.block.height):
for i in range(0, surface.block.height): for xi in range(0, surface.block.width):
offset = ((y*surface.block.height + j)*surface.width + x*surface.block.width + i)*4 y = yj*surface.block.height + yi
pixel = pixels[j*surface.block.width + i] 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): for ch in range(0, 4):
rgba[offset + ch] = float(pixel[ch])/255.0 rgba[offset + ch] = float(pixel[ch])/255.0
@@ -252,6 +255,14 @@ def generate_data_simple(surface):
surface.get_tile_rgba(0, 0, surface.width, surface.height, rgba) 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 return rgba

View File

@@ -33,7 +33,7 @@ from base import *
from data import generate_data 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 errors = 0
for y in range(0, height): for y in range(0, height):
for x in range(0, width): for x in range(0, width):
@@ -58,22 +58,25 @@ class TextureTest(Test):
Test.__init__(self) Test.__init__(self)
self.__dict__.update(kargs) self.__dict__.update(kargs)
def description(self):
return "%s %ux%u" % (formats[self.format], self.width, self.height)
def run(self): def run(self):
dev = self.dev dev = self.dev
#format = PIPE_FORMAT_A8R8G8B8_UNORM format = self.format
format = PIPE_FORMAT_DXT1_RGB width = self.width
height = self.height
if not dev.is_format_supported(format, PIPE_TEXTURE): if not dev.is_format_supported(format, PIPE_TEXTURE):
pass print "SKIP"
return
if not dev.is_format_supported(format, PIPE_SURFACE): if not dev.is_format_supported(format, PIPE_SURFACE):
pass print "SKIP"
return
ctx = dev.context_create() ctx = dev.context_create()
width = 64
height = 64
# disabled blending/masking # disabled blending/masking
blend = Blend() blend = Blend()
blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE
@@ -169,7 +172,7 @@ class TextureTest(Test):
0:TEX OUT[0], IN[0], SAMP[0], 2D 0:TEX OUT[0], IN[0], SAMP[0], 2D
1:END 1:END
''') ''')
fs.dump() #fs.dump()
ctx.set_fragment_shader(fs) ctx.set_fragment_shader(fs)
nverts = 4 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) 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(): def main():
dev = Device() dev = Device()
test = TextureTest(dev = dev) suite = TestSuite()
test.run() 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__': if __name__ == '__main__':