vrend: Support GLES shaders v2

Some features:
  * Always use the "#version 300 es" header
  * Set high precision by default
  * Do not use noperspective attribute

v2: Do not create a global state but instead add field
vrend_shader_cfg and send that into more functions.

Signed-off-by: Elie Tournier <elie.tournier@collabora.com>
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 3f2b72d333
commit 2f1558f520
  1. 5
      src/vrend_renderer.c
  2. 19
      src/vrend_shader.c
  3. 4
      src/vrend_shader.h

@ -856,11 +856,11 @@ static struct vrend_linked_shader_program *add_shader_program(struct vrend_conte
bool ret; bool ret;
if (gs) if (gs)
vrend_patch_vertex_shader_interpolants(gs->glsl_prog, vrend_patch_vertex_shader_interpolants(&ctx->shader_cfg, gs->glsl_prog,
&gs->sel->sinfo, &gs->sel->sinfo,
&fs->sel->sinfo, true, fs->key.flatshade); &fs->sel->sinfo, true, fs->key.flatshade);
else else
vrend_patch_vertex_shader_interpolants(vs->glsl_prog, vrend_patch_vertex_shader_interpolants(&ctx->shader_cfg, vs->glsl_prog,
&vs->sel->sinfo, &vs->sel->sinfo,
&fs->sel->sinfo, false, fs->key.flatshade); &fs->sel->sinfo, false, fs->key.flatshade);
ret = vrend_compile_shader(ctx, gs ? gs : vs); ret = vrend_compile_shader(ctx, gs ? gs : vs);
@ -4264,6 +4264,7 @@ struct vrend_context *vrend_create_context(int id, uint32_t nlen, const char *de
grctx->res_hash = vrend_object_init_ctx_table(); grctx->res_hash = vrend_object_init_ctx_table();
grctx->shader_cfg.use_gles = vrend_state.use_gles;
grctx->shader_cfg.use_core_profile = vrend_state.use_core_profile; grctx->shader_cfg.use_core_profile = vrend_state.use_core_profile;
grctx->shader_cfg.use_explicit_locations = vrend_state.use_explicit_locations; grctx->shader_cfg.use_explicit_locations = vrend_state.use_explicit_locations;
vrend_renderer_create_sub_ctx(grctx, 0); vrend_renderer_create_sub_ctx(grctx, 0);

@ -31,6 +31,7 @@
#include <math.h> #include <math.h>
#include <errno.h> #include <errno.h>
#include "vrend_shader.h" #include "vrend_shader.h"
extern int vrend_dump_shaders; extern int vrend_dump_shaders;
/* start convert of tgsi to glsl */ /* start convert of tgsi to glsl */
@ -2213,9 +2214,12 @@ prolog(struct tgsi_iterate_context *iter)
static char *emit_header(struct dump_ctx *ctx, char *glsl_hdr) 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");
STRCAT_WITH_RET(glsl_hdr, "precision highp float;\n");
} else {
if (ctx->prog_type == TGSI_PROCESSOR_GEOMETRY || ctx->glsl_ver_required == 150) if (ctx->prog_type == TGSI_PROCESSOR_GEOMETRY || ctx->glsl_ver_required == 150)
STRCAT_WITH_RET(glsl_hdr, "#version 150\n"); STRCAT_WITH_RET(glsl_hdr, "#version 150\n");
else if (ctx->glsl_ver_required == 140) else if (ctx->glsl_ver_required == 140)
STRCAT_WITH_RET(glsl_hdr, "#version 140\n"); STRCAT_WITH_RET(glsl_hdr, "#version 140\n");
else else
@ -2254,7 +2258,7 @@ static char *emit_header(struct dump_ctx *ctx, char *glsl_hdr)
STRCAT_WITH_RET(glsl_hdr, "#extension GL_ARB_sample_shading : require\n"); STRCAT_WITH_RET(glsl_hdr, "#extension GL_ARB_sample_shading : require\n");
if (ctx->uses_gpu_shader5) if (ctx->uses_gpu_shader5)
STRCAT_WITH_RET(glsl_hdr, "#extension GL_ARB_gpu_shader5 : require\n"); STRCAT_WITH_RET(glsl_hdr, "#extension GL_ARB_gpu_shader5 : require\n");
}
return glsl_hdr; return glsl_hdr;
} }
@ -2295,11 +2299,14 @@ const char *vrend_shader_samplertypeconv(int sampler_type, int *is_shad)
} }
} }
static const char *get_interp_string(int interpolate, bool flatshade) static const char *get_interp_string(struct vrend_shader_cfg *cfg, int interpolate, bool flatshade)
{ {
switch (interpolate) { switch (interpolate) {
case TGSI_INTERPOLATE_LINEAR: case TGSI_INTERPOLATE_LINEAR:
if (!cfg->use_gles)
return "noperspective "; return "noperspective ";
else
return "";
case TGSI_INTERPOLATE_PERSPECTIVE: case TGSI_INTERPOLATE_PERSPECTIVE:
return "smooth "; return "smooth ";
case TGSI_INTERPOLATE_CONSTANT: case TGSI_INTERPOLATE_CONSTANT:
@ -2363,7 +2370,7 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT && if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT &&
(ctx->inputs[i].name == TGSI_SEMANTIC_GENERIC || (ctx->inputs[i].name == TGSI_SEMANTIC_GENERIC ||
ctx->inputs[i].name == TGSI_SEMANTIC_COLOR)) { ctx->inputs[i].name == TGSI_SEMANTIC_COLOR)) {
prefix = get_interp_string(ctx->inputs[i].interpolate, ctx->key->flatshade); prefix = get_interp_string(ctx->cfg, ctx->inputs[i].interpolate, ctx->key->flatshade);
if (!prefix) if (!prefix)
prefix = ""; prefix = "";
ctx->num_interps++; ctx->num_interps++;
@ -2705,7 +2712,7 @@ static void replace_interp(char *program,
memcpy(ptr, pstring, strlen(pstring)); memcpy(ptr, pstring, strlen(pstring));
} }
bool vrend_patch_vertex_shader_interpolants(char *program, bool vrend_patch_vertex_shader_interpolants(struct vrend_shader_cfg *cfg, char *program,
struct vrend_shader_info *vs_info, struct vrend_shader_info *vs_info,
struct vrend_shader_info *fs_info, bool is_gs, bool flatshade) struct vrend_shader_info *fs_info, bool is_gs, bool flatshade)
{ {
@ -2719,7 +2726,7 @@ bool vrend_patch_vertex_shader_interpolants(char *program,
return true; return true;
for (i = 0; i < fs_info->num_interps; i++) { for (i = 0; i < fs_info->num_interps; i++) {
pstring = get_interp_string(fs_info->interpinfo[i].interpolate, flatshade); pstring = get_interp_string(cfg, fs_info->interpinfo[i].interpolate, flatshade);
if (!pstring) if (!pstring)
continue; continue;

@ -71,11 +71,13 @@ struct vrend_shader_key {
struct vrend_shader_cfg { struct vrend_shader_cfg {
int glsl_version; int glsl_version;
bool use_gles;
bool use_core_profile; bool use_core_profile;
bool use_explicit_locations; bool use_explicit_locations;
}; };
bool vrend_patch_vertex_shader_interpolants(char *program, bool vrend_patch_vertex_shader_interpolants(struct vrend_shader_cfg *cfg,
char *program,
struct vrend_shader_info *vs_info, struct vrend_shader_info *vs_info,
struct vrend_shader_info *fs_info, struct vrend_shader_info *fs_info,
bool is_gs, bool flatshade); bool is_gs, bool flatshade);

Loading…
Cancel
Save