IGpuAccessor.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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 whenever the current draw has written the base vertex and base instance into Constant Buffer 0.
  155. /// </summary>
  156. /// <returns>True if the shader translator can assume that the constant buffer contains the base IDs, false otherwise</returns>
  157. bool QueryHasConstantBufferDrawParameters()
  158. {
  159. return false;
  160. }
  161. /// <summary>
  162. /// Queries whenever the current draw uses unaligned storage buffer addresses.
  163. /// </summary>
  164. /// <returns>True if any storage buffer address is not aligned to 16 bytes, false otherwise</returns>
  165. bool QueryHasUnalignedStorageBuffer()
  166. {
  167. return false;
  168. }
  169. /// <summary>
  170. /// Queries host about the presence of the FrontFacing built-in variable bug.
  171. /// </summary>
  172. /// <returns>True if the bug is present on the host device used, false otherwise</returns>
  173. bool QueryHostHasFrontFacingBug()
  174. {
  175. return false;
  176. }
  177. /// <summary>
  178. /// Queries host about the presence of the vector indexing bug.
  179. /// </summary>
  180. /// <returns>True if the bug is present on the host device used, false otherwise</returns>
  181. bool QueryHostHasVectorIndexingBug()
  182. {
  183. return false;
  184. }
  185. /// <summary>
  186. /// Queries host storage buffer alignment required.
  187. /// </summary>
  188. /// <returns>Host storage buffer alignment in bytes</returns>
  189. int QueryHostStorageBufferOffsetAlignment()
  190. {
  191. return 16;
  192. }
  193. /// <summary>
  194. /// Queries host support for texture formats with BGRA component order (such as BGRA8).
  195. /// </summary>
  196. /// <returns>True if BGRA formats are supported, false otherwise</returns>
  197. bool QueryHostSupportsBgraFormat()
  198. {
  199. return true;
  200. }
  201. /// <summary>
  202. /// Queries host support for fragment shader ordering critical sections on the shader code.
  203. /// </summary>
  204. /// <returns>True if fragment shader interlock is supported, false otherwise</returns>
  205. bool QueryHostSupportsFragmentShaderInterlock()
  206. {
  207. return true;
  208. }
  209. /// <summary>
  210. /// Queries host support for fragment shader ordering scoped critical sections on the shader code.
  211. /// </summary>
  212. /// <returns>True if fragment shader ordering is supported, false otherwise</returns>
  213. bool QueryHostSupportsFragmentShaderOrderingIntel()
  214. {
  215. return false;
  216. }
  217. /// <summary>
  218. /// Queries host GPU geometry shader passthrough support.
  219. /// </summary>
  220. /// <returns>True if the GPU and driver supports geometry shader passthrough, false otherwise</returns>
  221. bool QueryHostSupportsGeometryShaderPassthrough()
  222. {
  223. return true;
  224. }
  225. /// <summary>
  226. /// Queries host support for readable images without a explicit format declaration on the shader.
  227. /// </summary>
  228. /// <returns>True if formatted image load is supported, false otherwise</returns>
  229. bool QueryHostSupportsImageLoadFormatted()
  230. {
  231. return true;
  232. }
  233. /// <summary>
  234. /// Queries host support for writes to Layer from vertex or tessellation shader stages.
  235. /// </summary>
  236. /// <returns>True if writes to layer from vertex or tessellation are supported, false otherwise</returns>
  237. bool QueryHostSupportsLayerVertexTessellation()
  238. {
  239. return true;
  240. }
  241. /// <summary>
  242. /// Queries host GPU non-constant texture offset support.
  243. /// </summary>
  244. /// <returns>True if the GPU and driver supports non-constant texture offsets, false otherwise</returns>
  245. bool QueryHostSupportsNonConstantTextureOffset()
  246. {
  247. return true;
  248. }
  249. /// <summary>
  250. /// Queries host GPU shader ballot support.
  251. /// </summary>
  252. /// <returns>True if the GPU and driver supports shader ballot, false otherwise</returns>
  253. bool QueryHostSupportsShaderBallot()
  254. {
  255. return true;
  256. }
  257. /// <summary>
  258. /// Queries host GPU support for signed normalized buffer texture formats.
  259. /// </summary>
  260. /// <returns>True if the GPU and driver supports the formats, false otherwise</returns>
  261. bool QueryHostSupportsSnormBufferTextureFormat()
  262. {
  263. return true;
  264. }
  265. /// <summary>
  266. /// Queries host GPU texture shadow LOD support.
  267. /// </summary>
  268. /// <returns>True if the GPU and driver supports texture shadow LOD, false otherwise</returns>
  269. bool QueryHostSupportsTextureShadowLod()
  270. {
  271. return true;
  272. }
  273. /// <summary>
  274. /// Queries host GPU shader viewport index output support.
  275. /// </summary>
  276. /// <returns>True if the GPU and driver supports shader viewport index output, false otherwise</returns>
  277. bool QueryHostSupportsViewportIndex()
  278. {
  279. return true;
  280. }
  281. /// <summary>
  282. /// Queries the point size from the GPU state, used when it is not explicitly set on the shader.
  283. /// </summary>
  284. /// <returns>Current point size</returns>
  285. float QueryPointSize()
  286. {
  287. return 1f;
  288. }
  289. /// <summary>
  290. /// Queries the state that indicates if the program point size should be explicitly set on the shader
  291. /// or read from the GPU state.
  292. /// </summary>
  293. /// <returns>True if the shader is expected to set the point size explicitly, false otherwise</returns>
  294. bool QueryProgramPointSize()
  295. {
  296. return true;
  297. }
  298. /// <summary>
  299. /// Queries sampler type information.
  300. /// </summary>
  301. /// <param name="handle">Texture handle</param>
  302. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  303. /// <returns>The sampler type value for the given handle</returns>
  304. SamplerType QuerySamplerType(int handle, int cbufSlot = -1)
  305. {
  306. return SamplerType.Texture2D;
  307. }
  308. /// <summary>
  309. /// Queries texture coordinate normalization information.
  310. /// </summary>
  311. /// <param name="handle">Texture handle</param>
  312. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  313. /// <returns>True if the coordinates are normalized, false otherwise</returns>
  314. bool QueryTextureCoordNormalized(int handle, int cbufSlot = -1)
  315. {
  316. return true;
  317. }
  318. /// <summary>
  319. /// Queries current primitive topology for geometry shaders.
  320. /// </summary>
  321. /// <returns>Current primitive topology</returns>
  322. InputTopology QueryPrimitiveTopology()
  323. {
  324. return InputTopology.Points;
  325. }
  326. /// <summary>
  327. /// Queries the tessellation evaluation shader primitive winding order.
  328. /// </summary>
  329. /// <returns>True if the primitive winding order is clockwise, false if counter-clockwise</returns>
  330. bool QueryTessCw()
  331. {
  332. return false;
  333. }
  334. /// <summary>
  335. /// Queries the tessellation evaluation shader abstract patch type.
  336. /// </summary>
  337. /// <returns>Abstract patch type</returns>
  338. TessPatchType QueryTessPatchType()
  339. {
  340. return TessPatchType.Triangles;
  341. }
  342. /// <summary>
  343. /// Queries the tessellation evaluation shader spacing between tessellated vertices of the patch.
  344. /// </summary>
  345. /// <returns>Spacing between tessellated vertices of the patch</returns>
  346. TessSpacing QueryTessSpacing()
  347. {
  348. return TessSpacing.EqualSpacing;
  349. }
  350. /// <summary>
  351. /// Queries texture format information, for shaders using image load or store.
  352. /// </summary>
  353. /// <remarks>
  354. /// This only returns non-compressed color formats.
  355. /// If the format of the texture is a compressed, depth or unsupported format, then a default value is returned.
  356. /// </remarks>
  357. /// <param name="handle">Texture handle</param>
  358. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  359. /// <returns>Color format of the non-compressed texture</returns>
  360. TextureFormat QueryTextureFormat(int handle, int cbufSlot = -1)
  361. {
  362. return TextureFormat.R8G8B8A8Unorm;
  363. }
  364. /// <summary>
  365. /// Queries depth mode information from the GPU state.
  366. /// </summary>
  367. /// <returns>True if current depth mode is -1 to 1, false if 0 to 1</returns>
  368. bool QueryTransformDepthMinusOneToOne()
  369. {
  370. return false;
  371. }
  372. /// <summary>
  373. /// Queries transform feedback enable state.
  374. /// </summary>
  375. /// <returns>True if the shader uses transform feedback, false otherwise</returns>
  376. bool QueryTransformFeedbackEnabled()
  377. {
  378. return false;
  379. }
  380. /// <summary>
  381. /// Queries the varying locations that should be written to the transform feedback buffer.
  382. /// </summary>
  383. /// <param name="bufferIndex">Index of the transform feedback buffer</param>
  384. /// <returns>Varying locations for the specified buffer</returns>
  385. ReadOnlySpan<byte> QueryTransformFeedbackVaryingLocations(int bufferIndex)
  386. {
  387. return ReadOnlySpan<byte>.Empty;
  388. }
  389. /// <summary>
  390. /// Queries the stride (in bytes) of the per vertex data written into the transform feedback buffer.
  391. /// </summary>
  392. /// <param name="bufferIndex">Index of the transform feedback buffer</param>
  393. /// <returns>Stride for the specified buffer</returns>
  394. int QueryTransformFeedbackStride(int bufferIndex)
  395. {
  396. return 0;
  397. }
  398. /// <summary>
  399. /// Queries if host state forces early depth testing.
  400. /// </summary>
  401. /// <returns>True if early depth testing is forced</returns>
  402. bool QueryEarlyZForce()
  403. {
  404. return false;
  405. }
  406. /// <summary>
  407. /// Queries if host state disables the viewport transform.
  408. /// </summary>
  409. /// <returns>True if the viewport transform is disabled</returns>
  410. bool QueryViewportTransformDisable()
  411. {
  412. return false;
  413. }
  414. /// <summary>
  415. /// Registers a texture used by the shader.
  416. /// </summary>
  417. /// <param name="handle">Texture handle word offset</param>
  418. /// <param name="cbufSlot">Constant buffer slot where the texture handle is located</param>
  419. void RegisterTexture(int handle, int cbufSlot)
  420. {
  421. // Only useful when recording information for a disk shader cache.
  422. }
  423. }
  424. }