[Mesa-dev] [PATCH v2 4/6] st/mesa: set a device reset callback when available
Nicolai Hähnle
nhaehnle at gmail.com
Tue Oct 4 08:11:22 UTC 2016
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
---
src/mesa/state_tracker/st_cb_flush.c | 31 ++++++++++++++++++++++++++++++-
src/mesa/state_tracker/st_cb_flush.h | 3 +++
src/mesa/state_tracker/st_context.h | 2 ++
src/mesa/state_tracker/st_manager.c | 4 +++-
4 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c
index 87c3d81..6442fc9 100644
--- a/src/mesa/state_tracker/st_cb_flush.c
+++ b/src/mesa/state_tracker/st_cb_flush.c
@@ -164,26 +164,55 @@ gl_reset_status_from_pipe_reset_status(enum pipe_reset_status status)
* Query information about GPU resets observed by this context
*
* Called via \c dd_function_table::GetGraphicsResetStatus.
*/
static GLenum
st_get_graphics_reset_status(struct gl_context *ctx)
{
struct st_context *st = st_context(ctx);
enum pipe_reset_status status;
- status = st->pipe->get_device_reset_status(st->pipe);
+ if (st->reset_status != PIPE_NO_RESET) {
+ status = st->reset_status;
+ st->reset_status = PIPE_NO_RESET;
+ } else {
+ status = st->pipe->get_device_reset_status(st->pipe);
+ }
return gl_reset_status_from_pipe_reset_status(status);
}
+static void
+st_device_reset_callback(void *data, enum pipe_reset_status status)
+{
+ struct st_context *st = data;
+
+ assert(status != PIPE_NO_RESET);
+
+ st->reset_status = status;
+ _mesa_set_context_lost_dispatch(st->ctx);
+}
+
+
+void
+st_install_device_reset_callback(struct st_context *st)
+{
+ if (st->pipe->set_device_reset_callback) {
+ struct pipe_device_reset_callback cb;
+ cb.reset = st_device_reset_callback;
+ cb.data = st;
+ st->pipe->set_device_reset_callback(st->pipe, &cb);
+ }
+}
+
+
void st_init_flush_functions(struct pipe_screen *screen,
struct dd_function_table *functions)
{
functions->Flush = st_glFlush;
functions->Finish = st_glFinish;
if (screen->get_param(screen, PIPE_CAP_DEVICE_RESET_STATUS_QUERY))
functions->GetGraphicsResetStatus = st_get_graphics_reset_status;
/* Windows opengl32.dll calls glFinish prior to every swapbuffers.
diff --git a/src/mesa/state_tracker/st_cb_flush.h b/src/mesa/state_tracker/st_cb_flush.h
index f92dcd5..5be68c9 100644
--- a/src/mesa/state_tracker/st_cb_flush.h
+++ b/src/mesa/state_tracker/st_cb_flush.h
@@ -41,13 +41,16 @@ st_init_flush_functions(struct pipe_screen *screen,
struct dd_function_table *functions);
extern void
st_flush(struct st_context *st,
struct pipe_fence_handle **fence,
unsigned flags);
extern void
st_finish(struct st_context *st);
+extern void
+st_install_device_reset_callback(struct st_context *st);
+
#endif /* ST_CB_FLUSH_H */
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 2b783e0..83d77fd 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -246,20 +246,22 @@ struct st_context
/* The number of vertex buffers from the last call of validate_arrays. */
unsigned last_num_vbuffers;
int32_t draw_stamp;
int32_t read_stamp;
struct st_config_options options;
struct st_perf_monitor_group *perfmon;
+
+ enum pipe_reset_status reset_status;
};
/* Need this so that we can implement Mesa callbacks in this module.
*/
static inline struct st_context *st_context(struct gl_context *ctx)
{
return ctx->st;
}
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index fece5d5..6922454 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -681,22 +681,24 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT;
st_update_debug_callback(st);
}
if (attribs->flags & ST_CONTEXT_FLAG_FORWARD_COMPATIBLE)
st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
if (attribs->flags & ST_CONTEXT_FLAG_ROBUST_ACCESS)
st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB;
- if (attribs->flags & ST_CONTEXT_FLAG_RESET_NOTIFICATION_ENABLED)
+ if (attribs->flags & ST_CONTEXT_FLAG_RESET_NOTIFICATION_ENABLED) {
st->ctx->Const.ResetStrategy = GL_LOSE_CONTEXT_ON_RESET_ARB;
+ st_install_device_reset_callback(st);
+ }
/* need to perform version check */
if (attribs->major > 1 || attribs->minor > 0) {
/* Is the actual version less than the requested version?
*/
if (st->ctx->Version < attribs->major * 10U + attribs->minor) {
*error = ST_CONTEXT_ERROR_BAD_VERSION;
st_destroy_context(st);
return NULL;
}
--
2.7.4
More information about the mesa-dev
mailing list