Mesa (master): util: use memset() to initialize surface, sampler_view templates

Brian Paul brianp at kemper.freedesktop.org
Tue Jan 10 11:38:17 PST 2012


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

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jan 10 11:35:57 2012 -0700

util: use memset() to initialize surface, sampler_view templates

These initialization functions weren't initializing all the fields so
some had undefined values.  The callers of these functions sometimes use
a structure assignment to initialize new objects from these templates
so we'd just propagate the undefined values.  That made for some confusing
info when debugging, plus it could lead to bugs.

v2: fix surf pointer mix-up: "&surf" -> "surf"

Jakob Bornecrantz <jakob at vmware.com>

---

 src/gallium/auxiliary/util/u_sampler.c |    6 ++++++
 src/gallium/auxiliary/util/u_surface.c |   17 ++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_sampler.c b/src/gallium/auxiliary/util/u_sampler.c
index bb26099..227641b 100644
--- a/src/gallium/auxiliary/util/u_sampler.c
+++ b/src/gallium/auxiliary/util/u_sampler.c
@@ -30,12 +30,18 @@
 #include "u_sampler.h"
 
 
+/**
+ * Initialize a pipe_sampler_view.  'view' is considered to have
+ * uninitialized contents.
+ */
 static void
 default_template(struct pipe_sampler_view *view,
                  const struct pipe_resource *texture,
                  enum pipe_format format,
                  unsigned expand_green_blue)
 {
+   memset(view, 0, sizeof(*view));
+
    /* XXX: Check if format is compatible with texture->format.
     */
 
diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c
index c7fbd36..a541a38 100644
--- a/src/gallium/auxiliary/util/u_surface.c
+++ b/src/gallium/auxiliary/util/u_surface.c
@@ -42,17 +42,21 @@
 #include "util/u_surface.h"
 #include "util/u_pack_color.h"
 
+
+/**
+ * Initialize a pipe_surface object.  'view' is considered to have
+ * uninitialized contents.
+ */
 void
-u_surface_default_template(struct pipe_surface *view,
+u_surface_default_template(struct pipe_surface *surf,
                            const struct pipe_resource *texture,
                            unsigned bind)
 {
-   view->format = texture->format;
-   view->u.tex.level = 0;
-   view->u.tex.first_layer = 0;
-   view->u.tex.last_layer = 0;
+   memset(surf, 0, sizeof(*surf));
+
+   surf->format = texture->format;
    /* XXX should filter out all non-rt/ds bind flags ? */
-   view->usage = bind;
+   surf->usage = bind;
 }
 
 /**
@@ -108,7 +112,6 @@ util_create_rgba_surface(struct pipe_context *pipe,
       return FALSE;
 
    /* create surface */
-   memset(&surf_templ, 0, sizeof(surf_templ));
    u_surface_default_template(&surf_templ, *textureOut, bind);
    /* create surface / view into texture */
    *surfaceOut = pipe->create_surface(pipe,



More information about the mesa-commit mailing list