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
_mesa_GenProgramsARB(GLsizei n, GLuint *ids)
{
GLuint first;
GLuint i;
GET_CURRENT_CONTEXT(ctx);
@ -231,20 +230,15 @@ _mesa_GenProgramsARB(GLsizei n, GLuint *ids)
_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 */
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_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,
bool create, const char *func)
{
GLuint first;
GLint i;
if (!arrays)
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
* 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++) {
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) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
return;
}
obj->EverBound = create;
_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
create_buffers(struct gl_context *ctx, GLsizei n, GLuint *buffers, bool dsa)
{
GLuint first;
struct gl_buffer_object *buf;
if (!buffers)
@ -1632,14 +1631,13 @@ create_buffers(struct gl_context *ctx, GLsizei n, GLuint *buffers, bool dsa)
*/
_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
* DummyBufferObject. Otherwise, create a new buffer object and insert
* it.
*/
for (int i = 0; i < n; i++) {
buffers[i] = first + i;
if (dsa) {
assert(ctx->Driver.NewBufferObject);
buf = ctx->Driver.NewBufferObject(ctx, buffers[i]);

View file

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

View file

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

View file

@ -338,7 +338,6 @@ _mesa_GetPerfMonitorCounterInfoAMD(GLuint group, GLuint counter, GLenum pname,
void GLAPIENTRY
_mesa_GenPerfMonitorsAMD(GLsizei n, GLuint *monitors)
{
GLuint first;
GET_CURRENT_CONTEXT(ctx);
if (MESA_VERBOSE & VERBOSE_API)
@ -354,21 +353,16 @@ _mesa_GenPerfMonitorsAMD(GLsizei n, GLuint *monitors)
if (monitors == NULL)
return;
/* We don't actually need them to be contiguous, but this is what
* the rest of Mesa does, so we may as well.
*/
first = _mesa_HashFindFreeKeyBlock(ctx->PerfMonitor.Monitors, n);
if (first) {
if (_mesa_HashFindFreeKeys(ctx->PerfMonitor.Monitors, monitors, n)) {
GLsizei i;
for (i = 0; i < n; i++) {
struct gl_perf_monitor_object *m =
new_performance_monitor(ctx, first + i);
new_performance_monitor(ctx, monitors[i]);
if (!m) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenPerfMonitorsAMD");
return;
}
monitors[i] = first + i;
_mesa_HashInsert(ctx->PerfMonitor.Monitors, first + i, m, true);
_mesa_HashInsert(ctx->PerfMonitor.Monitors, monitors[i], m, true);
}
} else {
_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)
{
const char *func = dsa ? "glCreateProgramPipelines" : "glGenProgramPipelines";
GLuint first;
GLint i;
if (!pipelines)
return;
first = _mesa_HashFindFreeKeyBlock(ctx->Pipeline.Objects, n);
_mesa_HashFindFreeKeys(ctx->Pipeline.Objects, pipelines, n);
for (i = 0; i < n; i++) {
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) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
return;
@ -620,7 +618,6 @@ create_program_pipelines(struct gl_context *ctx, GLsizei n, GLuint *pipelines,
}
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)
{
const char *func = dsa ? "glGenQueries" : "glCreateQueries";
GLuint first;
if (MESA_VERBOSE & VERBOSE_API)
_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;
}
first = _mesa_HashFindFreeKeyBlock(ctx->Query.QueryObjects, n);
if (first) {
if (_mesa_HashFindFreeKeys(ctx->Query.QueryObjects, ids, n)) {
GLsizei i;
for (i = 0; i < n; i++) {
struct gl_query_object *q
= ctx->Driver.NewQueryObject(ctx, first + i);
= ctx->Driver.NewQueryObject(ctx, ids[i]);
if (!q) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
return;
@ -286,8 +284,7 @@ create_queries(struct gl_context *ctx, GLenum target, GLsizei n, GLuint *ids,
q->Target = target;
q->EverBound = GL_TRUE;
}
ids[i] = first + i;
_mesa_HashInsertLocked(ctx->Query.QueryObjects, first + i, q, true);
_mesa_HashInsertLocked(ctx->Query.QueryObjects, ids[i], q, true);
}
}
}

View file

@ -157,7 +157,6 @@ static void
create_samplers(struct gl_context *ctx, GLsizei count, GLuint *samplers,
const char *caller)
{
GLuint first;
GLint i;
if (!samplers)
@ -165,22 +164,21 @@ create_samplers(struct gl_context *ctx, GLsizei count, GLuint *samplers,
_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 */
for (i = 0; i < count; i++) {
struct gl_sampler_object *sampObj;
GLuint name = first + i;
sampObj = ctx->Driver.NewSamplerObject(ctx, name);
sampObj = ctx->Driver.NewSamplerObject(ctx, samplers[i]);
if (!sampObj) {
_mesa_HashUnlockMutex(ctx->Shared->SamplerObjects);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
return;
}
_mesa_HashInsertLocked(ctx->Shared->SamplerObjects, name, sampObj, true);
samplers[i] = name;
_mesa_HashInsertLocked(ctx->Shared->SamplerObjects, samplers[i],
sampObj, true);
}
_mesa_HashUnlockMutex(ctx->Shared->SamplerObjects);

View file

@ -1212,7 +1212,6 @@ static void
create_textures(struct gl_context *ctx, GLenum target,
GLsizei n, GLuint *textures, const char *caller)
{
GLuint first;
GLint i;
if (!textures)
@ -1223,13 +1222,12 @@ create_textures(struct gl_context *ctx, GLenum target,
*/
_mesa_HashLockMutex(ctx->Shared->TexObjects);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
_mesa_HashFindFreeKeys(ctx->Shared->TexObjects, textures, n);
/* Allocate new, empty texture objects */
for (i = 0; i < n; i++) {
struct gl_texture_object *texObj;
GLuint name = first + i;
texObj = ctx->Driver.NewTextureObject(ctx, name, target);
texObj = ctx->Driver.NewTextureObject(ctx, textures[i], target);
if (!texObj) {
_mesa_HashUnlockMutex(ctx->Shared->TexObjects);
_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 */
_mesa_HashInsertLocked(ctx->Shared->TexObjects, texObj->Name, texObj, true);
textures[i] = name;
}
_mesa_HashUnlockMutex(ctx->Shared->TexObjects);
@ -1277,7 +1273,7 @@ create_textures_err(struct gl_context *ctx, GLenum target,
*
* \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
* objects are also generated.
*/
@ -1305,7 +1301,7 @@ _mesa_GenTextures(GLsizei n, GLuint *textures)
*
* \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
* objects are also generated.
*/

View file

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