xref: /aosp_15_r20/external/mesa3d/src/mesa/main/externalobjects.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker  * Copyright © 2016 Red Hat.
3*61046927SAndroid Build Coastguard Worker  *
4*61046927SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a
5*61046927SAndroid Build Coastguard Worker  * copy of this software and associated documentation files (the "Software"),
6*61046927SAndroid Build Coastguard Worker  * to deal in the Software without restriction, including without limitation
7*61046927SAndroid Build Coastguard Worker  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*61046927SAndroid Build Coastguard Worker  * and/or sell copies of the Software, and to permit persons to whom the
9*61046927SAndroid Build Coastguard Worker  * Software is furnished to do so, subject to the following conditions:
10*61046927SAndroid Build Coastguard Worker  *
11*61046927SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice (including the next
12*61046927SAndroid Build Coastguard Worker  * paragraph) shall be included in all copies or substantial portions of the
13*61046927SAndroid Build Coastguard Worker  * Software.
14*61046927SAndroid Build Coastguard Worker  *
15*61046927SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*61046927SAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*61046927SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*61046927SAndroid Build Coastguard Worker  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*61046927SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*61046927SAndroid Build Coastguard Worker  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*61046927SAndroid Build Coastguard Worker  * DEALINGS IN THE SOFTWARE.
22*61046927SAndroid Build Coastguard Worker  */
23*61046927SAndroid Build Coastguard Worker 
24*61046927SAndroid Build Coastguard Worker #include "macros.h"
25*61046927SAndroid Build Coastguard Worker #include "mtypes.h"
26*61046927SAndroid Build Coastguard Worker #include "bufferobj.h"
27*61046927SAndroid Build Coastguard Worker #include "context.h"
28*61046927SAndroid Build Coastguard Worker #include "enums.h"
29*61046927SAndroid Build Coastguard Worker #include "externalobjects.h"
30*61046927SAndroid Build Coastguard Worker #include "teximage.h"
31*61046927SAndroid Build Coastguard Worker #include "texobj.h"
32*61046927SAndroid Build Coastguard Worker #include "glformats.h"
33*61046927SAndroid Build Coastguard Worker #include "texstorage.h"
34*61046927SAndroid Build Coastguard Worker #include "util/u_memory.h"
35*61046927SAndroid Build Coastguard Worker 
36*61046927SAndroid Build Coastguard Worker #include "pipe/p_context.h"
37*61046927SAndroid Build Coastguard Worker #include "pipe/p_screen.h"
38*61046927SAndroid Build Coastguard Worker #include "api_exec_decl.h"
39*61046927SAndroid Build Coastguard Worker 
40*61046927SAndroid Build Coastguard Worker #include "state_tracker/st_cb_bitmap.h"
41*61046927SAndroid Build Coastguard Worker #include "state_tracker/st_texture.h"
42*61046927SAndroid Build Coastguard Worker 
43*61046927SAndroid Build Coastguard Worker struct st_context;
44*61046927SAndroid Build Coastguard Worker 
45*61046927SAndroid Build Coastguard Worker #include "frontend/drm_driver.h"
46*61046927SAndroid Build Coastguard Worker #ifdef HAVE_LIBDRM
47*61046927SAndroid Build Coastguard Worker #include "drm-uapi/drm_fourcc.h"
48*61046927SAndroid Build Coastguard Worker #endif
49*61046927SAndroid Build Coastguard Worker 
50*61046927SAndroid Build Coastguard Worker static struct gl_memory_object *
memoryobj_alloc(struct gl_context * ctx,GLuint name)51*61046927SAndroid Build Coastguard Worker memoryobj_alloc(struct gl_context *ctx, GLuint name)
52*61046927SAndroid Build Coastguard Worker {
53*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *obj = CALLOC_STRUCT(gl_memory_object);
54*61046927SAndroid Build Coastguard Worker    if (!obj)
55*61046927SAndroid Build Coastguard Worker       return NULL;
56*61046927SAndroid Build Coastguard Worker 
57*61046927SAndroid Build Coastguard Worker    obj->Name = name;
58*61046927SAndroid Build Coastguard Worker    obj->Dedicated = GL_FALSE;
59*61046927SAndroid Build Coastguard Worker    return obj;
60*61046927SAndroid Build Coastguard Worker }
61*61046927SAndroid Build Coastguard Worker 
62*61046927SAndroid Build Coastguard Worker static void
import_memoryobj_fd(struct gl_context * ctx,struct gl_memory_object * obj,GLuint64 size,int fd)63*61046927SAndroid Build Coastguard Worker import_memoryobj_fd(struct gl_context *ctx,
64*61046927SAndroid Build Coastguard Worker                     struct gl_memory_object *obj,
65*61046927SAndroid Build Coastguard Worker                     GLuint64 size,
66*61046927SAndroid Build Coastguard Worker                     int fd)
67*61046927SAndroid Build Coastguard Worker {
68*61046927SAndroid Build Coastguard Worker #if !defined(_WIN32)
69*61046927SAndroid Build Coastguard Worker    struct pipe_screen *screen = ctx->pipe->screen;
70*61046927SAndroid Build Coastguard Worker    struct winsys_handle whandle = {
71*61046927SAndroid Build Coastguard Worker       .type = WINSYS_HANDLE_TYPE_FD,
72*61046927SAndroid Build Coastguard Worker       .handle = fd,
73*61046927SAndroid Build Coastguard Worker #ifdef HAVE_LIBDRM
74*61046927SAndroid Build Coastguard Worker       .modifier = DRM_FORMAT_MOD_INVALID,
75*61046927SAndroid Build Coastguard Worker #endif
76*61046927SAndroid Build Coastguard Worker    };
77*61046927SAndroid Build Coastguard Worker 
78*61046927SAndroid Build Coastguard Worker    obj->memory = screen->memobj_create_from_handle(screen,
79*61046927SAndroid Build Coastguard Worker                                                    &whandle,
80*61046927SAndroid Build Coastguard Worker                                                    obj->Dedicated);
81*61046927SAndroid Build Coastguard Worker 
82*61046927SAndroid Build Coastguard Worker    /* We own fd, but we no longer need it. So get rid of it */
83*61046927SAndroid Build Coastguard Worker    close(fd);
84*61046927SAndroid Build Coastguard Worker #endif
85*61046927SAndroid Build Coastguard Worker }
86*61046927SAndroid Build Coastguard Worker 
87*61046927SAndroid Build Coastguard Worker static void
import_memoryobj_win32(struct gl_context * ctx,struct gl_memory_object * obj,GLuint64 size,void * handle,const void * name)88*61046927SAndroid Build Coastguard Worker import_memoryobj_win32(struct gl_context *ctx,
89*61046927SAndroid Build Coastguard Worker                        struct gl_memory_object *obj,
90*61046927SAndroid Build Coastguard Worker                        GLuint64 size,
91*61046927SAndroid Build Coastguard Worker                        void *handle,
92*61046927SAndroid Build Coastguard Worker                        const void *name)
93*61046927SAndroid Build Coastguard Worker {
94*61046927SAndroid Build Coastguard Worker    struct pipe_screen *screen = ctx->pipe->screen;
95*61046927SAndroid Build Coastguard Worker    struct winsys_handle whandle = {
96*61046927SAndroid Build Coastguard Worker       .type = handle ? WINSYS_HANDLE_TYPE_WIN32_HANDLE : WINSYS_HANDLE_TYPE_WIN32_NAME,
97*61046927SAndroid Build Coastguard Worker #ifdef _WIN32
98*61046927SAndroid Build Coastguard Worker       .handle = handle,
99*61046927SAndroid Build Coastguard Worker #else
100*61046927SAndroid Build Coastguard Worker       .handle = 0,
101*61046927SAndroid Build Coastguard Worker #endif
102*61046927SAndroid Build Coastguard Worker #ifdef HAVE_LIBDRM
103*61046927SAndroid Build Coastguard Worker       .modifier = DRM_FORMAT_MOD_INVALID,
104*61046927SAndroid Build Coastguard Worker #endif
105*61046927SAndroid Build Coastguard Worker       .name = name,
106*61046927SAndroid Build Coastguard Worker    };
107*61046927SAndroid Build Coastguard Worker 
108*61046927SAndroid Build Coastguard Worker    obj->memory = screen->memobj_create_from_handle(screen,
109*61046927SAndroid Build Coastguard Worker                                                    &whandle,
110*61046927SAndroid Build Coastguard Worker                                                    obj->Dedicated);
111*61046927SAndroid Build Coastguard Worker }
112*61046927SAndroid Build Coastguard Worker 
113*61046927SAndroid Build Coastguard Worker /**
114*61046927SAndroid Build Coastguard Worker  * Delete a memory object.
115*61046927SAndroid Build Coastguard Worker  * Not removed from hash table here.
116*61046927SAndroid Build Coastguard Worker  */
117*61046927SAndroid Build Coastguard Worker void
_mesa_delete_memory_object(struct gl_context * ctx,struct gl_memory_object * memObj)118*61046927SAndroid Build Coastguard Worker _mesa_delete_memory_object(struct gl_context *ctx,
119*61046927SAndroid Build Coastguard Worker                            struct gl_memory_object *memObj)
120*61046927SAndroid Build Coastguard Worker {
121*61046927SAndroid Build Coastguard Worker    struct pipe_screen *screen = ctx->pipe->screen;
122*61046927SAndroid Build Coastguard Worker    if (memObj->memory)
123*61046927SAndroid Build Coastguard Worker       screen->memobj_destroy(screen, memObj->memory);
124*61046927SAndroid Build Coastguard Worker    FREE(memObj);
125*61046927SAndroid Build Coastguard Worker }
126*61046927SAndroid Build Coastguard Worker 
127*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_DeleteMemoryObjectsEXT(GLsizei n,const GLuint * memoryObjects)128*61046927SAndroid Build Coastguard Worker _mesa_DeleteMemoryObjectsEXT(GLsizei n, const GLuint *memoryObjects)
129*61046927SAndroid Build Coastguard Worker {
130*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
131*61046927SAndroid Build Coastguard Worker 
132*61046927SAndroid Build Coastguard Worker    if (MESA_VERBOSE & (VERBOSE_API)) {
133*61046927SAndroid Build Coastguard Worker       _mesa_debug(ctx, "glDeleteMemoryObjectsEXT(%d, %p)\n", n,
134*61046927SAndroid Build Coastguard Worker                   memoryObjects);
135*61046927SAndroid Build Coastguard Worker    }
136*61046927SAndroid Build Coastguard Worker 
137*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object) {
138*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION,
139*61046927SAndroid Build Coastguard Worker                   "glDeleteMemoryObjectsEXT(unsupported)");
140*61046927SAndroid Build Coastguard Worker       return;
141*61046927SAndroid Build Coastguard Worker    }
142*61046927SAndroid Build Coastguard Worker 
143*61046927SAndroid Build Coastguard Worker    if (n < 0) {
144*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteMemoryObjectsEXT(n < 0)");
145*61046927SAndroid Build Coastguard Worker       return;
146*61046927SAndroid Build Coastguard Worker    }
147*61046927SAndroid Build Coastguard Worker 
148*61046927SAndroid Build Coastguard Worker    if (!memoryObjects)
149*61046927SAndroid Build Coastguard Worker       return;
150*61046927SAndroid Build Coastguard Worker 
151*61046927SAndroid Build Coastguard Worker    _mesa_HashLockMutex(&ctx->Shared->MemoryObjects);
152*61046927SAndroid Build Coastguard Worker    for (GLint i = 0; i < n; i++) {
153*61046927SAndroid Build Coastguard Worker       if (memoryObjects[i] > 0) {
154*61046927SAndroid Build Coastguard Worker          struct gl_memory_object *delObj
155*61046927SAndroid Build Coastguard Worker             = _mesa_lookup_memory_object_locked(ctx, memoryObjects[i]);
156*61046927SAndroid Build Coastguard Worker 
157*61046927SAndroid Build Coastguard Worker          if (delObj) {
158*61046927SAndroid Build Coastguard Worker             _mesa_HashRemoveLocked(&ctx->Shared->MemoryObjects,
159*61046927SAndroid Build Coastguard Worker                                    memoryObjects[i]);
160*61046927SAndroid Build Coastguard Worker             _mesa_delete_memory_object(ctx, delObj);
161*61046927SAndroid Build Coastguard Worker          }
162*61046927SAndroid Build Coastguard Worker       }
163*61046927SAndroid Build Coastguard Worker    }
164*61046927SAndroid Build Coastguard Worker    _mesa_HashUnlockMutex(&ctx->Shared->MemoryObjects);
165*61046927SAndroid Build Coastguard Worker }
166*61046927SAndroid Build Coastguard Worker 
167*61046927SAndroid Build Coastguard Worker GLboolean GLAPIENTRY
_mesa_IsMemoryObjectEXT(GLuint memoryObject)168*61046927SAndroid Build Coastguard Worker _mesa_IsMemoryObjectEXT(GLuint memoryObject)
169*61046927SAndroid Build Coastguard Worker {
170*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
171*61046927SAndroid Build Coastguard Worker 
172*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object) {
173*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION,
174*61046927SAndroid Build Coastguard Worker                   "glIsMemoryObjectEXT(unsupported)");
175*61046927SAndroid Build Coastguard Worker       return GL_FALSE;
176*61046927SAndroid Build Coastguard Worker    }
177*61046927SAndroid Build Coastguard Worker 
178*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *obj =
179*61046927SAndroid Build Coastguard Worker       _mesa_lookup_memory_object(ctx, memoryObject);
180*61046927SAndroid Build Coastguard Worker 
181*61046927SAndroid Build Coastguard Worker    return obj ? GL_TRUE : GL_FALSE;
182*61046927SAndroid Build Coastguard Worker }
183*61046927SAndroid Build Coastguard Worker 
184*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_CreateMemoryObjectsEXT(GLsizei n,GLuint * memoryObjects)185*61046927SAndroid Build Coastguard Worker _mesa_CreateMemoryObjectsEXT(GLsizei n, GLuint *memoryObjects)
186*61046927SAndroid Build Coastguard Worker {
187*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
188*61046927SAndroid Build Coastguard Worker 
189*61046927SAndroid Build Coastguard Worker    const char *func = "glCreateMemoryObjectsEXT";
190*61046927SAndroid Build Coastguard Worker 
191*61046927SAndroid Build Coastguard Worker    if (MESA_VERBOSE & (VERBOSE_API))
192*61046927SAndroid Build Coastguard Worker       _mesa_debug(ctx, "%s(%d, %p)\n", func, n, memoryObjects);
193*61046927SAndroid Build Coastguard Worker 
194*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object) {
195*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
196*61046927SAndroid Build Coastguard Worker       return;
197*61046927SAndroid Build Coastguard Worker    }
198*61046927SAndroid Build Coastguard Worker 
199*61046927SAndroid Build Coastguard Worker    if (n < 0) {
200*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func);
201*61046927SAndroid Build Coastguard Worker       return;
202*61046927SAndroid Build Coastguard Worker    }
203*61046927SAndroid Build Coastguard Worker 
204*61046927SAndroid Build Coastguard Worker    if (!memoryObjects)
205*61046927SAndroid Build Coastguard Worker       return;
206*61046927SAndroid Build Coastguard Worker 
207*61046927SAndroid Build Coastguard Worker    _mesa_HashLockMutex(&ctx->Shared->MemoryObjects);
208*61046927SAndroid Build Coastguard Worker    if (_mesa_HashFindFreeKeys(&ctx->Shared->MemoryObjects, memoryObjects, n)) {
209*61046927SAndroid Build Coastguard Worker       for (GLsizei i = 0; i < n; i++) {
210*61046927SAndroid Build Coastguard Worker          struct gl_memory_object *memObj;
211*61046927SAndroid Build Coastguard Worker 
212*61046927SAndroid Build Coastguard Worker          /* allocate memory object */
213*61046927SAndroid Build Coastguard Worker          memObj = memoryobj_alloc(ctx, memoryObjects[i]);
214*61046927SAndroid Build Coastguard Worker          if (!memObj) {
215*61046927SAndroid Build Coastguard Worker             _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s()", func);
216*61046927SAndroid Build Coastguard Worker             _mesa_HashUnlockMutex(&ctx->Shared->MemoryObjects);
217*61046927SAndroid Build Coastguard Worker             return;
218*61046927SAndroid Build Coastguard Worker          }
219*61046927SAndroid Build Coastguard Worker 
220*61046927SAndroid Build Coastguard Worker          /* insert into hash table */
221*61046927SAndroid Build Coastguard Worker          _mesa_HashInsertLocked(&ctx->Shared->MemoryObjects, memoryObjects[i],
222*61046927SAndroid Build Coastguard Worker                                 memObj);
223*61046927SAndroid Build Coastguard Worker       }
224*61046927SAndroid Build Coastguard Worker    }
225*61046927SAndroid Build Coastguard Worker 
226*61046927SAndroid Build Coastguard Worker    _mesa_HashUnlockMutex(&ctx->Shared->MemoryObjects);
227*61046927SAndroid Build Coastguard Worker }
228*61046927SAndroid Build Coastguard Worker 
229*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_MemoryObjectParameterivEXT(GLuint memoryObject,GLenum pname,const GLint * params)230*61046927SAndroid Build Coastguard Worker _mesa_MemoryObjectParameterivEXT(GLuint memoryObject,
231*61046927SAndroid Build Coastguard Worker                                  GLenum pname,
232*61046927SAndroid Build Coastguard Worker                                  const GLint *params)
233*61046927SAndroid Build Coastguard Worker {
234*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
235*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *memObj;
236*61046927SAndroid Build Coastguard Worker 
237*61046927SAndroid Build Coastguard Worker    const char *func = "glMemoryObjectParameterivEXT";
238*61046927SAndroid Build Coastguard Worker 
239*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object) {
240*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
241*61046927SAndroid Build Coastguard Worker       return;
242*61046927SAndroid Build Coastguard Worker    }
243*61046927SAndroid Build Coastguard Worker 
244*61046927SAndroid Build Coastguard Worker    memObj = _mesa_lookup_memory_object(ctx, memoryObject);
245*61046927SAndroid Build Coastguard Worker    if (!memObj)
246*61046927SAndroid Build Coastguard Worker       return;
247*61046927SAndroid Build Coastguard Worker 
248*61046927SAndroid Build Coastguard Worker    if (memObj->Immutable) {
249*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(memoryObject is immutable", func);
250*61046927SAndroid Build Coastguard Worker       return;
251*61046927SAndroid Build Coastguard Worker    }
252*61046927SAndroid Build Coastguard Worker 
253*61046927SAndroid Build Coastguard Worker    switch (pname) {
254*61046927SAndroid Build Coastguard Worker    case GL_DEDICATED_MEMORY_OBJECT_EXT:
255*61046927SAndroid Build Coastguard Worker       memObj->Dedicated = (GLboolean) params[0];
256*61046927SAndroid Build Coastguard Worker       break;
257*61046927SAndroid Build Coastguard Worker    case GL_PROTECTED_MEMORY_OBJECT_EXT:
258*61046927SAndroid Build Coastguard Worker       /* EXT_protected_textures not supported */
259*61046927SAndroid Build Coastguard Worker       goto invalid_pname;
260*61046927SAndroid Build Coastguard Worker    default:
261*61046927SAndroid Build Coastguard Worker       goto invalid_pname;
262*61046927SAndroid Build Coastguard Worker    }
263*61046927SAndroid Build Coastguard Worker    return;
264*61046927SAndroid Build Coastguard Worker 
265*61046927SAndroid Build Coastguard Worker invalid_pname:
266*61046927SAndroid Build Coastguard Worker    _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname);
267*61046927SAndroid Build Coastguard Worker }
268*61046927SAndroid Build Coastguard Worker 
269*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_GetMemoryObjectParameterivEXT(GLuint memoryObject,GLenum pname,GLint * params)270*61046927SAndroid Build Coastguard Worker _mesa_GetMemoryObjectParameterivEXT(GLuint memoryObject,
271*61046927SAndroid Build Coastguard Worker                                     GLenum pname,
272*61046927SAndroid Build Coastguard Worker                                     GLint *params)
273*61046927SAndroid Build Coastguard Worker {
274*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
275*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *memObj;
276*61046927SAndroid Build Coastguard Worker 
277*61046927SAndroid Build Coastguard Worker    const char *func = "glMemoryObjectParameterivEXT";
278*61046927SAndroid Build Coastguard Worker 
279*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object) {
280*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
281*61046927SAndroid Build Coastguard Worker       return;
282*61046927SAndroid Build Coastguard Worker    }
283*61046927SAndroid Build Coastguard Worker 
284*61046927SAndroid Build Coastguard Worker    memObj = _mesa_lookup_memory_object(ctx, memoryObject);
285*61046927SAndroid Build Coastguard Worker    if (!memObj)
286*61046927SAndroid Build Coastguard Worker       return;
287*61046927SAndroid Build Coastguard Worker 
288*61046927SAndroid Build Coastguard Worker    switch (pname) {
289*61046927SAndroid Build Coastguard Worker       case GL_DEDICATED_MEMORY_OBJECT_EXT:
290*61046927SAndroid Build Coastguard Worker          *params = (GLint) memObj->Dedicated;
291*61046927SAndroid Build Coastguard Worker          break;
292*61046927SAndroid Build Coastguard Worker       case GL_PROTECTED_MEMORY_OBJECT_EXT:
293*61046927SAndroid Build Coastguard Worker          /* EXT_protected_textures not supported */
294*61046927SAndroid Build Coastguard Worker          goto invalid_pname;
295*61046927SAndroid Build Coastguard Worker       default:
296*61046927SAndroid Build Coastguard Worker          goto invalid_pname;
297*61046927SAndroid Build Coastguard Worker    }
298*61046927SAndroid Build Coastguard Worker    return;
299*61046927SAndroid Build Coastguard Worker 
300*61046927SAndroid Build Coastguard Worker invalid_pname:
301*61046927SAndroid Build Coastguard Worker    _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname);
302*61046927SAndroid Build Coastguard Worker }
303*61046927SAndroid Build Coastguard Worker 
304*61046927SAndroid Build Coastguard Worker static struct gl_memory_object *
lookup_memory_object_err(struct gl_context * ctx,unsigned memory,const char * func)305*61046927SAndroid Build Coastguard Worker lookup_memory_object_err(struct gl_context *ctx, unsigned memory,
306*61046927SAndroid Build Coastguard Worker                          const char* func)
307*61046927SAndroid Build Coastguard Worker {
308*61046927SAndroid Build Coastguard Worker    if (memory == 0) {
309*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_VALUE, "%s(memory=0)", func);
310*61046927SAndroid Build Coastguard Worker       return NULL;
311*61046927SAndroid Build Coastguard Worker    }
312*61046927SAndroid Build Coastguard Worker 
313*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *memObj = _mesa_lookup_memory_object(ctx, memory);
314*61046927SAndroid Build Coastguard Worker    if (!memObj)
315*61046927SAndroid Build Coastguard Worker       return NULL;
316*61046927SAndroid Build Coastguard Worker 
317*61046927SAndroid Build Coastguard Worker    if (!memObj->Immutable) {
318*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no associated memory)",
319*61046927SAndroid Build Coastguard Worker                   func);
320*61046927SAndroid Build Coastguard Worker       return NULL;
321*61046927SAndroid Build Coastguard Worker    }
322*61046927SAndroid Build Coastguard Worker 
323*61046927SAndroid Build Coastguard Worker    return memObj;
324*61046927SAndroid Build Coastguard Worker }
325*61046927SAndroid Build Coastguard Worker 
326*61046927SAndroid Build Coastguard Worker /**
327*61046927SAndroid Build Coastguard Worker  * Helper used by _mesa_TexStorageMem1/2/3DEXT().
328*61046927SAndroid Build Coastguard Worker  */
329*61046927SAndroid Build Coastguard Worker static void
texstorage_memory(GLuint dims,GLenum target,GLsizei levels,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,GLuint memory,GLuint64 offset,const char * func)330*61046927SAndroid Build Coastguard Worker texstorage_memory(GLuint dims, GLenum target, GLsizei levels,
331*61046927SAndroid Build Coastguard Worker                   GLenum internalFormat, GLsizei width, GLsizei height,
332*61046927SAndroid Build Coastguard Worker                   GLsizei depth, GLuint memory, GLuint64 offset,
333*61046927SAndroid Build Coastguard Worker                   const char *func)
334*61046927SAndroid Build Coastguard Worker {
335*61046927SAndroid Build Coastguard Worker    struct gl_texture_object *texObj;
336*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *memObj;
337*61046927SAndroid Build Coastguard Worker 
338*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
339*61046927SAndroid Build Coastguard Worker 
340*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object) {
341*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
342*61046927SAndroid Build Coastguard Worker       return;
343*61046927SAndroid Build Coastguard Worker    }
344*61046927SAndroid Build Coastguard Worker 
345*61046927SAndroid Build Coastguard Worker    if (!_mesa_is_legal_tex_storage_target(ctx, dims, target)) {
346*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM,
347*61046927SAndroid Build Coastguard Worker                   "%s(illegal target=%s)",
348*61046927SAndroid Build Coastguard Worker                   func, _mesa_enum_to_string(target));
349*61046927SAndroid Build Coastguard Worker       return;
350*61046927SAndroid Build Coastguard Worker    }
351*61046927SAndroid Build Coastguard Worker 
352*61046927SAndroid Build Coastguard Worker    /* Check the format to make sure it is sized. */
353*61046927SAndroid Build Coastguard Worker    if (!_mesa_is_legal_tex_storage_format(ctx, internalFormat)) {
354*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM,
355*61046927SAndroid Build Coastguard Worker                   "%s(internalformat = %s)", func,
356*61046927SAndroid Build Coastguard Worker                   _mesa_enum_to_string(internalFormat));
357*61046927SAndroid Build Coastguard Worker       return;
358*61046927SAndroid Build Coastguard Worker    }
359*61046927SAndroid Build Coastguard Worker 
360*61046927SAndroid Build Coastguard Worker    texObj = _mesa_get_current_tex_object(ctx, target);
361*61046927SAndroid Build Coastguard Worker    if (!texObj)
362*61046927SAndroid Build Coastguard Worker       return;
363*61046927SAndroid Build Coastguard Worker 
364*61046927SAndroid Build Coastguard Worker    memObj = lookup_memory_object_err(ctx, memory, func);
365*61046927SAndroid Build Coastguard Worker    if (!memObj)
366*61046927SAndroid Build Coastguard Worker       return;
367*61046927SAndroid Build Coastguard Worker 
368*61046927SAndroid Build Coastguard Worker    _mesa_texture_storage_memory(ctx, dims, texObj, memObj, target,
369*61046927SAndroid Build Coastguard Worker                                 levels, internalFormat,
370*61046927SAndroid Build Coastguard Worker                                 width, height, depth, offset, false);
371*61046927SAndroid Build Coastguard Worker }
372*61046927SAndroid Build Coastguard Worker 
373*61046927SAndroid Build Coastguard Worker static void
texstorage_memory_ms(GLuint dims,GLenum target,GLsizei samples,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,GLboolean fixedSampleLocations,GLuint memory,GLuint64 offset,const char * func)374*61046927SAndroid Build Coastguard Worker texstorage_memory_ms(GLuint dims, GLenum target, GLsizei samples,
375*61046927SAndroid Build Coastguard Worker                      GLenum internalFormat, GLsizei width, GLsizei height,
376*61046927SAndroid Build Coastguard Worker                      GLsizei depth, GLboolean fixedSampleLocations,
377*61046927SAndroid Build Coastguard Worker                      GLuint memory, GLuint64 offset, const char* func)
378*61046927SAndroid Build Coastguard Worker {
379*61046927SAndroid Build Coastguard Worker    struct gl_texture_object *texObj;
380*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *memObj;
381*61046927SAndroid Build Coastguard Worker 
382*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
383*61046927SAndroid Build Coastguard Worker 
384*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object) {
385*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
386*61046927SAndroid Build Coastguard Worker       return;
387*61046927SAndroid Build Coastguard Worker    }
388*61046927SAndroid Build Coastguard Worker 
389*61046927SAndroid Build Coastguard Worker    texObj = _mesa_get_current_tex_object(ctx, target);
390*61046927SAndroid Build Coastguard Worker    if (!texObj)
391*61046927SAndroid Build Coastguard Worker       return;
392*61046927SAndroid Build Coastguard Worker 
393*61046927SAndroid Build Coastguard Worker    memObj = lookup_memory_object_err(ctx, memory, func);
394*61046927SAndroid Build Coastguard Worker    if (!memObj)
395*61046927SAndroid Build Coastguard Worker       return;
396*61046927SAndroid Build Coastguard Worker 
397*61046927SAndroid Build Coastguard Worker    _mesa_texture_storage_ms_memory(ctx, dims, texObj, memObj, target, samples,
398*61046927SAndroid Build Coastguard Worker                                    internalFormat, width, height, depth,
399*61046927SAndroid Build Coastguard Worker                                    fixedSampleLocations, offset, func);
400*61046927SAndroid Build Coastguard Worker }
401*61046927SAndroid Build Coastguard Worker 
402*61046927SAndroid Build Coastguard Worker /**
403*61046927SAndroid Build Coastguard Worker  * Helper used by _mesa_TextureStorageMem1/2/3DEXT().
404*61046927SAndroid Build Coastguard Worker  */
405*61046927SAndroid Build Coastguard Worker static void
texturestorage_memory(GLuint dims,GLuint texture,GLsizei levels,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,GLuint memory,GLuint64 offset,const char * func)406*61046927SAndroid Build Coastguard Worker texturestorage_memory(GLuint dims, GLuint texture, GLsizei levels,
407*61046927SAndroid Build Coastguard Worker                       GLenum internalFormat, GLsizei width, GLsizei height,
408*61046927SAndroid Build Coastguard Worker                       GLsizei depth, GLuint memory, GLuint64 offset,
409*61046927SAndroid Build Coastguard Worker                       const char *func)
410*61046927SAndroid Build Coastguard Worker {
411*61046927SAndroid Build Coastguard Worker    struct gl_texture_object *texObj;
412*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *memObj;
413*61046927SAndroid Build Coastguard Worker 
414*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
415*61046927SAndroid Build Coastguard Worker 
416*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object) {
417*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
418*61046927SAndroid Build Coastguard Worker       return;
419*61046927SAndroid Build Coastguard Worker    }
420*61046927SAndroid Build Coastguard Worker 
421*61046927SAndroid Build Coastguard Worker    /* Check the format to make sure it is sized. */
422*61046927SAndroid Build Coastguard Worker    if (!_mesa_is_legal_tex_storage_format(ctx, internalFormat)) {
423*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM,
424*61046927SAndroid Build Coastguard Worker                   "%s(internalformat = %s)", func,
425*61046927SAndroid Build Coastguard Worker                   _mesa_enum_to_string(internalFormat));
426*61046927SAndroid Build Coastguard Worker       return;
427*61046927SAndroid Build Coastguard Worker    }
428*61046927SAndroid Build Coastguard Worker 
429*61046927SAndroid Build Coastguard Worker    texObj = _mesa_lookup_texture(ctx, texture);
430*61046927SAndroid Build Coastguard Worker    if (!texObj)
431*61046927SAndroid Build Coastguard Worker       return;
432*61046927SAndroid Build Coastguard Worker 
433*61046927SAndroid Build Coastguard Worker    if (!_mesa_is_legal_tex_storage_target(ctx, dims, texObj->Target)) {
434*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION,
435*61046927SAndroid Build Coastguard Worker                   "%s(illegal target=%s)", func,
436*61046927SAndroid Build Coastguard Worker                   _mesa_enum_to_string(texObj->Target));
437*61046927SAndroid Build Coastguard Worker       return;
438*61046927SAndroid Build Coastguard Worker    }
439*61046927SAndroid Build Coastguard Worker 
440*61046927SAndroid Build Coastguard Worker    memObj = lookup_memory_object_err(ctx, memory, func);
441*61046927SAndroid Build Coastguard Worker    if (!memObj)
442*61046927SAndroid Build Coastguard Worker       return;
443*61046927SAndroid Build Coastguard Worker 
444*61046927SAndroid Build Coastguard Worker    _mesa_texture_storage_memory(ctx, dims, texObj, memObj, texObj->Target,
445*61046927SAndroid Build Coastguard Worker                                 levels, internalFormat,
446*61046927SAndroid Build Coastguard Worker                                 width, height, depth, offset, true);
447*61046927SAndroid Build Coastguard Worker }
448*61046927SAndroid Build Coastguard Worker 
449*61046927SAndroid Build Coastguard Worker static void
texturestorage_memory_ms(GLuint dims,GLuint texture,GLsizei samples,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,GLboolean fixedSampleLocations,GLuint memory,GLuint64 offset,const char * func)450*61046927SAndroid Build Coastguard Worker texturestorage_memory_ms(GLuint dims, GLuint texture, GLsizei samples,
451*61046927SAndroid Build Coastguard Worker                          GLenum internalFormat, GLsizei width, GLsizei height,
452*61046927SAndroid Build Coastguard Worker                          GLsizei depth, GLboolean fixedSampleLocations,
453*61046927SAndroid Build Coastguard Worker                          GLuint memory, GLuint64 offset, const char* func)
454*61046927SAndroid Build Coastguard Worker {
455*61046927SAndroid Build Coastguard Worker    struct gl_texture_object *texObj;
456*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *memObj;
457*61046927SAndroid Build Coastguard Worker 
458*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
459*61046927SAndroid Build Coastguard Worker 
460*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object) {
461*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
462*61046927SAndroid Build Coastguard Worker       return;
463*61046927SAndroid Build Coastguard Worker    }
464*61046927SAndroid Build Coastguard Worker 
465*61046927SAndroid Build Coastguard Worker    texObj = _mesa_lookup_texture(ctx, texture);
466*61046927SAndroid Build Coastguard Worker    if (!texObj)
467*61046927SAndroid Build Coastguard Worker       return;
468*61046927SAndroid Build Coastguard Worker 
469*61046927SAndroid Build Coastguard Worker    memObj = lookup_memory_object_err(ctx, memory, func);
470*61046927SAndroid Build Coastguard Worker    if (!memObj)
471*61046927SAndroid Build Coastguard Worker       return;
472*61046927SAndroid Build Coastguard Worker 
473*61046927SAndroid Build Coastguard Worker    _mesa_texture_storage_ms_memory(ctx, dims, texObj, memObj, texObj->Target,
474*61046927SAndroid Build Coastguard Worker                                    samples, internalFormat, width, height,
475*61046927SAndroid Build Coastguard Worker                                    depth, fixedSampleLocations, offset, func);
476*61046927SAndroid Build Coastguard Worker }
477*61046927SAndroid Build Coastguard Worker 
478*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_TexStorageMem2DEXT(GLenum target,GLsizei levels,GLenum internalFormat,GLsizei width,GLsizei height,GLuint memory,GLuint64 offset)479*61046927SAndroid Build Coastguard Worker _mesa_TexStorageMem2DEXT(GLenum target,
480*61046927SAndroid Build Coastguard Worker                          GLsizei levels,
481*61046927SAndroid Build Coastguard Worker                          GLenum internalFormat,
482*61046927SAndroid Build Coastguard Worker                          GLsizei width,
483*61046927SAndroid Build Coastguard Worker                          GLsizei height,
484*61046927SAndroid Build Coastguard Worker                          GLuint memory,
485*61046927SAndroid Build Coastguard Worker                          GLuint64 offset)
486*61046927SAndroid Build Coastguard Worker {
487*61046927SAndroid Build Coastguard Worker    texstorage_memory(2, target, levels, internalFormat, width, height, 1,
488*61046927SAndroid Build Coastguard Worker                      memory, offset, "glTexStorageMem2DEXT");
489*61046927SAndroid Build Coastguard Worker }
490*61046927SAndroid Build Coastguard Worker 
491*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_TexStorageMem2DMultisampleEXT(GLenum target,GLsizei samples,GLenum internalFormat,GLsizei width,GLsizei height,GLboolean fixedSampleLocations,GLuint memory,GLuint64 offset)492*61046927SAndroid Build Coastguard Worker _mesa_TexStorageMem2DMultisampleEXT(GLenum target,
493*61046927SAndroid Build Coastguard Worker                                     GLsizei samples,
494*61046927SAndroid Build Coastguard Worker                                     GLenum internalFormat,
495*61046927SAndroid Build Coastguard Worker                                     GLsizei width,
496*61046927SAndroid Build Coastguard Worker                                     GLsizei height,
497*61046927SAndroid Build Coastguard Worker                                     GLboolean fixedSampleLocations,
498*61046927SAndroid Build Coastguard Worker                                     GLuint memory,
499*61046927SAndroid Build Coastguard Worker                                     GLuint64 offset)
500*61046927SAndroid Build Coastguard Worker {
501*61046927SAndroid Build Coastguard Worker    texstorage_memory_ms(2, target, samples, internalFormat, width, height, 1,
502*61046927SAndroid Build Coastguard Worker                         fixedSampleLocations, memory, offset,
503*61046927SAndroid Build Coastguard Worker                         "glTexStorageMem2DMultisampleEXT");
504*61046927SAndroid Build Coastguard Worker }
505*61046927SAndroid Build Coastguard Worker 
506*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_TexStorageMem3DEXT(GLenum target,GLsizei levels,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,GLuint memory,GLuint64 offset)507*61046927SAndroid Build Coastguard Worker _mesa_TexStorageMem3DEXT(GLenum target,
508*61046927SAndroid Build Coastguard Worker                          GLsizei levels,
509*61046927SAndroid Build Coastguard Worker                          GLenum internalFormat,
510*61046927SAndroid Build Coastguard Worker                          GLsizei width,
511*61046927SAndroid Build Coastguard Worker                          GLsizei height,
512*61046927SAndroid Build Coastguard Worker                          GLsizei depth,
513*61046927SAndroid Build Coastguard Worker                          GLuint memory,
514*61046927SAndroid Build Coastguard Worker                          GLuint64 offset)
515*61046927SAndroid Build Coastguard Worker {
516*61046927SAndroid Build Coastguard Worker    texstorage_memory(3, target, levels, internalFormat, width, height, depth,
517*61046927SAndroid Build Coastguard Worker                      memory, offset, "glTexStorageMem3DEXT");
518*61046927SAndroid Build Coastguard Worker }
519*61046927SAndroid Build Coastguard Worker 
520*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_TexStorageMem3DMultisampleEXT(GLenum target,GLsizei samples,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,GLboolean fixedSampleLocations,GLuint memory,GLuint64 offset)521*61046927SAndroid Build Coastguard Worker _mesa_TexStorageMem3DMultisampleEXT(GLenum target,
522*61046927SAndroid Build Coastguard Worker                                     GLsizei samples,
523*61046927SAndroid Build Coastguard Worker                                     GLenum internalFormat,
524*61046927SAndroid Build Coastguard Worker                                     GLsizei width,
525*61046927SAndroid Build Coastguard Worker                                     GLsizei height,
526*61046927SAndroid Build Coastguard Worker                                     GLsizei depth,
527*61046927SAndroid Build Coastguard Worker                                     GLboolean fixedSampleLocations,
528*61046927SAndroid Build Coastguard Worker                                     GLuint memory,
529*61046927SAndroid Build Coastguard Worker                                     GLuint64 offset)
530*61046927SAndroid Build Coastguard Worker {
531*61046927SAndroid Build Coastguard Worker    texstorage_memory_ms(3, target, samples, internalFormat, width, height,
532*61046927SAndroid Build Coastguard Worker                         depth, fixedSampleLocations, memory, offset,
533*61046927SAndroid Build Coastguard Worker                         "glTexStorageMem3DMultisampleEXT");
534*61046927SAndroid Build Coastguard Worker }
535*61046927SAndroid Build Coastguard Worker 
536*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_TextureStorageMem2DEXT(GLuint texture,GLsizei levels,GLenum internalFormat,GLsizei width,GLsizei height,GLuint memory,GLuint64 offset)537*61046927SAndroid Build Coastguard Worker _mesa_TextureStorageMem2DEXT(GLuint texture,
538*61046927SAndroid Build Coastguard Worker                              GLsizei levels,
539*61046927SAndroid Build Coastguard Worker                              GLenum internalFormat,
540*61046927SAndroid Build Coastguard Worker                              GLsizei width,
541*61046927SAndroid Build Coastguard Worker                              GLsizei height,
542*61046927SAndroid Build Coastguard Worker                              GLuint memory,
543*61046927SAndroid Build Coastguard Worker                              GLuint64 offset)
544*61046927SAndroid Build Coastguard Worker {
545*61046927SAndroid Build Coastguard Worker    texturestorage_memory(2, texture, levels, internalFormat, width, height, 1,
546*61046927SAndroid Build Coastguard Worker                          memory, offset, "glTexureStorageMem2DEXT");
547*61046927SAndroid Build Coastguard Worker }
548*61046927SAndroid Build Coastguard Worker 
549*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_TextureStorageMem2DMultisampleEXT(GLuint texture,GLsizei samples,GLenum internalFormat,GLsizei width,GLsizei height,GLboolean fixedSampleLocations,GLuint memory,GLuint64 offset)550*61046927SAndroid Build Coastguard Worker _mesa_TextureStorageMem2DMultisampleEXT(GLuint texture,
551*61046927SAndroid Build Coastguard Worker                                         GLsizei samples,
552*61046927SAndroid Build Coastguard Worker                                         GLenum internalFormat,
553*61046927SAndroid Build Coastguard Worker                                         GLsizei width,
554*61046927SAndroid Build Coastguard Worker                                         GLsizei height,
555*61046927SAndroid Build Coastguard Worker                                         GLboolean fixedSampleLocations,
556*61046927SAndroid Build Coastguard Worker                                         GLuint memory,
557*61046927SAndroid Build Coastguard Worker                                         GLuint64 offset)
558*61046927SAndroid Build Coastguard Worker {
559*61046927SAndroid Build Coastguard Worker    texturestorage_memory_ms(2, texture, samples, internalFormat, width, height,
560*61046927SAndroid Build Coastguard Worker                             1, fixedSampleLocations, memory, offset,
561*61046927SAndroid Build Coastguard Worker                             "glTextureStorageMem2DMultisampleEXT");
562*61046927SAndroid Build Coastguard Worker }
563*61046927SAndroid Build Coastguard Worker 
564*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_TextureStorageMem3DEXT(GLuint texture,GLsizei levels,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,GLuint memory,GLuint64 offset)565*61046927SAndroid Build Coastguard Worker _mesa_TextureStorageMem3DEXT(GLuint texture,
566*61046927SAndroid Build Coastguard Worker                              GLsizei levels,
567*61046927SAndroid Build Coastguard Worker                              GLenum internalFormat,
568*61046927SAndroid Build Coastguard Worker                              GLsizei width,
569*61046927SAndroid Build Coastguard Worker                              GLsizei height,
570*61046927SAndroid Build Coastguard Worker                              GLsizei depth,
571*61046927SAndroid Build Coastguard Worker                              GLuint memory,
572*61046927SAndroid Build Coastguard Worker                              GLuint64 offset)
573*61046927SAndroid Build Coastguard Worker {
574*61046927SAndroid Build Coastguard Worker    texturestorage_memory(3, texture, levels, internalFormat, width, height,
575*61046927SAndroid Build Coastguard Worker                          depth, memory, offset, "glTextureStorageMem3DEXT");
576*61046927SAndroid Build Coastguard Worker }
577*61046927SAndroid Build Coastguard Worker 
578*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_TextureStorageMem3DMultisampleEXT(GLuint texture,GLsizei samples,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,GLboolean fixedSampleLocations,GLuint memory,GLuint64 offset)579*61046927SAndroid Build Coastguard Worker _mesa_TextureStorageMem3DMultisampleEXT(GLuint texture,
580*61046927SAndroid Build Coastguard Worker                                         GLsizei samples,
581*61046927SAndroid Build Coastguard Worker                                         GLenum internalFormat,
582*61046927SAndroid Build Coastguard Worker                                         GLsizei width,
583*61046927SAndroid Build Coastguard Worker                                         GLsizei height,
584*61046927SAndroid Build Coastguard Worker                                         GLsizei depth,
585*61046927SAndroid Build Coastguard Worker                                         GLboolean fixedSampleLocations,
586*61046927SAndroid Build Coastguard Worker                                         GLuint memory,
587*61046927SAndroid Build Coastguard Worker                                         GLuint64 offset)
588*61046927SAndroid Build Coastguard Worker {
589*61046927SAndroid Build Coastguard Worker    texturestorage_memory_ms(3, texture, samples, internalFormat, width, height,
590*61046927SAndroid Build Coastguard Worker                             depth, fixedSampleLocations, memory, offset,
591*61046927SAndroid Build Coastguard Worker                             "glTextureStorageMem3DMultisampleEXT");
592*61046927SAndroid Build Coastguard Worker }
593*61046927SAndroid Build Coastguard Worker 
594*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_TexStorageMem1DEXT(GLenum target,GLsizei levels,GLenum internalFormat,GLsizei width,GLuint memory,GLuint64 offset)595*61046927SAndroid Build Coastguard Worker _mesa_TexStorageMem1DEXT(GLenum target,
596*61046927SAndroid Build Coastguard Worker                          GLsizei levels,
597*61046927SAndroid Build Coastguard Worker                          GLenum internalFormat,
598*61046927SAndroid Build Coastguard Worker                          GLsizei width,
599*61046927SAndroid Build Coastguard Worker                          GLuint memory,
600*61046927SAndroid Build Coastguard Worker                          GLuint64 offset)
601*61046927SAndroid Build Coastguard Worker {
602*61046927SAndroid Build Coastguard Worker    texstorage_memory(1, target, levels, internalFormat, width, 1, 1, memory,
603*61046927SAndroid Build Coastguard Worker                      offset, "glTexStorageMem1DEXT");
604*61046927SAndroid Build Coastguard Worker }
605*61046927SAndroid Build Coastguard Worker 
606*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_TextureStorageMem1DEXT(GLuint texture,GLsizei levels,GLenum internalFormat,GLsizei width,GLuint memory,GLuint64 offset)607*61046927SAndroid Build Coastguard Worker _mesa_TextureStorageMem1DEXT(GLuint texture,
608*61046927SAndroid Build Coastguard Worker                              GLsizei levels,
609*61046927SAndroid Build Coastguard Worker                              GLenum internalFormat,
610*61046927SAndroid Build Coastguard Worker                              GLsizei width,
611*61046927SAndroid Build Coastguard Worker                              GLuint memory,
612*61046927SAndroid Build Coastguard Worker                              GLuint64 offset)
613*61046927SAndroid Build Coastguard Worker {
614*61046927SAndroid Build Coastguard Worker    texturestorage_memory(1, texture, levels, internalFormat, width, 1, 1,
615*61046927SAndroid Build Coastguard Worker                          memory, offset, "glTextureStorageMem1DEXT");
616*61046927SAndroid Build Coastguard Worker }
617*61046927SAndroid Build Coastguard Worker 
618*61046927SAndroid Build Coastguard Worker static struct gl_semaphore_object *
semaphoreobj_alloc(struct gl_context * ctx,GLuint name)619*61046927SAndroid Build Coastguard Worker semaphoreobj_alloc(struct gl_context *ctx, GLuint name)
620*61046927SAndroid Build Coastguard Worker {
621*61046927SAndroid Build Coastguard Worker    struct gl_semaphore_object *obj = CALLOC_STRUCT(gl_semaphore_object);
622*61046927SAndroid Build Coastguard Worker    if (!obj)
623*61046927SAndroid Build Coastguard Worker       return NULL;
624*61046927SAndroid Build Coastguard Worker 
625*61046927SAndroid Build Coastguard Worker    obj->Name = name;
626*61046927SAndroid Build Coastguard Worker    return obj;
627*61046927SAndroid Build Coastguard Worker }
628*61046927SAndroid Build Coastguard Worker 
629*61046927SAndroid Build Coastguard Worker static void
import_semaphoreobj_fd(struct gl_context * ctx,struct gl_semaphore_object * semObj,int fd)630*61046927SAndroid Build Coastguard Worker import_semaphoreobj_fd(struct gl_context *ctx,
631*61046927SAndroid Build Coastguard Worker                           struct gl_semaphore_object *semObj,
632*61046927SAndroid Build Coastguard Worker                           int fd)
633*61046927SAndroid Build Coastguard Worker {
634*61046927SAndroid Build Coastguard Worker    struct pipe_context *pipe = ctx->pipe;
635*61046927SAndroid Build Coastguard Worker 
636*61046927SAndroid Build Coastguard Worker    pipe->create_fence_fd(pipe, &semObj->fence, fd, PIPE_FD_TYPE_SYNCOBJ);
637*61046927SAndroid Build Coastguard Worker 
638*61046927SAndroid Build Coastguard Worker #if !defined(_WIN32)
639*61046927SAndroid Build Coastguard Worker    /* We own fd, but we no longer need it. So get rid of it */
640*61046927SAndroid Build Coastguard Worker    close(fd);
641*61046927SAndroid Build Coastguard Worker #endif
642*61046927SAndroid Build Coastguard Worker }
643*61046927SAndroid Build Coastguard Worker 
644*61046927SAndroid Build Coastguard Worker static void
import_semaphoreobj_win32(struct gl_context * ctx,struct gl_semaphore_object * semObj,void * handle,const void * name,enum pipe_fd_type type)645*61046927SAndroid Build Coastguard Worker import_semaphoreobj_win32(struct gl_context *ctx,
646*61046927SAndroid Build Coastguard Worker                           struct gl_semaphore_object *semObj,
647*61046927SAndroid Build Coastguard Worker                           void *handle,
648*61046927SAndroid Build Coastguard Worker                           const void *name,
649*61046927SAndroid Build Coastguard Worker                           enum pipe_fd_type type)
650*61046927SAndroid Build Coastguard Worker {
651*61046927SAndroid Build Coastguard Worker    struct pipe_context *pipe = ctx->pipe;
652*61046927SAndroid Build Coastguard Worker    semObj->type = type;
653*61046927SAndroid Build Coastguard Worker 
654*61046927SAndroid Build Coastguard Worker    pipe->screen->create_fence_win32(pipe->screen, &semObj->fence, handle, name, type);
655*61046927SAndroid Build Coastguard Worker }
656*61046927SAndroid Build Coastguard Worker 
657*61046927SAndroid Build Coastguard Worker static void
server_wait_semaphore(struct gl_context * ctx,struct gl_semaphore_object * semObj,GLuint numBufferBarriers,struct gl_buffer_object ** bufObjs,GLuint numTextureBarriers,struct gl_texture_object ** texObjs,const GLenum * srcLayouts)658*61046927SAndroid Build Coastguard Worker server_wait_semaphore(struct gl_context *ctx,
659*61046927SAndroid Build Coastguard Worker                       struct gl_semaphore_object *semObj,
660*61046927SAndroid Build Coastguard Worker                       GLuint numBufferBarriers,
661*61046927SAndroid Build Coastguard Worker                       struct gl_buffer_object **bufObjs,
662*61046927SAndroid Build Coastguard Worker                       GLuint numTextureBarriers,
663*61046927SAndroid Build Coastguard Worker                       struct gl_texture_object **texObjs,
664*61046927SAndroid Build Coastguard Worker                       const GLenum *srcLayouts)
665*61046927SAndroid Build Coastguard Worker {
666*61046927SAndroid Build Coastguard Worker    struct st_context *st = ctx->st;
667*61046927SAndroid Build Coastguard Worker    struct pipe_context *pipe = ctx->pipe;
668*61046927SAndroid Build Coastguard Worker    struct gl_buffer_object *bufObj;
669*61046927SAndroid Build Coastguard Worker    struct gl_texture_object *texObj;
670*61046927SAndroid Build Coastguard Worker 
671*61046927SAndroid Build Coastguard Worker    /* The driver is allowed to flush during fence_server_sync, be prepared */
672*61046927SAndroid Build Coastguard Worker    st_flush_bitmap_cache(st);
673*61046927SAndroid Build Coastguard Worker    pipe->fence_server_sync(pipe, semObj->fence);
674*61046927SAndroid Build Coastguard Worker 
675*61046927SAndroid Build Coastguard Worker    /**
676*61046927SAndroid Build Coastguard Worker     * According to the EXT_external_objects spec, the memory operations must
677*61046927SAndroid Build Coastguard Worker     * follow the wait. This is to make sure the flush is executed after the
678*61046927SAndroid Build Coastguard Worker     * other party is done modifying the memory.
679*61046927SAndroid Build Coastguard Worker     *
680*61046927SAndroid Build Coastguard Worker     * Relevant excerpt from section "4.2.3 Waiting for Semaphores":
681*61046927SAndroid Build Coastguard Worker     *
682*61046927SAndroid Build Coastguard Worker     * Following completion of the semaphore wait operation, memory will also be
683*61046927SAndroid Build Coastguard Worker     * made visible in the specified buffer and texture objects.
684*61046927SAndroid Build Coastguard Worker     *
685*61046927SAndroid Build Coastguard Worker     */
686*61046927SAndroid Build Coastguard Worker    for (unsigned i = 0; i < numBufferBarriers; i++) {
687*61046927SAndroid Build Coastguard Worker       if (!bufObjs[i])
688*61046927SAndroid Build Coastguard Worker          continue;
689*61046927SAndroid Build Coastguard Worker 
690*61046927SAndroid Build Coastguard Worker       bufObj = bufObjs[i];
691*61046927SAndroid Build Coastguard Worker       if (bufObj->buffer)
692*61046927SAndroid Build Coastguard Worker          pipe->flush_resource(pipe, bufObj->buffer);
693*61046927SAndroid Build Coastguard Worker    }
694*61046927SAndroid Build Coastguard Worker 
695*61046927SAndroid Build Coastguard Worker    for (unsigned i = 0; i < numTextureBarriers; i++) {
696*61046927SAndroid Build Coastguard Worker       if (!texObjs[i])
697*61046927SAndroid Build Coastguard Worker          continue;
698*61046927SAndroid Build Coastguard Worker 
699*61046927SAndroid Build Coastguard Worker       texObj = texObjs[i];
700*61046927SAndroid Build Coastguard Worker       if (texObj->pt)
701*61046927SAndroid Build Coastguard Worker          pipe->flush_resource(pipe, texObj->pt);
702*61046927SAndroid Build Coastguard Worker    }
703*61046927SAndroid Build Coastguard Worker }
704*61046927SAndroid Build Coastguard Worker 
705*61046927SAndroid Build Coastguard Worker static void
server_signal_semaphore(struct gl_context * ctx,struct gl_semaphore_object * semObj,GLuint numBufferBarriers,struct gl_buffer_object ** bufObjs,GLuint numTextureBarriers,struct gl_texture_object ** texObjs,const GLenum * dstLayouts)706*61046927SAndroid Build Coastguard Worker server_signal_semaphore(struct gl_context *ctx,
707*61046927SAndroid Build Coastguard Worker                         struct gl_semaphore_object *semObj,
708*61046927SAndroid Build Coastguard Worker                         GLuint numBufferBarriers,
709*61046927SAndroid Build Coastguard Worker                         struct gl_buffer_object **bufObjs,
710*61046927SAndroid Build Coastguard Worker                         GLuint numTextureBarriers,
711*61046927SAndroid Build Coastguard Worker                         struct gl_texture_object **texObjs,
712*61046927SAndroid Build Coastguard Worker                         const GLenum *dstLayouts)
713*61046927SAndroid Build Coastguard Worker {
714*61046927SAndroid Build Coastguard Worker    struct st_context *st = ctx->st;
715*61046927SAndroid Build Coastguard Worker    struct pipe_context *pipe = ctx->pipe;
716*61046927SAndroid Build Coastguard Worker    struct gl_buffer_object *bufObj;
717*61046927SAndroid Build Coastguard Worker    struct gl_texture_object *texObj;
718*61046927SAndroid Build Coastguard Worker 
719*61046927SAndroid Build Coastguard Worker    for (unsigned i = 0; i < numBufferBarriers; i++) {
720*61046927SAndroid Build Coastguard Worker       if (!bufObjs[i])
721*61046927SAndroid Build Coastguard Worker          continue;
722*61046927SAndroid Build Coastguard Worker 
723*61046927SAndroid Build Coastguard Worker       bufObj = bufObjs[i];
724*61046927SAndroid Build Coastguard Worker       if (bufObj->buffer)
725*61046927SAndroid Build Coastguard Worker          pipe->flush_resource(pipe, bufObj->buffer);
726*61046927SAndroid Build Coastguard Worker    }
727*61046927SAndroid Build Coastguard Worker 
728*61046927SAndroid Build Coastguard Worker    for (unsigned i = 0; i < numTextureBarriers; i++) {
729*61046927SAndroid Build Coastguard Worker       if (!texObjs[i])
730*61046927SAndroid Build Coastguard Worker          continue;
731*61046927SAndroid Build Coastguard Worker 
732*61046927SAndroid Build Coastguard Worker       texObj = texObjs[i];
733*61046927SAndroid Build Coastguard Worker       if (texObj->pt)
734*61046927SAndroid Build Coastguard Worker          pipe->flush_resource(pipe, texObj->pt);
735*61046927SAndroid Build Coastguard Worker    }
736*61046927SAndroid Build Coastguard Worker 
737*61046927SAndroid Build Coastguard Worker    /* The driver must flush during fence_server_signal, be prepared */
738*61046927SAndroid Build Coastguard Worker    st_flush_bitmap_cache(st);
739*61046927SAndroid Build Coastguard Worker    pipe->fence_server_signal(pipe, semObj->fence);
740*61046927SAndroid Build Coastguard Worker }
741*61046927SAndroid Build Coastguard Worker 
742*61046927SAndroid Build Coastguard Worker /**
743*61046927SAndroid Build Coastguard Worker  * Used as a placeholder for semaphore objects between glGenSemaphoresEXT()
744*61046927SAndroid Build Coastguard Worker  * and glImportSemaphoreFdEXT(), so that glIsSemaphoreEXT() can work correctly.
745*61046927SAndroid Build Coastguard Worker  */
746*61046927SAndroid Build Coastguard Worker static struct gl_semaphore_object DummySemaphoreObject;
747*61046927SAndroid Build Coastguard Worker 
748*61046927SAndroid Build Coastguard Worker /**
749*61046927SAndroid Build Coastguard Worker  * Delete a semaphore object.
750*61046927SAndroid Build Coastguard Worker  * Not removed from hash table here.
751*61046927SAndroid Build Coastguard Worker  */
752*61046927SAndroid Build Coastguard Worker void
_mesa_delete_semaphore_object(struct gl_context * ctx,struct gl_semaphore_object * semObj)753*61046927SAndroid Build Coastguard Worker _mesa_delete_semaphore_object(struct gl_context *ctx,
754*61046927SAndroid Build Coastguard Worker                               struct gl_semaphore_object *semObj)
755*61046927SAndroid Build Coastguard Worker {
756*61046927SAndroid Build Coastguard Worker    if (semObj != &DummySemaphoreObject) {
757*61046927SAndroid Build Coastguard Worker       struct pipe_context *pipe = ctx->pipe;
758*61046927SAndroid Build Coastguard Worker       pipe->screen->fence_reference(ctx->screen, &semObj->fence, NULL);
759*61046927SAndroid Build Coastguard Worker       FREE(semObj);
760*61046927SAndroid Build Coastguard Worker    }
761*61046927SAndroid Build Coastguard Worker }
762*61046927SAndroid Build Coastguard Worker 
763*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_GenSemaphoresEXT(GLsizei n,GLuint * semaphores)764*61046927SAndroid Build Coastguard Worker _mesa_GenSemaphoresEXT(GLsizei n, GLuint *semaphores)
765*61046927SAndroid Build Coastguard Worker {
766*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
767*61046927SAndroid Build Coastguard Worker 
768*61046927SAndroid Build Coastguard Worker    const char *func = "glGenSemaphoresEXT";
769*61046927SAndroid Build Coastguard Worker 
770*61046927SAndroid Build Coastguard Worker    if (MESA_VERBOSE & (VERBOSE_API))
771*61046927SAndroid Build Coastguard Worker       _mesa_debug(ctx, "%s(%d, %p)\n", func, n, semaphores);
772*61046927SAndroid Build Coastguard Worker 
773*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_semaphore) {
774*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
775*61046927SAndroid Build Coastguard Worker       return;
776*61046927SAndroid Build Coastguard Worker    }
777*61046927SAndroid Build Coastguard Worker 
778*61046927SAndroid Build Coastguard Worker    if (n < 0) {
779*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func);
780*61046927SAndroid Build Coastguard Worker       return;
781*61046927SAndroid Build Coastguard Worker    }
782*61046927SAndroid Build Coastguard Worker 
783*61046927SAndroid Build Coastguard Worker    if (!semaphores)
784*61046927SAndroid Build Coastguard Worker       return;
785*61046927SAndroid Build Coastguard Worker 
786*61046927SAndroid Build Coastguard Worker    _mesa_HashLockMutex(&ctx->Shared->SemaphoreObjects);
787*61046927SAndroid Build Coastguard Worker    if (_mesa_HashFindFreeKeys(&ctx->Shared->SemaphoreObjects, semaphores, n)) {
788*61046927SAndroid Build Coastguard Worker       for (GLsizei i = 0; i < n; i++) {
789*61046927SAndroid Build Coastguard Worker          _mesa_HashInsertLocked(&ctx->Shared->SemaphoreObjects, semaphores[i],
790*61046927SAndroid Build Coastguard Worker                                 &DummySemaphoreObject);
791*61046927SAndroid Build Coastguard Worker       }
792*61046927SAndroid Build Coastguard Worker    }
793*61046927SAndroid Build Coastguard Worker 
794*61046927SAndroid Build Coastguard Worker    _mesa_HashUnlockMutex(&ctx->Shared->SemaphoreObjects);
795*61046927SAndroid Build Coastguard Worker }
796*61046927SAndroid Build Coastguard Worker 
797*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_DeleteSemaphoresEXT(GLsizei n,const GLuint * semaphores)798*61046927SAndroid Build Coastguard Worker _mesa_DeleteSemaphoresEXT(GLsizei n, const GLuint *semaphores)
799*61046927SAndroid Build Coastguard Worker {
800*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
801*61046927SAndroid Build Coastguard Worker 
802*61046927SAndroid Build Coastguard Worker    const char *func = "glDeleteSemaphoresEXT";
803*61046927SAndroid Build Coastguard Worker 
804*61046927SAndroid Build Coastguard Worker    if (MESA_VERBOSE & (VERBOSE_API)) {
805*61046927SAndroid Build Coastguard Worker       _mesa_debug(ctx, "%s(%d, %p)\n", func, n, semaphores);
806*61046927SAndroid Build Coastguard Worker    }
807*61046927SAndroid Build Coastguard Worker 
808*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_semaphore) {
809*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
810*61046927SAndroid Build Coastguard Worker       return;
811*61046927SAndroid Build Coastguard Worker    }
812*61046927SAndroid Build Coastguard Worker 
813*61046927SAndroid Build Coastguard Worker    if (n < 0) {
814*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func);
815*61046927SAndroid Build Coastguard Worker       return;
816*61046927SAndroid Build Coastguard Worker    }
817*61046927SAndroid Build Coastguard Worker 
818*61046927SAndroid Build Coastguard Worker    if (!semaphores)
819*61046927SAndroid Build Coastguard Worker       return;
820*61046927SAndroid Build Coastguard Worker 
821*61046927SAndroid Build Coastguard Worker    _mesa_HashLockMutex(&ctx->Shared->SemaphoreObjects);
822*61046927SAndroid Build Coastguard Worker    for (GLint i = 0; i < n; i++) {
823*61046927SAndroid Build Coastguard Worker       if (semaphores[i] > 0) {
824*61046927SAndroid Build Coastguard Worker          struct gl_semaphore_object *delObj
825*61046927SAndroid Build Coastguard Worker             = _mesa_lookup_semaphore_object_locked(ctx, semaphores[i]);
826*61046927SAndroid Build Coastguard Worker 
827*61046927SAndroid Build Coastguard Worker          if (delObj) {
828*61046927SAndroid Build Coastguard Worker             _mesa_HashRemoveLocked(&ctx->Shared->SemaphoreObjects,
829*61046927SAndroid Build Coastguard Worker                                    semaphores[i]);
830*61046927SAndroid Build Coastguard Worker             _mesa_delete_semaphore_object(ctx, delObj);
831*61046927SAndroid Build Coastguard Worker          }
832*61046927SAndroid Build Coastguard Worker       }
833*61046927SAndroid Build Coastguard Worker    }
834*61046927SAndroid Build Coastguard Worker    _mesa_HashUnlockMutex(&ctx->Shared->SemaphoreObjects);
835*61046927SAndroid Build Coastguard Worker }
836*61046927SAndroid Build Coastguard Worker 
837*61046927SAndroid Build Coastguard Worker GLboolean GLAPIENTRY
_mesa_IsSemaphoreEXT(GLuint semaphore)838*61046927SAndroid Build Coastguard Worker _mesa_IsSemaphoreEXT(GLuint semaphore)
839*61046927SAndroid Build Coastguard Worker {
840*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
841*61046927SAndroid Build Coastguard Worker 
842*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_semaphore) {
843*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "glIsSemaphoreEXT(unsupported)");
844*61046927SAndroid Build Coastguard Worker       return GL_FALSE;
845*61046927SAndroid Build Coastguard Worker    }
846*61046927SAndroid Build Coastguard Worker 
847*61046927SAndroid Build Coastguard Worker    struct gl_semaphore_object *obj =
848*61046927SAndroid Build Coastguard Worker       _mesa_lookup_semaphore_object(ctx, semaphore);
849*61046927SAndroid Build Coastguard Worker 
850*61046927SAndroid Build Coastguard Worker    return obj ? GL_TRUE : GL_FALSE;
851*61046927SAndroid Build Coastguard Worker }
852*61046927SAndroid Build Coastguard Worker 
853*61046927SAndroid Build Coastguard Worker /**
854*61046927SAndroid Build Coastguard Worker  * Helper that outputs the correct error status for parameter
855*61046927SAndroid Build Coastguard Worker  * calls where no pnames are defined
856*61046927SAndroid Build Coastguard Worker  */
857*61046927SAndroid Build Coastguard Worker static void
semaphore_parameter_stub(const char * func,GLenum pname)858*61046927SAndroid Build Coastguard Worker semaphore_parameter_stub(const char* func, GLenum pname)
859*61046927SAndroid Build Coastguard Worker {
860*61046927SAndroid Build Coastguard Worker }
861*61046927SAndroid Build Coastguard Worker 
862*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_SemaphoreParameterui64vEXT(GLuint semaphore,GLenum pname,const GLuint64 * params)863*61046927SAndroid Build Coastguard Worker _mesa_SemaphoreParameterui64vEXT(GLuint semaphore,
864*61046927SAndroid Build Coastguard Worker                                  GLenum pname,
865*61046927SAndroid Build Coastguard Worker                                  const GLuint64 *params)
866*61046927SAndroid Build Coastguard Worker {
867*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
868*61046927SAndroid Build Coastguard Worker    const char *func = "glSemaphoreParameterui64vEXT";
869*61046927SAndroid Build Coastguard Worker 
870*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_semaphore) {
871*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
872*61046927SAndroid Build Coastguard Worker       return;
873*61046927SAndroid Build Coastguard Worker    }
874*61046927SAndroid Build Coastguard Worker 
875*61046927SAndroid Build Coastguard Worker    if (pname != GL_D3D12_FENCE_VALUE_EXT) {
876*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname);
877*61046927SAndroid Build Coastguard Worker       return;
878*61046927SAndroid Build Coastguard Worker    }
879*61046927SAndroid Build Coastguard Worker 
880*61046927SAndroid Build Coastguard Worker    struct gl_semaphore_object *semObj = _mesa_lookup_semaphore_object(ctx,
881*61046927SAndroid Build Coastguard Worker                                                                       semaphore);
882*61046927SAndroid Build Coastguard Worker    if (!semObj)
883*61046927SAndroid Build Coastguard Worker       return;
884*61046927SAndroid Build Coastguard Worker 
885*61046927SAndroid Build Coastguard Worker    if (semObj->type != PIPE_FD_TYPE_TIMELINE_SEMAPHORE) {
886*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(Not a D3D12 fence)", func);
887*61046927SAndroid Build Coastguard Worker       return;
888*61046927SAndroid Build Coastguard Worker    }
889*61046927SAndroid Build Coastguard Worker 
890*61046927SAndroid Build Coastguard Worker    semObj->timeline_value = params[0];
891*61046927SAndroid Build Coastguard Worker    ctx->screen->set_fence_timeline_value(ctx->screen, semObj->fence, params[0]);
892*61046927SAndroid Build Coastguard Worker }
893*61046927SAndroid Build Coastguard Worker 
894*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_GetSemaphoreParameterui64vEXT(GLuint semaphore,GLenum pname,GLuint64 * params)895*61046927SAndroid Build Coastguard Worker _mesa_GetSemaphoreParameterui64vEXT(GLuint semaphore,
896*61046927SAndroid Build Coastguard Worker                                     GLenum pname,
897*61046927SAndroid Build Coastguard Worker                                     GLuint64 *params)
898*61046927SAndroid Build Coastguard Worker {
899*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
900*61046927SAndroid Build Coastguard Worker    const char *func = "glGetSemaphoreParameterui64vEXT";
901*61046927SAndroid Build Coastguard Worker 
902*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_semaphore) {
903*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
904*61046927SAndroid Build Coastguard Worker       return;
905*61046927SAndroid Build Coastguard Worker    }
906*61046927SAndroid Build Coastguard Worker 
907*61046927SAndroid Build Coastguard Worker    if (pname != GL_D3D12_FENCE_VALUE_EXT) {
908*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname);
909*61046927SAndroid Build Coastguard Worker       return;
910*61046927SAndroid Build Coastguard Worker    }
911*61046927SAndroid Build Coastguard Worker 
912*61046927SAndroid Build Coastguard Worker    struct gl_semaphore_object *semObj = _mesa_lookup_semaphore_object(ctx,
913*61046927SAndroid Build Coastguard Worker                                                                       semaphore);
914*61046927SAndroid Build Coastguard Worker    if (!semObj)
915*61046927SAndroid Build Coastguard Worker       return;
916*61046927SAndroid Build Coastguard Worker 
917*61046927SAndroid Build Coastguard Worker    if (semObj->type != PIPE_FD_TYPE_TIMELINE_SEMAPHORE) {
918*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(Not a D3D12 fence)", func);
919*61046927SAndroid Build Coastguard Worker       return;
920*61046927SAndroid Build Coastguard Worker    }
921*61046927SAndroid Build Coastguard Worker 
922*61046927SAndroid Build Coastguard Worker    params[0] = semObj->timeline_value;
923*61046927SAndroid Build Coastguard Worker }
924*61046927SAndroid Build Coastguard Worker 
925*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_WaitSemaphoreEXT(GLuint semaphore,GLuint numBufferBarriers,const GLuint * buffers,GLuint numTextureBarriers,const GLuint * textures,const GLenum * srcLayouts)926*61046927SAndroid Build Coastguard Worker _mesa_WaitSemaphoreEXT(GLuint semaphore,
927*61046927SAndroid Build Coastguard Worker                        GLuint numBufferBarriers,
928*61046927SAndroid Build Coastguard Worker                        const GLuint *buffers,
929*61046927SAndroid Build Coastguard Worker                        GLuint numTextureBarriers,
930*61046927SAndroid Build Coastguard Worker                        const GLuint *textures,
931*61046927SAndroid Build Coastguard Worker                        const GLenum *srcLayouts)
932*61046927SAndroid Build Coastguard Worker {
933*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
934*61046927SAndroid Build Coastguard Worker    struct gl_semaphore_object *semObj = NULL;
935*61046927SAndroid Build Coastguard Worker    struct gl_buffer_object **bufObjs = NULL;
936*61046927SAndroid Build Coastguard Worker    struct gl_texture_object **texObjs = NULL;
937*61046927SAndroid Build Coastguard Worker 
938*61046927SAndroid Build Coastguard Worker    const char *func = "glWaitSemaphoreEXT";
939*61046927SAndroid Build Coastguard Worker 
940*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_semaphore) {
941*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
942*61046927SAndroid Build Coastguard Worker       return;
943*61046927SAndroid Build Coastguard Worker    }
944*61046927SAndroid Build Coastguard Worker 
945*61046927SAndroid Build Coastguard Worker    ASSERT_OUTSIDE_BEGIN_END(ctx);
946*61046927SAndroid Build Coastguard Worker 
947*61046927SAndroid Build Coastguard Worker    semObj = _mesa_lookup_semaphore_object(ctx, semaphore);
948*61046927SAndroid Build Coastguard Worker    if (!semObj)
949*61046927SAndroid Build Coastguard Worker       return;
950*61046927SAndroid Build Coastguard Worker 
951*61046927SAndroid Build Coastguard Worker    FLUSH_VERTICES(ctx, 0, 0);
952*61046927SAndroid Build Coastguard Worker 
953*61046927SAndroid Build Coastguard Worker    bufObjs = malloc(sizeof(struct gl_buffer_object *) * numBufferBarriers);
954*61046927SAndroid Build Coastguard Worker    if (!bufObjs) {
955*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numBufferBarriers=%u)",
956*61046927SAndroid Build Coastguard Worker                   func, numBufferBarriers);
957*61046927SAndroid Build Coastguard Worker       goto end;
958*61046927SAndroid Build Coastguard Worker    }
959*61046927SAndroid Build Coastguard Worker 
960*61046927SAndroid Build Coastguard Worker    for (unsigned i = 0; i < numBufferBarriers; i++) {
961*61046927SAndroid Build Coastguard Worker       bufObjs[i] = _mesa_lookup_bufferobj(ctx, buffers[i]);
962*61046927SAndroid Build Coastguard Worker    }
963*61046927SAndroid Build Coastguard Worker 
964*61046927SAndroid Build Coastguard Worker    texObjs = malloc(sizeof(struct gl_texture_object *) * numTextureBarriers);
965*61046927SAndroid Build Coastguard Worker    if (!texObjs) {
966*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numTextureBarriers=%u)",
967*61046927SAndroid Build Coastguard Worker                   func, numTextureBarriers);
968*61046927SAndroid Build Coastguard Worker       goto end;
969*61046927SAndroid Build Coastguard Worker    }
970*61046927SAndroid Build Coastguard Worker 
971*61046927SAndroid Build Coastguard Worker    for (unsigned i = 0; i < numTextureBarriers; i++) {
972*61046927SAndroid Build Coastguard Worker       texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
973*61046927SAndroid Build Coastguard Worker    }
974*61046927SAndroid Build Coastguard Worker 
975*61046927SAndroid Build Coastguard Worker    server_wait_semaphore(ctx, semObj,
976*61046927SAndroid Build Coastguard Worker                          numBufferBarriers, bufObjs,
977*61046927SAndroid Build Coastguard Worker                          numTextureBarriers, texObjs,
978*61046927SAndroid Build Coastguard Worker                          srcLayouts);
979*61046927SAndroid Build Coastguard Worker 
980*61046927SAndroid Build Coastguard Worker end:
981*61046927SAndroid Build Coastguard Worker    free(bufObjs);
982*61046927SAndroid Build Coastguard Worker    free(texObjs);
983*61046927SAndroid Build Coastguard Worker }
984*61046927SAndroid Build Coastguard Worker 
985*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_SignalSemaphoreEXT(GLuint semaphore,GLuint numBufferBarriers,const GLuint * buffers,GLuint numTextureBarriers,const GLuint * textures,const GLenum * dstLayouts)986*61046927SAndroid Build Coastguard Worker _mesa_SignalSemaphoreEXT(GLuint semaphore,
987*61046927SAndroid Build Coastguard Worker                          GLuint numBufferBarriers,
988*61046927SAndroid Build Coastguard Worker                          const GLuint *buffers,
989*61046927SAndroid Build Coastguard Worker                          GLuint numTextureBarriers,
990*61046927SAndroid Build Coastguard Worker                          const GLuint *textures,
991*61046927SAndroid Build Coastguard Worker                          const GLenum *dstLayouts)
992*61046927SAndroid Build Coastguard Worker {
993*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
994*61046927SAndroid Build Coastguard Worker    struct gl_semaphore_object *semObj = NULL;
995*61046927SAndroid Build Coastguard Worker    struct gl_buffer_object **bufObjs = NULL;
996*61046927SAndroid Build Coastguard Worker    struct gl_texture_object **texObjs = NULL;
997*61046927SAndroid Build Coastguard Worker 
998*61046927SAndroid Build Coastguard Worker    const char *func = "glSignalSemaphoreEXT";
999*61046927SAndroid Build Coastguard Worker 
1000*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_semaphore) {
1001*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
1002*61046927SAndroid Build Coastguard Worker       return;
1003*61046927SAndroid Build Coastguard Worker    }
1004*61046927SAndroid Build Coastguard Worker 
1005*61046927SAndroid Build Coastguard Worker    ASSERT_OUTSIDE_BEGIN_END(ctx);
1006*61046927SAndroid Build Coastguard Worker 
1007*61046927SAndroid Build Coastguard Worker    semObj = _mesa_lookup_semaphore_object(ctx, semaphore);
1008*61046927SAndroid Build Coastguard Worker    if (!semObj)
1009*61046927SAndroid Build Coastguard Worker       return;
1010*61046927SAndroid Build Coastguard Worker 
1011*61046927SAndroid Build Coastguard Worker    FLUSH_VERTICES(ctx, 0, 0);
1012*61046927SAndroid Build Coastguard Worker 
1013*61046927SAndroid Build Coastguard Worker    bufObjs = malloc(sizeof(struct gl_buffer_object *) * numBufferBarriers);
1014*61046927SAndroid Build Coastguard Worker    if (!bufObjs) {
1015*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numBufferBarriers=%u)",
1016*61046927SAndroid Build Coastguard Worker                   func, numBufferBarriers);
1017*61046927SAndroid Build Coastguard Worker       goto end;
1018*61046927SAndroid Build Coastguard Worker    }
1019*61046927SAndroid Build Coastguard Worker 
1020*61046927SAndroid Build Coastguard Worker    for (unsigned i = 0; i < numBufferBarriers; i++) {
1021*61046927SAndroid Build Coastguard Worker       bufObjs[i] = _mesa_lookup_bufferobj(ctx, buffers[i]);
1022*61046927SAndroid Build Coastguard Worker    }
1023*61046927SAndroid Build Coastguard Worker 
1024*61046927SAndroid Build Coastguard Worker    texObjs = malloc(sizeof(struct gl_texture_object *) * numTextureBarriers);
1025*61046927SAndroid Build Coastguard Worker    if (!texObjs) {
1026*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numTextureBarriers=%u)",
1027*61046927SAndroid Build Coastguard Worker                   func, numTextureBarriers);
1028*61046927SAndroid Build Coastguard Worker       goto end;
1029*61046927SAndroid Build Coastguard Worker    }
1030*61046927SAndroid Build Coastguard Worker 
1031*61046927SAndroid Build Coastguard Worker    for (unsigned i = 0; i < numTextureBarriers; i++) {
1032*61046927SAndroid Build Coastguard Worker       texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
1033*61046927SAndroid Build Coastguard Worker    }
1034*61046927SAndroid Build Coastguard Worker 
1035*61046927SAndroid Build Coastguard Worker    server_signal_semaphore(ctx, semObj,
1036*61046927SAndroid Build Coastguard Worker                            numBufferBarriers, bufObjs,
1037*61046927SAndroid Build Coastguard Worker                            numTextureBarriers, texObjs,
1038*61046927SAndroid Build Coastguard Worker                            dstLayouts);
1039*61046927SAndroid Build Coastguard Worker 
1040*61046927SAndroid Build Coastguard Worker end:
1041*61046927SAndroid Build Coastguard Worker    free(bufObjs);
1042*61046927SAndroid Build Coastguard Worker    free(texObjs);
1043*61046927SAndroid Build Coastguard Worker }
1044*61046927SAndroid Build Coastguard Worker 
1045*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ImportMemoryFdEXT(GLuint memory,GLuint64 size,GLenum handleType,GLint fd)1046*61046927SAndroid Build Coastguard Worker _mesa_ImportMemoryFdEXT(GLuint memory,
1047*61046927SAndroid Build Coastguard Worker                         GLuint64 size,
1048*61046927SAndroid Build Coastguard Worker                         GLenum handleType,
1049*61046927SAndroid Build Coastguard Worker                         GLint fd)
1050*61046927SAndroid Build Coastguard Worker {
1051*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
1052*61046927SAndroid Build Coastguard Worker 
1053*61046927SAndroid Build Coastguard Worker    const char *func = "glImportMemoryFdEXT";
1054*61046927SAndroid Build Coastguard Worker 
1055*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object_fd) {
1056*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
1057*61046927SAndroid Build Coastguard Worker       return;
1058*61046927SAndroid Build Coastguard Worker    }
1059*61046927SAndroid Build Coastguard Worker 
1060*61046927SAndroid Build Coastguard Worker    if (handleType != GL_HANDLE_TYPE_OPAQUE_FD_EXT) {
1061*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM, "%s(handleType=%u)", func, handleType);
1062*61046927SAndroid Build Coastguard Worker       return;
1063*61046927SAndroid Build Coastguard Worker    }
1064*61046927SAndroid Build Coastguard Worker 
1065*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *memObj = _mesa_lookup_memory_object(ctx, memory);
1066*61046927SAndroid Build Coastguard Worker    if (!memObj)
1067*61046927SAndroid Build Coastguard Worker       return;
1068*61046927SAndroid Build Coastguard Worker 
1069*61046927SAndroid Build Coastguard Worker    import_memoryobj_fd(ctx, memObj, size, fd);
1070*61046927SAndroid Build Coastguard Worker    memObj->Immutable = GL_TRUE;
1071*61046927SAndroid Build Coastguard Worker }
1072*61046927SAndroid Build Coastguard Worker 
1073*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ImportMemoryWin32HandleEXT(GLuint memory,GLuint64 size,GLenum handleType,void * handle)1074*61046927SAndroid Build Coastguard Worker _mesa_ImportMemoryWin32HandleEXT(GLuint memory,
1075*61046927SAndroid Build Coastguard Worker                                  GLuint64 size,
1076*61046927SAndroid Build Coastguard Worker                                  GLenum handleType,
1077*61046927SAndroid Build Coastguard Worker                                  void *handle)
1078*61046927SAndroid Build Coastguard Worker {
1079*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
1080*61046927SAndroid Build Coastguard Worker 
1081*61046927SAndroid Build Coastguard Worker    const char *func = "glImportMemoryWin32HandleEXT";
1082*61046927SAndroid Build Coastguard Worker 
1083*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object_win32) {
1084*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
1085*61046927SAndroid Build Coastguard Worker       return;
1086*61046927SAndroid Build Coastguard Worker    }
1087*61046927SAndroid Build Coastguard Worker 
1088*61046927SAndroid Build Coastguard Worker    if (handleType != GL_HANDLE_TYPE_OPAQUE_WIN32_EXT &&
1089*61046927SAndroid Build Coastguard Worker        handleType != GL_HANDLE_TYPE_D3D11_IMAGE_EXT &&
1090*61046927SAndroid Build Coastguard Worker        handleType != GL_HANDLE_TYPE_D3D12_RESOURCE_EXT &&
1091*61046927SAndroid Build Coastguard Worker        handleType != GL_HANDLE_TYPE_D3D12_TILEPOOL_EXT) {
1092*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM, "%s(handleType=%u)", func, handleType);
1093*61046927SAndroid Build Coastguard Worker       return;
1094*61046927SAndroid Build Coastguard Worker    }
1095*61046927SAndroid Build Coastguard Worker 
1096*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *memObj = _mesa_lookup_memory_object(ctx, memory);
1097*61046927SAndroid Build Coastguard Worker    if (!memObj)
1098*61046927SAndroid Build Coastguard Worker       return;
1099*61046927SAndroid Build Coastguard Worker 
1100*61046927SAndroid Build Coastguard Worker    import_memoryobj_win32(ctx, memObj, size, handle, NULL);
1101*61046927SAndroid Build Coastguard Worker    memObj->Immutable = GL_TRUE;
1102*61046927SAndroid Build Coastguard Worker }
1103*61046927SAndroid Build Coastguard Worker 
1104*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ImportMemoryWin32NameEXT(GLuint memory,GLuint64 size,GLenum handleType,const void * name)1105*61046927SAndroid Build Coastguard Worker _mesa_ImportMemoryWin32NameEXT(GLuint memory,
1106*61046927SAndroid Build Coastguard Worker                                  GLuint64 size,
1107*61046927SAndroid Build Coastguard Worker                                  GLenum handleType,
1108*61046927SAndroid Build Coastguard Worker                                  const void *name)
1109*61046927SAndroid Build Coastguard Worker {
1110*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
1111*61046927SAndroid Build Coastguard Worker 
1112*61046927SAndroid Build Coastguard Worker    const char *func = "glImportMemoryWin32NameEXT";
1113*61046927SAndroid Build Coastguard Worker 
1114*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_memory_object_win32) {
1115*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
1116*61046927SAndroid Build Coastguard Worker       return;
1117*61046927SAndroid Build Coastguard Worker    }
1118*61046927SAndroid Build Coastguard Worker 
1119*61046927SAndroid Build Coastguard Worker    if (handleType != GL_HANDLE_TYPE_OPAQUE_WIN32_EXT &&
1120*61046927SAndroid Build Coastguard Worker        handleType != GL_HANDLE_TYPE_D3D11_IMAGE_EXT &&
1121*61046927SAndroid Build Coastguard Worker        handleType != GL_HANDLE_TYPE_D3D12_RESOURCE_EXT &&
1122*61046927SAndroid Build Coastguard Worker        handleType != GL_HANDLE_TYPE_D3D12_TILEPOOL_EXT) {
1123*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM, "%s(handleType=%u)", func, handleType);
1124*61046927SAndroid Build Coastguard Worker       return;
1125*61046927SAndroid Build Coastguard Worker    }
1126*61046927SAndroid Build Coastguard Worker 
1127*61046927SAndroid Build Coastguard Worker    struct gl_memory_object *memObj = _mesa_lookup_memory_object(ctx, memory);
1128*61046927SAndroid Build Coastguard Worker    if (!memObj)
1129*61046927SAndroid Build Coastguard Worker       return;
1130*61046927SAndroid Build Coastguard Worker 
1131*61046927SAndroid Build Coastguard Worker    import_memoryobj_win32(ctx, memObj, size, NULL, name);
1132*61046927SAndroid Build Coastguard Worker    memObj->Immutable = GL_TRUE;
1133*61046927SAndroid Build Coastguard Worker }
1134*61046927SAndroid Build Coastguard Worker 
1135*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ImportSemaphoreFdEXT(GLuint semaphore,GLenum handleType,GLint fd)1136*61046927SAndroid Build Coastguard Worker _mesa_ImportSemaphoreFdEXT(GLuint semaphore,
1137*61046927SAndroid Build Coastguard Worker                            GLenum handleType,
1138*61046927SAndroid Build Coastguard Worker                            GLint fd)
1139*61046927SAndroid Build Coastguard Worker {
1140*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
1141*61046927SAndroid Build Coastguard Worker 
1142*61046927SAndroid Build Coastguard Worker    const char *func = "glImportSemaphoreFdEXT";
1143*61046927SAndroid Build Coastguard Worker 
1144*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_semaphore_fd) {
1145*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
1146*61046927SAndroid Build Coastguard Worker       return;
1147*61046927SAndroid Build Coastguard Worker    }
1148*61046927SAndroid Build Coastguard Worker 
1149*61046927SAndroid Build Coastguard Worker    if (handleType != GL_HANDLE_TYPE_OPAQUE_FD_EXT) {
1150*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM, "%s(handleType=%u)", func, handleType);
1151*61046927SAndroid Build Coastguard Worker       return;
1152*61046927SAndroid Build Coastguard Worker    }
1153*61046927SAndroid Build Coastguard Worker 
1154*61046927SAndroid Build Coastguard Worker    struct gl_semaphore_object *semObj = _mesa_lookup_semaphore_object(ctx,
1155*61046927SAndroid Build Coastguard Worker                                                                       semaphore);
1156*61046927SAndroid Build Coastguard Worker    if (!semObj)
1157*61046927SAndroid Build Coastguard Worker       return;
1158*61046927SAndroid Build Coastguard Worker 
1159*61046927SAndroid Build Coastguard Worker    if (semObj == &DummySemaphoreObject) {
1160*61046927SAndroid Build Coastguard Worker       semObj = semaphoreobj_alloc(ctx, semaphore);
1161*61046927SAndroid Build Coastguard Worker       if (!semObj) {
1162*61046927SAndroid Build Coastguard Worker          _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
1163*61046927SAndroid Build Coastguard Worker          return;
1164*61046927SAndroid Build Coastguard Worker       }
1165*61046927SAndroid Build Coastguard Worker       _mesa_HashInsert(&ctx->Shared->SemaphoreObjects, semaphore, semObj);
1166*61046927SAndroid Build Coastguard Worker    }
1167*61046927SAndroid Build Coastguard Worker 
1168*61046927SAndroid Build Coastguard Worker    import_semaphoreobj_fd(ctx, semObj, fd);
1169*61046927SAndroid Build Coastguard Worker }
1170*61046927SAndroid Build Coastguard Worker 
1171*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ImportSemaphoreWin32HandleEXT(GLuint semaphore,GLenum handleType,void * handle)1172*61046927SAndroid Build Coastguard Worker _mesa_ImportSemaphoreWin32HandleEXT(GLuint semaphore,
1173*61046927SAndroid Build Coastguard Worker                            GLenum handleType,
1174*61046927SAndroid Build Coastguard Worker                            void *handle)
1175*61046927SAndroid Build Coastguard Worker {
1176*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
1177*61046927SAndroid Build Coastguard Worker 
1178*61046927SAndroid Build Coastguard Worker    const char *func = "glImportSemaphoreWin32HandleEXT";
1179*61046927SAndroid Build Coastguard Worker 
1180*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_semaphore_win32) {
1181*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
1182*61046927SAndroid Build Coastguard Worker       return;
1183*61046927SAndroid Build Coastguard Worker    }
1184*61046927SAndroid Build Coastguard Worker 
1185*61046927SAndroid Build Coastguard Worker    if (handleType != GL_HANDLE_TYPE_OPAQUE_WIN32_EXT &&
1186*61046927SAndroid Build Coastguard Worker        handleType != GL_HANDLE_TYPE_D3D12_FENCE_EXT) {
1187*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM, "%s(handleType=%u)", func, handleType);
1188*61046927SAndroid Build Coastguard Worker       return;
1189*61046927SAndroid Build Coastguard Worker    }
1190*61046927SAndroid Build Coastguard Worker 
1191*61046927SAndroid Build Coastguard Worker    if (handleType == GL_HANDLE_TYPE_D3D12_FENCE_EXT &&
1192*61046927SAndroid Build Coastguard Worker        !ctx->screen->get_param(ctx->screen, PIPE_CAP_TIMELINE_SEMAPHORE_IMPORT)) {
1193*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM, "%s(handleType=%u)", func, handleType);
1194*61046927SAndroid Build Coastguard Worker    }
1195*61046927SAndroid Build Coastguard Worker 
1196*61046927SAndroid Build Coastguard Worker    struct gl_semaphore_object *semObj = _mesa_lookup_semaphore_object(ctx,
1197*61046927SAndroid Build Coastguard Worker                                                                       semaphore);
1198*61046927SAndroid Build Coastguard Worker    if (!semObj)
1199*61046927SAndroid Build Coastguard Worker       return;
1200*61046927SAndroid Build Coastguard Worker 
1201*61046927SAndroid Build Coastguard Worker    if (semObj == &DummySemaphoreObject) {
1202*61046927SAndroid Build Coastguard Worker       semObj = semaphoreobj_alloc(ctx, semaphore);
1203*61046927SAndroid Build Coastguard Worker       if (!semObj) {
1204*61046927SAndroid Build Coastguard Worker          _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
1205*61046927SAndroid Build Coastguard Worker          return;
1206*61046927SAndroid Build Coastguard Worker       }
1207*61046927SAndroid Build Coastguard Worker       _mesa_HashInsert(&ctx->Shared->SemaphoreObjects, semaphore, semObj);
1208*61046927SAndroid Build Coastguard Worker    }
1209*61046927SAndroid Build Coastguard Worker 
1210*61046927SAndroid Build Coastguard Worker    enum pipe_fd_type type = handleType == GL_HANDLE_TYPE_D3D12_FENCE_EXT ?
1211*61046927SAndroid Build Coastguard Worker       PIPE_FD_TYPE_TIMELINE_SEMAPHORE : PIPE_FD_TYPE_SYNCOBJ;
1212*61046927SAndroid Build Coastguard Worker    import_semaphoreobj_win32(ctx, semObj, handle, NULL, type);
1213*61046927SAndroid Build Coastguard Worker }
1214*61046927SAndroid Build Coastguard Worker 
1215*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ImportSemaphoreWin32NameEXT(GLuint semaphore,GLenum handleType,const void * name)1216*61046927SAndroid Build Coastguard Worker _mesa_ImportSemaphoreWin32NameEXT(GLuint semaphore,
1217*61046927SAndroid Build Coastguard Worker                                   GLenum handleType,
1218*61046927SAndroid Build Coastguard Worker                                   const void *name)
1219*61046927SAndroid Build Coastguard Worker {
1220*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
1221*61046927SAndroid Build Coastguard Worker 
1222*61046927SAndroid Build Coastguard Worker    const char *func = "glImportSemaphoreWin32HandleEXT";
1223*61046927SAndroid Build Coastguard Worker 
1224*61046927SAndroid Build Coastguard Worker    if (!ctx->Extensions.EXT_semaphore_win32) {
1225*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
1226*61046927SAndroid Build Coastguard Worker       return;
1227*61046927SAndroid Build Coastguard Worker    }
1228*61046927SAndroid Build Coastguard Worker 
1229*61046927SAndroid Build Coastguard Worker    if (handleType != GL_HANDLE_TYPE_OPAQUE_WIN32_EXT &&
1230*61046927SAndroid Build Coastguard Worker        handleType != GL_HANDLE_TYPE_D3D12_FENCE_EXT) {
1231*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM, "%s(handleType=%u)", func, handleType);
1232*61046927SAndroid Build Coastguard Worker       return;
1233*61046927SAndroid Build Coastguard Worker    }
1234*61046927SAndroid Build Coastguard Worker 
1235*61046927SAndroid Build Coastguard Worker    if (handleType == GL_HANDLE_TYPE_D3D12_FENCE_EXT &&
1236*61046927SAndroid Build Coastguard Worker        !ctx->screen->get_param(ctx->screen, PIPE_CAP_TIMELINE_SEMAPHORE_IMPORT)) {
1237*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM, "%s(handleType=%u)", func, handleType);
1238*61046927SAndroid Build Coastguard Worker    }
1239*61046927SAndroid Build Coastguard Worker 
1240*61046927SAndroid Build Coastguard Worker    struct gl_semaphore_object *semObj = _mesa_lookup_semaphore_object(ctx,
1241*61046927SAndroid Build Coastguard Worker                                                                       semaphore);
1242*61046927SAndroid Build Coastguard Worker    if (!semObj)
1243*61046927SAndroid Build Coastguard Worker       return;
1244*61046927SAndroid Build Coastguard Worker 
1245*61046927SAndroid Build Coastguard Worker    if (semObj == &DummySemaphoreObject) {
1246*61046927SAndroid Build Coastguard Worker       semObj = semaphoreobj_alloc(ctx, semaphore);
1247*61046927SAndroid Build Coastguard Worker       if (!semObj) {
1248*61046927SAndroid Build Coastguard Worker          _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
1249*61046927SAndroid Build Coastguard Worker          return;
1250*61046927SAndroid Build Coastguard Worker       }
1251*61046927SAndroid Build Coastguard Worker       _mesa_HashInsert(&ctx->Shared->SemaphoreObjects, semaphore, semObj);
1252*61046927SAndroid Build Coastguard Worker    }
1253*61046927SAndroid Build Coastguard Worker 
1254*61046927SAndroid Build Coastguard Worker    enum pipe_fd_type type = handleType == GL_HANDLE_TYPE_D3D12_FENCE_EXT ?
1255*61046927SAndroid Build Coastguard Worker       PIPE_FD_TYPE_TIMELINE_SEMAPHORE : PIPE_FD_TYPE_SYNCOBJ;
1256*61046927SAndroid Build Coastguard Worker    import_semaphoreobj_win32(ctx, semObj, NULL, name, type);
1257*61046927SAndroid Build Coastguard Worker }
1258