EmitterContextInsts.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  1. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  2. using System;
  3. using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
  4. namespace Ryujinx.Graphics.Shader.Translation
  5. {
  6. static class EmitterContextInsts
  7. {
  8. public static Operand AtomicAdd(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  9. {
  10. return context.Add(Instruction.AtomicAdd, storageKind, Local(), a, b, c);
  11. }
  12. public static Operand AtomicAnd(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  13. {
  14. return context.Add(Instruction.AtomicAnd, storageKind, Local(), a, b, c);
  15. }
  16. public static Operand AtomicCompareAndSwap(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c, Operand d)
  17. {
  18. return context.Add(Instruction.AtomicCompareAndSwap, storageKind, Local(), a, b, c, d);
  19. }
  20. public static Operand AtomicMaxS32(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  21. {
  22. return context.Add(Instruction.AtomicMaxS32, storageKind, Local(), a, b, c);
  23. }
  24. public static Operand AtomicMaxU32(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  25. {
  26. return context.Add(Instruction.AtomicMaxU32, storageKind, Local(), a, b, c);
  27. }
  28. public static Operand AtomicMinS32(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  29. {
  30. return context.Add(Instruction.AtomicMinS32, storageKind, Local(), a, b, c);
  31. }
  32. public static Operand AtomicMinU32(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  33. {
  34. return context.Add(Instruction.AtomicMinU32, storageKind, Local(), a, b, c);
  35. }
  36. public static Operand AtomicOr(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  37. {
  38. return context.Add(Instruction.AtomicOr, storageKind, Local(), a, b, c);
  39. }
  40. public static Operand AtomicSwap(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  41. {
  42. return context.Add(Instruction.AtomicSwap, storageKind, Local(), a, b, c);
  43. }
  44. public static Operand AtomicXor(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  45. {
  46. return context.Add(Instruction.AtomicXor, storageKind, Local(), a, b, c);
  47. }
  48. public static Operand AtomicAdd(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand value)
  49. {
  50. return context.Add(Instruction.AtomicAdd, storageKind, Local(), Const(binding), e0, e1, value);
  51. }
  52. public static Operand AtomicAnd(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand value)
  53. {
  54. return context.Add(Instruction.AtomicAnd, storageKind, Local(), Const(binding), e0, e1, value);
  55. }
  56. public static Operand AtomicCompareAndSwap(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand compare, Operand value)
  57. {
  58. return context.Add(Instruction.AtomicCompareAndSwap, storageKind, Local(), Const(binding), e0, compare, value);
  59. }
  60. public static Operand AtomicCompareAndSwap(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand compare, Operand value)
  61. {
  62. return context.Add(Instruction.AtomicCompareAndSwap, storageKind, Local(), Const(binding), e0, e1, compare, value);
  63. }
  64. public static Operand AtomicMaxS32(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand value)
  65. {
  66. return context.Add(Instruction.AtomicMaxS32, storageKind, Local(), Const(binding), e0, e1, value);
  67. }
  68. public static Operand AtomicMaxU32(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand value)
  69. {
  70. return context.Add(Instruction.AtomicMaxU32, storageKind, Local(), Const(binding), e0, e1, value);
  71. }
  72. public static Operand AtomicMinS32(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand value)
  73. {
  74. return context.Add(Instruction.AtomicMinS32, storageKind, Local(), Const(binding), e0, e1, value);
  75. }
  76. public static Operand AtomicMinU32(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand value)
  77. {
  78. return context.Add(Instruction.AtomicMinU32, storageKind, Local(), Const(binding), e0, e1, value);
  79. }
  80. public static Operand AtomicOr(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand value)
  81. {
  82. return context.Add(Instruction.AtomicOr, storageKind, Local(), Const(binding), e0, e1, value);
  83. }
  84. public static Operand AtomicSwap(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand value)
  85. {
  86. return context.Add(Instruction.AtomicSwap, storageKind, Local(), Const(binding), e0, e1, value);
  87. }
  88. public static Operand AtomicXor(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand value)
  89. {
  90. return context.Add(Instruction.AtomicXor, storageKind, Local(), Const(binding), e0, e1, value);
  91. }
  92. public static Operand Ballot(this EmitterContext context, Operand a, int index)
  93. {
  94. Operand dest = Local();
  95. context.Add(new Operation(Instruction.Ballot, index, dest, a));
  96. return dest;
  97. }
  98. public static Operand Barrier(this EmitterContext context)
  99. {
  100. return context.Add(Instruction.Barrier);
  101. }
  102. public static Operand BitCount(this EmitterContext context, Operand a)
  103. {
  104. return context.Add(Instruction.BitCount, Local(), a);
  105. }
  106. public static Operand BitfieldExtractS32(this EmitterContext context, Operand a, Operand b, Operand c)
  107. {
  108. return context.Add(Instruction.BitfieldExtractS32, Local(), a, b, c);
  109. }
  110. public static Operand BitfieldExtractU32(this EmitterContext context, Operand a, Operand b, Operand c)
  111. {
  112. return context.Add(Instruction.BitfieldExtractU32, Local(), a, b, c);
  113. }
  114. public static Operand BitfieldInsert(this EmitterContext context, Operand a, Operand b, Operand c, Operand d)
  115. {
  116. return context.Add(Instruction.BitfieldInsert, Local(), a, b, c, d);
  117. }
  118. public static Operand BitfieldReverse(this EmitterContext context, Operand a)
  119. {
  120. return context.Add(Instruction.BitfieldReverse, Local(), a);
  121. }
  122. public static Operand BitwiseAnd(this EmitterContext context, Operand a, Operand b)
  123. {
  124. return context.Add(Instruction.BitwiseAnd, Local(), a, b);
  125. }
  126. public static Operand BitwiseExclusiveOr(this EmitterContext context, Operand a, Operand b)
  127. {
  128. return context.Add(Instruction.BitwiseExclusiveOr, Local(), a, b);
  129. }
  130. public static Operand BitwiseNot(this EmitterContext context, Operand a, bool invert)
  131. {
  132. if (invert)
  133. {
  134. a = context.BitwiseNot(a);
  135. }
  136. return a;
  137. }
  138. public static Operand BitwiseNot(this EmitterContext context, Operand a)
  139. {
  140. return context.Add(Instruction.BitwiseNot, Local(), a);
  141. }
  142. public static Operand BitwiseOr(this EmitterContext context, Operand a, Operand b)
  143. {
  144. return context.Add(Instruction.BitwiseOr, Local(), a, b);
  145. }
  146. public static Operand Branch(this EmitterContext context, Operand d)
  147. {
  148. return context.Add(Instruction.Branch, d);
  149. }
  150. public static Operand BranchIfFalse(this EmitterContext context, Operand d, Operand a)
  151. {
  152. return context.Add(Instruction.BranchIfFalse, d, a);
  153. }
  154. public static Operand BranchIfTrue(this EmitterContext context, Operand d, Operand a)
  155. {
  156. return context.Add(Instruction.BranchIfTrue, d, a);
  157. }
  158. public static Operand Call(this EmitterContext context, int funcId, bool returns, params Operand[] args)
  159. {
  160. Operand[] args2 = new Operand[args.Length + 1];
  161. args2[0] = Const(funcId);
  162. args.CopyTo(args2, 1);
  163. return context.Add(Instruction.Call, returns ? Local() : null, args2);
  164. }
  165. public static Operand ConditionalSelect(this EmitterContext context, Operand a, Operand b, Operand c)
  166. {
  167. return context.Add(Instruction.ConditionalSelect, Local(), a, b, c);
  168. }
  169. public static Operand Copy(this EmitterContext context, Operand a)
  170. {
  171. return context.Add(Instruction.Copy, Local(), a);
  172. }
  173. public static void Copy(this EmitterContext context, Operand d, Operand a)
  174. {
  175. if (d.Type == OperandType.Constant)
  176. {
  177. return;
  178. }
  179. context.Add(Instruction.Copy, d, a);
  180. }
  181. public static Operand Discard(this EmitterContext context)
  182. {
  183. return context.Add(Instruction.Discard);
  184. }
  185. public static Operand EmitVertex(this EmitterContext context)
  186. {
  187. return context.Add(Instruction.EmitVertex);
  188. }
  189. public static Operand EndPrimitive(this EmitterContext context)
  190. {
  191. return context.Add(Instruction.EndPrimitive);
  192. }
  193. public static Operand FindLSB(this EmitterContext context, Operand a)
  194. {
  195. return context.Add(Instruction.FindLSB, Local(), a);
  196. }
  197. public static Operand FindMSBS32(this EmitterContext context, Operand a)
  198. {
  199. return context.Add(Instruction.FindMSBS32, Local(), a);
  200. }
  201. public static Operand FindMSBU32(this EmitterContext context, Operand a)
  202. {
  203. return context.Add(Instruction.FindMSBU32, Local(), a);
  204. }
  205. public static Operand FP32ConvertToFP64(this EmitterContext context, Operand a)
  206. {
  207. return context.Add(Instruction.ConvertFP32ToFP64, Local(), a);
  208. }
  209. public static Operand FP64ConvertToFP32(this EmitterContext context, Operand a)
  210. {
  211. return context.Add(Instruction.ConvertFP64ToFP32, Local(), a);
  212. }
  213. public static Operand FPAbsNeg(this EmitterContext context, Operand a, bool abs, bool neg, Instruction fpType = Instruction.FP32)
  214. {
  215. return context.FPNegate(context.FPAbsolute(a, abs, fpType), neg, fpType);
  216. }
  217. public static Operand FPAbsolute(this EmitterContext context, Operand a, bool abs, Instruction fpType = Instruction.FP32)
  218. {
  219. if (abs)
  220. {
  221. a = context.FPAbsolute(a, fpType);
  222. }
  223. return a;
  224. }
  225. public static Operand FPAbsolute(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  226. {
  227. return context.Add(fpType | Instruction.Absolute, Local(), a);
  228. }
  229. public static Operand FPAdd(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  230. {
  231. return context.Add(fpType | Instruction.Add, Local(), a, b);
  232. }
  233. public static Operand FPCeiling(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  234. {
  235. return context.Add(fpType | Instruction.Ceiling, Local(), a);
  236. }
  237. public static Operand FPCompareEqual(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  238. {
  239. return context.Add(fpType | Instruction.CompareEqual, Local(), a, b);
  240. }
  241. public static Operand FPCompareLess(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  242. {
  243. return context.Add(fpType | Instruction.CompareLess, Local(), a, b);
  244. }
  245. public static Operand FP32ConvertToS32(this EmitterContext context, Operand a)
  246. {
  247. return context.Add(Instruction.ConvertFP32ToS32, Local(), a);
  248. }
  249. public static Operand FP32ConvertToU32(this EmitterContext context, Operand a)
  250. {
  251. return context.Add(Instruction.ConvertFP32ToU32, Local(), a);
  252. }
  253. public static Operand FP64ConvertToS32(this EmitterContext context, Operand a)
  254. {
  255. return context.Add(Instruction.ConvertFP64ToS32, Local(), a);
  256. }
  257. public static Operand FP64ConvertToU32(this EmitterContext context, Operand a)
  258. {
  259. return context.Add(Instruction.ConvertFP64ToU32, Local(), a);
  260. }
  261. public static Operand FPCosine(this EmitterContext context, Operand a)
  262. {
  263. return context.Add(Instruction.FP32 | Instruction.Cosine, Local(), a);
  264. }
  265. public static Operand FPDivide(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  266. {
  267. return context.Add(fpType | Instruction.Divide, Local(), a, b);
  268. }
  269. public static Operand FPExponentB2(this EmitterContext context, Operand a)
  270. {
  271. return context.Add(Instruction.FP32 | Instruction.ExponentB2, Local(), a);
  272. }
  273. public static Operand FPFloor(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  274. {
  275. return context.Add(fpType | Instruction.Floor, Local(), a);
  276. }
  277. public static Operand FPFusedMultiplyAdd(this EmitterContext context, Operand a, Operand b, Operand c, Instruction fpType = Instruction.FP32)
  278. {
  279. return context.Add(fpType | Instruction.FusedMultiplyAdd, Local(), a, b, c);
  280. }
  281. public static Operand FPLogarithmB2(this EmitterContext context, Operand a)
  282. {
  283. return context.Add(Instruction.FP32 | Instruction.LogarithmB2, Local(), a);
  284. }
  285. public static Operand FPMaximum(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  286. {
  287. return context.Add(fpType | Instruction.Maximum, Local(), a, b);
  288. }
  289. public static Operand FPMinimum(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  290. {
  291. return context.Add(fpType | Instruction.Minimum, Local(), a, b);
  292. }
  293. public static Operand FPModulo(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  294. {
  295. return context.Add(fpType | Instruction.Modulo, Local(), a, b);
  296. }
  297. public static Operand FPMultiply(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  298. {
  299. return context.Add(fpType | Instruction.Multiply, Local(), a, b);
  300. }
  301. public static Operand FPNegate(this EmitterContext context, Operand a, bool neg, Instruction fpType = Instruction.FP32)
  302. {
  303. if (neg)
  304. {
  305. a = context.FPNegate(a, fpType);
  306. }
  307. return a;
  308. }
  309. public static Operand FPNegate(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  310. {
  311. return context.Add(fpType | Instruction.Negate, Local(), a);
  312. }
  313. public static Operand FPReciprocal(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  314. {
  315. return context.FPDivide(fpType == Instruction.FP64 ? context.PackDouble2x32(1.0) : ConstF(1), a, fpType);
  316. }
  317. public static Operand FPReciprocalSquareRoot(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  318. {
  319. return context.Add(fpType | Instruction.ReciprocalSquareRoot, Local(), a);
  320. }
  321. public static Operand FPRound(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  322. {
  323. return context.Add(fpType | Instruction.Round, Local(), a);
  324. }
  325. public static Operand FPSaturate(this EmitterContext context, Operand a, bool sat, Instruction fpType = Instruction.FP32)
  326. {
  327. if (sat)
  328. {
  329. a = context.FPSaturate(a, fpType);
  330. }
  331. return a;
  332. }
  333. public static Operand FPSaturate(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  334. {
  335. return fpType == Instruction.FP64
  336. ? context.Add(fpType | Instruction.Clamp, Local(), a, context.PackDouble2x32(0.0), context.PackDouble2x32(1.0))
  337. : context.Add(fpType | Instruction.Clamp, Local(), a, ConstF(0), ConstF(1));
  338. }
  339. public static Operand FPSine(this EmitterContext context, Operand a)
  340. {
  341. return context.Add(Instruction.FP32 | Instruction.Sine, Local(), a);
  342. }
  343. public static Operand FPSquareRoot(this EmitterContext context, Operand a)
  344. {
  345. return context.Add(Instruction.FP32 | Instruction.SquareRoot, Local(), a);
  346. }
  347. public static Operand FPSubtract(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  348. {
  349. return context.Add(fpType | Instruction.Subtract, Local(), a, b);
  350. }
  351. public static Operand FPTruncate(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  352. {
  353. return context.Add(fpType | Instruction.Truncate, Local(), a);
  354. }
  355. public static Operand FPSwizzleAdd(this EmitterContext context, Operand a, Operand b, int mask)
  356. {
  357. return context.Add(Instruction.SwizzleAdd, Local(), a, b, Const(mask));
  358. }
  359. public static void FSIBegin(this EmitterContext context)
  360. {
  361. context.Add(Instruction.FSIBegin);
  362. }
  363. public static void FSIEnd(this EmitterContext context)
  364. {
  365. context.Add(Instruction.FSIEnd);
  366. }
  367. public static Operand GroupMemoryBarrier(this EmitterContext context)
  368. {
  369. return context.Add(Instruction.GroupMemoryBarrier);
  370. }
  371. public static Operand IAbsNeg(this EmitterContext context, Operand a, bool abs, bool neg)
  372. {
  373. return context.INegate(context.IAbsolute(a, abs), neg);
  374. }
  375. public static Operand IAbsolute(this EmitterContext context, Operand a, bool abs)
  376. {
  377. if (abs)
  378. {
  379. a = context.IAbsolute(a);
  380. }
  381. return a;
  382. }
  383. public static Operand IAbsolute(this EmitterContext context, Operand a)
  384. {
  385. return context.Add(Instruction.Absolute, Local(), a);
  386. }
  387. public static Operand IAdd(this EmitterContext context, Operand a, Operand b)
  388. {
  389. return context.Add(Instruction.Add, Local(), a, b);
  390. }
  391. public static Operand IClampS32(this EmitterContext context, Operand a, Operand b, Operand c)
  392. {
  393. return context.Add(Instruction.Clamp, Local(), a, b, c);
  394. }
  395. public static Operand IClampU32(this EmitterContext context, Operand a, Operand b, Operand c)
  396. {
  397. return context.Add(Instruction.ClampU32, Local(), a, b, c);
  398. }
  399. public static Operand ICompareEqual(this EmitterContext context, Operand a, Operand b)
  400. {
  401. return context.Add(Instruction.CompareEqual, Local(), a, b);
  402. }
  403. public static Operand ICompareGreater(this EmitterContext context, Operand a, Operand b)
  404. {
  405. return context.Add(Instruction.CompareGreater, Local(), a, b);
  406. }
  407. public static Operand ICompareGreaterOrEqual(this EmitterContext context, Operand a, Operand b)
  408. {
  409. return context.Add(Instruction.CompareGreaterOrEqual, Local(), a, b);
  410. }
  411. public static Operand ICompareGreaterOrEqualUnsigned(this EmitterContext context, Operand a, Operand b)
  412. {
  413. return context.Add(Instruction.CompareGreaterOrEqualU32, Local(), a, b);
  414. }
  415. public static Operand ICompareGreaterUnsigned(this EmitterContext context, Operand a, Operand b)
  416. {
  417. return context.Add(Instruction.CompareGreaterU32, Local(), a, b);
  418. }
  419. public static Operand ICompareLess(this EmitterContext context, Operand a, Operand b)
  420. {
  421. return context.Add(Instruction.CompareLess, Local(), a, b);
  422. }
  423. public static Operand ICompareLessOrEqual(this EmitterContext context, Operand a, Operand b)
  424. {
  425. return context.Add(Instruction.CompareLessOrEqual, Local(), a, b);
  426. }
  427. public static Operand ICompareLessOrEqualUnsigned(this EmitterContext context, Operand a, Operand b)
  428. {
  429. return context.Add(Instruction.CompareLessOrEqualU32, Local(), a, b);
  430. }
  431. public static Operand ICompareLessUnsigned(this EmitterContext context, Operand a, Operand b)
  432. {
  433. return context.Add(Instruction.CompareLessU32, Local(), a, b);
  434. }
  435. public static Operand ICompareNotEqual(this EmitterContext context, Operand a, Operand b)
  436. {
  437. return context.Add(Instruction.CompareNotEqual, Local(), a, b);
  438. }
  439. public static Operand IConvertS32ToFP32(this EmitterContext context, Operand a)
  440. {
  441. return context.Add(Instruction.ConvertS32ToFP32, Local(), a);
  442. }
  443. public static Operand IConvertS32ToFP64(this EmitterContext context, Operand a)
  444. {
  445. return context.Add(Instruction.ConvertS32ToFP64, Local(), a);
  446. }
  447. public static Operand IConvertU32ToFP32(this EmitterContext context, Operand a)
  448. {
  449. return context.Add(Instruction.ConvertU32ToFP32, Local(), a);
  450. }
  451. public static Operand IConvertU32ToFP64(this EmitterContext context, Operand a)
  452. {
  453. return context.Add(Instruction.ConvertU32ToFP64, Local(), a);
  454. }
  455. public static Operand IMaximumS32(this EmitterContext context, Operand a, Operand b)
  456. {
  457. return context.Add(Instruction.Maximum, Local(), a, b);
  458. }
  459. public static Operand IMaximumU32(this EmitterContext context, Operand a, Operand b)
  460. {
  461. return context.Add(Instruction.MaximumU32, Local(), a, b);
  462. }
  463. public static Operand IMinimumS32(this EmitterContext context, Operand a, Operand b)
  464. {
  465. return context.Add(Instruction.Minimum, Local(), a, b);
  466. }
  467. public static Operand IMinimumU32(this EmitterContext context, Operand a, Operand b)
  468. {
  469. return context.Add(Instruction.MinimumU32, Local(), a, b);
  470. }
  471. public static Operand IMultiply(this EmitterContext context, Operand a, Operand b)
  472. {
  473. return context.Add(Instruction.Multiply, Local(), a, b);
  474. }
  475. public static Operand INegate(this EmitterContext context, Operand a, bool neg)
  476. {
  477. if (neg)
  478. {
  479. a = context.INegate(a);
  480. }
  481. return a;
  482. }
  483. public static Operand INegate(this EmitterContext context, Operand a)
  484. {
  485. return context.Add(Instruction.Negate, Local(), a);
  486. }
  487. public static Operand ISubtract(this EmitterContext context, Operand a, Operand b)
  488. {
  489. return context.Add(Instruction.Subtract, Local(), a, b);
  490. }
  491. public static Operand ImageAtomic(
  492. this EmitterContext context,
  493. SamplerType type,
  494. TextureFormat format,
  495. TextureFlags flags,
  496. int binding,
  497. Operand[] sources)
  498. {
  499. Operand dest = Local();
  500. context.Add(new TextureOperation(Instruction.ImageAtomic, type, format, flags, binding, 0, new[] { dest }, sources));
  501. return dest;
  502. }
  503. public static void ImageLoad(
  504. this EmitterContext context,
  505. SamplerType type,
  506. TextureFormat format,
  507. TextureFlags flags,
  508. int binding,
  509. int compMask,
  510. Operand[] dests,
  511. Operand[] sources)
  512. {
  513. context.Add(new TextureOperation(Instruction.ImageLoad, type, format, flags, binding, compMask, dests, sources));
  514. }
  515. public static void ImageStore(
  516. this EmitterContext context,
  517. SamplerType type,
  518. TextureFormat format,
  519. TextureFlags flags,
  520. int binding,
  521. Operand[] sources)
  522. {
  523. context.Add(new TextureOperation(Instruction.ImageStore, type, format, flags, binding, 0, null, sources));
  524. }
  525. public static Operand IsNan(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  526. {
  527. return context.Add(fpType | Instruction.IsNan, Local(), a);
  528. }
  529. public static Operand Load(this EmitterContext context, StorageKind storageKind, Operand e0, Operand e1)
  530. {
  531. return context.Add(Instruction.Load, storageKind, Local(), e0, e1);
  532. }
  533. public static Operand Load(this EmitterContext context, StorageKind storageKind, int binding)
  534. {
  535. return context.Add(Instruction.Load, storageKind, Local(), Const(binding));
  536. }
  537. public static Operand Load(this EmitterContext context, StorageKind storageKind, int binding, Operand e0)
  538. {
  539. return context.Add(Instruction.Load, storageKind, Local(), Const(binding), e0);
  540. }
  541. public static Operand Load(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1)
  542. {
  543. return context.Add(Instruction.Load, storageKind, Local(), Const(binding), e0, e1);
  544. }
  545. public static Operand Load(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand e2)
  546. {
  547. return context.Add(Instruction.Load, storageKind, Local(), Const(binding), e0, e1, e2);
  548. }
  549. public static Operand Load(this EmitterContext context, StorageKind storageKind, IoVariable ioVariable, Operand primVertex = null)
  550. {
  551. return primVertex != null
  552. ? context.Load(storageKind, (int)ioVariable, primVertex)
  553. : context.Load(storageKind, (int)ioVariable);
  554. }
  555. public static Operand Load(
  556. this EmitterContext context,
  557. StorageKind storageKind,
  558. IoVariable ioVariable,
  559. Operand primVertex,
  560. Operand elemIndex)
  561. {
  562. return primVertex != null
  563. ? context.Load(storageKind, (int)ioVariable, primVertex, elemIndex)
  564. : context.Load(storageKind, (int)ioVariable, elemIndex);
  565. }
  566. public static Operand Load(
  567. this EmitterContext context,
  568. StorageKind storageKind,
  569. IoVariable ioVariable,
  570. Operand primVertex,
  571. Operand arrayIndex,
  572. Operand elemIndex)
  573. {
  574. return primVertex != null
  575. ? context.Load(storageKind, (int)ioVariable, primVertex, arrayIndex, elemIndex)
  576. : context.Load(storageKind, (int)ioVariable, arrayIndex, elemIndex);
  577. }
  578. public static Operand Lod(
  579. this EmitterContext context,
  580. SamplerType type,
  581. TextureFlags flags,
  582. int binding,
  583. int compIndex,
  584. Operand[] sources)
  585. {
  586. Operand dest = Local();
  587. context.Add(new TextureOperation(Instruction.Lod, type, TextureFormat.Unknown, flags, binding, compIndex, new[] { dest }, sources));
  588. return dest;
  589. }
  590. public static Operand MemoryBarrier(this EmitterContext context)
  591. {
  592. return context.Add(Instruction.MemoryBarrier);
  593. }
  594. public static Operand MultiplyHighS32(this EmitterContext context, Operand a, Operand b)
  595. {
  596. return context.Add(Instruction.MultiplyHighS32, Local(), a, b);
  597. }
  598. public static Operand MultiplyHighU32(this EmitterContext context, Operand a, Operand b)
  599. {
  600. return context.Add(Instruction.MultiplyHighU32, Local(), a, b);
  601. }
  602. public static Operand PackDouble2x32(this EmitterContext context, double value)
  603. {
  604. long valueAsLong = BitConverter.DoubleToInt64Bits(value);
  605. return context.Add(Instruction.PackDouble2x32, Local(), Const((int)valueAsLong), Const((int)(valueAsLong >> 32)));
  606. }
  607. public static Operand PackDouble2x32(this EmitterContext context, Operand a, Operand b)
  608. {
  609. return context.Add(Instruction.PackDouble2x32, Local(), a, b);
  610. }
  611. public static Operand PackHalf2x16(this EmitterContext context, Operand a, Operand b)
  612. {
  613. return context.Add(Instruction.PackHalf2x16, Local(), a, b);
  614. }
  615. public static void Return(this EmitterContext context)
  616. {
  617. context.Add(Instruction.Return);
  618. }
  619. public static void Return(this EmitterContext context, Operand returnValue)
  620. {
  621. context.Add(Instruction.Return, null, returnValue);
  622. }
  623. public static Operand ShiftLeft(this EmitterContext context, Operand a, Operand b)
  624. {
  625. return context.Add(Instruction.ShiftLeft, Local(), a, b);
  626. }
  627. public static Operand ShiftRightS32(this EmitterContext context, Operand a, Operand b)
  628. {
  629. return context.Add(Instruction.ShiftRightS32, Local(), a, b);
  630. }
  631. public static Operand ShiftRightU32(this EmitterContext context, Operand a, Operand b)
  632. {
  633. return context.Add(Instruction.ShiftRightU32, Local(), a, b);
  634. }
  635. public static Operand Shuffle(this EmitterContext context, Operand a, Operand b)
  636. {
  637. return context.Add(Instruction.Shuffle, Local(), a, b);
  638. }
  639. public static (Operand, Operand) Shuffle(this EmitterContext context, Operand a, Operand b, Operand c)
  640. {
  641. return context.Add(Instruction.Shuffle, (Local(), Local()), a, b, c);
  642. }
  643. public static Operand ShuffleDown(this EmitterContext context, Operand a, Operand b)
  644. {
  645. return context.Add(Instruction.ShuffleDown, Local(), a, b);
  646. }
  647. public static (Operand, Operand) ShuffleDown(this EmitterContext context, Operand a, Operand b, Operand c)
  648. {
  649. return context.Add(Instruction.ShuffleDown, (Local(), Local()), a, b, c);
  650. }
  651. public static Operand ShuffleUp(this EmitterContext context, Operand a, Operand b)
  652. {
  653. return context.Add(Instruction.ShuffleUp, Local(), a, b);
  654. }
  655. public static (Operand, Operand) ShuffleUp(this EmitterContext context, Operand a, Operand b, Operand c)
  656. {
  657. return context.Add(Instruction.ShuffleUp, (Local(), Local()), a, b, c);
  658. }
  659. public static Operand ShuffleXor(this EmitterContext context, Operand a, Operand b)
  660. {
  661. return context.Add(Instruction.ShuffleXor, Local(), a, b);
  662. }
  663. public static (Operand, Operand) ShuffleXor(this EmitterContext context, Operand a, Operand b, Operand c)
  664. {
  665. return context.Add(Instruction.ShuffleXor, (Local(), Local()), a, b, c);
  666. }
  667. public static Operand Store(this EmitterContext context, StorageKind storageKind, Operand e0, Operand e1, Operand value)
  668. {
  669. return context.Add(Instruction.Store, storageKind, null, e0, e1, value);
  670. }
  671. public static Operand Store(this EmitterContext context, StorageKind storageKind, int binding, Operand value)
  672. {
  673. return context.Add(Instruction.Store, storageKind, null, Const(binding), value);
  674. }
  675. public static Operand Store(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand value)
  676. {
  677. return context.Add(Instruction.Store, storageKind, null, Const(binding), e0, value);
  678. }
  679. public static Operand Store(this EmitterContext context, StorageKind storageKind, int binding, Operand e0, Operand e1, Operand value)
  680. {
  681. return context.Add(Instruction.Store, storageKind, null, Const(binding), e0, e1, value);
  682. }
  683. public static Operand Store(
  684. this EmitterContext context,
  685. StorageKind storageKind,
  686. IoVariable ioVariable,
  687. Operand invocationId,
  688. Operand value)
  689. {
  690. return invocationId != null
  691. ? context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), invocationId, value)
  692. : context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), value);
  693. }
  694. public static Operand Store(
  695. this EmitterContext context,
  696. StorageKind storageKind,
  697. IoVariable ioVariable,
  698. Operand invocationId,
  699. Operand elemIndex,
  700. Operand value)
  701. {
  702. return invocationId != null
  703. ? context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), invocationId, elemIndex, value)
  704. : context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), elemIndex, value);
  705. }
  706. public static Operand Store(
  707. this EmitterContext context,
  708. StorageKind storageKind,
  709. IoVariable ioVariable,
  710. Operand invocationId,
  711. Operand arrayIndex,
  712. Operand elemIndex,
  713. Operand value)
  714. {
  715. return invocationId != null
  716. ? context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), invocationId, arrayIndex, elemIndex, value)
  717. : context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), arrayIndex, elemIndex, value);
  718. }
  719. public static void TextureSample(
  720. this EmitterContext context,
  721. SamplerType type,
  722. TextureFlags flags,
  723. int binding,
  724. int compMask,
  725. Operand[] dests,
  726. Operand[] sources)
  727. {
  728. context.Add(new TextureOperation(Instruction.TextureSample, type, TextureFormat.Unknown, flags, binding, compMask, dests, sources));
  729. }
  730. public static Operand TextureQuerySamples(
  731. this EmitterContext context,
  732. SamplerType type,
  733. TextureFlags flags,
  734. int binding,
  735. Operand[] sources)
  736. {
  737. Operand dest = Local();
  738. context.Add(new TextureOperation(Instruction.TextureQuerySamples, type, TextureFormat.Unknown, flags, binding, 0, new[] { dest }, sources));
  739. return dest;
  740. }
  741. public static Operand TextureQuerySize(
  742. this EmitterContext context,
  743. SamplerType type,
  744. TextureFlags flags,
  745. int binding,
  746. int compIndex,
  747. Operand[] sources)
  748. {
  749. Operand dest = Local();
  750. context.Add(new TextureOperation(Instruction.TextureQuerySize, type, TextureFormat.Unknown, flags, binding, compIndex, new[] { dest }, sources));
  751. return dest;
  752. }
  753. public static Operand UnpackDouble2x32High(this EmitterContext context, Operand a)
  754. {
  755. return UnpackDouble2x32(context, a, 1);
  756. }
  757. public static Operand UnpackDouble2x32Low(this EmitterContext context, Operand a)
  758. {
  759. return UnpackDouble2x32(context, a, 0);
  760. }
  761. private static Operand UnpackDouble2x32(this EmitterContext context, Operand a, int index)
  762. {
  763. Operand dest = Local();
  764. context.Add(new Operation(Instruction.UnpackDouble2x32, index, dest, a));
  765. return dest;
  766. }
  767. public static Operand UnpackHalf2x16High(this EmitterContext context, Operand a)
  768. {
  769. return UnpackHalf2x16(context, a, 1);
  770. }
  771. public static Operand UnpackHalf2x16Low(this EmitterContext context, Operand a)
  772. {
  773. return UnpackHalf2x16(context, a, 0);
  774. }
  775. private static Operand UnpackHalf2x16(this EmitterContext context, Operand a, int index)
  776. {
  777. Operand dest = Local();
  778. context.Add(new Operation(Instruction.UnpackHalf2x16, index, dest, a));
  779. return dest;
  780. }
  781. public static Operand VoteAll(this EmitterContext context, Operand a)
  782. {
  783. return context.Add(Instruction.VoteAll, Local(), a);
  784. }
  785. public static Operand VoteAllEqual(this EmitterContext context, Operand a)
  786. {
  787. return context.Add(Instruction.VoteAllEqual, Local(), a);
  788. }
  789. public static Operand VoteAny(this EmitterContext context, Operand a)
  790. {
  791. return context.Add(Instruction.VoteAny, Local(), a);
  792. }
  793. }
  794. }