ComputeQmd.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. using Ryujinx.Graphics.Gpu.Engine.Types;
  2. using System;
  3. using System.Runtime.CompilerServices;
  4. namespace Ryujinx.Graphics.Gpu.Engine.Compute
  5. {
  6. /// <summary>
  7. /// Type of the dependent Queue Meta Data.
  8. /// </summary>
  9. enum DependentQmdType
  10. {
  11. Queue,
  12. Grid
  13. }
  14. /// <summary>
  15. /// Type of the release memory barrier.
  16. /// </summary>
  17. enum ReleaseMembarType
  18. {
  19. FeNone,
  20. FeSysmembar
  21. }
  22. /// <summary>
  23. /// Type of the CWD memory barrier.
  24. /// </summary>
  25. enum CwdMembarType
  26. {
  27. L1None,
  28. L1Sysmembar,
  29. L1Membar
  30. }
  31. /// <summary>
  32. /// NaN behavior of 32-bits float operations on the shader.
  33. /// </summary>
  34. enum Fp32NanBehavior
  35. {
  36. Legacy,
  37. Fp64Compatible
  38. }
  39. /// <summary>
  40. /// NaN behavior of 32-bits float to integer conversion on the shader.
  41. /// </summary>
  42. enum Fp32F2iNanBehavior
  43. {
  44. PassZero,
  45. PassIndefinite
  46. }
  47. /// <summary>
  48. /// Limit of calls.
  49. /// </summary>
  50. enum ApiVisibleCallLimit
  51. {
  52. _32,
  53. NoCheck
  54. }
  55. /// <summary>
  56. /// Shared memory bank mapping mode.
  57. /// </summary>
  58. enum SharedMemoryBankMapping
  59. {
  60. FourBytesPerBank,
  61. EightBytesPerBank
  62. }
  63. /// <summary>
  64. /// Denormal behavior of 32-bits float narrowing instructions.
  65. /// </summary>
  66. enum Fp32NarrowInstruction
  67. {
  68. KeepDenorms,
  69. FlushDenorms
  70. }
  71. /// <summary>
  72. /// Configuration of the L1 cache.
  73. /// </summary>
  74. enum L1Configuration
  75. {
  76. DirectlyAddressableMemorySize16kb,
  77. DirectlyAddressableMemorySize32kb,
  78. DirectlyAddressableMemorySize48kb
  79. }
  80. /// <summary>
  81. /// Reduction operation.
  82. /// </summary>
  83. enum ReductionOp
  84. {
  85. RedAdd,
  86. RedMin,
  87. RedMax,
  88. RedInc,
  89. RedDec,
  90. RedAnd,
  91. RedOr,
  92. RedXor
  93. }
  94. /// <summary>
  95. /// Reduction format.
  96. /// </summary>
  97. enum ReductionFormat
  98. {
  99. Unsigned32,
  100. Signed32
  101. }
  102. /// <summary>
  103. /// Size of a structure in words.
  104. /// </summary>
  105. enum StructureSize
  106. {
  107. FourWords,
  108. OneWord
  109. }
  110. /// <summary>
  111. /// Compute Queue Meta Data.
  112. /// </summary>
  113. unsafe struct ComputeQmd
  114. {
  115. private fixed int _words[64];
  116. public int OuterPut => BitRange(30, 0);
  117. public bool OuterOverflow => Bit(31);
  118. public int OuterGet => BitRange(62, 32);
  119. public bool OuterStickyOverflow => Bit(63);
  120. public int InnerGet => BitRange(94, 64);
  121. public bool InnerOverflow => Bit(95);
  122. public int InnerPut => BitRange(126, 96);
  123. public bool InnerStickyOverflow => Bit(127);
  124. public int QmdReservedAA => BitRange(159, 128);
  125. public int DependentQmdPointer => BitRange(191, 160);
  126. public int QmdGroupId => BitRange(197, 192);
  127. public bool SmGlobalCachingEnable => Bit(198);
  128. public bool RunCtaInOneSmPartition => Bit(199);
  129. public bool IsQueue => Bit(200);
  130. public bool AddToHeadOfQmdGroupLinkedList => Bit(201);
  131. public bool SemaphoreReleaseEnable0 => Bit(202);
  132. public bool SemaphoreReleaseEnable1 => Bit(203);
  133. public bool RequireSchedulingPcas => Bit(204);
  134. public bool DependentQmdScheduleEnable => Bit(205);
  135. public DependentQmdType DependentQmdType => (DependentQmdType)BitRange(206, 206);
  136. public bool DependentQmdFieldCopy => Bit(207);
  137. public int QmdReservedB => BitRange(223, 208);
  138. public int CircularQueueSize => BitRange(248, 224);
  139. public bool QmdReservedC => Bit(249);
  140. public bool InvalidateTextureHeaderCache => Bit(250);
  141. public bool InvalidateTextureSamplerCache => Bit(251);
  142. public bool InvalidateTextureDataCache => Bit(252);
  143. public bool InvalidateShaderDataCache => Bit(253);
  144. public bool InvalidateInstructionCache => Bit(254);
  145. public bool InvalidateShaderConstantCache => Bit(255);
  146. public int ProgramOffset => BitRange(287, 256);
  147. public int CircularQueueAddrLower => BitRange(319, 288);
  148. public int CircularQueueAddrUpper => BitRange(327, 320);
  149. public int QmdReservedD => BitRange(335, 328);
  150. public int CircularQueueEntrySize => BitRange(351, 336);
  151. public int CwdReferenceCountId => BitRange(357, 352);
  152. public int CwdReferenceCountDeltaMinusOne => BitRange(365, 358);
  153. public ReleaseMembarType ReleaseMembarType => (ReleaseMembarType)BitRange(366, 366);
  154. public bool CwdReferenceCountIncrEnable => Bit(367);
  155. public CwdMembarType CwdMembarType => (CwdMembarType)BitRange(369, 368);
  156. public bool SequentiallyRunCtas => Bit(370);
  157. public bool CwdReferenceCountDecrEnable => Bit(371);
  158. public bool Throttled => Bit(372);
  159. public Fp32NanBehavior Fp32NanBehavior => (Fp32NanBehavior)BitRange(376, 376);
  160. public Fp32F2iNanBehavior Fp32F2iNanBehavior => (Fp32F2iNanBehavior)BitRange(377, 377);
  161. public ApiVisibleCallLimit ApiVisibleCallLimit => (ApiVisibleCallLimit)BitRange(378, 378);
  162. public SharedMemoryBankMapping SharedMemoryBankMapping => (SharedMemoryBankMapping)BitRange(379, 379);
  163. public SamplerIndex SamplerIndex => (SamplerIndex)BitRange(382, 382);
  164. public Fp32NarrowInstruction Fp32NarrowInstruction => (Fp32NarrowInstruction)BitRange(383, 383);
  165. public int CtaRasterWidth => BitRange(415, 384);
  166. public int CtaRasterHeight => BitRange(431, 416);
  167. public int CtaRasterDepth => BitRange(447, 432);
  168. public int CtaRasterWidthResume => BitRange(479, 448);
  169. public int CtaRasterHeightResume => BitRange(495, 480);
  170. public int CtaRasterDepthResume => BitRange(511, 496);
  171. public int QueueEntriesPerCtaMinusOne => BitRange(518, 512);
  172. public int CoalesceWaitingPeriod => BitRange(529, 522);
  173. public int SharedMemorySize => BitRange(561, 544);
  174. public int QmdReservedG => BitRange(575, 562);
  175. public int QmdVersion => BitRange(579, 576);
  176. public int QmdMajorVersion => BitRange(583, 580);
  177. public int QmdReservedH => BitRange(591, 584);
  178. public int CtaThreadDimension0 => BitRange(607, 592);
  179. public int CtaThreadDimension1 => BitRange(623, 608);
  180. public int CtaThreadDimension2 => BitRange(639, 624);
  181. public bool ConstantBufferValid(int i) => Bit(640 + i * 1);
  182. public int QmdReservedI => BitRange(668, 648);
  183. public L1Configuration L1Configuration => (L1Configuration)BitRange(671, 669);
  184. public int SmDisableMaskLower => BitRange(703, 672);
  185. public int SmDisableMaskUpper => BitRange(735, 704);
  186. public int Release0AddressLower => BitRange(767, 736);
  187. public int Release0AddressUpper => BitRange(775, 768);
  188. public int QmdReservedJ => BitRange(783, 776);
  189. public ReductionOp Release0ReductionOp => (ReductionOp)BitRange(790, 788);
  190. public bool QmdReservedK => Bit(791);
  191. public ReductionFormat Release0ReductionFormat => (ReductionFormat)BitRange(793, 792);
  192. public bool Release0ReductionEnable => Bit(794);
  193. public StructureSize Release0StructureSize => (StructureSize)BitRange(799, 799);
  194. public int Release0Payload => BitRange(831, 800);
  195. public int Release1AddressLower => BitRange(863, 832);
  196. public int Release1AddressUpper => BitRange(871, 864);
  197. public int QmdReservedL => BitRange(879, 872);
  198. public ReductionOp Release1ReductionOp => (ReductionOp)BitRange(886, 884);
  199. public bool QmdReservedM => Bit(887);
  200. public ReductionFormat Release1ReductionFormat => (ReductionFormat)BitRange(889, 888);
  201. public bool Release1ReductionEnable => Bit(890);
  202. public StructureSize Release1StructureSize => (StructureSize)BitRange(895, 895);
  203. public int Release1Payload => BitRange(927, 896);
  204. public int ConstantBufferAddrLower(int i) => BitRange(959 + i * 64, 928 + i * 64);
  205. public int ConstantBufferAddrUpper(int i) => BitRange(967 + i * 64, 960 + i * 64);
  206. public int ConstantBufferReservedAddr(int i) => BitRange(973 + i * 64, 968 + i * 64);
  207. public bool ConstantBufferInvalidate(int i) => Bit(974 + i * 64);
  208. public int ConstantBufferSize(int i) => BitRange(991 + i * 64, 975 + i * 64);
  209. public int ShaderLocalMemoryLowSize => BitRange(1463, 1440);
  210. public int QmdReservedN => BitRange(1466, 1464);
  211. public int BarrierCount => BitRange(1471, 1467);
  212. public int ShaderLocalMemoryHighSize => BitRange(1495, 1472);
  213. public int RegisterCount => BitRange(1503, 1496);
  214. public int ShaderLocalMemoryCrsSize => BitRange(1527, 1504);
  215. public int SassVersion => BitRange(1535, 1528);
  216. public int HwOnlyInnerGet => BitRange(1566, 1536);
  217. public bool HwOnlyRequireSchedulingPcas => Bit(1567);
  218. public int HwOnlyInnerPut => BitRange(1598, 1568);
  219. public bool HwOnlyScgType => Bit(1599);
  220. public int HwOnlySpanListHeadIndex => BitRange(1629, 1600);
  221. public bool QmdReservedQ => Bit(1630);
  222. public bool HwOnlySpanListHeadIndexValid => Bit(1631);
  223. public int HwOnlySkedNextQmdPointer => BitRange(1663, 1632);
  224. public int QmdSpareE => BitRange(1695, 1664);
  225. public int QmdSpareF => BitRange(1727, 1696);
  226. public int QmdSpareG => BitRange(1759, 1728);
  227. public int QmdSpareH => BitRange(1791, 1760);
  228. public int QmdSpareI => BitRange(1823, 1792);
  229. public int QmdSpareJ => BitRange(1855, 1824);
  230. public int QmdSpareK => BitRange(1887, 1856);
  231. public int QmdSpareL => BitRange(1919, 1888);
  232. public int QmdSpareM => BitRange(1951, 1920);
  233. public int QmdSpareN => BitRange(1983, 1952);
  234. public int DebugIdUpper => BitRange(2015, 1984);
  235. public int DebugIdLower => BitRange(2047, 2016);
  236. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  237. private bool Bit(int bit)
  238. {
  239. if ((uint)bit >= 64 * 32)
  240. {
  241. throw new ArgumentOutOfRangeException(nameof(bit));
  242. }
  243. return (_words[bit >> 5] & (1 << (bit & 31))) != 0;
  244. }
  245. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  246. private int BitRange(int upper, int lower)
  247. {
  248. if ((uint)lower >= 64 * 32)
  249. {
  250. throw new ArgumentOutOfRangeException(nameof(lower));
  251. }
  252. int mask = (int)(uint.MaxValue >> (32 - (upper - lower + 1)));
  253. return (_words[lower >> 5] >> (lower & 31)) & mask;
  254. }
  255. }
  256. }