v3d: don't try to render if shaders failed to compile
authorIago Toral Quiroga <itoral@igalia.com>
Wed, 9 Oct 2019 09:13:00 +0000 (11:13 +0200)
committerIago Toral Quiroga <itoral@igalia.com>
Mon, 16 Dec 2019 07:42:37 +0000 (08:42 +0100)
This is the same we do in the compute path to avoid crashes
at draw time.

Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
src/gallium/drivers/v3d/v3dx_draw.c

index a4cff4c86c6803f76301115a1f5ab09e204264c5..d0f6f623e6cfcb2b5f5c3e544267bca41c036b6a 100644 (file)
@@ -1030,6 +1030,33 @@ v3d_hw_prim_type(enum pipe_prim_type prim_type)
         }
 }
 
+static bool
+v3d_check_compiled_shaders(struct v3d_context *v3d)
+{
+        static bool warned[5] = { 0 };
+
+        uint32_t failed_stage = MESA_SHADER_NONE;
+        if (!v3d->prog.vs->resource || !v3d->prog.cs->resource) {
+                failed_stage = MESA_SHADER_VERTEX;
+        } else if ((v3d->prog.gs_bin && !v3d->prog.gs_bin->resource) ||
+                   (v3d->prog.gs && !v3d->prog.gs->resource)) {
+                failed_stage = MESA_SHADER_GEOMETRY;
+        } else if (v3d->prog.fs && !v3d->prog.fs->resource) {
+                failed_stage = MESA_SHADER_FRAGMENT;
+        }
+
+        if (likely(failed_stage == MESA_SHADER_NONE))
+                return true;
+
+        if (!warned[failed_stage]) {
+                fprintf(stderr,
+                        "%s shader failed to compile. Expect corruption.\n",
+                        _mesa_shader_stage_to_string(failed_stage));
+                warned[failed_stage] = true;
+        }
+        return false;
+}
+
 static void
 v3d_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
 {
@@ -1137,6 +1164,8 @@ v3d_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
 
         v3d_start_draw(v3d);
         v3d_update_compiled_shaders(v3d, info->mode);
+        if (!v3d_check_compiled_shaders(v3d))
+                return;
         v3d_update_job_ez(v3d, job);
 
         /* If this job was writing to transform feedback buffers before this