IGpuAccessor.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. using System;
  2. namespace Ryujinx.Graphics.Shader
  3. {
  4. /// <summary>
  5. /// GPU state access interface.
  6. /// </summary>
  7. public interface IGpuAccessor
  8. {
  9. /// <summary>
  10. /// Prints a log message.
  11. /// </summary>
  12. /// <param name="message">Message to print</param>
  13. void Log(string message)
  14. {
  15. // No default log output.
  16. }
  17. /// <summary>
  18. /// Reads data from the constant buffer 1.
  19. /// </summary>
  20. /// <param name="offset">Offset in bytes to read from</param>
  21. /// <returns>Value at the given offset</returns>
  22. uint ConstantBuffer1Read(int offset)
  23. {
  24. return 0;
  25. }
  26. /// <summary>
  27. /// Gets a span of the specified memory location, containing shader code.
  28. /// </summary>
  29. /// <param name="address">GPU virtual address of the data</param>
  30. /// <param name="minimumSize">Minimum size that the returned span may have</param>
  31. /// <returns>Span of the memory location</returns>
  32. ReadOnlySpan<ulong> GetCode(ulong address, int minimumSize);
  33. /// <summary>
  34. /// Queries whenever the alpha-to-coverage dithering feature is enabled.
  35. /// </summary>
  36. /// <returns>True if the feature is enabled, false otherwise</returns>
  37. bool QueryAlphaToCoverageDitherEnable()
  38. {
  39. return false;
  40. }
  41. /// <summary>
  42. /// Queries the binding number of a constant buffer.
  43. /// </summary>
  44. /// <param name="index">Constant buffer index</param>
  45. /// <returns>Binding number</returns>
  46. int QueryBindingConstantBuffer(int index)
  47. {
  48. return index;
  49. }
  50. /// <summary>
  51. /// Queries the binding number of a storage buffer.
  52. /// </summary>
  53. /// <param name="index">Storage buffer index</param>
  54. /// <returns>Binding number</returns>
  55. int QueryBindingStorageBuffer(int index)
  56. {
  57. return index;
  58. }
  59. /// <summary>
  60. /// Queries the binding number of a texture.
  61. /// </summary>
  62. /// <param name="index">Texture index</param>
  63. /// <returns>Binding number</returns>
  64. int QueryBindingTexture(int index)
  65. {
  66. return index;
  67. }
  68. /// <summary>
  69. /// Queries the binding number of an image.
  70. /// </summary>
  71. /// <param name="index">Image index</param>
  72. /// <returns>Binding number</returns>
  73. int QueryBindingImage(int index)
  74. {
  75. return index;
  76. }
  77. /// <summary>
  78. /// Queries Local Size X for compute shaders.
  79. /// </summary>
  80. /// <returns>Local Size X</returns>
  81. int QueryComputeLocalSizeX()
  82. {
  83. return 1;
  84. }
  85. /// <summary>
  86. /// Queries Local Size Y for compute shaders.
  87. /// </summary>
  88. /// <returns>Local Size Y</returns>
  89. int QueryComputeLocalSizeY()
  90. {
  91. return 1;
  92. }
  93. /// <summary>
  94. /// Queries Local Size Z for compute shaders.
  95. /// </summary>
  96. /// <returns>Local Size Z</returns>
  97. int QueryComputeLocalSizeZ()
  98. {
  99. return 1;
  100. }
  101. /// <summary>
  102. /// Queries Local Memory size in bytes for compute shaders.
  103. /// </summary>
  104. /// <returns>Local Memory size in bytes</returns>
  105. int QueryComputeLocalMemorySize()
  106. {
  107. return 0x1000;
  108. }
  109. /// <summary>
  110. /// Queries Shared Memory size in bytes for compute shaders.
  111. /// </summary>
  112. /// <returns>Shared Memory size in bytes</returns>
  113. int QueryComputeSharedMemorySize()
  114. {
  115. return 0xc000;
  116. }
  117. /// <summary>
  118. /// Queries Constant Buffer usage information.
  119. /// </summary>
  120. /// <returns>A mask where each bit set indicates a bound constant buffer</returns>
  121. uint QueryConstantBufferUse()
  122. {
  123. return 0;
  124. }
  125. /// <summary>
  126. /// Queries host about the presence of the FrontFacing built-in variable bug.
  127. /// </summary>
  128. /// <returns>True if the bug is present on the host device used, false otherwise</returns>
  129. bool QueryHostHasFrontFacingBug()
  130. {
  131. return false;
  132. }
  133. /// <summary>
  134. /// Queries host about the presence of the vector indexing bug.
  135. /// </summary>
  136. /// <returns>True if the bug is present on the host device used, false otherwise</returns>
  137. bool QueryHostHasVectorIndexingBug()
  138. {
  139. return false;
  140. }
  141. /// <summary>
  142. /// Queries host storage buffer alignment required.
  143. /// </summary>
  144. /// <returns>Host storage buffer alignment in bytes</returns>
  145. int QueryHostStorageBufferOffsetAlignment()
  146. {
  147. return 16;
  148. }
  149. /// <summary>
  150. /// Queries host support for texture formats with BGRA component order (such as BGRA8).
  151. /// </summary>
  152. /// <returns>True if BGRA formats are supported, false otherwise</returns>
  153. bool QueryHostSupportsBgraFormat()
  154. {
  155. return true;
  156. }
  157. /// <summary>
  158. /// Queries host support for fragment shader ordering critical sections on the shader code.
  159. /// </summary>
  160. /// <returns>True if fragment shader interlock is supported, false otherwise</returns>
  161. bool QueryHostSupportsFragmentShaderInterlock()
  162. {
  163. return true;
  164. }
  165. /// <summary>
  166. /// Queries host support for fragment shader ordering scoped critical sections on the shader code.
  167. /// </summary>
  168. /// <returns>True if fragment shader ordering is supported, false otherwise</returns>
  169. bool QueryHostSupportsFragmentShaderOrderingIntel()
  170. {
  171. return false;
  172. }
  173. /// <summary>
  174. /// Queries host support for readable images without a explicit format declaration on the shader.
  175. /// </summary>
  176. /// <returns>True if formatted image load is supported, false otherwise</returns>
  177. bool QueryHostSupportsImageLoadFormatted()
  178. {
  179. return true;
  180. }
  181. /// <summary>
  182. /// Queries host GPU non-constant texture offset support.
  183. /// </summary>
  184. /// <returns>True if the GPU and driver supports non-constant texture offsets, false otherwise</returns>
  185. bool QueryHostSupportsNonConstantTextureOffset()
  186. {
  187. return true;
  188. }
  189. /// <summary>
  190. /// Queries host GPU shader ballot support.
  191. /// </summary>
  192. /// <returns>True if the GPU and driver supports shader ballot, false otherwise</returns>
  193. bool QueryHostSupportsShaderBallot()
  194. {
  195. return true;
  196. }
  197. /// <summary>
  198. /// Queries host GPU texture shadow LOD support.
  199. /// </summary>
  200. /// <returns>True if the GPU and driver supports texture shadow LOD, false otherwise</returns>
  201. bool QueryHostSupportsTextureShadowLod()
  202. {
  203. return true;
  204. }
  205. /// <summary>
  206. /// Queries sampler type information.
  207. /// </summary>
  208. /// <param name="handle">Texture handle</param>
  209. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  210. /// <returns>The sampler type value for the given handle</returns>
  211. SamplerType QuerySamplerType(int handle, int cbufSlot = -1)
  212. {
  213. return SamplerType.Texture2D;
  214. }
  215. /// <summary>
  216. /// Queries texture coordinate normalization information.
  217. /// </summary>
  218. /// <param name="handle">Texture handle</param>
  219. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  220. /// <returns>True if the coordinates are normalized, false otherwise</returns>
  221. bool QueryTextureCoordNormalized(int handle, int cbufSlot = -1)
  222. {
  223. return true;
  224. }
  225. /// <summary>
  226. /// Queries current primitive topology for geometry shaders.
  227. /// </summary>
  228. /// <returns>Current primitive topology</returns>
  229. InputTopology QueryPrimitiveTopology()
  230. {
  231. return InputTopology.Points;
  232. }
  233. /// <summary>
  234. /// Queries the tessellation evaluation shader primitive winding order.
  235. /// </summary>
  236. /// <returns>True if the primitive winding order is clockwise, false if counter-clockwise</returns>
  237. bool QueryTessCw()
  238. {
  239. return false;
  240. }
  241. /// <summary>
  242. /// Queries the tessellation evaluation shader abstract patch type.
  243. /// </summary>
  244. /// <returns>Abstract patch type</returns>
  245. TessPatchType QueryTessPatchType()
  246. {
  247. return TessPatchType.Triangles;
  248. }
  249. /// <summary>
  250. /// Queries the tessellation evaluation shader spacing between tessellated vertices of the patch.
  251. /// </summary>
  252. /// <returns>Spacing between tessellated vertices of the patch</returns>
  253. TessSpacing QueryTessSpacing()
  254. {
  255. return TessSpacing.EqualSpacing;
  256. }
  257. /// <summary>
  258. /// Queries texture format information, for shaders using image load or store.
  259. /// </summary>
  260. /// <remarks>
  261. /// This only returns non-compressed color formats.
  262. /// If the format of the texture is a compressed, depth or unsupported format, then a default value is returned.
  263. /// </remarks>
  264. /// <param name="handle">Texture handle</param>
  265. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  266. /// <returns>Color format of the non-compressed texture</returns>
  267. TextureFormat QueryTextureFormat(int handle, int cbufSlot = -1)
  268. {
  269. return TextureFormat.R8G8B8A8Unorm;
  270. }
  271. /// <summary>
  272. /// Queries transform feedback enable state.
  273. /// </summary>
  274. /// <returns>True if the shader uses transform feedback, false otherwise</returns>
  275. bool QueryTransformFeedbackEnabled()
  276. {
  277. return false;
  278. }
  279. /// <summary>
  280. /// Queries the varying locations that should be written to the transform feedback buffer.
  281. /// </summary>
  282. /// <param name="bufferIndex">Index of the transform feedback buffer</param>
  283. /// <returns>Varying locations for the specified buffer</returns>
  284. ReadOnlySpan<byte> QueryTransformFeedbackVaryingLocations(int bufferIndex)
  285. {
  286. return ReadOnlySpan<byte>.Empty;
  287. }
  288. /// <summary>
  289. /// Queries the stride (in bytes) of the per vertex data written into the transform feedback buffer.
  290. /// </summary>
  291. /// <param name="bufferIndex">Index of the transform feedback buffer</param>
  292. /// <returns>Stride for the specified buffer</returns>
  293. int QueryTransformFeedbackStride(int bufferIndex)
  294. {
  295. return 0;
  296. }
  297. /// <summary>
  298. /// Queries if host state forces early depth testing.
  299. /// </summary>
  300. /// <returns>True if early depth testing is forced</returns>
  301. bool QueryEarlyZForce()
  302. {
  303. return false;
  304. }
  305. /// <summary>
  306. /// Queries if host state disables the viewport transform.
  307. /// </summary>
  308. /// <returns>True if the viewport transform is disabled</returns>
  309. bool QueryViewportTransformDisable()
  310. {
  311. return false;
  312. }
  313. /// <summary>
  314. /// Registers a texture used by the shader.
  315. /// </summary>
  316. /// <param name="handle">Texture handle word offset</param>
  317. /// <param name="cbufSlot">Constant buffer slot where the texture handle is located</param>
  318. void RegisterTexture(int handle, int cbufSlot)
  319. {
  320. // Only useful when recording information for a disk shader cache.
  321. }
  322. }
  323. }