ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / intel_blackhole_render / blackhole_dispatch.c
blob172e251bf931f46cafdfcad521b17f7fc6f8d469
1 /*
2 * Copyright © 2018 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 /** @file blackhole_draw.c
26 * Verifies that with GL_INTEL_black_render enabled, dispatch operations have no
27 * effect.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 #if defined(PIGLIT_USE_OPENGL)
35 config.supports_gl_core_version = 42;
36 #elif defined(PIGLIT_USE_OPENGL_ES2) || defined(PIGLIT_USE_OPENGL_ES3)
37 config.supports_gl_es_version = 20;
38 #endif
39 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
41 PIGLIT_GL_TEST_CONFIG_END
43 #define SIZE_X (4)
45 static const char *compute_shader =
46 "#version 430\n"
47 "layout (local_size_x = 1) in;"
48 "uniform float value;"
49 "\n"
50 "layout (std430, binding = 0) buffer OutBuf { float output_values[]; };\n"
51 "\n"
52 "void main()\n"
53 "{\n"
54 " uint pos = gl_GlobalInvocationID.x;\n"
55 " output_values[pos] = value;\n"
56 "}\n";
58 enum piglit_result
59 piglit_display(void)
61 return PIGLIT_FAIL;
64 void
65 piglit_init(int argc, char **argv)
67 GLuint data_bo = 0;
68 GLfloat *data_buf;
69 GLint ok = 1;
70 GLint prog = 0;
71 GLuint shader;
72 const float one = 1.0f, three = 3.0f;
74 piglit_require_extension("GL_ARB_compute_shader");
75 piglit_require_extension("GL_INTEL_blackhole_render");
77 data_buf = calloc(SIZE_X, sizeof(*data_buf));
78 glGenBuffers(1, &data_bo);
79 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, data_bo);
80 glBufferData(GL_SHADER_STORAGE_BUFFER,
81 sizeof(float) * SIZE_X,
82 data_buf, GL_STATIC_DRAW);
83 free(data_buf);
85 shader = glCreateShader(GL_COMPUTE_SHADER);
87 glShaderSource(shader, 1,
88 (const GLchar **) &compute_shader,
89 NULL);
91 glCompileShader(shader);
93 glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
94 if (!ok) {
95 piglit_report_result(PIGLIT_SKIP);
96 return;
99 prog = glCreateProgram();
101 glAttachShader(prog, shader);
103 glLinkProgram(prog);
105 glGetProgramiv(prog, GL_LINK_STATUS, &ok);
106 if (!ok) {
107 piglit_report_result(PIGLIT_SKIP);
108 return;
111 glUseProgram(prog);
113 if (glIsEnabled(GL_BLACKHOLE_RENDER_INTEL)) {
114 piglit_report_result(PIGLIT_FAIL);
115 return;
118 glMemoryBarrier(GL_ALL_BARRIER_BITS);
119 glUniform1f(glGetUniformLocation(prog, "value"), 1.0f);
120 glDispatchCompute(SIZE_X, 1, 1);
121 glMemoryBarrier(GL_ALL_BARRIER_BITS);
123 if (!piglit_probe_buffer(data_bo, GL_SHADER_STORAGE_BUFFER, "output_values",
124 SIZE_X, 1, &one)) {
125 piglit_report_result(PIGLIT_FAIL);
126 return;
129 glEnable(GL_BLACKHOLE_RENDER_INTEL);
130 if (!glIsEnabled(GL_BLACKHOLE_RENDER_INTEL)) {
131 piglit_report_result(PIGLIT_FAIL);
132 return;
135 glMemoryBarrier(GL_ALL_BARRIER_BITS);
136 glUniform1f(glGetUniformLocation(prog, "value"), 2.0f);
137 glDispatchCompute(SIZE_X, 1, 1);
138 glMemoryBarrier(GL_ALL_BARRIER_BITS);
140 glDisable(GL_BLACKHOLE_RENDER_INTEL);
142 if (!piglit_probe_buffer(data_bo, GL_SHADER_STORAGE_BUFFER, "output_values",
143 SIZE_X, 1, &one)) {
144 piglit_report_result(PIGLIT_FAIL);
145 return;
148 glMemoryBarrier(GL_ALL_BARRIER_BITS);
149 glUniform1f(glGetUniformLocation(prog, "value"), 3.0f);
150 glDispatchCompute(SIZE_X, 1, 1);
151 glMemoryBarrier(GL_ALL_BARRIER_BITS);
153 if (!piglit_probe_buffer(data_bo, GL_SHADER_STORAGE_BUFFER, "output_values",
154 SIZE_X, 1, &three)) {
155 piglit_report_result(PIGLIT_FAIL);
156 return;
159 piglit_report_result(PIGLIT_PASS);