BsRenderAPICapabilities.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "RenderAPI/BsGpuProgram.h"
  6. #include <cstdint>
  7. #define CAPS_CATEGORY_SIZE INT64_C(8)
  8. #define BS_CAPS_BITSHIFT (INT64_C(64) - CAPS_CATEGORY_SIZE)
  9. #define CAPS_CATEGORY_MASK (((INT64_C(1) << CAPS_CATEGORY_SIZE) - INT64_C(1)) << BS_CAPS_BITSHIFT)
  10. #define BS_CAPS_VALUE(cat, val) ((cat << BS_CAPS_BITSHIFT) | (INT64_C(1) << val))
  11. #define BS_MAX_BOUND_VERTEX_BUFFERS 16
  12. namespace bs
  13. {
  14. /** @addtogroup RenderAPI-Internal
  15. * @{
  16. */
  17. /** Categories of render API capabilities. */
  18. enum CapabilitiesCategory : UINT64
  19. {
  20. CAPS_CATEGORY_COMMON = 0,
  21. CAPS_CATEGORY_GL = 1,
  22. CAPS_CATEGORY_D3D11 = 2,
  23. CAPS_CATEGORY_VULKAN = 3,
  24. CAPS_CATEGORY_COUNT = 32 /**< Maximum number of categories. */
  25. };
  26. /** Enum describing the different hardware capabilities we can check for. */
  27. enum Capabilities : UINT64
  28. {
  29. RSC_TEXTURE_COMPRESSION_BC = BS_CAPS_VALUE(CAPS_CATEGORY_COMMON, 0), /**< Supports compressed textures in the BC formats. */
  30. RSC_TEXTURE_COMPRESSION_ETC2 = BS_CAPS_VALUE(CAPS_CATEGORY_COMMON, 1), /**< Supports compressed textures in the ETC2 and EAC format. */
  31. RSC_TEXTURE_COMPRESSION_ASTC = BS_CAPS_VALUE(CAPS_CATEGORY_COMMON, 2), /**< Supports compressed textures in the ASTC format. */
  32. RSC_GEOMETRY_PROGRAM = BS_CAPS_VALUE(CAPS_CATEGORY_COMMON, 3), /**< Supports hardware geometry programs. */
  33. RSC_TESSELLATION_PROGRAM = BS_CAPS_VALUE(CAPS_CATEGORY_COMMON, 4), /**< Supports hardware tessellation programs. */
  34. RSC_COMPUTE_PROGRAM = BS_CAPS_VALUE(CAPS_CATEGORY_COMMON, 5), /**< Supports hardware compute programs. */
  35. };
  36. /** Holds data about render system driver version. */
  37. struct BS_CORE_EXPORT DriverVersion
  38. {
  39. DriverVersion() { }
  40. /** Returns the driver version as a single string. */
  41. String toString() const
  42. {
  43. StringStream str;
  44. str << major << "." << minor << "." << release << "." << build;
  45. return str.str();
  46. }
  47. /** Parses a string in the major.minor.release.build format and stores the version numbers. */
  48. void fromString(const String& versionString)
  49. {
  50. Vector<bs::String> tokens = StringUtil::split(versionString, ".");
  51. if(!tokens.empty())
  52. {
  53. major = parseINT32(tokens[0]);
  54. if (tokens.size() > 1)
  55. minor = parseINT32(tokens[1]);
  56. if (tokens.size() > 2)
  57. release = parseINT32(tokens[2]);
  58. if (tokens.size() > 3)
  59. build = parseINT32(tokens[3]);
  60. }
  61. }
  62. INT32 major = 0;
  63. INT32 minor = 0;
  64. INT32 release = 0;
  65. INT32 build = 0;
  66. };
  67. /** Types of GPU vendors. */
  68. enum GPUVendor
  69. {
  70. GPU_UNKNOWN = 0,
  71. GPU_NVIDIA = 1,
  72. GPU_AMD = 2,
  73. GPU_INTEL = 3,
  74. GPU_VENDOR_COUNT = 4
  75. };
  76. /**
  77. * Holds information about render hardware and driver capabilities and allows you to easily set and query those
  78. * capabilities.
  79. */
  80. class BS_CORE_EXPORT RenderAPICapabilities
  81. {
  82. public:
  83. RenderAPICapabilities ();
  84. virtual ~RenderAPICapabilities ();
  85. /** Sets the current driver version. */
  86. void setDriverVersion(const DriverVersion& version)
  87. {
  88. mDriverVersion = version;
  89. }
  90. /** Returns current driver version. */
  91. DriverVersion getDriverVersion() const
  92. {
  93. return mDriverVersion;
  94. }
  95. /** Returns vendor of the currently used GPU. */
  96. GPUVendor getVendor() const
  97. {
  98. return mVendor;
  99. }
  100. /** Sets the GPU vendor. */
  101. void setVendor(GPUVendor v)
  102. {
  103. mVendor = v;
  104. }
  105. /** Parses a vendor string and returns an enum with the vendor if parsed succesfully. */
  106. static GPUVendor vendorFromString(const String& vendorString);
  107. /** Converts a vendor enum to a string. */
  108. static String vendorToString(GPUVendor v);
  109. /** Sets the maximum number of texture units per pipeline stage. */
  110. void setNumTextureUnits(GpuProgramType type, UINT16 num)
  111. {
  112. mNumTextureUnitsPerStage[type] = num;
  113. }
  114. /** Sets the maximum number of texture units in all pipeline stages. */
  115. void setNumCombinedTextureUnits(UINT16 num)
  116. {
  117. mNumCombinedTextureUnits = num;
  118. }
  119. /** Sets the maximum number of load-store texture units per pipeline stage. */
  120. void setNumLoadStoreTextureUnits(GpuProgramType type, UINT16 num)
  121. {
  122. mNumLoadStoreTextureUnitsPerStage[type] = num;
  123. }
  124. /** Sets the maximum number of load-store texture units in all pipeline stages. */
  125. void setNumCombinedLoadStoreTextureUnits(UINT16 num)
  126. {
  127. mNumCombinedLoadStoreTextureUnits = num;
  128. }
  129. /** Sets the maximum number of GPU param block buffers per pipeline stage. */
  130. void setNumGpuParamBlockBuffers(GpuProgramType type, UINT16 num)
  131. {
  132. mNumGpuParamBlocksPerStage[type] = num;
  133. }
  134. /** Sets the maximum number of GPU param block buffers in all pipeline stages. */
  135. void setNumCombinedGpuParamBlockBuffers(UINT16 num)
  136. {
  137. mNumCombinedUniformBlocks = num;
  138. }
  139. /** Sets maximum number of bound vertex buffers. */
  140. void setMaxBoundVertexBuffers(UINT32 num)
  141. {
  142. mMaxBoundVertexBuffers = num;
  143. }
  144. /** Sets maximum number of simultaneously set render targets. */
  145. void setNumMultiRenderTargets(UINT16 num)
  146. {
  147. mNumMultiRenderTargets = num;
  148. }
  149. /** Returns the number of texture units supported per pipeline stage. */
  150. UINT16 getNumTextureUnits(GpuProgramType type) const
  151. {
  152. auto iterFind = mNumTextureUnitsPerStage.find(type);
  153. if(iterFind != mNumTextureUnitsPerStage.end())
  154. return iterFind->second;
  155. else
  156. return 0;
  157. }
  158. /** Returns the number of texture units supported in all pipeline stages. */
  159. UINT16 getNumCombinedTextureUnits() const
  160. {
  161. return mNumCombinedTextureUnits;
  162. }
  163. /** Returns the number of load-store texture units supported per pipeline stage. */
  164. UINT16 getNumLoadStoreTextureUnits(GpuProgramType type) const
  165. {
  166. auto iterFind = mNumLoadStoreTextureUnitsPerStage.find(type);
  167. if (iterFind != mNumLoadStoreTextureUnitsPerStage.end())
  168. return iterFind->second;
  169. else
  170. return 0;
  171. }
  172. /** Returns the number of load-store texture units supported in all pipeline stages. */
  173. UINT16 getNumCombinedLoadStoreTextureUnits() const
  174. {
  175. return mNumCombinedLoadStoreTextureUnits;
  176. }
  177. /** Returns the maximum number of bound GPU program param block buffers per pipeline stage. */
  178. UINT16 getNumGpuParamBlockBuffers(GpuProgramType type) const
  179. {
  180. auto iterFind = mNumGpuParamBlocksPerStage.find(type);
  181. if(iterFind != mNumGpuParamBlocksPerStage.end())
  182. return iterFind->second;
  183. else
  184. return 0;
  185. }
  186. /** Returns the maximum number of bound GPU program param block buffers in all pipeline stages. */
  187. UINT16 getNumCombinedGpuParamBlockBuffers() const
  188. {
  189. return mNumCombinedUniformBlocks;
  190. }
  191. /** Returns the maximum number of vertex buffers that can be bound at once. */
  192. UINT32 getMaxBoundVertexBuffers() const
  193. {
  194. return mMaxBoundVertexBuffers;
  195. }
  196. /** Returns the maximum number of render targets we can render to simultaneously. */
  197. UINT16 getNumMultiRenderTargets() const
  198. {
  199. return mNumMultiRenderTargets;
  200. }
  201. /** Sets a capability flag indicating this capability is supported. */
  202. void setCapability(const Capabilities c)
  203. {
  204. UINT64 index = (CAPS_CATEGORY_MASK & c) >> BS_CAPS_BITSHIFT;
  205. mCapabilities[index] |= (c & ~CAPS_CATEGORY_MASK);
  206. }
  207. /** Remove a capability flag indicating this capability is not supported (default). */
  208. void unsetCapability(const Capabilities c)
  209. {
  210. UINT64 index = (CAPS_CATEGORY_MASK & c) >> BS_CAPS_BITSHIFT;
  211. mCapabilities[index] &= (~c | CAPS_CATEGORY_MASK);
  212. }
  213. /** Checks is the specified capability supported. */
  214. bool hasCapability(const Capabilities c) const
  215. {
  216. UINT64 index = (CAPS_CATEGORY_MASK & c) >> BS_CAPS_BITSHIFT;
  217. return (mCapabilities[index] & (c & ~CAPS_CATEGORY_MASK)) != 0;
  218. }
  219. /** Adds a shader profile to the list of render-system specific supported profiles. */
  220. void addShaderProfile(const String& profile)
  221. {
  222. mSupportedShaderProfiles.insert(profile);
  223. }
  224. /** Returns true if the provided profile is supported. */
  225. bool isShaderProfileSupported(const String& profile) const
  226. {
  227. return (mSupportedShaderProfiles.end() != mSupportedShaderProfiles.find(profile));
  228. }
  229. /** Returns a set of all supported shader profiles. */
  230. const Set<String>& getSupportedShaderProfiles() const
  231. {
  232. return mSupportedShaderProfiles;
  233. }
  234. /** Sets the current GPU device name. */
  235. void setDeviceName(const String& name)
  236. {
  237. mDeviceName = name;
  238. }
  239. /** Gets the current GPU device name. */
  240. String getDeviceName() const
  241. {
  242. return mDeviceName;
  243. }
  244. /** Sets the number of vertices a single geometry program run can emit. */
  245. void setGeometryProgramNumOutputVertices(int numOutputVertices)
  246. {
  247. mGeometryProgramNumOutputVertices = numOutputVertices;
  248. }
  249. /** Gets the number of vertices a single geometry program run can emit. */
  250. int getGeometryProgramNumOutputVertices(void) const
  251. {
  252. return mGeometryProgramNumOutputVertices;
  253. }
  254. /** Get the identifier of the render system from which these capabilities were generated. */
  255. StringID getRenderAPIName() const
  256. {
  257. return mRenderAPIName;
  258. }
  259. /** Set the identifier of the render system from which these capabilities were generated. */
  260. void setRenderAPIName(const StringID& rs)
  261. {
  262. mRenderAPIName = rs;
  263. }
  264. private:
  265. /** Initializes vendor enum -> vendor name mappings. */
  266. static void initVendorStrings();
  267. private:
  268. static Vector<String> msGPUVendorStrings;
  269. DriverVersion mDriverVersion;
  270. GPUVendor mVendor = GPU_UNKNOWN;
  271. // The number of texture units available per stage
  272. Map<GpuProgramType, UINT16> mNumTextureUnitsPerStage;
  273. // Total number of texture units available
  274. UINT16 mNumCombinedTextureUnits = 0;
  275. // The number of uniform blocks available per stage
  276. Map<GpuProgramType, UINT16> mNumGpuParamBlocksPerStage;
  277. // Total number of uniform blocks available
  278. UINT16 mNumCombinedUniformBlocks = 0;
  279. // The number of load-store texture unitss available per stage
  280. Map<GpuProgramType, UINT16> mNumLoadStoreTextureUnitsPerStage;
  281. // Total number of load-store texture units available
  282. UINT16 mNumCombinedLoadStoreTextureUnits = 0;
  283. // Maximum number of vertex buffers we can bind at once
  284. UINT32 mMaxBoundVertexBuffers = 0;
  285. // Stores the capabilities flags.
  286. UINT32 mCapabilities[CAPS_CATEGORY_COUNT];
  287. // The name of the device as reported by the render system
  288. String mDeviceName;
  289. // The identifier associated with the render API for which these capabilities are valid
  290. StringID mRenderAPIName;
  291. // The number of simultaneous render targets supported
  292. UINT16 mNumMultiRenderTargets = 0;
  293. // The number of vertices a geometry program can emit in a single run
  294. UINT32 mGeometryProgramNumOutputVertices = 0;
  295. // The list of supported shader profiles
  296. Set<String> mSupportedShaderProfiles;
  297. };
  298. /** @} */
  299. }