[Mesa-dev] [PATCH 4/4] svga: clean up the compile_vs/gs/fs() functions

Charmaine Lee charmainel at vmware.com
Thu Sep 10 11:15:12 PDT 2015


For the series, Reviewed-by: Charmaine Lee <charmainel at vmware.com>
________________________________________
From: Brian Paul <brianp at vmware.com>
Sent: Thursday, September 10, 2015 8:04 AM
To: mesa-dev at lists.freedesktop.org
Cc: Charmaine Lee; Brian Paul
Subject: [PATCH 4/4] svga: clean up the compile_vs/gs/fs() functions

Simplify structure and remove gotos.
---
 src/gallium/drivers/svga/svga_state_fs.c | 29 ++++++++++-------------------
 src/gallium/drivers/svga/svga_state_gs.c | 19 +++++++------------
 src/gallium/drivers/svga/svga_state_vs.c | 28 ++++++++++------------------
 3 files changed, 27 insertions(+), 49 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_state_fs.c b/src/gallium/drivers/svga/svga_state_fs.c
index 5d39100..c244d53 100644
--- a/src/gallium/drivers/svga/svga_state_fs.c
+++ b/src/gallium/drivers/svga/svga_state_fs.c
@@ -136,13 +136,8 @@ compile_fs(struct svga_context *svga,
       debug_printf("Failed to compile fragment shader,"
                    " using dummy shader instead.\n");
       variant = get_compiled_dummy_shader(svga, fs, key);
-      if (!variant) {
-         ret = PIPE_ERROR;
-         goto fail;
-      }
    }
-
-   if (svga_shader_too_large(svga, variant)) {
+   else if (svga_shader_too_large(svga, variant)) {
       /* too big, use dummy shader */
       debug_printf("Shader too large (%u bytes),"
                    " using dummy shader instead.\n",
@@ -152,29 +147,25 @@ compile_fs(struct svga_context *svga,
       svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant);
       /* Use simple pass-through shader instead */
       variant = get_compiled_dummy_shader(svga, fs, key);
-      if (!variant) {
-         ret = PIPE_ERROR;
-         goto fail;
-      }
+   }
+
+   if (!variant) {
+      return PIPE_ERROR;
    }

    ret = svga_define_shader(svga, SVGA3D_SHADERTYPE_PS, variant);
-   if (ret != PIPE_OK)
-      goto fail;
+   if (ret != PIPE_OK) {
+      svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant);
+      return ret;
+   }

    *out_variant = variant;

-   /* insert variants at head of linked list */
+   /* insert variant at head of linked list */
    variant->next = fs->base.variants;
    fs->base.variants = variant;

    return PIPE_OK;
-
-fail:
-   if (variant) {
-      svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant);
-   }
-   return ret;
 }


diff --git a/src/gallium/drivers/svga/svga_state_gs.c b/src/gallium/drivers/svga/svga_state_gs.c
index 9f6885b..7f75410 100644
--- a/src/gallium/drivers/svga/svga_state_gs.c
+++ b/src/gallium/drivers/svga/svga_state_gs.c
@@ -80,34 +80,29 @@ compile_gs(struct svga_context *svga,
       /* some problem during translation, try the dummy shader */
       const struct tgsi_token *dummy = get_dummy_geometry_shader();
       if (!dummy) {
-         ret = PIPE_ERROR_OUT_OF_MEMORY;
-         goto fail;
+         return PIPE_ERROR_OUT_OF_MEMORY;
       }
       debug_printf("Failed to compile geometry shader, using dummy shader instead.\n");
       FREE((void *) gs->base.tokens);
       gs->base.tokens = dummy;
       variant = translate_geometry_program(svga, gs, key);
       if (variant == NULL) {
-         ret = PIPE_ERROR;
-         goto fail;
+         return PIPE_ERROR;
       }
    }

    ret = svga_define_shader(svga, SVGA3D_SHADERTYPE_GS, variant);
-   if (ret != PIPE_OK)
-      goto fail;
+   if (ret != PIPE_OK) {
+      svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_GS, variant);
+      return ret;
+   }

    *out_variant = variant;

    return PIPE_OK;
-
-fail:
-   if (variant) {
-      svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_GS, variant);
-   }
-   return ret;
 }

+
 static void
 make_gs_key(struct svga_context *svga, struct svga_compile_key *key)
 {
diff --git a/src/gallium/drivers/svga/svga_state_vs.c b/src/gallium/drivers/svga/svga_state_vs.c
index de41519..a846b77 100644
--- a/src/gallium/drivers/svga/svga_state_vs.c
+++ b/src/gallium/drivers/svga/svga_state_vs.c
@@ -127,13 +127,8 @@ compile_vs(struct svga_context *svga,
       debug_printf("Failed to compile vertex shader,"
                    " using dummy shader instead.\n");
       variant = get_compiled_dummy_vertex_shader(svga, vs, key);
-      if (!variant) {
-         ret = PIPE_ERROR;
-         goto fail;
-      }
    }
-
-   if (svga_shader_too_large(svga, variant)) {
+   else if (svga_shader_too_large(svga, variant)) {
       /* too big, use dummy shader */
       debug_printf("Shader too large (%u bytes),"
                    " using dummy shader instead.\n",
@@ -143,27 +138,24 @@ compile_vs(struct svga_context *svga,
       svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_VS, variant);
       /* Use simple pass-through shader instead */
       variant = get_compiled_dummy_vertex_shader(svga, vs, key);
-      if (!variant) {
-         ret = PIPE_ERROR;
-         goto fail;
-      }
+   }
+
+   if (!variant) {
+      return PIPE_ERROR;
    }

    ret = svga_define_shader(svga, SVGA3D_SHADERTYPE_VS, variant);
-   if (ret != PIPE_OK)
-      goto fail;
+   if (ret != PIPE_OK) {
+      svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_VS, variant);
+      return ret;
+   }

    *out_variant = variant;

    return PIPE_OK;
-
-fail:
-   if (variant) {
-      svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_VS, variant);
-   }
-   return ret;
 }

+
 /* SVGA_NEW_PRESCALE, SVGA_NEW_RAST, SVGA_NEW_FS
  */
 static void
--
1.9.1



More information about the mesa-dev mailing list