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
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
25 * @file glsl-bug-110796.c
26 * @author Lionel Landwerlin
28 * Reproduction for a compiler bug.
33 #include "piglit-util-egl.h"
34 #include "piglit-util-gl.h"
36 static const char *vert_shader_text
=
40 " gl_Position = vec4(0.0); \n"
46 GLenum e
= glGetError();
48 printf("GL Error 0x%x at line %d\n", e
, line
);
51 int main(int argc
, char **argv
)
55 EGLContext ctx1
, ctx2
;
57 EGL_CONTEXT_MAJOR_VERSION_KHR
, 3,
58 EGL_CONTEXT_MINOR_VERSION_KHR
, 2,
63 char frag_shader_text1
[256];
64 char frag_shader_text2
[386];
68 snprintf(frag_shader_text1
, sizeof(frag_shader_text1
),
70 "uniform sampler2D s2D;\n"
71 "const ivec2 offset = ivec2(-%i, 7);\n"
72 "out mediump vec4 color;\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
),
81 "uniform sampler2D s2D;\n"
82 "const ivec2[] offsets = ivec2[](\n"
88 "out mediump vec4 color;\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
);
100 piglit_report_result(PIGLIT_FAIL
);
103 ctx1
= eglCreateContext(dpy
, EGL_NO_CONFIG_KHR
, EGL_NO_CONTEXT
, attr
);
106 fprintf(stderr
, "glsl-bug-110796: create contexts failed\n");
107 piglit_report_result(PIGLIT_FAIL
);
110 dpy
= piglit_egl_get_default_display(EGL_NONE
);
113 * Bind first context, make some shaders, draw something.
115 eglMakeCurrent(dpy
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, ctx1
);
117 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
119 program
= piglit_build_simple_program(vert_shader_text
, frag_shader_text1
);
120 check_error(__LINE__
);
122 piglit_report_result(PIGLIT_FAIL
);
125 glLinkProgram(program
);
126 glUseProgram(program
);
127 check_error(__LINE__
);
129 eglMakeCurrent(dpy
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, EGL_NO_CONTEXT
);
131 eglDestroyContext(dpy
, ctx1
);
133 ctx2
= eglCreateContext(dpy
, EGL_NO_CONFIG_KHR
, EGL_NO_CONTEXT
, attr
);
136 fprintf(stderr
, "glsl-bug-110796: create contexts failed\n");
137 piglit_report_result(PIGLIT_FAIL
);
140 eglMakeCurrent(dpy
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, ctx2
);
142 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
144 program
= piglit_build_simple_program(vert_shader_text
, frag_shader_text2
);
145 check_error(__LINE__
);
147 piglit_report_result(PIGLIT_FAIL
);
150 glLinkProgram(program
);
151 glUseProgram(program
);
152 check_error(__LINE__
);
154 eglDestroyContext(dpy
, ctx2
);
156 eglMakeCurrent(dpy
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, EGL_NO_CONTEXT
);
158 piglit_report_result(PIGLIT_PASS
);