Merge pull request #1547 from Igalia/apinheiro/xfb-struct-assignment
[platform/upstream/glslang.git] / gtests / Spv.FromFile.cpp
1  //
2 // Copyright (C) 2016 Google, Inc.
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 //    Redistributions of source code must retain the above copyright
11 //    notice, this list of conditions and the following disclaimer.
12 //
13 //    Redistributions in binary form must reproduce the above
14 //    copyright notice, this list of conditions and the following
15 //    disclaimer in the documentation and/or other materials provided
16 //    with the distribution.
17 //
18 //    Neither the name of Google Inc. nor the names of its
19 //    contributors may be used to endorse or promote products derived
20 //    from this software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 // POSSIBILITY OF SUCH DAMAGE.
34
35 #include <algorithm>
36
37 #include <gtest/gtest.h>
38
39 #include "TestFixture.h"
40
41 namespace glslangtest {
42 namespace {
43
44 struct IoMapData {
45     const char* fileName;
46     const char* entryPoint;
47     int baseSamplerBinding;
48     int baseTextureBinding;
49     int baseImageBinding;
50     int baseUboBinding;
51     int baseSsboBinding;
52     bool autoMapBindings;
53     bool flattenUniforms;
54 };
55
56 std::string FileNameAsCustomTestSuffixIoMap(
57     const ::testing::TestParamInfo<IoMapData>& info) {
58     std::string name = info.param.fileName;
59     // A valid test case suffix cannot have '.' and '-' inside.
60     std::replace(name.begin(), name.end(), '.', '_');
61     std::replace(name.begin(), name.end(), '-', '_');
62     return name;
63 }
64
65 using CompileVulkanToSpirvTest = GlslangTest<::testing::TestWithParam<std::string>>;
66 using CompileVulkan1_1ToSpirvTest = GlslangTest<::testing::TestWithParam<std::string>>;
67 using CompileOpenGLToSpirvTest = GlslangTest<::testing::TestWithParam<std::string>>;
68 using VulkanSemantics = GlslangTest<::testing::TestWithParam<std::string>>;
69 using OpenGLSemantics = GlslangTest<::testing::TestWithParam<std::string>>;
70 using VulkanAstSemantics = GlslangTest<::testing::TestWithParam<std::string>>;
71 using HlslIoMap = GlslangTest<::testing::TestWithParam<IoMapData>>;
72 using GlslIoMap = GlslangTest<::testing::TestWithParam<IoMapData>>;
73 #ifdef AMD_EXTENSIONS
74 using CompileVulkanToSpirvTestAMD = GlslangTest<::testing::TestWithParam<std::string>>;
75 #endif
76 #ifdef NV_EXTENSIONS
77 using CompileVulkanToSpirvTestNV = GlslangTest<::testing::TestWithParam<std::string>>;
78 #endif
79 using CompileUpgradeTextureToSampledTextureAndDropSamplersTest = GlslangTest<::testing::TestWithParam<std::string>>;
80
81 // Compiling GLSL to SPIR-V under Vulkan semantics. Expected to successfully
82 // generate SPIR-V.
83 TEST_P(CompileVulkanToSpirvTest, FromFile)
84 {
85     loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
86                             Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0,
87                             Target::Spv);
88 }
89
90 TEST_P(CompileVulkan1_1ToSpirvTest, FromFile)
91 {
92     loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
93                             Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_1,
94                             Target::Spv);
95 }
96
97 // Compiling GLSL to SPIR-V under OpenGL semantics. Expected to successfully
98 // generate SPIR-V.
99 TEST_P(CompileOpenGLToSpirvTest, FromFile)
100 {
101     loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
102                             Source::GLSL, Semantics::OpenGL, glslang::EShTargetVulkan_1_0,
103                             Target::Spv);
104 }
105
106 // GLSL-level Vulkan semantics test. Expected to error out before generating
107 // SPIR-V.
108 TEST_P(VulkanSemantics, FromFile)
109 {
110     loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
111                             Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0,
112                             Target::Spv, false);
113 }
114
115 // GLSL-level Vulkan semantics test. Expected to error out before generating
116 // SPIR-V.
117 TEST_P(OpenGLSemantics, FromFile)
118 {
119     loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
120                             Source::GLSL, Semantics::OpenGL, glslang::EShTargetVulkan_1_0,
121                             Target::Spv, false);
122 }
123
124 // GLSL-level Vulkan semantics test that need to see the AST for validation.
125 TEST_P(VulkanAstSemantics, FromFile)
126 {
127     loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
128                             Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0,
129                             Target::AST);
130 }
131
132 // HLSL-level Vulkan semantics tests.
133 TEST_P(HlslIoMap, FromFile)
134 {
135     loadFileCompileIoMapAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
136                                  Source::HLSL, Semantics::Vulkan,
137                                  Target::Spv, GetParam().entryPoint,
138                                  GetParam().baseSamplerBinding,
139                                  GetParam().baseTextureBinding,
140                                  GetParam().baseImageBinding,
141                                  GetParam().baseUboBinding,
142                                  GetParam().baseSsboBinding,
143                                  GetParam().autoMapBindings,
144                                  GetParam().flattenUniforms);
145 }
146
147 // GLSL-level Vulkan semantics tests.
148 TEST_P(GlslIoMap, FromFile)
149 {
150     loadFileCompileIoMapAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
151                                  Source::GLSL, Semantics::Vulkan,
152                                  Target::Spv, GetParam().entryPoint,
153                                  GetParam().baseSamplerBinding,
154                                  GetParam().baseTextureBinding,
155                                  GetParam().baseImageBinding,
156                                  GetParam().baseUboBinding,
157                                  GetParam().baseSsboBinding,
158                                  GetParam().autoMapBindings,
159                                  GetParam().flattenUniforms);
160 }
161
162 #ifdef AMD_EXTENSIONS
163 // Compiling GLSL to SPIR-V under Vulkan semantics (AMD extensions enabled).
164 // Expected to successfully generate SPIR-V.
165 TEST_P(CompileVulkanToSpirvTestAMD, FromFile)
166 {
167     loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
168                             Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0,
169                             Target::Spv);
170 }
171 #endif
172
173 #ifdef NV_EXTENSIONS
174 // Compiling GLSL to SPIR-V under Vulkan semantics (NV extensions enabled).
175 // Expected to successfully generate SPIR-V.
176 TEST_P(CompileVulkanToSpirvTestNV, FromFile)
177 {
178     loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
179                             Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0,
180                             Target::Spv);
181 }
182 #endif
183
184 TEST_P(CompileUpgradeTextureToSampledTextureAndDropSamplersTest, FromFile)
185 {
186     loadCompileUpgradeTextureToSampledTextureAndDropSamplersAndCheck(GlobalTestSettings.testRoot,
187                                                                      GetParam(),
188                                                                      Source::GLSL,
189                                                                      Semantics::Vulkan,
190                                                                      Target::Spv);
191 }
192
193 // clang-format off
194 INSTANTIATE_TEST_CASE_P(
195     Glsl, CompileVulkanToSpirvTest,
196     ::testing::ValuesIn(std::vector<std::string>({
197         // Test looping constructs.
198         // No tests yet for making sure break and continue from a nested loop
199         // goes to the innermost target.
200         "spv.barrier.vert",
201         "spv.do-simple.vert",
202         "spv.do-while-continue-break.vert",
203         "spv.for-complex-condition.vert",
204         "spv.for-continue-break.vert",
205         "spv.for-simple.vert",
206         "spv.for-notest.vert",
207         "spv.for-nobody.vert",
208         "spv.while-continue-break.vert",
209         "spv.while-simple.vert",
210         // vulkan-specific tests
211         "spv.set.vert",
212         "spv.double.comp",
213         "spv.100ops.frag",
214         "spv.130.frag",
215         "spv.140.frag",
216         "spv.150.geom",
217         "spv.150.vert",
218         "spv.16bitstorage.frag",
219         "spv.16bitstorage_Error.frag",
220         "spv.16bitstorage-int.frag",
221         "spv.16bitstorage_Error-int.frag",
222         "spv.16bitstorage-uint.frag",
223         "spv.16bitstorage_Error-uint.frag",
224         "spv.300BuiltIns.vert",
225         "spv.300layout.frag",
226         "spv.300layout.vert",
227         "spv.300layoutp.vert",
228         "spv.310.comp",
229         "spv.310.bitcast.frag",
230         "spv.330.geom",
231         "spv.400.frag",
232         "spv.400.tesc",
233         "spv.400.tese",
234         "spv.420.geom",
235         "spv.430.frag",
236         "spv.430.vert",
237         "spv.450.tesc",
238         "spv.450.geom",
239         "spv.450.noRedecl.tesc",
240         "spv.8bitstorage-int.frag",
241         "spv.8bitstorage_Error-int.frag",
242         "spv.8bitstorage-uint.frag",
243         "spv.8bitstorage_Error-uint.frag",
244         "spv.8bitstorage-ubo.vert",
245         "spv.8bitstorage-ssbo.vert",
246         "spv.accessChain.frag",
247         "spv.aggOps.frag",
248         "spv.always-discard.frag",
249         "spv.always-discard2.frag",
250         "spv.arbPostDepthCoverage.frag",
251         "spv.arbPostDepthCoverage_Error.frag",
252         "spv.bitCast.frag",
253         "spv.bool.vert",
254         "spv.boolInBlock.frag",
255         "spv.branch-return.vert",
256         "spv.builtInXFB.vert",
257         "spv.conditionalDiscard.frag",
258         "spv.constStruct.vert",
259         "spv.controlFlowAttributes.frag",
260         "spv.conversion.frag",
261         "spv.dataOut.frag",
262         "spv.dataOutIndirect.frag",
263         "spv.dataOutIndirect.vert",
264         "spv.deepRvalue.frag",
265         "spv.depthOut.frag",
266         "spv.discard-dce.frag",
267         "spv.doWhileLoop.frag",
268         "spv.earlyReturnDiscard.frag",
269         "spv.extPostDepthCoverage.frag",
270         "spv.extPostDepthCoverage_Error.frag",
271         "spv.flowControl.frag",
272         "spv.forLoop.frag",
273         "spv.forwardFun.frag",
274         "spv.fullyCovered.frag",
275         "spv.functionCall.frag",
276         "spv.functionNestedOpaque.vert",
277         "spv.functionSemantics.frag",
278         "spv.GeometryShaderPassthrough.geom",
279         "spv.interpOps.frag",
280         "spv.int64.frag",
281         "spv.intOps.vert",
282         "spv.layoutNested.vert",
283         "spv.length.frag",
284         "spv.localAggregates.frag",
285         "spv.loops.frag",
286         "spv.loopsArtificial.frag",
287         "spv.matFun.vert",
288         "spv.matrix.frag",
289         "spv.matrix2.frag",
290         "spv.memoryQualifier.frag",
291         "spv.memoryScopeSemantics.comp",
292         "spv.memoryScopeSemantics_Error.comp",
293         "spv.merge-unreachable.frag",
294         "spv.multiStruct.comp",
295         "spv.multiStructFuncall.frag",
296         "spv.newTexture.frag",
297         "spv.noDeadDecorations.vert",
298         "spv.nonSquare.vert",
299         "spv.nonuniform.frag",
300         "spv.noWorkgroup.comp",
301         "spv.offsets.frag",
302         "spv.Operations.frag",
303         "spv.paramMemory.frag",
304         "spv.precision.frag",
305         "spv.precisionNonESSamp.frag",
306         "spv.prepost.frag",
307         "spv.qualifiers.vert",
308         "spv.sample.frag",
309         "spv.sampleId.frag",
310         "spv.samplePosition.frag",
311         "spv.sampleMaskOverrideCoverage.frag",
312         "spv.shaderBallot.comp",
313         "spv.shaderDrawParams.vert",
314         "spv.shaderGroupVote.comp",
315         "spv.shaderStencilExport.frag",
316         "spv.shiftOps.frag",
317         "spv.simpleFunctionCall.frag",
318         "spv.simpleMat.vert",
319         "spv.sparseTexture.frag",
320         "spv.sparseTextureClamp.frag",
321         "spv.structAssignment.frag",
322         "spv.structDeref.frag",
323         "spv.structure.frag",
324         "spv.switch.frag",
325         "spv.swizzle.frag",
326         "spv.swizzleInversion.frag",
327         "spv.test.frag",
328         "spv.test.vert",
329         "spv.texture.frag",
330         "spv.texture.vert",
331         "spv.textureBuffer.vert",
332         "spv.image.frag",
333         "spv.types.frag",
334         "spv.uint.frag",
335         "spv.uniformArray.frag",
336         "spv.variableArrayIndex.frag",
337         "spv.varyingArray.frag",
338         "spv.varyingArrayIndirect.frag",
339         "spv.vecMatConstruct.frag",
340         "spv.voidFunction.frag",
341         "spv.whileLoop.frag",
342         "spv.AofA.frag",
343         "spv.queryL.frag",
344         "spv.separate.frag",
345         "spv.shortCircuit.frag",
346         "spv.pushConstant.vert",
347         "spv.pushConstantAnon.vert",
348         "spv.subpass.frag",
349         "spv.specConstant.vert",
350         "spv.specConstant.comp",
351         "spv.specConstantComposite.vert",
352         "spv.specConstantOperations.vert",
353         "spv.storageBuffer.vert",
354         "spv.precise.tese",
355         "spv.precise.tesc",
356         "spv.vulkan100.subgroupArithmetic.comp",
357         "spv.vulkan100.subgroupPartitioned.comp",
358         "spv.xfb.vert",
359         "spv.xfb2.vert",
360         "spv.xfb3.vert",
361         "spv.samplerlessTextureFunctions.frag",
362     })),
363     FileNameAsCustomTestSuffix
364 );
365
366 // clang-format off
367 INSTANTIATE_TEST_CASE_P(
368     Glsl, CompileVulkan1_1ToSpirvTest,
369     ::testing::ValuesIn(std::vector<std::string>({
370         "spv.1.3.8bitstorage-ubo.vert",
371         "spv.1.3.8bitstorage-ssbo.vert",
372         "spv.deviceGroup.frag",
373         "spv.drawParams.vert",
374         "spv.int8.frag",
375         "spv.vulkan110.int16.frag",
376         "spv.int32.frag",
377         "spv.explicittypes.frag",
378         "spv.float32.frag",
379         "spv.float64.frag",
380         "spv.multiView.frag",
381         "spv.subgroup.frag",
382         "spv.subgroup.geom",
383         "spv.subgroup.tesc",
384         "spv.subgroup.tese",
385         "spv.subgroup.vert",
386         "spv.subgroupArithmetic.comp",
387         "spv.subgroupBasic.comp",
388         "spv.subgroupBallot.comp",
389         "spv.subgroupClustered.comp",
390         "spv.subgroupClusteredNeg.comp",
391         "spv.subgroupPartitioned.comp",
392         "spv.subgroupShuffle.comp",
393         "spv.subgroupShuffleRelative.comp",
394         "spv.subgroupQuad.comp",
395         "spv.subgroupVote.comp",
396         "spv.vulkan110.storageBuffer.vert",
397     })),
398     FileNameAsCustomTestSuffix
399 );
400
401 // clang-format off
402 INSTANTIATE_TEST_CASE_P(
403     Hlsl, HlslIoMap,
404     ::testing::ValuesIn(std::vector<IoMapData>{
405         { "spv.register.autoassign.frag", "main_ep", 5, 10, 0, 20, 30, true, false },
406         { "spv.register.noautoassign.frag", "main_ep", 5, 10, 0, 15, 30, false, false },
407         { "spv.register.autoassign-2.frag", "main", 5, 10, 0, 15, 30, true, true },
408         { "spv.register.subpass.frag", "main", 0, 20, 0, 0, 0, true, true },
409         { "spv.buffer.autoassign.frag", "main", 5, 10, 0, 15, 30, true, true },
410         { "spv.ssbo.autoassign.frag", "main", 5, 10, 0, 15, 30, true, true },
411         { "spv.ssboAlias.frag", "main", 0, 0, 0, 0, 83, true, false },
412         { "spv.rw.autoassign.frag", "main", 5, 10, 20, 15, 30, true, true },
413         { "spv.register.autoassign.rangetest.frag", "main",
414                 glslang::TQualifier::layoutBindingEnd-2,
415                 glslang::TQualifier::layoutBindingEnd+5,
416                 20, 30, true, false },
417     }),
418     FileNameAsCustomTestSuffixIoMap
419 );
420
421 // clang-format off
422 INSTANTIATE_TEST_CASE_P(
423     Hlsl, GlslIoMap,
424     ::testing::ValuesIn(std::vector<IoMapData>{
425         { "spv.glsl.register.autoassign.frag", "main", 5, 10, 0, 20, 30, true, false },
426         { "spv.glsl.register.noautoassign.frag", "main", 5, 10, 0, 15, 30, false, false },
427     }),
428     FileNameAsCustomTestSuffixIoMap
429 );
430
431 // clang-format off
432 INSTANTIATE_TEST_CASE_P(
433     Glsl, CompileOpenGLToSpirvTest,
434     ::testing::ValuesIn(std::vector<std::string>({
435         "spv.460.frag",
436         "spv.460.vert",
437         "spv.460.comp",
438         "spv.atomic.comp",
439         "spv.glFragColor.frag",
440         "spv.rankShift.comp",
441         "spv.specConst.vert",
442         "spv.OVR_multiview.vert",
443         "spv.xfbOffsetOnStructMembersAssignment.vert",
444     })),
445     FileNameAsCustomTestSuffix
446 );
447
448 INSTANTIATE_TEST_CASE_P(
449     Glsl, VulkanSemantics,
450     ::testing::ValuesIn(std::vector<std::string>({
451         "vulkan.frag",
452         "vulkan.vert",
453         "vulkan.comp",
454         "samplerlessTextureFunctions.frag",
455     })),
456     FileNameAsCustomTestSuffix
457 );
458
459 INSTANTIATE_TEST_CASE_P(
460     Glsl, OpenGLSemantics,
461     ::testing::ValuesIn(std::vector<std::string>({
462         "glspv.esversion.vert",
463         "glspv.version.frag",
464         "glspv.version.vert",
465         "glspv.frag",
466         "glspv.vert",
467     })),
468     FileNameAsCustomTestSuffix
469 );
470
471 INSTANTIATE_TEST_CASE_P(
472     Glsl, VulkanAstSemantics,
473     ::testing::ValuesIn(std::vector<std::string>({
474         "vulkan.ast.vert",
475     })),
476     FileNameAsCustomTestSuffix
477 );
478
479 #ifdef AMD_EXTENSIONS
480 INSTANTIATE_TEST_CASE_P(
481     Glsl, CompileVulkanToSpirvTestAMD,
482     ::testing::ValuesIn(std::vector<std::string>({
483         "spv.float16.frag",
484         "spv.float16Fetch.frag",
485         "spv.imageLoadStoreLod.frag",
486         "spv.int16.frag",
487         "spv.int16.amd.frag",
488         "spv.shaderBallotAMD.comp",
489         "spv.shaderFragMaskAMD.frag",
490         "spv.textureGatherBiasLod.frag",
491     })),
492     FileNameAsCustomTestSuffix
493 );
494 #endif
495
496 #ifdef NV_EXTENSIONS
497 INSTANTIATE_TEST_CASE_P(
498     Glsl, CompileVulkanToSpirvTestNV,
499     ::testing::ValuesIn(std::vector<std::string>({
500     "spv.sampleMaskOverrideCoverage.frag",
501     "spv.GeometryShaderPassthrough.geom",
502     "spv.viewportArray2.vert",
503     "spv.viewportArray2.tesc",
504     "spv.stereoViewRendering.vert",
505     "spv.stereoViewRendering.tesc",
506     "spv.multiviewPerViewAttributes.vert",
507     "spv.multiviewPerViewAttributes.tesc",
508     "spv.atomicInt64.comp",
509     "spv.shadingRate.frag",
510     "spv.RayGenShader.rgen",
511     "spv.RayGenShader_Errors.rgen",
512     "spv.RayConstants.rgen",
513     "spv.IntersectShader.rint",
514     "spv.IntersectShader_Errors.rint",
515     "spv.AnyHitShader.rahit",
516     "spv.AnyHitShader_Errors.rahit",
517     "spv.ClosestHitShader.rchit",
518     "spv.ClosestHitShader_Errors.rchit",
519     "spv.MissShader.rmiss",
520     "spv.MissShader_Errors.rmiss",
521     "spv.RayCallable.rcall",
522     "spv.RayCallable_Errors.rcall",
523     "spv.fragmentShaderBarycentric.frag",
524     "spv.fragmentShaderBarycentric2.frag",
525     "spv.computeShaderDerivatives.comp",
526     "spv.computeShaderDerivatives2.comp",
527     "spv.shaderImageFootprint.frag",
528     "spv.meshShaderBuiltins.mesh",
529     "spv.meshShaderUserDefined.mesh",
530     "spv.meshShaderPerViewBuiltins.mesh",
531     "spv.meshShaderPerViewUserDefined.mesh",
532     "spv.meshShaderSharedMem.mesh",
533     "spv.meshShaderTaskMem.mesh",
534     "spv.320.meshShaderUserDefined.mesh",
535     "spv.meshShaderRedeclBuiltins.mesh",
536     "spv.meshShaderRedeclPerViewBuiltins.mesh",
537     "spv.meshTaskShader.task",
538     "spv.perprimitiveNV.frag",
539 })),
540 FileNameAsCustomTestSuffix
541 );
542 #endif
543
544 INSTANTIATE_TEST_CASE_P(
545     Glsl, CompileUpgradeTextureToSampledTextureAndDropSamplersTest,
546     ::testing::ValuesIn(std::vector<std::string>({
547       "spv.texture.sampler.transform.frag",
548     })),
549     FileNameAsCustomTestSuffix
550 );
551 // clang-format on
552
553 }  // anonymous namespace
554 }  // namespace glslangtest