Mesa (master): svga: fix result==NULL logic in emit_fs_consts()

Brian Paul brianp at kemper.freedesktop.org
Thu Aug 16 15:00:44 UTC 2012


Module: Mesa
Branch: master
Commit: 50188adf7d4ca12488a3cb4b70ffdedea2e9c9b1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=50188adf7d4ca12488a3cb4b70ffdedea2e9c9b1

Author: Brian Paul <brianp at vmware.com>
Date:   Thu Aug  9 10:14:51 2012 -0600

svga: fix result==NULL logic in emit_fs_consts()

The previous test for result != NULL was kind of bogus since we dereferenced
the pointer earlier in the code.  Now, check for result != NULL first, then
get the result->key info.

Also, remove the useless "offset +=" code at the end.

---

 src/gallium/drivers/svga/svga_state_constants.c |   48 ++++++++++++-----------
 1 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_state_constants.c b/src/gallium/drivers/svga/svga_state_constants.c
index a3d61fb..a871154 100644
--- a/src/gallium/drivers/svga/svga_state_constants.c
+++ b/src/gallium/drivers/svga/svga_state_constants.c
@@ -262,7 +262,6 @@ static enum pipe_error
 emit_fs_consts(struct svga_context *svga, unsigned dirty)
 {
    const struct svga_shader_result *result = svga->state.hw_draw.fs;
-   const struct svga_fs_compile_key *key = &result->key.fkey;
    enum pipe_error ret = PIPE_OK;
 
    ret = emit_consts( svga, PIPE_SHADER_FRAGMENT );
@@ -273,30 +272,33 @@ emit_fs_consts(struct svga_context *svga, unsigned dirty)
     * doesn't have a 'result' struct.  It should be fixed to avoid
     * this special case, but work around it with a NULL check:
     */
-   if (result != NULL && key->num_unnormalized_coords) {
-      unsigned offset = result->shader->info.file_max[TGSI_FILE_CONSTANT] + 1;
-      int i;
-
-      for (i = 0; i < key->num_textures; i++) {
-         if (key->tex[i].unnormalized) {
-            struct pipe_resource *tex = svga->curr.sampler_views[i]->texture;
-            float data[4];
-
-            data[0] = 1.0 / (float)tex->width0;
-            data[1] = 1.0 / (float)tex->height0;
-            data[2] = 1.0;
-            data[3] = 1.0;
-
-            ret = emit_const( svga,
-                              PIPE_SHADER_FRAGMENT,
-                              key->tex[i].width_height_idx + offset,
-                              data );
-            if (ret != PIPE_OK)
-               return ret;
+   if (result) {
+      const struct svga_fs_compile_key *key = &result->key.fkey;
+      if (key->num_unnormalized_coords) {
+         const unsigned offset =
+            result->shader->info.file_max[TGSI_FILE_CONSTANT] + 1;
+         unsigned i;
+
+         for (i = 0; i < key->num_textures; i++) {
+            if (key->tex[i].unnormalized) {
+               struct pipe_resource *tex = svga->curr.sampler_views[i]->texture;
+               float data[4];
+
+               data[0] = 1.0f / (float) tex->width0;
+               data[1] = 1.0f / (float) tex->height0;
+               data[2] = 1.0f;
+               data[3] = 1.0f;
+
+               ret = emit_const(svga,
+                                PIPE_SHADER_FRAGMENT,
+                                key->tex[i].width_height_idx + offset,
+                                data);
+               if (ret != PIPE_OK) {
+                  return ret;
+               }
+            }
          }
       }
-
-      offset += key->num_unnormalized_coords;
    }
 
    return PIPE_OK;




More information about the mesa-commit mailing list