2 * Copyright © 2021 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
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
24 #include "sample_common.h"
25 #include "image_common.h"
28 * @file reimport-bug.c
30 * Test verifies that we can successfully reimport and map a DMABUF. This
31 * specifically checks that drivers, which may map a DMABUF, invalidates any
32 * such mappings (as needed) when it is reimported. This test has been tuned
33 * specifically for the iris driver.
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_es_version
= 30;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
;
41 PIGLIT_GL_TEST_CONFIG_END
52 pbo_upload_bound_tex()
55 glGenBuffersARB(1, &pbo
);
56 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER
, pbo
);
57 glBufferDataARB(GL_PIXEL_UNPACK_BUFFER
, sizeof(uint32_t), NULL
,
60 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 1, 1, GL_RGBA
,
63 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER
, 0);
64 glDeleteBuffersARB(1, &pbo
);
68 ref_map_unref(struct piglit_dma_buf
*buf
, int fourcc
, bool mark_busy
)
70 enum piglit_result res
;
72 /* Import DMABUF as EGLImage */
74 res
= egl_image_for_dma_buf_fd(buf
, buf
->fd
, fourcc
, &img
);
75 if (res
!= PIGLIT_PASS
)
78 /* Import EGLImage as GL_TEXTURE_2D */
80 glGenTextures(1, &tex
);
81 glBindTexture(GL_TEXTURE_2D
, tex
);
82 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D
, (GLeglImageOES
)img
);
83 eglDestroyImageKHR(eglGetCurrentDisplay(), img
);
86 * EGL may not support binding of external textures, this is not an
91 if (error
== GL_INVALID_OPERATION
)
94 if (error
!= GL_NO_ERROR
) {
95 printf("glEGLImageTargetTexture2DOES() failed: %s 0x%x\n",
96 piglit_get_gl_error_name(error
), error
);
100 /* Attempt to make the driver map the buffer object. */
102 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 1, 1, GL_RGBA
,
103 GL_UNSIGNED_BYTE
, &pixels
);
106 /* Attempt to make the driver mark the buffer object as busy.
107 * Avoid using a draw call so that references aren't kept
108 * around longer than we'd like.
110 pbo_upload_bound_tex();
114 /* Delete driver references to the DMABUF */
115 glBindTexture(GL_TEXTURE_2D
, 0);
116 glDeleteTextures(1, &tex
);
121 piglit_init(int argc
, char **argv
)
123 EGLDisplay egl_dpy
= eglGetCurrentDisplay();
124 piglit_require_egl_extension(egl_dpy
, "EGL_EXT_image_dma_buf_import");
125 piglit_require_egl_extension(egl_dpy
, "EGL_KHR_gl_texture_2D_image");
127 enum piglit_result res
;
129 /* Create a DMABUF */
130 const uint64_t src
= 0;
131 const int fourcc
= DRM_FORMAT_ABGR8888
;
132 struct piglit_dma_buf
*buf
;
133 res
= piglit_create_dma_buf(1, 2, fourcc
, &src
, &buf
);
134 if (res
!= PIGLIT_PASS
)
135 piglit_report_result(PIGLIT_SKIP
);
137 if (!ref_map_unref(buf
, fourcc
, true)) {
138 piglit_destroy_dma_buf(buf
);
139 piglit_report_result(PIGLIT_SKIP
);
142 if (!ref_map_unref(buf
, fourcc
, false)) {
143 piglit_destroy_dma_buf(buf
);
144 piglit_report_result(PIGLIT_SKIP
);
147 piglit_destroy_dma_buf(buf
);
148 piglit_report_result(PIGLIT_PASS
);