glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / ati_fragment_shader / error11-invaliddst.c
blob11555e15c888118e386274ca8b9deb16cc964056
1 /*
2 * Copyright © 2017 Miklós Máté
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 /** Paragraph 11 of the Errors section:
26 * The error INVALID_ENUM is generated if <dst> passed to
27 * PassTexCoordATI, SampleMapATI, ColorFragmentOp[1..3]ATI, or
28 * AlphaFragmentOp[1..3]ATI is not a valid register or is greater than
29 * the number of texture units available on the implementation.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 10;
37 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
39 PIGLIT_GL_TEST_CONFIG_END
41 enum piglit_result
42 piglit_display(void)
44 /* UNREACHED */
45 return PIGLIT_FAIL;
48 #define check_enum_error(en) if (!piglit_check_gl_error(GL_INVALID_ENUM)) \
49 { printf("Enum %s 0x%x not rejected\n", piglit_get_gl_enum_name(en), en); pass = false; }
51 bool
52 try_enum(unsigned e)
54 bool pass = true;
56 printf(" trying %s 0x%x\n", piglit_get_gl_enum_name(e), e);
58 glBeginFragmentShaderATI();
59 pass &= piglit_check_gl_error(GL_NO_ERROR);
60 glPassTexCoordATI(e, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
61 check_enum_error(e);
63 glSampleMapATI(e, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
64 check_enum_error(e);
66 glColorFragmentOp1ATI(GL_MOV_ATI, e, GL_NONE, GL_NONE,
67 GL_REG_1_ATI, GL_NONE, GL_NONE);
68 check_enum_error(e);
70 glAlphaFragmentOp1ATI(GL_MOV_ATI, e, GL_NONE,
71 GL_REG_1_ATI, GL_NONE, GL_NONE);
72 check_enum_error(e);
73 glEndFragmentShaderATI();
74 /* All instructions were invalid, so the shader should be empty,
75 * which is invalid
77 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
79 /* TODO check fragment ops with more arguments? */
81 return pass;
84 /* Trying all possible enum values is overkill, only try ones that are
85 * used in fragment shaders, thus being common user errors.
86 * Note that some of them have the same numeric value.
88 static const unsigned enums[] = {
89 GL_CON_0_ATI,
90 GL_CON_1_ATI,
91 GL_CON_2_ATI,
92 GL_CON_3_ATI,
93 GL_CON_4_ATI,
94 GL_CON_5_ATI,
95 GL_CON_6_ATI,
96 GL_CON_7_ATI,
97 GL_MOV_ATI,
98 GL_ADD_ATI,
99 GL_MUL_ATI,
100 GL_SUB_ATI,
101 GL_DOT3_ATI,
102 GL_DOT4_ATI,
103 GL_MAD_ATI,
104 GL_LERP_ATI,
105 GL_CND_ATI,
106 GL_CND0_ATI,
107 GL_DOT2_ADD_ATI,
108 GL_SECONDARY_INTERPOLATOR_ATI,
109 GL_SWIZZLE_STR_ATI,
110 GL_SWIZZLE_STQ_ATI,
111 GL_SWIZZLE_STR_DR_ATI,
112 GL_SWIZZLE_STQ_DQ_ATI,
113 GL_SWIZZLE_STRQ_ATI,
114 GL_SWIZZLE_STRQ_DQ_ATI,
115 GL_RED_BIT_ATI,
116 GL_GREEN_BIT_ATI,
117 GL_BLUE_BIT_ATI,
118 GL_2X_BIT_ATI,
119 GL_4X_BIT_ATI,
120 GL_8X_BIT_ATI,
121 GL_HALF_BIT_ATI,
122 GL_QUARTER_BIT_ATI,
123 GL_EIGHTH_BIT_ATI,
124 GL_SATURATE_BIT_ATI,
125 GL_COMP_BIT_ATI,
126 GL_NEGATE_BIT_ATI,
127 GL_BIAS_BIT_ATI,
128 GL_TEXTURE0_ARB,
129 GL_TEXTURE1_ARB,
130 GL_TEXTURE2_ARB,
131 GL_TEXTURE3_ARB,
132 GL_TEXTURE4_ARB,
133 GL_TEXTURE5_ARB,
134 GL_TEXTURE6_ARB,
135 GL_TEXTURE7_ARB,
136 GL_PRIMARY_COLOR_ARB,
137 GL_NONE,
138 GL_RED,
139 GL_GREEN,
140 GL_BLUE,
141 GL_ALPHA,
144 void
145 piglit_init(int argc, char **argv)
147 int num_tex_units;
148 unsigned i;
149 bool pass = true;
151 piglit_require_extension("GL_ATI_fragment_shader");
153 /* The spec defines the number of registers to be fixed at 6, even
154 * though the enum values are defined up to 31 in glext.h. According
155 * to the paragraph above, when an implementation has less than 6
156 * texture units, glSampleMapATI(GL_REG_5_ATI, ...) is invalid.
158 * However, Doom3 uses 6 textures and 6 texcoords, so an implementation
159 * that supports less than 6 textures is not able to run it. Let's fail
160 * if it's less than 6.
162 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &num_tex_units);
163 if (num_tex_units < 6) {
164 printf("Max texture units %d < 6 is not enough for ATI_fragment_shader\n", num_tex_units);
165 piglit_report_result(PIGLIT_FAIL);
168 /* Try some invalid enums */
170 for (i=0; i<ARRAY_SIZE(enums); i++)
171 if (!try_enum(enums[i]))
172 pass = false;
174 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);