gfxD3D9QueryFence.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "gfx/D3D9/gfxD3D9QueryFence.h"
  24. GFXD3D9QueryFence::~GFXD3D9QueryFence()
  25. {
  26. SAFE_RELEASE( mQuery );
  27. }
  28. //------------------------------------------------------------------------------
  29. void GFXD3D9QueryFence::issue()
  30. {
  31. PROFILE_START( GFXD3D9QueryFence_issue );
  32. // Create the query if we need to
  33. if( mQuery == NULL )
  34. {
  35. HRESULT hRes = static_cast<GFXD3D9Device *>( mDevice )->getDevice()->CreateQuery( D3DQUERYTYPE_EVENT, &mQuery );
  36. AssertFatal( hRes != D3DERR_NOTAVAILABLE, "Hardware does not support D3D9 Queries, this should be caught before this fence type is created" );
  37. AssertISV( hRes != E_OUTOFMEMORY, "Out of memory" );
  38. }
  39. // Issue the query
  40. mQuery->Issue( D3DISSUE_END );
  41. PROFILE_END();
  42. }
  43. //------------------------------------------------------------------------------
  44. GFXFence::FenceStatus GFXD3D9QueryFence::getStatus() const
  45. {
  46. if( mQuery == NULL )
  47. return GFXFence::Unset;
  48. HRESULT hRes = mQuery->GetData( NULL, 0, 0 );
  49. return ( hRes == S_OK ? GFXFence::Processed : GFXFence::Pending );
  50. }
  51. //------------------------------------------------------------------------------
  52. void GFXD3D9QueryFence::block()
  53. {
  54. PROFILE_SCOPE(GFXD3D9QueryFence_block);
  55. // Calling block() before issue() is valid, catch this case
  56. if( mQuery == NULL )
  57. return;
  58. HRESULT hRes;
  59. while( ( hRes = mQuery->GetData( NULL, 0, D3DGETDATA_FLUSH ) ) == S_FALSE )
  60. ;
  61. // Check for D3DERR_DEVICELOST, if we lost the device, the fence will get
  62. // re-created next issue()
  63. if( hRes == D3DERR_DEVICELOST )
  64. SAFE_RELEASE( mQuery );
  65. }
  66. void GFXD3D9QueryFence::zombify()
  67. {
  68. // Release our query
  69. SAFE_RELEASE( mQuery );
  70. }
  71. void GFXD3D9QueryFence::resurrect()
  72. {
  73. // Recreate the query
  74. if( mQuery == NULL )
  75. {
  76. HRESULT hRes = static_cast<GFXD3D9Device *>( mDevice )->getDevice()->CreateQuery( D3DQUERYTYPE_EVENT, &mQuery );
  77. AssertFatal( hRes != D3DERR_NOTAVAILABLE, "GFXD3D9QueryFence::resurrect - Hardware does not support D3D9 Queries, this should be caught before this fence type is created" );
  78. AssertISV( hRes != E_OUTOFMEMORY, "GFXD3D9QueryFence::resurrect - Out of memory" );
  79. }
  80. }
  81. const String GFXD3D9QueryFence::describeSelf() const
  82. {
  83. // We've got nothing
  84. return String();
  85. }