Mesa (master): st/mesa: unbind constant buffer when not in use

Keith Whitwell keithw at kemper.freedesktop.org
Tue Nov 2 17:00:21 UTC 2010


Module: Mesa
Branch: master
Commit: 8dfafbf0861fe3d2542332658dd5493851053c78
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8dfafbf0861fe3d2542332658dd5493851053c78

Author: Keith Whitwell <keithw at vmware.com>
Date:   Tue Nov  2 16:29:10 2010 +0000

st/mesa: unbind constant buffer when not in use

Important as more constant buffers per shader start to get used.

Fix up r600 (tested) and nv50 (untested) to cope with this.  Drivers
previously didn't see unbinds of constant buffers often or ever, so
this isn't always dealt with cleanly.

For r600 just return and keep the reference.  Will try to do better in
a followup change.

---

 src/gallium/drivers/nv50/nv50_shader_state.c |    3 +++
 src/gallium/drivers/r600/r600_state.c        |    7 +++++++
 src/mesa/state_tracker/st_atom_constbuf.c    |    5 ++++-
 3 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/src/gallium/drivers/nv50/nv50_shader_state.c b/src/gallium/drivers/nv50/nv50_shader_state.c
index 6c41e8f..306aa81 100644
--- a/src/gallium/drivers/nv50/nv50_shader_state.c
+++ b/src/gallium/drivers/nv50/nv50_shader_state.c
@@ -39,6 +39,9 @@ nv50_transfer_constbuf(struct nv50_context *nv50,
    uint32_t *map;
    unsigned count, start;
 
+   if (buf == NULL)
+      return;
+
    map = pipe_buffer_map(pipe, buf, PIPE_TRANSFER_READ, &transfer);
    if (!map)
       return;
diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c
index b3e0d49..ccd7421 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -1018,6 +1018,13 @@ static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint
 	struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
 	struct r600_resource *rbuffer = (struct r600_resource*)buffer;
 
+	/* Note that the state tracker can unbind constant buffers by
+	 * passing NULL here.
+	 */
+	if (buffer == NULL) {
+		return;
+	}
+
 	switch (shader) {
 	case PIPE_SHADER_VERTEX:
 		rctx->vs_const_buffer.nregs = 0;
diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
index 6f9d71e..8d1dc79 100644
--- a/src/mesa/state_tracker/st_atom_constbuf.c
+++ b/src/mesa/state_tracker/st_atom_constbuf.c
@@ -90,8 +90,11 @@ void st_upload_constants( struct st_context *st,
 
       st->pipe->set_constant_buffer(st->pipe, shader_type, 0, *cbuf);
    }
-   else {
+   else if (*cbuf) {
       st->constants.tracked_state[shader_type].dirty.mesa = 0x0;
+
+      pipe_resource_reference(cbuf, NULL);
+      st->pipe->set_constant_buffer(st->pipe, shader_type, 0, NULL);
    }
 }
 




More information about the mesa-commit mailing list