util: Fix gles2 build

In piglit-framework-fbo.c, alias the following macros when doing a gles2
build:
    #define GL_DEPTH_STENCIL      GL_DEPTH_STENCIL_OES
    #define GL_UNSIGNED_INT_24_8  GL_UNSIGNED_INT_24_8_OES

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
msvc: Copy c99 headers from Mesa for MSVC

Add the following files:
    include/msvc/c99/inttypes.h
    include/msvc/c99/stdbool.h
    include/msvc/c99/stdint.h

Currently, the C99 types for MSCV are defined in piglit-util.h. This makes
nearly all piglit headers depend on piglit-util.h, even if they
really don't need to.

I'm about to begin cleaning up tests/util, and I want to break this
awkward dependency on piglit-util.h. Also, eventually glut_waffle will
need to build with MSVC, and that shouldn't include piglit-util.h.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
cmake: For MSVC, add "include/msvc/c99" to include path (v3)

v2: Place directive in `if (MSVC)` block`, per Jose.
v3: Really do what I said in v2.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Remove custom defs of C99 types for MSVC (v2)

piglit-util.h contained an #ifdef that defined C99 types for MSVC. Remove
the C99 definitions there and let MSVC simply include the C99 headers
located at $PIGLIT_TOP/include/msvc/c99.

v2: Don't delete `#define log2`, per Ken.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Add missing #include

piglit-framework-fbo.h used bool, but did not include stdbool.h.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Move piglit_use_fbo to piglit-framework.*

piglit_use_fbo was declared and defined in piglit-framework-fbo.{h,c}.

The next commit adds module piglit-framework-glut, which implements
functionality orthogonal to piglit-framework-fbo, and hence shouldn't rely
on its header. That's why piglit_use_fbo should be moved to the neutral
"parent" module, piglit-framework.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Remove unused piglit_set_default_fbo() [v2]

This was declared in piglit-framework.h, but never defined.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Move glut code from piglit-framework.* to piglit-framework-glut.*

The fbo code has already been moved into piglit-framework-fbo.*. For
symmetry and clarity, the glut code should exist in its own module too.

As a bonus, this refactor gives piglit-framework.c a well-defined purpose:
to parse argv and then dispatch the testrun to either piglit-framework-fbo
or piglit-framework-glut.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Refactor argv processing out of main()

Move argument processing out of main() into a separate function.  By
simplifying main(), we simplify the transition of main() from
libpiglitutil to test executable.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Move more GLUT initializtion code into piglit-framework-glut.c

Why move initialize GLUT in two different places?

This patch moves the GLUT initiliazation code located in piglit-util.c
into piglit_framework_glut_init().

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Refactor testrunner logic for fbo and glut tests out of main()

Move from main() the last remaining GLUT call and the last bit of logic
needed to run a piglit-framework-glut test into piglit-framework-glut.c.

For symmetry, also move from main() the last bit of logic needed to run
a piglit-framework-fbo test into piglit-framework-fbo.c

Now main() has a simple body and a well-defined purpose: to parse argv and
then dispatch the testrun to either piglit-framework-fbo or
piglit-framework-glut.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Define PIGLIT_GL_TEST_MAIN() and friends (v2)

PIGLIT_GL_TEST_MAIN() defines a boilerplate main() that should be suitable
for most OpenGL test executables.

This patch redefines piglit-framework.c:main() with PIGLIT_GL_TEST_MAIN().
In an upcoming patch, each test executable will define its own main()
likewise.

This patch also defines the following, which are used by
PIGLIT_GL_TEST_MAIN():
    struct piglit_gl_test_info
    piglit_gl_test_info_init()
    piglit_gl_test_run()

Even though piglit_gl_test_run() takes an info struct as input, it does
not yet use that info struct. A follow-on patch fixes this.

v2: Coalesce definitions of PIGLIT_EXTERN_C_{BEGIN,END}, per Ken.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
tests: Let each test define main()

Each test that did not define main() now does so using
PIGLIT_GL_TEST_MAIN().

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Remove unused piglit-framework.c:main()

Now that each test defines main(), piglit-framework's main() is no longer
used.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
util: Remove and refactor weak global symbols in libpiglitutil

This patch's goal is to change the the behavior of the dataflow between
test executables and libpiglitutil. To accomplish that, it removes some
weak global symbols in libpiglitutil and changes the semantics of others.
All changes are located in the piglit-framework-* files.

(I believe that, after this patch, libpiglit can be built as a shared
library on MSVC because it no longer defines weak symbols. But I haven't
tested this.)

Before this patch, the dataflow operated solely via global symbols. Some
symbols were used by the test executable to provide data to libpiglitutil;
some symbols were used for the other direction; and, confusingly, some
symbols provided bidirectional dataflow and conveyed different data
according to direction. The dataflow worked like this:

    Direction A: test executable => libpiglitutil
        - Test behavior, via global functions piglit_init and
          piglit_display.
        - Initialization parameters, via global variables piglit_width,
          piglit_height, and piglit_window_mode.

    Direction B: libpiglitutil => test executable
        - User-requested test options, via global variables piglit_use_fbo
          and piglit_automatic.
        - Dynamic test state, via global variables piglit_width and
          piglit_height.

Observe that, in direction A, piglit_width and piglit_height serve as
initialization parameters. In direction B, they serve to convey dynamic
state.

After this patch, global symbols are used for dataflow in only direction
B, and that dataflow remains unchanged. The dataflow for direction A now
works like this:

    Direction A: test executable => libpiglitutil
        - Test behavior, via function pointers piglit_gl_test_info::{init,display}.
        - Initialization parameters, via piglit_gl_test_info::window_{width,height,visual}.

As a consequence of this change, the following symbols in libpiglitutil
are no longer used and are removed:
    - piglit_init
    - piglit_display
    - piglit_window_mode

Also, since piglit_width and piglit_height are no longer defined by test
executables, but are defined exclusively by libpiglitutil, they need no
longer be declared as weak symbols.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Add a test to check whether the LODs are independant in parallel texture lookups.

Theorically, we should also test that as the fragment shader level,
but the code would be way more complex and the code paths are shared
in mesa.

That was designed to fix the issue in llvmpipe (which also exists in
textureSize).  NVidia passes.  Surprisingly enough, softpipe fails.

Signed-off-by: Olivier Galibert <galibert@pobox.com>
Signed-off-by: José Fonseca <jfonseca@vmware.com>
msaa: Refactor all.tests so that sample counts to test are specified once.
msaa: Test that msaa blits are clipped and scissored correctly.

There are three reasons why the set of rectangles passed to
glBlitFramebuffer() might need to be clipped before performing the
blit:

1. If the destination rectangle falls (partly or completely) outside
the bounds of the draw framebuffer.

2. If the destination rectangle falls (partly or completely) outside
the scissor rectangle.

3. If the source rectangle falls (party or completely) outside the
bounds of the read framebuffer.

In cases 1 and 2, it is clear from the GL spec that the blit should be
clipped.  In case 3, the spec is less clear, however Ian Romanick and
I have received clarification from the ARB that clipping is the
intended behaviour.

This test verifies that blits are properly clipped in cases 1-3.  It
only tests blits in which the source and destination rectangles are
the same size (i.e. no scaling is occurring), since scaling blits are
not allowed for MSAA.
glsl-1.30: Verify proper conversion of large floats to uints.

This patch adds two new tests that exercise a bug in Mesa/i965:
conversion from float to uint was being done in a two step process:
convert first to int and then to uint.  Since i965 uses saturating
arithmetic in float->int conversion, this caused conversion to give
the wrong result for values greater than 0x7fffffff.

I'll be submitting a Mesa fix shortly.
util: Make a separate function to compare in-memory images.

This patch splits off a new piglit-util function,
piglit_compare_images_color(), from the existing
piglit_probe_image_color() function.  The new function compares two
images in memory, so that the caller can take responsibility for
calling glReadPixels().

In addition, this patch creates a function
piglit_compute_probe_tolerance(), which detemines the correct
tolerance thresholds to use when comparing images.

These functions will be needed in order to test proper behaviour of
MSAA with different buffer formats, since the MSAA format test needs
to be able to read the rendered image using glReadPixels, make
adjustments to it in memory, and then compare the results.