mesa: rework enablement of force_gl_names_reuse

force_gl_names_reuse is changed to integer.
 -1 means default (currently disabled), 0 means disabled, 1 means enabled

The names reuse initialization is moved to _mesa_alloc_shared_state ->
_mesa_InitHashTable instead of _mesa_HashEnableNameReuse.

It will be enabled by default.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32715>
This commit is contained in:
Marek Olšák 2024-12-19 02:09:48 -05:00 committed by Marge Bot
parent 06423b1792
commit b15c8fe3f1
22 changed files with 43 additions and 69 deletions

View file

@ -41,7 +41,7 @@ DRI_CONF_SECTION_DEBUG
DRI_CONF_GLTHREAD_NOP_CHECK_FRAMEBUFFER_STATUS(false) DRI_CONF_GLTHREAD_NOP_CHECK_FRAMEBUFFER_STATUS(false)
DRI_CONF_FORCE_COMPAT_PROFILE(false) DRI_CONF_FORCE_COMPAT_PROFILE(false)
DRI_CONF_FORCE_COMPAT_SHADERS(false) DRI_CONF_FORCE_COMPAT_SHADERS(false)
DRI_CONF_FORCE_GL_NAMES_REUSE(false) DRI_CONF_FORCE_GL_NAMES_REUSE()
DRI_CONF_FORCE_GL_MAP_BUFFER_SYNCHRONIZED(false) DRI_CONF_FORCE_GL_MAP_BUFFER_SYNCHRONIZED(false)
DRI_CONF_TRANSCODE_ETC(false) DRI_CONF_TRANSCODE_ETC(false)
DRI_CONF_TRANSCODE_ASTC(false) DRI_CONF_TRANSCODE_ASTC(false)

View file

@ -67,7 +67,7 @@ u_driconf_fill_st_options(struct st_config_options *options,
query_bool_option(glthread_nop_check_framebuffer_status); query_bool_option(glthread_nop_check_framebuffer_status);
query_bool_option(ignore_map_unsynchronized); query_bool_option(ignore_map_unsynchronized);
query_bool_option(ignore_discard_framebuffer); query_bool_option(ignore_discard_framebuffer);
query_bool_option(force_gl_names_reuse); query_int_option(reuse_gl_names);
query_bool_option(force_gl_map_buffer_synchronized); query_bool_option(force_gl_map_buffer_synchronized);
query_bool_option(transcode_etc); query_bool_option(transcode_etc);
query_bool_option(transcode_astc); query_bool_option(transcode_astc);

View file

@ -196,7 +196,7 @@ struct st_config_options
bool ignore_map_unsynchronized; bool ignore_map_unsynchronized;
bool ignore_discard_framebuffer; bool ignore_discard_framebuffer;
bool force_integer_tex_nearest; bool force_integer_tex_nearest;
bool force_gl_names_reuse; int reuse_gl_names;
bool force_gl_map_buffer_synchronized; bool force_gl_map_buffer_synchronized;
bool transcode_etc; bool transcode_etc;
bool transcode_astc; bool transcode_astc;

View file

@ -666,11 +666,6 @@ struct gl_constants
*/ */
GLchar GLSLZeroInit; GLchar GLSLZeroInit;
/**
* Force GL names reuse. Needed by SPECviewperf13.
*/
GLboolean ForceGLNamesReuse;
/** /**
* Treat integer textures using GL_LINEAR filters as GL_NEAREST. * Treat integer textures using GL_LINEAR filters as GL_NEAREST.
*/ */

View file

@ -976,7 +976,8 @@ _mesa_initialize_context(struct gl_context *ctx,
bool no_error, bool no_error,
const struct gl_config *visual, const struct gl_config *visual,
struct gl_context *share_list, struct gl_context *share_list,
const struct dd_function_table *driverFunctions) const struct dd_function_table *driverFunctions,
const struct st_config_options *options)
{ {
struct gl_shared_state *shared; struct gl_shared_state *shared;
int i; int i;
@ -1032,7 +1033,7 @@ _mesa_initialize_context(struct gl_context *ctx,
} }
else { else {
/* allocate new, unshared state */ /* allocate new, unshared state */
shared = _mesa_alloc_shared_state(ctx); shared = _mesa_alloc_shared_state(ctx, options);
if (!shared) if (!shared)
return GL_FALSE; return GL_FALSE;
} }

View file

@ -76,7 +76,8 @@ _mesa_initialize_context( struct gl_context *ctx,
bool no_error, bool no_error,
const struct gl_config *visual, const struct gl_config *visual,
struct gl_context *share_list, struct gl_context *share_list,
const struct dd_function_table *driverFunctions); const struct dd_function_table *driverFunctions,
const struct st_config_options *options);
extern struct _glapi_table * extern struct _glapi_table *
_mesa_alloc_dispatch_table(bool glthread); _mesa_alloc_dispatch_table(bool glthread);

View file

@ -223,7 +223,7 @@ _mesa_glthread_init(struct gl_context *ctx)
return; return;
} }
_mesa_InitHashTable(&glthread->VAOs); _mesa_InitHashTable(&glthread->VAOs, ctx->Shared->ReuseGLNames);
_mesa_glthread_reset_vao(&glthread->DefaultVAO); _mesa_glthread_reset_vao(&glthread->DefaultVAO);
glthread->CurrentVAO = &glthread->DefaultVAO; glthread->CurrentVAO = &glthread->DefaultVAO;

View file

@ -45,7 +45,7 @@
* Initialize a hash table. * Initialize a hash table.
*/ */
void void
_mesa_InitHashTable(struct _mesa_HashTable *table) _mesa_InitHashTable(struct _mesa_HashTable *table, bool enable_reuse)
{ {
memset(table, 0, sizeof(*table)); memset(table, 0, sizeof(*table));
util_sparse_array_init(&table->array, sizeof(void*), 1024); util_sparse_array_init(&table->array, sizeof(void*), 1024);
@ -53,6 +53,7 @@ _mesa_InitHashTable(struct _mesa_HashTable *table)
/* Mark ID = 0 as used, so that we don't return it. */ /* Mark ID = 0 as used, so that we don't return it. */
util_idalloc_sparse_reserve(&table->id_alloc, 0); util_idalloc_sparse_reserve(&table->id_alloc, 0);
simple_mtx_init(&table->Mutex, mtx_plain); simple_mtx_init(&table->Mutex, mtx_plain);
table->alloc_via_idalloc = enable_reuse;
} }
/** /**
@ -86,14 +87,6 @@ _mesa_DeinitHashTable(struct _mesa_HashTable *table,
simple_mtx_destroy(&table->Mutex); simple_mtx_destroy(&table->Mutex);
} }
void
_mesa_HashEnableNameReuse(struct _mesa_HashTable *table)
{
_mesa_HashLockMutex(table);
table->alloc_via_idalloc = true;
_mesa_HashUnlockMutex(table);
}
/** /**
* Insert a key/pointer pair into the hash table without locking the mutex. * Insert a key/pointer pair into the hash table without locking the mutex.
* If an entry with this key already exists we'll replace the existing entry. * If an entry with this key already exists we'll replace the existing entry.

View file

@ -54,7 +54,7 @@ struct _mesa_HashTable {
}; };
void void
_mesa_InitHashTable(struct _mesa_HashTable *table); _mesa_InitHashTable(struct _mesa_HashTable *table, bool enable_reuse);
void void
_mesa_DeinitHashTable(struct _mesa_HashTable *table, _mesa_DeinitHashTable(struct _mesa_HashTable *table,
@ -90,9 +90,6 @@ bool
_mesa_HashFindFreeKeys(struct _mesa_HashTable *table, GLuint* keys, _mesa_HashFindFreeKeys(struct _mesa_HashTable *table, GLuint* keys,
GLuint numKeys); GLuint numKeys);
void
_mesa_HashEnableNameReuse(struct _mesa_HashTable *table);
/* Inline functions. */ /* Inline functions. */
/** /**

View file

@ -2392,6 +2392,9 @@ struct gl_shared_state
GLint RefCount; /**< Reference count */ GLint RefCount; /**< Reference count */
bool DisplayListsAffectGLThread; bool DisplayListsAffectGLThread;
/* Whether the next glGen returns the lowest unused GL ID. */
bool ReuseGLNames;
struct _mesa_HashTable DisplayList; /**< Display lists hash table */ struct _mesa_HashTable DisplayList; /**< Display lists hash table */
struct _mesa_HashTable TexObjects; /**< Texture objects hash table */ struct _mesa_HashTable TexObjects; /**< Texture objects hash table */

View file

@ -57,7 +57,7 @@
void void
_mesa_init_performance_monitors(struct gl_context *ctx) _mesa_init_performance_monitors(struct gl_context *ctx)
{ {
_mesa_InitHashTable(&ctx->PerfMonitor.Monitors); _mesa_InitHashTable(&ctx->PerfMonitor.Monitors, ctx->Shared->ReuseGLNames);
ctx->PerfMonitor.NumGroups = 0; ctx->PerfMonitor.NumGroups = 0;
ctx->PerfMonitor.Groups = NULL; ctx->PerfMonitor.Groups = NULL;
} }

View file

@ -44,7 +44,7 @@
void void
_mesa_init_performance_queries(struct gl_context *ctx) _mesa_init_performance_queries(struct gl_context *ctx)
{ {
_mesa_InitHashTable(&ctx->PerfQuery.Objects); _mesa_InitHashTable(&ctx->PerfQuery.Objects, ctx->Shared->ReuseGLNames);
} }
static void static void

View file

@ -93,7 +93,7 @@ _mesa_new_pipeline_object(struct gl_context *ctx, GLuint name)
void void
_mesa_init_pipeline(struct gl_context *ctx) _mesa_init_pipeline(struct gl_context *ctx)
{ {
_mesa_InitHashTable(&ctx->Pipeline.Objects); _mesa_InitHashTable(&ctx->Pipeline.Objects, ctx->Shared->ReuseGLNames);
ctx->Pipeline.Current = NULL; ctx->Pipeline.Current = NULL;

View file

@ -1342,7 +1342,7 @@ _mesa_init_queryobj(struct gl_context *ctx)
{ {
struct pipe_screen *screen = ctx->pipe->screen; struct pipe_screen *screen = ctx->pipe->screen;
_mesa_InitHashTable(&ctx->Query.QueryObjects); _mesa_InitHashTable(&ctx->Query.QueryObjects, ctx->Shared->ReuseGLNames);
ctx->Query.CurrentOcclusionObject = NULL; ctx->Query.CurrentOcclusionObject = NULL;
if (screen->get_param(screen, PIPE_CAP_OCCLUSION_QUERY)) if (screen->get_param(screen, PIPE_CAP_OCCLUSION_QUERY))

View file

@ -60,7 +60,8 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared);
* failure. * failure.
*/ */
struct gl_shared_state * struct gl_shared_state *
_mesa_alloc_shared_state(struct gl_context *ctx) _mesa_alloc_shared_state(struct gl_context *ctx,
const struct st_config_options *options)
{ {
struct gl_shared_state *shared; struct gl_shared_state *shared;
GLuint i; GLuint i;
@ -70,27 +71,28 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
return NULL; return NULL;
simple_mtx_init(&shared->Mutex, mtx_plain); simple_mtx_init(&shared->Mutex, mtx_plain);
shared->ReuseGLNames = options->reuse_gl_names == 1;
_mesa_InitHashTable(&shared->DisplayList); _mesa_InitHashTable(&shared->DisplayList, shared->ReuseGLNames);
_mesa_InitHashTable(&shared->TexObjects); _mesa_InitHashTable(&shared->TexObjects, shared->ReuseGLNames);
_mesa_InitHashTable(&shared->Programs); _mesa_InitHashTable(&shared->Programs, shared->ReuseGLNames);
shared->DefaultVertexProgram = shared->DefaultVertexProgram =
ctx->Driver.NewProgram(ctx, MESA_SHADER_VERTEX, 0, true); ctx->Driver.NewProgram(ctx, MESA_SHADER_VERTEX, 0, true);
shared->DefaultFragmentProgram = shared->DefaultFragmentProgram =
ctx->Driver.NewProgram(ctx, MESA_SHADER_FRAGMENT, 0, true); ctx->Driver.NewProgram(ctx, MESA_SHADER_FRAGMENT, 0, true);
_mesa_InitHashTable(&shared->ATIShaders); _mesa_InitHashTable(&shared->ATIShaders, shared->ReuseGLNames);
shared->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0); shared->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0);
_mesa_InitHashTable(&shared->ShaderObjects); _mesa_InitHashTable(&shared->ShaderObjects, shared->ReuseGLNames);
_mesa_InitHashTable(&shared->BufferObjects); _mesa_InitHashTable(&shared->BufferObjects, shared->ReuseGLNames);
shared->ZombieBufferObjects = _mesa_set_create(NULL, _mesa_hash_pointer, shared->ZombieBufferObjects = _mesa_set_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal); _mesa_key_pointer_equal);
/* GL_ARB_sampler_objects */ /* GL_ARB_sampler_objects */
_mesa_InitHashTable(&shared->SamplerObjects); _mesa_InitHashTable(&shared->SamplerObjects, shared->ReuseGLNames);
/* GL_ARB_bindless_texture */ /* GL_ARB_bindless_texture */
_mesa_init_shared_handles(shared); _mesa_init_shared_handles(shared);
@ -132,14 +134,14 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
simple_mtx_init(&shared->TexMutex, mtx_plain); simple_mtx_init(&shared->TexMutex, mtx_plain);
shared->TextureStateStamp = 0; shared->TextureStateStamp = 0;
_mesa_InitHashTable(&shared->FrameBuffers); _mesa_InitHashTable(&shared->FrameBuffers, shared->ReuseGLNames);
_mesa_InitHashTable(&shared->RenderBuffers); _mesa_InitHashTable(&shared->RenderBuffers, shared->ReuseGLNames);
shared->SyncObjects = _mesa_set_create(NULL, _mesa_hash_pointer, shared->SyncObjects = _mesa_set_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal); _mesa_key_pointer_equal);
_mesa_InitHashTable(&shared->MemoryObjects); _mesa_InitHashTable(&shared->MemoryObjects, shared->ReuseGLNames);
_mesa_InitHashTable(&shared->SemaphoreObjects); _mesa_InitHashTable(&shared->SemaphoreObjects, shared->ReuseGLNames);
shared->GLThread.NoLockDuration = ONE_SECOND_IN_NS; shared->GLThread.NoLockDuration = ONE_SECOND_IN_NS;

View file

@ -34,7 +34,8 @@ _mesa_reference_shared_state(struct gl_context *ctx,
struct gl_shared_state * struct gl_shared_state *
_mesa_alloc_shared_state(struct gl_context *ctx); _mesa_alloc_shared_state(struct gl_context *ctx,
const struct st_config_options *options);
#endif #endif

View file

@ -182,7 +182,7 @@ _mesa_init_transform_feedback(struct gl_context *ctx)
assert(ctx->TransformFeedback.DefaultObject->RefCount == 2); assert(ctx->TransformFeedback.DefaultObject->RefCount == 2);
_mesa_InitHashTable(&ctx->TransformFeedback.Objects); _mesa_InitHashTable(&ctx->TransformFeedback.Objects, ctx->Shared->ReuseGLNames);
_mesa_reference_buffer_object(ctx, _mesa_reference_buffer_object(ctx,
&ctx->TransformFeedback.CurrentBuffer, NULL); &ctx->TransformFeedback.CurrentBuffer, NULL);

View file

@ -4169,7 +4169,7 @@ _mesa_init_varray(struct gl_context *ctx)
_mesa_set_draw_vao(ctx, ctx->Array.VAO); _mesa_set_draw_vao(ctx, ctx->Array.VAO);
ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */ ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
_mesa_InitHashTable(&ctx->Array.Objects); _mesa_InitHashTable(&ctx->Array.Objects, ctx->Shared->ReuseGLNames);
} }

View file

@ -725,24 +725,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
st->bitmap.cache.empty = true; st->bitmap.cache.empty = true;
if (ctx->Const.ForceGLNamesReuse && ctx->Shared->RefCount == 1) {
_mesa_HashEnableNameReuse(&ctx->Shared->TexObjects);
_mesa_HashEnableNameReuse(&ctx->Shared->ShaderObjects);
_mesa_HashEnableNameReuse(&ctx->Shared->BufferObjects);
_mesa_HashEnableNameReuse(&ctx->Shared->SamplerObjects);
_mesa_HashEnableNameReuse(&ctx->Shared->FrameBuffers);
_mesa_HashEnableNameReuse(&ctx->Shared->RenderBuffers);
_mesa_HashEnableNameReuse(&ctx->Shared->MemoryObjects);
_mesa_HashEnableNameReuse(&ctx->Shared->SemaphoreObjects);
}
/* SPECviewperf13/sw-04 crashes since a56849ddda6 if Mesa is build with
* -O3 on gcc 7.5, which doesn't happen with ForceGLNamesReuse, which is
* the default setting for SPECviewperf because it simulates glGen behavior
* of closed source drivers.
*/
if (ctx->Const.ForceGLNamesReuse)
_mesa_HashEnableNameReuse(&ctx->Query.QueryObjects);
_mesa_override_extensions(ctx); _mesa_override_extensions(ctx);
_mesa_compute_version(ctx); _mesa_compute_version(ctx);
@ -844,7 +826,8 @@ st_create_context(gl_api api, struct pipe_context *pipe,
ctx->pipe = pipe; ctx->pipe = pipe;
ctx->screen = pipe->screen; ctx->screen = pipe->screen;
if (!_mesa_initialize_context(ctx, api, no_error, visual, shareCtx, &funcs)) { if (!_mesa_initialize_context(ctx, api, no_error, visual, shareCtx, &funcs,
options)) {
align_free(ctx); align_free(ctx);
return NULL; return NULL;
} }

View file

@ -1320,8 +1320,6 @@ void st_init_extensions(struct pipe_screen *screen,
consts->GLSLZeroInit = screen->get_param(screen, PIPE_CAP_GLSL_ZERO_INIT); consts->GLSLZeroInit = screen->get_param(screen, PIPE_CAP_GLSL_ZERO_INIT);
} }
consts->ForceGLNamesReuse = options->force_gl_names_reuse;
consts->ForceIntegerTexNearest = options->force_integer_tex_nearest; consts->ForceIntegerTexNearest = options->force_integer_tex_nearest;
consts->VendorOverride = options->force_gl_vendor; consts->VendorOverride = options->force_gl_vendor;

View file

@ -383,7 +383,7 @@ TODO: document the other workarounds.
<option name="vblank_mode" value="0" /> <option name="vblank_mode" value="0" />
<option name="allow_glsl_extension_directive_midshader" value="true" /> <option name="allow_glsl_extension_directive_midshader" value="true" />
<option name="allow_glsl_120_subset_in_110" value="true" /> <option name="allow_glsl_120_subset_in_110" value="true" />
<option name="force_gl_names_reuse" value="true" /> <option name="reuse_gl_names" value="1" />
<!-- This makes it use GL_NVX_gpu_memory_info to query memory info <!-- This makes it use GL_NVX_gpu_memory_info to query memory info
instead of non-existent GLX_AMD_gpu_association. Yes, it checks instead of non-existent GLX_AMD_gpu_association. Yes, it checks
the vendor string, not the extension list. --> the vendor string, not the extension list. -->
@ -888,7 +888,7 @@ TODO: document the other workarounds.
small enough to fit in the static array). small enough to fit in the static array).
--> -->
<application name="SWKOTOR (wine)" executable="swkotor.exe"> <application name="SWKOTOR (wine)" executable="swkotor.exe">
<option name="force_gl_names_reuse" value="true"/> <option name="reuse_gl_names" value="1"/>
</application> </application>
<application name="Assault Android Cactus (32-bit)" executable="cactus_demo.x86"> <application name="Assault Android Cactus (32-bit)" executable="cactus_demo.x86">

View file

@ -269,8 +269,8 @@
DRI_CONF_OPT_I(override_vram_size, -1, -1, 2147483647, \ DRI_CONF_OPT_I(override_vram_size, -1, -1, 2147483647, \
"Override the VRAM size advertised to the application in MiB (-1 = default)") "Override the VRAM size advertised to the application in MiB (-1 = default)")
#define DRI_CONF_FORCE_GL_NAMES_REUSE(def) \ #define DRI_CONF_FORCE_GL_NAMES_REUSE() \
DRI_CONF_OPT_B(force_gl_names_reuse, def, "Force GL names reuse") DRI_CONF_OPT_I(reuse_gl_names, -1, -1, 1, "GL names reuse: 1=enable, 0=disable, -1=default")
#define DRI_CONF_FORCE_GL_MAP_BUFFER_SYNCHRONIZED(def) \ #define DRI_CONF_FORCE_GL_MAP_BUFFER_SYNCHRONIZED(def) \
DRI_CONF_OPT_B(force_gl_map_buffer_synchronized, def, "Override GL_MAP_UNSYNCHRONIZED_BIT.") DRI_CONF_OPT_B(force_gl_map_buffer_synchronized, def, "Override GL_MAP_UNSYNCHRONIZED_BIT.")