meta: Remove support for multisample blits

Since i965 no longer uses this function for blitting color buffers,
there is no driver left that will ever support multisample textures and
use _mesa_meta_BlitFramebuffer.

v2: Delete blit_state::msaa_shaders and enum blit_msaa_shader.

   text     data     bss      dec    hex  filename
12243286 1344936 1290748 14878970 e308fa  before/lib64/dri/i965_dri.so
12240398 1344936 1290748 14876082 e2fdb2  after/lib64/dri/i965_dri.so

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/856>
This commit is contained in:
Ian Romanick 2017-06-15 14:47:54 -07:00 committed by Marge Bot
parent bb28ce7988
commit adc6336273
2 changed files with 15 additions and 407 deletions

View File

@ -234,56 +234,6 @@ struct blit_shader_table {
struct blit_shader sampler_cubemap_array;
};
/**
* Indices in the blit_state->msaa_shaders[] array
*
* Note that setup_glsl_msaa_blit_shader() assumes that the _INT enums are five
* more than the corresponding non-_INT versions and _UINT are five beyond that.
*/
enum blit_msaa_shader {
BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY,
BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY_INT,
BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY_UINT,
BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_RESOLVE,
BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_COPY,
BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY,
BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY_INT,
BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY_UINT,
BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_DEPTH_RESOLVE,
BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_DEPTH_COPY,
BLIT_MSAA_SHADER_COUNT,
};
/**
* State for glBlitFramebufer()
*/
@ -293,7 +243,6 @@ struct blit_state
struct gl_buffer_object *buf_obj;
struct blit_shader_table shaders_with_depth;
struct blit_shader_table shaders_without_depth;
struct gl_shader_program *msaa_shaders[BLIT_MSAA_SHADER_COUNT];
struct temp_texture depthTex;
bool no_ctsi_fallback;
};

View File

@ -27,7 +27,6 @@
#include "main/arbprogram.h"
#include "main/arrayobj.h"
#include "main/blend.h"
#include "main/condrender.h"
#include "main/depth.h"
#include "main/enable.h"
#include "main/enums.h"
@ -35,8 +34,6 @@
#include "main/image.h"
#include "main/macros.h"
#include "main/matrix.h"
#include "main/multisample.h"
#include "main/objectlabel.h"
#include "main/readpix.h"
#include "main/scissor.h"
#include "main/shaderapi.h"
@ -49,7 +46,6 @@
#include "main/viewport.h"
#include "swrast/swrast.h"
#include "drivers/common/meta.h"
#include "util/ralloc.h"
static struct gl_texture_object *
texture_object_from_renderbuffer(struct gl_context *, struct gl_renderbuffer *);
@ -61,345 +57,26 @@ setup_sampler(struct gl_context *, struct gl_texture_object *, GLenum target,
/** Return offset in bytes of the field within a vertex struct */
#define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD))
static void
setup_glsl_msaa_blit_shader(struct gl_context *ctx,
struct blit_state *blit,
const struct gl_framebuffer *drawFb,
struct gl_renderbuffer *src_rb,
GLenum target)
{
const char *vs_source;
char *fs_source;
void *mem_ctx;
enum blit_msaa_shader shader_index;
bool dst_is_msaa = false;
GLenum src_datatype;
const char *vec4_prefix;
const char *sampler_array_suffix = "";
char *name;
const char *texcoord_type = "vec2";
int samples;
int shader_offset = 0;
if (src_rb) {
samples = MAX2(src_rb->NumSamples, 1);
src_datatype = _mesa_get_format_datatype(src_rb->Format);
} else {
/* depth-or-color glCopyTexImage fallback path that passes a NULL rb and
* doesn't handle integer.
*/
samples = 1;
src_datatype = GL_UNSIGNED_NORMALIZED;
}
/* We expect only power of 2 samples in source multisample buffer. */
assert(samples > 0 && util_is_power_of_two_nonzero(samples));
while (samples >> (shader_offset + 1)) {
shader_offset++;
}
/* Update the assert if we plan to support more than 16X MSAA. */
assert(shader_offset >= 0 && shader_offset <= 4);
if (drawFb->Visual.samples > 1) {
/* If you're calling meta_BlitFramebuffer with the destination
* multisampled, this is the only path that will work -- swrast and
* CopyTexImage won't work on it either.
*/
assert(ctx->Extensions.ARB_sample_shading);
dst_is_msaa = true;
/* We need shader invocation per sample, not per pixel */
_mesa_set_enable(ctx, GL_MULTISAMPLE, GL_TRUE);
_mesa_set_enable(ctx, GL_SAMPLE_SHADING, GL_TRUE);
_mesa_MinSampleShading(1.0);
}
switch (target) {
case GL_TEXTURE_2D_MULTISAMPLE:
case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
if (src_rb && (src_rb->_BaseFormat == GL_DEPTH_COMPONENT ||
src_rb->_BaseFormat == GL_DEPTH_STENCIL)) {
if (dst_is_msaa)
shader_index = BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_COPY;
else
shader_index = BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_RESOLVE;
} else {
if (dst_is_msaa)
shader_index = BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY;
else {
shader_index = BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE +
shader_offset;
}
}
if (target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
shader_index += (BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE -
BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE);
sampler_array_suffix = "Array";
texcoord_type = "vec3";
}
break;
default:
_mesa_problem(ctx, "Unknown texture target %s\n",
_mesa_enum_to_string(target));
shader_index = BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE;
}
/* We rely on the enum being sorted this way. */
STATIC_ASSERT(BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT ==
BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE + 5);
STATIC_ASSERT(BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT ==
BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE + 10);
if (src_datatype == GL_INT) {
shader_index += 5;
vec4_prefix = "i";
} else if (src_datatype == GL_UNSIGNED_INT) {
shader_index += 10;
vec4_prefix = "u";
} else {
vec4_prefix = "";
}
if (blit->msaa_shaders[shader_index]) {
_mesa_meta_use_program(ctx, blit->msaa_shaders[shader_index]);
return;
}
mem_ctx = ralloc_context(NULL);
if (shader_index == BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_RESOLVE ||
shader_index == BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_DEPTH_RESOLVE ||
shader_index == BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_DEPTH_COPY ||
shader_index == BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_COPY) {
char *sample_index;
const char *tex_coords = "texCoords";
if (dst_is_msaa) {
sample_index = "gl_SampleID";
name = "depth MSAA copy";
if (ctx->Extensions.ARB_gpu_shader5 && samples >= 16) {
/* See comment below for the color copy */
tex_coords = "interpolateAtOffset(texCoords, vec2(0.0))";
}
} else {
/* From the GL 4.3 spec:
*
* "If there is a multisample buffer (the value of SAMPLE_BUFFERS
* is one), then values are obtained from the depth samples in
* this buffer. It is recommended that the depth value of the
* centermost sample be used, though implementations may choose
* any function of the depth sample values at each pixel.
*
* We're slacking and instead of choosing centermost, we've got 0.
*/
sample_index = "0";
name = "depth MSAA resolve";
}
vs_source = ralloc_asprintf(mem_ctx,
"#version 130\n"
"#extension GL_ARB_explicit_attrib_location: enable\n"
"layout(location = 0) in vec2 position;\n"
"layout(location = 1) in %s textureCoords;\n"
"out %s texCoords;\n"
"void main()\n"
"{\n"
" texCoords = textureCoords;\n"
" gl_Position = vec4(position, 0.0, 1.0);\n"
"}\n",
texcoord_type,
texcoord_type);
fs_source = ralloc_asprintf(mem_ctx,
"#version 130\n"
"#extension GL_ARB_texture_multisample : enable\n"
"#extension GL_ARB_sample_shading : enable\n"
"#extension GL_ARB_gpu_shader5 : enable\n"
"uniform sampler2DMS%s texSampler;\n"
"in %s texCoords;\n"
"out vec4 out_color;\n"
"\n"
"void main()\n"
"{\n"
" gl_FragDepth = texelFetch(texSampler, i%s(%s), %s).r;\n"
"}\n",
sampler_array_suffix,
texcoord_type,
texcoord_type,
tex_coords,
sample_index);
} else {
/* You can create 2D_MULTISAMPLE textures with 0 sample count (meaning 1
* sample). Yes, this is ridiculous.
*/
char *sample_resolve;
const char *merge_function;
name = ralloc_asprintf(mem_ctx, "%svec4 MSAA %s",
vec4_prefix,
dst_is_msaa ? "copy" : "resolve");
if (dst_is_msaa) {
const char *tex_coords;
if (ctx->Extensions.ARB_gpu_shader5 && samples >= 16) {
/* If interpolateAtOffset is available then it will be used to
* force the interpolation to the center. This is required at
* least on Intel hardware because it is possible to have a sample
* position on the 0 x or y axis which means it will lie exactly
* on the pixel boundary. If we let the hardware interpolate the
* coordinates at one of these positions then it is possible for
* it to jump to a neighboring texel when converting to ints due
* to rounding errors. This is only done for >= 16x MSAA because
* it probably has some overhead. It is more likely that some
* hardware will use one of these problematic positions at 16x
* MSAA because in that case in D3D they are defined to be at
* these positions.
*/
tex_coords = "interpolateAtOffset(texCoords, vec2(0.0))";
} else {
tex_coords = "texCoords";
}
sample_resolve =
ralloc_asprintf(mem_ctx,
" out_color = texelFetch(texSampler, "
"i%s(%s), gl_SampleID);",
texcoord_type, tex_coords);
merge_function = "";
} else {
int i;
int step;
if (src_datatype == GL_INT || src_datatype == GL_UNSIGNED_INT) {
/* From the OpenGL ES 3.2 spec section 16.2.1:
*
* "If the source formats are integer types or stencil values,
* a single sample's value is selected for each pixel."
*
* The OpenGL 4.4 spec contains exactly the same language.
*
* We can accomplish this by making the merge function return just
* one of the two samples. The compiler should do the rest.
*/
merge_function = "gvec4 merge(gvec4 a, gvec4 b) { return a; }\n";
} else {
/* The divide will happen at the end for floats. */
merge_function =
"vec4 merge(vec4 a, vec4 b) { return (a + b); }\n";
}
/* We're assuming power of two samples for this resolution procedure.
*
* To avoid losing any floating point precision if the samples all
* happen to have the same value, we merge pairs of values at a time
* (so the floating point exponent just gets increased), rather than
* doing a naive sum and dividing.
*/
assert(util_is_power_of_two_or_zero(samples));
/* Fetch each individual sample. */
sample_resolve = rzalloc_size(mem_ctx, 1);
for (i = 0; i < samples; i++) {
ralloc_asprintf_append(&sample_resolve,
" gvec4 sample_1_%d = texelFetch(texSampler, i%s(texCoords), %d);\n",
i, texcoord_type, i);
}
/* Now, merge each pair of samples, then merge each pair of those,
* etc.
*/
for (step = 2; step <= samples; step *= 2) {
for (i = 0; i < samples; i += step) {
ralloc_asprintf_append(&sample_resolve,
" gvec4 sample_%d_%d = merge(sample_%d_%d, sample_%d_%d);\n",
step, i,
step / 2, i,
step / 2, i + step / 2);
}
}
/* Scale the final result. */
if (src_datatype == GL_UNSIGNED_INT || src_datatype == GL_INT) {
ralloc_asprintf_append(&sample_resolve,
" out_color = sample_%d_0;\n",
samples);
} else {
ralloc_asprintf_append(&sample_resolve,
" gl_FragColor = sample_%d_0 / %f;\n",
samples, (float)samples);
}
}
vs_source = ralloc_asprintf(mem_ctx,
"#version 130\n"
"#extension GL_ARB_explicit_attrib_location: enable\n"
"layout(location = 0) in vec2 position;\n"
"layout(location = 1) in %s textureCoords;\n"
"out %s texCoords;\n"
"void main()\n"
"{\n"
" texCoords = textureCoords;\n"
" gl_Position = vec4(position, 0.0, 1.0);\n"
"}\n",
texcoord_type,
texcoord_type);
fs_source = ralloc_asprintf(mem_ctx,
"#version 130\n"
"#extension GL_ARB_texture_multisample : enable\n"
"#extension GL_ARB_sample_shading : enable\n"
"#extension GL_ARB_gpu_shader5 : enable\n"
"#define gvec4 %svec4\n"
"uniform %ssampler2DMS%s texSampler;\n"
"in %s texCoords;\n"
"out gvec4 out_color;\n"
"\n"
"%s" /* merge_function */
"void main()\n"
"{\n"
"%s\n" /* sample_resolve */
"}\n",
vec4_prefix,
vec4_prefix,
sampler_array_suffix,
texcoord_type,
merge_function,
sample_resolve);
}
_mesa_meta_compile_and_link_program(ctx, vs_source, fs_source, name,
&blit->msaa_shaders[shader_index]);
ralloc_free(mem_ctx);
}
static void
setup_glsl_blit_framebuffer(struct gl_context *ctx,
struct blit_state *blit,
const struct gl_framebuffer *drawFb,
struct gl_renderbuffer *src_rb,
GLenum target, GLenum filter,
bool is_scaled_blit,
GLenum target,
bool do_depth)
{
unsigned texcoord_size;
bool is_target_multisample = target == GL_TEXTURE_2D_MULTISAMPLE ||
target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
const unsigned texcoord_size = 2 + (src_rb->Depth > 1 ? 1 : 0);
/* target = GL_TEXTURE_RECTANGLE is not supported in GLES 3.0 */
assert(_mesa_is_desktop_gl(ctx) || target == GL_TEXTURE_2D);
texcoord_size = 2 + (src_rb->Depth > 1 ? 1 : 0);
_mesa_meta_setup_vertex_objects(ctx, &blit->VAO, &blit->buf_obj, true,
2, texcoord_size, 0);
if (is_target_multisample) {
setup_glsl_msaa_blit_shader(ctx, blit, drawFb, src_rb, target);
} else {
_mesa_meta_setup_blit_shader(ctx, target, do_depth,
do_depth ? &blit->shaders_with_depth
: &blit->shaders_without_depth);
}
_mesa_meta_setup_blit_shader(ctx, target, do_depth,
do_depth ? &blit->shaders_with_depth
: &blit->shaders_without_depth);
}
/**
@ -428,23 +105,19 @@ blitframebuffer_texture(struct gl_context *ctx,
const GLint dstH = abs(dstY1 - dstY0);
const int srcW = abs(srcX1 - srcX0);
const int srcH = abs(srcY1 - srcY0);
bool scaled_blit = false;
struct gl_texture_object *texObj;
GLuint srcLevel;
GLenum target;
struct gl_renderbuffer *rb = readAtt->Renderbuffer;
struct temp_texture *meta_temp_texture;
if (rb->NumSamples && !ctx->Extensions.ARB_texture_multisample)
return false;
assert(rb->NumSamples == 0);
_mesa_meta_fb_tex_blit_begin(ctx, &fb_tex_blit);
if (readAtt->Texture &&
(readAtt->Texture->Target == GL_TEXTURE_2D ||
readAtt->Texture->Target == GL_TEXTURE_RECTANGLE ||
readAtt->Texture->Target == GL_TEXTURE_2D_MULTISAMPLE ||
readAtt->Texture->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)) {
readAtt->Texture->Target == GL_TEXTURE_RECTANGLE)) {
/* If there's a texture attached of a type we can handle, then just use
* it directly.
*/
@ -472,9 +145,6 @@ blitframebuffer_texture(struct gl_context *ctx,
if (ctx->Meta->Blit.no_ctsi_fallback)
return false;
if (rb->NumSamples > 1)
return false;
if (do_depth) {
meta_temp_texture = _mesa_meta_get_temp_depth_texture(ctx);
tex_base_format = GL_DEPTH_COMPONENT;
@ -510,11 +180,8 @@ blitframebuffer_texture(struct gl_context *ctx,
fb_tex_blit.maxLevelSave = texObj->MaxLevel;
fb_tex_blit.stencilSamplingSave = texObj->StencilSampling;
scaled_blit = dstW != srcW || dstH != srcH;
if (glsl_version) {
setup_glsl_blit_framebuffer(ctx, blit, drawFb, rb, target, filter, scaled_blit,
do_depth);
setup_glsl_blit_framebuffer(ctx, blit, drawFb, rb, target, do_depth);
}
else {
_mesa_meta_setup_ff_tnl_for_blit(ctx,
@ -577,9 +244,7 @@ blitframebuffer_texture(struct gl_context *ctx,
t1 = srcY1 / (float) texImage->Height;
}
else {
assert(target == GL_TEXTURE_RECTANGLE_ARB ||
target == GL_TEXTURE_2D_MULTISAMPLE ||
target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY);
assert(target == GL_TEXTURE_RECTANGLE_ARB);
s0 = (float) srcX0;
s1 = (float) srcX1;
t0 = (float) srcY0;
@ -697,8 +362,7 @@ texture_object_from_renderbuffer(struct gl_context *ctx,
{
struct gl_texture_image *texImage;
struct gl_texture_object *texObj;
const GLenum target = rb->NumSamples > 1
? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D;
const GLenum target = GL_TEXTURE_2D;
texObj = ctx->Driver.NewTextureObject(ctx, 0xDEADBEEF, target);
texImage = _mesa_get_tex_image(ctx, texObj, target, 0);
@ -720,17 +384,14 @@ static struct gl_sampler_object *
setup_sampler(struct gl_context *ctx, struct gl_texture_object *texObj,
GLenum target, GLenum filter, GLuint srcLevel)
{
struct gl_sampler_object *samp_obj;
GLenum tex_filter = (filter == GL_SCALED_RESOLVE_FASTEST_EXT ||
filter == GL_SCALED_RESOLVE_NICEST_EXT) ?
GL_NEAREST : filter;
struct gl_sampler_object *samp_obj =
ctx->Driver.NewSamplerObject(ctx, 0xDEADBEEF);
samp_obj = ctx->Driver.NewSamplerObject(ctx, 0xDEADBEEF);
if (samp_obj == NULL)
return NULL;
_mesa_bind_sampler(ctx, ctx->Texture.CurrentUnit, samp_obj);
_mesa_set_sampler_filters(ctx, samp_obj, tex_filter, tex_filter);
_mesa_set_sampler_filters(ctx, samp_obj, filter, filter);
_mesa_set_sampler_wrap(ctx, samp_obj, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
samp_obj->WrapR);
@ -774,11 +435,9 @@ _mesa_meta_BlitFramebuffer(struct gl_context *ctx,
const GLboolean use_glsl_version = ctx->Extensions.ARB_vertex_shader &&
ctx->Extensions.ARB_fragment_shader;
/* Multisample texture blit support requires texture multisample. */
if (readFb->Visual.samples > 0 &&
!ctx->Extensions.ARB_texture_multisample) {
/* Multisample blit is not supported. */
if (readFb->Visual.samples > 0)
return mask;
}
/* Clip a copy of the blit coordinates. If these differ from the input
* coordinates, then we'll set the scissor.