gfxD3D9CardProfiler.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "gfx/D3D9/gfxD3D9Device.h"
  23. #include "console/console.h"
  24. #include "gfx/primBuilder.h"
  25. #include "gfx/D3D9/gfxD3D9CardProfiler.h"
  26. #include "gfx/D3D9/gfxD3D9EnumTranslate.h"
  27. #ifdef TORQUE_OS_WIN32
  28. #include "platformWin32/videoInfo/wmiVideoInfo.h"
  29. #endif
  30. GFXD3D9CardProfiler::GFXD3D9CardProfiler() : GFXCardProfiler()
  31. {
  32. }
  33. GFXD3D9CardProfiler::~GFXD3D9CardProfiler()
  34. {
  35. }
  36. void GFXD3D9CardProfiler::init()
  37. {
  38. mD3DDevice = dynamic_cast<GFXD3D9Device *>(GFX)->getDevice();
  39. AssertISV( mD3DDevice, "GFXD3D9CardProfiler::init() - No D3D9 Device found!");
  40. // Grab the caps so we can get our adapter ordinal and look up our name.
  41. D3DCAPS9 caps;
  42. D3D9Assert(mD3DDevice->GetDeviceCaps(&caps), "GFXD3D9CardProfiler::init - failed to get device caps!");
  43. #ifdef TORQUE_OS_XENON
  44. mCardDescription = "Xbox360 GPU";
  45. mChipSet = "ATI";
  46. mVersionString = String::ToString(_XDK_VER);
  47. mVideoMemory = 512 * 1024 * 1024;
  48. #else
  49. WMIVideoInfo wmiVidInfo;
  50. if( wmiVidInfo.profileAdapters() )
  51. {
  52. const PlatformVideoInfo::PVIAdapter &adapter = wmiVidInfo.getAdapterInformation( caps.AdapterOrdinal );
  53. mCardDescription = adapter.description;
  54. mChipSet = adapter.chipSet;
  55. mVersionString = adapter.driverVersion;
  56. mVideoMemory = adapter.vram;
  57. }
  58. #endif
  59. Parent::init();
  60. }
  61. void GFXD3D9CardProfiler::setupCardCapabilities()
  62. {
  63. // Get the D3D device caps
  64. D3DCAPS9 caps;
  65. mD3DDevice->GetDeviceCaps(&caps);
  66. setCapability( "autoMipMapLevel", ( caps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP ? 1 : 0 ) );
  67. setCapability( "maxTextureWidth", caps.MaxTextureWidth );
  68. setCapability( "maxTextureHeight", caps.MaxTextureHeight );
  69. setCapability( "maxTextureSize", getMin( (U32)caps.MaxTextureWidth, (U32)caps.MaxTextureHeight) );
  70. bool canDoLERPDetailBlend = ( caps.TextureOpCaps & D3DTEXOPCAPS_LERP ) && ( caps.MaxTextureBlendStages > 1 );
  71. bool canDoFourStageDetailBlend = ( caps.TextureOpCaps & D3DTEXOPCAPS_SUBTRACT ) &&
  72. ( caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP ) &&
  73. ( caps.MaxTextureBlendStages > 3 );
  74. setCapability( "lerpDetailBlend", canDoLERPDetailBlend );
  75. setCapability( "fourStageDetailBlend", canDoFourStageDetailBlend );
  76. }
  77. bool GFXD3D9CardProfiler::_queryCardCap(const String &query, U32 &foundResult)
  78. {
  79. return 0;
  80. }
  81. bool GFXD3D9CardProfiler::_queryFormat( const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips )
  82. {
  83. LPDIRECT3D9 pD3D = static_cast<GFXD3D9Device *>(GFX)->getD3D();
  84. D3DDISPLAYMODE displayMode = static_cast<GFXD3D9Device *>(GFX)->getDisplayMode();
  85. DWORD usage = 0;
  86. D3DRESOURCETYPE rType = D3DRTYPE_TEXTURE;
  87. D3DFORMAT adapterFormat = displayMode.Format;
  88. D3DFORMAT texFormat = GFXD3D9TextureFormat[fmt];
  89. #if defined(TORQUE_OS_XENON)
  90. inOutAutogenMips = false;
  91. adapterFormat = D3DFMT_A8B8G8R8;
  92. if(profile->isRenderTarget())
  93. {
  94. texFormat = (D3DFORMAT)MAKELEFMT(texFormat);
  95. }
  96. #else
  97. if( profile->isRenderTarget() )
  98. usage |= D3DUSAGE_RENDERTARGET;
  99. else if( profile->isZTarget() )
  100. {
  101. usage |= D3DUSAGE_DEPTHSTENCIL;
  102. rType = D3DRTYPE_SURFACE;
  103. }
  104. if( inOutAutogenMips )
  105. usage |= D3DUSAGE_AUTOGENMIPMAP;
  106. #endif
  107. // Early-check to see if the enum translation table has an unsupported value
  108. if(texFormat == (_D3DFORMAT)GFX_UNSUPPORTED_VAL)
  109. return false;
  110. HRESULT hr = pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
  111. adapterFormat, usage, rType, texFormat );
  112. bool retVal = SUCCEEDED( hr );
  113. #if !defined(TORQUE_OS_XENON)
  114. // If check device format failed, and auto gen mips were requested, try again
  115. // without autogen mips.
  116. if( !retVal && inOutAutogenMips )
  117. {
  118. usage ^= D3DUSAGE_AUTOGENMIPMAP;
  119. hr = pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
  120. adapterFormat, usage, D3DRTYPE_TEXTURE, GFXD3D9TextureFormat[fmt] );
  121. retVal = SUCCEEDED( hr );
  122. // If this one passed, auto gen mips are not supported with this format,
  123. // so set the variable properly
  124. if( retVal )
  125. inOutAutogenMips = false;
  126. }
  127. #endif
  128. return retVal;
  129. }