1 //
2 // Copyright (C) 2016 Google, Inc.
3 // Copyright (C) 2022-2024 Arm Limited.
4 //
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 // Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //
14 // Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following
16 // disclaimer in the documentation and/or other materials provided
17 // with the distribution.
18 //
19 // Neither the name of Google Inc. nor the names of its
20 // contributors may be used to endorse or promote products derived
21 // from this software without specific prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 // POSSIBILITY OF SUCH DAMAGE.
35
36 #include <gtest/gtest.h>
37
38 #include "TestFixture.h"
39
40 namespace glslangtest {
41 namespace {
42
43 using CompileToAstTest = GlslangTest<::testing::TestWithParam<std::string>>;
44
45 using CompileToAstTestNV = GlslangTest<::testing::TestWithParam<std::string>>;
46
TEST_P(CompileToAstTest,FromFile)47 TEST_P(CompileToAstTest, FromFile)
48 {
49 loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
50 Source::GLSL, Semantics::OpenGL, glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0,
51 Target::AST);
52 }
53
54 // Compiling GLSL to SPIR-V under OpenGL semantics (NV extensions enabled).
TEST_P(CompileToAstTestNV,FromFile)55 TEST_P(CompileToAstTestNV, FromFile)
56 {
57 loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
58 Source::GLSL, Semantics::OpenGL, glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0,
59 Target::AST);
60 }
61
62 // clang-format off
63 INSTANTIATE_TEST_SUITE_P(
64 Glsl, CompileToAstTest,
65 ::testing::ValuesIn(std::vector<std::string>({
66 "sample.frag",
67 "sample.vert",
68 "decls.frag",
69 "specExamples.frag",
70 "specExamples.vert",
71 "versionsClean.frag",
72 "versionsClean.vert",
73 "versionsErrors.frag",
74 "versionsErrors.vert",
75 "100.frag",
76 "100samplerExternal.frag",
77 "120.vert",
78 "120.frag",
79 "130.vert",
80 "130.frag",
81 "140.vert",
82 "140.frag",
83 "150.vert",
84 "150.geom",
85 "150.frag",
86 "precision.frag",
87 "precision.vert",
88 "nonSquare.vert",
89 "matrixError.vert",
90 "cppSimple.vert",
91 "cppIndent.vert",
92 "cppIntMinOverNegativeOne.frag",
93 "cppMerge.frag",
94 "cppNest.vert",
95 "cppBad.vert",
96 "cppBad2.vert",
97 "cppBad3.vert",
98 "cppBad4.vert",
99 "cppBad5.vert",
100 "cppComplexExpr.vert",
101 "cppDeepNest.frag",
102 "cppPassMacroName.frag",
103 "cppRelaxSkipTokensErrors.vert",
104 "badChars.frag",
105 "pointCoord.frag",
106 "array.frag",
107 "array100.frag",
108 "comment.frag",
109 "300.vert",
110 "300.frag",
111 "300BuiltIns.frag",
112 "300layout.vert",
113 "300layout.frag",
114 "300operations.frag",
115 "300block.frag",
116 "300samplerExternal.frag",
117 "300samplerExternalYUV.frag",
118 "310.comp",
119 "310.vert",
120 "310.geom",
121 "310.frag",
122 "310.tesc",
123 "310.tese",
124 "310implicitSizeArrayError.vert",
125 "310.inheritMemory.frag",
126 "310AofA.vert",
127 "310runtimeArray.vert",
128 "320.comp",
129 "320.vert",
130 "320.geom",
131 "320.frag",
132 "320.tesc",
133 "320.tese",
134 "330.frag",
135 "330comp.frag",
136 "constErrors.frag",
137 "constFold.frag",
138 "constFoldIntMin.frag",
139 "errors.frag",
140 "forwardRef.frag",
141 "uint.frag",
142 "switch.frag",
143 "tokenLength.vert",
144 "100Limits.vert",
145 "100scope.vert",
146 "110scope.vert",
147 "300scope.vert",
148 "400.frag",
149 "400.vert",
150 "410.vert",
151 "420.comp",
152 "420.frag",
153 "420.vert",
154 "420.geom",
155 "420_size_gl_in.geom",
156 "430scope.vert",
157 "lineContinuation100.vert",
158 "lineContinuation.vert",
159 "numeral.frag",
160 "400.geom",
161 "400.tesc",
162 "400.tese",
163 "410.tesc",
164 "420.tesc",
165 "420.tese",
166 "410.geom",
167 "430.vert",
168 "430.comp",
169 "430AofA.frag",
170 "435.vert",
171 "440.vert",
172 "440.frag",
173 "450.vert",
174 "450.geom",
175 "450.tesc",
176 "450.tese",
177 "450.frag",
178 "450.comp",
179 "460.frag",
180 "460.vert",
181 "dce.frag",
182 "atomic_uint.frag",
183 "implicitInnerAtomicUint.frag",
184 "aggOps.frag",
185 "always-discard.frag",
186 "always-discard2.frag",
187 "conditionalDiscard.frag",
188 "conversion.frag",
189 "dataOut.frag",
190 "dataOutIndirect.frag",
191 "deepRvalue.frag",
192 "depthOut.frag",
193 "discard-dce.frag",
194 "doWhileLoop.frag",
195 "earlyReturnDiscard.frag",
196 "flowControl.frag",
197 "forLoop.frag",
198 "functionCall.frag",
199 "functionSemantics.frag",
200 "length.frag",
201 "localAggregates.frag",
202 "loops.frag",
203 "loopsArtificial.frag",
204 "matrix.frag",
205 "matrix2.frag",
206 "mixedArrayDecls.frag",
207 "nonuniform.frag",
208 "newTexture.frag",
209 "Operations.frag",
210 "overlongLiteral.frag",
211 "prepost.frag",
212 "runtimeArray.vert",
213 "simpleFunctionCall.frag",
214 "stringToDouble.vert",
215 "struct.error.frag",
216 "structAssignment.frag",
217 "structDeref.frag",
218 "structure.frag",
219 "swizzle.frag",
220 "invalidSwizzle.vert",
221 "syntaxError.frag",
222 "test.frag",
223 "texture.frag",
224 "tokenPaste.vert",
225 "types.frag",
226 "uniformArray.frag",
227 "variableArrayIndex.frag",
228 "varyingArray.frag",
229 "varyingArrayIndirect.frag",
230 "voidFunction.frag",
231 "whileLoop.frag",
232 "nonVulkan.frag",
233 "negativeArraySize.comp",
234 "precise.tesc",
235 "precise_struct_block.vert",
236 "maxClipDistances.vert",
237 "findFunction.frag",
238 "noMatchingFunction.frag",
239 "constantUnaryConversion.comp",
240 "xfbUnsizedArray.error.vert",
241 "xfbUnsizedArray.error.tese",
242 "glsl.140.layoutOffset.error.vert",
243 "glsl.430.layoutOffset.error.vert",
244 "glsl.450.subgroup.frag",
245 "glsl.450.subgroup.geom",
246 "glsl.450.subgroup.tesc",
247 "glsl.450.subgroup.tese",
248 "glsl.450.subgroup.vert",
249 "glsl.450.subgroupArithmetic.comp",
250 "glsl.450.subgroupBasic.comp",
251 "glsl.450.subgroupBallot.comp",
252 "glsl.450.subgroupBallotNeg.comp",
253 "glsl.450.subgroupClustered.comp",
254 "glsl.450.subgroupClusteredNeg.comp",
255 "glsl.450.subgroupPartitioned.comp",
256 "glsl.450.subgroupRotate.comp",
257 "glsl.450.subgroupShuffle.comp",
258 "glsl.450.subgroupShuffleRelative.comp",
259 "glsl.450.subgroupQuad.comp",
260 "glsl.450.subgroupVote.comp",
261 "glsl.460.subgroup.mesh",
262 "glsl.460.subgroup.task",
263 "glsl.460.subgroup.rahit",
264 "glsl.460.subgroup.rcall",
265 "glsl.460.subgroup.rchit",
266 "glsl.460.subgroup.rgen",
267 "glsl.460.subgroup.rint",
268 "glsl.460.subgroup.rmiss",
269 "glsl.es300.layoutOffset.error.vert",
270 "glsl.es320.subgroup.frag",
271 "glsl.es320.subgroup.geom",
272 "glsl.es320.subgroup.tesc",
273 "glsl.es320.subgroup.tese",
274 "glsl.es320.subgroup.vert",
275 "glsl.es320.subgroupArithmetic.comp",
276 "glsl.es320.subgroupBasic.comp",
277 "glsl.es320.subgroupBallot.comp",
278 "glsl.es320.subgroupBallotNeg.comp",
279 "glsl.es320.subgroupClustered.comp",
280 "glsl.es320.subgroupClusteredNeg.comp",
281 "glsl.es320.subgroupPartitioned.comp",
282 "glsl.es320.subgroupRotate.comp",
283 "glsl.es320.subgroupShuffle.comp",
284 "glsl.es320.subgroupShuffleRelative.comp",
285 "glsl.es320.subgroupQuad.comp",
286 "glsl.es320.subgroupVote.comp",
287 "glsl.es320.extTextureShadowLod.frag",
288 "gl_samplemask_array_size.frag",
289 "glsl.ext.textureShadowLod.frag",
290 "terminate.frag",
291 "terminate.vert",
292 "negativeWorkGroupSize.comp",
293 "textureoffset_sampler2darrayshadow.vert",
294 "atomicAdd.comp",
295 "GL_ARB_gpu_shader5.u2i.vert",
296 "textureQueryLOD.frag",
297 "atomicCounterARBOps.vert",
298 "GL_EXT_shader_integer_mix.vert",
299 "GL_ARB_draw_instanced.vert",
300 "GL_ARB_fragment_coord_conventions.vert",
301 "GL_ARB_bindless_texture.frag",
302 "GL_ARB_texture_multisample.vert",
303 "BestMatchFunction.vert",
304 "EndStreamPrimitive.geom",
305 "floatBitsToInt.vert",
306 "coord_conventions.frag",
307 "gl_FragCoord.frag",
308 "glsl.interpOp.error.frag",
309 "GL_EXT_draw_instanced.vert",
310 "overflow_underflow_toinf_0.frag",
311 "GL_EXT_texture_array.frag",
312 })),
313 FileNameAsCustomTestSuffix
314 );
315
316 INSTANTIATE_TEST_SUITE_P(
317 Glsl, CompileToAstTestNV,
318 ::testing::ValuesIn(std::vector<std::string>({
319 "nvShaderNoperspectiveInterpolation.frag",
320 })),
321 FileNameAsCustomTestSuffix
322 );
323
324 // clang-format on
325
326 } // anonymous namespace
327 } // namespace glslangtest
328