diff options
author | Roland Scheidegger <[email protected]> | 2010-12-02 04:33:43 +0100 |
---|---|---|
committer | Roland Scheidegger <[email protected]> | 2010-12-02 04:33:43 +0100 |
commit | 4c7001462607e6e99e474d6271dd481d3f8f201c (patch) | |
tree | d5fc155ee50d2f41fa9e7d4a253a8f9c51bc9e51 /src/gallium/auxiliary/util | |
parent | 32e1e591467d9a28c2ac4d2e17af7be2dc429d43 (diff) |
gallium: support for array textures and related changes
resources have a array_size parameter now.
get_tex_surface and tex_surface_destroy have been renamed to create_surface
and surface_destroy and moved to context, similar to sampler views (and
create_surface now uses a template just like create_sampler_view). Surfaces
now really should only be used for rendering. In particular they shouldn't be
used as some kind of 2d abstraction for sharing a texture. offset/layout fields
don't make sense any longer and have been removed, width/height should go too.
surfaces and sampler views now specify a layer range (for texture resources),
layer is either array slice, depth slice or cube face.
pipe_subresource is gone array slices (or cube faces) are now treated the same
as depth slices in transfers etc. (that is, they use the z coord of the
respective functions).
Squashed commit of the following:
commit a45bd509014743d21a532194d7b658a1aeb00cb7
Merge: 1aeca28 32e1e59
Author: Roland Scheidegger <[email protected]>
Date: Thu Dec 2 04:32:06 2010 +0100
Merge remote branch 'origin/master' into gallium-array-textures
Conflicts:
src/gallium/drivers/i915/i915_resource_texture.c
src/gallium/drivers/i915/i915_state_emit.c
src/gallium/drivers/i915/i915_surface.c
commit 1aeca287a827f29206078fa1204715a477072c08
Merge: 912f042 6f7c8c3
Author: Roland Scheidegger <[email protected]>
Date: Thu Dec 2 00:37:11 2010 +0100
Merge remote branch 'origin/master' into gallium-array-textures
Conflicts:
src/gallium/state_trackers/vega/api_filters.c
src/gallium/state_trackers/vega/api_images.c
src/gallium/state_trackers/vega/mask.c
src/gallium/state_trackers/vega/paint.c
src/gallium/state_trackers/vega/renderer.c
src/gallium/state_trackers/vega/st_inlines.h
src/gallium/state_trackers/vega/vg_context.c
src/gallium/state_trackers/vega/vg_manager.c
commit 912f042e1d439de17b36be9a740358c876fcd144
Author: Roland Scheidegger <[email protected]>
Date: Wed Dec 1 03:01:55 2010 +0100
gallium: even more compile fixes after merge
commit 6fc95a58866d2a291def333608ba9c10c3f07e82
Author: Roland Scheidegger <[email protected]>
Date: Wed Dec 1 00:22:26 2010 +0100
gallium: some fixes after merge
commit a8d5ffaeb5397ffaa12fb422e4e7efdf0494c3e2
Merge: f7a202f 2da02e7
Author: Roland Scheidegger <[email protected]>
Date: Tue Nov 30 23:41:26 2010 +0100
Merge remote branch 'origin/master' into gallium-array-textures
Conflicts:
src/gallium/drivers/i915/i915_state_emit.c
src/gallium/state_trackers/vega/api_images.c
src/gallium/state_trackers/vega/vg_context.c
commit f7a202fde2aea2ec78ef58830f945a5e214e56ab
Author: Roland Scheidegger <[email protected]>
Date: Wed Nov 24 19:19:32 2010 +0100
gallium: even more fixes/cleanups after merge
commit 6895a7f969ed7f9fa8ceb788810df8dbcf04c4c9
Author: Roland Scheidegger <[email protected]>
Date: Wed Nov 24 03:07:36 2010 +0100
gallium: more compile fixes after merge
commit af0501a5103b9756bc4d79167bd81051ad6e8670
Author: Roland Scheidegger <[email protected]>
Date: Tue Nov 23 19:24:45 2010 +0100
gallium: lots of compile fixes after merge
commit 0332003c2feb60f2a20e9a40368180c4ecd33e6b
Merge: 26c6346 b6b91fa
Author: Roland Scheidegger <[email protected]>
Date: Tue Nov 23 17:02:26 2010 +0100
Merge remote branch 'origin/master' into gallium-array-textures
Conflicts:
src/gallium/auxiliary/gallivm/lp_bld_sample.c
src/gallium/auxiliary/util/u_blit.c
src/gallium/auxiliary/util/u_blitter.c
src/gallium/auxiliary/util/u_inlines.h
src/gallium/auxiliary/util/u_surface.c
src/gallium/auxiliary/util/u_surfaces.c
src/gallium/docs/source/context.rst
src/gallium/drivers/llvmpipe/lp_rast.c
src/gallium/drivers/nv50/nv50_state_validate.c
src/gallium/drivers/nvfx/nv04_surface_2d.c
src/gallium/drivers/nvfx/nv04_surface_2d.h
src/gallium/drivers/nvfx/nvfx_buffer.c
src/gallium/drivers/nvfx/nvfx_miptree.c
src/gallium/drivers/nvfx/nvfx_resource.c
src/gallium/drivers/nvfx/nvfx_resource.h
src/gallium/drivers/nvfx/nvfx_state_fb.c
src/gallium/drivers/nvfx/nvfx_surface.c
src/gallium/drivers/nvfx/nvfx_transfer.c
src/gallium/drivers/r300/r300_state_derived.c
src/gallium/drivers/r300/r300_texture.c
src/gallium/drivers/r600/r600_blit.c
src/gallium/drivers/r600/r600_buffer.c
src/gallium/drivers/r600/r600_context.h
src/gallium/drivers/r600/r600_screen.c
src/gallium/drivers/r600/r600_screen.h
src/gallium/drivers/r600/r600_state.c
src/gallium/drivers/r600/r600_texture.c
src/gallium/include/pipe/p_defines.h
src/gallium/state_trackers/egl/common/egl_g3d_api.c
src/gallium/state_trackers/glx/xlib/xm_st.c
src/gallium/targets/libgl-gdi/gdi_softpipe_winsys.c
src/gallium/targets/libgl-gdi/libgl_gdi.c
src/gallium/tests/graw/tri.c
src/mesa/state_tracker/st_cb_blit.c
src/mesa/state_tracker/st_cb_readpixels.c
commit 26c6346b385929fba94775f33838d0cceaaf1127
Author: Roland Scheidegger <[email protected]>
Date: Mon Aug 2 19:37:21 2010 +0200
fix more merge breakage
commit b30d87c6025eefe7f6979ffa8e369bbe755d5c1d
Merge: 9461bf3 1f1928d
Author: Roland Scheidegger <[email protected]>
Date: Mon Aug 2 19:15:38 2010 +0200
Merge remote branch 'origin/master' into gallium-array-textures
Conflicts:
src/gallium/drivers/llvmpipe/lp_rast.c
src/gallium/drivers/llvmpipe/lp_rast_priv.h
src/gallium/drivers/r300/r300_blit.c
src/gallium/drivers/r300/r300_screen_buffer.c
src/gallium/drivers/r300/r300_state_derived.c
src/gallium/drivers/r300/r300_texture.c
src/gallium/drivers/r300/r300_texture.h
src/gallium/drivers/r300/r300_transfer.c
src/gallium/drivers/r600/r600_screen.c
src/gallium/drivers/r600/r600_state.c
src/gallium/drivers/r600/r600_texture.c
src/gallium/drivers/r600/r600_texture.h
src/gallium/state_trackers/dri/common/dri1_helper.c
src/gallium/state_trackers/dri/sw/drisw.c
src/gallium/state_trackers/xorg/xorg_exa.c
commit 9461bf3cfb647d2301364ae29fc3084fff52862a
Merge: 17492d7 0eaccb3
Author: Roland Scheidegger <[email protected]>
Date: Thu Jul 15 20:13:45 2010 +0200
Merge commit 'origin/master' into gallium-array-textures
Conflicts:
src/gallium/auxiliary/util/u_blitter.c
src/gallium/drivers/llvmpipe/lp_rast.c
src/gallium/drivers/llvmpipe/lp_surface.c
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_texture.c
src/gallium/drivers/r300/r300_transfer.c
src/gallium/tests/trivial/quad-tex.c
commit 17492d705e7b7f607b71db045c3bf344cb6842b3
Author: Roland Scheidegger <[email protected]>
Date: Fri Jun 18 10:58:08 2010 +0100
gallium: rename element_offset/width fields in views to first/last_element
This is much more consistent with the other fields used there
(first/last level, first/last layer).
Actually thinking about removing the ugly union/structs again and
rename first/last_layer to something even more generic which could also
be used for buffers (like first/last_member) without inducing headaches.
commit 1b717a289299f942de834dcccafbab91361e20ab
Author: Roland Scheidegger <[email protected]>
Date: Thu Jun 17 14:46:09 2010 +0100
gallium: remove PIPE_SURFACE_LAYOUT_LINEAR definition
This was only used by the layout field of pipe_surface, but this
driver internal stuff is gone so there's no need for this driver independent
layout definition neither.
commit 10cb644b31b3ef47e6c7b55e514ad24bb891fac4
Merge: 5691db9 c85971d
Author: Roland Scheidegger <[email protected]>
Date: Thu Jun 17 12:20:41 2010 +0100
Merge commit 'origin/master' into gallium-array-textures
Conflicts:
src/gallium/docs/source/glossary.rst
src/gallium/tests/graw/fs-test.c
src/gallium/tests/graw/gs-test.c
commit 5691db960ca3d525ce7d6c32d9c7a28f5e907f3b
Author: Roland Scheidegger <[email protected]>
Date: Thu Jun 17 11:29:03 2010 +0100
st/wgl: fix interface changes bugs
commit 2303ec32143d363b46e59e4b7c91b0ebd34a16b2
Author: Roland Scheidegger <[email protected]>
Date: Wed Jun 16 19:42:32 2010 +0100
gallium: adapt code to interface changes...
commit dcae4f586f0d0885b72674a355e5d56d47afe77d
Author: Roland Scheidegger <[email protected]>
Date: Wed Jun 16 19:42:05 2010 +0100
gallium: separate depth0 and array_size in the resource itself.
These fields are still mutually exclusive (since no 3d array textures exist)
but it ultimately seemed to error-prone to adapt all code accept the new
meaning of depth0 (drivers stick that into hardware regs, calculate mipmap
sizes etc.). And it isn't really cleaner anyway.
So, array textures will have depth0 of 1, but instead use array_size,
3D textures will continue to use depth0 (and have array_size of 1). Cube
maps also will use array_size to indicate their 6 faces, but since all drivers
should just be fine by inferring this themselves from the fact it's a cube map
as they always used to nothing should break.
commit 621737a638d187d208712250fc19a91978fdea6b
Author: Roland Scheidegger <[email protected]>
Date: Wed Jun 16 17:47:38 2010 +0100
gallium: adapt code to interface changes
There are still usages of pipe_surface where pipe_resource should be used,
which should eventually be fixed.
commit 2d17f5efe166b2c3d51957c76294165ab30b8ae2
Author: Roland Scheidegger <[email protected]>
Date: Wed Jun 16 17:46:14 2010 +0100
gallium: more interface changes
In particular to enable usage of buffers in views, and ability to use a
different pipe_format in pipe_surface.
Get rid of layout and offset parameter in pipe_surface - the former was
not used in any (public) code anyway, and the latter should either be computed
on-demand or driver can use subclass of pipe_surface.
Also make create_surface() use a template to be more consistent with
other functions.
commit 71f885ee16aa5cf2742c44bfaf0dc5b8734b9901
Merge: 3232d11 8ad410d
Author: Roland Scheidegger <[email protected]>
Date: Mon Jun 14 14:19:51 2010 +0100
Merge commit 'origin/master' into gallium-array-textures
Conflicts:
src/gallium/auxiliary/util/u_box.h
src/gallium/drivers/nv50/nv50_surface.c
src/gallium/drivers/nvfx/nvfx_surface.c
src/gallium/drivers/r300/r300_blit.c
src/gallium/drivers/r300/r300_texture.c
src/gallium/drivers/r300/r300_transfer.c
src/gallium/drivers/r600/r600_blit.c
src/gallium/drivers/r600/r600_screen.h
src/gallium/include/pipe/p_state.h
commit 3232d11fe3ebf7686286013c357b404714853984
Author: Roland Scheidegger <[email protected]>
Date: Mon Jun 14 11:40:04 2010 +0100
mesa/st: adapt to interface changes
still need to fix pipe_surface sharing
(as that is now per-context).
Also broken is depth0 handling - half the code assumes
this is also used for array textures (and hence by extension
of that cube maps would have depth 6), half the code does not...
commit f433b7f7f552720e5eade0b4078db94590ee85e1
Author: Roland Scheidegger <[email protected]>
Date: Mon Jun 14 11:35:52 2010 +0100
gallium: fix a couple of bugs in interface chnage fixes
commit 818366b28ea18f514dc791646248ce6f08d9bbcf
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:42:11 2010 +0200
targets: adapt to interface changes
Yes even that needs adjustments...
commit 66c511ab1682c9918e0200902039247793acb41e
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:41:13 2010 +0200
tests: adapt to interface changes
Everything needs to be fixed :-(.
commit 6b494635d9dbdaa7605bc87b1ebf682b138c5808
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:39:50 2010 +0200
st: adapt non-rendering state trackers to interface changes
might not be quite right in all places, but they really don't want
to use pipe_surface.
commit 00c4289a35d86e4fe85919ec32aa9f5ffe69d16d
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:38:48 2010 +0200
winsys: adapt to interface changes
commit 39d858554dc9ed5dbc795626fec3ef9deae552a0
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:26:54 2010 +0200
st/python: adapt to interface changes
don't think that will work, sorry.
commit 6e9336bc49b32139cec4e683857d0958000e15e3
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:26:07 2010 +0200
st/vega: adapt to interface changes
commit e07f2ae9aaf8842757d5d50865f76f8276245e11
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:25:56 2010 +0200
st/xorg: adapt to interface changes
commit 05531c10a74a4358103e30d3b38a5eceb25c947f
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:24:53 2010 +0200
nv50: adapt to interface changes
commit 97704f388d7042121c6d496ba8c003afa3ea2bf3
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:24:45 2010 +0200
nvfx: adapt to interface changes
commit a8a9c93d703af6e8f5c12e1cea9ec665add1abe0
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:24:01 2010 +0200
i965g: adapt to interface changes
commit 0dde209589872d20cc34ed0b237e3ed7ae0e2de3
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:22:38 2010 +0200
i915g: adapt to interface changes
commit 5cac9beede69d12f5807ee1a247a4c864652799e
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:20:58 2010 +0200
svga: adapt to interface changes
resource_copy_region still looking fishy.
Was not very suited to unified zslice/face approach...
commit 08b5a6af4b963a3e4c75fc336bf6c0772dce5150
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:20:01 2010 +0200
rbug: adapt to interface changes
Not sure if that won't need changes elsewhere?
commit c9fd24b1f586bcef2e0a6e76b68e40fca3408964
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:19:31 2010 +0200
trace: adapt to interface changes
commit ed84e010afc5635a1a47390b32247a266f65b8d1
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:19:21 2010 +0200
failover: adapt to interface changes
commit a1d4b4a293da933276908e3393435ec4b43cf201
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:19:12 2010 +0200
identity: adapt to interface changes
commit a8dd73e2c56c7d95ffcf174408f38f4f35fd2f4c
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:18:55 2010 +0200
softpipe: adapt to interface changes
commit a886085893e461e8473978e8206ec2312b7077ff
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:18:44 2010 +0200
llvmpipe: adapt to interface changes
commit 70523f6d567d8b7cfda682157556370fd3c43460
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:18:14 2010 +0200
r600g: adapt to interface changes
commit 3f4bc72bd80994865eb9f6b8dfd11e2b97060d19
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:18:05 2010 +0200
r300g: adapt to interface changes
commit 5d353b55ee14db0ac0515b5a3cf9389430832c19
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:17:37 2010 +0200
cell: adapt to interface changes
not even compile tested
commit cf5d03601322c2dcb12d7a9c2f1745e2b2a35eb4
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:14:59 2010 +0200
util: adapt to interface changes
amazing how much code changes just due to some subtle interface changes?
commit dc98d713c6937c0e177fc2caf23020402cc7ea7b
Author: Roland Scheidegger <[email protected]>
Date: Sat Jun 12 02:12:40 2010 +0200
gallium: more interface fail, docs
this also changes flush_frontbuffer to use a pipe_resource instead of
a pipe_surface - pipe_surface is not meant to be (or at least no longer)
an abstraction for standalone 2d images which get passed around.
(This has also implications for the non-rendering state-trackers.)
commit 08436d27ddd59857c22827c609b692aa0c407b7b
Author: Roland Scheidegger <[email protected]>
Date: Thu Jun 10 17:42:52 2010 +0200
gallium: fix array texture interface changes bugs, docs
commit 4a4d927609b62b4d7fb9dffa35158afe282f277b
Author: Roland Scheidegger <[email protected]>
Date: Thu Jun 3 22:02:44 2010 +0200
gallium: interface changes for array textures and related cleanups
This patch introduces array textures to gallium (note they are not immediately
usable without the associated changes to the shader side).
Also, this abandons pipe_subresource in favor of using level and layer
parameters since the distinction between several faces (which was part of
pipe_subresource for cube textures) and several z slices (which were not part
of pipe_subresource but instead part of pipe_box where appropriate for 3d
textures) is gone at the resource level.
Textures, be it array, cube, or 3d, now use a "unified" set of parameters,
there is no distinction between array members, cube faces, or 3d zslices.
This is unlike d3d10, whose subresource index includes layer information for
array textures, but which considers all z slices of a 3d texture to be part
of the same subresource.
In contrast to d3d10, OpenGL though reuses old 2d and 3d function entry points
for 1d and 2d array textures, respectively, which also implies that for instance
it is possible to specify all layers of a 2d array texture at once (note that
this is not possible for cube maps, which use the 2d entry points, although
it is possible for cube map arrays, which aren't supported yet in gallium).
This should possibly make drivers a bit simpler, and also get rid of mutually
exclusive parameters in some functions (as z and face were exclusive), one
potential downside would be that 3d array textures could not easily be supported
without reverting this, but those are nowhere to be seen.
Also along with adjusting to new parameters, rename get_tex_surface /
tex_surface_destroy to create_surface / surface_destroy and move them from
screen to context, which reflects much better what those do (they are analogous
to create_sampler_view / sampler_view_destroy).
PIPE_CAP_ARRAY_TEXTURES is used to indicate if a driver supports all of this
functionality (that is, both sampling from array texture as well as use a range
of layers as a render target, with selecting the layer from the geometry shader).
Diffstat (limited to 'src/gallium/auxiliary/util')
23 files changed, 621 insertions, 548 deletions
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); |