Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
12 KiB

  1. //===== Copyright (c) 1996-2008, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef HARDWARECONFIG_H
  9. #define HARDWARECONFIG_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "materialsystem/imaterialsystemhardwareconfig.h"
  14. #include "IHardwareConfigInternal.h"
  15. #include "bitmap/imageformat.h"
  16. #include "materialsystem/imaterialsystem.h"
  17. //-----------------------------------------------------------------------------
  18. // Forward declarations
  19. //-----------------------------------------------------------------------------
  20. struct ShaderDeviceInfo_t;
  21. //-----------------------------------------------------------------------------
  22. // Vendor IDs sometimes needed for vendor-specific code
  23. //-----------------------------------------------------------------------------
  24. #define VENDORID_NVIDIA 0x10DE
  25. #define VENDORID_ATI 0x1002
  26. #define VENDORID_INTEL 0x8086
  27. //-----------------------------------------------------------------------------
  28. // ShaderAPI constants
  29. //-----------------------------------------------------------------------------
  30. enum
  31. {
  32. #if defined( DX_TO_GL_ABSTRACTION )
  33. MAXUSERCLIPPLANES = 2,
  34. #if defined( OSX )
  35. MAX_NUM_LIGHTS = 2,
  36. #else
  37. MAX_NUM_LIGHTS = 4,
  38. #endif
  39. #else
  40. MAXUSERCLIPPLANES = 6,
  41. MAX_NUM_LIGHTS = 4,
  42. #endif
  43. MAX_OUTPUTS = 3,
  44. #if defined( _PS3 )
  45. MAX_FRAGMENT_PROGRAM_CONSTS = 96,
  46. #endif
  47. };
  48. //-----------------------------------------------------------------------------
  49. // Hardware caps structures
  50. //-----------------------------------------------------------------------------
  51. enum CompressedTextureState_t
  52. {
  53. COMPRESSED_TEXTURES_ON,
  54. COMPRESSED_TEXTURES_OFF,
  55. COMPRESSED_TEXTURES_NOT_INITIALIZED
  56. };
  57. struct HardwareCaps_t : public MaterialAdapterInfo_t
  58. {
  59. // *****************************NOTE*********************************************
  60. // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
  61. // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
  62. // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
  63. // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
  64. // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
  65. // *****************************NOTE*********************************************
  66. //
  67. // NOTE: Texture stages are an obsolete concept; used by fixed-function hardware
  68. // Samplers are dx9+, indicating how many textures we can simultaneously bind
  69. // In Dx8, samplers didn't exist and texture stages were used to indicate the
  70. // number of simultaneously bound textures; we'll emulate that by slamming
  71. // the number of samplers to == the number of texture stages.
  72. CompressedTextureState_t m_SupportsCompressedTextures;
  73. VertexCompressionType_t m_SupportsCompressedVertices;
  74. int m_NumSamplers;
  75. int m_NumVertexSamplers;
  76. int m_nMaxAnisotropy;
  77. int m_MaxTextureWidth;
  78. int m_MaxTextureHeight;
  79. int m_MaxTextureDepth;
  80. int m_MaxTextureAspectRatio;
  81. int m_MaxPrimitiveCount;
  82. int m_NumPixelShaderConstants;
  83. int m_NumBooleanPixelShaderConstants;
  84. int m_NumIntegerPixelShaderConstants;
  85. int m_NumVertexShaderConstants;
  86. int m_NumBooleanVertexShaderConstants;
  87. int m_NumIntegerVertexShaderConstants;
  88. int m_TextureMemorySize;
  89. int m_MaxNumLights;
  90. int m_MaxVertexShaderBlendMatrices;
  91. int m_MaxUserClipPlanes;
  92. HDRType_t m_HDRType;
  93. char m_pShaderDLL[32];
  94. ImageFormat m_ShadowDepthTextureFormat;
  95. ImageFormat m_HighPrecisionShadowDepthTextureFormat;
  96. ImageFormat m_NullTextureFormat;
  97. int m_nMaxVertexTextureDimension;
  98. unsigned long m_AlphaToCoverageState; // State to ping to toggle Alpha To Coverage (vendor-dependent)
  99. unsigned long m_AlphaToCoverageEnableValue; // Value to set above state to turn on Alpha To Coverage (vendor-dependent)
  100. unsigned long m_AlphaToCoverageDisableValue; // Value to set above state to turn off Alpha To Coverage (vendor-dependent)
  101. int m_nMaxViewports;
  102. float m_flMinGammaControlPoint;
  103. float m_flMaxGammaControlPoint;
  104. int m_nGammaControlPointCount;
  105. int m_MaxVertexShader30InstructionSlots;
  106. int m_MaxPixelShader30InstructionSlots;
  107. int m_MaxSimultaneousRenderTargets;
  108. bool m_bDeviceOk : 1;
  109. bool m_HasSetDeviceGammaRamp : 1;
  110. bool m_SupportsPixelShaders_2_b : 1;
  111. bool m_SupportsShaderModel_3_0 : 1;
  112. bool m_bSupportsAnisotropicFiltering : 1;
  113. bool m_bSupportsMagAnisotropicFiltering : 1;
  114. bool m_bSupportsVertexTextures : 1;
  115. bool m_ZBiasAndSlopeScaledDepthBiasSupported : 1;
  116. bool m_SupportsMipmappedCubemaps : 1;
  117. bool m_PreferDynamicTextures : 1;
  118. bool m_SupportsSRGB : 1;
  119. bool m_UseFastClipping : 1;
  120. bool m_bNeedsATICentroidHack : 1;
  121. bool m_bDisableShaderOptimizations : 1;
  122. bool m_bSupportsStreamOffset : 1;
  123. bool m_bFogColorSpecifiedInLinearSpace : 1;
  124. bool m_bFogColorAlwaysLinearSpace : 1;
  125. bool m_bSupportsAlphaToCoverage : 1;
  126. bool m_bSupportsShadowDepthTextures : 1;
  127. bool m_bSupportsFetch4 : 1;
  128. bool m_bSoftwareVertexProcessing : 1;
  129. bool m_bScissorSupported : 1;
  130. bool m_bSupportsFloat32RenderTargets : 1;
  131. bool m_bSupportsBorderColor : 1;
  132. bool m_bDX10Card : 1; // Indicates DX10 part with performant vertex textures running DX9 path
  133. bool m_bDX10Blending : 1; // Indicates DX10 part that does DX10 blending (but may not have performant vertex textures, such as Intel parts)
  134. bool m_bSupportsTessellation : 1;
  135. bool m_bPreferZPrepass : 1;
  136. bool m_bSuppressPixelShaderCentroidHackFixup : 1;
  137. bool m_bPreferTexturesInHWMemory : 1;
  138. bool m_bPreferHardwareSync : 1;
  139. bool m_bUnsupported : 1;
  140. bool m_bSupportsStaticControlFlow : 1; // Useful on OpenGL, where we have a mix of support...
  141. bool m_FakeSRGBWrite : 1; // Gotta do this on OpenGL. Mostly hidden, but some high level code needs to know
  142. bool m_CanDoSRGBReadFromRTs : 1; // Gotta do this on OpenGL. Mostly hidden, but some high level code needs to know
  143. bool m_bSupportsGLMixedSizeTargets : 1; // on OpenGL, are mixed size depth buffers supported - aka ARB_framebuffer_object
  144. bool m_bSupportsSRGBDecode : 1; // Supports GL_EXT_texture_sRGB_decode, which allows us to toggle sRGB read D3D-style
  145. bool m_bSupportsCascadedShadowMapping : 1;
  146. bool m_bSupportsRESZ : 1;
  147. bool m_bSupportsINTZ : 1;
  148. HDRType_t m_MaxHDRType;
  149. uint8 m_nCSMQuality;
  150. };
  151. //-----------------------------------------------------------------------------
  152. // Contains the hardware configuration for the current device
  153. //-----------------------------------------------------------------------------
  154. class CHardwareConfig : public IHardwareConfigInternal
  155. {
  156. public:
  157. CHardwareConfig();
  158. // Sets up the hardware caps given the specified DX level
  159. void SetupHardwareCaps( const ShaderDeviceInfo_t& mode, const HardwareCaps_t &actualCaps );
  160. // FIXME: This is for backward compat only.. don't use these
  161. void SetupHardwareCaps( int nDXLevel, const HardwareCaps_t &actualCaps );
  162. HardwareCaps_t& ActualCapsForEdit() { return m_ActualCaps; }
  163. HardwareCaps_t& CapsForEdit() { return m_Caps; }
  164. // Members of IMaterialSystemHardwareConfig
  165. virtual bool HasStencilBuffer() const;
  166. virtual int GetFrameBufferColorDepth() const;
  167. virtual int GetSamplerCount() const;
  168. virtual bool HasSetDeviceGammaRamp() const;
  169. virtual VertexCompressionType_t SupportsCompressedVertices() const;
  170. virtual bool SupportsBorderColor() const;
  171. virtual bool SupportsFetch4() const;
  172. virtual bool SupportsStaticControlFlow() const;
  173. virtual int MaximumAnisotropicLevel() const;
  174. virtual int MaxTextureWidth() const;
  175. virtual int MaxTextureHeight() const;
  176. virtual int TextureMemorySize() const;
  177. virtual bool SupportsMipmappedCubemaps() const;
  178. virtual int NumVertexShaderConstants() const;
  179. virtual int NumBooleanVertexShaderConstants() const;
  180. virtual int NumIntegerVertexShaderConstants() const;
  181. virtual int NumPixelShaderConstants() const;
  182. virtual int NumBooleanPixelShaderConstants() const;
  183. virtual int NumIntegerPixelShaderConstants() const;
  184. virtual int MaxNumLights() const;
  185. virtual int MaxTextureAspectRatio() const;
  186. virtual int MaxVertexShaderBlendMatrices() const;
  187. virtual int MaxUserClipPlanes() const;
  188. virtual bool UseFastClipping() const;
  189. virtual int GetDXSupportLevel() const;
  190. virtual const char *GetShaderDLLName() const;
  191. virtual bool ReadPixelsFromFrontBuffer() const;
  192. virtual bool PreferDynamicTextures() const;
  193. virtual bool SupportsHDR() const;
  194. virtual bool NeedsAAClamp() const;
  195. virtual bool NeedsATICentroidHack() const;
  196. virtual int GetMaxDXSupportLevel() const;
  197. virtual bool SpecifiesFogColorInLinearSpace() const;
  198. virtual bool SupportsSRGB() const;
  199. virtual bool FakeSRGBWrite() const;
  200. virtual bool CanDoSRGBReadFromRTs() const;
  201. virtual bool SupportsGLMixedSizeTargets() const;
  202. virtual bool IsAAEnabled() const;
  203. virtual int GetVertexSamplerCount() const;
  204. virtual int GetMaxVertexTextureDimension() const;
  205. virtual int MaxTextureDepth() const;
  206. virtual HDRType_t GetHDRType() const;
  207. virtual HDRType_t GetHardwareHDRType() const;
  208. virtual bool SupportsStreamOffset() const;
  209. virtual int StencilBufferBits() const;
  210. virtual int MaxViewports() const;
  211. virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport );
  212. // PS30 only supports shadow filter modes 0-2 (there's no use supporting mode 3, which is the ATI_NOPCF pass only used on low end), while PS20B supports all modes
  213. virtual ShadowFilterMode_t GetShadowFilterMode( bool bForceLowQualityShadows, bool bPS30 ) const;
  214. virtual int NeedsShaderSRGBConversion() const;
  215. virtual bool UsesSRGBCorrectBlending() const;
  216. virtual bool HasFastVertexTextures() const;
  217. virtual int MaxHWMorphBatchCount() const;
  218. virtual float GetShadowDepthBias() const;
  219. virtual float GetShadowSlopeScaleDepthBias() const;
  220. virtual bool PreferZPrepass() const;
  221. virtual bool SuppressPixelShaderCentroidHackFixup() const;
  222. virtual bool PreferTexturesInHWMemory() const;
  223. virtual bool PreferHardwareSync() const;
  224. virtual bool ActualHasFastVertexTextures() const;
  225. virtual bool SupportsShadowDepthTextures( void ) const;
  226. virtual ImageFormat GetShadowDepthTextureFormat( void ) const;
  227. virtual ImageFormat GetHighPrecisionShadowDepthTextureFormat( void ) const;
  228. virtual ImageFormat GetNullTextureFormat( void ) const;
  229. virtual int GetMinDXSupportLevel() const;
  230. virtual bool IsUnsupported() const;
  231. const char *GetHWSpecificShaderDLLName() const;
  232. int GetActualSamplerCount() const;
  233. int GetActualVertexSamplerCount() const;
  234. virtual bool SupportsHDRMode( HDRType_t nHDRMode ) const;
  235. const HardwareCaps_t& ActualCaps() const { return m_ActualCaps; }
  236. const HardwareCaps_t& Caps() const { return m_Caps; }
  237. virtual bool GetHDREnabled( void ) const;
  238. virtual void SetHDREnabled( bool bEnable );
  239. float GetLightMapScaleFactor( void ) const;
  240. bool SupportsCascadedShadowMapping( void ) const;
  241. CSMQualityMode_t GetCSMQuality() const;
  242. bool SupportsBilinearPCFSampling() const;
  243. CSMShaderMode_t GetCSMShaderMode( CSMQualityMode_t nQualityLevel ) const;
  244. bool GetCSMAccurateBlending() const;
  245. void SetCSMAccurateBlending( bool bEnable );
  246. bool SupportsResolveDepth() const;
  247. bool HasFullResolutionDepthTexture() const;
  248. protected:
  249. // Gets the recommended configuration associated with a particular dx level
  250. void ForceCapsToDXLevel( HardwareCaps_t *pCaps, int nDxLevel, const HardwareCaps_t &actualCaps );
  251. // Members related to capabilities
  252. HardwareCaps_t m_ActualCaps;
  253. HardwareCaps_t m_Caps;
  254. HardwareCaps_t m_UnOverriddenCaps;
  255. bool m_bHDREnabled;
  256. bool m_bCSMAccurateBlending;
  257. };
  258. //-----------------------------------------------------------------------------
  259. // Singleton hardware config
  260. //-----------------------------------------------------------------------------
  261. extern CHardwareConfig *g_pHardwareConfig;
  262. #endif // HARDWARECONFIG_H