radeonsi/compute: Pass kernel arguments in a buffer v2
[mesa.git] / src / gallium / drivers / radeonsi / r600_buffer.c
index cdf9988c6e78d698026ecb85f394c5878bc92cf7..3d295e8a967a3119aef58b93e2a8b85d16f8157c 100644 (file)
@@ -25,6 +25,8 @@
  *      Corbin Simpson <MostAwesomeDude@gmail.com>
  */
 
+#include <byteswap.h>
+
 #include "pipe/p_screen.h"
 #include "util/u_format.h"
 #include "util/u_math.h"
@@ -168,3 +170,30 @@ void r600_upload_index_buffer(struct r600_context *rctx,
        u_upload_data(rctx->uploader, 0, count * ib->index_size,
                      ib->user_buffer, &ib->offset, &ib->buffer);
 }
+
+void r600_upload_const_buffer(struct r600_context *rctx, struct si_resource **rbuffer,
+                       const uint8_t *ptr, unsigned size,
+                       uint32_t *const_offset)
+{
+       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->uploader, 0, size, tmpPtr, const_offset,
+                               (struct pipe_resource**)rbuffer);
+
+               free(tmpPtr);
+       } else {
+               u_upload_data(rctx->uploader, 0, size, ptr, const_offset,
+                                       (struct pipe_resource**)rbuffer);
+       }
+}