[virglrenderer-devel] [PATCH 1/2] pad shaders with space for GL_ARB_gpu_shader5 it's needed

Erik Faye-Lund erik.faye-lund at collabora.com
Tue Jul 3 07:08:44 UTC 2018


The following patch will need enough padding to inject a line like
this into the start of the shader for vertex, geometry and
tesselation evaluation shaders:

So, let's add some appropriately sized space-padding that we can
search for and replace later.

Signed-off-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
---
 src/vrend_shader.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index 4d53203..608bed4 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -3815,10 +3815,15 @@ prolog(struct tgsi_iterate_context *iter)
       if ((mainstr) == NULL) return NULL;               \
    } while(0)
 
+/* reserve space for: "#extension GL_ARB_gpu_shader5 : require\n" */
+#define PAD_GPU_SHADER5(s) \
+   STRCAT_WITH_RET(s, "                                       \n")
+
 static char *emit_header(struct dump_ctx *ctx, char *glsl_hdr)
 {
    if (ctx->cfg->use_gles) {
       STRCAT_WITH_RET(glsl_hdr, "#version 300 es\n");
+      PAD_GPU_SHADER5(glsl_hdr);
       STRCAT_WITH_RET(glsl_hdr, "precision highp float;\n");
       STRCAT_WITH_RET(glsl_hdr, "precision highp int;\n");
    } else {
@@ -3826,15 +3831,21 @@ static char *emit_header(struct dump_ctx *ctx, char *glsl_hdr)
       if (ctx->prog_type == TGSI_PROCESSOR_COMPUTE) {
          STRCAT_WITH_RET(glsl_hdr, "#version 330\n");
          STRCAT_WITH_RET(glsl_hdr, "#extension GL_ARB_compute_shader : require\n");
-      } else if (ctx->prog_type == TGSI_PROCESSOR_GEOMETRY ||
-          ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL ||
-          ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL ||
-          ctx->glsl_ver_required == 150)
-         STRCAT_WITH_RET(glsl_hdr, "#version 150\n");
-      else if (ctx->glsl_ver_required == 140)
-         STRCAT_WITH_RET(glsl_hdr, "#version 140\n");
-      else
-         STRCAT_WITH_RET(glsl_hdr, "#version 130\n");
+      } else {
+         if (ctx->prog_type == TGSI_PROCESSOR_GEOMETRY ||
+             ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL ||
+             ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL ||
+             ctx->glsl_ver_required == 150)
+            STRCAT_WITH_RET(glsl_hdr, "#version 150\n");
+         else if (ctx->glsl_ver_required == 140)
+            STRCAT_WITH_RET(glsl_hdr, "#version 140\n");
+         else
+            STRCAT_WITH_RET(glsl_hdr, "#version 130\n");
+         if (ctx->prog_type == TGSI_PROCESSOR_VERTEX ||
+             ctx->prog_type == TGSI_PROCESSOR_GEOMETRY ||
+             ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL)
+            PAD_GPU_SHADER5(glsl_hdr);
+      }
 
       if (ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL ||
           ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL)
-- 
2.18.0.rc2



More information about the virglrenderer-devel mailing list