IGpuAccessor.cs 12 KB

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