ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / ext_image_dma_buf_import / ownership_transfer.c
blob5f7adbac2b6f3b4380b159cb0a4c438bfa4cbc39
1 /*
2 * Copyright © 2013 Intel Corporation
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 <errno.h>
26 #include "piglit-framework-gl/piglit_drm_dma_buf.h"
28 #include "image_common.h"
30 /**
31 * @file ownership_transfer.c
33 * From the EXT_image_dma_buf_import spec:
35 * "3. Does ownership of the file descriptor pass to the EGL library?
37 * ANSWER: No, EGL does not take ownership of the file descriptors. It is the
38 * responsibility of the application to close the file descriptors on success
39 * and failure.
42 * Here one checks that the creator of the buffer can drop its reference once
43 * it has given the buffer to EGL, i.e., after calling 'eglCreateImageKHR()'.
46 PIGLIT_GL_TEST_CONFIG_BEGIN
48 config.supports_gl_es_version = 10;
50 PIGLIT_GL_TEST_CONFIG_END
52 static enum piglit_result
53 test_create_and_destroy(unsigned w, unsigned h, void *buf, int fd,
54 unsigned stride, unsigned offset)
56 EGLint error;
57 EGLImageKHR img;
58 EGLint attr[] = {
59 EGL_WIDTH, w,
60 EGL_HEIGHT, h,
61 EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
62 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
63 EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
64 EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
65 EGL_NONE
68 img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
69 EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
71 /* Release the creator side of the buffer. */
72 piglit_destroy_dma_buf(buf);
74 error = eglGetError();
76 /* EGL may not support the format, this is not an error. */
77 if (!img && error == EGL_BAD_MATCH)
78 return PIGLIT_SKIP;
80 if (error != EGL_SUCCESS) {
81 fprintf(stderr, "eglCreateImageKHR() failed: %s 0x%x\n",
82 piglit_get_egl_error_name(error), error);
83 return PIGLIT_FAIL;
86 if (!img) {
87 fprintf(stderr, "image creation succeed but returned NULL\n");
88 return PIGLIT_FAIL;
91 eglDestroyImageKHR(eglGetCurrentDisplay(), img);
93 if (!piglit_check_egl_error(EGL_SUCCESS))
94 return PIGLIT_FAIL;
96 /**
97 * EGL stack is allowed to keep the importing file descriptor open until
98 * all resources are released. Therefore close the display first.
100 if (!eglTerminate(eglGetCurrentDisplay())) {
101 fprintf(stderr, "eglTerminate() failed\n");
102 return PIGLIT_FAIL;
106 * Our own file descriptor must still be valid, and therefore
107 * closing it must succeed.
109 return close(fd) == 0 ? PIGLIT_PASS : PIGLIT_FAIL;
112 enum piglit_result
113 piglit_display(void)
115 const unsigned w = 2;
116 const unsigned h = 2;
117 const unsigned cpp = 4;
118 const unsigned fourcc = DRM_FORMAT_ARGB8888;
119 const unsigned char *pixels = alloca(w * h * cpp);
120 struct piglit_dma_buf *buf;
121 enum piglit_result res;
123 res = piglit_create_dma_buf(w, h, fourcc, pixels, &buf);
124 if (res != PIGLIT_PASS)
125 return res;
127 return test_create_and_destroy(w, h, buf, buf->fd, buf->stride[0], buf->offset[0]);
130 void
131 piglit_init(int argc, char **argv)
133 EGLDisplay egl_dpy = eglGetCurrentDisplay();
134 piglit_require_egl_extension(egl_dpy, "EGL_EXT_image_dma_buf_import");