#include "pipe/p_defines.h"
#include "util/u_inlines.h"
+#include "util/u_cpu_detect.h"
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
+#include "util/u_simple_list.h"
#include "util/u_transfer.h"
#include "lp_context.h"
#include "lp_tile_image.h"
#include "lp_texture.h"
#include "lp_setup.h"
+#include "lp_state.h"
#include "state_tracker/sw_winsys.h"
+#ifdef DEBUG
+static struct llvmpipe_resource resource_list;
+#endif
+static unsigned id_counter = 0;
+
+
static INLINE boolean
resource_is_texture(const struct pipe_resource *resource)
{
case PIPE_BUFFER:
return FALSE;
case PIPE_TEXTURE_1D:
+ case PIPE_TEXTURE_1D_ARRAY:
case PIPE_TEXTURE_2D:
+ case PIPE_TEXTURE_2D_ARRAY:
+ case PIPE_TEXTURE_RECT:
case PIPE_TEXTURE_3D:
case PIPE_TEXTURE_CUBE:
return TRUE;
*/
static boolean
llvmpipe_texture_layout(struct llvmpipe_screen *screen,
- struct llvmpipe_resource *lpr)
+ struct llvmpipe_resource *lpr,
+ boolean allocate)
{
struct pipe_resource *pt = &lpr->base;
unsigned level;
unsigned width = pt->width0;
unsigned height = pt->height0;
unsigned depth = pt->depth0;
+ uint64_t total_size = 0;
+ unsigned layers = pt->array_size;
assert(LP_MAX_TEXTURE_2D_LEVELS <= LP_MAX_TEXTURE_LEVELS);
assert(LP_MAX_TEXTURE_3D_LEVELS <= LP_MAX_TEXTURE_LEVELS);
/* For non-compressed formats we need to align the texture size
* to the tile size to facilitate render-to-texture.
+ * XXX this blows up 1d/1d array textures by unreasonable
+ * amount (factor 64), probably should do something about it.
*/
if (util_format_is_compressed(pt->format))
alignment = 1;
lpr->row_stride[level] = align(nblocksx * block_size, 16);
- lpr->img_stride[level] = lpr->row_stride[level] * nblocksy * block_size;
+ /* if row_stride * height > LP_MAX_TEXTURE_SIZE */
+ if (lpr->row_stride[level] > LP_MAX_TEXTURE_SIZE / nblocksy) {
+ /* image too large */
+ goto fail;
+ }
+
+ lpr->img_stride[level] = lpr->row_stride[level] * nblocksy;
}
/* Size of the image in tiles (for tiled layout) */
lpr->tiles_per_image[level] = width_t * height_t;
}
- /* Number of 3D image slices or cube faces */
+ /* Number of 3D image slices, cube faces or texture array layers */
{
unsigned num_slices;
num_slices = 6;
else if (lpr->base.target == PIPE_TEXTURE_3D)
num_slices = depth;
+ else if (lpr->base.target == PIPE_TEXTURE_1D_ARRAY ||
+ lpr->base.target == PIPE_TEXTURE_2D_ARRAY)
+ num_slices = layers;
else
num_slices = 1;
lpr->num_slices_faces[level] = num_slices;
- lpr->layout[level] = alloc_layout_array(num_slices, width, height);
+ if (allocate) {
+ lpr->layout[level] = alloc_layout_array(num_slices, width, height);
+ if (!lpr->layout[level]) {
+ goto fail;
+ }
+ }
+ }
+
+ /* if img_stride * num_slices_faces > LP_MAX_TEXTURE_SIZE */
+ if (lpr->img_stride[level] >
+ LP_MAX_TEXTURE_SIZE / lpr->num_slices_faces[level]) {
+ /* volume too large */
+ goto fail;
+ }
+
+ total_size += (uint64_t) lpr->num_slices_faces[level]
+ * (uint64_t) lpr->img_stride[level];
+ if (total_size > LP_MAX_TEXTURE_SIZE) {
+ goto fail;
}
/* Compute size of next mipmap level */
}
return TRUE;
+
+fail:
+ for (level = 0; level <= pt->last_level; level++) {
+ FREE(lpr->layout[level]);
+ }
+
+ return FALSE;
}
+/**
+ * Check the size of the texture specified by 'res'.
+ * \return TRUE if OK, FALSE if too large.
+ */
+static boolean
+llvmpipe_can_create_resource(struct pipe_screen *screen,
+ const struct pipe_resource *res)
+{
+ struct llvmpipe_resource lpr;
+ memset(&lpr, 0, sizeof(lpr));
+ lpr.base = *res;
+ return llvmpipe_texture_layout(llvmpipe_screen(screen), &lpr, FALSE);
+}
+
static boolean
llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen,
*/
const unsigned width = align(lpr->base.width0, TILE_SIZE);
const unsigned height = align(lpr->base.height0, TILE_SIZE);
- const unsigned width_t = align(width, TILE_SIZE) / TILE_SIZE;
- const unsigned height_t = align(height, TILE_SIZE) / TILE_SIZE;
+ const unsigned width_t = width / TILE_SIZE;
+ const unsigned height_t = height / TILE_SIZE;
lpr->tiles_per_row[0] = width_t;
lpr->tiles_per_image[0] = width_t * height_t;
lpr->img_stride[0] = 0;
lpr->layout[0] = alloc_layout_array(1, width, height);
- //lpr->layout[0][0] = LP_TEX_LAYOUT_LINEAR;
+ if (!lpr->layout[0]) {
+ return FALSE;
+ }
lpr->dt = winsys->displaytarget_create(winsys,
lpr->base.bind,
16,
&lpr->row_stride[0] );
- return lpr->dt != NULL;
+ if (lpr->dt == NULL)
+ return FALSE;
+
+ {
+ void *map = winsys->displaytarget_map(winsys, lpr->dt,
+ PIPE_TRANSFER_WRITE);
+
+ if (map)
+ memset(map, 0, height * lpr->row_stride[0]);
+
+ winsys->displaytarget_unmap(winsys, lpr->dt);
+ }
+
+ return TRUE;
}
llvmpipe_resource_create(struct pipe_screen *_screen,
const struct pipe_resource *templat)
{
- static unsigned id_counter = 0;
struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
struct llvmpipe_resource *lpr = CALLOC_STRUCT(llvmpipe_resource);
if (!lpr)
pipe_reference_init(&lpr->base.reference, 1);
lpr->base.screen = &screen->base;
- assert(lpr->base.bind);
+ /* assert(lpr->base.bind); */
if (resource_is_texture(&lpr->base)) {
if (lpr->base.bind & PIPE_BIND_DISPLAY_TARGET) {
}
else {
/* texture map */
- if (!llvmpipe_texture_layout(screen, lpr))
+ if (!llvmpipe_texture_layout(screen, lpr, TRUE))
goto fail;
assert(lpr->layout[0][0] == LP_TEX_LAYOUT_NONE);
}
/* other data (vertex buffer, const buffer, etc) */
const enum pipe_format format = templat->format;
const uint w = templat->width0 / util_format_get_blockheight(format);
+ /* XXX buffers should only have one dimension, those values should be 1 */
const uint h = templat->height0 / util_format_get_blockwidth(format);
const uint d = templat->depth0;
const uint bpp = util_format_get_blocksize(format);
lpr->data = align_malloc(bytes, 16);
if (!lpr->data)
goto fail;
+ memset(lpr->data, 0, bytes);
}
lpr->id = id_counter++;
+#ifdef DEBUG
+ insert_at_tail(&resource_list, lpr);
+#endif
+
return &lpr->base;
fail:
static void
llvmpipe_resource_destroy(struct pipe_screen *pscreen,
- struct pipe_resource *pt)
+ struct pipe_resource *pt)
{
struct llvmpipe_screen *screen = llvmpipe_screen(pscreen);
struct llvmpipe_resource *lpr = llvmpipe_resource(pt);
struct sw_winsys *winsys = screen->winsys;
winsys->displaytarget_destroy(winsys, lpr->dt);
- if (lpr->tiled[0].data) {
- align_free(lpr->tiled[0].data);
- lpr->tiled[0].data = NULL;
+ if (lpr->tiled_img.data) {
+ align_free(lpr->tiled_img.data);
+ lpr->tiled_img.data = NULL;
}
FREE(lpr->layout[0]);
uint level;
/* free linear image data */
- for (level = 0; level < Elements(lpr->linear); level++) {
- if (lpr->linear[level].data) {
- align_free(lpr->linear[level].data);
- lpr->linear[level].data = NULL;
- }
+ if (lpr->linear_img.data) {
+ align_free(lpr->linear_img.data);
+ lpr->linear_img.data = NULL;
}
/* free tiled image data */
- for (level = 0; level < Elements(lpr->tiled); level++) {
- if (lpr->tiled[level].data) {
- align_free(lpr->tiled[level].data);
- lpr->tiled[level].data = NULL;
- }
+ if (lpr->tiled_img.data) {
+ align_free(lpr->tiled_img.data);
+ lpr->tiled_img.data = NULL;
}
/* free layout flag arrays */
- for (level = 0; level < Elements(lpr->tiled); level++) {
+ for (level = 0; level < Elements(lpr->layout); level++) {
FREE(lpr->layout[level]);
lpr->layout[level] = NULL;
}
align_free(lpr->data);
}
+#ifdef DEBUG
+ if (lpr->next)
+ remove_from_list(lpr);
+#endif
+
FREE(lpr);
}
*/
void *
llvmpipe_resource_map(struct pipe_resource *resource,
- unsigned face,
- unsigned level,
- unsigned zslice,
+ unsigned level,
+ unsigned layer,
enum lp_texture_usage tex_usage,
enum lp_texture_layout layout)
{
struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
uint8_t *map;
- assert(face < 6);
assert(level < LP_MAX_TEXTURE_LEVELS);
+ assert(layer < (u_minify(resource->depth0, level) + resource->array_size - 1));
assert(tex_usage == LP_TEX_USAGE_READ ||
tex_usage == LP_TEX_USAGE_READ_WRITE ||
dt_usage = PIPE_TRANSFER_READ_WRITE;
}
- assert(face == 0);
assert(level == 0);
- assert(zslice == 0);
+ assert(layer == 0);
/* FIXME: keep map count? */
map = winsys->displaytarget_map(winsys, lpr->dt, dt_usage);
/* install this linear image in texture data structure */
- lpr->linear[level].data = map;
+ lpr->linear_img.data = map;
/* make sure tiled data gets converted to linear data */
map2 = llvmpipe_get_texture_image(lpr, 0, 0, tex_usage, layout);
return map2;
}
else if (resource_is_texture(resource)) {
- /* regular texture */
- if (resource->target != PIPE_TEXTURE_CUBE) {
- assert(face == 0);
- }
- if (resource->target != PIPE_TEXTURE_3D) {
- assert(zslice == 0);
- }
- map = llvmpipe_get_texture_image(lpr, face + zslice, level,
+ map = llvmpipe_get_texture_image(lpr, layer, level,
tex_usage, layout);
- assert(map);
return map;
}
else {
*/
void
llvmpipe_resource_unmap(struct pipe_resource *resource,
- unsigned face,
unsigned level,
- unsigned zslice)
+ unsigned layer)
{
struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
struct llvmpipe_screen *lp_screen = llvmpipe_screen(resource->screen);
struct sw_winsys *winsys = lp_screen->winsys;
- assert(face == 0);
assert(level == 0);
- assert(zslice == 0);
+ assert(layer == 0);
/* make sure linear image is up to date */
- (void) llvmpipe_get_texture_image(lpr, face + zslice, level,
+ (void) llvmpipe_get_texture_image(lpr, layer, level,
LP_TEX_USAGE_READ,
LP_TEX_LAYOUT_LINEAR);
static struct pipe_resource *
llvmpipe_resource_from_handle(struct pipe_screen *screen,
- const struct pipe_resource *template,
- struct winsys_handle *whandle)
+ const struct pipe_resource *template,
+ struct winsys_handle *whandle)
{
struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys;
- struct llvmpipe_resource *lpr = CALLOC_STRUCT(llvmpipe_resource);
- if (!lpr)
- return NULL;
+ struct llvmpipe_resource *lpr;
+ unsigned width, height, width_t, height_t;
+
+ /* XXX Seems like from_handled depth textures doesn't work that well */
+
+ lpr = CALLOC_STRUCT(llvmpipe_resource);
+ if (!lpr) {
+ goto no_lpr;
+ }
lpr->base = *template;
pipe_reference_init(&lpr->base.reference, 1);
lpr->base.screen = screen;
+ width = align(lpr->base.width0, TILE_SIZE);
+ height = align(lpr->base.height0, TILE_SIZE);
+ width_t = width / TILE_SIZE;
+ height_t = height / TILE_SIZE;
+
+ /*
+ * Looks like unaligned displaytargets work just fine,
+ * at least sampler/render ones.
+ */
+#if 0
+ assert(lpr->base.width0 == width);
+ assert(lpr->base.height0 == height);
+#endif
+
+ lpr->tiles_per_row[0] = width_t;
+ lpr->tiles_per_image[0] = width_t * height_t;
+ lpr->num_slices_faces[0] = 1;
+ lpr->img_stride[0] = 0;
+
lpr->dt = winsys->displaytarget_from_handle(winsys,
template,
whandle,
&lpr->row_stride[0]);
- if (!lpr->dt)
- goto fail;
+ if (!lpr->dt) {
+ goto no_dt;
+ }
+
+ lpr->layout[0] = alloc_layout_array(1, lpr->base.width0, lpr->base.height0);
+ if (!lpr->layout[0]) {
+ goto no_layout_0;
+ }
+
+ assert(lpr->layout[0][0] == LP_TEX_LAYOUT_NONE);
+
+ lpr->id = id_counter++;
+
+#ifdef DEBUG
+ insert_at_tail(&resource_list, lpr);
+#endif
return &lpr->base;
- fail:
+no_layout_0:
+ winsys->displaytarget_destroy(winsys, lpr->dt);
+no_dt:
FREE(lpr);
+no_lpr:
return NULL;
}
static struct pipe_surface *
-llvmpipe_get_tex_surface(struct pipe_screen *screen,
- struct pipe_resource *pt,
- unsigned face, unsigned level, unsigned zslice,
- enum lp_texture_usage usage)
+llvmpipe_create_surface(struct pipe_context *pipe,
+ struct pipe_resource *pt,
+ const struct pipe_surface *surf_tmpl)
{
struct pipe_surface *ps;
- assert(level <= pt->last_level);
+ assert(surf_tmpl->u.tex.level <= pt->last_level);
ps = CALLOC_STRUCT(pipe_surface);
if (ps) {
pipe_reference_init(&ps->reference, 1);
pipe_resource_reference(&ps->texture, pt);
- ps->format = pt->format;
- ps->width = u_minify(pt->width0, level);
- ps->height = u_minify(pt->height0, level);
- ps->usage = usage;
-
- ps->face = face;
- ps->level = level;
- ps->zslice = zslice;
+ ps->context = pipe;
+ ps->format = surf_tmpl->format;
+ ps->width = u_minify(pt->width0, surf_tmpl->u.tex.level);
+ ps->height = u_minify(pt->height0, surf_tmpl->u.tex.level);
+ ps->usage = surf_tmpl->usage;
+
+ ps->u.tex.level = surf_tmpl->u.tex.level;
+ ps->u.tex.first_layer = surf_tmpl->u.tex.first_layer;
+ ps->u.tex.last_layer = surf_tmpl->u.tex.last_layer;
}
return ps;
}
static void
-llvmpipe_tex_surface_destroy(struct pipe_surface *surf)
+llvmpipe_surface_destroy(struct pipe_context *pipe,
+ struct pipe_surface *surf)
{
/* Effectively do the texture_update work here - if texture images
* needed post-processing to put them into hardware layout, this is
}
-static struct pipe_transfer *
-llvmpipe_get_transfer(struct pipe_context *pipe,
- struct pipe_resource *resource,
- struct pipe_subresource sr,
- unsigned usage,
- const struct pipe_box *box)
+static void *
+llvmpipe_transfer_map( struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **transfer )
{
- struct llvmpipe_resource *lprex = llvmpipe_resource(resource);
- struct llvmpipe_transfer *lpr;
+ struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
+ struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen);
+ struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
+ struct llvmpipe_transfer *lpt;
+ struct pipe_transfer *pt;
+ ubyte *map;
+ enum pipe_format format;
+ enum lp_texture_usage tex_usage;
+ const char *mode;
assert(resource);
- assert(sr.level <= resource->last_level);
+ assert(level <= resource->last_level);
/*
* Transfers, like other pipe operations, must happen in order, so flush the
boolean read_only = !(usage & PIPE_TRANSFER_WRITE);
boolean do_not_block = !!(usage & PIPE_TRANSFER_DONTBLOCK);
if (!llvmpipe_flush_resource(pipe, resource,
- sr.face, sr.level,
- 0, /* flush_flags */
+ level,
+ box->depth > 1 ? -1 : box->z,
read_only,
TRUE, /* cpu_access */
- do_not_block)) {
+ do_not_block,
+ __FUNCTION__)) {
/*
* It would have blocked, but state tracker requested no to.
*/
}
}
- lpr = CALLOC_STRUCT(llvmpipe_transfer);
- if (lpr) {
- struct pipe_transfer *pt = &lpr->base;
- pipe_resource_reference(&pt->resource, resource);
- pt->box = *box;
- pt->sr = sr;
- pt->stride = lprex->row_stride[sr.level];
- pt->usage = usage;
-
- return pt;
- }
- return NULL;
-}
-
+ if (resource == llvmpipe->constants[PIPE_SHADER_FRAGMENT][0])
+ llvmpipe->dirty |= LP_NEW_CONSTANTS;
-static void
-llvmpipe_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- /* Effectively do the texture_update work here - if texture images
- * needed post-processing to put them into hardware layout, this is
- * where it would happen. For llvmpipe, nothing to do.
- */
- assert (transfer->resource);
- pipe_resource_reference(&transfer->resource, NULL);
- FREE(transfer);
-}
-
-
-static void *
-llvmpipe_transfer_map( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
-{
- struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen);
- ubyte *map;
- struct llvmpipe_resource *lpr;
- enum pipe_format format;
- enum lp_texture_usage tex_usage;
- const char *mode;
+ lpt = CALLOC_STRUCT(llvmpipe_transfer);
+ if (!lpt)
+ return NULL;
+ pt = &lpt->base;
+ pipe_resource_reference(&pt->resource, resource);
+ pt->box = *box;
+ pt->level = level;
+ pt->stride = lpr->row_stride[level];
+ pt->layer_stride = lpr->img_stride[level];
+ pt->usage = usage;
+ *transfer = pt;
- assert(transfer->sr.face < 6);
- assert(transfer->sr.level < LP_MAX_TEXTURE_LEVELS);
+ assert(level < LP_MAX_TEXTURE_LEVELS);
/*
printf("tex_transfer_map(%d, %d %d x %d of %d x %d, usage %d )\n",
transfer->usage);
*/
- if (transfer->usage == PIPE_TRANSFER_READ) {
+ if (usage == PIPE_TRANSFER_READ) {
tex_usage = LP_TEX_USAGE_READ;
mode = "read";
}
}
if (0) {
- struct llvmpipe_resource *lpr = llvmpipe_resource(transfer->resource);
printf("transfer map tex %u mode %s\n", lpr->id, mode);
}
-
- assert(transfer->resource);
- lpr = llvmpipe_resource(transfer->resource);
format = lpr->base.format;
- map = llvmpipe_resource_map(transfer->resource,
- transfer->sr.face,
- transfer->sr.level,
- transfer->box.z,
+ map = llvmpipe_resource_map(resource,
+ level,
+ box->z,
tex_usage, LP_TEX_LAYOUT_LINEAR);
/* May want to do different things here depending on read/write nature
* of the map:
*/
- if (transfer->usage & PIPE_TRANSFER_WRITE) {
+ if (usage & PIPE_TRANSFER_WRITE) {
/* Do something to notify sharing contexts of a texture change.
*/
screen->timestamp++;
}
-
+
map +=
- transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
- transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+ box->y / util_format_get_blockheight(format) * pt->stride +
+ box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
return map;
}
assert(transfer->resource);
llvmpipe_resource_unmap(transfer->resource,
- transfer->sr.face,
- transfer->sr.level,
- transfer->box.z);
+ transfer->level,
+ transfer->box.z);
+
+ /* Effectively do the texture_update work here - if texture images
+ * needed post-processing to put them into hardware layout, this is
+ * where it would happen. For llvmpipe, nothing to do.
+ */
+ assert (transfer->resource);
+ pipe_resource_reference(&transfer->resource, NULL);
+ FREE(transfer);
}
-static unsigned int
+unsigned int
llvmpipe_is_resource_referenced( struct pipe_context *pipe,
- struct pipe_resource *presource,
- unsigned face, unsigned level)
+ struct pipe_resource *presource,
+ unsigned level, int layer)
{
struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
if (presource->target == PIPE_BUFFER)
- return PIPE_UNREFERENCED;
-
+ return LP_UNREFERENCED;
+
return lp_setup_is_resource_referenced(llvmpipe->setup, presource);
}
+/**
+ * Returns the largest possible alignment for a format in llvmpipe
+ */
+unsigned
+llvmpipe_get_format_alignment( enum pipe_format format )
+{
+ const struct util_format_description *desc = util_format_description(format);
+ unsigned size = 0;
+ unsigned bytes;
+ unsigned i;
+
+ for (i = 0; i < desc->nr_channels; ++i) {
+ size += desc->channel[i].size;
+ }
+
+ bytes = size / 8;
+
+ if (!util_is_power_of_two(bytes)) {
+ bytes /= desc->nr_channels;
+ }
+
+ if (bytes % 2 || bytes < 1) {
+ return 1;
+ } else {
+ return bytes;
+ }
+}
+
/**
* Create buffer which wraps user-space data.
*/
-static struct pipe_resource *
+struct pipe_resource *
llvmpipe_user_buffer_create(struct pipe_screen *screen,
void *ptr,
unsigned bytes,
buffer->base.width0 = bytes;
buffer->base.height0 = 1;
buffer->base.depth0 = 1;
+ buffer->base.array_size = 1;
buffer->userBuffer = TRUE;
buffer->data = ptr;
/**
* Compute size (in bytes) need to store a texture image / mipmap level,
- * for just one cube face or one 3D texture slice
+ * for just one cube face, one array layer or one 3D texture slice
*/
static unsigned
tex_image_face_size(const struct llvmpipe_resource *lpr, unsigned level,
unsigned offset;
if (layout == LP_TEX_LAYOUT_LINEAR) {
- img = &lpr->linear[level];
+ img = &lpr->linear_img;
+ offset = lpr->linear_mip_offsets[level];
}
else {
assert (layout == LP_TEX_LAYOUT_TILED);
- img = &lpr->tiled[level];
+ img = &lpr->tiled_img;
+ offset = lpr->tiled_mip_offsets[level];
}
if (face_slice > 0)
- offset = face_slice * tex_image_face_size(lpr, level, layout);
- else
- offset = 0;
+ offset += face_slice * tex_image_face_size(lpr, level, layout);
return (ubyte *) img->data + offset;
}
/**
* Allocate storage for a linear or tile texture image (all cube
- * faces and all 3D slices.
+ * faces and all 3D slices, all levels).
*/
static void
-alloc_image_data(struct llvmpipe_resource *lpr, unsigned level,
+alloc_image_data(struct llvmpipe_resource *lpr,
enum lp_texture_layout layout)
{
+ uint alignment = MAX2(16, util_cpu_caps.cacheline);
+ uint level;
+ uint offset = 0;
+
if (lpr->dt)
- assert(level == 0);
+ assert(lpr->base.last_level == 0);
if (layout == LP_TEX_LAYOUT_TILED) {
/* tiled data is stored in regular memory */
- uint buffer_size = tex_image_size(lpr, level, layout);
- lpr->tiled[level].data = align_malloc(buffer_size, 16);
+ for (level = 0; level <= lpr->base.last_level; level++) {
+ uint buffer_size = tex_image_size(lpr, level, layout);
+ lpr->tiled_mip_offsets[level] = offset;
+ offset += align(buffer_size, alignment);
+ }
+ lpr->tiled_img.data = align_malloc(offset, alignment);
+ if (lpr->tiled_img.data) {
+ memset(lpr->tiled_img.data, 0, offset);
+ }
}
else {
assert(layout == LP_TEX_LAYOUT_LINEAR);
if (lpr->dt) {
- /* we get the linear memory from the winsys */
+ /* we get the linear memory from the winsys, and it has
+ * already been zeroed
+ */
struct llvmpipe_screen *screen = llvmpipe_screen(lpr->base.screen);
struct sw_winsys *winsys = screen->winsys;
- lpr->linear[0].data =
+ lpr->linear_img.data =
winsys->displaytarget_map(winsys, lpr->dt,
PIPE_TRANSFER_READ_WRITE);
}
else {
/* not a display target - allocate regular memory */
- uint buffer_size = tex_image_size(lpr, level, LP_TEX_LAYOUT_LINEAR);
- lpr->linear[level].data = align_malloc(buffer_size, 16);
+ /*
+ * Offset calculation for start of a specific mip/layer is always
+ * offset = lpr->linear_mip_offsets[level] + lpr->img_stride[level] * layer
+ */
+ for (level = 0; level <= lpr->base.last_level; level++) {
+ uint buffer_size = tex_image_size(lpr, level, LP_TEX_LAYOUT_LINEAR);
+ lpr->linear_mip_offsets[level] = offset;
+ offset += align(buffer_size, alignment);
+ }
+ lpr->linear_img.data = align_malloc(offset, alignment);
+ if (lpr->linear_img.data) {
+ memset(lpr->linear_img.data, 0, offset);
+ }
}
}
}
const unsigned height = u_minify(lpr->base.height0, level);
const unsigned width_t = align(width, TILE_SIZE) / TILE_SIZE;
const unsigned height_t = align(height, TILE_SIZE) / TILE_SIZE;
+ unsigned target_offset, other_offset;
+ unsigned *target_off_ptr, *other_off_ptr;
enum lp_texture_layout other_layout;
boolean only_allocate;
}
if (lpr->dt) {
- assert(lpr->linear[level].data);
+ assert(lpr->linear_img.data);
}
/* which is target? which is other? */
if (layout == LP_TEX_LAYOUT_LINEAR) {
- target_img = &lpr->linear[level];
- other_img = &lpr->tiled[level];
+ target_img = &lpr->linear_img;
+ target_off_ptr = lpr->linear_mip_offsets;
+ other_img = &lpr->tiled_img;
+ other_off_ptr = lpr->tiled_mip_offsets;
other_layout = LP_TEX_LAYOUT_TILED;
}
else {
- target_img = &lpr->tiled[level];
- other_img = &lpr->linear[level];
+ target_img = &lpr->tiled_img;
+ target_off_ptr = lpr->tiled_mip_offsets;
+ other_img = &lpr->linear_img;
+ other_off_ptr = lpr->linear_mip_offsets;
other_layout = LP_TEX_LAYOUT_LINEAR;
}
if (!target_data) {
/* allocate memory for the target image now */
- alloc_image_data(lpr, level, layout);
+ alloc_image_data(lpr, layout);
target_data = target_img->data;
}
+ target_offset = target_off_ptr[level];
+ other_offset = other_off_ptr[level];
+
if (face_slice > 0) {
- unsigned target_offset, other_offset;
+ target_offset += face_slice * tex_image_face_size(lpr, level, layout);
+ other_offset += face_slice * tex_image_face_size(lpr, level, other_layout);
+ }
- target_offset = face_slice * tex_image_face_size(lpr, level, layout);
- other_offset = face_slice * tex_image_face_size(lpr, level, other_layout);
- if (target_data) {
- target_data = (uint8_t *) target_data + target_offset;
- }
- if (other_data) {
- other_data = (uint8_t *) other_data + other_offset;
- }
+ if (target_data) {
+ target_data = (uint8_t *) target_data + target_offset;
+ }
+ if (other_data) {
+ other_data = (uint8_t *) other_data + other_offset;
}
if (only_allocate) {
layout_logic(cur_layout, layout, usage, &new_layout, &convert);
- if (convert) {
+ if (convert && other_data && target_data) {
if (layout == LP_TEX_LAYOUT_TILED) {
lp_linear_to_tiled(other_data, target_data,
x * TILE_SIZE, y * TILE_SIZE,
lpr->tiles_per_row[level]);
}
else {
+ assert(layout == LP_TEX_LAYOUT_LINEAR);
lp_tiled_to_linear(other_data, target_data,
x * TILE_SIZE, y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
}
}
- llvmpipe_set_texture_tile_layout(lpr, face_slice, level, x, y,
- new_layout);
+ if (new_layout != cur_layout)
+ llvmpipe_set_texture_tile_layout(lpr, face_slice, level, x, y,
+ new_layout);
}
}
}
width_t, height_t, layout);
}
- assert(target_data);
-
return target_data;
}
enum lp_texture_usage usage,
unsigned x, unsigned y)
{
- struct llvmpipe_texture_image *linear_img = &lpr->linear[level];
+ struct llvmpipe_texture_image *linear_img = &lpr->linear_img;
enum lp_texture_layout cur_layout, new_layout;
const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE;
boolean convert;
if (!linear_img->data) {
/* allocate memory for the linear image now */
- alloc_image_data(lpr, level, LP_TEX_LAYOUT_LINEAR);
+ alloc_image_data(lpr, LP_TEX_LAYOUT_LINEAR);
}
/* compute address of the slice/face of the image that contains the tile */
layout_logic(cur_layout, LP_TEX_LAYOUT_LINEAR, usage,
&new_layout, &convert);
- if (convert) {
+ if (convert && tiled_image && linear_image) {
lp_tiled_to_linear(tiled_image, linear_image,
x, y, TILE_SIZE, TILE_SIZE, lpr->base.format,
lpr->row_stride[level],
enum lp_texture_usage usage,
unsigned x, unsigned y)
{
- struct llvmpipe_texture_image *tiled_img = &lpr->tiled[level];
+ struct llvmpipe_texture_image *tiled_img = &lpr->tiled_img;
enum lp_texture_layout cur_layout, new_layout;
const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE;
boolean convert;
if (!tiled_img->data) {
/* allocate memory for the tiled image now */
- alloc_image_data(lpr, level, LP_TEX_LAYOUT_TILED);
+ alloc_image_data(lpr, LP_TEX_LAYOUT_TILED);
}
/* compute address of the slice/face of the image that contains the tile */
cur_layout = llvmpipe_get_texture_tile_layout(lpr, face_slice, level, tx, ty);
layout_logic(cur_layout, LP_TEX_LAYOUT_TILED, usage, &new_layout, &convert);
- if (convert) {
+ if (convert && linear_image && tiled_image) {
lp_linear_to_tiled(linear_image, tiled_image,
x, y, TILE_SIZE, TILE_SIZE, lpr->base.format,
lpr->row_stride[level],
lpr->tiles_per_row[level]);
}
+ if (!tiled_image)
+ return NULL;
+
if (new_layout != cur_layout)
llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty, new_layout);
unsigned lvl, size = 0;
for (lvl = 0; lvl <= lpr->base.last_level; lvl++) {
- if (lpr->linear[lvl].data)
+ if (lpr->linear_img.data)
size += tex_image_size(lpr, lvl, LP_TEX_LAYOUT_LINEAR);
- if (lpr->tiled[lvl].data)
+ if (lpr->tiled_img.data)
size += tex_image_size(lpr, lvl, LP_TEX_LAYOUT_TILED);
}
}
+#ifdef DEBUG
+void
+llvmpipe_print_resources(void)
+{
+ struct llvmpipe_resource *lpr;
+ unsigned n = 0, total = 0;
+
+ debug_printf("LLVMPIPE: current resources:\n");
+ foreach(lpr, &resource_list) {
+ unsigned size = llvmpipe_resource_size(&lpr->base);
+ debug_printf("resource %u at %p, size %ux%ux%u: %u bytes, refcount %u\n",
+ lpr->id, (void *) lpr,
+ lpr->base.width0, lpr->base.height0, lpr->base.depth0,
+ size, lpr->base.reference.count);
+ total += size;
+ n++;
+ }
+ debug_printf("LLVMPIPE: total size of %u resources: %u\n", n, total);
+}
+#endif
+
+
void
llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen)
{
+#ifdef DEBUG
+ /* init linked list for tracking resources */
+ {
+ static boolean first_call = TRUE;
+ if (first_call) {
+ memset(&resource_list, 0, sizeof(resource_list));
+ make_empty_list(&resource_list);
+ first_call = FALSE;
+ }
+ }
+#endif
+
screen->resource_create = llvmpipe_resource_create;
screen->resource_destroy = llvmpipe_resource_destroy;
screen->resource_from_handle = llvmpipe_resource_from_handle;
screen->resource_get_handle = llvmpipe_resource_get_handle;
- screen->user_buffer_create = llvmpipe_user_buffer_create;
-
- screen->get_tex_surface = llvmpipe_get_tex_surface;
- screen->tex_surface_destroy = llvmpipe_tex_surface_destroy;
+ screen->can_create_resource = llvmpipe_can_create_resource;
}
void
llvmpipe_init_context_resource_funcs(struct pipe_context *pipe)
{
- pipe->get_transfer = llvmpipe_get_transfer;
- pipe->transfer_destroy = llvmpipe_transfer_destroy;
pipe->transfer_map = llvmpipe_transfer_map;
pipe->transfer_unmap = llvmpipe_transfer_unmap;
- pipe->is_resource_referenced = llvmpipe_is_resource_referenced;
pipe->transfer_flush_region = u_default_transfer_flush_region;
pipe->transfer_inline_write = u_default_transfer_inline_write;
+
+ pipe->create_surface = llvmpipe_create_surface;
+ pipe->surface_destroy = llvmpipe_surface_destroy;
}