Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

090-Vectors-Constructors.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. using Burst.Compiler.IL.Tests.Helpers;
  2. using Unity.Mathematics;
  3. namespace Burst.Compiler.IL.Tests
  4. {
  5. internal partial class VectorsConstructors
  6. {
  7. // ---------------------------------------------------
  8. // float4
  9. // ---------------------------------------------------
  10. [TestCompiler(DataRange.Standard)]
  11. public static float Float4Int(int a)
  12. {
  13. return Vectors.ConvertToFloat(new float4(a));
  14. }
  15. [TestCompiler(DataRange.Standard)]
  16. public static float Float4Float3Float(float x)
  17. {
  18. return Vectors.ConvertToFloat(new float4(new float3(x), 5.0f));
  19. }
  20. [TestCompiler(DataRange.Standard)]
  21. public static float Float4Float2Float2(float x)
  22. {
  23. return Vectors.ConvertToFloat(new float4(new float2(x), new float2(5.0f)));
  24. }
  25. [TestCompiler(DataRange.Standard)]
  26. public static float Float44Floats(float a)
  27. {
  28. return Vectors.ConvertToFloat(new float4(1.0f, 2.0f, 3.0f + a, 4.0f));
  29. }
  30. [TestCompiler(DataRange.Standard)]
  31. public static float Float4Float(float a)
  32. {
  33. return Vectors.ConvertToFloat(new float4(a));
  34. }
  35. [TestCompiler(DataRange.Standard)]
  36. public static float Float4Int4(ref int4 a)
  37. {
  38. return Vectors.ConvertToFloat((float4) new float4(a).x);
  39. }
  40. [TestCompiler(DataRange.Standard)]
  41. public static float Float4Half(float a)
  42. {
  43. var h = new half(a);
  44. return Vectors.ConvertToFloat((float4)new float4(h).x);
  45. }
  46. [TestCompiler(DataRange.Standard)]
  47. public static float Float4Half4(ref float4 a)
  48. {
  49. var h = new half4(a);
  50. return Vectors.ConvertToFloat((float4)new float4(h).x);
  51. }
  52. [TestCompiler(DataRange.Standard)]
  53. public static float Float4HalfExplicit(float a)
  54. {
  55. return Vectors.ConvertToFloat((float4) new half(a));
  56. }
  57. [TestCompiler(DataRange.Standard)]
  58. public static float Float4HalfImplicit(float a)
  59. {
  60. float4 x =new half(a);
  61. return Vectors.ConvertToFloat(x);
  62. }
  63. // ---------------------------------------------------
  64. // float3
  65. // ---------------------------------------------------
  66. [TestCompiler(DataRange.Standard)]
  67. public static float Float3Int(int a)
  68. {
  69. return Vectors.ConvertToFloat(new float3(a));
  70. }
  71. [TestCompiler(DataRange.Standard)]
  72. public static float Float33Floats(float a)
  73. {
  74. return Vectors.ConvertToFloat(new float3(1.0f, 2.0f, 3.0f + a));
  75. }
  76. [TestCompiler(DataRange.Standard)]
  77. public static float Float3Float(float a)
  78. {
  79. return Vectors.ConvertToFloat(new float3(a));
  80. }
  81. [TestCompiler(DataRange.Standard)]
  82. public static float Float3Float2Float(float a)
  83. {
  84. return Vectors.ConvertToFloat(new float3(new float2(a), 5.0f));
  85. }
  86. [TestCompiler(DataRange.Standard)]
  87. public static float Float3Half(float a)
  88. {
  89. var h = new half(a);
  90. return Vectors.ConvertToFloat((float3)new float3(h).x);
  91. }
  92. [TestCompiler(DataRange.Standard)]
  93. public static float Float3Half3(ref float3 a)
  94. {
  95. var h = new half3(a);
  96. return Vectors.ConvertToFloat((float3)new float3(h).x);
  97. }
  98. // ---------------------------------------------------
  99. // float2
  100. // ---------------------------------------------------
  101. [TestCompiler(DataRange.Standard)]
  102. public static float Float2Int(int a)
  103. {
  104. return Vectors.ConvertToFloat(new float2(a));
  105. }
  106. [TestCompiler(DataRange.Standard)]
  107. public static float Float22Floats(float a)
  108. {
  109. return Vectors.ConvertToFloat(new float2(1.0f, 3.0f + a));
  110. }
  111. [TestCompiler(DataRange.Standard)]
  112. public static float Float2Float(float a)
  113. {
  114. return Vectors.ConvertToFloat(new float2(a));
  115. }
  116. [TestCompiler(DataRange.Standard)]
  117. public static float Float2Half(float a)
  118. {
  119. var h = new half(a);
  120. return Vectors.ConvertToFloat((float2)new float2(h).x);
  121. }
  122. [TestCompiler(DataRange.Standard)]
  123. public static float Float2Half2(ref float2 a)
  124. {
  125. var h = new half2(a);
  126. return Vectors.ConvertToFloat((float2)new float2(h).x);
  127. }
  128. // ---------------------------------------------------
  129. // int4
  130. // ---------------------------------------------------
  131. [TestCompiler(DataRange.Standard)]
  132. public static int Int4Int(int a)
  133. {
  134. return Vectors.ConvertToInt(new int4(a));
  135. }
  136. [TestCompiler(DataRange.Standard)]
  137. public static int Int4Int3Int(int x)
  138. {
  139. return Vectors.ConvertToInt(new int4(new int3(x), 5));
  140. }
  141. [TestCompiler(DataRange.Standard)]
  142. public static int Int44Ints(int a)
  143. {
  144. return Vectors.ConvertToInt(new int4(1, 2, 3 + a, 4));
  145. }
  146. // ---------------------------------------------------
  147. // int3
  148. // ---------------------------------------------------
  149. [TestCompiler(DataRange.Standard)]
  150. public static int Int3Int(int a)
  151. {
  152. return Vectors.ConvertToInt(new int3(a));
  153. }
  154. [TestCompiler(DataRange.Standard)]
  155. public static int Int33Ints(int a)
  156. {
  157. return Vectors.ConvertToInt(new int3(1, 2, 3 + a));
  158. }
  159. [TestCompiler(DataRange.Standard)]
  160. public static int Int3Int2Int(int a)
  161. {
  162. return Vectors.ConvertToInt(new int3(new int2(a), 5));
  163. }
  164. // ---------------------------------------------------
  165. // int2
  166. // ---------------------------------------------------
  167. [TestCompiler(DataRange.Standard)]
  168. public static int Int2Int(int a)
  169. {
  170. return Vectors.ConvertToInt(new int2(a));
  171. }
  172. [TestCompiler(DataRange.Standard)]
  173. public static int Int22Ints(int a)
  174. {
  175. return Vectors.ConvertToInt(new int2(1, 3 + a));
  176. }
  177. // ---------------------------------------------------
  178. // bool4
  179. // ---------------------------------------------------
  180. [TestCompiler(true)]
  181. [TestCompiler(false)]
  182. public static int Bool4(bool a)
  183. {
  184. return Vectors.ConvertToInt(new bool4(a));
  185. }
  186. [TestCompiler(true)]
  187. [TestCompiler(false)]
  188. public static int Bool4Bool3(bool x)
  189. {
  190. return Vectors.ConvertToInt(new bool4(new bool3(x), true));
  191. }
  192. [TestCompiler(false, false, false, false)]
  193. [TestCompiler(true, false, false, false)]
  194. [TestCompiler(false, true, false, false)]
  195. [TestCompiler(false, false, true, false)]
  196. [TestCompiler(false, false, false, true)]
  197. public static int Bool44Bools(bool a, bool b, bool c, bool d)
  198. {
  199. return Vectors.ConvertToInt(new bool4(a, b, c, d));
  200. }
  201. // ---------------------------------------------------
  202. // bool3
  203. // ---------------------------------------------------
  204. [TestCompiler(true)]
  205. [TestCompiler(false)]
  206. public static int Bool3(bool a)
  207. {
  208. return Vectors.ConvertToInt(new bool3(a));
  209. }
  210. [TestCompiler(true)]
  211. [TestCompiler(false)]
  212. public static int Bool3Bool2(bool a)
  213. {
  214. return Vectors.ConvertToInt(new bool3(new bool2(a), true));
  215. }
  216. [TestCompiler(false, false, false)]
  217. [TestCompiler(true, false, false)]
  218. [TestCompiler(false, true, false)]
  219. [TestCompiler(false, false, true)]
  220. public static int Bool33Bools(bool a, bool b, bool c)
  221. {
  222. return Vectors.ConvertToInt(new bool3(a, b, c));
  223. }
  224. // ---------------------------------------------------
  225. // bool2
  226. // ---------------------------------------------------
  227. [TestCompiler(true)]
  228. [TestCompiler(false)]
  229. public static int Bool2(bool a)
  230. {
  231. return Vectors.ConvertToInt(new bool2(a));
  232. }
  233. [TestCompiler(true, false)]
  234. [TestCompiler(false, false)]
  235. [TestCompiler(false, true)]
  236. public static int Bool22Ints(bool a, bool b)
  237. {
  238. return Vectors.ConvertToInt(new bool2(a, b));
  239. }
  240. // ---------------------------------------------------
  241. // double4
  242. // ---------------------------------------------------
  243. [TestCompiler(DataRange.Standard)]
  244. public static double Double4Int(int a)
  245. {
  246. return Vectors.ConvertToDouble(new double4(a));
  247. }
  248. [TestCompiler(DataRange.Standard)]
  249. public static double Double4Double3Double(double x)
  250. {
  251. return Vectors.ConvertToDouble(new double4(new double3(x), 5.0f));
  252. }
  253. [TestCompiler(DataRange.Standard)]
  254. public static double Double4Double2Double2(double x)
  255. {
  256. return Vectors.ConvertToDouble(new double4(new double2(x), new double2(5.0f)));
  257. }
  258. [TestCompiler(DataRange.Standard)]
  259. public static double Double44Doubles(double a)
  260. {
  261. return Vectors.ConvertToDouble(new double4(1.0f, 2.0f, 3.0f + a, 4.0f));
  262. }
  263. [TestCompiler(DataRange.Standard)]
  264. public static double Double4Double(double a)
  265. {
  266. return Vectors.ConvertToDouble(new double4(a));
  267. }
  268. [TestCompiler(DataRange.Standard)]
  269. public static double Double4Int4(ref int4 a)
  270. {
  271. return Vectors.ConvertToDouble((double4)new double4(a).x);
  272. }
  273. [TestCompiler(DataRange.Standard)]
  274. public static double Double4Half(double a)
  275. {
  276. var h = new half(a);
  277. return Vectors.ConvertToDouble((double4)new double4(h).x);
  278. }
  279. [TestCompiler(DataRange.Standard)]
  280. public static double Double4Half4(ref double4 a)
  281. {
  282. var h = new half4(a);
  283. return Vectors.ConvertToDouble((double4)new double4(h).x);
  284. }
  285. // ---------------------------------------------------
  286. // double3
  287. // ---------------------------------------------------
  288. [TestCompiler(DataRange.Standard)]
  289. public static double Double3Int(int a)
  290. {
  291. return Vectors.ConvertToDouble(new double3(a));
  292. }
  293. [TestCompiler(DataRange.Standard)]
  294. public static double Double33Doubles(double a)
  295. {
  296. return Vectors.ConvertToDouble(new double3(1.0f, 2.0f, 3.0f + a));
  297. }
  298. [TestCompiler(DataRange.Standard)]
  299. public static double Double3Double(double a)
  300. {
  301. return Vectors.ConvertToDouble(new double3(a));
  302. }
  303. [TestCompiler(DataRange.Standard)]
  304. public static double Double3Double2Double(double a)
  305. {
  306. return Vectors.ConvertToDouble(new double3(new double2(a), 5.0f));
  307. }
  308. [TestCompiler(DataRange.Standard)]
  309. public static double Double3Half(double a)
  310. {
  311. var h = new half(a);
  312. return Vectors.ConvertToDouble((double3)new double3(h).x);
  313. }
  314. [TestCompiler(DataRange.Standard)]
  315. public static double Double3Half3(ref double3 a)
  316. {
  317. var h = new half3(a);
  318. return Vectors.ConvertToDouble((double3)new double3(h).x);
  319. }
  320. // ---------------------------------------------------
  321. // double2
  322. // ---------------------------------------------------
  323. [TestCompiler(DataRange.Standard)]
  324. public static double Double2Int(int a)
  325. {
  326. return Vectors.ConvertToDouble(new double2(a));
  327. }
  328. [TestCompiler(DataRange.Standard)]
  329. public static double Double22Doubles(double a)
  330. {
  331. return Vectors.ConvertToDouble(new double2(1.0f, 3.0f + a));
  332. }
  333. [TestCompiler(DataRange.Standard)]
  334. public static double Double2Double(double a)
  335. {
  336. return Vectors.ConvertToDouble(new double2(a));
  337. }
  338. [TestCompiler(DataRange.Standard)]
  339. public static double Double2Half(double a)
  340. {
  341. var h = new half(a);
  342. return Vectors.ConvertToDouble((double2)new double2(h).x);
  343. }
  344. [TestCompiler(DataRange.Standard)]
  345. public static double Double2Half2(ref double2 a)
  346. {
  347. var h = new half2(a);
  348. return Vectors.ConvertToDouble((double2)new double2(h).x);
  349. }
  350. [TestCompiler(uint.MaxValue, uint.MaxValue / 2 + 1)]
  351. public static float Float2UInt2(uint a, uint b)
  352. {
  353. return Vectors.ConvertToFloat(new float2(new uint2(a, b)));
  354. }
  355. [TestCompiler(uint.MaxValue, uint.MaxValue / 2 + 1)]
  356. public static float Float4UIntUIntUInt2Implicit(uint a, uint b)
  357. {
  358. var u = new uint2(a, b);
  359. return Vectors.ConvertToFloat(new float4(a, b, u));
  360. }
  361. [TestCompiler(uint.MaxValue, uint.MaxValue / 2 + 1)]
  362. public static float Float4UIntUIntUInt2Explicit(uint a, uint b)
  363. {
  364. var u = new uint2(a, b);
  365. return Vectors.ConvertToFloat(new float4(a, b, (float2) u));
  366. }
  367. }
  368. }