From: Brian Paul Date: Thu, 29 May 2014 19:56:48 +0000 (-0600) Subject: svga: use svga_shader_too_large() in compile_vs() X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3b66029dd372f54c1e0e14a036668404d11fbcfb;p=mesa.git svga: use svga_shader_too_large() in compile_vs() And rework the dummy shader code to match the fragment shader case. Reviewed-by: José Fonseca --- diff --git a/src/gallium/drivers/svga/svga_state_vs.c b/src/gallium/drivers/svga/svga_state_vs.c index 64dd7c99c34..125903b386a 100644 --- a/src/gallium/drivers/svga/svga_state_vs.c +++ b/src/gallium/drivers/svga/svga_state_vs.c @@ -99,6 +99,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. */ @@ -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; }