Mesa (refs/tags/segfault-1): nouveau: introduce nouveau_buffer_malloc helper

Emil Velikov evelikov at kemper.freedesktop.org
Mon Sep 1 00:17:34 UTC 2014


Module: Mesa
Branch: refs/tags/segfault-1
Commit: 4f70a1e89ef311981c3d704d2b8096a725fb2bbc
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4f70a1e89ef311981c3d704d2b8096a725fb2bbc

Author: Emil Velikov <emil.l.velikov at gmail.com>
Date:   Thu Jun 13 10:34:16 2013 +0100

nouveau: introduce nouveau_buffer_malloc helper

note newly mallocated memory is aligned to MIN_BUFFER_MAP_ALIGN

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>

---

 src/gallium/drivers/nouveau/nouveau_buffer.c |   28 +++++++++++++-------------
 src/gallium/drivers/nouveau/nouveau_winsys.h |    2 ++
 src/gallium/drivers/nv50/nv50_screen.c       |    2 +-
 src/gallium/drivers/nvc0/nvc0_screen.c       |    2 +-
 4 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nouveau_buffer.c b/src/gallium/drivers/nouveau/nouveau_buffer.c
index 0741b9b..89ea2de 100644
--- a/src/gallium/drivers/nouveau/nouveau_buffer.c
+++ b/src/gallium/drivers/nouveau/nouveau_buffer.c
@@ -22,6 +22,14 @@ nouveau_transfer(struct pipe_transfer *transfer)
 }
 
 static INLINE boolean
+nouveau_buffer_malloc(struct nv04_resource *buf)
+{
+   if (!buf->data)
+      buf->data = align_malloc(buf->base.width0, NOUVEAU_MIN_BUFFER_MAP_ALIGN);
+   return !!buf->data;
+}
+
+static INLINE boolean
 nouveau_buffer_allocate(struct nouveau_screen *screen,
                         struct nv04_resource *buf, unsigned domain)
 {
@@ -45,13 +53,10 @@ nouveau_buffer_allocate(struct nouveau_screen *screen,
       if (!buf->bo)
          return FALSE;
       NOUVEAU_DRV_STAT(screen, buf_obj_current_bytes_sys, buf->base.width0);
-   }
-   if (domain != NOUVEAU_BO_GART) {
-      if (!buf->data) {
-         buf->data = align_malloc(buf->base.width0, 64);
-         if (!buf->data)
-            return FALSE;
-      }
+   } else {
+      assert(domain == 0);
+      if (!nouveau_buffer_malloc(buf))
+         return FALSE;
    }
    buf->domain = domain;
    if (buf->bo)
@@ -495,20 +500,15 @@ nouveau_user_buffer_create(struct pipe_screen *pscreen, void *ptr,
    return &buffer->base;
 }
 
-/* Like download, but for GART buffers. Merge ? */
 static INLINE boolean
 nouveau_buffer_data_fetch(struct nouveau_context *nv, struct nv04_resource *buf,
                           struct nouveau_bo *bo, unsigned offset, unsigned size)
 {
-   if (!buf->data) {
-      buf->data = MALLOC(size);
-      if (!buf->data)
-         return FALSE;
-   }
+   if (!nouveau_buffer_malloc(buf))
+      return FALSE;
    if (nouveau_bo_map(bo, NOUVEAU_BO_RD, nv->client))
       return FALSE;
    memcpy(buf->data, (uint8_t *)bo->map + offset, size);
-
    return TRUE;
 }
 
diff --git a/src/gallium/drivers/nouveau/nouveau_winsys.h b/src/gallium/drivers/nouveau/nouveau_winsys.h
index faaa524..6d47f47 100644
--- a/src/gallium/drivers/nouveau/nouveau_winsys.h
+++ b/src/gallium/drivers/nouveau/nouveau_winsys.h
@@ -12,6 +12,8 @@
 #define NV04_PFIFO_MAX_PACKET_LEN 2047
 #endif
 
+#define NOUVEAU_MIN_BUFFER_MAP_ALIGN      64
+
 static INLINE uint32_t
 PUSH_AVAIL(struct nouveau_pushbuf *push)
 {
diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c
index 1291083..b6da303 100644
--- a/src/gallium/drivers/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nv50/nv50_screen.c
@@ -177,7 +177,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
       return 1; /* 256 for binding as RT, but that's not possible in GL */
    case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
-      return 64;
+      return NOUVEAU_MIN_BUFFER_MAP_ALIGN;
    case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
    case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
    case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
diff --git a/src/gallium/drivers/nvc0/nvc0_screen.c b/src/gallium/drivers/nvc0/nvc0_screen.c
index 31fde4a..97ce82c 100644
--- a/src/gallium/drivers/nvc0/nvc0_screen.c
+++ b/src/gallium/drivers/nvc0/nvc0_screen.c
@@ -169,7 +169,7 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
       return 1; /* 256 for binding as RT, but that's not possible in GL */
    case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
-      return 64;
+      return NOUVEAU_MIN_BUFFER_MAP_ALIGN;
    case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
    case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
    case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:




More information about the mesa-commit mailing list