vrend: Use OpenGL ES 3.0 shaders in blitter

Signed-off-by: Jakob Bornecrantz <jakob@collabora.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
macos/master
Jakob Bornecrantz 7 years ago committed by Dave Airlie
parent 048d8ccec2
commit 7b1ab9831a
  1. 17
      src/vrend_blitter.c
  2. 47
      src/vrend_blitter.h

@ -52,6 +52,7 @@
struct vrend_blitter_ctx { struct vrend_blitter_ctx {
virgl_gl_context gl_context; virgl_gl_context gl_context;
bool initialised; bool initialised;
bool use_gles;
GLuint vaoid; 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); 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); glDeleteShader(blit_ctx->vs);
blit_ctx->vs = 0; blit_ctx->vs = 0;
return false; 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) tgsi_tex_target == TGSI_TEXTURE_SHADOWCUBE_ARRAY)
ext_str = "#extension GL_ARB_texture_cube_map_array : require\n"; 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); 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) tgsi_tex_target == TGSI_TEXTURE_SHADOWCUBE_ARRAY)
ext_str = "#extension GL_ARB_texture_cube_map_array : require\n"; 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); fs_id = glCreateShader(GL_FRAGMENT_SHADER);
@ -245,7 +249,8 @@ static GLuint blit_build_frag_tex_writedepth(struct vrend_blitter_ctx *blit_ctx,
break; 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); 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; 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); 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->initialised = true;
blit_ctx->use_gles = epoxy_is_desktop_gl() == 0;
ctx_params.shared = true; ctx_params.shared = true;
for (uint32_t i = 0; i < ARRAY_SIZE(gl_versions); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(gl_versions); i++) {
ctx_params.major_ver = gl_versions[i].major; ctx_params.major_ver = gl_versions[i].major;

@ -26,8 +26,21 @@
/* shaders for blitting */ /* shaders for blitting */
#define VS_PASSTHROUGH \ #define HEADER_GL \
"// Blitter\n" \
"#version 130\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 arg0;\n" \
"in vec4 arg1;\n" \ "in vec4 arg1;\n" \
"out vec4 tc;\n" \ "out vec4 tc;\n" \
@ -36,8 +49,11 @@
" tc = arg1;\n" \ " tc = arg1;\n" \
"}\n" "}\n"
#define FS_TEXFETCH_COL \ #define VS_PASSTHROUGH_GL HEADER_GL VS_PASSTHROUGH_BODY
"#version 130\n" \ #define VS_PASSTHROUGH_GLES HEADER_GLES VS_PASSTHROUGH_BODY
#define FS_TEXFETCH_COL_BODY \
"%s" \ "%s" \
"uniform sampler%s samp;\n" \ "uniform sampler%s samp;\n" \
"in vec4 tc;\n" \ "in vec4 tc;\n" \
@ -45,8 +61,11 @@
" gl_FragColor = texture(samp, tc%s)%s;\n" \ " gl_FragColor = texture(samp, tc%s)%s;\n" \
"}\n" "}\n"
#define FS_TEXFETCH_COL_ALPHA_DEST \ #define FS_TEXFETCH_COL_GL HEADER_GL FS_TEXFETCH_COL_BODY
"#version 130\n" \ #define FS_TEXFETCH_COL_GLES HEADER_GLES OUTFRAG_GLES FS_TEXFETCH_COL_BODY
#define FS_TEXFETCH_COL_ALPHA_DEST_BODY \
"%s" \ "%s" \
"uniform sampler%s samp;\n" \ "uniform sampler%s samp;\n" \
"in vec4 tc;\n" \ "in vec4 tc;\n" \
@ -55,16 +74,22 @@
" gl_FragColor = temp.aaaa;\n" \ " gl_FragColor = temp.aaaa;\n" \
"}\n" "}\n"
#define FS_TEXFETCH_DS \ #define FS_TEXFETCH_COL_ALPHA_DEST_GL HEADER_GL FS_TEXFETCH_COL_ALPHA_DEST_BODY
"#version 130\n" \ #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" \ "uniform sampler%s samp;\n" \
"in vec4 tc;\n" \ "in vec4 tc;\n" \
"void main() {\n" \ "void main() {\n" \
" gl_FragDepth = float(texture(samp, tc%s).x);\n" \ " gl_FragDepth = float(texture(samp, tc%s).x);\n" \
"}\n" "}\n"
#define FS_TEXFETCH_DS_MSAA \ #define FS_TEXFETCH_DS_GL HEADER_GL FS_TEXFETCH_DS_BODY
"#version 130\n" \ #define FS_TEXFETCH_DS_GLES HEADER_GLES FS_TEXFETCH_DS_BODY
#define FS_TEXFETCH_DS_MSAA_BODY \
"#extension GL_ARB_texture_multisample : enable\n" \ "#extension GL_ARB_texture_multisample : enable\n" \
"uniform sampler%s samp;\n" \ "uniform sampler%s samp;\n" \
"in vec4 tc;\n" \ "in vec4 tc;\n" \
@ -72,4 +97,8 @@
" gl_FragDepth = float(texelFetch(samp, %s(tc%s), int(tc.z)).x);\n" \ " gl_FragDepth = float(texelFetch(samp, %s(tc%s), int(tc.z)).x);\n" \
"}\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 #endif

Loading…
Cancel
Save