Hash :
c7a41049
Author :
Date :
2014-06-23T12:03:25
Moved D3D specific files and folders under the D3D folder. Change-Id: I8afd67e08ee558fe94532c377d079673357a7192 Reviewed-on: https://chromium-review.googlesource.com/205229 Reviewed-by: Shannon Woods <shannonwoods@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
#include "precompiled.h"
//
// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Query11.cpp: Defines the rx::Query11 class which implements rx::QueryImpl.
#include "libGLESv2/renderer/d3d/d3d11/Query11.h"
#include "libGLESv2/renderer/d3d/d3d11/Renderer11.h"
#include "libGLESv2/renderer/d3d/d3d11/renderer11_utils.h"
#include "libGLESv2/main.h"
namespace rx
{
static bool checkOcclusionQuery(ID3D11DeviceContext *context, ID3D11Query *query, UINT64 *numPixels)
{
HRESULT result = context->GetData(query, numPixels, sizeof(UINT64), 0);
return (result == S_OK);
}
static bool checkStreamOutPrimitivesWritten(ID3D11DeviceContext *context, ID3D11Query *query, UINT64 *numPrimitives)
{
D3D11_QUERY_DATA_SO_STATISTICS soStats = { 0 };
HRESULT result = context->GetData(query, &soStats, sizeof(D3D11_QUERY_DATA_SO_STATISTICS), 0);
*numPrimitives = soStats.NumPrimitivesWritten;
return (result == S_OK);
}
Query11::Query11(rx::Renderer11 *renderer, GLenum type) : QueryImpl(type)
{
mRenderer = renderer;
mQuery = NULL;
}
Query11::~Query11()
{
SafeRelease(mQuery);
}
void Query11::begin()
{
if (mQuery == NULL)
{
D3D11_QUERY_DESC queryDesc;
queryDesc.Query = gl_d3d11::ConvertQueryType(getType());
queryDesc.MiscFlags = 0;
if (FAILED(mRenderer->getDevice()->CreateQuery(&queryDesc, &mQuery)))
{
return gl::error(GL_OUT_OF_MEMORY);
}
}
mRenderer->getDeviceContext()->Begin(mQuery);
}
void Query11::end()
{
ASSERT(mQuery);
mRenderer->getDeviceContext()->End(mQuery);
mStatus = GL_FALSE;
mResult = GL_FALSE;
}
GLuint Query11::getResult()
{
if (mQuery != NULL)
{
while (!testQuery())
{
Sleep(0);
// explicitly check for device loss, some drivers seem to return S_FALSE
// if the device is lost
if (mRenderer->testDeviceLost(true))
{
return gl::error(GL_OUT_OF_MEMORY, 0);
}
}
}
return mResult;
}
GLboolean Query11::isResultAvailable()
{
if (mQuery != NULL)
{
testQuery();
}
return mStatus;
}
GLboolean Query11::testQuery()
{
if (mQuery != NULL && mStatus != GL_TRUE)
{
ID3D11DeviceContext *context = mRenderer->getDeviceContext();
bool queryFinished = false;
switch (getType())
{
case GL_ANY_SAMPLES_PASSED_EXT:
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
{
UINT64 numPixels = 0;
queryFinished = checkOcclusionQuery(context, mQuery, &numPixels);
if (queryFinished)
{
mResult = (numPixels > 0) ? GL_TRUE : GL_FALSE;
}
}
break;
case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
{
UINT64 numPrimitives = 0;
queryFinished = checkStreamOutPrimitivesWritten(context, mQuery, &numPrimitives);
if (queryFinished)
{
mResult = static_cast<GLuint>(numPrimitives);
}
}
break;
default:
UNREACHABLE();
break;
}
if (queryFinished)
{
mStatus = GL_TRUE;
}
else if (mRenderer->testDeviceLost(true))
{
return gl::error(GL_OUT_OF_MEMORY, GL_TRUE);
}
return mStatus;
}
return GL_TRUE; // prevent blocking when query is null
}
bool Query11::isStarted() const
{
return (mQuery != NULL);
}
}