ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / intel_blackhole_render / blackhole_dispatch.c
blob222358afa348a65bf64c1ffe56051489ee1de232
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 enum piglit_result result = PIGLIT_PASS;
68 GLuint data_bo = 0;
69 GLfloat *data_buf;
70 GLint ok = 1;
71 GLint prog = 0;
72 GLuint shader;
73 const float one = 1.0f;
75 piglit_require_extension("GL_ARB_compute_shader");
76 piglit_require_extension("GL_INTEL_blackhole_render");
78 data_buf = calloc(SIZE_X, sizeof(*data_buf));
79 glGenBuffers(1, &data_bo);
80 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, data_bo);
81 glBufferData(GL_SHADER_STORAGE_BUFFER,
82 sizeof(float) * SIZE_X,
83 data_buf, GL_STATIC_DRAW);
84 free(data_buf);
86 shader = glCreateShader(GL_COMPUTE_SHADER);
88 glShaderSource(shader, 1,
89 (const GLchar **) &compute_shader,
90 NULL);
92 glCompileShader(shader);
94 glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
95 assert(ok);
97 prog = glCreateProgram();
99 glAttachShader(prog, shader);
101 glLinkProgram(prog);
103 glGetProgramiv(prog, GL_LINK_STATUS, &ok);
104 assert(ok);
106 glUseProgram(prog);
108 assert(!glIsEnabled(GL_BLACKHOLE_RENDER_INTEL));
110 glMemoryBarrier(GL_ALL_BARRIER_BITS);
111 glUniform1f(glGetUniformLocation(prog, "value"), 1.0f);
112 glDispatchCompute(SIZE_X, 1, 1);
113 glMemoryBarrier(GL_ALL_BARRIER_BITS);
115 if (!piglit_probe_buffer(data_bo, GL_SHADER_STORAGE_BUFFER, "output_values",
116 SIZE_X, 1, &one))
117 result = PIGLIT_FAIL;
119 glEnable(GL_BLACKHOLE_RENDER_INTEL);
120 assert(glIsEnabled(GL_BLACKHOLE_RENDER_INTEL));
122 glMemoryBarrier(GL_ALL_BARRIER_BITS);
123 glUniform1f(glGetUniformLocation(prog, "value"), 2.0f);
124 glDispatchCompute(SIZE_X, 1, 1);
125 glMemoryBarrier(GL_ALL_BARRIER_BITS);
127 if (!piglit_probe_buffer(data_bo, GL_SHADER_STORAGE_BUFFER, "output_values",
128 SIZE_X, 1, &one))
129 result = PIGLIT_FAIL;
131 piglit_report_result(result);