Team Fortress 2 Source Code as on 22/4/2020
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.

286 lines
12 KiB

  1. //========= Copyright 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. #else
  35. MAXUSERCLIPPLANES = 6,
  36. #endif
  37. MAX_NUM_LIGHTS = 4,
  38. MAX_OUTPUTS = 3,
  39. };
  40. //-----------------------------------------------------------------------------
  41. // Hardware caps structures
  42. //-----------------------------------------------------------------------------
  43. enum CompressedTextureState_t
  44. {
  45. COMPRESSED_TEXTURES_ON,
  46. COMPRESSED_TEXTURES_OFF,
  47. COMPRESSED_TEXTURES_NOT_INITIALIZED
  48. };
  49. struct HardwareCaps_t : public MaterialAdapterInfo_t
  50. {
  51. // *****************************NOTE*********************************************
  52. // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
  53. // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
  54. // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
  55. // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
  56. // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
  57. // *****************************NOTE*********************************************
  58. //
  59. // NOTE: Texture stages are an obsolete concept; used by fixed-function hardware
  60. // Samplers are dx9+, indicating how many textures we can simultaneously bind
  61. // In Dx8, samplers didn't exist and texture stages were used to indicate the
  62. // number of simultaneously bound textures; we'll emulate that by slamming
  63. // the number of samplers to == the number of texture stages.
  64. CompressedTextureState_t m_SupportsCompressedTextures;
  65. VertexCompressionType_t m_SupportsCompressedVertices;
  66. int m_NumSamplers;
  67. int m_NumTextureStages;
  68. int m_nMaxAnisotropy;
  69. int m_MaxTextureWidth;
  70. int m_MaxTextureHeight;
  71. int m_MaxTextureDepth;
  72. int m_MaxTextureAspectRatio;
  73. int m_MaxPrimitiveCount;
  74. int m_NumPixelShaderConstants;
  75. int m_NumBooleanPixelShaderConstants;
  76. int m_NumIntegerPixelShaderConstants;
  77. int m_NumVertexShaderConstants;
  78. int m_NumBooleanVertexShaderConstants;
  79. int m_NumIntegerVertexShaderConstants;
  80. int m_TextureMemorySize;
  81. int m_MaxNumLights;
  82. int m_MaxBlendMatrices;
  83. int m_MaxBlendMatrixIndices;
  84. int m_MaxVertexShaderBlendMatrices;
  85. int m_MaxUserClipPlanes;
  86. HDRType_t m_HDRType;
  87. char m_pShaderDLL[32];
  88. ImageFormat m_ShadowDepthTextureFormat;
  89. ImageFormat m_NullTextureFormat;
  90. int m_nVertexTextureCount;
  91. int m_nMaxVertexTextureDimension;
  92. unsigned long m_AlphaToCoverageState; // State to ping to toggle Alpha To Coverage (vendor-dependent)
  93. unsigned long m_AlphaToCoverageEnableValue; // Value to set above state to turn on Alpha To Coverage (vendor-dependent)
  94. unsigned long m_AlphaToCoverageDisableValue; // Value to set above state to turn off Alpha To Coverage (vendor-dependent)
  95. int m_nMaxViewports;
  96. float m_flMinGammaControlPoint;
  97. float m_flMaxGammaControlPoint;
  98. int m_nGammaControlPointCount;
  99. int m_MaxVertexShader30InstructionSlots;
  100. int m_MaxPixelShader30InstructionSlots;
  101. int m_MaxSimultaneousRenderTargets;
  102. bool m_bDeviceOk : 1;
  103. bool m_HasSetDeviceGammaRamp : 1;
  104. bool m_SupportsVertexShaders : 1;
  105. bool m_SupportsVertexShaders_2_0 : 1;
  106. bool m_SupportsPixelShaders : 1;
  107. bool m_SupportsPixelShaders_1_4 : 1;
  108. bool m_SupportsPixelShaders_2_0 : 1;
  109. bool m_SupportsPixelShaders_2_b : 1;
  110. bool m_SupportsShaderModel_3_0 : 1;
  111. bool m_bSupportsAnisotropicFiltering : 1;
  112. bool m_bSupportsMagAnisotropicFiltering : 1;
  113. bool m_bSupportsVertexTextures : 1;
  114. bool m_ZBiasAndSlopeScaledDepthBiasSupported : 1;
  115. bool m_SupportsMipmapping : 1;
  116. bool m_SupportsOverbright : 1;
  117. bool m_SupportsCubeMaps : 1;
  118. bool m_SupportsHardwareLighting : 1;
  119. bool m_SupportsMipmappedCubemaps : 1;
  120. bool m_SupportsNonPow2Textures : 1;
  121. bool m_PreferDynamicTextures : 1;
  122. bool m_HasProjectedBumpEnv : 1;
  123. bool m_SupportsSRGB : 1; // Means both read and write
  124. bool m_bSupportsSpheremapping : 1;
  125. bool m_UseFastClipping : 1;
  126. bool m_bNeedsATICentroidHack : 1;
  127. bool m_bDisableShaderOptimizations : 1;
  128. bool m_bColorOnSecondStream : 1;
  129. bool m_bSupportsStreamOffset : 1;
  130. bool m_bFogColorSpecifiedInLinearSpace : 1;
  131. bool m_bFogColorAlwaysLinearSpace : 1;
  132. bool m_bSupportsAlphaToCoverage : 1;
  133. bool m_bSupportsShadowDepthTextures : 1;
  134. bool m_bSupportsFetch4 : 1;
  135. bool m_bSoftwareVertexProcessing : 1;
  136. bool m_bScissorSupported : 1;
  137. bool m_bSupportsFloat32RenderTargets : 1;
  138. bool m_bSupportsBorderColor : 1;
  139. bool m_bDX10Card : 1; // Indicates DX10 part with performant vertex textures running DX9 path
  140. bool m_bDX10Blending : 1; // Indicates DX10 part that does DX10 blending (but may not have performant vertex textures, such as Intel parts)
  141. bool m_bSupportsStaticControlFlow : 1; // Useful on OpenGL, where we have a mix of support...
  142. bool m_FakeSRGBWrite : 1; // Gotta do this on OpenGL. Mostly hidden, but some high level code needs to know
  143. bool m_CanDoSRGBReadFromRTs : 1; // Gotta do this on OpenGL. Mostly hidden, but some high level code needs to know
  144. bool m_bSupportsGLMixedSizeTargets : 1; // on OpenGL, are mixed size depth buffers supported - aka ARB_framebuffer_object
  145. bool m_bCanStretchRectFromTextures : 1; // Does the device expose D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES (or is it >DX9?)
  146. HDRType_t m_MaxHDRType;
  147. };
  148. //-----------------------------------------------------------------------------
  149. // Contains the hardware configuration for the current device
  150. //-----------------------------------------------------------------------------
  151. class CHardwareConfig : public IHardwareConfigInternal
  152. {
  153. public:
  154. CHardwareConfig();
  155. // Sets up the hardware caps given the specified DX level
  156. void SetupHardwareCaps( const ShaderDeviceInfo_t& mode, const HardwareCaps_t &actualCaps );
  157. // FIXME: This is for backward compat only.. don't use these
  158. void SetupHardwareCaps( int nDXLevel, const HardwareCaps_t &actualCaps );
  159. HardwareCaps_t& ActualCapsForEdit() { return m_ActualCaps; }
  160. HardwareCaps_t& CapsForEdit() { return m_Caps; }
  161. // Members of IMaterialSystemHardwareConfig
  162. virtual bool HasDestAlphaBuffer() const;
  163. virtual bool HasStencilBuffer() const;
  164. virtual int GetFrameBufferColorDepth() const;
  165. virtual int GetSamplerCount() const;
  166. virtual bool HasSetDeviceGammaRamp() const;
  167. virtual bool SupportsCompressedTextures() const;
  168. virtual VertexCompressionType_t SupportsCompressedVertices() const;
  169. virtual bool SupportsBorderColor() const;
  170. virtual bool SupportsFetch4() const;
  171. virtual bool CanStretchRectFromTextures() const;
  172. virtual bool SupportsVertexAndPixelShaders() const;
  173. virtual bool SupportsPixelShaders_1_4() const;
  174. virtual bool SupportsPixelShaders_2_0() const;
  175. virtual bool SupportsStaticControlFlow() const;
  176. virtual bool SupportsVertexShaders_2_0() const;
  177. virtual int MaximumAnisotropicLevel() const;
  178. virtual int MaxTextureWidth() const;
  179. virtual int MaxTextureHeight() const;
  180. virtual int TextureMemorySize() const;
  181. virtual bool SupportsOverbright() const;
  182. virtual bool SupportsCubeMaps() const;
  183. virtual bool SupportsMipmappedCubemaps() const;
  184. virtual bool SupportsNonPow2Textures() const;
  185. virtual int GetTextureStageCount() const;
  186. virtual int NumVertexShaderConstants() const;
  187. virtual int NumBooleanVertexShaderConstants() const;
  188. virtual int NumIntegerVertexShaderConstants() const;
  189. virtual int NumPixelShaderConstants() const;
  190. virtual int NumBooleanPixelShaderConstants() const;
  191. virtual int NumIntegerPixelShaderConstants() const;
  192. virtual int MaxNumLights() const;
  193. virtual bool SupportsHardwareLighting() const;
  194. virtual int MaxBlendMatrices() const;
  195. virtual int MaxBlendMatrixIndices() const;
  196. virtual int MaxTextureAspectRatio() const;
  197. virtual int MaxVertexShaderBlendMatrices() const;
  198. virtual int MaxUserClipPlanes() const;
  199. virtual bool UseFastClipping() const;
  200. virtual int GetDXSupportLevel() const;
  201. virtual const char *GetShaderDLLName() const;
  202. virtual bool ReadPixelsFromFrontBuffer() const;
  203. virtual bool PreferDynamicTextures() const;
  204. virtual bool SupportsHDR() const;
  205. virtual bool HasProjectedBumpEnv() const;
  206. virtual bool SupportsSpheremapping() const;
  207. virtual bool NeedsAAClamp() const;
  208. virtual bool NeedsATICentroidHack() const;
  209. virtual bool SupportsColorOnSecondStream() const;
  210. virtual bool SupportsStaticPlusDynamicLighting() const;
  211. virtual bool PreferReducedFillrate() const;
  212. virtual int GetMaxDXSupportLevel() const;
  213. virtual bool SpecifiesFogColorInLinearSpace() const;
  214. virtual bool SupportsSRGB() const;
  215. virtual bool FakeSRGBWrite() const;
  216. virtual bool CanDoSRGBReadFromRTs() const;
  217. virtual bool SupportsGLMixedSizeTargets() const;
  218. virtual bool IsAAEnabled() const;
  219. virtual int GetVertexTextureCount() const;
  220. virtual int GetMaxVertexTextureDimension() const;
  221. virtual int MaxTextureDepth() const;
  222. virtual HDRType_t GetHDRType() const;
  223. virtual HDRType_t GetHardwareHDRType() const;
  224. virtual bool SupportsPixelShaders_2_b() const;
  225. virtual bool SupportsShaderModel_3_0() const;
  226. virtual bool SupportsStreamOffset() const;
  227. virtual int StencilBufferBits() const;
  228. virtual int MaxViewports() const;
  229. virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport );
  230. virtual int GetShadowFilterMode() const;
  231. virtual int NeedsShaderSRGBConversion() const;
  232. virtual bool UsesSRGBCorrectBlending() const;
  233. virtual bool HasFastVertexTextures() const;
  234. virtual int MaxHWMorphBatchCount() const;
  235. const char *GetHWSpecificShaderDLLName() const;
  236. int GetActualSamplerCount() const;
  237. int GetActualTextureStageCount() const;
  238. bool SupportsMipmapping() const;
  239. virtual bool ActuallySupportsPixelShaders_2_b() const;
  240. virtual bool SupportsHDRMode( HDRType_t nHDRMode ) const;
  241. const HardwareCaps_t& ActualCaps() const { return m_ActualCaps; }
  242. const HardwareCaps_t& Caps() const { return m_Caps; }
  243. virtual bool GetHDREnabled( void ) const;
  244. virtual void SetHDREnabled( bool bEnable );
  245. protected:
  246. // Gets the recommended configuration associated with a particular dx level
  247. void ForceCapsToDXLevel( HardwareCaps_t *pCaps, int nDxLevel, const HardwareCaps_t &actualCaps );
  248. // Members related to capabilities
  249. HardwareCaps_t m_ActualCaps;
  250. HardwareCaps_t m_Caps;
  251. HardwareCaps_t m_UnOverriddenCaps;
  252. bool m_bHDREnabled;
  253. };
  254. //-----------------------------------------------------------------------------
  255. // Singleton hardware config
  256. //-----------------------------------------------------------------------------
  257. extern CHardwareConfig *g_pHardwareConfig;
  258. #endif // HARDWARECONFIG_H