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
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
24 /** @file blackhole_draw.c
26 * Verifies that with GL_INTEL_black_render enabled, dispatch operations have no
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;
39 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
41 PIGLIT_GL_TEST_CONFIG_END
45 static const char *compute_shader
=
47 "layout (local_size_x = 1) in;"
48 "uniform float value;"
50 "layout (std430, binding = 0) buffer OutBuf { float output_values[]; };\n"
54 " uint pos = gl_GlobalInvocationID.x;\n"
55 " output_values[pos] = value;\n"
65 piglit_init(int argc
, char **argv
)
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
);
85 shader
= glCreateShader(GL_COMPUTE_SHADER
);
87 glShaderSource(shader
, 1,
88 (const GLchar
**) &compute_shader
,
91 glCompileShader(shader
);
93 glGetShaderiv(shader
, GL_COMPILE_STATUS
, &ok
);
95 piglit_report_result(PIGLIT_SKIP
);
99 prog
= glCreateProgram();
101 glAttachShader(prog
, shader
);
105 glGetProgramiv(prog
, GL_LINK_STATUS
, &ok
);
107 piglit_report_result(PIGLIT_SKIP
);
113 if (glIsEnabled(GL_BLACKHOLE_RENDER_INTEL
)) {
114 piglit_report_result(PIGLIT_FAIL
);
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",
125 piglit_report_result(PIGLIT_FAIL
);
129 glEnable(GL_BLACKHOLE_RENDER_INTEL
);
130 if (!glIsEnabled(GL_BLACKHOLE_RENDER_INTEL
)) {
131 piglit_report_result(PIGLIT_FAIL
);
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",
144 piglit_report_result(PIGLIT_FAIL
);
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
);
159 piglit_report_result(PIGLIT_PASS
);