mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 04:48:08 +02:00
python: Test all miplevels.
This commit is contained in:
parent
78d18bb690
commit
32fe752d31
2 changed files with 116 additions and 43 deletions
|
|
@ -27,6 +27,12 @@
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
||||||
|
"""Base classes for tests.
|
||||||
|
|
||||||
|
Loosely inspired on Python's unittest module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
from gallium import *
|
from gallium import *
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -87,17 +93,54 @@ def show_image(width, height, **rgbas):
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
|
class TestFailure(Exception):
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
class TestSkip(Exception):
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Test:
|
class Test:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
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):
|
def description(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def run(self):
|
def test(self):
|
||||||
raise NotImplementedError
|
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):
|
class TestSuite(Test):
|
||||||
|
|
@ -112,21 +155,35 @@ class TestSuite(Test):
|
||||||
def add_test(self, test):
|
def add_test(self, test):
|
||||||
self.tests.append(test)
|
self.tests.append(test)
|
||||||
|
|
||||||
def run(self):
|
def _run(self, result):
|
||||||
for test in self.tests:
|
for test in self.tests:
|
||||||
print "Running %s..." % test.description()
|
test._run(result)
|
||||||
test.run()
|
|
||||||
|
|
||||||
|
|
||||||
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):
|
def __init__(self):
|
||||||
self.format = format
|
self.tests = 0
|
||||||
self.width = width
|
self.passed = 0
|
||||||
self.height = height
|
self.skipped = 0
|
||||||
self.depth = depth
|
self.failed = 0
|
||||||
self.last_level = last_level
|
|
||||||
self.target = target
|
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)
|
||||||
|
|
||||||
|
|
@ -52,30 +52,39 @@ def compare_rgba(width, height, rgba1, rgba2, tol=4.0/256):
|
||||||
return errors == 0
|
return errors == 0
|
||||||
|
|
||||||
|
|
||||||
class TextureTest(Test):
|
def lods(*dims):
|
||||||
|
size = max(dims)
|
||||||
def __init__(self, **kargs):
|
lods = 0
|
||||||
Test.__init__(self)
|
while size:
|
||||||
self.__dict__.update(kargs)
|
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):
|
def description(self):
|
||||||
return "%s %ux%u" % (formats[self.format], self.width, self.height)
|
return "%s %ux%u level=%u" % (formats[self.format], self.width, self.height, self.level)
|
||||||
|
|
||||||
def run(self):
|
def test(self):
|
||||||
dev = self.dev
|
dev = self.dev
|
||||||
|
|
||||||
format = self.format
|
format = self.format
|
||||||
width = self.width
|
width = self.width
|
||||||
height = self.height
|
height = self.height
|
||||||
|
level = self.level
|
||||||
|
|
||||||
|
levels = lods(width, height)
|
||||||
|
|
||||||
|
|
||||||
if not dev.is_format_supported(format, PIPE_TEXTURE):
|
if not dev.is_format_supported(format, PIPE_TEXTURE):
|
||||||
print "SKIP"
|
raise TestSkip
|
||||||
return
|
|
||||||
if not dev.is_format_supported(format, PIPE_SURFACE):
|
|
||||||
print "SKIP"
|
|
||||||
return
|
|
||||||
|
|
||||||
ctx = dev.context_create()
|
ctx = self.dev.context_create()
|
||||||
|
|
||||||
# disabled blending/masking
|
# disabled blending/masking
|
||||||
blend = Blend()
|
blend = Blend()
|
||||||
|
|
@ -123,15 +132,20 @@ class TextureTest(Test):
|
||||||
sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
|
sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
|
||||||
sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
|
sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
|
||||||
sampler.normalized_coords = 1
|
sampler.normalized_coords = 1
|
||||||
|
sampler.min_lod = level
|
||||||
|
sampler.max_lod = level
|
||||||
ctx.set_sampler(0, sampler)
|
ctx.set_sampler(0, sampler)
|
||||||
|
|
||||||
# texture
|
# texture
|
||||||
texture = dev.texture_create(format,
|
texture = dev.texture_create(format,
|
||||||
width,
|
width,
|
||||||
height)
|
height,
|
||||||
|
last_level = levels - 1)
|
||||||
ctx.set_sampler_texture(0, texture)
|
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
|
# framebuffer
|
||||||
cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM,
|
cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM,
|
||||||
|
|
@ -181,8 +195,7 @@ class TextureTest(Test):
|
||||||
|
|
||||||
x = 0
|
x = 0
|
||||||
y = 0
|
y = 0
|
||||||
w = width
|
w, h = minify((width, height), level)
|
||||||
h = height
|
|
||||||
|
|
||||||
verts[ 0] = x # x1
|
verts[ 0] = x # x1
|
||||||
verts[ 1] = y # y1
|
verts[ 1] = y # y1
|
||||||
|
|
@ -223,32 +236,35 @@ class TextureTest(Test):
|
||||||
verts)
|
verts)
|
||||||
|
|
||||||
ctx.flush()
|
ctx.flush()
|
||||||
|
|
||||||
del ctx
|
rgba = FloatArray(h*w*4)
|
||||||
|
|
||||||
rgba = FloatArray(height*width*4)
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
if compare_rgba(width, height, rgba, expected_rgba):
|
if not compare_rgba(w, h, rgba, expected_rgba):
|
||||||
print "OK"
|
|
||||||
else:
|
|
||||||
print "FAIL"
|
|
||||||
|
|
||||||
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, rgba, "result.png")
|
||||||
#save_image(width, height, expected_rgba, "expected.png")
|
#save_image(width, height, expected_rgba, "expected.png")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
raise TestFailure
|
||||||
|
|
||||||
|
del ctx
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
dev = Device()
|
dev = Device()
|
||||||
suite = TestSuite()
|
suite = TestSuite()
|
||||||
formats = [PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_YCBCR, PIPE_FORMAT_DXT1_RGB]
|
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]
|
sizes = [64, 32, 16, 8, 4, 2]
|
||||||
for format in formats:
|
for format in formats:
|
||||||
for size in sizes:
|
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()
|
suite.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue