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