From cfa1a0a609daefffc6f8c4087ed0bc34c2665ef4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 16 Sep 2009 12:57:26 -0600 Subject: [PATCH 1/4] st/mesa: fix texture memory allocation bug The following example caused an incorrect GL_OUT_OF_MEMORY error to be raised in glTexSubImage2D: glTexImage2D(level=0, width=32, height=32, pixels=NULL); glTexImage2D(level=0, width=64, height=64, pixels=NULL); glTexSubImage2D(level=0, pixels!=NULL); The second glTexImage2D() call needs to cause the first image to be deallocated then reallocated at the new size. This was not happening because we were testing for pixels==NULL too early. --- src/mesa/state_tracker/st_cb_texture.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 2db28ef0a44..31196fe776b 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -661,8 +661,10 @@ st_TexImage(GLcontext * ctx, format, type, pixels, unpack, "glTexImage"); } - if (!pixels) - return; + + /* Note: we can't check for pixels==NULL until after we've allocated + * memory for the texture. + */ /* See if we can do texture compression with a blit/render. */ @@ -673,6 +675,9 @@ st_TexImage(GLcontext * ctx, stImage->pt->format, stImage->pt->target, PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { + if (!pixels) + goto done; + if (compress_with_blit(ctx, target, level, 0, 0, 0, width, height, depth, format, type, pixels, unpack, texImage)) { goto done; @@ -714,6 +719,9 @@ st_TexImage(GLcontext * ctx, return; } + if (!pixels) + goto done; + DBG("Upload image %dx%dx%d row_len %x pitch %x\n", width, height, depth, width * texelBytes, dstRowStride); From 08d39251a79a964e4a3ac0d7d8a397c2b66a0808 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 16 Sep 2009 13:07:12 -0600 Subject: [PATCH 2/4] st/mesa: fix some incorrect branching/clean-up code in TexImage functions We need to be sure to call the _mesa_unmap_teximage_pbo() function if we called _mesa_validate_pbo_teximage(). --- src/mesa/state_tracker/st_cb_texture.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 31196fe776b..cfa33d48e12 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -764,9 +764,9 @@ st_TexImage(GLcontext * ctx, } } +done: _mesa_unmap_teximage_pbo(ctx, unpack); -done: if (stImage->pt && texImage->Data) { st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; @@ -1107,7 +1107,7 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level, if (!texImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage"); - return; + goto done; } src = (const GLubyte *) pixels; @@ -1138,9 +1138,9 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level, } } +done: _mesa_unmap_teximage_pbo(ctx, packing); -done: if (stImage->pt) { st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; From 9666529b5a5be1fcde82caadc2fe2efa5ea81e49 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Wed, 16 Sep 2009 16:43:50 -0700 Subject: [PATCH 3/4] glx: Use initstate_r / random_r instead of corrupting global random number state Previously srandom and random were used. This cause the global random number generator state to be modified. This caused problems for applications that called srandom before calling into GLX. By using local state the global state is left unmodified. This should fix bug #23774. --- src/glx/x11/glxhash.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/glx/x11/glxhash.c b/src/glx/x11/glxhash.c index 74cd4f344df..7d28ada49ca 100644 --- a/src/glx/x11/glxhash.c +++ b/src/glx/x11/glxhash.c @@ -87,9 +87,13 @@ #define HASH_ALLOC malloc #define HASH_FREE free -#define HASH_RANDOM_DECL -#define HASH_RANDOM_INIT(seed) srandom(seed) -#define HASH_RANDOM random() +#define HASH_RANDOM_DECL struct random_data rd; int32_t rv; char rs[256] +#define HASH_RANDOM_INIT(seed) \ + do { \ + (void) memset(&rd, 0, sizeof(rd)); \ + (void) initstate_r(seed, rs, sizeof(rs), &rd); \ + } while(0) +#define HASH_RANDOM ((void) random_r(&rd, &rv), rv) #define HASH_RANDOM_DESTROY typedef struct __glxHashBucket From c4ce6f6a7c124c62a8ee9bd9fba28fc69a38e18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= Date: Sat, 12 Sep 2009 12:13:35 +0200 Subject: [PATCH 4/4] mesa/st: Initialize format bits of framebuffer renderbuffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolai Hähnle --- src/mesa/state_tracker/st_cb_fbo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 21ddf2fc7a2..6762ed39c3b 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -256,6 +256,7 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw) strb->Base.ClassID = 0x4242; /* just a unique value */ strb->Base.NumSamples = samples; strb->format = format; + init_renderbuffer_bits(strb, format); strb->software = sw; switch (format) {