diff options
Diffstat (limited to 'src/gallium/auxiliary')
26 files changed, 631 insertions, 556 deletions
diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c index d1aba763098..0851b9acc0d 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -406,6 +406,7 @@ aaline_create_texture(struct aaline_stage *aaline) texTemp.width0 = 1 << MAX_TEXTURE_LEVEL; texTemp.height0 = 1 << MAX_TEXTURE_LEVEL; texTemp.depth0 = 1; + texTemp.array_size = 1; texTemp.bind = PIPE_BIND_SAMPLER_VIEW; aaline->texture = screen->resource_create(screen, &texTemp); @@ -441,10 +442,10 @@ aaline_create_texture(struct aaline_stage *aaline) /* This texture is new, no need to flush. */ transfer = pipe->get_transfer(pipe, - aaline->texture, - u_subresource(0, level), - PIPE_TRANSFER_WRITE, - &box); + aaline->texture, + level, + PIPE_TRANSFER_WRITE, + &box); data = pipe->transfer_map(pipe, transfer); if (data == NULL) diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index ed9a53e154d..f5515c1df76 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -393,8 +393,8 @@ pstip_update_texture(struct pstip_stage *pstip) */ pipe->flush( pipe, PIPE_FLUSH_TEXTURE_CACHE, NULL ); - transfer = pipe_get_transfer(pipe, pstip->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, 0, 0, 32, 32); + transfer = pipe_get_transfer(pipe, pstip->texture, 0, 0, + PIPE_TRANSFER_WRITE, 0, 0, 32, 32); data = pipe->transfer_map(pipe, transfer); /* @@ -440,6 +440,7 @@ pstip_create_texture(struct pstip_stage *pstip) texTemp.width0 = 32; texTemp.height0 = 32; texTemp.depth0 = 1; + texTemp.array_size = 1; texTemp.bind = PIPE_BIND_SAMPLER_VIEW; pstip->texture = screen->resource_create(screen, &texTemp); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c index 771095f43a8..4a7fe6983c1 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c @@ -134,7 +134,7 @@ lp_sampler_static_state(struct lp_sampler_static_state *state, state->min_img_filter = sampler->min_img_filter; state->mag_img_filter = sampler->mag_img_filter; - if (view->last_level && sampler->max_lod > 0.0f) { + if (view->u.tex.last_level && sampler->max_lod > 0.0f) { state->min_mip_filter = sampler->min_mip_filter; } else { state->min_mip_filter = PIPE_TEX_MIPFILTER_NONE; @@ -155,7 +155,7 @@ lp_sampler_static_state(struct lp_sampler_static_state *state, state->apply_min_lod = 1; } - if (sampler->max_lod < (float)view->last_level) { + if (sampler->max_lod < (float)view->u.tex.last_level) { state->apply_max_lod = 1; } } diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 9e70aa266af..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, 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 bd9e65f43b1..eeed87ec634 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -409,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 { @@ -448,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++) { @@ -466,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*/ @@ -482,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) { @@ -490,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); @@ -516,7 +516,7 @@ static void blitter_draw_quad(struct blitter_context_priv *ctx) /* write vertices and draw them */ u_box_1d(0, sizeof(ctx->vertices), &box); - pipe->transfer_inline_write(pipe, ctx->vbuf, u_subresource(0,0), + pipe->transfer_inline_write(pipe, ctx->vbuf, 0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, &box, ctx->vertices, sizeof(ctx->vertices), 0); @@ -709,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; @@ -734,12 +735,14 @@ 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(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; @@ -757,15 +760,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); @@ -807,7 +813,7 @@ void util_blitter_copy_region(struct blitter_context *blitter, pipe->bind_rasterizer_state(pipe, ctx->rs_state); 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); @@ -822,8 +828,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, @@ -836,11 +842,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); 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_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..d4716bffe47 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,14 @@ 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 */ + /* address of the dest image */ ubyte *imgDst = dstPtr - + (bytesPerDstImage + bytesPerDstRow + border) * bpt * border - + img * bytesPerDstImage; + + img * dstImageStride; /* setup the four source row pointers and the dest row pointer */ const ubyte *srcImgARowA = imgSrcA; @@ -1102,11 +1085,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 +1100,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 +1138,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 +1150,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 +1178,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 +1228,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 +1314,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 +1361,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 +1387,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 ); @@ -1478,9 +1468,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 +1483,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 +1548,84 @@ 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..d5bc114fce6 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; } @@ -137,25 +137,24 @@ 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) + 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; } static INLINE void pipe_surface_init(struct pipe_surface* ps, struct pipe_resource *pt, - unsigned face, unsigned level, unsigned zslice, unsigned flags) + 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(ps, pt, level, layer, flags); } /* @@ -177,6 +176,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 +202,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 +231,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 +240,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 +250,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 +266,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 +276,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 +284,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 +309,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 +343,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 +375,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_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..6b82e14aeca 100644 --- a/src/gallium/auxiliary/util/u_surface.h +++ b/src/gallium/auxiliary/util/u_surface.h @@ -32,9 +32,13 @@ #include "pipe/p_compiler.h" #include "pipe/p_state.h" +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 +53,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, diff --git a/src/gallium/auxiliary/util/u_surfaces.c b/src/gallium/auxiliary/util/u_surfaces.c index 404e1219952..45aa15e0447 100644 --- a/src/gallium/auxiliary/util/u_surfaces.c +++ b/src/gallium/auxiliary/util/u_surfaces.c @@ -30,7 +30,9 @@ #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) +util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, + struct pipe_screen *pscreen, struct pipe_resource *pt, + unsigned level, unsigned layer, unsigned flags) { struct pipe_surface *ps; @@ -39,7 +41,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 { @@ -58,11 +60,10 @@ util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, str if(!ps) return NULL; - pipe_surface_init(ps, pt, face, level, zslice, flags); - ps->offset = ~0; + pipe_surface_init(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; @@ -75,10 +76,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..86a1c2f83c9 100644 --- a/src/gallium/auxiliary/util/u_surfaces.h +++ b/src/gallium/auxiliary/util/u_surfaces.h @@ -42,11 +42,11 @@ 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); +struct pipe_surface *util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, struct pipe_screen *pscreen, struct pipe_resource *pt, unsigned level, unsigned layer, unsigned flags); /* 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) +util_surfaces_get(struct util_surfaces *us, unsigned surface_struct_size, struct pipe_screen *pscreen, struct pipe_resource *pt, unsigned level, unsigned layer, unsigned flags) { if(likely((pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT) && us->u.array)) { @@ -58,17 +58,17 @@ util_surfaces_get(struct util_surfaces *us, unsigned surface_struct_size, struct } } - return util_surfaces_do_get(us, surface_struct_size, pscreen, pt, face, level, zslice, flags); + return util_surfaces_do_get(us, surface_struct_size, pscreen, pt, level, layer, flags); } 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 +80,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); |