diff options
author | Ian Romanick <[email protected]> | 2015-11-13 17:57:18 -0800 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2016-03-01 11:07:20 -0800 |
commit | 1a80ca22fef420142d128f98bb3a04a5d9c46bf9 (patch) | |
tree | f8f1d13e3b6340c1467d9dc34138acf5e3c4ab57 | |
parent | 8f1b1878a0ae80dddc95a4322b0e84f486015c81 (diff) |
i965/meta: Don't pollute the framebuffer namespace
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 <[email protected]>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92363
Reviewed-by: Topi Pohjolainen <[email protected]>
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_meta_fast_clear.c | 15 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c | 28 | ||||
-rw-r--r-- | 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 50d8004d111..b81b1438ba3 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" @@ -848,19 +849,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); @@ -893,7 +894,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 d1a8780447c..5b0c2e9bdd5 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 da06fef4fee..f5fc2072dd7 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); |