[Mesa-dev] [PATCH] nv30, nv50: handle pure integer vertex attributes

Emil Velikov emil.l.velikov at gmail.com
Wed Jul 10 18:00:15 PDT 2013


Fixes nouveau crash in the following piglit test:
general/attribs GL3

v3: Handle both signed and unsigned ints.
    Do not typecast the ints to floats, rather feed the ints directly.
    This is what the blob does :)

v2: Convert the attribute(s) to float and submit as such.
    Comment about using channel[0] rather than "first-non-void".

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/gallium/drivers/nv30/nv30_vbo.c | 13 ++++++++++++-
 src/gallium/drivers/nv50/nv50_vbo.c | 13 ++++++++++++-
 src/gallium/drivers/nvc0/nvc0_vbo.c |  2 ++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/nv30/nv30_vbo.c b/src/gallium/drivers/nv30/nv30_vbo.c
index 9033fa5..8117303 100644
--- a/src/gallium/drivers/nv30/nv30_vbo.c
+++ b/src/gallium/drivers/nv30/nv30_vbo.c
@@ -40,13 +40,24 @@ nv30_emit_vtxattr(struct nv30_context *nv30, struct pipe_vertex_buffer *vb,
    const unsigned nc = util_format_get_nr_components(ve->src_format);
    struct nouveau_pushbuf *push = nv30->base.pushbuf;
    struct nv04_resource *res = nv04_resource(vb->buffer);
+   const struct util_format_description *desc = 
+      util_format_description(ve->src_format);
    const void *data;
    float v[4];
 
    data = nouveau_resource_map_offset(&nv30->base, res, vb->buffer_offset +
                                       ve->src_offset, NOUVEAU_BO_RD);
 
-   util_format_read_4f(ve->src_format, v, 0, data, 0, 0, 0, 1, 1);
+   /* Vertex formats's first channel is always non void */
+   if (desc->channel[0].pure_integer) {
+      if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
+         desc->unpack_rgba_sint((int32_t *)v, 0, data, 0, 1, 1);
+      } else {
+         desc->unpack_rgba_uint((uint32_t *)v, 0, data, 0, 1, 1);
+      }
+   } else {
+      desc->unpack_rgba_float(v, 0, data, 0, 1, 1);
+   }
 
    switch (nc) {
    case 4:
diff --git a/src/gallium/drivers/nv50/nv50_vbo.c b/src/gallium/drivers/nv50/nv50_vbo.c
index db4e0cd..c1793f2 100644
--- a/src/gallium/drivers/nv50/nv50_vbo.c
+++ b/src/gallium/drivers/nv50/nv50_vbo.c
@@ -140,10 +140,21 @@ nv50_emit_vtxattr(struct nv50_context *nv50, struct pipe_vertex_buffer *vb,
    const void *data = (const uint8_t *)vb->user_buffer + ve->src_offset;
    float v[4];
    const unsigned nc = util_format_get_nr_components(ve->src_format);
+   const struct util_format_description *desc = 
+      util_format_description(ve->src_format);
 
    assert(vb->user_buffer);
 
-   util_format_read_4f(ve->src_format, v, 0, data, 0, 0, 0, 1, 1);
+   /* Vertex formats's first channel is always non void */
+   if (desc->channel[0].pure_integer) {
+      if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
+         desc->unpack_rgba_sint((int32_t *)v, 0, data, 0, 1, 1);
+      } else {
+         desc->unpack_rgba_uint((uint32_t *)v, 0, data, 0, 1, 1);
+      }
+   } else {
+      desc->unpack_rgba_float(v, 0, data, 0, 1, 1);
+   }
 
    switch (nc) {
    case 4:
diff --git a/src/gallium/drivers/nvc0/nvc0_vbo.c b/src/gallium/drivers/nvc0/nvc0_vbo.c
index 1e9fc62..f227180 100644
--- a/src/gallium/drivers/nvc0/nvc0_vbo.c
+++ b/src/gallium/drivers/nvc0/nvc0_vbo.c
@@ -113,6 +113,7 @@ nvc0_vertex_state_create(struct pipe_context *pipe,
             unsigned ca;
             unsigned j = transkey.nr_elements++;
 
+            /* Vertex formats's first channel is always non void */
             ca = util_format_description(fmt)->channel[0].size / 8;
             if (ca != 1 && ca != 2)
                ca = 4;
@@ -180,6 +181,7 @@ nvc0_set_constant_vertex_attrib(struct nvc0_context *nvc0, const unsigned a)
    PUSH_SPACE(push, 6);
    BEGIN_NVC0(push, NVC0_3D(VTX_ATTR_DEFINE), 5);
    dst = &push->cur[1];
+   /* Vertex formats's first channel is always non void */
    if (desc->channel[0].pure_integer) {
       if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
          mode = VTX_ATTR(a, 4, SINT, 32);
-- 
1.8.3.2



More information about the mesa-dev mailing list