diff options
author | Marek Olšák <marek.olsak@amd.com> | 2014-01-08 01:09:15 +0100 |
---|---|---|
committer | Marek Olšák <marek.olsak@amd.com> | 2014-01-13 15:48:07 +0100 |
commit | 9baa45f78b8ca7d66280e36009b6a685055d7cd6 (patch) | |
tree | 1aa17409335d9643983dfcd7abbbcc0126581817 /src/mesa/state_tracker/st_atom_framebuffer.c | |
parent | 9bf9578c1b79e5622a2325f1a2bb80fcf0e22a6d (diff) | |
download | external_mesa3d-9baa45f78b8ca7d66280e36009b6a685055d7cd6.zip external_mesa3d-9baa45f78b8ca7d66280e36009b6a685055d7cd6.tar.gz external_mesa3d-9baa45f78b8ca7d66280e36009b6a685055d7cd6.tar.bz2 |
st/mesa: bind NULL colorbuffers as specified by glDrawBuffers
An example why it is required:
Let's say there's a fragment shader writing to gl_FragData[0..1].
The user calls: glDrawBuffers(2, {GL_NONE, GL_COLOR_ATTACHMENT0});
That means gl_FragData[0] is unused and gl_FragData[1] is written
to GL_COLOR_ATTACHMENT0.
st/mesa was skipping the GL_NONE draw buffer, therefore gl_FragData[0]
was written to GL_COLOR_ATTACHMENT0, which was wrong.
This commit fixes it, but drivers must also be fixed not to crash when
binding NULL colorbuffers. There is also a new set of piglit tests for this.
The MSAA state also had to be fixed not to crash when reading fb->cbufs[0].
Reviewed-by: Brian Paul <brianp@vmware.com>
Diffstat (limited to 'src/mesa/state_tracker/st_atom_framebuffer.c')
-rw-r--r-- | src/mesa/state_tracker/st_atom_framebuffer.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index 51f079c..a77fe54 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -65,12 +65,14 @@ update_framebuffer_state( struct st_context *st ) /* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state * to determine which surfaces to draw to */ - framebuffer->nr_cbufs = 0; + framebuffer->nr_cbufs = fb->_NumColorDrawBuffers; + for (i = 0; i < fb->_NumColorDrawBuffers; i++) { + pipe_surface_reference(&framebuffer->cbufs[i], NULL); + strb = st_renderbuffer(fb->_ColorDrawBuffers[i]); if (strb) { - /*printf("--------- framebuffer surface rtt %p\n", strb->rtt);*/ if (strb->is_rtt || (strb->texture && util_format_is_srgb(strb->texture->format))) { /* rendering to a GL texture, may have to update surface */ @@ -78,13 +80,12 @@ update_framebuffer_state( struct st_context *st ) } if (strb->surface) { - pipe_surface_reference(&framebuffer->cbufs[framebuffer->nr_cbufs], - strb->surface); - framebuffer->nr_cbufs++; + pipe_surface_reference(&framebuffer->cbufs[i], strb->surface); } strb->defined = GL_TRUE; /* we'll be drawing something */ } } + for (i = framebuffer->nr_cbufs; i < PIPE_MAX_COLOR_BUFS; i++) { pipe_surface_reference(&framebuffer->cbufs[i], NULL); } @@ -113,7 +114,8 @@ update_framebuffer_state( struct st_context *st ) #ifdef DEBUG /* Make sure the resource binding flags were set properly */ for (i = 0; i < framebuffer->nr_cbufs; i++) { - assert(framebuffer->cbufs[i]->texture->bind & PIPE_BIND_RENDER_TARGET); + assert(!framebuffer->cbufs[i] || + framebuffer->cbufs[i]->texture->bind & PIPE_BIND_RENDER_TARGET); } if (framebuffer->zsbuf) { assert(framebuffer->zsbuf->texture->bind & PIPE_BIND_DEPTH_STENCIL); |