gfxD3D9CardProfiler.cpp 5.4 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_WIN
  28. #include "platformWin32/videoInfo/wmiVideoInfo.h"
  29. #endif
  30. GFXD3D9CardProfiler::GFXD3D9CardProfiler(U32 adapterIndex) : GFXCardProfiler()
  31. {
  32. mAdapterOrdinal = adapterIndex;
  33. }
  34. GFXD3D9CardProfiler::~GFXD3D9CardProfiler()
  35. {
  36. }
  37. void GFXD3D9CardProfiler::init()
  38. {
  39. mD3DDevice = dynamic_cast<GFXD3D9Device *>(GFX)->getDevice();
  40. AssertISV( mD3DDevice, "GFXD3D9CardProfiler::init() - No D3D9 Device found!");
  41. // Grab the caps so we can get our adapter ordinal and look up our name.
  42. D3DCAPS9 caps;
  43. D3D9Assert(mD3DDevice->GetDeviceCaps(&caps), "GFXD3D9CardProfiler::init - failed to get device caps!");
  44. #ifdef TORQUE_OS_XENON
  45. mCardDescription = "Xbox360 GPU";
  46. mChipSet = "ATI";
  47. mVersionString = String::ToString(_XDK_VER);
  48. mVideoMemory = 512 * 1024 * 1024;
  49. #else
  50. WMIVideoInfo wmiVidInfo;
  51. if( wmiVidInfo.profileAdapters() )
  52. {
  53. const PlatformVideoInfo::PVIAdapter &adapter = wmiVidInfo.getAdapterInformation( caps.AdapterOrdinal );
  54. mCardDescription = adapter.description;
  55. mChipSet = adapter.chipSet;
  56. mVersionString = adapter.driverVersion;
  57. mVideoMemory = adapter.vram;
  58. }
  59. #endif
  60. Parent::init();
  61. }
  62. void GFXD3D9CardProfiler::setupCardCapabilities()
  63. {
  64. // Get the D3D device caps
  65. D3DCAPS9 caps;
  66. mD3DDevice->GetDeviceCaps(&caps);
  67. setCapability( "autoMipMapLevel", ( caps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP ? 1 : 0 ) );
  68. setCapability( "maxTextureWidth", caps.MaxTextureWidth );
  69. setCapability( "maxTextureHeight", caps.MaxTextureHeight );
  70. setCapability( "maxTextureSize", getMin( (U32)caps.MaxTextureWidth, (U32)caps.MaxTextureHeight) );
  71. bool canDoLERPDetailBlend = ( caps.TextureOpCaps & D3DTEXOPCAPS_LERP ) && ( caps.MaxTextureBlendStages > 1 );
  72. bool canDoFourStageDetailBlend = ( caps.TextureOpCaps & D3DTEXOPCAPS_SUBTRACT ) &&
  73. ( caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP ) &&
  74. ( caps.MaxTextureBlendStages > 3 );
  75. setCapability( "lerpDetailBlend", canDoLERPDetailBlend );
  76. setCapability( "fourStageDetailBlend", canDoFourStageDetailBlend );
  77. }
  78. bool GFXD3D9CardProfiler::_queryCardCap(const String &query, U32 &foundResult)
  79. {
  80. return 0;
  81. }
  82. bool GFXD3D9CardProfiler::_queryFormat( const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips )
  83. {
  84. LPDIRECT3D9 pD3D = static_cast<GFXD3D9Device *>(GFX)->getD3D();
  85. D3DDISPLAYMODE displayMode = static_cast<GFXD3D9Device *>(GFX)->getDisplayMode();
  86. DWORD usage = 0;
  87. D3DRESOURCETYPE rType = D3DRTYPE_TEXTURE;
  88. D3DFORMAT adapterFormat = displayMode.Format;
  89. D3DFORMAT texFormat = GFXD3D9TextureFormat[fmt];
  90. #if defined(TORQUE_OS_XENON)
  91. inOutAutogenMips = false;
  92. adapterFormat = D3DFMT_A8B8G8R8;
  93. if(profile->isRenderTarget())
  94. {
  95. texFormat = (D3DFORMAT)MAKELEFMT(texFormat);
  96. }
  97. #else
  98. if( profile->isRenderTarget() )
  99. usage |= D3DUSAGE_RENDERTARGET;
  100. else if( profile->isZTarget() )
  101. {
  102. usage |= D3DUSAGE_DEPTHSTENCIL;
  103. rType = D3DRTYPE_SURFACE;
  104. }
  105. if( inOutAutogenMips )
  106. usage |= D3DUSAGE_AUTOGENMIPMAP;
  107. #endif
  108. // Early-check to see if the enum translation table has an unsupported value
  109. if(texFormat == (_D3DFORMAT)GFX_UNSUPPORTED_VAL)
  110. return false;
  111. HRESULT hr = pD3D->CheckDeviceFormat( mAdapterOrdinal, D3DDEVTYPE_HAL,
  112. adapterFormat, usage, rType, texFormat );
  113. bool retVal = SUCCEEDED( hr );
  114. #if !defined(TORQUE_OS_XENON)
  115. // If check device format failed, and auto gen mips were requested, try again
  116. // without autogen mips.
  117. if( !retVal && inOutAutogenMips )
  118. {
  119. usage ^= D3DUSAGE_AUTOGENMIPMAP;
  120. hr = pD3D->CheckDeviceFormat( mAdapterOrdinal, D3DDEVTYPE_HAL,
  121. adapterFormat, usage, D3DRTYPE_TEXTURE, GFXD3D9TextureFormat[fmt] );
  122. retVal = SUCCEEDED( hr );
  123. // If this one passed, auto gen mips are not supported with this format,
  124. // so set the variable properly
  125. if( retVal )
  126. inOutAutogenMips = false;
  127. }
  128. #endif
  129. return retVal;
  130. }