TextureDescriptor.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. namespace Ryujinx.Graphics.Gpu.Image
  2. {
  3. /// <summary>
  4. /// Maxwell texture descriptor, as stored on the GPU texture pool memory region.
  5. /// </summary>
  6. struct TextureDescriptor
  7. {
  8. #pragma warning disable CS0649
  9. public uint Word0;
  10. public uint Word1;
  11. public uint Word2;
  12. public uint Word3;
  13. public uint Word4;
  14. public uint Word5;
  15. public uint Word6;
  16. public uint Word7;
  17. #pragma warning restore CS0649
  18. /// <summary>
  19. /// Unpacks Maxwell texture format integer.
  20. /// </summary>
  21. /// <returns>The texture format integer</returns>
  22. public uint UnpackFormat()
  23. {
  24. return Word0 & 0x8007ffff;
  25. }
  26. /// <summary>
  27. /// Unpacks the swizzle component for the texture red color channel.
  28. /// </summary>
  29. /// <returns>The swizzle component</returns>
  30. public TextureComponent UnpackSwizzleR()
  31. {
  32. return(TextureComponent)((Word0 >> 19) & 7);
  33. }
  34. /// <summary>
  35. /// Unpacks the swizzle component for the texture green color channel.
  36. /// </summary>
  37. /// <returns>The swizzle component</returns>
  38. public TextureComponent UnpackSwizzleG()
  39. {
  40. return(TextureComponent)((Word0 >> 22) & 7);
  41. }
  42. /// <summary>
  43. /// Unpacks the swizzle component for the texture blue color channel.
  44. /// </summary>
  45. /// <returns>The swizzle component</returns>
  46. public TextureComponent UnpackSwizzleB()
  47. {
  48. return(TextureComponent)((Word0 >> 25) & 7);
  49. }
  50. /// <summary>
  51. /// Unpacks the swizzle component for the texture alpha color channel.
  52. /// </summary>
  53. /// <returns>The swizzle component</returns>
  54. public TextureComponent UnpackSwizzleA()
  55. {
  56. return(TextureComponent)((Word0 >> 28) & 7);
  57. }
  58. /// <summary>
  59. /// Unpacks the 40-bits texture GPU virtual address.
  60. /// </summary>
  61. /// <returns>The GPU virtual address</returns>
  62. public ulong UnpackAddress()
  63. {
  64. return Word1 | ((ulong)(Word2 & 0xffff) << 32);
  65. }
  66. /// <summary>
  67. /// Unpacks texture descriptor type for this texture descriptor.
  68. /// This defines the texture layout, among other things.
  69. /// </summary>
  70. /// <returns>The texture descriptor type</returns>
  71. public TextureDescriptorType UnpackTextureDescriptorType()
  72. {
  73. return (TextureDescriptorType)((Word2 >> 21) & 7);
  74. }
  75. /// <summary>
  76. /// Unpacks the texture stride (bytes per line) for linear textures only.
  77. /// Always 32-bytes aligned.
  78. /// </summary>
  79. /// <returns>The linear texture stride</returns>
  80. public int UnpackStride()
  81. {
  82. return (int)(Word3 & 0xffff) << 5;
  83. }
  84. /// <summary>
  85. /// Unpacks the GOB block size in X (width) for block linear textures.
  86. /// Must be always 1, ignored by the GPU.
  87. /// </summary>
  88. /// <returns>THe GOB block X size</returns>
  89. public int UnpackGobBlocksInX()
  90. {
  91. return 1 << (int)(Word3 & 7);
  92. }
  93. /// <summary>
  94. /// Unpacks the GOB block size in Y (height) for block linear textures.
  95. /// Must be always a power of 2, with a maximum value of 32.
  96. /// </summary>
  97. /// <returns>THe GOB block Y size</returns>
  98. public int UnpackGobBlocksInY()
  99. {
  100. return 1 << (int)((Word3 >> 3) & 7);
  101. }
  102. /// <summary>
  103. /// Unpacks the GOB block size in Z (depth) for block linear textures.
  104. /// Must be always a power of 2, with a maximum value of 32.
  105. /// Must be 1 for any texture target other than 3D textures.
  106. /// </summary>
  107. /// <returns>The GOB block Z size</returns>
  108. public int UnpackGobBlocksInZ()
  109. {
  110. return 1 << (int)((Word3 >> 6) & 7);
  111. }
  112. /// <summary>
  113. /// Number of GOB blocks per tile in the X direction.
  114. /// This is only used for sparse textures, should be 1 otherwise.
  115. /// </summary>
  116. /// <returns>The number of GOB blocks per tile</returns>
  117. public int UnpackGobBlocksInTileX()
  118. {
  119. return 1 << (int)((Word3 >> 10) & 7);
  120. }
  121. /// <summary>
  122. /// Unpacks the number of mipmap levels of the texture.
  123. /// </summary>
  124. /// <returns>The number of mipmap levels</returns>
  125. public int UnpackLevels()
  126. {
  127. return (int)(Word3 >> 28) + 1;
  128. }
  129. /// <summary>
  130. /// Unpack the base level texture width size.
  131. /// </summary>
  132. /// <returns>The texture width</returns>
  133. public int UnpackWidth()
  134. {
  135. return (int)(Word4 & 0xffff) + 1;
  136. }
  137. /// <summary>
  138. /// Unpacks the texture sRGB format flag.
  139. /// </summary>
  140. /// <returns>True if the texture is sRGB, false otherwise</returns>
  141. public bool UnpackSrgb()
  142. {
  143. return (Word4 & (1 << 22)) != 0;
  144. }
  145. /// <summary>
  146. /// Unpacks the texture target.
  147. /// </summary>
  148. /// <returns>The texture target</returns>
  149. public TextureTarget UnpackTextureTarget()
  150. {
  151. return (TextureTarget)((Word4 >> 23) & 0xf);
  152. }
  153. /// <summary>
  154. /// Unpack the base level texture height size, or array layers for 1D array textures.
  155. /// Should be ignored for 1D or buffer textures.
  156. /// </summary>
  157. /// <returns>The texture height or layers count</returns>
  158. public int UnpackHeight()
  159. {
  160. return (int)(Word5 & 0xffff) + 1;
  161. }
  162. /// <summary>
  163. /// Unpack the base level texture depth size, number of array layers or cubemap faces.
  164. /// The meaning of this value depends on the texture target.
  165. /// </summary>
  166. /// <returns>The texture depth, layer or faces count</returns>
  167. public int UnpackDepth()
  168. {
  169. return (int)((Word5 >> 16) & 0x3fff) + 1;
  170. }
  171. /// <summary>
  172. /// Unpacks the texture coordinates normalized flag.
  173. /// When this is true, texture coordinates are expected to be in the [0, 1] range on the shader.
  174. /// When this is false, texture coordinates are expected to be in the [0, W], [0, H] and [0, D] range.
  175. /// It must be set to false (by the guest driver) for rectangle textures.
  176. /// </summary>
  177. /// <returns>The texture coordinates normalized flag</returns>
  178. public bool UnpackTextureCoordNormalized()
  179. {
  180. return (Word5 & (1 << 31)) != 0;
  181. }
  182. /// <summary>
  183. /// Unpacks the base mipmap level of the texture.
  184. /// </summary>
  185. /// <returns>The base mipmap level of the texture</returns>
  186. public int UnpackBaseLevel()
  187. {
  188. return (int)(Word7 & 0xf);
  189. }
  190. /// <summary>
  191. /// Unpacks the maximum mipmap level (inclusive) of the texture.
  192. /// Usually equal to Levels minus 1.
  193. /// </summary>
  194. /// <returns>The maximum mipmap level (inclusive) of the texture</returns>
  195. public int UnpackMaxLevelInclusive()
  196. {
  197. return (int)((Word7 >> 4) & 0xf);
  198. }
  199. /// <summary>
  200. /// Unpacks the multisampled texture samples count in each direction.
  201. /// Must be ignored for non-multisample textures.
  202. /// </summary>
  203. /// <returns>The multisample counts enum</returns>
  204. public TextureMsaaMode UnpackTextureMsaaMode()
  205. {
  206. return (TextureMsaaMode)((Word7 >> 8) & 0xf);
  207. }
  208. }
  209. }