summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2009-05-02 08:38:18 +0100
committerJosé Fonseca <jfonseca@vmware.com>2009-05-02 08:38:18 +0100
commita302c07ab405726df035c752e7fa1e2256e71c91 (patch)
tree66106158491cb9a6b890b55c938c1072b1a7705d
parent986d4a9ec60ee52067b2d6f81c05f8ec3b8dc8b1 (diff)
softpipe: New softpipe_winsys.
Implement software buffers internally. Only display targets are allocated by the winsys.
-rw-r--r--src/gallium/drivers/softpipe/Makefile1
-rw-r--r--src/gallium/drivers/softpipe/SConscript1
-rw-r--r--src/gallium/drivers/softpipe/sp_buffer.c207
-rw-r--r--src/gallium/drivers/softpipe/sp_buffer.h59
-rw-r--r--src/gallium/drivers/softpipe/sp_draw_arrays.c10
-rw-r--r--src/gallium/drivers/softpipe/sp_screen.c12
-rw-r--r--src/gallium/drivers/softpipe/sp_screen.h3
-rw-r--r--src/gallium/drivers/softpipe/sp_winsys.h71
8 files changed, 348 insertions, 16 deletions
diff --git a/src/gallium/drivers/softpipe/Makefile b/src/gallium/drivers/softpipe/Makefile
index 516e3992fd..588aa4ec6a 100644
--- a/src/gallium/drivers/softpipe/Makefile
+++ b/src/gallium/drivers/softpipe/Makefile
@@ -7,6 +7,7 @@ C_SOURCES = \
sp_fs_exec.c \
sp_fs_sse.c \
sp_fs_llvm.c \
+ sp_buffer.c \
sp_clear.c \
sp_flush.c \
sp_query.c \
diff --git a/src/gallium/drivers/softpipe/SConscript b/src/gallium/drivers/softpipe/SConscript
index f8720638a7..1772833e3d 100644
--- a/src/gallium/drivers/softpipe/SConscript
+++ b/src/gallium/drivers/softpipe/SConscript
@@ -8,6 +8,7 @@ softpipe = env.ConvenienceLibrary(
'sp_fs_exec.c',
'sp_fs_sse.c',
'sp_fs_llvm.c',
+ 'sp_buffer.c',
'sp_clear.c',
'sp_context.c',
'sp_draw_arrays.c',
diff --git a/src/gallium/drivers/softpipe/sp_buffer.c b/src/gallium/drivers/softpipe/sp_buffer.c
new file mode 100644
index 0000000000..68beabfa76
--- /dev/null
+++ b/src/gallium/drivers/softpipe/sp_buffer.c
@@ -0,0 +1,207 @@
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include "util/u_memory.h"
+
+#include "sp_winsys.h"
+#include "sp_screen.h"
+#include "sp_texture.h"
+#include "sp_buffer.h"
+
+
+static void *
+softpipe_buffer_map(struct pipe_screen *screen,
+ struct pipe_buffer *buf,
+ unsigned flags)
+{
+ struct softpipe_buffer *softpipe_buf = softpipe_buffer(buf);
+ return softpipe_buf->data;
+}
+
+
+static void
+softpipe_buffer_unmap(struct pipe_screen *screen,
+ struct pipe_buffer *buf)
+{
+}
+
+
+static void
+softpipe_buffer_destroy(struct pipe_buffer *buf)
+{
+ struct softpipe_screen *sscreen = softpipe_screen(buf->screen);
+ struct softpipe_winsys *winsys = sscreen->winsys;
+ struct softpipe_buffer *sbuf = softpipe_buffer(buf);
+
+ if (sbuf->dt)
+ winsys->displaytarget_destroy(winsys, sbuf->dt);
+ else if (!sbuf->userBuffer)
+ align_free(sbuf->data);
+
+ FREE(sbuf);
+}
+
+
+static struct pipe_buffer *
+softpipe_buffer_create(struct pipe_screen *screen,
+ unsigned alignment,
+ unsigned usage,
+ unsigned size)
+{
+ struct softpipe_buffer *buffer = CALLOC_STRUCT(softpipe_buffer);
+
+ pipe_reference_init(&buffer->base.reference, 1);
+ buffer->base.alignment = alignment;
+ buffer->base.usage = usage;
+ buffer->base.size = size;
+
+ buffer->data = align_malloc(size, alignment);
+
+ return &buffer->base;
+}
+
+
+/**
+ * Create buffer which wraps user-space data.
+ */
+static struct pipe_buffer *
+softpipe_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes)
+{
+ struct softpipe_buffer *buffer;
+
+ buffer = CALLOC_STRUCT(softpipe_buffer);
+ if(!buffer)
+ return NULL;
+
+ pipe_reference_init(&buffer->base.reference, 1);
+ buffer->base.size = bytes;
+ buffer->userBuffer = TRUE;
+ buffer->data = ptr;
+
+ return &buffer->base;
+}
+
+
+static struct pipe_buffer *
+softpipe_surface_buffer_create(struct pipe_screen *screen,
+ unsigned width, unsigned height,
+ enum pipe_format format,
+ unsigned usage,
+ unsigned *stride)
+{
+ struct softpipe_screen *sscreen = softpipe_screen(screen);
+ struct softpipe_winsys *winsys = sscreen->winsys;
+ struct softpipe_buffer *buffer;
+
+ buffer = CALLOC_STRUCT(softpipe_buffer);
+ if(!buffer)
+ goto no_buffer;
+
+ pipe_reference_init(&buffer->base.reference, 1);
+ buffer->userBuffer = FALSE;
+
+ buffer->dt = winsys->displaytarget_create(winsys, width, height, format);
+ if(!buffer->dt)
+ goto no_rt;
+
+ buffer->data = buffer->dt->data;
+
+ buffer->base.usage = usage;
+ buffer->base.alignment = 1;
+ buffer->base.size = buffer->dt->size;
+
+ return &buffer->base;
+
+no_rt:
+ FREE(buffer);
+no_buffer:
+ return NULL;
+}
+
+
+static void
+softpipe_flush_frontbuffer(struct pipe_screen *screen,
+ struct pipe_surface *surface,
+ void *context_private)
+{
+ struct softpipe_screen *sscreen = softpipe_screen(screen);
+ struct softpipe_winsys *winsys = sscreen->winsys;
+ struct softpipe_texture *st = softpipe_texture(surface->texture);
+ struct softpipe_buffer *sbuf = softpipe_buffer(st->buffer);
+
+ assert(sbuf->dt);
+ if (sbuf->dt)
+ winsys->displaytarget_display(winsys, sbuf->dt, context_private);
+}
+
+
+static void
+softpipe_fence_reference(struct pipe_screen *screen,
+ struct pipe_fence_handle **ptr,
+ struct pipe_fence_handle *fence)
+{
+}
+
+
+static int
+softpipe_fence_signalled(struct pipe_screen *screen,
+ struct pipe_fence_handle *fence,
+ unsigned flag)
+{
+ return 0;
+}
+
+
+static int
+softpipe_fence_finish(struct pipe_screen *screen,
+ struct pipe_fence_handle *fence,
+ unsigned flag)
+{
+ return 0;
+}
+
+
+void
+softpipe_init_screen_buffer_funcs(struct pipe_screen *screen)
+{
+ screen->buffer_create = softpipe_buffer_create;
+ screen->user_buffer_create = softpipe_user_buffer_create;
+ screen->buffer_map = softpipe_buffer_map;
+ screen->buffer_unmap = softpipe_buffer_unmap;
+ screen->buffer_destroy = softpipe_buffer_destroy;
+
+ screen->surface_buffer_create = softpipe_surface_buffer_create;
+ screen->flush_frontbuffer = softpipe_flush_frontbuffer;
+
+ screen->fence_reference = softpipe_fence_reference;
+ screen->fence_signalled = softpipe_fence_signalled;
+ screen->fence_finish = softpipe_fence_finish;
+
+}
diff --git a/src/gallium/drivers/softpipe/sp_buffer.h b/src/gallium/drivers/softpipe/sp_buffer.h
new file mode 100644
index 0000000000..2f53a1849b
--- /dev/null
+++ b/src/gallium/drivers/softpipe/sp_buffer.h
@@ -0,0 +1,59 @@
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef SP_BUFFER_H
+#define SP_BUFFER_H
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_state.h"
+
+
+struct softpipe_rendertarget;
+
+
+struct softpipe_buffer
+{
+ struct pipe_buffer base;
+ boolean userBuffer; /** Is this a user-space buffer? */
+ struct softpipe_displaytarget *dt;
+ void *data;
+};
+
+
+/** Cast wrapper */
+static INLINE struct softpipe_buffer *
+softpipe_buffer( struct pipe_buffer *buf )
+{
+ return (struct softpipe_buffer *)buf;
+}
+
+
+void
+softpipe_init_screen_buffer_funcs(struct pipe_screen *screen);
+
+
+#endif /* SP_BUFFER_H */
diff --git a/src/gallium/drivers/softpipe/sp_draw_arrays.c b/src/gallium/drivers/softpipe/sp_draw_arrays.c
index f117096bf7..bfb31e41df 100644
--- a/src/gallium/drivers/softpipe/sp_draw_arrays.c
+++ b/src/gallium/drivers/softpipe/sp_draw_arrays.c
@@ -46,13 +46,13 @@
static void
softpipe_map_constant_buffers(struct softpipe_context *sp)
{
- struct pipe_winsys *ws = sp->pipe.winsys;
+ struct pipe_screen *screen = sp->pipe.screen;
uint i, size;
for (i = 0; i < PIPE_SHADER_TYPES; i++) {
if (sp->constants[i].buffer && sp->constants[i].buffer->size)
- sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer,
- PIPE_BUFFER_USAGE_CPU_READ);
+ sp->mapped_constants[i] = screen->buffer_map(screen, sp->constants[i].buffer,
+ PIPE_BUFFER_USAGE_CPU_READ);
}
if (sp->constants[PIPE_SHADER_VERTEX].buffer)
@@ -68,7 +68,7 @@ softpipe_map_constant_buffers(struct softpipe_context *sp)
static void
softpipe_unmap_constant_buffers(struct softpipe_context *sp)
{
- struct pipe_winsys *ws = sp->pipe.winsys;
+ struct pipe_screen *screen = sp->pipe.screen;
uint i;
/* really need to flush all prims since the vert/frag shaders const buffers
@@ -80,7 +80,7 @@ softpipe_unmap_constant_buffers(struct softpipe_context *sp)
for (i = 0; i < 2; i++) {
if (sp->constants[i].buffer && sp->constants[i].buffer->size)
- ws->buffer_unmap(ws, sp->constants[i].buffer);
+ screen->buffer_unmap(screen, sp->constants[i].buffer);
sp->mapped_constants[i] = NULL;
}
}
diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
index 7380a6ae2b..ec0ff2a94d 100644
--- a/src/gallium/drivers/softpipe/sp_screen.c
+++ b/src/gallium/drivers/softpipe/sp_screen.c
@@ -33,6 +33,7 @@
#include "pipe/p_screen.h"
#include "sp_texture.h"
+#include "sp_buffer.h"
#include "sp_winsys.h"
#include "sp_screen.h"
@@ -142,12 +143,13 @@ softpipe_is_format_supported( struct pipe_screen *screen,
static void
softpipe_destroy_screen( struct pipe_screen *screen )
{
- struct pipe_winsys *winsys = screen->winsys;
+ struct softpipe_screen *sscreen = softpipe_screen(screen);
+ struct softpipe_winsys *winsys = sscreen->winsys;
if(winsys->destroy)
winsys->destroy(winsys);
- FREE(screen);
+ FREE(sscreen);
}
@@ -157,14 +159,14 @@ softpipe_destroy_screen( struct pipe_screen *screen )
* Note: we're not presently subclassing pipe_screen (no softpipe_screen).
*/
struct pipe_screen *
-softpipe_create_screen(struct pipe_winsys *winsys)
+softpipe_create_screen(struct softpipe_winsys *winsys)
{
struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
if (!screen)
return NULL;
- screen->base.winsys = winsys;
+ screen->winsys = winsys;
screen->base.destroy = softpipe_destroy_screen;
@@ -175,7 +177,7 @@ softpipe_create_screen(struct pipe_winsys *winsys)
screen->base.is_format_supported = softpipe_is_format_supported;
softpipe_init_screen_texture_funcs(&screen->base);
- u_simple_screen_init(&screen->base);
+ softpipe_init_screen_buffer_funcs(&screen->base);
return &screen->base;
}
diff --git a/src/gallium/drivers/softpipe/sp_screen.h b/src/gallium/drivers/softpipe/sp_screen.h
index 3d4bfd3e84..0693a754e2 100644
--- a/src/gallium/drivers/softpipe/sp_screen.h
+++ b/src/gallium/drivers/softpipe/sp_screen.h
@@ -35,10 +35,13 @@
#include "pipe/p_defines.h"
+struct softpipe_winsys;
struct softpipe_screen {
struct pipe_screen base;
+ struct softpipe_winsys *winsys;
+
/* Increments whenever textures are modified. Contexts can track
* this.
*/
diff --git a/src/gallium/drivers/softpipe/sp_winsys.h b/src/gallium/drivers/softpipe/sp_winsys.h
index 9e571862b7..bdc714b283 100644
--- a/src/gallium/drivers/softpipe/sp_winsys.h
+++ b/src/gallium/drivers/softpipe/sp_winsys.h
@@ -25,9 +25,10 @@
*
**************************************************************************/
-/* This is the interface that softpipe requires any window system
- * hosting it to implement. This is the only include file in softpipe
- * which is public.
+/**
+ * @file
+ *
+ * This is the only include file in softpipe which is public.
*/
@@ -35,21 +36,79 @@
#define SP_WINSYS_H
+#include "pipe/p_compiler.h" // for boolean
+#include "pipe/p_format.h"
+
+
#ifdef __cplusplus
extern "C" {
#endif
struct pipe_screen;
-struct pipe_winsys;
struct pipe_context;
-struct pipe_context *softpipe_create( struct pipe_screen * );
+struct softpipe_displaytarget
+{
+ enum pipe_format format;
+ unsigned width;
+ unsigned height;
+ unsigned stride;
+ unsigned size;
+ void *data;
+};
+
+
+/**
+ * This is the interface that softpipe expects any window system
+ * hosting it to implement.
+ *
+ * Softpipe is for the most part a self suficient driver. The only thing it
+ * does not know is how to display a surface.
+ */
+struct softpipe_winsys
+{
+ void
+ (*destroy)( struct softpipe_winsys *ws );
+
+ boolean
+ (*is_displaytarget_format_supported)( struct softpipe_winsys *ws,
+ enum pipe_format format );
+
+ /**
+ * Allocate storage for a render target.
+ *
+ * Often surfaces which are meant to be blitted to the front screen (i.e.,
+ * display targets) must be allocated with special characteristics, memory
+ * pools, or obtained directly from the windowing system.
+ *
+ * This callback is invoked by the pipe_screen when creating a texture marked
+ * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
+ * storage.
+ */
+ struct softpipe_displaytarget *
+ (*displaytarget_create)( struct softpipe_winsys *ws,
+ unsigned width, unsigned height,
+ enum pipe_format format );
+
+ void
+
+ (*displaytarget_display)( struct softpipe_winsys *ws,
+ struct softpipe_displaytarget *dt,
+ void *context_private );
+ void
+ (*displaytarget_destroy)( struct softpipe_winsys *ws,
+ struct softpipe_displaytarget *dt );
+};
+
+
+struct pipe_context *
+softpipe_create( struct pipe_screen * );
struct pipe_screen *
-softpipe_create_screen(struct pipe_winsys *);
+softpipe_create_screen( struct softpipe_winsys * );
boolean