diff options
author | Christian König <[email protected]> | 2010-12-11 13:43:44 +0100 |
---|---|---|
committer | Christian König <[email protected]> | 2010-12-11 13:43:44 +0100 |
commit | 772b25e1f366edc857e77b8c1ccdc5297d82cc41 (patch) | |
tree | 88d38b52e80319dbd4a0c5b5e038d92f1105110a /src/gallium/auxiliary/util | |
parent | ab130400cf91ab471e265e58193c95f04c7aeeda (diff) | |
parent | b3d2ec9942303d1d03e28a25b030eb060415abfb (diff) |
Merge remote branch 'origin/master' into pipe-video
Conflicts:
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/r600/r600_texture.c
Diffstat (limited to 'src/gallium/auxiliary/util')
30 files changed, 777 insertions, 663 deletions
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index dfb142b9e1c..c11f7d383db 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -291,7 +291,7 @@ regions_overlap(int srcX0, int srcY0, void util_blit_pixels_writemask(struct blit_state *ctx, struct pipe_resource *src_tex, - struct pipe_subresource srcsub, + unsigned src_level, int srcX0, int srcY0, int srcX1, int srcY1, int srcZ0, @@ -316,13 +316,12 @@ util_blit_pixels_writemask(struct blit_state *ctx, assert(filter == PIPE_TEX_MIPFILTER_NEAREST || filter == PIPE_TEX_MIPFILTER_LINEAR); - assert(srcsub.level <= src_tex->last_level); + assert(src_level <= src_tex->last_level); /* do the regions overlap? */ overlap = src_tex == dst->texture && - dst->face == srcsub.face && - dst->level == srcsub.level && - dst->zslice == srcZ0 && + dst->u.tex.level == src_level && + dst->u.tex.first_layer == srcZ0 && regions_overlap(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1); @@ -339,16 +338,19 @@ util_blit_pixels_writemask(struct blit_state *ctx, (dstX1 - dstX0) == (srcX1 - srcX0) && (dstY1 - dstY0) == (srcY1 - srcY0) && !overlap) { - struct pipe_subresource subdst; - subdst.face = dst->face; - subdst.level = dst->level; + struct pipe_box src_box; + src_box.x = srcX0; + src_box.y = srcY0; + src_box.z = srcZ0; + src_box.width = srcW; + src_box.height = srcH; + src_box.depth = 1; pipe->resource_copy_region(pipe, - dst->texture, subdst, - dstX0, dstY0, dst->zslice,/* dest */ - src_tex, srcsub, - srcX0, srcY0, srcZ0,/* src */ - srcW, srcH); /* size */ - return; + dst->texture, dst->u.tex.level, + dstX0, dstY0, dst->u.tex.first_layer,/* dest */ + src_tex, src_level, + &src_box); + return; } /* Create a temporary texture when src and dest alias or when src @@ -359,16 +361,16 @@ util_blit_pixels_writemask(struct blit_state *ctx, * This can still be improved upon. */ if ((src_tex == dst->texture && - dst->face == srcsub.face && - dst->level == srcsub.level && - dst->zslice == srcZ0) || + dst->u.tex.level == src_level && + dst->u.tex.first_layer == srcZ0) || (src_tex->target != PIPE_TEXTURE_2D && + src_tex->target != PIPE_TEXTURE_2D && src_tex->target != PIPE_TEXTURE_RECT)) { struct pipe_resource texTemp; struct pipe_resource *tex; struct pipe_sampler_view sv_templ; - struct pipe_subresource texsub; + struct pipe_box src_box; const int srcLeft = MIN2(srcX0, srcX1); const int srcTop = MIN2(srcY0, srcY1); @@ -394,19 +396,23 @@ util_blit_pixels_writemask(struct blit_state *ctx, texTemp.width0 = srcW; texTemp.height0 = srcH; texTemp.depth0 = 1; + texTemp.array_size = 1; texTemp.bind = PIPE_BIND_SAMPLER_VIEW; tex = screen->resource_create(screen, &texTemp); if (!tex) return; - texsub.face = 0; - texsub.level = 0; + src_box.x = srcLeft; + src_box.y = srcTop; + src_box.z = srcZ0; + src_box.width = srcW; + src_box.height = srcH; + src_box.depth = 1; /* load temp texture */ pipe->resource_copy_region(pipe, - tex, texsub, 0, 0, 0, /* dest */ - src_tex, srcsub, srcLeft, srcTop, srcZ0, /* src */ - srcW, srcH); /* size */ + tex, 0, 0, 0, 0, /* dest */ + src_tex, src_level, &src_box); normalized = tex->target != PIPE_TEXTURE_RECT; if(normalized) { @@ -433,7 +439,6 @@ util_blit_pixels_writemask(struct blit_state *ctx, } else { u_sampler_view_default_template(&sv_templ, src_tex, src_tex->format); - sv_templ.first_level = sv_templ.last_level = srcsub.level; sampler_view = pipe->create_sampler_view(pipe, src_tex, &sv_templ); if (!sampler_view) { @@ -447,10 +452,10 @@ util_blit_pixels_writemask(struct blit_state *ctx, normalized = sampler_view->texture->target != PIPE_TEXTURE_RECT; if(normalized) { - s0 /= (float)(u_minify(sampler_view->texture->width0, srcsub.level)); - s1 /= (float)(u_minify(sampler_view->texture->width0, srcsub.level)); - t0 /= (float)(u_minify(sampler_view->texture->height0, srcsub.level)); - t1 /= (float)(u_minify(sampler_view->texture->height0, srcsub.level)); + s0 /= (float)(u_minify(sampler_view->texture->width0, src_level)); + s1 /= (float)(u_minify(sampler_view->texture->width0, src_level)); + t0 /= (float)(u_minify(sampler_view->texture->height0, src_level)); + t1 /= (float)(u_minify(sampler_view->texture->height0, src_level)); } } @@ -489,9 +494,8 @@ util_blit_pixels_writemask(struct blit_state *ctx, ctx->sampler.normalized_coords = normalized; ctx->sampler.min_img_filter = filter; ctx->sampler.mag_img_filter = filter; - /* we've limited this already with the sampler view but you never know... */ - ctx->sampler.min_lod = srcsub.level; - ctx->sampler.max_lod = srcsub.level; + ctx->sampler.min_lod = src_level; + ctx->sampler.max_lod = src_level; cso_single_sampler(ctx->cso, 0, &ctx->sampler); cso_single_sampler_done(ctx->cso); @@ -575,7 +579,7 @@ util_blit_pixels_writemask(struct blit_state *ctx, void util_blit_pixels(struct blit_state *ctx, struct pipe_resource *src_tex, - struct pipe_subresource srcsub, + unsigned src_level, int srcX0, int srcY0, int srcX1, int srcY1, int srcZ, @@ -585,7 +589,7 @@ util_blit_pixels(struct blit_state *ctx, float z, uint filter ) { util_blit_pixels_writemask( ctx, src_tex, - srcsub, + src_level, srcX0, srcY0, srcX1, srcY1, srcZ, @@ -662,6 +666,7 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_save_rasterizer(ctx->cso); cso_save_samplers(ctx->cso); cso_save_fragment_sampler_views(ctx->cso); + cso_save_viewport(ctx->cso); cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); @@ -729,6 +734,7 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_restore_rasterizer(ctx->cso); cso_restore_samplers(ctx->cso); cso_restore_fragment_sampler_views(ctx->cso); + cso_restore_viewport(ctx->cso); cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); cso_restore_vertex_shader(ctx->cso); diff --git a/src/gallium/auxiliary/util/u_blit.h b/src/gallium/auxiliary/util/u_blit.h index b8a0dfce13f..3009e25eca3 100644 --- a/src/gallium/auxiliary/util/u_blit.h +++ b/src/gallium/auxiliary/util/u_blit.h @@ -42,7 +42,6 @@ struct cso_context; struct pipe_context; struct pipe_resource; struct pipe_sampler_view; -struct pipe_subresource; struct pipe_surface; @@ -55,7 +54,7 @@ util_destroy_blit(struct blit_state *ctx); extern void util_blit_pixels(struct blit_state *ctx, struct pipe_resource *src_tex, - struct pipe_subresource srcsub, + unsigned src_level, int srcX0, int srcY0, int srcX1, int srcY1, int srcZ0, @@ -67,7 +66,7 @@ util_blit_pixels(struct blit_state *ctx, void util_blit_pixels_writemask(struct blit_state *ctx, struct pipe_resource *src_tex, - struct pipe_subresource srcsub, + unsigned src_level, int srcX0, int srcY0, int srcX1, int srcY1, int srcZ0, diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index a163f93cb82..4c986e3565c 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -63,8 +63,7 @@ struct blitter_context_priv /* Constant state objects. */ /* Vertex shaders. */ - void *vs_col; /**< Vertex shader which passes {pos, color} to the output */ - void *vs_tex; /**< Vertex shader which passes {pos, texcoord} to the output.*/ + void *vs; /**< Vertex shader which passes {pos, generic} to the output.*/ /* Fragment shaders. */ /* The shader at index i outputs color to color buffers 0,1,...,i-1. */ @@ -211,20 +210,12 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) /* fragment shaders are created on-demand */ - /* vertex shaders */ - { - const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, - TGSI_SEMANTIC_COLOR }; - const uint semantic_indices[] = { 0, 0 }; - ctx->vs_col = - util_make_vertex_passthrough_shader(pipe, 2, semantic_names, - semantic_indices); - } + /* vertex shader */ { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC }; const uint semantic_indices[] = { 0, 0 }; - ctx->vs_tex = + ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names, semantic_indices); } @@ -257,8 +248,7 @@ void util_blitter_destroy(struct blitter_context *blitter) pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_flush_depth_stencil); pipe->delete_rasterizer_state(pipe, ctx->rs_state); - pipe->delete_vs_state(pipe, ctx->vs_col); - pipe->delete_vs_state(pipe, ctx->vs_tex); + pipe->delete_vs_state(pipe, ctx->vs); pipe->delete_vertex_elements_state(pipe, ctx->velem_state); for (i = 0; i < PIPE_MAX_TEXTURE_TYPES; i++) { @@ -419,17 +409,17 @@ static void blitter_set_clear_color(struct blitter_context_priv *ctx, } static void get_texcoords(struct pipe_resource *src, - struct pipe_subresource subsrc, - unsigned x1, unsigned y1, - unsigned x2, unsigned y2, - boolean normalized, float out[4]) + unsigned level, + unsigned x1, unsigned y1, + unsigned x2, unsigned y2, + boolean normalized, float out[4]) { if(normalized) { - out[0] = x1 / (float)u_minify(src->width0, subsrc.level); - out[1] = y1 / (float)u_minify(src->height0, subsrc.level); - out[2] = x2 / (float)u_minify(src->width0, subsrc.level); - out[3] = y2 / (float)u_minify(src->height0, subsrc.level); + out[0] = x1 / (float)u_minify(src->width0, level); + out[1] = y1 / (float)u_minify(src->height0, level); + out[2] = x2 / (float)u_minify(src->width0, level); + out[3] = y2 / (float)u_minify(src->height0, level); } else { @@ -458,14 +448,14 @@ static void set_texcoords_in_vertices(const float coord[4], static void blitter_set_texcoords_2d(struct blitter_context_priv *ctx, struct pipe_resource *src, - struct pipe_subresource subsrc, + unsigned level, unsigned x1, unsigned y1, unsigned x2, unsigned y2) { unsigned i; float coord[4]; - get_texcoords(src, subsrc, x1, y1, x2, y2, TRUE, coord); + get_texcoords(src, level, x1, y1, x2, y2, TRUE, coord); set_texcoords_in_vertices(coord, &ctx->vertices[0][1][0], 8); for (i = 0; i < 4; i++) { @@ -476,15 +466,15 @@ static void blitter_set_texcoords_2d(struct blitter_context_priv *ctx, static void blitter_set_texcoords_3d(struct blitter_context_priv *ctx, struct pipe_resource *src, - struct pipe_subresource subsrc, + unsigned level, unsigned zslice, unsigned x1, unsigned y1, unsigned x2, unsigned y2) { int i; - float r = zslice / (float)u_minify(src->depth0, subsrc.level); + float r = zslice / (float)u_minify(src->depth0, level); - blitter_set_texcoords_2d(ctx, src, subsrc, x1, y1, x2, y2); + blitter_set_texcoords_2d(ctx, src, level, x1, y1, x2, y2); for (i = 0; i < 4; i++) ctx->vertices[i][1][2] = r; /*r*/ @@ -492,7 +482,7 @@ static void blitter_set_texcoords_3d(struct blitter_context_priv *ctx, static void blitter_set_texcoords_cube(struct blitter_context_priv *ctx, struct pipe_resource *src, - struct pipe_subresource subsrc, + unsigned level, unsigned face, unsigned x1, unsigned y1, unsigned x2, unsigned y2) { @@ -500,10 +490,10 @@ static void blitter_set_texcoords_cube(struct blitter_context_priv *ctx, float coord[4]; float st[4][2]; - get_texcoords(src, subsrc, x1, y1, x2, y2, TRUE, coord); + get_texcoords(src, level, x1, y1, x2, y2, TRUE, coord); set_texcoords_in_vertices(coord, &st[0][0], 2); - util_map_texcoords2d_onto_cubemap(subsrc.face, + util_map_texcoords2d_onto_cubemap(face, /* pointer, stride in floats */ &st[0][0], 2, &ctx->vertices[0][1][0], 8); @@ -522,10 +512,13 @@ static void blitter_set_dst_dimensions(struct blitter_context_priv *ctx, static void blitter_draw_quad(struct blitter_context_priv *ctx) { struct pipe_context *pipe = ctx->base.pipe; + struct pipe_box box; /* write vertices and draw them */ - pipe_buffer_write(pipe, ctx->vbuf, - 0, sizeof(ctx->vertices), ctx->vertices); + u_box_1d(0, sizeof(ctx->vertices), &box); + pipe->transfer_inline_write(pipe, ctx->vbuf, 0, + PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, + &box, ctx->vertices, sizeof(ctx->vertices), 0); util_draw_vertex_buffer(pipe, ctx->vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, /* verts */ @@ -566,7 +559,9 @@ void *blitter_get_fs_col(struct blitter_context_priv *ctx, unsigned num_cbufs) if (!ctx->fs_col[num_cbufs]) ctx->fs_col[num_cbufs] = - util_make_fragment_clonecolor_shader(pipe, num_cbufs); + util_make_fragment_cloneinput_shader(pipe, num_cbufs, + TGSI_SEMANTIC_GENERIC, + TGSI_INTERPOLATE_LINEAR); return ctx->fs_col[num_cbufs]; } @@ -697,7 +692,7 @@ void util_blitter_clear(struct blitter_context *blitter, pipe->bind_rasterizer_state(pipe, ctx->rs_state); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, num_cbufs)); - pipe->bind_vs_state(pipe, ctx->vs_col); + pipe->bind_vs_state(pipe, ctx->vs); blitter_set_dst_dimensions(ctx, width, height); blitter->draw_rectangle(blitter, 0, 0, width, height, depth, @@ -714,21 +709,22 @@ boolean is_overlap(unsigned sx1, unsigned sx2, unsigned sy1, unsigned sy2, void util_blitter_copy_region(struct blitter_context *blitter, struct pipe_resource *dst, - struct pipe_subresource subdst, + unsigned dstlevel, unsigned dstx, unsigned dsty, unsigned dstz, struct pipe_resource *src, - struct pipe_subresource subsrc, - unsigned srcx, unsigned srcy, unsigned srcz, - unsigned width, unsigned height, + unsigned srclevel, + const struct pipe_box *srcbox, boolean ignore_stencil) { struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; struct pipe_context *pipe = ctx->base.pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_surface *dstsurf; + struct pipe_surface *dstsurf, surf_templ; struct pipe_framebuffer_state fb_state; struct pipe_sampler_view viewTempl, *view; unsigned bind; + unsigned width = srcbox->width; + unsigned height = srcbox->height; boolean is_stencil, is_depth; boolean normalized; @@ -739,12 +735,15 @@ void util_blitter_copy_region(struct blitter_context *blitter, /* Sanity checks. */ if (dst == src) { - assert(!is_overlap(srcx, srcx + width, srcy, srcy + height, + assert(!is_overlap(srcbox->x, srcbox->x + width, srcbox->y, srcbox->y + height, dstx, dstx + width, dsty, dsty + height)); } else { - assert(dst->format == src->format); + assert(util_is_format_compatible(util_format_description(dst->format), + util_format_description(src->format))); } assert(src->target < PIPE_MAX_TEXTURE_TYPES); + /* XXX should handle 3d regions */ + assert(srcbox->depth == 1); /* Is this a ZS format? */ is_depth = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0; @@ -762,15 +761,18 @@ void util_blitter_copy_region(struct blitter_context *blitter, dst->nr_samples, bind, 0) || !screen->is_format_supported(screen, src->format, src->target, src->nr_samples, PIPE_BIND_SAMPLER_VIEW, 0)) { - util_resource_copy_region(pipe, dst, subdst, dstx, dsty, dstz, - src, subsrc, srcx, srcy, srcz, width, height); + util_resource_copy_region(pipe, dst, dstlevel, dstx, dsty, dstz, + src, srclevel, srcbox); return; } - /* Get surfaces. */ - dstsurf = screen->get_tex_surface(screen, dst, - subdst.face, subdst.level, dstz, - bind); + /* Get surface. */ + memset(&surf_templ, 0, sizeof(surf_templ)); + u_surface_default_template(&surf_templ, dst, bind); + surf_templ.u.tex.level = dstlevel; + surf_templ.u.tex.first_layer = dstz; + surf_templ.u.tex.last_layer = dstz; + dstsurf = pipe->create_surface(pipe, dst, &surf_templ); /* Check whether the states are properly saved. */ blitter_check_saved_CSOs(ctx); @@ -810,9 +812,9 @@ void util_blitter_copy_region(struct blitter_context *blitter, /* Set rasterizer state, shaders, and textures. */ pipe->bind_rasterizer_state(pipe, ctx->rs_state); - pipe->bind_vs_state(pipe, ctx->vs_tex); + pipe->bind_vs_state(pipe, ctx->vs); pipe->bind_fragment_sampler_states(pipe, 1, - blitter_get_sampler_state(ctx, subsrc.level, normalized)); + blitter_get_sampler_state(ctx, srclevel, normalized)); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); pipe->set_fragment_sampler_views(pipe, 1, &view); pipe->set_framebuffer_state(pipe, &fb_state); @@ -827,8 +829,8 @@ void util_blitter_copy_region(struct blitter_context *blitter, { /* Set texture coordinates. */ float coord[4]; - get_texcoords(src, subsrc, srcx, srcy, - srcx+width, srcy+height, normalized, coord); + get_texcoords(src, srclevel, srcbox->x, srcbox->y, + srcbox->x+width, srcbox->y+height, normalized, coord); /* Draw. */ blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, 0, @@ -841,11 +843,13 @@ void util_blitter_copy_region(struct blitter_context *blitter, case PIPE_TEXTURE_CUBE: /* Set texture coordinates. */ if (src->target == PIPE_TEXTURE_3D) - blitter_set_texcoords_3d(ctx, src, subsrc, srcz, - srcx, srcy, srcx+width, srcy+height); + blitter_set_texcoords_3d(ctx, src, srclevel, srcbox->z, + srcbox->x, srcbox->y, + srcbox->x + width, srcbox->y + height); else - blitter_set_texcoords_cube(ctx, src, subsrc, - srcx, srcy, srcx+width, srcy+height); + blitter_set_texcoords_cube(ctx, src, srclevel, srcbox->z, + srcbox->x, srcbox->y, + srcbox->x + width, srcbox->y + height); /* Draw. */ blitter_set_rectangle(ctx, dstx, dsty, dstx+width, dsty+height, 0); @@ -887,7 +891,7 @@ void util_blitter_clear_render_target(struct blitter_context *blitter, pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil); pipe->bind_rasterizer_state(pipe, ctx->rs_state); pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1)); - pipe->bind_vs_state(pipe, ctx->vs_col); + pipe->bind_vs_state(pipe, ctx->vs); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); /* set a framebuffer state */ @@ -947,7 +951,7 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter, pipe->bind_rasterizer_state(pipe, ctx->rs_state); pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0)); - pipe->bind_vs_state(pipe, ctx->vs_col); + pipe->bind_vs_state(pipe, ctx->vs); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); /* set a framebuffer state */ @@ -988,7 +992,7 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter, pipe->bind_rasterizer_state(pipe, ctx->rs_state); pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0)); - pipe->bind_vs_state(pipe, ctx->vs_col); + pipe->bind_vs_state(pipe, ctx->vs); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); /* set a framebuffer state */ diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h index f9f96f25c77..c5660cf2d00 100644 --- a/src/gallium/auxiliary/util/u_blitter.h +++ b/src/gallium/auxiliary/util/u_blitter.h @@ -164,12 +164,11 @@ void util_blitter_clear(struct blitter_context *blitter, */ void util_blitter_copy_region(struct blitter_context *blitter, struct pipe_resource *dst, - struct pipe_subresource subdst, + unsigned dstlevel, unsigned dstx, unsigned dsty, unsigned dstz, struct pipe_resource *src, - struct pipe_subresource subsrc, - unsigned srcx, unsigned srcy, unsigned srcz, - unsigned width, unsigned height, + unsigned srclevel, + const struct pipe_box *srcbox, boolean ignore_stencil); /** diff --git a/src/gallium/auxiliary/util/u_box.h b/src/gallium/auxiliary/util/u_box.h index e9c71743fc8..0b28d0f12c3 100644 --- a/src/gallium/auxiliary/util/u_box.h +++ b/src/gallium/auxiliary/util/u_box.h @@ -60,7 +60,6 @@ void u_box_2d_zslice( unsigned x, box->depth = 1; } - static INLINE void u_box_3d( unsigned x, unsigned y, @@ -78,15 +77,4 @@ void u_box_3d( unsigned x, box->depth = d; } - -static INLINE -struct pipe_subresource u_subresource( unsigned face, - unsigned level ) -{ - struct pipe_subresource subresource; - subresource.face = face; - subresource.level = level; - return subresource; -} - #endif diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 504e6d2a18f..2ad2f95b13e 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -40,7 +40,8 @@ #include "util/u_string.h" #include "util/u_math.h" #include "util/u_tile.h" -#include "util/u_prim.h" +#include "util/u_prim.h" +#include "util/u_surface.h" #include <limits.h> /* CHAR_BIT */ @@ -453,9 +454,10 @@ void debug_dump_image(const char *prefix, #endif } +/* FIXME: dump resources, not surfaces... */ void debug_dump_surface(struct pipe_context *pipe, - const char *prefix, - struct pipe_surface *surface) + const char *prefix, + struct pipe_surface *surface) { struct pipe_resource *texture; struct pipe_transfer *transfer; @@ -472,23 +474,23 @@ void debug_dump_surface(struct pipe_context *pipe, */ texture = surface->texture; - transfer = pipe_get_transfer(pipe, texture, surface->face, - surface->level, surface->zslice, - PIPE_TRANSFER_READ, 0, 0, surface->width, - surface->height); - + transfer = pipe_get_transfer(pipe, texture, surface->u.tex.level, + surface->u.tex.first_layer, + PIPE_TRANSFER_READ, + 0, 0, surface->width, surface->height); + data = pipe->transfer_map(pipe, transfer); if(!data) goto error; - - debug_dump_image(prefix, + + debug_dump_image(prefix, texture->format, - util_format_get_blocksize(texture->format), + util_format_get_blocksize(texture->format), util_format_get_nblocksx(texture->format, surface->width), util_format_get_nblocksy(texture->format, surface->height), transfer->stride, data); - + pipe->transfer_unmap(pipe, transfer); error: pipe->transfer_destroy(pipe, transfer); @@ -499,20 +501,18 @@ void debug_dump_texture(struct pipe_context *pipe, const char *prefix, struct pipe_resource *texture) { - struct pipe_surface *surface; - struct pipe_screen *screen; + struct pipe_surface *surface, surf_tmpl; if (!texture) return; - screen = texture->screen; - - /* XXX for now, just dump image for face=0, level=0 */ - surface = screen->get_tex_surface(screen, texture, 0, 0, 0, - PIPE_BIND_SAMPLER_VIEW); + /* XXX for now, just dump image for layer=0, level=0 */ + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + u_surface_default_template(&surf_tmpl, texture, 0 /* no bind flag - not a surface */); + surface = pipe->create_surface(pipe, texture, &surf_tmpl); if (surface) { debug_dump_surface(pipe, prefix, surface); - screen->tex_surface_destroy(surface); + pipe->surface_destroy(pipe, surface); } } @@ -550,17 +550,16 @@ struct bmp_rgb_quad { void debug_dump_surface_bmp(struct pipe_context *pipe, - const char *filename, + const char *filename, struct pipe_surface *surface) { #ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT struct pipe_transfer *transfer; struct pipe_resource *texture = surface->texture; - transfer = pipe_get_transfer(pipe, texture, surface->face, - surface->level, surface->zslice, - PIPE_TRANSFER_READ, 0, 0, surface->width, - surface->height); + transfer = pipe_get_transfer(pipe, texture, surface->u.tex.level, + surface->u.tex.first_layer, PIPE_TRANSFER_READ, + 0, 0, surface->width, surface->height); debug_dump_transfer_bmp(pipe, filename, transfer); diff --git a/src/gallium/auxiliary/util/u_debug_describe.c b/src/gallium/auxiliary/util/u_debug_describe.c index 1c90ff31069..7ed8ee608a8 100644 --- a/src/gallium/auxiliary/util/u_debug_describe.c +++ b/src/gallium/auxiliary/util/u_debug_describe.c @@ -69,7 +69,7 @@ debug_describe_surface(char* buf, const struct pipe_surface *ptr) { char res[128]; debug_describe_resource(res, ptr->texture); - util_sprintf(buf, "pipe_surface<%s,%u,%u,%u>", res, ptr->face, ptr->level, ptr->zslice); + util_sprintf(buf, "pipe_surface<%s,%u,%u,%u>", res, ptr->u.tex.level, ptr->u.tex.first_layer, ptr->u.tex.last_layer); } void diff --git a/src/gallium/auxiliary/util/u_debug_stack.c b/src/gallium/auxiliary/util/u_debug_stack.c index 528a1c394be..24e039fd226 100644 --- a/src/gallium/auxiliary/util/u_debug_stack.c +++ b/src/gallium/auxiliary/util/u_debug_stack.c @@ -48,7 +48,10 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace, if(!nr_frames) return; -#if defined(PIPE_CC_GCC) +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86) + __asm__ __volatile__("mov (%%ebp),%0": "=r" (frame_pointer)); + frame_pointer = (const void **)frame_pointer[0]; +#elif defined(PIPE_CC_GCC) frame_pointer = ((const void **)__builtin_frame_address(1)); #elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86) __asm { diff --git a/src/gallium/auxiliary/util/u_debug_symbol.c b/src/gallium/auxiliary/util/u_debug_symbol.c index 332952af88b..44d437747a1 100644 --- a/src/gallium/auxiliary/util/u_debug_symbol.c +++ b/src/gallium/auxiliary/util/u_debug_symbol.c @@ -40,7 +40,7 @@ #include "u_debug_symbol.h" #include "u_hash_table.h" -#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) && defined(PIPE_ARCH_X86) +#if defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86) #include <windows.h> #include <stddef.h> @@ -165,7 +165,7 @@ debug_symbol_name_glibc(const void *addr, char* buf, unsigned size) void debug_symbol_name(const void *addr, char* buf, unsigned size) { -#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) && defined(PIPE_ARCH_X86) +#if defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86) debug_symbol_name_imagehlp(addr, buf, size); if(buf[0]) return; diff --git a/src/gallium/auxiliary/util/u_dirty_flags.h b/src/gallium/auxiliary/util/u_dirty_flags.h index 7e1be45ad5a..40539f0b0ea 100644 --- a/src/gallium/auxiliary/util/u_dirty_flags.h +++ b/src/gallium/auxiliary/util/u_dirty_flags.h @@ -24,5 +24,9 @@ #define U_NEW_VERTEX_BUFFER 0x10000 #define U_NEW_QUERY 0x20000 #define U_NEW_DEPTH_STENCIL 0x40000 +#define U_NEW_GS 0x80000 +#define U_NEW_GS_CONSTANTS 0x100000 +#define U_NEW_GS_SAMPLER_VIEW 0x200000 +#define U_NEW_GS_SAMPLER_STATES 0x400000 #endif diff --git a/src/gallium/auxiliary/util/u_dirty_surfaces.h b/src/gallium/auxiliary/util/u_dirty_surfaces.h index fd1bbe5ffdf..f3618d9be74 100644 --- a/src/gallium/auxiliary/util/u_dirty_surfaces.h +++ b/src/gallium/auxiliary/util/u_dirty_surfaces.h @@ -77,7 +77,7 @@ util_dirty_surfaces_use_levels_for_sampling(struct pipe_context *pipe, struct ut struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list); next = p->next; - if(ds->base.level >= first && ds->base.level <= last) + if(ds->base.u.tex.level >= first && ds->base.u.tex.level <= last) flush(pipe, &ds->base); } } @@ -86,7 +86,8 @@ static INLINE void util_dirty_surfaces_use_for_sampling_with(struct pipe_context *pipe, struct util_dirty_surfaces *dss, struct pipe_sampler_view *psv, struct pipe_sampler_state *pss, util_dirty_surface_flush_t flush) { if(!LIST_IS_EMPTY(&dss->dirty_list)) - util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->first_level, MIN2((unsigned)ceilf(pss->max_lod) + psv->first_level, psv->last_level), flush); + util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->u.tex.first_level, + MIN2((unsigned)ceilf(pss->max_lod) + psv->u.tex.first_level, psv->u.tex.last_level), flush); } static INLINE void diff --git a/src/gallium/auxiliary/util/u_dump_state.c b/src/gallium/auxiliary/util/u_dump_state.c index cda5b8ba512..b471d59eebf 100644 --- a/src/gallium/auxiliary/util/u_dump_state.c +++ b/src/gallium/auxiliary/util/u_dump_state.c @@ -279,6 +279,10 @@ util_dump_template(struct os_stream *stream, const struct pipe_resource *templat util_dump_uint(stream, templat->depth0); util_dump_member_end(stream); + util_dump_member_begin(stream, "array_size"); + util_dump_uint(stream, templat->array_size); + util_dump_member_end(stream); + util_dump_member(stream, uint, templat, last_level); util_dump_member(stream, uint, templat, usage); util_dump_member(stream, uint, templat, bind); @@ -633,14 +637,12 @@ util_dump_surface(struct os_stream *stream, const struct pipe_surface *state) util_dump_member(stream, uint, state, width); util_dump_member(stream, uint, state, height); - util_dump_member(stream, uint, state, layout); - util_dump_member(stream, uint, state, offset); util_dump_member(stream, uint, state, usage); util_dump_member(stream, ptr, state, texture); - util_dump_member(stream, uint, state, face); - util_dump_member(stream, uint, state, level); - util_dump_member(stream, uint, state, zslice); + util_dump_member(stream, uint, state, u.tex.level); + util_dump_member(stream, uint, state, u.tex.first_layer); + util_dump_member(stream, uint, state, u.tex.last_layer); util_dump_struct_end(stream); } @@ -660,7 +662,7 @@ util_dump_transfer(struct os_stream *stream, const struct pipe_transfer *state) /*util_dump_member(stream, uint, state, box);*/ util_dump_member(stream, uint, state, stride); - util_dump_member(stream, uint, state, slice_stride); + util_dump_member(stream, uint, state, layer_stride); /*util_dump_member(stream, ptr, state, data);*/ diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 6a931a95819..d22ae8b375b 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -48,6 +48,8 @@ #include "util/u_simple_shaders.h" #include "util/u_math.h" #include "util/u_texture.h" +#include "util/u_half.h" +#include "util/u_surface.h" #include "cso_cache/cso_context.h" @@ -65,7 +67,7 @@ struct gen_mipmap_state struct pipe_vertex_element velem[2]; void *vs; - void *fs2d, *fsCube; + void *fs1d, *fs2d, *fs3d, *fsCube; struct pipe_resource *vbuf; /**< quad vertices */ unsigned vbuf_slot; @@ -89,24 +91,7 @@ enum dtype }; -typedef ushort half_float; - - -static half_float -float_to_half(float f) -{ - /* XXX fix this */ - return 0; -} - -static float -half_to_float(half_float h) -{ - /* XXX fix this */ - return 0.0f; -} - - +typedef uint16_t half_float; /** @@ -145,7 +130,7 @@ half_to_float(half_float h) rowC[j][e], rowC[k][e], \ rowD[j][e], rowD[k][e]); \ } while(0) - + #define FILTER_F_3D(e) \ do { \ dst[i][e] = (rowA[j][e] + rowA[k][e] \ @@ -156,15 +141,15 @@ half_to_float(half_float h) #define FILTER_HF_3D(e) \ do { \ - const float aj = half_to_float(rowA[j][e]); \ - const float ak = half_to_float(rowA[k][e]); \ - const float bj = half_to_float(rowB[j][e]); \ - const float bk = half_to_float(rowB[k][e]); \ - const float cj = half_to_float(rowC[j][e]); \ - const float ck = half_to_float(rowC[k][e]); \ - const float dj = half_to_float(rowD[j][e]); \ - const float dk = half_to_float(rowD[k][e]); \ - dst[i][e] = float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \ + const float aj = util_half_to_float(rowA[j][e]); \ + const float ak = util_half_to_float(rowA[k][e]); \ + const float bj = util_half_to_float(rowB[j][e]); \ + const float bk = util_half_to_float(rowB[k][e]); \ + const float cj = util_half_to_float(rowC[j][e]); \ + const float ck = util_half_to_float(rowC[k][e]); \ + const float dj = util_half_to_float(rowD[j][e]); \ + const float dk = util_half_to_float(rowD[k][e]); \ + dst[i][e] = util_float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \ * 0.125F); \ } while(0) /*@}*/ @@ -343,8 +328,7 @@ do_row(enum dtype datatype, uint comps, int srcWidth, } } -#if 0 - else if (datatype == HALF_DTYPE_FLOAT && comps == 4) { + else if (datatype == DTYPE_HALF_FLOAT && comps == 4) { uint i, j, k, comp; const half_float(*rowA)[4] = (const half_float(*)[4]) srcRowA; const half_float(*rowB)[4] = (const half_float(*)[4]) srcRowB; @@ -353,11 +337,11 @@ do_row(enum dtype datatype, uint comps, int srcWidth, i++, j += colStride, k += colStride) { for (comp = 0; comp < 4; comp++) { float aj, ak, bj, bk; - aj = half_to_float(rowA[j][comp]); - ak = half_to_float(rowA[k][comp]); - bj = half_to_float(rowB[j][comp]); - bk = half_to_float(rowB[k][comp]); - dst[i][comp] = float_to_half((aj + ak + bj + bk) * 0.25F); + aj = util_half_to_float(rowA[j][comp]); + ak = util_half_to_float(rowA[k][comp]); + bj = util_half_to_float(rowB[j][comp]); + bk = util_half_to_float(rowB[k][comp]); + dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F); } } } @@ -370,11 +354,11 @@ do_row(enum dtype datatype, uint comps, int srcWidth, i++, j += colStride, k += colStride) { for (comp = 0; comp < 3; comp++) { float aj, ak, bj, bk; - aj = half_to_float(rowA[j][comp]); - ak = half_to_float(rowA[k][comp]); - bj = half_to_float(rowB[j][comp]); - bk = half_to_float(rowB[k][comp]); - dst[i][comp] = float_to_half((aj + ak + bj + bk) * 0.25F); + aj = util_half_to_float(rowA[j][comp]); + ak = util_half_to_float(rowA[k][comp]); + bj = util_half_to_float(rowB[j][comp]); + bk = util_half_to_float(rowB[k][comp]); + dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F); } } } @@ -387,11 +371,11 @@ do_row(enum dtype datatype, uint comps, int srcWidth, i++, j += colStride, k += colStride) { for (comp = 0; comp < 2; comp++) { float aj, ak, bj, bk; - aj = half_to_float(rowA[j][comp]); - ak = half_to_float(rowA[k][comp]); - bj = half_to_float(rowB[j][comp]); - bk = half_to_float(rowB[k][comp]); - dst[i][comp] = float_to_half((aj + ak + bj + bk) * 0.25F); + aj = util_half_to_float(rowA[j][comp]); + ak = util_half_to_float(rowA[k][comp]); + bj = util_half_to_float(rowB[j][comp]); + bk = util_half_to_float(rowB[k][comp]); + dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F); } } } @@ -403,14 +387,13 @@ do_row(enum dtype datatype, uint comps, int srcWidth, for (i = j = 0, k = k0; i < (uint) dstWidth; i++, j += colStride, k += colStride) { float aj, ak, bj, bk; - aj = half_to_float(rowA[j]); - ak = half_to_float(rowA[k]); - bj = half_to_float(rowB[j]); - bk = half_to_float(rowB[k]); - dst[i] = float_to_half((aj + ak + bj + bk) * 0.25F); + aj = util_half_to_float(rowA[j]); + ak = util_half_to_float(rowA[k]); + bj = util_half_to_float(rowB[j]); + bk = util_half_to_float(rowB[k]); + dst[i] = util_float_to_half((aj + ak + bj + bk) * 0.25F); } } -#endif else if (datatype == DTYPE_UINT && comps == 1) { uint i, j, k; @@ -1036,32 +1019,34 @@ reduce_2d(enum pipe_format pformat, static void reduce_3d(enum pipe_format pformat, int srcWidth, int srcHeight, int srcDepth, - int srcRowStride, const ubyte *srcPtr, + int srcRowStride, int srcImageStride, const ubyte *srcPtr, int dstWidth, int dstHeight, int dstDepth, - int dstRowStride, ubyte *dstPtr) + int dstRowStride, int dstImageStride, ubyte *dstPtr) { const int bpt = util_format_get_blocksize(pformat); - const int border = 0; int img, row; - int bytesPerSrcImage, bytesPerDstImage; - int bytesPerSrcRow, bytesPerDstRow; int srcImageOffset, srcRowOffset; enum dtype datatype; uint comps; format_to_type_comps(pformat, &datatype, &comps); - bytesPerSrcImage = srcWidth * srcHeight * bpt; - bytesPerDstImage = dstWidth * dstHeight * bpt; + /* XXX I think we should rather assert those strides */ + if (!srcImageStride) + srcImageStride = srcWidth * srcHeight * bpt; + if (!dstImageStride) + dstImageStride = dstWidth * dstHeight * bpt; - bytesPerSrcRow = srcWidth * bpt; - bytesPerDstRow = dstWidth * bpt; + if (!srcRowStride) + srcRowStride = srcWidth * bpt; + if (!dstRowStride) + dstRowStride = dstWidth * bpt; /* Offset between adjacent src images to be averaged together */ - srcImageOffset = (srcDepth == dstDepth) ? 0 : bytesPerSrcImage; + srcImageOffset = (srcDepth == dstDepth) ? 0 : srcImageStride; /* Offset between adjacent src rows to be averaged together */ - srcRowOffset = (srcHeight == dstHeight) ? 0 : srcWidth * bpt; + srcRowOffset = (srcHeight == dstHeight) ? 0 : srcRowStride; /* * Need to average together up to 8 src pixels for each dest pixel. @@ -1077,16 +1062,13 @@ reduce_3d(enum pipe_format pformat, */ for (img = 0; img < dstDepth; img++) { - /* first source image pointer, skipping border */ + /* first source image pointer */ const ubyte *imgSrcA = srcPtr - + (bytesPerSrcImage + bytesPerSrcRow + border) * bpt * border - + img * (bytesPerSrcImage + srcImageOffset); - /* second source image pointer, skipping border */ + + img * (srcImageStride + srcImageOffset); + /* second source image pointer */ const ubyte *imgSrcB = imgSrcA + srcImageOffset; - /* address of the dest image, skipping border */ - ubyte *imgDst = dstPtr - + (bytesPerDstImage + bytesPerDstRow + border) * bpt * border - + img * bytesPerDstImage; + /* address of the dest image */ + ubyte *imgDst = dstPtr + img * dstImageStride; /* setup the four source row pointers and the dest row pointer */ const ubyte *srcImgARowA = imgSrcA; @@ -1102,11 +1084,11 @@ reduce_3d(enum pipe_format pformat, dstWidth, dstImgRow); /* advance to next rows */ - srcImgARowA += bytesPerSrcRow + srcRowOffset; - srcImgARowB += bytesPerSrcRow + srcRowOffset; - srcImgBRowA += bytesPerSrcRow + srcRowOffset; - srcImgBRowB += bytesPerSrcRow + srcRowOffset; - dstImgRow += bytesPerDstRow; + srcImgARowA += srcRowStride + srcRowOffset; + srcImgARowB += srcRowStride + srcRowOffset; + srcImgBRowA += srcRowStride + srcRowOffset; + srcImgBRowB += srcRowStride + srcRowOffset; + dstImgRow += dstImageStride; } } } @@ -1117,25 +1099,24 @@ reduce_3d(enum pipe_format pformat, static void make_1d_mipmap(struct gen_mipmap_state *ctx, struct pipe_resource *pt, - uint face, uint baseLevel, uint lastLevel) + uint layer, uint baseLevel, uint lastLevel) { struct pipe_context *pipe = ctx->pipe; - const uint zslice = 0; uint dstLevel; for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { const uint srcLevel = dstLevel - 1; struct pipe_transfer *srcTrans, *dstTrans; void *srcMap, *dstMap; - - srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice, - PIPE_TRANSFER_READ, 0, 0, - u_minify(pt->width0, srcLevel), - u_minify(pt->height0, srcLevel)); - dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice, - PIPE_TRANSFER_WRITE, 0, 0, - u_minify(pt->width0, dstLevel), - u_minify(pt->height0, dstLevel)); + + srcTrans = pipe_get_transfer(pipe, pt, srcLevel, layer, + PIPE_TRANSFER_READ, 0, 0, + u_minify(pt->width0, srcLevel), + u_minify(pt->height0, srcLevel)); + dstTrans = pipe_get_transfer(pipe, pt, dstLevel, layer, + PIPE_TRANSFER_WRITE, 0, 0, + u_minify(pt->width0, dstLevel), + u_minify(pt->height0, dstLevel)); srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans); dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans); @@ -1156,12 +1137,11 @@ make_1d_mipmap(struct gen_mipmap_state *ctx, static void make_2d_mipmap(struct gen_mipmap_state *ctx, struct pipe_resource *pt, - uint face, uint baseLevel, uint lastLevel) + uint layer, uint baseLevel, uint lastLevel) { struct pipe_context *pipe = ctx->pipe; - const uint zslice = 0; uint dstLevel; - + assert(util_format_get_blockwidth(pt->format) == 1); assert(util_format_get_blockheight(pt->format) == 1); @@ -1169,15 +1149,15 @@ make_2d_mipmap(struct gen_mipmap_state *ctx, const uint srcLevel = dstLevel - 1; struct pipe_transfer *srcTrans, *dstTrans; ubyte *srcMap, *dstMap; - - srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice, - PIPE_TRANSFER_READ, 0, 0, - u_minify(pt->width0, srcLevel), - u_minify(pt->height0, srcLevel)); - dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice, - PIPE_TRANSFER_WRITE, 0, 0, - u_minify(pt->width0, dstLevel), - u_minify(pt->height0, dstLevel)); + + srcTrans = pipe_get_transfer(pipe, pt, srcLevel, layer, + PIPE_TRANSFER_READ, 0, 0, + u_minify(pt->width0, srcLevel), + u_minify(pt->height0, srcLevel)); + dstTrans = pipe_get_transfer(pipe, pt, dstLevel, layer, + PIPE_TRANSFER_WRITE, 0, 0, + u_minify(pt->width0, dstLevel), + u_minify(pt->height0, dstLevel)); srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans); dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans); @@ -1197,41 +1177,49 @@ make_2d_mipmap(struct gen_mipmap_state *ctx, } +/* XXX looks a bit more like it could work now but need to test */ static void make_3d_mipmap(struct gen_mipmap_state *ctx, struct pipe_resource *pt, uint face, uint baseLevel, uint lastLevel) { -#if 0 struct pipe_context *pipe = ctx->pipe; - struct pipe_screen *screen = pipe->screen; - uint dstLevel, zslice = 0; + uint dstLevel; + struct pipe_box src_box, dst_box; assert(util_format_get_blockwidth(pt->format) == 1); assert(util_format_get_blockheight(pt->format) == 1); + src_box.x = src_box.y = src_box.z = 0; + dst_box.x = dst_box.y = dst_box.z = 0; + for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { const uint srcLevel = dstLevel - 1; struct pipe_transfer *srcTrans, *dstTrans; ubyte *srcMap, *dstMap; - - srcTrans = pipe->get_transfer(pipe, pt, face, srcLevel, zslice, - PIPE_TRANSFER_READ, 0, 0, - u_minify(pt->width0, srcLevel), - u_minify(pt->height0, srcLevel)); - dstTrans = pipe->get_transfer(pipe, pt, face, dstLevel, zslice, - PIPE_TRANSFER_WRITE, 0, 0, - u_minify(pt->width0, dstLevel), - u_minify(pt->height0, dstLevel)); + struct pipe_box src_box, dst_box; + src_box.width = u_minify(pt->width0, srcLevel); + src_box.height = u_minify(pt->height0, srcLevel); + src_box.depth = u_minify(pt->depth0, srcLevel); + dst_box.width = u_minify(pt->width0, dstLevel); + dst_box.height = u_minify(pt->height0, dstLevel); + dst_box.depth = u_minify(pt->depth0, dstLevel); + + srcTrans = pipe->get_transfer(pipe, pt, srcLevel, + PIPE_TRANSFER_READ, + &src_box); + dstTrans = pipe->get_transfer(pipe, pt, dstLevel, + PIPE_TRANSFER_WRITE, + &dst_box); srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans); dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans); reduce_3d(pt->format, - srcTrans->width, srcTrans->height, - srcTrans->stride, srcMap, - dstTrans->width, dstTrans->height, - dstTrans->stride, dstMap); + srcTrans->box.width, srcTrans->box.height, srcTrans->box.depth, + srcTrans->stride, srcTrans->layer_stride, srcMap, + dstTrans->box.width, dstTrans->box.height, dstTrans->box.depth, + dstTrans->stride, dstTrans->layer_stride, dstMap); pipe->transfer_unmap(pipe, srcTrans); pipe->transfer_unmap(pipe, dstTrans); @@ -1239,28 +1227,25 @@ make_3d_mipmap(struct gen_mipmap_state *ctx, pipe->transfer_destroy(pipe, srcTrans); pipe->transfer_destroy(pipe, dstTrans); } -#else - (void) reduce_3d; -#endif } static void fallback_gen_mipmap(struct gen_mipmap_state *ctx, struct pipe_resource *pt, - uint face, uint baseLevel, uint lastLevel) + uint layer, uint baseLevel, uint lastLevel) { switch (pt->target) { case PIPE_TEXTURE_1D: - make_1d_mipmap(ctx, pt, face, baseLevel, lastLevel); + make_1d_mipmap(ctx, pt, layer, baseLevel, lastLevel); break; case PIPE_TEXTURE_2D: case PIPE_TEXTURE_RECT: case PIPE_TEXTURE_CUBE: - make_2d_mipmap(ctx, pt, face, baseLevel, lastLevel); + make_2d_mipmap(ctx, pt, layer, baseLevel, lastLevel); break; case PIPE_TEXTURE_3D: - make_3d_mipmap(ctx, pt, face, baseLevel, lastLevel); + make_3d_mipmap(ctx, pt, layer, baseLevel, lastLevel); break; default: assert(0); @@ -1328,8 +1313,12 @@ util_create_gen_mipmap(struct pipe_context *pipe, } /* fragment shader */ + ctx->fs1d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_1D, + TGSI_INTERPOLATE_LINEAR); ctx->fs2d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D, TGSI_INTERPOLATE_LINEAR); + ctx->fs3d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_3D, + TGSI_INTERPOLATE_LINEAR); ctx->fsCube = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_CUBE, TGSI_INTERPOLATE_LINEAR); @@ -1371,7 +1360,7 @@ get_next_slot(struct gen_mipmap_state *ctx) static unsigned set_vertex_data(struct gen_mipmap_state *ctx, enum pipe_texture_target tex_target, - uint face) + uint layer, float r) { unsigned offset; @@ -1397,26 +1386,26 @@ set_vertex_data(struct gen_mipmap_state *ctx, {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f} }; - util_map_texcoords2d_onto_cubemap(face, &st[0][0], 2, + util_map_texcoords2d_onto_cubemap(layer, &st[0][0], 2, &ctx->vertices[0][1][0], 8); } else { - /* 1D/2D */ + /* 1D/2D/3D */ ctx->vertices[0][1][0] = 0.0f; /*s*/ ctx->vertices[0][1][1] = 0.0f; /*t*/ - ctx->vertices[0][1][2] = 0.0f; /*r*/ + ctx->vertices[0][1][2] = r; /*r*/ ctx->vertices[1][1][0] = 1.0f; ctx->vertices[1][1][1] = 0.0f; - ctx->vertices[1][1][2] = 0.0f; + ctx->vertices[1][1][2] = r; ctx->vertices[2][1][0] = 1.0f; ctx->vertices[2][1][1] = 1.0f; - ctx->vertices[2][1][2] = 0.0f; + ctx->vertices[2][1][2] = r; ctx->vertices[3][1][0] = 0.0f; ctx->vertices[3][1][1] = 1.0f; - ctx->vertices[3][1][2] = 0.0f; + ctx->vertices[3][1][2] = r; } offset = get_next_slot( ctx ); @@ -1437,9 +1426,11 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx) { struct pipe_context *pipe = ctx->pipe; - pipe->delete_vs_state(pipe, ctx->vs); - pipe->delete_fs_state(pipe, ctx->fs2d); pipe->delete_fs_state(pipe, ctx->fsCube); + pipe->delete_fs_state(pipe, ctx->fs3d); + pipe->delete_fs_state(pipe, ctx->fs2d); + pipe->delete_fs_state(pipe, ctx->fs1d); + pipe->delete_vs_state(pipe, ctx->vs); pipe_resource_reference(&ctx->vbuf, NULL); @@ -1478,9 +1469,8 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, struct pipe_screen *screen = pipe->screen; struct pipe_framebuffer_state fb; struct pipe_resource *pt = psv->texture; - void *fs = (pt->target == PIPE_TEXTURE_CUBE) ? ctx->fsCube : ctx->fs2d; + void *fs; uint dstLevel; - uint zslice = 0; uint offset; /* The texture object should have room for the levels which we're @@ -1494,8 +1484,28 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, assert(filter == PIPE_TEX_FILTER_LINEAR || filter == PIPE_TEX_FILTER_NEAREST); + switch (pt->target) { + case PIPE_TEXTURE_1D: + fs = ctx->fs1d; + break; + case PIPE_TEXTURE_2D: + fs = ctx->fs2d; + break; + case PIPE_TEXTURE_3D: + fs = ctx->fs3d; + break; + case PIPE_TEXTURE_CUBE: + fs = ctx->fsCube; + break; + case PIPE_TEXTURE_1D_ARRAY: + case PIPE_TEXTURE_2D_ARRAY: + default: + assert(0); + fs = ctx->fs2d; + } + /* check if we can render in the texture's format */ - if (!screen->is_format_supported(screen, psv->format, PIPE_TEXTURE_2D, + if (!screen->is_format_supported(screen, psv->format, pt->target, pt->nr_samples, PIPE_BIND_RENDER_TARGET, 0)) { fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel); return; @@ -1539,60 +1549,85 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { const uint srcLevel = dstLevel - 1; struct pipe_viewport_state vp; - - struct pipe_surface *surf = - screen->get_tex_surface(screen, pt, face, dstLevel, zslice, - PIPE_BIND_RENDER_TARGET); - - /* - * Setup framebuffer / dest surface - */ - fb.cbufs[0] = surf; - fb.width = u_minify(pt->width0, dstLevel); - fb.height = u_minify(pt->height0, dstLevel); - cso_set_framebuffer(ctx->cso, &fb); - - /* viewport */ - vp.scale[0] = 0.5f * fb.width; - vp.scale[1] = 0.5f * fb.height; - vp.scale[2] = 1.0f; - vp.scale[3] = 1.0f; - vp.translate[0] = 0.5f * fb.width; - vp.translate[1] = 0.5f * fb.height; - vp.translate[2] = 0.0f; - vp.translate[3] = 0.0f; - cso_set_viewport(ctx->cso, &vp); - - /* - * Setup sampler state - * Note: we should only have to set the min/max LOD clamps to ensure - * we grab texels from the right mipmap level. But some hardware - * has trouble with min clamping so we also set the lod_bias to - * try to work around that. - */ - ctx->sampler.min_lod = ctx->sampler.max_lod = (float) srcLevel; - ctx->sampler.lod_bias = (float) srcLevel; - cso_single_sampler(ctx->cso, 0, &ctx->sampler); - cso_single_sampler_done(ctx->cso); - - cso_set_fragment_sampler_views(ctx->cso, 1, &psv); - - /* quad coords in clip coords */ - offset = set_vertex_data(ctx, - pt->target, - face); - - util_draw_vertex_buffer(ctx->pipe, - ctx->vbuf, - offset, - PIPE_PRIM_TRIANGLE_FAN, - 4, /* verts */ - 2); /* attribs/vert */ - - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); - - /* need to signal that the texture has changed _after_ rendering to it */ - pipe_surface_reference( &surf, NULL ); + unsigned nr_layers, layer, i; + float rcoord = 0.0f; + + if (pt->target == PIPE_TEXTURE_3D) + nr_layers = u_minify(pt->depth0, dstLevel); + else + nr_layers = 1; + + for (i = 0; i < nr_layers; i++) { + struct pipe_surface *surf, surf_templ; + if (pt->target == PIPE_TEXTURE_3D) { + /* in theory with geom shaders and driver with full layer support + could do that in one go. */ + layer = i; + offset = 1.0f / (float)(nr_layers * 2); + /* XXX hmm really? */ + rcoord = (float)layer / (float)nr_layers + 1.0f / (float)(nr_layers * 2); + } + else + layer = face; + + memset(&surf_templ, 0, sizeof(surf_templ)); + u_surface_default_template(&surf_templ, pt, PIPE_BIND_RENDER_TARGET); + surf_templ.u.tex.level = dstLevel; + surf_templ.u.tex.first_layer = layer; + surf_templ.u.tex.last_layer = layer; + surf = pipe->create_surface(pipe, pt, &surf_templ); + + /* + * Setup framebuffer / dest surface + */ + fb.cbufs[0] = surf; + fb.width = u_minify(pt->width0, dstLevel); + fb.height = u_minify(pt->height0, dstLevel); + cso_set_framebuffer(ctx->cso, &fb); + + /* viewport */ + vp.scale[0] = 0.5f * fb.width; + vp.scale[1] = 0.5f * fb.height; + vp.scale[2] = 1.0f; + vp.scale[3] = 1.0f; + vp.translate[0] = 0.5f * fb.width; + vp.translate[1] = 0.5f * fb.height; + vp.translate[2] = 0.0f; + vp.translate[3] = 0.0f; + cso_set_viewport(ctx->cso, &vp); + + /* + * Setup sampler state + * Note: we should only have to set the min/max LOD clamps to ensure + * we grab texels from the right mipmap level. But some hardware + * has trouble with min clamping so we also set the lod_bias to + * try to work around that. + */ + ctx->sampler.min_lod = ctx->sampler.max_lod = (float) srcLevel; + ctx->sampler.lod_bias = (float) srcLevel; + cso_single_sampler(ctx->cso, 0, &ctx->sampler); + cso_single_sampler_done(ctx->cso); + + cso_set_fragment_sampler_views(ctx->cso, 1, &psv); + + /* quad coords in clip coords */ + offset = set_vertex_data(ctx, + pt->target, + face, + rcoord); + + util_draw_vertex_buffer(ctx->pipe, + ctx->vbuf, + offset, + PIPE_PRIM_TRIANGLE_FAN, + 4, /* verts */ + 2); /* attribs/vert */ + + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + /* need to signal that the texture has changed _after_ rendering to it */ + pipe_surface_reference( &surf, NULL ); + } } /* restore state we changed */ diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.h b/src/gallium/auxiliary/util/u_gen_mipmap.h index a7502b9982b..a10b6a4aba9 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.h +++ b/src/gallium/auxiliary/util/u_gen_mipmap.h @@ -60,7 +60,7 @@ util_gen_mipmap_flush( struct gen_mipmap_state *ctx ); extern void util_gen_mipmap(struct gen_mipmap_state *ctx, struct pipe_sampler_view *psv, - uint face, uint baseLevel, uint lastLevel, uint filter); + uint layer, uint baseLevel, uint lastLevel, uint filter); #ifdef __cplusplus diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index 6ed39561fbe..e55aafe90f0 100644 --- a/src/gallium/auxiliary/util/u_inlines.h +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -109,7 +109,7 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) if (pipe_reference_described(&(*ptr)->reference, &surf->reference, (debug_reference_descriptor)debug_describe_surface)) - old_surf->texture->screen->tex_surface_destroy(old_surf); + old_surf->context->surface_destroy(old_surf->context, old_surf); *ptr = surf; } @@ -136,26 +136,28 @@ pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct pipe_sampler_ } static INLINE void -pipe_surface_reset(struct pipe_surface* ps, struct pipe_resource *pt, - unsigned face, unsigned level, unsigned zslice, unsigned flags) +pipe_surface_reset(struct pipe_context *ctx, struct pipe_surface* ps, + struct pipe_resource *pt, unsigned level, unsigned layer, + unsigned flags) { pipe_resource_reference(&ps->texture, pt); ps->format = pt->format; ps->width = u_minify(pt->width0, level); ps->height = u_minify(pt->height0, level); ps->usage = flags; - ps->face = face; - ps->level = level; - ps->zslice = zslice; + ps->u.tex.level = level; + ps->u.tex.first_layer = ps->u.tex.last_layer = layer; + ps->context = ctx; } static INLINE void -pipe_surface_init(struct pipe_surface* ps, struct pipe_resource *pt, - unsigned face, unsigned level, unsigned zslice, unsigned flags) +pipe_surface_init(struct pipe_context *ctx, struct pipe_surface* ps, + struct pipe_resource *pt, unsigned level, unsigned layer, + unsigned flags) { ps->texture = 0; pipe_reference_init(&ps->reference, 1); - pipe_surface_reset(ps, pt, face, level, zslice, flags); + pipe_surface_reset(ctx, ps, pt, level, layer, flags); } /* @@ -177,6 +179,7 @@ pipe_buffer_create( struct pipe_screen *screen, buffer.width0 = size; buffer.height0 = 1; buffer.depth0 = 1; + buffer.array_size = 1; return screen->resource_create(screen, &buffer); } @@ -202,15 +205,15 @@ pipe_buffer_map_range(struct pipe_context *pipe, assert(offset < buffer->width0); assert(offset + length <= buffer->width0); assert(length); - + u_box_1d(offset, length, &box); *transfer = pipe->get_transfer( pipe, - buffer, - u_subresource(0, 0), - usage, - &box); - + buffer, + 0, + usage, + &box); + if (*transfer == NULL) return NULL; @@ -231,7 +234,7 @@ static INLINE void * pipe_buffer_map(struct pipe_context *pipe, struct pipe_resource *buffer, unsigned usage, - struct pipe_transfer **transfer) + struct pipe_transfer **transfer) { return pipe_buffer_map_range(pipe, buffer, 0, buffer->width0, usage, transfer); } @@ -240,7 +243,7 @@ pipe_buffer_map(struct pipe_context *pipe, static INLINE void pipe_buffer_unmap(struct pipe_context *pipe, struct pipe_resource *buf, - struct pipe_transfer *transfer) + struct pipe_transfer *transfer) { if (transfer) { pipe->transfer_unmap(pipe, transfer); @@ -250,7 +253,7 @@ pipe_buffer_unmap(struct pipe_context *pipe, static INLINE void pipe_buffer_flush_mapped_range(struct pipe_context *pipe, - struct pipe_transfer *transfer, + struct pipe_transfer *transfer, unsigned offset, unsigned length) { @@ -266,7 +269,7 @@ pipe_buffer_flush_mapped_range(struct pipe_context *pipe, * mapped range. */ transfer_offset = offset - transfer->box.x; - + u_box_1d(transfer_offset, length, &box); pipe->transfer_flush_region(pipe, transfer, &box); @@ -276,7 +279,7 @@ static INLINE void pipe_buffer_write(struct pipe_context *pipe, struct pipe_resource *buf, unsigned offset, - unsigned size, + unsigned size, const void *data) { struct pipe_box box; @@ -284,13 +287,13 @@ pipe_buffer_write(struct pipe_context *pipe, u_box_1d(offset, size, &box); pipe->transfer_inline_write( pipe, - buf, - u_subresource(0,0), - PIPE_TRANSFER_WRITE, - &box, - data, - size, - 0); + buf, + 0, + PIPE_TRANSFER_WRITE, + &box, + data, + size, + 0); } /** @@ -309,21 +312,21 @@ pipe_buffer_write_nooverlap(struct pipe_context *pipe, u_box_1d(offset, size, &box); - pipe->transfer_inline_write(pipe, - buf, - u_subresource(0,0), - (PIPE_TRANSFER_WRITE | - PIPE_TRANSFER_NOOVERWRITE), - &box, - data, - 0, 0); + pipe->transfer_inline_write(pipe, + buf, + 0, + (PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_NOOVERWRITE), + &box, + data, + 0, 0); } static INLINE void pipe_buffer_read(struct pipe_context *pipe, struct pipe_resource *buf, unsigned offset, - unsigned size, + unsigned size, void *data) { struct pipe_transfer *src_transfer; @@ -343,20 +346,19 @@ pipe_buffer_read(struct pipe_context *pipe, static INLINE struct pipe_transfer * pipe_get_transfer( struct pipe_context *context, - struct pipe_resource *resource, - unsigned face, unsigned level, - unsigned zslice, - enum pipe_transfer_usage usage, - unsigned x, unsigned y, - unsigned w, unsigned h) + struct pipe_resource *resource, + unsigned level, unsigned layer, + enum pipe_transfer_usage usage, + unsigned x, unsigned y, + unsigned w, unsigned h) { struct pipe_box box; - u_box_2d_zslice( x, y, zslice, w, h, &box ); + u_box_2d_zslice( x, y, layer, w, h, &box ); return context->get_transfer( context, - resource, - u_subresource(face, level), - usage, - &box ); + resource, + level, + usage, + &box ); } static INLINE void * @@ -376,7 +378,7 @@ pipe_transfer_unmap( struct pipe_context *context, static INLINE void pipe_transfer_destroy( struct pipe_context *context, - struct pipe_transfer *transfer ) + struct pipe_transfer *transfer ) { context->transfer_destroy(context, transfer); } diff --git a/src/gallium/auxiliary/util/u_resource.c b/src/gallium/auxiliary/util/u_resource.c index 9e6474b83de..443c9f8067e 100644 --- a/src/gallium/auxiliary/util/u_resource.c +++ b/src/gallium/auxiliary/util/u_resource.c @@ -10,85 +10,85 @@ u_resource( struct pipe_resource *res ) } boolean u_resource_get_handle_vtbl(struct pipe_screen *screen, - struct pipe_resource *resource, - struct winsys_handle *handle) + struct pipe_resource *resource, + struct winsys_handle *handle) { struct u_resource *ur = u_resource(resource); return ur->vtbl->resource_get_handle(screen, resource, handle); } void u_resource_destroy_vtbl(struct pipe_screen *screen, - struct pipe_resource *resource) + struct pipe_resource *resource) { struct u_resource *ur = u_resource(resource); ur->vtbl->resource_destroy(screen, resource); } unsigned u_is_resource_referenced_vtbl( struct pipe_context *pipe, - struct pipe_resource *resource, - unsigned face, unsigned level) + struct pipe_resource *resource, + unsigned level, int layer) { struct u_resource *ur = u_resource(resource); - return ur->vtbl->is_resource_referenced(pipe, resource, face, level); + return ur->vtbl->is_resource_referenced(pipe, resource, level, layer); } struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context, - struct pipe_resource *resource, - struct pipe_subresource sr, - enum pipe_transfer_usage usage, - const struct pipe_box *box) + struct pipe_resource *resource, + unsigned level, + enum pipe_transfer_usage usage, + const struct pipe_box *box) { struct u_resource *ur = u_resource(resource); - return ur->vtbl->get_transfer(context, resource, sr, usage, box); + return ur->vtbl->get_transfer(context, resource, level, usage, box); } void u_transfer_destroy_vtbl(struct pipe_context *pipe, - struct pipe_transfer *transfer) + struct pipe_transfer *transfer) { struct u_resource *ur = u_resource(transfer->resource); ur->vtbl->transfer_destroy(pipe, transfer); } void *u_transfer_map_vtbl( struct pipe_context *pipe, - struct pipe_transfer *transfer ) + struct pipe_transfer *transfer ) { struct u_resource *ur = u_resource(transfer->resource); return ur->vtbl->transfer_map(pipe, transfer); } void u_transfer_flush_region_vtbl( struct pipe_context *pipe, - struct pipe_transfer *transfer, - const struct pipe_box *box) + struct pipe_transfer *transfer, + const struct pipe_box *box) { struct u_resource *ur = u_resource(transfer->resource); ur->vtbl->transfer_flush_region(pipe, transfer, box); } void u_transfer_unmap_vtbl( struct pipe_context *pipe, - struct pipe_transfer *transfer ) + struct pipe_transfer *transfer ) { struct u_resource *ur = u_resource(transfer->resource); ur->vtbl->transfer_unmap(pipe, transfer); } void u_transfer_inline_write_vtbl( struct pipe_context *pipe, - struct pipe_resource *resource, - struct pipe_subresource sr, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned slice_stride) + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) { struct u_resource *ur = u_resource(resource); - ur->vtbl->transfer_inline_write(pipe, - resource, - sr, - usage, - box, - data, - stride, - slice_stride); + ur->vtbl->transfer_inline_write(pipe, + resource, + level, + usage, + box, + data, + stride, + layer_stride); } diff --git a/src/gallium/auxiliary/util/u_sampler.c b/src/gallium/auxiliary/util/u_sampler.c index e77f562ea22..bb26099b7e1 100644 --- a/src/gallium/auxiliary/util/u_sampler.c +++ b/src/gallium/auxiliary/util/u_sampler.c @@ -40,8 +40,11 @@ default_template(struct pipe_sampler_view *view, */ view->format = format; - view->first_level = 0; - view->last_level = texture->last_level; + view->u.tex.first_level = 0; + view->u.tex.last_level = texture->last_level; + view->u.tex.first_layer = 0; + view->u.tex.last_layer = texture->target == PIPE_TEXTURE_3D ? + texture->depth0 - 1 : texture->array_size - 1; view->swizzle_r = PIPE_SWIZZLE_RED; view->swizzle_g = PIPE_SWIZZLE_GREEN; view->swizzle_b = PIPE_SWIZZLE_BLUE; diff --git a/src/gallium/auxiliary/util/u_simple_screen.h b/src/gallium/auxiliary/util/u_simple_screen.h index b52232f025c..7139aaabc56 100644 --- a/src/gallium/auxiliary/util/u_simple_screen.h +++ b/src/gallium/auxiliary/util/u_simple_screen.h @@ -57,7 +57,8 @@ struct pipe_winsys * displayed, eg copy fake frontbuffer. */ void (*flush_frontbuffer)( struct pipe_winsys *ws, - struct pipe_surface *surf, + struct pipe_resource *resource, + unsigned level, unsigned layer, void *context_private ); diff --git a/src/gallium/auxiliary/util/u_simple_shaders.c b/src/gallium/auxiliary/util/u_simple_shaders.c index 58ef68377fc..b0f2dd8aa29 100644 --- a/src/gallium/auxiliary/util/u_simple_shaders.c +++ b/src/gallium/auxiliary/util/u_simple_shaders.c @@ -204,7 +204,8 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe, void * util_make_fragment_passthrough_shader(struct pipe_context *pipe) { - return util_make_fragment_clonecolor_shader(pipe, 1); + return util_make_fragment_cloneinput_shader(pipe, 1, TGSI_SEMANTIC_COLOR, + TGSI_INTERPOLATE_PERSPECTIVE); } @@ -212,7 +213,9 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe) * Make a fragment shader that copies the input color to N output colors. */ void * -util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs) +util_make_fragment_cloneinput_shader(struct pipe_context *pipe, int num_cbufs, + int input_semantic, + int input_interpolate) { struct ureg_program *ureg; struct ureg_src src; @@ -225,8 +228,8 @@ util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs) if (ureg == NULL) return NULL; - src = ureg_DECL_fs_input( ureg, TGSI_SEMANTIC_COLOR, 0, - TGSI_INTERPOLATE_PERSPECTIVE ); + src = ureg_DECL_fs_input( ureg, input_semantic, 0, + input_interpolate ); for (i = 0; i < num_cbufs; i++) dst[i] = ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, i ); diff --git a/src/gallium/auxiliary/util/u_simple_shaders.h b/src/gallium/auxiliary/util/u_simple_shaders.h index 4aa34bc4757..1bfec183e34 100644 --- a/src/gallium/auxiliary/util/u_simple_shaders.h +++ b/src/gallium/auxiliary/util/u_simple_shaders.h @@ -71,7 +71,9 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe); extern void * -util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs); +util_make_fragment_cloneinput_shader(struct pipe_context *pipe, int num_cbufs, + int input_semantic, + int input_interpolate); #ifdef __cplusplus } diff --git a/src/gallium/auxiliary/util/u_mempool.c b/src/gallium/auxiliary/util/u_slab.c index 1f336b39a1a..21bf2d735ac 100644 --- a/src/gallium/auxiliary/util/u_mempool.c +++ b/src/gallium/auxiliary/util/u_slab.c @@ -20,7 +20,7 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "util/u_mempool.h" +#include "util/u_slab.h" #include "util/u_math.h" #include "util/u_memory.h" @@ -28,13 +28,13 @@ #include <stdio.h> -#define UTIL_MEMPOOL_MAGIC 0xcafe4321 +#define UTIL_SLAB_MAGIC 0xcafe4321 /* The block is either allocated memory or free space. */ -struct util_mempool_block { +struct util_slab_block { /* The header. */ /* The first next free block. */ - struct util_mempool_block *next_free; + struct util_slab_block *next_free; intptr_t magic; @@ -42,19 +42,19 @@ struct util_mempool_block { * The allocated size is always larger than this structure. */ }; -static struct util_mempool_block * -util_mempool_get_block(struct util_mempool *pool, - struct util_mempool_page *page, unsigned index) +static struct util_slab_block * +util_slab_get_block(struct util_slab_mempool *pool, + struct util_slab_page *page, unsigned index) { - return (struct util_mempool_block*) - ((uint8_t*)page + sizeof(struct util_mempool_page) + + return (struct util_slab_block*) + ((uint8_t*)page + sizeof(struct util_slab_page) + (pool->block_size * index)); } -static void util_mempool_add_new_page(struct util_mempool *pool) +static void util_slab_add_new_page(struct util_slab_mempool *pool) { - struct util_mempool_page *page; - struct util_mempool_block *block; + struct util_slab_page *page; + struct util_slab_block *block; int i; page = MALLOC(pool->page_size); @@ -62,15 +62,15 @@ static void util_mempool_add_new_page(struct util_mempool *pool) /* Mark all blocks as free. */ for (i = 0; i < pool->num_blocks-1; i++) { - block = util_mempool_get_block(pool, page, i); - block->next_free = util_mempool_get_block(pool, page, i+1); - block->magic = UTIL_MEMPOOL_MAGIC; + block = util_slab_get_block(pool, page, i); + block->next_free = util_slab_get_block(pool, page, i+1); + block->magic = UTIL_SLAB_MAGIC; } - block = util_mempool_get_block(pool, page, pool->num_blocks-1); + block = util_slab_get_block(pool, page, pool->num_blocks-1); block->next_free = pool->first_free; - block->magic = UTIL_MEMPOOL_MAGIC; - pool->first_free = util_mempool_get_block(pool, page, 0); + block->magic = UTIL_SLAB_MAGIC; + pool->first_free = util_slab_get_block(pool, page, 0); pool->num_pages++; #if 0 @@ -78,74 +78,74 @@ static void util_mempool_add_new_page(struct util_mempool *pool) #endif } -static void *util_mempool_malloc_st(struct util_mempool *pool) +static void *util_slab_alloc_st(struct util_slab_mempool *pool) { - struct util_mempool_block *block; + struct util_slab_block *block; if (!pool->first_free) - util_mempool_add_new_page(pool); + util_slab_add_new_page(pool); block = pool->first_free; - assert(block->magic == UTIL_MEMPOOL_MAGIC); + assert(block->magic == UTIL_SLAB_MAGIC); pool->first_free = block->next_free; - return (uint8_t*)block + sizeof(struct util_mempool_block); + return (uint8_t*)block + sizeof(struct util_slab_block); } -static void util_mempool_free_st(struct util_mempool *pool, void *ptr) +static void util_slab_free_st(struct util_slab_mempool *pool, void *ptr) { - struct util_mempool_block *block = - (struct util_mempool_block*) - ((uint8_t*)ptr - sizeof(struct util_mempool_block)); + struct util_slab_block *block = + (struct util_slab_block*) + ((uint8_t*)ptr - sizeof(struct util_slab_block)); - assert(block->magic == UTIL_MEMPOOL_MAGIC); + assert(block->magic == UTIL_SLAB_MAGIC); block->next_free = pool->first_free; pool->first_free = block; } -static void *util_mempool_malloc_mt(struct util_mempool *pool) +static void *util_slab_alloc_mt(struct util_slab_mempool *pool) { void *mem; pipe_mutex_lock(pool->mutex); - mem = util_mempool_malloc_st(pool); + mem = util_slab_alloc_st(pool); pipe_mutex_unlock(pool->mutex); return mem; } -static void util_mempool_free_mt(struct util_mempool *pool, void *ptr) +static void util_slab_free_mt(struct util_slab_mempool *pool, void *ptr) { pipe_mutex_lock(pool->mutex); - util_mempool_free_st(pool, ptr); + util_slab_free_st(pool, ptr); pipe_mutex_unlock(pool->mutex); } -void util_mempool_set_thread_safety(struct util_mempool *pool, - enum util_mempool_threading threading) +void util_slab_set_thread_safety(struct util_slab_mempool *pool, + enum util_slab_threading threading) { pool->threading = threading; if (threading) { - pool->malloc = util_mempool_malloc_mt; - pool->free = util_mempool_free_mt; + pool->alloc = util_slab_alloc_mt; + pool->free = util_slab_free_mt; } else { - pool->malloc = util_mempool_malloc_st; - pool->free = util_mempool_free_st; + pool->alloc = util_slab_alloc_st; + pool->free = util_slab_free_st; } } -void util_mempool_create(struct util_mempool *pool, - unsigned item_size, - unsigned num_blocks, - enum util_mempool_threading threading) +void util_slab_create(struct util_slab_mempool *pool, + unsigned item_size, + unsigned num_blocks, + enum util_slab_threading threading) { item_size = align(item_size, sizeof(intptr_t)); pool->num_pages = 0; pool->num_blocks = num_blocks; - pool->block_size = sizeof(struct util_mempool_block) + item_size; + pool->block_size = sizeof(struct util_slab_block) + item_size; pool->block_size = align(pool->block_size, sizeof(intptr_t)); - pool->page_size = sizeof(struct util_mempool_page) + + pool->page_size = sizeof(struct util_slab_page) + num_blocks * pool->block_size; pool->first_free = NULL; @@ -153,12 +153,12 @@ void util_mempool_create(struct util_mempool *pool, pipe_mutex_init(pool->mutex); - util_mempool_set_thread_safety(pool, threading); + util_slab_set_thread_safety(pool, threading); } -void util_mempool_destroy(struct util_mempool *pool) +void util_slab_destroy(struct util_slab_mempool *pool) { - struct util_mempool_page *page, *temp; + struct util_slab_page *page, *temp; foreach_s(page, temp, &pool->list) { remove_from_list(page); diff --git a/src/gallium/auxiliary/util/u_mempool.h b/src/gallium/auxiliary/util/u_slab.h index a5b5d6a9b7c..6b9718d08a7 100644 --- a/src/gallium/auxiliary/util/u_mempool.h +++ b/src/gallium/auxiliary/util/u_slab.h @@ -22,66 +22,66 @@ /** * @file - * Simple memory pool for equally sized memory allocations. - * util_mempool_malloc and util_mempool_free are in O(1). + * Simple slab allocator for equally sized memory allocations. + * util_slab_alloc and util_slab_free have time complexity in O(1). * * Good for allocations which have very low lifetime and are allocated - * and freed very often. Use a profiler first! + * and freed very often. Use a profiler first to know if it's worth using it! * * Candidates: get_transfer, user_buffer_create * * @author Marek Olšák */ -#ifndef U_MEMPOOL_H -#define U_MEMPOOL_H +#ifndef U_SLAB_H +#define U_SLAB_H #include "os/os_thread.h" -enum util_mempool_threading { - UTIL_MEMPOOL_SINGLETHREADED = FALSE, - UTIL_MEMPOOL_MULTITHREADED = TRUE +enum util_slab_threading { + UTIL_SLAB_SINGLETHREADED = FALSE, + UTIL_SLAB_MULTITHREADED = TRUE }; /* The page is an array of blocks (allocations). */ -struct util_mempool_page { +struct util_slab_page { /* The header (linked-list pointers). */ - struct util_mempool_page *prev, *next; + struct util_slab_page *prev, *next; /* Memory after the last member is dedicated to the page itself. * The allocated size is always larger than this structure. */ }; -struct util_mempool { +struct util_slab_mempool { /* Public members. */ - void *(*malloc)(struct util_mempool *pool); - void (*free)(struct util_mempool *pool, void *ptr); + void *(*alloc)(struct util_slab_mempool *pool); + void (*free)(struct util_slab_mempool *pool, void *ptr); /* Private members. */ - struct util_mempool_block *first_free; + struct util_slab_block *first_free; - struct util_mempool_page list; + struct util_slab_page list; unsigned block_size; unsigned page_size; unsigned num_blocks; unsigned num_pages; - enum util_mempool_threading threading; + enum util_slab_threading threading; pipe_mutex mutex; }; -void util_mempool_create(struct util_mempool *pool, - unsigned item_size, - unsigned num_blocks, - enum util_mempool_threading threading); +void util_slab_create(struct util_slab_mempool *pool, + unsigned item_size, + unsigned num_blocks, + enum util_slab_threading threading); -void util_mempool_destroy(struct util_mempool *pool); +void util_slab_destroy(struct util_slab_mempool *pool); -void util_mempool_set_thread_safety(struct util_mempool *pool, - enum util_mempool_threading threading); +void util_slab_set_thread_safety(struct util_slab_mempool *pool, + enum util_slab_threading threading); -#define util_mempool_malloc(pool) (pool)->malloc(pool) -#define util_mempool_free(pool, ptr) (pool)->free(pool, ptr) +#define util_slab_alloc(pool) (pool)->alloc(pool) +#define util_slab_free(pool, ptr) (pool)->free(pool, ptr) #endif diff --git a/src/gallium/auxiliary/util/u_staging.c b/src/gallium/auxiliary/util/u_staging.c index c5d68f8df86..b6bf241a22a 100644 --- a/src/gallium/auxiliary/util/u_staging.c +++ b/src/gallium/auxiliary/util/u_staging.c @@ -41,6 +41,7 @@ util_staging_resource_template(struct pipe_resource *pt, unsigned width, unsigne template->width0 = width; template->height0 = height; template->depth0 = depth; + template->array_size = 1; template->last_level = 0; template->nr_samples = pt->nr_samples; template->bind = 0; @@ -51,7 +52,7 @@ util_staging_resource_template(struct pipe_resource *pt, unsigned width, unsigne struct util_staging_transfer * util_staging_transfer_init(struct pipe_context *pipe, struct pipe_resource *pt, - struct pipe_subresource sr, + unsigned level, unsigned usage, const struct pipe_box *box, bool direct, struct util_staging_transfer *tx) @@ -61,7 +62,7 @@ util_staging_transfer_init(struct pipe_context *pipe, struct pipe_resource staging_resource_template; pipe_resource_reference(&tx->base.resource, pt); - tx->base.sr = sr; + tx->base.level = level; tx->base.usage = usage; tx->base.box = *box; @@ -82,12 +83,20 @@ util_staging_transfer_init(struct pipe_context *pipe, if (usage & PIPE_TRANSFER_READ) { - struct pipe_subresource dstsr; + /* XXX this looks wrong dst is always the same but looping over src z? */ unsigned zi; - dstsr.face = 0; - dstsr.level = 0; - for(zi = 0; zi < box->depth; ++zi) - pipe->resource_copy_region(pipe, tx->staging_resource, dstsr, 0, 0, 0, tx->base.resource, sr, box->x, box->y, box->z + zi, box->width, box->height); + struct pipe_box sbox; + sbox.x = box->x; + sbox.y = box->y; + sbox.z = box->z; + sbox.width = box->width; + sbox.height = box->height; + sbox.depth = 1; + for(zi = 0; zi < box->depth; ++zi) { + sbox.z = sbox.z + zi; + pipe->resource_copy_region(pipe, tx->staging_resource, 0, 0, 0, 0, + tx->base.resource, level, &sbox); + } } return tx; @@ -101,12 +110,18 @@ util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *p if (tx->staging_resource != tx->base.resource) { if(tx->base.usage & PIPE_TRANSFER_WRITE) { - struct pipe_subresource srcsr; + /* XXX this looks wrong src is always the same but looping over dst z? */ unsigned zi; - srcsr.face = 0; - srcsr.level = 0; + struct pipe_box sbox; + sbox.x = 0; + sbox.y = 0; + sbox.z = 0; + sbox.width = tx->base.box.width; + sbox.height = tx->base.box.height; + sbox.depth = 1; for(zi = 0; zi < tx->base.box.depth; ++zi) - pipe->resource_copy_region(pipe, tx->base.resource, tx->base.sr, tx->base.box.x, tx->base.box.y, tx->base.box.z + zi, tx->staging_resource, srcsr, 0, 0, 0, tx->base.box.width, tx->base.box.height); + pipe->resource_copy_region(pipe, tx->base.resource, tx->base.level, tx->base.box.x, tx->base.box.y, tx->base.box.z + zi, + tx->staging_resource, 0, &sbox); } pipe_resource_reference(&tx->staging_resource, NULL); diff --git a/src/gallium/auxiliary/util/u_staging.h b/src/gallium/auxiliary/util/u_staging.h index 1aab78cc881..49839d25439 100644 --- a/src/gallium/auxiliary/util/u_staging.h +++ b/src/gallium/auxiliary/util/u_staging.h @@ -52,7 +52,7 @@ struct util_staging_transfer { struct util_staging_transfer * util_staging_transfer_init(struct pipe_context *pipe, struct pipe_resource *pt, - struct pipe_subresource sr, + unsigned level, unsigned usage, const struct pipe_box *box, bool direct, struct util_staging_transfer *tx); diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index f78b6838a72..4eddd3f519e 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -42,6 +42,18 @@ #include "util/u_surface.h" #include "util/u_pack_color.h" +void +u_surface_default_template(struct pipe_surface *view, + const struct pipe_resource *texture, + unsigned bind) +{ + view->format = texture->format; + view->u.tex.level = 0; + view->u.tex.first_layer = 0; + view->u.tex.last_layer = 0; + /* XXX should filter out all non-rt/ds bind flags ? */ + view->usage = bind; +} /** * Helper to quickly create an RGBA rendering surface of a certain size. @@ -50,9 +62,9 @@ * \return TRUE for success, FALSE if failure */ boolean -util_create_rgba_surface(struct pipe_screen *screen, +util_create_rgba_surface(struct pipe_context *pipe, uint width, uint height, - uint bind, + uint bind, struct pipe_resource **textureOut, struct pipe_surface **surfaceOut) { @@ -65,6 +77,8 @@ util_create_rgba_surface(struct pipe_screen *screen, const uint target = PIPE_TEXTURE_2D; enum pipe_format format = PIPE_FORMAT_NONE; struct pipe_resource templ; + struct pipe_surface surf_templ; + struct pipe_screen *screen = pipe->screen; uint i; /* Choose surface format */ @@ -86,17 +100,20 @@ util_create_rgba_surface(struct pipe_screen *screen, templ.width0 = width; templ.height0 = height; templ.depth0 = 1; + templ.array_size = 1; templ.bind = bind; *textureOut = screen->resource_create(screen, &templ); if (!*textureOut) return FALSE; + /* create surface */ + memset(&surf_templ, 0, sizeof(surf_templ)); + u_surface_default_template(&surf_templ, *textureOut, bind); /* create surface / view into texture */ - *surfaceOut = screen->get_tex_surface(screen, - *textureOut, - 0, 0, 0, - bind); + *surfaceOut = pipe->create_surface(pipe, + *textureOut, + &surf_templ); if (!*surfaceOut) { pipe_resource_reference(textureOut, NULL); return FALSE; @@ -126,17 +143,18 @@ util_destroy_rgba_surface(struct pipe_resource *texture, void util_resource_copy_region(struct pipe_context *pipe, struct pipe_resource *dst, - struct pipe_subresource subdst, + unsigned dst_level, unsigned dst_x, unsigned dst_y, unsigned dst_z, struct pipe_resource *src, - struct pipe_subresource subsrc, - unsigned src_x, unsigned src_y, unsigned src_z, - unsigned w, unsigned h) + unsigned src_level, + const struct pipe_box *src_box) { struct pipe_transfer *src_trans, *dst_trans; void *dst_map; const void *src_map; enum pipe_format src_format, dst_format; + unsigned w = src_box->width; + unsigned h = src_box->height; assert(src && dst); if (!src || !dst) @@ -146,20 +164,18 @@ util_resource_copy_region(struct pipe_context *pipe, dst_format = dst->format; src_trans = pipe_get_transfer(pipe, - src, - subsrc.face, - subsrc.level, - src_z, - PIPE_TRANSFER_READ, - src_x, src_y, w, h); + src, + src_level, + src_box->z, + PIPE_TRANSFER_READ, + src_box->x, src_box->y, w, h); dst_trans = pipe_get_transfer(pipe, - dst, - subdst.face, - subdst.level, - src_z, - PIPE_TRANSFER_WRITE, - dst_x, dst_y, w, h); + dst, + dst_level, + dst_z, + PIPE_TRANSFER_WRITE, + dst_x, dst_y, w, h); assert(util_format_get_blocksize(dst_format) == util_format_get_blocksize(src_format)); assert(util_format_get_blockwidth(dst_format) == util_format_get_blockwidth(src_format)); @@ -216,14 +232,13 @@ util_clear_render_target(struct pipe_context *pipe, assert(dst->texture); if (!dst->texture) return; - + /* XXX: should handle multiple layers */ dst_trans = pipe_get_transfer(pipe, - dst->texture, - dst->face, - dst->level, - dst->zslice, - PIPE_TRANSFER_WRITE, - dstx, dsty, width, height); + dst->texture, + dst->u.tex.level, + dst->u.tex.first_layer, + PIPE_TRANSFER_WRITE, + dstx, dsty, width, height); dst_map = pipe->transfer_map(pipe, dst_trans); @@ -271,9 +286,8 @@ util_clear_depth_stencil(struct pipe_context *pipe, return; dst_trans = pipe_get_transfer(pipe, dst->texture, - dst->face, - dst->level, - dst->zslice, + dst->u.tex.level, + dst->u.tex.first_layer, (need_rmw ? PIPE_TRANSFER_READ_WRITE : PIPE_TRANSFER_WRITE), dstx, dsty, width, height); diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h index 6cd12af3a8b..6a7cc82b055 100644 --- a/src/gallium/auxiliary/util/u_surface.h +++ b/src/gallium/auxiliary/util/u_surface.h @@ -33,8 +33,18 @@ #include "pipe/p_state.h" +#ifdef __cplusplus +extern "C" { +#endif + + +extern void +u_surface_default_template(struct pipe_surface *view, + const struct pipe_resource *texture, + unsigned bind); + extern boolean -util_create_rgba_surface(struct pipe_screen *screen, +util_create_rgba_surface(struct pipe_context *ctx, uint width, uint height, uint bind, struct pipe_resource **textureOut, struct pipe_surface **surfaceOut); @@ -49,12 +59,11 @@ util_destroy_rgba_surface(struct pipe_resource *texture, extern void util_resource_copy_region(struct pipe_context *pipe, struct pipe_resource *dst, - struct pipe_subresource subdst, + unsigned dst_level, unsigned dst_x, unsigned dst_y, unsigned dst_z, struct pipe_resource *src, - struct pipe_subresource subsrc, - unsigned src_x, unsigned src_y, unsigned src_z, - unsigned w, unsigned h); + unsigned src_level, + const struct pipe_box *src_box); extern void util_clear_render_target(struct pipe_context *pipe, @@ -73,4 +82,9 @@ util_clear_depth_stencil(struct pipe_context *pipe, unsigned width, unsigned height); +#ifdef __cplusplus +} +#endif + + #endif /* U_SURFACE_H */ diff --git a/src/gallium/auxiliary/util/u_surfaces.c b/src/gallium/auxiliary/util/u_surfaces.c index 404e1219952..b0cfec2a826 100644 --- a/src/gallium/auxiliary/util/u_surfaces.c +++ b/src/gallium/auxiliary/util/u_surfaces.c @@ -29,8 +29,11 @@ #include "util/u_inlines.h" #include "util/u_memory.h" -struct pipe_surface * -util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, struct pipe_screen *pscreen, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned flags) +boolean +util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, + struct pipe_context *ctx, struct pipe_resource *pt, + unsigned level, unsigned layer, unsigned flags, + struct pipe_surface **res) { struct pipe_surface *ps; @@ -39,7 +42,7 @@ util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, str if(!us->u.hash) us->u.hash = cso_hash_create(); - ps = cso_hash_iter_data(cso_hash_find(us->u.hash, ((zslice + face) << 8) | level)); + ps = cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level)); } else { @@ -48,25 +51,29 @@ util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, str ps = us->u.array[level]; } - if(ps) + if(ps && ps->context == ctx) { p_atomic_inc(&ps->reference.count); - return ps; + *res = ps; + return FALSE; } ps = (struct pipe_surface *)CALLOC(1, surface_struct_size); if(!ps) - return NULL; + { + *res = NULL; + return FALSE; + } - pipe_surface_init(ps, pt, face, level, zslice, flags); - ps->offset = ~0; + pipe_surface_init(ctx, ps, pt, level, layer, flags); if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) - cso_hash_insert(us->u.hash, ((zslice + face) << 8) | level, ps); + cso_hash_insert(us->u.hash, (layer << 8) | level, ps); else us->u.array[level] = ps; - return ps; + *res = ps; + return TRUE; } void @@ -75,10 +82,10 @@ util_surfaces_do_detach(struct util_surfaces *us, struct pipe_surface *ps) struct pipe_resource *pt = ps->texture; if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) { /* or 2D array */ - cso_hash_erase(us->u.hash, cso_hash_find(us->u.hash, ((ps->zslice + ps->face) << 8) | ps->level)); + cso_hash_erase(us->u.hash, cso_hash_find(us->u.hash, (ps->u.tex.first_layer << 8) | ps->u.tex.level)); } else - us->u.array[ps->level] = 0; + us->u.array[ps->u.tex.level] = 0; } void diff --git a/src/gallium/auxiliary/util/u_surfaces.h b/src/gallium/auxiliary/util/u_surfaces.h index 17d8a5d3a5b..9581feda7c8 100644 --- a/src/gallium/auxiliary/util/u_surfaces.h +++ b/src/gallium/auxiliary/util/u_surfaces.h @@ -42,33 +42,42 @@ struct util_surfaces } u; }; -struct pipe_surface *util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, struct pipe_screen *pscreen, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned flags); +/* Return value indicates if the pipe surface result is new */ +boolean +util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, + struct pipe_context *ctx, struct pipe_resource *pt, + unsigned level, unsigned layer, unsigned flags, + struct pipe_surface **res); /* fast inline path for the very common case */ -static INLINE struct pipe_surface * -util_surfaces_get(struct util_surfaces *us, unsigned surface_struct_size, struct pipe_screen *pscreen, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned flags) +static INLINE boolean +util_surfaces_get(struct util_surfaces *us, unsigned surface_struct_size, + struct pipe_context *ctx, struct pipe_resource *pt, + unsigned level, unsigned layer, unsigned flags, + struct pipe_surface **res) { if(likely((pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT) && us->u.array)) { struct pipe_surface *ps = us->u.array[level]; - if(ps) + if(ps && ps->context == ctx) { p_atomic_inc(&ps->reference.count); - return ps; + *res = ps; + return FALSE; } } - return util_surfaces_do_get(us, surface_struct_size, pscreen, pt, face, level, zslice, flags); + return util_surfaces_do_get(us, surface_struct_size, ctx, pt, level, layer, flags, res); } static INLINE struct pipe_surface * -util_surfaces_peek(struct util_surfaces *us, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice) +util_surfaces_peek(struct util_surfaces *us, struct pipe_resource *pt, unsigned level, unsigned layer) { if(!us->u.pv) return 0; if(unlikely(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)) - return cso_hash_iter_data(cso_hash_find(us->u.hash, ((zslice + face) << 8) | level)); + return cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level)); else return us->u.array[level]; } @@ -80,7 +89,7 @@ util_surfaces_detach(struct util_surfaces *us, struct pipe_surface *ps) { if(likely(ps->texture->target == PIPE_TEXTURE_2D || ps->texture->target == PIPE_TEXTURE_RECT)) { - us->u.array[ps->level] = 0; + us->u.array[ps->u.tex.level] = 0; return; } diff --git a/src/gallium/auxiliary/util/u_transfer.c b/src/gallium/auxiliary/util/u_transfer.c index 69f6fab9504..e2828cfd99e 100644 --- a/src/gallium/auxiliary/util/u_transfer.c +++ b/src/gallium/auxiliary/util/u_transfer.c @@ -8,22 +8,24 @@ * pointer. XXX: strides?? */ void u_default_transfer_inline_write( struct pipe_context *pipe, - struct pipe_resource *resource, - struct pipe_subresource sr, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned slice_stride) + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) { struct pipe_transfer *transfer = NULL; uint8_t *map = NULL; - - transfer = pipe->get_transfer(pipe, - resource, - sr, - usage, - box ); + const uint8_t *src_data = data; + unsigned i; + + transfer = pipe->get_transfer(pipe, + resource, + level, + usage, + box ); if (transfer == NULL) goto out; @@ -31,17 +33,19 @@ void u_default_transfer_inline_write( struct pipe_context *pipe, if (map == NULL) goto out; - assert(box->depth == 1); /* XXX: fix me */ - - util_copy_rect(map, - resource->format, - transfer->stride, /* bytes */ - 0, 0, - box->width, - box->height, - data, - stride, /* bytes */ - 0, 0); + for (i = 0; i < box->depth; i++) { + util_copy_rect(map, + resource->format, + transfer->stride, /* bytes */ + 0, 0, + box->width, + box->height, + src_data, + stride, /* bytes */ + 0, 0); + map += transfer->layer_stride; + src_data += layer_stride; + } out: if (map) @@ -53,8 +57,8 @@ out: boolean u_default_resource_get_handle(struct pipe_screen *screen, - struct pipe_resource *resource, - struct winsys_handle *handle) + struct pipe_resource *resource, + struct winsys_handle *handle) { return FALSE; } @@ -62,32 +66,32 @@ boolean u_default_resource_get_handle(struct pipe_screen *screen, void u_default_transfer_flush_region( struct pipe_context *pipe, - struct pipe_transfer *transfer, - const struct pipe_box *box) + struct pipe_transfer *transfer, + const struct pipe_box *box) { /* This is a no-op implementation, nothing to do. */ } unsigned u_default_is_resource_referenced( struct pipe_context *pipe, - struct pipe_resource *resource, - unsigned face, unsigned level) + struct pipe_resource *resource, + unsigned level, int layer) { return 0; } struct pipe_transfer * u_default_get_transfer(struct pipe_context *context, - struct pipe_resource *resource, - struct pipe_subresource sr, - unsigned usage, - const struct pipe_box *box) + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) { struct pipe_transfer *transfer = CALLOC_STRUCT(pipe_transfer); if (transfer == NULL) return NULL; transfer->resource = resource; - transfer->sr = sr; + transfer->level = level; transfer->usage = usage; transfer->box = *box; @@ -98,12 +102,12 @@ struct pipe_transfer * u_default_get_transfer(struct pipe_context *context, } void u_default_transfer_unmap( struct pipe_context *pipe, - struct pipe_transfer *transfer ) + struct pipe_transfer *transfer ) { } void u_default_transfer_destroy(struct pipe_context *pipe, - struct pipe_transfer *transfer) + struct pipe_transfer *transfer) { FREE(transfer); } diff --git a/src/gallium/auxiliary/util/u_transfer.h b/src/gallium/auxiliary/util/u_transfer.h index e3a38730f21..3412e13c3cc 100644 --- a/src/gallium/auxiliary/util/u_transfer.h +++ b/src/gallium/auxiliary/util/u_transfer.h @@ -11,37 +11,37 @@ struct pipe_context; struct winsys_handle; boolean u_default_resource_get_handle(struct pipe_screen *screen, - struct pipe_resource *resource, - struct winsys_handle *handle); + struct pipe_resource *resource, + struct winsys_handle *handle); void u_default_transfer_inline_write( struct pipe_context *pipe, - struct pipe_resource *resource, - struct pipe_subresource sr, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned slice_stride); + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride); void u_default_transfer_flush_region( struct pipe_context *pipe, - struct pipe_transfer *transfer, - const struct pipe_box *box); + struct pipe_transfer *transfer, + const struct pipe_box *box); unsigned u_default_is_resource_referenced( struct pipe_context *pipe, - struct pipe_resource *resource, - unsigned face, unsigned level); + struct pipe_resource *resource, + unsigned level, int layer); struct pipe_transfer * u_default_get_transfer(struct pipe_context *context, - struct pipe_resource *resource, - struct pipe_subresource sr, - unsigned usage, - const struct pipe_box *box); + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box); void u_default_transfer_unmap( struct pipe_context *pipe, - struct pipe_transfer *transfer ); + struct pipe_transfer *transfer ); void u_default_transfer_destroy(struct pipe_context *pipe, - struct pipe_transfer *transfer); + struct pipe_transfer *transfer); @@ -51,43 +51,43 @@ void u_default_transfer_destroy(struct pipe_context *pipe, struct u_resource_vtbl { boolean (*resource_get_handle)(struct pipe_screen *, - struct pipe_resource *tex, - struct winsys_handle *handle); + struct pipe_resource *tex, + struct winsys_handle *handle); void (*resource_destroy)(struct pipe_screen *, - struct pipe_resource *pt); + struct pipe_resource *pt); unsigned (*is_resource_referenced)(struct pipe_context *pipe, - struct pipe_resource *texture, - unsigned face, unsigned level); + struct pipe_resource *texture, + unsigned level, int layer); struct pipe_transfer *(*get_transfer)(struct pipe_context *, - struct pipe_resource *resource, - struct pipe_subresource, - unsigned usage, - const struct pipe_box *); + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *); void (*transfer_destroy)(struct pipe_context *, - struct pipe_transfer *); + struct pipe_transfer *); void *(*transfer_map)( struct pipe_context *, - struct pipe_transfer *transfer ); + struct pipe_transfer *transfer ); void (*transfer_flush_region)( struct pipe_context *, - struct pipe_transfer *transfer, - const struct pipe_box *); + struct pipe_transfer *transfer, + const struct pipe_box *); void (*transfer_unmap)( struct pipe_context *, - struct pipe_transfer *transfer ); + struct pipe_transfer *transfer ); void (*transfer_inline_write)( struct pipe_context *pipe, - struct pipe_resource *resource, - struct pipe_subresource sr, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned slice_stride); + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride); }; @@ -98,43 +98,43 @@ struct u_resource { boolean u_resource_get_handle_vtbl(struct pipe_screen *screen, - struct pipe_resource *resource, - struct winsys_handle *handle); + struct pipe_resource *resource, + struct winsys_handle *handle); void u_resource_destroy_vtbl(struct pipe_screen *screen, - struct pipe_resource *resource); + struct pipe_resource *resource); unsigned u_is_resource_referenced_vtbl( struct pipe_context *pipe, - struct pipe_resource *resource, - unsigned face, unsigned level); + struct pipe_resource *resource, + unsigned level, int layer); struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context, - struct pipe_resource *resource, - struct pipe_subresource sr, - unsigned usage, - const struct pipe_box *box); + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box); void u_transfer_destroy_vtbl(struct pipe_context *pipe, - struct pipe_transfer *transfer); + struct pipe_transfer *transfer); void *u_transfer_map_vtbl( struct pipe_context *pipe, - struct pipe_transfer *transfer ); + struct pipe_transfer *transfer ); void u_transfer_flush_region_vtbl( struct pipe_context *pipe, - struct pipe_transfer *transfer, - const struct pipe_box *box); + struct pipe_transfer *transfer, + const struct pipe_box *box); void u_transfer_unmap_vtbl( struct pipe_context *rm_ctx, - struct pipe_transfer *transfer ); + struct pipe_transfer *transfer ); void u_transfer_inline_write_vtbl( struct pipe_context *rm_ctx, - struct pipe_resource *resource, - struct pipe_subresource sr, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned slice_stride); + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride); |