cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / shaders / glsl-bug-110796.c
blob18c8891561c22e4455bbff491c72faa947937de7
1 /*
2 * Copyright © 2019 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 /**
25 * @file glsl-bug-110796.c
26 * @author Lionel Landwerlin
28 * Reproduction for a compiler bug.
31 #include <time.h>
33 #include "piglit-util-egl.h"
34 #include "piglit-util-gl.h"
36 static const char *vert_shader_text =
37 "#version 320 es\n"
38 "void main() \n"
39 "{ \n"
40 " gl_Position = vec4(0.0); \n"
41 "} \n";
43 static void
44 check_error(int line)
46 GLenum e = glGetError();
47 if (e)
48 printf("GL Error 0x%x at line %d\n", e, line);
51 int main(int argc, char **argv)
53 EGLint major, minor;
54 EGLDisplay dpy;
55 EGLContext ctx1, ctx2;
56 EGLint attr[] = {
57 EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
58 EGL_CONTEXT_MINOR_VERSION_KHR, 2,
59 EGL_NONE
61 GLuint program;
62 bool ok;
63 char frag_shader_text1[256];
64 char frag_shader_text2[386];
66 srand(time(NULL));
68 snprintf(frag_shader_text1, sizeof(frag_shader_text1),
69 "#version 320 es\n"
70 "uniform sampler2D s2D;\n"
71 "const ivec2 offset = ivec2(-%i, 7);\n"
72 "out mediump vec4 color;\n"
73 "\n"
74 "void main() \n"
75 "{ \n"
76 " color = vec4(1.0) - textureGatherOffset(s2D, vec2(0), offset); \n"
77 "} \n", rand() % 10000);
79 snprintf(frag_shader_text2, sizeof(frag_shader_text2),
80 "#version 320 es\n"
81 "uniform sampler2D s2D;\n"
82 "const ivec2[] offsets = ivec2[](\n"
83 " ivec2(-%i, 7),\n"
84 " ivec2(-%i, 2),\n"
85 " ivec2(-%i, 3),\n"
86 " ivec2(-%i, 4)\n"
87 ");\n"
88 "out mediump vec4 color;\n"
89 "\n"
90 "void main() \n"
91 "{ \n"
92 " color = vec4(1.0) - textureGatherOffsets(s2D, vec2(0), offsets);\n"
93 "} \n", rand() % 10000, rand() % 10000,
94 rand() % 10000, rand() % 10000);
96 dpy = piglit_egl_get_default_display(EGL_NONE);
98 ok = eglInitialize(dpy, &major, &minor);
99 if (!ok) {
100 piglit_report_result(PIGLIT_FAIL);
103 ctx1 = eglCreateContext(dpy, EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, attr);
105 if (ctx1 == EGL_NO_CONTEXT) {
106 EGLint error = eglGetError();
107 switch (error) {
108 case EGL_BAD_MATCH:
109 printf("EGL_BAD_MATCH: Test requires at least ES 3.2.\n");
110 piglit_report_result(PIGLIT_SKIP);
111 break;
112 default:
113 fprintf(stderr, "glsl-bug-110796: first context creation failed\n");
114 piglit_report_result(PIGLIT_FAIL);
115 break;
119 dpy = piglit_egl_get_default_display(EGL_NONE);
122 * Bind first context, make some shaders, draw something.
124 eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx1);
126 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
128 program = piglit_build_simple_program(vert_shader_text, frag_shader_text1);
129 check_error(__LINE__);
130 if (!program) {
131 piglit_report_result(PIGLIT_FAIL);
134 glLinkProgram(program);
135 glUseProgram(program);
136 check_error(__LINE__);
138 eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
140 eglDestroyContext(dpy, ctx1);
142 ctx2 = eglCreateContext(dpy, EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, attr);
144 if (!ctx2) {
145 fprintf(stderr, "glsl-bug-110796: second context creation failed\n");
146 piglit_report_result(PIGLIT_FAIL);
149 eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx2);
151 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
153 program = piglit_build_simple_program(vert_shader_text, frag_shader_text2);
154 check_error(__LINE__);
155 if (!program) {
156 piglit_report_result(PIGLIT_FAIL);
159 glLinkProgram(program);
160 glUseProgram(program);
161 check_error(__LINE__);
163 eglDestroyContext(dpy, ctx2);
165 eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
167 piglit_report_result(PIGLIT_PASS);
169 return 0;