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. 25
      src/vrend_renderer.c
  2. 23
      src/vrend_shader.c
  3. 1
      src/vrend_shader.h

@ -1781,10 +1781,12 @@ static struct vrend_linked_shader_program *add_shader_program(struct vrend_sub_c
sprog->attrib_locs = NULL; sprog->attrib_locs = NULL;
} }
sprog->clip_enabled_loc = glGetUniformLocation(prog_id, "clip_plane_enabled"); if (has_feature(feat_cull_distance)) {
for (i = 0; i < VIRGL_NUM_CLIP_PLANES; i++) { sprog->clip_enabled_loc = glGetUniformLocation(prog_id, "clip_plane_enabled");
snprintf(name, 32, "clipp[%d]", i); for (i = 0; i < VIRGL_NUM_CLIP_PLANES; i++) {
sprog->clip_locs[i] = glGetUniformLocation(prog_id, name); snprintf(name, 32, "clipp[%d]", i);
sprog->clip_locs[i] = glGetUniformLocation(prog_id, name);
}
} }
return sprog; return sprog;
} }
@ -4949,13 +4951,15 @@ int vrend_draw_vbo(struct vrend_context *ctx,
sub_ctx->prog->viewport_neg_val = viewport_neg_val; sub_ctx->prog->viewport_neg_val = viewport_neg_val;
} }
if (sub_ctx->rs_state.clip_plane_enable) { if (has_feature(feat_cull_distance)) {
glUniform1i(sub_ctx->prog->clip_enabled_loc, 1); if (sub_ctx->rs_state.clip_plane_enable) {
for (i = 0 ; i < 8; i++) { glUniform1i(sub_ctx->prog->clip_enabled_loc, 1);
glUniform4fv(sub_ctx->prog->clip_locs[i], 1, (const GLfloat *)&sub_ctx->ucp_state.ucp[i]); for (i = 0 ; i < 8; i++) {
glUniform4fv(sub_ctx->prog->clip_locs[i], 1, (const GLfloat *)&sub_ctx->ucp_state.ucp[i]);
}
} else {
glUniform1i(sub_ctx->prog->clip_enabled_loc, 0);
} }
} else {
glUniform1i(sub_ctx->prog->clip_enabled_loc, 0);
} }
if (has_feature(feat_gles31_vertex_attrib_binding)) if (has_feature(feat_gles31_vertex_attrib_binding))
@ -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.use_integer = vrend_state.use_integer;
grctx->shader_cfg.has_dual_src_blend = has_feature(feat_dual_src_blend); 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_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_create_sub_ctx(grctx, 0);
vrend_renderer_set_sub_ctx(grctx, 0); vrend_renderer_set_sub_ctx(grctx, 0);

@ -2146,7 +2146,8 @@ static void handle_vertex_proc_exit(const struct dump_ctx *ctx,
if (ctx->so && !ctx->key->gs_present && !ctx->key->tes_present) if (ctx->so && !ctx->key->gs_present && !ctx->key->tes_present)
emit_so_movs(ctx, glsl_strbufs, has_clipvertex_so); emit_so_movs(ctx, glsl_strbufs, has_clipvertex_so);
emit_clip_dist_movs(ctx, glsl_strbufs); if (ctx->cfg->has_cull_distance)
emit_clip_dist_movs(ctx, glsl_strbufs);
if (!ctx->key->gs_present && !ctx->key->tes_present) if (!ctx->key->gs_present && !ctx->key->tes_present)
emit_prescale(glsl_strbufs); emit_prescale(glsl_strbufs);
@ -5391,9 +5392,9 @@ iter_instruction(struct tgsi_iterate_context *iter,
case TGSI_OPCODE_END: case TGSI_OPCODE_END:
if (iter->processor.Processor == TGSI_PROCESSOR_VERTEX) { if (iter->processor.Processor == TGSI_PROCESSOR_VERTEX) {
handle_vertex_proc_exit(ctx, &ctx->glsl_strbufs, &ctx->has_clipvertex_so); 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); 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) if (ctx->so && !ctx->key->gs_present)
emit_so_movs(ctx, &ctx->glsl_strbufs, &ctx->has_clipvertex_so); emit_so_movs(ctx, &ctx->glsl_strbufs, &ctx->has_clipvertex_so);
emit_clip_dist_movs(ctx, &ctx->glsl_strbufs); emit_clip_dist_movs(ctx, &ctx->glsl_strbufs);
@ -5437,7 +5438,8 @@ iter_instruction(struct tgsi_iterate_context *iter,
struct immed *imd = &ctx->imm[(inst->Src[0].Register.Index)]; struct immed *imd = &ctx->imm[(inst->Src[0].Register.Index)];
if (ctx->so && ctx->key->gs_present) if (ctx->so && ctx->key->gs_present)
emit_so_movs(ctx, &ctx->glsl_strbufs, &ctx->has_clipvertex_so); emit_so_movs(ctx, &ctx->glsl_strbufs, &ctx->has_clipvertex_so);
emit_clip_dist_movs(ctx, &ctx->glsl_strbufs); if (ctx->cfg->has_cull_distance)
emit_clip_dist_movs(ctx, &ctx->glsl_strbufs);
emit_prescale(&ctx->glsl_strbufs); emit_prescale(&ctx->glsl_strbufs);
if (imd->val[inst->Src[0].Register.SwizzleX].ui > 0) { if (imd->val[inst->Src[0].Register.SwizzleX].ui > 0) {
ctx->shader_req_bits |= SHADER_REQ_GPU_SHADER5; ctx->shader_req_bits |= SHADER_REQ_GPU_SHADER5;
@ -5641,7 +5643,8 @@ static void emit_header(const struct dump_ctx *ctx, struct vrend_glsl_strbufs *g
if (ctx->cfg->use_gles) { if (ctx->cfg->use_gles) {
emit_ver_extf(glsl_strbufs, "#version %d es\n", ctx->cfg->glsl_version); 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"); 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 cull_buf[64] = "";
char clip_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_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; int num_cull_dists = ctx->num_cull_dist_prop ? ctx->num_cull_dist_prop : 0;
@ -6862,8 +6865,10 @@ static void emit_ios_geom(const struct dump_ctx *ctx,
emit_hdrf(glsl_strbufs, "vec4 clip_dist_temp[2];\n"); emit_hdrf(glsl_strbufs, "vec4 clip_dist_temp[2];\n");
} }
emit_hdr(glsl_strbufs, "uniform bool clip_plane_enabled;\n"); if (ctx->cfg->has_cull_distance) {
emit_hdr(glsl_strbufs, "uniform vec4 clipp[8];\n"); emit_hdr(glsl_strbufs, "uniform bool clip_plane_enabled;\n");
emit_hdr(glsl_strbufs, "uniform vec4 clipp[8];\n");
}
} }
@ -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_in(ctx, glsl_strbufs, has_pervertex);
emit_ios_per_vertex_out(ctx, glsl_strbufs, ""); 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 bool clip_plane_enabled;\n");
emit_hdr(glsl_strbufs, "uniform vec4 clipp[8];\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 use_integer : 1;
uint32_t has_dual_src_blend : 1; uint32_t has_dual_src_blend : 1;
uint32_t has_fbfetch_coherent : 1; uint32_t has_fbfetch_coherent : 1;
uint32_t has_cull_distance : 1;
}; };
struct vrend_context; struct vrend_context;

Loading…
Cancel
Save