summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2016-07-25 15:11:21 -0700
committerEric Anholt <eric@anholt.net>2016-07-25 17:43:21 -0700
commitb2bd9dcb8092e9abc30f142c5c55e3fcca3d6161 (patch)
treefd5166a0ef15e8f37e66fc4f58e175f08e68e7a6
parent89ed0abcf53461cb89edac729e58be96d5b19c3d (diff)
EGL_EXT_image_dma_buf_import/refcount: New test for GEM handle bug.dmabuf-refcount
Drivers can miss the need to refcount their GEM handles, and the destroy of the image/texture pair for tex2 will result in tex1 no longer being usable. This fails to piglit_report_result(PIGLIT_FAIL) on vc4 (which is missing the handle code), because tex1's shadow tiled temporary already has the texture contents in it when the shadow linear->tiled blit fails, but the driver does make a noisy warning on stderr. On intel, if you drop the global name lookup in libdrm, the driver exit()s due to the -EINVAL from the draw call.
-rw-r--r--tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt1
-rw-r--r--tests/spec/ext_image_dma_buf_import/refcount.c134
-rw-r--r--tests/spec/ext_image_dma_buf_import/sample_common.c6
-rw-r--r--tests/spec/ext_image_dma_buf_import/sample_common.h2
4 files changed, 139 insertions, 4 deletions
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 fdf43595a..93f43fad9 100644
--- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
@@ -16,6 +16,7 @@ if(PIGLIT_BUILD_DMA_BUF_TESTS)
${LIBDRM_INCLUDE_DIRS}
)
+ piglit_add_executable(ext_image_dma_buf_import-refcount refcount.c sample_common.c image_common.c)
piglit_add_executable(ext_image_dma_buf_import-sample_yuv sample_yuv.c sample_common.c image_common.c)
piglit_add_executable(ext_image_dma_buf_import-sample_rgb sample_rgb.c sample_common.c image_common.c)
piglit_add_executable(ext_image_dma_buf_import-intel_external_sampler_with_dma_only intel_external_sampler_with_dma_only.c image_common.c)
diff --git a/tests/spec/ext_image_dma_buf_import/refcount.c b/tests/spec/ext_image_dma_buf_import/refcount.c
new file mode 100644
index 000000000..5b14cdd76
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/refcount.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright © 2016 Broadcom
+ *
+ * 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.
+ */
+
+#include "sample_common.h"
+#include "image_common.h"
+
+/**
+ * @file refcount.c
+ *
+ * Creates two EGL images from an ARGB8888 dmabuf, samples each one,
+ * destroys one, then tests that the other can still be sampled.
+ *
+ * This gets at a common refcounting bug in drivers: GEM returns the
+ * same handle for a given BO re-opened through dmabuf on the same
+ * device fd, but that GEM handle is not refcounted. The userspace
+ * driver needs to be sure that it's doing handle refcounting itself.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_es_version = 20;
+ config.window_visual = PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+ static int fourcc = fourcc_code('A', 'R', '2', '4');
+ int w = 2, h = 2;
+ const unsigned char src[] = {
+ 0x00, 0x00, 0xff, 0xff,
+ 0x00, 0xff, 0x00, 0xff,
+ 0xff, 0x00, 0x00, 0xff,
+ 0xff, 0xff, 0xff, 0xff
+ };
+ int cpp = 4;
+ enum piglit_result res;
+ struct piglit_dma_buf *buf;
+ unsigned stride, offset;
+ int fd;
+ EGLImageKHR img1, img2;
+ GLuint tex1, tex2;
+ /* Scale up factor for drawing the texture to the screen. */
+ int scale = 10;
+ int y_spacing = h * scale + 5;
+ int i;
+ GLubyte *expected;
+
+ res = piglit_create_dma_buf(w, h, cpp, src, w * cpp,
+ &buf, &fd, &stride, &offset);
+ if (res != PIGLIT_PASS)
+ return res;
+
+ res = egl_image_for_dma_buf_fd(dup(fd), fourcc, w, h, stride, offset,
+ &img1);
+ if (res != PIGLIT_PASS)
+ return res;
+
+ res = egl_image_for_dma_buf_fd(dup(fd), fourcc, w, h, stride, offset,
+ &img2);
+ if (res != PIGLIT_PASS)
+ return res;
+
+ close(fd);
+
+ res = texture_for_egl_image(img1, &tex1);
+ if (res != PIGLIT_PASS)
+ return res;
+
+ res = texture_for_egl_image(img2, &tex2);
+ if (res != PIGLIT_PASS)
+ return res;
+
+ sample_tex(tex1,
+ 0, y_spacing * 0,
+ w * scale, h * scale);
+ sample_tex(tex2,
+ 0, y_spacing * 1,
+ w * scale, h * scale);
+
+ glDeleteTextures(1, &tex2);
+ eglDestroyImageKHR(eglGetCurrentDisplay(), img2);
+
+ sample_tex(tex1,
+ 0, y_spacing * 2,
+ w * scale, h * scale);
+
+ expected = piglit_rgbw_image_ubyte(w * scale, h * scale, false);
+
+ for (i = 0; i < 3; i++) {
+ if (!piglit_probe_image_ubyte(0,
+ y_spacing * i,
+ w * scale, h * scale,
+ GL_RGBA, expected)) {
+ res = PIGLIT_FAIL;
+ }
+ }
+
+ free(expected);
+
+ piglit_present_results();
+
+ return res;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ EGLDisplay egl_dpy = eglGetCurrentDisplay();
+
+ piglit_require_egl_extension(egl_dpy, "EGL_EXT_image_dma_buf_import");
+ piglit_require_extension("GL_OES_EGL_image_external");
+}
diff --git a/tests/spec/ext_image_dma_buf_import/sample_common.c b/tests/spec/ext_image_dma_buf_import/sample_common.c
index 076d6245e..c5aa1e1b9 100644
--- a/tests/spec/ext_image_dma_buf_import/sample_common.c
+++ b/tests/spec/ext_image_dma_buf_import/sample_common.c
@@ -85,7 +85,7 @@ texture_for_egl_image(EGLImageKHR img, GLuint *out_tex)
}
void
-sample_tex(GLuint tex, unsigned w, unsigned h)
+sample_tex(GLuint tex, unsigned x, unsigned y, unsigned w, unsigned h)
{
GLuint prog;
@@ -96,7 +96,7 @@ sample_tex(GLuint tex, unsigned w, unsigned h)
glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
glUniform1i(glGetUniformLocation(prog, "sampler"), 0);
- glViewport(0, 0, w, h);
+ glViewport(x, y, w, h);
piglit_draw_rect_tex(-1, -1, 2, 2,
0, 0, 1, 1);
@@ -215,7 +215,7 @@ sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h,
if (res != PIGLIT_PASS)
goto destroy;
- sample_tex(tex, w, h);
+ sample_tex(tex, 0, 0, w, h);
destroy:
glDeleteTextures(1, &tex);
diff --git a/tests/spec/ext_image_dma_buf_import/sample_common.h b/tests/spec/ext_image_dma_buf_import/sample_common.h
index 6964dc12f..db2ff82a2 100644
--- a/tests/spec/ext_image_dma_buf_import/sample_common.h
+++ b/tests/spec/ext_image_dma_buf_import/sample_common.h
@@ -43,6 +43,6 @@ enum piglit_result
texture_for_egl_image(EGLImageKHR img, GLuint *out_tex);
void
-sample_tex(GLuint tex, unsigned w, unsigned h);
+sample_tex(GLuint tex, unsigned x, unsigned y, unsigned w, unsigned h);
#endif /* SAMPLE_COMMON_H */