summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/llvmpipe
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/drivers/llvmpipe')
-rw-r--r--src/gallium/drivers/llvmpipe/lp_jit.h4
-rw-r--r--src/gallium/drivers/llvmpipe/lp_screen.c4
-rw-r--r--src/gallium/drivers/llvmpipe/lp_setup.c130
-rw-r--r--src/gallium/drivers/llvmpipe/lp_state_sampler.c84
-rw-r--r--src/gallium/drivers/llvmpipe/lp_texture.c36
-rw-r--r--src/gallium/drivers/llvmpipe/lp_texture.h22
6 files changed, 177 insertions, 103 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h
index 472d3911e71..4eddb2a2f3c 100644
--- a/src/gallium/drivers/llvmpipe/lp_jit.h
+++ b/src/gallium/drivers/llvmpipe/lp_jit.h
@@ -49,9 +49,9 @@ struct llvmpipe_screen;
struct lp_jit_texture
{
- uint32_t width;
+ uint32_t width; /* same as number of elements */
uint32_t height;
- uint32_t depth;
+ uint32_t depth; /* doubles as array size */
uint32_t first_level;
uint32_t last_level;
const void *base;
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c
index b9c1567bd55..05bbca5e19b 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -216,9 +216,11 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
case PIPE_CAP_TEXTURE_MULTISAMPLE:
case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
case PIPE_CAP_CUBE_MAP_ARRAY:
+ return 0;
case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
+ return 1;
case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
- return 0;
+ return 1;
}
/* should only get here on unhandled cases */
debug_printf("Unexpected PIPE_CAP %d query\n", param);
diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c
index b0bc4a8132f..4529775f907 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup.c
@@ -674,70 +674,108 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
struct pipe_sampler_view *view = i < num ? views[i] : NULL;
if (view) {
- struct pipe_resource *tex = view->texture;
- struct llvmpipe_resource *lp_tex = llvmpipe_resource(tex);
+ struct pipe_resource *res = view->texture;
+ struct llvmpipe_resource *lp_tex = llvmpipe_resource(res);
struct lp_jit_texture *jit_tex;
jit_tex = &setup->fs.current.jit_context.textures[i];
- jit_tex->width = tex->width0;
- jit_tex->height = tex->height0;
- jit_tex->first_level = view->u.tex.first_level;
- jit_tex->last_level = tex->last_level;
-
- if (tex->target == PIPE_TEXTURE_3D) {
- jit_tex->depth = tex->depth0;
- }
- else {
- jit_tex->depth = tex->array_size;
- }
/* We're referencing the texture's internal data, so save a
* reference to it.
*/
- pipe_resource_reference(&setup->fs.current_tex[i], tex);
+ pipe_resource_reference(&setup->fs.current_tex[i], res);
if (!lp_tex->dt) {
/* regular texture - setup array of mipmap level offsets */
void *mip_ptr;
int j;
- /*
- * XXX this is messed up we don't want to accidentally trigger
- * tiled->linear conversion for levels we don't need.
- * So ask for first_level data (which will allocate all levels)
- * then if successful get base ptr.
- */
- mip_ptr = llvmpipe_get_texture_image_all(lp_tex, view->u.tex.first_level,
- LP_TEX_USAGE_READ,
- LP_TEX_LAYOUT_LINEAR);
+ unsigned first_level = 0;
+ unsigned last_level = 0;
+
+ if (llvmpipe_resource_is_texture(res)) {
+ first_level = view->u.tex.first_level;
+ last_level = view->u.tex.last_level;
+ assert(first_level <= last_level);
+ assert(last_level <= res->last_level);
+
+ /*
+ * The complexity here is only necessary for depth textures which
+ * still are tiled.
+ */
+ mip_ptr = llvmpipe_get_texture_image_all(lp_tex, first_level,
+ LP_TEX_USAGE_READ,
+ LP_TEX_LAYOUT_LINEAR);
+ jit_tex->base = lp_tex->linear_img.data;
+ }
+ else {
+ mip_ptr = lp_tex->data;
+ jit_tex->base = mip_ptr;
+ }
+
if ((LP_PERF & PERF_TEX_MEM) || !mip_ptr) {
/* out of memory - use dummy tile memory */
+ /* Note if using PERF_TEX_MEM will also skip tile conversion */
jit_tex->base = lp_dummy_tile;
jit_tex->width = TILE_SIZE/8;
jit_tex->height = TILE_SIZE/8;
jit_tex->depth = 1;
jit_tex->first_level = 0;
jit_tex->last_level = 0;
+ jit_tex->mip_offsets[j] = 0;
+ jit_tex->row_stride[j] = 0;
+ jit_tex->img_stride[j] = 0;
}
else {
- jit_tex->base = lp_tex->linear_img.data;
- }
- for (j = view->u.tex.first_level; j <= tex->last_level; j++) {
- mip_ptr = llvmpipe_get_texture_image_all(lp_tex, j,
- LP_TEX_USAGE_READ,
- LP_TEX_LAYOUT_LINEAR);
- jit_tex->mip_offsets[j] = (uint8_t *)mip_ptr - (uint8_t *)jit_tex->base;
- /*
- * could get mip offset directly but need call above to
- * invoke tiled->linear conversion.
- */
- assert(lp_tex->linear_mip_offsets[j] == jit_tex->mip_offsets[j]);
- jit_tex->row_stride[j] = lp_tex->row_stride[j];
- jit_tex->img_stride[j] = lp_tex->img_stride[j];
-
- if (jit_tex->base == lp_dummy_tile) {
- /* out of memory - use dummy tile memory */
- jit_tex->mip_offsets[j] = 0;
- jit_tex->row_stride[j] = 0;
- jit_tex->img_stride[j] = 0;
+ jit_tex->width = res->width0;
+ jit_tex->height = res->height0;
+ jit_tex->depth = res->depth0;
+ jit_tex->first_level = first_level;
+ jit_tex->last_level = last_level;
+
+ if (llvmpipe_resource_is_texture(res)) {
+ for (j = first_level; j <= last_level; j++) {
+ mip_ptr = llvmpipe_get_texture_image_all(lp_tex, j,
+ LP_TEX_USAGE_READ,
+ LP_TEX_LAYOUT_LINEAR);
+ jit_tex->mip_offsets[j] = (uint8_t *)mip_ptr - (uint8_t *)jit_tex->base;
+ /*
+ * could get mip offset directly but need call above to
+ * invoke tiled->linear conversion.
+ */
+ assert(lp_tex->linear_mip_offsets[j] == jit_tex->mip_offsets[j]);
+ jit_tex->row_stride[j] = lp_tex->row_stride[j];
+ jit_tex->img_stride[j] = lp_tex->img_stride[j];
+ }
+
+ /*
+ * We don't use anything like first_element (for buffers) or
+ * first_layer (for arrays), instead adjust the last_element
+ * (width) or last_layer (depth) plus the base pointer.
+ * Less parameters and faster at shader execution.
+ * XXX Could do the same for mip levels.
+ */
+ if (res->target == PIPE_TEXTURE_1D_ARRAY ||
+ res->target == PIPE_TEXTURE_2D_ARRAY) {
+ jit_tex->depth = view->u.tex.last_layer - view->u.tex.first_layer + 1;
+ jit_tex->base = (uint8_t *)jit_tex->base +
+ view->u.tex.first_layer * lp_tex->img_stride[0];
+ assert(view->u.tex.first_layer <= view->u.tex.last_layer);
+ assert(view->u.tex.last_layer < res->array_size);
+ }
+ }
+ else {
+ unsigned view_blocksize = util_format_get_blocksize(view->format);
+ /* probably don't really need to fill that out */
+ jit_tex->mip_offsets[0] = 0;
+ jit_tex->row_stride[0] = 0;
+ jit_tex->row_stride[0] = 0;
+
+ /* everything specified in number of elements here. */
+ jit_tex->width = view->u.buf.last_element - view->u.buf.first_element + 1;
+ jit_tex->base = (uint8_t *)jit_tex->base + view->u.buf.first_element *
+ view_blocksize;
+ /* XXX Unsure if we need to sanitize parameters? */
+ assert(view->u.buf.first_element <= view->u.buf.last_element);
+ assert(view->u.buf.last_element * view_blocksize < res->width0);
}
}
}
@@ -746,13 +784,17 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
/*
* XXX: Where should this be unmapped?
*/
- struct llvmpipe_screen *screen = llvmpipe_screen(tex->screen);
+ struct llvmpipe_screen *screen = llvmpipe_screen(res->screen);
struct sw_winsys *winsys = screen->winsys;
jit_tex->base = winsys->displaytarget_map(winsys, lp_tex->dt,
PIPE_TRANSFER_READ);
jit_tex->row_stride[0] = lp_tex->row_stride[0];
jit_tex->img_stride[0] = lp_tex->img_stride[0];
jit_tex->mip_offsets[0] = 0;
+ jit_tex->width = res->width0;
+ jit_tex->height = res->height0;
+ jit_tex->depth = res->depth0;
+ jit_tex->first_level = jit_tex->last_level = 0;
assert(jit_tex->base);
}
}
diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
index 9736ca94905..30547a69f0d 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_sampler.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
@@ -268,14 +268,10 @@ llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp,
if (view) {
struct pipe_resource *tex = view->texture;
struct llvmpipe_resource *lp_tex = llvmpipe_resource(tex);
- unsigned num_layers;
-
- if (tex->target == PIPE_TEXTURE_3D) {
- num_layers = tex->depth0;
- }
- else {
- num_layers = tex->array_size;
- }
+ unsigned width0 = tex->width0;
+ unsigned num_layers = tex->depth0;
+ unsigned first_level = 0;
+ unsigned last_level = 0;
/* We're referencing the texture's internal data, so save a
* reference to it.
@@ -283,27 +279,61 @@ llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp,
pipe_resource_reference(&lp->mapped_vs_tex[i], tex);
if (!lp_tex->dt) {
- /* regular texture - setup array of mipmap level pointers */
- /* XXX this may fail due to OOM ? */
+ /* regular texture - setup array of mipmap level offsets */
+ struct pipe_resource *res = view->texture;
int j;
void *mip_ptr;
- /* must trigger allocation first before we can get base ptr */
- mip_ptr = llvmpipe_get_texture_image_all(lp_tex, view->u.tex.first_level,
- LP_TEX_USAGE_READ,
- LP_TEX_LAYOUT_LINEAR);
- addr = lp_tex->linear_img.data;
- for (j = view->u.tex.first_level; j <= tex->last_level; j++) {
- mip_ptr = llvmpipe_get_texture_image_all(lp_tex, j,
+
+ if (llvmpipe_resource_is_texture(res)) {
+ first_level = view->u.tex.first_level;
+ last_level = view->u.tex.last_level;
+ assert(first_level <= last_level);
+ assert(last_level <= res->last_level);
+
+ /* must trigger allocation first before we can get base ptr */
+ /* XXX this may fail due to OOM ? */
+ mip_ptr = llvmpipe_get_texture_image_all(lp_tex, view->u.tex.first_level,
LP_TEX_USAGE_READ,
LP_TEX_LAYOUT_LINEAR);
- mip_offsets[j] = (uint8_t *)mip_ptr - (uint8_t *)addr;
- /*
- * could get mip offset directly but need call above to
- * invoke tiled->linear conversion.
- */
- assert(lp_tex->linear_mip_offsets[j] == mip_offsets[j]);
- row_stride[j] = lp_tex->row_stride[j];
- img_stride[j] = lp_tex->img_stride[j];
+ addr = lp_tex->linear_img.data;
+
+ for (j = first_level; j <= last_level; j++) {
+ mip_ptr = llvmpipe_get_texture_image_all(lp_tex, j,
+ LP_TEX_USAGE_READ,
+ LP_TEX_LAYOUT_LINEAR);
+ mip_offsets[j] = (uint8_t *)mip_ptr - (uint8_t *)addr;
+ /*
+ * could get mip offset directly but need call above to
+ * invoke tiled->linear conversion.
+ */
+ assert(lp_tex->linear_mip_offsets[j] == mip_offsets[j]);
+ row_stride[j] = lp_tex->row_stride[j];
+ img_stride[j] = lp_tex->img_stride[j];
+ }
+ if (res->target == PIPE_TEXTURE_1D_ARRAY ||
+ res->target == PIPE_TEXTURE_2D_ARRAY) {
+ num_layers = view->u.tex.last_layer - view->u.tex.first_layer + 1;
+ addr = (uint8_t *)addr +
+ view->u.tex.first_layer * lp_tex->img_stride[0];
+ assert(view->u.tex.first_layer <= view->u.tex.last_layer);
+ assert(view->u.tex.last_layer < res->array_size);
+ }
+ }
+ else {
+ unsigned view_blocksize = util_format_get_blocksize(view->format);
+ mip_ptr = lp_tex->data;
+ addr = mip_ptr;
+ /* probably don't really need to fill that out */
+ mip_offsets[0] = 0;
+ row_stride[0] = 0;
+ row_stride[0] = 0;
+
+ /* everything specified in number of elements here. */
+ width0 = view->u.buf.last_element - view->u.buf.first_element + 1;
+ addr = (uint8_t *)addr + view->u.buf.first_element *
+ view_blocksize;
+ assert(view->u.buf.first_element <= view->u.buf.last_element);
+ assert(view->u.buf.last_element * view_blocksize < res->width0);
}
}
else {
@@ -323,8 +353,8 @@ llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp,
draw_set_mapped_texture(lp->draw,
PIPE_SHADER_VERTEX,
i,
- tex->width0, tex->height0, num_layers,
- view->u.tex.first_level, tex->last_level,
+ width0, tex->height0, num_layers,
+ first_level, last_level,
addr,
row_stride, img_stride, mip_offsets);
}
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c
index f34882808a4..f9232923733 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.c
+++ b/src/gallium/drivers/llvmpipe/lp_texture.c
@@ -60,28 +60,6 @@ static struct llvmpipe_resource resource_list;
static unsigned id_counter = 0;
-static INLINE boolean
-resource_is_texture(const struct pipe_resource *resource)
-{
- switch (resource->target) {
- 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;
- default:
- assert(0);
- return FALSE;
- }
-}
-
-
-
/**
* Allocate storage for llvmpipe_texture::layout array.
* The number of elements is width_in_tiles * height_in_tiles.
@@ -294,7 +272,7 @@ llvmpipe_resource_create(struct pipe_screen *_screen,
/* assert(lpr->base.bind); */
- if (resource_is_texture(&lpr->base)) {
+ if (llvmpipe_resource_is_texture(&lpr->base)) {
if (lpr->base.bind & (PIPE_BIND_DISPLAY_TARGET |
PIPE_BIND_SCANOUT |
PIPE_BIND_SHARED)) {
@@ -357,7 +335,7 @@ llvmpipe_resource_destroy(struct pipe_screen *pscreen,
FREE(lpr->layout[0]);
}
- else if (resource_is_texture(pt)) {
+ else if (llvmpipe_resource_is_texture(pt)) {
/* regular texture */
uint level;
@@ -447,7 +425,7 @@ llvmpipe_resource_map(struct pipe_resource *resource,
return map2;
}
- else if (resource_is_texture(resource)) {
+ else if (llvmpipe_resource_is_texture(resource)) {
map = llvmpipe_get_texture_image(lpr, layer, level,
tex_usage, layout);
@@ -492,7 +470,7 @@ llvmpipe_resource_data(struct pipe_resource *resource)
{
struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
- assert(!resource_is_texture(resource));
+ assert(!llvmpipe_resource_is_texture(resource));
return lpr->data;
}
@@ -967,7 +945,7 @@ llvmpipe_get_texture_tile_layout(const struct llvmpipe_resource *lpr,
unsigned x, unsigned y)
{
uint i;
- assert(resource_is_texture(&lpr->base));
+ assert(llvmpipe_resource_is_texture(&lpr->base));
assert(x < lpr->tiles_per_row[level]);
i = face_slice * lpr->tiles_per_image[level]
+ y * lpr->tiles_per_row[level] + x;
@@ -982,7 +960,7 @@ llvmpipe_set_texture_tile_layout(struct llvmpipe_resource *lpr,
enum lp_texture_layout layout)
{
uint i;
- assert(resource_is_texture(&lpr->base));
+ assert(llvmpipe_resource_is_texture(&lpr->base));
assert(x < lpr->tiles_per_row[level]);
i = face_slice * lpr->tiles_per_image[level]
+ y * lpr->tiles_per_row[level] + x;
@@ -1264,7 +1242,7 @@ llvmpipe_get_texture_tile_linear(struct llvmpipe_resource *lpr,
boolean convert;
uint8_t *tiled_image, *linear_image;
- assert(resource_is_texture(&lpr->base));
+ assert(llvmpipe_resource_is_texture(&lpr->base));
assert(x % TILE_SIZE == 0);
assert(y % TILE_SIZE == 0);
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.h b/src/gallium/drivers/llvmpipe/lp_texture.h
index 172228dc3fb..58d719e51e5 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.h
+++ b/src/gallium/drivers/llvmpipe/lp_texture.h
@@ -163,6 +163,28 @@ llvmpipe_transfer(struct pipe_transfer *pt)
void llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen);
void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe);
+
+static INLINE boolean
+llvmpipe_resource_is_texture(const struct pipe_resource *resource)
+{
+ switch (resource->target) {
+ 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;
+ default:
+ assert(0);
+ return FALSE;
+ }
+}
+
+
static INLINE unsigned
llvmpipe_resource_stride(struct pipe_resource *resource,
unsigned level)