gfxD3D11QueryFence.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2015 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/D3D11/gfxD3D11Device.h"
  23. #include "gfx/D3D11/gfxD3D11QueryFence.h"
  24. GFXD3D11QueryFence::~GFXD3D11QueryFence()
  25. {
  26. SAFE_RELEASE(mQuery);
  27. }
  28. void GFXD3D11QueryFence::issue()
  29. {
  30. PROFILE_START(GFXD3D11QueryFence_issue);
  31. // Create the query if we need to
  32. if(mQuery == NULL)
  33. {
  34. D3D11_QUERY_DESC QueryDesc;
  35. QueryDesc.Query = D3D11_QUERY_EVENT;
  36. QueryDesc.MiscFlags = 0;
  37. HRESULT hRes = D3D11DEVICE->CreateQuery(&QueryDesc, &mQuery);
  38. if(FAILED(hRes))
  39. {
  40. AssertFatal(false, "Hardware does not support D3D11 Queries, this should be caught before this fence type is created" );
  41. }
  42. AssertISV(hRes != E_OUTOFMEMORY, "Out of memory");
  43. }
  44. // Issue the query
  45. D3D11DEVICECONTEXT->End(mQuery);
  46. PROFILE_END();
  47. }
  48. GFXFence::FenceStatus GFXD3D11QueryFence::getStatus() const
  49. {
  50. if(mQuery == NULL)
  51. return GFXFence::Unset;
  52. HRESULT hRes = D3D11DEVICECONTEXT->GetData(mQuery, NULL, 0, 0);
  53. return (hRes == S_OK ? GFXFence::Processed : GFXFence::Pending);
  54. }
  55. void GFXD3D11QueryFence::block()
  56. {
  57. PROFILE_SCOPE(GFXD3D11QueryFence_block);
  58. // Calling block() before issue() is valid, catch this case
  59. if( mQuery == NULL )
  60. return;
  61. HRESULT hRes;
  62. while((hRes = D3D11DEVICECONTEXT->GetData(mQuery, NULL, 0, 0)) == S_FALSE); //D3DGETDATA_FLUSH
  63. }
  64. void GFXD3D11QueryFence::zombify()
  65. {
  66. // Release our query
  67. SAFE_RELEASE( mQuery );
  68. }
  69. void GFXD3D11QueryFence::resurrect()
  70. {
  71. // Recreate the query
  72. if(mQuery == NULL)
  73. {
  74. D3D11_QUERY_DESC QueryDesc;
  75. QueryDesc.Query = D3D11_QUERY_EVENT;
  76. QueryDesc.MiscFlags = 0;
  77. HRESULT hRes = D3D11DEVICE->CreateQuery(&QueryDesc, &mQuery);
  78. if(FAILED(hRes))
  79. {
  80. AssertFatal(false, "GFXD3D11QueryFence::resurrect - Hardware does not support D3D11 Queries, this should be caught before this fence type is created");
  81. }
  82. AssertISV(hRes != E_OUTOFMEMORY, "GFXD3D11QueryFence::resurrect - Out of memory");
  83. }
  84. }
  85. const String GFXD3D11QueryFence::describeSelf() const
  86. {
  87. // We've got nothing
  88. return String();
  89. }