+/**
+ * If we fail to compile a fragment shader (because it uses too many
+ * registers, for example) we'll use a dummy/fallback shader that
+ * simply emits a constant color (red for debug, black for release).
+ * We hit this with the Unigine/Heaven demo when Shaders = High.
+ * With black, the demo still looks good.
+ */
+static const struct tgsi_token *
+get_dummy_fragment_shader(void)
+{
+#ifdef DEBUG
+ static const float color[4] = { 1.0, 0.0, 0.0, 0.0 }; /* red */
+#else
+ static const float color[4] = { 0.0, 0.0, 0.0, 0.0 }; /* black */
+#endif
+ struct ureg_program *ureg;
+ const struct tgsi_token *tokens;
+ struct ureg_src src;
+ struct ureg_dst dst;
+ unsigned num_tokens;
+
+ ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT);
+ if (!ureg)
+ return NULL;
+
+ dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, 0);
+ src = ureg_DECL_immediate(ureg, color, 4);
+ ureg_MOV(ureg, dst, src);
+ ureg_END(ureg);
+
+ tokens = ureg_get_tokens(ureg, &num_tokens);
+
+ ureg_destroy(ureg);
+
+ return tokens;
+}
+
+
+/**
+ * Replace the given shader's instruction with a simple constant-color
+ * shader. We use this when normal shader translation fails.
+ */
+static struct svga_shader_variant *
+get_compiled_dummy_shader(struct svga_fragment_shader *fs,
+ const struct svga_fs_compile_key *key)
+{
+ const struct tgsi_token *dummy = get_dummy_fragment_shader();
+ struct svga_shader_variant *variant;
+
+ if (!dummy) {
+ return NULL;
+ }
+
+ FREE((void *) fs->base.tokens);
+ fs->base.tokens = dummy;
+
+ variant = svga_translate_fragment_program(fs, key);
+ return variant;
+}
+
+
+/**
+ * Translate TGSI shader into an svga shader variant.
+ */
+static enum pipe_error
+compile_fs(struct svga_context *svga,
+ struct svga_fragment_shader *fs,
+ const struct svga_fs_compile_key *key,
+ struct svga_shader_variant **out_variant)