CodeGenSPIRVTest.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. TEST_F(FileTest, MatrixTypes) { runFileTest("type.matrix.hlsl"); }
  32. // For constants
  33. TEST_F(FileTest, ScalarConstants) { runFileTest("constant.scalar.hlsl"); }
  34. TEST_F(FileTest, VectorConstants) { runFileTest("constant.vector.hlsl"); }
  35. // For variables
  36. TEST_F(FileTest, VariableInitializer) { runFileTest("var.init.hlsl"); }
  37. // For prefix/postfix increment/decrement
  38. TEST_F(FileTest, UnaryOpPrefixIncrement) {
  39. runFileTest("unary-op.prefix-inc.hlsl");
  40. }
  41. TEST_F(FileTest, UnaryOpPrefixDecrement) {
  42. runFileTest("unary-op.prefix-dec.hlsl");
  43. }
  44. TEST_F(FileTest, UnaryOpPostfixIncrement) {
  45. runFileTest("unary-op.postfix-inc.hlsl");
  46. }
  47. TEST_F(FileTest, UnaryOpPostfixDecrement) {
  48. runFileTest("unary-op.postfix-dec.hlsl");
  49. }
  50. // For unary operators
  51. TEST_F(FileTest, UnaryOpPlus) { runFileTest("unary-op.plus.hlsl"); }
  52. TEST_F(FileTest, UnaryOpMinus) { runFileTest("unary-op.minus.hlsl"); }
  53. TEST_F(FileTest, UnaryOpLogicalNot) {
  54. runFileTest("unary-op.logical-not.hlsl");
  55. }
  56. // For assignments
  57. TEST_F(FileTest, BinaryOpAssign) { runFileTest("binary-op.assign.hlsl"); }
  58. // For arithmetic binary operators
  59. TEST_F(FileTest, BinaryOpScalarArithmetic) {
  60. runFileTest("binary-op.arithmetic.scalar.hlsl");
  61. }
  62. TEST_F(FileTest, BinaryOpVectorArithmetic) {
  63. runFileTest("binary-op.arithmetic.vector.hlsl");
  64. }
  65. TEST_F(FileTest, BinaryOpMatrixArithmetic) {
  66. runFileTest("binary-op.arithmetic.matrix.hlsl");
  67. }
  68. TEST_F(FileTest, BinaryOpMixedArithmetic) {
  69. runFileTest("binary-op.arithmetic.mixed.hlsl");
  70. }
  71. // For arithmetic assignments
  72. TEST_F(FileTest, BinaryOpScalarArithAssign) {
  73. runFileTest("binary-op.arith-assign.scalar.hlsl");
  74. }
  75. TEST_F(FileTest, BinaryOpVectorArithAssign) {
  76. runFileTest("binary-op.arith-assign.vector.hlsl");
  77. }
  78. TEST_F(FileTest, BinaryOpMatrixArithAssign) {
  79. runFileTest("binary-op.arith-assign.matrix.hlsl");
  80. }
  81. TEST_F(FileTest, BinaryOpMixedArithAssign) {
  82. runFileTest("binary-op.arith-assign.mixed.hlsl");
  83. }
  84. // For bitwise binary operators
  85. TEST_F(FileTest, BinaryOpScalarBitwise) {
  86. runFileTest("binary-op.bitwise.scalar.hlsl");
  87. }
  88. TEST_F(FileTest, BinaryOpVectorBitwise) {
  89. runFileTest("binary-op.bitwise.vector.hlsl");
  90. }
  91. // For bitwise assignments
  92. TEST_F(FileTest, BinaryOpScalarBitwiseAssign) {
  93. runFileTest("binary-op.bitwise-assign.scalar.hlsl");
  94. }
  95. TEST_F(FileTest, BinaryOpVectorBitwiseAssign) {
  96. runFileTest("binary-op.bitwise-assign.vector.hlsl");
  97. }
  98. // For comparison operators
  99. TEST_F(FileTest, BinaryOpScalarComparison) {
  100. runFileTest("binary-op.comparison.scalar.hlsl");
  101. }
  102. TEST_F(FileTest, BinaryOpVectorComparison) {
  103. runFileTest("binary-op.comparison.vector.hlsl");
  104. }
  105. // For logical binary operators
  106. TEST_F(FileTest, BinaryOpLogicalAnd) {
  107. runFileTest("binary-op.logical-and.hlsl");
  108. }
  109. TEST_F(FileTest, BinaryOpLogicalOr) {
  110. runFileTest("binary-op.logical-or.hlsl");
  111. }
  112. // For ternary operators
  113. TEST_F(FileTest, TernaryOpConditionalOp) {
  114. runFileTest("ternary-op.cond-op.hlsl");
  115. }
  116. // For vector swizzle operators
  117. TEST_F(FileTest, OpVectorSwizzle) { runFileTest("op.vector.swizzle.hlsl"); }
  118. TEST_F(FileTest, OpVectorSize1Swizzle) {
  119. runFileTest("op.vector.swizzle.size1.hlsl");
  120. }
  121. // For casting
  122. TEST_F(FileTest, CastNoOp) { runFileTest("cast.no-op.hlsl"); }
  123. TEST_F(FileTest, CastImplicit2Bool) { runFileTest("cast.2bool.implicit.hlsl"); }
  124. TEST_F(FileTest, CastExplicit2Bool) { runFileTest("cast.2bool.explicit.hlsl"); }
  125. TEST_F(FileTest, CastImplicit2SInt) { runFileTest("cast.2sint.implicit.hlsl"); }
  126. TEST_F(FileTest, CastExplicit2SInt) { runFileTest("cast.2sint.explicit.hlsl"); }
  127. TEST_F(FileTest, CastImplicit2UInt) { runFileTest("cast.2uint.implicit.hlsl"); }
  128. TEST_F(FileTest, CastExplicit2UInt) { runFileTest("cast.2uint.explicit.hlsl"); }
  129. TEST_F(FileTest, CastImplicit2FP) { runFileTest("cast.2fp.implicit.hlsl"); }
  130. TEST_F(FileTest, CastExplicit2FP) { runFileTest("cast.2fp.explicit.hlsl"); }
  131. // For vector splatting and trunction
  132. TEST_F(FileTest, CastTruncateVector) { runFileTest("cast.vector.trunc.hlsl"); }
  133. TEST_F(FileTest, CastSplatVector) { runFileTest("cast.vector.splat.hlsl"); }
  134. // For if statements
  135. TEST_F(FileTest, IfStmtPlainAssign) { runFileTest("if-stmt.plain.hlsl"); }
  136. TEST_F(FileTest, IfStmtNestedIfStmt) { runFileTest("if-stmt.nested.hlsl"); }
  137. // For switch statements
  138. TEST_F(FileTest, SwitchStmtUsingOpSwitch) {
  139. runFileTest("switch-stmt.opswitch.hlsl");
  140. }
  141. // For for statements
  142. TEST_F(FileTest, ForStmtPlainAssign) { runFileTest("for-stmt.plain.hlsl"); }
  143. TEST_F(FileTest, ForStmtNestedForStmt) { runFileTest("for-stmt.nested.hlsl"); }
  144. // For control flows
  145. TEST_F(FileTest, ControlFlowNestedIfForStmt) { runFileTest("cf.if.for.hlsl"); }
  146. TEST_F(FileTest, ControlFlowLogicalAnd) { runFileTest("cf.logical-and.hlsl"); }
  147. TEST_F(FileTest, ControlFlowLogicalOr) { runFileTest("cf.logical-or.hlsl"); }
  148. TEST_F(FileTest, ControlFlowConditionalOp) { runFileTest("cf.cond-op.hlsl"); }
  149. // For function calls
  150. TEST_F(FileTest, FunctionCall) { runFileTest("fn.call.hlsl"); }
  151. // For intrinsic functions
  152. TEST_F(FileTest, IntrinsicsDot) { runFileTest("intrinsics.dot.hlsl"); }
  153. TEST_F(FileTest, IntrinsicsAll) { runFileTest("intrinsics.all.hlsl"); }
  154. TEST_F(FileTest, IntrinsicsAny) { runFileTest("intrinsics.any.hlsl"); }
  155. TEST_F(FileTest, IntrinsicsAsfloat) { runFileTest("intrinsics.asfloat.hlsl"); }
  156. TEST_F(FileTest, IntrinsicsAsint) { runFileTest("intrinsics.asint.hlsl"); }
  157. TEST_F(FileTest, IntrinsicsAsuint) { runFileTest("intrinsics.asuint.hlsl"); }
  158. } // namespace