[virglrenderer-devel] [PATCH 3/3] vrend: Use OpenGL ES 3.0 shaders in blitter

Jakob Bornecrantz jakob at collabora.com
Fri Feb 23 17:32:44 UTC 2018


Signed-off-by: Jakob Bornecrantz <jakob at collabora.com>
---
 src/vrend_blitter.c | 17 ++++++++++-----
 src/vrend_blitter.h | 59 +++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/src/vrend_blitter.c b/src/vrend_blitter.c
index bac82d3..908a82d 100644
--- a/src/vrend_blitter.c
+++ b/src/vrend_blitter.c
@@ -52,6 +52,7 @@
 struct vrend_blitter_ctx {
    virgl_gl_context gl_context;
    bool initialised;
+   bool use_gles;
 
    GLuint vaoid;
 
@@ -94,7 +95,8 @@ static bool blit_build_vs_passthrough(struct vrend_blitter_ctx *blit_ctx)
 {
    blit_ctx->vs = glCreateShader(GL_VERTEX_SHADER);
 
-   if (!build_and_check(blit_ctx->vs, VS_PASSTHROUGH)) {
+   if (!build_and_check(blit_ctx->vs,
+        blit_ctx->use_gles ? VS_PASSTHROUGH_GLES : VS_PASSTHROUGH_GL)) {
       glDeleteShader(blit_ctx->vs);
       blit_ctx->vs = 0;
       return false;
@@ -143,7 +145,8 @@ static GLuint blit_build_frag_tex_col(struct vrend_blitter_ctx *blit_ctx, int tg
        tgsi_tex_target == TGSI_TEXTURE_SHADOWCUBE_ARRAY)
       ext_str = "#extension GL_ARB_texture_cube_map_array : require\n";
 
-   snprintf(shader_buf, 4096, FS_TEXFETCH_COL, ext_str, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), twm, "");
+   snprintf(shader_buf, 4096, blit_ctx->use_gles ? FS_TEXFETCH_COL_GLES : FS_TEXFETCH_COL_GL,
+      ext_str, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), twm, "");
 
    fs_id = glCreateShader(GL_FRAGMENT_SHADER);
 
@@ -196,7 +199,8 @@ static GLuint blit_build_frag_tex_col_emu_alpha(struct vrend_blitter_ctx *blit_c
        tgsi_tex_target == TGSI_TEXTURE_SHADOWCUBE_ARRAY)
       ext_str = "#extension GL_ARB_texture_cube_map_array : require\n";
 
-   snprintf(shader_buf, 4096, FS_TEXFETCH_COL_ALPHA_DEST, ext_str, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), twm, "");
+   snprintf(shader_buf, 4096, blit_ctx->use_gles ? FS_TEXFETCH_COL_ALPHA_DEST_GLES : FS_TEXFETCH_COL_ALPHA_DEST_GL,
+      ext_str, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), twm, "");
 
    fs_id = glCreateShader(GL_FRAGMENT_SHADER);
 
@@ -245,7 +249,8 @@ static GLuint blit_build_frag_tex_writedepth(struct vrend_blitter_ctx *blit_ctx,
       break;
    }
 
-   snprintf(shader_buf, 4096, FS_TEXFETCH_DS, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), twm);
+   snprintf(shader_buf, 4096, blit_ctx->use_gles ? FS_TEXFETCH_DS_GLES : FS_TEXFETCH_DS_GL,
+      vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), twm);
 
    fs_id = glCreateShader(GL_FRAGMENT_SHADER);
 
@@ -278,7 +283,8 @@ static GLuint blit_build_frag_blit_msaa_depth(struct vrend_blitter_ctx *blit_ctx
       return 0;
    }
 
-   snprintf(shader_buf, 4096, FS_TEXFETCH_DS_MSAA, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), ivec, twm);
+   snprintf(shader_buf, 4096, blit_ctx->use_gles ? FS_TEXFETCH_DS_MSAA_GLES : FS_TEXFETCH_DS_MSAA_GL,
+      vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), ivec, twm);
 
    fs_id = glCreateShader(GL_FRAGMENT_SHADER);
 
@@ -362,6 +368,7 @@ static void vrend_renderer_init_blit_ctx(struct vrend_blitter_ctx *blit_ctx)
    }
 
    blit_ctx->initialised = true;
+   blit_ctx->use_gles = epoxy_is_desktop_gl() == 0;
    ctx_params.shared = true;
    for (uint32_t i = 0; i < ARRAY_SIZE(gl_versions); i++) {
       ctx_params.major_ver = gl_versions[i].major;
diff --git a/src/vrend_blitter.h b/src/vrend_blitter.h
index ad1f196..07573a7 100644
--- a/src/vrend_blitter.h
+++ b/src/vrend_blitter.h
@@ -26,8 +26,21 @@
 
 /* shaders for blitting */
 
-#define VS_PASSTHROUGH                          \
+#define HEADER_GL                               \
+   "// Blitter\n"                               \
    "#version 130\n"                             \
+
+#define HEADER_GLES                             \
+   "// Blitter\n"                               \
+   "#version 300 es\n"                          \
+   "precision mediump float;\n"                 \
+
+#define OUTFRAG_GLES                            \
+   "out vec4 FragColor;\n"                      \
+   "#define gl_FragColor FragColor\n"
+
+
+#define VS_PASSTHROUGH_BODY                     \
    "in vec4 arg0;\n"                            \
    "in vec4 arg1;\n"                            \
    "out vec4 tc;\n"                             \
@@ -36,8 +49,11 @@
    "   tc = arg1;\n"                            \
    "}\n"
 
-#define FS_TEXFETCH_COL                         \
-   "#version 130\n"                             \
+#define VS_PASSTHROUGH_GL HEADER_GL VS_PASSTHROUGH_BODY
+#define VS_PASSTHROUGH_GLES HEADER_GLES VS_PASSTHROUGH_BODY
+
+
+#define FS_TEXFETCH_COL_BODY                    \
    "%s"                                         \
    "uniform sampler%s samp;\n"                  \
    "in vec4 tc;\n"                              \
@@ -45,31 +61,44 @@
    "   gl_FragColor = texture(samp, tc%s)%s;\n" \
    "}\n"
 
-#define FS_TEXFETCH_COL_ALPHA_DEST              \
-   "#version 130\n"                             \
+#define FS_TEXFETCH_COL_GL HEADER_GL FS_TEXFETCH_COL_BODY
+#define FS_TEXFETCH_COL_GLES HEADER_GLES OUTFRAG_GLES FS_TEXFETCH_COL_BODY
+
+
+#define FS_TEXFETCH_COL_ALPHA_DEST_BODY         \
    "%s"                                         \
    "uniform sampler%s samp;\n"                  \
    "in vec4 tc;\n"                              \
    "void main() {\n"                            \
-   "   vec4 temp = texture(samp, tc%s)%s;\n"     \
-   "   gl_FragColor = temp.aaaa;\n" \
+   "   vec4 temp = texture(samp, tc%s)%s;\n"    \
+   "   gl_FragColor = temp.aaaa;\n"             \
    "}\n"
 
-#define FS_TEXFETCH_DS                                  \
-   "#version 130\n"                                     \
+#define FS_TEXFETCH_COL_ALPHA_DEST_GL HEADER_GL FS_TEXFETCH_COL_ALPHA_DEST_BODY
+#define FS_TEXFETCH_COL_ALPHA_DEST_GLES HEADER_GLES OUTFRAG_GLES FS_TEXFETCH_COL_ALPHA_DEST_BODY
+
+
+#define FS_TEXFETCH_DS_BODY                             \
    "uniform sampler%s samp;\n"                          \
    "in vec4 tc;\n"                                      \
    "void main() {\n"                                    \
    "   gl_FragDepth = float(texture(samp, tc%s).x);\n"  \
    "}\n"
 
-#define FS_TEXFETCH_DS_MSAA                                             \
-   "#version 130\n"                                                     \
-   "#extension GL_ARB_texture_multisample : enable\n"                   \
-   "uniform sampler%s samp;\n"                                          \
-   "in vec4 tc;\n"                                                      \
-   "void main() {\n"                                                    \
+#define FS_TEXFETCH_DS_GL HEADER_GL FS_TEXFETCH_DS_BODY
+#define FS_TEXFETCH_DS_GLES HEADER_GLES FS_TEXFETCH_DS_BODY
+
+
+#define FS_TEXFETCH_DS_MSAA_BODY                                         \
+   "#extension GL_ARB_texture_multisample : enable\n"                    \
+   "uniform sampler%s samp;\n"                                           \
+   "in vec4 tc;\n"                                                       \
+   "void main() {\n"                                                     \
    "   gl_FragDepth = float(texelFetch(samp, %s(tc%s), int(tc.z)).x);\n" \
    "}\n"
 
+#define FS_TEXFETCH_DS_MSAA_GL HEADER_GL FS_TEXFETCH_DS_MSAA_BODY
+#define FS_TEXFETCH_DS_MSAA_GLES HEADER_GLES FS_TEXFETCH_DS_MSAA_BODY
+
+
 #endif
-- 
2.14.1



More information about the virglrenderer-devel mailing list