| 1 |
// |
| 2 |
// Copyright (C) 2016 LunarG, 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 <gtest/gtest.h> |
| 36 |
|
| 37 |
#include "TestFixture.h" |
| 38 |
|
| 39 |
namespace glslangtest { |
| 40 |
namespace { |
| 41 |
|
| 42 |
struct RemapTestArgs { |
| 43 |
const char* fileName; |
| 44 |
const char* entryPoint; |
| 45 |
Source sourceLanguage; |
| 46 |
unsigned int remapOpts; |
| 47 |
}; |
| 48 |
|
| 49 |
// We are using FileNameEntryPointPair objects as parameters for instantiating |
| 50 |
// the template, so the global FileNameAsCustomTestSuffix() won't work since |
| 51 |
// it assumes std::string as parameters. Thus, an overriding one here. |
| 52 |
std::string FileNameAsCustomTestSuffix( |
| 53 |
const ::testing::TestParamInfo<RemapTestArgs>& info) { |
| 54 |
std::string name = info.param.fileName; |
| 55 |
// A valid test case suffix cannot have '.' and '-' inside. |
| 56 |
std::replace(name.begin(), name.end(), '.', '_'); |
| 57 |
std::replace(name.begin(), name.end(), '-', '_'); |
| 58 |
return name; |
| 59 |
} |
| 60 |
|
| 61 |
using RemapTest = GlslangTest<::testing::TestWithParam<RemapTestArgs>>; |
| 62 |
|
| 63 |
// Remapping SPIR-V modules. |
| 64 |
TEST_P(RemapTest, FromFile) |
| 65 |
{ |
| 66 |
if (GetSuffix(GetParam().fileName) == "spv") { |
| 67 |
loadFileRemapAndCheck(GlobalTestSettings.testRoot, GetParam().fileName, |
| 68 |
GetParam().sourceLanguage, |
| 69 |
Semantics::Vulkan, |
| 70 |
Target::Spv, |
| 71 |
GetParam().remapOpts); |
| 72 |
} else { |
| 73 |
loadFileCompileRemapAndCheck(GlobalTestSettings.testRoot, GetParam().fileName, |
| 74 |
GetParam().sourceLanguage, |
| 75 |
Semantics::Vulkan, |
| 76 |
Target::Spv, |
| 77 |
GetParam().entryPoint, |
| 78 |
GetParam().remapOpts); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
// clang-format off |
| 83 |
INSTANTIATE_TEST_SUITE_P( |
| 84 |
ToSpirv, RemapTest, |
| 85 |
::testing::ValuesIn(std::vector<RemapTestArgs>{ |
| 86 |
// GLSL remapper tests |
| 87 |
// testname entry language remapper_options |
| 88 |
{ "remap.basic.none.frag", "main", Source::GLSL, spv::spirvbin_t::NONE }, |
| 89 |
{ "remap.basic.everything.frag", "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING }, |
| 90 |
{ "remap.basic.dcefunc.frag", "main", Source::GLSL, spv::spirvbin_t::DCE_FUNCS }, |
| 91 |
{ "remap.basic.strip.frag", "main", Source::GLSL, spv::spirvbin_t::STRIP }, |
| 92 |
{ "remap.specconst.comp", "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING }, |
| 93 |
{ "remap.switch.none.frag", "main", Source::GLSL, spv::spirvbin_t::NONE }, |
| 94 |
{ "remap.switch.everything.frag", "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING }, |
| 95 |
{ "remap.literal64.none.spv", "main", Source::GLSL, spv::spirvbin_t::NONE }, |
| 96 |
{ "remap.literal64.everything.spv", "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING }, |
| 97 |
{ "remap.if.none.frag", "main", Source::GLSL, spv::spirvbin_t::NONE }, |
| 98 |
{ "remap.if.everything.frag", "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING }, |
| 99 |
{ "remap.similar_1a.none.frag", "main", Source::GLSL, spv::spirvbin_t::NONE }, |
| 100 |
{ "remap.similar_1b.none.frag", "main", Source::GLSL, spv::spirvbin_t::NONE }, |
| 101 |
{ "remap.similar_1a.everything.frag", "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING }, |
| 102 |
{ "remap.similar_1b.everything.frag", "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING }, |
| 103 |
{ "remap.uniformarray.none.frag", "main", Source::GLSL, spv::spirvbin_t::NONE }, |
| 104 |
{ "remap.uniformarray.everything.frag", "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING }, |
| 105 |
|
| 106 |
// HLSL remapper tests |
| 107 |
{ "remap.hlsl.sample.basic.strip.frag", "main", Source::HLSL, spv::spirvbin_t::STRIP }, |
| 108 |
{ "remap.hlsl.sample.basic.everything.frag", "main", Source::HLSL, spv::spirvbin_t::DO_EVERYTHING }, |
| 109 |
{ "remap.hlsl.sample.basic.none.frag", "main", Source::HLSL, spv::spirvbin_t::NONE }, |
| 110 |
{ "remap.hlsl.templatetypes.none.frag", "main", Source::HLSL, spv::spirvbin_t::NONE }, |
| 111 |
{ "remap.hlsl.templatetypes.everything.frag", "main", Source::HLSL, spv::spirvbin_t::DO_EVERYTHING }, |
| 112 |
}), |
| 113 |
FileNameAsCustomTestSuffix |
| 114 |
); |
| 115 |
// clang-format on |
| 116 |
|
| 117 |
} // anonymous namespace |
| 118 |
} // namespace glslangtest |