gallium: implement pipe_screen for softpipe driver
authorBrian <brian@i915.localnet.net>
Wed, 27 Feb 2008 16:47:46 +0000 (09:47 -0700)
committerBrian <brian@i915.localnet.net>
Wed, 27 Feb 2008 16:47:46 +0000 (09:47 -0700)
src/gallium/drivers/softpipe/Makefile
src/gallium/drivers/softpipe/sp_context.c
src/gallium/drivers/softpipe/sp_screen.c [new file with mode: 0644]
src/gallium/drivers/softpipe/sp_texture.c
src/gallium/drivers/softpipe/sp_texture.h
src/gallium/drivers/softpipe/sp_winsys.h
src/gallium/winsys/dri/intel/intel_winsys_softpipe.c
src/gallium/winsys/xlib/xm_winsys.c

index 539ffb77f55ec5ef18c71dbf48b7414774668435..f32db35d587f2f6a9379ad97c3e96fb1bdc654d8 100644 (file)
@@ -27,6 +27,7 @@ C_SOURCES = \
        sp_quad_output.c \
        sp_quad_stencil.c \
        sp_quad_stipple.c \
+       sp_screen.c \
        sp_state_blend.c \
        sp_state_clip.c \
        sp_state_derived.c \
index 78acf51433a05fe3ccfd487a74dadff5ccf2ce92..4ac1719cbbe48d2ee5663e7bad8aab47e2f38272 100644 (file)
@@ -143,76 +143,31 @@ static void softpipe_destroy( struct pipe_context *pipe )
 }
 
 
+/* XXX these will go away shortly */
 static const char *softpipe_get_name( struct pipe_context *pipe )
 {
-   return "softpipe";
+   return pipe->screen->get_name(pipe->screen);
 }
 
 static const char *softpipe_get_vendor( struct pipe_context *pipe )
 {
-   return "Tungsten Graphics, Inc.";
+   return pipe->screen->get_vendor(pipe->screen);
 }
 
 static int softpipe_get_param(struct pipe_context *pipe, int param)
 {
-   switch (param) {
-   case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
-      return 8;
-   case PIPE_CAP_NPOT_TEXTURES:
-      return 1;
-   case PIPE_CAP_TWO_SIDED_STENCIL:
-      return 1;
-   case PIPE_CAP_GLSL:
-      return 1;
-   case PIPE_CAP_S3TC:
-      return 0;
-   case PIPE_CAP_ANISOTROPIC_FILTER:
-      return 0;
-   case PIPE_CAP_POINT_SPRITE:
-      return 1;
-   case PIPE_CAP_MAX_RENDER_TARGETS:
-      return 1;
-   case PIPE_CAP_OCCLUSION_QUERY:
-      return 1;
-   case PIPE_CAP_TEXTURE_SHADOW_MAP:
-      return 1;
-   case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
-      return 12; /* max 2Kx2K */
-   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
-      return 8;  /* max 128x128x128 */
-   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
-      return 12; /* max 2Kx2K */
-   default:
-      return 0;
-   }
+   return pipe->screen->get_param(pipe->screen, param);
 }
 
 static float softpipe_get_paramf(struct pipe_context *pipe, int param)
 {
-   switch (param) {
-   case PIPE_CAP_MAX_LINE_WIDTH:
-      /* fall-through */
-   case PIPE_CAP_MAX_LINE_WIDTH_AA:
-      return 255.0; /* arbitrary */
-
-   case PIPE_CAP_MAX_POINT_WIDTH:
-      /* fall-through */
-   case PIPE_CAP_MAX_POINT_WIDTH_AA:
-      return 255.0; /* arbitrary */
-
-   case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
-      return 0.0;
-
-   case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
-      return 16.0; /* arbitrary */
-
-   default:
-      return 0;
-   }
+   return pipe->screen->get_paramf(pipe->screen, param);
 }
 
-struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
-                                     struct softpipe_winsys *softpipe_winsys )
+struct pipe_context *
+softpipe_create( struct pipe_screen *screen,
+                 struct pipe_winsys *pipe_winsys,
+                 struct softpipe_winsys *softpipe_winsys )
 {
    struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
    uint i;
@@ -226,6 +181,7 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
    softpipe->dump_fs = GETENV( "GALLIUM_DUMP_FS" ) != NULL;
 
    softpipe->pipe.winsys = pipe_winsys;
+   softpipe->pipe.screen = screen;
    softpipe->pipe.destroy = softpipe_destroy;
 
    /* queries */
diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
new file mode 100644 (file)
index 0000000..cc3b962
--- /dev/null
@@ -0,0 +1,141 @@
+/**************************************************************************
+ * 
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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 TUNGSTEN GRAPHICS 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 "pipe/p_util.h"
+#include "pipe/p_winsys.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_screen.h"
+
+#include "sp_texture.h"
+#include "sp_winsys.h"
+
+
+static const char *
+softpipe_get_vendor(struct pipe_screen *screen)
+{
+   return "Tungsten Graphics, Inc.";
+}
+
+
+static const char *
+softpipe_get_name(struct pipe_screen *screen)
+{
+   return "softpipe";
+}
+
+
+static int
+softpipe_get_param(struct pipe_screen *screen, int param)
+{
+   switch (param) {
+   case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
+      return 8;
+   case PIPE_CAP_NPOT_TEXTURES:
+      return 1;
+   case PIPE_CAP_TWO_SIDED_STENCIL:
+      return 1;
+   case PIPE_CAP_GLSL:
+      return 1;
+   case PIPE_CAP_S3TC:
+      return 0;
+   case PIPE_CAP_ANISOTROPIC_FILTER:
+      return 0;
+   case PIPE_CAP_POINT_SPRITE:
+      return 1;
+   case PIPE_CAP_MAX_RENDER_TARGETS:
+      return 1;
+   case PIPE_CAP_OCCLUSION_QUERY:
+      return 1;
+   case PIPE_CAP_TEXTURE_SHADOW_MAP:
+      return 1;
+   case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
+      return 12; /* max 2Kx2K */
+   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
+      return 8;  /* max 128x128x128 */
+   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
+      return 12; /* max 2Kx2K */
+   default:
+      return 0;
+   }
+}
+
+
+static float
+softpipe_get_paramf(struct pipe_screen *screen, int param)
+{
+   switch (param) {
+   case PIPE_CAP_MAX_LINE_WIDTH:
+      /* fall-through */
+   case PIPE_CAP_MAX_LINE_WIDTH_AA:
+      return 255.0; /* arbitrary */
+   case PIPE_CAP_MAX_POINT_WIDTH:
+      /* fall-through */
+   case PIPE_CAP_MAX_POINT_WIDTH_AA:
+      return 255.0; /* arbitrary */
+   case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
+      return 0.0;
+   case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
+      return 16.0; /* arbitrary */
+   default:
+      return 0;
+   }
+}
+
+
+static void
+softpipe_destroy_screen( struct pipe_screen *screen )
+{
+   FREE(screen);
+}
+
+
+/**
+ * Create a new pipe_screen object
+ * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
+ */
+struct pipe_screen *
+softpipe_create_screen(struct pipe_winsys *winsys)
+{
+   struct pipe_screen *screen = CALLOC_STRUCT(pipe_screen);
+
+   if (!screen)
+      return NULL;
+
+   screen->winsys = winsys;
+
+   screen->destroy = softpipe_destroy_screen;
+
+   screen->get_name = softpipe_get_name;
+   screen->get_vendor = softpipe_get_vendor;
+   screen->get_param = softpipe_get_param;
+   screen->get_paramf = softpipe_get_paramf;
+
+   softpipe_init_screen_texture_funcs(screen);
+
+   return screen;
+}
index 159452196125d615680948a964d0edf322018ef1..f0e8350a4a1e1221fd54dddb00ca80c158184e9c 100644 (file)
@@ -80,23 +80,34 @@ softpipe_texture_layout(struct softpipe_texture * spt)
 }
 
 
+/* XXX temporary */
 static struct pipe_texture *
 softpipe_texture_create(struct pipe_context *pipe,
                         const struct pipe_texture *templat)
 {
+   return pipe->screen->texture_create(pipe->screen, templat);
+}
+
+
+static struct pipe_texture *
+softpipe_texture_create_screen(struct pipe_screen *screen,
+                               const struct pipe_texture *templat)
+{
+   struct pipe_winsys *ws = screen->winsys;
    struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture);
    if (!spt)
       return NULL;
 
    spt->base = *templat;
    spt->base.refcount = 1;
-   spt->base.pipe = pipe;
+   spt->base.pipe = NULL;
+   spt->base.screen = screen;
 
    softpipe_texture_layout(spt);
 
-   spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32,
-                                             PIPE_BUFFER_USAGE_PIXEL,
-                                             spt->buffer_size);
+   spt->buffer = ws->buffer_create(ws, 32,
+                                   PIPE_BUFFER_USAGE_PIXEL,
+                                   spt->buffer_size);
    if (!spt->buffer) {
       FREE(spt);
       return NULL;
@@ -108,8 +119,17 @@ softpipe_texture_create(struct pipe_context *pipe,
 }
 
 
+/* XXX temporary */
 static void
 softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt)
+{
+   return pipe->screen->texture_release(pipe->screen, pt);
+}
+
+
+static void
+softpipe_texture_release_screen(struct pipe_screen *screen,
+                                struct pipe_texture **pt)
 {
    if (!*pt)
       return;
@@ -125,7 +145,7 @@ softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt)
       DBG("%s deleting %p\n", __FUNCTION__, (void *) spt);
       */
 
-      pipe_buffer_reference(pipe->winsys, &spt->buffer, NULL);
+      pipe_buffer_reference(screen->winsys, &spt->buffer, NULL);
 
       FREE(spt);
    }
@@ -150,21 +170,32 @@ softpipe_texture_update(struct pipe_context *pipe,
 /**
  * Called via pipe->get_tex_surface()
  */
+/* XXX temporary */
 static struct pipe_surface *
 softpipe_get_tex_surface(struct pipe_context *pipe,
                          struct pipe_texture *pt,
                          unsigned face, unsigned level, unsigned zslice)
 {
+   return pipe->screen->get_tex_surface(pipe->screen, pt, face, level, zslice);
+}
+
+
+static struct pipe_surface *
+softpipe_get_tex_surface_screen(struct pipe_screen *screen,
+                                struct pipe_texture *pt,
+                                unsigned face, unsigned level, unsigned zslice)
+{
+   struct pipe_winsys *ws = screen->winsys;
    struct softpipe_texture *spt = softpipe_texture(pt);
    struct pipe_surface *ps;
 
    assert(level <= pt->last_level);
 
-   ps = pipe->winsys->surface_alloc(pipe->winsys);
+   ps = ws->surface_alloc(ws);
    if (ps) {
       assert(ps->refcount);
       assert(ps->winsys);
-      pipe_buffer_reference(pipe->winsys, &ps->buffer, spt->buffer);
+      pipe_buffer_reference(ws, &ps->buffer, spt->buffer);
       ps->format = pt->format;
       ps->cpp = pt->cpp;
       ps->width = pt->width[level];
@@ -176,7 +207,8 @@ softpipe_get_tex_surface(struct pipe_context *pipe,
         ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) *
                       (pt->compressed ? ps->height/4 : ps->height) *
                       ps->width * ps->cpp;
-      } else {
+      }
+      else {
         assert(face == 0);
         assert(zslice == 0);
       }
@@ -194,3 +226,12 @@ softpipe_init_texture_funcs( struct softpipe_context *softpipe )
    softpipe->pipe.texture_update = softpipe_texture_update;
    softpipe->pipe.get_tex_surface = softpipe_get_tex_surface;
 }
+
+
+void
+softpipe_init_screen_texture_funcs(struct pipe_screen *screen)
+{
+   screen->texture_create = softpipe_texture_create_screen;
+   screen->texture_release = softpipe_texture_release_screen;
+   screen->get_tex_surface = softpipe_get_tex_surface_screen;
+}
index 01b1e28ec5e060e0706bb8dc882130b7b5ad6fdf..a7322144e6f7f857567747c68c537b753dc5350c 100644 (file)
 #define SP_TEXTURE_H
 
 
+#include "pipe/p_state.h"
+
+
 struct pipe_context;
-struct pipe_texture;
+struct pipe_screen;
+struct softpipe_context;
 
 
 struct softpipe_texture
@@ -58,4 +62,8 @@ extern void
 softpipe_init_texture_funcs( struct softpipe_context *softpipe );
 
 
+extern void
+softpipe_init_screen_texture_funcs(struct pipe_screen *screen);
+
+
 #endif /* SP_TEXTURE */
index d6b379f58c6416fce1cf5e960a16f731694be3c0..80f535480817df6ff7286fcaa4b892457683473b 100644 (file)
@@ -50,8 +50,13 @@ struct pipe_winsys;
 struct pipe_context;
 
 
-struct pipe_context *softpipe_create( struct pipe_winsys *,
+struct pipe_context *softpipe_create( struct pipe_screen *,
+                                      struct pipe_winsys *,
                                      struct softpipe_winsys * );
 
 
+struct pipe_screen *
+softpipe_create_screen(struct pipe_winsys *);
+
+
 #endif /* SP_WINSYS_H */
index 9e483bdc9f58c333eb4a708245dfa7d8718baa1f..0bc2dc40025d7e202c2fe2b1d9a68e5cd06965c2 100644 (file)
@@ -68,6 +68,7 @@ intel_create_softpipe( struct intel_context *intel,
                        struct pipe_winsys *winsys )
 {
    struct intel_softpipe_winsys *isws = CALLOC_STRUCT( intel_softpipe_winsys );
+   struct pipe_screen *screen = softpipe_create_screen(winsys);
    
    /* Fill in this struct with callbacks that softpipe will need to
     * communicate with the window system, buffer manager, etc. 
@@ -77,5 +78,5 @@ intel_create_softpipe( struct intel_context *intel,
 
    /* Create the softpipe context:
     */
-   return softpipe_create( winsys, &isws->sws );
+   return softpipe_create( screen, winsys, &isws->sws );
 }
index 8da596d419e7d8ec726d007e835a36f58401c7f5..adebe4020a1f9a70c610f39e88e42c21ead0a3fb 100644 (file)
@@ -457,7 +457,8 @@ xmesa_create_pipe_context(XMesaContext xmesa, uint pixelformat)
 #endif
    {
       struct softpipe_winsys *spws = xmesa_get_softpipe_winsys(pixelformat);
-      pipe = softpipe_create( pws, spws );
+      struct pipe_screen *screen = softpipe_create_screen(pws);
+      pipe = softpipe_create( screen, pws, spws );
       if (pipe)
          pipe->priv = xmesa;