GLContext::WasLost - Determines if we lost the context due to a TDR or another outstanding event.

This commit is contained in:
Dr. Chat 2015-12-20 21:13:51 -06:00
parent 0c60cc5f48
commit 30eda6909f
3 changed files with 66 additions and 18 deletions

View File

@ -133,20 +133,31 @@ bool GLContext::Initialize(GLContext* share_context) {
return false;
}
bool robust_access_supported = false;
if (GLEW_ARB_robustness) {
robust_access_supported = true;
}
int context_flags = 0;
if (FLAGS_gl_debug) {
context_flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
}
if (robust_access_supported) {
context_flags |= WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB;
}
int attrib_list[] = {WGL_CONTEXT_MAJOR_VERSION_ARB,
4,
WGL_CONTEXT_MINOR_VERSION_ARB,
5,
WGL_CONTEXT_FLAGS_ARB,
context_flags,
WGL_CONTEXT_PROFILE_MASK_ARB,
WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0};
int attrib_list[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB,
4,
WGL_CONTEXT_MINOR_VERSION_ARB,
5,
WGL_CONTEXT_FLAGS_ARB,
context_flags,
WGL_CONTEXT_PROFILE_MASK_ARB,
WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
robust_access_supported ? WGL_LOSE_CONTEXT_ON_RESET_ARB : 0,
0};
glrc_ = wglCreateContextAttribsARB(
dc_, share_context ? share_context->glrc_ : nullptr, attrib_list);
@ -196,20 +207,31 @@ std::unique_ptr<GLContext> GLContext::CreateOffscreen(
{
GraphicsContextLock context_lock(parent_context);
bool robust_access_supported = false;
if (GLEW_ARB_robustness) {
robust_access_supported = true;
}
int context_flags = 0;
if (FLAGS_gl_debug) {
context_flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
}
if (robust_access_supported) {
context_flags |= WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB;
}
int attrib_list[] = {WGL_CONTEXT_MAJOR_VERSION_ARB,
4,
WGL_CONTEXT_MINOR_VERSION_ARB,
5,
WGL_CONTEXT_FLAGS_ARB,
context_flags,
WGL_CONTEXT_PROFILE_MASK_ARB,
WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0};
int attrib_list[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB,
4,
WGL_CONTEXT_MINOR_VERSION_ARB,
5,
WGL_CONTEXT_FLAGS_ARB,
context_flags,
WGL_CONTEXT_PROFILE_MASK_ARB,
WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
robust_access_supported ? WGL_LOSE_CONTEXT_ON_RESET_ARB : 0,
0};
new_glrc = wglCreateContextAttribsARB(parent_context->dc_,
parent_context->glrc_, attrib_list);
if (!new_glrc) {
@ -450,6 +472,23 @@ void GLContext::ClearCurrent() {
}
}
bool GLContext::WasLost() {
if (context_lost_) {
return true;
}
auto status = glGetGraphicsResetStatusARB();
if (status != GL_NO_ERROR) {
// Graphics card reset.
XELOGE("============= TDR detected on context %p! Context %s =============",
glrc_, status == GL_GUILTY_CONTEXT_RESET ? "guilty" : "innocent");
context_lost_ = true;
return true;
}
return false;
}
void GLContext::BeginSwap() {
SCOPE_profile_cpu_i("gpu", "xe::ui::gl::GLContext::BeginSwap");
float clear_color[] = {238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.0f};

View File

@ -40,6 +40,7 @@ class GLContext : public GraphicsContext {
bool is_current() override;
bool MakeCurrent() override;
void ClearCurrent() override;
bool WasLost() override;
void BeginSwap() override;
void EndSwap() override;
@ -80,6 +81,8 @@ class GLContext : public GraphicsContext {
Blitter blitter_;
std::unique_ptr<GLImmediateDrawer> immediate_drawer_;
bool context_lost_ = false;
};
} // namespace gl

View File

@ -45,6 +45,12 @@ class GraphicsContext {
virtual bool MakeCurrent() = 0;
virtual void ClearCurrent() = 0;
// Returns true if the OS took away our context because we caused a TDR or
// some other outstanding error. When this happens, this context, as well as
// any other shared contexts are junk.
// This context must be made current in order for this call to work properly.
virtual bool WasLost() { return false; }
virtual void BeginSwap() = 0;
virtual void EndSwap() = 0;