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.

1026 lines
26 KiB

  1. //===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #define DISABLE_PROTECTED_THINGS
  9. #include "togl/rendermechanism.h"
  10. #include "hardwareconfig.h"
  11. #include "shaderapi/ishaderutil.h"
  12. #include "shaderapi_global.h"
  13. #include "materialsystem/materialsystem_config.h"
  14. #include "tier1/convar.h"
  15. #include "shaderdevicebase.h"
  16. #include "tier0/icommandline.h"
  17. // NOTE: This has to be the last file included!
  18. #include "tier0/memdbgon.h"
  19. extern ConVar mat_slopescaledepthbias_shadowmap;
  20. extern ConVar mat_depthbias_shadowmap;
  21. static ConVar developer( "developer", "0", FCVAR_RELEASE, "Set developer message level" );
  22. //-----------------------------------------------------------------------------
  23. //
  24. // Hardware Config!
  25. //
  26. //-----------------------------------------------------------------------------
  27. static CHardwareConfig s_HardwareConfig;
  28. CHardwareConfig *g_pHardwareConfig = &s_HardwareConfig;
  29. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CHardwareConfig, IMaterialSystemHardwareConfig,
  30. MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, s_HardwareConfig )
  31. CHardwareConfig::CHardwareConfig()
  32. {
  33. memset( &m_Caps, 0, sizeof( HardwareCaps_t ) );
  34. memset( &m_ActualCaps, 0, sizeof( HardwareCaps_t ) );
  35. memset( &m_UnOverriddenCaps, 0, sizeof( HardwareCaps_t ) );
  36. m_bHDREnabled = false;
  37. // FIXME: This is kind of a hack to deal with DX8 worldcraft startup.
  38. // We can at least have this much texture
  39. m_Caps.m_MaxTextureWidth = m_Caps.m_MaxTextureHeight = m_Caps.m_MaxTextureDepth = 256;
  40. }
  41. //-----------------------------------------------------------------------------
  42. bool CHardwareConfig::GetHDREnabled( void ) const
  43. {
  44. // printf("\n CHardwareConfig::GetHDREnabled returning m_bHDREnabled value of %s on %8x", m_bHDREnabled?"true":"false", this );
  45. return m_bHDREnabled;
  46. }
  47. void CHardwareConfig::SetHDREnabled( bool bEnable )
  48. {
  49. // printf("\n CHardwareConfig::SetHDREnabled setting m_bHDREnabled to value of %s on %8x", bEnable?"true":"false", this );
  50. m_bHDREnabled = bEnable;
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Gets the recommended configuration associated with a particular dx level
  54. //-----------------------------------------------------------------------------
  55. void CHardwareConfig::ForceCapsToDXLevel( HardwareCaps_t *pCaps, int nDxLevel, const HardwareCaps_t &actualCaps )
  56. {
  57. if ( !IsPC() || nDxLevel > 100 )
  58. return;
  59. pCaps->m_nDXSupportLevel = nDxLevel;
  60. switch( nDxLevel )
  61. {
  62. case 90:
  63. pCaps->m_NumVertexSamplers = 0;
  64. pCaps->m_nMaxVertexTextureDimension = 0;
  65. pCaps->m_bSupportsVertexTextures = false;
  66. pCaps->m_bSupportsBorderColor = false;
  67. // 2b gets four lights, 2.0 gets two...
  68. pCaps->m_SupportsPixelShaders_2_b = false;
  69. pCaps->m_SupportsShaderModel_3_0 = false;
  70. pCaps->m_MaxNumLights = 2;
  71. pCaps->m_nMaxViewports = 1;
  72. pCaps->m_NumPixelShaderConstants = 32;
  73. pCaps->m_nMaxVertexTextureDimension = 0;
  74. pCaps->m_bDX10Card = false;
  75. pCaps->m_bDX10Blending = false;
  76. pCaps->m_MaxVertexShader30InstructionSlots = 0;
  77. pCaps->m_MaxPixelShader30InstructionSlots = 0;
  78. pCaps->m_bSupportsCascadedShadowMapping = false;
  79. pCaps->m_nCSMQuality = 0;
  80. break;
  81. case 92:
  82. pCaps->m_NumVertexSamplers = 0;
  83. pCaps->m_nMaxVertexTextureDimension = 0;
  84. pCaps->m_bSupportsVertexTextures = false;
  85. pCaps->m_bSupportsBorderColor = false;
  86. // 2b gets four lights (iff supports static control flow otherwise 2), 2.0 gets two...
  87. pCaps->m_SupportsShaderModel_3_0 = false;
  88. if ( IsOpenGL() )
  89. {
  90. if ( IsOSX() )
  91. {
  92. pCaps->m_bSupportsStaticControlFlow = CommandLine()->CheckParm( "-glslcontrolflow" ) != NULL;
  93. }
  94. else
  95. {
  96. pCaps->m_bSupportsStaticControlFlow = !CommandLine()->CheckParm( "-noglslcontrolflow" );
  97. }
  98. pCaps->m_MaxUserClipPlanes = 2;
  99. pCaps->m_UseFastClipping = false;
  100. pCaps->m_MaxNumLights = pCaps->m_bSupportsStaticControlFlow ? 4 : 2;
  101. }
  102. else
  103. {
  104. pCaps->m_MaxNumLights = MAX_NUM_LIGHTS;
  105. }
  106. pCaps->m_nMaxViewports = 1;
  107. pCaps->m_NumPixelShaderConstants = 32;
  108. pCaps->m_nMaxVertexTextureDimension = 0;
  109. pCaps->m_bDX10Card = false;
  110. pCaps->m_bDX10Blending = false;
  111. pCaps->m_MaxVertexShader30InstructionSlots = 0;
  112. pCaps->m_MaxPixelShader30InstructionSlots = 0;
  113. pCaps->m_bSupportsCascadedShadowMapping = false;
  114. pCaps->m_nCSMQuality = 0;
  115. break;
  116. case 95:
  117. pCaps->m_bDX10Card = false;
  118. pCaps->m_bDX10Blending = false;
  119. pCaps->m_nMaxViewports = 1;
  120. pCaps->m_bSupportsBorderColor = false;
  121. if ( IsOpenGL() )
  122. {
  123. if ( IsOSX() )
  124. {
  125. pCaps->m_bSupportsStaticControlFlow = CommandLine()->CheckParm( "-glslcontrolflow" ) != NULL;
  126. }
  127. else
  128. {
  129. pCaps->m_bSupportsStaticControlFlow = !CommandLine()->CheckParm( "-noglslcontrolflow" );
  130. }
  131. pCaps->m_MaxUserClipPlanes = 2;
  132. pCaps->m_UseFastClipping = false;
  133. pCaps->m_MaxNumLights = pCaps->m_bSupportsStaticControlFlow ? 4 : 2;
  134. }
  135. else
  136. {
  137. pCaps->m_MaxNumLights = MAX_NUM_LIGHTS;
  138. }
  139. break;
  140. case 100:
  141. if ( IsOpenGL() )
  142. {
  143. if ( IsOSX() )
  144. {
  145. pCaps->m_bSupportsStaticControlFlow = CommandLine()->CheckParm( "-glslcontrolflow" ) != NULL;
  146. }
  147. else
  148. {
  149. pCaps->m_bSupportsStaticControlFlow = !CommandLine()->CheckParm( "-noglslcontrolflow" );
  150. }
  151. pCaps->m_MaxUserClipPlanes = 2;
  152. pCaps->m_UseFastClipping = false;
  153. pCaps->m_MaxNumLights = pCaps->m_bSupportsStaticControlFlow ? 4 : 2;
  154. }
  155. else
  156. {
  157. pCaps->m_MaxNumLights = MAX_NUM_LIGHTS;
  158. }
  159. break;
  160. default:
  161. Assert( 0 );
  162. break;
  163. }
  164. #ifdef _PS3
  165. pCaps->m_NumPixelShaderConstants = MAX_FRAGMENT_PROGRAM_CONSTS; // this is somewhat of a lie... fragment shader constants are special on PS3 and we actually have a larger number of these
  166. #endif
  167. }
  168. //-----------------------------------------------------------------------------
  169. // Sets up the hardware caps given the specified DX level
  170. //-----------------------------------------------------------------------------
  171. void CHardwareConfig::SetupHardwareCaps( int nDXLevel, const HardwareCaps_t &actualCaps )
  172. {
  173. Assert( nDXLevel != 0 );
  174. if ( nDXLevel < actualCaps.m_nMinDXSupportLevel )
  175. {
  176. Warning( "Trying to set dxlevel (%d) which is lower than the card can support (%d)!\n", nDXLevel, actualCaps.m_nMinDXSupportLevel );
  177. }
  178. if ( nDXLevel > actualCaps.m_nMaxDXSupportLevel )
  179. {
  180. Warning( "Trying to set dxlevel (%d) which is higher than the card can support (%d)!\n", nDXLevel, actualCaps.m_nMaxDXSupportLevel );
  181. }
  182. memcpy( &m_Caps, &actualCaps, sizeof(HardwareCaps_t) );
  183. memcpy( &m_UnOverriddenCaps, &actualCaps, sizeof(HardwareCaps_t) );
  184. // Don't bother with fallbacks for DX10 or consoles
  185. #ifdef DX_TO_GL_ABSTRACTION
  186. if ( nDXLevel >= 100 )
  187. #else
  188. if ( !( IsPC() || IsPosix() ) || ( nDXLevel >= 100 ) )
  189. #endif
  190. return;
  191. // Don't bother with fallbacks for consoles.
  192. if ( IsGameConsole() )
  193. return;
  194. int nForceDXLevel = CommandLine()->ParmValue( "-maxdxlevel", 0 );
  195. if ( nForceDXLevel >= 90 )
  196. {
  197. nDXLevel = nForceDXLevel;
  198. }
  199. else
  200. {
  201. // Don't bother with fallbacks for DX10 or consoles
  202. if ( !IsPC() || !IsPosix() || ( nDXLevel >= 100 ) )
  203. return;
  204. }
  205. // Slam the support level to what we were requested
  206. m_Caps.m_nDXSupportLevel = nDXLevel;
  207. int nMaxDXLevel = CommandLine()->ParmValue( "-maxdxlevel", m_Caps.m_nMaxDXSupportLevel );
  208. if ( IsOpenGL() )
  209. {
  210. // Prevent customers from ever trying to slam the dxlevel too low in GL mode.
  211. nMaxDXLevel = MAX( nMaxDXLevel, 90 );
  212. }
  213. {
  214. // We're falling back to some other dx level
  215. ForceCapsToDXLevel( &m_Caps, m_Caps.m_nDXSupportLevel, m_ActualCaps );
  216. }
  217. // Read dxsupport.cfg which has config overrides for particular cards.
  218. g_pShaderDeviceMgr->ReadHardwareCaps( m_Caps, m_Caps.m_nDXSupportLevel );
  219. // This is the spot to validate read in caps versus actual caps.
  220. if ( m_Caps.m_MaxUserClipPlanes > m_ActualCaps.m_MaxUserClipPlanes )
  221. {
  222. m_Caps.m_MaxUserClipPlanes = m_ActualCaps.m_MaxUserClipPlanes;
  223. }
  224. if ( m_Caps.m_MaxUserClipPlanes == 0 )
  225. {
  226. m_Caps.m_UseFastClipping = true;
  227. }
  228. // 2b supports more lights than just 2.0
  229. if ( ( m_Caps.m_SupportsPixelShaders_2_b ) && ( m_Caps.m_nDXSupportLevel >= 92 ) )
  230. {
  231. m_Caps.m_MaxNumLights = MAX_NUM_LIGHTS;
  232. }
  233. else
  234. {
  235. m_Caps.m_MaxNumLights = MAX_NUM_LIGHTS-2;
  236. }
  237. if ( IsOpenGL() )
  238. {
  239. m_Caps.m_MaxNumLights = MIN( m_Caps.m_bSupportsStaticControlFlow ? MAX_NUM_LIGHTS : 2, m_Caps.m_MaxNumLights );
  240. m_Caps.m_bSupportsShadowDepthTextures = true;
  241. }
  242. m_Caps.m_MaxNumLights = MIN( m_Caps.m_MaxNumLights, MAX_NUM_LIGHTS );
  243. memcpy( &m_UnOverriddenCaps, &m_Caps, sizeof(HardwareCaps_t) );
  244. }
  245. //-----------------------------------------------------------------------------
  246. // Sets up the hardware caps given the specified DX level
  247. //-----------------------------------------------------------------------------
  248. void CHardwareConfig::SetupHardwareCaps( const ShaderDeviceInfo_t& mode, const HardwareCaps_t &actualCaps )
  249. {
  250. memcpy( &m_ActualCaps, &actualCaps, sizeof(HardwareCaps_t) );
  251. SetupHardwareCaps( mode.m_nDXLevel, actualCaps );
  252. }
  253. void CHardwareConfig::OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport )
  254. {
  255. if ( bOverrideEnabled )
  256. {
  257. m_Caps.m_bSupportsStreamOffset = bEnableSupport;
  258. if ( !m_ActualCaps.m_bSupportsStreamOffset )
  259. {
  260. m_Caps.m_bSupportsStreamOffset = false;
  261. }
  262. }
  263. else
  264. {
  265. // Go back to default
  266. m_Caps.m_bSupportsStreamOffset = m_UnOverriddenCaps.m_bSupportsStreamOffset;
  267. }
  268. }
  269. //-----------------------------------------------------------------------------
  270. // Implementation of IMaterialSystemHardwareConfig
  271. //-----------------------------------------------------------------------------
  272. bool CHardwareConfig::HasStencilBuffer() const
  273. {
  274. return StencilBufferBits() > 0;
  275. }
  276. int CHardwareConfig::GetFrameBufferColorDepth() const
  277. {
  278. if ( !g_pShaderDevice )
  279. return 0;
  280. return ShaderUtil()->ImageFormatInfo( g_pShaderDevice->GetBackBufferFormat() ).m_nNumBytes;
  281. }
  282. int CHardwareConfig::GetSamplerCount() const
  283. {
  284. return m_Caps.m_NumSamplers;
  285. }
  286. int CHardwareConfig::GetVertexSamplerCount() const
  287. {
  288. return m_Caps.m_NumVertexSamplers;
  289. }
  290. bool CHardwareConfig::HasSetDeviceGammaRamp() const
  291. {
  292. return m_Caps.m_HasSetDeviceGammaRamp;
  293. }
  294. VertexCompressionType_t CHardwareConfig::SupportsCompressedVertices() const
  295. {
  296. return m_Caps.m_SupportsCompressedVertices;
  297. }
  298. bool CHardwareConfig::SupportsBorderColor() const
  299. {
  300. return m_Caps.m_bSupportsBorderColor;
  301. }
  302. bool CHardwareConfig::SupportsFetch4() const
  303. {
  304. return m_Caps.m_bSupportsFetch4;
  305. }
  306. float CHardwareConfig::GetShadowDepthBias() const
  307. {
  308. // FIXME: Should these not use convars?
  309. return mat_depthbias_shadowmap.GetFloat();
  310. }
  311. float CHardwareConfig::GetShadowSlopeScaleDepthBias() const
  312. {
  313. // FIXME: Should these not use convars?
  314. return mat_slopescaledepthbias_shadowmap.GetFloat();
  315. }
  316. bool CHardwareConfig::PreferZPrepass() const
  317. {
  318. return m_Caps.m_bPreferZPrepass;
  319. }
  320. bool CHardwareConfig::SuppressPixelShaderCentroidHackFixup() const
  321. {
  322. return m_Caps.m_bSuppressPixelShaderCentroidHackFixup;
  323. }
  324. bool CHardwareConfig::PreferTexturesInHWMemory() const
  325. {
  326. return m_Caps.m_bPreferTexturesInHWMemory;
  327. }
  328. bool CHardwareConfig::PreferHardwareSync() const
  329. {
  330. return m_Caps.m_bPreferHardwareSync;
  331. }
  332. bool CHardwareConfig::SupportsStaticControlFlow() const
  333. {
  334. return m_Caps.m_bSupportsStaticControlFlow;
  335. }
  336. bool CHardwareConfig::IsUnsupported() const
  337. {
  338. return m_Caps.m_bUnsupported;
  339. }
  340. ShadowFilterMode_t CHardwareConfig::GetShadowFilterMode( bool bForceLowQualityShadows, bool bPS30 ) const
  341. {
  342. #if PLATFORM_POSIX || !defined( PLATFORM_X360 )
  343. static ConVarRef gpu_level( "gpu_level" );
  344. int nGPULevel = gpu_level.GetInt();
  345. const bool bUseLowQualityShadows = ( nGPULevel < 2 ) || ( bForceLowQualityShadows );
  346. #endif
  347. #if PLATFORM_POSIX
  348. // Currently Mac or PS3
  349. if ( !m_Caps.m_bSupportsShadowDepthTextures )
  350. return SHADOWFILTERMODE_DEFAULT;
  351. if ( IsOSXOpenGL() &&
  352. ( bUseLowQualityShadows || ( m_Caps.m_VendorID == VENDORID_INTEL ) ) )
  353. {
  354. return NVIDIA_PCF_CHEAP;
  355. }
  356. if( IsPS3() )
  357. {
  358. // PS3 shaders doesn't use the regular PC/POSIX values. It supports either 9 (the default) or 1 tap (fast) filtering.
  359. return bForceLowQualityShadows ? GAMECONSOLE_SINGLE_TAP_PCF : GAMECONSOLE_NINE_TAP_PCF;
  360. }
  361. #elif defined( PLATFORM_X360 )
  362. // X360
  363. return bForceLowQualityShadows ? GAMECONSOLE_SINGLE_TAP_PCF : GAMECONSOLE_NINE_TAP_PCF;
  364. #else
  365. // PC
  366. if ( !m_Caps.m_bSupportsShadowDepthTextures || !ShaderUtil()->GetConfig().ShadowDepthTexture() )
  367. return SHADOWFILTERMODE_DEFAULT;
  368. switch ( m_Caps.m_ShadowDepthTextureFormat )
  369. {
  370. case IMAGE_FORMAT_D16_SHADOW:
  371. case IMAGE_FORMAT_D24X8_SHADOW:
  372. if ( ( m_Caps.m_VendorID == VENDORID_NVIDIA ) || ( m_Caps.m_VendorID == VENDORID_INTEL ) )
  373. {
  374. if ( bUseLowQualityShadows )
  375. return NVIDIA_PCF_CHEAP; // NVIDIA hardware bilinear PCF
  376. else
  377. return NVIDIA_PCF; // NVIDIA hardware PCF with larger kernel
  378. }
  379. if ( m_Caps.m_VendorID == VENDORID_ATI )
  380. {
  381. // PS30 shaders purposely don't support ATI_NOPCF to reduce the combo permutation space.
  382. if ( ( !bPS30 ) && ( bUseLowQualityShadows ) )
  383. {
  384. return ATI_NOPCF; // Don't bother with a cheap Fetch 4
  385. }
  386. else
  387. {
  388. static bool bForceATIFetch4 = CommandLine()->CheckParm( "-forceatifetch4" ) ? true : false;
  389. // Either PS30, or high quality shadows.
  390. if ( m_Caps.m_bDX10Card && !bForceATIFetch4 )
  391. return ( bUseLowQualityShadows ) ? NVIDIA_PCF_CHEAP : NVIDIA_PCF; // ATI wants us to run NVIDIA PCF on DX10 parts (this is the common case)
  392. else if ( m_Caps.m_bSupportsFetch4 )
  393. return ATI_NO_PCF_FETCH4; // ATI fetch4 depth texture sampling
  394. else if ( bPS30 )
  395. {
  396. // We can't return ATI_NOPCF when using PS30 shaders. (This path should actually never get hit - either we're on a DX10 card or its fetch10 capable, I think.)
  397. return ATI_NO_PCF_FETCH4;
  398. }
  399. else
  400. {
  401. return ATI_NOPCF; // ATI vanilla depth texture sampling
  402. }
  403. }
  404. }
  405. break;
  406. default:
  407. return SHADOWFILTERMODE_DEFAULT;
  408. }
  409. #endif
  410. return SHADOWFILTERMODE_DEFAULT;
  411. }
  412. #if defined( CSTRIKE15 ) && defined( _X360 )
  413. static ConVar r_shader_srgb( "r_shader_srgb", "0", 0, "-1 = use hardware caps. 0 = use hardware srgb. 1 = use shader srgb(software lookup)" ); // -1=use caps 0=off 1=on
  414. static ConVar r_shader_srgbread( "r_shader_srgbread", "1", 0, "1 = use shader srgb texture reads, 0 = use HW" );
  415. #else
  416. static ConVar r_shader_srgb( "r_shader_srgb", "0", 0, "-1 = use hardware caps. 0 = use hardware srgb. 1 = use shader srgb(software lookup)" ); // -1=use caps 0=off 1=on
  417. static ConVar r_shader_srgbread( "r_shader_srgbread", "0", 0, "1 = use shader srgb texture reads, 0 = use HW" );
  418. #endif
  419. int CHardwareConfig::NeedsShaderSRGBConversion() const
  420. {
  421. if ( IsX360() )
  422. {
  423. #if defined( CSTRIKE15 )
  424. // [mariod] TODO - tidy up the use of this (now mostly obsolete) convar after PAX
  425. if( r_shader_srgbread.GetBool() )
  426. {
  427. return false;
  428. }
  429. #else
  430. // 360 always now uses a permanent hw solution
  431. return false;
  432. #endif
  433. }
  434. if ( IsPS3() )
  435. {
  436. // PS3 natively supports srgb in hardware
  437. return false;
  438. }
  439. int cValue = r_shader_srgb.GetInt();
  440. switch( cValue )
  441. {
  442. case 0:
  443. return false;
  444. case 1:
  445. return true;
  446. default:
  447. return m_ActualCaps.m_bDX10Blending; // !!! change to return false after portal depot built!!!!!
  448. }
  449. }
  450. bool CHardwareConfig::UsesSRGBCorrectBlending() const
  451. {
  452. int cValue = r_shader_srgb.GetInt();
  453. return ( cValue == 0 ) && ( ( m_ActualCaps.m_bDX10Blending ) || IsX360() );
  454. }
  455. static ConVar mat_disablehwmorph( "mat_disablehwmorph", "0", FCVAR_DEVELOPMENTONLY, "Disables HW morphing for particular mods" );
  456. static int s_bEnableFastVertexTextures = -1;
  457. static bool s_bDisableHWMorph = false;
  458. bool CHardwareConfig::HasFastVertexTextures() const
  459. {
  460. // NOTE: This disallows you to change mat_disablehwmorph on the fly
  461. if ( s_bEnableFastVertexTextures < 0 )
  462. {
  463. s_bEnableFastVertexTextures = 1;
  464. if ( CommandLine()->FindParm( "-disallowhwmorph" ) )
  465. {
  466. s_bEnableFastVertexTextures = 0;
  467. }
  468. s_bDisableHWMorph = ( mat_disablehwmorph.GetInt() != 0 );
  469. }
  470. return ( s_bEnableFastVertexTextures != 0 ) && ( !s_bDisableHWMorph ) && ( GetDXSupportLevel() >= 100 );
  471. }
  472. bool CHardwareConfig::ActualHasFastVertexTextures() const
  473. {
  474. // NOTE: This disallows you to change mat_disablehwmorph on the fly
  475. if ( s_bEnableFastVertexTextures < 0 )
  476. {
  477. s_bEnableFastVertexTextures = 1;
  478. if ( CommandLine()->FindParm( "-disallowhwmorph" ) )
  479. {
  480. s_bEnableFastVertexTextures = 0;
  481. }
  482. s_bDisableHWMorph = ( mat_disablehwmorph.GetInt() != 0 );
  483. }
  484. return ( s_bEnableFastVertexTextures != 0 ) && ( !s_bDisableHWMorph ) && ( GetMaxDXSupportLevel() >= 100 );
  485. }
  486. int CHardwareConfig::MaxHWMorphBatchCount() const
  487. {
  488. return ShaderUtil()->MaxHWMorphBatchCount();
  489. }
  490. int CHardwareConfig::MaximumAnisotropicLevel() const
  491. {
  492. return m_Caps.m_nMaxAnisotropy;
  493. }
  494. int CHardwareConfig::MaxTextureWidth() const
  495. {
  496. return m_Caps.m_MaxTextureWidth;
  497. }
  498. int CHardwareConfig::MaxTextureHeight() const
  499. {
  500. return m_Caps.m_MaxTextureHeight;
  501. }
  502. int CHardwareConfig::TextureMemorySize() const
  503. {
  504. return m_Caps.m_TextureMemorySize;
  505. }
  506. bool CHardwareConfig::SupportsMipmappedCubemaps() const
  507. {
  508. return m_Caps.m_SupportsMipmappedCubemaps;
  509. }
  510. int CHardwareConfig::NumVertexShaderConstants() const
  511. {
  512. return m_Caps.m_NumVertexShaderConstants;
  513. }
  514. int CHardwareConfig::NumBooleanVertexShaderConstants() const
  515. {
  516. return m_Caps.m_NumBooleanVertexShaderConstants;
  517. }
  518. int CHardwareConfig::NumIntegerVertexShaderConstants() const
  519. {
  520. return m_Caps.m_NumIntegerVertexShaderConstants;
  521. }
  522. int CHardwareConfig::NumPixelShaderConstants() const
  523. {
  524. return m_Caps.m_NumPixelShaderConstants;
  525. }
  526. int CHardwareConfig::NumBooleanPixelShaderConstants() const
  527. {
  528. return m_Caps.m_NumBooleanPixelShaderConstants;
  529. }
  530. int CHardwareConfig::NumIntegerPixelShaderConstants() const
  531. {
  532. return m_Caps.m_NumIntegerPixelShaderConstants;
  533. }
  534. int CHardwareConfig::MaxNumLights() const
  535. {
  536. return m_Caps.m_MaxNumLights;
  537. }
  538. int CHardwareConfig::MaxTextureAspectRatio() const
  539. {
  540. return m_Caps.m_MaxTextureAspectRatio;
  541. }
  542. int CHardwareConfig::MaxVertexShaderBlendMatrices() const
  543. {
  544. return m_Caps.m_MaxVertexShaderBlendMatrices;
  545. }
  546. // Useful for testing fastclip on Windows
  547. extern ConVar mat_fastclip;
  548. int CHardwareConfig::MaxUserClipPlanes() const
  549. {
  550. if ( mat_fastclip.GetBool() )
  551. return 0;
  552. return m_Caps.m_MaxUserClipPlanes;
  553. }
  554. bool CHardwareConfig::UseFastClipping() const
  555. {
  556. // rbarris broke this up for easier view of outcome in debugger
  557. bool fastclip = mat_fastclip.GetBool();
  558. bool result = m_Caps.m_UseFastClipping || fastclip;
  559. return result;
  560. }
  561. int CHardwareConfig::MaxTextureDepth() const
  562. {
  563. return m_Caps.m_MaxTextureDepth;
  564. }
  565. int CHardwareConfig::GetDXSupportLevel() const
  566. {
  567. return m_Caps.m_nDXSupportLevel;
  568. }
  569. const char *CHardwareConfig::GetShaderDLLName() const
  570. {
  571. return ( m_Caps.m_pShaderDLL && m_Caps.m_pShaderDLL[0] ) ? m_Caps.m_pShaderDLL : "DEFAULT";
  572. }
  573. bool CHardwareConfig::ReadPixelsFromFrontBuffer() const
  574. {
  575. if ( IsX360() )
  576. {
  577. // future proof safety, not allowing the front read path
  578. return false;
  579. }
  580. // GR - in DX 9.0a can blit from MSAA back buffer
  581. return false;
  582. }
  583. bool CHardwareConfig::PreferDynamicTextures() const
  584. {
  585. if ( IsX360() )
  586. {
  587. // future proof safety, not allowing these
  588. return false;
  589. }
  590. return m_Caps.m_PreferDynamicTextures;
  591. }
  592. bool CHardwareConfig::SupportsHDR() const
  593. {
  594. // This is a deprecated function. . use GetHDRType instead. For shipping HL2, this always being false is correct.
  595. Assert( 0 );
  596. return false;
  597. }
  598. bool CHardwareConfig::SupportsHDRMode( HDRType_t nHDRType ) const
  599. {
  600. switch( nHDRType )
  601. {
  602. case HDR_TYPE_NONE:
  603. return true;
  604. case HDR_TYPE_INTEGER:
  605. return ( m_Caps.m_MaxHDRType == HDR_TYPE_INTEGER ) || ( m_Caps.m_MaxHDRType == HDR_TYPE_FLOAT );
  606. case HDR_TYPE_FLOAT:
  607. return ( m_Caps.m_MaxHDRType == HDR_TYPE_FLOAT );
  608. }
  609. return false;
  610. }
  611. bool CHardwareConfig::NeedsAAClamp() const
  612. {
  613. return false;
  614. }
  615. bool CHardwareConfig::NeedsATICentroidHack() const
  616. {
  617. return m_Caps.m_bNeedsATICentroidHack;
  618. }
  619. // This is the max dx support level supported by the card
  620. int CHardwareConfig::GetMaxDXSupportLevel() const
  621. {
  622. return m_ActualCaps.m_nMaxDXSupportLevel;
  623. }
  624. int CHardwareConfig::GetMinDXSupportLevel() const
  625. {
  626. return ( developer.GetInt() > 0 ) ? 90 : m_ActualCaps.m_nMinDXSupportLevel;
  627. }
  628. bool CHardwareConfig::SpecifiesFogColorInLinearSpace() const
  629. {
  630. return m_Caps.m_bFogColorSpecifiedInLinearSpace;
  631. }
  632. bool CHardwareConfig::SupportsSRGB() const
  633. {
  634. return m_Caps.m_SupportsSRGB;
  635. }
  636. bool CHardwareConfig::FakeSRGBWrite() const
  637. {
  638. return m_Caps.m_FakeSRGBWrite;
  639. }
  640. bool CHardwareConfig::CanDoSRGBReadFromRTs() const
  641. {
  642. return m_Caps.m_CanDoSRGBReadFromRTs;
  643. }
  644. bool CHardwareConfig::SupportsGLMixedSizeTargets() const
  645. {
  646. return m_Caps.m_bSupportsGLMixedSizeTargets;
  647. }
  648. bool CHardwareConfig::IsAAEnabled() const
  649. {
  650. return g_pShaderDevice ? g_pShaderDevice->IsAAEnabled() : false;
  651. // bool bAntialiasing = ( m_PresentParameters.MultiSampleType != D3DMULTISAMPLE_NONE );
  652. // return bAntialiasing;
  653. }
  654. int CHardwareConfig::GetMaxVertexTextureDimension() const
  655. {
  656. return m_Caps.m_nMaxVertexTextureDimension;
  657. }
  658. HDRType_t CHardwareConfig::GetHDRType() const
  659. {
  660. // On MacOS, this value comes down from the engine, which read it from the registry...which doesn't exist on Mac, so we're slamming to true here
  661. if ( IsOpenGL() )
  662. {
  663. g_pHardwareConfig->SetHDREnabled( true );
  664. }
  665. bool enabled = m_bHDREnabled;
  666. int dxlev = GetDXSupportLevel();
  667. int dxsupp = dxlev >= 90;
  668. HDRType_t caps_hdr = m_Caps.m_HDRType;
  669. HDRType_t result = HDR_TYPE_NONE;
  670. //printf("\nCHardwareConfig::GetHDRType...");
  671. if (enabled)
  672. {
  673. //printf("-> enabled...");
  674. if (dxsupp)
  675. {
  676. //printf("-> supported...");
  677. result = caps_hdr;
  678. }
  679. }
  680. //printf("-> result is %d.\n", result);
  681. return result;
  682. /*
  683. if ( m_bHDREnabled && ( GetDXSupportLevel() >= 90 ) )
  684. return m_Caps.m_HDRType;
  685. return HDR_TYPE_NONE;
  686. */
  687. }
  688. float CHardwareConfig::GetLightMapScaleFactor( void ) const
  689. {
  690. #ifdef _PS3
  691. // PS3 uses floating point lightmaps but not the full HDR_TYPE_FLOAT codepath
  692. return 1.0f;
  693. #else // _PS3
  694. switch( GetHDRType() )
  695. {
  696. case HDR_TYPE_FLOAT:
  697. return 1.0;
  698. break;
  699. case HDR_TYPE_INTEGER:
  700. return 16.0;
  701. case HDR_TYPE_NONE:
  702. default:
  703. return GammaToLinearFullRange( 2.0 ); // light map scale
  704. }
  705. #endif // !_PS3
  706. }
  707. HDRType_t CHardwareConfig::GetHardwareHDRType() const
  708. {
  709. return m_Caps.m_HDRType;
  710. }
  711. bool CHardwareConfig::SupportsStreamOffset() const
  712. {
  713. return m_Caps.m_bSupportsStreamOffset;
  714. }
  715. int CHardwareConfig::StencilBufferBits() const
  716. {
  717. return g_pShaderDevice ? g_pShaderDevice->StencilBufferBits() : 0;
  718. }
  719. int CHardwareConfig:: MaxViewports() const
  720. {
  721. return m_Caps.m_nMaxViewports;
  722. }
  723. int CHardwareConfig::GetActualSamplerCount() const
  724. {
  725. return m_ActualCaps.m_NumSamplers;
  726. }
  727. int CHardwareConfig::GetActualVertexSamplerCount() const
  728. {
  729. return m_ActualCaps.m_NumVertexSamplers;
  730. }
  731. const char *CHardwareConfig::GetHWSpecificShaderDLLName() const
  732. {
  733. return m_Caps.m_pShaderDLL && m_Caps.m_pShaderDLL[0] ? m_Caps.m_pShaderDLL : NULL;
  734. }
  735. bool CHardwareConfig::SupportsShadowDepthTextures( void ) const
  736. {
  737. return m_Caps.m_bSupportsShadowDepthTextures;
  738. }
  739. ImageFormat CHardwareConfig::GetShadowDepthTextureFormat( void ) const
  740. {
  741. return m_Caps.m_ShadowDepthTextureFormat;
  742. }
  743. ImageFormat CHardwareConfig::GetHighPrecisionShadowDepthTextureFormat( void ) const
  744. {
  745. return m_Caps.m_HighPrecisionShadowDepthTextureFormat;
  746. }
  747. ImageFormat CHardwareConfig::GetNullTextureFormat( void ) const
  748. {
  749. return m_Caps.m_NullTextureFormat;
  750. }
  751. bool CHardwareConfig::SupportsCascadedShadowMapping( void ) const
  752. {
  753. #if defined(_PS3)
  754. return m_Caps.m_bSupportsCascadedShadowMapping;
  755. #elif defined(_X360)
  756. return m_Caps.m_bSupportsCascadedShadowMapping;
  757. #else
  758. return m_Caps.m_bSupportsCascadedShadowMapping && ( GetDXSupportLevel() >= 95 );
  759. #endif
  760. }
  761. CSMQualityMode_t CHardwareConfig::GetCSMQuality( void ) const
  762. {
  763. #if defined( _X360 ) || defined( _PS3 )
  764. return CSMQUALITY_VERY_LOW;
  765. #else
  766. return (CSMQualityMode_t)m_Caps.m_nCSMQuality;
  767. #endif
  768. }
  769. bool CHardwareConfig::SupportsBilinearPCFSampling() const
  770. {
  771. if( IsOpenGL() || IsPS3() || IsX360() )
  772. return true;
  773. if ( ( m_Caps.m_VendorID == VENDORID_NVIDIA ) || ( m_Caps.m_VendorID == VENDORID_INTEL ) )
  774. return true;
  775. static bool bForceATIFetch4 = CommandLine()->CheckParm( "-forceatifetch4" ) ? true : false;
  776. if ( bForceATIFetch4 )
  777. return false;
  778. // Non-DX10 class ATI cards (pre-X2000) don't support bilinear PCF in hardware.
  779. if ( ( m_Caps.m_VendorID == VENDORID_ATI ) && ( m_Caps.m_bDX10Card ) )
  780. return true;
  781. return false;
  782. }
  783. // Returns the CSM static combo to select given the current card's capablities and the configured CSM quality level.
  784. CSMShaderMode_t CHardwareConfig::GetCSMShaderMode( CSMQualityMode_t nQualityLevel ) const
  785. {
  786. #if defined( _X360 ) || defined( _PS3 )
  787. return CSMSHADERMODE_LOW_OR_VERY_LOW;
  788. #endif
  789. // Special case for ATI DX9-class (pre ATI HD 2xxx) cards that don't support NVidia-style PCF filtering - always set to CSMSHADERMODE_ATIFETCH4.
  790. if ( !SupportsBilinearPCFSampling() )
  791. return CSMSHADERMODE_ATIFETCH4;
  792. int nMode = nQualityLevel - 1;
  793. if ( nMode < CSMSHADERMODE_LOW_OR_VERY_LOW )
  794. nMode = CSMSHADERMODE_LOW_OR_VERY_LOW;
  795. else if ( nMode > CSMSHADERMODE_HIGH )
  796. nMode = CSMSHADERMODE_HIGH;
  797. return static_cast< CSMShaderMode_t >( nMode );
  798. }
  799. bool CHardwareConfig::GetCSMAccurateBlending( void ) const
  800. {
  801. return m_bCSMAccurateBlending;
  802. }
  803. void CHardwareConfig::SetCSMAccurateBlending( bool bEnable )
  804. {
  805. m_bCSMAccurateBlending = bEnable;
  806. }
  807. bool CHardwareConfig::SupportsResolveDepth( void ) const
  808. {
  809. static ConVarRef mat_resolveFullFrameDepth( "mat_resolveFullFrameDepth" );
  810. static ConVarRef gpu_level( "gpu_level" );
  811. if ( ( gpu_level.GetInt() >= 2 ) &&
  812. ( mat_resolveFullFrameDepth.GetInt() == 1 ) )
  813. {
  814. #if defined(DX_TO_GL_ABSTRACTION)
  815. {
  816. if ( gGL->m_bHave_GL_EXT_framebuffer_blit )
  817. {
  818. return true;
  819. }
  820. else
  821. {
  822. return false;
  823. }
  824. }
  825. #else
  826. {
  827. if ( g_pHardwareConfig->ActualCaps().m_bSupportsINTZ &&
  828. ( g_pHardwareConfig->ActualCaps().m_bSupportsRESZ || ( g_pHardwareConfig->ActualCaps().m_VendorID == VENDORID_NVIDIA ) ) )
  829. {
  830. return true;
  831. }
  832. else
  833. {
  834. return false;
  835. }
  836. }
  837. #endif
  838. }
  839. else
  840. {
  841. return false;
  842. }
  843. }
  844. bool CHardwareConfig::HasFullResolutionDepthTexture(void) const
  845. {
  846. static ConVarRef mat_resolveFullFrameDepth( "mat_resolveFullFrameDepth" );
  847. if ( SupportsResolveDepth() || ( mat_resolveFullFrameDepth.GetInt() == 2 ) )
  848. {
  849. return true;
  850. }
  851. else
  852. {
  853. return false;
  854. }
  855. }
  856. #ifdef _PS3
  857. #include "hardwareconfig_ps3nonvirt.h"
  858. #include "hardwareconfig_ps3nonvirt.inl"
  859. #endif