diff options
author | Joakim Sindholt <[email protected]> | 2009-02-18 20:32:40 +0100 |
---|---|---|
committer | Michel Dänzer <[email protected]> | 2009-02-18 23:23:30 +0100 |
commit | 310ea0354c75be693874bd63b5508eb7b3107f27 (patch) | |
tree | 1b9b1bb631663e6731666c09ef093f16fa94b5f0 | |
parent | dac19f17f360b730a0e6d651ef2e5b03c59b9b53 (diff) |
r300-gallium: implement simple pipe_transfer Basically make the driver compile and behave like it did before the gallium-texture-transfer merge
-rw-r--r-- | src/gallium/drivers/r300/r300_context.h | 3 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_screen.c | 92 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_screen.h | 15 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_surface.c | 8 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_texture.c | 8 |
5 files changed, 104 insertions, 22 deletions
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index a3727c8fb47..fc32f8f669a 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -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; diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c index d7354ad893e..de3e80daf93 100644 --- a/src/gallium/drivers/r300/r300_screen.c +++ b/src/gallium/drivers/r300/r300_screen.c @@ -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); diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h index 2e25f61dbf1..6c845144cb3 100644 --- a/src/gallium/drivers/r300/r300_screen.h +++ b/src/gallium/drivers/r300/r300_screen.h @@ -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); diff --git a/src/gallium/drivers/r300/r300_surface.c b/src/gallium/drivers/r300/r300_surface.c index b2c4f4251d9..e4589cc5836 100644 --- a/src/gallium/drivers/r300/r300_surface.c +++ b/src/gallium/drivers/r300/r300_surface.c @@ -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 */ diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index bd35e089f98..edd43706634 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -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); |