diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 85f9dbd..58e182b 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -1998,6 +1998,7 @@ static void vrend_destroy_shader_object(void *obj_ptr) } static inline void vrend_fill_shader_key(struct vrend_context *ctx, + unsigned type, struct vrend_shader_key *key) { if (vrend_state.use_core_profile == true) { @@ -2032,6 +2033,11 @@ static inline void vrend_fill_shader_key(struct vrend_context *ctx, if (ctx->sub->shaders[PIPE_SHADER_GEOMETRY]) key->gs_present = true; + + if (type == PIPE_SHADER_GEOMETRY && ctx->sub->shaders[PIPE_SHADER_VERTEX]) { + key->vs_has_pervertex = ctx->sub->shaders[PIPE_SHADER_VERTEX]->sinfo.num_pervertex_clip > 0; + key->vs_pervertex_num_clip = ctx->sub->shaders[PIPE_SHADER_VERTEX]->sinfo.num_pervertex_clip; + } } static inline int conv_shader_type(int type) @@ -2086,7 +2092,7 @@ static int vrend_shader_select(struct vrend_context *ctx, int r; memset(&key, 0, sizeof(key)); - vrend_fill_shader_key(ctx, &key); + vrend_fill_shader_key(ctx, sel->type, &key); if (sel->current && !memcmp(&sel->current->key, &key, sizeof(key))) return 0; diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 0afc938..82a571c 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -140,6 +140,7 @@ struct dump_ctx { bool has_clipvertex_so; bool has_viewport_idx; bool has_frag_viewport_idx; + bool vs_has_pervertex; }; static inline const char *tgsi_proc_to_prefix(int shader_type) @@ -2290,6 +2291,7 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr) STRCAT_WITH_RET(glsl_hdr, buf); } if (ctx->key->gs_present) { + ctx->vs_has_pervertex = true; snprintf(buf, 255, "out gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize;\n float gl_ClipDistance[%d];\n};\n", ctx->num_clip_dist ? ctx->num_clip_dist : 8); STRCAT_WITH_RET(glsl_hdr, buf); } else { @@ -2304,8 +2306,17 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr) if (ctx->prog_type == TGSI_PROCESSOR_GEOMETRY) { snprintf(buf, 255, "uniform vec4 winsys_adjust;\n"); STRCAT_WITH_RET(glsl_hdr, buf); - if (ctx->num_in_clip_dist || ctx->key->clip_plane_enable) { - snprintf(buf, 255, "in gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize; \n float gl_ClipDistance[%d];\n} gl_in[];\n", ctx->num_in_clip_dist ? ctx->num_in_clip_dist : 8); + if (ctx->num_in_clip_dist || ctx->key->clip_plane_enable || ctx->key->vs_has_pervertex) { + int clip_dist; + + if (ctx->key->vs_has_pervertex) + clip_dist = ctx->key->vs_pervertex_num_clip; + else if (ctx->num_in_clip_dist) + clip_dist = ctx->num_in_clip_dist; + else + clip_dist = 8; + + snprintf(buf, 255, "in gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize; \n float gl_ClipDistance[%d];\n} gl_in[];\n", clip_dist); STRCAT_WITH_RET(glsl_hdr, buf); } if (ctx->num_clip_dist) { @@ -2515,6 +2526,7 @@ char *vrend_convert_shader(struct vrend_shader_cfg *cfg, free(ctx.glsl_main); free(glsl_hdr); sinfo->num_ucp = ctx.key->clip_plane_enable ? 8 : 0; + sinfo->num_pervertex_clip = (ctx.vs_has_pervertex ? (ctx.num_clip_dist ? ctx.num_clip_dist : 8) : 0); sinfo->samplers_used_mask = ctx.samplers_used; sinfo->num_consts = ctx.num_consts; sinfo->num_ubos = ctx.num_ubo; diff --git a/src/vrend_shader.h b/src/vrend_shader.h index 818097b..1e4c7a3 100644 --- a/src/vrend_shader.h +++ b/src/vrend_shader.h @@ -43,6 +43,7 @@ struct vrend_shader_info { int num_ubos; int num_ucp; int glsl_ver; + uint8_t num_pervertex_clip; uint32_t shadow_samp_mask; int gs_out_prim; uint32_t attrib_input_mask; @@ -62,6 +63,8 @@ struct vrend_shader_key { uint8_t clip_plane_enable; bool gs_present; bool flatshade; + bool vs_has_pervertex; + uint8_t vs_pervertex_num_clip; float alpha_ref_val; uint32_t cbufs_are_a8_bitmask; };