ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_image_dma_buf_import / refcount.c
blob7ea200edd21a10f609f8c1cde1bdd03ff1c32ffb
1 /*
2 * Copyright © 2016 Broadcom
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 #include "piglit-framework-gl/piglit_drm_dma_buf.h"
26 #include "sample_common.h"
27 #include "image_common.h"
29 /**
30 * @file refcount.c
32 * Creates two EGL images from an ARGB8888 dmabuf, samples each one,
33 * destroys one, then tests that the other can still be sampled.
35 * This gets at a common refcounting bug in drivers: GEM returns the
36 * same handle for a given BO re-opened through dmabuf on the same
37 * device fd, but that GEM handle is not refcounted. The userspace
38 * driver needs to be sure that it's doing handle refcounting itself.
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config.supports_gl_es_version = 20;
44 config.window_visual = PIGLIT_GL_VISUAL_RGBA;
46 PIGLIT_GL_TEST_CONFIG_END
48 enum piglit_result
49 piglit_display(void)
51 static int fourcc = fourcc_code('A', 'R', '2', '4');
52 int w = 2, h = 2;
53 const unsigned char src[] = {
54 0x00, 0x00, 0xff, 0xff,
55 0x00, 0xff, 0x00, 0xff,
56 0xff, 0x00, 0x00, 0xff,
57 0xff, 0xff, 0xff, 0xff
59 enum piglit_result res;
60 struct piglit_dma_buf *buf;
61 EGLImageKHR img1, img2;
62 GLuint tex1, tex2;
63 /* Scale up factor for drawing the texture to the screen. */
64 int scale = 10;
65 int y_spacing = h * scale + 5;
66 int i;
67 GLubyte *expected;
69 res = piglit_create_dma_buf(w, h, fourcc, src, &buf);
70 if (res != PIGLIT_PASS)
71 return res;
73 res = egl_image_for_dma_buf_fd(buf, dup(buf->fd), fourcc, &img1);
74 if (res != PIGLIT_PASS)
75 return res;
77 res = egl_image_for_dma_buf_fd(buf, dup(buf->fd), fourcc, &img2);
78 if (res != PIGLIT_PASS)
79 return res;
81 close(buf->fd);
83 res = texture_for_egl_image(img1, &tex1);
84 if (res != PIGLIT_PASS)
85 return res;
87 res = texture_for_egl_image(img2, &tex2);
88 if (res != PIGLIT_PASS)
89 return res;
91 sample_tex(tex1,
92 0, y_spacing * 0,
93 w * scale, h * scale);
94 sample_tex(tex2,
95 0, y_spacing * 1,
96 w * scale, h * scale);
98 glDeleteTextures(1, &tex2);
99 eglDestroyImageKHR(eglGetCurrentDisplay(), img2);
101 sample_tex(tex1,
102 0, y_spacing * 2,
103 w * scale, h * scale);
105 expected = piglit_rgbw_image_ubyte(w * scale, h * scale, false);
107 for (i = 0; i < 3; i++) {
108 if (!piglit_probe_image_ubyte(0,
109 y_spacing * i,
110 w * scale, h * scale,
111 GL_RGBA, expected)) {
112 res = PIGLIT_FAIL;
116 free(expected);
118 piglit_present_results();
120 return res;
123 void
124 piglit_init(int argc, char **argv)
126 EGLDisplay egl_dpy = eglGetCurrentDisplay();
128 piglit_require_egl_extension(egl_dpy, "EGL_EXT_image_dma_buf_import");
129 piglit_require_extension("GL_OES_EGL_image_external");