conversion-explicit: use a different value for normalized +/- min
[piglit.git] / tests / spec / arb_program_interface_query / getprograminterfaceiv.c
blob4f522c2b0487e0c692fc940d1188d02e681f59f5
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 DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * \file getprograminterfaceiv.c
27 * Tests the error cases of the GetProgramInterfaceiv interface.
29 * From the GL_ARB_program_interface_query spec:
30 * "The command
32 * void GetProgramInterfaceiv(uint program, enum programInterface,
33 * enum pname, int *params);
35 * queries a property of the interface <programInterface> in program
36 * <program>, returning its value in <params>. The property to return is
37 * specified by <pname>.
39 * If <pname> is ACTIVE_RESOURCES, the value returned is the number of
40 * resources in the active resource list for <programInterface>. If the
41 * list of active resources for <programInterface> is empty, zero is
42 * returned.
44 * If <pname> is MAX_NAME_LENGTH, the value returned is the length of the
45 * longest active name string for an active resource in <programInterface>.
46 * This length includes an extra character for the null terminator. If
47 * the list of active resources for <programInterface> is empty, zero is
48 * returned. The error INVALID_OPERATION is generated if
49 * <programInterface> is ATOMIC_COUNTER_BUFFER, since active atomic counter
50 * buffer resources are not assigned name strings.
52 * If <pname> is MAX_NUM_ACTIVE_VARIABLES, the value returned is the number
53 * of active variables belonging to the interface block or atomic counter
54 * buffer resource in <programInterface> with the most active variables.
55 * If the list of active resources for <programInterface> is empty, zero is
56 * returned. The error INVALID_OPERATION is generated if
57 * <programInterface> is not UNIFORM_BLOCK, ATOMIC_COUNTER_BUFFER, or
58 * SHADER_STORAGE_BLOCK.
60 * If <pname> is MAX_NUM_COMPATIBLE_SUBROUTINES, the value returned is the
61 * number of compatible subroutines belonging to the active subroutine
62 * uniform in <programInterface> with the most compatible subroutines. If
63 * the list of active resources for <programInterface> is empty, zero is
64 * returned. The error INVALID_OPERATION is generated unless
65 * <programInterface> is VERTEX_SUBROUTINE_UNIFORM,
66 * TESS_CONTROL_SUBROUTINE_UNIFORM, TESS_EVALUATION_SUBROUTINE_UNIFORM,
67 * GEOMETRY_SUBROUTINE_UNIFORM, FRAGMENT_SUBROUTINE_UNIFORM, or
68 * COMPUTE_SUBROUTINE_UNIFORM.
70 * [...]
72 * An INVALID_VALUE error is generated by GetProgramInterfaceiv,
73 * GetProgramResourceIndex, GetProgramResourceName, GetProgramResourceiv,
74 * GetProgramResourceLocation, and GetProgramResourceLocationIndex if
75 * <program> is not the name of either a shader or program object.
77 * An INVALID_OPERATION error is generated by GetProgramInterfaceiv,
78 * GetProgramResourceIndex, GetProgramResourceName, GetProgramResourceiv,
79 * GetProgramResourceLocation, and GetProgramResourceLocationIndex if
80 * <program> is the name of a shader object.
82 * INVALID_OPERATION is generated by GetProgramInterfaceiv if the parameter
83 * <pname> is not supported for the interface <programInterface>."
86 #include "piglit-util-gl.h"
87 #include "common.h"
89 PIGLIT_GL_TEST_CONFIG_BEGIN
91 config.supports_gl_core_version = 32;
92 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
94 PIGLIT_GL_TEST_CONFIG_END
96 struct subtest_t {
97 GLenum programInterface;
98 GLenum pname;
99 GLenum expected_error;
102 static const struct subtest_t programInterface_subtests[] = {
103 { GL_TRUE, GL_MAX_NAME_LENGTH, GL_INVALID_OPERATION },
104 { GL_UNIFORM, GL_TRUE, GL_INVALID_OPERATION },
105 { GL_ATOMIC_COUNTER_BUFFER, GL_MAX_NAME_LENGTH,
106 GL_INVALID_OPERATION },
107 { GL_UNIFORM, GL_MAX_NUM_ACTIVE_VARIABLES, GL_INVALID_OPERATION },
108 { GL_PROGRAM_OUTPUT, GL_MAX_NUM_COMPATIBLE_SUBROUTINES,
109 GL_INVALID_OPERATION },
112 static bool
113 check_extensions(const struct subtest_t st)
115 if (st.programInterface == GL_ATOMIC_COUNTER_BUFFER &&
116 !piglit_is_extension_supported("GL_ARB_shader_atomic_counters")) {
117 return false;
120 return true;
123 static void
124 run_subtest(const struct subtest_t st, GLuint prog, bool *pass)
126 enum piglit_result result;
127 bool local_pass = true;
128 int value;
129 const char *programInterface_str =
130 piglit_get_gl_enum_name(st.programInterface);
131 const char *pname_str = piglit_get_gl_enum_name(st.pname);
133 if (!check_extensions(st)) {
134 result = PIGLIT_SKIP;
135 goto report_result;
138 glGetProgramInterfaceiv(prog, st.programInterface, st.pname, &value);
139 if (!piglit_check_gl_error(st.expected_error)) {
140 printf(" Call was glGetProgramInterfaceiv(prog, %s, "
141 "%s, ...)\n", programInterface_str, pname_str);
142 local_pass = false;
145 *pass = *pass && local_pass;
146 result = local_pass ? PIGLIT_PASS : PIGLIT_FAIL;
148 report_result:
149 piglit_report_subtest_result(result, "%s on %s", pname_str,
150 programInterface_str);
153 void
154 piglit_init(int argc, char **argv)
156 piglit_require_extension("GL_ARB_program_interface_query");
159 enum piglit_result
160 piglit_display(void)
162 GLuint prog, shader, test_cnt;
163 bool pass = true, prg_tst;
164 int i;
166 /* test using an unexisting program ID */
167 glGetProgramInterfaceiv(1337, GL_UNIFORM, GL_MAX_NUM_ACTIVE_VARIABLES,
168 &i);
169 prg_tst = piglit_check_gl_error(GL_INVALID_VALUE);
170 pass = pass && prg_tst;
171 piglit_report_subtest_result(prg_tst ? PIGLIT_PASS : PIGLIT_FAIL,
172 "Invalid program (undefined ID)");
174 /* test using a shader ID */
175 shader = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_empty);
176 glGetProgramInterfaceiv(shader, GL_UNIFORM, GL_MAX_NUM_ACTIVE_VARIABLES,
177 &i);
178 prg_tst = piglit_check_gl_error(GL_INVALID_OPERATION);
179 pass = pass && prg_tst;
180 piglit_report_subtest_result(prg_tst ? PIGLIT_PASS : PIGLIT_FAIL,
181 "Invalid program (call on shader)");
183 /* build a valid program that will be used to run the other tests */
184 prog = piglit_build_simple_program(vs_empty, fs_empty);
185 if (!piglit_link_check_status(prog)) {
186 glDeleteProgram(prog);
187 return PIGLIT_FAIL;
190 /* run all the getprograminterfaceiv tests */
191 test_cnt = sizeof(programInterface_subtests) / sizeof(struct subtest_t);
192 for (i = 0; i < test_cnt; i++) {
193 run_subtest(programInterface_subtests[i], prog, &pass);
196 glDeleteProgram(prog);
198 return pass ? PIGLIT_PASS : PIGLIT_FAIL;