st/mesa: use fragment shader to copy stencil buffer

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5836>
This commit is contained in:
Indrajit Kumar Das
2020-07-10 11:45:22 +05:30
committed by Marge Bot
parent 3af0711c40
commit f611af3594

View File

@@ -1704,6 +1704,8 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
GLboolean invertTex = GL_FALSE;
GLint readX, readY, readW, readH;
struct gl_pixelstore_attrib pack = ctx->DefaultPacking;
GLboolean write_stencil = GL_FALSE;
GLboolean write_depth = GL_FALSE;
_mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
@@ -1722,12 +1724,6 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
return;
}
if (type == GL_STENCIL) {
/* can't use texturing to do stencil */
copy_stencil_pixels(ctx, srcx, srcy, width, height, dstx, dsty);
return;
}
/*
* The subsequent code implements glCopyPixels by copying the source
* pixels into a temporary texture that's then applied to a textured quad.
@@ -1757,13 +1753,15 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
* into the constant buffer, we need to update them
*/
st_upload_constants(st, &st->fp->Base);
}
else {
assert(type == GL_DEPTH);
} else if (type == GL_DEPTH) {
rbRead = st_renderbuffer(ctx->ReadBuffer->
Attachment[BUFFER_DEPTH].Renderbuffer);
driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_FALSE);
} else {
assert(type == GL_STENCIL);
rbRead = st_renderbuffer(ctx->ReadBuffer->
Attachment[BUFFER_STENCIL].Renderbuffer);
driver_fp = get_drawpix_z_stencil_program(st, GL_FALSE, GL_TRUE);
}
/* Choose the format for the temporary texture. */
@@ -1779,6 +1777,11 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
GL_NONE, st->internal_target, 0, 0,
srcBind, false, false);
}
else if (type == GL_STENCIL) {
/* can't use texturing, fallback to copy */
copy_stencil_pixels(ctx, srcx, srcy, width, height, dstx, dsty);
return;
}
else {
assert(type == GL_COLOR);
@@ -1854,6 +1857,23 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
return;
}
/* Create a second sampler view to read stencil */
if (type == GL_STENCIL) {
write_stencil = GL_TRUE;
enum pipe_format stencil_format =
util_format_stencil_only(pt->format);
/* we should not be doing pixel map/transfer (see above) */
assert(num_sampler_view == 1);
sv[1] = st_create_texture_sampler_view_format(st->pipe, pt,
stencil_format);
if (!sv[1]) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
pipe_resource_reference(&pt, NULL);
pipe_sampler_view_reference(&sv[0], NULL);
return;
}
num_sampler_view++;
}
/* Copy the src region to the temporary texture. */
{
struct pipe_blit_info blit;
@@ -1877,7 +1897,10 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
blit.dst.box.width = readW;
blit.dst.box.height = readH;
blit.dst.box.depth = 1;
blit.mask = util_format_get_mask(pt->format) & ~PIPE_MASK_S;
if (type != GL_STENCIL)
blit.mask = util_format_get_mask(pt->format) & ~PIPE_MASK_S;
else
blit.mask = util_format_get_mask(pt->format) & ~PIPE_MASK_Z;
blit.filter = PIPE_TEX_FILTER_NEAREST;
pipe->blit(pipe, &blit);
@@ -1894,7 +1917,7 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
st->passthrough_vs,
driver_fp, fpv,
ctx->Current.Attrib[VERT_ATTRIB_COLOR0],
invertTex, GL_FALSE, GL_FALSE);
invertTex, write_depth, write_stencil);
pipe_resource_reference(&pt, NULL);
pipe_sampler_view_reference(&sv[0], NULL);