[Mesa-stable] [PATCH] meta: Handle array textures in scaled MSAA blits
Anuj Phogat
anuj.phogat at gmail.com
Wed Sep 23 10:55:00 PDT 2015
On Tue, Sep 22, 2015 at 3:00 PM, Ian Romanick <idr at freedesktop.org> wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> The old code had some significant problems with respect to
> sampler2DArray textures. The biggest problem was that some of the code
> would use vec3 for the texture coordinate type, and other parts of the
> code would use vec2. The resulting shader would not even compile.
> Since there were not tests for this path, nobody noticed.
>
> The input to the fragment shader is always treated as a vec3. If the
> source data is only vec2, the vertex puller will supply 0 for the .z
> component. The texture coordinate passed to the fragment shader is
> always a vec2 that comes from the .xy part of the vertex shader input.
> The layer, taken from the .z of the vertex shader input is passed
> separately as a flat integer. If the generated fragment shader does not
> use the layer integer, the GLSL linker will eliminate all the dead code
> in the vertex shader.
>
> Fixes the new piglit tests "blit-scaled samples=2 with
> gl_texture_2d_multisample_array", etc. on i965.
>
> Note for stable maintainer: This patch may depend on 46037237, and that
> patch should be safe for stable.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> Cc: Anuj Phogat <anuj.phogat at gmail.com>
> Cc: Topi Pohjolainen <topi.pohjolainen at intel.com>
> Cc: Jordan Justen <jordan.l.justen at intel.com>
> Cc: "10.6 11.0" <mesa-stable at lists.freedesktop.org>
> ---
> This is currently running through our Jenkins server. There were no
> regressions on my BDW system.
>
> src/mesa/drivers/common/meta_blit.c | 35 ++++++++++++++++++++---------------
> 1 file changed, 20 insertions(+), 15 deletions(-)
>
> diff --git a/src/mesa/drivers/common/meta_blit.c b/src/mesa/drivers/common/meta_blit.c
> index a41fe42..5972a5a 100644
> --- a/src/mesa/drivers/common/meta_blit.c
> +++ b/src/mesa/drivers/common/meta_blit.c
> @@ -71,9 +71,7 @@ setup_glsl_msaa_blit_scaled_shader(struct gl_context *ctx,
> char *sample_map_str = rzalloc_size(mem_ctx, 1);
> char *sample_map_expr = rzalloc_size(mem_ctx, 1);
> char *texel_fetch_macro = rzalloc_size(mem_ctx, 1);
> - const char *vs_source;
> const char *sampler_array_suffix = "";
> - const char *texcoord_type = "vec2";
> float y_scale;
> enum blit_msaa_shader shader_index;
>
> @@ -99,7 +97,6 @@ setup_glsl_msaa_blit_scaled_shader(struct gl_context *ctx,
> shader_index += BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_SCALED_RESOLVE -
> BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_SCALED_RESOLVE;
> sampler_array_suffix = "Array";
> - texcoord_type = "vec3";
> }
>
> if (blit->msaa_shaders[shader_index]) {
> @@ -150,28 +147,37 @@ setup_glsl_msaa_blit_scaled_shader(struct gl_context *ctx,
> " const int sample_map[%d] = int[%d](%s);\n",
> samples, samples, sample_map_str);
>
> - ralloc_asprintf_append(&texel_fetch_macro,
> - "#define TEXEL_FETCH(coord) texelFetch(texSampler, i%s(coord), %s);\n",
> - texcoord_type, sample_number);
> + if (target == GL_TEXTURE_2D_MULTISAMPLE) {
> + ralloc_asprintf_append(&texel_fetch_macro,
> + "#define TEXEL_FETCH(coord) texelFetch(texSampler, ivec2(coord), %s);\n",
> + sample_number);
> + } else {
> + ralloc_asprintf_append(&texel_fetch_macro,
> + "#define TEXEL_FETCH(coord) texelFetch(texSampler, ivec3(coord, layer), %s);\n",
> + sample_number);
> + }
>
> - vs_source = ralloc_asprintf(mem_ctx,
> + static const char vs_source[] =
> "#version 130\n"
> "in vec2 position;\n"
> - "in %s textureCoords;\n"
> - "out %s texCoords;\n"
> + "in vec3 textureCoords;\n"
> + "out vec2 texCoords;\n"
> + "flat out int layer;\n"
> "void main()\n"
> "{\n"
> - " texCoords = textureCoords;\n"
> + " texCoords = textureCoords.xy;\n"
> + " layer = int(textureCoords.z);\n"
> " gl_Position = vec4(position, 0.0, 1.0);\n"
> - "}\n",
> - texcoord_type,
> - texcoord_type);
> + "}\n"
> + ;
> +
> fs_source = ralloc_asprintf(mem_ctx,
> "#version 130\n"
> "#extension GL_ARB_texture_multisample : enable\n"
> "uniform sampler2DMS%s texSampler;\n"
> "uniform float src_width, src_height;\n"
> - "in %s texCoords;\n"
> + "in vec2 texCoords;\n"
> + "flat in int layer;\n"
> "out vec4 out_color;\n"
> "\n"
> "void main()\n"
> @@ -212,7 +218,6 @@ setup_glsl_msaa_blit_scaled_shader(struct gl_context *ctx,
> " out_color = mix(x_0_color, x_1_color, interp.y);\n"
> "}\n",
> sampler_array_suffix,
> - texcoord_type,
> sample_map_expr,
> y_scale,
> 1.0f / y_scale,
> --
> 2.1.0
>
Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>
More information about the mesa-stable
mailing list