glapi: fix parsing of extensions containing string "EGL_"

Category for 'EGLImageTargetTexture2DOES' becomes 'GL_OES_EGL_image'
instead of 'GL_OES_Eimage'.

v2 (Chad): replace first occurence explicitly

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
util/gl: gl-profile style image probe for gles

As GLES reads pixels as non-normalized integers compare the
integers directly instead of transforming to floats first.

v2 (Chad): fix cut-paste error from core-gl - color component
           values for separate and combined alpha/luminance

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
framework: hardware independent interface for dma buffers

In order to test the EXT_image_dma_buf_import, one needs a way for
creating dma buffers that can be imported to EGL and filling them
with data for the GL-stack to sample.
While dma buffer themselves are only defined for linux, the actual
writing of the buffers using CPU differs from hardware to another,
and possibly from window system to another. The intention here is
to push these details into the framework leaving the actual tests
environment independent.

v2 (Chad):
   - replace 'void*' buffer type by 'struct piglit_dma_buf *'

v3 (Chan, Ken):
   - document passing NULL pointers to buffer desctruction

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com> (v2)
Reviewed-by: Eric Anholt <eric@anholt.net>
framework: support for creating dma buffers through libdrm

In order to test EXT_image_dma_buf_import one needs the capability
of creating driver specific buffers. By probing the environment for
drm libraries one can decide for which drivers the support is to
be built.

v2 (first five according to Chad's advice):
   - replace manual search for drm with 'pkg_check_modules()'
   - move BATCH_SZ into intel specific part
   - use ARRAY_SIZE
   - fix faulty check for mem-allocation (drm_buf vs. buf)
   - define the opaque type piglit_dma_buf declared in platform
     independent interface instead of introducing new local type
     (piglit_drm_dma_buf)
   - use 'drm_intel_bo_subdata()' instead of mapping the buffers
     for CPU
   - also set the support for GBM in addition to X11

v3:
   - fix a type (does -> doesn't)
   - exclude intel driver entry points when the driver is not
     present

v4:
   - introduce checking for the libdrm base in the top level of
     the build system. This can be then used to control the
     compilation of the invidual tests as well.
   - add the hooks for all the supported configurations in the
     same place (piglit_gl_framework_init()) instead of one by one
     locally (Chad)
   - added destruction hook NULL pointer support (Chad, Ken)
   - set the file descriptor to zero before exporting (Chad)

v5 (Eric):
   - use 'bool' instead of "zero for success, non-zero for failure"

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
framework: automatic drm authentication for dma buffer support

Fix tests to work as non-root user. Get DRM authentication before
calling intel_bufmgr_gem_init().

v2: refactored into its own patch and allowing the dma buffer
    support to be compiled even without this (change by Topi)

v3: use 'bool' instead of "zero for success, negative for failure"
    (review by Eric, change by Topi)

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
tests/spec: EXT_image_dma_buf_import invalid hints

v2:
   - compile only on platforms that have drm (Eric)
   - use standard drm definitions for fourcc instead of duplicated
     local (Daniel, Eric)
   - use helper variables for width, height and cpp instead
     of repeating the magic numbers over and over again (Eric)
   - use the stride and offset provided by the framework instead of
     hardcoded assumed values (Eric)
   - check that EGL did not take the ownership and revise the
     explanation for it (Eric)

v3 (Eric):
   - revise the explanation claimed but not done in version two
   - use properly linked egl-extension calls

v4 (Eric):
   - add to 'all.tests'
   - removed inclusion of standard EGL entrypoints as there is the
     special dispatcher for the test cases to use
   - check for 'EGL_KHR_image_base' instead of 'GL_OES_EGL_image'
   - initialised 'pass = true' and used '&& pass'-pattern (Chad, Eric)

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
tests/spec: EXT_image_dma_buf_import invalid attributes

v2:
   - compile only on platforms that have drm (Eric)
   - use standard drm definitions for fourcc instead of duplicated
     local (Daniel, Eric)
   - use helper variables for width, height and cpp instead of
     repeating the magic numbers over and over again (Eric)
   - use the stride and offset provided by the framework instead of
     hardcoded assumed values (Eric)
   - rewritten excess attribute test vector using only one set of
     attributes with a re-writable slot for one excess attribute
     (Eric)
   - check that EGL stack does not take the ownersip of the buffer
     and revise the explanation for it (Eric)
   - check also for EGL_DMA_BUF_PLANE2_* as excess attributes (Eric)
   - removed irrelevant quotes of the spec (Eric)
   - changed the error expected for non-NULL context from
     'EGL_BAD_CONTEXT' to 'EGL_BAD_PARAMETER' (Eric)

v3:
   - use properly linked egl-extension calls (Eric)
   - make a distinction between invalid and unsupported formats.
     The former is signified by 'EGL_BAD_ATTRIBUTE' while the latter
     generates 'EGL_BAD_MATCH'. There is test only for the former
     as the latter is driver dependent.

v4:
   - add to 'all.tests' (Eric)
   - removed inclusion of standard EGL entrypoints as there is the
     special dispatcher for the test cases to use (Eric)
   - removed irrelevant quote of the spec (Chad)
   - initialised 'pass = true' and used '&& pass'-pattern (Chad, Eric)

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
tests/spec: EXT_image_dma_buf_import missing attributes

v2:
   - compile only on platforms that have drm (Eric)
   - use standard drm definitions for fourcc instead of duplicated
     local (Daniel, Eric)
   - removed irrelevant quotes of the spec (Eric)
   - rewritten attribute test vector using a full set which is then
     trimmed down in individual tests (Eric)
   - check that EGL did not take the ownership and revise the
     explanation for it (Eric)
   - use helper variables for width, height and cpp instead
     of repeating the magic numbers over and over again (Eric)
   - use the stride and offset provided by the framework instead of
     hardcoded assumed values (Eric)

v3 (Eric):
   - use properly linked egl-extension calls

v4:
   - add to 'all.tests' (Eric)
   - fix filling of the attribute array (Eric)
   - removed inclusion of standard EGL entrypoints as there is the
     special dispatcher for the test cases to use (Eric)
   - initialised 'pass = true' and used '&& pass'-pattern (Chad, Eric)

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
tests/spec: EXT_image_dma_buf_import fd ownership transfer

Simple test checking that EGL closes the export file handle and
the creator can in turn drop its reference.

v2:
   - compile only on platforms that have drm (Eric)
   - use standard drm definitions for fourcc instead of duplicated
     local (Daniel, Eric)
   - use helper variables for width, height and cpp instead of
     repeating the magic numbers over and over again (Eric)
   - try to close the export file descriptor and check that it is
     already closed by the EGL stack (Eric, Chad)
   - fix typo in the description (and commit) (Chad)
   - renamed from "close_buffer" to "ownership_transfer"
   - removed irrelevant quote of the spec (Eric)

v3:
   - use properly linked egl-extension calls (Eric)
   - check for EBADF and not just for close()-failure (Daniel)

v4 (Eric):
   - add to 'all.tests'
   - removed inclusion of standard EGL entrypoints as there is the
     special dispatcher for the test cases to use
   - close the egl-display before checking if the file descriptor
     is closed

v5 (Chad):
   - skip the test if EGL does not support the chosen format
   - report possible failure of 'eglTerminate()' in the console

v6 (Chad):
   - fix egl-image error checking - do not call eglGetError() twice
     in a row as the first call resets the error

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
tests/spec: EXT_image_dma_buf_import sample argb

Tests that one can sample the given buffer without other mipmap
levels by setting texture filtering accordingly.

v2:
   - compile only on platforms that have drm (Eric)
   - use standard drm definitions for fourcc instead of duplicated
     local (Daniel, Eric)
   - removed irrelevant quote of the spec (Eric)
   - use helper variables for width, height and cpp instead
     of repeating the magic numbers over and over again (Eric)
   - used the same refactored common logic as the mipmap ARGB test

v3 (Eric):
   - use properly linked egl-extension calls

v4 (Eric):
   - add to 'all.tests'
   - removed inclusion of standard EGL entrypoints as there is the
     special dispatcher for the test cases to use

v5 (Eric, Chad):
   - sample using image-external extension
   - fix inclusion in all.tests

v6 (Chad):
   - check for GL error instead of EGL when invoking
     glEGLImageTargetTexture2DOES()
   - allow the test to be skipped if external textures or the
     chosen format are not supported
   - fix the scope of the comment describing the need for closing
     file descriptors in case image creation fails
   - introduce format as command line argument and merge the XRGB
     test here
   - don't invoke glReadPixels() for each pixel separately

v7 (Chad):
   - fix egl-image error checking - do not call eglGetError() twice
     in a row as the first call resets the error
   - convert the boolean returned by 'piglit_probe_image_ubyte()'
     into 'enum piglit_result'
   - re-introduce separate vector for expected results - probe
     expects RGB instead of the BGR of source

v8:
   - add missing fragment shader float precision qualifier

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
tests/spec: EXT_image_dma_buf_import intel unsupported format

v2 (Chad): add dependency to 'EGL_KHR_image_base'

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
tests/spec: EXT_image_dma_buf_import intel dma-buf with img-ext only

v2 (Chad):
   - be more specific: rename try_as_non_external_texture() as
     try_as_texture_2d()
   - skip the test if EGL stack does not support the chosen format
   - add dependency to 'EGL_KHR_image_base'

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
tests/spec: EXT_image_dma_buf_import intel img-ext with dma-buf only

v2 (Chad): add dependency to 'EGL_KHR_image_base'

v3: cast 'GLuint' into 'intptr_t' before trying to cast to
    'EGLClientBuffer'. Makes compiler happy on platforms where
    integer and pointer are of different size.

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
util: Add an implementation of strndup

Commit 4c617fa7 added a use of strndup, and that broke this build with
various Windows compilers that don't support strndup.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=68780
Tested-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Ken Phillis Jr. <kphillisjr@gmail.com>
texture-integer: fix issue with GL_RGB_INTEGER_EXT swizzle

The expected alpha was set to zero instead of the random alpha value.
The test passed for all random alpha values greater than zero, because
for those values the resulting alpha was zero. Matching the, incorrect,
expected alpha value of zero. The reason the resulting alpha was zero
was because the computed bias became negative, that in turn caused the
resulting alpha to become negative and then rounded to zero.

The test failed when the random alpha value became zero because it was
expecting the, incorrect, alpha value of zero but got the correct value
of one.

Signed-off-by: Marek Olšák <marek.olsak@amd.com>
texture-integer: fix issue with GL_ALPHA_INTEGER_EXT swizzle

Set value[0], value[1] and value[2] to zero to prevent negative results
in the bias computation.

Signed-off-by: Marek Olšák <marek.olsak@amd.com>
cl: Fix test create-context to test what it was supposed to test

Fixed function parameters to match description.
ARB_texture_gather: add initial execution test

This test exercises combinations of:
- Shader stage vs/fs
- Offsetting
- Component count, up to implementation-defined limit
- Swizzling
- Unsigned normalized, float, int, unsigned int component types

The test works by numbering the texels, and ensuring that the four
texels sampled by textureGather*() are those we expect.

Not exercised yet:
- gsampler2DArray, gsamplerCube, gsamplerCubeArray
- Other interesting internalformats [DEPTH_COMPONENT, etc]
- Addressing modes other than WRAP.
- Use in Geometry Shader. I'd like to pick this up later, as mesa's
  GS support matures.

V2: - Use textureSize rather than hardcoding size in shader;
    - Use piglit_build_simple_program
    - Whitespace tidyups
    - Convert swizzle to enum
    - More component types, for all gsampler2D variants.

V3: - More whitespace
V4: - allow explicit 'unorm' component type; rework usage

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
wiring for more sampler types

Test not actually updated to use them yet.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
add support for testing 2darray