2 // Copyright (C) 2016 Google, Inc.
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
10 // Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
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.
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.
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.
37 #include <gtest/gtest.h>
39 #include "TestFixture.h"
41 namespace glslangtest {
46 const char* entryPoint;
47 int baseSamplerBinding;
48 int baseTextureBinding;
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(), '-', '_');
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>>;
74 using CompileVulkanToSpirvTestAMD = GlslangTest<::testing::TestWithParam<std::string>>;
77 using CompileVulkanToSpirvTestNV = GlslangTest<::testing::TestWithParam<std::string>>;
79 using CompileUpgradeTextureToSampledTextureAndDropSamplersTest = GlslangTest<::testing::TestWithParam<std::string>>;
81 // Compiling GLSL to SPIR-V under Vulkan semantics. Expected to successfully
83 TEST_P(CompileVulkanToSpirvTest, FromFile)
85 loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
86 Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0,
90 TEST_P(CompileVulkan1_1ToSpirvTest, FromFile)
92 loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
93 Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_1,
97 // Compiling GLSL to SPIR-V under OpenGL semantics. Expected to successfully
99 TEST_P(CompileOpenGLToSpirvTest, FromFile)
101 loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
102 Source::GLSL, Semantics::OpenGL, glslang::EShTargetVulkan_1_0,
106 // GLSL-level Vulkan semantics test. Expected to error out before generating
108 TEST_P(VulkanSemantics, FromFile)
110 loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
111 Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0,
115 // GLSL-level Vulkan semantics test. Expected to error out before generating
117 TEST_P(OpenGLSemantics, FromFile)
119 loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
120 Source::GLSL, Semantics::OpenGL, glslang::EShTargetVulkan_1_0,
124 // GLSL-level Vulkan semantics test that need to see the AST for validation.
125 TEST_P(VulkanAstSemantics, FromFile)
127 loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
128 Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0,
132 // HLSL-level Vulkan semantics tests.
133 TEST_P(HlslIoMap, FromFile)
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);
147 // GLSL-level Vulkan semantics tests.
148 TEST_P(GlslIoMap, FromFile)
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);
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)
167 loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
168 Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0,
174 // Compiling GLSL to SPIR-V under Vulkan semantics (NV extensions enabled).
175 // Expected to successfully generate SPIR-V.
176 TEST_P(CompileVulkanToSpirvTestNV, FromFile)
178 loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
179 Source::GLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0,
184 TEST_P(CompileUpgradeTextureToSampledTextureAndDropSamplersTest, FromFile)
186 loadCompileUpgradeTextureToSampledTextureAndDropSamplersAndCheck(GlobalTestSettings.testRoot,
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.
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
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",
229 "spv.310.bitcast.frag",
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.accessChain.frag",
246 "spv.always-discard.frag",
247 "spv.always-discard2.frag",
248 "spv.arbPostDepthCoverage.frag",
249 "spv.arbPostDepthCoverage_Error.frag",
252 "spv.boolInBlock.frag",
253 "spv.branch-return.vert",
254 "spv.builtInXFB.vert",
255 "spv.conditionalDiscard.frag",
256 "spv.constStruct.vert",
257 "spv.controlFlowAttributes.frag",
258 "spv.conversion.frag",
260 "spv.dataOutIndirect.frag",
261 "spv.dataOutIndirect.vert",
262 "spv.deepRvalue.frag",
264 "spv.discard-dce.frag",
265 "spv.doWhileLoop.frag",
266 "spv.earlyReturnDiscard.frag",
267 "spv.extPostDepthCoverage.frag",
268 "spv.extPostDepthCoverage_Error.frag",
269 "spv.flowControl.frag",
271 "spv.forwardFun.frag",
272 "spv.fullyCovered.frag",
273 "spv.functionCall.frag",
274 "spv.functionNestedOpaque.vert",
275 "spv.functionSemantics.frag",
276 "spv.GeometryShaderPassthrough.geom",
277 "spv.interpOps.frag",
280 "spv.layoutNested.vert",
282 "spv.localAggregates.frag",
284 "spv.loopsArtificial.frag",
288 "spv.memoryQualifier.frag",
289 "spv.merge-unreachable.frag",
290 "spv.multiStruct.comp",
291 "spv.multiStructFuncall.frag",
292 "spv.newTexture.frag",
293 "spv.noDeadDecorations.vert",
294 "spv.nonSquare.vert",
295 "spv.nonuniform.frag",
296 "spv.noWorkgroup.comp",
298 "spv.Operations.frag",
299 "spv.paramMemory.frag",
300 "spv.precision.frag",
301 "spv.precisionNonESSamp.frag",
303 "spv.qualifiers.vert",
306 "spv.samplePosition.frag",
307 "spv.sampleMaskOverrideCoverage.frag",
308 "spv.shaderBallot.comp",
309 "spv.shaderDrawParams.vert",
310 "spv.shaderGroupVote.comp",
311 "spv.shaderStencilExport.frag",
313 "spv.simpleFunctionCall.frag",
314 "spv.simpleMat.vert",
315 "spv.sparseTexture.frag",
316 "spv.sparseTextureClamp.frag",
317 "spv.structAssignment.frag",
318 "spv.structDeref.frag",
319 "spv.structure.frag",
322 "spv.swizzleInversion.frag",
327 "spv.textureBuffer.vert",
331 "spv.uniformArray.frag",
332 "spv.variableArrayIndex.frag",
333 "spv.varyingArray.frag",
334 "spv.varyingArrayIndirect.frag",
335 "spv.vecMatConstruct.frag",
336 "spv.voidFunction.frag",
337 "spv.whileLoop.frag",
341 "spv.shortCircuit.frag",
342 "spv.pushConstant.vert",
343 "spv.pushConstantAnon.vert",
345 "spv.specConstant.vert",
346 "spv.specConstant.comp",
347 "spv.specConstantComposite.vert",
348 "spv.specConstantOperations.vert",
349 "spv.storageBuffer.vert",
352 "spv.vulkan100.subgroupArithmetic.comp",
353 "spv.vulkan100.subgroupPartitioned.comp",
357 "spv.samplerlessTextureFunctions.frag",
359 FileNameAsCustomTestSuffix
363 INSTANTIATE_TEST_CASE_P(
364 Glsl, CompileVulkan1_1ToSpirvTest,
365 ::testing::ValuesIn(std::vector<std::string>({
366 "spv.deviceGroup.frag",
367 "spv.drawParams.vert",
369 "spv.vulkan110.int16.frag",
371 "spv.explicittypes.frag",
374 "spv.multiView.frag",
380 "spv.subgroupArithmetic.comp",
381 "spv.subgroupBasic.comp",
382 "spv.subgroupBallot.comp",
383 "spv.subgroupClustered.comp",
384 "spv.subgroupClusteredNeg.comp",
385 "spv.subgroupPartitioned.comp",
386 "spv.subgroupShuffle.comp",
387 "spv.subgroupShuffleRelative.comp",
388 "spv.subgroupQuad.comp",
389 "spv.subgroupVote.comp",
390 "spv.vulkan110.storageBuffer.vert",
392 FileNameAsCustomTestSuffix
396 INSTANTIATE_TEST_CASE_P(
398 ::testing::ValuesIn(std::vector<IoMapData>{
399 { "spv.register.autoassign.frag", "main_ep", 5, 10, 0, 20, 30, true, false },
400 { "spv.register.noautoassign.frag", "main_ep", 5, 10, 0, 15, 30, false, false },
401 { "spv.register.autoassign-2.frag", "main", 5, 10, 0, 15, 30, true, true },
402 { "spv.register.subpass.frag", "main", 0, 20, 0, 0, 0, true, true },
403 { "spv.buffer.autoassign.frag", "main", 5, 10, 0, 15, 30, true, true },
404 { "spv.ssbo.autoassign.frag", "main", 5, 10, 0, 15, 30, true, true },
405 { "spv.ssboAlias.frag", "main", 0, 0, 0, 0, 83, true, false },
406 { "spv.rw.autoassign.frag", "main", 5, 10, 20, 15, 30, true, true },
407 { "spv.register.autoassign.rangetest.frag", "main",
408 glslang::TQualifier::layoutBindingEnd-2,
409 glslang::TQualifier::layoutBindingEnd+5,
410 20, 30, true, false },
412 FileNameAsCustomTestSuffixIoMap
416 INSTANTIATE_TEST_CASE_P(
418 ::testing::ValuesIn(std::vector<IoMapData>{
419 { "spv.glsl.register.autoassign.frag", "main", 5, 10, 0, 20, 30, true, false },
420 { "spv.glsl.register.noautoassign.frag", "main", 5, 10, 0, 15, 30, false, false },
422 FileNameAsCustomTestSuffixIoMap
426 INSTANTIATE_TEST_CASE_P(
427 Glsl, CompileOpenGLToSpirvTest,
428 ::testing::ValuesIn(std::vector<std::string>({
433 "spv.glFragColor.frag",
434 "spv.rankShift.comp",
435 "spv.specConst.vert",
436 "spv.OVR_multiview.vert",
438 FileNameAsCustomTestSuffix
441 INSTANTIATE_TEST_CASE_P(
442 Glsl, VulkanSemantics,
443 ::testing::ValuesIn(std::vector<std::string>({
447 "samplerlessTextureFunctions.frag",
449 FileNameAsCustomTestSuffix
452 INSTANTIATE_TEST_CASE_P(
453 Glsl, OpenGLSemantics,
454 ::testing::ValuesIn(std::vector<std::string>({
455 "glspv.esversion.vert",
456 "glspv.version.frag",
457 "glspv.version.vert",
461 FileNameAsCustomTestSuffix
464 INSTANTIATE_TEST_CASE_P(
465 Glsl, VulkanAstSemantics,
466 ::testing::ValuesIn(std::vector<std::string>({
469 FileNameAsCustomTestSuffix
472 #ifdef AMD_EXTENSIONS
473 INSTANTIATE_TEST_CASE_P(
474 Glsl, CompileVulkanToSpirvTestAMD,
475 ::testing::ValuesIn(std::vector<std::string>({
477 "spv.float16Fetch.frag",
478 "spv.imageLoadStoreLod.frag",
480 "spv.int16.amd.frag",
481 "spv.shaderBallotAMD.comp",
482 "spv.shaderFragMaskAMD.frag",
483 "spv.textureGatherBiasLod.frag",
485 FileNameAsCustomTestSuffix
490 INSTANTIATE_TEST_CASE_P(
491 Glsl, CompileVulkanToSpirvTestNV,
492 ::testing::ValuesIn(std::vector<std::string>({
493 "spv.sampleMaskOverrideCoverage.frag",
494 "spv.GeometryShaderPassthrough.geom",
495 "spv.viewportArray2.vert",
496 "spv.viewportArray2.tesc",
497 "spv.stereoViewRendering.vert",
498 "spv.stereoViewRendering.tesc",
499 "spv.multiviewPerViewAttributes.vert",
500 "spv.multiviewPerViewAttributes.tesc",
501 "spv.atomicInt64.comp",
503 FileNameAsCustomTestSuffix
507 INSTANTIATE_TEST_CASE_P(
508 Glsl, CompileUpgradeTextureToSampledTextureAndDropSamplersTest,
509 ::testing::ValuesIn(std::vector<std::string>({
510 "spv.texture.sampler.transform.frag",
512 FileNameAsCustomTestSuffix
516 } // anonymous namespace
517 } // namespace glslangtest