Indicates if the given name has been returned by _mesa_HashFindFreeKeyBlock.
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6600>
/* Bind a user program */
newProg = _mesa_lookup_program(ctx, id);
if (!newProg || newProg == &_mesa_DummyProgram) {
+ bool isGenName = newProg != NULL;
/* allocate a new program now */
newProg = ctx->Driver.NewProgram(ctx, _mesa_program_enum_to_shader_stage(target),
id, true);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
return NULL;
}
- _mesa_HashInsert(ctx->Shared->Programs, id, newProg);
+ _mesa_HashInsert(ctx->Shared->Programs, id, newProg, isGenName);
}
else if (newProg->Target != target) {
_mesa_error(ctx, GL_INVALID_OPERATION,
/* Insert pointer to dummy program as placeholder */
for (i = 0; i < (GLuint) n; i++) {
_mesa_HashInsertLocked(ctx->Shared->Programs, first + i,
- &_mesa_DummyProgram);
+ &_mesa_DummyProgram, true);
}
_mesa_HashUnlockMutex(ctx->Shared->Programs);
return;
}
obj->EverBound = create;
- _mesa_HashInsertLocked(ctx->Array.Objects, obj->Name, obj);
+ _mesa_HashInsertLocked(ctx->Array.Objects, obj->Name, obj, true);
arrays[i] = first + i;
}
}
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->ATIShaders, range);
for (i = 0; i < range; i++) {
- _mesa_HashInsertLocked(ctx->Shared->ATIShaders, first + i, &DummyShader);
+ _mesa_HashInsertLocked(ctx->Shared->ATIShaders, first + i, &DummyShader, true);
}
_mesa_HashUnlockMutex(ctx->Shared->ATIShaders);
newProg = ctx->Shared->DefaultFragmentShader;
}
else {
+ bool isGenName;
newProg = (struct ati_fragment_shader *)
_mesa_HashLookup(ctx->Shared->ATIShaders, id);
+ isGenName = newProg != NULL;
if (!newProg || newProg == &DummyShader) {
/* allocate a new program now */
newProg = _mesa_new_ati_fragment_shader(ctx, id);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFragmentShaderATI");
return;
}
- _mesa_HashInsert(ctx->Shared->ATIShaders, id, newProg);
+ _mesa_HashInsert(ctx->Shared->ATIShaders, id, newProg, isGenName);
}
}
/* If this is a new buffer object id, or one which was generated but
* never used before, allocate a buffer object now.
*/
- buf = ctx->Driver.NewBufferObject(ctx, buffer);
- if (!buf) {
+ *buf_handle = ctx->Driver.NewBufferObject(ctx, buffer);
+ if (!*buf_handle) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
return false;
}
- _mesa_HashInsert(ctx->Shared->BufferObjects, buffer, buf);
- *buf_handle = buf;
+ _mesa_HashInsert(ctx->Shared->BufferObjects, buffer, *buf_handle, buf != NULL);
}
return true;
else
buf = &DummyBufferObject;
- _mesa_HashInsertLocked(ctx->Shared->BufferObjects, buffers[i], buf);
+ _mesa_HashInsertLocked(ctx->Shared->BufferObjects, buffers[i], buf, true);
}
_mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
* Create new bitmap atlas and insert into hash table.
*/
static struct gl_bitmap_atlas *
-alloc_bitmap_atlas(struct gl_context *ctx, GLuint listBase)
+alloc_bitmap_atlas(struct gl_context *ctx, GLuint listBase, bool isGenName)
{
struct gl_bitmap_atlas *atlas;
atlas = calloc(1, sizeof(*atlas));
if (atlas) {
- _mesa_HashInsert(ctx->Shared->BitmapAtlas, listBase, atlas);
+ _mesa_HashInsert(ctx->Shared->BitmapAtlas, listBase, atlas, isGenName);
}
return atlas;
GLint i;
for (i = 0; i < range; i++) {
_mesa_HashInsertLocked(ctx->Shared->DisplayList, base + i,
- make_list(base + i, 1));
+ make_list(base + i, 1), true);
}
}
*/
struct gl_bitmap_atlas *atlas = lookup_bitmap_atlas(ctx, base);
if (!atlas) {
- atlas = alloc_bitmap_atlas(ctx, base);
+ atlas = alloc_bitmap_atlas(ctx, base, true);
}
if (atlas) {
/* Atlas _should_ be new/empty now, but clobbering is OK */
/* Install the new list */
_mesa_HashInsert(ctx->Shared->DisplayList,
ctx->ListState.CurrentList->Name,
- ctx->ListState.CurrentList);
+ ctx->ListState.CurrentList, true);
if (MESA_VERBOSE & VERBOSE_DISPLAY_LIST)
/* Even if glGenLists wasn't called, we can still try to create
* the atlas now.
*/
- atlas = alloc_bitmap_atlas(ctx, ctx->List.ListBase);
+ atlas = alloc_bitmap_atlas(ctx, ctx->List.ListBase, false);
}
if (atlas && !atlas->complete && !atlas->incomplete) {
/* insert into hash table */
_mesa_HashInsertLocked(ctx->Shared->MemoryObjects,
memoryObjects[i],
- memObj);
+ memObj, true);
}
}
for (GLsizei i = 0; i < n; i++) {
semaphores[i] = first + i;
_mesa_HashInsertLocked(ctx->Shared->SemaphoreObjects,
- semaphores[i], &DummySemaphoreObject);
+ semaphores[i], &DummySemaphoreObject, true);
}
}
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
return;
}
- _mesa_HashInsert(ctx->Shared->SemaphoreObjects, semaphore, semObj);
+ _mesa_HashInsert(ctx->Shared->SemaphoreObjects, semaphore, semObj, true);
}
ctx->Driver.ImportSemaphoreFd(ctx, semObj, fd);
/* Name exists but buffer is not initialized */
if (fb == &DummyFramebuffer) {
fb = ctx->Driver.NewFramebuffer(ctx, id);
- _mesa_HashInsert(ctx->Shared->FrameBuffers, id, fb);
+ _mesa_HashInsert(ctx->Shared->FrameBuffers, id, fb, true);
}
/* Name doesn't exist */
else if (!fb) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
return NULL;
}
- _mesa_HashInsert(ctx->Shared->FrameBuffers, id, fb);
+ _mesa_HashInsert(ctx->Shared->FrameBuffers, id, fb, false);
}
return fb;
}
static struct gl_renderbuffer *
allocate_renderbuffer_locked(struct gl_context *ctx, GLuint renderbuffer,
+ bool isGenName,
const char *func)
{
struct gl_renderbuffer *newRb;
return NULL;
}
assert(newRb->AllocStorage);
- _mesa_HashInsertLocked(ctx->Shared->RenderBuffers, renderbuffer, newRb);
+ _mesa_HashInsertLocked(ctx->Shared->RenderBuffers, renderbuffer,
+ newRb, isGenName);
return newRb;
}
*/
if (renderbuffer) {
+ bool isGenName = false;
newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
if (newRb == &DummyRenderbuffer) {
/* ID was reserved, but no real renderbuffer object made yet */
newRb = NULL;
+ isGenName = true;
}
else if (!newRb && ctx->API == API_OPENGL_CORE) {
/* All RB IDs must be Gen'd */
if (!newRb) {
_mesa_HashLockMutex(ctx->Shared->RenderBuffers);
newRb = allocate_renderbuffer_locked(ctx, renderbuffer,
- "glBindRenderbufferEXT");
+ isGenName, "glBindRenderbufferEXT");
_mesa_HashUnlockMutex(ctx->Shared->RenderBuffers);
}
}
renderbuffers[i] = name;
if (dsa) {
- allocate_renderbuffer_locked(ctx, name, func);
+ allocate_renderbuffer_locked(ctx, name, true, func);
} else {
/* insert a dummy renderbuffer into the hash table */
_mesa_HashInsertLocked(ctx->Shared->RenderBuffers, name,
- &DummyRenderbuffer);
+ &DummyRenderbuffer, true);
}
}
struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
if (!rb || rb == &DummyRenderbuffer) {
_mesa_HashLockMutex(ctx->Shared->RenderBuffers);
- rb = allocate_renderbuffer_locked(ctx, renderbuffer, "glNamedRenderbufferStorageEXT");
+ rb = allocate_renderbuffer_locked(ctx, renderbuffer, rb != NULL,
+ "glNamedRenderbufferStorageEXT");
_mesa_HashUnlockMutex(ctx->Shared->RenderBuffers);
}
renderbuffer_storage(ctx, rb, internalformat, width, height, NO_SAMPLES,
struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
if (!rb || rb == &DummyRenderbuffer) {
_mesa_HashLockMutex(ctx->Shared->RenderBuffers);
- rb = allocate_renderbuffer_locked(ctx, renderbuffer,
+ rb = allocate_renderbuffer_locked(ctx, renderbuffer, rb != NULL,
"glNamedRenderbufferStorageMultisampleEXT");
_mesa_HashUnlockMutex(ctx->Shared->RenderBuffers);
}
struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
if (!rb || rb == &DummyRenderbuffer) {
_mesa_HashLockMutex(ctx->Shared->RenderBuffers);
- rb = allocate_renderbuffer_locked(ctx, renderbuffer, "glGetNamedRenderbufferParameterivEXT");
+ rb = allocate_renderbuffer_locked(ctx, renderbuffer, rb != NULL,
+ "glGetNamedRenderbufferParameterivEXT");
_mesa_HashUnlockMutex(ctx->Shared->RenderBuffers);
}
}
if (framebuffer) {
+ bool isGenName = false;
/* Binding a user-created framebuffer object */
newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer);
if (newDrawFb == &DummyFramebuffer) {
/* ID was reserved, but no real framebuffer object made yet */
newDrawFb = NULL;
+ isGenName = true;
}
else if (!newDrawFb && ctx->API == API_OPENGL_CORE) {
/* All FBO IDs must be Gen'd */
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT");
return;
}
- _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb);
+ _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb, isGenName);
}
newReadFb = newDrawFb;
}
else
fb = &DummyFramebuffer;
- _mesa_HashInsertLocked(ctx->Shared->FrameBuffers, name, fb);
+ _mesa_HashInsertLocked(ctx->Shared->FrameBuffers, name, fb, true);
}
_mesa_HashUnlockMutex(ctx->Shared->FrameBuffers);
/* Then, make sure it's initialized */
if (fb == &DummyFramebuffer) {
fb = ctx->Driver.NewFramebuffer(ctx, framebuffer);
- _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, fb);
+ _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, fb, true);
}
}
else
vao->Name = id;
_mesa_glthread_reset_vao(vao);
- _mesa_HashInsertLocked(glthread->VAOs, id, vao);
+ _mesa_HashInsertLocked(glthread->VAOs, id, vao, true);
}
}
* \param table the hash table.
* \param key the key (not zero).
* \param data pointer to user data.
+ * \param isGenName true if the key has been generated by a HashFindFreeKey* function
*/
void
-_mesa_HashInsertLocked(struct _mesa_HashTable *table, GLuint key, void *data)
+_mesa_HashInsertLocked(struct _mesa_HashTable *table, GLuint key, void *data,
+ GLboolean isGenName)
{
_mesa_HashInsert_unlocked(table, key, data);
}
* \param table the hash table.
* \param key the key (not zero).
* \param data pointer to user data.
+ * \param isGenName true if the key has been generated by a HashFindFreeKey* function
*/
void
-_mesa_HashInsert(struct _mesa_HashTable *table, GLuint key, void *data)
+_mesa_HashInsert(struct _mesa_HashTable *table, GLuint key, void *data,
+ GLboolean isGenName)
{
_mesa_HashLockMutex(table);
_mesa_HashInsert_unlocked(table, key, data);
extern void *_mesa_HashLookup(struct _mesa_HashTable *table, GLuint key);
-extern void _mesa_HashInsert(struct _mesa_HashTable *table, GLuint key, void *data);
+extern void _mesa_HashInsert(struct _mesa_HashTable *table, GLuint key, void *data,
+ GLboolean isGenName);
extern void _mesa_HashRemove(struct _mesa_HashTable *table, GLuint key);
extern void *_mesa_HashLookupLocked(struct _mesa_HashTable *table, GLuint key);
extern void _mesa_HashInsertLocked(struct _mesa_HashTable *table,
- GLuint key, void *data);
+ GLuint key, void *data, GLboolean isGenName);
extern void _mesa_HashRemoveLocked(struct _mesa_HashTable *table, GLuint key);
return;
}
monitors[i] = first + i;
- _mesa_HashInsert(ctx->PerfMonitor.Monitors, first + i, m);
+ _mesa_HashInsert(ctx->PerfMonitor.Monitors, first + i, m, true);
}
} else {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenPerfMonitorsAMD");
obj->Active = false;
obj->Ready = false;
- _mesa_HashInsert(ctx->PerfQuery.Objects, id, obj);
+ _mesa_HashInsert(ctx->PerfQuery.Objects, id, obj, true);
*queryHandle = id;
}
save_pipeline_object(struct gl_context *ctx, struct gl_pipeline_object *obj)
{
if (obj->Name > 0) {
- _mesa_HashInsertLocked(ctx->Pipeline.Objects, obj->Name, obj);
+ _mesa_HashInsertLocked(ctx->Pipeline.Objects, obj->Name, obj, true);
}
}
q->EverBound = GL_TRUE;
}
ids[i] = first + i;
- _mesa_HashInsertLocked(ctx->Query.QueryObjects, first + i, q);
+ _mesa_HashInsertLocked(ctx->Query.QueryObjects, first + i, q, true);
}
}
}
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBeginQuery{Indexed}");
return;
}
- _mesa_HashInsertLocked(ctx->Query.QueryObjects, id, q);
+ _mesa_HashInsertLocked(ctx->Query.QueryObjects, id, q, false);
}
}
else {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glQueryCounter");
return;
}
- _mesa_HashInsertLocked(ctx->Query.QueryObjects, id, q);
+ _mesa_HashInsertLocked(ctx->Query.QueryObjects, id, q, false);
}
else {
if (q->Target && q->Target != GL_TIMESTAMP) {
return;
}
- _mesa_HashInsertLocked(ctx->Shared->SamplerObjects, name, sampObj);
+ _mesa_HashInsertLocked(ctx->Shared->SamplerObjects, name, sampObj, true);
samplers[i] = name;
}
name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
sh = _mesa_new_shader(name, _mesa_shader_enum_to_shader_stage(type));
sh->Type = type;
- _mesa_HashInsertLocked(ctx->Shared->ShaderObjects, name, sh);
+ _mesa_HashInsertLocked(ctx->Shared->ShaderObjects, name, sh, true);
_mesa_HashUnlockMutex(ctx->Shared->ShaderObjects);
return name;
shProg = _mesa_new_shader_program(name);
- _mesa_HashInsertLocked(ctx->Shared->ShaderObjects, name, shProg);
+ _mesa_HashInsertLocked(ctx->Shared->ShaderObjects, name, shProg, true);
assert(shProg->RefCount == 1);
texObj = ctx->Shared->DefaultTex[targetIndex];
assert(texObj);
} else {
+ bool isGenName;
texObj = _mesa_lookup_texture(ctx, texture);
+ isGenName = texObj != NULL;
if (!texObj && ctx->API == API_OPENGL_CORE) {
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", caller);
return NULL;
}
/* insert into hash table */
- _mesa_HashInsert(ctx->Shared->TexObjects, texObj->Name, texObj);
+ _mesa_HashInsert(ctx->Shared->TexObjects, texObj->Name, texObj, isGenName);
}
if (texObj->Target != boundTarget) {
}
/* insert into hash table */
- _mesa_HashInsertLocked(ctx->Shared->TexObjects, texObj->Name, texObj);
+ _mesa_HashInsertLocked(ctx->Shared->TexObjects, texObj->Name, texObj, true);
textures[i] = name;
}
}
/* and insert it into hash table */
- _mesa_HashInsert(ctx->Shared->TexObjects, texName, newTexObj);
+ _mesa_HashInsert(ctx->Shared->TexObjects, texName, newTexObj, false);
}
}
}
ids[i] = first + i;
_mesa_HashInsertLocked(ctx->TransformFeedback.Objects, first + i,
- obj);
+ obj, true);
if (dsa) {
/* this is normally done at bind time in the non-dsa case */
obj->EverBound = GL_TRUE;