CodeGenSPIRVTest.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //===- unittests/SPIRV/CodeGenSPIRVTest.cpp ---- Run CodeGenSPIRV tests ---===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "FileTestFixture.h"
  10. #include "WholeFileTestFixture.h"
  11. namespace {
  12. using clang::spirv::FileTest;
  13. using clang::spirv::WholeFileTest;
  14. // === Whole output tests ===
  15. TEST_F(WholeFileTest, EmptyVoidMain) {
  16. runWholeFileTest("empty-void-main.hlsl2spv", /*generateHeader*/ true);
  17. }
  18. TEST_F(WholeFileTest, PassThruPixelShader) {
  19. runWholeFileTest("passthru-ps.hlsl2spv", /*generateHeader*/ true);
  20. }
  21. TEST_F(WholeFileTest, PassThruVertexShader) {
  22. runWholeFileTest("passthru-vs.hlsl2spv", /*generateHeader*/ true);
  23. }
  24. TEST_F(WholeFileTest, ConstantPixelShader) {
  25. runWholeFileTest("constant-ps.hlsl2spv", /*generateHeader*/ true);
  26. }
  27. // === Partial output tests ===
  28. // For types
  29. TEST_F(FileTest, ScalarTypes) { runFileTest("type.scalar.hlsl"); }
  30. TEST_F(FileTest, VectorTypes) { runFileTest("type.vector.hlsl"); }
  31. // For constants
  32. TEST_F(FileTest, ScalarConstants) { runFileTest("constant.scalar.hlsl"); }
  33. TEST_F(FileTest, VectorConstants) { runFileTest("constant.vector.hlsl"); }
  34. // For variables
  35. TEST_F(FileTest, VariableInitializer) { runFileTest("var.init.hlsl"); }
  36. // For prefix/postfix increment/decrement
  37. TEST_F(FileTest, UnaryOpPrefixIncrement) {
  38. runFileTest("unary-op.prefix-inc.hlsl");
  39. }
  40. TEST_F(FileTest, UnaryOpPrefixDecrement) {
  41. runFileTest("unary-op.prefix-dec.hlsl");
  42. }
  43. TEST_F(FileTest, UnaryOpPostfixIncrement) {
  44. runFileTest("unary-op.postfix-inc.hlsl");
  45. }
  46. TEST_F(FileTest, UnaryOpPostfixDecrement) {
  47. runFileTest("unary-op.postfix-dec.hlsl");
  48. }
  49. // For unary operators
  50. TEST_F(FileTest, UnaryOpPlus) { runFileTest("unary-op.plus.hlsl"); }
  51. TEST_F(FileTest, UnaryOpMinus) { runFileTest("unary-op.minus.hlsl"); }
  52. TEST_F(FileTest, UnaryOpLogicalNot) {
  53. runFileTest("unary-op.logical-not.hlsl");
  54. }
  55. // For assignments
  56. TEST_F(FileTest, BinaryOpAssign) { runFileTest("binary-op.assign.hlsl"); }
  57. // For arithmetic binary operators
  58. TEST_F(FileTest, BinaryOpScalarArithmetic) {
  59. runFileTest("binary-op.arithmetic.scalar.hlsl");
  60. }
  61. TEST_F(FileTest, BinaryOpVectorArithmetic) {
  62. runFileTest("binary-op.arithmetic.vector.hlsl");
  63. }
  64. TEST_F(FileTest, BinaryOpMixedArithmetic) {
  65. runFileTest("binary-op.arithmetic.mixed.hlsl");
  66. }
  67. // For arithmetic assignments
  68. TEST_F(FileTest, BinaryOpScalarArithAssign) {
  69. runFileTest("binary-op.arith-assign.scalar.hlsl");
  70. }
  71. TEST_F(FileTest, BinaryOpVectorArithAssign) {
  72. runFileTest("binary-op.arith-assign.vector.hlsl");
  73. }
  74. TEST_F(FileTest, BinaryOpMixedArithAssign) {
  75. runFileTest("binary-op.arith-assign.mixed.hlsl");
  76. }
  77. // For bitwise binary operators
  78. TEST_F(FileTest, BinaryOpScalarBitwise) {
  79. runFileTest("binary-op.bitwise.scalar.hlsl");
  80. }
  81. TEST_F(FileTest, BinaryOpVectorBitwise) {
  82. runFileTest("binary-op.bitwise.vector.hlsl");
  83. }
  84. // For bitwise assignments
  85. TEST_F(FileTest, BinaryOpScalarBitwiseAssign) {
  86. runFileTest("binary-op.bitwise-assign.scalar.hlsl");
  87. }
  88. TEST_F(FileTest, BinaryOpVectorBitwiseAssign) {
  89. runFileTest("binary-op.bitwise-assign.vector.hlsl");
  90. }
  91. // For comparison operators
  92. TEST_F(FileTest, BinaryOpScalarComparison) {
  93. runFileTest("binary-op.comparison.scalar.hlsl");
  94. }
  95. TEST_F(FileTest, BinaryOpVectorComparison) {
  96. runFileTest("binary-op.comparison.vector.hlsl");
  97. }
  98. // For logical binary operators
  99. TEST_F(FileTest, BinaryOpLogicalAnd) {
  100. runFileTest("binary-op.logical-and.hlsl");
  101. }
  102. TEST_F(FileTest, BinaryOpLogicalOr) {
  103. runFileTest("binary-op.logical-or.hlsl");
  104. }
  105. // For ternary operators
  106. TEST_F(FileTest, TernaryOpConditionalOp) {
  107. runFileTest("ternary-op.cond-op.hlsl");
  108. }
  109. // For casting
  110. TEST_F(FileTest, CastNoOp) { runFileTest("cast.no-op.hlsl"); }
  111. TEST_F(FileTest, CastImplicit2Bool) { runFileTest("cast.2bool.implicit.hlsl"); }
  112. TEST_F(FileTest, CastExplicit2Bool) { runFileTest("cast.2bool.explicit.hlsl"); }
  113. TEST_F(FileTest, CastImplicit2SInt) { runFileTest("cast.2sint.implicit.hlsl"); }
  114. TEST_F(FileTest, CastExplicit2SInt) { runFileTest("cast.2sint.explicit.hlsl"); }
  115. TEST_F(FileTest, CastImplicit2UInt) { runFileTest("cast.2uint.implicit.hlsl"); }
  116. TEST_F(FileTest, CastExplicit2UInt) { runFileTest("cast.2uint.explicit.hlsl"); }
  117. TEST_F(FileTest, CastImplicit2FP) { runFileTest("cast.2fp.implicit.hlsl"); }
  118. TEST_F(FileTest, CastExplicit2FP) { runFileTest("cast.2fp.explicit.hlsl"); }
  119. // For vector splatting and trunction
  120. TEST_F(FileTest, CastTruncateVector) { runFileTest("cast.vector.trunc.hlsl"); }
  121. TEST_F(FileTest, CastSplatVector) { runFileTest("cast.vector.splat.hlsl"); }
  122. // For if statements
  123. TEST_F(FileTest, IfStmtPlainAssign) { runFileTest("if-stmt.plain.hlsl"); }
  124. TEST_F(FileTest, IfStmtNestedIfStmt) { runFileTest("if-stmt.nested.hlsl"); }
  125. // For for statements
  126. TEST_F(FileTest, ForStmtPlainAssign) { runFileTest("for-stmt.plain.hlsl"); }
  127. TEST_F(FileTest, ForStmtNestedForStmt) { runFileTest("for-stmt.nested.hlsl"); }
  128. // For control flows
  129. TEST_F(FileTest, ControlFlowNestedIfForStmt) { runFileTest("cf.if.for.hlsl"); }
  130. TEST_F(FileTest, ControlFlowLogicalAnd) { runFileTest("cf.logical-and.hlsl"); }
  131. TEST_F(FileTest, ControlFlowLogicalOr) { runFileTest("cf.logical-or.hlsl"); }
  132. TEST_F(FileTest, ControlFlowConditionalOp) { runFileTest("cf.cond-op.hlsl"); }
  133. // For function calls
  134. TEST_F(FileTest, FunctionCall) { runFileTest("fn.call.hlsl"); }
  135. TEST_F(FileTest, IntrinsicsDot) { runFileTest("intrinsics.dot.hlsl"); }
  136. } // namespace