[Nouveau] [PATCH] nvc0: respect edgeflag attribute width

Ilia Mirkin
2015-10-23T06:14:31Z

The edgeflag comes in as ubyte with glEdgeFlagPointer but as float with
plain immediate glEdgeFlag. Avoid reading bytes that weren't meant for
the edgeflag in the pointer case.

Fixes intermittent failures with gl-2.0-edgeflag piglit (and valgrind
complaints about reading uninitialized memory).

Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
Cc: mesa-stable at lists.freedesktop.org
---
 src/gallium/drivers/nouveau/nvc0/nvc0_vbo_translate.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_vbo_translate.c
b/src/gallium/drivers/nouveau/nvc0/nvc0_vbo_translate.c
index 8b23a48..efadeeb 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_vbo_translate.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_vbo_translate.c
@@ -27,6 +27,7 @@ struct push_context {
    struct {
       bool enabled;
       bool value;
+      uint8_t width;
       unsigned stride;
       const uint8_t *data;
    } edgeflag;
@@ -100,6 +101,7 @@ nvc0_push_map_edgeflag(struct push_context *ctx, struct
nvc0_context *nvc0,
    struct nv04_resource *buf = nv04_resource(vb->buffer);

    ctx->edgeflag.stride = vb->stride;
+   ctx->edgeflag.width = util_format_get_blocksize(ve->src_format);
    if (buf) {
       unsigned offset = vb->buffer_offset + ve->src_offset;
       ctx->edgeflag.data = nouveau_resource_map_offset(&nvc0->base,
@@ -139,8 +141,9 @@ prim_restart_search_i32(const uint32_t *elts, unsigned push,
uint32_t index)
 static inline bool
 ef_value(const struct push_context *ctx, uint32_t index)
 {
-   float *pf = (float *)&ctx->edgeflag.data[index *
ctx->edgeflag.stride];
-   return *pf ? true : false;
+   static const uint64_t zero = 0;
+   uint8_t *pf = (uint8_t *)&ctx->edgeflag.data[index *
ctx->edgeflag.stride];
+   return !!memcmp(pf, &zero, ctx->edgeflag.width);
 }

 static inline bool
--
2.4.10