X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fllvmpipe%2Flp_texture.c;h=0088b6ad0289f5cd14275585dcf3f0ddd247bc51;hb=72c6d0e506ad0e8262dddbc7a7cf2d6813761753;hp=0ac3528f7accd7ca5add50498785290a05dcd30d;hpb=33fcce36828d6ae413c1673f8de5c56fbd8ba4a1;p=mesa.git diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index 0ac3528f7ac..0088b6ad028 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -49,6 +49,7 @@ #include "lp_texture.h" #include "lp_setup.h" #include "lp_state.h" +#include "lp_rast.h" #include "state_tracker/sw_winsys.h" @@ -82,25 +83,36 @@ llvmpipe_texture_layout(struct llvmpipe_screen *screen, /* Row stride and image stride */ { - unsigned alignment, nblocksx, nblocksy, block_size; - - /* 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. + unsigned align_x, align_y, nblocksx, nblocksy, block_size; + + /* For non-compressed formats we need 4x4 pixel alignment + * so we can read/write LP_RASTER_BLOCK_SIZE when rendering to them. + * We also want cache line size in x direction, + * otherwise same cache line could end up in multiple threads. + * For explicit 1d resources however we reduce this to 4x1 and + * handle specially in render output code (as we need to do special + * handling there for buffers in any case). */ if (util_format_is_compressed(pt->format)) - alignment = 1; - else - alignment = TILE_SIZE; + align_x = align_y = 1; + else { + align_x = LP_RASTER_BLOCK_SIZE; + if (llvmpipe_resource_is_1d(&lpr->base)) + align_y = 1; + else + align_y = LP_RASTER_BLOCK_SIZE; + } nblocksx = util_format_get_nblocksx(pt->format, - align(width, alignment)); + align(width, align_x)); nblocksy = util_format_get_nblocksy(pt->format, - align(height, alignment)); + align(height, align_y)); block_size = util_format_get_blocksize(pt->format); - lpr->row_stride[level] = align(nblocksx * block_size, 16); + if (util_format_is_compressed(pt->format)) + lpr->row_stride[level] = nblocksx * block_size; + else + lpr->row_stride[level] = align(nblocksx * block_size, util_cpu_caps.cacheline); /* if row_stride * height > LP_MAX_TEXTURE_SIZE */ if (lpr->row_stride[level] > LP_MAX_TEXTURE_SIZE / nblocksy) { @@ -244,7 +256,12 @@ llvmpipe_resource_create(struct pipe_screen *_screen, assert(templat->height0 == 1); assert(templat->depth0 == 1); assert(templat->last_level == 0); - lpr->data = align_malloc(bytes, 16); + /* + * Reserve some extra storage since if we'd render to a buffer we + * read/write always LP_RASTER_BLOCK_SIZE pixels, but the element + * offset doesn't need to be aligned to LP_RASTER_BLOCK_SIZE. + */ + lpr->data = align_malloc(bytes + (LP_RASTER_BLOCK_SIZE - 1) * 4 * sizeof(float), 16); /* * buffers don't really have stride but it's probably safer * (for code doing same calculations for buffers and textures) @@ -327,7 +344,6 @@ llvmpipe_resource_map(struct pipe_resource *resource, struct llvmpipe_screen *screen = llvmpipe_screen(resource->screen); struct sw_winsys *winsys = screen->winsys; unsigned dt_usage; - uint8_t *map2; if (tex_usage == LP_TEX_USAGE_READ) { dt_usage = PIPE_TRANSFER_READ; @@ -345,14 +361,11 @@ llvmpipe_resource_map(struct pipe_resource *resource, /* install this linear image in texture data structure */ lpr->linear_img.data = map; - /* make sure tiled data gets converted to linear data */ - map2 = llvmpipe_get_texture_image(lpr, 0, 0, tex_usage); - return map2; + return map; } else if (llvmpipe_resource_is_texture(resource)) { - map = llvmpipe_get_texture_image(lpr, layer, level, - tex_usage); + map = llvmpipe_get_texture_image(lpr, layer, level, tex_usage); return map; } else { @@ -465,62 +478,6 @@ llvmpipe_resource_get_handle(struct pipe_screen *screen, } -static struct pipe_surface * -llvmpipe_create_surface(struct pipe_context *pipe, - struct pipe_resource *pt, - const struct pipe_surface *surf_tmpl) -{ - struct pipe_surface *ps; - - assert(surf_tmpl->u.tex.level <= pt->last_level); - if (!(pt->bind & (PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_RENDER_TARGET))) - debug_printf("Illegal surface creation without bind flag\n"); - - ps = CALLOC_STRUCT(pipe_surface); - if (ps) { - pipe_reference_init(&ps->reference, 1); - pipe_resource_reference(&ps->texture, pt); - ps->context = pipe; - ps->format = surf_tmpl->format; - if (llvmpipe_resource_is_texture(pt)) { - assert(surf_tmpl->u.tex.level <= pt->last_level); - ps->width = u_minify(pt->width0, surf_tmpl->u.tex.level); - ps->height = u_minify(pt->height0, surf_tmpl->u.tex.level); - 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; - if (ps->u.tex.first_layer != ps->u.tex.last_layer) { - debug_printf("creating surface with multiple layers, rendering to first layer only\n"); - } - } - else { - /* setting width as number of elements should get us correct renderbuffer width */ - ps->width = surf_tmpl->u.buf.last_element - surf_tmpl->u.buf.first_element + 1; - ps->height = pt->height0; - ps->u.buf.first_element = surf_tmpl->u.buf.first_element; - ps->u.buf.last_element = surf_tmpl->u.buf.last_element; - assert(ps->u.buf.first_element <= ps->u.buf.last_element); - assert(ps->u.buf.last_element < ps->width); - } - } - return ps; -} - - -static void -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 - * where it would happen. For llvmpipe, nothing to do. - */ - assert(surf->texture); - pipe_resource_reference(&surf->texture, NULL); - FREE(surf); -} - - static void * llvmpipe_transfer_map( struct pipe_context *pipe, struct pipe_resource *resource, @@ -1002,10 +959,7 @@ llvmpipe_init_context_resource_funcs(struct pipe_context *pipe) { pipe->transfer_map = llvmpipe_transfer_map; pipe->transfer_unmap = llvmpipe_transfer_unmap; - + 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; }