glx-multithread-texture: Avoid front-buffer rendering.
[piglit.git] / tests / shaders / glsl-bug-110796.c
blob2210f53176210fd40a49b70af710bb917a055ca8
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) {
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__);
121 if (!program) {
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);
135 if (!ctx2) {
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__);
146 if (!program) {
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);
160 return 0;