summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2015-11-13 16:51:27 -0800
committerIan Romanick <[email protected]>2016-03-01 11:07:20 -0800
commit3071da303211701df38ee052cb80c30acba51768 (patch)
treed6c666d7874df3fe017e27a52b8595414db82a57 /src/mesa/drivers
parent91e5825b8af38109b3a58a0be28749859d2516a3 (diff)
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. Fixes piglit tests: - object-namespace-pollution glGetTexImage-compressed framebuffer - object-namespace-pollution glGenerateMipmap framebuffer Signed-off-by: Ian Romanick <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92363 Reviewed-by: Topi Pohjolainen <[email protected]>
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r--src/mesa/drivers/common/meta.c34
-rw-r--r--src/mesa/drivers/common/meta_copy_image.c16
-rw-r--r--src/mesa/drivers/common/meta_generate_mipmap.c17
-rw-r--r--src/mesa/drivers/common/meta_tex_subimage.c38
4 files changed, 51 insertions, 54 deletions
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index bf03563954e..ab78f4565da 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -2784,7 +2784,6 @@ copytexsubimage_using_blit_framebuffer(struct gl_context *ctx, GLuint dims,
GLint x, GLint y,
GLsizei width, GLsizei height)
{
- GLuint fbo;
struct gl_framebuffer *drawFb;
bool success = false;
GLbitfield mask;
@@ -2793,12 +2792,11 @@ copytexsubimage_using_blit_framebuffer(struct gl_context *ctx, GLuint dims,
if (!ctx->Extensions.ARB_framebuffer_object)
return false;
- _mesa_meta_begin(ctx, MESA_META_ALL & ~MESA_META_DRAW_BUFFERS);
-
- _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)
+ return false;
+ _mesa_meta_begin(ctx, MESA_META_ALL & ~MESA_META_DRAW_BUFFERS);
_mesa_bind_framebuffers(ctx, drawFb, ctx->ReadBuffer);
if (rb->_BaseFormat == GL_DEPTH_STENCIL ||
@@ -2850,7 +2848,7 @@ copytexsubimage_using_blit_framebuffer(struct gl_context *ctx, GLuint dims,
success = mask == 0x0;
out:
- _mesa_DeleteFramebuffers(1, &fbo);
+ _mesa_reference_framebuffer(&drawFb, NULL);
_mesa_meta_end(ctx);
return success;
}
@@ -2946,7 +2944,7 @@ static void
meta_decompress_fbo_cleanup(struct decompress_fbo_state *decompress_fbo)
{
if (decompress_fbo->fb != NULL) {
- _mesa_DeleteFramebuffers(1, &decompress_fbo->fb->Name);
+ _mesa_reference_framebuffer(&decompress_fbo->fb, NULL);
_mesa_reference_renderbuffer(&decompress_fbo->rb, NULL);
}
@@ -3050,8 +3048,6 @@ decompress_texture_image(struct gl_context *ctx,
/* Create/bind FBO/renderbuffer */
if (decompress_fbo->fb == NULL) {
- GLuint FBO;
-
decompress_fbo->rb = ctx->Driver.NewRenderbuffer(ctx, 0xDEADBEEF);
if (decompress_fbo->rb == NULL) {
_mesa_meta_end(ctx);
@@ -3060,9 +3056,11 @@ decompress_texture_image(struct gl_context *ctx,
decompress_fbo->rb->RefCount = 1;
- _mesa_CreateFramebuffers(1, &FBO);
- decompress_fbo->fb = _mesa_lookup_framebuffer(ctx, FBO);
- assert(decompress_fbo->fb != NULL && decompress_fbo->fb->Name == FBO);
+ decompress_fbo->fb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (decompress_fbo->fb == NULL) {
+ _mesa_meta_end(ctx);
+ return false;
+ }
_mesa_bind_framebuffers(ctx, decompress_fbo->fb, decompress_fbo->fb);
_mesa_framebuffer_renderbuffer(ctx, ctx->DrawBuffer, GL_COLOR_ATTACHMENT0,
@@ -3518,14 +3516,12 @@ cleartexsubimage_for_zoffset(struct gl_context *ctx,
GLint zoffset,
const GLvoid *clearValue)
{
- GLuint fbo;
struct gl_framebuffer *drawFb;
bool success;
- _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)
+ return false;
_mesa_bind_framebuffers(ctx, drawFb, ctx->ReadBuffer);
@@ -3540,7 +3536,7 @@ cleartexsubimage_for_zoffset(struct gl_context *ctx,
break;
}
- _mesa_DeleteFramebuffers(1, &fbo);
+ _mesa_reference_framebuffer(&drawFb, NULL);
return success;
}
diff --git a/src/mesa/drivers/common/meta_copy_image.c b/src/mesa/drivers/common/meta_copy_image.c
index 1d45785a177..18b9681b710 100644
--- a/src/mesa/drivers/common/meta_copy_image.c
+++ b/src/mesa/drivers/common/meta_copy_image.c
@@ -30,6 +30,7 @@
#include "teximage.h"
#include "texobj.h"
#include "fbobject.h"
+#include "framebuffer.h"
#include "buffers.h"
#include "state.h"
#include "mtypes.h"
@@ -166,7 +167,6 @@ _mesa_meta_CopyImageSubData_uncompressed(struct gl_context *ctx,
GLint src_internal_format, dst_internal_format;
GLuint src_view_texture = 0;
struct gl_texture_image *src_view_tex_image;
- GLuint fbos[2];
struct gl_framebuffer *readFb;
struct gl_framebuffer *drawFb;
bool success = false;
@@ -212,12 +212,13 @@ _mesa_meta_CopyImageSubData_uncompressed(struct gl_context *ctx,
/* We really only need to stash the bound framebuffers and scissor. */
_mesa_meta_begin(ctx, MESA_META_SCISSOR);
- _mesa_CreateFramebuffers(2, fbos);
- readFb = _mesa_lookup_framebuffer(ctx, fbos[0]);
- assert(readFb != NULL && readFb->Name == fbos[0]);
+ readFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (readFb == NULL)
+ goto meta_end;
- drawFb = _mesa_lookup_framebuffer(ctx, fbos[1]);
- assert(drawFb != NULL && drawFb->Name == fbos[1]);
+ drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (drawFb == NULL)
+ goto meta_end;
_mesa_bind_framebuffers(ctx, drawFb, readFb);
@@ -288,7 +289,8 @@ _mesa_meta_CopyImageSubData_uncompressed(struct gl_context *ctx,
success = true;
meta_end:
- _mesa_DeleteFramebuffers(2, fbos);
+ _mesa_reference_framebuffer(&readFb, NULL);
+ _mesa_reference_framebuffer(&drawFb, NULL);
_mesa_meta_end(ctx);
cleanup:
diff --git a/src/mesa/drivers/common/meta_generate_mipmap.c b/src/mesa/drivers/common/meta_generate_mipmap.c
index ffc26164235..892d8d34619 100644
--- a/src/mesa/drivers/common/meta_generate_mipmap.c
+++ b/src/mesa/drivers/common/meta_generate_mipmap.c
@@ -101,11 +101,12 @@ fallback_required(struct gl_context *ctx, GLenum target,
* Test that we can actually render in the texture's format.
*/
if (mipmap->fb == NULL) {
- GLuint FBO;
-
- _mesa_CreateFramebuffers(1, &FBO);
- mipmap->fb = _mesa_lookup_framebuffer(ctx, FBO);
- assert(mipmap->fb != NULL && mipmap->fb->Name == FBO);
+ mipmap->fb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (mipmap->fb == NULL) {
+ _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH,
+ "glGenerateMipmap() ran out of memory\n");
+ return true;
+ }
}
_mesa_meta_framebuffer_texture_image(ctx, mipmap->fb,
@@ -131,11 +132,7 @@ _mesa_meta_glsl_generate_mipmap_cleanup(struct gl_context *ctx,
mipmap->VAO = 0;
_mesa_reference_buffer_object(ctx, &mipmap->buf_obj, NULL);
_mesa_reference_sampler_object(ctx, &mipmap->samp_obj, NULL);
-
- if (mipmap->fb != NULL) {
- _mesa_DeleteFramebuffers(1, &mipmap->fb->Name);
- mipmap->fb = NULL;
- }
+ _mesa_reference_framebuffer(&mipmap->fb, NULL);
_mesa_meta_blit_shader_table_cleanup(&mipmap->shaders);
}
diff --git a/src/mesa/drivers/common/meta_tex_subimage.c b/src/mesa/drivers/common/meta_tex_subimage.c
index 55605554157..639d3236359 100644
--- a/src/mesa/drivers/common/meta_tex_subimage.c
+++ b/src/mesa/drivers/common/meta_tex_subimage.c
@@ -179,9 +179,9 @@ _mesa_meta_pbo_TexSubImage(struct gl_context *ctx, GLuint dims,
const struct gl_pixelstore_attrib *packing)
{
struct gl_buffer_object *pbo = NULL;
- GLuint pbo_tex = 0, fbos[2] = { 0, 0 };
- struct gl_framebuffer *readFb;
- struct gl_framebuffer *drawFb;
+ GLuint pbo_tex = 0;
+ struct gl_framebuffer *readFb = NULL;
+ struct gl_framebuffer *drawFb = NULL;
int image_height;
struct gl_texture_image *pbo_tex_image;
GLenum status;
@@ -228,13 +228,13 @@ _mesa_meta_pbo_TexSubImage(struct gl_context *ctx, GLuint dims,
_mesa_meta_begin(ctx, ~(MESA_META_PIXEL_TRANSFER |
MESA_META_PIXEL_STORE));
- _mesa_CreateFramebuffers(2, fbos);
-
- readFb = _mesa_lookup_framebuffer(ctx, fbos[0]);
- assert(readFb != NULL && readFb->Name == fbos[0]);
+ readFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (readFb == NULL)
+ goto fail;
- drawFb = _mesa_lookup_framebuffer(ctx, fbos[1]);
- assert(drawFb != NULL && drawFb->Name == fbos[1]);
+ drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (drawFb == NULL)
+ goto fail;
_mesa_bind_framebuffers(ctx, drawFb, tex_image ? readFb : ctx->ReadBuffer);
@@ -291,7 +291,8 @@ _mesa_meta_pbo_TexSubImage(struct gl_context *ctx, GLuint dims,
success = true;
fail:
- _mesa_DeleteFramebuffers(2, fbos);
+ _mesa_reference_framebuffer(&readFb, NULL);
+ _mesa_reference_framebuffer(&drawFb, NULL);
_mesa_DeleteTextures(1, &pbo_tex);
_mesa_reference_buffer_object(ctx, &pbo, NULL);
@@ -309,7 +310,7 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
const struct gl_pixelstore_attrib *packing)
{
struct gl_buffer_object *pbo = NULL;
- GLuint pbo_tex = 0, fbos[2] = { 0, 0 };
+ GLuint pbo_tex = 0;
struct gl_framebuffer *readFb;
struct gl_framebuffer *drawFb;
int image_height;
@@ -374,13 +375,13 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
if (ctx->Extensions.ARB_color_buffer_float)
_mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE);
- _mesa_CreateFramebuffers(2, fbos);
-
- readFb = _mesa_lookup_framebuffer(ctx, fbos[0]);
- assert(readFb != NULL && readFb->Name == fbos[0]);
+ readFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (readFb == NULL)
+ goto fail;
- drawFb = _mesa_lookup_framebuffer(ctx, fbos[1]);
- assert(drawFb != NULL && drawFb->Name == fbos[1]);
+ drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (drawFb == NULL)
+ goto fail;
if (tex_image && tex_image->TexObject->Target == GL_TEXTURE_1D_ARRAY) {
assert(depth == 1);
@@ -474,7 +475,8 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
success = true;
fail:
- _mesa_DeleteFramebuffers(2, fbos);
+ _mesa_reference_framebuffer(&drawFb, NULL);
+ _mesa_reference_framebuffer(&readFb, NULL);
_mesa_DeleteTextures(1, &pbo_tex);
_mesa_reference_buffer_object(ctx, &pbo, NULL);