aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGert Wollny <gert.wollny@collabora.com>2022-11-11 09:52:30 +0100
committerMarge Bot <emma+marge@anholt.net>2022-11-14 14:02:01 +0000
commitf509cdae76d76794ac85da024f5a6d27bb23c72f (patch)
tree023aaad35fdd39149ff7ba8f0e772f65bc00ade7
parent48a43a116901116b0f8fe3082483789c8a50f78f (diff)
downloadvirglrenderer-f509cdae76d76794ac85da024f5a6d27bb23c72f.tar.gz
shader: Stay in varying limits when emitting clip-plane code
Writing to gl_ClipDistance can be triggered in two ways: Either the shader emits the code explicitely, or the GL state enables a clip plane and no extra shader code is emitted in the original GLSL code. In this latter case we emulate the clip planes defined in the compatibility profile by using gl_ClipDistance and emit these extra values that occupy two extra varying slots. With that we may exceed the number of 32 supported varyings, which leads to undefined behaviour in the host driver. To avoid this emit gl_ClipDistance only in this case if we don't exceed that limit. Signed-off-by: Gert Wollny <gert.wollny@collabora.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/981>
-rw-r--r--src/vrend_shader.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index 68af4335..aca018e1 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -2359,7 +2359,10 @@ static void emit_clip_dist_movs(const struct dump_ctx *ctx,
if (ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL)
prefix = "gl_out[gl_InvocationID].";
- if (ctx->num_out_clip_dist == 0 && ctx->is_last_vertex_stage) {
+
+ if (ctx->num_out_clip_dist == 0 &&
+ ctx->is_last_vertex_stage &&
+ ctx->num_outputs + 2 <= MAX_VARYING) {
emit_buff(glsl_strbufs, "if (clip_plane_enabled) {\n");
for (i = 0; i < 8; i++) {
emit_buff(glsl_strbufs, " %sgl_ClipDistance[%d] = dot(%s, clipp[%d]);\n",