Commit 0a153b2a authored by Arno Messiaen's avatar Arno Messiaen Committed by Qiang Yu

lima: add mipmap settings to texture description

Signed-off-by: Arno Messiaen's avatarArno Messiaen <arnomessiaen@gmail.com>
parent d1e778c7
......@@ -269,7 +269,8 @@ lima_pack_reload_plbu_cmd(struct lima_context *ctx)
struct lima_context_framebuffer *fb = &ctx->framebuffer;
uint32_t *td = cpu + lima_reload_tex_desc_offset;
lima_texture_desc_set_res(ctx, td, fb->cbuf->texture);
memset(td, 0, lima_tex_desc_size);
lima_texture_desc_set_res(ctx, td, fb->cbuf->texture, 0, 0);
td[1] = 0x00000480;
td[2] |= 0x00093800;
td[4] = 0x00000000;
......
......@@ -44,7 +44,6 @@
#define LIMA_TEXEL_FORMAT_RGBA_8888 0x16
#define LIMA_TEXEL_FORMAT_RGBX_8888 0x17
#define lima_tex_desc_size 64
#define lima_tex_list_size 64
static uint32_t pipe_format_to_lima(enum pipe_format pformat)
......@@ -79,24 +78,29 @@ static uint32_t pipe_format_to_lima(enum pipe_format pformat)
void
lima_texture_desc_set_res(struct lima_context *ctx, uint32_t *desc,
struct pipe_resource *prsc)
struct pipe_resource *prsc,
unsigned first_level, unsigned last_level)
{
unsigned width, height, layout;
unsigned width, height, layout, i;
struct lima_resource *lima_res = lima_resource(prsc);
width = prsc->width0;
height = prsc->height0;
if (first_level != 0) {
width = u_minify(width, first_level);
height = u_minify(height, first_level);
}
desc[0] = pipe_format_to_lima(prsc->format);
desc[2] = (width << 22);
desc[3] = 0x10000 | (height << 3) | (width >> 10);
desc[0] |= pipe_format_to_lima(prsc->format);
desc[2] |= (width << 22);
desc[3] |= 0x10000 | (height << 3) | (width >> 10);
if (lima_res->tiled)
layout = 3;
else {
/* for padded linear texture */
if (lima_res->levels[0].width != width) {
desc[0] |= lima_res->levels[0].width << 18;
if (lima_res->levels[first_level].width != width) {
desc[0] |= lima_res->levels[first_level].width << 18;
desc[2] |= 0x100;
}
layout = 0;
......@@ -105,9 +109,36 @@ lima_texture_desc_set_res(struct lima_context *ctx, uint32_t *desc,
lima_submit_add_bo(ctx->pp_submit, lima_res->bo, LIMA_SUBMIT_BO_READ);
lima_bo_update(lima_res->bo, false, true);
uint32_t base_va = lima_res->bo->va;
/* attach level 0 */
desc[6] = (lima_res->bo->va << 24) | (layout << 13);
desc[7] = lima_res->bo->va >> 8;
desc[6] |= (base_va << 24) | (layout << 13);
desc[7] |= base_va >> 8;
/* Attach remaining levels.
* Each subsequent mipmap address is specified using the 26 msbs.
* These addresses are then packed continuously in memory */
unsigned current_desc_index = 7;
unsigned current_desc_bit_index = 24;
for (i = 1; i < LIMA_MAX_MIP_LEVELS; i++) {
if (first_level + i > last_level)
break;
uint32_t address = base_va + lima_res->levels[i].offset;
address = (address >> 6);
desc[current_desc_index] |= (address << current_desc_bit_index);
if (current_desc_bit_index <= 6) {
current_desc_bit_index += 26;
if (current_desc_bit_index >= 32) {
current_desc_bit_index &= 0x1F;
current_desc_index++;
}
continue;
}
desc[current_desc_index + 1] |= (address >> (32 - current_desc_bit_index));
current_desc_bit_index = (current_desc_bit_index + 26) & 0x1F;
current_desc_index++;
}
}
static void
......@@ -115,18 +146,50 @@ lima_update_tex_desc(struct lima_context *ctx, struct lima_sampler_state *sample
struct lima_sampler_view *texture, void *pdesc)
{
uint32_t *desc = pdesc;
unsigned first_level;
unsigned last_level;
bool mipmapping;
lima_texture_desc_set_res(ctx, desc, texture->base.texture);
memset(desc, 0, lima_tex_desc_size);
/* 2D texture */
desc[1] = 0x400;
desc[1] |= 0x400;
desc[1] &= ~0xff000000;
switch (sampler->base.min_mip_filter) {
case PIPE_TEX_MIPFILTER_NEAREST:
first_level = texture->base.u.tex.first_level;
last_level = texture->base.u.tex.last_level;
if (last_level - first_level >= LIMA_MAX_MIP_LEVELS)
last_level = first_level + LIMA_MAX_MIP_LEVELS - 1;
mipmapping = true;
desc[1] |= ((last_level - first_level) << 24);
desc[2] &= ~0x0600;
break;
case PIPE_TEX_MIPFILTER_LINEAR:
first_level = texture->base.u.tex.first_level;
last_level = texture->base.u.tex.last_level;
if (last_level - first_level >= LIMA_MAX_MIP_LEVELS)
last_level = first_level + LIMA_MAX_MIP_LEVELS - 1;
mipmapping = true;
desc[1] |= ((last_level - first_level) << 24);
desc[2] |= 0x0600;
break;
case PIPE_TEX_MIPFILTER_NONE:
default:
first_level = 0;
last_level = 0;
mipmapping = false;
desc[2] &= ~0x0600;
break;
}
switch (sampler->base.mag_img_filter) {
case PIPE_TEX_FILTER_LINEAR:
desc[2] &= ~0x1000;
/* no mipmap, filter_mag = linear */
desc[1] |= 0x80000000;
if (!mipmapping)
desc[1] |= 0x80000000;
break;
case PIPE_TEX_FILTER_NEAREST:
default:
......@@ -180,6 +243,9 @@ lima_update_tex_desc(struct lima_context *ctx, struct lima_sampler_state *sample
default:
break;
}
lima_texture_desc_set_res(ctx, desc, texture->base.texture,
first_level, last_level);
}
void
......
......@@ -25,8 +25,11 @@
#ifndef H_LIMA_TEXTURE
#define H_LIMA_TEXTURE
#define lima_tex_desc_size 64
void lima_texture_desc_set_res(struct lima_context *ctx, uint32_t *desc,
struct pipe_resource *prsc);
struct pipe_resource *prsc,
unsigned first_level, unsigned last_level);
void lima_update_textures(struct lima_context *ctx);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment