IGpuAccessor.cs 17 KB

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