Remap.FromFile.cpp 5.9 KB

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