1 #include "precompiled.h" 2 // 3 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style license that can be 5 // found in the LICENSE file. 6 // 7 8 // Query11.cpp: Defines the rx::Query11 class which implements rx::QueryImpl. 9 10 #include "libGLESv2/renderer/Query11.h" 11 #include "libGLESv2/renderer/Renderer11.h" 12 #include "libGLESv2/main.h" 13 14 namespace rx 15 { 16 Query11(rx::Renderer11 * renderer,GLenum type)17Query11::Query11(rx::Renderer11 *renderer, GLenum type) : QueryImpl(type) 18 { 19 mRenderer = renderer; 20 mQuery = NULL; 21 } 22 ~Query11()23Query11::~Query11() 24 { 25 if (mQuery) 26 { 27 mQuery->Release(); 28 mQuery = NULL; 29 } 30 } 31 begin()32void Query11::begin() 33 { 34 if (mQuery == NULL) 35 { 36 D3D11_QUERY_DESC queryDesc; 37 queryDesc.Query = D3D11_QUERY_OCCLUSION; 38 queryDesc.MiscFlags = 0; 39 40 if (FAILED(mRenderer->getDevice()->CreateQuery(&queryDesc, &mQuery))) 41 { 42 return gl::error(GL_OUT_OF_MEMORY); 43 } 44 } 45 46 mRenderer->getDeviceContext()->Begin(mQuery); 47 } 48 end()49void Query11::end() 50 { 51 if (mQuery == NULL) 52 { 53 return gl::error(GL_INVALID_OPERATION); 54 } 55 56 mRenderer->getDeviceContext()->End(mQuery); 57 58 mStatus = GL_FALSE; 59 mResult = GL_FALSE; 60 } 61 getResult()62GLuint Query11::getResult() 63 { 64 if (mQuery != NULL) 65 { 66 while (!testQuery()) 67 { 68 Sleep(0); 69 // explicitly check for device loss, some drivers seem to return S_FALSE 70 // if the device is lost 71 if (mRenderer->testDeviceLost(true)) 72 { 73 return gl::error(GL_OUT_OF_MEMORY, 0); 74 } 75 } 76 } 77 78 return mResult; 79 } 80 isResultAvailable()81GLboolean Query11::isResultAvailable() 82 { 83 if (mQuery != NULL) 84 { 85 testQuery(); 86 } 87 88 return mStatus; 89 } 90 testQuery()91GLboolean Query11::testQuery() 92 { 93 if (mQuery != NULL && mStatus != GL_TRUE) 94 { 95 UINT64 numPixels = 0; 96 HRESULT result = mRenderer->getDeviceContext()->GetData(mQuery, &numPixels, sizeof(UINT64), 0); 97 if (result == S_OK) 98 { 99 mStatus = GL_TRUE; 100 101 switch (getType()) 102 { 103 case GL_ANY_SAMPLES_PASSED_EXT: 104 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: 105 mResult = (numPixels > 0) ? GL_TRUE : GL_FALSE; 106 break; 107 default: 108 UNREACHABLE(); 109 } 110 } 111 else if (mRenderer->testDeviceLost(true)) 112 { 113 return gl::error(GL_OUT_OF_MEMORY, GL_TRUE); 114 } 115 116 return mStatus; 117 } 118 119 return GL_TRUE; // prevent blocking when query is null 120 } 121 122 } 123