mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-30 00:40:25 +01:00
meta: Don't pollute the buffer object namespace in _mesa_meta_DrawTex
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.romanick@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92363
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
(cherry picked from commit 76cfe2bc44)
This commit is contained in:
parent
089fa07dee
commit
9c2a7cfbbf
4 changed files with 29 additions and 38 deletions
|
|
@ -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(&ctx->Meta->Blit);
|
||||
meta_glsl_clear_cleanup(&ctx->Meta->Clear);
|
||||
_mesa_meta_glsl_generate_mipmap_cleanup(&ctx->Meta->Mipmap);
|
||||
_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);
|
||||
meta_decompress_cleanup(&ctx->Meta->Decompress);
|
||||
meta_drawpix_cleanup(&ctx->Meta->DrawPix);
|
||||
meta_decompress_cleanup(ctx, &ctx->Meta->Decompress);
|
||||
meta_drawpix_cleanup(ctx, &ctx->Meta->DrawPix);
|
||||
if (old_context)
|
||||
_mesa_make_current(old_context, old_context->WinSysDrawBuffer, old_context->WinSysReadBuffer);
|
||||
else
|
||||
|
|
@ -1649,14 +1652,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, &clear->VAO);
|
||||
clear->VAO = 0;
|
||||
_mesa_DeleteBuffers(1, &clear->buf_obj->Name);
|
||||
clear->buf_obj = NULL;
|
||||
_mesa_reference_buffer_object(ctx, &clear->buf_obj, NULL);
|
||||
_mesa_DeleteProgram(clear->ShaderProg);
|
||||
clear->ShaderProg = 0;
|
||||
|
||||
|
|
@ -1950,14 +1952,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, &drawpix->VAO);
|
||||
drawpix->VAO = 0;
|
||||
|
||||
_mesa_DeleteBuffers(1, &drawpix->buf_obj->Name);
|
||||
drawpix->buf_obj = NULL;
|
||||
_mesa_reference_buffer_object(ctx, &drawpix->buf_obj, NULL);
|
||||
}
|
||||
|
||||
if (drawpix->StencilFP != 0) {
|
||||
|
|
@ -2986,14 +2987,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(&decompress->byteFBO);
|
||||
meta_decompress_fbo_cleanup(&decompress->floatFBO);
|
||||
|
||||
if (decompress->VAO != 0) {
|
||||
_mesa_DeleteVertexArrays(1, &decompress->VAO);
|
||||
_mesa_DeleteBuffers(1, &decompress->buf_obj->Name);
|
||||
_mesa_reference_buffer_object(ctx, &decompress->buf_obj, NULL);
|
||||
}
|
||||
|
||||
if (decompress->Sampler != 0)
|
||||
|
|
@ -3310,7 +3312,6 @@ _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
|
|||
if (drawtex->VAO == 0) {
|
||||
/* one-time setup */
|
||||
struct gl_vertex_array_object *array_obj;
|
||||
GLuint VBO;
|
||||
|
||||
/* create vertex array object */
|
||||
_mesa_GenVertexArrays(1, &drawtex->VAO);
|
||||
|
|
@ -3320,23 +3321,13 @@ _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
|
|||
assert(array_obj != NULL);
|
||||
|
||||
/* create vertex array buffer */
|
||||
_mesa_CreateBuffers(1, &VBO);
|
||||
drawtex->buf_obj = _mesa_lookup_bufferobj(ctx, VBO);
|
||||
|
||||
/* _mesa_lookup_bufferobj only returns NULL if name is 0. If the object
|
||||
* does not yet exist (i.e., hasn't been bound) it will return a dummy
|
||||
* object that you can't do anything with.
|
||||
*/
|
||||
assert(drawtex->buf_obj != NULL && (drawtex->buf_obj)->Name == VBO);
|
||||
assert(drawtex->buf_obj == ctx->Array.ArrayBufferObj);
|
||||
drawtex->buf_obj = ctx->Driver.NewBufferObject(ctx, 0xDEADBEEF);
|
||||
if (drawtex->buf_obj == NULL)
|
||||
return;
|
||||
|
||||
_mesa_buffer_data(ctx, drawtex->buf_obj, GL_NONE, sizeof(verts), verts,
|
||||
GL_DYNAMIC_DRAW, __func__);
|
||||
|
||||
assert(drawtex->buf_obj->Size == sizeof(verts));
|
||||
|
||||
_mesa_BindBuffer(GL_ARRAY_BUFFER_ARB, VBO);
|
||||
|
||||
/* setup vertex arrays */
|
||||
_mesa_update_array_format(ctx, array_obj, VERT_ATTRIB_POS,
|
||||
3, GL_FLOAT, GL_RGBA, GL_FALSE,
|
||||
|
|
|
|||
|
|
@ -655,13 +655,14 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
|
|||
struct blit_shader_table *table);
|
||||
|
||||
void
|
||||
_mesa_meta_glsl_blit_cleanup(struct blit_state *blit);
|
||||
_mesa_meta_glsl_blit_cleanup(struct gl_context *ctx, struct blit_state *blit);
|
||||
|
||||
void
|
||||
_mesa_meta_blit_shader_table_cleanup(struct blit_shader_table *table);
|
||||
|
||||
void
|
||||
_mesa_meta_glsl_generate_mipmap_cleanup(struct gen_mipmap_state *mipmap);
|
||||
_mesa_meta_glsl_generate_mipmap_cleanup(struct gl_context *ctx,
|
||||
struct gen_mipmap_state *mipmap);
|
||||
|
||||
void
|
||||
_mesa_meta_bind_fbo_image(GLenum target, GLenum attachment,
|
||||
|
|
|
|||
|
|
@ -1006,13 +1006,12 @@ _mesa_meta_BlitFramebuffer(struct gl_context *ctx,
|
|||
}
|
||||
|
||||
void
|
||||
_mesa_meta_glsl_blit_cleanup(struct blit_state *blit)
|
||||
_mesa_meta_glsl_blit_cleanup(struct gl_context *ctx, struct blit_state *blit)
|
||||
{
|
||||
if (blit->VAO) {
|
||||
_mesa_DeleteVertexArrays(1, &blit->VAO);
|
||||
blit->VAO = 0;
|
||||
_mesa_DeleteBuffers(1, &blit->buf_obj->Name);
|
||||
blit->buf_obj = NULL;
|
||||
_mesa_reference_buffer_object(ctx, &blit->buf_obj, NULL);
|
||||
}
|
||||
|
||||
_mesa_meta_blit_shader_table_cleanup(&blit->shaders_with_depth);
|
||||
|
|
|
|||
|
|
@ -120,14 +120,14 @@ fallback_required(struct gl_context *ctx, GLenum target,
|
|||
}
|
||||
|
||||
void
|
||||
_mesa_meta_glsl_generate_mipmap_cleanup(struct gen_mipmap_state *mipmap)
|
||||
_mesa_meta_glsl_generate_mipmap_cleanup(struct gl_context *ctx,
|
||||
struct gen_mipmap_state *mipmap)
|
||||
{
|
||||
if (mipmap->VAO == 0)
|
||||
return;
|
||||
_mesa_DeleteVertexArrays(1, &mipmap->VAO);
|
||||
mipmap->VAO = 0;
|
||||
_mesa_DeleteBuffers(1, &mipmap->buf_obj->Name);
|
||||
mipmap->buf_obj->Name = NULL;
|
||||
_mesa_reference_buffer_object(ctx, &mipmap->buf_obj, NULL);
|
||||
_mesa_DeleteSamplers(1, &mipmap->Sampler);
|
||||
mipmap->Sampler = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue