summaryrefslogtreecommitdiffstats
path: root/progs/gallium
diff options
context:
space:
mode:
Diffstat (limited to 'progs/gallium')
-rw-r--r--progs/gallium/python/samples/tri.py1
-rwxr-xr-xprogs/gallium/python/tests/base.py17
-rwxr-xr-xprogs/gallium/python/tests/surface_copy.py16
-rwxr-xr-xprogs/gallium/python/tests/texture_blit.py (renamed from progs/gallium/python/tests/texture_sample.py)204
-rwxr-xr-xprogs/gallium/python/tests/texture_transfer.py12
-rw-r--r--progs/gallium/unit/u_format_test.c83
6 files changed, 207 insertions, 126 deletions
diff --git a/progs/gallium/python/samples/tri.py b/progs/gallium/python/samples/tri.py
index 9f6d787dcb2..8cc272db812 100644
--- a/progs/gallium/python/samples/tri.py
+++ b/progs/gallium/python/samples/tri.py
@@ -128,6 +128,7 @@ def test(dev):
scissor.maxy = height
ctx.set_scissor(scissor)
+ # clip
clip = Clip()
clip.nr = 0
ctx.set_clip(clip)
diff --git a/progs/gallium/python/tests/base.py b/progs/gallium/python/tests/base.py
index bd82f50811f..8c55e3ae5d5 100755
--- a/progs/gallium/python/tests/base.py
+++ b/progs/gallium/python/tests/base.py
@@ -43,18 +43,9 @@ from gallium import *
# Enumerate all pixel formats
formats = {}
for name, value in globals().items():
- if name.startswith("PIPE_FORMAT_") and isinstance(value, int):
+ if name.startswith("PIPE_FORMAT_") and isinstance(value, int) and name not in ("PIPE_FORMAT_NONE", "PIPE_FORMAT_COUNT"):
formats[value] = name
-def is_depth_stencil_format(format):
- # FIXME: make and use binding to util_format_is_depth_or_stencil
- return format in (
- PIPE_FORMAT_Z32_UNORM,
- PIPE_FORMAT_S8Z24_UNORM,
- PIPE_FORMAT_X8Z24_UNORM,
- PIPE_FORMAT_Z16_UNORM,
- )
-
def make_image(width, height, rgba):
import Image
outimage = Image.new(
@@ -127,16 +118,16 @@ class Test:
self._run(result)
result.summary()
- def assert_rgba(self, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85):
+ def assert_rgba(self, ctx, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85):
total = h*w
- different = surface.compare_tile_rgba(x, y, w, h, expected_rgba, tol=pixel_tol)
+ different = ctx.surface_compare_rgba(surface, x, y, w, h, expected_rgba, tol=pixel_tol)
if different:
sys.stderr.write("%u out of %u pixels differ\n" % (different, total))
if float(total - different)/float(total) < surface_tol:
if 0:
rgba = FloatArray(h*w*4)
- surface.get_tile_rgba(x, y, w, h, rgba)
+ ctx.surface_read_rgba(surface, 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")
diff --git a/progs/gallium/python/tests/surface_copy.py b/progs/gallium/python/tests/surface_copy.py
index a3f1b3e130c..9364fd1110f 100755
--- a/progs/gallium/python/tests/surface_copy.py
+++ b/progs/gallium/python/tests/surface_copy.py
@@ -56,6 +56,7 @@ class TextureTest(TestCase):
def test(self):
dev = self.dev
+ ctx = self.ctx
target = self.target
format = self.format
@@ -99,21 +100,16 @@ class TextureTest(TestCase):
w = dst_surface.width
h = dst_surface.height
- # ???
- stride = pf_get_stride(texture->format, w)
- size = pf_get_nblocksy(texture->format) * stride
+ stride = util_format_get_stride(format, w)
+ size = util_format_get_nblocksy(format, h) * stride
src_raw = os.urandom(size)
- src_surface.put_tile_raw(0, 0, w, h, src_raw, stride)
+ ctx.surface_write_raw(src_surface, 0, 0, w, h, src_raw, stride)
- ctx = self.dev.context_create()
-
ctx.surface_copy(dst_surface, 0, 0,
src_surface, 0, 0, w, h)
- ctx.flush()
-
- dst_raw = dst_surface.get_tile_raw(0, 0, w, h)
+ dst_raw = ctx.surface_read_raw(dst_surface, 0, 0, w, h)
if dst_raw != src_raw:
raise TestFailure
@@ -122,6 +118,7 @@ class TextureTest(TestCase):
def main():
dev = Device()
+ ctx = dev.context_create()
suite = TestSuite()
targets = [
@@ -181,6 +178,7 @@ def main():
while zslice < depth >> level:
test = TextureTest(
dev = dev,
+ ctx = ctx,
target = target,
format = format,
width = size,
diff --git a/progs/gallium/python/tests/texture_sample.py b/progs/gallium/python/tests/texture_blit.py
index 49545c2e07a..5ae0a7398d7 100755
--- a/progs/gallium/python/tests/texture_sample.py
+++ b/progs/gallium/python/tests/texture_blit.py
@@ -28,6 +28,8 @@
##########################################################################
+import random
+
from gallium import *
from base import *
@@ -115,6 +117,7 @@ class TextureColorSampleTest(TestCase):
def test(self):
dev = self.dev
+ ctx = self.ctx
target = self.target
format = self.format
@@ -125,6 +128,8 @@ class TextureColorSampleTest(TestCase):
face = self.face
level = self.level
zslice = self.zslice
+ minz = 0.0
+ maxz = 1.0
tex_usage = PIPE_TEXTURE_USAGE_SAMPLER
geom_flags = 0
@@ -136,8 +141,6 @@ class TextureColorSampleTest(TestCase):
if not dev.is_format_supported(format, target, tex_usage, geom_flags):
raise TestSkip
- ctx = self.dev.context_create()
-
# disabled blending/masking
blend = Blend()
blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
@@ -155,7 +158,6 @@ class TextureColorSampleTest(TestCase):
rasterizer = Rasterizer()
rasterizer.front_winding = PIPE_WINDING_CW
rasterizer.cull_mode = PIPE_WINDING_NONE
- rasterizer.bypass_vs_clip_and_viewport = 1
ctx.set_rasterizer(rasterizer)
# samplers
@@ -183,14 +185,45 @@ class TextureColorSampleTest(TestCase):
)
expected_rgba = FloatArray(height*width*4)
- texture.get_surface(
+ surface = texture.get_surface(
face = face,
level = level,
zslice = zslice,
- ).sample_rgba(expected_rgba)
+ )
+
+ ctx.surface_sample_rgba(surface, expected_rgba)
ctx.set_fragment_sampler_texture(0, texture)
+ # viewport
+ viewport = Viewport()
+ scale = FloatArray(4)
+ scale[0] = width
+ scale[1] = height
+ scale[2] = (maxz - minz) / 2.0
+ scale[3] = 1.0
+ viewport.scale = scale
+ translate = FloatArray(4)
+ translate[0] = 0.0
+ translate[1] = 0.0
+ translate[2] = (maxz - minz) / 2.0
+ translate[3] = 0.0
+ viewport.translate = translate
+ ctx.set_viewport(viewport)
+
+ # scissor
+ scissor = Scissor()
+ scissor.minx = 0
+ scissor.miny = 0
+ scissor.maxx = width
+ scissor.maxy = height
+ ctx.set_scissor(scissor)
+
+ # clip
+ clip = Clip()
+ clip.nr = 0
+ ctx.set_clip(clip)
+
# framebuffer
cbuf_tex = dev.texture_create(
PIPE_FORMAT_B8G8R8A8_UNORM,
@@ -265,8 +298,8 @@ class TextureColorSampleTest(TestCase):
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 + 0] = pos[i][0]/float(width) # x
+ verts[j + 1] = pos[i][1]/float(height) # y
verts[j + 2] = 0.0 # z
verts[j + 3] = 1.0 # w
verts[j + 4] = tex[i][0] # s
@@ -283,7 +316,7 @@ class TextureColorSampleTest(TestCase):
cbuf = cbuf_tex.get_surface()
- self.assert_rgba(cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
+ self.assert_rgba(ctx, cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
class TextureDepthSampleTest(TestCase):
@@ -302,6 +335,7 @@ class TextureDepthSampleTest(TestCase):
def test(self):
dev = self.dev
+ ctx = self.ctx
target = self.target
format = self.format
@@ -312,6 +346,8 @@ class TextureDepthSampleTest(TestCase):
face = self.face
level = self.level
zslice = self.zslice
+ minz = 0.0
+ maxz = 1.0
tex_usage = PIPE_TEXTURE_USAGE_SAMPLER
geom_flags = 0
@@ -323,8 +359,6 @@ class TextureDepthSampleTest(TestCase):
if not dev.is_format_supported(format, target, tex_usage, geom_flags):
raise TestSkip
- ctx = self.dev.context_create()
-
# disabled blending/masking
blend = Blend()
blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
@@ -345,9 +379,24 @@ class TextureDepthSampleTest(TestCase):
rasterizer = Rasterizer()
rasterizer.front_winding = PIPE_WINDING_CW
rasterizer.cull_mode = PIPE_WINDING_NONE
- rasterizer.bypass_vs_clip_and_viewport = 1
ctx.set_rasterizer(rasterizer)
+ # viewport
+ viewport = Viewport()
+ scale = FloatArray(4)
+ scale[0] = width
+ scale[1] = height
+ scale[2] = (maxz - minz) / 2.0
+ scale[3] = 1.0
+ viewport.scale = scale
+ translate = FloatArray(4)
+ translate[0] = 0.0
+ translate[1] = 0.0
+ translate[2] = (maxz - minz) / 2.0
+ translate[3] = 0.0
+ viewport.translate = translate
+ ctx.set_viewport(viewport)
+
# samplers
sampler = Sampler()
sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
@@ -373,14 +422,29 @@ class TextureDepthSampleTest(TestCase):
)
expected_rgba = FloatArray(height*width*4)
- texture.get_surface(
+ surface = texture.get_surface(
face = face,
level = level,
zslice = zslice,
- ).sample_rgba(expected_rgba)
+ )
+
+ ctx.surface_sample_rgba(surface, expected_rgba)
ctx.set_fragment_sampler_texture(0, texture)
+ # scissor
+ scissor = Scissor()
+ scissor.minx = 0
+ scissor.miny = 0
+ scissor.maxx = width
+ scissor.maxy = height
+ ctx.set_scissor(scissor)
+
+ # clip
+ clip = Clip()
+ clip.nr = 0
+ ctx.set_clip(clip)
+
# framebuffer
cbuf_tex = dev.texture_create(
PIPE_FORMAT_B8G8R8A8_UNORM,
@@ -464,8 +528,8 @@ class TextureDepthSampleTest(TestCase):
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 + 0] = pos[i][0]/float(width) # x
+ verts[j + 1] = pos[i][1]/float(height) # y
verts[j + 2] = 0.0 # z
verts[j + 3] = 1.0 # w
verts[j + 4] = tex[i][0] # s
@@ -482,12 +546,14 @@ class TextureDepthSampleTest(TestCase):
zsbuf = zsbuf_tex.get_surface()
- self.assert_rgba(zsbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
+ self.assert_rgba(ctx, zsbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
def main():
+ random.seed(0xdead3eef)
+
dev = Device()
suite = TestSuite()
@@ -497,32 +563,9 @@ def main():
PIPE_TEXTURE_3D,
]
- color_formats = [
- PIPE_FORMAT_B8G8R8A8_UNORM,
- PIPE_FORMAT_B8G8R8X8_UNORM,
- #PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_FORMAT_B5G6R5_UNORM,
- PIPE_FORMAT_B5G5R5A1_UNORM,
- PIPE_FORMAT_B4G4R4A4_UNORM,
- PIPE_FORMAT_A8_UNORM,
- PIPE_FORMAT_L8_UNORM,
- PIPE_FORMAT_UYVY,
- PIPE_FORMAT_DXT1_RGB,
- #PIPE_FORMAT_DXT1_RGBA,
- #PIPE_FORMAT_DXT3_RGBA,
- #PIPE_FORMAT_DXT5_RGBA,
- ]
-
- depth_formats = [
- PIPE_FORMAT_Z32_UNORM,
- PIPE_FORMAT_S8Z24_UNORM,
- PIPE_FORMAT_X8Z24_UNORM,
- PIPE_FORMAT_Z16_UNORM,
- ]
-
- sizes = [64, 32, 16, 8, 4, 2, 1]
+ #sizes = [64, 32, 16, 8, 4, 2, 1]
#sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
- #sizes = [64]
+ sizes = [64]
#sizes = [63]
faces = [
@@ -534,45 +577,48 @@ def main():
PIPE_TEX_FACE_NEG_Z,
]
- for format in color_formats:
- for target in targets:
- for size in sizes:
- if target == PIPE_TEXTURE_3D:
- depth = size
- else:
- depth = 1
- for face in faces:
- if target != PIPE_TEXTURE_CUBE and face:
- continue
- levels = lods(size)
- for last_level in range(levels):
- for level in range(0, last_level + 1):
- zslice = 0
- while zslice < depth >> level:
- test = TextureColorSampleTest(
- 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)
- zslice = (zslice + 1)*2 - 1
- for format in depth_formats:
- target = PIPE_TEXTURE_2D
- depth = 1
- face = 0
- last_level = 0
- level = 0
- zslice = 0
- for size in sizes:
- test = TextureDepthSampleTest(
+ ctx = dev.context_create()
+
+ try:
+ n = int(sys.argv[1])
+ except:
+ n = 10000
+
+ for i in range(n):
+ format = random.choice(formats.keys())
+ if not util_format_is_depth_or_stencil(format):
+ is_depth_or_stencil = util_format_is_depth_or_stencil(format)
+
+ if is_depth_or_stencil:
+ target = PIPE_TEXTURE_2D
+ else:
+ target = random.choice(targets)
+
+ size = random.choice(sizes)
+
+ if target == PIPE_TEXTURE_3D:
+ depth = size
+ else:
+ depth = 1
+
+ if target == PIPE_TEXTURE_CUBE:
+ face =random.choice(faces)
+ else:
+ face = PIPE_TEX_FACE_POS_X
+
+ levels = lods(size)
+ last_level = random.randint(0, levels - 1)
+ level = random.randint(0, last_level)
+ zslice = random.randint(0, max(depth >> level, 1) - 1)
+
+ if is_depth_or_stencil:
+ klass = TextureDepthSampleTest
+ else:
+ klass = TextureColorSampleTest
+
+ test = klass(
dev = dev,
+ ctx = ctx,
target = target,
format = format,
width = size,
diff --git a/progs/gallium/python/tests/texture_transfer.py b/progs/gallium/python/tests/texture_transfer.py
index 7da00e42550..97a28e01a45 100755
--- a/progs/gallium/python/tests/texture_transfer.py
+++ b/progs/gallium/python/tests/texture_transfer.py
@@ -59,6 +59,7 @@ class TextureTest(TestCase):
def test(self):
dev = self.dev
+ ctx = self.ctx
target = self.target
format = self.format
@@ -86,15 +87,14 @@ class TextureTest(TestCase):
surface = texture.get_surface(face, level, zslice)
- # ???
- stride = pf_get_stride(texture->format, w)
- size = pf_get_nblocksy(texture->format) * stride
+ stride = util_format_get_stride(format, width)
+ size = util_format_get_nblocksy(format, height) * stride
in_raw = os.urandom(size)
- surface.put_tile_raw(0, 0, surface.width, surface.height, in_raw, stride)
+ ctx.surface_write_raw(surface, 0, 0, surface.width, surface.height, in_raw, stride)
- out_raw = surface.get_tile_raw(0, 0, surface.width, surface.height)
+ out_raw = ctx.surface_read_raw(surface, 0, 0, surface.width, surface.height)
if in_raw != out_raw:
raise TestFailure
@@ -102,6 +102,7 @@ class TextureTest(TestCase):
def main():
dev = Device()
+ ctx = dev.context_create()
suite = TestSuite()
targets = [
@@ -161,6 +162,7 @@ def main():
while zslice < depth >> level:
test = TextureTest(
dev = dev,
+ ctx = ctx,
target = target,
format = format,
width = size,
diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c
index 5274311e035..54cb6b879e5 100644
--- a/progs/gallium/unit/u_format_test.c
+++ b/progs/gallium/unit/u_format_test.c
@@ -31,17 +31,24 @@
#include "util/u_format.h"
#include "util/u_format_tests.h"
-#include "util/u_format_pack.h"
static boolean
-test_format_unpack_4f(const struct util_format_test_case *test)
+test_format_fetch_float(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
{
float unpacked[4];
unsigned i;
boolean success;
- util_format_unpack_4f(test->format, unpacked, test->packed);
+ /*
+ * TODO: test block formats too.
+ */
+ if (format_desc->block.width != 1 && format_desc->block.height != 1) {
+ return TRUE;
+ }
+
+ format_desc->fetch_float(unpacked, test->packed, 0, 0);
success = TRUE;
for (i = 0; i < 4; ++i)
@@ -58,15 +65,44 @@ test_format_unpack_4f(const struct util_format_test_case *test)
static boolean
-test_format_pack_4f(const struct util_format_test_case *test)
+test_format_unpack_float(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
{
+ float unpacked[4];
+ unsigned i;
+ boolean success;
+
+ format_desc->unpack_float(unpacked, 0, test->packed, 0, 1, 1);
+
+ success = TRUE;
+ for (i = 0; i < 4; ++i)
+ if (test->unpacked[i] != unpacked[i])
+ success = FALSE;
+
+ if (!success) {
+ printf("FAILED: (%f %f %f %f) obtained\n", unpacked[0], unpacked[1], unpacked[2], unpacked[3]);
+ printf(" (%f %f %f %f) expected\n", test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]);
+ }
+
+ return success;
+}
+
+
+static boolean
+test_format_pack_float(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
+{
+ float unpacked[4];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i;
boolean success;
memset(packed, 0, sizeof packed);
- util_format_pack_4f(test->format, packed, test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]);
+ for (i = 0; i < 4; ++i)
+ unpacked[i] = (float) test->unpacked[i];
+
+ format_desc->pack_float(packed, 0, unpacked, 0, 1, 1);
success = TRUE;
for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i)
@@ -92,7 +128,7 @@ test_format_pack_4f(const struct util_format_test_case *test)
static boolean
-convert_4f_to_4ub(uint8_t *dst, const double *src)
+convert_float_to_8unorm(uint8_t *dst, const double *src)
{
unsigned i;
boolean accurate = TRUE;
@@ -116,16 +152,17 @@ convert_4f_to_4ub(uint8_t *dst, const double *src)
static boolean
-test_format_unpack_4ub(const struct util_format_test_case *test)
+test_format_unpack_8unorm(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
{
uint8_t unpacked[4];
uint8_t expected[4];
unsigned i;
boolean success;
- util_format_unpack_4ub(test->format, unpacked, test->packed);
+ format_desc->unpack_8unorm(unpacked, 0, test->packed, 0, 1, 1);
- convert_4f_to_4ub(expected, test->unpacked);
+ convert_float_to_8unorm(expected, test->unpacked);
success = TRUE;
for (i = 0; i < 4; ++i)
@@ -142,14 +179,15 @@ test_format_unpack_4ub(const struct util_format_test_case *test)
static boolean
-test_format_pack_4ub(const struct util_format_test_case *test)
+test_format_pack_8unorm(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
{
uint8_t unpacked[4];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i;
boolean success;
- if (!convert_4f_to_4ub(unpacked, test->unpacked)) {
+ if (!convert_float_to_8unorm(unpacked, test->unpacked)) {
/*
* Skip test cases which cannot be represented by four unorm bytes.
*/
@@ -158,7 +196,7 @@ test_format_pack_4ub(const struct util_format_test_case *test)
memset(packed, 0, sizeof packed);
- util_format_pack_4ub(test->format, packed, unpacked[0], unpacked[1], unpacked[2], unpacked[3]);
+ format_desc->pack_8unorm(packed, 0, unpacked, 0, 1, 1);
success = TRUE;
for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i)
@@ -184,7 +222,8 @@ test_format_pack_4ub(const struct util_format_test_case *test)
typedef boolean
-(*test_func_t)(const struct util_format_test_case *test);
+(*test_func_t)(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test);
static boolean
@@ -196,14 +235,15 @@ test_one(test_func_t func, const char *suffix)
for (i = 0; i < util_format_nr_test_cases; ++i) {
const struct util_format_test_case *test = &util_format_test_cases[i];
+ const struct util_format_description *format_desc;
+ format_desc = util_format_description(test->format);
+
if (test->format != last_format) {
- const struct util_format_description *format_desc;
- format_desc = util_format_description(test->format);
printf("Testing util_format_%s_%s ...\n", format_desc->short_name, suffix);
last_format = test->format;
}
- if (!func(&util_format_test_cases[i]))
+ if (!func(format_desc, &util_format_test_cases[i]))
success = FALSE;
}
@@ -216,16 +256,19 @@ test_all(void)
{
bool success = TRUE;
- if (!test_one(&test_format_pack_4f, "pack_4f"))
+ if (!test_one(&test_format_fetch_float, "fetch_float"))
+ success = FALSE;
+
+ if (!test_one(&test_format_pack_float, "pack_float"))
success = FALSE;
- if (!test_one(&test_format_unpack_4f, "unpack_4f"))
+ if (!test_one(&test_format_unpack_float, "unpack_float"))
success = FALSE;
- if (!test_one(&test_format_pack_4ub, "pack_4ub"))
+ if (!test_one(&test_format_pack_8unorm, "pack_8unorm"))
success = FALSE;
- if (!test_one(&test_format_unpack_4ub, "unpack_4ub"))
+ if (!test_one(&test_format_unpack_8unorm, "unpack_8unorm"))
success = FALSE;
return success;