2 * Copyright © 2016 Red Hat.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
26 #include "externalobjects.h"
29 * Allocate and initialize a new memory object. But don't put it into the
30 * memory object hash table.
32 * Called via ctx->Driver.NewMemoryObject, unless overridden by a device
35 * \return pointer to new memory object.
37 static struct gl_memory_object
*
38 _mesa_new_memory_object(struct gl_context
*ctx
, GLuint name
)
40 struct gl_memory_object
*obj
= MALLOC_STRUCT(gl_memory_object
);
44 _mesa_initialize_memory_object(ctx
, obj
, name
);
49 * Delete a memory object. Called via ctx->Driver.DeleteMemory().
50 * Not removed from hash table here.
53 _mesa_delete_memory_object(struct gl_context
*ctx
,
54 struct gl_memory_object
*memObj
)
60 _mesa_init_memory_object_functions(struct dd_function_table
*driver
)
62 driver
->NewMemoryObject
= _mesa_new_memory_object
;
63 driver
->DeleteMemoryObject
= _mesa_delete_memory_object
;
67 * Initialize a buffer object to default values.
70 _mesa_initialize_memory_object(struct gl_context
*ctx
,
71 struct gl_memory_object
*obj
,
74 memset(obj
, 0, sizeof(struct gl_memory_object
));
79 _mesa_DeleteMemoryObjectsEXT(GLsizei n
, const GLuint
*memoryObjects
)
81 GET_CURRENT_CONTEXT(ctx
);
83 if (MESA_VERBOSE
& (VERBOSE_API
)) {
84 _mesa_debug(ctx
, "glDeleteMemoryObjectsEXT(%d, %p)\n", n
,
89 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteMemoryObjectsEXT(n < 0)");
96 _mesa_HashLockMutex(ctx
->Shared
->MemoryObjects
);
97 for (GLint i
= 0; i
< n
; i
++) {
98 if (memoryObjects
[i
] > 0) {
99 struct gl_memory_object
*delObj
100 = _mesa_lookup_memory_object_locked(ctx
, memoryObjects
[i
]);
103 _mesa_HashRemoveLocked(ctx
->Shared
->MemoryObjects
,
105 ctx
->Driver
.DeleteMemoryObject(ctx
, delObj
);
109 _mesa_HashUnlockMutex(ctx
->Shared
->MemoryObjects
);
113 _mesa_IsMemoryObjectEXT(GLuint memoryObject
)
115 GET_CURRENT_CONTEXT(ctx
);
116 struct gl_memory_object
*obj
=
117 _mesa_lookup_memory_object(ctx
, memoryObject
);
119 return obj
? GL_TRUE
: GL_FALSE
;
123 _mesa_CreateMemoryObjectsEXT(GLsizei n
, GLuint
*memoryObjects
)
125 GET_CURRENT_CONTEXT(ctx
);
127 const char *func
= "glCreateMemoryObjectsEXT";
129 if (MESA_VERBOSE
& (VERBOSE_API
))
130 _mesa_debug(ctx
, "%s(%d, %p)", func
, n
, memoryObjects
);
133 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
140 _mesa_HashLockMutex(ctx
->Shared
->MemoryObjects
);
141 GLuint first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->MemoryObjects
, n
);
143 for (GLsizei i
= 0; i
< n
; i
++) {
144 struct gl_memory_object
*memObj
;
146 memoryObjects
[i
] = first
+ i
;
148 /* allocate memory object */
149 memObj
= ctx
->Driver
.NewMemoryObject(ctx
, memoryObjects
[i
]);
151 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
152 _mesa_HashUnlockMutex(ctx
->Shared
->MemoryObjects
);
156 /* insert into hash table */
157 _mesa_HashInsertLocked(ctx
->Shared
->MemoryObjects
,
163 _mesa_HashUnlockMutex(ctx
->Shared
->MemoryObjects
);
167 _mesa_MemoryObjectParameterivEXT(GLuint memoryObject
,
175 _mesa_GetMemoryObjectParameterivEXT(GLuint memoryObject
,
183 _mesa_TexStorageMem2DEXT(GLenum target
,
185 GLenum internalFormat
,
195 _mesa_TexStorageMem2DMultisampleEXT(GLenum target
,
197 GLenum internalFormat
,
200 GLboolean fixedSampleLocations
,
208 _mesa_TexStorageMem3DEXT(GLenum target
,
210 GLenum internalFormat
,
221 _mesa_TexStorageMem3DMultisampleEXT(GLenum target
,
223 GLenum internalFormat
,
227 GLboolean fixedSampleLocations
,
235 _mesa_TextureStorageMem2DEXT(GLuint texture
,
237 GLenum internalFormat
,
247 _mesa_TextureStorageMem2DMultisampleEXT(GLuint texture
,
249 GLenum internalFormat
,
252 GLboolean fixedSampleLocations
,
260 _mesa_TextureStorageMem3DEXT(GLuint texture
,
262 GLenum internalFormat
,
273 _mesa_TextureStorageMem3DMultisampleEXT(GLuint texture
,
275 GLenum internalFormat
,
279 GLboolean fixedSampleLocations
,
287 _mesa_TexStorageMem1DEXT(GLenum target
,
289 GLenum internalFormat
,
298 _mesa_TextureStorageMem1DEXT(GLuint texture
,
300 GLenum internalFormat
,
309 _mesa_GenSemaphoresEXT(GLsizei n
, GLuint
*semaphores
)
315 _mesa_DeleteSemaphoresEXT(GLsizei n
, const GLuint
*semaphores
)
321 _mesa_IsSemaphoreEXT(GLuint semaphore
)
327 _mesa_SemaphoreParameterui64vEXT(GLuint semaphore
,
329 const GLuint64
*params
)
335 _mesa_GetSemaphoreParameterui64vEXT(GLuint semaphore
,
343 _mesa_WaitSemaphoreEXT(GLuint semaphore
,
344 GLuint numBufferBarriers
,
345 const GLuint
*buffers
,
346 GLuint numTextureBarriers
,
347 const GLuint
*textures
,
348 const GLenum
*srcLayouts
)
354 _mesa_SignalSemaphoreEXT(GLuint semaphore
,
355 GLuint numBufferBarriers
,
356 const GLuint
*buffers
,
357 GLuint numTextureBarriers
,
358 const GLuint
*textures
,
359 const GLenum
*dstLayouts
)
365 _mesa_ImportMemoryFdEXT(GLuint memory
,
370 GET_CURRENT_CONTEXT(ctx
);
372 if (handleType
!= GL_HANDLE_TYPE_OPAQUE_FD_EXT
) {
373 _mesa_error(ctx
, GL_INVALID_VALUE
, "glImportMemoryFdEXT(handleType=%u)",
378 struct gl_memory_object
*memObj
= _mesa_lookup_memory_object(ctx
, memory
);
382 ctx
->Driver
.ImportMemoryObjectFd(ctx
, memObj
, size
, fd
);
386 _mesa_ImportSemaphoreFdEXT(GLuint semaphore
,