2 * Copyright © 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
26 #include "debug_output.h"
30 #include "main/dispatch.h" /* for _gloffset_COUNT */
32 static void GLAPIENTRY
33 _context_lost_GetSynciv(GLsync sync
, GLenum pname
, GLsizei bufSize
,
34 GLsizei
*length
, GLint
*values
)
36 GET_CURRENT_CONTEXT(ctx
);
38 _mesa_error(ctx
, GL_CONTEXT_LOST
, "GetSynciv(invalid call)");
40 if (pname
== GL_SYNC_STATUS
&& bufSize
>= 1)
41 *values
= GL_SIGNALED
;
44 static void GLAPIENTRY
45 _context_lost_GetQueryObjectuiv(GLuint id
, GLenum pname
, GLuint
*params
)
47 GET_CURRENT_CONTEXT(ctx
);
49 _mesa_error(ctx
, GL_CONTEXT_LOST
, "GetQueryObjectuiv(context lost)");
51 if (pname
== GL_QUERY_RESULT_AVAILABLE
)
56 context_lost_nop_handler(void)
58 GET_CURRENT_CONTEXT(ctx
);
60 _mesa_error(ctx
, GL_CONTEXT_LOST
, "context lost");
66 _mesa_set_context_lost_dispatch(struct gl_context
*ctx
)
68 if (ctx
->ContextLost
== NULL
) {
69 int numEntries
= MAX2(_glapi_get_dispatch_table_size(), _gloffset_COUNT
);
71 ctx
->ContextLost
= malloc(numEntries
* sizeof(_glapi_proc
));
72 if (!ctx
->ContextLost
)
75 _glapi_proc
*entry
= (_glapi_proc
*) ctx
->ContextLost
;
77 for (i
= 0; i
< numEntries
; i
++)
78 entry
[i
] = (_glapi_proc
) context_lost_nop_handler
;
80 /* The ARB_robustness specification says:
82 * "* GetError and GetGraphicsResetStatus behave normally following a
83 * graphics reset, so that the application can determine a reset
84 * has occurred, and when it is safe to destroy and recreate the
87 * * Any commands which might cause a polling application to block
88 * indefinitely will generate a CONTEXT_LOST error, but will also
89 * return a value indicating completion to the application. Such
92 * + GetSynciv with <pname> SYNC_STATUS ignores the other
93 * parameters and returns SIGNALED in <values>.
95 * + GetQueryObjectuiv with <pname> QUERY_RESULT_AVAILABLE
96 * ignores the other parameters and returns TRUE in <params>."
98 SET_GetError(ctx
->ContextLost
, _mesa_GetError
);
99 SET_GetGraphicsResetStatusARB(ctx
->ContextLost
, _mesa_GetGraphicsResetStatusARB
);
100 SET_GetSynciv(ctx
->ContextLost
, _context_lost_GetSynciv
);
101 SET_GetQueryObjectuiv(ctx
->ContextLost
, _context_lost_GetQueryObjectuiv
);
104 ctx
->CurrentServerDispatch
= ctx
->ContextLost
;
105 _glapi_set_dispatch(ctx
->CurrentServerDispatch
);
109 * Returns an error code specified by GL_ARB_robustness, or GL_NO_ERROR.
110 * \return current context status
113 _mesa_GetGraphicsResetStatusARB( void )
115 GET_CURRENT_CONTEXT(ctx
);
116 GLenum status
= GL_NO_ERROR
;
118 /* The ARB_robustness specification says:
120 * "If the reset notification behavior is NO_RESET_NOTIFICATION_ARB,
121 * then the implementation will never deliver notification of reset
122 * events, and GetGraphicsResetStatusARB will always return NO_ERROR."
124 if (ctx
->Const
.ResetStrategy
== GL_NO_RESET_NOTIFICATION_ARB
) {
125 if (MESA_VERBOSE
& VERBOSE_API
)
127 "glGetGraphicsResetStatusARB always returns GL_NO_ERROR "
128 "because reset notifictation was not requested at context "
134 if (ctx
->Driver
.GetGraphicsResetStatus
) {
135 /* Query the reset status of this context from the driver core.
137 status
= ctx
->Driver
.GetGraphicsResetStatus(ctx
);
139 simple_mtx_lock(&ctx
->Shared
->Mutex
);
141 /* If this context has not been affected by a GPU reset, check to see if
142 * some other context in the share group has been affected by a reset.
143 * If another context saw a reset but this context did not, assume that
144 * this context was not guilty.
146 if (status
!= GL_NO_ERROR
) {
147 ctx
->Shared
->ShareGroupReset
= true;
148 ctx
->Shared
->DisjointOperation
= true;
149 } else if (ctx
->Shared
->ShareGroupReset
&& !ctx
->ShareGroupReset
) {
150 status
= GL_INNOCENT_CONTEXT_RESET_ARB
;
153 ctx
->ShareGroupReset
= ctx
->Shared
->ShareGroupReset
;
154 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
157 if (status
!= GL_NO_ERROR
)
158 _mesa_set_context_lost_dispatch(ctx
);
160 if (!ctx
->Driver
.GetGraphicsResetStatus
&& (MESA_VERBOSE
& VERBOSE_API
))
162 "glGetGraphicsResetStatusARB always returns GL_NO_ERROR "
163 "because the driver doesn't track reset status.\n");