ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_image_dma_buf_import / sample_yuv.c
blobb80b58f4bd1cc57888977165419a200a4544cc46
1 /*
2 * Copyright © 2016 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 "sample_common.h"
25 #include "image_common.h"
27 /**
28 * @file sample_rgb.c
30 * Create EGL images out of various YUV formatted dma buffers, set
31 * them as external textures, set texture filters for avoiding need
32 * for other mipmap-levels and sample the textures using a shader
33 * program.
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config.supports_gl_es_version = 20;
39 config.window_visual = PIGLIT_GL_VISUAL_RGBA;
41 PIGLIT_GL_TEST_CONFIG_END
43 static int fourcc = -1;
45 static bool
46 format_has_alpha(int fourcc)
48 switch (fourcc) {
49 case DRM_FORMAT_AYUV:
50 return true;
51 default:
52 return false;
56 enum piglit_result
57 piglit_display(void)
59 uint16_t p0xx[] = {
60 /* Y */
61 12850, 17990, 23130, 28270,
62 12850, 17990, 23130, 28270,
63 12850, 17990, 23130, 28270,
64 12850, 17990, 23130, 28270,
65 /* UV */
66 30840, 33410, 35980, 33410,
67 30840, 41120, 35980, 41120,
70 static const unsigned char nv12[] = {
71 /* Y */
72 50, 70, 90, 110,
73 50, 70, 90, 110,
74 50, 70, 90, 110,
75 50, 70, 90, 110,
76 /* UV */
77 120, 130, 140, 130,
78 120, 160, 140, 160,
79 }, yuv420[] = {
80 /* Y */
81 50, 70, 90, 110,
82 50, 70, 90, 110,
83 50, 70, 90, 110,
84 50, 70, 90, 110,
85 /* U */
86 120, 140,
87 120, 140,
88 /* V */
89 130, 130,
90 160, 160,
91 }, yvu420[] = {
92 /* Y */
93 50, 70, 90, 110,
94 50, 70, 90, 110,
95 50, 70, 90, 110,
96 50, 70, 90, 110,
97 /* V */
98 130, 130,
99 160, 160,
100 /* U */
101 120, 140,
102 120, 140,
103 }, ayuv[] = {
104 /* Increasing alpha ramp. */
105 130, 120, 50, 0,
106 130, 127, 70, 64,
107 130, 133, 90, 128,
108 130, 140, 110, 192,
110 140, 120, 50, 0,
111 140, 127, 70, 64,
112 140, 133, 90, 128,
113 140, 140, 110, 192,
115 150, 120, 50, 0,
116 150, 127, 70, 64,
117 150, 133, 90, 128,
118 150, 140, 110, 192,
120 160, 120, 50, 0,
121 160, 127, 70, 64,
122 160, 133, 90, 128,
123 160, 140, 110, 192,
124 }, yuyv[] = {
125 /* YUYV */
126 50, 120, 70, 130,
127 89, 140, 110, 130,
128 50, 120, 70, 130,
129 89, 140, 110, 130,
130 50, 121, 70, 161,
131 90, 140, 110, 160,
132 50, 121, 70, 161,
133 90, 140, 110, 160,
134 }, uyvy[] = {
135 /* UYVY */
136 120, 50, 130, 70,
137 140, 89, 130, 110,
138 120, 50, 130, 70,
139 140, 89, 130, 110,
140 121, 50, 161, 70,
141 140, 90, 160, 110,
142 121, 50, 161, 70,
143 140, 90, 160, 110,
146 static unsigned char expected[4 * 4 * 4] = {
147 44, 41, 25, 255,
148 67, 64, 48, 255,
149 90, 79, 111, 255,
150 114, 103, 135, 255,
152 44, 41, 25, 255,
153 67, 64, 48, 255,
154 90, 79, 111, 255,
155 114, 103, 135, 255,
157 92, 16, 25, 255,
158 115, 39, 48, 255,
159 138, 55, 111, 255,
160 161, 78, 135, 255,
162 92, 16, 25, 255,
163 115, 39, 48, 255,
164 138, 55, 111, 255,
165 161, 78, 135, 255,
168 const unsigned char *t;
170 enum piglit_result res;
171 switch (fourcc) {
172 case DRM_FORMAT_P010:
173 for (uint32_t i = 0; i < ARRAY_SIZE(p0xx); i++)
174 p0xx[i] &= (1023 << 6);
175 t = (unsigned char *) p0xx;
176 break;
177 case DRM_FORMAT_P012:
178 for (uint32_t i = 0; i < ARRAY_SIZE(p0xx); i++)
179 p0xx[i] &= (4095 << 4);
180 t = (unsigned char *) p0xx;
181 break;
182 case DRM_FORMAT_P016:
183 t = (unsigned char *) p0xx;
184 break;
185 case DRM_FORMAT_NV12:
186 t = nv12;
187 break;
188 case DRM_FORMAT_YUV420:
189 t = yuv420;
190 break;
191 case DRM_FORMAT_YVU420:
192 t = yvu420;
193 break;
194 case DRM_FORMAT_AYUV:
195 case DRM_FORMAT_XYUV8888:
196 t = ayuv;
197 break;
198 case DRM_FORMAT_YUYV:
199 t = yuyv;
200 break;
201 case DRM_FORMAT_UYVY:
202 t = uyvy;
203 break;
204 default:
205 return PIGLIT_SKIP;
208 /* Modify alpha values of the expected result. */
209 if (format_has_alpha(fourcc)) {
210 unsigned char *p = expected;
211 for (uint32_t i = 0; i < 4 * 4; i++, p += 4)
212 p[3] = i * (256 / 4);
215 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
217 res = dma_buf_create_and_sample_32bpp(4, 4, fourcc, t);
218 if (res != PIGLIT_PASS)
219 return res;
221 /* Lower tolerance in case we're running against a 565 render
222 * target (gbm).
224 piglit_set_tolerance_for_bits(5, 6, 5, 8);
226 if (!piglit_probe_image_ubyte(0, 0, 4, 4, GL_RGBA, expected))
227 res = PIGLIT_FAIL;
229 piglit_present_results();
231 return res;
234 static int
235 parse_format(const char *s)
237 if (strlen(s) != 4)
238 return -1;
240 return (int)fourcc_code(s[0], s[1], s[2], s[3]);
243 void
244 piglit_init(int argc, char **argv)
246 unsigned i;
247 EGLDisplay egl_dpy = eglGetCurrentDisplay();
249 piglit_require_egl_extension(egl_dpy, "EGL_EXT_image_dma_buf_import");
250 piglit_require_extension("GL_OES_EGL_image_external");
252 for (i = 1; i < argc; i++) {
253 static const char fmt[] = "-fmt=";
255 if (strncmp(argv[i], fmt, sizeof(fmt) - 1)) {
256 fprintf(stderr, "unknown argument %s\n", argv[i]);
257 continue;
260 fourcc = parse_format(argv[i] + sizeof(fmt) - 1);
261 if (fourcc == -1) {
262 fprintf(stderr, "invalid format: %s\n", argv[i]);
263 piglit_report_result(PIGLIT_SKIP);
267 if (fourcc == -1) {
268 fprintf(stderr, "format not specified\n");
269 piglit_report_result(PIGLIT_SKIP);