r300-gallium: implement simple pipe_transfer Basically make the driver compile and...
authorJoakim Sindholt <opensource@zhasha.com>
Wed, 18 Feb 2009 19:32:40 +0000 (20:32 +0100)
committerMichel Dänzer <daenzer@vmware.com>
Wed, 18 Feb 2009 22:23:30 +0000 (23:23 +0100)
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r300/r300_screen.h
src/gallium/drivers/r300/r300_surface.c
src/gallium/drivers/r300/r300_texture.c

index a3727c8fb47f563ed5fcebb71fca972a84df51f2..fc32f8f669af7b823d5c7934d09777ce69b123a5 100644 (file)
@@ -181,6 +181,9 @@ struct r300_texture {
     /* Offsets into the buffer. */
     unsigned offset[PIPE_MAX_TEXTURE_LEVELS];
 
+    /* Stride (pitch?) of this texture in bytes */
+    unsigned stride;
+    
     /* Total size of this texture, in bytes. */
     unsigned size;
 
index d7354ad893e1295afd15f744bd6e0ac8955c1069..de3e80daf93d84d8382284f2d16be9385918ead9 100644 (file)
@@ -221,24 +221,92 @@ static boolean r300_is_format_supported(struct pipe_screen* pscreen,
     return FALSE;
 }
 
-static void* r300_surface_map(struct pipe_screen* screen,
-                              struct pipe_surface* surface,
-                              unsigned flags)
+static struct pipe_transfer*
+r300_get_tex_transfer(struct pipe_screen *screen,
+                      struct pipe_texture *texture,
+                      unsigned face, unsigned level, unsigned zslice,
+                      enum pipe_transfer_usage usage, unsigned x, unsigned y,
+                      unsigned w, unsigned h)
 {
-    struct r300_texture* tex = (struct r300_texture*)surface->texture;
-    char* map = pipe_buffer_map(screen, tex->buffer, flags);
+    struct r300_texture *tex = (struct r300_texture *)texture;
+    struct r300_transfer *trans;
+    unsigned offset;  /* in bytes */
+
+    /* XXX Add support for these things */
+    if (texture->target == PIPE_TEXTURE_CUBE) {
+        debug_printf("PIPE_TEXTURE_CUBE is not yet supported.\n");
+        /* offset = tex->image_offset[level][face]; */
+    }
+    else if (texture->target == PIPE_TEXTURE_3D) {
+        debug_printf("PIPE_TEXTURE_3D is not yet supported.\n");
+        /* offset = tex->image_offset[level][zslice]; */
+    }
+    else {
+        offset = tex->offset[level];
+        assert(face == 0);
+        assert(zslice == 0);
+    }
+
+    trans = CALLOC_STRUCT(r300_transfer);
+    if (trans) {
+        trans->transfer.refcount = 1;
+        pipe_texture_reference(&trans->transfer.texture, texture);
+        trans->transfer.format = trans->transfer.format;
+        trans->transfer.width = w;
+        trans->transfer.height = h;
+        trans->transfer.block = texture->block;
+        trans->transfer.nblocksx = texture->nblocksx[level];
+        trans->transfer.nblocksy = texture->nblocksy[level];
+        trans->transfer.stride = tex->stride;
+        trans->transfer.usage = usage;
+        trans->offset = offset;
+    }
+    return &trans->transfer;
+}
+
+static void
+r300_tex_transfer_release(struct pipe_screen *screen,
+                          struct pipe_transfer **transfer)
+{
+   struct pipe_transfer *trans = *transfer;
+
+   if (--trans->refcount == 0) {
+      pipe_texture_reference(&trans->texture, NULL);
+      FREE(trans);
+   }
+
+   *transfer = NULL;
+}
+
+static void* r300_transfer_map(struct pipe_screen* screen,
+                              struct pipe_transfer* transfer)
+{
+    struct r300_texture* tex = (struct r300_texture*)transfer->texture;
+    char* map;
+    unsigned flags = 0;
+
+    if (transfer->usage != PIPE_TRANSFER_WRITE) {
+        flags |= PIPE_BUFFER_USAGE_CPU_READ;
+    }
+    if (transfer->usage != PIPE_TRANSFER_READ) {
+        flags |= PIPE_BUFFER_USAGE_CPU_WRITE;
+    }
+    
+    map = pipe_buffer_map(screen, tex->buffer, flags);
 
     if (!map) {
         return NULL;
     }
 
-    return map + surface->offset;
+    return map + r300_transfer(transfer)->offset +
+        transfer->y / transfer->block.height * transfer->stride +
+        transfer->x / transfer->block.width * transfer->block.size;
 }
 
-static void r300_surface_unmap(struct pipe_screen* screen,
-                               struct pipe_surface* surface)
+static void r300_transfer_unmap(struct pipe_screen* screen,
+                                struct pipe_transfer* transfer)
 {
-    struct r300_texture* tex = (struct r300_texture*)surface->texture;
+    struct r300_texture* tex = (struct r300_texture*)transfer->texture;
     pipe_buffer_unmap(screen, tex->buffer);
 }
 
@@ -272,8 +340,10 @@ struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys,
     r300screen->screen.get_param = r300_get_param;
     r300screen->screen.get_paramf = r300_get_paramf;
     r300screen->screen.is_format_supported = r300_is_format_supported;
-    r300screen->screen.surface_map = r300_surface_map;
-    r300screen->screen.surface_unmap = r300_surface_unmap;
+    r300screen->screen.get_tex_transfer = r300_get_tex_transfer;
+    r300screen->screen.tex_transfer_release = r300_tex_transfer_release;
+    r300screen->screen.transfer_map = r300_transfer_map;
+    r300screen->screen.transfer_unmap = r300_transfer_unmap;
 
     r300_init_screen_texture_functions(&r300screen->screen);
     u_simple_screen_init(&r300screen->screen);
index 2e25f61dbf136517dd73da52739bd74d1ce5cbe3..6c845144cb3a53b09870ab8943a23b4c43b5e969 100644 (file)
@@ -40,11 +40,26 @@ struct r300_screen {
     struct r300_capabilities* caps;
 };
 
+struct r300_transfer {
+    /* Parent class */
+    struct pipe_transfer transfer;
+
+    /* Offset from start of buffer. */
+    unsigned offset;
+};
+
 /* Convenience cast wrapper. */
 static struct r300_screen* r300_screen(struct pipe_screen* screen) {
     return (struct r300_screen*)screen;
 }
 
+/* Convenience cast wrapper. */
+static INLINE struct r300_transfer*
+r300_transfer(struct pipe_transfer* transfer)
+{
+    return (struct r300_transfer*)transfer;
+}
+
 /* Creates a new r300 screen. */
 struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys,
                                        struct r300_winsys* r300_winsys);
index b2c4f4251d99805a8ff267e71b3f9faa3d8db7be..e4589cc5836d5ed9fdc4e241fd8ff9305e625d7c 100644 (file)
@@ -42,17 +42,17 @@ static void r300_surface_fill(struct pipe_context* pipe,
     b = (float)((color >>  0) & 0xff) / 255.0f;
     debug_printf("r300: Filling surface %p at (%d,%d),"
         " dimensions %dx%d (stride %d), color 0x%x\n",
-        dest, x, y, w, h, dest->stride, color);
+        dest, x, y, w, h, tex->stride, color);
 
     /* Fallback? */
-    if (0) {
+    /*if (0) {
         debug_printf("r300: Falling back on surface clear...");
         void* map = pipe->screen->surface_map(pipe->screen, dest,
             PIPE_BUFFER_USAGE_CPU_WRITE);
         pipe_fill_rect(map, &dest->block, &dest->stride, x, y, w, h, color);
         pipe->screen->surface_unmap(pipe->screen, dest);
         return;
-    }
+    }*/
 
     BEGIN_CS(163 + (caps->is_r500 ? 22 : 14) + (caps->has_tcl ? 4 : 2));
     /* Flush PVS. */
@@ -293,7 +293,7 @@ static void r300_surface_fill(struct pipe_context* pipe,
     OUT_CS_RELOC(tex->buffer, 0, 0, RADEON_GEM_DOMAIN_VRAM, 0);
     /* XXX (dest->stride >> 2) should be the buffer width in pixels however,
      * this little calculation is only good as long as the buffer is 32bpp */
-    OUT_CS_REG(R300_RB3D_COLORPITCH0, (dest->stride >> 2) |
+    OUT_CS_REG(R300_RB3D_COLORPITCH0, (tex->stride >> 2) |
         R300_COLOR_FORMAT_ARGB8888);
     OUT_CS_REG(RB3D_COLOR_CHANNEL_MASK, 0x0000000F);
     /* XXX Packet3 */
index bd35e089f98ca026dadee1a340dbbd0586fdb157..edd437066340e956a6c730f883eb080c89ae75e8 100644 (file)
@@ -124,12 +124,6 @@ static struct pipe_surface* r300_get_tex_surface(struct pipe_screen* screen,
         surface->format = texture->format;
         surface->width = texture->width[level];
         surface->height = texture->height[level];
-        surface->block = texture->block;
-        surface->nblocksx = texture->nblocksx[level];
-        surface->nblocksy = texture->nblocksy[level];
-        /* XXX save the actual stride instead plz kthnxbai */
-        surface->stride =
-            (texture->nblocksx[level] * texture->block.size + 63) & ~63;
         surface->offset = offset;
         surface->usage = flags;
         surface->status = PIPE_SURFACE_STATUS_DEFINED;
@@ -176,7 +170,7 @@ static struct pipe_texture*
     tex->tex.refcount = 1;
     tex->tex.screen = screen;
 
-    /* XXX tex->stride = *stride; */
+    tex->stride = *stride;
 
     pipe_buffer_reference(screen, &tex->buffer, buffer);