gfxD3D11QueryFence.cpp
Engine/source/gfx/D3D11/gfxD3D11QueryFence.cpp
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2015 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "gfx/D3D11/gfxD3D11Device.h" 25#include "gfx/D3D11/gfxD3D11QueryFence.h" 26 27GFXD3D11QueryFence::~GFXD3D11QueryFence() 28{ 29 SAFE_RELEASE(mQuery); 30} 31 32void GFXD3D11QueryFence::issue() 33{ 34 PROFILE_START(GFXD3D11QueryFence_issue); 35 36 // Create the query if we need to 37 if(mQuery == NULL) 38 { 39 D3D11_QUERY_DESC QueryDesc; 40 QueryDesc.Query = D3D11_QUERY_EVENT; 41 QueryDesc.MiscFlags = 0; 42 43 HRESULT hRes = D3D11DEVICE->CreateQuery(&QueryDesc, &mQuery); 44 45 if(FAILED(hRes)) 46 { 47 AssertFatal(false, "Hardware does not support D3D11 Queries, this should be caught before this fence type is created" ); 48 } 49 50 AssertISV(hRes != E_OUTOFMEMORY, "Out of memory"); 51 } 52 53 // Issue the query 54 D3D11DEVICECONTEXT->End(mQuery); 55 PROFILE_END(); 56} 57 58GFXFence::FenceStatus GFXD3D11QueryFence::getStatus() const 59{ 60 if(mQuery == NULL) 61 return GFXFence::Unset; 62 63 HRESULT hRes = D3D11DEVICECONTEXT->GetData(mQuery, NULL, 0, 0); 64 65 return (hRes == S_OK ? GFXFence::Processed : GFXFence::Pending); 66} 67 68void GFXD3D11QueryFence::block() 69{ 70 PROFILE_SCOPE(GFXD3D11QueryFence_block); 71 72 // Calling block() before issue() is valid, catch this case 73 if( mQuery == NULL ) 74 return; 75 76 HRESULT hRes; 77 while((hRes = D3D11DEVICECONTEXT->GetData(mQuery, NULL, 0, 0)) == S_FALSE); //D3DGETDATA_FLUSH 78 79} 80 81void GFXD3D11QueryFence::zombify() 82{ 83 // Release our query 84 SAFE_RELEASE( mQuery ); 85} 86 87void GFXD3D11QueryFence::resurrect() 88{ 89 // Recreate the query 90 if(mQuery == NULL) 91 { 92 D3D11_QUERY_DESC QueryDesc; 93 QueryDesc.Query = D3D11_QUERY_EVENT; 94 QueryDesc.MiscFlags = 0; 95 96 HRESULT hRes = D3D11DEVICE->CreateQuery(&QueryDesc, &mQuery); 97 98 if(FAILED(hRes)) 99 { 100 AssertFatal(false, "GFXD3D11QueryFence::resurrect - Hardware does not support D3D11 Queries, this should be caught before this fence type is created"); 101 } 102 103 AssertISV(hRes != E_OUTOFMEMORY, "GFXD3D11QueryFence::resurrect - Out of memory"); 104 } 105} 106 107const String GFXD3D11QueryFence::describeSelf() const 108{ 109 // We've got nothing 110 return String(); 111} 112