IGpuAccessor.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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 the alpha test comparison operator that is being used currently.
  35. /// If alpha test is disabled, it should be set to <see cref="AlphaTestOp.Always"/>.
  36. /// </summary>
  37. /// <returns>Current alpha test comparison</returns>
  38. AlphaTestOp QueryAlphaTestCompare()
  39. {
  40. return AlphaTestOp.Always;
  41. }
  42. /// <summary>
  43. /// Queries the current alpha test reference value used by the comparison.
  44. /// </summary>
  45. /// <returns>Current alpha test reference value</returns>
  46. float QueryAlphaTestReference()
  47. {
  48. return 0f;
  49. }
  50. /// <summary>
  51. /// Queries the type of the vertex shader input attribute at the specified <paramref name="location"/>.
  52. /// </summary>
  53. /// <param name="location">Location of the input attribute</param>
  54. /// <returns>Input type</returns>
  55. AttributeType QueryAttributeType(int location)
  56. {
  57. return AttributeType.Float;
  58. }
  59. /// <summary>
  60. /// Queries whenever the alpha-to-coverage dithering feature is enabled.
  61. /// </summary>
  62. /// <returns>True if the feature is enabled, false otherwise</returns>
  63. bool QueryAlphaToCoverageDitherEnable()
  64. {
  65. return false;
  66. }
  67. /// <summary>
  68. /// Queries the binding number of a constant buffer.
  69. /// </summary>
  70. /// <param name="index">Constant buffer index</param>
  71. /// <returns>Binding number</returns>
  72. int QueryBindingConstantBuffer(int index)
  73. {
  74. return index;
  75. }
  76. /// <summary>
  77. /// Queries the binding number of a storage buffer.
  78. /// </summary>
  79. /// <param name="index">Storage buffer index</param>
  80. /// <returns>Binding number</returns>
  81. int QueryBindingStorageBuffer(int index)
  82. {
  83. return index;
  84. }
  85. /// <summary>
  86. /// Queries the binding number of a texture.
  87. /// </summary>
  88. /// <param name="index">Texture index</param>
  89. /// <param name="isBuffer">Indicates if the texture is a buffer texture</param>
  90. /// <returns>Binding number</returns>
  91. int QueryBindingTexture(int index, bool isBuffer)
  92. {
  93. return index;
  94. }
  95. /// <summary>
  96. /// Queries the binding number of an image.
  97. /// </summary>
  98. /// <param name="index">Image index</param>
  99. /// <param name="isBuffer">Indicates if the image is a buffer image</param>
  100. /// <returns>Binding number</returns>
  101. int QueryBindingImage(int index, bool isBuffer)
  102. {
  103. return index;
  104. }
  105. /// <summary>
  106. /// Queries Local Size X for compute shaders.
  107. /// </summary>
  108. /// <returns>Local Size X</returns>
  109. int QueryComputeLocalSizeX()
  110. {
  111. return 1;
  112. }
  113. /// <summary>
  114. /// Queries Local Size Y for compute shaders.
  115. /// </summary>
  116. /// <returns>Local Size Y</returns>
  117. int QueryComputeLocalSizeY()
  118. {
  119. return 1;
  120. }
  121. /// <summary>
  122. /// Queries Local Size Z for compute shaders.
  123. /// </summary>
  124. /// <returns>Local Size Z</returns>
  125. int QueryComputeLocalSizeZ()
  126. {
  127. return 1;
  128. }
  129. /// <summary>
  130. /// Queries Local Memory size in bytes for compute shaders.
  131. /// </summary>
  132. /// <returns>Local Memory size in bytes</returns>
  133. int QueryComputeLocalMemorySize()
  134. {
  135. return 0x1000;
  136. }
  137. /// <summary>
  138. /// Queries Shared Memory size in bytes for compute shaders.
  139. /// </summary>
  140. /// <returns>Shared Memory size in bytes</returns>
  141. int QueryComputeSharedMemorySize()
  142. {
  143. return 0xc000;
  144. }
  145. /// <summary>
  146. /// Queries Constant Buffer usage information.
  147. /// </summary>
  148. /// <returns>A mask where each bit set indicates a bound constant buffer</returns>
  149. uint QueryConstantBufferUse()
  150. {
  151. return 0;
  152. }
  153. /// <summary>
  154. /// Queries host about the presence of the FrontFacing built-in variable bug.
  155. /// </summary>
  156. /// <returns>True if the bug is present on the host device used, false otherwise</returns>
  157. bool QueryHostHasFrontFacingBug()
  158. {
  159. return false;
  160. }
  161. /// <summary>
  162. /// Queries host about the presence of the vector indexing bug.
  163. /// </summary>
  164. /// <returns>True if the bug is present on the host device used, false otherwise</returns>
  165. bool QueryHostHasVectorIndexingBug()
  166. {
  167. return false;
  168. }
  169. /// <summary>
  170. /// Queries host storage buffer alignment required.
  171. /// </summary>
  172. /// <returns>Host storage buffer alignment in bytes</returns>
  173. int QueryHostStorageBufferOffsetAlignment()
  174. {
  175. return 16;
  176. }
  177. /// <summary>
  178. /// Queries host support for texture formats with BGRA component order (such as BGRA8).
  179. /// </summary>
  180. /// <returns>True if BGRA formats are supported, false otherwise</returns>
  181. bool QueryHostSupportsBgraFormat()
  182. {
  183. return true;
  184. }
  185. /// <summary>
  186. /// Queries host support for fragment shader ordering critical sections on the shader code.
  187. /// </summary>
  188. /// <returns>True if fragment shader interlock is supported, false otherwise</returns>
  189. bool QueryHostSupportsFragmentShaderInterlock()
  190. {
  191. return true;
  192. }
  193. /// <summary>
  194. /// Queries host support for fragment shader ordering scoped critical sections on the shader code.
  195. /// </summary>
  196. /// <returns>True if fragment shader ordering is supported, false otherwise</returns>
  197. bool QueryHostSupportsFragmentShaderOrderingIntel()
  198. {
  199. return false;
  200. }
  201. /// <summary>
  202. /// Queries host GPU geometry shader passthrough support.
  203. /// </summary>
  204. /// <returns>True if the GPU and driver supports geometry shader passthrough, false otherwise</returns>
  205. bool QueryHostSupportsGeometryShaderPassthrough()
  206. {
  207. return true;
  208. }
  209. /// <summary>
  210. /// Queries host support for readable images without a explicit format declaration on the shader.
  211. /// </summary>
  212. /// <returns>True if formatted image load is supported, false otherwise</returns>
  213. bool QueryHostSupportsImageLoadFormatted()
  214. {
  215. return true;
  216. }
  217. /// <summary>
  218. /// Queries host GPU non-constant texture offset support.
  219. /// </summary>
  220. /// <returns>True if the GPU and driver supports non-constant texture offsets, false otherwise</returns>
  221. bool QueryHostSupportsNonConstantTextureOffset()
  222. {
  223. return true;
  224. }
  225. /// <summary>
  226. /// Queries host GPU shader ballot support.
  227. /// </summary>
  228. /// <returns>True if the GPU and driver supports shader ballot, false otherwise</returns>
  229. bool QueryHostSupportsShaderBallot()
  230. {
  231. return true;
  232. }
  233. /// <summary>
  234. /// Queries host GPU texture shadow LOD support.
  235. /// </summary>
  236. /// <returns>True if the GPU and driver supports texture shadow LOD, false otherwise</returns>
  237. bool QueryHostSupportsTextureShadowLod()
  238. {
  239. return true;
  240. }
  241. /// <summary>
  242. /// Queries host GPU shader viewport index output support.
  243. /// </summary>
  244. /// <returns>True if the GPU and driver supports shader viewport index output, false otherwise</returns>
  245. bool QueryHostSupportsViewportIndex()
  246. {
  247. return true;
  248. }
  249. /// <summary>
  250. /// Queries the point size from the GPU state, used when it is not explicitly set on the shader.
  251. /// </summary>
  252. /// <returns>Current point size</returns>
  253. float QueryPointSize()
  254. {
  255. return 1f;
  256. }
  257. /// <summary>
  258. /// Queries the state that indicates if the program point size should be explicitly set on the shader
  259. /// or read from the GPU state.
  260. /// </summary>
  261. /// <returns>True if the shader is expected to set the point size explicitly, false otherwise</returns>
  262. bool QueryProgramPointSize()
  263. {
  264. return true;
  265. }
  266. /// <summary>
  267. /// Queries sampler type information.
  268. /// </summary>
  269. /// <param name="handle">Texture handle</param>
  270. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  271. /// <returns>The sampler type value for the given handle</returns>
  272. SamplerType QuerySamplerType(int handle, int cbufSlot = -1)
  273. {
  274. return SamplerType.Texture2D;
  275. }
  276. /// <summary>
  277. /// Queries texture coordinate normalization information.
  278. /// </summary>
  279. /// <param name="handle">Texture handle</param>
  280. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  281. /// <returns>True if the coordinates are normalized, false otherwise</returns>
  282. bool QueryTextureCoordNormalized(int handle, int cbufSlot = -1)
  283. {
  284. return true;
  285. }
  286. /// <summary>
  287. /// Queries current primitive topology for geometry shaders.
  288. /// </summary>
  289. /// <returns>Current primitive topology</returns>
  290. InputTopology QueryPrimitiveTopology()
  291. {
  292. return InputTopology.Points;
  293. }
  294. /// <summary>
  295. /// Queries the tessellation evaluation shader primitive winding order.
  296. /// </summary>
  297. /// <returns>True if the primitive winding order is clockwise, false if counter-clockwise</returns>
  298. bool QueryTessCw()
  299. {
  300. return false;
  301. }
  302. /// <summary>
  303. /// Queries the tessellation evaluation shader abstract patch type.
  304. /// </summary>
  305. /// <returns>Abstract patch type</returns>
  306. TessPatchType QueryTessPatchType()
  307. {
  308. return TessPatchType.Triangles;
  309. }
  310. /// <summary>
  311. /// Queries the tessellation evaluation shader spacing between tessellated vertices of the patch.
  312. /// </summary>
  313. /// <returns>Spacing between tessellated vertices of the patch</returns>
  314. TessSpacing QueryTessSpacing()
  315. {
  316. return TessSpacing.EqualSpacing;
  317. }
  318. /// <summary>
  319. /// Queries texture format information, for shaders using image load or store.
  320. /// </summary>
  321. /// <remarks>
  322. /// This only returns non-compressed color formats.
  323. /// If the format of the texture is a compressed, depth or unsupported format, then a default value is returned.
  324. /// </remarks>
  325. /// <param name="handle">Texture handle</param>
  326. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  327. /// <returns>Color format of the non-compressed texture</returns>
  328. TextureFormat QueryTextureFormat(int handle, int cbufSlot = -1)
  329. {
  330. return TextureFormat.R8G8B8A8Unorm;
  331. }
  332. /// <summary>
  333. /// Queries depth mode information from the GPU state.
  334. /// </summary>
  335. /// <returns>True if current depth mode is -1 to 1, false if 0 to 1</returns>
  336. bool QueryTransformDepthMinusOneToOne()
  337. {
  338. return false;
  339. }
  340. /// <summary>
  341. /// Queries transform feedback enable state.
  342. /// </summary>
  343. /// <returns>True if the shader uses transform feedback, false otherwise</returns>
  344. bool QueryTransformFeedbackEnabled()
  345. {
  346. return false;
  347. }
  348. /// <summary>
  349. /// Queries the varying locations that should be written to the transform feedback buffer.
  350. /// </summary>
  351. /// <param name="bufferIndex">Index of the transform feedback buffer</param>
  352. /// <returns>Varying locations for the specified buffer</returns>
  353. ReadOnlySpan<byte> QueryTransformFeedbackVaryingLocations(int bufferIndex)
  354. {
  355. return ReadOnlySpan<byte>.Empty;
  356. }
  357. /// <summary>
  358. /// Queries the stride (in bytes) of the per vertex data written into the transform feedback buffer.
  359. /// </summary>
  360. /// <param name="bufferIndex">Index of the transform feedback buffer</param>
  361. /// <returns>Stride for the specified buffer</returns>
  362. int QueryTransformFeedbackStride(int bufferIndex)
  363. {
  364. return 0;
  365. }
  366. /// <summary>
  367. /// Queries if host state forces early depth testing.
  368. /// </summary>
  369. /// <returns>True if early depth testing is forced</returns>
  370. bool QueryEarlyZForce()
  371. {
  372. return false;
  373. }
  374. /// <summary>
  375. /// Queries if host state disables the viewport transform.
  376. /// </summary>
  377. /// <returns>True if the viewport transform is disabled</returns>
  378. bool QueryViewportTransformDisable()
  379. {
  380. return false;
  381. }
  382. /// <summary>
  383. /// Registers a texture used by the shader.
  384. /// </summary>
  385. /// <param name="handle">Texture handle word offset</param>
  386. /// <param name="cbufSlot">Constant buffer slot where the texture handle is located</param>
  387. void RegisterTexture(int handle, int cbufSlot)
  388. {
  389. // Only useful when recording information for a disk shader cache.
  390. }
  391. }
  392. }