[Mesa-dev] [PATCH 14/16] svga: flush buffers when mapping for reading

Brian Paul brianp at vmware.com
Tue Jun 28 23:52:18 UTC 2016


With host-side buffer copies (via SVGA3D_vgpu10_BufferCopy()) we have
to make sure any pending map-write operations are completed before reading.
Otherwise the ReadbackSubResource operation could get stale data from
the host buffer.

This allows the piglit arb_copy_buffer-subdata-sync test to pass when
we start using the SVGA3D_vgpu10_BufferCopy command.
---
 src/gallium/drivers/svga/svga_resource_buffer.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_resource_buffer.c b/src/gallium/drivers/svga/svga_resource_buffer.c
index 9ecb975..3c6ee20 100644
--- a/src/gallium/drivers/svga/svga_resource_buffer.c
+++ b/src/gallium/drivers/svga/svga_resource_buffer.c
@@ -95,13 +95,25 @@ svga_buffer_transfer_map(struct pipe_context *pipe,
    transfer->usage = usage;
    transfer->box = *box;
 
-   if ((usage & PIPE_TRANSFER_READ) && sbuf->dirty) {
-      /* Only need to test for vgpu10 since only vgpu10 features (streamout,
-       * buffer copy) can modify buffers on the device.
-       */
-      if (svga_have_vgpu10(svga)) {
+   if (usage & PIPE_TRANSFER_READ) {
+      if (!sbuf->user) {
+         (void) svga_buffer_handle(svga, resource);
+      }
+
+      if (sbuf->dma.pending > 0) {
+         svga_buffer_upload_flush(svga, sbuf);
+         svga_context_finish(svga);
+      }
+
+      if (sbuf->dirty) {
          enum pipe_error ret;
+
+         /* Host-side buffers can only be dirtied with vgpu10 features
+          * (streamout and buffer copy).
+          */
+         assert(svga_have_vgpu10(svga));
          assert(sbuf->handle);
+
          ret = SVGA3D_vgpu10_ReadbackSubResource(svga->swc, sbuf->handle, 0);
          if (ret != PIPE_OK) {
             svga_context_flush(svga, NULL);
-- 
1.9.1



More information about the mesa-dev mailing list