void
draw_set_mapped_texture(struct draw_context *draw,
unsigned shader_stage,
- unsigned sampler_idx,
+ unsigned sview_idx,
uint32_t width, uint32_t height, uint32_t depth,
uint32_t first_level, uint32_t last_level,
const void *base_ptr,
#ifdef HAVE_LLVM
if (draw->llvm)
draw_llvm_set_mapped_texture(draw,
- sampler_idx,
+ sview_idx,
width, height, depth, first_level,
last_level, base_ptr,
row_stride, img_stride, mip_offsets);
void
draw_set_mapped_texture(struct draw_context *draw,
unsigned shader_stage,
- unsigned sampler_idx,
+ unsigned sview_idx,
uint32_t width, uint32_t height, uint32_t depth,
uint32_t first_level, uint32_t last_level,
const void *base,
void
draw_llvm_set_mapped_texture(struct draw_context *draw,
- unsigned sampler_idx,
+ unsigned sview_idx,
uint32_t width, uint32_t height, uint32_t depth,
uint32_t first_level, uint32_t last_level,
const void *base_ptr,
unsigned j;
struct draw_jit_texture *jit_tex;
- assert(sampler_idx < Elements(draw->llvm->jit_context.textures));
+ assert(sview_idx < Elements(draw->llvm->jit_context.textures));
- jit_tex = &draw->llvm->jit_context.textures[sampler_idx];
+ jit_tex = &draw->llvm->jit_context.textures[sview_idx];
jit_tex->width = width;
jit_tex->height = height;
void
draw_llvm_set_mapped_texture(struct draw_context *draw,
- unsigned sampler_idx,
+ unsigned sview_idx,
uint32_t width, uint32_t height, uint32_t depth,
uint32_t first_level, uint32_t last_level,
const void *base_ptr,
{
/* First callbacks for sampler view state */
- /** Obtain the base texture width (returns int32) */
+ /** Obtain the base texture width (or number of elements) (returns int32) */
LLVMValueRef
(*width)( const struct lp_sampler_dynamic_state *state,
struct gallivm_state *gallivm,
struct gallivm_state *gallivm,
unsigned texture_unit);
- /** Obtain the base texture depth (returns int32) */
+ /** Obtain the base texture depth (or array size) (returns int32) */
LLVMValueRef
(*depth)( const struct lp_sampler_dynamic_state *state,
struct gallivm_state *gallivm,
struct lp_static_sampler_state derived_sampler_state = *static_sampler_state;
LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMBuilderRef builder = gallivm->builder;
- LLVMValueRef tex_width, tex_height, tex_depth;
+ LLVMValueRef tex_width;
LLVMValueRef s;
LLVMValueRef t;
LLVMValueRef r;
/* Get the dynamic state */
tex_width = dynamic_state->width(dynamic_state, gallivm, texture_index);
- tex_height = dynamic_state->height(dynamic_state, gallivm, texture_index);
- tex_depth = dynamic_state->depth(dynamic_state, gallivm, texture_index);
bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm, texture_index);
bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm, texture_index);
bld.base_ptr = dynamic_state->base_ptr(dynamic_state, gallivm, texture_index);
bld.int_size = LLVMBuildInsertElement(builder, bld.int_size_in_bld.undef,
tex_width, LLVMConstInt(i32t, 0, 0), "");
if (dims >= 2) {
+ LLVMValueRef tex_height =
+ dynamic_state->height(dynamic_state, gallivm, texture_index);
bld.int_size = LLVMBuildInsertElement(builder, bld.int_size,
tex_height, LLVMConstInt(i32t, 1, 0), "");
if (dims >= 3) {
+ LLVMValueRef tex_depth =
+ dynamic_state->depth(dynamic_state, gallivm, texture_index);
bld.int_size = LLVMBuildInsertElement(builder, bld.int_size,
tex_depth, LLVMConstInt(i32t, 2, 0), "");
}
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;
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);
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);
}
}
}
/*
* 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);
}
}
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.
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 {
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);
}
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.
/* 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)) {
FREE(lpr->layout[0]);
}
- else if (resource_is_texture(pt)) {
+ else if (llvmpipe_resource_is_texture(pt)) {
/* regular texture */
uint level;
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);
{
struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
- assert(!resource_is_texture(resource));
+ assert(!llvmpipe_resource_is_texture(resource));
return lpr->data;
}
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;
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;
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);
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)