mesa: use _mesa_HashFindFreeKeys for GL functions

This allows to implement name reuse if we want to.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6600>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2020-08-17 15:12:03 +02:00
parent 60ffadcbc0
commit a56849ddda
11 changed files with 32 additions and 77 deletions

View file

@ -217,7 +217,6 @@ _mesa_DeleteProgramsARB(GLsizei n, const GLuint *ids)
void GLAPIENTRY void GLAPIENTRY
_mesa_GenProgramsARB(GLsizei n, GLuint *ids) _mesa_GenProgramsARB(GLsizei n, GLuint *ids)
{ {
GLuint first;
GLuint i; GLuint i;
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
@ -231,20 +230,15 @@ _mesa_GenProgramsARB(GLsizei n, GLuint *ids)
_mesa_HashLockMutex(ctx->Shared->Programs); _mesa_HashLockMutex(ctx->Shared->Programs);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, n); _mesa_HashFindFreeKeys(ctx->Shared->Programs, ids, n);
/* Insert pointer to dummy program as placeholder */ /* Insert pointer to dummy program as placeholder */
for (i = 0; i < (GLuint) n; i++) { for (i = 0; i < (GLuint) n; i++) {
_mesa_HashInsertLocked(ctx->Shared->Programs, first + i, _mesa_HashInsertLocked(ctx->Shared->Programs, ids[i],
&_mesa_DummyProgram, true); &_mesa_DummyProgram, true);
} }
_mesa_HashUnlockMutex(ctx->Shared->Programs); _mesa_HashUnlockMutex(ctx->Shared->Programs);
/* Return the program names */
for (i = 0; i < (GLuint) n; i++) {
ids[i] = first + i;
}
} }

View file

@ -1110,13 +1110,12 @@ static void
gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays, gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays,
bool create, const char *func) bool create, const char *func)
{ {
GLuint first;
GLint i; GLint i;
if (!arrays) if (!arrays)
return; return;
first = _mesa_HashFindFreeKeyBlock(ctx->Array.Objects, n); _mesa_HashFindFreeKeys(ctx->Array.Objects, arrays, n);
/* For the sake of simplicity we create the array objects in both /* For the sake of simplicity we create the array objects in both
* the Gen* and Create* cases. The only difference is the value of * the Gen* and Create* cases. The only difference is the value of
@ -1124,16 +1123,14 @@ gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays,
*/ */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
struct gl_vertex_array_object *obj; struct gl_vertex_array_object *obj;
GLuint name = first + i;
obj = _mesa_new_vao(ctx, name); obj = _mesa_new_vao(ctx, arrays[i]);
if (!obj) { if (!obj) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
return; return;
} }
obj->EverBound = create; obj->EverBound = create;
_mesa_HashInsertLocked(ctx->Array.Objects, obj->Name, obj, true); _mesa_HashInsertLocked(ctx->Array.Objects, obj->Name, obj, true);
arrays[i] = first + i;
} }
} }

View file

@ -1621,7 +1621,6 @@ _mesa_DeleteBuffers(GLsizei n, const GLuint *ids)
static void static void
create_buffers(struct gl_context *ctx, GLsizei n, GLuint *buffers, bool dsa) create_buffers(struct gl_context *ctx, GLsizei n, GLuint *buffers, bool dsa)
{ {
GLuint first;
struct gl_buffer_object *buf; struct gl_buffer_object *buf;
if (!buffers) if (!buffers)
@ -1632,14 +1631,13 @@ create_buffers(struct gl_context *ctx, GLsizei n, GLuint *buffers, bool dsa)
*/ */
_mesa_HashLockMutex(ctx->Shared->BufferObjects); _mesa_HashLockMutex(ctx->Shared->BufferObjects);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->BufferObjects, n); _mesa_HashFindFreeKeys(ctx->Shared->BufferObjects, buffers, n);
/* Insert the ID and pointer into the hash table. If non-DSA, insert a /* Insert the ID and pointer into the hash table. If non-DSA, insert a
* DummyBufferObject. Otherwise, create a new buffer object and insert * DummyBufferObject. Otherwise, create a new buffer object and insert
* it. * it.
*/ */
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
buffers[i] = first + i;
if (dsa) { if (dsa) {
assert(ctx->Driver.NewBufferObject); assert(ctx->Driver.NewBufferObject);
buf = ctx->Driver.NewBufferObject(ctx, buffers[i]); buf = ctx->Driver.NewBufferObject(ctx, buffers[i]);

View file

@ -164,13 +164,10 @@ _mesa_CreateMemoryObjectsEXT(GLsizei n, GLuint *memoryObjects)
return; return;
_mesa_HashLockMutex(ctx->Shared->MemoryObjects); _mesa_HashLockMutex(ctx->Shared->MemoryObjects);
GLuint first = _mesa_HashFindFreeKeyBlock(ctx->Shared->MemoryObjects, n); if (_mesa_HashFindFreeKeys(ctx->Shared->MemoryObjects, memoryObjects, n)) {
if (first) {
for (GLsizei i = 0; i < n; i++) { for (GLsizei i = 0; i < n; i++) {
struct gl_memory_object *memObj; struct gl_memory_object *memObj;
memoryObjects[i] = first + i;
/* allocate memory object */ /* allocate memory object */
memObj = ctx->Driver.NewMemoryObject(ctx, memoryObjects[i]); memObj = ctx->Driver.NewMemoryObject(ctx, memoryObjects[i]);
if (!memObj) { if (!memObj) {
@ -602,10 +599,8 @@ _mesa_GenSemaphoresEXT(GLsizei n, GLuint *semaphores)
return; return;
_mesa_HashLockMutex(ctx->Shared->SemaphoreObjects); _mesa_HashLockMutex(ctx->Shared->SemaphoreObjects);
GLuint first = _mesa_HashFindFreeKeyBlock(ctx->Shared->SemaphoreObjects, n); if (_mesa_HashFindFreeKeys(ctx->Shared->SemaphoreObjects, semaphores, n)) {
if (first) {
for (GLsizei i = 0; i < n; i++) { for (GLsizei i = 0; i < n; i++) {
semaphores[i] = first + i;
_mesa_HashInsertLocked(ctx->Shared->SemaphoreObjects, _mesa_HashInsertLocked(ctx->Shared->SemaphoreObjects,
semaphores[i], &DummySemaphoreObject, true); semaphores[i], &DummySemaphoreObject, true);
} }

View file

@ -2026,7 +2026,6 @@ create_render_buffers(struct gl_context *ctx, GLsizei n, GLuint *renderbuffers,
bool dsa) bool dsa)
{ {
const char *func = dsa ? "glCreateRenderbuffers" : "glGenRenderbuffers"; const char *func = dsa ? "glCreateRenderbuffers" : "glGenRenderbuffers";
GLuint first;
GLint i; GLint i;
if (!renderbuffers) if (!renderbuffers)
@ -2034,17 +2033,14 @@ create_render_buffers(struct gl_context *ctx, GLsizei n, GLuint *renderbuffers,
_mesa_HashLockMutex(ctx->Shared->RenderBuffers); _mesa_HashLockMutex(ctx->Shared->RenderBuffers);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n); _mesa_HashFindFreeKeys(ctx->Shared->RenderBuffers, renderbuffers, n);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
GLuint name = first + i;
renderbuffers[i] = name;
if (dsa) { if (dsa) {
allocate_renderbuffer_locked(ctx, name, true, func); allocate_renderbuffer_locked(ctx, renderbuffers[i], true, func);
} else { } else {
/* insert a dummy renderbuffer into the hash table */ /* insert a dummy renderbuffer into the hash table */
_mesa_HashInsertLocked(ctx->Shared->RenderBuffers, name, _mesa_HashInsertLocked(ctx->Shared->RenderBuffers, renderbuffers[i],
&DummyRenderbuffer, true); &DummyRenderbuffer, true);
} }
} }
@ -3211,7 +3207,6 @@ static void
create_framebuffers(GLsizei n, GLuint *framebuffers, bool dsa) create_framebuffers(GLsizei n, GLuint *framebuffers, bool dsa)
{ {
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
GLuint first;
GLint i; GLint i;
struct gl_framebuffer *fb; struct gl_framebuffer *fb;
@ -3227,12 +3222,9 @@ create_framebuffers(GLsizei n, GLuint *framebuffers, bool dsa)
_mesa_HashLockMutex(ctx->Shared->FrameBuffers); _mesa_HashLockMutex(ctx->Shared->FrameBuffers);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n); _mesa_HashFindFreeKeys(ctx->Shared->FrameBuffers, framebuffers, n);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
GLuint name = first + i;
framebuffers[i] = name;
if (dsa) { if (dsa) {
fb = ctx->Driver.NewFramebuffer(ctx, framebuffers[i]); fb = ctx->Driver.NewFramebuffer(ctx, framebuffers[i]);
if (!fb) { if (!fb) {
@ -3244,7 +3236,8 @@ create_framebuffers(GLsizei n, GLuint *framebuffers, bool dsa)
else else
fb = &DummyFramebuffer; fb = &DummyFramebuffer;
_mesa_HashInsertLocked(ctx->Shared->FrameBuffers, name, fb, true); _mesa_HashInsertLocked(ctx->Shared->FrameBuffers, framebuffers[i],
fb, true);
} }
_mesa_HashUnlockMutex(ctx->Shared->FrameBuffers); _mesa_HashUnlockMutex(ctx->Shared->FrameBuffers);

View file

@ -338,7 +338,6 @@ _mesa_GetPerfMonitorCounterInfoAMD(GLuint group, GLuint counter, GLenum pname,
void GLAPIENTRY void GLAPIENTRY
_mesa_GenPerfMonitorsAMD(GLsizei n, GLuint *monitors) _mesa_GenPerfMonitorsAMD(GLsizei n, GLuint *monitors)
{ {
GLuint first;
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
if (MESA_VERBOSE & VERBOSE_API) if (MESA_VERBOSE & VERBOSE_API)
@ -354,21 +353,16 @@ _mesa_GenPerfMonitorsAMD(GLsizei n, GLuint *monitors)
if (monitors == NULL) if (monitors == NULL)
return; return;
/* We don't actually need them to be contiguous, but this is what if (_mesa_HashFindFreeKeys(ctx->PerfMonitor.Monitors, monitors, n)) {
* the rest of Mesa does, so we may as well.
*/
first = _mesa_HashFindFreeKeyBlock(ctx->PerfMonitor.Monitors, n);
if (first) {
GLsizei i; GLsizei i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
struct gl_perf_monitor_object *m = struct gl_perf_monitor_object *m =
new_performance_monitor(ctx, first + i); new_performance_monitor(ctx, monitors[i]);
if (!m) { if (!m) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenPerfMonitorsAMD"); _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenPerfMonitorsAMD");
return; return;
} }
monitors[i] = first + i; _mesa_HashInsert(ctx->PerfMonitor.Monitors, monitors[i], m, true);
_mesa_HashInsert(ctx->PerfMonitor.Monitors, first + i, m, true);
} }
} else { } else {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenPerfMonitorsAMD"); _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenPerfMonitorsAMD");

View file

@ -596,19 +596,17 @@ create_program_pipelines(struct gl_context *ctx, GLsizei n, GLuint *pipelines,
bool dsa) bool dsa)
{ {
const char *func = dsa ? "glCreateProgramPipelines" : "glGenProgramPipelines"; const char *func = dsa ? "glCreateProgramPipelines" : "glGenProgramPipelines";
GLuint first;
GLint i; GLint i;
if (!pipelines) if (!pipelines)
return; return;
first = _mesa_HashFindFreeKeyBlock(ctx->Pipeline.Objects, n); _mesa_HashFindFreeKeys(ctx->Pipeline.Objects, pipelines, n);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
struct gl_pipeline_object *obj; struct gl_pipeline_object *obj;
GLuint name = first + i;
obj = _mesa_new_pipeline_object(ctx, name); obj = _mesa_new_pipeline_object(ctx, pipelines[i]);
if (!obj) { if (!obj) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
return; return;
@ -620,7 +618,6 @@ create_program_pipelines(struct gl_context *ctx, GLsizei n, GLuint *pipelines,
} }
save_pipeline_object(ctx, obj); save_pipeline_object(ctx, obj);
pipelines[i] = first + i;
} }
} }

View file

@ -262,7 +262,6 @@ create_queries(struct gl_context *ctx, GLenum target, GLsizei n, GLuint *ids,
bool dsa) bool dsa)
{ {
const char *func = dsa ? "glGenQueries" : "glCreateQueries"; const char *func = dsa ? "glGenQueries" : "glCreateQueries";
GLuint first;
if (MESA_VERBOSE & VERBOSE_API) if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "%s(%d)\n", func, n); _mesa_debug(ctx, "%s(%d)\n", func, n);
@ -272,12 +271,11 @@ create_queries(struct gl_context *ctx, GLenum target, GLsizei n, GLuint *ids,
return; return;
} }
first = _mesa_HashFindFreeKeyBlock(ctx->Query.QueryObjects, n); if (_mesa_HashFindFreeKeys(ctx->Query.QueryObjects, ids, n)) {
if (first) {
GLsizei i; GLsizei i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
struct gl_query_object *q struct gl_query_object *q
= ctx->Driver.NewQueryObject(ctx, first + i); = ctx->Driver.NewQueryObject(ctx, ids[i]);
if (!q) { if (!q) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
return; return;
@ -286,8 +284,7 @@ create_queries(struct gl_context *ctx, GLenum target, GLsizei n, GLuint *ids,
q->Target = target; q->Target = target;
q->EverBound = GL_TRUE; q->EverBound = GL_TRUE;
} }
ids[i] = first + i; _mesa_HashInsertLocked(ctx->Query.QueryObjects, ids[i], q, true);
_mesa_HashInsertLocked(ctx->Query.QueryObjects, first + i, q, true);
} }
} }
} }

View file

@ -157,7 +157,6 @@ static void
create_samplers(struct gl_context *ctx, GLsizei count, GLuint *samplers, create_samplers(struct gl_context *ctx, GLsizei count, GLuint *samplers,
const char *caller) const char *caller)
{ {
GLuint first;
GLint i; GLint i;
if (!samplers) if (!samplers)
@ -165,22 +164,21 @@ create_samplers(struct gl_context *ctx, GLsizei count, GLuint *samplers,
_mesa_HashLockMutex(ctx->Shared->SamplerObjects); _mesa_HashLockMutex(ctx->Shared->SamplerObjects);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->SamplerObjects, count); _mesa_HashFindFreeKeys(ctx->Shared->SamplerObjects, samplers, count);
/* Insert the ID and pointer to new sampler object into hash table */ /* Insert the ID and pointer to new sampler object into hash table */
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
struct gl_sampler_object *sampObj; struct gl_sampler_object *sampObj;
GLuint name = first + i;
sampObj = ctx->Driver.NewSamplerObject(ctx, name); sampObj = ctx->Driver.NewSamplerObject(ctx, samplers[i]);
if (!sampObj) { if (!sampObj) {
_mesa_HashUnlockMutex(ctx->Shared->SamplerObjects); _mesa_HashUnlockMutex(ctx->Shared->SamplerObjects);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller); _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
return; return;
} }
_mesa_HashInsertLocked(ctx->Shared->SamplerObjects, name, sampObj, true); _mesa_HashInsertLocked(ctx->Shared->SamplerObjects, samplers[i],
samplers[i] = name; sampObj, true);
} }
_mesa_HashUnlockMutex(ctx->Shared->SamplerObjects); _mesa_HashUnlockMutex(ctx->Shared->SamplerObjects);

View file

@ -1212,7 +1212,6 @@ static void
create_textures(struct gl_context *ctx, GLenum target, create_textures(struct gl_context *ctx, GLenum target,
GLsizei n, GLuint *textures, const char *caller) GLsizei n, GLuint *textures, const char *caller)
{ {
GLuint first;
GLint i; GLint i;
if (!textures) if (!textures)
@ -1223,13 +1222,12 @@ create_textures(struct gl_context *ctx, GLenum target,
*/ */
_mesa_HashLockMutex(ctx->Shared->TexObjects); _mesa_HashLockMutex(ctx->Shared->TexObjects);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n); _mesa_HashFindFreeKeys(ctx->Shared->TexObjects, textures, n);
/* Allocate new, empty texture objects */ /* Allocate new, empty texture objects */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
struct gl_texture_object *texObj; struct gl_texture_object *texObj;
GLuint name = first + i; texObj = ctx->Driver.NewTextureObject(ctx, textures[i], target);
texObj = ctx->Driver.NewTextureObject(ctx, name, target);
if (!texObj) { if (!texObj) {
_mesa_HashUnlockMutex(ctx->Shared->TexObjects); _mesa_HashUnlockMutex(ctx->Shared->TexObjects);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller); _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
@ -1238,8 +1236,6 @@ create_textures(struct gl_context *ctx, GLenum target,
/* insert into hash table */ /* insert into hash table */
_mesa_HashInsertLocked(ctx->Shared->TexObjects, texObj->Name, texObj, true); _mesa_HashInsertLocked(ctx->Shared->TexObjects, texObj->Name, texObj, true);
textures[i] = name;
} }
_mesa_HashUnlockMutex(ctx->Shared->TexObjects); _mesa_HashUnlockMutex(ctx->Shared->TexObjects);
@ -1277,7 +1273,7 @@ create_textures_err(struct gl_context *ctx, GLenum target,
* *
* \sa glGenTextures(), glCreateTextures(). * \sa glGenTextures(), glCreateTextures().
* *
* Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture * Calls _mesa_HashFindFreeKeys() to find a block of free texture
* IDs which are stored in \p textures. Corresponding empty texture * IDs which are stored in \p textures. Corresponding empty texture
* objects are also generated. * objects are also generated.
*/ */
@ -1305,7 +1301,7 @@ _mesa_GenTextures(GLsizei n, GLuint *textures)
* *
* \sa glCreateTextures(), glGenTextures(). * \sa glCreateTextures(), glGenTextures().
* *
* Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture * Calls _mesa_HashFindFreeKeys() to find a block of free texture
* IDs which are stored in \p textures. Corresponding empty texture * IDs which are stored in \p textures. Corresponding empty texture
* objects are also generated. * objects are also generated.
*/ */

View file

@ -1054,7 +1054,6 @@ static void
create_transform_feedbacks(struct gl_context *ctx, GLsizei n, GLuint *ids, create_transform_feedbacks(struct gl_context *ctx, GLsizei n, GLuint *ids,
bool dsa) bool dsa)
{ {
GLuint first;
const char* func; const char* func;
if (dsa) if (dsa)
@ -1070,19 +1069,16 @@ create_transform_feedbacks(struct gl_context *ctx, GLsizei n, GLuint *ids,
if (!ids) if (!ids)
return; return;
/* we don't need contiguous IDs, but this might be faster */ if (_mesa_HashFindFreeKeys(ctx->TransformFeedback.Objects, ids, n)) {
first = _mesa_HashFindFreeKeyBlock(ctx->TransformFeedback.Objects, n);
if (first) {
GLsizei i; GLsizei i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
struct gl_transform_feedback_object *obj struct gl_transform_feedback_object *obj
= ctx->Driver.NewTransformFeedback(ctx, first + i); = ctx->Driver.NewTransformFeedback(ctx, ids[i]);
if (!obj) { if (!obj) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
return; return;
} }
ids[i] = first + i; _mesa_HashInsertLocked(ctx->TransformFeedback.Objects, ids[i],
_mesa_HashInsertLocked(ctx->TransformFeedback.Objects, first + i,
obj, true); obj, true);
if (dsa) { if (dsa) {
/* this is normally done at bind time in the non-dsa case */ /* this is normally done at bind time in the non-dsa case */