[Mesa-dev] [PATCH 07/10] gallium/util: add util_copy_shader_buffer() helper

Rob Clark robdclark at gmail.com
Tue Jun 14 15:57:59 UTC 2016


From: Rob Clark <robclark at freedesktop.org>

Signed-off-by: Rob Clark <robclark at freedesktop.org>
---
 src/gallium/auxiliary/util/u_inlines.h        | 15 +++++++++++++++
 src/gallium/drivers/nouveau/nvc0/nvc0_state.c |  6 ++----
 src/gallium/drivers/softpipe/sp_state_image.c |  6 ++----
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h
index 78125c8..ebaf368 100644
--- a/src/gallium/auxiliary/util/u_inlines.h
+++ b/src/gallium/auxiliary/util/u_inlines.h
@@ -640,6 +640,21 @@ util_copy_index_buffer(struct pipe_index_buffer *dst,
 }
 
 static inline void
+util_copy_shader_buffer(struct pipe_shader_buffer *dst,
+                        const struct pipe_shader_buffer *src)
+{
+   if (src) {
+      pipe_resource_reference(&dst->buffer, src->buffer);
+      dst->buffer_offset = src->buffer_offset;
+      dst->buffer_size = src->buffer_size;
+   } else {
+      pipe_resource_reference(&dst->buffer, NULL);
+      dst->buffer_offset = 0;
+      dst->buffer_size = 0;
+   }
+}
+
+static inline void
 util_copy_image_view(struct pipe_image_view *dst,
                      const struct pipe_image_view *src)
 {
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
index 0bd756f..79847ec 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
@@ -1338,9 +1338,7 @@ nvc0_bind_buffers_range(struct nvc0_context *nvc0, const unsigned t,
             nvc0->buffers_valid[t] |= (1 << i);
          else
             nvc0->buffers_valid[t] &= ~(1 << i);
-         buf->buffer_offset = pbuffers[p].buffer_offset;
-         buf->buffer_size = pbuffers[p].buffer_size;
-         pipe_resource_reference(&buf->buffer, pbuffers[p].buffer);
+         util_copy_shader_buffer(buf, &pbuffers[p]);
       }
       if (!mask)
          return false;
@@ -1349,7 +1347,7 @@ nvc0_bind_buffers_range(struct nvc0_context *nvc0, const unsigned t,
       if (!(nvc0->buffers_valid[t] & mask))
          return false;
       for (i = start; i < end; ++i)
-         pipe_resource_reference(&nvc0->buffers[t][i].buffer, NULL);
+         util_copy_shader_buffer(&nvc0->buffers[t][i], NULL);
       nvc0->buffers_valid[t] &= ~mask;
    }
    nvc0->buffers_dirty[t] |= mask;
diff --git a/src/gallium/drivers/softpipe/sp_state_image.c b/src/gallium/drivers/softpipe/sp_state_image.c
index 553a76a..b7e1f30 100644
--- a/src/gallium/drivers/softpipe/sp_state_image.c
+++ b/src/gallium/drivers/softpipe/sp_state_image.c
@@ -68,12 +68,10 @@ static void softpipe_set_shader_buffers(struct pipe_context *pipe,
       int idx = start + i;
 
       if (buffers) {
-         pipe_resource_reference(&softpipe->tgsi.buffer[shader]->sp_bview[idx].buffer, buffers[i].buffer);
-         softpipe->tgsi.buffer[shader]->sp_bview[idx] = buffers[i];
+         util_copy_shader_buffer(&softpipe->tgsi.buffer[shader]->sp_bview[idx], &buffers[i]);
       }
       else {
-         pipe_resource_reference(&softpipe->tgsi.buffer[shader]->sp_bview[idx].buffer, NULL);
-         memset(&softpipe->tgsi.buffer[shader]->sp_bview[idx], 0, sizeof(struct pipe_shader_buffer));
+         util_copy_shader_buffer(&softpipe->tgsi.buffer[shader]->sp_bview[idx], NULL);
       }
    }
 }
-- 
2.5.5



More information about the mesa-dev mailing list