From: Ian Romanick <ian.d.roman...@intel.com>

tl;dr: For many types of GL object, we can *NEVER* use the Gen function.

In OpenGL ES (all versions!) and OpenGL compatibility profile,
applications don't have to call Gen functions.  The GL spec is very
clear about how you can mix-and-match generated names and non-generated
names: you can use any name you want for a particular object type until
you call the Gen function for that object type.

Here's the problem scenario:

 - Application calls a meta function that generates a name.  The first
   Gen will probably return 1.

 - Application decides to use the same name for an object of the same
   type without calling Gen.  Many demo programs use names 1, 2, 3,
   etc. without calling Gen.

 - Application calls the meta function again, and the meta function
   replaces the data.  The application's data is lost, and the app
   fails.  Have fun debugging that.

Signed-off-by: Ian Romanick <ian.d.roman...@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92363
---
 src/mesa/drivers/common/meta.c      | 21 ++++++---------------
 src/mesa/drivers/common/meta_blit.c | 18 ++++--------------
 2 files changed, 10 insertions(+), 29 deletions(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 55d803f..f4830ec 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -98,7 +98,8 @@ meta_clear(struct gl_context *ctx, GLbitfield buffers, bool 
glsl);
 static struct blit_shader *
 choose_blit_shader(GLenum target, struct blit_shader_table *table);
 
-static void cleanup_temp_texture(struct temp_texture *tex);
+static void cleanup_temp_texture(struct gl_context *ctx,
+                                 struct temp_texture *tex);
 static void meta_glsl_clear_cleanup(struct gl_context *ctx,
                                     struct clear_state *clear);
 static void meta_decompress_cleanup(struct gl_context *ctx,
@@ -418,7 +419,7 @@ _mesa_meta_free(struct gl_context *ctx)
    _mesa_meta_glsl_blit_cleanup(ctx, &ctx->Meta->Blit);
    meta_glsl_clear_cleanup(ctx, &ctx->Meta->Clear);
    _mesa_meta_glsl_generate_mipmap_cleanup(ctx, &ctx->Meta->Mipmap);
-   cleanup_temp_texture(&ctx->Meta->TempTex);
+   cleanup_temp_texture(ctx, &ctx->Meta->TempTex);
    meta_decompress_cleanup(ctx, &ctx->Meta->Decompress);
    meta_drawpix_cleanup(ctx, &ctx->Meta->DrawPix);
    if (old_context)
@@ -1228,8 +1229,6 @@ invert_z(GLfloat normZ)
 static void
 init_temp_texture(struct gl_context *ctx, struct temp_texture *tex)
 {
-   GLuint texObj;
-
    /* prefer texture rectangle */
    if (_mesa_is_desktop_gl(ctx) && ctx->Extensions.NV_texture_rectangle) {
       tex->Target = GL_TEXTURE_RECTANGLE;
@@ -1245,21 +1244,13 @@ init_temp_texture(struct gl_context *ctx, struct 
temp_texture *tex)
    tex->MinSize = 16;  /* 16 x 16 at least */
    assert(tex->MaxSize > 0);
 
-   _mesa_CreateTextures(tex->Target, 1, &texObj);
-   tex->tex_obj = NULL;
-
-   if (texObj == 0)
-      return;
-
-   tex->tex_obj = _mesa_lookup_texture(ctx, texObj);
+   tex->tex_obj = ctx->Driver.NewTextureObject(ctx, 0xDEADBEEF, tex->Target);
 }
 
 static void
-cleanup_temp_texture(struct temp_texture *tex)
+cleanup_temp_texture(struct gl_context *ctx, struct temp_texture *tex)
 {
-   if (tex->tex_obj == NULL)
-     return;
-   _mesa_DeleteTextures(1, &tex->tex_obj->Name);
+   _mesa_delete_nameless_texture(ctx, tex->tex_obj);
    tex->tex_obj = NULL;
 }
 
diff --git a/src/mesa/drivers/common/meta_blit.c 
b/src/mesa/drivers/common/meta_blit.c
index 95dfa64..496ef28 100644
--- a/src/mesa/drivers/common/meta_blit.c
+++ b/src/mesa/drivers/common/meta_blit.c
@@ -879,9 +879,7 @@ _mesa_meta_fb_tex_blit_end(struct gl_context *ctx, GLenum 
target,
    _mesa_bind_sampler(ctx, ctx->Texture.CurrentUnit, blit->samp_obj_save);
    _mesa_reference_sampler_object(ctx, &blit->samp_obj_save, NULL);
    _mesa_reference_sampler_object(ctx, &blit->samp_obj, NULL);
-
-   if (blit->temp_tex_obj)
-      _mesa_DeleteTextures(1, &blit->temp_tex_obj->Name);
+   _mesa_delete_nameless_texture(ctx, blit->temp_tex_obj);
 }
 
 struct gl_texture_object *
@@ -890,20 +888,14 @@ _mesa_meta_texture_object_from_renderbuffer(struct 
gl_context *ctx,
 {
    struct gl_texture_image *texImage;
    struct gl_texture_object *texObj;
-   GLuint tempTex;
    const GLenum target = rb->NumSamples > 1
       ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D;
 
-   tempTex = 0;
-   _mesa_CreateTextures(target, 1, &tempTex);
-   if (tempTex == 0)
-      return NULL;
-
-   texObj = _mesa_lookup_texture(ctx, tempTex);
+   texObj = ctx->Driver.NewTextureObject(ctx, 0xDEADBEEF, target);
    texImage = _mesa_get_tex_image(ctx, texObj, target, 0);
 
    if (!ctx->Driver.BindRenderbufferTexImage(ctx, rb, texImage)) {
-      _mesa_DeleteTextures(1, &tempTex);
+      _mesa_delete_nameless_texture(ctx, texObj);
       return NULL;
    }
 
@@ -912,8 +904,6 @@ _mesa_meta_texture_object_from_renderbuffer(struct 
gl_context *ctx,
       ctx->Driver.FinishRenderTexture(ctx, rb);
    }
 
-   assert(target == texObj->Target);
-   assert(tempTex == texObj->Name);
    return texObj;
 }
 
@@ -1057,7 +1047,7 @@ _mesa_meta_glsl_blit_cleanup(struct gl_context *ctx, 
struct blit_state *blit)
    _mesa_meta_blit_shader_table_cleanup(ctx, &blit->shaders_without_depth);
 
    if (blit->depthTex.tex_obj != NULL) {
-      _mesa_DeleteTextures(1, &blit->depthTex.tex_obj->Name);
+      _mesa_delete_nameless_texture(ctx, blit->depthTex.tex_obj);
       blit->depthTex.tex_obj = NULL;
    }
 }
-- 
2.9.5

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to