[Mesa-dev,05/19] mesa/st: start adding memory object support

Submitted by Andres Rodriguez on June 30, 2017, 11:02 p.m.

Details

Message ID 20170630230312.23213-6-andresx7@gmail.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Andres Rodriguez June 30, 2017, 11:02 p.m.
From: Dave Airlie <airlied@redhat.com>

---
 src/mesa/Makefile.sources                    |  2 +
 src/mesa/state_tracker/st_cb_memoryobjects.c | 65 ++++++++++++++++++++++++++++
 src/mesa/state_tracker/st_cb_memoryobjects.h | 25 +++++++++++
 src/mesa/state_tracker/st_context.c          |  2 +
 4 files changed, 94 insertions(+)
 create mode 100644 src/mesa/state_tracker/st_cb_memoryobjects.c
 create mode 100644 src/mesa/state_tracker/st_cb_memoryobjects.h

Patch hide | download patch | download mbox

diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index 2ee1d2f..2e4b04c 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -467,6 +467,8 @@  STATETRACKER_FILES = \
 	state_tracker/st_cb_feedback.h \
 	state_tracker/st_cb_flush.c \
 	state_tracker/st_cb_flush.h \
+	state_tracker/st_cb_memoryobjects.c \
+	state_tracker/st_cb_memoryobjects.h \
 	state_tracker/st_cb_msaa.c \
 	state_tracker/st_cb_msaa.h \
 	state_tracker/st_cb_perfmon.c \
diff --git a/src/mesa/state_tracker/st_cb_memoryobjects.c b/src/mesa/state_tracker/st_cb_memoryobjects.c
new file mode 100644
index 0000000..cc2aa81
--- /dev/null
+++ b/src/mesa/state_tracker/st_cb_memoryobjects.c
@@ -0,0 +1,65 @@ 
+#include "main/imports.h"
+#include "main/mtypes.h"
+
+#include "main/externalobjects.h"
+
+#include "st_context.h"
+#include "st_cb_memoryobjects.h"
+
+#include "state_tracker/drm_driver.h"
+#include "pipe/p_context.h"
+#include "pipe/p_screen.h"
+
+static struct gl_memory_object *
+st_memoryobj_alloc(struct gl_context *ctx, GLuint name)
+{
+   struct st_memory_object *st_obj = ST_CALLOC_STRUCT(st_memory_object);
+   if (!st_obj)
+      return NULL;
+
+   _mesa_initialize_memory_object(ctx, &st_obj->Base, name);
+   return &st_obj->Base;
+}
+
+static void
+st_memoryobj_free(struct gl_context *ctx,
+                  struct gl_memory_object *obj)
+{
+   _mesa_delete_memory_object(ctx, obj);
+}
+
+
+static void
+st_import_memoryobj_fd(struct gl_context *ctx,
+                       struct gl_memory_object *obj,
+                       GLuint64 size,
+                       int fd)
+{
+   struct st_memory_object *st_obj = st_memory_object(obj);
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
+   struct pipe_screen *screen = pipe->screen;
+   struct winsys_handle whandle;
+
+   whandle.type = DRM_API_HANDLE_TYPE_FD;
+   whandle.handle = fd;
+   whandle.offset = 0;
+   whandle.layer = 0;
+   whandle.stride = 0;
+
+   st_obj->memory = screen->memobj_create_from_handle(screen,
+                                                      &whandle);
+
+   /* We own fd, but we no longer need it. So get rid of it */
+   close(fd);
+}
+
+void
+st_init_memoryobject_functions(struct dd_function_table *functions)
+{
+   _mesa_init_memory_object_functions(functions);
+
+   functions->NewMemoryObject = st_memoryobj_alloc;
+   functions->DeleteMemoryObject = st_memoryobj_free;
+   functions->ImportMemoryObjectFd = st_import_memoryobj_fd;
+}
diff --git a/src/mesa/state_tracker/st_cb_memoryobjects.h b/src/mesa/state_tracker/st_cb_memoryobjects.h
new file mode 100644
index 0000000..6606516
--- /dev/null
+++ b/src/mesa/state_tracker/st_cb_memoryobjects.h
@@ -0,0 +1,25 @@ 
+#ifndef ST_CB_MEMORYOBJECTS_H
+#define ST_CB_MEMORYOBJECTS_H
+
+#include "main/compiler.h"
+#include "main/mtypes.h"
+
+struct dd_function_table;
+struct pipe_screen;
+
+struct st_memory_object
+{
+   struct gl_memory_object Base;
+   struct pipe_memory_object *memory;
+};
+
+static inline struct st_memory_object *
+st_memory_object(struct gl_memory_object *obj)
+{
+   return (struct st_memory_object *)obj;
+}
+
+extern void
+st_init_memoryobject_functions(struct dd_function_table *functions);
+
+#endif
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index f535139..a846be3 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -53,6 +53,7 @@ 
 #include "st_cb_eglimage.h"
 #include "st_cb_fbo.h"
 #include "st_cb_feedback.h"
+#include "st_cb_memoryobjects.h"
 #include "st_cb_msaa.h"
 #include "st_cb_perfmon.h"
 #include "st_cb_program.h"
@@ -660,6 +661,7 @@  void st_init_driver_functions(struct pipe_screen *screen,
 
    st_init_fbo_functions(functions);
    st_init_feedback_functions(functions);
+   st_init_memoryobject_functions(functions);
    st_init_msaa_functions(functions);
    st_init_perfmon_functions(functions);
    st_init_program_functions(functions);

Comments

On 01.07.2017 01:02, Andres Rodriguez wrote:
> From: Dave Airlie <airlied@redhat.com>
> 
> ---
>   src/mesa/Makefile.sources                    |  2 +
>   src/mesa/state_tracker/st_cb_memoryobjects.c | 65 ++++++++++++++++++++++++++++
>   src/mesa/state_tracker/st_cb_memoryobjects.h | 25 +++++++++++
>   src/mesa/state_tracker/st_context.c          |  2 +
>   4 files changed, 94 insertions(+)
>   create mode 100644 src/mesa/state_tracker/st_cb_memoryobjects.c
>   create mode 100644 src/mesa/state_tracker/st_cb_memoryobjects.h
> 
> diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
> index 2ee1d2f..2e4b04c 100644
> --- a/src/mesa/Makefile.sources
> +++ b/src/mesa/Makefile.sources
> @@ -467,6 +467,8 @@ STATETRACKER_FILES = \
>   	state_tracker/st_cb_feedback.h \
>   	state_tracker/st_cb_flush.c \
>   	state_tracker/st_cb_flush.h \
> +	state_tracker/st_cb_memoryobjects.c \
> +	state_tracker/st_cb_memoryobjects.h \
>   	state_tracker/st_cb_msaa.c \
>   	state_tracker/st_cb_msaa.h \
>   	state_tracker/st_cb_perfmon.c \
> diff --git a/src/mesa/state_tracker/st_cb_memoryobjects.c b/src/mesa/state_tracker/st_cb_memoryobjects.c
> new file mode 100644
> index 0000000..cc2aa81
> --- /dev/null
> +++ b/src/mesa/state_tracker/st_cb_memoryobjects.c
> @@ -0,0 +1,65 @@
> +#include "main/imports.h"
> +#include "main/mtypes.h"
> +
> +#include "main/externalobjects.h"
> +
> +#include "st_context.h"
> +#include "st_cb_memoryobjects.h"
> +
> +#include "state_tracker/drm_driver.h"
> +#include "pipe/p_context.h"
> +#include "pipe/p_screen.h"
> +
> +static struct gl_memory_object *
> +st_memoryobj_alloc(struct gl_context *ctx, GLuint name)
> +{
> +   struct st_memory_object *st_obj = ST_CALLOC_STRUCT(st_memory_object);
> +   if (!st_obj)
> +      return NULL;
> +
> +   _mesa_initialize_memory_object(ctx, &st_obj->Base, name);
> +   return &st_obj->Base;
> +}
> +
> +static void
> +st_memoryobj_free(struct gl_context *ctx,
> +                  struct gl_memory_object *obj)
> +{
> +   _mesa_delete_memory_object(ctx, obj);
> +}
> +
> +
> +static void
> +st_import_memoryobj_fd(struct gl_context *ctx,
> +                       struct gl_memory_object *obj,
> +                       GLuint64 size,
> +                       int fd)
> +{
> +   struct st_memory_object *st_obj = st_memory_object(obj);
> +   struct st_context *st = st_context(ctx);
> +   struct pipe_context *pipe = st->pipe;
> +   struct pipe_screen *screen = pipe->screen;
> +   struct winsys_handle whandle;
> +
> +   whandle.type = DRM_API_HANDLE_TYPE_FD;
> +   whandle.handle = fd;
> +   whandle.offset = 0;
> +   whandle.layer = 0;
> +   whandle.stride = 0;
> +
> +   st_obj->memory = screen->memobj_create_from_handle(screen,
> +                                                      &whandle);
> +
> +   /* We own fd, but we no longer need it. So get rid of it */
> +   close(fd);

I've only been skimming this so far, but this seems inconsistent with 
the gallium docs in the previous patch.

Cheers,
Nicolai


> +}
> +
> +void
> +st_init_memoryobject_functions(struct dd_function_table *functions)
> +{
> +   _mesa_init_memory_object_functions(functions);
> +
> +   functions->NewMemoryObject = st_memoryobj_alloc;
> +   functions->DeleteMemoryObject = st_memoryobj_free;
> +   functions->ImportMemoryObjectFd = st_import_memoryobj_fd;
> +}
> diff --git a/src/mesa/state_tracker/st_cb_memoryobjects.h b/src/mesa/state_tracker/st_cb_memoryobjects.h
> new file mode 100644
> index 0000000..6606516
> --- /dev/null
> +++ b/src/mesa/state_tracker/st_cb_memoryobjects.h
> @@ -0,0 +1,25 @@
> +#ifndef ST_CB_MEMORYOBJECTS_H
> +#define ST_CB_MEMORYOBJECTS_H
> +
> +#include "main/compiler.h"
> +#include "main/mtypes.h"
> +
> +struct dd_function_table;
> +struct pipe_screen;
> +
> +struct st_memory_object
> +{
> +   struct gl_memory_object Base;
> +   struct pipe_memory_object *memory;
> +};
> +
> +static inline struct st_memory_object *
> +st_memory_object(struct gl_memory_object *obj)
> +{
> +   return (struct st_memory_object *)obj;
> +}
> +
> +extern void
> +st_init_memoryobject_functions(struct dd_function_table *functions);
> +
> +#endif
> diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
> index f535139..a846be3 100644
> --- a/src/mesa/state_tracker/st_context.c
> +++ b/src/mesa/state_tracker/st_context.c
> @@ -53,6 +53,7 @@
>   #include "st_cb_eglimage.h"
>   #include "st_cb_fbo.h"
>   #include "st_cb_feedback.h"
> +#include "st_cb_memoryobjects.h"
>   #include "st_cb_msaa.h"
>   #include "st_cb_perfmon.h"
>   #include "st_cb_program.h"
> @@ -660,6 +661,7 @@ void st_init_driver_functions(struct pipe_screen *screen,
>   
>      st_init_fbo_functions(functions);
>      st_init_feedback_functions(functions);
> +   st_init_memoryobject_functions(functions);
>      st_init_msaa_functions(functions);
>      st_init_perfmon_functions(functions);
>      st_init_program_functions(functions);
>
On 2017-07-04 09:04 AM, Nicolai Hähnle wrote:
> On 01.07.2017 01:02, Andres Rodriguez wrote:
>> From: Dave Airlie <airlied@redhat.com>
>>
>> ---
>>   src/mesa/Makefile.sources                    |  2 +
>>   src/mesa/state_tracker/st_cb_memoryobjects.c | 65 
>> ++++++++++++++++++++++++++++
>>   src/mesa/state_tracker/st_cb_memoryobjects.h | 25 +++++++++++
>>   src/mesa/state_tracker/st_context.c          |  2 +
>>   4 files changed, 94 insertions(+)
>>   create mode 100644 src/mesa/state_tracker/st_cb_memoryobjects.c
>>   create mode 100644 src/mesa/state_tracker/st_cb_memoryobjects.h
>>
>> diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
>> index 2ee1d2f..2e4b04c 100644
>> --- a/src/mesa/Makefile.sources
>> +++ b/src/mesa/Makefile.sources
>> @@ -467,6 +467,8 @@ STATETRACKER_FILES = \
>>       state_tracker/st_cb_feedback.h \
>>       state_tracker/st_cb_flush.c \
>>       state_tracker/st_cb_flush.h \
>> +    state_tracker/st_cb_memoryobjects.c \
>> +    state_tracker/st_cb_memoryobjects.h \
>>       state_tracker/st_cb_msaa.c \
>>       state_tracker/st_cb_msaa.h \
>>       state_tracker/st_cb_perfmon.c \
>> diff --git a/src/mesa/state_tracker/st_cb_memoryobjects.c 
>> b/src/mesa/state_tracker/st_cb_memoryobjects.c
>> new file mode 100644
>> index 0000000..cc2aa81
>> --- /dev/null
>> +++ b/src/mesa/state_tracker/st_cb_memoryobjects.c
>> @@ -0,0 +1,65 @@
>> +#include "main/imports.h"
>> +#include "main/mtypes.h"
>> +
>> +#include "main/externalobjects.h"
>> +
>> +#include "st_context.h"
>> +#include "st_cb_memoryobjects.h"
>> +
>> +#include "state_tracker/drm_driver.h"
>> +#include "pipe/p_context.h"
>> +#include "pipe/p_screen.h"
>> +
>> +static struct gl_memory_object *
>> +st_memoryobj_alloc(struct gl_context *ctx, GLuint name)
>> +{
>> +   struct st_memory_object *st_obj = ST_CALLOC_STRUCT(st_memory_object);
>> +   if (!st_obj)
>> +      return NULL;
>> +
>> +   _mesa_initialize_memory_object(ctx, &st_obj->Base, name);
>> +   return &st_obj->Base;
>> +}
>> +
>> +static void
>> +st_memoryobj_free(struct gl_context *ctx,
>> +                  struct gl_memory_object *obj)
>> +{
>> +   _mesa_delete_memory_object(ctx, obj);
>> +}
>> +
>> +
>> +static void
>> +st_import_memoryobj_fd(struct gl_context *ctx,
>> +                       struct gl_memory_object *obj,
>> +                       GLuint64 size,
>> +                       int fd)
>> +{
>> +   struct st_memory_object *st_obj = st_memory_object(obj);
>> +   struct st_context *st = st_context(ctx);
>> +   struct pipe_context *pipe = st->pipe;
>> +   struct pipe_screen *screen = pipe->screen;
>> +   struct winsys_handle whandle;
>> +
>> +   whandle.type = DRM_API_HANDLE_TYPE_FD;
>> +   whandle.handle = fd;
>> +   whandle.offset = 0;
>> +   whandle.layer = 0;
>> +   whandle.stride = 0;
>> +
>> +   st_obj->memory = screen->memobj_create_from_handle(screen,
>> +                                                      &whandle);
>> +
>> +   /* We own fd, but we no longer need it. So get rid of it */
>> +   close(fd);
> 
> I've only been skimming this so far, but this seems inconsistent with 
> the gallium docs in the previous patch.
> 

Thanks. Seems like I forgot to update the comments for this section. 
Although piping it down to gallium might be better for consistency with 
the extension.

Regards,
Andres

> Cheers,
> Nicolai
> 
> 
>> +}
>> +
>> +void
>> +st_init_memoryobject_functions(struct dd_function_table *functions)
>> +{
>> +   _mesa_init_memory_object_functions(functions);
>> +
>> +   functions->NewMemoryObject = st_memoryobj_alloc;
>> +   functions->DeleteMemoryObject = st_memoryobj_free;
>> +   functions->ImportMemoryObjectFd = st_import_memoryobj_fd;
>> +}
>> diff --git a/src/mesa/state_tracker/st_cb_memoryobjects.h 
>> b/src/mesa/state_tracker/st_cb_memoryobjects.h
>> new file mode 100644
>> index 0000000..6606516
>> --- /dev/null
>> +++ b/src/mesa/state_tracker/st_cb_memoryobjects.h
>> @@ -0,0 +1,25 @@
>> +#ifndef ST_CB_MEMORYOBJECTS_H
>> +#define ST_CB_MEMORYOBJECTS_H
>> +
>> +#include "main/compiler.h"
>> +#include "main/mtypes.h"
>> +
>> +struct dd_function_table;
>> +struct pipe_screen;
>> +
>> +struct st_memory_object
>> +{
>> +   struct gl_memory_object Base;
>> +   struct pipe_memory_object *memory;
>> +};
>> +
>> +static inline struct st_memory_object *
>> +st_memory_object(struct gl_memory_object *obj)
>> +{
>> +   return (struct st_memory_object *)obj;
>> +}
>> +
>> +extern void
>> +st_init_memoryobject_functions(struct dd_function_table *functions);
>> +
>> +#endif
>> diff --git a/src/mesa/state_tracker/st_context.c 
>> b/src/mesa/state_tracker/st_context.c
>> index f535139..a846be3 100644
>> --- a/src/mesa/state_tracker/st_context.c
>> +++ b/src/mesa/state_tracker/st_context.c
>> @@ -53,6 +53,7 @@
>>   #include "st_cb_eglimage.h"
>>   #include "st_cb_fbo.h"
>>   #include "st_cb_feedback.h"
>> +#include "st_cb_memoryobjects.h"
>>   #include "st_cb_msaa.h"
>>   #include "st_cb_perfmon.h"
>>   #include "st_cb_program.h"
>> @@ -660,6 +661,7 @@ void st_init_driver_functions(struct pipe_screen 
>> *screen,
>>      st_init_fbo_functions(functions);
>>      st_init_feedback_functions(functions);
>> +   st_init_memoryobject_functions(functions);
>>      st_init_msaa_functions(functions);
>>      st_init_perfmon_functions(functions);
>>      st_init_program_functions(functions);
>>
> 
>