From 8706e97ffdd8d35bcbb3c9a3cd9858d61f95d08d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 19 Dec 2020 03:21:25 -0500 Subject: [PATCH] mesa: partially skip glPush/PopAttrib for MSAA textures and texture buffers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is based on the GL 4.6 Compatibility profile spec. Some fields just don't have to be restored. This decreases CPU overhead. Reviewed-by: Zoltán Böszörményi Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/attrib.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index 583dc51..82f7ed6 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -63,6 +63,26 @@ #include "util/u_memory.h" +static inline bool +copy_texture_attribs(struct gl_texture_object *dst, + const struct gl_texture_object *src, + gl_texture_index tex) +{ + /* All pushed fields have no effect on texture buffers. */ + if (tex == TEXTURE_BUFFER_INDEX) + return false; + + /* Sampler fields have no effect on MSAA textures. */ + if (tex != TEXTURE_2D_MULTISAMPLE_INDEX && + tex != TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX) { + memcpy(&dst->Sampler.Attrib, &src->Sampler.Attrib, + sizeof(src->Sampler.Attrib)); + } + memcpy(&dst->Attrib, &src->Attrib, sizeof(src->Attrib)); + return true; +} + + void GLAPIENTRY _mesa_PushAttrib(GLbitfield mask) { @@ -251,8 +271,8 @@ _mesa_PushAttrib(GLbitfield mask) struct gl_texture_object *src = ctx->Texture.Unit[u].CurrentTex[tex]; dst->Name = src->Name; - memcpy(&dst->Sampler.Attrib, &src->Sampler.Attrib, sizeof(src->Sampler.Attrib)); - memcpy(&dst->Attrib, &src->Attrib, sizeof(src->Attrib)); + + copy_texture_attribs(dst, src, tex); } } @@ -594,8 +614,15 @@ pop_texture_group(struct gl_context *ctx, struct gl_texture_attrib_node *texstat const struct gl_texture_object *savedObj = &texstate->SavedObj[u][tgt]; struct gl_texture_object *texObj = _mesa_get_tex_unit(ctx, u)->CurrentTex[tgt]; + bool is_msaa = tgt == TEXTURE_2D_MULTISAMPLE_INDEX || + tgt == TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX; - if (texObj->Name != savedObj->Name) { + /* According to the OpenGL 4.6 Compatibility Profile specification, + * table 23.17, GL_TEXTURE_BINDING_2D_MULTISAMPLE and + * GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY do not belong in the + * texture attrib group. + */ + if (!is_msaa && texObj->Name != savedObj->Name) { /* We don't need to check whether the texture target is supported, * because we wouldn't get in this conditional block if it wasn't. */ @@ -603,9 +630,8 @@ pop_texture_group(struct gl_context *ctx, struct gl_texture_attrib_node *texstat texObj = _mesa_get_tex_unit(ctx, u)->CurrentTex[tgt]; } - memcpy(&texObj->Sampler.Attrib, &savedObj->Sampler.Attrib, - sizeof(savedObj->Sampler.Attrib)); - memcpy(&texObj->Attrib, &savedObj->Attrib, sizeof(savedObj->Attrib)); + if (!copy_texture_attribs(texObj, savedObj, tgt)) + continue; /* GL_ALL_ATTRIB_BITS means all pnames. (internal) */ if (texObj->Name != 0 && ctx->Driver.TexParameter) -- 2.7.4