[Mesa-dev] [PATCH] mesa: Add support for GL_CONTEXT_LOST
Kristian Høgsberg
krh at bitplanet.net
Tue May 24 21:30:24 UTC 2016
From: Kristian Høgsberg Kristensen <krh at bitplanet.net>
As per GL_KHR_robustness, we have to return GL_CONTEXT_LOST from all
entry points when we lose a context. We do this by creating a new
dispatch table and setting that when we learn that we've lost the
context.
With the GL_CONTEXT_LOST reporting in place we can turn on
GL_KHR_robustness.
Signed-off-by: Kristian Høgsberg Kristensen <krh at bitplanet.net>
---
docs/GL3.txt | 2 +-
docs/relnotes/11.3.0.html | 1 +
src/mesa/drivers/dri/i965/brw_context.h | 2 +
src/mesa/drivers/dri/i965/brw_reset.c | 20 +++++++
src/mesa/drivers/dri/i965/intel_batchbuffer.c | 3 +
src/mesa/drivers/dri/i965/intel_extensions.c | 1 +
src/mesa/main/context.c | 1 +
src/mesa/main/context.h | 2 +
src/mesa/main/extensions_table.h | 1 +
src/mesa/main/getstring.c | 82 ++++++++++++++++++++++++++-
src/mesa/main/mtypes.h | 7 ++-
11 files changed, 119 insertions(+), 3 deletions(-)
diff --git a/docs/GL3.txt b/docs/GL3.txt
index b5f03af..21ab46a 100644
--- a/docs/GL3.txt
+++ b/docs/GL3.txt
@@ -218,7 +218,7 @@ GL 4.5, GLSL 4.50:
GL_ARB_shader_texture_image_samples DONE (i965, nv50, nvc0, r600, radeonsi)
GL_ARB_texture_barrier DONE (i965, nv50, nvc0, r600, radeonsi)
GL_KHR_context_flush_control DONE (all - but needs GLX/EGL extension to be useful)
- GL_KHR_robustness not started (90% done with the ARB variant)
+ GL_KHR_robustness DONE (i965)
GL_EXT_shader_integer_mix DONE (all drivers that support GLSL)
These are the extensions cherry-picked to make GLES 3.1
diff --git a/docs/relnotes/11.3.0.html b/docs/relnotes/11.3.0.html
index 5871ec8..d5bb292 100644
--- a/docs/relnotes/11.3.0.html
+++ b/docs/relnotes/11.3.0.html
@@ -59,6 +59,7 @@ Note: some of the new features are only available with certain drivers.
<li>GL_ARB_shader_storage_buffer_objects on radeonsi, softpipe</li>
<li>GL_ATI_fragment_shader on all Gallium drivers</li>
<li>GL_EXT_base_instance on all drivers that support GL_ARB_base_instance</li>
+<li>GL_KHR_robustness on i965</li>
<li>GL_OES_draw_buffers_indexed and GL_EXT_draw_buffers_indexed on all drivers that support GL_ARB_draw_buffers_blend</li>
<li>GL_OES_sample_shading on i965, nvc0, r600, radeonsi</li>
<li>GL_OES_sample_variables on i965, nvc0, r600, radeonsi</li>
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 5155475..4b22201 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1704,6 +1704,8 @@ gen7_emit_urb_state(struct brw_context *brw,
/* brw_reset.c */
extern GLenum
brw_get_graphics_reset_status(struct gl_context *ctx);
+void
+brw_check_for_reset(struct brw_context *brw);
/* brw_compute.c */
extern void
diff --git a/src/mesa/drivers/dri/i965/brw_reset.c b/src/mesa/drivers/dri/i965/brw_reset.c
index e3182b1..df734e5 100644
--- a/src/mesa/drivers/dri/i965/brw_reset.c
+++ b/src/mesa/drivers/dri/i965/brw_reset.c
@@ -20,6 +20,9 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
+
+#include "main/context.h"
+
#include "brw_context.h"
/**
@@ -73,3 +76,20 @@ brw_get_graphics_reset_status(struct gl_context *ctx)
return GL_NO_ERROR;
}
+
+void
+brw_check_for_reset(struct brw_context *brw)
+{
+ uint32_t reset_count;
+ uint32_t active;
+ uint32_t pending;
+ int err;
+
+ err = drm_intel_get_reset_stats(brw->hw_ctx, &reset_count, &active,
+ &pending);
+ if (err)
+ return;
+
+ if (active > 0 || pending > 0)
+ _mesa_set_context_lost_dispatch(&brw->ctx);
+}
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index f220311..5a0db9f 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -368,6 +368,9 @@ do_flush_locked(struct brw_context *brw)
if (unlikely(INTEL_DEBUG & DEBUG_BATCH))
do_batch_dump(brw);
+ if (brw->ctx.Const.ResetStrategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
+ brw_check_for_reset(brw);
+
if (ret != 0) {
fprintf(stderr, "intel_do_flush_locked failed: %s\n", strerror(-ret));
exit(1);
diff --git a/src/mesa/drivers/dri/i965/intel_extensions.c b/src/mesa/drivers/dri/i965/intel_extensions.c
index feea6ca..b8d7517 100644
--- a/src/mesa/drivers/dri/i965/intel_extensions.c
+++ b/src/mesa/drivers/dri/i965/intel_extensions.c
@@ -246,6 +246,7 @@ intelInitExtensions(struct gl_context *ctx)
ctx->Extensions.EXT_texture_sRGB_decode = true;
ctx->Extensions.EXT_texture_swizzle = true;
ctx->Extensions.EXT_vertex_array_bgra = true;
+ ctx->Extensions.KHR_robustness = true;
ctx->Extensions.AMD_seamless_cubemap_per_texture = true;
ctx->Extensions.APPLE_object_purgeable = true;
ctx->Extensions.ATI_separate_stencil = true;
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 7c0a6ef..172c854 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1367,6 +1367,7 @@ _mesa_free_context_data( struct gl_context *ctx )
free(ctx->BeginEnd);
free(ctx->OutsideBeginEnd);
free(ctx->Save);
+ free(ctx->ContextLost);
/* Shared context state (display lists, textures, etc) */
_mesa_reference_shared_state(ctx, &ctx->Shared, NULL);
diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h
index 46444d2..ef19cc6 100644
--- a/src/mesa/main/context.h
+++ b/src/mesa/main/context.h
@@ -158,6 +158,8 @@ _mesa_notifySwapBuffers(struct gl_context *gc);
extern struct _glapi_table *
_mesa_get_dispatch(struct gl_context *ctx);
+extern void
+_mesa_set_context_lost_dispatch(struct gl_context *ctx);
extern GLboolean
_mesa_valid_to_render(struct gl_context *ctx, const char *where);
diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h
index a809023..a30e729 100644
--- a/src/mesa/main/extensions_table.h
+++ b/src/mesa/main/extensions_table.h
@@ -279,6 +279,7 @@ EXT(INTEL_performance_query , INTEL_performance_query
EXT(KHR_context_flush_control , dummy_true , GLL, GLC, x , ES2, 2014)
EXT(KHR_debug , dummy_true , GLL, GLC, 11, ES2, 2012)
EXT(KHR_robust_buffer_access_behavior , ARB_robust_buffer_access_behavior , GLL, GLC, x , ES2, 2014)
+EXT(KHR_robustness , KHR_robustness , GLL, GLC, 11, ES2, 2012)
EXT(KHR_texture_compression_astc_hdr , KHR_texture_compression_astc_hdr , GLL, GLC, x , ES2, 2012)
EXT(KHR_texture_compression_astc_ldr , KHR_texture_compression_astc_ldr , GLL, GLC, x , ES2, 2012)
diff --git a/src/mesa/main/getstring.c b/src/mesa/main/getstring.c
index 92f8a38..125b03a 100644
--- a/src/mesa/main/getstring.c
+++ b/src/mesa/main/getstring.c
@@ -31,7 +31,8 @@
#include "enums.h"
#include "extensions.h"
#include "mtypes.h"
-
+#include "macros.h"
+#include "main/dispatch.h" /* for _gloffset_COUNT */
/**
* Return the string for a glGetString(GL_SHADING_LANGUAGE_VERSION) query.
@@ -310,6 +311,82 @@ _mesa_GetError( void )
return e;
}
+static void
+_context_lost_GetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length,
+ GLint *values)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (ctx)
+ _mesa_error(ctx, GL_CONTEXT_LOST, "GetSynciv(invalid call)");
+
+ if (pname == GL_SYNC_STATUS && bufSize >= 1)
+ *values = GL_SIGNALED;
+}
+
+static void
+_context_lost_GetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (ctx)
+ _mesa_error(ctx, GL_CONTEXT_LOST, "GetQueryObjectuiv(context lost)");
+
+ if (pname == GL_QUERY_RESULT_AVAILABLE)
+ *params = GL_TRUE;
+}
+
+static int
+context_lost_nop_handler(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (ctx)
+ _mesa_error(ctx, GL_CONTEXT_LOST, "context lost");
+
+ return 0;
+}
+
+void
+_mesa_set_context_lost_dispatch(struct gl_context *ctx)
+{
+ if (ctx->ContextLost == NULL) {
+ int numEntries = MAX2(_glapi_get_dispatch_table_size(), _gloffset_COUNT);
+
+ ctx->ContextLost = malloc(numEntries * sizeof(_glapi_proc));
+ if (!ctx->ContextLost)
+ return;
+
+ _glapi_proc *entry = (_glapi_proc *) ctx->ContextLost;
+ unsigned i;
+ for (i = 0; i < numEntries; i++)
+ entry[i] = (_glapi_proc) context_lost_nop_handler;
+
+ /* The ARB_robustness specification says:
+ *
+ * "* GetError and GetGraphicsResetStatus behave normally following a
+ * graphics reset, so that the application can determine a reset
+ * has occurred, and when it is safe to destroy and recreate the
+ * context.
+ *
+ * * Any commands which might cause a polling application to block
+ * indefinitely will generate a CONTEXT_LOST error, but will also
+ * return a value indicating completion to the application. Such
+ * commands include:
+ *
+ * + GetSynciv with <pname> SYNC_STATUS ignores the other
+ * parameters and returns SIGNALED in <values>.
+ *
+ * + GetQueryObjectuiv with <pname> QUERY_RESULT_AVAILABLE
+ * ignores the other parameters and returns TRUE in <params>."
+ */
+ SET_GetError(ctx->ContextLost, _mesa_GetError);
+ SET_GetGraphicsResetStatusARB(ctx->ContextLost, _mesa_GetGraphicsResetStatusARB);
+ SET_GetSynciv(ctx->ContextLost, _context_lost_GetSynciv);
+ SET_GetQueryObjectuiv(ctx->ContextLost, _context_lost_GetQueryObjectuiv);
+ }
+
+ ctx->CurrentDispatch = ctx->ContextLost;
+ _glapi_set_dispatch(ctx->CurrentDispatch);
+}
+
/**
* Returns an error code specified by GL_ARB_robustness, or GL_NO_ERROR.
* \return current context status
@@ -358,6 +435,9 @@ _mesa_GetGraphicsResetStatusARB( void )
mtx_unlock(&ctx->Shared->Mutex);
}
+ if (status != GL_NO_ERROR)
+ _mesa_set_context_lost_dispatch(ctx);
+
if (!ctx->Driver.GetGraphicsResetStatus && (MESA_VERBOSE & VERBOSE_API))
_mesa_debug(ctx,
"glGetGraphicsResetStatusARB always returns GL_NO_ERROR "
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index b7b3ede..e16663d 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3899,6 +3899,7 @@ struct gl_extensions
GLboolean ATI_separate_stencil;
GLboolean GREMEDY_string_marker;
GLboolean INTEL_performance_query;
+ GLboolean KHR_robustness;
GLboolean KHR_texture_compression_astc_hdr;
GLboolean KHR_texture_compression_astc_ldr;
GLboolean MESA_pack_invert;
@@ -4302,7 +4303,11 @@ struct gl_context
*/
struct _glapi_table *BeginEnd;
/**
- * Tracks the current dispatch table out of the 3 above, so that it can be
+ * Dispatch table for when a graphics reset has happened.
+ */
+ struct _glapi_table *ContextLost;
+ /**
+ * Tracks the current dispatch table out of the 4 above, so that it can be
* re-set on glXMakeCurrent().
*/
struct _glapi_table *CurrentDispatch;
--
2.5.0
More information about the mesa-dev
mailing list