Re: [Mesa-dev] [PATCH 20/23] meta: Don't pollute the buffer object namespace in _mesa_meta_DrawTex

2015-11-13 Thread Anuj Phogat
On Mon, Nov 9, 2015 at 4:56 PM, Ian Romanick  wrote:
> From: Ian Romanick 
>
> 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 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92363
> ---
>  src/mesa/drivers/common/meta.c | 51 
> +++---
>  src/mesa/drivers/common/meta.h |  5 ++-
>  src/mesa/drivers/common/meta_blit.c|  5 +--
>  src/mesa/drivers/common/meta_generate_mipmap.c |  6 +--
>  4 files changed, 29 insertions(+), 38 deletions(-)
>
> diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
> index 57993cf..b06f683 100644
> --- a/src/mesa/drivers/common/meta.c
> +++ b/src/mesa/drivers/common/meta.c
> @@ -95,9 +95,12 @@ 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 meta_glsl_clear_cleanup(struct clear_state *clear);
> -static void meta_decompress_cleanup(struct decompress_state *decompress);
> -static void meta_drawpix_cleanup(struct drawpix_state *drawpix);
> +static void meta_glsl_clear_cleanup(struct gl_context *ctx,
> +struct clear_state *clear);
> +static void meta_decompress_cleanup(struct gl_context *ctx,
> +struct decompress_state *decompress);
> +static void meta_drawpix_cleanup(struct gl_context *ctx,
> + struct drawpix_state *drawpix);
>
>  void
>  _mesa_meta_bind_fbo_image(GLenum fboTarget, GLenum attachment,
> @@ -435,12 +438,12 @@ _mesa_meta_free(struct gl_context *ctx)
>  {
> GET_CURRENT_CONTEXT(old_context);
> _mesa_make_current(ctx, NULL, NULL);
> -   _mesa_meta_glsl_blit_cleanup(>Meta->Blit);
> -   meta_glsl_clear_cleanup(>Meta->Clear);
> -   _mesa_meta_glsl_generate_mipmap_cleanup(>Meta->Mipmap);
> +   _mesa_meta_glsl_blit_cleanup(ctx, >Meta->Blit);
> +   meta_glsl_clear_cleanup(ctx, >Meta->Clear);
> +   _mesa_meta_glsl_generate_mipmap_cleanup(ctx, >Meta->Mipmap);
> cleanup_temp_texture(>Meta->TempTex);
> -   meta_decompress_cleanup(>Meta->Decompress);
> -   meta_drawpix_cleanup(>Meta->DrawPix);
> +   meta_decompress_cleanup(ctx, >Meta->Decompress);
> +   meta_drawpix_cleanup(ctx, >Meta->DrawPix);
> if (old_context)
>_mesa_make_current(old_context, old_context->WinSysDrawBuffer, 
> old_context->WinSysReadBuffer);
> else
> @@ -1638,14 +1641,13 @@ meta_glsl_clear_init(struct gl_context *ctx, struct 
> clear_state *clear)
>  }
>
>  static void
> -meta_glsl_clear_cleanup(struct clear_state *clear)
> +meta_glsl_clear_cleanup(struct gl_context *ctx, struct clear_state *clear)
>  {
> if (clear->VAO == 0)
>return;
> _mesa_DeleteVertexArrays(1, >VAO);
> clear->VAO = 0;
> -   _mesa_DeleteBuffers(1, >buf_obj->Name);
> -   clear->buf_obj = NULL;
> +   _mesa_reference_buffer_object(ctx, >buf_obj, NULL);
> _mesa_DeleteProgram(clear->ShaderProg);
> clear->ShaderProg = 0;
>
> @@ -1939,14 +1941,13 @@ _mesa_meta_CopyPixels(struct gl_context *ctx, GLint 
> srcX, GLint srcY,
>  }
>
>  static void
> -meta_drawpix_cleanup(struct drawpix_state *drawpix)
> +meta_drawpix_cleanup(struct gl_context *ctx, struct drawpix_state *drawpix)
>  {
> if (drawpix->VAO != 0) {
>_mesa_DeleteVertexArrays(1, >VAO);
>drawpix->VAO = 0;
>
> -  _mesa_DeleteBuffers(1, >buf_obj->Name);
> -  drawpix->buf_obj = NULL;
> +  _mesa_reference_buffer_object(ctx, >buf_obj, NULL);
> }
>
> if (drawpix->StencilFP != 0) {
> @@ -2975,14 +2976,15 @@ meta_decompress_fbo_cleanup(struct 
> decompress_fbo_state *decompress_fbo)
>  }
>
>  static void
> -meta_decompress_cleanup(struct decompress_state *decompress)
> +meta_decompress_cleanup(struct gl_context *ctx,
> +struct decompress_state *decompress)
>  {
> meta_decompress_fbo_cleanup(>byteFBO);
> meta_decompress_fbo_cleanup(>floatFBO);
>
> if (decompress->VAO != 0) {
>

[Mesa-dev] [PATCH 20/23] meta: Don't pollute the buffer object namespace in _mesa_meta_DrawTex

2015-11-09 Thread Ian Romanick
From: Ian Romanick 

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 
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92363
---
 src/mesa/drivers/common/meta.c | 51 +++---
 src/mesa/drivers/common/meta.h |  5 ++-
 src/mesa/drivers/common/meta_blit.c|  5 +--
 src/mesa/drivers/common/meta_generate_mipmap.c |  6 +--
 4 files changed, 29 insertions(+), 38 deletions(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 57993cf..b06f683 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -95,9 +95,12 @@ 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 meta_glsl_clear_cleanup(struct clear_state *clear);
-static void meta_decompress_cleanup(struct decompress_state *decompress);
-static void meta_drawpix_cleanup(struct drawpix_state *drawpix);
+static void meta_glsl_clear_cleanup(struct gl_context *ctx,
+struct clear_state *clear);
+static void meta_decompress_cleanup(struct gl_context *ctx,
+struct decompress_state *decompress);
+static void meta_drawpix_cleanup(struct gl_context *ctx,
+ struct drawpix_state *drawpix);
 
 void
 _mesa_meta_bind_fbo_image(GLenum fboTarget, GLenum attachment,
@@ -435,12 +438,12 @@ _mesa_meta_free(struct gl_context *ctx)
 {
GET_CURRENT_CONTEXT(old_context);
_mesa_make_current(ctx, NULL, NULL);
-   _mesa_meta_glsl_blit_cleanup(>Meta->Blit);
-   meta_glsl_clear_cleanup(>Meta->Clear);
-   _mesa_meta_glsl_generate_mipmap_cleanup(>Meta->Mipmap);
+   _mesa_meta_glsl_blit_cleanup(ctx, >Meta->Blit);
+   meta_glsl_clear_cleanup(ctx, >Meta->Clear);
+   _mesa_meta_glsl_generate_mipmap_cleanup(ctx, >Meta->Mipmap);
cleanup_temp_texture(>Meta->TempTex);
-   meta_decompress_cleanup(>Meta->Decompress);
-   meta_drawpix_cleanup(>Meta->DrawPix);
+   meta_decompress_cleanup(ctx, >Meta->Decompress);
+   meta_drawpix_cleanup(ctx, >Meta->DrawPix);
if (old_context)
   _mesa_make_current(old_context, old_context->WinSysDrawBuffer, 
old_context->WinSysReadBuffer);
else
@@ -1638,14 +1641,13 @@ meta_glsl_clear_init(struct gl_context *ctx, struct 
clear_state *clear)
 }
 
 static void
-meta_glsl_clear_cleanup(struct clear_state *clear)
+meta_glsl_clear_cleanup(struct gl_context *ctx, struct clear_state *clear)
 {
if (clear->VAO == 0)
   return;
_mesa_DeleteVertexArrays(1, >VAO);
clear->VAO = 0;
-   _mesa_DeleteBuffers(1, >buf_obj->Name);
-   clear->buf_obj = NULL;
+   _mesa_reference_buffer_object(ctx, >buf_obj, NULL);
_mesa_DeleteProgram(clear->ShaderProg);
clear->ShaderProg = 0;
 
@@ -1939,14 +1941,13 @@ _mesa_meta_CopyPixels(struct gl_context *ctx, GLint 
srcX, GLint srcY,
 }
 
 static void
-meta_drawpix_cleanup(struct drawpix_state *drawpix)
+meta_drawpix_cleanup(struct gl_context *ctx, struct drawpix_state *drawpix)
 {
if (drawpix->VAO != 0) {
   _mesa_DeleteVertexArrays(1, >VAO);
   drawpix->VAO = 0;
 
-  _mesa_DeleteBuffers(1, >buf_obj->Name);
-  drawpix->buf_obj = NULL;
+  _mesa_reference_buffer_object(ctx, >buf_obj, NULL);
}
 
if (drawpix->StencilFP != 0) {
@@ -2975,14 +2976,15 @@ meta_decompress_fbo_cleanup(struct decompress_fbo_state 
*decompress_fbo)
 }
 
 static void
-meta_decompress_cleanup(struct decompress_state *decompress)
+meta_decompress_cleanup(struct gl_context *ctx,
+struct decompress_state *decompress)
 {
meta_decompress_fbo_cleanup(>byteFBO);
meta_decompress_fbo_cleanup(>floatFBO);
 
if (decompress->VAO != 0) {
   _mesa_DeleteVertexArrays(1, >VAO);
-  _mesa_DeleteBuffers(1, >buf_obj->Name);
+  _mesa_reference_buffer_object(ctx, >buf_obj, NULL);
}
 
if (decompress->Sampler != 0)
@@ -3299,7 +3301,6 @@ _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, 
GLfloat y, GLfloat z,
if (drawtex->VAO == 0) {