Tests that one can sample the given buffer without other mipmap levels by setting texture filtering accordingly.
Signed-off-by: Topi Pohjolainen <topi.pohjolai...@intel.com> --- .../ext_image_dma_buf_import/CMakeLists.gles2.txt | 1 + .../sample_argb8888_level_zero_only.c | 215 +++++++++++++++++++++ 2 files changed, 216 insertions(+) create mode 100644 tests/spec/ext_image_dma_buf_import/sample_argb8888_level_zero_only.c diff --git a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt index d92c3ba..f60afb6 100644 --- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt +++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt @@ -11,5 +11,6 @@ link_libraries( piglit_add_executable(ext_image_dma_buf_import-sample_argb8888 sample_argb8888.c) piglit_add_executable(ext_image_dma_buf_import-sample_xrgb8888 sample_xrgb8888.c) +piglit_add_executable(ext_image_dma_buf_import-sample_argb8888_level_zero_only sample_argb8888_level_zero_only.c) # vim: ft=cmake: diff --git a/tests/spec/ext_image_dma_buf_import/sample_argb8888_level_zero_only.c b/tests/spec/ext_image_dma_buf_import/sample_argb8888_level_zero_only.c new file mode 100644 index 0000000..8fef182 --- /dev/null +++ b/tests/spec/ext_image_dma_buf_import/sample_argb8888_level_zero_only.c @@ -0,0 +1,215 @@ +/* + * Copyright © 2013 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. + */ + +#define GL_GLEXT_PROTOTYPES 1 +#include "piglit-util-egl.h" +#define EGL_EGLEXT_PROTOTYPES 1 +#include <EGL/eglext.h> +#include <unistd.h> +#include "ext_image_dma_buf_fourcc.h" + +/** + * @file sample_argb8888_level_zero_only.c + * + * Create EGL image out of ARGB8888 formatted dma buffer, set is as level + * zero, set texture filters for avoiding need for other mipmap-levels and + * sample it using a shader program. + */ + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_es_version = 20; + +PIGLIT_GL_TEST_CONFIG_END + +static const char fs_src[] = + "uniform sampler2D sampler;\n" + "varying vec2 texcoords;\n" + "\n" + "void main()\n" + "{\n" + "gl_FragColor = texture2D(sampler, texcoords, 1.0);\n" + "}\n"; +static const char vs_src[] = + "attribute vec4 position;\n" + "varying vec2 texcoords;\n" + "\n" + "void main()\n" + "{\n" + "texcoords = 0.5 * (position.xy + vec2(1.0, 1.0));\n" + "gl_Position = position;\n" + "}\n"; + +static GLuint +make_program(const char *vs, const char *fs) +{ + GLuint prog, tmp; + + prog = glCreateProgram(); + + tmp = piglit_compile_shader_text(GL_VERTEX_SHADER, vs); + glAttachShader(prog, tmp); + + tmp = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs); + glAttachShader(prog, tmp); + + glLinkProgram(prog); + if (!piglit_link_check_status(prog)) + piglit_report_result(PIGLIT_FAIL); + + glUseProgram(prog); + + return prog; +} + +void set_vertices(GLuint prog) +{ + static const GLfloat v[] = { -1.0f, 1.0f, -1.0f, -1.0f, + 1.0f, -1.0f, 1.0f, 1.0f }; + + GLint i = glGetAttribLocation(prog, "position"); + glVertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, 0, v); + glEnableVertexAttribArray(i); +} + +static bool +sample_and_destroy_img(unsigned w, unsigned h, EGLImageKHR img) +{ + GLuint tex, prog; + + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + /* Set the image as level zero */ + glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)img); + if (!piglit_check_egl_error(EGL_SUCCESS)) + return false; + + prog = make_program(vs_src, fs_src); + + glUniform1i(glGetUniformLocation(prog, "sampler"), 0); + set_vertices(prog); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glViewport(0, 0, w, h); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + glDeleteProgram(prog); + glUseProgram(0); + + glDeleteTextures(1, &tex); + eglDestroyImageKHR(eglGetCurrentDisplay(), img); + + return true; +} + +static bool +sample_buffer(void *buf, int fd, unsigned w, unsigned h, unsigned stride, + unsigned offset) +{ + EGLImageKHR img; + EGLint attr[] = { + EGL_WIDTH, w, + EGL_HEIGHT, h, + EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888, + EGL_DMA_BUF_PLANE0_FD_EXT, fd, + EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset, + EGL_DMA_BUF_PLANE0_PITCH_EXT, stride, + EGL_NONE + }; + + /** + * The spec says: + * + * "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid + * display, <ctx> must be EGL_NO_CONTEXT, and <buffer> must be + * NULL, cast into the type EGLClientBuffer." + */ + img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT, + EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr); + + /** + * Release the creator side of the buffer, EGL should have the + * ownership now. + */ + piglit_destroy_dma_buf(buf); + + /* Close the file descriptor also, EGL does not have ownership */ + if (!piglit_check_egl_error(EGL_SUCCESS)) { + close(fd); + return false; + } + + if (!img) { + fprintf(stderr, "image creation succeed but returned NULL\n"); + return false; + } + + return sample_and_destroy_img(w, h, img); +} + +enum piglit_result +piglit_display(void) +{ + const unsigned char src[2 * 2 * 4] = { + 10, 20, 30, 40, 50, 60, 70, 80, + 11, 22, 33, 44, 55, 66, 77, 88 }; + struct piglit_dma_buf *buf; + unsigned stride, offset, i, j; + int fd; + enum piglit_result res; + + res = piglit_create_dma_buf(2, 2, 4, src, 2 * 4, &buf, &fd, &stride, + &offset); + if (res != PIGLIT_PASS) + return res; + + if (!sample_buffer(buf, fd, 2, 2, stride, offset)) + return PIGLIT_FAIL; + + for (i = 0; i < 2; ++i) { + for (j = 0; j < 2; ++j) { + const float expected[] = { + src[i * 2 * 4 + j * 4 + 2] / 255.0f, + src[i * 2 * 4 + j * 4 + 1] / 255.0f, + src[i * 2 * 4 + j * 4 + 0] / 255.0f, + src[i * 2 * 4 + j * 4 + 3] / 255.0f}; + + if (!piglit_probe_pixel_rgba(j, i, expected)) + return PIGLIT_FAIL; + } + } + + return PIGLIT_PASS; +} + +void +piglit_init(int argc, char **argv) +{ + piglit_require_extension("GL_OES_EGL_image"); + piglit_require_egl_extension("EGL_EXT_image_dma_buf_import"); +} -- 1.8.1.2 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/piglit