[virglrenderer-devel] [PATCH 2/4] vrend_shader: generate bindings with layout qualifiers

Dave Airlie airlied at gmail.com
Tue Aug 7 00:51:46 UTC 2018


On 7 August 2018 at 04:38, Erik Faye-Lund <erik.faye-lund at collabora.com> wrote:
> OpenGL ES 3.1 doesn't support using glUniform1i() for binding
> images, so let's use layout qualifiers instead. This should in
> theory be slightly more performant as well, as we do less API
> calls.

I like this idea, I think we can get rid of a bunch of stuff with
explicit bindings,

However I think explicit layout bindings on GL require a shader extension,

At least on desktop GL a lot of tests fail after I apply this.

Dave.

>
> Signed-off-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
> ---
>  src/vrend_renderer.c |  2 --
>  src/vrend_shader.c   | 82 ++++++++++++++++++++++----------------------
>  2 files changed, 41 insertions(+), 43 deletions(-)
>
> diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
> index ddf7f3a..12bf981 100644
> --- a/src/vrend_renderer.c
> +++ b/src/vrend_renderer.c
> @@ -3647,8 +3647,6 @@ static void vrend_draw_bind_images_shader(struct vrend_context *ctx, int shader_
>                        iview->texture->base.depth0 > 1) && (iview->u.tex.first_layer == iview->u.tex.last_layer));
>        }
>
> -      glUniform1i(ctx->sub->prog->img_locs[shader_type][i], i);
> -
>        switch (iview->access) {
>        case PIPE_IMAGE_ACCESS_READ:
>           access = GL_READ_ONLY;
> diff --git a/src/vrend_shader.c b/src/vrend_shader.c
> index 67c12a5..ee92795 100644
> --- a/src/vrend_shader.c
> +++ b/src/vrend_shader.c
> @@ -4106,121 +4106,121 @@ const char *get_internalformat_string(int virgl_format, enum tgsi_return_type *s
>     switch (virgl_format) {
>     case PIPE_FORMAT_R11G11B10_FLOAT:
>        *stype = TGSI_RETURN_TYPE_FLOAT;
> -      return "layout(r11f_g11f_b10f) ";
> +      return ", r11f_g11f_b10f";
>     case PIPE_FORMAT_R10G10B10A2_UNORM:
>        *stype = TGSI_RETURN_TYPE_UNORM;
> -      return "layout(rgb10_a2) ";
> +      return ", rgb10_a2";
>     case PIPE_FORMAT_R10G10B10A2_UINT:
>        *stype = TGSI_RETURN_TYPE_UINT;
> -      return "layout(rgb10_a2ui) ";
> +      return ", rgb10_a2ui";
>     case PIPE_FORMAT_R8_UNORM:
>        *stype = TGSI_RETURN_TYPE_UNORM;
> -      return "layout(r8) ";
> +      return ", r8";
>     case PIPE_FORMAT_R8_SNORM:
>        *stype = TGSI_RETURN_TYPE_SNORM;
> -      return "layout(r8_snorm) ";
> +      return ", r8_snorm";
>     case PIPE_FORMAT_R8_UINT:
>        *stype = TGSI_RETURN_TYPE_UINT;
> -      return "layout(r8ui) ";
> +      return ", r8ui";
>     case PIPE_FORMAT_R8_SINT:
>        *stype = TGSI_RETURN_TYPE_SINT;
> -      return "layout(r8i) ";
> +      return ", r8i";
>     case PIPE_FORMAT_R8G8_UNORM:
>        *stype = TGSI_RETURN_TYPE_UNORM;
> -      return "layout(rg8) ";
> +      return ", rg8";
>     case PIPE_FORMAT_R8G8_SNORM:
>        *stype = TGSI_RETURN_TYPE_SNORM;
> -      return "layout(rg8_snorm) ";
> +      return ", rg8_snorm";
>     case PIPE_FORMAT_R8G8_UINT:
>        *stype = TGSI_RETURN_TYPE_UINT;
> -      return "layout(rg8ui) ";
> +      return ", rg8ui";
>     case PIPE_FORMAT_R8G8_SINT:
>        *stype = TGSI_RETURN_TYPE_SINT;
> -      return "layout(rg8i) ";
> +      return ", rg8i";
>     case PIPE_FORMAT_R8G8B8A8_UNORM:
>        *stype = TGSI_RETURN_TYPE_UNORM;
> -      return "layout(rgba8) ";
> +      return ", rgba8";
>     case PIPE_FORMAT_R8G8B8A8_SNORM:
>        *stype = TGSI_RETURN_TYPE_SNORM;
> -      return "layout(rgba8_snorm) ";
> +      return ", rgba8_snorm";
>     case PIPE_FORMAT_R8G8B8A8_UINT:
>        *stype = TGSI_RETURN_TYPE_UINT;
> -      return "layout(rgba8ui) ";
> +      return ", rgba8ui";
>     case PIPE_FORMAT_R8G8B8A8_SINT:
>        *stype = TGSI_RETURN_TYPE_SINT;
> -      return "layout(rgba8i) ";
> +      return ", rgba8i";
>     case PIPE_FORMAT_R16_UNORM:
>        *stype = TGSI_RETURN_TYPE_UNORM;
> -      return "layout(r16) ";
> +      return ", r16";
>     case PIPE_FORMAT_R16_SNORM:
>        *stype = TGSI_RETURN_TYPE_SNORM;
> -      return "layout(r16_snorm) ";
> +      return ", r16_snorm";
>     case PIPE_FORMAT_R16_UINT:
>        *stype = TGSI_RETURN_TYPE_UINT;
> -      return "layout(r16ui) ";
> +      return ", r16ui";
>     case PIPE_FORMAT_R16_SINT:
>        *stype = TGSI_RETURN_TYPE_SINT;
> -      return "layout(r16i) ";
> +      return ", r16i";
>     case PIPE_FORMAT_R16_FLOAT:
>        *stype = TGSI_RETURN_TYPE_FLOAT;
> -      return "layout(r16f) ";
> +      return ", r16f";
>     case PIPE_FORMAT_R16G16_UNORM:
>        *stype = TGSI_RETURN_TYPE_UNORM;
> -      return "layout(rg16) ";
> +      return ", rg16";
>     case PIPE_FORMAT_R16G16_SNORM:
>        *stype = TGSI_RETURN_TYPE_SNORM;
> -      return "layout(rg16_snorm) ";
> +      return ", rg16_snorm";
>     case PIPE_FORMAT_R16G16_UINT:
>        *stype = TGSI_RETURN_TYPE_UINT;
> -      return "layout(rg16ui) ";
> +      return ", rg16ui";
>     case PIPE_FORMAT_R16G16_SINT:
>        *stype = TGSI_RETURN_TYPE_SINT;
> -      return "layout(rg16i) ";
> +      return ", rg16i";
>     case PIPE_FORMAT_R16G16_FLOAT:
>        *stype = TGSI_RETURN_TYPE_FLOAT;
> -      return "layout(rg16f) ";
> +      return ", rg16f";
>     case PIPE_FORMAT_R16G16B16A16_UNORM:
>        *stype = TGSI_RETURN_TYPE_UNORM;
> -      return "layout(rgba16) ";
> +      return ", rgba16";
>     case PIPE_FORMAT_R16G16B16A16_SNORM:
>        *stype = TGSI_RETURN_TYPE_SNORM;
> -      return "layout(rgba16_snorm) ";
> +      return ", rgba16_snorm";
>     case PIPE_FORMAT_R16G16B16A16_FLOAT:
>        *stype = TGSI_RETURN_TYPE_FLOAT;
> -      return "layout(rgba16f) ";
> +      return ", rgba16f";
>     case PIPE_FORMAT_R32_FLOAT:
>        *stype = TGSI_RETURN_TYPE_FLOAT;
> -      return "layout(r32f) ";
> +      return ", r32f";
>     case PIPE_FORMAT_R32_UINT:
>        *stype = TGSI_RETURN_TYPE_UINT;
> -      return "layout(r32ui) ";
> +      return ", r32ui";
>     case PIPE_FORMAT_R32_SINT:
>        *stype = TGSI_RETURN_TYPE_SINT;
> -      return "layout(r32i) ";
> +      return ", r32i";
>     case PIPE_FORMAT_R32G32_FLOAT:
>        *stype = TGSI_RETURN_TYPE_FLOAT;
> -      return "layout(rg32f) ";
> +      return ", rg32f";
>     case PIPE_FORMAT_R32G32_UINT:
>        *stype = TGSI_RETURN_TYPE_UINT;
> -      return "layout(rg32ui) ";
> +      return ", rg32ui";
>     case PIPE_FORMAT_R32G32_SINT:
>        *stype = TGSI_RETURN_TYPE_SINT;
> -      return "layout(rg32i) ";
> +      return ", rg32i";
>     case PIPE_FORMAT_R32G32B32A32_FLOAT:
>        *stype = TGSI_RETURN_TYPE_FLOAT;
> -      return "layout(rgba32f) ";
> +      return ", rgba32f";
>     case PIPE_FORMAT_R32G32B32A32_UINT:
>        *stype = TGSI_RETURN_TYPE_UINT;
> -      return "layout(rgba32ui) ";
> +      return ", rgba32ui";
>     case PIPE_FORMAT_R16G16B16A16_UINT:
>        *stype = TGSI_RETURN_TYPE_UINT;
> -      return "layout(rgba16ui) ";
> +      return ", rgba16ui";
>     case PIPE_FORMAT_R16G16B16A16_SINT:
>        *stype = TGSI_RETURN_TYPE_SINT;
> -      return "layout(rgba16i) ";
> +      return ", rgba16i";
>     case PIPE_FORMAT_R32G32B32A32_SINT:
>        *stype = TGSI_RETURN_TYPE_SINT;
> -      return "layout(rgba32i) ";
> +      return ", rgba32i";
>     case PIPE_FORMAT_NONE:
>        *stype = TGSI_RETURN_TYPE_UNORM;
>        return "";
> @@ -4685,7 +4685,7 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
>           ptc = vrend_shader_samplerreturnconv(itype);
>           sname = tgsi_proc_to_prefix(ctx->prog_type);
>           stc = vrend_shader_samplertypeconv(ctx->images[idx].decl.Resource, &is_shad);
> -         snprintf(buf, 255, "%s%s%suniform %cimage%s %simg%d[%d];\n", formatstr, writeonly, volatile_str, ptc, stc, sname, idx, ctx->image_arrays[i].array_size);
> +         snprintf(buf, 255, "layout(binding=%d%s) %s%suniform %cimage%s %simg%d[%d];\n", idx, formatstr, writeonly, volatile_str, ptc, stc, sname, idx, ctx->image_arrays[i].array_size);
>           STRCAT_WITH_RET(glsl_hdr, buf);
>        }
>     } else {
> @@ -4704,7 +4704,7 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
>           ptc = vrend_shader_samplerreturnconv(itype);
>           sname = tgsi_proc_to_prefix(ctx->prog_type);
>           stc = vrend_shader_samplertypeconv(ctx->images[i].decl.Resource, &is_shad);
> -         snprintf(buf, 255, "%s%s%suniform %cimage%s %simg%d;\n", formatstr, writeonly, volatile_str, ptc, stc, sname, i);
> +         snprintf(buf, 255, "layout(binding=%d%s) %s%suniform %cimage%s %simg%d;\n", i, formatstr, writeonly, volatile_str, ptc, stc, sname, i);
>           STRCAT_WITH_RET(glsl_hdr, buf);
>        }
>     }
> --
> 2.18.0
>
> _______________________________________________
> virglrenderer-devel mailing list
> virglrenderer-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/virglrenderer-devel


More information about the virglrenderer-devel mailing list