fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / spec / arb_shader_storage_buffer_object / array-ssbo-binding.c
blob68242c11777f71c667271588d4e4c0d37e8eba73
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 array-ssbo-binding.c
26 * Tests that modifying the binding point of an array of shader
27 * storage block works correctly, i.e., former attached buffer is not
28 * modified and the other is.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.window_width = 100;
35 config.window_height = 100;
36 config.supports_gl_compat_version = 32;
37 config.supports_gl_core_version = 32;
38 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
39 config.khr_no_error_support = PIGLIT_NO_ERRORS;
41 PIGLIT_GL_TEST_CONFIG_END
43 #define SSBO_SIZE 4
45 static const char vs_pass_thru_text[] =
46 "#version 330\n"
47 "#extension GL_ARB_shader_storage_buffer_object : require\n"
48 "\n"
49 "layout(std140, binding=2) buffer ssbo {\n"
50 " vec4 v;\n"
51 "} a[2];\n"
52 "\n"
53 "in vec4 piglit_vertex;\n"
54 "\n"
55 "void main() {\n"
56 " gl_Position = piglit_vertex;\n"
57 " a[0].v = a[0].v + 1.0;\n"
58 " a[1].v = a[1].v + 10.0;\n"
59 "}\n";
61 static const char fs_source[] =
62 "#version 330\n"
63 "#extension GL_ARB_shader_storage_buffer_object : require\n"
64 "\n"
65 "out vec4 color;\n"
66 "\n"
67 "layout(std140, binding=2) buffer ssbo {\n"
68 " vec4 v;\n"
69 "} a[2];\n"
70 "\n"
71 "void main() {\n"
72 " color = a[0].v;\n"
73 "}\n";
75 GLuint prog;
77 void
78 piglit_init(int argc, char **argv)
80 bool pass = true;
81 GLuint buffer[2];
82 unsigned int i;
83 float ssbo_values[SSBO_SIZE] = {0};
84 float *map;
85 int index;
86 GLint num_vertex_ssbo;
88 piglit_require_extension("GL_ARB_shader_storage_buffer_object");
89 piglit_require_extension("GL_ARB_program_interface_query");
91 glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &num_vertex_ssbo);
92 if (num_vertex_ssbo < 1)
93 piglit_report_result(PIGLIT_SKIP);
95 prog = piglit_build_simple_program(vs_pass_thru_text, fs_source);
97 glUseProgram(prog);
99 glClearColor(0, 0, 0, 0);
101 glGenBuffers(2, buffer);
102 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, buffer[0]);
103 glBufferData(GL_SHADER_STORAGE_BUFFER, SSBO_SIZE*sizeof(GLfloat),
104 &ssbo_values[0], GL_DYNAMIC_DRAW);
105 /* Change binding point */
106 index = glGetProgramResourceIndex(prog,
107 GL_SHADER_STORAGE_BLOCK, "ssbo[0]");
108 glShaderStorageBlockBinding(prog, index, 4);
110 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, buffer[1]);
111 glBufferData(GL_SHADER_STORAGE_BUFFER, SSBO_SIZE*sizeof(GLfloat),
112 &ssbo_values[0], GL_DYNAMIC_DRAW);
114 glViewport(0, 0, piglit_width, piglit_height);
116 piglit_draw_rect(-1, -1, 2, 2);
118 glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer[0]);
119 map = (float *) glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);
121 /* Former bound buffer should not be modified */
122 for (i = 0; i < SSBO_SIZE; i++) {
123 if (map[i] != 0) {
124 printf("Wrong %d value in buffer[0]: %.2f\n",
125 i, map[i]);
126 pass = false;
129 glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
131 glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer[1]);
132 map = (float *) glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);
134 for (i = 0; i < SSBO_SIZE; i++) {
135 /* Values should be below ten but different than zero */
136 if (map[i] == 0 || map[i] > 10) {
137 printf("Wrong %d value in buffer[1]: %.2f\n",
138 i, map[i]);
139 pass = false;
143 glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
145 if (!piglit_check_gl_error(GL_NO_ERROR))
146 pass = false;
148 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
151 enum piglit_result piglit_display(void)
153 /* UNREACHED */
154 return PIGLIT_FAIL;