Merge branch 'gallium-userbuf'
[mesa.git] / src / gallium / drivers / r600 / r600_state_common.c
index a817831fd8251422ac04d5b3c58c199a7acaf5b8..d47383558d9b23b8dcd173f311ec0bbf027e786a 100644 (file)
@@ -532,12 +532,12 @@ void r600_constant_buffers_dirty(struct r600_context *rctx, struct r600_constbuf
 }
 
 void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
-                             struct pipe_resource *buffer)
+                             struct pipe_constant_buffer *input)
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
        struct r600_constbuf_state *state;
-       struct r600_constant_buffer *cb;
-       uint8_t *ptr;
+       struct pipe_constant_buffer *cb;
+       const uint8_t *ptr;
 
        switch (shader) {
        case PIPE_SHADER_VERTEX:
@@ -553,7 +553,7 @@ void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
        /* Note that the state tracker can unbind constant buffers by
         * passing NULL here.
         */
-       if (unlikely(!buffer)) {
+       if (unlikely(!input)) {
                state->enabled_mask &= ~(1 << index);
                state->dirty_mask &= ~(1 << index);
                pipe_resource_reference(&state->cb[index].buffer, NULL);
@@ -561,15 +561,15 @@ void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
        }
 
        cb = &state->cb[index];
-       cb->buffer_size = buffer->width0;
+       cb->buffer_size = input->buffer_size;
 
-       ptr = buffer->user_ptr;
+       ptr = input->user_buffer;
 
        if (ptr) {
                /* Upload the user buffer. */
                if (R600_BIG_ENDIAN) {
                        uint32_t *tmpPtr;
-                       unsigned i, size = buffer->width0;
+                       unsigned i, size = input->buffer_size;
 
                        if (!(tmpPtr = malloc(size))) {
                                R600_ERR("Failed to allocate BE swap buffer.\n");
@@ -583,12 +583,12 @@ void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
                        u_upload_data(rctx->uploader, 0, size, tmpPtr, &cb->buffer_offset, &cb->buffer);
                        free(tmpPtr);
                } else {
-                       u_upload_data(rctx->uploader, 0, buffer->width0, ptr, &cb->buffer_offset, &cb->buffer);
+                       u_upload_data(rctx->uploader, 0, input->buffer_size, ptr, &cb->buffer_offset, &cb->buffer);
                }
        } else {
                /* Setup the hw buffer. */
-               cb->buffer_offset = 0;
-               pipe_resource_reference(&cb->buffer, buffer);
+               cb->buffer_offset = input->buffer_offset;
+               pipe_resource_reference(&cb->buffer, input->buffer);
        }
 
        state->enabled_mask |= 1 << index;
@@ -753,7 +753,6 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *dinfo)
        uint8_t *ptr;
 
        if ((!info.count && (info.indexed || !info.count_from_stream_output)) ||
-           (info.indexed && !rctx->index_buffer.buffer) ||
            !r600_conv_pipe_prim(info.mode, &prim)) {
                assert(0);
                return;
@@ -769,14 +768,15 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *dinfo)
        if (info.indexed) {
                /* Initialize the index buffer struct. */
                pipe_resource_reference(&ib.buffer, rctx->index_buffer.buffer);
+               ib.user_buffer = rctx->index_buffer.user_buffer;
                ib.index_size = rctx->index_buffer.index_size;
                ib.offset = rctx->index_buffer.offset + info.start * ib.index_size;
 
                /* Translate or upload, if needed. */
                r600_translate_index_buffer(rctx, &ib, info.count);
 
-               ptr = ib.buffer->user_ptr;
-               if (ptr) {
+               ptr = (uint8_t*)ib.user_buffer;
+               if (!ib.buffer && ptr) {
                        u_upload_data(rctx->uploader, 0, info.count * ib.index_size,
                                      ptr, &ib.offset, &ib.buffer);
                }