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/dri/i965/brw_meta_fast_clear.c | 15 ++++++------ src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c | 28 ++++++++++++----------- src/mesa/drivers/dri/i965/brw_meta_updownsample.c | 17 ++++++++------ 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c b/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c index 89ec0d5..c2459f4 100644 --- a/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c +++ b/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c @@ -36,6 +36,7 @@ #include "main/varray.h" #include "main/uniforms.h" #include "main/fbobject.h" +#include "main/framebuffer.h" #include "main/renderbuffer.h" #include "main/texobj.h" @@ -846,19 +847,19 @@ brw_meta_resolve_color(struct brw_context *brw, struct intel_mipmap_tree *mt) { struct gl_context *ctx = &brw->ctx; - GLuint fbo; struct gl_framebuffer *drawFb; struct gl_renderbuffer *rb; struct rect rect; brw_emit_mi_flush(brw); - _mesa_meta_begin(ctx, MESA_META_ALL); - - _mesa_CreateFramebuffers(1, &fbo); + drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF); + if (drawFb == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "in %s", __func__); + return; + } - drawFb = _mesa_lookup_framebuffer(ctx, fbo); - assert(drawFb != NULL && drawFb->Name == fbo); + _mesa_meta_begin(ctx, MESA_META_ALL); rb = brw_get_rb_for_slice(brw, mt, 0, 0, false); @@ -888,7 +889,7 @@ brw_meta_resolve_color(struct brw_context *brw, use_rectlist(brw, false); _mesa_reference_renderbuffer(&rb, NULL); - _mesa_DeleteFramebuffers(1, &fbo); + _mesa_reference_framebuffer(&drawFb, NULL); _mesa_meta_end(ctx); diff --git a/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c b/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c index d1a8780..5b0c2e9 100644 --- a/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c +++ b/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c @@ -49,6 +49,7 @@ #include "main/blit.h" #include "main/buffers.h" #include "main/fbobject.h" +#include "main/framebuffer.h" #include "main/uniforms.h" #include "main/texparam.h" #include "main/texobj.h" @@ -424,9 +425,9 @@ brw_meta_stencil_blit(struct brw_context *brw, struct gl_context *ctx = &brw->ctx; struct blit_dims dims = *orig_dims; struct fb_tex_blit_state blit; - GLuint prog, fbo; - struct gl_framebuffer *drawFb; - struct gl_renderbuffer *rb; + GLuint prog; + struct gl_framebuffer *drawFb = NULL; + struct gl_renderbuffer *rb = NULL; GLenum target; _mesa_meta_fb_tex_blit_begin(ctx, &blit); @@ -437,9 +438,11 @@ brw_meta_stencil_blit(struct brw_context *brw, assert(ctx->Extensions.ARB_texture_stencil8 == false); ctx->Extensions.ARB_texture_stencil8 = true; - _mesa_CreateFramebuffers(1, &fbo); - drawFb = _mesa_lookup_framebuffer(ctx, fbo); - assert(drawFb != NULL && drawFb->Name == fbo); + drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF); + if (drawFb == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "in %s", __func__); + goto error; + } /* Force the surface to be configured for level zero. */ rb = brw_get_rb_for_slice(brw, dst_mt, 0, dst_layer, true); @@ -481,7 +484,7 @@ error: _mesa_meta_end(ctx); _mesa_reference_renderbuffer(&rb, NULL); - _mesa_DeleteFramebuffers(1, &fbo); + _mesa_reference_framebuffer(&drawFb, NULL); } void @@ -538,20 +541,19 @@ brw_meta_stencil_updownsample(struct brw_context *brw, .dst_x0 = 0, .dst_y0 = 0, .dst_x1 = dst->logical_width0, .dst_y1 = dst->logical_height0, .mirror_x = 0, .mirror_y = 0 }; - GLuint fbo; struct gl_framebuffer *readFb; struct gl_renderbuffer *rb; if (dst->stencil_mt) dst = dst->stencil_mt; + readFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF); + if (readFb == NULL) + return; + brw_emit_mi_flush(brw); _mesa_meta_begin(ctx, MESA_META_ALL); - _mesa_CreateFramebuffers(1, &fbo); - readFb = _mesa_lookup_framebuffer(ctx, fbo); - assert(readFb != NULL && readFb->Name == fbo); - rb = brw_get_rb_for_slice(brw, src, 0, 0, false); _mesa_bind_framebuffers(ctx, ctx->DrawBuffer, readFb); @@ -562,5 +564,5 @@ brw_meta_stencil_updownsample(struct brw_context *brw, brw_emit_mi_flush(brw); _mesa_reference_renderbuffer(&rb, NULL); - _mesa_DeleteFramebuffers(1, &fbo); + _mesa_reference_framebuffer(&readFb, NULL); } diff --git a/src/mesa/drivers/dri/i965/brw_meta_updownsample.c b/src/mesa/drivers/dri/i965/brw_meta_updownsample.c index da06fef..f5fc207 100644 --- a/src/mesa/drivers/dri/i965/brw_meta_updownsample.c +++ b/src/mesa/drivers/dri/i965/brw_meta_updownsample.c @@ -29,6 +29,7 @@ #include "main/buffers.h" #include "main/enums.h" #include "main/fbobject.h" +#include "main/framebuffer.h" #include "main/renderbuffer.h" #include "drivers/common/meta.h" @@ -93,7 +94,6 @@ brw_meta_updownsample(struct brw_context *brw, struct intel_mipmap_tree *dst_mt) { struct gl_context *ctx = &brw->ctx; - GLuint fbos[2]; struct gl_framebuffer *src_fb; struct gl_framebuffer *dst_fb; struct gl_renderbuffer *src_rb; @@ -115,14 +115,15 @@ brw_meta_updownsample(struct brw_context *brw, brw_emit_mi_flush(brw); _mesa_meta_begin(ctx, MESA_META_ALL); - _mesa_CreateFramebuffers(2, fbos); src_rb = brw_get_rb_for_slice(brw, src_mt, 0, 0, false); dst_rb = brw_get_rb_for_slice(brw, dst_mt, 0, 0, false); - src_fb = _mesa_lookup_framebuffer(ctx, fbos[0]); - dst_fb = _mesa_lookup_framebuffer(ctx, fbos[1]); + src_fb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF); + dst_fb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF); - assert(src_fb != NULL && src_fb->Name == fbos[0]); - assert(dst_fb != NULL && dst_fb->Name == fbos[1]); + if (src_fb == NULL || dst_fb == NULL || src_rb == NULL || dst_rb == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "in %s", __func__); + goto error; + } _mesa_bind_framebuffers(ctx, dst_fb, src_fb); _mesa_framebuffer_renderbuffer(ctx, ctx->ReadBuffer, attachment, src_rb); @@ -137,9 +138,11 @@ brw_meta_updownsample(struct brw_context *brw, dst_mt->logical_width0, dst_mt->logical_height0, blit_bit, GL_NEAREST); +error: _mesa_reference_renderbuffer(&src_rb, NULL); _mesa_reference_renderbuffer(&dst_rb, NULL); - _mesa_DeleteFramebuffers(2, fbos); + _mesa_reference_framebuffer(&src_fb, NULL); + _mesa_reference_framebuffer(&dst_fb, NULL); _mesa_meta_end(ctx); -- 2.5.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev