TextureDescriptor.cs 7.6 KB

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