shader: make setting a requested glsl_ver more robust.

This makes sure we never accidentally set a lower glsl version
after a higher one (we don't ever, but best to make sure).

Reviewed-by: Elie Tournier <elie.tournier@collabora.com>
macos/master
Dave Airlie 6 years ago
parent e716b00fd4
commit 2dd41453ab
  1. 20
      src/vrend_shader.c

@ -235,6 +235,12 @@ static inline bool fs_emit_layout(struct dump_ctx *ctx)
return false; return false;
} }
static void require_glsl_ver(struct dump_ctx *ctx, int glsl_ver)
{
if (glsl_ver > ctx->glsl_ver_required)
ctx->glsl_ver_required = glsl_ver;
}
static char *strcat_realloc(char *str, const char *catstr) static char *strcat_realloc(char *str, const char *catstr)
{ {
char *new = realloc(str, strlen(str) + strlen(catstr) + 1); char *new = realloc(str, strlen(str) + strlen(catstr) + 1);
@ -413,7 +419,7 @@ iter_declaration(struct tgsi_iterate_context *iter,
name_prefix = "gl_PrimitiveID"; name_prefix = "gl_PrimitiveID";
ctx->inputs[i].glsl_predefined_no_emit = true; ctx->inputs[i].glsl_predefined_no_emit = true;
ctx->inputs[i].glsl_no_index = true; ctx->inputs[i].glsl_no_index = true;
ctx->glsl_ver_required = 150; require_glsl_ver(ctx, 150);
break; break;
} }
case TGSI_SEMANTIC_VIEWPORT_INDEX: case TGSI_SEMANTIC_VIEWPORT_INDEX:
@ -588,7 +594,7 @@ iter_declaration(struct tgsi_iterate_context *iter,
ctx->num_clip_dist += 4; ctx->num_clip_dist += 4;
if (iter->processor.Processor == TGSI_PROCESSOR_VERTEX && if (iter->processor.Processor == TGSI_PROCESSOR_VERTEX &&
ctx->key->gs_present) ctx->key->gs_present)
ctx->glsl_ver_required = 150; require_glsl_ver(ctx, 150);
break; break;
case TGSI_SEMANTIC_CLIPVERTEX: case TGSI_SEMANTIC_CLIPVERTEX:
name_prefix = "gl_ClipVertex"; name_prefix = "gl_ClipVertex";
@ -1309,7 +1315,7 @@ static int translate_tex(struct dump_ctx *ctx,
if (ctx->cfg->glsl_version >= 140) if (ctx->cfg->glsl_version >= 140)
if ((ctx->shader_req_bits & SHADER_REQ_SAMPLER_RECT) || ctx->uses_sampler_buf) if ((ctx->shader_req_bits & SHADER_REQ_SAMPLER_RECT) || ctx->uses_sampler_buf)
ctx->glsl_ver_required = 140; require_glsl_ver(ctx, 140);
sampler_index = 1; sampler_index = 1;
@ -2596,7 +2602,7 @@ prolog(struct tgsi_iterate_context *iter)
if (iter->processor.Processor == TGSI_PROCESSOR_VERTEX && if (iter->processor.Processor == TGSI_PROCESSOR_VERTEX &&
ctx->key->gs_present) ctx->key->gs_present)
ctx->glsl_ver_required = 150; require_glsl_ver(ctx, 150);
return TRUE; return TRUE;
} }
@ -2978,7 +2984,7 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
const char *cname = tgsi_proc_to_prefix(ctx->prog_type); const char *cname = tgsi_proc_to_prefix(ctx->prog_type);
if (ctx->info.dimension_indirect_files & (1 << TGSI_FILE_CONSTANT)) { if (ctx->info.dimension_indirect_files & (1 << TGSI_FILE_CONSTANT)) {
ctx->glsl_ver_required = 150; require_glsl_ver(ctx, 150);
snprintf(buf, 255, "uniform %subo { vec4 ubocontents[%d]; } %suboarr[%d];\n", cname, ctx->ubo_sizes[0], cname, ctx->num_ubo); snprintf(buf, 255, "uniform %subo { vec4 ubocontents[%d]; } %suboarr[%d];\n", cname, ctx->ubo_sizes[0], cname, ctx->num_ubo);
STRCAT_WITH_RET(glsl_hdr, buf); STRCAT_WITH_RET(glsl_hdr, buf);
} else { } else {
@ -3127,7 +3133,7 @@ char *vrend_convert_shader(struct vrend_shader_cfg *cfg,
tgsi_scan_shader(tokens, &ctx.info); tgsi_scan_shader(tokens, &ctx.info);
/* if we are in core profile mode we should use GLSL 1.40 */ /* if we are in core profile mode we should use GLSL 1.40 */
if (cfg->use_core_profile && cfg->glsl_version >= 140) if (cfg->use_core_profile && cfg->glsl_version >= 140)
ctx.glsl_ver_required = 140; require_glsl_ver(&ctx, 140);
if (sinfo->so_info.num_outputs) { if (sinfo->so_info.num_outputs) {
ctx.so = &sinfo->so_info; ctx.so = &sinfo->so_info;
@ -3138,7 +3144,7 @@ char *vrend_convert_shader(struct vrend_shader_cfg *cfg,
ctx.so_names = NULL; ctx.so_names = NULL;
if (ctx.info.dimension_indirect_files & (1 << TGSI_FILE_CONSTANT)) if (ctx.info.dimension_indirect_files & (1 << TGSI_FILE_CONSTANT))
ctx.glsl_ver_required = 150; require_glsl_ver(&ctx, 150);
if (ctx.info.indirect_files & (1 << TGSI_FILE_SAMPLER)) if (ctx.info.indirect_files & (1 << TGSI_FILE_SAMPLER))
ctx.shader_req_bits |= SHADER_REQ_GPU_SHADER5; ctx.shader_req_bits |= SHADER_REQ_GPU_SHADER5;

Loading…
Cancel
Save