diff options
author | marha <marha@users.sourceforge.net> | 2012-07-13 10:11:58 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-07-13 10:11:58 +0200 |
commit | f0a7d1d88be0c31bd471f4428c4493a93f2d9321 (patch) | |
tree | 15b5078011dc751f9c1a1bb21e51dc2e600ee205 /mesalib/src/gallium/auxiliary | |
parent | 165450290d6c26756ede118f52ba2164abce7c9a (diff) | |
download | vcxsrv-f0a7d1d88be0c31bd471f4428c4493a93f2d9321.tar.gz vcxsrv-f0a7d1d88be0c31bd471f4428c4493a93f2d9321.tar.bz2 vcxsrv-f0a7d1d88be0c31bd471f4428c4493a93f2d9321.zip |
xserver mesa git update 13 Jul 2012
Diffstat (limited to 'mesalib/src/gallium/auxiliary')
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_blit.c | 337 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_blit.h | 20 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_blitter.c | 153 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_blitter.h | 4 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_format.h | 29 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_gen_mipmap.c | 84 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_inlines.h | 26 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_simple_shaders.c | 100 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_simple_shaders.h | 12 |
9 files changed, 573 insertions, 192 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_blit.c b/mesalib/src/gallium/auxiliary/util/u_blit.c index 9bd2ef52d..b52f4c092 100644 --- a/mesalib/src/gallium/auxiliary/util/u_blit.c +++ b/mesalib/src/gallium/auxiliary/util/u_blit.c @@ -56,9 +56,11 @@ struct blit_state struct pipe_context *pipe; struct cso_context *cso; - struct pipe_blend_state blend; - struct pipe_depth_stencil_alpha_state depthstencil_keep; - struct pipe_depth_stencil_alpha_state depthstencil_write; + struct pipe_blend_state blend_write_color, blend_keep_color; + struct pipe_depth_stencil_alpha_state dsa_keep_depthstencil; + struct pipe_depth_stencil_alpha_state dsa_write_depthstencil; + struct pipe_depth_stencil_alpha_state dsa_write_depth; + struct pipe_depth_stencil_alpha_state dsa_write_stencil; struct pipe_rasterizer_state rasterizer; struct pipe_sampler_state sampler; struct pipe_viewport_state viewport; @@ -66,13 +68,17 @@ struct blit_state enum pipe_texture_target internal_target; void *vs; - void *fs[TGSI_WRITEMASK_XYZW + 1]; - void *fs_depth; + void *fs[PIPE_MAX_TEXTURE_TYPES][TGSI_WRITEMASK_XYZW + 1]; + void *fs_depthstencil[PIPE_MAX_TEXTURE_TYPES]; + void *fs_depth[PIPE_MAX_TEXTURE_TYPES]; + void *fs_stencil[PIPE_MAX_TEXTURE_TYPES]; struct pipe_resource *vbuf; /**< quad vertices */ unsigned vbuf_slot; float vertices[4][2][4]; /**< vertex/texcoords for quad */ + + boolean has_stencil_export; }; @@ -94,24 +100,28 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso) ctx->cso = cso; /* disabled blending/masking */ - memset(&ctx->blend, 0, sizeof(ctx->blend)); - ctx->blend.rt[0].colormask = PIPE_MASK_RGBA; - - /* no-op depth/stencil/alpha */ - memset(&ctx->depthstencil_keep, 0, sizeof(ctx->depthstencil_keep)); - memset(&ctx->depthstencil_write, 0, sizeof(ctx->depthstencil_write)); - ctx->depthstencil_write.depth.enabled = 1; - ctx->depthstencil_write.depth.writemask = 1; - ctx->depthstencil_write.depth.func = PIPE_FUNC_ALWAYS; + ctx->blend_write_color.rt[0].colormask = PIPE_MASK_RGBA; + + /* depth stencil states */ + ctx->dsa_write_depth.depth.enabled = 1; + ctx->dsa_write_depth.depth.writemask = 1; + ctx->dsa_write_depth.depth.func = PIPE_FUNC_ALWAYS; + ctx->dsa_write_stencil.stencil[0].enabled = 1; + ctx->dsa_write_stencil.stencil[0].func = PIPE_FUNC_ALWAYS; + ctx->dsa_write_stencil.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE; + ctx->dsa_write_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE; + ctx->dsa_write_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE; + ctx->dsa_write_stencil.stencil[0].valuemask = 0xff; + ctx->dsa_write_stencil.stencil[0].writemask = 0xff; + ctx->dsa_write_depthstencil.depth = ctx->dsa_write_depth.depth; + ctx->dsa_write_depthstencil.stencil[0] = ctx->dsa_write_stencil.stencil[0]; /* rasterizer */ - memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer)); ctx->rasterizer.cull_face = PIPE_FACE_NONE; ctx->rasterizer.gl_rasterization_rules = 1; ctx->rasterizer.depth_clip = 1; /* samplers */ - memset(&ctx->sampler, 0, sizeof(ctx->sampler)); ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; @@ -120,7 +130,6 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso) ctx->sampler.mag_img_filter = 0; /* set later */ /* vertex elements state */ - memset(&ctx->velem[0], 0, sizeof(ctx->velem[0]) * 2); for (i = 0; i < 2; i++) { ctx->velem[i].src_offset = i * 4 * sizeof(float); ctx->velem[i].instance_divisor = 0; @@ -142,6 +151,9 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso) else ctx->internal_target = PIPE_TEXTURE_RECT; + ctx->has_stencil_export = + pipe->screen->get_param(pipe->screen, PIPE_CAP_SHADER_STENCIL_EXPORT); + return ctx; } @@ -153,17 +165,29 @@ void util_destroy_blit(struct blit_state *ctx) { struct pipe_context *pipe = ctx->pipe; - unsigned i; + unsigned i, j; if (ctx->vs) pipe->delete_vs_state(pipe, ctx->vs); - for (i = 0; i < Elements(ctx->fs); i++) - if (ctx->fs[i]) - pipe->delete_fs_state(pipe, ctx->fs[i]); + for (i = 0; i < Elements(ctx->fs); i++) { + for (j = 0; j < Elements(ctx->fs[i]); j++) { + if (ctx->fs[i][j]) + pipe->delete_fs_state(pipe, ctx->fs[i][j]); + } + } - if (ctx->fs_depth) - pipe->delete_fs_state(pipe, ctx->fs_depth); + for (i = 0; i < PIPE_MAX_TEXTURE_TYPES; i++) { + if (ctx->fs_depthstencil[i]) { + pipe->delete_fs_state(pipe, ctx->fs_depthstencil[i]); + } + if (ctx->fs_depth[i]) { + pipe->delete_fs_state(pipe, ctx->fs_depth[i]); + } + if (ctx->fs_stencil[i]) { + pipe->delete_fs_state(pipe, ctx->fs_stencil[i]); + } + } pipe_resource_reference(&ctx->vbuf, NULL); @@ -175,30 +199,76 @@ util_destroy_blit(struct blit_state *ctx) * Helper function to set the fragment shaders. */ static INLINE void -set_fragment_shader(struct blit_state *ctx, uint writemask) +set_fragment_shader(struct blit_state *ctx, uint writemask, + enum pipe_texture_target pipe_tex) { - if (!ctx->fs[writemask]) - ctx->fs[writemask] = - util_make_fragment_tex_shader_writemask(ctx->pipe, TGSI_TEXTURE_2D, + if (!ctx->fs[pipe_tex][writemask]) { + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex); + + ctx->fs[pipe_tex][writemask] = + util_make_fragment_tex_shader_writemask(ctx->pipe, tgsi_tex, TGSI_INTERPOLATE_LINEAR, writemask); + } - cso_set_fragment_shader_handle(ctx->cso, ctx->fs[writemask]); + cso_set_fragment_shader_handle(ctx->cso, ctx->fs[pipe_tex][writemask]); } /** - * Helper function to set the depthwrite shader. + * Helper function to set the shader which writes depth and stencil. */ static INLINE void -set_depth_fragment_shader(struct blit_state *ctx) +set_depthstencil_fragment_shader(struct blit_state *ctx, + enum pipe_texture_target pipe_tex) { - if (!ctx->fs_depth) - ctx->fs_depth = - util_make_fragment_tex_shader_writedepth(ctx->pipe, TGSI_TEXTURE_2D, + if (!ctx->fs_depthstencil[pipe_tex]) { + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex); + + ctx->fs_depthstencil[pipe_tex] = + util_make_fragment_tex_shader_writedepthstencil(ctx->pipe, tgsi_tex, TGSI_INTERPOLATE_LINEAR); + } - cso_set_fragment_shader_handle(ctx->cso, ctx->fs_depth); + cso_set_fragment_shader_handle(ctx->cso, ctx->fs_depthstencil[pipe_tex]); +} + + +/** + * Helper function to set the shader which writes depth. + */ +static INLINE void +set_depth_fragment_shader(struct blit_state *ctx, + enum pipe_texture_target pipe_tex) +{ + if (!ctx->fs_depth[pipe_tex]) { + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex); + + ctx->fs_depth[pipe_tex] = + util_make_fragment_tex_shader_writedepth(ctx->pipe, tgsi_tex, + TGSI_INTERPOLATE_LINEAR); + } + + cso_set_fragment_shader_handle(ctx->cso, ctx->fs_depth[pipe_tex]); +} + + +/** + * Helper function to set the shader which writes stencil. + */ +static INLINE void +set_stencil_fragment_shader(struct blit_state *ctx, + enum pipe_texture_target pipe_tex) +{ + if (!ctx->fs_stencil[pipe_tex]) { + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex); + + ctx->fs_stencil[pipe_tex] = + util_make_fragment_tex_shader_writestencil(ctx->pipe, tgsi_tex, + TGSI_INTERPOLATE_LINEAR); + } + + cso_set_fragment_shader_handle(ctx->cso, ctx->fs_stencil[pipe_tex]); } @@ -350,20 +420,19 @@ formats_compatible(enum pipe_format src_format, * \param writemask controls which channels in the dest surface are sourced * from the src surface. Disabled channels are sourced * from (0,0,0,1). - * XXX need some control over blitting stencil. */ void -util_blit_pixels_writemask(struct blit_state *ctx, - struct pipe_resource *src_tex, - unsigned src_level, - int srcX0, int srcY0, - int srcX1, int srcY1, - int srcZ0, - struct pipe_surface *dst, - int dstX0, int dstY0, - int dstX1, int dstY1, - float z, uint filter, - uint writemask) +util_blit_pixels(struct blit_state *ctx, + struct pipe_resource *src_tex, + unsigned src_level, + int srcX0, int srcY0, + int srcX1, int srcY1, + int srcZ0, + struct pipe_surface *dst, + int dstX0, int dstY0, + int dstX1, int dstY1, + float z, uint filter, + uint writemask, uint zs_writemask) { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; @@ -375,9 +444,12 @@ util_blit_pixels_writemask(struct blit_state *ctx, const int srcW = abs(srcX1 - srcX0); const int srcH = abs(srcY1 - srcY0); unsigned offset; - boolean overlap, dst_is_depth; + boolean overlap; float s0, t0, s1, t1; boolean normalized; + boolean is_stencil, is_depth, blit_depth, blit_stencil; + const struct util_format_description *src_desc = + util_format_description(src_tex->format); assert(filter == PIPE_TEX_MIPFILTER_NEAREST || filter == PIPE_TEX_MIPFILTER_LINEAR); @@ -394,12 +466,24 @@ util_blit_pixels_writemask(struct blit_state *ctx, src_format = util_format_linear(src_tex->format); dst_format = util_format_linear(dst->format); + /* See whether we will blit depth or stencil. */ + is_depth = util_format_has_depth(src_desc); + is_stencil = util_format_has_stencil(src_desc); + + blit_depth = is_depth && (zs_writemask & BLIT_WRITEMASK_Z); + blit_stencil = is_stencil && (zs_writemask & BLIT_WRITEMASK_STENCIL); + + assert((writemask && !zs_writemask && !is_depth && !is_stencil) || + (!writemask && (blit_depth || blit_stencil))); + /* * Check for simple case: no format conversion, no flipping, no stretching, * no overlapping. * Filter mode should not matter since there's no stretching. */ if (formats_compatible(src_format, dst_format) && + is_stencil == blit_stencil && + is_depth == blit_depth && srcX0 < srcX1 && dstX0 < dstX1 && srcY0 < srcY1 && @@ -422,6 +506,17 @@ util_blit_pixels_writemask(struct blit_state *ctx, return; } + /* It's a mistake to call this function with a stencil format and + * without shader stencil export. We don't do software fallbacks here. + * Ignore stencil and only copy depth. + */ + if (blit_stencil && !ctx->has_stencil_export) { + blit_stencil = FALSE; + + if (!blit_depth) + return; + } + if (dst_format == dst->format) { dst_surface = dst; } else { @@ -430,20 +525,11 @@ util_blit_pixels_writemask(struct blit_state *ctx, dst_surface = pipe->create_surface(pipe, dst->texture, &templ); } - /* Create a temporary texture when src and dest alias or when src - * is anything other than a 2d texture. - * XXX should just use appropriate shader to access 1d / 3d slice / cube face, - * much like the u_blitter code does (should be pretty trivial). - * - * This can still be improved upon. + /* Create a temporary texture when src and dest alias. */ - if ((src_tex == dst_surface->texture && + if (src_tex == dst_surface->texture && dst_surface->u.tex.level == src_level && - dst_surface->u.tex.first_layer == srcZ0) || - (src_tex->target != PIPE_TEXTURE_2D && - src_tex->target != PIPE_TEXTURE_2D && - src_tex->target != PIPE_TEXTURE_RECT)) - { + dst_surface->u.tex.first_layer == srcZ0) { /* Make a temporary texture which contains a copy of the source pixels. * Then we'll sample from the temporary texture. */ @@ -509,6 +595,11 @@ util_blit_pixels_writemask(struct blit_state *ctx, } u_sampler_view_default_template(&sv_templ, tex, tex->format); + if (!blit_depth && blit_stencil) { + /* set a stencil-only format, e.g. Z24S8 --> X24S8 */ + sv_templ.format = util_format_stencil_only(tex->format); + assert(sv_templ.format != PIPE_FORMAT_NONE); + } sampler_view = pipe->create_sampler_view(pipe, tex, &sv_templ); if (!sampler_view) { @@ -520,6 +611,11 @@ util_blit_pixels_writemask(struct blit_state *ctx, else { /* Directly sample from the source resource/texture */ u_sampler_view_default_template(&sv_templ, src_tex, src_format); + if (!blit_depth && blit_stencil) { + /* set a stencil-only format, e.g. Z24S8 --> X24S8 */ + sv_templ.format = util_format_stencil_only(src_format); + assert(sv_templ.format != PIPE_FORMAT_NONE); + } sampler_view = pipe->create_sampler_view(pipe, src_tex, &sv_templ); if (!sampler_view) { @@ -540,15 +636,14 @@ util_blit_pixels_writemask(struct blit_state *ctx, } } - dst_is_depth = util_format_is_depth_or_stencil(dst_format); - - assert(screen->is_format_supported(screen, sampler_view->format, ctx->internal_target, - sampler_view->texture->nr_samples, - PIPE_BIND_SAMPLER_VIEW)); + assert(screen->is_format_supported(screen, sampler_view->format, + ctx->internal_target, sampler_view->texture->nr_samples, + PIPE_BIND_SAMPLER_VIEW)); assert(screen->is_format_supported(screen, dst_format, ctx->internal_target, - dst_surface->texture->nr_samples, - dst_is_depth ? PIPE_BIND_DEPTH_STENCIL : - PIPE_BIND_RENDER_TARGET)); + dst_surface->texture->nr_samples, + is_depth || is_stencil ? PIPE_BIND_DEPTH_STENCIL : + PIPE_BIND_RENDER_TARGET)); + /* save state (restored below) */ cso_save_blend(ctx->cso); cso_save_depth_stencil_alpha(ctx->cso); @@ -565,23 +660,76 @@ util_blit_pixels_writemask(struct blit_state *ctx, cso_save_vertex_buffers(ctx->cso); /* set misc state we care about */ - cso_set_blend(ctx->cso, &ctx->blend); - cso_set_depth_stencil_alpha(ctx->cso, - dst_is_depth ? &ctx->depthstencil_write : - &ctx->depthstencil_keep); + if (writemask) + cso_set_blend(ctx->cso, &ctx->blend_write_color); + else + cso_set_blend(ctx->cso, &ctx->blend_keep_color); + cso_set_rasterizer(ctx->cso, &ctx->rasterizer); cso_set_vertex_elements(ctx->cso, 2, ctx->velem); cso_set_stream_outputs(ctx->cso, 0, NULL, 0); - /* sampler */ + /* default sampler state */ ctx->sampler.normalized_coords = normalized; ctx->sampler.min_img_filter = filter; ctx->sampler.mag_img_filter = filter; ctx->sampler.min_lod = src_level; ctx->sampler.max_lod = src_level; - cso_single_sampler(ctx->cso, 0, &ctx->sampler); + + /* Depth stencil state, fragment shader and sampler setup depending on what + * we blit. + */ + if (blit_depth && blit_stencil) { + cso_single_sampler(ctx->cso, 0, &ctx->sampler); + /* don't filter stencil */ + ctx->sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; + ctx->sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + cso_single_sampler(ctx->cso, 1, &ctx->sampler); + + cso_set_depth_stencil_alpha(ctx->cso, &ctx->dsa_write_depthstencil); + set_depthstencil_fragment_shader(ctx, sampler_view->texture->target); + } + else if (blit_depth) { + cso_single_sampler(ctx->cso, 0, &ctx->sampler); + cso_set_depth_stencil_alpha(ctx->cso, &ctx->dsa_write_depth); + set_depth_fragment_shader(ctx, sampler_view->texture->target); + } + else if (blit_stencil) { + /* don't filter stencil */ + ctx->sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; + ctx->sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + cso_single_sampler(ctx->cso, 0, &ctx->sampler); + + cso_set_depth_stencil_alpha(ctx->cso, &ctx->dsa_write_stencil); + set_stencil_fragment_shader(ctx, sampler_view->texture->target); + } + else { /* color */ + cso_single_sampler(ctx->cso, 0, &ctx->sampler); + cso_set_depth_stencil_alpha(ctx->cso, &ctx->dsa_keep_depthstencil); + set_fragment_shader(ctx, writemask, sampler_view->texture->target); + } cso_single_sampler_done(ctx->cso); + /* textures */ + if (blit_depth && blit_stencil) { + /* Setup two samplers, one for depth and the other one for stencil. */ + struct pipe_sampler_view templ; + struct pipe_sampler_view *views[2]; + + templ = *sampler_view; + templ.format = util_format_stencil_only(templ.format); + assert(templ.format != PIPE_FORMAT_NONE); + + views[0] = sampler_view; + views[1] = pipe->create_sampler_view(pipe, views[0]->texture, &templ); + cso_set_fragment_sampler_views(ctx->cso, 2, views); + + pipe_sampler_view_reference(&views[1], NULL); + } + else { + cso_set_fragment_sampler_views(ctx->cso, 1, &sampler_view); + } + /* viewport */ ctx->viewport.scale[0] = 0.5f * dst_surface->width; ctx->viewport.scale[1] = 0.5f * dst_surface->height; @@ -593,15 +741,6 @@ util_blit_pixels_writemask(struct blit_state *ctx, ctx->viewport.translate[3] = 0.0f; cso_set_viewport(ctx->cso, &ctx->viewport); - /* texture */ - cso_set_fragment_sampler_views(ctx->cso, 1, &sampler_view); - - /* shaders */ - if (dst_is_depth) { - set_depth_fragment_shader(ctx); - } else { - set_fragment_shader(ctx, writemask); - } set_vertex_shader(ctx); cso_set_geometry_shader_handle(ctx->cso, NULL); @@ -609,7 +748,7 @@ util_blit_pixels_writemask(struct blit_state *ctx, memset(&fb, 0, sizeof(fb)); fb.width = dst_surface->width; fb.height = dst_surface->height; - if (dst_is_depth) { + if (blit_depth || blit_stencil) { fb.zsbuf = dst_surface; } else { fb.nr_cbufs = 1; @@ -655,31 +794,6 @@ util_blit_pixels_writemask(struct blit_state *ctx, } -void -util_blit_pixels(struct blit_state *ctx, - struct pipe_resource *src_tex, - unsigned src_level, - int srcX0, int srcY0, - int srcX1, int srcY1, - int srcZ, - struct pipe_surface *dst, - int dstX0, int dstY0, - int dstX1, int dstY1, - float z, uint filter ) -{ - util_blit_pixels_writemask( ctx, src_tex, - src_level, - srcX0, srcY0, - srcX1, srcY1, - srcZ, - dst, - dstX0, dstY0, - dstX1, dstY1, - z, filter, - TGSI_WRITEMASK_XYZW ); -} - - /** * Copy pixel block from src texture to dst surface. * The sampler view's first_level field indicates the source @@ -747,8 +861,8 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_save_vertex_buffers(ctx->cso); /* set misc state we care about */ - cso_set_blend(ctx->cso, &ctx->blend); - cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil_keep); + cso_set_blend(ctx->cso, &ctx->blend_write_color); + cso_set_depth_stencil_alpha(ctx->cso, &ctx->dsa_keep_depthstencil); cso_set_rasterizer(ctx->cso, &ctx->rasterizer); cso_set_vertex_elements(ctx->cso, 2, ctx->velem); cso_set_stream_outputs(ctx->cso, 0, NULL, 0); @@ -775,7 +889,8 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_set_fragment_sampler_views(ctx->cso, 1, &src_sampler_view); /* shaders */ - set_fragment_shader(ctx, TGSI_WRITEMASK_XYZW); + set_fragment_shader(ctx, TGSI_WRITEMASK_XYZW, + src_sampler_view->texture->target); set_vertex_shader(ctx); cso_set_geometry_shader_handle(ctx->cso, NULL); diff --git a/mesalib/src/gallium/auxiliary/util/u_blit.h b/mesalib/src/gallium/auxiliary/util/u_blit.h index 810d01b04..56ab03083 100644 --- a/mesalib/src/gallium/auxiliary/util/u_blit.h +++ b/mesalib/src/gallium/auxiliary/util/u_blit.h @@ -31,6 +31,8 @@ #include "pipe/p_compiler.h" +/* for TGSI_WRITEMASK_* specification in util_blit_pixels */ +#include "pipe/p_shader_tokens.h" #ifdef __cplusplus @@ -44,6 +46,8 @@ struct pipe_resource; struct pipe_sampler_view; struct pipe_surface; +#define BLIT_WRITEMASK_Z 1 +#define BLIT_WRITEMASK_STENCIL 2 extern struct blit_state * util_create_blit(struct pipe_context *pipe, struct cso_context *cso); @@ -61,20 +65,8 @@ util_blit_pixels(struct blit_state *ctx, struct pipe_surface *dst, int dstX0, int dstY0, int dstX1, int dstY1, - float z, uint filter); - -void -util_blit_pixels_writemask(struct blit_state *ctx, - struct pipe_resource *src_tex, - unsigned src_level, - int srcX0, int srcY0, - int srcX1, int srcY1, - int srcZ0, - struct pipe_surface *dst, - int dstX0, int dstY0, - int dstX1, int dstY1, - float z, uint filter, - uint writemask); + float z, uint filter, + uint writemask, uint zs_writemask); extern void util_blit_pixels_tex(struct blit_state *ctx, diff --git a/mesalib/src/gallium/auxiliary/util/u_blitter.c b/mesalib/src/gallium/auxiliary/util/u_blitter.c index 47d0227a9..b31ac2d5c 100644 --- a/mesalib/src/gallium/auxiliary/util/u_blitter.c +++ b/mesalib/src/gallium/auxiliary/util/u_blitter.c @@ -78,6 +78,8 @@ struct blitter_context_priv /* FS which outputs a depth from a texture, where the index is PIPE_TEXTURE_* to be sampled. */ void *fs_texfetch_depth[PIPE_MAX_TEXTURE_TYPES]; + void *fs_texfetch_depthstencil[PIPE_MAX_TEXTURE_TYPES]; + void *fs_texfetch_stencil[PIPE_MAX_TEXTURE_TYPES]; /* Blend state. */ void *blend_write_color; /**< blend state with writemask of RGBA */ @@ -112,6 +114,7 @@ struct blitter_context_priv boolean has_geometry_shader; boolean vertex_has_integers; boolean has_stream_out; + boolean has_stencil_export; }; static void blitter_draw_rectangle(struct blitter_context *blitter, @@ -163,6 +166,10 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS) != 0; + ctx->has_stencil_export = + pipe->screen->get_param(pipe->screen, + PIPE_CAP_SHADER_STENCIL_EXPORT); + /* blend state objects */ memset(&blend, 0, sizeof(blend)); ctx->blend_keep_color = pipe->create_blend_state(pipe, &blend); @@ -314,6 +321,10 @@ void util_blitter_destroy(struct blitter_context *blitter) pipe->delete_fs_state(pipe, ctx->fs_texfetch_col[i]); if (ctx->fs_texfetch_depth[i]) pipe->delete_fs_state(pipe, ctx->fs_texfetch_depth[i]); + if (ctx->fs_texfetch_depthstencil[i]) + pipe->delete_fs_state(pipe, ctx->fs_texfetch_depthstencil[i]); + if (ctx->fs_texfetch_stencil[i]) + pipe->delete_fs_state(pipe, ctx->fs_texfetch_stencil[i]); } for (i = 0; i <= PIPE_MAX_COLOR_BUFS; i++) { @@ -653,32 +664,6 @@ void *blitter_get_fs_col(struct blitter_context_priv *ctx, unsigned num_cbufs, } } -/** Convert PIPE_TEXTURE_x to TGSI_TEXTURE_x */ -static unsigned -pipe_tex_to_tgsi_tex(enum pipe_texture_target pipe_tex_target) -{ - switch (pipe_tex_target) { - case PIPE_TEXTURE_1D: - return TGSI_TEXTURE_1D; - case PIPE_TEXTURE_2D: - return TGSI_TEXTURE_2D; - case PIPE_TEXTURE_RECT: - return TGSI_TEXTURE_RECT; - case PIPE_TEXTURE_3D: - return TGSI_TEXTURE_3D; - case PIPE_TEXTURE_CUBE: - return TGSI_TEXTURE_CUBE; - case PIPE_TEXTURE_1D_ARRAY: - return TGSI_TEXTURE_1D_ARRAY; - case PIPE_TEXTURE_2D_ARRAY: - return TGSI_TEXTURE_2D_ARRAY; - default: - assert(0 && "unexpected texture target"); - return TGSI_TEXTURE_UNKNOWN; - } -} - - static INLINE void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx, unsigned tex_target) @@ -689,7 +674,7 @@ void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx, /* Create the fragment shader on-demand. */ if (!ctx->fs_texfetch_col[tex_target]) { - unsigned tgsi_tex = pipe_tex_to_tgsi_tex(tex_target); + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex_target); ctx->fs_texfetch_col[tex_target] = util_make_fragment_tex_shader(pipe, tgsi_tex, TGSI_INTERPOLATE_LINEAR); @@ -708,7 +693,7 @@ void *blitter_get_fs_texfetch_depth(struct blitter_context_priv *ctx, /* Create the fragment shader on-demand. */ if (!ctx->fs_texfetch_depth[tex_target]) { - unsigned tgsi_tex = pipe_tex_to_tgsi_tex(tex_target); + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex_target); ctx->fs_texfetch_depth[tex_target] = util_make_fragment_tex_shader_writedepth(pipe, tgsi_tex, @@ -718,6 +703,46 @@ void *blitter_get_fs_texfetch_depth(struct blitter_context_priv *ctx, return ctx->fs_texfetch_depth[tex_target]; } +static INLINE +void *blitter_get_fs_texfetch_depthstencil(struct blitter_context_priv *ctx, + unsigned tex_target) +{ + struct pipe_context *pipe = ctx->base.pipe; + + assert(tex_target < PIPE_MAX_TEXTURE_TYPES); + + /* Create the fragment shader on-demand. */ + if (!ctx->fs_texfetch_depthstencil[tex_target]) { + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex_target); + + ctx->fs_texfetch_depthstencil[tex_target] = + util_make_fragment_tex_shader_writedepthstencil(pipe, tgsi_tex, + TGSI_INTERPOLATE_LINEAR); + } + + return ctx->fs_texfetch_depthstencil[tex_target]; +} + +static INLINE +void *blitter_get_fs_texfetch_stencil(struct blitter_context_priv *ctx, + unsigned tex_target) +{ + struct pipe_context *pipe = ctx->base.pipe; + + assert(tex_target < PIPE_MAX_TEXTURE_TYPES); + + /* Create the fragment shader on-demand. */ + if (!ctx->fs_texfetch_stencil[tex_target]) { + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex_target); + + ctx->fs_texfetch_stencil[tex_target] = + util_make_fragment_tex_shader_writestencil(pipe, tgsi_tex, + TGSI_INTERPOLATE_LINEAR); + } + + return ctx->fs_texfetch_stencil[tex_target]; +} + static void blitter_set_common_draw_rect_state(struct blitter_context_priv *ctx) { struct pipe_context *pipe = ctx->base.pipe; @@ -892,7 +917,7 @@ void util_blitter_default_src_texture(struct pipe_sampler_view *src_templ, src_templ->u.tex.last_level = srclevel; src_templ->u.tex.first_layer = 0; src_templ->u.tex.last_layer = - src->target == PIPE_TEXTURE_3D ? src->depth0 - 1 + src->target == PIPE_TEXTURE_3D ? u_minify(src->depth0, srclevel) - 1 : src->array_size - 1; src_templ->swizzle_r = PIPE_SWIZZLE_RED; src_templ->swizzle_g = PIPE_SWIZZLE_GREEN; @@ -916,6 +941,8 @@ void util_blitter_copy_texture(struct blitter_context *blitter, struct pipe_sampler_view src_templ, *src_view; unsigned bind; boolean is_stencil, is_depth; + const struct util_format_description *src_desc = + util_format_description(src->format); /* Give up if textures are not set. */ assert(dst && src); @@ -925,8 +952,8 @@ void util_blitter_copy_texture(struct blitter_context *blitter, assert(src->target < PIPE_MAX_TEXTURE_TYPES); /* Is this a ZS format? */ - is_depth = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0; - is_stencil = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 1) != 0; + is_depth = util_format_has_depth(src_desc); + is_stencil = util_format_has_stencil(src_desc); if (is_depth || is_stencil) bind = PIPE_BIND_DEPTH_STENCIL; @@ -935,7 +962,7 @@ void util_blitter_copy_texture(struct blitter_context *blitter, /* Check if we can sample from and render to the surfaces. */ /* (assuming copying a stencil buffer is not possible) */ - if ((!ignore_stencil && is_stencil) || + if ((!ignore_stencil && is_stencil && !ctx->has_stencil_export) || !screen->is_format_supported(screen, dst->format, dst->target, dst->nr_samples, bind) || !screen->is_format_supported(screen, src->format, src->target, @@ -976,6 +1003,21 @@ void util_blitter_copy_texture_view(struct blitter_context *blitter, enum pipe_texture_target src_target = src->texture->target; unsigned width = srcbox->width; unsigned height = srcbox->height; + boolean is_stencil, is_depth; + const struct util_format_description *src_desc = + util_format_description(src->format); + + is_depth = util_format_has_depth(src_desc); + is_stencil = util_format_has_stencil(src_desc); + + /* If you want a fallback for stencil copies, + * use util_blitter_copy_texture. */ + if (is_stencil && !ctx->has_stencil_export) { + is_stencil = FALSE; + + if (!is_depth) + return; + } /* Sanity checks. */ if (dst->texture == src->texture && @@ -997,12 +1039,25 @@ void util_blitter_copy_texture_view(struct blitter_context *blitter, fb_state.width = dst->width; fb_state.height = dst->height; - if (util_format_is_depth_or_stencil(dst->format)) { + if (is_depth || is_stencil) { pipe->bind_blend_state(pipe, ctx->blend_keep_color); - pipe->bind_depth_stencil_alpha_state(pipe, - ctx->dsa_write_depth_keep_stencil); - pipe->bind_fs_state(pipe, - blitter_get_fs_texfetch_depth(ctx, src_target)); + + if (is_depth && is_stencil) { + pipe->bind_depth_stencil_alpha_state(pipe, + ctx->dsa_write_depth_stencil); + pipe->bind_fs_state(pipe, + blitter_get_fs_texfetch_depthstencil(ctx, src_target)); + } else if (is_depth) { + pipe->bind_depth_stencil_alpha_state(pipe, + ctx->dsa_write_depth_keep_stencil); + pipe->bind_fs_state(pipe, + blitter_get_fs_texfetch_depth(ctx, src_target)); + } else { /* is_stencil */ + pipe->bind_depth_stencil_alpha_state(pipe, + ctx->dsa_keep_depth_write_stencil); + pipe->bind_fs_state(pipe, + blitter_get_fs_texfetch_stencil(ctx, src_target)); + } fb_state.nr_cbufs = 0; fb_state.zsbuf = dst; @@ -1017,9 +1072,29 @@ void util_blitter_copy_texture_view(struct blitter_context *blitter, fb_state.zsbuf = 0; } - pipe->bind_fragment_sampler_states(pipe, 1, &ctx->sampler_state); + if (is_depth && is_stencil) { + /* Setup two samplers, one for depth and the other one for stencil. */ + struct pipe_sampler_view templ; + struct pipe_sampler_view *views[2]; + void *samplers[2] = {ctx->sampler_state, ctx->sampler_state}; + + templ = *src; + templ.format = util_format_stencil_only(templ.format); + assert(templ.format != PIPE_FORMAT_NONE); + + views[0] = src; + views[1] = pipe->create_sampler_view(pipe, src->texture, &templ); + + pipe->set_fragment_sampler_views(pipe, 2, views); + pipe->bind_fragment_sampler_states(pipe, 2, samplers); + + pipe_sampler_view_reference(&views[1], NULL); + } else { + pipe->set_fragment_sampler_views(pipe, 1, &src); + pipe->bind_fragment_sampler_states(pipe, 1, &ctx->sampler_state); + } + pipe->bind_vertex_elements_state(pipe, ctx->velem_state); - pipe->set_fragment_sampler_views(pipe, 1, &src); pipe->set_framebuffer_state(pipe, &fb_state); blitter_set_common_draw_rect_state(ctx); diff --git a/mesalib/src/gallium/auxiliary/util/u_blitter.h b/mesalib/src/gallium/auxiliary/util/u_blitter.h index d4d30852b..2db984c8a 100644 --- a/mesalib/src/gallium/auxiliary/util/u_blitter.h +++ b/mesalib/src/gallium/auxiliary/util/u_blitter.h @@ -169,8 +169,8 @@ void util_blitter_clear_depth_custom(struct blitter_context *blitter, * The same holds for depth-stencil formats with the exception that stencil * cannot be copied unless you set ignore_stencil to FALSE. In that case, * a software fallback path is taken and both surfaces must be of the same - * format. - * XXX implement hw-accel stencil copy using shader stencil export. + * format. If the shader stencil export is supported, stencil copy is always + * accelerated. * * Use pipe_screen->is_format_supported to know your options. * diff --git a/mesalib/src/gallium/auxiliary/util/u_format.h b/mesalib/src/gallium/auxiliary/util/u_format.h index e35e164b4..a718389dd 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format.h +++ b/mesalib/src/gallium/auxiliary/util/u_format.h @@ -882,6 +882,35 @@ util_format_linear(enum pipe_format format) } /** + * Given a depth-stencil format, return the corresponding stencil-only format. + * For stencil-only formats, return the format unchanged. + */ +static INLINE enum pipe_format +util_format_stencil_only(enum pipe_format format) +{ + switch (format) { + /* mask out the depth component */ + case PIPE_FORMAT_Z24_UNORM_S8_UINT: + return PIPE_FORMAT_X24S8_UINT; + case PIPE_FORMAT_S8_UINT_Z24_UNORM: + return PIPE_FORMAT_S8X24_UINT; + case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: + return PIPE_FORMAT_X32_S8X24_UINT; + + /* stencil only formats */ + case PIPE_FORMAT_X24S8_UINT: + case PIPE_FORMAT_S8X24_UINT: + case PIPE_FORMAT_X32_S8X24_UINT: + case PIPE_FORMAT_S8_UINT: + return format; + + default: + assert(0); + return PIPE_FORMAT_NONE; + } +} + +/** * Return the number of components stored. * Formats with block size != 1x1 will always have 1 component (the block). */ diff --git a/mesalib/src/gallium/auxiliary/util/u_gen_mipmap.c b/mesalib/src/gallium/auxiliary/util/u_gen_mipmap.c index 2ff1af70a..a96cf6a30 100644 --- a/mesalib/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/mesalib/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -59,14 +59,17 @@ struct gen_mipmap_state struct pipe_context *pipe; struct cso_context *cso; - struct pipe_blend_state blend; - struct pipe_depth_stencil_alpha_state depthstencil; + struct pipe_blend_state blend_keep_color, blend_write_color; + struct pipe_depth_stencil_alpha_state dsa_keep_depth, dsa_write_depth; struct pipe_rasterizer_state rasterizer; struct pipe_sampler_state sampler; struct pipe_vertex_element velem[2]; void *vs; - void *fs[TGSI_TEXTURE_COUNT]; /**< Not all are used, but simplifies code */ + + /** Not all are used, but simplifies code */ + void *fs_color[TGSI_TEXTURE_COUNT]; + void *fs_depth[TGSI_TEXTURE_COUNT]; struct pipe_resource *vbuf; /**< quad vertices */ unsigned vbuf_slot; @@ -1272,11 +1275,16 @@ util_create_gen_mipmap(struct pipe_context *pipe, ctx->cso = cso; /* disabled blending/masking */ - memset(&ctx->blend, 0, sizeof(ctx->blend)); - ctx->blend.rt[0].colormask = PIPE_MASK_RGBA; + memset(&ctx->blend_keep_color, 0, sizeof(ctx->blend_keep_color)); + memset(&ctx->blend_write_color, 0, sizeof(ctx->blend_write_color)); + ctx->blend_write_color.rt[0].colormask = PIPE_MASK_RGBA; /* no-op depth/stencil/alpha */ - memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil)); + memset(&ctx->dsa_keep_depth, 0, sizeof(ctx->dsa_keep_depth)); + memset(&ctx->dsa_write_depth, 0, sizeof(ctx->dsa_write_depth)); + ctx->dsa_write_depth.depth.enabled = 1; + ctx->dsa_write_depth.depth.func = PIPE_FUNC_ALWAYS; + ctx->dsa_write_depth.depth.writemask = 1; /* rasterizer */ memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer)); @@ -1318,14 +1326,25 @@ util_create_gen_mipmap(struct pipe_context *pipe, * Helper function to set the fragment shaders. */ static INLINE void -set_fragment_shader(struct gen_mipmap_state *ctx, uint type) +set_fragment_shader(struct gen_mipmap_state *ctx, uint type, + boolean output_depth) { - if (!ctx->fs[type]) - ctx->fs[type] = - util_make_fragment_tex_shader(ctx->pipe, type, - TGSI_INTERPOLATE_LINEAR); + if (output_depth) { + if (!ctx->fs_depth[type]) + ctx->fs_depth[type] = + util_make_fragment_tex_shader_writedepth(ctx->pipe, type, + TGSI_INTERPOLATE_LINEAR); - cso_set_fragment_shader_handle(ctx->cso, ctx->fs[type]); + cso_set_fragment_shader_handle(ctx->cso, ctx->fs_depth[type]); + } + else { + if (!ctx->fs_color[type]) + ctx->fs_color[type] = + util_make_fragment_tex_shader(ctx->pipe, type, + TGSI_INTERPOLATE_LINEAR); + + cso_set_fragment_shader_handle(ctx->cso, ctx->fs_color[type]); + } } @@ -1464,9 +1483,13 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx) struct pipe_context *pipe = ctx->pipe; unsigned i; - for (i = 0; i < Elements(ctx->fs); i++) - if (ctx->fs[i]) - pipe->delete_fs_state(pipe, ctx->fs[i]); + for (i = 0; i < Elements(ctx->fs_color); i++) + if (ctx->fs_color[i]) + pipe->delete_fs_state(pipe, ctx->fs_color[i]); + + for (i = 0; i < Elements(ctx->fs_depth); i++) + if (ctx->fs_depth[i]) + pipe->delete_fs_state(pipe, ctx->fs_depth[i]); if (ctx->vs) pipe->delete_vs_state(pipe, ctx->vs); @@ -1500,6 +1523,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, uint dstLevel; uint offset; uint type; + boolean is_depth = util_format_is_depth_or_stencil(psv->format); /* The texture object should have room for the levels which we're * about to generate. @@ -1538,7 +1562,9 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, /* check if we can render in the texture's format */ if (!screen->is_format_supported(screen, psv->format, pt->target, - pt->nr_samples, PIPE_BIND_RENDER_TARGET)) { + pt->nr_samples, + is_depth ? PIPE_BIND_DEPTH_STENCIL : + PIPE_BIND_RENDER_TARGET)) { fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel); return; } @@ -1559,28 +1585,25 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, cso_save_vertex_buffers(ctx->cso); /* bind our state */ - cso_set_blend(ctx->cso, &ctx->blend); - cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil); + cso_set_blend(ctx->cso, is_depth ? &ctx->blend_keep_color : + &ctx->blend_write_color); + cso_set_depth_stencil_alpha(ctx->cso, is_depth ? &ctx->dsa_write_depth : + &ctx->dsa_keep_depth); cso_set_rasterizer(ctx->cso, &ctx->rasterizer); cso_set_vertex_elements(ctx->cso, 2, ctx->velem); cso_set_stream_outputs(ctx->cso, 0, NULL, 0); - set_fragment_shader(ctx, type); + set_fragment_shader(ctx, type, is_depth); set_vertex_shader(ctx); cso_set_geometry_shader_handle(ctx->cso, NULL); /* init framebuffer state */ memset(&fb, 0, sizeof(fb)); - fb.nr_cbufs = 1; /* set min/mag to same filter for faster sw speed */ ctx->sampler.mag_img_filter = filter; ctx->sampler.min_img_filter = filter; - /* - * XXX for small mipmap levels, it may be faster to use the software - * fallback path... - */ for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { const uint srcLevel = dstLevel - 1; struct pipe_viewport_state vp; @@ -1609,7 +1632,9 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, layer = face; memset(&surf_templ, 0, sizeof(surf_templ)); - u_surface_default_template(&surf_templ, pt, PIPE_BIND_RENDER_TARGET); + u_surface_default_template(&surf_templ, pt, + is_depth ? PIPE_BIND_DEPTH_STENCIL : + PIPE_BIND_RENDER_TARGET); surf_templ.u.tex.level = dstLevel; surf_templ.u.tex.first_layer = layer; surf_templ.u.tex.last_layer = layer; @@ -1618,7 +1643,14 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, /* * Setup framebuffer / dest surface */ - fb.cbufs[0] = surf; + if (is_depth) { + fb.nr_cbufs = 0; + fb.zsbuf = surf; + } + else { + fb.nr_cbufs = 1; + fb.cbufs[0] = surf; + } fb.width = u_minify(pt->width0, dstLevel); fb.height = u_minify(pt->height0, dstLevel); cso_set_framebuffer(ctx->cso, &fb); diff --git a/mesalib/src/gallium/auxiliary/util/u_inlines.h b/mesalib/src/gallium/auxiliary/util/u_inlines.h index 2ec153c58..2d603e4dd 100644 --- a/mesalib/src/gallium/auxiliary/util/u_inlines.h +++ b/mesalib/src/gallium/auxiliary/util/u_inlines.h @@ -30,6 +30,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" #include "pipe/p_state.h" #include "pipe/p_screen.h" #include "util/u_debug.h" @@ -545,6 +546,31 @@ util_query_clear_result(union pipe_query_result *result, unsigned type) } } +/** Convert PIPE_TEXTURE_x to TGSI_TEXTURE_x */ +static INLINE unsigned +util_pipe_tex_to_tgsi_tex(enum pipe_texture_target pipe_tex_target) +{ + switch (pipe_tex_target) { + case PIPE_TEXTURE_1D: + return TGSI_TEXTURE_1D; + case PIPE_TEXTURE_2D: + return TGSI_TEXTURE_2D; + case PIPE_TEXTURE_RECT: + return TGSI_TEXTURE_RECT; + case PIPE_TEXTURE_3D: + return TGSI_TEXTURE_3D; + case PIPE_TEXTURE_CUBE: + return TGSI_TEXTURE_CUBE; + case PIPE_TEXTURE_1D_ARRAY: + return TGSI_TEXTURE_1D_ARRAY; + case PIPE_TEXTURE_2D_ARRAY: + return TGSI_TEXTURE_2D_ARRAY; + default: + assert(0 && "unexpected texture target"); + return TGSI_TEXTURE_UNKNOWN; + } +} + #ifdef __cplusplus } #endif diff --git a/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c b/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c index 320c0f7a8..3476b6ce0 100644 --- a/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c +++ b/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c @@ -211,6 +211,106 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe, /** + * Make a simple fragment texture shader which reads the texture unit 0 and 1 + * and writes it as depth and stencil, respectively. + */ +void * +util_make_fragment_tex_shader_writedepthstencil(struct pipe_context *pipe, + unsigned tex_target, + unsigned interp_mode) +{ + struct ureg_program *ureg; + struct ureg_src depth_sampler, stencil_sampler; + struct ureg_src tex; + struct ureg_dst out, depth, stencil; + struct ureg_src imm; + + ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT ); + if (ureg == NULL) + return NULL; + + depth_sampler = ureg_DECL_sampler( ureg, 0 ); + stencil_sampler = ureg_DECL_sampler( ureg, 1 ); + + tex = ureg_DECL_fs_input( ureg, + TGSI_SEMANTIC_GENERIC, 0, + interp_mode ); + + out = ureg_DECL_output( ureg, + TGSI_SEMANTIC_COLOR, + 0 ); + + depth = ureg_DECL_output( ureg, + TGSI_SEMANTIC_POSITION, + 0 ); + + stencil = ureg_DECL_output( ureg, + TGSI_SEMANTIC_STENCIL, + 0 ); + + imm = ureg_imm4f( ureg, 0, 0, 0, 1 ); + + ureg_MOV( ureg, out, imm ); + + ureg_TEX( ureg, + ureg_writemask(depth, TGSI_WRITEMASK_Z), + tex_target, tex, depth_sampler ); + ureg_TEX( ureg, + ureg_writemask(stencil, TGSI_WRITEMASK_Y), + tex_target, tex, stencil_sampler ); + ureg_END( ureg ); + + return ureg_create_shader_and_destroy( ureg, pipe ); +} + + +/** + * Make a simple fragment texture shader which reads a texture and writes it + * as stencil. + */ +void * +util_make_fragment_tex_shader_writestencil(struct pipe_context *pipe, + unsigned tex_target, + unsigned interp_mode) +{ + struct ureg_program *ureg; + struct ureg_src stencil_sampler; + struct ureg_src tex; + struct ureg_dst out, stencil; + struct ureg_src imm; + + ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT ); + if (ureg == NULL) + return NULL; + + stencil_sampler = ureg_DECL_sampler( ureg, 0 ); + + tex = ureg_DECL_fs_input( ureg, + TGSI_SEMANTIC_GENERIC, 0, + interp_mode ); + + out = ureg_DECL_output( ureg, + TGSI_SEMANTIC_COLOR, + 0 ); + + stencil = ureg_DECL_output( ureg, + TGSI_SEMANTIC_STENCIL, + 0 ); + + imm = ureg_imm4f( ureg, 0, 0, 0, 1 ); + + ureg_MOV( ureg, out, imm ); + + ureg_TEX( ureg, + ureg_writemask(stencil, TGSI_WRITEMASK_Y), + tex_target, tex, stencil_sampler ); + ureg_END( ureg ); + + return ureg_create_shader_and_destroy( ureg, pipe ); +} + + +/** * Make simple fragment color pass-through shader. */ void * diff --git a/mesalib/src/gallium/auxiliary/util/u_simple_shaders.h b/mesalib/src/gallium/auxiliary/util/u_simple_shaders.h index 5f31b72c4..0764998a3 100644 --- a/mesalib/src/gallium/auxiliary/util/u_simple_shaders.h +++ b/mesalib/src/gallium/auxiliary/util/u_simple_shaders.h @@ -75,6 +75,18 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe, extern void * +util_make_fragment_tex_shader_writedepthstencil(struct pipe_context *pipe, + unsigned tex_target, + unsigned interp_mode); + + +extern void * +util_make_fragment_tex_shader_writestencil(struct pipe_context *pipe, + unsigned tex_target, + unsigned interp_mode); + + +extern void * util_make_fragment_passthrough_shader(struct pipe_context *pipe); |