8786f0f2d09124841ed0dd0066a58315664b2c61
2 * Copyright © 2020 Advanced Micro Devices, Inc.
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 DEALINGS
24 /* This implements vertex array state tracking for glthread. It's separate
25 * from the rest of Mesa. Only minimum functionality is implemented here
29 #include "main/glthread.h"
30 #include "main/mtypes.h"
31 #include "main/hash.h"
32 #include "main/dispatch.h"
35 * - Implement better tracking of user pointers
36 * - These can unbind user pointers:
37 * ARB_vertex_attrib_binding
38 * ARB_direct_state_access
39 * EXT_direct_state_access
42 static struct glthread_vao
*
43 lookup_vao(struct gl_context
*ctx
, GLuint id
)
45 struct glthread_state
*glthread
= ctx
->GLThread
;
46 struct glthread_vao
*vao
;
50 if (glthread
->LastLookedUpVAO
&&
51 glthread
->LastLookedUpVAO
->Name
== id
) {
52 vao
= glthread
->LastLookedUpVAO
;
54 vao
= _mesa_HashLookupLocked(glthread
->VAOs
, id
);
58 glthread
->LastLookedUpVAO
= vao
;
65 _mesa_glthread_BindVertexArray(struct gl_context
*ctx
, GLuint id
)
67 struct glthread_state
*glthread
= ctx
->GLThread
;
70 glthread
->CurrentVAO
= &glthread
->DefaultVAO
;
72 struct glthread_vao
*vao
= lookup_vao(ctx
, id
);
75 glthread
->CurrentVAO
= vao
;
80 _mesa_glthread_DeleteVertexArrays(struct gl_context
*ctx
,
81 GLsizei n
, const GLuint
*ids
)
83 struct glthread_state
*glthread
= ctx
->GLThread
;
88 for (int i
= 0; i
< n
; i
++) {
89 /* IDs equal to 0 should be silently ignored. */
93 struct glthread_vao
*vao
= lookup_vao(ctx
, ids
[i
]);
97 /* If the array object is currently bound, the spec says "the binding
98 * for that object reverts to zero and the default vertex array
101 if (glthread
->CurrentVAO
== vao
)
102 glthread
->CurrentVAO
= &glthread
->DefaultVAO
;
104 if (glthread
->LastLookedUpVAO
== vao
)
105 glthread
->LastLookedUpVAO
= NULL
;
107 /* The ID is immediately freed for re-use */
108 _mesa_HashRemoveLocked(glthread
->VAOs
, vao
->Name
);
114 _mesa_glthread_GenVertexArrays(struct gl_context
*ctx
,
115 GLsizei n
, GLuint
*arrays
)
117 struct glthread_state
*glthread
= ctx
->GLThread
;
122 /* The IDs have been generated at this point. Create VAOs for glthread. */
123 for (int i
= 0; i
< n
; i
++) {
124 GLuint id
= arrays
[i
];
125 struct glthread_vao
*vao
;
127 vao
= malloc(sizeof(*vao
));
129 continue; /* Is that all we can do? */
132 vao
->HasUserPointer
= false;
133 _mesa_HashInsertLocked(glthread
->VAOs
, id
, vao
);
138 _mesa_glthread_AttribPointer(struct gl_context
*ctx
)
140 struct glthread_state
*glthread
= ctx
->GLThread
;
142 if (ctx
->API
!= API_OPENGL_CORE
&& !glthread
->vertex_array_is_vbo
)
143 glthread
->CurrentVAO
->HasUserPointer
= true;