Re: [Mesa-dev] [PATCH 12/24] mesa/st: implement memory objects as a backend for buffer objects

2017-07-28 Thread Samuel Pitoiset

Reviewed-by: Samuel Pitoiset 

On 07/27/2017 03:08 PM, Timothy Arceri wrote:

From: Andres Rodriguez 

Use a memory object instead of user memory.

Signed-off-by: Andres Rodriguez 
Reviewed-by: Timothy Arceri 
---
  src/mesa/main/dd.h   | 12 +
  src/mesa/state_tracker/st_cb_bufferobjects.c | 66 +---
  2 files changed, 61 insertions(+), 17 deletions(-)

diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 9cdc4a945e..512873434e 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -1090,20 +1090,32 @@ struct dd_function_table {
  
 /**

  * Set the given memory object as the texture's storage.
  */
 GLboolean (*SetTextureStorageForMemoryObject)(struct gl_context *ctx,
   struct gl_texture_object 
*tex_obj,
   struct gl_memory_object 
*mem_obj,
   GLsizei levels, GLsizei 
width,
   GLsizei height, GLsizei 
depth,
   GLuint64 offset);
+
+   /**
+* Use a memory object as the backing data for a buffer object
+*/
+   GLboolean (*BufferDataMem)(struct gl_context *ctx,
+  GLenum target,
+  GLsizeiptrARB size,
+  struct gl_memory_object *memObj,
+  GLuint64 offset,
+  GLenum usage,
+  struct gl_buffer_object *bufObj);
+
 /*@}*/
  
 /**

  * \name GL_EXT_external_objects_fd interface
  */
 /*@{*/
 /**
  * Called to import a memory object. The caller relinquishes ownership
  * of fd after the call returns.
  *
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c 
b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 1fa9389b32..d8e2a5cfe7 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -33,20 +33,21 @@
  
  #include   /* for PRId64 macro */
  
  #include "main/imports.h"

  #include "main/mtypes.h"
  #include "main/arrayobj.h"
  #include "main/bufferobj.h"
  
  #include "st_context.h"

  #include "st_cb_bufferobjects.h"
+#include "st_cb_memoryobjects.h"
  #include "st_debug.h"
  
  #include "pipe/p_context.h"

  #include "pipe/p_defines.h"
  #include "util/u_inlines.h"
  
  
  /**

   * There is some duplication between mesa's bufferobjects and our
   * bufmgr buffers.  Both have an integer handle and a hashtable to
@@ -156,41 +157,36 @@ st_bufferobj_get_subdata(struct gl_context *ctx,
  
 if (!st_obj->buffer) {

/* we probably ran out of memory during buffer allocation */
return;
 }
  
 pipe_buffer_read(st_context(ctx)->pipe, st_obj->buffer,

  offset, size, data);
  }
  
-

-/**
- * Allocate space for and store data in a buffer object.  Any data that was
- * previously stored in the buffer object is lost.  If data is NULL,
- * memory will be allocated, but no copy will occur.
- * Called via ctx->Driver.BufferData().
- * \return GL_TRUE for success, GL_FALSE if out of memory
- */
-static GLboolean
-st_bufferobj_data(struct gl_context *ctx,
-  GLenum target,
-  GLsizeiptrARB size,
-  const void *data,
-  GLenum usage,
-  GLbitfield storageFlags,
-  struct gl_buffer_object *obj)
+static ALWAYS_INLINE GLboolean
+bufferobj_data(struct gl_context *ctx,
+   GLenum target,
+   GLsizeiptrARB size,
+   const void *data,
+   struct gl_memory_object *memObj,
+   GLuint64 offset,
+   GLenum usage,
+   GLbitfield storageFlags,
+   struct gl_buffer_object *obj)
  {
 struct st_context *st = st_context(ctx);
 struct pipe_context *pipe = st->pipe;
 struct pipe_screen *screen = pipe->screen;
 struct st_buffer_object *st_obj = st_buffer_object(obj);
+   struct st_memory_object *st_mem_obj = st_memory_object(memObj);
 unsigned bind, pipe_usage, pipe_flags = 0;
  
 if (target != GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD &&

 size && st_obj->buffer &&
 st_obj->Base.Size == size &&
 st_obj->Base.Usage == usage &&
 st_obj->Base.StorageFlags == storageFlags) {
if (data) {
   /* Just discard the old contents and write new data.
* This should be the same as creating a new buffer, but we avoid
@@ -310,21 +306,26 @@ st_bufferobj_data(struct gl_context *ctx,
buffer.target = PIPE_BUFFER;
buffer.format = PIPE_FORMAT_R8_UNORM; /* want TYPELESS or similar */
buffer.bind = bind;
buffer.usage = pipe_usage;
buffer.flags = pipe_flags;
buffer.width0 = size;
buffer.height0 = 1;
buffer.dept

Re: [Mesa-dev] [PATCH 12/24] mesa/st: implement memory objects as a backend for buffer objects

2017-07-26 Thread Samuel Pitoiset



On 07/26/2017 01:46 PM, Timothy Arceri wrote:

From: Andres Rodriguez 

Use a memory object instead of user memory.

Signed-off-by: Andres Rodriguez 
Reviewed-by: Timothy Arceri 
---
  src/mesa/main/dd.h   | 12 +
  src/mesa/state_tracker/st_cb_bufferobjects.c | 66 +---
  2 files changed, 61 insertions(+), 17 deletions(-)

diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index ec7a195..27c6efc 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -1096,6 +1096,18 @@ struct dd_function_table {
   struct gl_memory_object 
*mem_obj,
   GLsizei levels, GLsizei 
width, GLsizei height,
   GLsizei depth, GLuint64 
offset);
+
+   /**
+* Use a memory object as the backing data for a buffer object
+*/
+   GLboolean (*BufferDataMem)(struct gl_context *ctx,
+  GLenum target,
+  GLsizeiptrARB size,
+  struct gl_memory_object *memObj,
+  GLuint64 offset,
+  GLenum usage,
+  struct gl_buffer_object *bufObj);
+
 /*@}*/
  
 /**

diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c 
b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 68ec250..940c65d 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -40,6 +40,7 @@
  
  #include "st_context.h"

  #include "st_cb_bufferobjects.h"
+#include "st_cb_memoryobjects.h"
  #include "st_debug.h"
  
  #include "pipe/p_context.h"

@@ -163,27 +164,22 @@ st_bufferobj_get_subdata(struct gl_context *ctx,
  offset, size, data);
  }
  
-

-/**
- * Allocate space for and store data in a buffer object.  Any data that was
- * previously stored in the buffer object is lost.  If data is NULL,
- * memory will be allocated, but no copy will occur.
- * Called via ctx->Driver.BufferData().
- * \return GL_TRUE for success, GL_FALSE if out of memory
- */
-static GLboolean
-st_bufferobj_data(struct gl_context *ctx,
-  GLenum target,
-  GLsizeiptrARB size,
-  const void * data,


Extra space.


-  GLenum usage,
-  GLbitfield storageFlags,
-  struct gl_buffer_object *obj)
+static ALWAYS_INLINE GLboolean
+bufferobj_data(struct gl_context *ctx,
+   GLenum target,
+   GLsizeiptrARB size,
+   const void * data,
+   struct gl_memory_object *memObj,
+   GLuint64 offset,
+   GLenum usage,
+   GLbitfield storageFlags,
+   struct gl_buffer_object *obj)
  {
 struct st_context *st = st_context(ctx);
 struct pipe_context *pipe = st->pipe;
 struct pipe_screen *screen = pipe->screen;
 struct st_buffer_object *st_obj = st_buffer_object(obj);
+   struct st_memory_object *st_mem_obj = st_memory_object(memObj);
 unsigned bind, pipe_usage, pipe_flags = 0;
  
 if (target != GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD &&

@@ -317,7 +313,12 @@ st_bufferobj_data(struct gl_context *ctx,
buffer.depth0 = 1;
buffer.array_size = 1;
  
-  if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {

+  if (st_mem_obj) {
+ st_obj->buffer = screen->resource_from_memobj(screen, &buffer,
+   st_mem_obj->memory,
+   offset);
+  }
+  else if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {
   st_obj->buffer =
  screen->resource_from_user_memory(screen, &buffer, (void*)data);
}
@@ -352,6 +353,36 @@ st_bufferobj_data(struct gl_context *ctx,
 return GL_TRUE;
  }
  
+/**

+ * Allocate space for and store data in a buffer object.  Any data that was
+ * previously stored in the buffer object is lost.  If data is NULL,
+ * memory will be allocated, but no copy will occur.
+ * Called via ctx->Driver.BufferData().
+ * \return GL_TRUE for success, GL_FALSE if out of memory
+ */
+static GLboolean
+st_bufferobj_data(struct gl_context *ctx,
+  GLenum target,
+  GLsizeiptrARB size,
+  const void * data,


Extra space.

With these nitpicks fixed, patch is:

Reviewed-by: Samuel Pitoiset 


+  GLenum usage,
+  GLbitfield storageFlags,
+  struct gl_buffer_object *obj)
+{
+   return bufferobj_data(ctx, target, size, data, NULL, 0, usage, 
storageFlags, obj);
+}
+
+static GLboolean
+st_bufferobj_data_mem(struct gl_context *ctx,
+  GLenum target,
+  GLsizeiptrARB size,
+  struct gl_memory_object *memObj,
+  GLuint64 offset,
+