[Mesa-dev] [PATCH 3/3] svga: use svga_shader_too_large() in compile_vs()

Brian Paul brianp at vmware.com
Thu May 29 13:59:59 PDT 2014


And rework the dummy shader code to match the fragment shader case.
---
 src/gallium/drivers/svga/svga_state_vs.c |   44 ++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_state_vs.c b/src/gallium/drivers/svga/svga_state_vs.c
index 64dd7c9..125903b 100644
--- a/src/gallium/drivers/svga/svga_state_vs.c
+++ b/src/gallium/drivers/svga/svga_state_vs.c
@@ -100,6 +100,29 @@ get_dummy_vertex_shader(void)
 
 
 /**
+ * Replace the given shader's instruction with a simple / dummy shader.
+ * We use this when normal shader translation fails.
+ */
+static struct svga_shader_variant *
+get_compiled_dummy_vertex_shader(struct svga_vertex_shader *vs,
+                                 const struct svga_vs_compile_key *key)
+{
+   const struct tgsi_token *dummy = get_dummy_vertex_shader();
+   struct svga_shader_variant *variant;
+
+   if (!dummy) {
+      return NULL;
+   }
+
+   FREE((void *) vs->base.tokens);
+   vs->base.tokens = dummy;
+
+   variant = svga_translate_vertex_program(vs, key);
+   return variant;
+}
+
+
+/**
  * Translate TGSI shader into an svga shader variant.
  */
 static enum pipe_error
@@ -114,16 +137,21 @@ compile_vs(struct svga_context *svga,
    variant = svga_translate_vertex_program( vs, key );
    if (variant == NULL) {
       /* some problem during translation, try the dummy shader */
-      const struct tgsi_token *dummy = get_dummy_vertex_shader();
-      if (!dummy) {
-         ret = PIPE_ERROR_OUT_OF_MEMORY;
+      variant = get_compiled_dummy_vertex_shader(vs, key);
+      if (!variant) {
+         ret = PIPE_ERROR;
          goto fail;
       }
-      debug_printf("Failed to compile vertex shader, using dummy shader instead.\n");
-      FREE((void *) vs->base.tokens);
-      vs->base.tokens = dummy;
-      variant = svga_translate_vertex_program(vs, key);
-      if (variant == NULL) {
+   }
+
+   if (svga_shader_too_large(svga, variant)) {
+      /* too big, use dummy shader */
+      debug_printf("Shader too large (%lu bytes),"
+                   " using dummy shader instead.\n",
+                   (unsigned long ) variant->nr_tokens
+                   * sizeof(variant->tokens[0]));
+      variant = get_compiled_dummy_vertex_shader(vs, key);
+      if (!variant) {
          ret = PIPE_ERROR;
          goto fail;
       }
-- 
1.7.10.4



More information about the mesa-dev mailing list