shader: check for clip/cull distance support

This fixes an issue where a shader would be emitted using
EXT_clip_cull_distance even if the host didn't support the extension.

Fixes 072f30955b

Signed-off-by: Italo Nicola <italonicola@collabora.com>
Reviewed-by: John Bates <jbates@chromium.org>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
macos/master
Italo Nicola 3 years ago committed by Yiwei Zhang
parent b04e55d18f
commit abb7df90c1
  1. 5
      src/vrend_renderer.c
  2. 15
      src/vrend_shader.c
  3. 1
      src/vrend_shader.h

@ -1781,11 +1781,13 @@ static struct vrend_linked_shader_program *add_shader_program(struct vrend_sub_c
sprog->attrib_locs = NULL;
}
if (has_feature(feat_cull_distance)) {
sprog->clip_enabled_loc = glGetUniformLocation(prog_id, "clip_plane_enabled");
for (i = 0; i < VIRGL_NUM_CLIP_PLANES; i++) {
snprintf(name, 32, "clipp[%d]", i);
sprog->clip_locs[i] = glGetUniformLocation(prog_id, name);
}
}
return sprog;
}
@ -4949,6 +4951,7 @@ int vrend_draw_vbo(struct vrend_context *ctx,
sub_ctx->prog->viewport_neg_val = viewport_neg_val;
}
if (has_feature(feat_cull_distance)) {
if (sub_ctx->rs_state.clip_plane_enable) {
glUniform1i(sub_ctx->prog->clip_enabled_loc, 1);
for (i = 0 ; i < 8; i++) {
@ -4957,6 +4960,7 @@ int vrend_draw_vbo(struct vrend_context *ctx,
} else {
glUniform1i(sub_ctx->prog->clip_enabled_loc, 0);
}
}
if (has_feature(feat_gles31_vertex_attrib_binding))
vrend_draw_bind_vertex_binding(ctx, sub_ctx->ve);
@ -6743,6 +6747,7 @@ struct vrend_context *vrend_create_context(int id, uint32_t nlen, const char *de
grctx->shader_cfg.use_integer = vrend_state.use_integer;
grctx->shader_cfg.has_dual_src_blend = has_feature(feat_dual_src_blend);
grctx->shader_cfg.has_fbfetch_coherent = has_feature(feat_framebuffer_fetch);
grctx->shader_cfg.has_cull_distance = has_feature(feat_cull_distance);
vrend_renderer_create_sub_ctx(grctx, 0);
vrend_renderer_set_sub_ctx(grctx, 0);

@ -2146,6 +2146,7 @@ static void handle_vertex_proc_exit(const struct dump_ctx *ctx,
if (ctx->so && !ctx->key->gs_present && !ctx->key->tes_present)
emit_so_movs(ctx, glsl_strbufs, has_clipvertex_so);
if (ctx->cfg->has_cull_distance)
emit_clip_dist_movs(ctx, glsl_strbufs);
if (!ctx->key->gs_present && !ctx->key->tes_present)
@ -5391,9 +5392,9 @@ iter_instruction(struct tgsi_iterate_context *iter,
case TGSI_OPCODE_END:
if (iter->processor.Processor == TGSI_PROCESSOR_VERTEX) {
handle_vertex_proc_exit(ctx, &ctx->glsl_strbufs, &ctx->has_clipvertex_so);
} else if (iter->processor.Processor == TGSI_PROCESSOR_TESS_CTRL) {
} else if (iter->processor.Processor == TGSI_PROCESSOR_TESS_CTRL && ctx->cfg->has_cull_distance) {
emit_clip_dist_movs(ctx, &ctx->glsl_strbufs);
} else if (iter->processor.Processor == TGSI_PROCESSOR_TESS_EVAL) {
} else if (iter->processor.Processor == TGSI_PROCESSOR_TESS_EVAL && ctx->cfg->has_cull_distance) {
if (ctx->so && !ctx->key->gs_present)
emit_so_movs(ctx, &ctx->glsl_strbufs, &ctx->has_clipvertex_so);
emit_clip_dist_movs(ctx, &ctx->glsl_strbufs);
@ -5437,6 +5438,7 @@ iter_instruction(struct tgsi_iterate_context *iter,
struct immed *imd = &ctx->imm[(inst->Src[0].Register.Index)];
if (ctx->so && ctx->key->gs_present)
emit_so_movs(ctx, &ctx->glsl_strbufs, &ctx->has_clipvertex_so);
if (ctx->cfg->has_cull_distance)
emit_clip_dist_movs(ctx, &ctx->glsl_strbufs);
emit_prescale(&ctx->glsl_strbufs);
if (imd->val[inst->Src[0].Register.SwizzleX].ui > 0) {
@ -5641,7 +5643,8 @@ static void emit_header(const struct dump_ctx *ctx, struct vrend_glsl_strbufs *g
if (ctx->cfg->use_gles) {
emit_ver_extf(glsl_strbufs, "#version %d es\n", ctx->cfg->glsl_version);
if ((ctx->shader_req_bits & SHADER_REQ_CLIP_DISTANCE) || ctx->num_out_clip_dist == 0) {
if ((ctx->shader_req_bits & SHADER_REQ_CLIP_DISTANCE) ||
(ctx->cfg->has_cull_distance && ctx->num_out_clip_dist == 0)) {
emit_ext(glsl_strbufs, "EXT_clip_cull_distance", "require");
}
@ -6520,7 +6523,7 @@ static void emit_ios_vs(const struct dump_ctx *ctx,
char cull_buf[64] = "";
char clip_buf[64] = "";
if (ctx->num_out_clip_dist || ctx->is_last_vertex_stage) {
if (ctx->cfg->has_cull_distance && (ctx->num_out_clip_dist || ctx->is_last_vertex_stage)) {
int num_clip_dists = ctx->num_clip_dist_prop ? ctx->num_clip_dist_prop : 0;
int num_cull_dists = ctx->num_cull_dist_prop ? ctx->num_cull_dist_prop : 0;
@ -6862,9 +6865,11 @@ static void emit_ios_geom(const struct dump_ctx *ctx,
emit_hdrf(glsl_strbufs, "vec4 clip_dist_temp[2];\n");
}
if (ctx->cfg->has_cull_distance) {
emit_hdr(glsl_strbufs, "uniform bool clip_plane_enabled;\n");
emit_hdr(glsl_strbufs, "uniform vec4 clipp[8];\n");
}
}
static void emit_ios_tcs(const struct dump_ctx *ctx,
@ -6953,7 +6958,7 @@ static void emit_ios_tes(const struct dump_ctx *ctx,
emit_ios_per_vertex_in(ctx, glsl_strbufs, has_pervertex);
emit_ios_per_vertex_out(ctx, glsl_strbufs, "");
if (ctx->is_last_vertex_stage) {
if (ctx->cfg->has_cull_distance && ctx->is_last_vertex_stage) {
emit_hdr(glsl_strbufs, "uniform bool clip_plane_enabled;\n");
emit_hdr(glsl_strbufs, "uniform vec4 clipp[8];\n");
}

@ -204,6 +204,7 @@ struct vrend_shader_cfg {
uint32_t use_integer : 1;
uint32_t has_dual_src_blend : 1;
uint32_t has_fbfetch_coherent : 1;
uint32_t has_cull_distance : 1;
};
struct vrend_context;

Loading…
Cancel
Save