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
)
67 enum piglit_result result
= PIGLIT_PASS
;
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
);
86 shader
= glCreateShader(GL_COMPUTE_SHADER
);
88 glShaderSource(shader
, 1,
89 (const GLchar
**) &compute_shader
,
92 glCompileShader(shader
);
94 glGetShaderiv(shader
, GL_COMPILE_STATUS
, &ok
);
97 prog
= glCreateProgram();
99 glAttachShader(prog
, shader
);
103 glGetProgramiv(prog
, GL_LINK_STATUS
, &ok
);
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",
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",
129 result
= PIGLIT_FAIL
;
131 piglit_report_result(result
);