r600g: fix vertex format fallback
authorMarek Olšák <maraeo@gmail.com>
Sat, 29 Jan 2011 12:49:41 +0000 (13:49 +0100)
committerMarek Olšák <maraeo@gmail.com>
Sun, 30 Jan 2011 02:29:48 +0000 (03:29 +0100)
This fixes:
- piglit/draw-vertices
- piglit/draw-vertices-half-float

src/gallium/drivers/r600/r600_asm.c
src/gallium/drivers/r600/r600_blit.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_state_common.c
src/gallium/drivers/r600/r600_translate.c

index 9cdd10f9876a67a8e452792015ddbcbb0e38b43e..3b0d01b8720bdd91c7163ec76d302d7116c8d436 100644 (file)
@@ -1889,7 +1889,7 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format,
        }
 
        switch (desc->channel[i].type) {
-               /* Half-floats, floats, doubles */
+       /* Half-floats, floats, ints */
        case UTIL_FORMAT_TYPE_FLOAT:
                switch (desc->channel[i].size) {
                case 16:
@@ -1901,8 +1901,6 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format,
                                *format = FMT_16_16_FLOAT;
                                break;
                        case 3:
-                               *format = FMT_16_16_16_FLOAT;
-                               break;
                        case 4:
                                *format = FMT_16_16_16_16_FLOAT;
                                break;
@@ -1942,8 +1940,6 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format,
                                *format = FMT_8_8;
                                break;
                        case 3:
-                       //      *format = FMT_8_8_8; /* fails piglit draw-vertices test */
-                       //      break;
                        case 4:
                                *format = FMT_8_8_8_8;
                                break;
@@ -1958,8 +1954,6 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format,
                                *format = FMT_16_16;
                                break;
                        case 3:
-                       //      *format = FMT_16_16_16; /* fails piglit draw-vertices test */
-                       //      break;
                        case 4:
                                *format = FMT_16_16_16_16;
                                break;
index b9ec9592e357f9dac2ed5709bbb0003200ff6d37..b487182e3aab5aaa72177592dbefeaf0abf7270f 100644 (file)
@@ -53,7 +53,7 @@ static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op
        if (rctx->states[R600_PIPE_STATE_CLIP]) {
                util_blitter_save_clip(rctx->blitter, &rctx->clip);
        }
-       util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffer, rctx->vertex_buffer);
+       util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffers, rctx->vertex_buffer);
 
        rctx->vertex_elements = NULL;
 
index 360ee2af1fc31464d33015c256b3831d474bb5ba..301888abc78c9477514b03478780712647c1ac8f 100644 (file)
@@ -125,6 +125,7 @@ struct r600_translate_context {
        struct translate_cache          *translate_cache;
        /* The vertex buffer slot containing the translated buffer. */
        unsigned                        vb_slot;
+       void                            *saved_velems;
        void                            *new_velems;
 };
 
@@ -145,7 +146,8 @@ struct r600_pipe_context {
        struct pipe_index_buffer        index_buffer;
        struct pipe_vertex_buffer       vertex_buffer[PIPE_MAX_ATTRIBS];
        struct pipe_resource            *real_vertex_buffer[PIPE_MAX_ATTRIBS];
-       unsigned                        nvertex_buffer;
+       unsigned                        nvertex_buffers;
+       unsigned                        nreal_vertex_buffers; /* with the translated vertex buffer */
        unsigned                        cb_target_mask;
        /* for saving when using blitter */
        struct pipe_stencil_ref         stencil_ref;
index 409a07bda17eab05338baab2ba7419c699659fb8..4a2c7fe935c50e699244653b1d761fef568dacc2 100644 (file)
@@ -205,7 +205,7 @@ void r600_set_vertex_buffers(struct pipe_context *ctx, unsigned count,
                }
        }
 
-       for (; i < rctx->nvertex_buffer; i++) {
+       for (; i < rctx->nreal_vertex_buffers; i++) {
                pipe_resource_reference(&rctx->vertex_buffer[i].buffer, NULL);
                pipe_resource_reference(&rctx->real_vertex_buffer[i], NULL);
 
@@ -219,7 +219,8 @@ void r600_set_vertex_buffers(struct pipe_context *ctx, unsigned count,
 
        memcpy(rctx->vertex_buffer, buffers, sizeof(struct pipe_vertex_buffer) * count);
 
-       rctx->nvertex_buffer = count;
+       rctx->nvertex_buffers = count;
+       rctx->nreal_vertex_buffers = count;
        rctx->vb_max_index = max_index;
 }
 
@@ -252,6 +253,28 @@ void *r600_create_vertex_elements(struct pipe_context *ctx,
                FORMAT_REPLACE(R64G64_FLOAT,        R32G32_FLOAT);
                FORMAT_REPLACE(R64G64B64_FLOAT,     R32G32B32_FLOAT);
                FORMAT_REPLACE(R64G64B64A64_FLOAT,  R32G32B32A32_FLOAT);
+
+               /* r600 doesn't seem to support 32_*SCALED, these formats
+                * aren't in D3D10 either. */
+               FORMAT_REPLACE(R32_UNORM,           R32_FLOAT);
+               FORMAT_REPLACE(R32G32_UNORM,        R32G32_FLOAT);
+               FORMAT_REPLACE(R32G32B32_UNORM,     R32G32B32_FLOAT);
+               FORMAT_REPLACE(R32G32B32A32_UNORM,  R32G32B32A32_FLOAT);
+
+               FORMAT_REPLACE(R32_USCALED,         R32_FLOAT);
+               FORMAT_REPLACE(R32G32_USCALED,      R32G32_FLOAT);
+               FORMAT_REPLACE(R32G32B32_USCALED,   R32G32B32_FLOAT);
+               FORMAT_REPLACE(R32G32B32A32_USCALED,R32G32B32A32_FLOAT);
+
+               FORMAT_REPLACE(R32_SNORM,           R32_FLOAT);
+               FORMAT_REPLACE(R32G32_SNORM,        R32G32_FLOAT);
+               FORMAT_REPLACE(R32G32B32_SNORM,     R32G32B32_FLOAT);
+               FORMAT_REPLACE(R32G32B32A32_SNORM,  R32G32B32A32_FLOAT);
+
+               FORMAT_REPLACE(R32_SSCALED,         R32_FLOAT);
+               FORMAT_REPLACE(R32G32_SSCALED,      R32G32_FLOAT);
+               FORMAT_REPLACE(R32G32B32_SSCALED,   R32G32B32_FLOAT);
+               FORMAT_REPLACE(R32G32B32A32_SSCALED,R32G32B32A32_FLOAT);
                default:;
                }
                v->incompatible_layout =
@@ -426,7 +449,7 @@ static void r600_vertex_buffer_update(struct r600_pipe_context *rctx)
                rctx->nvs_resource = rctx->vertex_elements->count;
        } else {
                /* bind vertex buffer once */
-               rctx->nvs_resource = rctx->nvertex_buffer;
+               rctx->nvs_resource = rctx->nreal_vertex_buffers;
        }
 
        for (i = 0 ; i < rctx->nvs_resource; i++) {
index f80fa7af941a3da920785b8a7c0a94479671bdf2..5f63af59ccc6a3f3640b9e4089cd5397ec36568a 100644 (file)
@@ -98,14 +98,14 @@ void r600_begin_vertex_translate(struct r600_pipe_context *rctx)
        tr = translate_cache_find(rctx->tran.translate_cache, &key);
 
        /* Map buffers we want to translate. */
-       for (i = 0; i < rctx->nvertex_buffer; i++) {
+       for (i = 0; i < rctx->nvertex_buffers; i++) {
                if (vb_translated[i]) {
                        struct pipe_vertex_buffer *vb = &rctx->vertex_buffer[i];
 
                        vb_map[i] = pipe_buffer_map(pipe, vb->buffer,
                                                    PIPE_TRANSFER_READ, &vb_transfer[i]);
 
-                       tr->set_buffer(tr, i, vb_map[i], vb->stride, vb->max_index);
+                       tr->set_buffer(tr, i, vb_map[i], vb->stride, ~0);
                }
        }
 
@@ -123,7 +123,7 @@ void r600_begin_vertex_translate(struct r600_pipe_context *rctx)
        tr->run(tr, 0, num_verts, 0, out_map);
 
        /* Unmap all buffers. */
-       for (i = 0; i < rctx->nvertex_buffer; i++) {
+       for (i = 0; i < rctx->nvertex_buffers; i++) {
                if (vb_translated[i]) {
                        pipe_buffer_unmap(pipe, vb_transfer[i]);
                }
@@ -136,11 +136,14 @@ void r600_begin_vertex_translate(struct r600_pipe_context *rctx)
                struct pipe_vertex_buffer *vb = &rctx->vertex_buffer[i];
 
                if (!vb->buffer) {
-                       pipe_resource_reference(&vb->buffer, out_buffer);
+                       pipe_resource_reference(&rctx->real_vertex_buffer[i], out_buffer);
                        vb->buffer_offset = 0;
-                       vb->max_index = num_verts - 1;
                        vb->stride = key.output_stride;
                        rctx->tran.vb_slot = i;
+
+                       if (i >= rctx->nvertex_buffers) {
+                               rctx->nreal_vertex_buffers = i+1;
+                       }
                        break;
                }
        }
@@ -159,6 +162,7 @@ void r600_begin_vertex_translate(struct r600_pipe_context *rctx)
                }
        }
 
+       rctx->tran.saved_velems = rctx->vertex_elements;
        tmp = pipe->create_vertex_elements_state(pipe, ve->count, new_velems);
        pipe->bind_vertex_elements_state(pipe, tmp);
        rctx->tran.new_velems = tmp;
@@ -174,11 +178,14 @@ void r600_end_vertex_translate(struct r600_pipe_context *rctx)
                return;
        }
        /* Restore vertex elements. */
+       pipe->bind_vertex_elements_state(pipe, rctx->tran.saved_velems);
+       rctx->tran.saved_velems = NULL;
        pipe->delete_vertex_elements_state(pipe, rctx->tran.new_velems);
        rctx->tran.new_velems = NULL;
 
        /* Delete the now-unused VBO. */
-       pipe_resource_reference(&rctx->vertex_buffer[rctx->tran.vb_slot].buffer, NULL);
+       pipe_resource_reference(&rctx->real_vertex_buffer[rctx->tran.vb_slot], NULL);
+       rctx->nreal_vertex_buffers = rctx->nvertex_buffers;
 }
 
 void r600_translate_index_buffer(struct r600_pipe_context *r600,
@@ -192,8 +199,5 @@ void r600_translate_index_buffer(struct r600_pipe_context *r600,
                *index_size = 2;
                *start = 0;
                break;
-       case 2:
-       case 4:
-               break;
        }
 }