diff options
Diffstat (limited to 'progs')
-rw-r--r-- | progs/demos/SConscript | 1 | ||||
-rw-r--r-- | progs/demos/arbocclude2.c | 314 | ||||
-rwxr-xr-x | progs/gallium/python/retrace/interpreter.py | 2 | ||||
-rw-r--r-- | progs/gallium/python/samples/gs.py | 2 | ||||
-rw-r--r-- | progs/gallium/python/samples/tri.py | 2 | ||||
-rwxr-xr-x | progs/gallium/python/tests/base.py | 4 | ||||
-rw-r--r-- | progs/gallium/python/tests/regress/fragment-shader/fragment-shader.py | 2 | ||||
-rw-r--r-- | progs/gallium/python/tests/regress/vertex-shader/vertex-shader.py | 2 | ||||
-rwxr-xr-x | progs/gallium/python/tests/surface_copy.py | 16 | ||||
-rwxr-xr-x | progs/gallium/python/tests/texture_render.py | 20 | ||||
-rwxr-xr-x | progs/gallium/python/tests/texture_sample.py | 24 | ||||
-rwxr-xr-x | progs/gallium/python/tests/texture_transfer.py | 16 | ||||
-rw-r--r-- | progs/gallium/unit/u_format_test.c | 305 | ||||
-rw-r--r-- | progs/rbug/bin_to_bmp.c | 2 | ||||
-rw-r--r-- | progs/tests/getprocaddress.py | 2 | ||||
-rw-r--r-- | progs/xdemos/.gitignore | 1 | ||||
-rw-r--r-- | progs/xdemos/Makefile | 1 | ||||
-rw-r--r-- | progs/xdemos/glsync.c | 11 | ||||
-rw-r--r-- | progs/xdemos/msctest.c | 13 | ||||
-rw-r--r-- | progs/xdemos/omlsync.c | 265 |
20 files changed, 768 insertions, 237 deletions
diff --git a/progs/demos/SConscript b/progs/demos/SConscript index 067c162390..20ec6a002a 100644 --- a/progs/demos/SConscript +++ b/progs/demos/SConscript @@ -4,6 +4,7 @@ progs = [ 'arbfplight', 'arbfslight', 'arbocclude', + 'arbocclude2', 'bounce', 'clearspd', 'copypix', diff --git a/progs/demos/arbocclude2.c b/progs/demos/arbocclude2.c new file mode 100644 index 0000000000..195a23803a --- /dev/null +++ b/progs/demos/arbocclude2.c @@ -0,0 +1,314 @@ +/* + * GL_ARB_occlusion_query demo + * + * Brian Paul + * 12 June 2003 + * + * Copyright (C) 2003 Brian Paul 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL 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 <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + +static GLboolean Anim = GL_TRUE; +static GLfloat Xpos = 0; +static GLuint OccQuery1; +static GLuint OccQuery2; +static GLint Win = 0; + + +static void +PrintString(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + + + +static void Idle(void) +{ + static int lastTime = 0; + static int sign = +1; + int time = glutGet(GLUT_ELAPSED_TIME); + float step; + + if (lastTime == 0) + lastTime = time; + else if (time - lastTime < 20) /* 50Hz update */ + return; + + step = (time - lastTime) / 1000.0 * sign; + lastTime = time; + + Xpos += step; + + if (Xpos > 2.5) { + Xpos = 2.5; + sign = -1; + } + else if (Xpos < -2.5) { + Xpos = -2.5; + sign = +1; + } + glutPostRedisplay(); +} + + +static void Display( void ) +{ + GLuint passed1, passed2; + GLint ready; + char s[100]; + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -15.0 ); + + /* draw the occluding polygons */ + glColor3f(0, 0.6, 0.8); + glBegin(GL_QUADS); + glVertex2f(-1.6, -1.5); + glVertex2f(-0.4, -1.5); + glVertex2f(-0.4, 1.5); + glVertex2f(-1.6, 1.5); + + glVertex2f( 0.4, -1.5); + glVertex2f( 1.6, -1.5); + glVertex2f( 1.6, 1.5); + glVertex2f( 0.4, 1.5); + glEnd(); + +#if defined(GL_ARB_occlusion_query) + glColorMask(0, 0, 0, 0); + glDepthMask(GL_FALSE); + + /* draw the first polygon with occlusion testing */ + glPushMatrix(); + glTranslatef(Xpos, 0.4, -0.5); + glScalef(0.3, 0.3, 1.0); + glRotatef(-90.0 * Xpos, 0, 0, 1); + + glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery1); + + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + + glEndQueryARB(GL_SAMPLES_PASSED_ARB); + + /* draw the second polygon with occlusion testing */ + glPopMatrix(); + glPushMatrix(); + glTranslatef(Xpos, -0.4, -0.5); + glScalef(0.3, 0.3, 1.0); + + glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery2); + + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + + glEndQueryARB(GL_SAMPLES_PASSED_ARB); + + /* turn off occlusion testing */ + glColorMask(1, 1, 1, 1); + glDepthMask(GL_TRUE); + + do { + /* do useful work here, if any */ + glGetQueryObjectivARB(OccQuery1, GL_QUERY_RESULT_AVAILABLE_ARB, &ready); + } while (!ready); + glGetQueryObjectuivARB(OccQuery1, GL_QUERY_RESULT_ARB, &passed1); + + do { + /* do useful work here, if any */ + glGetQueryObjectivARB(OccQuery2, GL_QUERY_RESULT_AVAILABLE_ARB, &ready); + } while (!ready); + glGetQueryObjectuivARB(OccQuery2, GL_QUERY_RESULT_ARB, &passed2); +#endif /* GL_ARB_occlusion_query */ + + /* draw the second rect, so we can see what's going on */ + glColor3f(0.8, 0.5, 0); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + + glPopMatrix(); + glPushMatrix(); + glTranslatef(Xpos, 0.4, -0.5); + glScalef(0.3, 0.3, 1.0); + glRotatef(-90.0 * Xpos, 0, 0, 1); + + /* draw the first rect, so we can see what's going on */ + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + + glPopMatrix(); + + /* Print result message */ + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + glColor3f(1, 1, 1); +#if defined(GL_ARB_occlusion_query) + sprintf(s, " %4d Fragments Visible", passed1); + glRasterPos3f(-0.50, -0.6, 0); + PrintString(s); + if (!passed1) { + glRasterPos3f(-0.25, -0.7, 0); + PrintString("Fully Occluded"); + } + sprintf(s, " %4d Fragments Visible", passed2); + glRasterPos3f(-0.50, -0.8, 0); + PrintString(s); + if (!passed2) { + glRasterPos3f(-0.25, -0.9, 0); + PrintString("Fully Occluded"); + } +#else + glRasterPos3f(-0.25, -0.8, 0); + PrintString("GL_ARB_occlusion_query not available at compile time"); +#endif /* GL_ARB_occlusion_query */ + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + glutDestroyWindow(Win); + exit(0); + break; + case ' ': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + const GLfloat step = 0.1; + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_LEFT: + Xpos -= step; + break; + case GLUT_KEY_RIGHT: + Xpos += step; + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + const char *ext = (const char *) glGetString(GL_EXTENSIONS); + GLint bits; + + if (!strstr(ext, "GL_ARB_occlusion_query")) { + printf("Sorry, this demo requires the GL_ARB_occlusion_query extension\n"); + exit(-1); + } + +#if defined(GL_ARB_occlusion_query) + glGetQueryivARB(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, &bits); + if (!bits) { + printf("Hmmm, GL_QUERY_COUNTER_BITS_ARB is zero!\n"); + exit(-1); + } +#endif /* GL_ARB_occlusion_query */ + + glGetIntegerv(GL_DEPTH_BITS, &bits); + printf("Depthbits: %d\n", bits); + +#if defined(GL_ARB_occlusion_query) + glGenQueriesARB(1, &OccQuery1); + assert(OccQuery1 > 0); + glGenQueriesARB(1, &OccQuery2); + assert(OccQuery2 > 0); +#endif /* GL_ARB_occlusion_query */ + + glEnable(GL_DEPTH_TEST); +} + + +int main( int argc, char *argv[] ) +{ + glutInitWindowSize( 400, 400 ); + glutInit( &argc, argv ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutIdleFunc( Idle ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/gallium/python/retrace/interpreter.py b/progs/gallium/python/retrace/interpreter.py index d0ada7decd..b30469dfae 100755 --- a/progs/gallium/python/retrace/interpreter.py +++ b/progs/gallium/python/retrace/interpreter.py @@ -543,7 +543,7 @@ class Context(Object): gallium.PIPE_FORMAT_R32G32_FLOAT: '2f', gallium.PIPE_FORMAT_R32G32B32_FLOAT: '3f', gallium.PIPE_FORMAT_R32G32B32A32_FLOAT: '4f', - gallium.PIPE_FORMAT_B8G8R8A8_UNORM: '4B', + gallium.PIPE_FORMAT_A8R8G8B8_UNORM: '4B', gallium.PIPE_FORMAT_R8G8B8A8_UNORM: '4B', gallium.PIPE_FORMAT_R16G16B16_SNORM: '3h', }[velem.src_format] diff --git a/progs/gallium/python/samples/gs.py b/progs/gallium/python/samples/gs.py index cd68abac9a..5c22269b18 100644 --- a/progs/gallium/python/samples/gs.py +++ b/progs/gallium/python/samples/gs.py @@ -134,7 +134,7 @@ def test(dev): # framebuffer cbuf = dev.texture_create( - PIPE_FORMAT_X8R8G8B8_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, width, height, tex_usage=PIPE_TEXTURE_USAGE_RENDER_TARGET, ).get_surface() diff --git a/progs/gallium/python/samples/tri.py b/progs/gallium/python/samples/tri.py index f0b5e3dc98..d7fbdb10ac 100644 --- a/progs/gallium/python/samples/tri.py +++ b/progs/gallium/python/samples/tri.py @@ -134,7 +134,7 @@ def test(dev): # framebuffer cbuf = dev.texture_create( - PIPE_FORMAT_X8R8G8B8_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, width, height, tex_usage=PIPE_TEXTURE_USAGE_RENDER_TARGET, ).get_surface() diff --git a/progs/gallium/python/tests/base.py b/progs/gallium/python/tests/base.py index b022d073fd..bd82f50811 100755 --- a/progs/gallium/python/tests/base.py +++ b/progs/gallium/python/tests/base.py @@ -50,8 +50,8 @@ 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_Z24S8_UNORM, - PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_X8Z24_UNORM, PIPE_FORMAT_Z16_UNORM, ) diff --git a/progs/gallium/python/tests/regress/fragment-shader/fragment-shader.py b/progs/gallium/python/tests/regress/fragment-shader/fragment-shader.py index 41dd69d254..b758b4c622 100644 --- a/progs/gallium/python/tests/regress/fragment-shader/fragment-shader.py +++ b/progs/gallium/python/tests/regress/fragment-shader/fragment-shader.py @@ -113,7 +113,7 @@ def test(dev, name): # framebuffer cbuf = dev.texture_create( - PIPE_FORMAT_X8R8G8B8_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, width, height, tex_usage=PIPE_TEXTURE_USAGE_RENDER_TARGET, ).get_surface() diff --git a/progs/gallium/python/tests/regress/vertex-shader/vertex-shader.py b/progs/gallium/python/tests/regress/vertex-shader/vertex-shader.py index 2c44f872e1..bd838cc282 100644 --- a/progs/gallium/python/tests/regress/vertex-shader/vertex-shader.py +++ b/progs/gallium/python/tests/regress/vertex-shader/vertex-shader.py @@ -114,7 +114,7 @@ def test(dev, name): # framebuffer cbuf = dev.texture_create( - PIPE_FORMAT_X8R8G8B8_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, width, height, tex_usage=PIPE_TEXTURE_USAGE_RENDER_TARGET, ).get_surface() diff --git a/progs/gallium/python/tests/surface_copy.py b/progs/gallium/python/tests/surface_copy.py index df5babb78a..a3f1b3e130 100755 --- a/progs/gallium/python/tests/surface_copy.py +++ b/progs/gallium/python/tests/surface_copy.py @@ -131,15 +131,15 @@ def main(): ] formats = [ - PIPE_FORMAT_A8R8G8B8_UNORM, - PIPE_FORMAT_X8R8G8B8_UNORM, - PIPE_FORMAT_A8R8G8B8_SRGB, - PIPE_FORMAT_R5G6B5_UNORM, - PIPE_FORMAT_A1R5G5B5_UNORM, - PIPE_FORMAT_A4R4G4B4_UNORM, + 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_Z32_UNORM, - PIPE_FORMAT_Z24S8_UNORM, - PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_X8Z24_UNORM, PIPE_FORMAT_Z16_UNORM, PIPE_FORMAT_S8_UNORM, PIPE_FORMAT_A8_UNORM, diff --git a/progs/gallium/python/tests/texture_render.py b/progs/gallium/python/tests/texture_render.py index 0fac1ea5ef..1e26639db6 100755 --- a/progs/gallium/python/tests/texture_render.py +++ b/progs/gallium/python/tests/texture_render.py @@ -96,7 +96,7 @@ class TextureTest(TestCase): src_texture = dev.texture_create( target = target, - format = PIPE_FORMAT_A8R8G8B8_UNORM, + format = PIPE_FORMAT_B8G8R8A8_UNORM, width = dst_surface.width, height = dst_surface.height, depth = 1, @@ -149,7 +149,7 @@ class TextureTest(TestCase): # framebuffer cbuf_tex = dev.texture_create( - PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, width, height, tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, @@ -251,15 +251,15 @@ def main(): ] formats = [ - PIPE_FORMAT_A8R8G8B8_UNORM, - PIPE_FORMAT_X8R8G8B8_UNORM, - #PIPE_FORMAT_A8R8G8B8_SRGB, - PIPE_FORMAT_R5G6B5_UNORM, - PIPE_FORMAT_A1R5G5B5_UNORM, - PIPE_FORMAT_A4R4G4B4_UNORM, + 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_Z32_UNORM, - #PIPE_FORMAT_Z24S8_UNORM, - #PIPE_FORMAT_Z24X8_UNORM, + #PIPE_FORMAT_S8Z24_UNORM, + #PIPE_FORMAT_X8Z24_UNORM, #PIPE_FORMAT_Z16_UNORM, #PIPE_FORMAT_S8_UNORM, PIPE_FORMAT_A8_UNORM, diff --git a/progs/gallium/python/tests/texture_sample.py b/progs/gallium/python/tests/texture_sample.py index db32b537a1..49545c2e07 100755 --- a/progs/gallium/python/tests/texture_sample.py +++ b/progs/gallium/python/tests/texture_sample.py @@ -193,7 +193,7 @@ class TextureColorSampleTest(TestCase): # framebuffer cbuf_tex = dev.texture_create( - PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, width, height, tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, @@ -383,14 +383,14 @@ class TextureDepthSampleTest(TestCase): # framebuffer cbuf_tex = dev.texture_create( - PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, width, height, tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, ) zsbuf_tex = dev.texture_create( - PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_X8Z24_UNORM, width, height, tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, @@ -498,15 +498,15 @@ def main(): ] color_formats = [ - PIPE_FORMAT_A8R8G8B8_UNORM, - PIPE_FORMAT_X8R8G8B8_UNORM, - #PIPE_FORMAT_A8R8G8B8_SRGB, - PIPE_FORMAT_R5G6B5_UNORM, - PIPE_FORMAT_A1R5G5B5_UNORM, - PIPE_FORMAT_A4R4G4B4_UNORM, + 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_YCBCR, + PIPE_FORMAT_UYVY, PIPE_FORMAT_DXT1_RGB, #PIPE_FORMAT_DXT1_RGBA, #PIPE_FORMAT_DXT3_RGBA, @@ -515,8 +515,8 @@ def main(): depth_formats = [ PIPE_FORMAT_Z32_UNORM, - PIPE_FORMAT_Z24S8_UNORM, - PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_X8Z24_UNORM, PIPE_FORMAT_Z16_UNORM, ] diff --git a/progs/gallium/python/tests/texture_transfer.py b/progs/gallium/python/tests/texture_transfer.py index 35daca9e49..7da00e4255 100755 --- a/progs/gallium/python/tests/texture_transfer.py +++ b/progs/gallium/python/tests/texture_transfer.py @@ -111,15 +111,15 @@ def main(): ] formats = [ - PIPE_FORMAT_A8R8G8B8_UNORM, - PIPE_FORMAT_X8R8G8B8_UNORM, - PIPE_FORMAT_A8R8G8B8_SRGB, - PIPE_FORMAT_R5G6B5_UNORM, - PIPE_FORMAT_A1R5G5B5_UNORM, - PIPE_FORMAT_A4R4G4B4_UNORM, + 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_Z32_UNORM, - PIPE_FORMAT_Z24S8_UNORM, - PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_X8Z24_UNORM, PIPE_FORMAT_Z16_UNORM, PIPE_FORMAT_S8_UNORM, PIPE_FORMAT_A8_UNORM, diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c index 35bf0220e5..5274311e03 100644 --- a/progs/gallium/unit/u_format_test.c +++ b/progs/gallium/unit/u_format_test.c @@ -30,188 +30,111 @@ #include <stdio.h> #include "util/u_format.h" +#include "util/u_format_tests.h" #include "util/u_format_pack.h" -#define MAX_PACKED_BYTES 4 +static boolean +test_format_unpack_4f(const struct util_format_test_case *test) +{ + float unpacked[4]; + unsigned i; + boolean success; + util_format_unpack_4f(test->format, unpacked, test->packed); -/** - * A (packed, unpacked) color pair. - */ -struct util_format_test_case -{ - enum pipe_format format; + 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; +} - /** - * Mask of the bits that actually meaningful data. Used to mask out the - * "X" channels. - */ - uint8_t mask[MAX_PACKED_BYTES]; - uint8_t packed[MAX_PACKED_BYTES]; +static boolean +test_format_pack_4f(const struct util_format_test_case *test) +{ + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; + unsigned i; + boolean success; - /** - * RGBA. - */ - double unpacked[4]; -}; + memset(packed, 0, sizeof packed); + + util_format_pack_4f(test->format, packed, test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]); + success = TRUE; + for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) + if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) + success = FALSE; -/* - * Helper macros to create the packed bytes for longer words. - */ + if (!success) { + /* TODO: print more than 4 bytes */ + printf("FAILED: (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) obtained\n", + packed[0], packed[1], packed[2], packed[3], + packed[4], packed[5], packed[6], packed[7], + packed[8], packed[9], packed[10], packed[11], + packed[12], packed[13], packed[14], packed[15]); + printf(" (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) expected\n", + test->packed[0], test->packed[1], test->packed[2], test->packed[3], + test->packed[4], test->packed[5], test->packed[6], test->packed[7], + test->packed[8], test->packed[9], test->packed[10], test->packed[11], + test->packed[12], test->packed[13], test->packed[14], test->packed[15]); + } -#define PACKED_1x8(x) {x, 0, 0, 0} -#define PACKED_4x8(x, y, z, w) {x, y, z, w} -#define PACKED_1x32(x) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, ((x) >> 24) & 0xff} -#define PACKED_1x16(x) {(x) & 0xff, ((x) >> 8) & 0xff, 0, 0} + return success; +} -/** - * Test cases. - * - * These were manually entered. We could generate these - * - * To keep this to a we cover only the corner cases, which should produce - * good enough coverage since that pixel format transformations are afine for - * non SRGB formats. - */ -static const struct util_format_test_case -test_cases[] = +static boolean +convert_4f_to_4ub(uint8_t *dst, const double *src) { - {PIPE_FORMAT_R5G6B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5G6B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R5G6B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x07e0), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5G6B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf800), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5G6B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A1R5G5B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A1R5G5B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A1R5G5B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A1R5G5B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7c00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A1R5G5B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A1R5G5B5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A4R4G4B4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A4R4G4B4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A4R4G4B4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00f0), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A4R4G4B4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0f00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A4R4G4B4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A4R4G4B4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A2B10G10R10_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A2B10G10R10_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000003ff), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A2B10G10R10_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000ffc00), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A2B10G10R10_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x3ff00000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A2B10G10R10_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xc0000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A2B10G10R10_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000ff00), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - -#if 0 - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, -#endif - - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {0.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A8L8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8L8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00ff), {1.0, 1.0, 1.0, 0.0}}, - {PIPE_FORMAT_A8L8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xff00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A8L8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A8B8G8R8_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000007f), { 1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000081), {-1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00007f00), { 0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00008100), { 0.0, -1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x007f0000), { 0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00810000), { 0.0, 0.0, -1.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x7f000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A8B8G8R8_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x81000000), { 0.0, 0.0, 0.0, -1.0}}, - - {PIPE_FORMAT_X8UB8UG8SR8S_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8UB8UG8SR8S_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000007f), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8UB8UG8SR8S_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000081), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8UB8UG8SR8S_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00007f00), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8UB8UG8SR8S_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00008100), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8UB8UG8SR8S_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_X8UB8UG8SR8S_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), { 0.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_B6UG5SR5S_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B6UG5SR5S_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B6UG5SR5S_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0011), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B6UG5SR5S_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x01e0), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_B6UG5SR5S_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0220), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_B6UG5SR5S_NORM, PACKED_1x16(0xffff), PACKED_1x16(0xfc00), { 0.0, 0.0, 1.0, 1.0}}, -}; + unsigned i; + boolean accurate = TRUE; + + for (i = 0; i < 4; ++i) { + if (src[i] < 0.0) { + accurate = FALSE; + dst[i] = 0; + } + else if (src[i] > 1.0) { + accurate = FALSE; + dst[i] = 255; + } + else { + dst[i] = src[i] * 255.0; + } + } + + return accurate; +} static boolean -test_format_unpack(const struct util_format_test_case *test) +test_format_unpack_4ub(const struct util_format_test_case *test) { - float unpacked[4]; + uint8_t unpacked[4]; + uint8_t expected[4]; unsigned i; boolean success; - util_format_unpack_4f(test->format, unpacked, test->packed); + util_format_unpack_4ub(test->format, unpacked, test->packed); + + convert_4f_to_4ub(expected, test->unpacked); success = TRUE; for (i = 0; i < 4; ++i) - if (test->unpacked[i] != unpacked[i]) + if (expected[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]); + printf("FAILED: (0x%02x 0x%02x 0x%02x 0x%02x) obtained\n", unpacked[0], unpacked[1], unpacked[2], unpacked[3]); + printf(" (0x%02x 0x%02x 0x%02x 0x%02x) expected\n", expected[0], expected[1], expected[2], expected[3]); } return success; @@ -219,49 +142,68 @@ test_format_unpack(const struct util_format_test_case *test) static boolean -test_format_pack(const struct util_format_test_case *test) +test_format_pack_4ub(const struct util_format_test_case *test) { - uint8_t packed[MAX_PACKED_BYTES]; + uint8_t unpacked[4]; + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; unsigned i; boolean success; + if (!convert_4f_to_4ub(unpacked, test->unpacked)) { + /* + * Skip test cases which cannot be represented by four unorm bytes. + */ + return TRUE; + } + memset(packed, 0, sizeof packed); - util_format_pack_4f(test->format, packed, test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]); + util_format_pack_4ub(test->format, packed, unpacked[0], unpacked[1], unpacked[2], unpacked[3]); success = TRUE; - for (i = 0; i < MAX_PACKED_BYTES; ++i) + for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) success = FALSE; if (!success) { - printf("FAILED: (%02x %02x %02x %02x) obtained\n", packed[0], packed[1], packed[2], packed[3]); - printf(" (%02x %02x %02x %02x) expected\n", test->packed[0], test->packed[1], test->packed[2], test->packed[3]); + /* TODO: print more than 4 bytes */ + printf("FAILED: (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) obtained\n", + packed[0], packed[1], packed[2], packed[3], + packed[4], packed[5], packed[6], packed[7], + packed[8], packed[9], packed[10], packed[11], + packed[12], packed[13], packed[14], packed[15]); + printf(" (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) expected\n", + test->packed[0], test->packed[1], test->packed[2], test->packed[3], + test->packed[4], test->packed[5], test->packed[6], test->packed[7], + test->packed[8], test->packed[9], test->packed[10], test->packed[11], + test->packed[12], test->packed[13], test->packed[14], test->packed[15]); } return success; } +typedef boolean +(*test_func_t)(const struct util_format_test_case *test); + + static boolean -test_all(void) +test_one(test_func_t func, const char *suffix) { enum pipe_format last_format = PIPE_FORMAT_NONE; unsigned i; bool success = TRUE; - for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) { - if (test_cases[i].format != last_format) { + for (i = 0; i < util_format_nr_test_cases; ++i) { + const struct util_format_test_case *test = &util_format_test_cases[i]; + if (test->format != last_format) { const struct util_format_description *format_desc; - format_desc = util_format_description(test_cases[i].format); - fprintf(stderr, "Testing %s ...\n", format_desc->name); - last_format = test_cases[i].format; + format_desc = util_format_description(test->format); + printf("Testing util_format_%s_%s ...\n", format_desc->short_name, suffix); + last_format = test->format; } - if (!test_format_pack(&test_cases[i])) - success = FALSE; - - if (!test_format_unpack(&test_cases[i])) + if (!func(&util_format_test_cases[i])) success = FALSE; } @@ -269,6 +211,27 @@ test_all(void) } +static boolean +test_all(void) +{ + bool success = TRUE; + + if (!test_one(&test_format_pack_4f, "pack_4f")) + success = FALSE; + + if (!test_one(&test_format_unpack_4f, "unpack_4f")) + success = FALSE; + + if (!test_one(&test_format_pack_4ub, "pack_4ub")) + success = FALSE; + + if (!test_one(&test_format_unpack_4ub, "unpack_4ub")) + success = FALSE; + + return success; +} + + int main(int argc, char **argv) { boolean success; diff --git a/progs/rbug/bin_to_bmp.c b/progs/rbug/bin_to_bmp.c index 40ae629090..99a7ec5bc5 100644 --- a/progs/rbug/bin_to_bmp.c +++ b/progs/rbug/bin_to_bmp.c @@ -48,7 +48,7 @@ int main(int argc, char** argv) unsigned stride = width * 4; unsigned size = stride * height; const char *filename = "mybin.bin"; - enum pipe_format format = PIPE_FORMAT_A8R8G8B8_UNORM; + enum pipe_format format = PIPE_FORMAT_B8G8R8A8_UNORM; dump(width, height, stride, format, rbug_read(filename, size), size); diff --git a/progs/tests/getprocaddress.py b/progs/tests/getprocaddress.py index e88ad4c5e4..60111cb801 100644 --- a/progs/tests/getprocaddress.py +++ b/progs/tests/getprocaddress.py @@ -4,7 +4,7 @@ # Helper for the getprocaddress.c test. import sys, getopt, re -sys.path.append("../../src/mesa/glapi/" ) +sys.path.append("../../src/mesa/glapi/gen" ) import gl_XML import license diff --git a/progs/xdemos/.gitignore b/progs/xdemos/.gitignore index 5ae0f5a062..a65b890d3d 100644 --- a/progs/xdemos/.gitignore +++ b/progs/xdemos/.gitignore @@ -27,3 +27,4 @@ xfont xrotfontdemo yuvrect_client msctest +omlsync diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index f866a32865..9cf984b59e 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -32,6 +32,7 @@ PROGS = \ msctest \ multictx \ offset \ + omlsync \ overlay \ pbinfo \ pbdemo \ diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c index c00ba9e468..3751373e23 100644 --- a/progs/xdemos/glsync.c +++ b/progs/xdemos/glsync.c @@ -63,10 +63,9 @@ void (*swap_interval)(); static int GLXExtensionSupported(Display *dpy, const char *extension) { - const char *extensionsString, *client_extensions, *pos; + const char *extensionsString, *pos; extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy)); - client_extensions = glXGetClientString(dpy, GLX_EXTENSIONS); pos = strstr(extensionsString, extension); @@ -74,12 +73,6 @@ static int GLXExtensionSupported(Display *dpy, const char *extension) (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0')) return 1; - pos = strstr(client_extensions, extension); - - if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') && - (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0')) - return 1; - return 0; } @@ -235,7 +228,7 @@ int main(int argc, char *argv[]) XMapWindow(disp, winGL); ret = glXMakeCurrent(disp, winGL, context); - if (ret) { + if (!ret) { fprintf(stderr, "failed to make context current: %d\n", ret); } diff --git a/progs/xdemos/msctest.c b/progs/xdemos/msctest.c index 001ecf04d6..11b0434442 100644 --- a/progs/xdemos/msctest.c +++ b/progs/xdemos/msctest.c @@ -45,10 +45,9 @@ void (*wait_sync)(Display *dpy, Window winGL, int64_t target_msc, int64_t diviso static int GLXExtensionSupported(Display *dpy, const char *extension) { - const char *extensionsString, *client_extensions, *pos; + const char *extensionsString, *pos; extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy)); - client_extensions = glXGetClientString(dpy, GLX_EXTENSIONS); pos = strstr(extensionsString, extension); @@ -56,12 +55,6 @@ static int GLXExtensionSupported(Display *dpy, const char *extension) (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0')) return 1; - pos = strstr(client_extensions, extension); - - if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') && - (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0')) - return 1; - return 0; } @@ -167,8 +160,8 @@ int main(int argc, char *argv[]) glXMakeCurrent(disp, winGL, context); - get_sync_values = glXGetProcAddress((unsigned char *)"glXGetSyncValuesOML"); - wait_sync = glXGetProcAddress((unsigned char *)"glXWaitForMscOML"); + get_sync_values = (void *)glXGetProcAddress((unsigned char *)"glXGetSyncValuesOML"); + wait_sync = (void *)glXGetProcAddress((unsigned char *)"glXWaitForMscOML"); if (!get_sync_values || !wait_sync) { fprintf(stderr, "failed to get sync values function\n"); diff --git a/progs/xdemos/omlsync.c b/progs/xdemos/omlsync.c new file mode 100644 index 0000000000..a2baf4ad72 --- /dev/null +++ b/progs/xdemos/omlsync.c @@ -0,0 +1,265 @@ +/* + * Copyright © 2007-2010 Intel Corporation + * + * 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, sublicense, + * 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + * + * Authors: + * Jesse Barnes <jesse.barnes@intel.com> + * + */ + +/** @file omlsync.c + * The program is simple: it paints a window alternating colors (red & + * white) either as fast as possible or synchronized to vblank events + * + * If run normally, the program should display a window that exhibits + * significant tearing between red and white colors (e.g. you might get + * a "waterfall" effect of red and white horizontal bars). + * + * If run with the '-s b' option, the program should synchronize the + * window color changes with the vertical blank period, resulting in a + * window that looks orangish with a high frequency flicker (which may + * be invisible). If the window is moved to another screen, this + * property should be preserved. If the window spans two screens, it + * shouldn't tear on whichever screen most of the window is on; the + * portion on the other screen may show some tearing (like the + * waterfall effect above). + * + * Other options include '-w <width>' and '-h <height>' to set the + * window size. + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/glx.h> +#include <GL/glxext.h> +#include <X11/X.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +Bool (*glXGetSyncValuesOML)(Display *dpy, GLXDrawable drawable, + int64_t *ust, int64_t *msc, int64_t *sbc); +Bool (*glXGetMscRateOML)(Display *dpy, GLXDrawable drawable, int32_t *numerator, + int32_t *denominator); +int64_t (*glXSwapBuffersMscOML)(Display *dpy, GLXDrawable drawable, + int64_t target_msc, int64_t divisor, + int64_t remainder); +Bool (*glXWaitForMscOML)(Display *dpy, GLXDrawable drawable, int64_t target_msc, + int64_t divisor, int64_t remainder, int64_t *ust, + int64_t *msc, int64_t *sbc); +Bool (*glXWaitForSbcOML)(Display *dpy, GLXDrawable drawable, int64_t target_sbc, + int64_t *ust, int64_t *msc, int64_t *sbc); +int (*glXSwapInterval)(int interval); + +static int GLXExtensionSupported(Display *dpy, const char *extension) +{ + const char *extensionsString, *pos; + + extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy)); + + pos = strstr(extensionsString, extension); + + if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') && + (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0')) + return 1; + + return 0; +} + +extern char *optarg; +extern int optind, opterr, optopt; +static char optstr[] = "w:h:vd:r:n:i:"; + +static void usage(char *name) +{ + printf("usage: %s [-w <width>] [-h <height>] ...\n", name); + printf("\t-d<divisor> - divisor for OML swap\n"); + printf("\t-r<remainder> - remainder for OML swap\n"); + printf("\t-n<interval> - wait interval for OML WaitMSC\n"); + printf("\t-i<swap interval> - swap at most once every n frames\n"); + printf("\t-v: verbose (print count)\n"); + exit(-1); +} + +int main(int argc, char *argv[]) +{ + Display *disp; + XVisualInfo *pvi; + XSetWindowAttributes swa; + Window winGL; + GLXContext context; + int dummy; + Atom wmDelete; + int64_t ust, msc, sbc; + int width = 500, height = 500, verbose = 0, divisor = 0, remainder = 0, + wait_interval = 0, swap_interval = 1; + int c, i = 1; + int ret; + int db_attribs[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + None }; + XSizeHints sizehints; + + opterr = 0; + while ((c = getopt(argc, argv, optstr)) != -1) { + switch (c) { + case 'w': + width = atoi(optarg); + break; + case 'h': + height = atoi(optarg); + break; + case 'v': + verbose = 1; + break; + case 'd': + divisor = atoi(optarg); + break; + case 'r': + remainder = atoi(optarg); + break; + case 'n': + wait_interval = atoi(optarg); + break; + case 'i': + swap_interval = atoi(optarg); + break; + default: + usage(argv[0]); + break; + } + } + + disp = XOpenDisplay(NULL); + if (!disp) { + fprintf(stderr, "failed to open display\n"); + return -1; + } + + if (!glXQueryExtension(disp, &dummy, &dummy)) { + fprintf(stderr, "glXQueryExtension failed\n"); + return -1; + } + + if (!GLXExtensionSupported(disp, "GLX_OML_sync_control")) { + fprintf(stderr, "GLX_OML_sync_control not supported\n"); + return -1; + } + + if (!GLXExtensionSupported(disp, "GLX_MESA_swap_control")) { + fprintf(stderr, "GLX_MESA_swap_control not supported\n"); + return -1; + } + + pvi = glXChooseVisual(disp, DefaultScreen(disp), db_attribs); + + if (!pvi) { + fprintf(stderr, "failed to choose visual, exiting\n"); + return -1; + } + + pvi->screen = DefaultScreen(disp); + + swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen), + pvi->visual, AllocNone); + swa.border_pixel = 0; + swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | + StructureNotifyMask; + winGL = XCreateWindow(disp, RootWindow(disp, pvi->screen), + 0, 0, + width, height, + 0, pvi->depth, InputOutput, pvi->visual, + CWBorderPixel | CWColormap | CWEventMask, &swa); + if (!winGL) { + fprintf(stderr, "window creation failed\n"); + return -1; + } + wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True); + XSetWMProtocols(disp, winGL, &wmDelete, 1); + + sizehints.x = 0; + sizehints.y = 0; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + + XSetNormalHints(disp, winGL, &sizehints); + XSetStandardProperties(disp, winGL, "glsync test", "glsync text", + None, NULL, 0, &sizehints); + + context = glXCreateContext(disp, pvi, NULL, GL_TRUE); + if (!context) { + fprintf(stderr, "failed to create glx context\n"); + return -1; + } + + XMapWindow(disp, winGL); + ret = glXMakeCurrent(disp, winGL, context); + if (!ret) { + fprintf(stderr, "failed to make context current: %d\n", ret); + } + + glXGetSyncValuesOML = (void *)glXGetProcAddress((unsigned char *)"glXGetSyncValuesOML"); + glXGetMscRateOML = (void *)glXGetProcAddress((unsigned char *)"glXGetMscRateOML"); + glXSwapBuffersMscOML = (void *)glXGetProcAddress((unsigned char *)"glXSwapBuffersMscOML"); + glXWaitForMscOML = (void *)glXGetProcAddress((unsigned char *)"glXWaitForMscOML"); + glXWaitForSbcOML = (void *)glXGetProcAddress((unsigned char *)"glXWaitForSbcOML"); + glXSwapInterval = (void *)glXGetProcAddress((unsigned char *)"glXSwapIntervalMESA"); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glXSwapInterval(swap_interval); + fprintf(stderr, "set swap interval to %d\n", swap_interval); + + glXGetSyncValuesOML(disp, winGL, &ust, &msc, &sbc); + while (i++) { + /* Alternate colors to make tearing obvious */ + if (i & 1) { + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + glColor3f(1.0f, 1.0f, 1.0f); + } else { + glClearColor(1.0f, 0.0f, 0.0f, 0.0f); + glColor3f(1.0f, 0.0f, 0.0f); + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glRectf(0, 0, width, height); + + glXSwapBuffersMscOML(disp, winGL, 0, divisor, remainder); + + if (wait_interval) { + glXWaitForMscOML(disp, winGL, msc + wait_interval, + 0, 0, &ust, &msc, &sbc); + } + } + + XDestroyWindow(disp, winGL); + glXDestroyContext(disp, context); + XCloseDisplay(disp); + + return 0; +} |