IGpuAccessor.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. using Ryujinx.Graphics.Shader.CodeGen;
  2. using System;
  3. namespace Ryujinx.Graphics.Shader
  4. {
  5. /// <summary>
  6. /// GPU state access interface.
  7. /// </summary>
  8. public interface IGpuAccessor : ILogger
  9. {
  10. /// <summary>
  11. /// Reads data from the constant buffer 1.
  12. /// </summary>
  13. /// <param name="offset">Offset in bytes to read from</param>
  14. /// <returns>Value at the given offset</returns>
  15. uint ConstantBuffer1Read(int offset)
  16. {
  17. return 0;
  18. }
  19. /// <summary>
  20. /// Gets a span of the specified memory location, containing shader code.
  21. /// </summary>
  22. /// <param name="address">GPU virtual address of the data</param>
  23. /// <param name="minimumSize">Minimum size that the returned span may have</param>
  24. /// <returns>Span of the memory location</returns>
  25. ReadOnlySpan<ulong> GetCode(ulong address, int minimumSize);
  26. /// <summary>
  27. /// Gets the binding number of a constant buffer.
  28. /// </summary>
  29. /// <param name="index">Constant buffer index</param>
  30. /// <returns>Binding number</returns>
  31. SetBindingPair CreateConstantBufferBinding(int index);
  32. /// <summary>
  33. /// Gets the binding number of an image.
  34. /// </summary>
  35. /// <param name="count">For array of images, the number of elements of the array, otherwise it should be 1</param>
  36. /// <param name="isBuffer">Indicates if the image is a buffer image</param>
  37. /// <returns>Binding number</returns>
  38. SetBindingPair CreateImageBinding(int count, bool isBuffer);
  39. /// <summary>
  40. /// Gets the binding number of a storage buffer.
  41. /// </summary>
  42. /// <param name="index">Storage buffer index</param>
  43. /// <returns>Binding number</returns>
  44. SetBindingPair CreateStorageBufferBinding(int index);
  45. /// <summary>
  46. /// Gets the binding number of a texture.
  47. /// </summary>
  48. /// <param name="count">For array of textures, the number of elements of the array, otherwise it should be 1</param>
  49. /// <param name="isBuffer">Indicates if the texture is a buffer texture</param>
  50. /// <returns>Binding number</returns>
  51. SetBindingPair CreateTextureBinding(int count, bool isBuffer);
  52. /// <summary>
  53. /// Gets the set index for an additional set, or -1 if there's no extra set available.
  54. /// </summary>
  55. /// <returns>Extra set index, or -1 if not available</returns>
  56. int CreateExtraSet()
  57. {
  58. return -1;
  59. }
  60. /// <summary>
  61. /// Queries Local Size X for compute shaders.
  62. /// </summary>
  63. /// <returns>Local Size X</returns>
  64. int QueryComputeLocalSizeX()
  65. {
  66. return 1;
  67. }
  68. /// <summary>
  69. /// Queries Local Size Y for compute shaders.
  70. /// </summary>
  71. /// <returns>Local Size Y</returns>
  72. int QueryComputeLocalSizeY()
  73. {
  74. return 1;
  75. }
  76. /// <summary>
  77. /// Queries Local Size Z for compute shaders.
  78. /// </summary>
  79. /// <returns>Local Size Z</returns>
  80. int QueryComputeLocalSizeZ()
  81. {
  82. return 1;
  83. }
  84. /// <summary>
  85. /// Queries Local Memory size in bytes for compute shaders.
  86. /// </summary>
  87. /// <returns>Local Memory size in bytes</returns>
  88. int QueryComputeLocalMemorySize()
  89. {
  90. return 0x1000;
  91. }
  92. /// <summary>
  93. /// Queries Shared Memory size in bytes for compute shaders.
  94. /// </summary>
  95. /// <returns>Shared Memory size in bytes</returns>
  96. int QueryComputeSharedMemorySize()
  97. {
  98. return 0xc000;
  99. }
  100. /// <summary>
  101. /// Queries Constant Buffer usage information.
  102. /// </summary>
  103. /// <returns>A mask where each bit set indicates a bound constant buffer</returns>
  104. uint QueryConstantBufferUse()
  105. {
  106. return 0;
  107. }
  108. /// <summary>
  109. /// Queries specialized GPU graphics state that the shader depends on.
  110. /// </summary>
  111. /// <returns>GPU graphics state</returns>
  112. GpuGraphicsState QueryGraphicsState()
  113. {
  114. return new GpuGraphicsState(
  115. false,
  116. InputTopology.Points,
  117. false,
  118. TessPatchType.Triangles,
  119. TessSpacing.EqualSpacing,
  120. false,
  121. false,
  122. false,
  123. false,
  124. false,
  125. 1f,
  126. AlphaTestOp.Always,
  127. 0f,
  128. default,
  129. true,
  130. default,
  131. false,
  132. false,
  133. false,
  134. false);
  135. }
  136. /// <summary>
  137. /// Queries whenever the current draw has written the base vertex and base instance into Constant Buffer 0.
  138. /// </summary>
  139. /// <returns>True if the shader translator can assume that the constant buffer contains the base IDs, false otherwise</returns>
  140. bool QueryHasConstantBufferDrawParameters()
  141. {
  142. return false;
  143. }
  144. /// <summary>
  145. /// Queries whenever the current draw uses unaligned storage buffer addresses.
  146. /// </summary>
  147. /// <returns>True if any storage buffer address is not aligned to 16 bytes, false otherwise</returns>
  148. bool QueryHasUnalignedStorageBuffer()
  149. {
  150. return false;
  151. }
  152. /// <summary>
  153. /// Queries host's gather operation precision bits for biasing their coordinates. Zero means no bias.
  154. /// </summary>
  155. /// <returns>Bits of gather operation precision to use for coordinate bias</returns>
  156. int QueryHostGatherBiasPrecision()
  157. {
  158. return 0;
  159. }
  160. /// <summary>
  161. /// Queries host about whether to reduce precision to improve performance.
  162. /// </summary>
  163. /// <returns>True if precision is limited to vertex position, false otherwise</returns>
  164. bool QueryHostReducedPrecision()
  165. {
  166. return false;
  167. }
  168. /// <summary>
  169. /// Queries host about the presence of the FrontFacing built-in variable bug.
  170. /// </summary>
  171. /// <returns>True if the bug is present on the host device used, false otherwise</returns>
  172. bool QueryHostHasFrontFacingBug()
  173. {
  174. return false;
  175. }
  176. /// <summary>
  177. /// Queries host about the presence of the vector indexing bug.
  178. /// </summary>
  179. /// <returns>True if the bug is present on the host device used, false otherwise</returns>
  180. bool QueryHostHasVectorIndexingBug()
  181. {
  182. return false;
  183. }
  184. /// <summary>
  185. /// Queries host storage buffer alignment required.
  186. /// </summary>
  187. /// <returns>Host storage buffer alignment in bytes</returns>
  188. int QueryHostStorageBufferOffsetAlignment()
  189. {
  190. return 16;
  191. }
  192. /// <summary>
  193. /// Queries host shader subgroup size.
  194. /// </summary>
  195. /// <returns>Host shader subgroup size in invocations</returns>
  196. int QueryHostSubgroupSize()
  197. {
  198. return 32;
  199. }
  200. /// <summary>
  201. /// Queries host support for texture formats with BGRA component order (such as BGRA8).
  202. /// </summary>
  203. /// <returns>True if BGRA formats are supported, false otherwise</returns>
  204. bool QueryHostSupportsBgraFormat()
  205. {
  206. return true;
  207. }
  208. /// <summary>
  209. /// Queries host support for fragment shader ordering critical sections on the shader code.
  210. /// </summary>
  211. /// <returns>True if fragment shader interlock is supported, false otherwise</returns>
  212. bool QueryHostSupportsFragmentShaderInterlock()
  213. {
  214. return true;
  215. }
  216. /// <summary>
  217. /// Queries host support for fragment shader ordering scoped critical sections on the shader code.
  218. /// </summary>
  219. /// <returns>True if fragment shader ordering is supported, false otherwise</returns>
  220. bool QueryHostSupportsFragmentShaderOrderingIntel()
  221. {
  222. return false;
  223. }
  224. /// <summary>
  225. /// Queries host GPU geometry shader support.
  226. /// </summary>
  227. /// <returns>True if the GPU and driver supports geometry shaders, false otherwise</returns>
  228. bool QueryHostSupportsGeometryShader()
  229. {
  230. return true;
  231. }
  232. /// <summary>
  233. /// Queries host GPU geometry shader passthrough support.
  234. /// </summary>
  235. /// <returns>True if the GPU and driver supports geometry shader passthrough, false otherwise</returns>
  236. bool QueryHostSupportsGeometryShaderPassthrough()
  237. {
  238. return true;
  239. }
  240. /// <summary>
  241. /// Queries host support for readable images without a explicit format declaration on the shader.
  242. /// </summary>
  243. /// <returns>True if formatted image load is supported, false otherwise</returns>
  244. bool QueryHostSupportsImageLoadFormatted()
  245. {
  246. return true;
  247. }
  248. /// <summary>
  249. /// Queries host support for writes to the layer from vertex or tessellation shader stages.
  250. /// </summary>
  251. /// <returns>True if writes to the layer from vertex or tessellation are supported, false otherwise</returns>
  252. bool QueryHostSupportsLayerVertexTessellation()
  253. {
  254. return true;
  255. }
  256. /// <summary>
  257. /// Queries host GPU non-constant texture offset support.
  258. /// </summary>
  259. /// <returns>True if the GPU and driver supports non-constant texture offsets, false otherwise</returns>
  260. bool QueryHostSupportsNonConstantTextureOffset()
  261. {
  262. return true;
  263. }
  264. /// <summary>
  265. /// Queries host support scaled vertex formats, where a integer value is converted to floating-point.
  266. /// </summary>
  267. /// <returns>True if the host support scaled vertex formats, false otherwise</returns>
  268. bool QueryHostSupportsScaledVertexFormats()
  269. {
  270. return true;
  271. }
  272. /// <summary>
  273. /// Queries host API support for separate textures and samplers.
  274. /// </summary>
  275. /// <returns>True if the API supports samplers and textures to be combined on the shader, false otherwise</returns>
  276. bool QueryHostSupportsSeparateSampler()
  277. {
  278. return true;
  279. }
  280. /// <summary>
  281. /// Queries host GPU shader ballot support.
  282. /// </summary>
  283. /// <returns>True if the GPU and driver supports shader ballot, false otherwise</returns>
  284. bool QueryHostSupportsShaderBallot()
  285. {
  286. return true;
  287. }
  288. /// <summary>
  289. /// Queries host GPU shader support for barrier instructions on divergent control flow paths.
  290. /// </summary>
  291. /// <returns>True if the GPU supports barriers on divergent control flow paths, false otherwise</returns>
  292. bool QueryHostSupportsShaderBarrierDivergence()
  293. {
  294. return true;
  295. }
  296. /// <summary>
  297. /// Queries host GPU support for 64-bit floating point (double precision) operations on the shader.
  298. /// </summary>
  299. /// <returns>True if the GPU and driver supports double operations, false otherwise</returns>
  300. bool QueryHostSupportsShaderFloat64()
  301. {
  302. return true;
  303. }
  304. /// <summary>
  305. /// Queries host GPU support for signed normalized buffer texture formats.
  306. /// </summary>
  307. /// <returns>True if the GPU and driver supports the formats, false otherwise</returns>
  308. bool QueryHostSupportsSnormBufferTextureFormat()
  309. {
  310. return true;
  311. }
  312. /// <summary>
  313. /// Queries host GPU texture gather with multiple offsets support.
  314. /// </summary>
  315. /// <returns>True if the GPU and driver supports texture gather offsets, false otherwise</returns>
  316. bool QueryHostSupportsTextureGatherOffsets()
  317. {
  318. return true;
  319. }
  320. /// <summary>
  321. /// Queries host GPU texture shadow LOD support.
  322. /// </summary>
  323. /// <returns>True if the GPU and driver supports texture shadow LOD, false otherwise</returns>
  324. bool QueryHostSupportsTextureShadowLod()
  325. {
  326. return true;
  327. }
  328. /// <summary>
  329. /// Queries host GPU transform feedback support.
  330. /// </summary>
  331. /// <returns>True if the GPU and driver supports transform feedback, false otherwise</returns>
  332. bool QueryHostSupportsTransformFeedback()
  333. {
  334. return true;
  335. }
  336. /// <summary>
  337. /// Queries host support for writes to the viewport index from vertex or tessellation shader stages.
  338. /// </summary>
  339. /// <returns>True if writes to the viewport index from vertex or tessellation are supported, false otherwise</returns>
  340. bool QueryHostSupportsViewportIndexVertexTessellation()
  341. {
  342. return true;
  343. }
  344. /// <summary>
  345. /// Queries host GPU shader viewport mask output support.
  346. /// </summary>
  347. /// <returns>True if the GPU and driver supports shader viewport mask output, false otherwise</returns>
  348. bool QueryHostSupportsViewportMask()
  349. {
  350. return true;
  351. }
  352. /// <summary>
  353. /// Queries whether the host supports depth clip control.
  354. /// </summary>
  355. /// <returns>True if the GPU and driver supports depth clip control, false otherwise</returns>
  356. bool QueryHostSupportsDepthClipControl()
  357. {
  358. return true;
  359. }
  360. /// <summary>
  361. /// Gets the maximum number of samplers that the bound texture pool may have.
  362. /// </summary>
  363. /// <returns>Maximum amount of samplers that the pool may have</returns>
  364. int QuerySamplerArrayLengthFromPool();
  365. /// <summary>
  366. /// Queries sampler type information.
  367. /// </summary>
  368. /// <param name="handle">Texture handle</param>
  369. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  370. /// <returns>The sampler type value for the given handle</returns>
  371. SamplerType QuerySamplerType(int handle, int cbufSlot = -1)
  372. {
  373. return SamplerType.Texture2D;
  374. }
  375. /// <summary>
  376. /// Gets the size in bytes of a bound constant buffer for the current shader stage.
  377. /// </summary>
  378. /// <param name="slot">The number of the constant buffer to get the size from</param>
  379. /// <returns>Size in bytes</returns>
  380. int QueryTextureArrayLengthFromBuffer(int slot);
  381. /// <summary>
  382. /// Gets the maximum number of textures that the bound texture pool may have.
  383. /// </summary>
  384. /// <returns>Maximum amount of textures that the pool may have</returns>
  385. int QueryTextureArrayLengthFromPool();
  386. /// <summary>
  387. /// Queries texture coordinate normalization information.
  388. /// </summary>
  389. /// <param name="handle">Texture handle</param>
  390. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  391. /// <returns>True if the coordinates are normalized, false otherwise</returns>
  392. bool QueryTextureCoordNormalized(int handle, int cbufSlot = -1)
  393. {
  394. return true;
  395. }
  396. /// <summary>
  397. /// Queries texture format information, for shaders using image load or store.
  398. /// </summary>
  399. /// <remarks>
  400. /// This only returns non-compressed color formats.
  401. /// If the format of the texture is a compressed, depth or unsupported format, then a default value is returned.
  402. /// </remarks>
  403. /// <param name="handle">Texture handle</param>
  404. /// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
  405. /// <returns>Color format of the non-compressed texture</returns>
  406. TextureFormat QueryTextureFormat(int handle, int cbufSlot = -1)
  407. {
  408. return TextureFormat.R8G8B8A8Unorm;
  409. }
  410. /// <summary>
  411. /// Queries transform feedback enable state.
  412. /// </summary>
  413. /// <returns>True if the shader uses transform feedback, false otherwise</returns>
  414. bool QueryTransformFeedbackEnabled()
  415. {
  416. return false;
  417. }
  418. /// <summary>
  419. /// Queries the varying locations that should be written to the transform feedback buffer.
  420. /// </summary>
  421. /// <param name="bufferIndex">Index of the transform feedback buffer</param>
  422. /// <returns>Varying locations for the specified buffer</returns>
  423. ReadOnlySpan<byte> QueryTransformFeedbackVaryingLocations(int bufferIndex)
  424. {
  425. return ReadOnlySpan<byte>.Empty;
  426. }
  427. /// <summary>
  428. /// Queries the stride (in bytes) of the per vertex data written into the transform feedback buffer.
  429. /// </summary>
  430. /// <param name="bufferIndex">Index of the transform feedback buffer</param>
  431. /// <returns>Stride for the specified buffer</returns>
  432. int QueryTransformFeedbackStride(int bufferIndex)
  433. {
  434. return 0;
  435. }
  436. /// <summary>
  437. /// Registers a texture used by the shader.
  438. /// </summary>
  439. /// <param name="handle">Texture handle word offset</param>
  440. /// <param name="cbufSlot">Constant buffer slot where the texture handle is located</param>
  441. void RegisterTexture(int handle, int cbufSlot)
  442. {
  443. // Only useful when recording information for a disk shader cache.
  444. }
  445. }
  446. }