diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2013-09-30 12:06:39 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2013-09-30 12:06:39 +0200 |
commit | 6355ae85586d27472a1f27d6c057d4dae99bad35 (patch) | |
tree | bde39fb579b91ee97a50a4d80b2175c9d69b756a | |
parent | 4cf94a6f40bf760f5c3b9ddf0366601a4b05a64c (diff) |
driver: align mipmaps to 64 bytes
This fixes automatic mipmap generation with 16 bit textures
-rw-r--r-- | native/driver/etna_internal.h | 2 | ||||
-rw-r--r-- | native/driver/etna_pipe.c | 2 | ||||
-rw-r--r-- | native/driver/etna_resource.c | 2 | ||||
-rw-r--r-- | native/fb/downsample_test.c | 33 |
4 files changed, 29 insertions, 10 deletions
diff --git a/native/driver/etna_internal.h b/native/driver/etna_internal.h index 7e534a1..d9eaaaf 100644 --- a/native/driver/etna_internal.h +++ b/native/driver/etna_internal.h @@ -39,6 +39,8 @@ #define ETNA_RS_WIDTH_MASK (16-1) /* RS tiled operations must have height%4 = 0 */ #define ETNA_RS_HEIGHT_MASK (3) +/* PE render targets must be aligned to 64 bytes */ +#define ETNA_PE_ALIGNMENT (64) /* GPU chip 3D specs */ struct etna_pipe_specs diff --git a/native/driver/etna_pipe.c b/native/driver/etna_pipe.c index fd7e4c3..713e282 100644 --- a/native/driver/etna_pipe.c +++ b/native/driver/etna_pipe.c @@ -939,7 +939,6 @@ static void etna_pipe_set_framebuffer_state(struct pipe_context *pipe, int nr_samples_color = -1; int nr_samples_depth = -1; - /* Set up TS as well. Warning: this state is used by both the RS and PE */ uint32_t ts_mem_config = 0; if(sv->nr_cbufs > 0) /* at least one color buffer? */ @@ -953,6 +952,7 @@ static void etna_pipe_set_framebuffer_state(struct pipe_context *pipe, (color_supertiled ? VIVS_PE_COLOR_FORMAT_SUPER_TILED : 0); /* XXX VIVS_PE_COLOR_FORMAT_OVERWRITE and the rest comes from blend_state / depth_stencil_alpha */ /* merged with depth_stencil_alpha */ + if (priv->ctx->conn->chip.pixel_pipes == 1) { cs->PE_COLOR_ADDR = cbuf->surf.address; diff --git a/native/driver/etna_resource.c b/native/driver/etna_resource.c index bb9a143..3a2272d 100644 --- a/native/driver/etna_resource.c +++ b/native/driver/etna_resource.c @@ -203,7 +203,7 @@ static struct pipe_resource * etna_screen_resource_create(struct pipe_screen *sc mip->layer_stride = align(mip->padded_width, divSizeX)/divSizeX * align(mip->padded_height, divSizeY)/divSizeY * element_size; mip->size = templat->array_size * mip->layer_stride; - offset += mip->size; + offset += align(mip->size, ETNA_PE_ALIGNMENT); /* align mipmaps to 64 bytes to be able to render to them */ if(ix == max_mip_level || (x == 1 && y == 1)) break; // stop at last level x = (x+1)>>1; diff --git a/native/fb/downsample_test.c b/native/fb/downsample_test.c index e9154fa..de37bb4 100644 --- a/native/fb/downsample_test.c +++ b/native/fb/downsample_test.c @@ -38,6 +38,7 @@ #include "etna_pipe.h" #include "util/u_inlines.h" +#include "util/u_format.h" #include "util/u_gen_mipmap.h" #include "cso_cache/cso_context.h" #include "write_bmp.h" @@ -53,15 +54,28 @@ int main(int argc, char **argv) struct fbdemos_scaffold *fbs = 0; fbdemo_init(&fbs); struct pipe_context *pipe = fbs->pipe; + unsigned format = PIPE_FORMAT_B5G6R5_UNORM; /* texture format */ + //unsigned format = PIPE_FORMAT_B8G8R8X8_UNORM; + const struct util_format_description *format_desc = util_format_description(format); + unsigned bs = util_format_get_blocksize(format); /* Convert and upload embedded texture */ - struct pipe_resource *tex_resource = fbdemo_create_2d(fbs->screen, - PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET, PIPE_FORMAT_B8G8R8X8_UNORM, + struct pipe_resource *tex_resource = fbdemo_create_2d(fbs->screen, + PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET, format, COMPANION_TEXTURE_WIDTH, COMPANION_TEXTURE_HEIGHT, 1000); - void *temp = malloc(COMPANION_TEXTURE_WIDTH * COMPANION_TEXTURE_HEIGHT * 4); - etna_convert_r8g8b8_to_b8g8r8x8(temp, (const uint8_t*)companion_texture, COMPANION_TEXTURE_WIDTH * COMPANION_TEXTURE_HEIGHT); - etna_pipe_inline_write(pipe, tex_resource, 0, 0, temp, COMPANION_TEXTURE_WIDTH * COMPANION_TEXTURE_HEIGHT * 4); - free(temp); + + /* First convert from cumbersome RGB to RGBX */ + void *temp_rgbx8888 = malloc(COMPANION_TEXTURE_WIDTH * COMPANION_TEXTURE_HEIGHT * 4); + etna_convert_r8g8b8_to_b8g8r8x8(temp_rgbx8888, (const uint8_t*)companion_texture, COMPANION_TEXTURE_WIDTH * COMPANION_TEXTURE_HEIGHT); + + /* Then convert to destination format */ + void *temp_fmt = malloc(COMPANION_TEXTURE_WIDTH * COMPANION_TEXTURE_HEIGHT * bs); + format_desc->pack_rgba_8unorm(temp_fmt, COMPANION_TEXTURE_WIDTH*bs, temp_rgbx8888, COMPANION_TEXTURE_WIDTH*4, + COMPANION_TEXTURE_WIDTH, COMPANION_TEXTURE_HEIGHT); + etna_pipe_inline_write(pipe, tex_resource, 0, 0, temp_fmt, COMPANION_TEXTURE_WIDTH * COMPANION_TEXTURE_HEIGHT * bs); + + free(temp_rgbx8888); + free(temp_fmt); /* 0 512x512 * 1 256x256 * 2 128x128 @@ -87,7 +101,6 @@ int main(int argc, char **argv) assert(cso); struct gen_mipmap_state *gen_mipmap = util_create_gen_mipmap(pipe, cso); assert(gen_mipmap); - for(int frame=0; frame<1; ++frame) { if(frame%50 == 0) @@ -119,8 +132,12 @@ int main(int argc, char **argv) void *data = pipe->transfer_map(pipe, tex_resource, level, PIPE_TRANSFER_READ, &box, &transfer); + void *temp = malloc(lwidth * lheight * 4); + printf("%i: Transfer stride is %i\n", level, transfer->stride); + format_desc->unpack_rgba_8unorm(temp, lwidth*4, data, transfer->stride, lwidth, lheight); snprintf(filename, sizeof(filename), "mip%i.bmp", level); - bmp_dump32_ex(data, lwidth, lheight, /*flip*/ false, /*bgra*/true, /*alpha*/false, filename); + bmp_dump32_ex(temp, lwidth, lheight, /*flip*/ false, /*bgra*/true, /*alpha*/false, filename); + free(temp); pipe->transfer_unmap(pipe, transfer); |