Hash :
9d737966
Author :
Date :
2019-08-14T12:25:12
Standardize copyright notices to project style
For all "ANGLE Project" copyrights, standardize to the format specified
by the style guide. Changes:
- "Copyright (c)" and "Copyright(c)" changed to just "Copyright".
- Removed the second half of date ranges ("Y1Y1-Y2Y2"->"Y1Y1").
- Fixed a small number of files that had no copyright date using the
initial commit year from the version control history.
- Fixed one instance of copyright being "The ANGLE Project" rather than
"The ANGLE Project Authors"
These changes are applied both to the copyright of source file, and
where applicable to copyright statements that are generated by
templates.
BUG=angleproject:3811
Change-Id: I973dd65e4ef9deeba232d5be74c768256a0eb2e5
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1754397
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Jamie Madill <jmadill@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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
//
// Copyright 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.
//
// Fence11.cpp: Defines the rx::FenceNV11 and rx::Sync11 classes which implement
// rx::FenceNVImpl and rx::SyncImpl.
#include "libANGLE/renderer/d3d/d3d11/Fence11.h"
#include "common/utilities.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/d3d/d3d11/Context11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
namespace rx
{
//
// Template helpers for set and test operations.
//
template <class FenceClass>
angle::Result FenceSetHelper(const gl::Context *context, FenceClass *fence)
{
if (!fence->mQuery)
{
D3D11_QUERY_DESC queryDesc;
queryDesc.Query = D3D11_QUERY_EVENT;
queryDesc.MiscFlags = 0;
Context11 *context11 = GetImplAs<Context11>(context);
HRESULT result = fence->mRenderer->getDevice()->CreateQuery(&queryDesc, &fence->mQuery);
ANGLE_TRY_HR(context11, result, "Failed to create event query");
}
fence->mRenderer->getDeviceContext()->End(fence->mQuery);
return angle::Result::Continue;
}
template <class FenceClass>
angle::Result FenceTestHelper(const gl::Context *context,
FenceClass *fence,
bool flushCommandBuffer,
GLboolean *outFinished)
{
ASSERT(fence->mQuery);
UINT getDataFlags = (flushCommandBuffer ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH);
Context11 *context11 = GetImplAs<Context11>(context);
HRESULT result =
fence->mRenderer->getDeviceContext()->GetData(fence->mQuery, nullptr, 0, getDataFlags);
ANGLE_TRY_HR(context11, result, "Failed to get query data");
ASSERT(result == S_OK || result == S_FALSE);
*outFinished = ((result == S_OK) ? GL_TRUE : GL_FALSE);
return angle::Result::Continue;
}
//
// FenceNV11
//
FenceNV11::FenceNV11(Renderer11 *renderer) : FenceNVImpl(), mRenderer(renderer), mQuery(nullptr) {}
FenceNV11::~FenceNV11()
{
SafeRelease(mQuery);
}
angle::Result FenceNV11::set(const gl::Context *context, GLenum condition)
{
return FenceSetHelper(context, this);
}
angle::Result FenceNV11::test(const gl::Context *context, GLboolean *outFinished)
{
return FenceTestHelper(context, this, true, outFinished);
}
angle::Result FenceNV11::finish(const gl::Context *context)
{
GLboolean finished = GL_FALSE;
int loopCount = 0;
while (finished != GL_TRUE)
{
loopCount++;
ANGLE_TRY(FenceTestHelper(context, this, true, &finished));
bool checkDeviceLost = (loopCount % kPollingD3DDeviceLostCheckFrequency) == 0;
if (checkDeviceLost && mRenderer->testDeviceLost())
{
ANGLE_TRY_HR(GetImplAs<Context11>(context), DXGI_ERROR_DRIVER_INTERNAL_ERROR,
"Device was lost while querying result of an event query.");
}
ScheduleYield();
}
return angle::Result::Continue;
}
//
// Sync11
//
// Important note on accurate timers in Windows:
//
// QueryPerformanceCounter has a few major issues, including being 10x as expensive to call
// as timeGetTime on laptops and "jumping" during certain hardware events.
//
// See the comments at the top of the Chromium source file "chromium/src/base/time/time_win.cc"
// https://code.google.com/p/chromium/codesearch#chromium/src/base/time/time_win.cc
//
// We still opt to use QPC. In the present and moving forward, most newer systems will not suffer
// from buggy implementations.
Sync11::Sync11(Renderer11 *renderer) : SyncImpl(), mRenderer(renderer), mQuery(nullptr)
{
LARGE_INTEGER counterFreqency = {};
BOOL success = QueryPerformanceFrequency(&counterFreqency);
ASSERT(success);
mCounterFrequency = counterFreqency.QuadPart;
}
Sync11::~Sync11()
{
SafeRelease(mQuery);
}
angle::Result Sync11::set(const gl::Context *context, GLenum condition, GLbitfield flags)
{
ASSERT(condition == GL_SYNC_GPU_COMMANDS_COMPLETE && flags == 0);
return FenceSetHelper(context, this);
}
angle::Result Sync11::clientWait(const gl::Context *context,
GLbitfield flags,
GLuint64 timeout,
GLenum *outResult)
{
ASSERT(outResult);
bool flushCommandBuffer = ((flags & GL_SYNC_FLUSH_COMMANDS_BIT) != 0);
*outResult = GL_WAIT_FAILED;
GLboolean result = GL_FALSE;
ANGLE_TRY(FenceTestHelper(context, this, flushCommandBuffer, &result));
if (result == GL_TRUE)
{
*outResult = GL_ALREADY_SIGNALED;
return angle::Result::Continue;
}
if (timeout == 0)
{
*outResult = GL_TIMEOUT_EXPIRED;
return angle::Result::Continue;
}
LARGE_INTEGER currentCounter = {};
BOOL success = QueryPerformanceCounter(¤tCounter);
ASSERT(success);
LONGLONG timeoutInSeconds = static_cast<LONGLONG>(timeout / 1000000000ull);
LONGLONG endCounter = currentCounter.QuadPart + mCounterFrequency * timeoutInSeconds;
// Extremely unlikely, but if mCounterFrequency is large enough, endCounter can wrap
if (endCounter < currentCounter.QuadPart)
{
endCounter = MAXLONGLONG;
}
int loopCount = 0;
while (currentCounter.QuadPart < endCounter && !result)
{
loopCount++;
ScheduleYield();
success = QueryPerformanceCounter(¤tCounter);
ASSERT(success);
*outResult = GL_WAIT_FAILED;
ANGLE_TRY(FenceTestHelper(context, this, flushCommandBuffer, &result));
bool checkDeviceLost = (loopCount % kPollingD3DDeviceLostCheckFrequency) == 0;
if (checkDeviceLost && mRenderer->testDeviceLost())
{
*outResult = GL_WAIT_FAILED;
ANGLE_TRY_HR(GetImplAs<Context11>(context), DXGI_ERROR_DRIVER_INTERNAL_ERROR,
"Device was lost while querying result of an event query.");
}
}
if (currentCounter.QuadPart >= endCounter)
{
*outResult = GL_TIMEOUT_EXPIRED;
}
else
{
*outResult = GL_CONDITION_SATISFIED;
}
return angle::Result::Continue;
}
angle::Result Sync11::serverWait(const gl::Context *context, GLbitfield flags, GLuint64 timeout)
{
// Because our API is currently designed to be called from a single thread, we don't need to do
// extra work for a server-side fence. GPU commands issued after the fence is created will
// always be processed after the fence is signaled.
return angle::Result::Continue;
}
angle::Result Sync11::getStatus(const gl::Context *context, GLint *outResult)
{
GLboolean result = GL_FALSE;
// The spec does not specify any way to report errors during the status test (e.g. device
// lost) so we report the fence is unblocked in case of error or signaled.
*outResult = GL_SIGNALED;
ANGLE_TRY(FenceTestHelper(context, this, false, &result));
*outResult = (result ? GL_SIGNALED : GL_UNSIGNALED);
return angle::Result::Continue;
}
} // namespace rx