ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_shader_storage_buffer_object / ssbo-binding.c
blobe4701d7aabf393fe217820643ceb931bfb92519d
1 /*
2 * Copyright © 2015 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
21 * DEALINGS IN THE SOFTWARE.
24 /** @file shaderstorageblockbinding.c
26 * From GL_ARB_shader_storage_buffer_object:
27 * "After a program is linked, the command
29 * void ShaderStorageBlockBinding(uint program, uint storageBlockIndex,
30 * uint storageBlockBinding);
32 * changes the active shader storage block with an assigned index of
33 * <storageBlockIndex> in program object <program>. The error INVALID_VALUE
34 * is generated if <storageBlockIndex> is not an active shader storage block
35 * index in <program>, or if <storageBlockBinding> is greater than or equal
36 * to the value of MAX_SHADER_STORAGE_BUFFER_BINDINGS. If successful,
37 * ShaderStorageBlockBinding specifies that <program> will use the data
38 * store of the buffer object bound to the binding point
39 * <storageBlockBinding> to read and write the values of the buffer
40 * variables in the shader storage block identified by <storageBlockIndex>."
43 #include "piglit-util-gl.h"
45 PIGLIT_GL_TEST_CONFIG_BEGIN
47 config.supports_gl_compat_version = 32;
48 config.supports_gl_core_version = 32;
49 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
50 config.khr_no_error_support = PIGLIT_NO_ERRORS;
52 PIGLIT_GL_TEST_CONFIG_END
54 static GLuint prog;
56 static const char frag_shader_text[] =
57 "#version 130\n"
58 "#extension GL_ARB_shader_storage_buffer_object : require\n"
59 "\n"
60 "buffer ssbo_a { vec4 a; };\n"
61 "\n"
62 "void main()\n"
63 "{\n"
64 " gl_FragColor = a;\n"
65 "}\n";
67 void
68 piglit_init(int argc, char **argv)
70 bool pass = true;
71 int max_binding;
72 int index;
74 piglit_require_extension("GL_ARB_shader_storage_buffer_object");
75 piglit_require_extension("GL_ARB_program_interface_query");
77 prog = piglit_build_simple_program(NULL, frag_shader_text);
79 glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &max_binding);
80 printf("MAX_SHADER_STORAGE_BUFFER_BINDINGS: %d\n", max_binding);
82 index = glGetProgramResourceIndex(prog,
83 GL_SHADER_STORAGE_BLOCK, "ssbo_a");
84 if (!piglit_check_gl_error(0)) {
85 pass = false;
87 printf("Shader storage block \"ssbo_a\" index: %d\n", index);
89 printf("Test binding value: %d\n", 0);
90 glShaderStorageBlockBinding(prog, index, 0);
91 if (!piglit_check_gl_error(0)) {
92 pass = false;
94 printf("Test binding value: %d\n", max_binding - 1);
95 glShaderStorageBlockBinding(prog, index, max_binding - 1);
96 if (!piglit_check_gl_error(0)) {
97 pass = false;
100 if (!piglit_khr_no_error) {
101 /* The error INVALID_VALUE is generated if <storageBlockIndex>
102 * is not an active shader storage block index in <program>,
103 * or if <storageBlockBinding> is greater than or equal to the
104 * value of MAX_SHADER_STORAGE_BUFFER_BINDINGS.
106 printf("Test binding value: %d\n", max_binding);
107 glShaderStorageBlockBinding(prog, index, max_binding);
108 if (!piglit_check_gl_error(GL_INVALID_VALUE)) {
109 pass = false;
112 /* The error INVALID_VALUE is generated if <storageBlockIndex>
113 * is not an active shader storage block index in <program>
115 printf("Test invalid index: %d\n", index + 1);
116 glShaderStorageBlockBinding(prog, index + 1, 0);
117 if (!piglit_check_gl_error(GL_INVALID_VALUE)) {
118 pass = false;
122 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
125 enum piglit_result piglit_display(void)
127 /* UNREACHED */
128 return PIGLIT_FAIL;