[Mesa-dev] [PATCH 10/17] gallium/util: Ensure util_framebuffer_get_num_samples() is valid

Edward O'Callaghan eocallaghan at alterapraxis.com
Fri Mar 25 00:11:14 UTC 2016


Upon context creation, internal driver structures are malloc()'ed
and memset() to zero them. This results in a invalid number of
samples 'by default'. Handle this in the simplest way to avoid
elaborate and probably equally sub-optimial solutions.

V2: Minor, use "NOTE:" instead of "N.B." in comment.

Signed-off-by: Edward O'Callaghan <eocallaghan at alterapraxis.com>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
---
 src/gallium/auxiliary/util/u_framebuffer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/util/u_framebuffer.c b/src/gallium/auxiliary/util/u_framebuffer.c
index 775f050..b020f27 100644
--- a/src/gallium/auxiliary/util/u_framebuffer.c
+++ b/src/gallium/auxiliary/util/u_framebuffer.c
@@ -204,9 +204,15 @@ util_framebuffer_get_num_samples(const struct pipe_framebuffer_state *fb)
     * In the case of ARB_framebuffer_no_attachment
     * we obtain the number of samples directly from
     * the framebuffer state.
+    *
+    * NOTE: fb->samples may wind up as zero due to memset()'s on internal
+    *       driver structures on their initialization and so we take the
+    *       MAX here to ensure we have a valid number of samples. However,
+    *       if samples is legitimately not getting set somewhere
+    *       multi-sampling will evidently break.
     */
    if (!(fb->nr_cbufs || fb->zsbuf))
-      return fb->samples;
+      return MAX2(fb->samples, 1);
 
    for (i = 0; i < fb->nr_cbufs; i++) {
       if (fb->cbufs[i]) {
-- 
2.5.5



More information about the mesa-dev mailing list