r600g: inline r600_upload_const_buffer
authorMarek Olšák <maraeo@gmail.com>
Mon, 2 Apr 2012 00:45:27 +0000 (02:45 +0200)
committerMarek Olšák <maraeo@gmail.com>
Wed, 4 Apr 2012 11:09:47 +0000 (13:09 +0200)
src/gallium/drivers/r600/r600_buffer.c
src/gallium/drivers/r600/r600_resource.h
src/gallium/drivers/r600/r600_state_common.c

index f9f32b2c7ee8ef84c3ce7d146b2c5263e63478ed..b165c319de4cc330417e9e4d51a4f3149588ffc9 100644 (file)
@@ -25,7 +25,6 @@
  *      Corbin Simpson <MostAwesomeDude@gmail.com>
  */
 #include "r600_pipe.h"
-#include <byteswap.h>
 #include "util/u_upload_mgr.h"
 
 static void r600_buffer_destroy(struct pipe_screen *screen,
@@ -267,38 +266,3 @@ void r600_upload_index_buffer(struct r600_context *rctx,
        u_upload_data(rctx->vbuf_mgr->uploader, 0, count * ib->index_size,
                      rbuffer->b.user_ptr, &ib->offset, &ib->buffer);
 }
-
-void r600_upload_const_buffer(struct r600_context *rctx, struct r600_resource **rbuffer,
-                            uint32_t *const_offset)
-{
-       if ((*rbuffer)->b.user_ptr) {
-               uint8_t *ptr = (*rbuffer)->b.user_ptr;
-               unsigned size = (*rbuffer)->b.b.b.width0;
-
-               *rbuffer = NULL;
-
-               if (R600_BIG_ENDIAN) {
-                       uint32_t *tmpPtr;
-                       unsigned i;
-
-                       if (!(tmpPtr = malloc(size))) {
-                               R600_ERR("Failed to allocate BE swap buffer.\n");
-                               return;
-                       }
-
-                       for (i = 0; i < size / 4; ++i) {
-                               tmpPtr[i] = bswap_32(((uint32_t *)ptr)[i]);
-                       }
-
-                       u_upload_data(rctx->vbuf_mgr->uploader, 0, size, tmpPtr, const_offset,
-                                     (struct pipe_resource**)rbuffer);
-
-                       free(tmpPtr);
-               } else {
-                       u_upload_data(rctx->vbuf_mgr->uploader, 0, size, ptr, const_offset,
-                                     (struct pipe_resource**)rbuffer);
-               }
-       } else {
-               *const_offset = 0;
-       }
-}
index 5bb5e577ee649339ed8c8b8d2cc972551e5edc3f..87bef7306548e2464c462271b279e800a647e45e 100644 (file)
@@ -94,8 +94,4 @@ void* r600_texture_transfer_map(struct pipe_context *ctx,
 void r600_texture_transfer_unmap(struct pipe_context *ctx,
                                 struct pipe_transfer* transfer);
 
-struct r600_context;
-
-void r600_upload_const_buffer(struct r600_context *rctx, struct r600_resource **rbuffer, uint32_t *offset);
-
 #endif
index 24e9ae3b7e7d95d8f572a3dac0141a3c33965a6f..1738d30430987ef9a24930117ffc50ee6ba5fff5 100644 (file)
@@ -28,7 +28,9 @@
 #include "r600d.h"
 
 #include "util/u_blitter.h"
+#include "util/u_upload_mgr.h"
 #include "tgsi/tgsi_parse.h"
+#include <byteswap.h>
 
 static void r600_emit_command_buffer(struct r600_context *rctx, struct r600_atom *atom)
 {
@@ -531,10 +533,9 @@ void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
                              struct pipe_resource *buffer)
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
-       struct r600_resource *rbuffer = r600_resource(buffer);
        struct r600_constbuf_state *state;
        struct r600_constant_buffer *cb;
-       uint32_t offset;
+       uint8_t *ptr;
 
        switch (shader) {
        case PIPE_SHADER_VERTEX:
@@ -550,26 +551,47 @@ 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 (buffer == NULL) {
+       if (unlikely(!buffer)) {
                state->enabled_mask &= ~(1 << index);
                state->dirty_mask &= ~(1 << index);
                pipe_resource_reference(&state->cb[index].buffer, NULL);
                return;
        }
 
-       r600_upload_const_buffer(rctx, &rbuffer, &offset);
-
        cb = &state->cb[index];
-       pipe_resource_reference(&cb->buffer, &rbuffer->b.b.b);
-       cb->buffer_offset = offset;
        cb->buffer_size = buffer->width0;
 
+       ptr = u_vbuf_resource(buffer)->user_ptr;
+
+       if (ptr) {
+               /* Upload the user buffer. */
+               if (R600_BIG_ENDIAN) {
+                       uint32_t *tmpPtr;
+                       unsigned i, size = buffer->width0;
+
+                       if (!(tmpPtr = malloc(size))) {
+                               R600_ERR("Failed to allocate BE swap buffer.\n");
+                               return;
+                       }
+
+                       for (i = 0; i < size / 4; ++i) {
+                               tmpPtr[i] = bswap_32(((uint32_t *)ptr)[i]);
+                       }
+
+                       u_upload_data(rctx->vbuf_mgr->uploader, 0, size, tmpPtr, &cb->buffer_offset, &cb->buffer);
+                       free(tmpPtr);
+               } else {
+                       u_upload_data(rctx->vbuf_mgr->uploader, 0, buffer->width0, ptr, &cb->buffer_offset, &cb->buffer);
+               }
+       } else {
+               /* Setup the hw buffer. */
+               cb->buffer_offset = 0;
+               pipe_resource_reference(&cb->buffer, buffer);
+       }
+
        state->enabled_mask |= 1 << index;
        state->dirty_mask |= 1 << index;
        r600_constant_buffers_dirty(rctx, state);
-
-       if (buffer != &rbuffer->b.b.b)
-               pipe_resource_reference((struct pipe_resource**)&rbuffer, NULL);
 }
 
 struct pipe_stream_output_target *