Mesa (master): draw/aaline: stronger guard against no free samplers (v2)

Nicolai Hähnle nh at kemper.freedesktop.org
Thu Apr 7 18:16:58 UTC 2016


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

Author: Nicolai Hähnle <nicolai.haehnle at amd.com>
Date:   Wed Apr  6 16:27:21 2016 -0500

draw/aaline: stronger guard against no free samplers (v2)

Line anti-aliasing will fail when there is no free sampler available. Make
the corresponding guard more robust in preparation of raising
PIPE_MAX_SAMPLERS to 32.

The literal 1 is a (signed) int, and shifting into the sign bit is undefined
in C, so change occurences of 1 to 1u.

v2: add an assert for bitfield size and use 1u << idx

Reviewed-by: Brian Paul <brianp at vmware.com>
Reviewed-by: Roland Scheidegger <sroland at vmware.com> (v1)
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl> (v1)
Reviewed-by: Marek Olšák <marek.olsak at amd.com> (v1)

---

 src/gallium/auxiliary/draw/draw_pipe_aaline.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c
index cd9ee54..a5f0723 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c
@@ -163,7 +163,7 @@ aa_transform_decl(struct tgsi_transform_context *ctx,
       uint i;
       for (i = decl->Range.First;
            i <= decl->Range.Last; i++) {
-         aactx->samplersUsed |= 1 << i;
+         aactx->samplersUsed |= 1u << i;
       }
    }
    else if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
@@ -208,9 +208,11 @@ aa_transform_prolog(struct tgsi_transform_context *ctx)
    struct aa_transform_context *aactx = (struct aa_transform_context *) ctx;
    uint i;
 
+   STATIC_ASSERT(sizeof(aactx->samplersUsed) * 8 >= PIPE_MAX_SAMPLERS);
+
    /* find free sampler */
    aactx->freeSampler = free_bit(aactx->samplersUsed);
-   if (aactx->freeSampler >= PIPE_MAX_SAMPLERS)
+   if (aactx->freeSampler < 0 || aactx->freeSampler >= PIPE_MAX_SAMPLERS)
       aactx->freeSampler = PIPE_MAX_SAMPLERS - 1;
 
    /* find two free temp regs */




More information about the mesa-commit mailing list