Cell: Add initial texture functions
authorBrian <brian.paul@tungstengraphics.com>
Tue, 22 Jan 2008 03:26:40 +0000 (20:26 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Tue, 22 Jan 2008 04:17:21 +0000 (21:17 -0700)
src/mesa/pipe/cell/ppu/Makefile
src/mesa/pipe/cell/ppu/cell_context.c
src/mesa/pipe/cell/ppu/cell_context.h
src/mesa/pipe/cell/ppu/cell_texture.c [new file with mode: 0644]
src/mesa/pipe/cell/ppu/cell_texture.h [new file with mode: 0644]

index 6a1bd5982f44e8ed8a57b8825b10e642bd53018d..0df07004a4625984335a7eb198289dd401e458f8 100644 (file)
@@ -31,6 +31,7 @@ SOURCES = \
        cell_state_vertex.c \
        cell_spu.c \
        cell_surface.c \
+       cell_texture.c \
        cell_vbuf.c \
        cell_winsys.c
 
index 897c187d6543599104246a6febde24dd9983c1d1..fc1ca28f3a08c8a067a7996a992cdd8dcfad8125 100644 (file)
@@ -46,6 +46,7 @@
 #include "cell_state.h"
 #include "cell_surface.h"
 #include "cell_spu.h"
+#include "cell_texture.h"
 #include "cell_vbuf.h"
 
 
@@ -225,14 +226,17 @@ cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws)
    cell->pipe.clear = cell_clear_surface;
    cell->pipe.flush = cell_flush;
 
+   /* textures */
+   cell->pipe.texture_create = cell_texture_create;
+   cell->pipe.texture_release = cell_texture_release;
+   cell->pipe.get_tex_surface = cell_get_tex_surface;
+
+   cell->pipe.set_sampler_texture = cell_set_sampler_texture;
+
 #if 0
    cell->pipe.begin_query = cell_begin_query;
    cell->pipe.end_query = cell_end_query;
    cell->pipe.wait_query = cell_wait_query;
-
-   /* textures */
-   cell->pipe.mipmap_tree_layout = cell_mipmap_tree_layout;
-   cell->pipe.get_tex_surface = cell_get_tex_surface;
 #endif
 
 
index 08e448f14f6904221201e60563da0db1d996aac3..1937812e2de2c6cb025c337c4854c548ef7b2da7 100644 (file)
@@ -76,7 +76,7 @@ struct cell_context
    struct pipe_framebuffer_state framebuffer;
    struct pipe_poly_stipple poly_stipple;
    struct pipe_scissor_state scissor;
-   struct softpipe_texture *texture[PIPE_MAX_SAMPLERS];
+   struct pipe_texture *texture[PIPE_MAX_SAMPLERS];
    struct pipe_viewport_state viewport;
    struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX];
    struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX];
diff --git a/src/mesa/pipe/cell/ppu/cell_texture.c b/src/mesa/pipe/cell/ppu/cell_texture.c
new file mode 100644 (file)
index 0000000..8f342d8
--- /dev/null
@@ -0,0 +1,168 @@
+/**************************************************************************
+ * 
+ * Copyright 2006 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.
+ * 
+ **************************************************************************/
+ /*
+  * Authors:
+  *   Keith Whitwell <keith@tungstengraphics.com>
+  *   Michel Dänzer <michel@tungstengraphics.com>
+  */
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_inlines.h"
+#include "pipe/p_util.h"
+#include "pipe/p_winsys.h"
+
+#include "cell_context.h"
+#include "cell_state.h"
+#include "cell_texture.h"
+
+
+/* Simple, maximally packed layout.
+ */
+
+static unsigned minify( unsigned d )
+{
+   return MAX2(1, d>>1);
+}
+
+
+static void
+cell_texture_layout(struct cell_texture * spt)
+{
+   struct pipe_texture *pt = &spt->base;
+   unsigned level;
+   unsigned width = pt->width[0];
+   unsigned height = pt->height[0];
+   unsigned depth = pt->depth[0];
+
+   spt->buffer_size = 0;
+
+   for ( level = pt->first_level ; level <= pt->last_level ; level++ ) {
+      pt->width[level] = width;
+      pt->height[level] = height;
+      pt->depth[level] = depth;
+
+      spt->level_offset[level] = spt->buffer_size;
+
+      spt->buffer_size += ((pt->compressed) ? MAX2(1, height/4) : height) *
+                         ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) *
+                         width * pt->cpp;
+
+      width  = minify(width);
+      height = minify(height);
+      depth = minify(depth);
+   }
+}
+
+
+void
+cell_texture_create(struct pipe_context *pipe, struct pipe_texture **pt)
+{
+   struct cell_texture *spt = REALLOC(*pt, sizeof(struct pipe_texture),
+                                         sizeof(struct cell_texture));
+
+   if (spt) {
+      memset(&spt->base + 1, 0,
+            sizeof(struct cell_texture) - sizeof(struct pipe_texture));
+
+      cell_texture_layout(spt);
+
+      spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0);
+
+      if (spt->buffer) {
+        pipe->winsys->buffer_data(pipe->winsys, spt->buffer, spt->buffer_size,
+                                  NULL, PIPE_BUFFER_USAGE_PIXEL);
+      }
+
+      if (!spt->buffer) {
+        FREE(spt);
+        spt = NULL;
+      }
+   }
+
+   *pt = &spt->base;
+}
+
+void
+cell_texture_release(struct pipe_context *pipe, struct pipe_texture **pt)
+{
+   if (!*pt)
+      return;
+
+   /*
+   DBG("%s %p refcount will be %d\n",
+       __FUNCTION__, (void *) *pt, (*pt)->refcount - 1);
+   */
+   if (--(*pt)->refcount <= 0) {
+      struct cell_texture *spt = cell_texture(*pt);
+
+      /*
+      DBG("%s deleting %p\n", __FUNCTION__, (void *) spt);
+      */
+
+      pipe->winsys->buffer_reference(pipe->winsys, &spt->buffer, NULL);
+
+      FREE(spt);
+   }
+   *pt = NULL;
+}
+
+
+/**
+ * Called via pipe->get_tex_surface()
+ */
+struct pipe_surface *
+cell_get_tex_surface(struct pipe_context *pipe,
+                         struct pipe_texture *pt,
+                         unsigned face, unsigned level, unsigned zslice)
+{
+   struct cell_texture *spt = cell_texture(pt);
+   struct pipe_surface *ps;
+
+   ps = pipe->winsys->surface_alloc(pipe->winsys);
+   if (ps) {
+      assert(ps->refcount);
+      assert(ps->winsys);
+      pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, spt->buffer);
+      ps->format = pt->format;
+      ps->cpp = pt->cpp;
+      ps->width = pt->width[level];
+      ps->height = pt->height[level];
+      ps->pitch = ps->width;
+      ps->offset = spt->level_offset[level];
+
+      if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) {
+        ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) *
+                      (pt->compressed ? ps->height/4 : ps->height) *
+                      ps->width * ps->cpp;
+      } else {
+        assert(face == 0);
+        assert(zslice == 0);
+      }
+   }
+   return ps;
+}
diff --git a/src/mesa/pipe/cell/ppu/cell_texture.h b/src/mesa/pipe/cell/ppu/cell_texture.h
new file mode 100644 (file)
index 0000000..97d8bd1
--- /dev/null
@@ -0,0 +1,73 @@
+/**************************************************************************
+ * 
+ * Copyright 2007 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.
+ * 
+ **************************************************************************/
+
+#ifndef CELL_TEXTURE_H
+#define CELL_TEXTURE_H
+
+
+struct pipe_context;
+struct pipe_texture;
+
+
+/**
+ * Subclass of pipe_texture
+ */
+struct cell_texture
+{
+   struct pipe_texture base;
+
+   unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS];
+
+   /* The data is held here:
+    */
+   struct pipe_buffer_handle *buffer;
+   unsigned long buffer_size;
+};
+
+
+/** cast wrapper */
+static INLINE struct cell_texture *
+cell_texture(struct pipe_texture *pt)
+{
+   return (struct cell_texture *) pt;
+}
+
+
+
+extern void
+cell_texture_create(struct pipe_context *pipe, struct pipe_texture **pt);
+
+extern void
+cell_texture_release(struct pipe_context *pipe, struct pipe_texture **pt);
+
+extern struct pipe_surface *
+cell_get_tex_surface(struct pipe_context *pipe,
+                     struct pipe_texture *pt,
+                     unsigned face, unsigned level, unsigned zslice);
+
+
+#endif /* CELL_TEXTURE */